diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-04 20:45:47 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-04 20:45:47 -0800 |
commit | 19109e4228c2687427257f06f80b19f3c95e1642 (patch) | |
tree | 064f32dec0a52c536a073108d7d7293b33501b5b /src/wasm2asm.h | |
parent | 6c37ba0c87208cf0e1a5f3a84ba9df26a93aab9f (diff) | |
download | binaryen-19109e4228c2687427257f06f80b19f3c95e1642.tar.gz binaryen-19109e4228c2687427257f06f80b19f3c95e1642.tar.bz2 binaryen-19109e4228c2687427257f06f80b19f3c95e1642.zip |
return result from block
Diffstat (limited to 'src/wasm2asm.h')
-rw-r--r-- | src/wasm2asm.h | 13 |
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); |