summaryrefslogtreecommitdiff
path: root/src/wasm-s-parser.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-09-21 13:33:51 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-09-21 13:53:41 -0700
commit3355792fba29e62f02cf1f1acb3a219cf5a69970 (patch)
tree5b6b4145d05bf248e080b784d23ff1d43310f328 /src/wasm-s-parser.h
parent228b9a1cfc89ede2dcc064de9b2e60f53a047128 (diff)
downloadbinaryen-3355792fba29e62f02cf1f1acb3a219cf5a69970.tar.gz
binaryen-3355792fba29e62f02cf1f1acb3a219cf5a69970.tar.bz2
binaryen-3355792fba29e62f02cf1f1acb3a219cf5a69970.zip
new if label behavior
Diffstat (limited to 'src/wasm-s-parser.h')
-rw-r--r--src/wasm-s-parser.h54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 6e0eda826..ace7c31d7 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -1227,44 +1227,32 @@ private:
Expression* makeIf(Element& s) {
auto ret = allocator.alloc<If>();
Index i = 1;
+ Name label;
+ if (s[i]->dollared()) {
+ // the if is labeled
+ label = s[i++]->str();
+ } else {
+ label = getPrefixedName("if");
+ }
+ labelStack.push_back(label);
if (s[i]->isStr()) {
- // if type
+ // if type, TODO: parse?
i++;
}
ret->condition = parseExpression(s[i++]);
-
- // ifTrue and ifFalse may get implicit blocks
- auto handle = [&](const char* title, Element& s) {
- Name name = getPrefixedName(title);
- bool explicitThenElse = false;
- if (s[0]->str() == THEN || s[0]->str() == ELSE) {
- explicitThenElse = true;
- if (s[1]->isStr() && s[1]->dollared()) {
- name = s[1]->str();
- }
- }
- labelStack.push_back(name);
- auto* ret = parseExpression(&s);
- labelStack.pop_back();
- if (explicitThenElse) {
- ret->dynCast<Block>()->name = name;
- } else {
- // add a block if we must
- if (BreakSeeker::has(ret, name)) {
- auto* block = allocator.alloc<Block>();
- block->name = name;
- block->list.push_back(ret);
- block->finalize();
- ret = block;
- }
- }
- return ret;
- };
-
- ret->ifTrue = handle("if-true", *s[i++]);
+ ret->ifTrue = parseExpression(*s[i++]);
if (i < s.size()) {
- ret->ifFalse = handle("if-else", *s[i++]);
- ret->finalize();
+ ret->ifFalse = parseExpression(*s[i++]);
+ }
+ ret->finalize();
+ labelStack.pop_back();
+ // create a break target if we must
+ if (BreakSeeker::has(ret, label)) {
+ auto* block = allocator.alloc<Block>();
+ block->name = label;
+ block->list.push_back(ret);
+ block->finalize();
+ return block;
}
return ret;
}