summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h14
-rw-r--r--test/unit.asm.js10
-rw-r--r--test/unit.fromasm23
-rw-r--r--test/unit.fromasm.imprecise23
-rw-r--r--test/unit.fromasm.imprecise.no-opts25
-rw-r--r--test/unit.fromasm.no-opts25
6 files changed, 116 insertions, 4 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index a85fd4676..5167ad70f 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -401,9 +401,9 @@ private:
}
void fixCallType(Expression* call, WasmType type) {
- if (call->is<Call>()) call->type = type;
- if (call->is<CallImport>()) call->type = type;
- else if (call->is<CallIndirect>()) call->type = type;
+ if (call->is<Call>()) call->cast<Call>()->type = type;
+ if (call->is<CallImport>()) call->cast<CallImport>()->type = type;
+ else if (call->is<CallIndirect>()) call->cast<CallIndirect>()->type = type;
}
FunctionType* getBuiltinFunctionType(Name module, Name base, ExpressionList* operands = nullptr) {
@@ -736,7 +736,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
wasm.removeImport(curr);
}
- // Finalize indirect calls and import calls
+ // Finalize calls now that everything is known and generated
struct FinalizeCalls : public WalkerPass<PostWalker<FinalizeCalls, Visitor<FinalizeCalls>>> {
bool isFunctionParallel() override { return true; }
@@ -747,6 +747,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
FinalizeCalls(Asm2WasmBuilder* parent) : parent(parent) {}
+ void visitCall(Call* curr) {
+ curr->type = getModule()->getFunction(curr->target)->result;
+ }
+
void visitCallImport(CallImport* curr) {
// fill out call_import - add extra params as needed, etc. asm tolerates ffi overloading, wasm does not
auto iter = parent->importedFunctionTypes.find(curr->target);
@@ -768,6 +772,8 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
}
}
}
+
+ curr->type = getModule()->getImport(curr->target)->functionType->result;
}
void visitCallIndirect(CallIndirect* curr) {
// we already call into target = something + offset, where offset is a callImport with the name of the table. replace that with the table offset
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 5eb48f776..d6d0a27e8 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -9,6 +9,7 @@ function asm(global, env, buffer) {
var Math_ceil = global.Math.ceil;
var tempDoublePtr = env.tempDoublePtr | 0;
var n = env.gb | 0;
+ var setTempRet0=env.setTempRet0;
var abort = env.abort;
var print = env.print;
@@ -271,6 +272,15 @@ function asm(global, env, buffer) {
} while (0);
}
+ function dropCall() {
+ if (0) {
+ phi(); // drop this
+ setTempRet0(10); // this too
+ zeroInit(setTempRet0(10) | 0);
+ }
+ return phi() | 0;
+ }
+
function z() {
}
function w() {
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 78a97a9d7..daaf1359d 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -5,11 +5,13 @@
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(type $FUNCSIG$vf (func (param f32)))
(type $FUNCSIG$vi (func (param i32)))
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$vd (func (param f64)))
(import $t global "global" "NaN" f64)
(import $u global "global" "Infinity" f64)
(import $tempDoublePtr global "env" "tempDoublePtr" i32)
(import $n global "env" "gb" i32)
+ (import $setTempRet0 "env" "setTempRet0" (param i32) (result i32))
(import $abort "env" "abort" (param f64))
(import $print "env" "print" (param i32))
(import $h "env" "h" (param i32))
@@ -496,4 +498,25 @@
)
)
)
+ (func $dropCall (result i32)
+ (if
+ (i32.const 0)
+ (block
+ (drop
+ (call $phi)
+ )
+ (drop
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ (call $zeroInit
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ )
+ )
+ (call $phi)
+ )
)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index a18e1f436..b2c79ff79 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -3,11 +3,13 @@
(type $FUNCSIG$ddd (func (param f64 f64) (result f64)))
(type $FUNCSIG$vf (func (param f32)))
(type $FUNCSIG$vi (func (param i32)))
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$vd (func (param f64)))
(import $t global "global" "NaN" f64)
(import $u global "global" "Infinity" f64)
(import $tempDoublePtr global "env" "tempDoublePtr" i32)
(import $n global "env" "gb" i32)
+ (import $setTempRet0 "env" "setTempRet0" (param i32) (result i32))
(import $abort "env" "abort" (param f64))
(import $print "env" "print" (param i32))
(import $h "env" "h" (param i32))
@@ -478,4 +480,25 @@
)
)
)
+ (func $dropCall (result i32)
+ (if
+ (i32.const 0)
+ (block
+ (drop
+ (call $phi)
+ )
+ (drop
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ (call $zeroInit
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ )
+ )
+ (call $phi)
+ )
)
diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts
index 46d746946..06ab8089b 100644
--- a/test/unit.fromasm.imprecise.no-opts
+++ b/test/unit.fromasm.imprecise.no-opts
@@ -3,11 +3,13 @@
(type $FUNCSIG$ddd (func (param f64 f64) (result f64)))
(type $FUNCSIG$vf (func (param f32)))
(type $FUNCSIG$vi (func (param i32)))
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$vd (func (param f64)))
(import $t global "global" "NaN" f64)
(import $u global "global" "Infinity" f64)
(import $tempDoublePtr global "env" "tempDoublePtr" i32)
(import $n global "env" "gb" i32)
+ (import $setTempRet0 "env" "setTempRet0" (param i32) (result i32))
(import $abort "env" "abort" (param f64))
(import $print "env" "print" (param i32))
(import $h "env" "h" (param i32))
@@ -861,6 +863,29 @@
(nop)
)
)
+ (func $dropCall (result i32)
+ (if
+ (i32.const 0)
+ (block
+ (drop
+ (call $phi)
+ )
+ (drop
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ (call $zeroInit
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ )
+ )
+ (return
+ (call $phi)
+ )
+ )
(func $z
(nop)
)
diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts
index 56a1d4085..169d4fe5b 100644
--- a/test/unit.fromasm.no-opts
+++ b/test/unit.fromasm.no-opts
@@ -5,11 +5,13 @@
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(type $FUNCSIG$vf (func (param f32)))
(type $FUNCSIG$vi (func (param i32)))
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$vd (func (param f64)))
(import $t global "global" "NaN" f64)
(import $u global "global" "Infinity" f64)
(import $tempDoublePtr global "env" "tempDoublePtr" i32)
(import $n global "env" "gb" i32)
+ (import $setTempRet0 "env" "setTempRet0" (param i32) (result i32))
(import $abort "env" "abort" (param f64))
(import $print "env" "print" (param i32))
(import $h "env" "h" (param i32))
@@ -867,6 +869,29 @@
(nop)
)
)
+ (func $dropCall (result i32)
+ (if
+ (i32.const 0)
+ (block
+ (drop
+ (call $phi)
+ )
+ (drop
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ (call $zeroInit
+ (call_import $setTempRet0
+ (i32.const 10)
+ )
+ )
+ )
+ )
+ (return
+ (call $phi)
+ )
+ )
(func $z
(nop)
)