diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-02-01 10:39:27 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-02-01 10:48:06 -0800 |
commit | 27bdda2e01d83a5b4023a729ed2a427f1ee9fe41 (patch) | |
tree | eb1524591ec46122553cfc1b4aabd67339059032 | |
parent | d7e7328addef046ef103837e24e6df40645f4040 (diff) | |
download | binaryen-27bdda2e01d83a5b4023a729ed2a427f1ee9fe41.tar.gz binaryen-27bdda2e01d83a5b4023a729ed2a427f1ee9fe41.tar.bz2 binaryen-27bdda2e01d83a5b4023a729ed2a427f1ee9fe41.zip |
fix call_indirect s2wasm parsing order #162
-rw-r--r-- | src/s2wasm.h | 14 | ||||
-rw-r--r-- | test/dot_s/bcp-1.s | 424 | ||||
-rw-r--r-- | test/dot_s/bcp-1.wast | 393 |
3 files changed, 822 insertions, 9 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index f1cc89586..8b6aabeb7 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -671,16 +671,12 @@ class S2WasmBuilder { // indirect call auto indirect = allocator.alloc<CallIndirect>(); Name assign = getAssign(); - indirect->target = getInput(); + int num = getNumInputs(); + auto inputs = getInputs(num); + indirect->target = inputs[0]; indirect->type = type; - skipWhitespace(); - if (*s == ',') { - skipComma(); - int num = getNumInputs(); - auto inputs = getInputs(num); - for (int i = 0; i < num; i++) { - indirect->operands.push_back(inputs[i]); - } + for (int i = 1; i < num; i++) { + indirect->operands.push_back(inputs[i]); } setOutput(indirect, assign); auto typeName = cashew::IString((std::string("FUNCSIG_") + getSig(indirect)).c_str(), false); diff --git a/test/dot_s/bcp-1.s b/test/dot_s/bcp-1.s new file mode 100644 index 000000000..c27542eef --- /dev/null +++ b/test/dot_s/bcp-1.s @@ -0,0 +1,424 @@ + .text + .file "/b/build/slave/linux/build/src/src/work/gcc/gcc/testsuite/gcc.c-torture/execute/bcp-1.c" + .section .text.bad0,"ax",@progbits + .hidden bad0 + .globl bad0 + .type bad0,@function +bad0: # @bad0 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end0: + .size bad0, .Lfunc_end0-bad0 + + .section .text.bad1,"ax",@progbits + .hidden bad1 + .globl bad1 + .type bad1,@function +bad1: # @bad1 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end1: + .size bad1, .Lfunc_end1-bad1 + + .section .text.bad2,"ax",@progbits + .hidden bad2 + .globl bad2 + .type bad2,@function +bad2: # @bad2 + .param i32 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end2: + .size bad2, .Lfunc_end2-bad2 + + .section .text.bad3,"ax",@progbits + .hidden bad3 + .globl bad3 + .type bad3,@function +bad3: # @bad3 + .param i32 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end3: + .size bad3, .Lfunc_end3-bad3 + + .section .text.bad4,"ax",@progbits + .hidden bad4 + .globl bad4 + .type bad4,@function +bad4: # @bad4 + .param i32 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end4: + .size bad4, .Lfunc_end4-bad4 + + .section .text.bad5,"ax",@progbits + .hidden bad5 + .globl bad5 + .type bad5,@function +bad5: # @bad5 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end5: + .size bad5, .Lfunc_end5-bad5 + + .section .text.bad6,"ax",@progbits + .hidden bad6 + .globl bad6 + .type bad6,@function +bad6: # @bad6 + .param i32 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end6: + .size bad6, .Lfunc_end6-bad6 + + .section .text.bad7,"ax",@progbits + .hidden bad7 + .globl bad7 + .type bad7,@function +bad7: # @bad7 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end7: + .size bad7, .Lfunc_end7-bad7 + + .section .text.bad8,"ax",@progbits + .hidden bad8 + .globl bad8 + .type bad8,@function +bad8: # @bad8 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end8: + .size bad8, .Lfunc_end8-bad8 + + .section .text.bad9,"ax",@progbits + .hidden bad9 + .globl bad9 + .type bad9,@function +bad9: # @bad9 + .param i32 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end9: + .size bad9, .Lfunc_end9-bad9 + + .section .text.bad10,"ax",@progbits + .hidden bad10 + .globl bad10 + .type bad10,@function +bad10: # @bad10 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end10: + .size bad10, .Lfunc_end10-bad10 + + .section .text.good0,"ax",@progbits + .hidden good0 + .globl good0 + .type good0,@function +good0: # @good0 + .result i32 +# BB#0: # %entry + i32.const $push0=, 1 + return $pop0 + .endfunc +.Lfunc_end11: + .size good0, .Lfunc_end11-good0 + + .section .text.good1,"ax",@progbits + .hidden good1 + .globl good1 + .type good1,@function +good1: # @good1 + .result i32 +# BB#0: # %entry + i32.const $push0=, 1 + return $pop0 + .endfunc +.Lfunc_end12: + .size good1, .Lfunc_end12-good1 + + .section .text.good2,"ax",@progbits + .hidden good2 + .globl good2 + .type good2,@function +good2: # @good2 + .result i32 +# BB#0: # %entry + i32.const $push0=, 1 + return $pop0 + .endfunc +.Lfunc_end13: + .size good2, .Lfunc_end13-good2 + + .section .text.opt0,"ax",@progbits + .hidden opt0 + .globl opt0 + .type opt0,@function +opt0: # @opt0 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end14: + .size opt0, .Lfunc_end14-opt0 + + .section .text.opt1,"ax",@progbits + .hidden opt1 + .globl opt1 + .type opt1,@function +opt1: # @opt1 + .result i32 +# BB#0: # %entry + i32.const $push0=, 0 + return $pop0 + .endfunc +.Lfunc_end15: + .size opt1, .Lfunc_end15-opt1 + + .section .text.opt2,"ax",@progbits + .hidden opt2 + .globl opt2 + .type opt2,@function +opt2: # @opt2 + .result i32 +# BB#0: # %entry + i32.const $push0=, 1 + return $pop0 + .endfunc +.Lfunc_end16: + .size opt2, .Lfunc_end16-opt2 + + .section .text.main,"ax",@progbits + .hidden main + .globl main + .type main,@function +main: # @main + .result i32 + .local i32, i32, i32 +# BB#0: # %entry + i32.const $0=, 0 + block + i32.load $push0=, bad_t0($0) + i32.call_indirect $push1=, $pop0 + br_if $pop1, 0 # 0: down to label0 +# BB#1: # %for.cond + i32.load $push2=, bad_t0+4($0) + i32.call_indirect $push3=, $pop2 + br_if $pop3, 0 # 0: down to label0 +# BB#2: # %for.cond.1 + i32.load $push4=, bad_t0+8($0) + i32.call_indirect $push5=, $pop4 + br_if $pop5, 0 # 0: down to label0 +# BB#3: # %for.cond.2 + i32.load $push6=, bad_t0+12($0) + i32.call_indirect $push7=, $pop6 + br_if $pop7, 0 # 0: down to label0 +# BB#4: # %for.cond.3 + i32.load $push8=, bad_t0+16($0) + i32.call_indirect $push9=, $pop8 + br_if $pop9, 0 # 0: down to label0 +# BB#5: # %for.cond.4 + i32.load $push10=, bad_t0+20($0) + i32.call_indirect $push11=, $pop10 + br_if $pop11, 0 # 0: down to label0 +# BB#6: # %for.cond.5 + i32.load $1=, bad_t1($0) + i32.const $2=, 1 + block + i32.call_indirect $push12=, $1, $2 + br_if $pop12, 0 # 0: down to label1 +# BB#7: # %for.cond1 + i32.load $push13=, bad_t1+4($0) + i32.call_indirect $push14=, $pop13, $2 + br_if $pop14, 0 # 0: down to label1 +# BB#8: # %for.cond1.1 + i32.load $push15=, bad_t1+8($0) + i32.call_indirect $push16=, $pop15, $2 + br_if $pop16, 0 # 0: down to label1 +# BB#9: # %for.cond1.2 + i32.load $1=, bad_t2($0) + i32.const $2=, .L.str + block + i32.call_indirect $push17=, $1, $2 + br_if $pop17, 0 # 0: down to label2 +# BB#10: # %for.cond12 + i32.load $push18=, bad_t2+4($0) + i32.call_indirect $push19=, $pop18, $2 + br_if $pop19, 0 # 0: down to label2 +# BB#11: # %for.cond12.1 + block + i32.load $push20=, good_t0($0) + i32.call_indirect $push21=, $pop20 + i32.const $push32=, 0 + i32.eq $push33=, $pop21, $pop32 + br_if $pop33, 0 # 0: down to label3 +# BB#12: # %for.cond23 + i32.load $push22=, good_t0+4($0) + i32.call_indirect $push23=, $pop22 + i32.const $push34=, 0 + i32.eq $push35=, $pop23, $pop34 + br_if $pop35, 0 # 0: down to label3 +# BB#13: # %for.cond23.1 + i32.load $push24=, good_t0+8($0) + i32.call_indirect $push25=, $pop24 + i32.const $push36=, 0 + i32.eq $push37=, $pop25, $pop36 + br_if $pop37, 0 # 0: down to label3 +# BB#14: # %for.cond23.2 + block + i32.load $push26=, opt_t0($0) + i32.call_indirect $push27=, $pop26 + i32.const $push38=, 0 + i32.eq $push39=, $pop27, $pop38 + br_if $pop39, 0 # 0: down to label4 +# BB#15: # %for.cond34 + i32.load $push28=, opt_t0+4($0) + i32.call_indirect $push29=, $pop28 + i32.const $push40=, 0 + i32.eq $push41=, $pop29, $pop40 + br_if $pop41, 0 # 0: down to label4 +# BB#16: # %for.cond34.1 + i32.load $push30=, opt_t0+8($0) + i32.call_indirect $push31=, $pop30 + i32.const $push42=, 0 + i32.eq $push43=, $pop31, $pop42 + br_if $pop43, 0 # 0: down to label4 +# BB#17: # %for.cond34.2 + call exit@FUNCTION, $0 + unreachable +.LBB17_18: # %if.then40 + end_block # label4: + call abort@FUNCTION + unreachable +.LBB17_19: # %if.then29 + end_block # label3: + call abort@FUNCTION + unreachable +.LBB17_20: # %if.then18 + end_block # label2: + call abort@FUNCTION + unreachable +.LBB17_21: # %if.then7 + end_block # label1: + call abort@FUNCTION + unreachable +.LBB17_22: # %if.then + end_block # label0: + call abort@FUNCTION + unreachable + .endfunc +.Lfunc_end17: + .size main, .Lfunc_end17-main + + .hidden bad_t0 # @bad_t0 + .type bad_t0,@object + .section .data.bad_t0,"aw",@progbits + .globl bad_t0 + .align 4 +bad_t0: + .int32 bad0@FUNCTION + .int32 bad1@FUNCTION + .int32 bad5@FUNCTION + .int32 bad7@FUNCTION + .int32 bad8@FUNCTION + .int32 bad10@FUNCTION + .size bad_t0, 24 + + .hidden bad_t1 # @bad_t1 + .type bad_t1,@object + .section .data.bad_t1,"aw",@progbits + .globl bad_t1 + .align 2 +bad_t1: + .int32 bad2@FUNCTION + .int32 bad3@FUNCTION + .int32 bad6@FUNCTION + .size bad_t1, 12 + + .hidden bad_t2 # @bad_t2 + .type bad_t2,@object + .section .data.bad_t2,"aw",@progbits + .globl bad_t2 + .align 2 +bad_t2: + .int32 bad4@FUNCTION + .int32 bad9@FUNCTION + .size bad_t2, 8 + + .hidden good_t0 # @good_t0 + .type good_t0,@object + .section .data.good_t0,"aw",@progbits + .globl good_t0 + .align 2 +good_t0: + .int32 good0@FUNCTION + .int32 good1@FUNCTION + .int32 good2@FUNCTION + .size good_t0, 12 + + .hidden opt_t0 # @opt_t0 + .type opt_t0,@object + .section .data.opt_t0,"aw",@progbits + .globl opt_t0 + .align 2 +opt_t0: + .int32 opt0@FUNCTION + .int32 opt1@FUNCTION + .int32 opt2@FUNCTION + .size opt_t0, 12 + + .type .L.str,@object # @.str + .section .rodata.str1.1,"aMS",@progbits,1 +.L.str: + .asciz "hi" + .size .L.str, 3 + + .hidden global # @global + .type global,@object + .section .bss.global,"aw",@nobits + .globl global + .align 2 +global: + .int32 0 # 0x0 + .size global, 4 + + + .ident "clang version 3.9.0 " diff --git a/test/dot_s/bcp-1.wast b/test/dot_s/bcp-1.wast new file mode 100644 index 000000000..af8cc92ec --- /dev/null +++ b/test/dot_s/bcp-1.wast @@ -0,0 +1,393 @@ +(module + (memory 104 4294967295 + (segment 16 "\00\00\00\00\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00\05\00\00\00") + (segment 40 "\06\00\00\00\07\00\00\00\08\00\00\00") + (segment 52 "\t\00\00\00\n\00\00\00") + (segment 60 "\0b\00\00\00\0c\00\00\00\0d\00\00\00") + (segment 72 "\0e\00\00\00\0f\00\00\00\10\00\00\00") + (segment 96 "hi\00") + (segment 100 "\00\00\00\00") + ) + (type $FUNCSIG_i (func (result i32))) + (type $FUNCSIG_ii (func (param i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$v (func)) + (import $exit "env" "exit" (param i32)) + (import $abort "env" "abort") + (export "bad0" $bad0) + (export "bad1" $bad1) + (export "bad2" $bad2) + (export "bad3" $bad3) + (export "bad4" $bad4) + (export "bad5" $bad5) + (export "bad6" $bad6) + (export "bad7" $bad7) + (export "bad8" $bad8) + (export "bad9" $bad9) + (export "bad10" $bad10) + (export "good0" $good0) + (export "good1" $good1) + (export "good2" $good2) + (export "opt0" $opt0) + (export "opt1" $opt1) + (export "opt2" $opt2) + (export "main" $main) + (table $bad0 $bad1 $bad5 $bad7 $bad8 $bad10 $bad2 $bad3 $bad6 $bad4 $bad9 $good0 $good1 $good2 $opt0 $opt1 $opt2) + (func $bad0 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad1 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad2 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad3 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad4 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad5 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad6 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad7 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad8 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad9 (param $$0 i32) (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $bad10 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $good0 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 1) + ) + ) + ) + ) + (func $good1 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 1) + ) + ) + ) + ) + (func $good2 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 1) + ) + ) + ) + ) + (func $opt0 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $opt1 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 0) + ) + ) + ) + ) + (func $opt2 (result i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.const 1) + ) + ) + ) + ) + (func $main (result i32) + (local $$0 i32) + (local $$1 i32) + (local $$2 i32) + (set_local $$0 + (i32.const 0) + ) + (block $label$0 + (br_if + (call_indirect $FUNCSIG_i + (i32.load offset=16 align=4 + (get_local $$0) + ) + ) + $label$0 + ) + (br_if + (call_indirect $FUNCSIG_i + (i32.load offset=20 align=4 + (get_local $$0) + ) + ) + $label$0 + ) + (br_if + (call_indirect $FUNCSIG_i + (i32.load offset=24 align=4 + (get_local $$0) + ) + ) + $label$0 + ) + (br_if + (call_indirect $FUNCSIG_i + (i32.load offset=28 align=4 + (get_local $$0) + ) + ) + $label$0 + ) + (br_if + (call_indirect $FUNCSIG_i + (i32.load offset=32 align=4 + (get_local $$0) + ) + ) + $label$0 + ) + (br_if + (call_indirect $FUNCSIG_i + (i32.load offset=36 align=4 + (get_local $$0) + ) + ) + $label$0 + ) + (set_local $$1 + (i32.load offset=40 align=4 + (get_local $$0) + ) + ) + (set_local $$2 + (i32.const 1) + ) + (block $label$1 + (br_if + (call_indirect $FUNCSIG_ii + (get_local $$1) + (get_local $$2) + ) + $label$1 + ) + (br_if + (call_indirect $FUNCSIG_ii + (i32.load offset=44 align=4 + (get_local $$0) + ) + (get_local $$2) + ) + $label$1 + ) + (br_if + (call_indirect $FUNCSIG_ii + (i32.load offset=48 align=4 + (get_local $$0) + ) + (get_local $$2) + ) + $label$1 + ) + (set_local $$1 + (i32.load offset=52 align=4 + (get_local $$0) + ) + ) + (set_local $$2 + (i32.const 96) + ) + (block $label$2 + (br_if + (call_indirect $FUNCSIG_ii + (get_local $$1) + (get_local $$2) + ) + $label$2 + ) + (br_if + (call_indirect $FUNCSIG_ii + (i32.load offset=56 align=4 + (get_local $$0) + ) + (get_local $$2) + ) + $label$2 + ) + (block $label$3 + (br_if + (i32.eq + (call_indirect $FUNCSIG_i + (i32.load offset=60 align=4 + (get_local $$0) + ) + ) + (i32.const 0) + ) + $label$3 + ) + (br_if + (i32.eq + (call_indirect $FUNCSIG_i + (i32.load offset=64 align=4 + (get_local $$0) + ) + ) + (i32.const 0) + ) + $label$3 + ) + (br_if + (i32.eq + (call_indirect $FUNCSIG_i + (i32.load offset=68 align=4 + (get_local $$0) + ) + ) + (i32.const 0) + ) + $label$3 + ) + (block $label$4 + (br_if + (i32.eq + (call_indirect $FUNCSIG_i + (i32.load offset=72 align=4 + (get_local $$0) + ) + ) + (i32.const 0) + ) + $label$4 + ) + (br_if + (i32.eq + (call_indirect $FUNCSIG_i + (i32.load offset=76 align=4 + (get_local $$0) + ) + ) + (i32.const 0) + ) + $label$4 + ) + (br_if + (i32.eq + (call_indirect $FUNCSIG_i + (i32.load offset=80 align=4 + (get_local $$0) + ) + ) + (i32.const 0) + ) + $label$4 + ) + (call_import $exit + (get_local $$0) + ) + (unreachable) + ) + (call_import $abort) + (unreachable) + ) + (call_import $abort) + (unreachable) + ) + (call_import $abort) + (unreachable) + ) + (call_import $abort) + (unreachable) + ) + (call_import $abort) + (unreachable) + ) +) +;; METADATA: { "asmConsts": {},"staticBump": 103 } |