diff options
author | Thomas Lively <tlively@google.com> | 2023-11-21 08:50:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-20 23:50:53 -0800 |
commit | cccc7a6a66b00ab79626afe02f259aa5290d479c (patch) | |
tree | 1f03896877a1d59ee9c7ae6c25194382f767e4c6 /src/wasm/wasm-ir-builder.cpp | |
parent | beb816be810caa0b32ab37986e7cae6f6cf11b1b (diff) | |
download | binaryen-cccc7a6a66b00ab79626afe02f259aa5290d479c.tar.gz binaryen-cccc7a6a66b00ab79626afe02f259aa5290d479c.tar.bz2 binaryen-cccc7a6a66b00ab79626afe02f259aa5290d479c.zip |
[Parser] Parse tags and throw (#6126)
Also fix the parser to correctly error if an imported item appears after a
non-imported item and make the corresponding fix to the test.
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index dfbf156b2..9bca1967b 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -445,6 +445,17 @@ Result<> IRBuilder::visitCallRef(CallRef* curr) { return Ok{}; } +Result<> IRBuilder::visitThrow(Throw* curr) { + auto numArgs = wasm.getTag(curr->tag)->sig.params.size(); + curr->operands.resize(numArgs); + for (size_t i = 0; i < numArgs; ++i) { + auto arg = pop(); + CHECK_ERR(arg); + curr->operands[numArgs - 1 - i] = *arg; + } + return Ok{}; +} + Result<> IRBuilder::visitFunctionStart(Function* func) { if (!scopeStack.empty()) { return Err{"unexpected start of function"}; @@ -1005,7 +1016,13 @@ Result<> IRBuilder::makeRefEq() { // Result<> IRBuilder::makeTry() {} -// Result<> IRBuilder::makeThrow() {} +Result<> IRBuilder::makeThrow(Name tag) { + Throw curr(wasm.allocator); + curr.tag = tag; + CHECK_ERR(visitThrow(&curr)); + push(builder.makeThrow(tag, curr.operands)); + return Ok{}; +} // Result<> IRBuilder::makeRethrow() {} |