diff options
author | Heejin Ahn <aheejin@gmail.com> | 2020-05-11 10:51:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 10:51:07 -0700 |
commit | 3de8c98b682e1347e5c50c58eaddc4b01f3e26ab (patch) | |
tree | c068fef90f72839106f6f15f48f34c12d526ef99 /src/wasm/wasm-s-parser.cpp | |
parent | 91ec2ee5bedefc4736fcda78ae39298846aeeb41 (diff) | |
download | binaryen-3de8c98b682e1347e5c50c58eaddc4b01f3e26ab.tar.gz binaryen-3de8c98b682e1347e5c50c58eaddc4b01f3e26ab.tar.bz2 binaryen-3de8c98b682e1347e5c50c58eaddc4b01f3e26ab.zip |
Make try body start with 'do' (#2846)
In WebAssembly/exception-handling#52, We decided to put `try` bodies in
a `do` clause to be more consistent with `catch`.
- Before
```wast
(try
...
(catch
...
)
)
```
- After
```wast
(try
(do
...
)
(catch
...
)
)
```
Another upside of this change is when there are multiple instructions
within a `try` body, we no longer need to wrap them in a `block`.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
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>(); |