summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2019-11-11 14:27:53 -0800
committerGitHub <noreply@github.com>2019-11-11 14:27:53 -0800
commit63ddbc04cf75a45a05a2b1f11564563915ebdbec (patch)
tree4a449c0c53642aa803f48ce33d55155e9771dc8f /src
parent4ad7a2cfd0b3ac14fbe767d50e4994f8297d37f6 (diff)
downloadbinaryen-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')
-rw-r--r--src/gen-s-parser.inc20
-rw-r--r--src/wasm-s-parser.h2
-rw-r--r--src/wasm/wasm-s-parser.cpp13
3 files changed, 15 insertions, 20 deletions
diff --git a/src/gen-s-parser.inc b/src/gen-s-parser.inc
index 5e6e37f5a..59dc23077 100644
--- a/src/gen-s-parser.inc
+++ b/src/gen-s-parser.inc
@@ -57,20 +57,12 @@ switch (op[0]) {
}
}
case 'c': {
- switch (op[2]) {
- case 'l': {
- switch (op[4]) {
- case '\0':
- if (strcmp(op, "call") == 0) { return makeCall(s, /*isReturn=*/false); }
- goto parse_error;
- case '_':
- if (strcmp(op, "call_indirect") == 0) { return makeCallIndirect(s, /*isReturn=*/false); }
- goto parse_error;
- default: goto parse_error;
- }
- }
- case 't':
- if (strcmp(op, "catch") == 0) { return makeCatch(s); }
+ switch (op[4]) {
+ case '\0':
+ if (strcmp(op, "call") == 0) { return makeCall(s, /*isReturn=*/false); }
+ goto parse_error;
+ case '_':
+ if (strcmp(op, "call_indirect") == 0) { return makeCallIndirect(s, /*isReturn=*/false); }
goto parse_error;
default: goto parse_error;
}
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index c7d43b581..924c1d968 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -224,7 +224,7 @@ private:
Expression* makeBreakTable(Element& s);
Expression* makeReturn(Element& s);
Expression* makeTry(Element& s);
- Expression* makeCatch(Element& s);
+ Expression* makeCatch(Element& s, Type type);
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 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;
}