diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 15:48:14 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 15:48:14 -0800 |
commit | 0b41a7d99f7652d607b14897e2ee963b28b6916e (patch) | |
tree | 52abaf68dab5b388523b4f52ae1d31a99263e7f4 | |
parent | 1d9bacd6187703e2dff43a09d034e4ac094b241c (diff) | |
download | binaryen-0b41a7d99f7652d607b14897e2ee963b28b6916e.tar.gz binaryen-0b41a7d99f7652d607b14897e2ee963b28b6916e.tar.bz2 binaryen-0b41a7d99f7652d607b14897e2ee963b28b6916e.zip |
parse switch in s2wasm
-rwxr-xr-x | auto_update_tests.py | 2 | ||||
-rwxr-xr-x | check.py | 2 | ||||
-rw-r--r-- | src/s2wasm.h | 9 | ||||
-rw-r--r-- | test/dot_s/cfg-stackify.wast | 607 | ||||
-rw-r--r-- | test/dot_s/switch.wast | 93 |
5 files changed, 711 insertions, 2 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index 69691aa07..fcceed4d1 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -32,7 +32,7 @@ for t in sorted(os.listdir('test')): open(t, 'w').write(actual) -for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s', 'signext-zeroext.s']: # TODO: 'relocation.s', 'inline-asm.s', 'switch.s', 'cfg-stackify.s' +for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s', 'signext-zeroext.s', 'cfg-stackify.s', 'switch.s']: # TODO: 'relocation.s', 'inline-asm.s' print '..', s wasm = s.replace('.s', '.wast') full = os.path.join('test', 'dot_s', s) @@ -214,7 +214,7 @@ for t in spec_tests: print '\n[ checking .s testcases... ]\n' -for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s', 'signext-zeroext.s']: # TODO: 'relocation.s', 'inline-asm.s', 'switch.s', 'cfg-stackify.s' +for s in ['minimal.s', 'basics.s', 'call.s', 'conv.s', 'fast-isel.s', 'i64.s', 'load.s', 'phi.s', 'select.s', 'unreachable.s', 'cpus.s', 'frem.s', 'immediates.s', 'load-store-i1.s', 'reg-stackify.s', 'unused-argument.s', 'comparisons_f32.s', 'dead-vreg.s', 'func.s', 'import.s', 'memory-addr32.s', 'store-results.s', 'varargs.s', 'comparisons_f64.s', 'exit.s', 'global.s', 'memory-addr64.s', 'returned.s', 'store.s', 'comparisons_i32.s', 'f32.s', 'globl.s', 'legalize.s', 'offset-folding.s', 'return-int32.s', 'store-trunc.s', 'comparisons_i64.s', 'f64.s', 'i32.s', 'load-ext.s', 'permute.s', 'return-void.s', 'signext-zeroext.s', 'cfg-stackify.s', 'switch.s']: # TODO: 'relocation.s', 'inline-asm.s' print '..', s wasm = s.replace('.s', '.wast') full = os.path.join('test', 'dot_s', s) diff --git a/src/s2wasm.h b/src/s2wasm.h index 8dac81b4c..a1805e659 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -695,6 +695,15 @@ private: curr->value = getInput(); } bstack.back()->list.push_back(curr); + } else if (match("tableswitch")) { + auto curr = allocator.alloc<Switch>(); + curr->value = getInput(); + skipComma(); + curr->default_ = getCommaSeparated(); + while (skipComma()) { + curr->targets.push_back(getCommaSeparated()); + } + bstack.back()->list.push_back(curr); } else if (match("unreachable")) { bstack.back()->list.push_back(allocator.alloc<Unreachable>()); } else if (match("memory_size")) { diff --git a/test/dot_s/cfg-stackify.wast b/test/dot_s/cfg-stackify.wast index 8f80df96a..2d70401ee 100644 --- a/test/dot_s/cfg-stackify.wast +++ b/test/dot_s/cfg-stackify.wast @@ -13,6 +13,15 @@ (export "ifelse_earlyexits" $ifelse_earlyexits) (export "doublediamond_in_a_loop" $doublediamond_in_a_loop) (export "test3" $test3) + (export "test4" $test4) + (export "test5" $test5) + (export "test6" $test6) + (export "test7" $test7) + (export "test8" $test8) + (export "test9" $test9) + (export "test10" $test10) + (export "test11" $test11) + (export "test12" $test12) (func $test0 (param $$0 i32) (local $$1 i32) (block $fake_return_waka123 @@ -474,4 +483,602 @@ ) ) ) + (func $test4 (param $$0 i32) + (block $fake_return_waka123 + (block + (block $BB13_8 + (block $BB13_7 + (block $BB13_4 + (br_if + (i32.gt_s + (i32.const 3) + (get_local $$0) + ) + $BB13_4 + ) + (block $BB13_3 + (br_if + (i32.eq + (i32.const 0) + (get_local $$0) + ) + $BB13_3 + ) + (br_if + (i32.ne + (i32.const 2) + (get_local $$0) + ) + $BB13_7 + ) + ) + (br $fake_return_waka123) + ) + (br_if + (i32.eq + (i32.const 4) + (get_local $$0) + ) + $BB13_8 + ) + (br_if + (i32.ne + (i32.const 622) + (get_local $$0) + ) + $BB13_7 + ) + (br $fake_return_waka123) + ) + (br $fake_return_waka123) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $test5 (param $$0 i32) (param $$1 i32) + (local $$2 i32) + (local $$3 i32) + (block $fake_return_waka123 + (block + (block $BB14_4 + (loop $BB14_3 $BB14_1 + (block + (set_local $$2 + (i32.const 0) + ) + (set_local $$3 + (i32.store align=4 + (get_local $$2) + (get_local $$2) + ) + ) + (set_local $$2 + (i32.const 1) + ) + (br_if + (i32.eq + (i32.and + (get_local $$2) + (get_local $$0) + ) + (i32.const 0) + ) + $BB14_4 + ) + (br_if + (i32.and + (i32.store align=4 + (get_local $$3) + (get_local $$2) + ) + (get_local $$1) + ) + $BB14_1 + ) + ) + ) + (i32.store align=4 + (get_local $$3) + (i32.const 3) + ) + (br $fake_return_waka123) + ) + (i32.store align=4 + (get_local $$3) + (i32.const 2) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $test6 (param $$0 i32) (param $$1 i32) + (local $$2 i32) + (local $$3 i32) + (local $$4 i32) + (block $fake_return_waka123 + (block + (block $BB15_6 + (block $BB15_5 + (loop $BB15_4 $BB15_1 + (block + (set_local $$2 + (i32.const 0) + ) + (i32.store align=4 + (get_local $$2) + (get_local $$2) + ) + (set_local $$3 + (i32.const 1) + ) + (br_if + (i32.eq + (i32.and + (get_local $$3) + (get_local $$0) + ) + (i32.const 0) + ) + $BB15_6 + ) + (i32.store align=4 + (get_local $$2) + (get_local $$3) + ) + (set_local $$4 + (i32.and + (get_local $$3) + (get_local $$1) + ) + ) + (br_if + (i32.eq + (i32.const 0) + (get_local $$4) + ) + $BB15_5 + ) + (i32.store align=4 + (get_local $$2) + (get_local $$3) + ) + (br_if + (get_local $$4) + $BB15_1 + ) + ) + ) + (i32.store align=4 + (get_local $$2) + (i32.const 2) + ) + (br $fake_return_waka123) + ) + (i32.store align=4 + (get_local $$2) + (i32.const 3) + ) + ) + (i32.store align=4 + (get_local $$2) + (i32.const 4) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $test7 (param $$0 i32) (param $$1 i32) + (local $$2 i32) + (local $$3 i32) + (block + (set_local $$3 + (i32.const 0) + ) + (set_local $$2 + (i32.store align=4 + (get_local $$3) + (get_local $$3) + ) + ) + (loop $BB16_5 $BB16_1 + (block + (set_local $$3 + (i32.store align=4 + (get_local $$2) + (i32.const 1) + ) + ) + (block $BB16_4 + (br_if + (i32.and + (get_local $$3) + (get_local $$0) + ) + $BB16_4 + ) + (i32.store align=4 + (get_local $$2) + (i32.const 2) + ) + (br_if + (i32.and + (get_local $$3) + (get_local $$1) + ) + $BB16_1 + ) + (i32.store align=4 + (get_local $$2) + (i32.const 4) + ) + (unreachable) + ) + (i32.store align=4 + (get_local $$2) + (i32.const 3) + ) + (br_if + (i32.and + (get_local $$3) + (get_local $$1) + ) + $BB16_1 + ) + ) + ) + (i32.store align=4 + (get_local $$2) + (i32.const 5) + ) + (unreachable) + ) + ) + (func $test8 (result i32) + (local $$0 i32) + (block + (set_local $$0 + (i32.const 0) + ) + (loop $BB17_4 $BB17_1 + (block + (block $BB17_3 + (br_if + (i32.eq + (i32.const 0) + (get_local $$0) + ) + $BB17_3 + ) + (br_if + (i32.eq + (i32.const 0) + (get_local $$0) + ) + $BB17_1 + ) + ) + (loop $BB17_4 $BB17_3 + (block + (br_if + (get_local $$0) + $BB17_3 + ) + (br $BB17_1) + ) + ) + ) + ) + ) + ) + (func $test9 + (local $$0 i32) + (local $$1 i32) + (block $fake_return_waka123 + (block + (set_local $$1 + (i32.const 0) + ) + (set_local $$0 + (i32.store align=4 + (get_local $$1) + (get_local $$1) + ) + ) + (loop $BB18_5 $BB18_1 + (block + (set_local $$1 + (i32.store align=4 + (get_local $$0) + (i32.const 1) + ) + ) + (br_if + (i32.eq + (i32.and + (get_local $$1) + (call $a) + ) + (i32.const 0) + ) + $BB18_5 + ) + (loop $BB18_5 $BB18_2 + (block + (i32.store align=4 + (get_local $$0) + (i32.const 2) + ) + (block $BB18_4 + (br_if + (i32.eq + (i32.and + (get_local $$1) + (call $a) + ) + (i32.const 0) + ) + $BB18_4 + ) + (i32.store align=4 + (get_local $$0) + (i32.const 3) + ) + (br_if + (i32.and + (get_local $$1) + (call $a) + ) + $BB18_2 + ) + (br $BB18_1) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 4) + ) + (br_if + (i32.and + (get_local $$1) + (call $a) + ) + $BB18_2 + ) + (br $BB18_1) + ) + ) + ) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 5) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $test10 + (local $$0 i32) + (local $$1 i32) + (local $$2 i32) + (local $$3 i32) + (local $$4 i32) + (block $fake_return_waka123 + (block + (set_local $$0 + (i32.const 2) + ) + (loop $BB19_7 $BB19_1 + (block + (set_local $$4 + (get_local $$1) + ) + (set_local $$3 + (get_local $$0) + ) + (set_local $$1 + (i32.const 0) + ) + (set_local $$0 + (i32.const 3) + ) + (set_local $$2 + (i32.const 4) + ) + (br_if + (get_local $$4) + $BB19_1 + ) + (block $BB19_6 + (loop $BB19_5 $BB19_2 + (block + (set_local $$4 + (get_local $$3) + ) + (set_local $$3 + (get_local $$2) + ) + (loop $BB19_5 $BB19_3 + (block + (set_local $$2 + (get_local $$4) + ) + (br_if + (i32.gt_u + (i32.const 4) + (get_local $$2) + ) + $BB19_1 + ) + (set_local $$4 + (get_local $$3) + ) + (tableswitch + (get_local $$2) + (table (case $BB19_3) (case $BB19_5) (case $BB19_1) (case $BB19_2) (case $BB19_6)) (case $BB19_3) + ) + ) + ) + ) + ) + (br $fake_return_waka123) + ) + (set_local $$1 + (i32.const 1) + ) + (br $BB19_1) + ) + ) + ) + ) + ) + (func $test11 + (local $$0 i32) + (block $fake_return_waka123 + (block + (set_local $$0 + (i32.const 0) + ) + (i32.store align=4 + (get_local $$0) + (get_local $$0) + ) + (block $BB20_8 + (block $BB20_7 + (block $BB20_6 + (block $BB20_4 + (br_if + (get_local $$0) + $BB20_4 + ) + (i32.store align=4 + (get_local $$0) + (i32.const 1) + ) + (block $BB20_3 + (br_if + (get_local $$0) + $BB20_3 + ) + (i32.store align=4 + (get_local $$0) + (i32.const 2) + ) + (br_if + (get_local $$0) + $BB20_6 + ) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 3) + ) + (br $fake_return_waka123) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 4) + ) + (br_if + (get_local $$0) + $BB20_8 + ) + (i32.store align=4 + (get_local $$0) + (i32.const 5) + ) + (br_if + (i32.eq + (i32.const 0) + (get_local $$0) + ) + $BB20_7 + ) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 7) + ) + (br $fake_return_waka123) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 6) + ) + (br $fake_return_waka123) + ) + (i32.store align=4 + (get_local $$0) + (i32.const 8) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $test12 (param $$0 i32) + (local $$1 i32) + (block $fake_return_waka123 + (block + (loop $BB21_8 $BB21_1 + (block + (set_local $$1 + (i32.load align=8 + (get_local $$0) + ) + ) + (block $BB21_7 + (block $BB21_6 + (block $BB21_4 + (br_if + (i32.gt_s + (i32.const 103) + (get_local $$1) + ) + $BB21_4 + ) + (br_if + (i32.eq + (i32.const 42) + (get_local $$1) + ) + $BB21_7 + ) + (br_if + (i32.eq + (i32.const 76) + (get_local $$1) + ) + $BB21_7 + ) + (br $BB21_6) + ) + (br_if + (i32.eq + (i32.const 108) + (get_local $$1) + ) + $BB21_7 + ) + (br_if + (i32.eq + (i32.const 104) + (get_local $$1) + ) + $BB21_7 + ) + ) + (br $fake_return_waka123) + ) + (set_local $$0 + (i32.add + (i32.const 1) + (get_local $$0) + ) + ) + (br $BB21_1) + ) + ) + ) + ) + ) ) diff --git a/test/dot_s/switch.wast b/test/dot_s/switch.wast new file mode 100644 index 000000000..7d97fbe57 --- /dev/null +++ b/test/dot_s/switch.wast @@ -0,0 +1,93 @@ +(module + (memory 0 4294967295) + (export "bar32" $bar32) + (export "bar64" $bar64) + (func $bar32 (param $$0 i32) + (block $fake_return_waka123 + (block + (block $BB0_8 + (br_if + (i32.gt_u + (i32.const 23) + (get_local $$0) + ) + $BB0_8 + ) + (block $BB0_7 + (block $BB0_6 + (block $BB0_5 + (block $BB0_4 + (block $BB0_3 + (block $BB0_2 + (tableswitch + (get_local $$0) + (table (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_2) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_3) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_4) (case $BB0_5) (case $BB0_6) (case $BB0_7)) (case $BB0_2) + ) + ) + (call $foo0) + (br $BB0_8) + ) + (call $foo1) + (br $BB0_8) + ) + (call $foo2) + (br $BB0_8) + ) + (call $foo3) + (br $BB0_8) + ) + (call $foo4) + (br $BB0_8) + ) + (call $foo5) + ) + (br $fake_return_waka123) + ) + ) + ) + (func $bar64 (param $$0 i64) + (block $fake_return_waka123 + (block + (block $BB1_8 + (br_if + (i64.gt_u + (i64.const 23) + (get_local $$0) + ) + $BB1_8 + ) + (block $BB1_7 + (block $BB1_6 + (block $BB1_5 + (block $BB1_4 + (block $BB1_3 + (block $BB1_2 + (tableswitch + (i32.wrap/i64 + (get_local $$0) + ) + (table (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_2) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_3) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_4) (case $BB1_5) (case $BB1_6) (case $BB1_7)) (case $BB1_2) + ) + ) + (call $foo0) + (br $BB1_8) + ) + (call $foo1) + (br $BB1_8) + ) + (call $foo2) + (br $BB1_8) + ) + (call $foo3) + (br $BB1_8) + ) + (call $foo4) + (br $BB1_8) + ) + (call $foo5) + ) + (br $fake_return_waka123) + ) + ) + ) +) |