diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-04 16:31:28 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-04 16:31:28 -0800 |
commit | 3e1bb693f27039d308d941c1399ff920fa10aae7 (patch) | |
tree | c892df6846a8e6b7cf650d6e0db6f77fa3a9a88d /src/wasm2asm.h | |
parent | ef4553db21e7e93fb82b375df4d32feb7f3f5915 (diff) | |
download | binaryen-3e1bb693f27039d308d941c1399ff920fa10aae7.tar.gz binaryen-3e1bb693f27039d308d941c1399ff920fa10aae7.tar.bz2 binaryen-3e1bb693f27039d308d941c1399ff920fa10aae7.zip |
handle functions whose entire body is an expression
Diffstat (limited to 'src/wasm2asm.h')
-rw-r--r-- | src/wasm2asm.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h index 722eb56eb..d75c92e84 100644 --- a/src/wasm2asm.h +++ b/src/wasm2asm.h @@ -168,9 +168,14 @@ Ref Wasm2AsmBuilder::processFunction(Function* func) { ret[3]->push_back(theVar); // body scanFunctionBody(func->body); - IString result = func->result != none ? getTemp(func->result) : NO_RESULT; - ret[3]->push_back(processFunctionBody(func->body, result)); - if (result != NO_RESULT) freeTemp(func->result, result); + if (isStatement(func->body)) { + IString result = func->result != none ? getTemp(func->result) : NO_RESULT; + ret[3]->push_back(processFunctionBody(func->body, result)); + if (result != NO_RESULT) freeTemp(func->result, result); + } else { + // whole thing is an expression, just do a return + ret[3]->push_back(ValueBuilder::makeStatement(ValueBuilder::makeReturn(processFunctionBody(func->body, EXPRESSION_RESULT)))); + } // locals, including new temp locals for (auto& local : func->locals) { ValueBuilder::appendToVar(theVar, fromName(local.name), makeAsmCoercedZero(wasmToAsmType(local.type))); |