diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-05 17:53:36 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-05 17:59:07 -0800 |
commit | 538e2d9813dd46e76aa226143b978f2b1acfb8e6 (patch) | |
tree | 17134f1b536ce597dbdeeb0ccb9fbd73a8b22f31 | |
parent | b2812d358ef291cee41f4670d2a0622876c5b113 (diff) | |
download | binaryen-538e2d9813dd46e76aa226143b978f2b1acfb8e6.tar.gz binaryen-538e2d9813dd46e76aa226143b978f2b1acfb8e6.tar.bz2 binaryen-538e2d9813dd46e76aa226143b978f2b1acfb8e6.zip |
call coercions in wasm2asm
-rw-r--r-- | src/wasm2asm.h | 11 | ||||
-rw-r--r-- | test/unit.2asm.js | 4 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h index 8f4c54de3..f33065a5d 100644 --- a/src/wasm2asm.h +++ b/src/wasm2asm.h @@ -553,7 +553,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { return ret; } - Ref makeStatementizedCall(ExpressionList& operands, Ref ret, Ref theCall, IString result) { + Ref makeStatementizedCall(ExpressionList& operands, Ref ret, Ref theCall, IString result, WasmType type) { std::vector<ScopedTemp> temps; for (auto& operand : operands) { temps.emplace_back(operand->type, parent); @@ -561,6 +561,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { ret[1]->push_back(visitAndAssign(operand, temp)); theCall[2]->push_back(ValueBuilder::makeName(temp)); } + theCall = makeAsmCoercion(theCall, wasmToAsmType(type)); if (result != NO_RESULT) { theCall = ValueBuilder::makeStatement(ValueBuilder::makeAssign(ValueBuilder::makeName(result), theCall)); } @@ -575,10 +576,10 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { for (auto operand : curr->operands) { theCall[2]->push_back(visit(operand, EXPRESSION_RESULT)); } - return theCall; + return makeAsmCoercion(theCall, wasmToAsmType(curr->type)); } // we must statementize them all - return makeStatementizedCall(curr->operands, ValueBuilder::makeBlock(), theCall, result); + return makeStatementizedCall(curr->operands, ValueBuilder::makeBlock(), theCall, result, curr->type); } Ref visitCallImport(CallImport *curr) override { return visitCall(curr); @@ -590,14 +591,14 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { for (auto operand : curr->operands) { theCall[2]->push_back(visit(operand, EXPRESSION_RESULT)); } - return theCall; + return makeAsmCoercion(theCall, wasmToAsmType(curr->type)); } // we must statementize them all Ref ret = ValueBuilder::makeBlock(); ScopedTemp temp(i32, parent); ret[1]->push_back(visit(curr->target, temp)); Ref theCall = ValueBuilder::makeCall(ValueBuilder::makeSub(ValueBuilder::makeName(FUNCTION_TABLE), temp.getAstName())); - return makeStatementizedCall(curr->operands, ret, theCall, result); + return makeStatementizedCall(curr->operands, ret, theCall, result, curr->type); } Ref visitGetLocal(GetLocal *curr) override { return ValueBuilder::makeName(fromName(curr->name)); diff --git a/test/unit.2asm.js b/test/unit.2asm.js index ffc03b240..daf81c3b8 100644 --- a/test/unit.2asm.js +++ b/test/unit.2asm.js @@ -61,7 +61,7 @@ function asmFunc() { function conversions() { var i = 0, d = 0.0; { - i = f64-to-int(d); + i = f64-to-int(d) | 0; d = +i; d = +((i >>> 0 | 0) >>> 0); } @@ -100,7 +100,7 @@ function asmFunc() { } function frem() { - return f64-rem(5.5, 1.2); + return +f64-rem(5.5, 1.2); } function big_uint_div_u() { |