diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm2js.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h index 84c65b189..fdfa77b84 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -823,9 +823,14 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func, bool standalo Ref visitLoop(Loop* curr) { Name asmLabel = curr->name; continueLabels.insert(asmLabel); - Ref body = blockify(visit(curr->body, result)); - flattenAppend(body, ValueBuilder::makeBreak(fromName(asmLabel, NameScope::Label))); - Ref ret = ValueBuilder::makeDo(body, ValueBuilder::makeInt(1)); + Ref body = visit(curr->body, result); + // if we can reach the end of the block, we must leave the while (1) loop + if (curr->body->type != unreachable) { + assert(curr->body->type == none); // flat IR + body = blockify(body); + flattenAppend(body, ValueBuilder::makeBreak(fromName(asmLabel, NameScope::Label))); + } + Ref ret = ValueBuilder::makeWhile(ValueBuilder::makeInt(1), body); return ValueBuilder::makeLabel(fromName(asmLabel, NameScope::Label), ret); } @@ -1207,10 +1212,8 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func, bool standalo << std::endl; WASM_UNREACHABLE(); case EqZInt32: - return ValueBuilder::makeBinary( - makeAsmCoercion(visit(curr->value, - EXPRESSION_RESULT), ASM_INT), EQ, - makeAsmCoercion(ValueBuilder::makeInt(0), ASM_INT)); + // XXX !x does change the type to bool, which is correct, but may be slower? + return ValueBuilder::makeUnary(L_NOT, visit(curr->value, EXPRESSION_RESULT)); case ReinterpretFloat32: { ABI::wasm2js::ensureScratchMemoryHelpers(module, ABI::wasm2js::SCRATCH_STORE_F32); ABI::wasm2js::ensureScratchMemoryHelpers(module, ABI::wasm2js::SCRATCH_LOAD_I32); |