summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp11
-rw-r--r--src/wasm-s-parser.h2
-rw-r--r--src/wasm/wasm-s-parser.cpp16
3 files changed, 22 insertions, 7 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index a87eae325..0839b3feb 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -1930,9 +1930,11 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
}
// try-catch-end is written in the folded wat format as
// (try
+ // (do
// ...
+ // )
// (catch
- // ...
+ // ...
// )
// )
// The parenthesis wrapping 'catch' is just a syntax and does not affect
@@ -1941,7 +1943,12 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
o << '(';
PrintExpressionContents(currFunction, o).visit(curr);
incIndent();
- maybePrintImplicitBlock(curr->body, false);
+ doIndent(o, indent);
+ o << "(do";
+ incIndent();
+ maybePrintImplicitBlock(curr->body, true);
+ decIndent();
+ o << "\n";
doIndent(o, indent);
o << "(catch";
incIndent();
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 24cb7914a..6cbef5599 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -232,7 +232,7 @@ private:
Expression* makeRefIsNull(Element& s);
Expression* makeRefFunc(Element& s);
Expression* makeTry(Element& s);
- Expression* makeCatch(Element& s, Type type);
+ Expression* makeTryOrCatchBody(Element& s, Type type, bool isTry);
Expression* makeThrow(Element& s);
Expression* makeRethrow(Element& s);
Expression* makeBrOnExn(Element& s);
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index a39e52b6d..eae03faa6 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1828,12 +1828,16 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) {
if (elementStartsWith(*s[i], "catch")) { // empty try body
ret->body = makeNop();
} else {
- ret->body = parseExpression(*s[i++]);
+ if (!elementStartsWith(*s[i], "do")) {
+ throw ParseException(
+ "try body should start with 'do'", s[i]->line, s[i]->col);
+ }
+ ret->body = makeTryOrCatchBody(*s[i++], type, true);
}
if (!elementStartsWith(*s[i], "catch")) {
throw ParseException("catch clause does not exist", s[i]->line, s[i]->col);
}
- ret->catchBody = makeCatch(*s[i++], type);
+ ret->catchBody = makeTryOrCatchBody(*s[i++], type, false);
ret->finalize(type);
nameMapper.popLabelName(label);
// create a break target if we must
@@ -1847,8 +1851,12 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) {
return ret;
}
-Expression* SExpressionWasmBuilder::makeCatch(Element& s, Type type) {
- if (!elementStartsWith(s, "catch")) {
+Expression*
+SExpressionWasmBuilder::makeTryOrCatchBody(Element& s, Type type, bool isTry) {
+ if (isTry && !elementStartsWith(s, "do")) {
+ throw ParseException("invalid try do clause", s.line, s.col);
+ }
+ if (!isTry && !elementStartsWith(s, "catch")) {
throw ParseException("invalid catch clause", s.line, s.col);
}
auto ret = allocator.alloc<Block>();