UNPKG

@grain/libbinaryen

Version:

Libbinaryen packaged for OCaml.

1,531 lines (1,304 loc) 117 kB
function assertDeepEqual(x, y) { if (typeof x === "object") { for (let i in x) assertDeepEqual(x[i], y[i]); for (let i in y) assertDeepEqual(x[i], y[i]); } else { assert(x === y); } } console.log("# Expression"); (function testWrapper() { const module = new binaryen.Module(); const ptr = module.block(null, []); var theExpression = binaryen.Expression(ptr); // works without new assert(theExpression instanceof binaryen.Block); assert(theExpression instanceof binaryen.Expression); assert(theExpression.constructor === binaryen.Block); assert(typeof binaryen.Block.getId === "function"); // proto assert(typeof binaryen.Block.getName === "function"); // own assert(typeof theExpression.getId === "function"); // proto assert(typeof theExpression.getName === "function"); // own assert((theExpression | 0) === ptr); // via valueOf module.dispose(); })(); console.log("# Block"); (function testBlock() { const module = new binaryen.Module(); const theBlock = binaryen.Block(module.block(null, [])); assert(theBlock instanceof binaryen.Block); assert(theBlock instanceof binaryen.Expression); assert(theBlock.id === binaryen.BlockId); assert(theBlock.name === null); assert(theBlock.type === binaryen.none); var info = binaryen.getExpressionInfo(theBlock); assert(info.id === theBlock.id); assert(info.type === theBlock.type); assert(info.name === theBlock.name); assertDeepEqual(info.children, theBlock.children); theBlock.name ="theName"; assert(theBlock.name === "theName"); theBlock.type = binaryen.i32; assert(theBlock.type === binaryen.i32); assert(theBlock.numChildren === 0); assertDeepEqual(theBlock.children, []); assertDeepEqual(theBlock.getChildren(), []); var child1 = module.i32.const(1); theBlock.appendChild(child1); assert(theBlock.numChildren === 1); assert(theBlock.getChildAt(0) === child1); var child2 = module.i32.const(2); theBlock.insertChildAt(1, child2); assert(theBlock.numChildren === 2); assert(theBlock.getChildAt(0) === child1); assert(theBlock.getChildAt(1) === child2); var child0 = module.i32.const(0); theBlock.insertChildAt(0, child0); assert(theBlock.numChildren === 3); assert(theBlock.getChildAt(0) === child0); assert(theBlock.getChildAt(1) === child1); assert(theBlock.getChildAt(2) === child2); var newChild1 = module.i32.const(11); theBlock.setChildAt(1, newChild1); assert(theBlock.numChildren === 3); assert(theBlock.getChildAt(0) === child0); assert(theBlock.getChildAt(1) === newChild1); assert(theBlock.getChildAt(2) === child2); theBlock.removeChildAt(1); assert(theBlock.numChildren === 2); assert(theBlock.getChildAt(0) === child0); assert(theBlock.getChildAt(1) === child2); theBlock.removeChildAt(1); assert(theBlock.numChildren === 1); assert(theBlock.getChildAt(0) === child0); theBlock.finalize(); info = binaryen.getExpressionInfo(theBlock); assert(info.name === theBlock.name); assertDeepEqual(info.children, theBlock.children); console.log(theBlock.toText()); assert( theBlock.toText() == "(block $theName (result i32)\n (i32.const 0)\n)\n" ); theBlock.removeChildAt(0); assert(theBlock.numChildren === 0); module.dispose(); })(); console.log("# If"); (function testIf() { const module = new binaryen.Module(); var condition = module.i32.const(1); var ifTrue = module.i32.const(2); var ifFalse = module.i32.const(3); const theIf = binaryen.If(module.if(condition, ifTrue, ifFalse)); assert(theIf instanceof binaryen.If); assert(theIf instanceof binaryen.Expression); assert(theIf.id === binaryen.IfId); assert(theIf.condition === condition); assert(theIf.ifTrue === ifTrue); assert(theIf.ifFalse === ifFalse); assert(theIf.type == binaryen.i32); var info = binaryen.getExpressionInfo(theIf); assert(info.id === theIf.id); assert(info.type === theIf.type); assert(info.condition === theIf.condition); assert(info.ifTrue === theIf.ifTrue); assert(info.ifFalse === theIf.ifFalse); theIf.condition = condition = module.i32.const(4); assert(theIf.condition === condition); theIf.ifTrue = ifTrue = module.i32.const(5); assert(theIf.ifTrue === ifTrue); theIf.ifFalse = ifFalse = module.i32.const(6); assert(theIf.ifFalse === ifFalse); theIf.finalize(); info = binaryen.getExpressionInfo(theIf); assert(info.condition === theIf.condition); assert(info.ifTrue === theIf.ifTrue); assert(info.ifFalse === theIf.ifFalse); console.log(theIf.toText()); assert( theIf.toText() == "(if (result i32)\n (i32.const 4)\n (then\n (i32.const 5)\n )\n (else\n (i32.const 6)\n )\n)\n" ); theIf.ifFalse = null; assert(!theIf.ifFalse); info = binaryen.getExpressionInfo(theIf); assert(info.ifFalse === theIf.ifFalse); console.log(theIf.toText()); assert( theIf.toText() == "(if (result i32)\n (i32.const 4)\n (then\n (i32.const 5)\n )\n)\n" ); module.dispose(); })(); console.log("# Loop"); (function testLoop() { const module = new binaryen.Module(); var name = null; var body = module.i32.const(1); const theLoop = binaryen.Loop(module.loop(name, body)); assert(theLoop instanceof binaryen.Loop); assert(theLoop instanceof binaryen.Expression); assert(theLoop.id === binaryen.LoopId); assert(theLoop.name === name); assert(theLoop.body === body); assert(theLoop.type === binaryen.i32); var info = binaryen.getExpressionInfo(theLoop); assert(info.id === theLoop.id); assert(info.type === theLoop.type); assert(info.name === theLoop.name); assert(info.body === theLoop.body); theLoop.name = name = "theName"; assert(theLoop.name === name); theLoop.body = body = module.drop(body); assert(theLoop.body === body); theLoop.finalize(); assert(theLoop.type === binaryen.none); info = binaryen.getExpressionInfo(theLoop); assert(info.type === theLoop.type); assert(info.name === theLoop.name); assert(info.body === theLoop.body); console.log(theLoop.toText()); assert( theLoop.toText() == "(loop $theName\n (drop\n (i32.const 1)\n )\n)\n" ); module.dispose(); })(); console.log("# Break"); (function testBreak() { const module = new binaryen.Module(); var name = "theName"; var condition = module.i32.const(1); var value = module.i32.const(2); const theBreak = binaryen.Break(module.br(name, condition, value)); assert(theBreak instanceof binaryen.Break); assert(theBreak instanceof binaryen.Expression); assert(theBreak.name === name); assert(theBreak.condition === condition); assert(theBreak.value === value); assert(theBreak.type === binaryen.i32); var info = binaryen.getExpressionInfo(theBreak); assert(info.id === theBreak.id); assert(info.type === theBreak.type); assert(info.name === theBreak.name); assert(info.condition === theBreak.condition); assert(info.value === theBreak.value); theBreak.name = name = "theNewName"; assert(theBreak.name === "theNewName"); theBreak.condition = condition = module.i32.const(3); assert(theBreak.condition === condition); theBreak.value = value = module.i32.const(4); assert(theBreak.value === value); theBreak.finalize(); info = binaryen.getExpressionInfo(theBreak); assert(info.name === theBreak.name); assert(info.condition === theBreak.condition); assert(info.value === theBreak.value); console.log(theBreak.toText()); assert( theBreak.toText() == "(br_if $theNewName\n (i32.const 4)\n (i32.const 3)\n)\n" ); module.dispose(); })(); console.log("# Switch"); (function testSwitch() { const module = new binaryen.Module(); var names = ["a", "b"]; var defaultName = "c"; var condition = module.i32.const(1); var value = module.i32.const(2); const theSwitch = binaryen.Switch(module.switch(names, defaultName, condition, value)); assert(theSwitch instanceof binaryen.Switch); assert(theSwitch instanceof binaryen.Expression); assert(theSwitch.numNames === 2); assertDeepEqual(theSwitch.names, names); assert(theSwitch.defaultName === defaultName); assert(theSwitch.condition === condition); assert(theSwitch.value === value); assert(theSwitch.type === binaryen.unreachable); var info = binaryen.getExpressionInfo(theSwitch); assert(info.id === theSwitch.id); assert(info.type === theSwitch.type); assertDeepEqual(info.names, theSwitch.names); assert(info.defaultName === theSwitch.defaultName); assert(info.condition === theSwitch.condition); assert(info.value === theSwitch.value); names = [ "1", // set "2", //set "3" // append ] theSwitch.setNames(names); assertDeepEqual(theSwitch.names, names); theSwitch.names = names = [ "x", // set // remove // remove ]; assertDeepEqual(theSwitch.names, names); assertDeepEqual(theSwitch.getNames(), names); theSwitch.insertNameAt(1, "y"); theSwitch.condition = condition = module.i32.const(3); assert(theSwitch.condition === condition); theSwitch.value = value = module.i32.const(4); assert(theSwitch.value === value); theSwitch.finalize(); info = binaryen.getExpressionInfo(theSwitch); assertDeepEqual(info.names, theSwitch.names); assert(info.defaultName === theSwitch.defaultName); assert(info.condition === theSwitch.condition); assert(info.value === theSwitch.value); console.log(theSwitch.toText()); assert( theSwitch.toText() == "(br_table $x $y $c\n (i32.const 4)\n (i32.const 3)\n)\n" ); module.dispose(); })(); console.log("# Call"); (function testCall() { const module = new binaryen.Module(); var target = "foo"; var operands = [ module.i32.const(1), module.i32.const(2) ]; const theCall = binaryen.Call(module.call(target, operands, binaryen.i32)); assert(theCall instanceof binaryen.Call); assert(theCall instanceof binaryen.Expression); assert(theCall.target === target); assertDeepEqual(theCall.operands, operands); assertDeepEqual(theCall.getOperands(), operands); assert(theCall.return === false); assert(theCall.type === binaryen.i32); var info = binaryen.getExpressionInfo(theCall); assert(info.id === theCall.id); assert(info.type === theCall.type); assert(info.target === theCall.target); assertDeepEqual(info.operands, theCall.operands); assert(info.isReturn === theCall.return); theCall.target = "bar"; assert(theCall.target === "bar"); theCall.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; assertDeepEqual(theCall.operands, operands); operands = [ module.i32.const(6) // set // remove // remove ]; theCall.setOperands(operands); assertDeepEqual(theCall.operands, operands); theCall.insertOperandAt(0, module.i32.const(7)); theCall.return = true; assert(theCall.return === true); theCall.finalize(); assert(theCall.type === binaryen.unreachable); // finalized tail call info = binaryen.getExpressionInfo(theCall); assert(info.type === theCall.type); assert(info.target === theCall.target); assertDeepEqual(info.operands, theCall.operands); assert(info.isReturn === theCall.return); theCall.return = false; theCall.type = binaryen.i32; theCall.finalize(); assert(theCall.type === binaryen.i32); // finalized call info = binaryen.getExpressionInfo(theCall); assert(info.type === theCall.type); assert(info.isReturn === theCall.return); console.log(theCall.toText()); assert( theCall.toText() == "(call $bar\n (i32.const 7)\n (i32.const 6)\n)\n" ); module.dispose(); })(); console.log("# CallIndirect"); (function testCallIndirect() { const module = new binaryen.Module(); var table = "0"; var target = module.i32.const(42); var params = binaryen.none; var results = binaryen.none; var operands = [ module.i32.const(1), module.i32.const(2) ]; const theCallIndirect = binaryen.CallIndirect(module.call_indirect(table, target, operands, params, results)); assert(theCallIndirect instanceof binaryen.CallIndirect); assert(theCallIndirect instanceof binaryen.Expression); assert(theCallIndirect.table === table); assert(theCallIndirect.target === target); assertDeepEqual(theCallIndirect.operands, operands); assert(theCallIndirect.params === params); assert(theCallIndirect.results === results); assert(theCallIndirect.return === false); assert(theCallIndirect.type === theCallIndirect.results); var info = binaryen.getExpressionInfo(theCallIndirect); assert(info.id === theCallIndirect.id); assert(info.type === theCallIndirect.type); assert(info.table === theCallIndirect.table); assert(info.target === theCallIndirect.target); assertDeepEqual(info.operands, theCallIndirect.operands); assert(info.params === theCallIndirect.params); assert(info.results === theCallIndirect.results); assert(info.isReturn === theCallIndirect.return); theCallIndirect.target = target = module.i32.const(9000); assert(theCallIndirect.target === target); theCallIndirect.operands = operands = [ module.i32.const(3), // set module.i32.const(4), // set module.i32.const(5) // append ]; assertDeepEqual(theCallIndirect.operands, operands); operands = [ module.i32.const(6) // set // remove // remove ]; theCallIndirect.setOperands(operands); assertDeepEqual(theCallIndirect.operands, operands); assertDeepEqual(theCallIndirect.getOperands(), operands); theCallIndirect.insertOperandAt(0, module.i32.const(7)); theCallIndirect.return = true; assert(theCallIndirect.return === true); theCallIndirect.params = params = binaryen.createType([ binaryen.i32, binaryen.i32 ]); assert(theCallIndirect.params === params); theCallIndirect.results = results = binaryen.i32; assert(theCallIndirect.results === results); theCallIndirect.finalize(); assert(theCallIndirect.type === binaryen.unreachable); // finalized tail call info = binaryen.getExpressionInfo(theCallIndirect); assert(info.type === theCallIndirect.type); assert(info.target === theCallIndirect.target); assertDeepEqual(info.operands, theCallIndirect.operands); assert(info.params === theCallIndirect.params); assert(info.results === theCallIndirect.results); assert(info.isReturn === theCallIndirect.return); theCallIndirect.return = false; theCallIndirect.finalize(); assert(theCallIndirect.type === results); // finalized call info = binaryen.getExpressionInfo(theCallIndirect); assert(info.isReturn === theCallIndirect.return); console.log(theCallIndirect.toText()); assert( theCallIndirect.toText() == "(call_indirect $0 (type $func.0)\n (i32.const 7)\n (i32.const 6)\n (i32.const 9000)\n)\n" ); module.dispose(); })(); console.log("# LocalGet"); (function testLocalGet() { const module = new binaryen.Module(); var index = 1; var type = binaryen.i32; const theLocalGet = binaryen.LocalGet(module.local.get(index, type)); assert(theLocalGet instanceof binaryen.LocalGet); assert(theLocalGet instanceof binaryen.Expression); assert(theLocalGet.index === index); assert(theLocalGet.type === type); var info = binaryen.getExpressionInfo(theLocalGet); assert(info.id === theLocalGet.id); assert(info.type === theLocalGet.type); assert(info.index === theLocalGet.index); theLocalGet.index = index = 2; assert(theLocalGet.index === index); theLocalGet.type = type = binaryen.f64; assert(theLocalGet.type === type); theLocalGet.finalize(); info = binaryen.getExpressionInfo(theLocalGet); assert(info.type === theLocalGet.type); assert(info.index === theLocalGet.index); console.log(theLocalGet.toText()); assert( theLocalGet.toText() == "(local.get $2)\n" ); module.dispose(); })(); console.log("# LocalSet"); (function testLocalSet() { const module = new binaryen.Module(); var index = 1; var value = module.i32.const(1); const theLocalSet = binaryen.LocalSet(module.local.set(index, value)); assert(theLocalSet instanceof binaryen.LocalSet); assert(theLocalSet instanceof binaryen.Expression); assert(theLocalSet.index === index); assert(theLocalSet.value === value); assert(theLocalSet.tee === false); assert(theLocalSet.type == binaryen.none); var info = binaryen.getExpressionInfo(theLocalSet); assert(info.id === theLocalSet.id); assert(info.type === theLocalSet.type); assert(info.index === theLocalSet.index); assert(info.value === theLocalSet.value); assert(info.isTee === theLocalSet.tee) theLocalSet.index = index = 2; assert(theLocalSet.index === index); theLocalSet.value = value = module.i32.const(3); assert(theLocalSet.value === value); theLocalSet.type = binaryen.i32; assert(theLocalSet.type === binaryen.i32); assert(theLocalSet.tee === true); theLocalSet.type = binaryen.none; theLocalSet.finalize(); info = binaryen.getExpressionInfo(theLocalSet); assert(info.type === theLocalSet.type); assert(info.index === theLocalSet.index); assert(info.value === theLocalSet.value); assert(info.isTee === theLocalSet.tee) console.log(theLocalSet.toText()); assert( theLocalSet.toText() == "(local.set $2\n (i32.const 3)\n)\n" ); module.dispose(); })(); console.log("# GlobalGet"); (function testGlobalGet() { const module = new binaryen.Module(); var name = "a"; var type = binaryen.i32; const theGlobalGet = binaryen.GlobalGet(module.global.get(name, type)); assert(theGlobalGet instanceof binaryen.GlobalGet); assert(theGlobalGet instanceof binaryen.Expression); assert(theGlobalGet.name === name); assert(theGlobalGet.type === type); var info = binaryen.getExpressionInfo(theGlobalGet); assert(info.id === theGlobalGet.id); assert(info.type === theGlobalGet.type); assert(info.name === theGlobalGet.name); theGlobalGet.name = name = "b"; assert(theGlobalGet.name === name); theGlobalGet.type = type = binaryen.f64; assert(theGlobalGet.type === type); theGlobalGet.finalize(); info = binaryen.getExpressionInfo(theGlobalGet); assert(info.type === theGlobalGet.type); assert(info.name === theGlobalGet.name); console.log(theGlobalGet.toText()); assert( theGlobalGet.toText() == "(global.get $b)\n" ); module.dispose(); })(); console.log("# GlobalSet"); (function testGlobalSet() { const module = new binaryen.Module(); var name = "a"; var value = module.i32.const(1); const theGlobalSet = binaryen.GlobalSet(module.global.set(name, value)); assert(theGlobalSet instanceof binaryen.GlobalSet); assert(theGlobalSet instanceof binaryen.Expression); assert(theGlobalSet.name === name); assert(theGlobalSet.value === value); assert(theGlobalSet.type == binaryen.none); var info = binaryen.getExpressionInfo(theGlobalSet); assert(info.id === theGlobalSet.id); assert(info.type === theGlobalSet.type); assert(info.name === theGlobalSet.name); assert(info.value === theGlobalSet.value); theGlobalSet.name = name = "b"; assert(theGlobalSet.name === name); theGlobalSet.value = value = module.f64.const(3); assert(theGlobalSet.value === value); theGlobalSet.finalize(); info = binaryen.getExpressionInfo(theGlobalSet); assert(info.name === theGlobalSet.name); assert(info.value === theGlobalSet.value); console.log(theGlobalSet.toText()); assert( theGlobalSet.toText() == "(global.set $b\n (f64.const 3)\n)\n" ); module.dispose(); })(); console.log("# MemorySize"); (function testMemorySize() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var type = binaryen.i32; const theMemorySize = binaryen.MemorySize(module.memory.size()); assert(theMemorySize instanceof binaryen.MemorySize); assert(theMemorySize instanceof binaryen.Expression); assert(theMemorySize.type === type); theMemorySize.finalize(); var info = binaryen.getExpressionInfo(theMemorySize); assert(info.id === theMemorySize.id); assert(info.type === theMemorySize.type); console.log(theMemorySize.toText()); assert( theMemorySize.toText() == "(memory.size $0)\n" ); module.dispose(); })(); console.log("# MemoryGrow"); (function testMemoryGrow() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var type = binaryen.i32; var delta = module.i32.const(1); const theMemoryGrow = binaryen.MemoryGrow(module.memory.grow(delta)); assert(theMemoryGrow instanceof binaryen.MemoryGrow); assert(theMemoryGrow instanceof binaryen.Expression); assert(theMemoryGrow.delta === delta); assert(theMemoryGrow.type === type); var info = binaryen.getExpressionInfo(theMemoryGrow); assert(info.id === theMemoryGrow.id); assert(info.type === theMemoryGrow.type); assert(info.delta === theMemoryGrow.delta); theMemoryGrow.delta = delta = module.i32.const(2); assert(theMemoryGrow.delta === delta); theMemoryGrow.finalize(); info = binaryen.getExpressionInfo(theMemoryGrow); assert(info.delta === theMemoryGrow.delta); console.log(theMemoryGrow.toText()); assert( theMemoryGrow.toText() == "(memory.grow $0\n (i32.const 2)\n)\n" ); module.dispose(); })(); console.log("# Load"); (function testLoad() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var offset = 16; var align = 2; var ptr = module.i32.const(64); const theLoad = binaryen.Load(module.i32.load(offset, align, ptr)); assert(theLoad instanceof binaryen.Load); assert(theLoad instanceof binaryen.Expression); assert(theLoad.offset === offset); assert(theLoad.align === align); assert(theLoad.ptr === ptr); assert(theLoad.bytes === 4); assert(theLoad.signed === true); assert(theLoad.atomic === false); assert(theLoad.type == binaryen.i32); var info = binaryen.getExpressionInfo(theLoad); assert(info.id === theLoad.id); assert(info.type === theLoad.type); assert(info.offset === theLoad.offset); assert(info.align === theLoad.align); assert(info.ptr === theLoad.ptr); assert(info.bytes === theLoad.bytes); assert(info.isSigned === theLoad.signed); assert(info.isAtomic === theLoad.atomic); theLoad.offset = offset = 32; assert(theLoad.offset === offset); theLoad.align = align = 4; assert(theLoad.align === align); theLoad.ptr = ptr = module.i32.const(128); assert(theLoad.ptr === ptr); theLoad.type = binaryen.i64; assert(theLoad.type === binaryen.i64); theLoad.signed = false; assert(theLoad.signed === false); theLoad.bytes = 8; assert(theLoad.bytes === 8); theLoad.memoryOrder = binaryen.MemoryOrder.seqcst; assert(theLoad.atomic === true); theLoad.finalize(); assert(theLoad.align === 4); info = binaryen.getExpressionInfo(theLoad); assert(info.offset === theLoad.offset); assert(info.align === theLoad.align); assert(info.ptr === theLoad.ptr); assert(info.bytes === theLoad.bytes); assert(info.isSigned === theLoad.signed); assert(info.isAtomic === theLoad.atomic); console.log(theLoad.toText()); assert( theLoad.toText() == "(i64.atomic.load $0 offset=32 align=4\n (i32.const 128)\n)\n" ); module.dispose(); })(); console.log("# Store"); (function testStore() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var offset = 16; var align = 2; var ptr = module.i32.const(64); var value = module.i32.const(1); const theStore = binaryen.Store(module.i32.store(offset, align, ptr, value)); assert(theStore instanceof binaryen.Store); assert(theStore instanceof binaryen.Expression); assert(theStore.offset === offset); assert(theStore.align === align); assert(theStore.ptr === ptr); assert(theStore.value === value); assert(theStore.bytes === 4); assert(theStore.atomic === false); assert(theStore.valueType === binaryen.i32); assert(theStore.type === binaryen.none); var info = binaryen.getExpressionInfo(theStore); assert(info.id === theStore.id); assert(info.type === theStore.type); assert(info.offset === theStore.offset); assert(info.align === theStore.align); assert(info.ptr === theStore.ptr); assert(info.value === theStore.value); assert(info.bytes === theStore.bytes); assert(info.isAtomic === theStore.atomic); assert(info.valueType === theStore.valueType); theStore.offset = offset = 32; assert(theStore.offset === offset); theStore.align = align = 4; assert(theStore.align === align); theStore.ptr = ptr = module.i32.const(128); assert(theStore.ptr === ptr); theStore.value = value = module.i32.const(2); assert(theStore.value === value); theStore.signed = false; assert(theStore.signed === false); theStore.valueType = binaryen.i64; assert(theStore.valueType === binaryen.i64); theStore.bytes = 8; assert(theStore.bytes === 8); theStore.memoryOrder = binaryen.MemoryOrder.seqcst; assert(theStore.atomic === true); theStore.finalize(); assert(theStore.align === 4); info = binaryen.getExpressionInfo(theStore); assert(info.offset === theStore.offset); assert(info.align === theStore.align); assert(info.ptr === theStore.ptr); assert(info.value === theStore.value); assert(info.bytes === theStore.bytes); assert(info.isAtomic === theStore.atomic); assert(info.valueType === theStore.valueType); console.log(theStore.toText()); assert( theStore.toText() == "(i64.atomic.store $0 offset=32 align=4\n (i32.const 128)\n (i32.const 2)\n)\n" ); module.dispose(); })(); console.log("# Const"); (function testConst() { const module = new binaryen.Module(); const theConst = binaryen.Const(module.i32.const(1)); assert(theConst instanceof binaryen.Const); assert(theConst instanceof binaryen.Expression); assert(theConst.valueI32 === 1); theConst.valueI32 = 2; assert(theConst.valueI32 === 2); assert(theConst.type === binaryen.i32); var info = binaryen.getExpressionInfo(theConst); assert(info.id === theConst.id); assert(info.type === theConst.type); assert(info.value === theConst.valueI32); theConst.valueI64 = 3; assert(theConst.valueI64 === 3n); theConst.finalize(); assert(theConst.type == binaryen.i64); info = binaryen.getExpressionInfo(theConst); assert(info.type === theConst.type); assert(info.value === theConst.valueI64); theConst.valueF32 = 5; assert(theConst.valueF32 === 5); theConst.finalize(); assert(theConst.type === binaryen.f32); info = binaryen.getExpressionInfo(theConst); assert(info.type === theConst.type); assert(info.value === theConst.valueF32); theConst.valueF64 = 6; assert(theConst.valueF64 === 6); theConst.finalize(); assert(theConst.type === binaryen.f64); info = binaryen.getExpressionInfo(theConst); assert(info.type === theConst.type); assert(info.value === theConst.valueF64); theConst.valueV128 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; assertDeepEqual(theConst.valueV128, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); theConst.finalize(); assert(theConst.type === binaryen.v128); info = binaryen.getExpressionInfo(theConst); assert(info.type === theConst.type); assertDeepEqual(info.value, theConst.valueV128); console.log(theConst.toText()); assert( theConst.toText() == "(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)\n" ); module.dispose(); })(); console.log("# Unary"); (function testUnary() { const module = new binaryen.Module(); var op = binaryen.Operations.EqZInt32; var value = module.i32.const(1); const theUnary = binaryen.Unary(module.i32.eqz(value)); assert(theUnary instanceof binaryen.Unary); assert(theUnary instanceof binaryen.Expression); assert(theUnary.op === op); assert(theUnary.value === value); assert(theUnary.type === binaryen.i32); var info = binaryen.getExpressionInfo(theUnary); assert(info.id === theUnary.id); assert(info.type === theUnary.type); assert(info.op === theUnary.op); assert(info.value === theUnary.value); theUnary.op = op = binaryen.Operations.EqZInt64; assert(theUnary.op === op); theUnary.value = value = module.i64.const(2); assert(theUnary.value === value); theUnary.type = binaryen.f32; theUnary.finalize(); assert(theUnary.type === binaryen.i32); info = binaryen.getExpressionInfo(theUnary); assert(info.type === theUnary.type); assert(info.op === theUnary.op); assert(info.value === theUnary.value); console.log(theUnary.toText()); assert( theUnary.toText() == "(i64.eqz\n (i64.const 2)\n)\n" ); module.dispose(); })(); console.log("# Binary"); (function testBinary() { const module = new binaryen.Module(); var op = binaryen.Operations.AddInt32; var left = module.i32.const(1); var right = module.i32.const(2); const theBinary = binaryen.Binary(module.i32.add(left, right)); assert(theBinary instanceof binaryen.Binary); assert(theBinary instanceof binaryen.Expression); assert(theBinary.op === op); assert(theBinary.left === left); assert(theBinary.right === right); assert(theBinary.type === binaryen.i32) var info = binaryen.getExpressionInfo(theBinary); assert(info.id === theBinary.id); assert(info.type === theBinary.type); assert(info.op === theBinary.op); assert(info.left === theBinary.left); assert(info.right === theBinary.right); theBinary.op = op = binaryen.Operations.AddInt64; assert(theBinary.op === op); theBinary.left = left = module.i64.const(3); assert(theBinary.left === left); theBinary.right = right = module.i64.const(4); assert(theBinary.right === right); theBinary.type = binaryen.f32; theBinary.finalize(); assert(theBinary.type === binaryen.i64); info = binaryen.getExpressionInfo(theBinary); assert(info.type === theBinary.type); assert(info.op === theBinary.op); assert(info.left === theBinary.left); assert(info.right === theBinary.right); console.log(theBinary.toText()); assert( theBinary.toText() == "(i64.add\n (i64.const 3)\n (i64.const 4)\n)\n" ); module.dispose(); })(); console.log("# Select"); (function testSelect() { const module = new binaryen.Module(); var condition = module.i32.const(1); var ifTrue = module.i32.const(2); var ifFalse = module.i32.const(3); const theSelect = binaryen.Select(module.select(condition, ifTrue, ifFalse)); assert(theSelect.ifTrue === ifTrue); assert(theSelect instanceof binaryen.Select); assert(theSelect instanceof binaryen.Expression); assert(theSelect.condition === condition); assert(theSelect.ifTrue === ifTrue); assert(theSelect.ifFalse === ifFalse); assert(theSelect.type === binaryen.i32); var info = binaryen.getExpressionInfo(theSelect); assert(info.id === theSelect.id); assert(info.type === theSelect.type); assert(info.condition === theSelect.condition); assert(info.ifTrue === theSelect.ifTrue); assert(info.ifFalse === theSelect.ifFalse); theSelect.condition = condition = module.i32.const(4); assert(theSelect.condition === condition); theSelect.ifTrue = ifTrue = module.i64.const(5); assert(theSelect.ifTrue === ifTrue); theSelect.ifFalse = ifFalse = module.i64.const(6); assert(theSelect.ifFalse === ifFalse); theSelect.finalize(); assert(theSelect.type === binaryen.i64); info = binaryen.getExpressionInfo(theSelect); assert(info.type === theSelect.type); assert(info.condition === theSelect.condition); assert(info.ifTrue === theSelect.ifTrue); assert(info.ifFalse === theSelect.ifFalse); console.log(theSelect.toText()); assert( theSelect.toText() == "(select\n (i64.const 5)\n (i64.const 6)\n (i32.const 4)\n)\n" ); module.dispose(); })(); console.log("# Drop"); (function testDrop() { const module = new binaryen.Module(); var value = module.i32.const(1); const theDrop = binaryen.Drop(module.drop(value)); assert(theDrop instanceof binaryen.Drop); assert(theDrop instanceof binaryen.Expression); assert(theDrop.value === value); assert(theDrop.type === binaryen.none); var info = binaryen.getExpressionInfo(theDrop); assert(info.id === theDrop.id); assert(info.type === theDrop.type); assert(info.value === theDrop.value); theDrop.value = value = module.i32.const(2); assert(theDrop.value === value); theDrop.finalize(); assert(theDrop.type === binaryen.none); info = binaryen.getExpressionInfo(theDrop); assert(info.type === theDrop.type); assert(info.value === theDrop.value); console.log(theDrop.toText()); assert( theDrop.toText() == "(drop\n (i32.const 2)\n)\n" ); module.dispose(); })(); console.log("# Return"); (function testReturn() { const module = new binaryen.Module(); var value = module.i32.const(1); const theReturn = binaryen.Return(module.return(value)); assert(theReturn instanceof binaryen.Return); assert(theReturn instanceof binaryen.Expression); assert(theReturn.value === value); assert(theReturn.type === binaryen.unreachable); var info = binaryen.getExpressionInfo(theReturn); assert(info.id === theReturn.id); assert(info.type === theReturn.type); assert(info.value === theReturn.value); theReturn.value = value = module.i32.const(2); assert(theReturn.value === value); theReturn.finalize(); assert(theReturn.type === binaryen.unreachable); info = binaryen.getExpressionInfo(theReturn); assert(info.type === theReturn.type); assert(info.value === theReturn.value); console.log(theReturn.toText()); assert( theReturn.toText() == "(return\n (i32.const 2)\n)\n" ); module.dispose(); })(); console.log("# AtomicRMW"); (function testAtomicRMW() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var op = binaryen.Operations.AtomicRMWAdd; var offset = 8; var ptr = module.i32.const(2); var value = module.i32.const(3); const theAtomicRMW = binaryen.AtomicRMW(module.i32.atomic.rmw.add(offset, ptr, value)); assert(theAtomicRMW instanceof binaryen.AtomicRMW); assert(theAtomicRMW instanceof binaryen.Expression); assert(theAtomicRMW.op === op); assert(theAtomicRMW.bytes === 4); assert(theAtomicRMW.offset === offset); assert(theAtomicRMW.ptr === ptr); assert(theAtomicRMW.value === value); assert(theAtomicRMW.type === binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicRMW); assert(info.id === theAtomicRMW.id); assert(info.type === theAtomicRMW.type); assert(info.op === theAtomicRMW.op); assert(info.bytes === theAtomicRMW.bytes); assert(info.offset === theAtomicRMW.offset); assert(info.ptr === theAtomicRMW.ptr); assert(info.value === theAtomicRMW.value); theAtomicRMW.op = op = binaryen.Operations.AtomicRMWSub; assert(theAtomicRMW.op === op); theAtomicRMW.bytes = 2; assert(theAtomicRMW.bytes === 2); theAtomicRMW.offset = offset = 16; assert(theAtomicRMW.offset === offset); theAtomicRMW.ptr = ptr = module.i32.const(4); assert(theAtomicRMW.ptr === ptr); theAtomicRMW.value = value = module.i64.const(5); assert(theAtomicRMW.value === value); theAtomicRMW.type = binaryen.i64; theAtomicRMW.finalize(); assert(theAtomicRMW.type === binaryen.i64); info = binaryen.getExpressionInfo(theAtomicRMW); assert(info.type === theAtomicRMW.type); assert(info.op === theAtomicRMW.op); assert(info.bytes === theAtomicRMW.bytes); assert(info.offset === theAtomicRMW.offset); assert(info.ptr === theAtomicRMW.ptr); assert(info.value === theAtomicRMW.value); console.log(theAtomicRMW.toText()); assert( theAtomicRMW.toText() == "(i64.atomic.rmw16.sub_u $0 offset=16\n (i32.const 4)\n (i64.const 5)\n)\n" ); module.dispose(); })(); console.log("# AtomicCmpxchg"); (function testAtomicCmpxchg() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var offset = 8; var ptr = module.i32.const(2); var expected = module.i32.const(3); var replacement = module.i32.const(4); const theAtomicCmpxchg = binaryen.AtomicCmpxchg(module.i32.atomic.rmw.cmpxchg(offset, ptr, expected, replacement)); assert(theAtomicCmpxchg instanceof binaryen.AtomicCmpxchg); assert(theAtomicCmpxchg instanceof binaryen.Expression); assert(theAtomicCmpxchg.bytes === 4); assert(theAtomicCmpxchg.offset === offset); assert(theAtomicCmpxchg.ptr === ptr); assert(theAtomicCmpxchg.expected === expected); assert(theAtomicCmpxchg.replacement === replacement); assert(theAtomicCmpxchg.type === binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicCmpxchg); assert(info.id === theAtomicCmpxchg.id); assert(info.type === theAtomicCmpxchg.type); assert(info.bytes === theAtomicCmpxchg.bytes); assert(info.offset === theAtomicCmpxchg.offset); assert(info.ptr === theAtomicCmpxchg.ptr); assert(info.expected === theAtomicCmpxchg.expected); assert(info.replacement === theAtomicCmpxchg.replacement); theAtomicCmpxchg.bytes = 2; assert(theAtomicCmpxchg.bytes === 2); theAtomicCmpxchg.offset = offset = 16; assert(theAtomicCmpxchg.offset === offset); theAtomicCmpxchg.ptr = ptr = module.i32.const(5); assert(theAtomicCmpxchg.ptr === ptr); theAtomicCmpxchg.expected = expected = module.i64.const(6); assert(theAtomicCmpxchg.expected === expected); theAtomicCmpxchg.replacement = replacement = module.i64.const(7); assert(theAtomicCmpxchg.replacement === replacement); theAtomicCmpxchg.type = binaryen.i64; theAtomicCmpxchg.finalize(); assert(theAtomicCmpxchg.type === binaryen.i64); info = binaryen.getExpressionInfo(theAtomicCmpxchg); assert(info.type === theAtomicCmpxchg.type); assert(info.bytes === theAtomicCmpxchg.bytes); assert(info.offset === theAtomicCmpxchg.offset); assert(info.ptr === theAtomicCmpxchg.ptr); assert(info.expected === theAtomicCmpxchg.expected); assert(info.replacement === theAtomicCmpxchg.replacement); console.log(theAtomicCmpxchg.toText()); assert( theAtomicCmpxchg.toText() == "(i64.atomic.rmw16.cmpxchg_u $0 offset=16\n (i32.const 5)\n (i64.const 6)\n (i64.const 7)\n)\n" ); module.dispose(); })(); console.log("# AtomicWait"); (function testAtomicWait() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var ptr = module.i32.const(2); var expected = module.i32.const(3); var timeout = module.i64.const(4); const theAtomicWait = binaryen.AtomicWait(module.memory.atomic.wait32(ptr, expected, timeout)); assert(theAtomicWait instanceof binaryen.AtomicWait); assert(theAtomicWait instanceof binaryen.Expression); assert(theAtomicWait.ptr === ptr); assert(theAtomicWait.expected === expected); assert(theAtomicWait.expectedType === binaryen.i32); assert(theAtomicWait.timeout === timeout); assert(theAtomicWait.type === binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicWait); assert(info.id === theAtomicWait.id); assert(info.type === theAtomicWait.type); assert(info.ptr === theAtomicWait.ptr); assert(info.expected === theAtomicWait.expected); assert(info.expectedType === theAtomicWait.expectedType); assert(info.timeout === theAtomicWait.timeout); theAtomicWait.ptr = ptr = module.i32.const(5); assert(theAtomicWait.ptr === ptr); theAtomicWait.expected = expected = module.i32.const(6); assert(theAtomicWait.expected === expected); theAtomicWait.expectedType = binaryen.i64; assert(theAtomicWait.expectedType === binaryen.i64); theAtomicWait.timeout = timeout = module.i64.const(7); assert(theAtomicWait.timeout === timeout); theAtomicWait.type = binaryen.f64; theAtomicWait.finalize(); assert(theAtomicWait.type === binaryen.i32); info = binaryen.getExpressionInfo(theAtomicWait); assert(info.type === theAtomicWait.type); assert(info.ptr === theAtomicWait.ptr); assert(info.expected === theAtomicWait.expected); assert(info.expectedType === theAtomicWait.expectedType); assert(info.timeout === theAtomicWait.timeout); console.log(theAtomicWait.toText()); assert( theAtomicWait.toText() == "(memory.atomic.wait64 $0\n (i32.const 5)\n (i32.const 6)\n (i64.const 7)\n)\n" ); module.dispose(); })(); console.log("# AtomicNotify"); (function testAtomicNotify() { const module = new binaryen.Module(); module.setMemory(1, 1, null); var ptr = module.i32.const(1); var notifyCount = module.i32.const(2); const theAtomicNotify = binaryen.AtomicNotify(module.memory.atomic.notify(ptr, notifyCount)); assert(theAtomicNotify instanceof binaryen.AtomicNotify); assert(theAtomicNotify instanceof binaryen.Expression); assert(theAtomicNotify.ptr === ptr); assert(theAtomicNotify.notifyCount === notifyCount); assert(theAtomicNotify.type === binaryen.i32); var info = binaryen.getExpressionInfo(theAtomicNotify); assert(info.id === theAtomicNotify.id); assert(info.type === theAtomicNotify.type); assert(info.ptr === theAtomicNotify.ptr); assert(info.notifyCount === theAtomicNotify.notifyCount); theAtomicNotify.ptr = ptr = module.i32.const(3); assert(theAtomicNotify.ptr === ptr); theAtomicNotify.notifyCount = notifyCount = module.i32.const(4); assert(theAtomicNotify.notifyCount === notifyCount); theAtomicNotify.type = binaryen.f64; theAtomicNotify.finalize(); assert(theAtomicNotify.type === binaryen.i32); info = binaryen.getExpressionInfo(theAtomicNotify); assert(info.type === theAtomicNotify.type); assert(info.ptr === theAtomicNotify.ptr); assert(info.notifyCount === theAtomicNotify.notifyCount); console.log(theAtomicNotify.toText()); assert( theAtomicNotify.toText() == "(memory.atomic.notify $0\n (i32.const 3)\n (i32.const 4)\n)\n" ); module.dispose(); })(); console.log("# AtomicFence"); (function testAtomicFence() { const module = new binaryen.Module(); const theAtomicFence = binaryen.AtomicFence(module.atomic.fence()); assert(theAtomicFence instanceof binaryen.AtomicFence); assert(theAtomicFence instanceof binaryen.Expression); assert(theAtomicFence.order === 0); // reserved, not yet used assert(theAtomicFence.type === binaryen.none); var info = binaryen.getExpressionInfo(theAtomicFence); assert(info.id === theAtomicFence.id); assert(info.type === theAtomicFence.type); assert(info.order === theAtomicFence.order); theAtomicFence.order = 1; assert(theAtomicFence.order === 1); info = binaryen.getExpressionInfo(theAtomicFence); assert(info.type === theAtomicFence.type); assert(info.order === theAtomicFence.order); console.log(theAtomicFence.toText()); assert( theAtomicFence.toText() == "(atomic.fence)\n" ); module.dispose(); })(); console.log("# SIMDExtract"); (function testSIMDExtract() { const module = new binaryen.Module(); var op = binaryen.Operations.ExtractLaneSVecI8x16; var vec = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var index = 0; const theSIMDExtract = binaryen.SIMDExtract(module.i8x16.extract_lane_s(vec, index)); assert(theSIMDExtract instanceof binaryen.SIMDExtract); assert(theSIMDExtract instanceof binaryen.Expression); assert(theSIMDExtract.op === op); assert(theSIMDExtract.vec === vec); assert(theSIMDExtract.index === index); assert(theSIMDExtract.type === binaryen.i32); var info = binaryen.getExpressionInfo(theSIMDExtract); assert(info.id === theSIMDExtract.id); assert(info.type === theSIMDExtract.type); assert(info.op === theSIMDExtract.op); assert(info.vec === theSIMDExtract.vec); assert(info.index === theSIMDExtract.index); theSIMDExtract.op = op = binaryen.Operations.ExtractLaneSVecI16x8; assert(theSIMDExtract.op === op); theSIMDExtract.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); assert(theSIMDExtract.vec === vec); theSIMDExtract.index = index = 1; assert(theSIMDExtract.index === index); theSIMDExtract.type = binaryen.f64; theSIMDExtract.finalize(); assert(theSIMDExtract.type === binaryen.i32); info = binaryen.getExpressionInfo(theSIMDExtract); assert(info.type === theSIMDExtract.type); assert(info.op === theSIMDExtract.op); assert(info.vec === theSIMDExtract.vec); assert(info.index === theSIMDExtract.index); console.log(theSIMDExtract.toText()); assert( theSIMDExtract.toText() == "(i16x8.extract_lane_s 1\n (v128.const i32x4 0x01010101 0x01010101 0x01010101 0x01010101)\n)\n" ); module.dispose(); })(); console.log("# SIMDReplace"); (function testSIMDReplace() { const module = new binaryen.Module(); var op = binaryen.Operations.ReplaceLaneVecI8x16; var vec = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var index = 0; var value = module.i32.const(1); const theSIMDReplace = binaryen.SIMDReplace(module.i8x16.replace_lane(vec, index, value)); assert(theSIMDReplace instanceof binaryen.SIMDReplace); assert(theSIMDReplace instanceof binaryen.Expression); assert(theSIMDReplace.op === op); assert(theSIMDReplace.vec === vec); assert(theSIMDReplace.index === index); assert(theSIMDReplace.value === value); assert(theSIMDReplace.type === binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDReplace); assert(info.id === theSIMDReplace.id); assert(info.type === theSIMDReplace.type); assert(info.op === theSIMDReplace.op); assert(info.vec === theSIMDReplace.vec); assert(info.index === theSIMDReplace.index); assert(info.value === theSIMDReplace.value); theSIMDReplace.op = op = binaryen.Operations.ReplaceLaneVecI16x8; assert(theSIMDReplace.op === op); theSIMDReplace.vec = vec = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); assert(theSIMDReplace.vec === vec); theSIMDReplace.index = index = 1; assert(theSIMDReplace.index === index); theSIMDReplace.value = value = module.i32.const(2); assert(theSIMDReplace.value === value); theSIMDReplace.type = binaryen.f64; theSIMDReplace.finalize(); assert(theSIMDReplace.type === binaryen.v128); info = binaryen.getExpressionInfo(theSIMDReplace); assert(info.type === theSIMDReplace.type); assert(info.op === theSIMDReplace.op); assert(info.vec === theSIMDReplace.vec); assert(info.index === theSIMDReplace.index); assert(info.value === theSIMDReplace.value); console.log(theSIMDReplace.toText()); assert( theSIMDReplace.toText() == "(i16x8.replace_lane 1\n (v128.const i32x4 0x01010101 0x01010101 0x01010101 0x01010101)\n (i32.const 2)\n)\n" ); module.dispose(); })(); console.log("# SIMDShuffle"); (function testSIMDShuffle() { const module = new binaryen.Module(); var left = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var right = module.v128.const([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]); var mask = [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]; const theSIMDShuffle = binaryen.SIMDShuffle(module.i8x16.shuffle(left, right, mask)); assert(theSIMDShuffle instanceof binaryen.SIMDShuffle); assert(theSIMDShuffle instanceof binaryen.Expression); assert(theSIMDShuffle.left === left); assert(theSIMDShuffle.right === right); assertDeepEqual(theSIMDShuffle.mask, mask); assert(theSIMDShuffle.type === binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDShuffle); assert(info.id === theSIMDShuffle.id); assert(info.type === theSIMDShuffle.type); assert(info.left === theSIMDShuffle.left); assert(info.right === theSIMDShuffle.right); assertDeepEqual(info.mask, theSIMDShuffle.mask); theSIMDShuffle.left = left = module.v128.const([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); assert(theSIMDShuffle.left === left); theSIMDShuffle.right = right = module.v128.const([2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]); assert(theSIMDShuffle.right === right); theSIMDShuffle.mask = mask = [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]; assertDeepEqual(theSIMDShuffle.mask, mask); theSIMDShuffle.type = binaryen.f64; theSIMDShuffle.finalize(); assert(theSIMDShuffle.type === binaryen.v128); info = binaryen.getExpressionInfo(theSIMDShuffle); assert(info.type === theSIMDShuffle.type); assert(info.left === theSIMDShuffle.left); assert(info.right === theSIMDShuffle.right); assertDeepEqual(info.mask, theSIMDShuffle.mask); console.log(theSIMDShuffle.toText()); assert( theSIMDShuffle.toText() == "(i8x16.shuffle 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n (v128.const i32x4 0x01010101 0x01010101 0x01010101 0x01010101)\n (v128.const i32x4 0x02020202 0x02020202 0x02020202 0x02020202)\n)\n" ); module.dispose(); })(); console.log("# SIMDTernary"); (function testSIMDTernary() { const module = new binaryen.Module(); var op = binaryen.Operations.BitselectVec128; var a = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var b = module.v128.const([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]); var c = module.v128.const([3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]); const theSIMDTernary = binaryen.SIMDTernary(module.v128.bitselect(a, b, c)); assert(theSIMDTernary instanceof binaryen.SIMDTernary); assert(theSIMDTernary instanceof binaryen.Expression); assert(theSIMDTernary.op === op); assert(theSIMDTernary.a === a); assert(theSIMDTernary.b === b); assert(theSIMDTernary.c === c); assert(theSIMDTernary.type === binaryen.v128); var info = binaryen.getExpressionInfo(theSIMDTernary); assert(info.id === theSIMDTernary.id); assert(info.type === theSIMDTernary.type); assert(info.op === theSIMDTernary.op); assert(info.a === theSIMDTernary.a); assert(info.b === theSIMDTernary.b); assert(info.c === theSIMDTernary.c); console.log(theSIMDTernary.toText() + "\n"); assert( theSIMDTernary.toText() == "(v128.bitselect\n (v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)\n (v128.const i32x4 0x05040302 0x09080706 0x0d0c0b0a 0x11100f0e)\n (v128.const i32x4 0x06050403 0x0a090807 0x0e0d0c0b 0x1211100f)\n)\n" ); module.dispose(); })(); console.log("# SIMDShift"); (function testSIMDShift() { const module = new binaryen.Module(); var op = binaryen.Operations.BitselectVec128; var vec = module.v128.const([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]); var shift = module.i32.const(1); const theSIMDShift = binaryen.SIM