diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-21 17:32:49 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-21 17:36:32 -0700 |
commit | 51283a2da84f8cbd606b64a1883777a4a3a6aff0 (patch) | |
tree | c4cc833fdca0b5a90472026f7daec3014bb1b1fb /src | |
parent | 66412d32a863fff2308ffc349eeca7f6ffbc2a31 (diff) | |
download | binaryen-51283a2da84f8cbd606b64a1883777a4a3a6aff0.tar.gz binaryen-51283a2da84f8cbd606b64a1883777a4a3a6aff0.tar.bz2 binaryen-51283a2da84f8cbd606b64a1883777a4a3a6aff0.zip |
fix if and else bodies, which can be lists
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-binary.h | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 9a911b07d..3e4002c0e 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1485,11 +1485,16 @@ public: std::vector<Expression*> expressionStack; - BinaryConsts::ASTNodes processExpressions() { // until an end or else marker, or the end of the function + BinaryConsts::ASTNodes lastSeparator = BinaryConsts::End; + + void processExpressions() { // until an end or else marker, or the end of the function while (1) { Expression* curr; auto ret = readExpression(curr); - if (!curr) return ret; + if (!curr) { + lastSeparator = ret; + return; + } expressionStack.push_back(curr); } } @@ -1688,19 +1693,12 @@ public: void visitIf(If *curr) { if (debug) std::cerr << "zz node: If" << std::endl; curr->condition = popExpression(); - size_t start = expressionStack.size(); - auto next = processExpressions(); - size_t end = expressionStack.size(); - assert(end - start == 1); - curr->ifTrue = popExpression(); - if (next == BinaryConsts::Else) { - size_t start = expressionStack.size(); - processExpressions(); - size_t end = expressionStack.size(); - assert(end - start == 1); - curr->ifFalse = popExpression(); + curr->ifTrue = getMaybeBlock(); + if (lastSeparator == BinaryConsts::Else) { + curr->ifFalse = getMaybeBlock(); curr->finalize(); } + assert(lastSeparator == BinaryConsts::End); } void visitLoop(Loop *curr) { if (debug) std::cerr << "zz node: Loop" << std::endl; |