diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-11-11 14:27:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-11 14:27:53 -0800 |
commit | 63ddbc04cf75a45a05a2b1f11564563915ebdbec (patch) | |
tree | 4a449c0c53642aa803f48ce33d55155e9771dc8f /src/wasm/wasm-s-parser.cpp | |
parent | 4ad7a2cfd0b3ac14fbe767d50e4994f8297d37f6 (diff) | |
download | binaryen-63ddbc04cf75a45a05a2b1f11564563915ebdbec.tar.gz binaryen-63ddbc04cf75a45a05a2b1f11564563915ebdbec.tar.bz2 binaryen-63ddbc04cf75a45a05a2b1f11564563915ebdbec.zip |
Fix catch parsing (#2428)
- When a catch body is a block, call its `finalize` function with the
correct type
- Don't create a block when there's one instruction in a catch body
- Remove `makeCatch` from gen-s-parser.py; it's not necessary
- Fix a test case that has a `catch` without `try`
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index f666abc25..307c94375 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1597,7 +1597,7 @@ Expression* SExpressionWasmBuilder::makeIf(Element& s) { auto* block = allocator.alloc<Block>(); block->name = label; block->list.push_back(ret); - block->finalize(ret->type); + block->finalize(type); return block; } return ret; @@ -1794,7 +1794,7 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) { if (!elementStartsWith(*s[i], "catch")) { throw ParseException("catch clause does not exist", s[i]->line, s[i]->col); } - ret->catchBody = makeCatch(*s[i++]); + ret->catchBody = makeCatch(*s[i++], type); ret->finalize(type); nameMapper.popLabelName(label); // create a break target if we must @@ -1802,13 +1802,13 @@ Expression* SExpressionWasmBuilder::makeTry(Element& s) { auto* block = allocator.alloc<Block>(); block->name = label; block->list.push_back(ret); - block->finalize(ret->type); + block->finalize(type); return block; } return ret; } -Expression* SExpressionWasmBuilder::makeCatch(Element& s) { +Expression* SExpressionWasmBuilder::makeCatch(Element& s, Type type) { if (!elementStartsWith(s, "catch")) { throw ParseException("invalid catch clause", s.line, s.col); } @@ -1816,7 +1816,10 @@ Expression* SExpressionWasmBuilder::makeCatch(Element& s) { for (size_t i = 1; i < s.size(); i++) { ret->list.push_back(parseExpression(s[i])); } - ret->finalize(); + if (ret->list.size() == 1) { + return ret->list[0]; + } + ret->finalize(type); return ret; } |