diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/help/wasm-wast.txt | 1 | ||||
-rw-r--r-- | test/roundtrip/fold-basic.txt | 70 | ||||
-rw-r--r-- | test/roundtrip/fold-block.txt | 105 | ||||
-rw-r--r-- | test/roundtrip/fold-call.txt | 69 | ||||
-rw-r--r-- | test/roundtrip/fold-fac.txt | 60 | ||||
-rw-r--r-- | test/roundtrip/fold-getset-global.txt | 41 | ||||
-rw-r--r-- | test/roundtrip/fold-getset-local.txt | 66 | ||||
-rw-r--r-- | test/roundtrip/fold-load-store.txt | 59 | ||||
-rw-r--r-- | test/roundtrip/fold-nop.txt | 17 | ||||
-rw-r--r-- | test/roundtrip/fold-unreachable.txt | 54 | ||||
-rw-r--r-- | test/roundtrip/generate-if-label-names.txt | 10 | ||||
-rwxr-xr-x | test/run-roundtrip.py | 2 | ||||
-rwxr-xr-x | test/run-tests.py | 13 |
13 files changed, 559 insertions, 8 deletions
diff --git a/test/help/wasm-wast.txt b/test/help/wasm-wast.txt index 1da862da..21a8c994 100644 --- a/test/help/wasm-wast.txt +++ b/test/help/wasm-wast.txt @@ -17,6 +17,7 @@ options: -v, --verbose use multiple times for more info -h, --help print this help message -o, --output=FILENAME output file for the generated wast file, by default use stdout + -f, --fold-exprs Write folded expressions where possible --no-debug-names Ignore debug names in the binary file --generate-names Give auto-generated names to non-named functions, types, etc. ;;; STDOUT ;;) diff --git a/test/roundtrip/fold-basic.txt b/test/roundtrip/fold-basic.txt new file mode 100644 index 00000000..f0f0bff3 --- /dev/null +++ b/test/roundtrip/fold-basic.txt @@ -0,0 +1,70 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs +(module + (func $fold-binary (result i32) + i32.const 1 + i32.const 2 + i32.add) + + (func $fold-binary-chain (result i32) + i32.const 1 + i32.const 1 + i32.const 1 + i32.add + i32.sub) + + (func $fold-compare (result i32) + f32.const 1 + f32.const 2 + f32.le) + + (func $fold-unary (result f32) + f32.const 1 + f32.neg + f32.neg) + + (func $fold-convert (result i64) + f64.const 0 + f32.demote/f64 + i32.trunc_s/f32 + i64.extend_s/i32) + + (func $fold-select (result f32) + f32.const 1 + f32.const 2 + i32.const 3 + select)) +(;; STDOUT ;;; +(module + (type (;0;) (func (result i32))) + (type (;1;) (func (result f32))) + (type (;2;) (func (result i64))) + (func (;0;) (type 0) (result i32) + (i32.add + (i32.const 1) + (i32.const 2))) + (func (;1;) (type 0) (result i32) + (i32.sub + (i32.const 1) + (i32.add + (i32.const 1) + (i32.const 1)))) + (func (;2;) (type 0) (result i32) + (f32.le + (f32.const 0x1p+0 (;=1;)) + (f32.const 0x1p+1 (;=2;)))) + (func (;3;) (type 1) (result f32) + (f32.neg + (f32.neg + (f32.const 0x1p+0 (;=1;))))) + (func (;4;) (type 2) (result i64) + (i64.extend_s/i32 + (i32.trunc_s/f32 + (f32.demote/f64 + (f64.const 0x0p+0 (;=0;)))))) + (func (;5;) (type 1) (result f32) + (select + (f32.const 0x1p+0 (;=1;)) + (f32.const 0x1p+1 (;=2;)) + (i32.const 3)))) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-block.txt b/test/roundtrip/fold-block.txt new file mode 100644 index 00000000..a2f84d08 --- /dev/null +++ b/test/roundtrip/fold-block.txt @@ -0,0 +1,105 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs --debug-names +(module + (func $fold-block (result f32) + f32.const 2 + block + f32.const 3 + br 0 + end + f32.const 1 + f32.add) + + (func $fold-block-br-value (result i32) + block i32 + i32.const 1 + br 0 + end) + + (func $fold-loop + loop i64 + br 0 + i64.const 1 + end + drop) + + (func $fold-loop-br (result i32) + loop i32 + i32.const 1 + br 0 + end) + + (func $fold-if + i32.const 1 + if + nop + nop + end) + + (func $fold-if-else + i32.const 1 + if i32 + i32.const 2 + else + i32.const 3 + end + drop) + + (func $fold-if-else-br + i32.const 1 + if i32 + i32.const 2 + br 0 + else + i32.const 3 + end + drop)) +(;; STDOUT ;;; +(module + (type (;0;) (func (result f32))) + (type (;1;) (func (result i32))) + (type (;2;) (func)) + (func $fold-block (type 0) (result f32) + (f32.const 0x1p+1 (;=2;)) + (block ;; label = @1 + (f32.const 0x1.8p+1 (;=3;)) + (br 0 (;@1;))) + (f32.const 0x1p+0 (;=1;)) + (f32.add)) + (func $fold-block-br-value (type 1) (result i32) + (block i32 ;; label = @1 + (br 0 (;@1;) + (i32.const 1)))) + (func $fold-loop (type 2) + (drop + (loop i64 ;; label = @1 + (br 0 (;@1;)) + (i64.const 1)))) + (func $fold-loop-br (type 1) (result i32) + (loop i32 ;; label = @1 + (i32.const 1) + (br 0 (;@1;)))) + (func $fold-if (type 2) + (if ;; label = @1 + (i32.const 1) + (then + (nop) + (nop)))) + (func $fold-if-else (type 2) + (drop + (if i32 ;; label = @1 + (i32.const 1) + (then + (i32.const 2)) + (else + (i32.const 3))))) + (func $fold-if-else-br (type 2) + (drop + (if i32 ;; label = @1 + (i32.const 1) + (then + (br 0 (;@1;) + (i32.const 2))) + (else + (i32.const 3)))))) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-call.txt b/test/roundtrip/fold-call.txt new file mode 100644 index 00000000..73c72cc0 --- /dev/null +++ b/test/roundtrip/fold-call.txt @@ -0,0 +1,69 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs +(module + (type $i_i (func (param i32) (result i32))) + + (func $i_i (type $i_i) + i32.const 1) + + (func $if_f (param i32 f32) (result f32) + f32.const 0) + + (func $ffff_v (param f32 f32 f32 f32)) + + (func $fold-call (result i32) + i32.const 1 + call $i_i + drop + i32.const 2 + call $i_i) + + (func $fold-call-2 + f32.const 0 + f32.const 1 + f32.const 2 + i32.const 3 + f32.const 4 + call $if_f + call $ffff_v) + + (table anyfunc (elem $i_i $if_f)) + (func $fold-call-indirect (result i32) + i32.const 1 + i32.const 2 + call_indirect $i_i) +) + +(;; STDOUT ;;; +(module + (type (;0;) (func (param i32) (result i32))) + (type (;1;) (func (param i32 f32) (result f32))) + (type (;2;) (func (param f32 f32 f32 f32))) + (type (;3;) (func (result i32))) + (type (;4;) (func)) + (func (;0;) (type 0) (param i32) (result i32) + (i32.const 1)) + (func (;1;) (type 1) (param i32 f32) (result f32) + (f32.const 0x0p+0 (;=0;))) + (func (;2;) (type 2) (param f32 f32 f32 f32)) + (func (;3;) (type 3) (result i32) + (drop + (call 0 + (i32.const 1))) + (call 0 + (i32.const 2))) + (func (;4;) (type 4) + (call 2 + (f32.const 0x0p+0 (;=0;)) + (f32.const 0x1p+0 (;=1;)) + (f32.const 0x1p+1 (;=2;)) + (call 1 + (i32.const 3) + (f32.const 0x1p+2 (;=4;))))) + (func (;5;) (type 3) (result i32) + (call_indirect 0 + (i32.const 1) + (i32.const 2))) + (table (;0;) 2 2 anyfunc) + (elem (i32.const 0) 0 1)) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-fac.txt b/test/roundtrip/fold-fac.txt new file mode 100644 index 00000000..a41f822b --- /dev/null +++ b/test/roundtrip/fold-fac.txt @@ -0,0 +1,60 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs --debug-names --generate-names +(module + (func $fac-stack-raw (param $n i64) (result i64) + (local $i i64) + (local $res i64) + get_local $n + set_local $i + i64.const 1 + set_local $res + block $done + loop $loop + get_local $i + i64.const 0 + i64.eq + if $body + br $done + else $body + get_local $i + get_local $res + i64.mul + set_local $res + get_local $i + i64.const 1 + i64.sub + set_local $i + end $body + br $loop + end $loop + end $done + get_local $res)) +(;; STDOUT ;;; +(module + (type $t0 (func (param i64) (result i64))) + (func $fac-stack-raw (type $t0) (param $n i64) (result i64) + (local $i i64) (local $res i64) + (set_local $i + (get_local $n)) + (set_local $res + (i64.const 1)) + (block $B0 + (loop $L1 + (if $I2 + (i64.eq + (get_local $i) + (i64.const 0)) + (then + (br $B0)) + (else + (set_local $res + (i64.mul + (get_local $i) + (get_local $res))) + (set_local $i + (i64.sub + (get_local $i) + (i64.const 1))))) + (br $L1))) + (get_local $res))) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-getset-global.txt b/test/roundtrip/fold-getset-global.txt new file mode 100644 index 00000000..c5005019 --- /dev/null +++ b/test/roundtrip/fold-getset-global.txt @@ -0,0 +1,41 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs +(module + (global i32 (i32.const 1)) + (global f32 (f32.const 1.5)) + + (func $fold-get-global (result i32) + get_global 1 + drop + get_global 0 + get_global 0 + i32.mul) + + (func $fold-set-global + get_global 0 + i32.const 1 + i32.add + set_global 0 + f32.const 2 + set_global 1) +) +(;; STDOUT ;;; +(module + (type (;0;) (func (result i32))) + (type (;1;) (func)) + (func (;0;) (type 0) (result i32) + (drop + (get_global 1)) + (i32.mul + (get_global 0) + (get_global 0))) + (func (;1;) (type 1) + (set_global 0 + (i32.add + (get_global 0) + (i32.const 1))) + (set_global 1 + (f32.const 0x1p+1 (;=2;)))) + (global (;0;) i32 (i32.const 1)) + (global (;1;) f32 (f32.const 0x1.8p+0 (;=1.5;)))) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-getset-local.txt b/test/roundtrip/fold-getset-local.txt new file mode 100644 index 00000000..31230efd --- /dev/null +++ b/test/roundtrip/fold-getset-local.txt @@ -0,0 +1,66 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs +(module + (func $fold-get-local (result f32) + (local f32 f32 f64 f64) + get_local 0 + get_local 1 + f32.add + get_local 2 + get_local 3 + f64.add + f32.demote/f64 + f32.add) + + (func $fold-set-local + (local i64 i32) + i64.const 1 + i64.const 2 + i64.const 3 + i64.xor + i64.xor + set_local 0 + i32.const 4 + set_local 1) + + (func $fold-tee-local (result i32) + (local i32 i32) + i32.const 1 + tee_local 0 + i32.const 2 + tee_local 1 + i32.add) + ) +(;; STDOUT ;;; +(module + (type (;0;) (func (result f32))) + (type (;1;) (func)) + (type (;2;) (func (result i32))) + (func (;0;) (type 0) (result f32) + (local f32 f32 f64 f64) + (f32.add + (f32.add + (get_local 0) + (get_local 1)) + (f32.demote/f64 + (f64.add + (get_local 2) + (get_local 3))))) + (func (;1;) (type 1) + (local i64 i32) + (set_local 0 + (i64.xor + (i64.const 1) + (i64.xor + (i64.const 2) + (i64.const 3)))) + (set_local 1 + (i32.const 4))) + (func (;2;) (type 2) (result i32) + (local i32 i32) + (i32.add + (tee_local 0 + (i32.const 1)) + (tee_local 1 + (i32.const 2))))) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-load-store.txt b/test/roundtrip/fold-load-store.txt new file mode 100644 index 00000000..108dd27f --- /dev/null +++ b/test/roundtrip/fold-load-store.txt @@ -0,0 +1,59 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs +(module + (memory 1) + (func $fold-load + i32.const 1 + i32.load + drop + i32.const 2 + i32.load + drop) + + (func $fold-store + i32.const 1 + i32.load + f32.const 2 + f32.store) + + (func $fold-current-memory (result i32) + current_memory + i32.const 1 + i32.add + drop + i32.const 2) + + (func $fold-grow-memory (result i32) + i32.const 1 + i32.const 2 + grow_memory + i32.lt_s)) +(;; STDOUT ;;; +(module + (type (;0;) (func)) + (type (;1;) (func (result i32))) + (func (;0;) (type 0) + (drop + (i32.load + (i32.const 1))) + (drop + (i32.load + (i32.const 2)))) + (func (;1;) (type 0) + (f32.store + (i32.load + (i32.const 1)) + (f32.const 0x1p+1 (;=2;)))) + (func (;2;) (type 1) (result i32) + (drop + (i32.add + (current_memory) + (i32.const 1))) + (i32.const 2)) + (func (;3;) (type 1) (result i32) + (i32.lt_s + (i32.const 1) + (grow_memory + (i32.const 2)))) + (memory (;0;) 1)) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-nop.txt b/test/roundtrip/fold-nop.txt new file mode 100644 index 00000000..197312e2 --- /dev/null +++ b/test/roundtrip/fold-nop.txt @@ -0,0 +1,17 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs +(module + (func (result i32) + i32.const 1 + i32.const 2 + nop + i32.add)) +(;; STDOUT ;;; +(module + (type (;0;) (func (result i32))) + (func (;0;) (type 0) (result i32) + (i32.const 1) + (i32.const 2) + (nop) + (i32.add))) +;;; STDOUT ;;) diff --git a/test/roundtrip/fold-unreachable.txt b/test/roundtrip/fold-unreachable.txt new file mode 100644 index 00000000..51867ae4 --- /dev/null +++ b/test/roundtrip/fold-unreachable.txt @@ -0,0 +1,54 @@ +;;; TOOL: run-roundtrip +;;; FLAGS: --stdout --fold-exprs +(module + (func (result i32) + i32.const 1 + unreachable + i32.add) + + (func + br 0 + drop) + + (func + block + block + block + i32.const 1 + br_table 0 1 2 0 + i32.const 2 + i32.div_s + return + end + end + end) + + (func (result i32) + i32.const 0 + return + i32.eqz)) +(;; STDOUT ;;; +(module + (type (;0;) (func (result i32))) + (type (;1;) (func)) + (func (;0;) (type 0) (result i32) + (i32.add + (i32.const 1) + (unreachable))) + (func (;1;) (type 1) + (drop + (br 0 (;@0;)))) + (func (;2;) (type 1) + (block ;; label = @1 + (block ;; label = @2 + (block ;; label = @3 + (i32.div_s + (br_table 0 (;@3;) 1 (;@2;) 2 (;@1;) 0 (;@3;) + (i32.const 1)) + (i32.const 2)) + (return))))) + (func (;3;) (type 0) (result i32) + (i32.eqz + (return + (i32.const 0))))) +;;; STDOUT ;;) diff --git a/test/roundtrip/generate-if-label-names.txt b/test/roundtrip/generate-if-label-names.txt index 4604aa28..bfe8962c 100644 --- a/test/roundtrip/generate-if-label-names.txt +++ b/test/roundtrip/generate-if-label-names.txt @@ -18,13 +18,13 @@ (type $t0 (func)) (func $f0 (type $t0) i32.const 1 - if $L0 - br $L0 + if $I0 + br $I0 end i32.const 2 - if $L1 - br $L1 + if $I1 + br $I1 else - br $L1 + br $I1 end)) ;;; STDOUT ;;) diff --git a/test/run-roundtrip.py b/test/run-roundtrip.py index 49afecf3..66c3d4f2 100755 --- a/test/run-roundtrip.py +++ b/test/run-roundtrip.py @@ -115,6 +115,7 @@ def main(args): parser.add_argument('--no-check', action='store_true') parser.add_argument('--debug-names', action='store_true') parser.add_argument('--generate-names', action='store_true') + parser.add_argument('--fold-exprs', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) @@ -130,6 +131,7 @@ def main(args): find_exe.GetWasm2WastExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wast.AppendOptionalArgs({ + '--fold-exprs': options.fold_exprs, '--no-debug-names': not options.debug_names, '--generate-names': options.generate_names, }) diff --git a/test/run-tests.py b/test/run-tests.py index 6359bf74..47de4fe9 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -228,7 +228,7 @@ class TestInfo(object): self.skip = False self.is_roundtrip = False - def CreateRoundtripInfo(self): + def CreateRoundtripInfo(self, fold_exprs): result = TestInfo() result.filename = self.filename result.header = self.header @@ -239,16 +239,22 @@ class TestInfo(object): result.tool = 'run-roundtrip' result.exe = ROUNDTRIP_PY result.flags = ['--bindir', '%(bindir)s', '-v'] + if fold_exprs: + result.flags.append('--fold-exprs') result.expected_error = 0 result.slow = self.slow result.skip = self.skip result.is_roundtrip = True + result.fold_exprs = fold_exprs return result def GetName(self): name = self.filename if self.is_roundtrip: - name += ' (roundtrip)' + if self.fold_exprs: + name += ' (roundtrip fold-exprs)' + else: + name += ' (roundtrip)' return name def GetGeneratedInputFilename(self): @@ -735,7 +741,8 @@ def main(args): infos_to_run.append(info) if options.roundtrip and info.ShouldCreateRoundtrip(): - infos_to_run.append(info.CreateRoundtripInfo()) + infos_to_run.append(info.CreateRoundtripInfo(fold_exprs=False)) + infos_to_run.append(info.CreateRoundtripInfo(fold_exprs=True)) if not os.path.exists(OUT_DIR): os.makedirs(OUT_DIR) |