diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-05-14 15:43:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 15:43:57 -0700 |
commit | 8e73ee0d79c03468ca764adfa4ef869e53dcdff6 (patch) | |
tree | bf98e7cf4455377d084659f14c6232581b616c7b /src/wasm/wasm-s-parser.cpp | |
parent | 5db77a72a7c62d045e6650e96974fe1455fa1a1a (diff) | |
download | binaryen-8e73ee0d79c03468ca764adfa4ef869e53dcdff6.tar.gz binaryen-8e73ee0d79c03468ca764adfa4ef869e53dcdff6.tar.bz2 binaryen-8e73ee0d79c03468ca764adfa4ef869e53dcdff6.zip |
Make 'do' clause mandatory in 'try' (#2851)
Previously we were able to omit the new syntax `do` when `try` body is
empty. This makes `do` clause mandatory, so when a `try` body is empty,
the folded text format will be
```
(try
(do)
(catch
...
)
```
Suggested in
https://github.com/WebAssembly/exception-handling/issues/52#issuecomment-626696720.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index eae03faa6..65351fe99 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1825,15 +1825,11 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) { } auto label = nameMapper.pushLabelName(sName); Type type = parseOptionalResultType(s, i); // signature - if (elementStartsWith(*s[i], "catch")) { // empty try body - ret->body = makeNop(); - } else { - 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], "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); } @@ -1859,6 +1855,9 @@ SExpressionWasmBuilder::makeTryOrCatchBody(Element& s, Type type, bool isTry) { if (!isTry && !elementStartsWith(s, "catch")) { throw ParseException("invalid catch clause", s.line, s.col); } + if (s.size() == 1) { // (do) or (catch) without instructions + return makeNop(); + } auto ret = allocator.alloc<Block>(); for (size_t i = 1; i < s.size(); i++) { ret->list.push_back(parseExpression(s[i])); |