diff options
-rwxr-xr-x | scripts/gen-s-parser.py | 1 | ||||
-rw-r--r-- | src/gen-s-parser.inc | 18 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 6 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 1 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 82 | ||||
-rw-r--r-- | test/binaryen.js/push-pop.js | 2 | ||||
-rw-r--r-- | test/binaryen.js/push-pop.js.txt | 4 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 7 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 87 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt.txt | 18 |
10 files changed, 168 insertions, 58 deletions
diff --git a/scripts/gen-s-parser.py b/scripts/gen-s-parser.py index 9085633fc..133e70d03 100755 --- a/scripts/gen-s-parser.py +++ b/scripts/gen-s-parser.py @@ -49,6 +49,7 @@ instructions = [ ("f32.pop", "makePop(f32)"), ("f64.pop", "makePop(f64)"), ("v128.pop", "makePop(v128)"), + ("anyref.pop", "makePop(anyref)"), ("exnref.pop", "makePop(exnref)"), ("i32.load", "makeLoad(s, i32, /*isAtomic=*/false)"), ("i64.load", "makeLoad(s, i64, /*isAtomic=*/false)"), diff --git a/src/gen-s-parser.inc b/src/gen-s-parser.inc index 7f1958582..85702d326 100644 --- a/src/gen-s-parser.inc +++ b/src/gen-s-parser.inc @@ -8,13 +8,21 @@ char op[27] = {'\0'}; strncpy(op, s[0]->c_str(), 26); switch (op[0]) { case 'a': { - switch (op[7]) { - case 'f': - if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); } - goto parse_error; + switch (op[1]) { case 'n': - if (strcmp(op, "atomic.notify") == 0) { return makeAtomicNotify(s); } + if (strcmp(op, "anyref.pop") == 0) { return makePop(anyref); } goto parse_error; + case 't': { + switch (op[7]) { + case 'f': + if (strcmp(op, "atomic.fence") == 0) { return makeAtomicFence(s); } + goto parse_error; + case 'n': + if (strcmp(op, "atomic.notify") == 0) { return makeAtomicNotify(s); } + goto parse_error; + default: goto parse_error; + } + } default: goto parse_error; } } diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index b11d2769b..8f49b105c 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -1872,6 +1872,12 @@ function wrapModule(module, self) { }, }; + self['anyref'] = { + 'pop': function() { + return Module['_BinaryenPop'](module, Module['anyref']); + } + }; + self['exnref'] = { 'pop': function() { return Module['_BinaryenPop'](module, Module['exnref']); diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index 9d947988a..1d955eb6f 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -488,6 +488,7 @@ function test_core() { module.push(module.f32.pop()), module.push(module.f64.pop()), module.push(module.v128.pop()), + module.push(module.anyref.pop()), module.push(module.exnref.pop()), // TODO: Host module.nop(), diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index c1b0b3782..1bf0b3b54 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -1659,6 +1659,9 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} (v128.pop) ) (push + (anyref.pop) + ) + (push (exnref.pop) ) (nop) @@ -3262,6 +3265,9 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} (v128.pop) ) (push + (anyref.pop) + ) + (push (exnref.pop) ) (nop) @@ -5336,10 +5342,12 @@ int main() { expressions[758] = BinaryenPush(the_module, expressions[757]); expressions[759] = BinaryenPop(the_module, 5); expressions[760] = BinaryenPush(the_module, expressions[759]); - expressions[761] = BinaryenPop(the_module, 7); + expressions[761] = BinaryenPop(the_module, 6); expressions[762] = BinaryenPush(the_module, expressions[761]); - expressions[763] = BinaryenNop(the_module); - expressions[764] = BinaryenUnreachable(the_module); + expressions[763] = BinaryenPop(the_module, 7); + expressions[764] = BinaryenPush(the_module, expressions[763]); + expressions[765] = BinaryenNop(the_module); + expressions[766] = BinaryenUnreachable(the_module); BinaryenExpressionGetId(expressions[30]); BinaryenExpressionGetType(expressions[30]); BinaryenUnaryGetOp(expressions[30]); @@ -5350,26 +5358,26 @@ getExpressionInfo={"id":15,"type":3,"op":6} (f32.const -33.61199951171875) ) - expressions[765] = BinaryenConst(the_module, BinaryenLiteralInt32(5)); - BinaryenExpressionGetId(expressions[765]); - BinaryenExpressionGetType(expressions[765]); - BinaryenConstGetValueI32(expressions[765]); -getExpressionInfo(i32.const)={"id":14,"type":1,"value":5} - expressions[766] = BinaryenConst(the_module, BinaryenLiteralInt64(30064771078)); - BinaryenExpressionGetId(expressions[766]); - BinaryenExpressionGetType(expressions[766]); - BinaryenConstGetValueI64Low(expressions[766]); - BinaryenConstGetValueI64High(expressions[766]); -getExpressionInfo(i64.const)={"id":14,"type":2,"value":{"low":6,"high":7}} - expressions[767] = BinaryenConst(the_module, BinaryenLiteralFloat32(8.5)); + expressions[767] = BinaryenConst(the_module, BinaryenLiteralInt32(5)); BinaryenExpressionGetId(expressions[767]); BinaryenExpressionGetType(expressions[767]); - BinaryenConstGetValueF32(expressions[767]); -getExpressionInfo(f32.const)={"id":14,"type":3,"value":8.5} - expressions[768] = BinaryenConst(the_module, BinaryenLiteralFloat64(9.5)); + BinaryenConstGetValueI32(expressions[767]); +getExpressionInfo(i32.const)={"id":14,"type":1,"value":5} + expressions[768] = BinaryenConst(the_module, BinaryenLiteralInt64(30064771078)); BinaryenExpressionGetId(expressions[768]); BinaryenExpressionGetType(expressions[768]); - BinaryenConstGetValueF64(expressions[768]); + BinaryenConstGetValueI64Low(expressions[768]); + BinaryenConstGetValueI64High(expressions[768]); +getExpressionInfo(i64.const)={"id":14,"type":2,"value":{"low":6,"high":7}} + expressions[769] = BinaryenConst(the_module, BinaryenLiteralFloat32(8.5)); + BinaryenExpressionGetId(expressions[769]); + BinaryenExpressionGetType(expressions[769]); + BinaryenConstGetValueF32(expressions[769]); +getExpressionInfo(f32.const)={"id":14,"type":3,"value":8.5} + expressions[770] = BinaryenConst(the_module, BinaryenLiteralFloat64(9.5)); + BinaryenExpressionGetId(expressions[770]); + BinaryenExpressionGetType(expressions[770]); + BinaryenConstGetValueF64(expressions[770]); getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} { BinaryenExpressionRef children[] = { expressions[24], expressions[26], expressions[28], expressions[30], expressions[32], @@ -5419,25 +5427,25 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} expressions[705], expressions[707], expressions[709], expressions[710], expressions[711], expressions[712], expressions[714], expressions[719], expressions[725], expressions[736], expressions[740], expressions[745], expressions[749], expressions[750], expressions[752], expressions[754], expressions[756], expressions[758], - expressions[760], expressions[762], expressions[763], expressions[764] }; - expressions[769] = BinaryenBlock(the_module, "the-value", children, 285, 0); + expressions[760], expressions[762], expressions[764], expressions[765], expressions[766] }; + expressions[771] = BinaryenBlock(the_module, "the-value", children, 286, 0); } - expressions[770] = BinaryenDrop(the_module, expressions[769]); + expressions[772] = BinaryenDrop(the_module, expressions[771]); { - BinaryenExpressionRef children[] = { expressions[770] }; - expressions[771] = BinaryenBlock(the_module, "the-nothing", children, 1, 0); + BinaryenExpressionRef children[] = { expressions[772] }; + expressions[773] = BinaryenBlock(the_module, "the-nothing", children, 1, 0); } - expressions[772] = BinaryenConst(the_module, BinaryenLiteralInt32(42)); + expressions[774] = BinaryenConst(the_module, BinaryenLiteralInt32(42)); { - BinaryenExpressionRef children[] = { expressions[771], expressions[772] }; - expressions[773] = BinaryenBlock(the_module, "the-body", children, 2, 0); + BinaryenExpressionRef children[] = { expressions[773], expressions[774] }; + expressions[775] = BinaryenBlock(the_module, "the-body", children, 2, 0); } { BinaryenType varTypes[] = { 1, 7 }; - functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[1], varTypes, 2, expressions[773]); + functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[1], varTypes, 2, expressions[775]); } - expressions[774] = BinaryenConst(the_module, BinaryenLiteralInt32(1)); - globals[0] = BinaryenAddGlobal(the_module, "a-global", 1, 0, expressions[774]); + expressions[776] = BinaryenConst(the_module, BinaryenLiteralInt32(1)); + globals[0] = BinaryenAddGlobal(the_module, "a-global", 1, 0, expressions[776]); { BinaryenType paramTypes[] = { 1, 4 }; functionTypes[2] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2); @@ -5467,13 +5475,13 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} const char* funcNames[] = { "kitchen()sinker" }; BinaryenSetFunctionTable(the_module, 1, 4294967295, funcNames, 1); } - expressions[775] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); + expressions[777] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); { const char segment0[] = { 104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100 }; const char segment1[] = { 73, 32, 97, 109, 32, 112, 97, 115, 115, 105, 118, 101 }; const char* segments[] = { segment0, segment1 }; int8_t segmentPassive[] = { 0, 1 }; - BinaryenExpressionRef segmentOffsets[] = { expressions[775], expressions[0] }; + BinaryenExpressionRef segmentOffsets[] = { expressions[777], expressions[0] }; BinaryenIndex segmentSizes[] = { 12, 12 }; BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 1); } @@ -5481,10 +5489,10 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} BinaryenType paramTypes[] = { 0 }; functionTypes[3] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } - expressions[776] = BinaryenNop(the_module); + expressions[778] = BinaryenNop(the_module); { BinaryenType varTypes[] = { 0 }; - functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[776]); + functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[778]); } BinaryenSetStart(the_module, functions[1]); { @@ -7083,6 +7091,9 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} (v128.pop) ) (push + (anyref.pop) + ) + (push (exnref.pop) ) (nop) @@ -8688,6 +8699,9 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} (v128.pop) ) (push + (anyref.pop) + ) + (push (exnref.pop) ) (nop) diff --git a/test/binaryen.js/push-pop.js b/test/binaryen.js/push-pop.js index b182afbc8..1bc24963e 100644 --- a/test/binaryen.js/push-pop.js +++ b/test/binaryen.js/push-pop.js @@ -27,6 +27,7 @@ var func = module.addFunction("func", v, [], module.push(module.f32.pop()), module.push(module.f64.pop()), module.push(module.v128.pop()), + module.push(module.anyref.pop()), module.push(module.exnref.pop()) ] ) @@ -40,5 +41,6 @@ console.log("getExpressionInfo(i64.pop) = " + stringify(module.i64.pop())); console.log("getExpressionInfo(f32.pop) = " + stringify(module.f32.pop())); console.log("getExpressionInfo(f64.pop) = " + stringify(module.f64.pop())); console.log("getExpressionInfo(v128.pop) = " + stringify(module.v128.pop())); +console.log("getExpressionInfo(anyref.pop) = " + stringify(module.anyref.pop())); console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop())); console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0)))); diff --git a/test/binaryen.js/push-pop.js.txt b/test/binaryen.js/push-pop.js.txt index 2b895ed4f..aafe4f5ec 100644 --- a/test/binaryen.js/push-pop.js.txt +++ b/test/binaryen.js/push-pop.js.txt @@ -17,6 +17,9 @@ (v128.pop) ) (push + (anyref.pop) + ) + (push (exnref.pop) ) ) @@ -27,5 +30,6 @@ getExpressionInfo(i64.pop) = {"id":39,"type":2} getExpressionInfo(f32.pop) = {"id":39,"type":3} getExpressionInfo(f64.pop) = {"id":39,"type":4} getExpressionInfo(v128.pop) = {"id":39,"type":5} +getExpressionInfo(anyref.pop) = {"id":39,"type":6} getExpressionInfo(exnref.pop) = {"id":39,"type":7} getExpressionInfo(push) = {"id":38} diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 742c88b76..ba546e408 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -593,6 +593,13 @@ void test_core() { BinaryenAtomicWait(module, temp6, temp6, temp16, BinaryenTypeInt32())), BinaryenDrop(module, BinaryenAtomicNotify(module, temp6, temp6)), BinaryenAtomicFence(module), + // Push and pop + BinaryenPush(module, BinaryenPop(module, BinaryenTypeInt32())), + BinaryenPush(module, BinaryenPop(module, BinaryenTypeInt64())), + BinaryenPush(module, BinaryenPop(module, BinaryenTypeFloat32())), + BinaryenPush(module, BinaryenPop(module, BinaryenTypeFloat64())), + BinaryenPush(module, BinaryenPop(module, BinaryenTypeAnyref())), + BinaryenPush(module, BinaryenPop(module, BinaryenTypeExnref())), // TODO: Host BinaryenNop(module), diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 72645ea68..f76bb02b9 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -1590,6 +1590,24 @@ BinaryenFeatureAll: 511 ) ) (atomic.fence) + (push + (i32.pop) + ) + (push + (i64.pop) + ) + (push + (f32.pop) + ) + (push + (f64.pop) + ) + (push + (anyref.pop) + ) + (push + (exnref.pop) + ) (nop) (unreachable) ) @@ -3659,8 +3677,20 @@ int main() { expressions[734] = BinaryenAtomicNotify(the_module, expressions[23], expressions[23]); expressions[735] = BinaryenDrop(the_module, expressions[734]); expressions[736] = BinaryenAtomicFence(the_module); - expressions[737] = BinaryenNop(the_module); - expressions[738] = BinaryenUnreachable(the_module); + expressions[737] = BinaryenPop(the_module, 1); + expressions[738] = BinaryenPush(the_module, expressions[737]); + expressions[739] = BinaryenPop(the_module, 2); + expressions[740] = BinaryenPush(the_module, expressions[739]); + expressions[741] = BinaryenPop(the_module, 3); + expressions[742] = BinaryenPush(the_module, expressions[741]); + expressions[743] = BinaryenPop(the_module, 4); + expressions[744] = BinaryenPush(the_module, expressions[743]); + expressions[745] = BinaryenPop(the_module, 6); + expressions[746] = BinaryenPush(the_module, expressions[745]); + expressions[747] = BinaryenPop(the_module, 7); + expressions[748] = BinaryenPush(the_module, expressions[747]); + expressions[749] = BinaryenNop(the_module); + expressions[750] = BinaryenUnreachable(the_module); BinaryenExpressionPrint(expressions[51]); (f32.neg (f32.const -33.61199951171875) @@ -3712,27 +3742,28 @@ int main() { expressions[702], expressions[705], expressions[707], expressions[709], expressions[712], expressions[714], expressions[716], expressions[718], expressions[720], expressions[721], expressions[722], expressions[723], expressions[725], expressions[726], expressions[728], expressions[729], expressions[731], expressions[733], - expressions[735], expressions[736], expressions[737], expressions[738] }; - expressions[739] = BinaryenBlock(the_module, "the-value", children, 279, BinaryenTypeAuto()); + expressions[735], expressions[736], expressions[738], expressions[740], expressions[742], expressions[744], + expressions[746], expressions[748], expressions[749], expressions[750] }; + expressions[751] = BinaryenBlock(the_module, "the-value", children, 285, BinaryenTypeAuto()); } - expressions[740] = BinaryenDrop(the_module, expressions[739]); + expressions[752] = BinaryenDrop(the_module, expressions[751]); { - BinaryenExpressionRef children[] = { expressions[740] }; - expressions[741] = BinaryenBlock(the_module, "the-nothing", children, 1, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = { expressions[752] }; + expressions[753] = BinaryenBlock(the_module, "the-nothing", children, 1, BinaryenTypeAuto()); } - expressions[742] = BinaryenConst(the_module, BinaryenLiteralInt32(42)); + expressions[754] = BinaryenConst(the_module, BinaryenLiteralInt32(42)); { - BinaryenExpressionRef children[] = { expressions[741], expressions[742] }; - expressions[743] = BinaryenBlock(the_module, "the-body", children, 2, BinaryenTypeAuto()); + BinaryenExpressionRef children[] = { expressions[753], expressions[754] }; + expressions[755] = BinaryenBlock(the_module, "the-body", children, 2, BinaryenTypeAuto()); } { BinaryenType varTypes[] = { 1, 7 }; - functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[0], varTypes, 2, expressions[743]); + functions[0] = BinaryenAddFunction(the_module, "kitchen()sinker", functionTypes[0], varTypes, 2, expressions[755]); } - expressions[744] = BinaryenConst(the_module, BinaryenLiteralInt32(7)); - globals[0] = BinaryenAddGlobal(the_module, "a-global", 1, 0, expressions[744]); - expressions[745] = BinaryenConst(the_module, BinaryenLiteralFloat32(7.5)); - globals[1] = BinaryenAddGlobal(the_module, "a-mutable-global", 3, 1, expressions[745]); + expressions[756] = BinaryenConst(the_module, BinaryenLiteralInt32(7)); + globals[0] = BinaryenAddGlobal(the_module, "a-global", 1, 0, expressions[756]); + expressions[757] = BinaryenConst(the_module, BinaryenLiteralFloat32(7.5)); + globals[1] = BinaryenAddGlobal(the_module, "a-mutable-global", 3, 1, expressions[757]); { BinaryenType paramTypes[] = { 1, 4 }; functionTypes[2] = BinaryenAddFunctionType(the_module, "fiF", 3, paramTypes, 2); @@ -3744,13 +3775,13 @@ int main() { const char* funcNames[] = { "kitchen()sinker" }; BinaryenSetFunctionTable(the_module, 1, 1, funcNames, 1); } - expressions[746] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); + expressions[758] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); { const char segment0[] = { 104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100 }; const char segment1[] = { 73, 32, 97, 109, 32, 112, 97, 115, 115, 105, 118, 101 }; const char* segments[] = { segment0, segment1 }; int8_t segmentPassive[] = { 0, 1 }; - BinaryenExpressionRef segmentOffsets[] = { expressions[746], expressions[0] }; + BinaryenExpressionRef segmentOffsets[] = { expressions[758], expressions[0] }; BinaryenIndex segmentSizes[] = { 12, 12 }; BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 1); } @@ -3758,10 +3789,10 @@ int main() { BinaryenType paramTypes[] = { 0 }; functionTypes[3] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } - expressions[747] = BinaryenNop(the_module); + expressions[759] = BinaryenNop(the_module); { BinaryenType varTypes[] = { 0 }; - functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[747]); + functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[759]); } BinaryenSetStart(the_module, functions[1]); { @@ -5341,6 +5372,24 @@ int main() { ) ) (atomic.fence) + (push + (i32.pop) + ) + (push + (i64.pop) + ) + (push + (f32.pop) + ) + (push + (f64.pop) + ) + (push + (anyref.pop) + ) + (push + (exnref.pop) + ) (nop) (unreachable) ) diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index 2f30c22df..7c1959742 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -1569,6 +1569,24 @@ ) ) (atomic.fence) + (push + (i32.pop) + ) + (push + (i64.pop) + ) + (push + (f32.pop) + ) + (push + (f64.pop) + ) + (push + (anyref.pop) + ) + (push + (exnref.pop) + ) (nop) (unreachable) ) |