diff --git a/ml-proto/test/countUp.wasm b/ml-proto/test/countUp.wasm index fcc7f33830..9150b30ffd 100644 --- a/ml-proto/test/countUp.wasm +++ b/ml-proto/test/countUp.wasm @@ -3,15 +3,14 @@ (module (func $Program_countUp - (param $outOffset i32) (param $count i32) (local $i i32) (local $num i32) - + (param $outOffset i32) (param $count i32) (local $i i32) (block ;; for (var (@ = 0); ...) (setlocal $i (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -21,32 +20,31 @@ (getlocal $count) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { - (block - (stores.1.i32 - (mul.i32 - (add.i32 - (getlocal $outOffset) - (getlocal $i) - ) - (const.i32 4) + (stores.1.i32 + (mul.i32 + (add.i32 + (getlocal $outOffset) + (getlocal $i) ) - (getlocal $i) + (const.i32 4) ) - (setlocal $num (getlocal $i)) - (setlocal $i (add.i32 - (getlocal $num) - (const.i32 1) - )) + (getlocal $i) ) + + ;; for (...; ...; ) + (setlocal $i (add.i32 + (getlocal $i) + (const.i32 1) + )) ) ) ) - ) + (func $Program_readI32 (param $base i32) (param $offset i32) (result i32) @@ -61,13 +59,13 @@ ) (export "countUp" $Program_countUp) - (export "readI32" $Program_readI32) (memory 4096 4096) ) + (invoke "countUp" (const.i32 0) (const.i32 32) ) (invoke "countUp" (const.i32 16) (const.i32 4) ) (asserteq (invoke "readI32" (const.i32 0) (const.i32 0) ) (const.i32 0) ) diff --git a/ml-proto/test/fannkuch.broken-wasm b/ml-proto/test/fannkuch.broken-wasm index 17e5f2908e..8c1c846dc3 100644 --- a/ml-proto/test/fannkuch.broken-wasm +++ b/ml-proto/test/fannkuch.broken-wasm @@ -4,16 +4,15 @@ (func $Program_fannkuch (param $n i32) (local $sign i32) (local $maxflips i32) (local $sum i32) - (local $j i32) (local $num i32) (local $q0 i32) (local $flag i32) - (local $k i32) (local $flips i32) (local $qq i32) (local $flag2 i32) - (local $flag3 i32) (local $l i32) (local $m i32) (local $t i32) - (local $flag4 i32) (local $flag5 i32) (local $t3 i32) (local $i2 i32) - (local $sx i32) (local $flag7 i32) (local $j2 i32) + (local $j i32) (local $q0 i32) (local $k i32) (local $flips i32) + (local $qq i32) (local $l i32) (local $m i32) (local $t i32) + (local $t3 i32) (local $i2 i32) (local $sx i32) (local $j2 i32) + (local $currentLabel_0 i32) (block - ;; LabelGroup 0 + ;; LabelGroup 0 (starting at $entry0) (setlocal $currentLabel_0 (const.i32 0)) (label $labelgroup_0 (loop (label $labelgroup_0_dispatch @@ -27,7 +26,7 @@ ;; for (var (@ = 0); ...) (setlocal $j (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -37,7 +36,7 @@ (getlocal $n) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { @@ -72,41 +71,41 @@ ) (getlocal $j) ) - (setlocal $num (getlocal $j)) - (setlocal $j (add.i32 - (getlocal $num) - (const.i32 1) - )) ) + + ;; for (...; ...; ) + (setlocal $j (add.i32 + (getlocal $j) + (const.i32 1) + )) ) ) ;; while () - (label $loop_4097 + (label $loop_1 (loop (if (const.i32 1) (nop) - (break $loop_4097) + (break $loop_1) ) ;; while (...) { (block (setlocal $q0 (loads.1.i32 (const.i32 128) )) - (setlocal $flag (gts.i32 - (getlocal $q0) - (const.i32 0) - )) (if - (getlocal $flag) + (neq.i32 + (getlocal $q0) + (const.i32 0) + ) (block ;; for (var (@ = 1); ...) (setlocal $k (const.i32 1)) - (label $loop_4098 + (label $loop_2 (loop ;; for (...; (@ < @); ...) @@ -116,33 +115,32 @@ (getlocal $n) ) (nop) - (break $loop_4098) + (break $loop_2) ) ;; for (...) { - (block - (stores.1.i32 - (mul.i32 + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 64) + (getlocal $k) + ) + (const.i32 4) + ) + (loads.1.i32 (mul.i32 (add.i32 - (const.i32 64) + (const.i32 32) (getlocal $k) ) (const.i32 4) - ) - (loads.1.i32 (mul.i32 - (add.i32 - (const.i32 32) - (getlocal $k) - ) - (const.i32 4) - ) ) - ) - (setlocal $num (getlocal $k)) - (setlocal $k (add.i32 - (getlocal $num) - (const.i32 1) - )) + ) ) ) + + ;; for (...; ...; ) + (setlocal $k (add.i32 + (getlocal $k) + (const.i32 1) + )) ) ) (setlocal $flips (const.i32 1)) @@ -166,13 +164,12 @@ ) (const.i32 4) ) )) - (setlocal $flag2 (eq.i32 - (getlocal $qq) - (const.i32 0) - )) (if - (getlocal $flag2) + (eq.i32 + (getlocal $qq) + (const.i32 0) + ) (break $loop_3) ) (stores.1.i32 @@ -185,13 +182,12 @@ ) (getlocal $q0) ) - (setlocal $flag3 (ges.i32 - (getlocal $q0) - (const.i32 3) - )) (if - (getlocal $flag3) + (ges.i32 + (getlocal $q0) + (const.i32 3) + ) (block (setlocal $l (const.i32 1)) (setlocal $m (sub.i32 @@ -200,7 +196,7 @@ )) ;; do { - (label $loop_4099 + (label $loop_4 (loop (block (setlocal $t (loads.1.i32 (mul.i32 @@ -236,14 +232,12 @@ ) (getlocal $t) ) - (setlocal $num (getlocal $l)) (setlocal $l (add.i32 - (getlocal $num) + (getlocal $l) (const.i32 1) )) - (setlocal $num (getlocal $m)) (setlocal $m (sub.i32 - (getlocal $num) + (getlocal $m) (const.i32 1) )) ) @@ -256,16 +250,15 @@ (getlocal $m) ) (nop) - (break $loop_4099) + (break $loop_4) ) ) ) ) ) (setlocal $q0 (getlocal $qq)) - (setlocal $num (getlocal $flips)) (setlocal $flips (add.i32 - (getlocal $num) + (getlocal $flips) (const.i32 1) )) ) @@ -278,24 +271,22 @@ (getlocal $flips) ) )) - (setlocal $flag4 (gts.i32 - (getlocal $flips) - (getlocal $maxflips) - )) (if - (getlocal $flag4) + (gts.i32 + (getlocal $flips) + (getlocal $maxflips) + ) (setlocal $maxflips (getlocal $flips)) ) ) ) - (setlocal $flag5 (eq.i32 - (getlocal $sign) - (const.i32 1) - )) (if - (getlocal $flag5) + (eq.i32 + (getlocal $sign) + (const.i32 1) + ) (block (stores.1.i32 (const.i32 132) @@ -346,7 +337,7 @@ ) )) (if - (gts.i32 + (neq.i32 (getlocal $sx) (const.i32 0) ) @@ -367,16 +358,15 @@ (break $loop_5) ) ) - (setlocal $flag7 (eq.i32 + + (if + (eq.i32 (getlocal $i2) (sub.i32 (getlocal $n) (const.i32 1) ) - )) - - (if - (getlocal $flag7) + ) ;; goto Block_8 (block (setlocal $currentLabel_0 (const.i32 1)) (break $labelgroup_0_dispatch) ) ) @@ -395,7 +385,7 @@ ;; for (var (@ = 0); ...) (setlocal $j2 (const.i32 0)) - (label $loop_4100 + (label $loop_6 (loop ;; for (...; (@ <= @); ...) @@ -405,36 +395,35 @@ (getlocal $i2) ) (nop) - (break $loop_4100) + (break $loop_6) ) ;; for (...) { - (block - (stores.1.i32 - (mul.i32 + (stores.1.i32 + (mul.i32 + (add.i32 + (const.i32 32) + (getlocal $j2) + ) + (const.i32 4) + ) + (loads.1.i32 (mul.i32 (add.i32 (const.i32 32) - (getlocal $j2) - ) - (const.i32 4) - ) - (loads.1.i32 (mul.i32 (add.i32 - (const.i32 32) - (add.i32 - (getlocal $j2) - (const.i32 1) - ) + (getlocal $j2) + (const.i32 1) ) - (const.i32 4) - ) ) - ) - (setlocal $num (getlocal $j2)) - (setlocal $j2 (add.i32 - (getlocal $num) - (const.i32 1) - )) + ) + (const.i32 4) + ) ) ) + + ;; for (...; ...; ) + (setlocal $j2 (add.i32 + (getlocal $j2) + (const.i32 1) + )) ) ) (stores.1.i32 @@ -450,12 +439,13 @@ ) (getlocal $t3) ) - (setlocal $num (getlocal $i2)) - (setlocal $i2 (add.i32 - (getlocal $num) - (const.i32 1) - )) ) + + ;; for (...; ...; ) + (setlocal $i2 (add.i32 + (getlocal $i2) + (const.i32 1) + )) ) ) ) @@ -489,8 +479,8 @@ ) )) ) - ) + (func $Program_readI32 (param $base i32) (param $offset i32) (result i32) @@ -505,13 +495,13 @@ ) (export "fannkuch" $Program_fannkuch) - (export "readI32" $Program_readI32) (memory 4096 4096) ) + (invoke "fannkuch" (const.i32 7) ) (asserteq (invoke "readI32" (const.i32 0) (const.i32 0) ) (const.i32 228) ) (asserteq (invoke "readI32" (const.i32 0) (const.i32 1) ) (const.i32 16) ) diff --git a/ml-proto/test/goto.wasm b/ml-proto/test/goto.wasm index 961746f5e7..82fdd34439 100644 --- a/ml-proto/test/goto.wasm +++ b/ml-proto/test/goto.wasm @@ -6,24 +6,21 @@ (param $result i32) (local $count i32) (block - (setlocal $count (loads.1.i32 (const.i32 0) )) + (setlocal $count (call $Program_get_ResultCount)) (storeu.1.i8 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $count) ) (getlocal $result) ) - (stores.1.i32 - (const.i32 0) - (add.i32 + (call $Program_set_ResultCount (add.i32 (getlocal $count) (const.i32 1) - ) - ) + )) ) - ) + (func $Program_Clear (param $offset i32) (param $count i32) (local $i i32) @@ -32,7 +29,7 @@ ;; for (var (@ = 0); ...) (setlocal $i (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -42,7 +39,7 @@ (getlocal $count) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { @@ -62,36 +59,34 @@ ) ) ) + ) + + (func $Program_get_ResultCount + + (result i32) + (return (load_global $Program_ResultCount_value)) ) + (func $Program_GetResult (param $index i32) (result i32) (return (loadu.1.i8 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $index) ) )) ) - (func $Program_GetResultCount - (result i32) - - (return (loads.1.i32 (const.i32 0) )) - ) (func $Program_Gotos - (block - (stores.1.i32 - (const.i32 0) - (const.i32 0) - ) - (call $Program_Clear (const.i32 4) (const.i32 128) ) + (call $Program_set_ResultCount (const.i32 0)) + (call $Program_Clear (const.i32 0) (const.i32 128) ) (call $Program_GotosInner ) ) - ) + (func $Program_GotosInner (local $i i32) (local $currentLabel_0 i32) @@ -125,7 +120,7 @@ )) (call $Program_AddResult (const.i32 1) ) - (label $loop_4097 + (label $loop_1 (loop ;; for (...; (@ < 16); ...) @@ -135,7 +130,7 @@ (const.i32 16) ) (nop) - (break $loop_4097) + (break $loop_1) ) ;; for (...) { @@ -173,21 +168,28 @@ ) ) ) - ) - (export "getResult" $Program_GetResult) + (func $Program_set_ResultCount + (param $value i32) - (export "getResultCount" $Program_GetResultCount) + (store_global $Program_ResultCount_value (getlocal $value)) + ) + (export "get_ResultCount" $Program_get_ResultCount) + (export "getResult" $Program_GetResult) (export "gotos" $Program_Gotos) + (export "set_ResultCount" $Program_set_ResultCount) + + (global $Program_ResultCount_value i32) (memory 1024 1024) ) + (invoke "gotos" ) -(asserteq (invoke "getResultCount" ) (const.i32 16) ) +(asserteq (invoke "get_ResultCount" ) (const.i32 16) ) (asserteq (invoke "getResult" (const.i32 0) ) (const.i32 1) ) (asserteq (invoke "getResult" (const.i32 1) ) (const.i32 3) ) (asserteq (invoke "getResult" (const.i32 2) ) (const.i32 3) ) diff --git a/ml-proto/test/sieve.wasm b/ml-proto/test/sieve.wasm index 02d43aeef8..64c3f0076b 100644 --- a/ml-proto/test/sieve.wasm +++ b/ml-proto/test/sieve.wasm @@ -6,27 +6,24 @@ (param $result i32) (local $count i32) (block - (setlocal $count (loads.1.i32 (const.i32 0) )) + (setlocal $count (call $Program_get_ResultCount)) (stores.1.i32 (mul.i32 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $count) ) (const.i32 4) ) (getlocal $result) ) - (stores.1.i32 - (const.i32 0) - (add.i32 + (call $Program_set_ResultCount (add.i32 (getlocal $count) (const.i32 1) - ) - ) + )) ) - ) + (func $Program_Clear (param $offset i32) (param $count i32) (local $i i32) @@ -35,7 +32,7 @@ ;; for (var (@ = 0); ...) (setlocal $i (const.i32 0)) - (label $loop_4096 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -45,7 +42,7 @@ (getlocal $count) ) (nop) - (break $loop_4096) + (break $loop_0) ) ;; for (...) { @@ -65,36 +62,40 @@ ) ) ) + ) + + (func $Program_get_ResultCount + (result i32) + + (return (load_global $Program_ResultCount_value)) ) + (func $Program_GetResult (param $index i32) (result i32) (return (loads.1.i32 (mul.i32 (add.i32 - (const.i32 4) + (const.i32 0) (getlocal $index) ) (const.i32 4) ) )) ) - (func $Program_GetResultCount - (result i32) + (func $Program_set_ResultCount + (param $value i32) - (return (loads.1.i32 (const.i32 0) )) + (store_global $Program_ResultCount_value (getlocal $value)) ) + (func $Program_Sieve (param $target i32) (local $squareRoot f64) (local $candidate i32) (local $multiple i32) - (block - (stores.1.i32 - (const.i32 0) - (const.i32 0) - ) - (call $Program_Clear (const.i32 4) (const.i32 16384) ) + (call $Program_set_ResultCount (const.i32 0)) + (call $Program_Clear (const.i32 0) (const.i32 16384) ) (call $Program_Clear (const.i32 16388) (getlocal $target) ) (setlocal $squareRoot (sqrt.f64 (converts.i32.f64 (getlocal $target)) )) (call $Program_AddResult (const.i32 2) ) @@ -102,7 +103,7 @@ ;; for (var (@ = 3); ...) (setlocal $candidate (const.i32 3)) - (label $loop_4097 + (label $loop_0 (loop ;; for (...; (@ < @); ...) @@ -112,7 +113,7 @@ (getlocal $target) ) (nop) - (break $loop_4097) + (break $loop_0) ) ;; for (...) { @@ -141,7 +142,7 @@ (getlocal $candidate) )) - (label $loop_4098 + (label $loop_1 (loop ;; for (...; (@ < @); ...) @@ -151,7 +152,7 @@ (getlocal $target) ) (nop) - (break $loop_4098) + (break $loop_1) ) ;; for (...) { @@ -188,21 +189,22 @@ ) ) ) - ) + (export "get_ResultCount" $Program_get_ResultCount) (export "getResult" $Program_GetResult) - - (export "getResultCount" $Program_GetResultCount) - + (export "set_ResultCount" $Program_set_ResultCount) (export "sieve" $Program_Sieve) + (global $Program_ResultCount_value i32) + (memory 131072 131072) ) + (invoke "sieve" (const.i32 24) ) -(asserteq (invoke "getResultCount" ) (const.i32 9) ) +(asserteq (invoke "get_ResultCount" ) (const.i32 9) ) (asserteq (invoke "getResult" (const.i32 0) ) (const.i32 2) ) (asserteq (invoke "getResult" (const.i32 1) ) (const.i32 3) ) (asserteq (invoke "getResult" (const.i32 2) ) (const.i32 5) )