diff options
-rw-r--r-- | src/asm2wasm.h | 18 | ||||
-rw-r--r-- | test/unit.asm.js | 7 | ||||
-rw-r--r-- | test/unit.fromasm | 12 | ||||
-rw-r--r-- | test/unit.fromasm.clamp | 12 | ||||
-rw-r--r-- | test/unit.fromasm.clamp.no-opts | 18 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 12 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise.no-opts | 18 | ||||
-rw-r--r-- | test/unit.fromasm.no-opts | 18 | ||||
-rw-r--r-- | test/use-import-and-drop.fromasm.clamp.no-opts | 36 | ||||
-rw-r--r-- | test/use-import-and-drop.fromasm.imprecise.no-opts | 36 | ||||
-rw-r--r-- | test/use-import-and-drop.fromasm.no-opts | 36 |
11 files changed, 156 insertions, 67 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 153839065..e8349627f 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -476,15 +476,20 @@ private: } } - FunctionType* getFunctionType(Ref parent, ExpressionList& operands) { - WasmType result = none; + WasmType getResultTypeOfCallUsingParent(Ref parent, AsmData* data) { + auto result = none; if (!!parent) { // if the parent is a seq, we cannot be the last element in it (we would have a coercion, which would be // the parent), so we must be (us, somethingElse), and so our return is void if (parent[0] != SEQ) { - result = detectWasmType(parent, nullptr); + result = detectWasmType(parent, data); } } + return result; + } + + FunctionType* getFunctionType(Ref parent, ExpressionList& operands, AsmData* data) { + WasmType result = getResultTypeOfCallUsingParent(parent, data); return ensureFunctionType(getSig(result, operands), &wasm); } @@ -2189,7 +2194,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { if (tableCall) { auto specific = ret->dynCast<CallIndirect>(); // note that we could also get the type from the suffix of the name, e.g., mftCall_vi - auto* fullType = getFunctionType(astStackHelper.getParent(), specific->operands); + auto* fullType = getFunctionType(astStackHelper.getParent(), specific->operands, &asmData); specific->fullType = fullType->name; specific->type = fullType->result; } @@ -2202,8 +2207,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { // this is important as we run the optimizer on functions before we get // to finalizeCalls (which we can only do once we've read all the functions, // and we optimize in parallel starting earlier). - Ref parent = astStackHelper.getParent(); - callImport->type = !!parent ? detectWasmType(parent, &asmData) : none; + callImport->type = getResultTypeOfCallUsingParent(astStackHelper.getParent(), &asmData); noteImportedFunctionCall(ast, callImport->type, callImport); } return ret; @@ -2217,7 +2221,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { for (unsigned i = 0; i < args->size(); i++) { ret->operands.push_back(process(args[i])); } - auto* fullType = getFunctionType(astStackHelper.getParent(), ret->operands); + auto* fullType = getFunctionType(astStackHelper.getParent(), ret->operands, &asmData); ret->fullType = fullType->name; ret->type = fullType->result; // we don't know the table offset yet. emit target = target + callImport(tableName), which we fix up later when we know how asm function tables are layed out inside the wasm table. diff --git a/test/unit.asm.js b/test/unit.asm.js index 065512011..22e2cf9b4 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -19,6 +19,7 @@ function asm(global, env, buffer) { var print = env.print; var h = env.h; var return_int = env.return_int; + var emscripten_log = env.emscripten_log; var HEAP8 = new global.Int8Array(buffer); var HEAP16 = new global.Int16Array(buffer); @@ -718,6 +719,11 @@ function asm(global, env, buffer) { FUNCTION_TABLE_vi[(Int = 1) & 7](i1 | 0); } + function call_emscripten_log() { + // emscripten_log has no return value, don't let the conditional after the comma confuse you + emscripten_log(), 2 ? abort() | 0 : 3; + } + function keepAlive() { sqrts(3.14159); f2u(100.0); @@ -725,6 +731,7 @@ function asm(global, env, buffer) { autoDrop(52) | 0; indirectInSequence(); emterpretify_assertions_safeHeap(); + call_emscripten_log(); } function v() { diff --git a/test/unit.fromasm b/test/unit.fromasm index 020ded163..8e6cd5956 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -14,6 +14,7 @@ (import "env" "print" (func $print (param i32))) (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) + (import "env" "emscripten_log" (func $emscripten_log)) (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) @@ -1196,6 +1197,16 @@ ) ) ) + (func $call_emscripten_log + (call $emscripten_log) + (drop + (call $f64-to-int + (call $abort + (f64.const 0) + ) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1219,6 +1230,7 @@ ) (call $indirectInSequence) (call $emterpretify_assertions_safeHeap) + (call $call_emscripten_log) ) (func $vi (param $0 i32) (nop) diff --git a/test/unit.fromasm.clamp b/test/unit.fromasm.clamp index 06c577753..9ab53f183 100644 --- a/test/unit.fromasm.clamp +++ b/test/unit.fromasm.clamp @@ -13,6 +13,7 @@ (import "env" "print" (func $print (param i32))) (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) + (import "env" "emscripten_log" (func $emscripten_log)) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 25 25 anyfunc)) @@ -1220,6 +1221,16 @@ ) ) ) + (func $call_emscripten_log + (call $emscripten_log) + (drop + (call $f64-to-int + (call $abort + (f64.const 0) + ) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1243,6 +1254,7 @@ ) (call $indirectInSequence) (call $emterpretify_assertions_safeHeap) + (call $call_emscripten_log) ) (func $vi (param $0 i32) (nop) diff --git a/test/unit.fromasm.clamp.no-opts b/test/unit.fromasm.clamp.no-opts index 393147603..9055bda68 100644 --- a/test/unit.fromasm.clamp.no-opts +++ b/test/unit.fromasm.clamp.no-opts @@ -17,6 +17,7 @@ (import "env" "print" (func $print (param i32))) (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) + (import "env" "emscripten_log" (func $emscripten_log)) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 25 25 anyfunc)) @@ -2010,6 +2011,22 @@ ) ) ) + (func $call_emscripten_log + (call $emscripten_log) + (if + (i32.const 2) + (drop + (call $f64-to-int + (call $abort + (f64.const 0) + ) + ) + ) + (drop + (i32.const 3) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -2033,6 +2050,7 @@ ) (call $indirectInSequence) (call $emterpretify_assertions_safeHeap) + (call $call_emscripten_log) ) (func $v (nop) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 8ee0b073f..f57931d20 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -13,6 +13,7 @@ (import "env" "print" (func $print (param i32))) (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) + (import "env" "emscripten_log" (func $emscripten_log)) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 25 25 anyfunc)) @@ -1169,6 +1170,16 @@ ) ) ) + (func $call_emscripten_log + (call $emscripten_log) + (drop + (i32.trunc_s/f64 + (call $abort + (f64.const 0) + ) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1192,6 +1203,7 @@ ) (call $indirectInSequence) (call $emterpretify_assertions_safeHeap) + (call $call_emscripten_log) ) (func $vi (param $0 i32) (nop) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index 70eece97d..b66c69cf7 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -17,6 +17,7 @@ (import "env" "print" (func $print (param i32))) (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) + (import "env" "emscripten_log" (func $emscripten_log)) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 25 25 anyfunc)) @@ -1970,6 +1971,22 @@ ) ) ) + (func $call_emscripten_log + (call $emscripten_log) + (if + (i32.const 2) + (drop + (i32.trunc_s/f64 + (call $abort + (f64.const 0) + ) + ) + ) + (drop + (i32.const 3) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -1993,6 +2010,7 @@ ) (call $indirectInSequence) (call $emterpretify_assertions_safeHeap) + (call $call_emscripten_log) ) (func $v (nop) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index 511e310a3..074a44bfe 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -18,6 +18,7 @@ (import "env" "print" (func $print (param i32))) (import "env" "h" (func $h (param i32))) (import "env" "return_int" (func $return_int (result i32))) + (import "env" "emscripten_log" (func $emscripten_log)) (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) (import "asm2wasm" "f64-rem" (func $f64-rem (param f64 f64) (result f64))) (import "env" "memory" (memory $0 256 256)) @@ -1986,6 +1987,22 @@ ) ) ) + (func $call_emscripten_log + (call $emscripten_log) + (if + (i32.const 2) + (drop + (call $f64-to-int + (call $abort + (f64.const 0) + ) + ) + ) + (drop + (i32.const 3) + ) + ) + ) (func $keepAlive (drop (call $sqrts @@ -2009,6 +2026,7 @@ ) (call $indirectInSequence) (call $emterpretify_assertions_safeHeap) + (call $call_emscripten_log) ) (func $v (nop) diff --git a/test/use-import-and-drop.fromasm.clamp.no-opts b/test/use-import-and-drop.fromasm.clamp.no-opts index 332851f61..5ce22091a 100644 --- a/test/use-import-and-drop.fromasm.clamp.no-opts +++ b/test/use-import-and-drop.fromasm.clamp.no-opts @@ -1,6 +1,6 @@ (module - (type $FUNCSIG$ii (func (param i32) (result i32))) - (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (import "env" "setTempRet0" (func $setTempRet0 (param i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) @@ -13,23 +13,21 @@ (local $$1$0 i32) (return (block (result i32) - (drop - (call $setTempRet0 - (i32.or + (call $setTempRet0 + (i32.or + (i32.add (i32.add - (i32.add - (i32.mul - (get_local $$b$1) - (get_local $$x_sroa_0_0_extract_trunc) - ) - (get_local $$2) + (i32.mul + (get_local $$b$1) + (get_local $$x_sroa_0_0_extract_trunc) ) - (get_local $$1$1) - ) - (i32.and - (get_local $$1$1) - (i32.const 0) + (get_local $$2) ) + (get_local $$1$1) + ) + (i32.and + (get_local $$1$1) + (i32.const 0) ) ) ) @@ -44,10 +42,8 @@ ) ) (func $test2 - (drop - (call $setTempRet0 - (i32.const 10) - ) + (call $setTempRet0 + (i32.const 10) ) ) ) diff --git a/test/use-import-and-drop.fromasm.imprecise.no-opts b/test/use-import-and-drop.fromasm.imprecise.no-opts index 332851f61..5ce22091a 100644 --- a/test/use-import-and-drop.fromasm.imprecise.no-opts +++ b/test/use-import-and-drop.fromasm.imprecise.no-opts @@ -1,6 +1,6 @@ (module - (type $FUNCSIG$ii (func (param i32) (result i32))) - (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (import "env" "setTempRet0" (func $setTempRet0 (param i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) @@ -13,23 +13,21 @@ (local $$1$0 i32) (return (block (result i32) - (drop - (call $setTempRet0 - (i32.or + (call $setTempRet0 + (i32.or + (i32.add (i32.add - (i32.add - (i32.mul - (get_local $$b$1) - (get_local $$x_sroa_0_0_extract_trunc) - ) - (get_local $$2) + (i32.mul + (get_local $$b$1) + (get_local $$x_sroa_0_0_extract_trunc) ) - (get_local $$1$1) - ) - (i32.and - (get_local $$1$1) - (i32.const 0) + (get_local $$2) ) + (get_local $$1$1) + ) + (i32.and + (get_local $$1$1) + (i32.const 0) ) ) ) @@ -44,10 +42,8 @@ ) ) (func $test2 - (drop - (call $setTempRet0 - (i32.const 10) - ) + (call $setTempRet0 + (i32.const 10) ) ) ) diff --git a/test/use-import-and-drop.fromasm.no-opts b/test/use-import-and-drop.fromasm.no-opts index 332851f61..5ce22091a 100644 --- a/test/use-import-and-drop.fromasm.no-opts +++ b/test/use-import-and-drop.fromasm.no-opts @@ -1,6 +1,6 @@ (module - (type $FUNCSIG$ii (func (param i32) (result i32))) - (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (import "env" "setTempRet0" (func $setTempRet0 (param i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) (import "env" "memoryBase" (global $memoryBase i32)) @@ -13,23 +13,21 @@ (local $$1$0 i32) (return (block (result i32) - (drop - (call $setTempRet0 - (i32.or + (call $setTempRet0 + (i32.or + (i32.add (i32.add - (i32.add - (i32.mul - (get_local $$b$1) - (get_local $$x_sroa_0_0_extract_trunc) - ) - (get_local $$2) + (i32.mul + (get_local $$b$1) + (get_local $$x_sroa_0_0_extract_trunc) ) - (get_local $$1$1) - ) - (i32.and - (get_local $$1$1) - (i32.const 0) + (get_local $$2) ) + (get_local $$1$1) + ) + (i32.and + (get_local $$1$1) + (i32.const 0) ) ) ) @@ -44,10 +42,8 @@ ) ) (func $test2 - (drop - (call $setTempRet0 - (i32.const 10) - ) + (call $setTempRet0 + (i32.const 10) ) ) ) |