From 79d405b82b648cc406a12ce7164a4ef31279c67c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 8 Feb 2016 10:54:19 -0800 Subject: update spec tests and shift to putting the br_if condition at the end, as was just changed to in the spec --- src/wasm-interpreter.h | 10 +++++----- src/wasm-s-parser.h | 13 ++++++++----- src/wasm.h | 7 ++++--- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 3f9427ed7..73a536903 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -233,17 +233,17 @@ private: Flow visitBreak(Break *curr) { NOTE_ENTER("Break"); bool condition = true; - if (curr->condition) { - Flow flow = visit(curr->condition); - if (flow.breaking()) return flow; - condition = flow.value.getInteger(); - } Flow flow(curr->name); if (curr->value) { flow = visit(curr->value); if (flow.breaking()) return flow; flow.breakTo = curr->name; } + if (curr->condition) { + Flow conditionFlow = visit(curr->condition); + if (conditionFlow.breaking()) return conditionFlow; + condition = conditionFlow.value.getInteger(); + } return condition ? flow : Flow(); } Flow visitSwitch(Switch *curr) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index dc946fc3b..ce216fd8e 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -868,10 +868,6 @@ private: Expression* makeBreak(Element& s) { auto ret = allocator.alloc(); size_t i = 1; - if (s[0]->str() == BR_IF) { - ret->condition = parseExpression(s[i]); - i++; - } if (s[i]->dollared()) { ret->name = s[i]->str(); } else { @@ -881,7 +877,14 @@ private: ret->name = labelStack[labelStack.size() - 1 - offset]; } i++; - if (i < s.size()) { + if (i == s.size()) return ret; + if (s[0]->str() == BR_IF) { + if (i + 1 < s.size()) { + ret->value = parseExpression(s[i]); + i++; + } + ret->condition = parseExpression(s[i]); + } else { ret->value = parseExpression(s[i]); } return ret; diff --git a/src/wasm.h b/src/wasm.h index 893c777c4..20a7b34ef 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -511,10 +511,8 @@ public: std::ostream& doPrint(std::ostream &o, unsigned indent) { if (condition) { - printOpening(o, "br_if"); + printOpening(o, "br_if ") << name; incIndent(o, indent); - printFullLine(o, indent, condition); - doIndent(o, indent) << name << '\n'; } else { printOpening(o, "br ") << name; if (!value || value->is()) { @@ -525,6 +523,9 @@ public: incIndent(o, indent); } if (value && !value->is()) printFullLine(o, indent, value); + if (condition) { + printFullLine(o, indent, condition); + } return decIndent(o, indent); } }; -- cgit v1.2.3