From 3355792fba29e62f02cf1f1acb3a219cf5a69970 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 21 Sep 2016 13:33:51 -0700 Subject: new if label behavior --- src/wasm-s-parser.h | 54 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) (limited to 'src') 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(); 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()->name = name; - } else { - // add a block if we must - if (BreakSeeker::has(ret, name)) { - auto* block = allocator.alloc(); - 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->name = label; + block->list.push_back(ret); + block->finalize(); + return block; } return ret; } -- cgit v1.2.3