summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-stack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-stack.cpp')
-rw-r--r--src/wasm/wasm-stack.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 00b1e5368..cb9d94093 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -1904,7 +1904,7 @@ void BinaryInstWriter::visitRefEq(RefEq* curr) {
}
void BinaryInstWriter::visitTry(Try* curr) {
- breakStack.emplace_back(IMPOSSIBLE_CONTINUE);
+ breakStack.push_back(curr->name);
o << int8_t(BinaryConsts::Try);
emitResultType(curr->type);
}
@@ -1924,6 +1924,13 @@ void BinaryInstWriter::emitCatchAll(Try* curr) {
o << int8_t(BinaryConsts::CatchAll);
}
+void BinaryInstWriter::emitDelegate(Try* curr) {
+ assert(!breakStack.empty());
+ breakStack.pop_back();
+ o << int8_t(BinaryConsts::Delegate)
+ << U32LEB(getBreakIndex(curr->delegateTarget));
+}
+
void BinaryInstWriter::visitThrow(Throw* curr) {
o << int8_t(BinaryConsts::Throw) << U32LEB(parent.getEventIndex(curr->event));
}
@@ -2216,6 +2223,9 @@ void BinaryInstWriter::emitMemoryAccess(size_t alignment,
}
int32_t BinaryInstWriter::getBreakIndex(Name name) { // -1 if not found
+ if (name == DELEGATE_CALLER_TARGET) {
+ return breakStack.size();
+ }
for (int i = breakStack.size() - 1; i >= 0; i--) {
if (breakStack[i] == name) {
return breakStack.size() - 1 - i;
@@ -2321,6 +2331,10 @@ void StackIRToBinaryWriter::write() {
writer.emitCatchAll(inst->origin->cast<Try>());
break;
}
+ case StackInst::Delegate: {
+ writer.emitDelegate(inst->origin->cast<Try>());
+ break;
+ }
default:
WASM_UNREACHABLE("unexpected op");
}