diff --git a/benchmarks/wasm/btree/2o1u-tee.wat b/benchmarks/wasm/btree/2o1u-tee.wat index 2b0be28a..78d98170 100644 --- a/benchmarks/wasm/btree/2o1u-tee.wat +++ b/benchmarks/wasm/btree/2o1u-tee.wat @@ -1,12 +1,10 @@ (module - (type (;0;) (func (param i32))) - (type (;1;) (func (param i32) (result i32))) - (type (;2;) (func (param i32 i32) (result i32))) - (type (;3;) (func (param i32 i32))) - (type (;4;) (func (param i32 i32 i32))) - (type (;5;) (func)) - (import "console" "log" (func (;0;) (type 0))) - (func (;1;) (type 1) (param i32) (result i32) + (type (;0;) (func (param i32) (result i32))) + (type (;1;) (func (param i32 i32) (result i32))) + (type (;2;) (func (param i32 i32))) + (type (;3;) (func (param i32 i32 i32))) + (type (;4;) (func)) + (func (;0;) (type 0) (param i32) (result i32) i32.const 0 local.get 0 i32.store @@ -29,7 +27,7 @@ i32.store offset=4 end i32.const 65536) - (func (;2;) (type 2) (param i32 i32) (result i32) + (func (;1;) (type 1) (param i32 i32) (result i32) (local i32) i32.const 0 local.set 2 @@ -109,7 +107,7 @@ i32.add i32.load offset=8 local.get 1 - call 2 + call 1 end end else @@ -134,10 +132,10 @@ i32.add i32.load offset=8 local.get 1 - call 2 + call 1 end end) - (func (;3;) (type 3) (param i32 i32) + (func (;2;) (type 2) (param i32 i32) (local i32 i32) i32.const 1 memory.grow @@ -480,7 +478,7 @@ i32.add i32.store offset=4 end) - (func (;4;) (type 3) (param i32 i32) + (func (;3;) (type 2) (param i32 i32) (local i32 i32) local.get 0 i32.load offset=4 @@ -489,10 +487,6 @@ local.set 2 local.get 0 i32.load - local.tee 3 - local.get 3 - call 0 - unreachable i32.const 1 i32.eq if ;; label = @1 @@ -612,7 +606,7 @@ if ;; label = @2 local.get 0 local.get 2 - call 3 + call 2 local.get 1 local.get 0 i32.const 4 @@ -642,13 +636,14 @@ i32.add i32.load offset=8 local.get 1 - call 4 + call 3 end) - (func (;5;) (type 1) (param i32) (result i32) + (func (;4;) (type 0) (param i32) (result i32) (local i32 i32) i32.const 0 i32.load offset=8 local.tee 2 + unreachable i32.load offset=4 i32.const 0 i32.load @@ -699,10 +694,10 @@ i32.store offset=8 local.get 1 i32.const 0 - call 3 + call 2 local.get 1 local.get 0 - call 4 + call 3 local.get 1 else i32.const -1 @@ -710,10 +705,10 @@ else local.get 2 local.get 0 - call 4 + call 3 local.get 2 end) - (func (;6;) (type 2) (param i32 i32) (result i32) + (func (;5;) (type 1) (param i32 i32) (result i32) (local i32 i32 i32 i32) local.get 0 i32.load @@ -894,7 +889,7 @@ i32.mul i32.add i32.load offset=8 - call 6 + call 5 drop i32.store offset=8 else @@ -939,7 +934,7 @@ i32.mul i32.add i32.load offset=8 - call 6 + call 5 drop i32.store offset=8 else @@ -1230,7 +1225,7 @@ i32.store offset=4 local.get 5 local.get 1 - call 6 + call 5 drop end end @@ -2531,12 +2526,12 @@ i32.add i32.load offset=8 local.get 1 - call 6 + call 5 drop else local.get 5 local.get 1 - call 6 + call 5 drop end end @@ -2566,7 +2561,7 @@ end i32.const 0 i32.load offset=8) - (func (;7;) (type 4) (param i32 i32 i32) + (func (;6;) (type 3) (param i32 i32 i32) (local i32) local.get 0 local.get 1 @@ -2584,58 +2579,58 @@ unreachable end i32.const 4 - call 1 + call 0 local.set 3 local.get 0 - call 5 + call 4 local.set 3 local.get 1 - call 5 + call 4 local.set 3 local.get 2 - call 5 + call 4 local.set 3 local.get 3 local.get 0 - call 2 + call 1 i32.const -1 i32.ne local.get 3 local.get 1 - call 2 + call 1 i32.const -1 i32.ne local.get 3 local.get 2 - call 2 + call 1 i32.const -1 i32.ne i32.and i32.and local.get 3 local.get 0 - call 6 + call 5 local.tee 3 local.get 0 - call 2 + call 1 i32.const -1 i32.eq local.get 3 local.get 1 - call 6 + call 5 local.tee 3 local.get 1 - call 2 + call 1 i32.const -1 i32.eq i32.and i32.and drop) - (func (;8;) (type 5) + (func (;7;) (type 4) i32.const 3 i32.const 2 i32.const 1 - call 7) + call 6) (memory (;0;) 2) - (start 8) -) + (export "main" (func 7)) + (start 7)) diff --git a/benchmarks/wasm/btree/2o1u.wat b/benchmarks/wasm/btree/2o1u.wat index c1cb05f4..ea5d8485 100644 --- a/benchmarks/wasm/btree/2o1u.wat +++ b/benchmarks/wasm/btree/2o1u.wat @@ -528,10 +528,6 @@ (local.set 2) ;; i = x.n -1 (local.get 0) ;; x (i32.load) ;; get first i32 --> isLeaf - ;; (local.tee $tmp) - ;; (local.get $tmp) - ;; (call $log) - (unreachable) (i32.const 1) (i32.eq) ;; is leaf? (if @@ -708,6 +704,10 @@ (i32.const 0) (i32.load offset=8) ;; root addr (local.tee 2) ;; set r + ;; FIXME: first divergence + ;; tos should be 65536, but we got 256 + ;; (call $log) + (unreachable) (i32.load offset=4) ;; r.n (i32.const 0) (i32.load) ;; t @@ -2822,5 +2822,4 @@ call $main ) (start $real_main) - (export "real_main" (func $real_main)) - ) +) diff --git a/src/main/scala/wasm/MiniWasm.scala b/src/main/scala/wasm/MiniWasm.scala index 98d5fa85..f100399c 100644 --- a/src/main/scala/wasm/MiniWasm.scala +++ b/src/main/scala/wasm/MiniWasm.scala @@ -181,8 +181,8 @@ object Evaluator { val inst = insts.head val rest = insts.tail - //println(f"stack size: ${stack.size}") - //println(s"eval: $inst") + // println(s"inst: ${inst} \t | ${frame.locals} | ${stack.reverse}" ) + inst match { case Drop => eval(rest, stack.tail, frame, kont, trail, ret) case Select(_) => diff --git a/src/test/scala/genwasym/TestEval.scala b/src/test/scala/genwasym/TestEval.scala index d0f1b379..39743b0c 100644 --- a/src/test/scala/genwasym/TestEval.scala +++ b/src/test/scala/genwasym/TestEval.scala @@ -41,8 +41,8 @@ class TestEval extends FunSuite { test("return") { testFile("./benchmarks/wasm/return.wat", None, None) } // Parser works, but the memory issue remains - test("btree") { testFile("./benchmarks/wasm/btree/2o1u-tee.wat") } + // test("btree") { testFile("./benchmarks/wasm/btree/2o1u-tee.wat") } // TODO: add more wasm spec tests? - // test("memory") { test_btree("./benchmarks/wasm/spectest/test.wat", "$real_main") } + // test("memory") { testFile("./benchmarks/wasm/spectest/test.wat") } }