summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-05 15:02:43 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-05 15:02:43 -0800
commitb2812d358ef291cee41f4670d2a0622876c5b113 (patch)
tree1a4db38828cece651a87a4243cbb84d9c5013747 /src
parent730c770784cc83922bcfdf43fe04064319d191d5 (diff)
downloadbinaryen-b2812d358ef291cee41f4670d2a0622876c5b113.tar.gz
binaryen-b2812d358ef291cee41f4670d2a0622876c5b113.tar.bz2
binaryen-b2812d358ef291cee41f4670d2a0622876c5b113.zip
flatten out blocks in wasm2asm
Diffstat (limited to 'src')
-rw-r--r--src/wasm2asm.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index 3fd743dcf..8f4c54de3 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -448,8 +448,15 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) {
size_t size = curr->list.size();
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], NO_RESULT)));
+ // add to our return block. if we receive a block, can just flatten it out here
+ Ref ast = ValueBuilder::makeStatement(visit(curr->list[i], NO_RESULT));
+ if (ast[0] == BLOCK) {
+ for (int j = 0; j < ast[1]->size(); j++) {
+ ret[1]->push_back(ast[1][j]);
+ }
+ } else {
+ ret[1]->push_back(ast);
+ }
}
if (result != NO_RESULT) {
ret[1]->push_back(ValueBuilder::makeStatement(