From 7e3917884152eda021cff9107b5f789aee92fb1b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 12 Aug 2016 11:57:12 -0700 Subject: support expressions in segment offsets --- test/dot_s/alias.wast | 5 ++-- test/dot_s/asm_const.wast | 5 ++-- test/dot_s/basics.wast | 9 +++---- test/dot_s/bcp-1.wast | 17 ++++++------- test/dot_s/data-offset-folding.wast | 7 +++--- test/dot_s/function-data-sections.wast | 9 +++---- test/dot_s/indidx.wast | 5 ++-- test/dot_s/lcomm-in-text-segment.wast | 5 ++-- test/dot_s/macClangMetaData.wast | 5 ++-- test/dot_s/memops.wast | 5 ++-- test/dot_s/permute.wast | 5 ++-- test/dot_s/relocation.wast | 7 +++--- test/dot_s/symbolic-offset.wast | 5 ++-- test/example/c-api-kitchen-sink.c | 2 +- test/example/c-api-kitchen-sink.txt | 17 ++++++------- test/example/c-api-kitchen-sink.txt.txt | 5 ++-- test/kitchen_sink.wast | 5 ++-- test/kitchen_sink.wast.fromBinary | 5 ++-- test/llvm_autogenerated/byval.wast | 5 ++-- test/llvm_autogenerated/call.wast | 5 ++-- test/llvm_autogenerated/cfg-stackify.wast | 5 ++-- test/llvm_autogenerated/comparisons_f32.wast | 5 ++-- test/llvm_autogenerated/comparisons_f64.wast | 5 ++-- test/llvm_autogenerated/comparisons_i32.wast | 5 ++-- test/llvm_autogenerated/comparisons_i64.wast | 5 ++-- test/llvm_autogenerated/conv.wast | 5 ++-- test/llvm_autogenerated/copysign-casts.wast | 5 ++-- test/llvm_autogenerated/cpus.wast | 5 ++-- test/llvm_autogenerated/dead-vreg.wast | 5 ++-- test/llvm_autogenerated/divrem-constant.wast | 5 ++-- test/llvm_autogenerated/f32.wast | 5 ++-- test/llvm_autogenerated/f64.wast | 5 ++-- test/llvm_autogenerated/fast-isel.wast | 5 ++-- test/llvm_autogenerated/frem.wast | 5 ++-- test/llvm_autogenerated/func.wast | 5 ++-- test/llvm_autogenerated/global.wast | 29 +++++++++++----------- test/llvm_autogenerated/globl.wast | 5 ++-- test/llvm_autogenerated/i128.wast | 5 ++-- .../i32-load-store-alignment.wast | 5 ++-- test/llvm_autogenerated/i32.wast | 5 ++-- .../i64-load-store-alignment.wast | 5 ++-- test/llvm_autogenerated/i64.wast | 5 ++-- test/llvm_autogenerated/ident.wast | 5 ++-- test/llvm_autogenerated/immediates.wast | 5 ++-- test/llvm_autogenerated/irreducible-cfg.wast | 5 ++-- test/llvm_autogenerated/legalize.wast | 5 ++-- test/llvm_autogenerated/load-ext.wast | 5 ++-- test/llvm_autogenerated/load-store-i1.wast | 5 ++-- test/llvm_autogenerated/load.wast | 5 ++-- test/llvm_autogenerated/mem-intrinsics.wast | 5 ++-- test/llvm_autogenerated/memory-addr32.wast | 5 ++-- test/llvm_autogenerated/non-executable-stack.wast | 5 ++-- test/llvm_autogenerated/offset.wast | 7 +++--- test/llvm_autogenerated/phi.wast | 5 ++-- test/llvm_autogenerated/reg-stackify.wast | 7 +++--- test/llvm_autogenerated/return-int32.wast | 5 ++-- test/llvm_autogenerated/return-void.wast | 5 ++-- test/llvm_autogenerated/select.wast | 5 ++-- test/llvm_autogenerated/signext-zeroext.wast | 5 ++-- test/llvm_autogenerated/store-results.wast | 5 ++-- test/llvm_autogenerated/store-trunc.wast | 5 ++-- test/llvm_autogenerated/store.wast | 5 ++-- test/llvm_autogenerated/switch.wast | 5 ++-- test/llvm_autogenerated/unreachable.wast | 5 ++-- test/llvm_autogenerated/unused-argument.wast | 5 ++-- test/llvm_autogenerated/userstack.wast | 5 ++-- test/llvm_autogenerated/varargs.wast | 5 ++-- test/unit.wast | 5 ++-- test/unit.wast.fromBinary | 5 ++-- 69 files changed, 169 insertions(+), 237 deletions(-) (limited to 'test') diff --git a/test/dot_s/alias.wast b/test/dot_s/alias.wast index 5744f8e8a..bd114b9dc 100644 --- a/test/dot_s/alias.wast +++ b/test/dot_s/alias.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 16 "\d2\04\00\00\00\00\00\00)\t\00\00") - ) + (memory 1) + (data (i32.const 16) "\d2\04\00\00\00\00\00\00)\t\00\00") (export "memory" memory) (type $FUNCSIG$v (func)) (export "__exit" $__exit) diff --git a/test/dot_s/asm_const.wast b/test/dot_s/asm_const.wast index ec9389029..564a565ef 100644 --- a/test/dot_s/asm_const.wast +++ b/test/dot_s/asm_const.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 16 "{ Module.print(\"hello, world!\"); }\00") - ) + (memory 1) + (data (i32.const 16) "{ Module.print(\"hello, world!\"); }\00") (export "memory" memory) (type $FUNCSIG$vi (func (param i32))) (import $emscripten_asm_const_vi "env" "emscripten_asm_const_vi" (param i32)) diff --git a/test/dot_s/basics.wast b/test/dot_s/basics.wast index b93bcd5cc..7b13be3d8 100644 --- a/test/dot_s/basics.wast +++ b/test/dot_s/basics.wast @@ -1,9 +1,8 @@ (module - (memory 1 - (segment 16 "hello, world!\n\00") - (segment 32 "vcq") - (segment 48 "\16\00\00\00") - ) + (memory 1) + (data (i32.const 16) "hello, world!\n\00") + (data (i32.const 32) "vcq") + (data (i32.const 48) "\16\00\00\00") (export "memory" memory) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) diff --git a/test/dot_s/bcp-1.wast b/test/dot_s/bcp-1.wast index fcbe3b81e..c090d90e5 100644 --- a/test/dot_s/bcp-1.wast +++ b/test/dot_s/bcp-1.wast @@ -1,13 +1,12 @@ (module - (memory 1 - (segment 16 "\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00\05\00\00\00\06\00\00\00") - (segment 40 "\07\00\00\00\08\00\00\00\t\00\00\00") - (segment 52 "\n\00\00\00\0b\00\00\00") - (segment 60 "\0c\00\00\00\0d\00\00\00\0e\00\00\00") - (segment 72 "\0f\00\00\00\10\00\00\00\11\00\00\00") - (segment 96 "hi\00") - (segment 100 "\00\00\00\00") - ) + (memory 1) + (data (i32.const 16) "\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00\05\00\00\00\06\00\00\00") + (data (i32.const 40) "\07\00\00\00\08\00\00\00\t\00\00\00") + (data (i32.const 52) "\n\00\00\00\0b\00\00\00") + (data (i32.const 60) "\0c\00\00\00\0d\00\00\00\0e\00\00\00") + (data (i32.const 72) "\0f\00\00\00\10\00\00\00\11\00\00\00") + (data (i32.const 96) "hi\00") + (data (i32.const 100) "\00\00\00\00") (export "memory" memory) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) diff --git a/test/dot_s/data-offset-folding.wast b/test/dot_s/data-offset-folding.wast index e737e04f1..9cdacd60b 100644 --- a/test/dot_s/data-offset-folding.wast +++ b/test/dot_s/data-offset-folding.wast @@ -1,8 +1,7 @@ (module - (memory 1 - (segment 12 "\00\00\00\00") - (segment 416 "`\00\00\00") - ) + (memory 1) + (data (i32.const 12) "\00\00\00\00") + (data (i32.const 416) "`\00\00\00") (export "memory" memory) ) ;; METADATA: { "asmConsts": {},"staticBump": 420, "initializers": [] } diff --git a/test/dot_s/function-data-sections.wast b/test/dot_s/function-data-sections.wast index 82aa6f8c9..43947a3cc 100644 --- a/test/dot_s/function-data-sections.wast +++ b/test/dot_s/function-data-sections.wast @@ -1,9 +1,8 @@ (module - (memory 1 - (segment 12 "\00\00\00\00") - (segment 16 "\01\00\00\00") - (segment 20 "33\13@") - ) + (memory 1) + (data (i32.const 12) "\00\00\00\00") + (data (i32.const 16) "\01\00\00\00") + (data (i32.const 20) "33\13@") (export "memory" memory) (export "foo" $foo) (export "bar" $bar) diff --git a/test/dot_s/indidx.wast b/test/dot_s/indidx.wast index 2a5224d00..5fb481197 100644 --- a/test/dot_s/indidx.wast +++ b/test/dot_s/indidx.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 16 "\04\00\00\00\02\00\00\00\01\00\00\00\03\00\00\00") - ) + (memory 1) + (data (i32.const 16) "\04\00\00\00\02\00\00\00\01\00\00\00\03\00\00\00") (export "memory" memory) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$v (func)) diff --git a/test/dot_s/lcomm-in-text-segment.wast b/test/dot_s/lcomm-in-text-segment.wast index 27ebc9b87..e154c6c78 100644 --- a/test/dot_s/lcomm-in-text-segment.wast +++ b/test/dot_s/lcomm-in-text-segment.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 20 "\10\00\00\00") - ) + (memory 1) + (data (i32.const 20) "\10\00\00\00") (export "memory" memory) ) ;; METADATA: { "asmConsts": {},"staticBump": 24, "initializers": [] } diff --git a/test/dot_s/macClangMetaData.wast b/test/dot_s/macClangMetaData.wast index ed41e459c..2d1b5a68f 100644 --- a/test/dot_s/macClangMetaData.wast +++ b/test/dot_s/macClangMetaData.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 16 "Hello, World!\00") - ) + (memory 1) + (data (i32.const 16) "Hello, World!\00") (export "memory" memory) (type $FUNCSIG$ii (func (param i32) (result i32))) (import $puts "env" "puts" (param i32) (result i32)) diff --git a/test/dot_s/memops.wast b/test/dot_s/memops.wast index 07d5caec3..12a13372e 100644 --- a/test/dot_s/memops.wast +++ b/test/dot_s/memops.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 16 "{ Module.print(\"hello, world! \" + HEAP32[8>>2]); }\00") - ) + (memory 1) + (data (i32.const 16) "{ Module.print(\"hello, world! \" + HEAP32[8>>2]); }\00") (export "memory" memory) (type $FUNCSIG$vi (func (param i32))) (import $emscripten_asm_const_vi "env" "emscripten_asm_const_vi" (param i32)) diff --git a/test/dot_s/permute.wast b/test/dot_s/permute.wast index 13abcf66c..a58bc21c8 100644 --- a/test/dot_s/permute.wast +++ b/test/dot_s/permute.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 16 "hE?\8ds\0e7\db[g\8f\955it\c4k\0b\e2\ef\bcld\e0\fd\8c\9e\86&~\d8\94\89+\c8\a4\c2\f2\fb\12\1cej\d99\b7\b3W\c6w\af\ae\caM>\92ub\96\84\b6\b0N\ec;q\11\f7\bf\e31\e6\a7\90\fc\03\e4\aa\d7\cc- \15\83DH\80r\fa\01X\eb:_\00A\cd\e9o`n\ac(\ad\ba0\dcyS#\f4$\"\82\7f}\8e\f6\93L\'\bb\bdZ\ed4\18\f3\c0\cf\ff\a3\f8\07\05\9c\d3\0f\a0\06m%\\\f9^B<\e7\b1\17\98]\0c\dd\c5\f5p\e5\fezJ\ab,F\a5@\08R\85!\b8\1a\ce\d5\04\nI\a6\d1\9f\8a\c9\a9|\97\9aG\be8Y\8b\c1\1b\d4\ea\b9\19\14\9b\9163\d0\1d\d2\df=C\1f\0dc\e1\c7QUv\02\b5aK\b4\tV\c3x\e8\a1\1e\81\de/{\da\d6Pf\10T\f0)\88\16\ee\a8\9d\f1\cbO*\b2\99\132\87.\a2") - ) + (memory 1) + (data (i32.const 16) "hE?\8ds\0e7\db[g\8f\955it\c4k\0b\e2\ef\bcld\e0\fd\8c\9e\86&~\d8\94\89+\c8\a4\c2\f2\fb\12\1cej\d99\b7\b3W\c6w\af\ae\caM>\92ub\96\84\b6\b0N\ec;q\11\f7\bf\e31\e6\a7\90\fc\03\e4\aa\d7\cc- \15\83DH\80r\fa\01X\eb:_\00A\cd\e9o`n\ac(\ad\ba0\dcyS#\f4$\"\82\7f}\8e\f6\93L\'\bb\bdZ\ed4\18\f3\c0\cf\ff\a3\f8\07\05\9c\d3\0f\a0\06m%\\\f9^B<\e7\b1\17\98]\0c\dd\c5\f5p\e5\fezJ\ab,F\a5@\08R\85!\b8\1a\ce\d5\04\nI\a6\d1\9f\8a\c9\a9|\97\9aG\be8Y\8b\c1\1b\d4\ea\b9\19\14\9b\9163\d0\1d\d2\df=C\1f\0dc\e1\c7QUv\02\b5aK\b4\tV\c3x\e8\a1\1e\81\de/{\da\d6Pf\10T\f0)\88\16\ee\a8\9d\f1\cbO*\b2\99\132\87.\a2") (export "memory" memory) ) ;; METADATA: { "asmConsts": {},"staticBump": 272, "initializers": [] } diff --git a/test/dot_s/relocation.wast b/test/dot_s/relocation.wast index 35fcd1562..eb00bac89 100644 --- a/test/dot_s/relocation.wast +++ b/test/dot_s/relocation.wast @@ -1,8 +1,7 @@ (module - (memory 1 - (segment 12 "\10\00\00\00") - (segment 16 "\0c\00\00\00") - ) + (memory 1) + (data (i32.const 12) "\10\00\00\00") + (data (i32.const 16) "\0c\00\00\00") (export "memory" memory) (export "main" $main) (func $main (result i32) diff --git a/test/dot_s/symbolic-offset.wast b/test/dot_s/symbolic-offset.wast index 15ec8f1be..51879232a 100644 --- a/test/dot_s/symbolic-offset.wast +++ b/test/dot_s/symbolic-offset.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 12 "\01\00\00\00\00\00\00\00\00\00\00\00") - ) + (memory 1) + (data (i32.const 12) "\01\00\00\00\00\00\00\00\00\00\00\00") (export "memory" memory) (export "f" $f) (func $f (param $0 i32) (param $1 i32) diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 496ac4efd..0aaf5ab95 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -246,7 +246,7 @@ void test_core() { // Memory. One per module const char *segments[] = { "hello, world" }; - BinaryenIndex segmentOffsets[] = { 10 }; + BinaryenExpressionRef segmentOffsets[] = { BinaryenConst(module, BinaryenLiteralInt32(10)) }; BinaryenIndex segmentSizes[] = { 12 }; BinaryenSetMemory(module, 1, 256, "mem", segments, segmentOffsets, segmentSizes, 1); diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 64f5fc3b4..c8f123bdd 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -7,9 +7,8 @@ BinaryenFloat64: 4 (f32.const -33.61199951171875) ) (module - (memory 1 256 - (segment 10 "hello, world") - ) + (memory 1 256) + (data (i32.const 10) "hello, world") (export "mem" memory) (start $starter) (type $iiIfF (func (param i32 i64 f32 f64) (result i32))) @@ -1375,10 +1374,11 @@ int main() { BinaryenFunctionRef funcs[] = { functions[0] }; BinaryenSetFunctionTable(the_module, funcs, 1); } + expressions[245] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); { const char segment0[] = { 104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100 }; const char* segments[] = { segment0 }; - BinaryenIndex segmentOffsets[] = { 10 }; + BinaryenExpressionRef segmentOffsets[] = { expressions[245] }; BinaryenIndex segmentSizes[] = { 12 }; BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentOffsets, segmentSizes, 1); } @@ -1386,10 +1386,10 @@ int main() { BinaryenIndex paramTypes[] = { 0 }; functionTypes[2] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } - expressions[245] = BinaryenNop(the_module); + expressions[246] = BinaryenNop(the_module); { BinaryenType varTypes[] = { 0 }; - functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[245]); + functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[2], varTypes, 0, expressions[246]); } BinaryenSetStart(the_module, functions[1]); { @@ -1399,9 +1399,8 @@ int main() { BinaryenModuleValidate(the_module); BinaryenModulePrint(the_module); (module - (memory 1 256 - (segment 10 "hello, world") - ) + (memory 1 256) + (data (i32.const 10) "hello, world") (export "mem" memory) (start $starter) (type $iiIfF (func (param i32 i64 f32 f64) (result i32))) diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index 96cbaaa00..24dcc8a5c 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -2,9 +2,8 @@ (f32.const -33.61199951171875) ) (module - (memory 1 256 - (segment 10 "hello, world") - ) + (memory 1 256) + (data (i32.const 10) "hello, world") (export "mem" memory) (start $starter) (type $iiIfF (func (param i32 i64 f32 f64) (result i32))) diff --git a/test/kitchen_sink.wast b/test/kitchen_sink.wast index e0cc6617a..2b139a95b 100644 --- a/test/kitchen_sink.wast +++ b/test/kitchen_sink.wast @@ -1,7 +1,6 @@ (module - (memory 4096 4096 - (segment 1026 "\14\00") - ) + (memory 4096 4096) + (data (i32.const 1026) "\14\00") (type $0 (func (result i32))) (func $kitchensink (type $0) (result i32) (block $block0 diff --git a/test/kitchen_sink.wast.fromBinary b/test/kitchen_sink.wast.fromBinary index cd58fdf65..dd55b5bae 100644 --- a/test/kitchen_sink.wast.fromBinary +++ b/test/kitchen_sink.wast.fromBinary @@ -1,7 +1,6 @@ (module - (memory 4096 4096 - (segment 1026 "\14\00") - ) + (memory 4096 4096) + (data (i32.const 1026) "\14\00") (type $0 (func (result i32))) (func $kitchensink (type $0) (result i32) (block $label$0 diff --git a/test/llvm_autogenerated/byval.wast b/test/llvm_autogenerated/byval.wast index 9ebb4b446..c4dc678ea 100644 --- a/test/llvm_autogenerated/byval.wast +++ b/test/llvm_autogenerated/byval.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) diff --git a/test/llvm_autogenerated/call.wast b/test/llvm_autogenerated/call.wast index 812667aec..8dc92ff80 100644 --- a/test/llvm_autogenerated/call.wast +++ b/test/llvm_autogenerated/call.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) diff --git a/test/llvm_autogenerated/cfg-stackify.wast b/test/llvm_autogenerated/cfg-stackify.wast index ac20e3398..2dbdd5e93 100644 --- a/test/llvm_autogenerated/cfg-stackify.wast +++ b/test/llvm_autogenerated/cfg-stackify.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$v (func)) diff --git a/test/llvm_autogenerated/comparisons_f32.wast b/test/llvm_autogenerated/comparisons_f32.wast index 2ab127beb..9d9898846 100644 --- a/test/llvm_autogenerated/comparisons_f32.wast +++ b/test/llvm_autogenerated/comparisons_f32.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "ord_f32" $ord_f32) (export "uno_f32" $uno_f32) diff --git a/test/llvm_autogenerated/comparisons_f64.wast b/test/llvm_autogenerated/comparisons_f64.wast index 8d9ddf0c0..edd3cd9b7 100644 --- a/test/llvm_autogenerated/comparisons_f64.wast +++ b/test/llvm_autogenerated/comparisons_f64.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "ord_f64" $ord_f64) (export "uno_f64" $uno_f64) diff --git a/test/llvm_autogenerated/comparisons_i32.wast b/test/llvm_autogenerated/comparisons_i32.wast index 2e9a074ee..2657cabd1 100644 --- a/test/llvm_autogenerated/comparisons_i32.wast +++ b/test/llvm_autogenerated/comparisons_i32.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "eq_i32" $eq_i32) (export "ne_i32" $ne_i32) diff --git a/test/llvm_autogenerated/comparisons_i64.wast b/test/llvm_autogenerated/comparisons_i64.wast index 2bf520862..0ce7ab530 100644 --- a/test/llvm_autogenerated/comparisons_i64.wast +++ b/test/llvm_autogenerated/comparisons_i64.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "eq_i64" $eq_i64) (export "ne_i64" $ne_i64) diff --git a/test/llvm_autogenerated/conv.wast b/test/llvm_autogenerated/conv.wast index 273217a23..0ee43f493 100644 --- a/test/llvm_autogenerated/conv.wast +++ b/test/llvm_autogenerated/conv.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "i32_wrap_i64" $i32_wrap_i64) (export "i64_extend_s_i32" $i64_extend_s_i32) diff --git a/test/llvm_autogenerated/copysign-casts.wast b/test/llvm_autogenerated/copysign-casts.wast index 14da8c65d..853cce958 100644 --- a/test/llvm_autogenerated/copysign-casts.wast +++ b/test/llvm_autogenerated/copysign-casts.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "fold_promote" $fold_promote) (export "fold_demote" $fold_demote) diff --git a/test/llvm_autogenerated/cpus.wast b/test/llvm_autogenerated/cpus.wast index c874eab7c..ce2ace210 100644 --- a/test/llvm_autogenerated/cpus.wast +++ b/test/llvm_autogenerated/cpus.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "f" $f) (func $f (param $0 i32) (result i32) diff --git a/test/llvm_autogenerated/dead-vreg.wast b/test/llvm_autogenerated/dead-vreg.wast index efb17b49b..be6e82cfd 100644 --- a/test/llvm_autogenerated/dead-vreg.wast +++ b/test/llvm_autogenerated/dead-vreg.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "foo" $foo) (func $foo (param $0 i32) (param $1 i32) (param $2 i32) diff --git a/test/llvm_autogenerated/divrem-constant.wast b/test/llvm_autogenerated/divrem-constant.wast index c0f05f8b8..358ecdbf3 100644 --- a/test/llvm_autogenerated/divrem-constant.wast +++ b/test/llvm_autogenerated/divrem-constant.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "test_udiv_2" $test_udiv_2) (export "test_udiv_5" $test_udiv_5) diff --git a/test/llvm_autogenerated/f32.wast b/test/llvm_autogenerated/f32.wast index 03409d03b..466ce049a 100644 --- a/test/llvm_autogenerated/f32.wast +++ b/test/llvm_autogenerated/f32.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$ffff (func (param f32 f32 f32) (result f32))) (import $fmaf "env" "fmaf" (param f32 f32 f32) (result f32)) diff --git a/test/llvm_autogenerated/f64.wast b/test/llvm_autogenerated/f64.wast index 860d183f5..0c74c17ea 100644 --- a/test/llvm_autogenerated/f64.wast +++ b/test/llvm_autogenerated/f64.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$dddd (func (param f64 f64 f64) (result f64))) (import $fma "env" "fma" (param f64 f64 f64) (result f64)) diff --git a/test/llvm_autogenerated/fast-isel.wast b/test/llvm_autogenerated/fast-isel.wast index 02d8e97f1..50cdb5469 100644 --- a/test/llvm_autogenerated/fast-isel.wast +++ b/test/llvm_autogenerated/fast-isel.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "immediate_f32" $immediate_f32) (export "immediate_f64" $immediate_f64) diff --git a/test/llvm_autogenerated/frem.wast b/test/llvm_autogenerated/frem.wast index 15d5cc222..b7f784d2d 100644 --- a/test/llvm_autogenerated/frem.wast +++ b/test/llvm_autogenerated/frem.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$ddd (func (param f64 f64) (result f64))) (type $FUNCSIG$fff (func (param f32 f32) (result f32))) diff --git a/test/llvm_autogenerated/func.wast b/test/llvm_autogenerated/func.wast index 118fb252b..b4298e449 100644 --- a/test/llvm_autogenerated/func.wast +++ b/test/llvm_autogenerated/func.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "f0" $f0) (export "f1" $f1) diff --git a/test/llvm_autogenerated/global.wast b/test/llvm_autogenerated/global.wast index cbb8ac184..85c50ff03 100644 --- a/test/llvm_autogenerated/global.wast +++ b/test/llvm_autogenerated/global.wast @@ -1,19 +1,18 @@ (module - (memory 1 - (segment 4 "\b0\08\00\00") - (segment 12 "9\05\00\00") - (segment 28 "\01\00\00\00") - (segment 32 "*\00\00\00") - (segment 36 "\ff\ff\ff\ff") - (segment 64 "\00\00\00\00\01\00\00\00") - (segment 72 "\ff\ff\ff\ff\ff\ff\ff\ff") - (segment 92 "\00\00\00\80") - (segment 96 "\00\00\00@") - (segment 128 "\00\00\00\00\00\00\00\80") - (segment 136 "\00\00\00\00\00\00\00@") - (segment 656 "\e0\00\00\00") - (segment 1192 "\a4\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\b0\08\00\00") + (data (i32.const 12) "9\05\00\00") + (data (i32.const 28) "\01\00\00\00") + (data (i32.const 32) "*\00\00\00") + (data (i32.const 36) "\ff\ff\ff\ff") + (data (i32.const 64) "\00\00\00\00\01\00\00\00") + (data (i32.const 72) "\ff\ff\ff\ff\ff\ff\ff\ff") + (data (i32.const 92) "\00\00\00\80") + (data (i32.const 96) "\00\00\00@") + (data (i32.const 128) "\00\00\00\00\00\00\00\80") + (data (i32.const 136) "\00\00\00\00\00\00\00@") + (data (i32.const 656) "\e0\00\00\00") + (data (i32.const 1192) "\a4\04\00\00") (export "memory" memory) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import $memcpy "env" "memcpy" (param i32 i32 i32) (result i32)) diff --git a/test/llvm_autogenerated/globl.wast b/test/llvm_autogenerated/globl.wast index e357a6337..cf493cb12 100644 --- a/test/llvm_autogenerated/globl.wast +++ b/test/llvm_autogenerated/globl.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "foo" $foo) (func $foo diff --git a/test/llvm_autogenerated/i128.wast b/test/llvm_autogenerated/i128.wast index 19b600792..830c1433c 100644 --- a/test/llvm_autogenerated/i128.wast +++ b/test/llvm_autogenerated/i128.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$vijji (func (param i32 i64 i64 i32))) (type $FUNCSIG$vijjjj (func (param i32 i64 i64 i64 i64))) diff --git a/test/llvm_autogenerated/i32-load-store-alignment.wast b/test/llvm_autogenerated/i32-load-store-alignment.wast index 230d3ffdc..e1ef2f5e8 100644 --- a/test/llvm_autogenerated/i32-load-store-alignment.wast +++ b/test/llvm_autogenerated/i32-load-store-alignment.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "ldi32_a1" $ldi32_a1) (export "ldi32_a2" $ldi32_a2) diff --git a/test/llvm_autogenerated/i32.wast b/test/llvm_autogenerated/i32.wast index 2f1bf90ca..72d5b14a8 100644 --- a/test/llvm_autogenerated/i32.wast +++ b/test/llvm_autogenerated/i32.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "add32" $add32) (export "sub32" $sub32) diff --git a/test/llvm_autogenerated/i64-load-store-alignment.wast b/test/llvm_autogenerated/i64-load-store-alignment.wast index f345f6dcc..33362acfc 100644 --- a/test/llvm_autogenerated/i64-load-store-alignment.wast +++ b/test/llvm_autogenerated/i64-load-store-alignment.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "ldi64_a1" $ldi64_a1) (export "ldi64_a2" $ldi64_a2) diff --git a/test/llvm_autogenerated/i64.wast b/test/llvm_autogenerated/i64.wast index bcbca2611..fa50edd5f 100644 --- a/test/llvm_autogenerated/i64.wast +++ b/test/llvm_autogenerated/i64.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "add64" $add64) (export "sub64" $sub64) diff --git a/test/llvm_autogenerated/ident.wast b/test/llvm_autogenerated/ident.wast index d54e39f47..20a88f29f 100644 --- a/test/llvm_autogenerated/ident.wast +++ b/test/llvm_autogenerated/ident.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) ) ;; METADATA: { "asmConsts": {},"staticBump": 1040, "initializers": [] } diff --git a/test/llvm_autogenerated/immediates.wast b/test/llvm_autogenerated/immediates.wast index 5e16ec488..89820cdf1 100644 --- a/test/llvm_autogenerated/immediates.wast +++ b/test/llvm_autogenerated/immediates.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "zero_i32" $zero_i32) (export "one_i32" $one_i32) diff --git a/test/llvm_autogenerated/irreducible-cfg.wast b/test/llvm_autogenerated/irreducible-cfg.wast index 6990faa76..3e7dbd28f 100644 --- a/test/llvm_autogenerated/irreducible-cfg.wast +++ b/test/llvm_autogenerated/irreducible-cfg.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "test0" $test0) (export "test1" $test1) diff --git a/test/llvm_autogenerated/legalize.wast b/test/llvm_autogenerated/legalize.wast index 8ceba3431..912efce02 100644 --- a/test/llvm_autogenerated/legalize.wast +++ b/test/llvm_autogenerated/legalize.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$vijji (func (param i32 i64 i64 i32))) (import $__ashlti3 "env" "__ashlti3" (param i32 i64 i64 i32)) diff --git a/test/llvm_autogenerated/load-ext.wast b/test/llvm_autogenerated/load-ext.wast index 4b734e546..67c07444d 100644 --- a/test/llvm_autogenerated/load-ext.wast +++ b/test/llvm_autogenerated/load-ext.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "sext_i8_i32" $sext_i8_i32) (export "zext_i8_i32" $zext_i8_i32) diff --git a/test/llvm_autogenerated/load-store-i1.wast b/test/llvm_autogenerated/load-store-i1.wast index 994c70a51..3138a07bf 100644 --- a/test/llvm_autogenerated/load-store-i1.wast +++ b/test/llvm_autogenerated/load-store-i1.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "load_u_i1_i32" $load_u_i1_i32) (export "load_s_i1_i32" $load_s_i1_i32) diff --git a/test/llvm_autogenerated/load.wast b/test/llvm_autogenerated/load.wast index 361027640..22774cc57 100644 --- a/test/llvm_autogenerated/load.wast +++ b/test/llvm_autogenerated/load.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "ldi32" $ldi32) (export "ldi64" $ldi64) diff --git a/test/llvm_autogenerated/mem-intrinsics.wast b/test/llvm_autogenerated/mem-intrinsics.wast index 6f3416a14..62d586ad9 100644 --- a/test/llvm_autogenerated/mem-intrinsics.wast +++ b/test/llvm_autogenerated/mem-intrinsics.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) diff --git a/test/llvm_autogenerated/memory-addr32.wast b/test/llvm_autogenerated/memory-addr32.wast index e75c80eaf..d5e43423a 100644 --- a/test/llvm_autogenerated/memory-addr32.wast +++ b/test/llvm_autogenerated/memory-addr32.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "current_memory" $current_memory) (export "grow_memory" $grow_memory) diff --git a/test/llvm_autogenerated/non-executable-stack.wast b/test/llvm_autogenerated/non-executable-stack.wast index d54e39f47..20a88f29f 100644 --- a/test/llvm_autogenerated/non-executable-stack.wast +++ b/test/llvm_autogenerated/non-executable-stack.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) ) ;; METADATA: { "asmConsts": {},"staticBump": 1040, "initializers": [] } diff --git a/test/llvm_autogenerated/offset.wast b/test/llvm_autogenerated/offset.wast index 63383af3a..a24a055e3 100644 --- a/test/llvm_autogenerated/offset.wast +++ b/test/llvm_autogenerated/offset.wast @@ -1,8 +1,7 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - (segment 12 "\00\00\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") + (data (i32.const 12) "\00\00\00\00") (export "memory" memory) (export "load_i32_with_folded_offset" $load_i32_with_folded_offset) (export "load_i32_with_folded_gep_offset" $load_i32_with_folded_gep_offset) diff --git a/test/llvm_autogenerated/phi.wast b/test/llvm_autogenerated/phi.wast index 30c5aa12c..3bd742e8d 100644 --- a/test/llvm_autogenerated/phi.wast +++ b/test/llvm_autogenerated/phi.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "test0" $test0) (export "test1" $test1) diff --git a/test/llvm_autogenerated/reg-stackify.wast b/test/llvm_autogenerated/reg-stackify.wast index eea7e8bbf..b9526b566 100644 --- a/test/llvm_autogenerated/reg-stackify.wast +++ b/test/llvm_autogenerated/reg-stackify.wast @@ -1,8 +1,7 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - (segment 12 "\00\00\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") + (data (i32.const 12) "\00\00\00\00") (export "memory" memory) (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) diff --git a/test/llvm_autogenerated/return-int32.wast b/test/llvm_autogenerated/return-int32.wast index 8a10e58e4..eca34d41d 100644 --- a/test/llvm_autogenerated/return-int32.wast +++ b/test/llvm_autogenerated/return-int32.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "return_i32" $return_i32) (export "return_i32_twice" $return_i32_twice) diff --git a/test/llvm_autogenerated/return-void.wast b/test/llvm_autogenerated/return-void.wast index e8c9ba861..f2aa0eb37 100644 --- a/test/llvm_autogenerated/return-void.wast +++ b/test/llvm_autogenerated/return-void.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "return_void" $return_void) (export "return_void_twice" $return_void_twice) diff --git a/test/llvm_autogenerated/select.wast b/test/llvm_autogenerated/select.wast index 0bb26d95f..b8c32c86e 100644 --- a/test/llvm_autogenerated/select.wast +++ b/test/llvm_autogenerated/select.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "select_i32_bool" $select_i32_bool) (export "select_i32_eq" $select_i32_eq) diff --git a/test/llvm_autogenerated/signext-zeroext.wast b/test/llvm_autogenerated/signext-zeroext.wast index e7004abe8..f3534f9ba 100644 --- a/test/llvm_autogenerated/signext-zeroext.wast +++ b/test/llvm_autogenerated/signext-zeroext.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "z2s_func" $z2s_func) (export "s2z_func" $s2z_func) diff --git a/test/llvm_autogenerated/store-results.wast b/test/llvm_autogenerated/store-results.wast index dd974db29..c0969bf5f 100644 --- a/test/llvm_autogenerated/store-results.wast +++ b/test/llvm_autogenerated/store-results.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 " \04\00\00") - ) + (memory 1) + (data (i32.const 4) " \04\00\00") (export "memory" memory) (export "single_block" $single_block) (export "foo" $foo) diff --git a/test/llvm_autogenerated/store-trunc.wast b/test/llvm_autogenerated/store-trunc.wast index c337018bf..cf20bcd00 100644 --- a/test/llvm_autogenerated/store-trunc.wast +++ b/test/llvm_autogenerated/store-trunc.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "trunc_i8_i32" $trunc_i8_i32) (export "trunc_i16_i32" $trunc_i16_i32) diff --git a/test/llvm_autogenerated/store.wast b/test/llvm_autogenerated/store.wast index 1234d94a9..1017588b1 100644 --- a/test/llvm_autogenerated/store.wast +++ b/test/llvm_autogenerated/store.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (export "sti32" $sti32) (export "sti64" $sti64) diff --git a/test/llvm_autogenerated/switch.wast b/test/llvm_autogenerated/switch.wast index 78f9a2859..abd4045ae 100644 --- a/test/llvm_autogenerated/switch.wast +++ b/test/llvm_autogenerated/switch.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$v (func)) (import $foo0 "env" "foo0") diff --git a/test/llvm_autogenerated/unreachable.wast b/test/llvm_autogenerated/unreachable.wast index 8c9838b3d..27a783ccf 100644 --- a/test/llvm_autogenerated/unreachable.wast +++ b/test/llvm_autogenerated/unreachable.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$v (func)) (import $abort "env" "abort") diff --git a/test/llvm_autogenerated/unused-argument.wast b/test/llvm_autogenerated/unused-argument.wast index 318ef7a87..c212ea165 100644 --- a/test/llvm_autogenerated/unused-argument.wast +++ b/test/llvm_autogenerated/unused-argument.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$i (func (result i32))) (import $return_something "env" "return_something" (result i32)) diff --git a/test/llvm_autogenerated/userstack.wast b/test/llvm_autogenerated/userstack.wast index c2b38605e..216930a03 100644 --- a/test/llvm_autogenerated/userstack.wast +++ b/test/llvm_autogenerated/userstack.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$vi (func (param i32))) (import $ext_func "env" "ext_func" (param i32)) diff --git a/test/llvm_autogenerated/varargs.wast b/test/llvm_autogenerated/varargs.wast index d460e2efb..02b3f2202 100644 --- a/test/llvm_autogenerated/varargs.wast +++ b/test/llvm_autogenerated/varargs.wast @@ -1,7 +1,6 @@ (module - (memory 1 - (segment 4 "\10\04\00\00") - ) + (memory 1) + (data (i32.const 4) "\10\04\00\00") (export "memory" memory) (type $FUNCSIG$vi (func (param i32))) (import $callee "env" "callee" (param i32)) diff --git a/test/unit.wast b/test/unit.wast index 301ba719c..b18ba6fdf 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -1,7 +1,6 @@ (module - (memory 4096 4096 - (segment 1026 "\14\00") - ) + (memory 4096 4096) + (data (i32.const 1026) "\14\00") (type $FUNCSIG$vf (func (param f32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$id (func (param f64) (result i32))) diff --git a/test/unit.wast.fromBinary b/test/unit.wast.fromBinary index c9ba4528b..495b3daed 100644 --- a/test/unit.wast.fromBinary +++ b/test/unit.wast.fromBinary @@ -1,7 +1,6 @@ (module - (memory 4096 4096 - (segment 1026 "\14\00") - ) + (memory 4096 4096) + (data (i32.const 1026) "\14\00") (type $0 (func (param f32))) (type $1 (func)) (type $2 (func (param f64) (result i32))) -- cgit v1.2.3 From 35bd9109ab07aa21f9e55214a61390fa61c93638 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 12 Aug 2016 14:40:26 -0700 Subject: support function table initial and max sizes, and new printing format --- src/asm2wasm.h | 1 + src/binaryen-c.cpp | 1 + src/passes/Print.cpp | 6 +++++- src/shared-constants.h | 2 ++ src/wasm-binary.h | 1 + src/wasm-linker.cpp | 3 +++ src/wasm-s-parser.h | 25 +++++++++++++++++++++- src/wasm.cpp | 2 ++ src/wasm.h | 5 +++++ test/dot_s/alias.wast | 3 ++- test/dot_s/basics.wast | 3 ++- test/dot_s/bcp-1.wast | 3 ++- test/dot_s/dyncall.wast | 3 ++- test/dot_s/indidx.wast | 3 ++- test/dot_s/indirect-import.wast | 3 ++- test/dot_s/invoke_wrapper.wast | 3 ++- test/emcc_O2_hello_world.fromasm | 3 ++- test/emcc_O2_hello_world.fromasm.imprecise | 3 ++- test/emcc_O2_hello_world.fromasm.imprecise.no-opts | 3 ++- test/emcc_O2_hello_world.fromasm.no-opts | 3 ++- test/emcc_hello_world.fromasm | 3 ++- test/emcc_hello_world.fromasm.imprecise | 3 ++- test/emcc_hello_world.fromasm.imprecise.no-opts | 3 ++- test/emcc_hello_world.fromasm.no-opts | 3 ++- test/example/c-api-kitchen-sink.txt | 6 ++++-- test/example/c-api-kitchen-sink.txt.txt | 3 ++- test/memorygrowth.fromasm | 3 ++- test/memorygrowth.fromasm.imprecise | 3 ++- test/memorygrowth.fromasm.imprecise.no-opts | 3 ++- test/memorygrowth.fromasm.no-opts | 3 ++- test/passes/dce.txt | 3 ++- test/passes/duplicate-function-elimination.txt | 12 +++++++---- test/passes/remove-unused-functions.txt | 3 ++- test/passes/remove-unused-names_merge-blocks.txt | 3 ++- test/unit.fromasm | 3 ++- test/unit.fromasm.imprecise | 3 ++- test/unit.fromasm.imprecise.no-opts | 3 ++- test/unit.fromasm.no-opts | 3 ++- test/unit.wast | 3 ++- test/unit.wast.fromBinary | 3 ++- 40 files changed, 114 insertions(+), 37 deletions(-) (limited to 'test') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index c0f13ff8f..868aa31d3 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -666,6 +666,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { IString curr = contents[k][1]->getIString(); wasm.table.names.push_back(curr); } + wasm.table.initial = wasm.table.max = wasm.table.names.size(); } else { abort_on("invalid var element", pair); } diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index b0e241ab3..d7f866663 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -732,6 +732,7 @@ void BinaryenSetFunctionTable(BinaryenModuleRef module, BinaryenFunctionRef* fun for (BinaryenIndex i = 0; i < numFuncs; i++) { wasm->table.names.push_back(((Function*)funcs[i])->name); } + wasm->table.initial = wasm->table.max = wasm->table.names.size(); } // Memory. One per module diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index eb97eead5..711cc8a84 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -575,7 +575,11 @@ struct PrintSExpression : public Visitor { decIndent(); } void visitTable(Table *curr) { - printOpening(o, "table"); + printOpening(o, "table") << ' ' << curr->initial; + if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max; + o << " anyfunc)\n"; + doIndent(o, indent); + printOpening(o, "elem", true); for (auto name : curr->names) { o << ' '; printName(name); diff --git a/src/shared-constants.h b/src/shared-constants.h index 8599d8144..f0148cb67 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -29,6 +29,7 @@ extern Name GROW_WASM_MEMORY, EXPORT, IMPORT, TABLE, + ELEM, LOCAL, TYPE, CALL, @@ -44,6 +45,7 @@ extern Name GROW_WASM_MEMORY, NEG_NAN, CASE, BR, + ANYFUNC, FAKE_RETURN, ASSERT_RETURN, ASSERT_TRAP, diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b67a79c3d..d405c91dc 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1648,6 +1648,7 @@ public: assert(index < wasm.functions.size()); wasm.table.names.push_back(wasm.functions[index]->name); } + wasm.table.initial = wasm.table.max = wasm.table.names.size(); } void readDataSegments() { diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 1f06c6ec2..29f439bfb 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -223,6 +223,9 @@ void Linker::layout() { if (out.symbolInfo.implementedFunctions.count("free")) { exportFunction("free", true); } + + // finalize function table + out.wasm.table.initial = out.wasm.table.max = out.wasm.table.names.size(); } bool Linker::linkObject(S2WasmBuilder& builder) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 87217cd20..7f652da5a 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -372,6 +372,7 @@ private: if (id == IMPORT) return; // already done if (id == GLOBAL) return parseGlobal(curr); if (id == TABLE) return parseTable(curr); + if (id == ELEM) return parseElem(curr); if (id == TYPE) return; // already done std::cerr << "bad module element " << id.str << '\n'; throw ParseException("unknown module element", curr.line, curr.col); @@ -1424,7 +1425,29 @@ private: } void parseTable(Element& s) { - for (size_t i = 1; i < s.size(); i++) { + if (s.size() == 1) return; // empty table in old notation + if (!s[1]->dollared()) { + if (s[1]->str() == ANYFUNC) { + // (table type (elem ..)) + parseElem(*s[2]); + wasm.table.initial = wasm.table.max = wasm.table.names.size(); + return; + } + // first element isn't dollared, and isn't anyfunc. this could be old syntax for (table 0 1) which means function 0 and 1, or it could be (table initial max? type), look for type + if (s[s.size() - 1]->str() == ANYFUNC) { + // (table initial max? type) + wasm.table.initial = atoi(s[1]->c_str()); + wasm.table.max = atoi(s[2]->c_str()); + return; + } + } + // old notation (table func1 func2 ..) + parseElem(s); + wasm.table.initial = wasm.table.max = wasm.table.names.size(); + } + + void parseElem(Element& s) { + for (Index i = 1; i < s.size(); i++) { wasm.table.names.push_back(getFunctionName(*s[i])); } } diff --git a/src/wasm.cpp b/src/wasm.cpp index 2138ec34d..8cfdee759 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -54,6 +54,7 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), EXPORT("export"), IMPORT("import"), TABLE("table"), + ELEM("elem"), LOCAL("local"), TYPE("type"), CALL("call"), @@ -69,6 +70,7 @@ Name GROW_WASM_MEMORY("__growWasmMemory"), NEG_NAN("-nan"), CASE("case"), BR("br"), + ANYFUNC("anyfunc"), FAKE_RETURN("fake_return_waka123"), ASSERT_RETURN("assert_return"), ASSERT_TRAP("assert_trap"), diff --git a/src/wasm.h b/src/wasm.h index c0129cf23..82933bda0 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1432,7 +1432,12 @@ public: class Table { public: + static const Index kMaxSize = Index(-1); + + Address initial, max; std::vector names; + + Table() : initial(0), max(kMaxSize) {} }; class Memory { diff --git a/test/dot_s/alias.wast b/test/dot_s/alias.wast index bd114b9dc..ab52137a1 100644 --- a/test/dot_s/alias.wast +++ b/test/dot_s/alias.wast @@ -6,7 +6,8 @@ (export "__exit" $__exit) (export "__needs_exit" $__needs_exit) (export "dynCall_v" $dynCall_v) - (table $__wasm_nullptr $__exit) + (table 2 2 anyfunc) + (elem $__wasm_nullptr $__exit) (func $__exit (type $FUNCSIG$v) (return (i32.add diff --git a/test/dot_s/basics.wast b/test/dot_s/basics.wast index 7b13be3d8..e4cd73251 100644 --- a/test/dot_s/basics.wast +++ b/test/dot_s/basics.wast @@ -10,7 +10,8 @@ (import $puts "env" "puts" (param i32)) (export "main" $main) (export "dynCall_iii" $dynCall_iii) - (table $__wasm_nullptr $main) + (table 2 2 anyfunc) + (elem $__wasm_nullptr $main) (func $main (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (call_import $puts (i32.const 16) diff --git a/test/dot_s/bcp-1.wast b/test/dot_s/bcp-1.wast index c090d90e5..a5a63d750 100644 --- a/test/dot_s/bcp-1.wast +++ b/test/dot_s/bcp-1.wast @@ -34,7 +34,8 @@ (export "main" $main) (export "dynCall_i" $dynCall_i) (export "dynCall_ii" $dynCall_ii) - (table $__wasm_nullptr $bad0 $bad1 $bad5 $bad7 $bad8 $bad10 $bad2 $bad3 $bad6 $bad4 $bad9 $good0 $good1 $good2 $opt0 $opt1 $opt2) + (table 18 18 anyfunc) + (elem $__wasm_nullptr $bad0 $bad1 $bad5 $bad7 $bad8 $bad10 $bad2 $bad3 $bad6 $bad4 $bad9 $good0 $good1 $good2 $opt0 $opt1 $opt2) (func $bad0 (type $FUNCSIG$i) (result i32) (return (i32.const 0) diff --git a/test/dot_s/dyncall.wast b/test/dot_s/dyncall.wast index e284c838d..f349bce7f 100644 --- a/test/dot_s/dyncall.wast +++ b/test/dot_s/dyncall.wast @@ -15,7 +15,8 @@ (export "dynCall_i" $dynCall_i) (export "dynCall_if" $dynCall_if) (export "dynCall_vd" $dynCall_vd) - (table $__wasm_nullptr $i $i_f $vd $ffjjdi $vd2) + (table 6 6 anyfunc) + (elem $__wasm_nullptr $i $i_f $vd $ffjjdi $vd2) (func $i (type $FUNCSIG$i) (result i32) (i32.const 0) ) diff --git a/test/dot_s/indidx.wast b/test/dot_s/indidx.wast index 5fb481197..797183b04 100644 --- a/test/dot_s/indidx.wast +++ b/test/dot_s/indidx.wast @@ -7,7 +7,8 @@ (import $getchar "env" "getchar" (result i32)) (export "main" $main) (export "dynCall_i" $dynCall_i) - (table $__wasm_nullptr $c $b $d $a) + (table 5 5 anyfunc) + (elem $__wasm_nullptr $c $b $d $a) (func $a (type $FUNCSIG$i) (result i32) (i32.const 0) ) diff --git a/test/dot_s/indirect-import.wast b/test/dot_s/indirect-import.wast index 22821a4e0..8c8c3e01c 100644 --- a/test/dot_s/indirect-import.wast +++ b/test/dot_s/indirect-import.wast @@ -17,7 +17,8 @@ (export "dynCall_fd" $dynCall_fd) (export "dynCall_v" $dynCall_v) (export "dynCall_vi" $dynCall_vi) - (table $__wasm_nullptr $__importThunk_extern_fd $__importThunk_extern_vj $__importThunk_extern_v $__importThunk_extern_ijidf $__importThunk_extern_struct $__importThunk_extern_sret) + (table 7 7 anyfunc) + (elem $__wasm_nullptr $__importThunk_extern_fd $__importThunk_extern_vj $__importThunk_extern_v $__importThunk_extern_ijidf $__importThunk_extern_struct $__importThunk_extern_sret) (func $bar (result i32) (local $0 i32) (local $1 i32) diff --git a/test/dot_s/invoke_wrapper.wast b/test/dot_s/invoke_wrapper.wast index 6aa7a4ce6..c4a6d5931 100644 --- a/test/dot_s/invoke_wrapper.wast +++ b/test/dot_s/invoke_wrapper.wast @@ -17,7 +17,8 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_ffd" $dynCall_ffd) (export "dynCall_iii" $dynCall_iii) - (table $__wasm_nullptr $_Z5func1v $_Z5func2iii $_Z5func3fd $_Z5func4P8mystructS_) + (table 5 5 anyfunc) + (elem $__wasm_nullptr $_Z5func1v $_Z5func2iii $_Z5func3fd $_Z5func4P8mystructS_) (func $_Z5func1v (type $FUNCSIG$v) ) (func $_Z5func2iii (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index 828905561..a324f42ba 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -42,7 +42,8 @@ (export "dynCall_ii" $dynCall_ii) (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index ede6c05d4..127b7f77f 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -41,7 +41,8 @@ (export "dynCall_ii" $dynCall_ii) (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts index d34022a9e..6822928b3 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts @@ -41,7 +41,8 @@ (export "dynCall_ii" $dynCall_ii) (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) (local $i2 i32) (local $i3 i32) diff --git a/test/emcc_O2_hello_world.fromasm.no-opts b/test/emcc_O2_hello_world.fromasm.no-opts index f850b8306..6c6ad73c7 100644 --- a/test/emcc_O2_hello_world.fromasm.no-opts +++ b/test/emcc_O2_hello_world.fromasm.no-opts @@ -42,7 +42,8 @@ (export "dynCall_ii" $dynCall_ii) (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) (local $i2 i32) (local $i3 i32) diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index c99290ba8..9d4993ec3 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -55,7 +55,8 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) (local $1 i32) (set_local $1 diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index ee84765a1..6c9047895 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -49,7 +49,8 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) (local $1 i32) (set_local $1 diff --git a/test/emcc_hello_world.fromasm.imprecise.no-opts b/test/emcc_hello_world.fromasm.imprecise.no-opts index 327618169..35e23d120 100644 --- a/test/emcc_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_hello_world.fromasm.imprecise.no-opts @@ -49,7 +49,8 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) (local $ret i32) (set_local $ret diff --git a/test/emcc_hello_world.fromasm.no-opts b/test/emcc_hello_world.fromasm.no-opts index 41e3e9e26..27409fe49 100644 --- a/test/emcc_hello_world.fromasm.no-opts +++ b/test/emcc_hello_world.fromasm.no-opts @@ -55,7 +55,8 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) - (table $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (table 18 18 anyfunc) + (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) (local $ret i32) (set_local $ret diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index c8f123bdd..6b766f173 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -17,7 +17,8 @@ BinaryenFloat64: 4 (type $3 (func)) (import $an-imported "module" "base" (param i32 f64) (result f32)) (export "kitchen_sinker" "$kitchen()sinker") - (table "$kitchen()sinker") + (table 1 1 anyfunc) + (elem "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) (block $the-body @@ -1409,7 +1410,8 @@ int main() { (type $3 (func)) (import $an-imported "module" "base" (param i32 f64) (result f32)) (export "kitchen_sinker" "$kitchen()sinker") - (table "$kitchen()sinker") + (table 1 1 anyfunc) + (elem "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) (block $the-body diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index 24dcc8a5c..feae7152c 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -12,7 +12,8 @@ (type $3 (func)) (import $an-imported "module" "base" (param i32 f64) (result f32)) (export "kitchen_sinker" "$kitchen()sinker") - (table "$kitchen()sinker") + (table 1 1 anyfunc) + (elem "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) (block $the-body diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index 5c005ba99..ee6b3ae68 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -40,7 +40,8 @@ (export "dynCall_iiii" $lb) (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) - (table $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (table 8 8 anyfunc) + (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index b70bc7c9e..458ab8f8f 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -39,7 +39,8 @@ (export "dynCall_iiii" $lb) (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) - (table $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (table 8 8 anyfunc) + (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/memorygrowth.fromasm.imprecise.no-opts b/test/memorygrowth.fromasm.imprecise.no-opts index dd03e651e..c30a5933b 100644 --- a/test/memorygrowth.fromasm.imprecise.no-opts +++ b/test/memorygrowth.fromasm.imprecise.no-opts @@ -39,7 +39,8 @@ (export "dynCall_iiii" $lb) (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) - (table $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (table 8 8 anyfunc) + (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) (local $b i32) (local $c i32) diff --git a/test/memorygrowth.fromasm.no-opts b/test/memorygrowth.fromasm.no-opts index 29aa4aa30..3abed2662 100644 --- a/test/memorygrowth.fromasm.no-opts +++ b/test/memorygrowth.fromasm.no-opts @@ -40,7 +40,8 @@ (export "dynCall_iiii" $lb) (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) - (table $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (table 8 8 anyfunc) + (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) (local $b i32) (local $c i32) diff --git a/test/passes/dce.txt b/test/passes/dce.txt index 692a5005e..9c2836123 100644 --- a/test/passes/dce.txt +++ b/test/passes/dce.txt @@ -2,7 +2,8 @@ (memory 10) (type $ii (func (param i32 i32))) (type $1 (func)) - (table $call-me) + (table 1 1 anyfunc) + (elem $call-me) (func $call-me (type $ii) (param $0 i32) (param $1 i32) (nop) ) diff --git a/test/passes/duplicate-function-elimination.txt b/test/passes/duplicate-function-elimination.txt index 3671ce24b..6c64b081c 100644 --- a/test/passes/duplicate-function-elimination.txt +++ b/test/passes/duplicate-function-elimination.txt @@ -38,7 +38,8 @@ (type $0 (func)) (export "keep2" $keep2) (export "other" $keep2) - (table $keep2 $keep2 $caller) + (table 3 3 anyfunc) + (elem $keep2 $keep2 $caller) (func $keep2 (type $0) (nop) ) @@ -363,7 +364,8 @@ (module (memory 0) (type $T (func)) - (table $erase $erase) + (table 2 2 anyfunc) + (elem $erase $erase) (func $erase (type $T) (call_indirect $T (i32.const 0) @@ -373,7 +375,8 @@ (module (memory 0) (type $T (func)) - (table $keep2 $other) + (table 2 2 anyfunc) + (elem $keep2 $other) (func $keep2 (type $T) (call_indirect $T (i32.const 0) @@ -389,7 +392,8 @@ (memory 0) (type $T (func)) (type $S (func)) - (table $keep2 $other) + (table 2 2 anyfunc) + (elem $keep2 $other) (func $keep2 (type $T) (call_indirect $T (i32.const 0) diff --git a/test/passes/remove-unused-functions.txt b/test/passes/remove-unused-functions.txt index b6f7cf3e1..6aa8e3265 100644 --- a/test/passes/remove-unused-functions.txt +++ b/test/passes/remove-unused-functions.txt @@ -3,7 +3,8 @@ (start $start) (type $0 (func)) (export "exported" $exported) - (table $called_indirect) + (table 1 1 anyfunc) + (elem $called_indirect) (func $start (type $0) (call $called0) ) diff --git a/test/passes/remove-unused-names_merge-blocks.txt b/test/passes/remove-unused-names_merge-blocks.txt index fe5bd5cf8..ead2c99ca 100644 --- a/test/passes/remove-unused-names_merge-blocks.txt +++ b/test/passes/remove-unused-names_merge-blocks.txt @@ -4,7 +4,8 @@ (type $ii (func (param i32 i32))) (type $iii (func (param i32 i32 i32))) (type $3 (func)) - (table $call-i) + (table 1 1 anyfunc) + (elem $call-i) (func $call-i (type $i) (param $0 i32) (nop) ) diff --git a/test/unit.fromasm b/test/unit.fromasm index f939782e7..e292f47ae 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -15,7 +15,8 @@ (import $i32u-div "asm2wasm" "i32u-div" (param i32 i32) (result i32)) (export "big_negative" $big_negative) (export "pick" $big_negative) - (table $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) + (table 10 10 anyfunc) + (elem $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index f80f4ce6c..ef3c09ff0 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -11,7 +11,8 @@ (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) (export "pick" $big_negative) - (table $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) + (table 10 10 anyfunc) + (elem $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) ) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index 4fa627938..cde7eb176 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -11,7 +11,8 @@ (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) (export "pick" $exportMe) - (table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (table 10 10 anyfunc) + (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) (set_local $temp diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index c10bd3dff..c0650ebd5 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -15,7 +15,8 @@ (import $i32u-div "asm2wasm" "i32u-div" (param i32 i32) (result i32)) (export "big_negative" $big_negative) (export "pick" $exportMe) - (table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (table 10 10 anyfunc) + (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) (set_local $temp diff --git a/test/unit.wast b/test/unit.wast index b18ba6fdf..30d16d1a2 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -13,7 +13,8 @@ (import $f64-to-int "asm2wasm" "f64-to-int" (param f64) (result i32)) (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) - (table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (table 10 anyfunc) + (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (type $FUNCSIG$v) (local $temp f64) (block $block0 diff --git a/test/unit.wast.fromBinary b/test/unit.wast.fromBinary index 495b3daed..4348394af 100644 --- a/test/unit.wast.fromBinary +++ b/test/unit.wast.fromBinary @@ -13,7 +13,8 @@ (import $import$1 "asm2wasm" "f64-to-int" (param f64) (result i32)) (import $import$2 "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) - (table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (table 10 10 anyfunc) + (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (type $1) (local $var$0 f64) (block $label$0 -- cgit v1.2.3 From 113efcaa1e814304662ccc56312d8c59014a3a6c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 15 Aug 2016 14:29:57 -0700 Subject: offset support in table --- src/asm2wasm.h | 10 +++- src/binaryen-c.cpp | 6 +- src/passes/DuplicateFunctionElimination.cpp | 10 ++-- src/passes/Print.cpp | 15 +++-- src/passes/RemoveUnusedFunctions.cpp | 6 +- src/passes/ReorderFunctions.cpp | 6 +- src/shell-interface.h | 24 ++++++++ src/wasm-binary.h | 37 ++++++++---- src/wasm-interpreter.h | 21 +++---- src/wasm-js.cpp | 68 +++++++++++++++++++--- src/wasm-linker.cpp | 31 +++++++--- src/wasm-linker.h | 4 ++ src/wasm-s-parser.h | 18 ++++-- src/wasm.h | 14 ++++- test/dot_s/alias.wast | 2 +- test/dot_s/basics.wast | 2 +- test/dot_s/bcp-1.wast | 2 +- test/dot_s/dyncall.wast | 2 +- test/dot_s/indidx.wast | 2 +- test/dot_s/indirect-import.wast | 2 +- test/dot_s/invoke_wrapper.wast | 2 +- test/emcc_O2_hello_world.fromasm | 2 +- test/emcc_O2_hello_world.fromasm.imprecise | 2 +- test/emcc_O2_hello_world.fromasm.imprecise.no-opts | 2 +- test/emcc_O2_hello_world.fromasm.no-opts | 2 +- test/emcc_hello_world.fromasm | 2 +- test/emcc_hello_world.fromasm.imprecise | 2 +- test/emcc_hello_world.fromasm.imprecise.no-opts | 2 +- test/emcc_hello_world.fromasm.no-opts | 2 +- test/example/c-api-kitchen-sink.txt | 4 +- test/example/c-api-kitchen-sink.txt.txt | 2 +- test/memorygrowth.fromasm | 2 +- test/memorygrowth.fromasm.imprecise | 2 +- test/memorygrowth.fromasm.imprecise.no-opts | 2 +- test/memorygrowth.fromasm.no-opts | 2 +- test/passes/dce.txt | 2 +- test/passes/duplicate-function-elimination.txt | 8 +-- test/passes/remove-unused-functions.txt | 2 +- test/passes/remove-unused-names_merge-blocks.txt | 2 +- test/unit.fromasm | 2 +- test/unit.fromasm.imprecise | 2 +- test/unit.fromasm.imprecise.no-opts | 2 +- test/unit.fromasm.no-opts | 2 +- test/unit.wast | 2 +- test/unit.wast.fromBinary | 4 +- 45 files changed, 240 insertions(+), 102 deletions(-) (limited to 'test') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 868aa31d3..a5754f725 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -660,13 +660,17 @@ void Asm2WasmBuilder::processAsm(Ref ast) { // TODO: when not using aliasing function pointers, we could merge them by noticing that // index 0 in each table is the null func, and each other index should only have one // non-null func. However, that breaks down when function pointer casts are emulated. - functionTableStarts[name] = wasm.table.names.size(); // this table starts here + if (wasm.table.segments.size() == 0) { + wasm.table.segments.emplace_back(wasm.allocator.alloc()->set(Literal(uint32_t(0)))); + } + auto& segment = wasm.table.segments[0]; + functionTableStarts[name] = segment.data.size(); // this table starts here Ref contents = value[1]; for (unsigned k = 0; k < contents->size(); k++) { IString curr = contents[k][1]->getIString(); - wasm.table.names.push_back(curr); + segment.data.push_back(curr); } - wasm.table.initial = wasm.table.max = wasm.table.names.size(); + wasm.table.initial = wasm.table.max = segment.data.size(); } else { abort_on("invalid var element", pair); } diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index d7f866663..83c626eb1 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -729,10 +729,12 @@ void BinaryenSetFunctionTable(BinaryenModuleRef module, BinaryenFunctionRef* fun } auto* wasm = (Module*)module; + Table::Segment segment(wasm->allocator.alloc()->set(Literal(int32_t(0)))); for (BinaryenIndex i = 0; i < numFuncs; i++) { - wasm->table.names.push_back(((Function*)funcs[i])->name); + segment.data.push_back(((Function*)funcs[i])->name); } - wasm->table.initial = wasm->table.max = wasm->table.names.size(); + wasm->table.segments.push_back(segment); + wasm->table.initial = wasm->table.max = numFuncs; } // Memory. One per module diff --git a/src/passes/DuplicateFunctionElimination.cpp b/src/passes/DuplicateFunctionElimination.cpp index 961d26ba5..2b8e69b54 100644 --- a/src/passes/DuplicateFunctionElimination.cpp +++ b/src/passes/DuplicateFunctionElimination.cpp @@ -123,10 +123,12 @@ struct DuplicateFunctionElimination : public Pass { replacerRunner.add(&replacements); replacerRunner.run(); // replace in table - for (auto& name : module->table.names) { - auto iter = replacements.find(name); - if (iter != replacements.end()) { - name = iter->second; + for (auto& segment : module->table.segments) { + for (auto& name : segment.data) { + auto iter = replacements.find(name); + if (iter != replacements.end()) { + name = iter->second; + } } } // replace in start diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 711cc8a84..5eea38bdc 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -579,12 +579,15 @@ struct PrintSExpression : public Visitor { if (curr->max && curr->max != Table::kMaxSize) o << ' ' << curr->max; o << " anyfunc)\n"; doIndent(o, indent); - printOpening(o, "elem", true); - for (auto name : curr->names) { - o << ' '; - printName(name); + for (auto& segment : curr->segments) { + printOpening(o, "elem ", true); + visit(segment.offset); + for (auto name : segment.data) { + o << ' '; + printName(name); + } + o << ')'; } - o << ')'; } void visitModule(Module *curr) { currModule = curr; @@ -652,7 +655,7 @@ struct PrintSExpression : public Visitor { visitGlobal(child.get()); o << maybeNewLine; } - if (curr->table.names.size() > 0) { + if (curr->table.segments.size() > 0 || curr->table.initial > 0 || curr->table.max != Table::kMaxSize) { doIndent(o, indent); visitTable(&curr->table); o << maybeNewLine; diff --git a/src/passes/RemoveUnusedFunctions.cpp b/src/passes/RemoveUnusedFunctions.cpp index a2941aff6..78b0f0ffc 100644 --- a/src/passes/RemoveUnusedFunctions.cpp +++ b/src/passes/RemoveUnusedFunctions.cpp @@ -39,8 +39,10 @@ struct RemoveUnusedFunctions : public Pass { root.push_back(module->getFunction(curr->value)); } // For now, all functions that can be called indirectly are marked as roots. - for (auto& curr : module->table.names) { - root.push_back(module->getFunction(curr)); + for (auto& segment : module->table.segments) { + for (auto& curr : segment.data) { + root.push_back(module->getFunction(curr)); + } } // Compute function reachability starting from the root set. DirectCallGraphAnalyzer analyzer(module, root); diff --git a/src/passes/ReorderFunctions.cpp b/src/passes/ReorderFunctions.cpp index 38ef98afb..679fedb61 100644 --- a/src/passes/ReorderFunctions.cpp +++ b/src/passes/ReorderFunctions.cpp @@ -38,8 +38,10 @@ struct ReorderFunctions : public WalkerPassexports) { counts[curr->value]++; } - for (auto& curr : module->table.names) { - counts[curr]++; + for (auto& segment : module->table.segments) { + for (auto& curr : segment.data) { + counts[curr]++; + } } std::sort(module->functions.begin(), module->functions.end(), [this]( const std::unique_ptr& a, diff --git a/src/shell-interface.h b/src/shell-interface.h index 55f9b2a0b..f332307ad 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -86,6 +86,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { } } memory; + std::vector table; + ShellExternalInterface() : memory() {} void init(Module& wasm) override { @@ -98,6 +100,15 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { memory.set(offset + i, segment.data[i]); } } + + table.resize(wasm.table.initial); + for (auto& segment : wasm.table.segments) { + Address offset = ConstantExpressionRunner().visit(segment.offset).value.geti32(); + assert(offset + segment.data.size() <= wasm.table.initial); + for (size_t i = 0; i != segment.data.size(); ++i) { + table[offset + i] = segment.data[i]; + } + } } Literal callImport(Import *import, LiteralList& arguments) override { @@ -115,6 +126,19 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { abort(); } + Literal callTable(Index index, Name type, LiteralList& arguments, ModuleInstance& instance) override { + if (index >= table.size()) trap("callTable overflow"); + auto* func = instance.wasm.getFunction(table[index]); + if (func->type.is() && func->type != type) trap("callIndirect: bad type"); + if (func->params.size() != arguments.size()) trap("callIndirect: bad # of arguments"); + for (size_t i = 0; i < func->params.size(); i++) { + if (func->params[i] != arguments[i].type) { + trap("callIndirect: bad argument type"); + } + } + return instance.callFunctionInternal(func->name, arguments); + } + Literal load(Load* load, Address addr) override { switch (load->type) { case i32: { diff --git a/src/wasm-binary.h b/src/wasm-binary.h index d405c91dc..04bebddc5 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -740,12 +740,19 @@ public: } void writeFunctionTable() { - if (wasm->table.names.size() == 0) return; + if (wasm->table.segments.size() == 0) return; if (debug) std::cerr << "== writeFunctionTable" << std::endl; auto start = startSection(BinaryConsts::Section::FunctionTable); - o << U32LEB(wasm->table.names.size()); - for (auto name : wasm->table.names) { - o << U32LEB(getFunctionIndex(name)); + o << U32LEB(wasm->table.initial); + o << U32LEB(wasm->table.max); + o << U32LEB(wasm->table.segments.size()); + for (auto& segment : wasm->table.segments) { + writeExpression(segment.offset); + o << int8_t(BinaryConsts::End); + o << U32LEB(segment.data.size()); + for (auto name : segment.data) { + o << U32LEB(getFunctionIndex(name)); + } } finishSection(start); } @@ -1644,11 +1651,13 @@ public: } } - for (size_t index : functionTable) { - assert(index < wasm.functions.size()); - wasm.table.names.push_back(wasm.functions[index]->name); + for (auto& pair : functionTable) { + auto i = pair.first; + auto& indexes = pair.second; + for (auto j : indexes) { + wasm.table.segments[i].data.push_back(wasm.functions[j]->name); + } } - wasm.table.initial = wasm.table.max = wasm.table.names.size(); } void readDataSegments() { @@ -1667,14 +1676,20 @@ public: } } - std::vector functionTable; + std::map> functionTable; void readFunctionTable() { if (debug) std::cerr << "== readFunctionTable" << std::endl; + wasm.table.initial = getU32LEB(); + wasm.table.max = getU32LEB(); auto num = getU32LEB(); for (size_t i = 0; i < num; i++) { - auto index = getU32LEB(); - functionTable.push_back(index); + wasm.table.segments.emplace_back(readExpression()); + auto& temporary = functionTable[i]; + auto size = getU32LEB(); + for (Index j = 0; j < size; j++) { + temporary.push_back(getU32LEB()); + } } } diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 0be36a677..f2deed039 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -533,6 +533,7 @@ public: struct ExternalInterface { virtual void init(Module& wasm) {} virtual Literal callImport(Import* import, LiteralList& arguments) = 0; + virtual Literal callTable(Index index, Name type, LiteralList& arguments, ModuleInstance& instance) = 0; virtual Literal load(Load* load, Address addr) = 0; virtual void store(Store* store, Address addr, Literal value) = 0; virtual void growMemory(Address oldSize, Address newSize) = 0; @@ -591,8 +592,8 @@ private: return callFunctionInternal(name, arguments); } -private: - // Internal function call. +public: + // Internal function call. Must be public so that callTable implementations can use it (refactor?) Literal callFunctionInternal(IString name, LiteralList& arguments) { class FunctionScope { @@ -672,18 +673,8 @@ private: LiteralList arguments; Flow flow = generateArguments(curr->operands, arguments); if (flow.breaking()) return flow; - size_t index = target.value.geti32(); - if (index >= instance.wasm.table.names.size()) trap("callIndirect: overflow"); - Name name = instance.wasm.table.names[index]; - Function *func = instance.wasm.getFunction(name); - if (func->type.is() && func->type != curr->fullType) trap("callIndirect: bad type"); - if (func->params.size() != arguments.size()) trap("callIndirect: bad # of arguments"); - for (size_t i = 0; i < func->params.size(); i++) { - if (func->params[i] != arguments[i].type) { - trap("callIndirect: bad argument type"); - } - } - return instance.callFunctionInternal(name, arguments); + Index index = target.value.geti32(); + return instance.externalInterface->callTable(index, curr->fullType, arguments, instance); } Flow visitGetLocal(GetLocal *curr) { @@ -802,6 +793,8 @@ private: return ret; } +private: + Address memorySize; // in pages template diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp index 2aacd94d4..83956e47e 100644 --- a/src/wasm-js.cpp +++ b/src/wasm-js.cpp @@ -195,10 +195,23 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() { target.set(source, $0); }, ConstantExpressionRunner().visit(segment.offset).value.geti32(), &segment.data[0], segment.data.size()); } + // Table support is in a JS array. If the entry is a number, it's a function pointer. If not, it's a JS method to be called directly + // TODO: make them all JS methods, wrapping a dynCall where necessary? + EM_ASM_({ + Module['outside']['wasmTable'] = new Array($0); + }, wasm.table.initial); + for (auto segment : wasm.table.segments) { + Address offset = ConstantExpressionRunner().visit(segment.offset).value.geti32(); + assert(offset + segment.data.size() <= wasm.table.initial); + for (size_t i = 0; i != segment.data.size(); ++i) { + EM_ASM_({ + Module['outside']['wasmTable'][$0] = $1; + }, offset + i, wasm.getFunction(segment.data[i])); + } + } } - Literal callImport(Import *import, LiteralList& arguments) override { - if (wasmJSDebug) std::cout << "calling import " << import->name.str << '\n'; + void prepareTempArgments(LiteralList& arguments) { EM_ASM({ Module['tempArguments'] = []; }); @@ -213,6 +226,21 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() { abort(); } } + } + + Literal getResultFromJS(double ret, WasmType type) { + switch (type) { + case none: return Literal(0); + case i32: return Literal((int32_t)ret); + case f32: return Literal((float)ret); + case f64: return Literal((double)ret); + default: abort(); + } + } + + Literal callImport(Import *import, LiteralList& arguments) override { + if (wasmJSDebug) std::cout << "calling import " << import->name.str << '\n'; + prepareTempArgments(arguments); double ret = EM_ASM_DOUBLE({ var mod = Pointer_stringify($0); var base = Pointer_stringify($1); @@ -224,12 +252,36 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() { if (wasmJSDebug) std::cout << "calling import returning " << ret << '\n'; - switch (import->type->result) { - case none: return Literal(0); - case i32: return Literal((int32_t)ret); - case f32: return Literal((float)ret); - case f64: return Literal((double)ret); - default: abort(); + return getResultFromJS(ret, import->type->result); + } + + Literal callTable(Index index, Name type, LiteralList& arguments, ModuleInstance& instance) override { + void* ptr = (void*)EM_ASM_INT({ + var value = Module['outside']['wasmTable'][$0]; + return typeof value === "number" ? value : -1; + }, index); + if (ptr == nullptr) trap("callTable overflow"); + if (ptr != (void*)-1) { + // a Function we can call + Function* func = (Function*)ptr; + if (func->type.is() && func->type != type) trap("callIndirect: bad type"); + if (func->params.size() != arguments.size()) trap("callIndirect: bad # of arguments"); + for (size_t i = 0; i < func->params.size(); i++) { + if (func->params[i] != arguments[i].type) { + trap("callIndirect: bad argument type"); + } + } + return instance.callFunctionInternal(func->name, arguments); + } else { + // A JS function JS can call + prepareTempArgments(arguments); + double ret = EM_ASM_DOUBLE({ + var func = Module['outside']['wasmTable'][$0]; + var tempArguments = Module['tempArguments']; + Module['tempArguments'] = null; + return func.apply(null, tempArguments); + }, index); + return getResultFromJS(ret, instance.wasm.getFunctionType(type)->result); } } diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 29f439bfb..2c9a4cd4d 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -132,7 +132,7 @@ void Linker::layout() { // Emit the pre-assigned function names in sorted order for (const auto& P : functionNames) { - out.wasm.table.names.push_back(P.second); + getTableSegment().data.push_back(P.second); } for (auto& relocation : out.relocations) { @@ -206,9 +206,11 @@ void Linker::layout() { } // ensure an explicit function type for indirect call targets - for (auto& name : out.wasm.table.names) { - auto* func = out.wasm.getFunction(name); - func->type = ensureFunctionType(getSig(func), &out.wasm)->name; + for (auto& segment : out.wasm.table.segments) { + for (auto& name : segment.data) { + auto* func = out.wasm.getFunction(name); + func->type = ensureFunctionType(getSig(func), &out.wasm)->name; + } } // Export malloc and free whenever availble. JavsScript version of malloc has @@ -225,7 +227,9 @@ void Linker::layout() { } // finalize function table - out.wasm.table.initial = out.wasm.table.max = out.wasm.table.names.size(); + if (out.wasm.table.segments.size() > 0) { + out.wasm.table.initial = out.wasm.table.max = getTableSegment().data.size(); + } } bool Linker::linkObject(S2WasmBuilder& builder) { @@ -385,10 +389,19 @@ void Linker::emscriptenGlue(std::ostream& o) { o << " }\n"; } +Table::Segment& Linker::getTableSegment() { + if (out.wasm.table.segments.size() == 0) { + out.wasm.table.segments.emplace_back(out.wasm.allocator.alloc()->set(Literal(uint32_t(0)))); + } else { + assert(out.wasm.table.segments.size() == 1); + } + return out.wasm.table.segments[0]; +} + Index Linker::getFunctionIndex(Name name) { if (!functionIndexes.count(name)) { - functionIndexes[name] = out.wasm.table.names.size(); - out.wasm.table.names.push_back(name); + functionIndexes[name] = getTableSegment().data.size(); + getTableSegment().data.push_back(name); if (debug) { std::cerr << "function index: " << name << ": " << functionIndexes[name] << '\n'; @@ -406,7 +419,6 @@ bool hasI64ResultOrParam(FunctionType* ft) { } void Linker::makeDummyFunction() { - assert(out.wasm.table.names.empty()); bool create = false; // Check if there are address-taken functions for (auto& relocation : out.relocations) { @@ -424,9 +436,10 @@ void Linker::makeDummyFunction() { } void Linker::makeDynCallThunks() { + if (out.wasm.table.segments.size() == 0) return; std::unordered_set sigs; wasm::Builder wasmBuilder(out.wasm); - for (const auto& indirectFunc : out.wasm.table.names) { + for (const auto& indirectFunc : getTableSegment().data) { // Skip generating thunks for the dummy function if (indirectFunc == dummyFunction) continue; std::string sig(getSig(out.wasm.getFunction(indirectFunc))); diff --git a/src/wasm-linker.h b/src/wasm-linker.h index bf76a8f94..a6f5d319a 100644 --- a/src/wasm-linker.h +++ b/src/wasm-linker.h @@ -282,6 +282,10 @@ class Linker { void ensureImport(Name target, std::string signature); + // Makes sure the table has a single segment, with offset 0, + // to which we can add content. + Table::Segment& getTableSegment(); + // Retrieves (and assigns) an entry index in the indirect function table for // a given function. Index getFunctionIndex(Name name); diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 7f652da5a..b70f70b4e 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -1430,7 +1430,7 @@ private: if (s[1]->str() == ANYFUNC) { // (table type (elem ..)) parseElem(*s[2]); - wasm.table.initial = wasm.table.max = wasm.table.names.size(); + wasm.table.initial = wasm.table.max = wasm.table.segments[0].data.size(); return; } // first element isn't dollared, and isn't anyfunc. this could be old syntax for (table 0 1) which means function 0 and 1, or it could be (table initial max? type), look for type @@ -1443,13 +1443,23 @@ private: } // old notation (table func1 func2 ..) parseElem(s); - wasm.table.initial = wasm.table.max = wasm.table.names.size(); + wasm.table.initial = wasm.table.max = wasm.table.segments[0].data.size(); } void parseElem(Element& s) { - for (Index i = 1; i < s.size(); i++) { - wasm.table.names.push_back(getFunctionName(*s[i])); + Index i = 1; + Expression* offset; + if (s[i]->isList()) { + // there is an init expression + offset = parseExpression(s[i++]); + } else { + offset = allocator.alloc()->set(Literal(int32_t(0))); + } + Table::Segment segment(offset); + for (; i < s.size(); i++) { + segment.data.push_back(getFunctionName(*s[i])); } + wasm.table.segments.push_back(segment); } void parseType(Element& s) { diff --git a/src/wasm.h b/src/wasm.h index 82933bda0..68558033d 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1434,8 +1434,19 @@ class Table { public: static const Index kMaxSize = Index(-1); + struct Segment { + Expression* offset; + std::vector data; + Segment() {} + Segment(Expression* offset) : offset(offset) { + } + Segment(Expression* offset, std::vector& init) : offset(offset) { + data.swap(init); + } + }; + Address initial, max; - std::vector names; + std::vector segments; Table() : initial(0), max(kMaxSize) {} }; @@ -1445,6 +1456,7 @@ public: static const Address::address_t kPageSize = 64 * 1024; static const Address::address_t kMaxSize = ~Address::address_t(0) / kPageSize; static const Address::address_t kPageMask = ~(kPageSize - 1); + struct Segment { Expression* offset; std::vector data; // TODO: optimize diff --git a/test/dot_s/alias.wast b/test/dot_s/alias.wast index ab52137a1..8ba469564 100644 --- a/test/dot_s/alias.wast +++ b/test/dot_s/alias.wast @@ -7,7 +7,7 @@ (export "__needs_exit" $__needs_exit) (export "dynCall_v" $dynCall_v) (table 2 2 anyfunc) - (elem $__wasm_nullptr $__exit) + (elem (i32.const 0) $__wasm_nullptr $__exit) (func $__exit (type $FUNCSIG$v) (return (i32.add diff --git a/test/dot_s/basics.wast b/test/dot_s/basics.wast index e4cd73251..3562140fb 100644 --- a/test/dot_s/basics.wast +++ b/test/dot_s/basics.wast @@ -11,7 +11,7 @@ (export "main" $main) (export "dynCall_iii" $dynCall_iii) (table 2 2 anyfunc) - (elem $__wasm_nullptr $main) + (elem (i32.const 0) $__wasm_nullptr $main) (func $main (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (call_import $puts (i32.const 16) diff --git a/test/dot_s/bcp-1.wast b/test/dot_s/bcp-1.wast index a5a63d750..1b76a98af 100644 --- a/test/dot_s/bcp-1.wast +++ b/test/dot_s/bcp-1.wast @@ -35,7 +35,7 @@ (export "dynCall_i" $dynCall_i) (export "dynCall_ii" $dynCall_ii) (table 18 18 anyfunc) - (elem $__wasm_nullptr $bad0 $bad1 $bad5 $bad7 $bad8 $bad10 $bad2 $bad3 $bad6 $bad4 $bad9 $good0 $good1 $good2 $opt0 $opt1 $opt2) + (elem (i32.const 0) $__wasm_nullptr $bad0 $bad1 $bad5 $bad7 $bad8 $bad10 $bad2 $bad3 $bad6 $bad4 $bad9 $good0 $good1 $good2 $opt0 $opt1 $opt2) (func $bad0 (type $FUNCSIG$i) (result i32) (return (i32.const 0) diff --git a/test/dot_s/dyncall.wast b/test/dot_s/dyncall.wast index f349bce7f..c6dae687a 100644 --- a/test/dot_s/dyncall.wast +++ b/test/dot_s/dyncall.wast @@ -16,7 +16,7 @@ (export "dynCall_if" $dynCall_if) (export "dynCall_vd" $dynCall_vd) (table 6 6 anyfunc) - (elem $__wasm_nullptr $i $i_f $vd $ffjjdi $vd2) + (elem (i32.const 0) $__wasm_nullptr $i $i_f $vd $ffjjdi $vd2) (func $i (type $FUNCSIG$i) (result i32) (i32.const 0) ) diff --git a/test/dot_s/indidx.wast b/test/dot_s/indidx.wast index 797183b04..6cdb6c4ce 100644 --- a/test/dot_s/indidx.wast +++ b/test/dot_s/indidx.wast @@ -8,7 +8,7 @@ (export "main" $main) (export "dynCall_i" $dynCall_i) (table 5 5 anyfunc) - (elem $__wasm_nullptr $c $b $d $a) + (elem (i32.const 0) $__wasm_nullptr $c $b $d $a) (func $a (type $FUNCSIG$i) (result i32) (i32.const 0) ) diff --git a/test/dot_s/indirect-import.wast b/test/dot_s/indirect-import.wast index 8c8c3e01c..86c8ded00 100644 --- a/test/dot_s/indirect-import.wast +++ b/test/dot_s/indirect-import.wast @@ -18,7 +18,7 @@ (export "dynCall_v" $dynCall_v) (export "dynCall_vi" $dynCall_vi) (table 7 7 anyfunc) - (elem $__wasm_nullptr $__importThunk_extern_fd $__importThunk_extern_vj $__importThunk_extern_v $__importThunk_extern_ijidf $__importThunk_extern_struct $__importThunk_extern_sret) + (elem (i32.const 0) $__wasm_nullptr $__importThunk_extern_fd $__importThunk_extern_vj $__importThunk_extern_v $__importThunk_extern_ijidf $__importThunk_extern_struct $__importThunk_extern_sret) (func $bar (result i32) (local $0 i32) (local $1 i32) diff --git a/test/dot_s/invoke_wrapper.wast b/test/dot_s/invoke_wrapper.wast index c4a6d5931..d54e94d03 100644 --- a/test/dot_s/invoke_wrapper.wast +++ b/test/dot_s/invoke_wrapper.wast @@ -18,7 +18,7 @@ (export "dynCall_ffd" $dynCall_ffd) (export "dynCall_iii" $dynCall_iii) (table 5 5 anyfunc) - (elem $__wasm_nullptr $_Z5func1v $_Z5func2iii $_Z5func3fd $_Z5func4P8mystructS_) + (elem (i32.const 0) $__wasm_nullptr $_Z5func1v $_Z5func2iii $_Z5func3fd $_Z5func4P8mystructS_) (func $_Z5func1v (type $FUNCSIG$v) ) (func $_Z5func2iii (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index a324f42ba..49d63fa8c 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -43,7 +43,7 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index 127b7f77f..4f0513d28 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -42,7 +42,7 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts index 6822928b3..494915489 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_O2_hello_world.fromasm.imprecise.no-opts @@ -42,7 +42,7 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) (local $i2 i32) (local $i3 i32) diff --git a/test/emcc_O2_hello_world.fromasm.no-opts b/test/emcc_O2_hello_world.fromasm.no-opts index 6c6ad73c7..e75c5e4b2 100644 --- a/test/emcc_O2_hello_world.fromasm.no-opts +++ b/test/emcc_O2_hello_world.fromasm.no-opts @@ -43,7 +43,7 @@ (export "dynCall_iiii" $dynCall_iiii) (export "dynCall_vi" $dynCall_vi) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2) (func $_malloc (param $i1 i32) (result i32) (local $i2 i32) (local $i3 i32) diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 9d4993ec3..1ef3b9017 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -56,7 +56,7 @@ (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) (local $1 i32) (set_local $1 diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 6c9047895..13c8baec6 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -50,7 +50,7 @@ (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $0 i32) (result i32) (local $1 i32) (set_local $1 diff --git a/test/emcc_hello_world.fromasm.imprecise.no-opts b/test/emcc_hello_world.fromasm.imprecise.no-opts index 35e23d120..d8b887891 100644 --- a/test/emcc_hello_world.fromasm.imprecise.no-opts +++ b/test/emcc_hello_world.fromasm.imprecise.no-opts @@ -50,7 +50,7 @@ (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) (local $ret i32) (set_local $ret diff --git a/test/emcc_hello_world.fromasm.no-opts b/test/emcc_hello_world.fromasm.no-opts index 27409fe49..efa2de849 100644 --- a/test/emcc_hello_world.fromasm.no-opts +++ b/test/emcc_hello_world.fromasm.no-opts @@ -56,7 +56,7 @@ (export "dynCall_vi" $dynCall_vi) (export "___udivmoddi4" $___udivmoddi4) (table 18 18 anyfunc) - (elem $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) + (elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2) (func $stackAlloc (param $size i32) (result i32) (local $ret i32) (set_local $ret diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 6b766f173..42a5bfee1 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -18,7 +18,7 @@ BinaryenFloat64: 4 (import $an-imported "module" "base" (param i32 f64) (result f32)) (export "kitchen_sinker" "$kitchen()sinker") (table 1 1 anyfunc) - (elem "$kitchen()sinker") + (elem (i32.const 0) "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) (block $the-body @@ -1411,7 +1411,7 @@ int main() { (import $an-imported "module" "base" (param i32 f64) (result f32)) (export "kitchen_sinker" "$kitchen()sinker") (table 1 1 anyfunc) - (elem "$kitchen()sinker") + (elem (i32.const 0) "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) (block $the-body diff --git a/test/example/c-api-kitchen-sink.txt.txt b/test/example/c-api-kitchen-sink.txt.txt index feae7152c..7e32ba431 100644 --- a/test/example/c-api-kitchen-sink.txt.txt +++ b/test/example/c-api-kitchen-sink.txt.txt @@ -13,7 +13,7 @@ (import $an-imported "module" "base" (param i32 f64) (result f32)) (export "kitchen_sinker" "$kitchen()sinker") (table 1 1 anyfunc) - (elem "$kitchen()sinker") + (elem (i32.const 0) "$kitchen()sinker") (func "$kitchen()sinker" (type $iiIfF) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) (block $the-body diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index ee6b3ae68..c07cc247e 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -41,7 +41,7 @@ (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) (table 8 8 anyfunc) - (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index 458ab8f8f..5482b08f6 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -40,7 +40,7 @@ (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) (table 8 8 anyfunc) - (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $0 i32) (result i32) (local $1 i32) (local $2 i32) diff --git a/test/memorygrowth.fromasm.imprecise.no-opts b/test/memorygrowth.fromasm.imprecise.no-opts index c30a5933b..ddd73a5f8 100644 --- a/test/memorygrowth.fromasm.imprecise.no-opts +++ b/test/memorygrowth.fromasm.imprecise.no-opts @@ -40,7 +40,7 @@ (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) (table 8 8 anyfunc) - (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) (local $b i32) (local $c i32) diff --git a/test/memorygrowth.fromasm.no-opts b/test/memorygrowth.fromasm.no-opts index 3abed2662..c0a7307c5 100644 --- a/test/memorygrowth.fromasm.no-opts +++ b/test/memorygrowth.fromasm.no-opts @@ -41,7 +41,7 @@ (export "dynCall_vi" $mb) (export "__growWasmMemory" $__growWasmMemory) (table 8 8 anyfunc) - (elem $nb $Oa $ob $Va $Ua $Ra $pb $Sa) + (elem (i32.const 0) $nb $Oa $ob $Va $Ua $Ra $pb $Sa) (func $eb (param $a i32) (result i32) (local $b i32) (local $c i32) diff --git a/test/passes/dce.txt b/test/passes/dce.txt index 9c2836123..9ae5977b6 100644 --- a/test/passes/dce.txt +++ b/test/passes/dce.txt @@ -3,7 +3,7 @@ (type $ii (func (param i32 i32))) (type $1 (func)) (table 1 1 anyfunc) - (elem $call-me) + (elem (i32.const 0) $call-me) (func $call-me (type $ii) (param $0 i32) (param $1 i32) (nop) ) diff --git a/test/passes/duplicate-function-elimination.txt b/test/passes/duplicate-function-elimination.txt index 6c64b081c..a7511fc5c 100644 --- a/test/passes/duplicate-function-elimination.txt +++ b/test/passes/duplicate-function-elimination.txt @@ -39,7 +39,7 @@ (export "keep2" $keep2) (export "other" $keep2) (table 3 3 anyfunc) - (elem $keep2 $keep2 $caller) + (elem (i32.const 0) $keep2 $keep2 $caller) (func $keep2 (type $0) (nop) ) @@ -365,7 +365,7 @@ (memory 0) (type $T (func)) (table 2 2 anyfunc) - (elem $erase $erase) + (elem (i32.const 0) $erase $erase) (func $erase (type $T) (call_indirect $T (i32.const 0) @@ -376,7 +376,7 @@ (memory 0) (type $T (func)) (table 2 2 anyfunc) - (elem $keep2 $other) + (elem (i32.const 0) $keep2 $other) (func $keep2 (type $T) (call_indirect $T (i32.const 0) @@ -393,7 +393,7 @@ (type $T (func)) (type $S (func)) (table 2 2 anyfunc) - (elem $keep2 $other) + (elem (i32.const 0) $keep2 $other) (func $keep2 (type $T) (call_indirect $T (i32.const 0) diff --git a/test/passes/remove-unused-functions.txt b/test/passes/remove-unused-functions.txt index 6aa8e3265..cd819d347 100644 --- a/test/passes/remove-unused-functions.txt +++ b/test/passes/remove-unused-functions.txt @@ -4,7 +4,7 @@ (type $0 (func)) (export "exported" $exported) (table 1 1 anyfunc) - (elem $called_indirect) + (elem (i32.const 0) $called_indirect) (func $start (type $0) (call $called0) ) diff --git a/test/passes/remove-unused-names_merge-blocks.txt b/test/passes/remove-unused-names_merge-blocks.txt index ead2c99ca..88d284a5a 100644 --- a/test/passes/remove-unused-names_merge-blocks.txt +++ b/test/passes/remove-unused-names_merge-blocks.txt @@ -5,7 +5,7 @@ (type $iii (func (param i32 i32 i32))) (type $3 (func)) (table 1 1 anyfunc) - (elem $call-i) + (elem (i32.const 0) $call-i) (func $call-i (type $i) (param $0 i32) (nop) ) diff --git a/test/unit.fromasm b/test/unit.fromasm index e292f47ae..49189df43 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -16,7 +16,7 @@ (export "big_negative" $big_negative) (export "pick" $big_negative) (table 10 10 anyfunc) - (elem $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) + (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index ef3c09ff0..d2c10b549 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -12,7 +12,7 @@ (export "big_negative" $big_negative) (export "pick" $big_negative) (table 10 10 anyfunc) - (elem $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) + (elem (i32.const 0) $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) ) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index cde7eb176..7037a6c1c 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -12,7 +12,7 @@ (export "big_negative" $big_negative) (export "pick" $exportMe) (table 10 10 anyfunc) - (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) (set_local $temp diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index c0650ebd5..51ae345b9 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -16,7 +16,7 @@ (export "big_negative" $big_negative) (export "pick" $exportMe) (table 10 10 anyfunc) - (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) (set_local $temp diff --git a/test/unit.wast b/test/unit.wast index 30d16d1a2..2e21d44dd 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -14,7 +14,7 @@ (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) (table 10 anyfunc) - (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (type $FUNCSIG$v) (local $temp f64) (block $block0 diff --git a/test/unit.wast.fromBinary b/test/unit.wast.fromBinary index 4348394af..29d53598a 100644 --- a/test/unit.wast.fromBinary +++ b/test/unit.wast.fromBinary @@ -13,8 +13,8 @@ (import $import$1 "asm2wasm" "f64-to-int" (param f64) (result i32)) (import $import$2 "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) - (table 10 10 anyfunc) - (elem $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) + (table 10 anyfunc) + (elem (i32.const 0) $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (type $1) (local $var$0 f64) (block $label$0 -- cgit v1.2.3