diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-21 17:13:32 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-21 17:36:32 -0700 |
commit | 66412d32a863fff2308ffc349eeca7f6ffbc2a31 (patch) | |
tree | 8232c7d53a9269c82c5a8fd6dfba283eeb32f607 /src | |
parent | a7ddd9614b4a7b567258eb018d5e7827d3f48cba (diff) | |
download | binaryen-66412d32a863fff2308ffc349eeca7f6ffbc2a31.tar.gz binaryen-66412d32a863fff2308ffc349eeca7f6ffbc2a31.tar.bz2 binaryen-66412d32a863fff2308ffc349eeca7f6ffbc2a31.zip |
fix loop binary parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-binary.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 12ea039ac..9a911b07d 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -815,7 +815,7 @@ public: void visitLoop(Loop *curr) { if (debug) std::cerr << "zz node: Loop" << std::endl; // TODO: optimize, as we usually have a block as our singleton child - o << int8_t(BinaryConsts::Loop) << int8_t(1); + o << int8_t(BinaryConsts::Loop); breakStack.push_back(curr->out); breakStack.push_back(curr->in); recurse(curr->body); @@ -1668,6 +1668,23 @@ public: breakStack.pop_back(); } } + + Expression* getMaybeBlock() { + auto start = expressionStack.size(); + processExpressions(); + size_t end = expressionStack.size(); + if (end - start == 1) { + return popExpression(); + } else { + auto* body = allocator.alloc<Block>(); + for (size_t i = start; i < end; i++) { + body->list.push_back(expressionStack[i]); + } + expressionStack.resize(start); + return body; + } + } + void visitIf(If *curr) { if (debug) std::cerr << "zz node: If" << std::endl; curr->condition = popExpression(); @@ -1687,13 +1704,11 @@ public: } void visitLoop(Loop *curr) { if (debug) std::cerr << "zz node: Loop" << std::endl; - verifyInt8(1); // size TODO: generalize curr->out = getNextLabel(); curr->in = getNextLabel(); breakStack.push_back(curr->out); breakStack.push_back(curr->in); - processExpressions(); - curr->body = popExpression(); + curr->body = getMaybeBlock(); breakStack.pop_back(); breakStack.pop_back(); curr->finalize(); |