From 4e1667aa3454f56b3e96df674c504cb16366b628 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 4 Oct 2016 20:04:57 -0700 Subject: handle ifs with an i64 condition #741 (#742) --- src/asm2wasm.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index f00004b1f..d9618d8fd 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -539,6 +539,12 @@ private: return call; } + Expression* truncateToInt32(Expression* value) { + if (value->type == i64) return builder.makeUnary(UnaryOp::WrapInt64, value); + // either i32, or a call_import whose type we don't know yet (but would be legalized to i32 anyhow) + return value; + } + Function* processFunction(Ref ast); }; @@ -1432,7 +1438,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { } else if (what == IF) { auto* condition = process(ast[1]); auto* ifTrue = process(ast[2]); - return builder.makeIf(condition, ifTrue, !!ast[3] ? process(ast[3]) : nullptr); + return builder.makeIf(truncateToInt32(condition), ifTrue, !!ast[3] ? process(ast[3]) : nullptr); } else if (what == CALL) { if (ast[1][0] == NAME) { IString name = ast[1][1]->getIString(); -- cgit v1.2.3