summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wasm2asm.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index 867cab374..b09d4ef7c 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -445,9 +445,18 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) {
breakResults[curr->name] = result;
Ref ret = ValueBuilder::makeBlock();
size_t size = curr->list.size();
- for (size_t i = 0; i < size; i++) {
+ int noResults = result == NO_RESULT ? size : size-1;
+ for (size_t i = 0; i < noResults; i++) {
// TODO: flatten out, if we receive a block, just insert the elements
- ret[1]->push_back(ValueBuilder::makeStatement(visit(curr->list[i], i < size-1 ? NO_RESULT : result)));
+ ret[1]->push_back(ValueBuilder::makeStatement(visit(curr->list[i], NO_RESULT)));
+ }
+ if (result != NO_RESULT) {
+ ret[1]->push_back(ValueBuilder::makeStatement(
+ ValueBuilder::makeAssign(
+ ValueBuilder::makeName(result),
+ visit(curr->list[size-1], result)
+ )
+ ));
}
if (curr->name.is()) {
ret = ValueBuilder::makeLabel(fromName(curr->name), ret);