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.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 049573fc5..c96ceabb6 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -1859,14 +1859,24 @@ void BinaryInstWriter::visitTry(Try* curr) {
emitResultType(curr->type);
}
-void BinaryInstWriter::emitCatch(Try* curr) {
+void BinaryInstWriter::emitCatch(Try* curr, Index i) {
assert(!breakStack.empty());
breakStack.pop_back();
breakStack.emplace_back(IMPOSSIBLE_CONTINUE);
+ // TODO Fix handling of BinaryLocations for the new EH spec
if (func && !sourceMap) {
parent.writeExtraDebugLocation(curr, func, BinaryLocations::Catch);
}
- o << int8_t(BinaryConsts::Catch);
+ o << int8_t(BinaryConsts::Catch)
+ << U32LEB(parent.getEventIndex(curr->catchEvents[i]));
+}
+
+void BinaryInstWriter::emitCatchAll(Try* curr) {
+ assert(!breakStack.empty());
+ breakStack.pop_back();
+ breakStack.emplace_back(IMPOSSIBLE_CONTINUE);
+ // TODO Fix handling of BinaryLocations for the new EH spec
+ o << int8_t(BinaryConsts::CatchAll);
}
void BinaryInstWriter::visitThrow(Throw* curr) {
@@ -1874,7 +1884,7 @@ void BinaryInstWriter::visitThrow(Throw* curr) {
}
void BinaryInstWriter::visitRethrow(Rethrow* curr) {
- o << int8_t(BinaryConsts::Rethrow);
+ o << int8_t(BinaryConsts::Rethrow) << U32LEB(curr->depth);
}
void BinaryInstWriter::visitBrOnExn(BrOnExn* curr) {
@@ -2200,23 +2210,29 @@ StackInst* StackIRGenerator::makeStackInst(StackInst::Op op,
void StackIRToBinaryWriter::write() {
writer.mapLocalsAndEmitHeader();
+ // Stack to track indices of catches within a try
+ SmallVector<Index, 4> catchIndexStack;
for (auto* inst : *func->stackIR) {
if (!inst) {
continue; // a nullptr is just something we can skip
}
switch (inst->op) {
+ case StackInst::TryBegin:
+ catchIndexStack.push_back(0);
+ // fallthrough
case StackInst::Basic:
case StackInst::BlockBegin:
case StackInst::IfBegin:
- case StackInst::LoopBegin:
- case StackInst::TryBegin: {
+ case StackInst::LoopBegin: {
writer.visit(inst->origin);
break;
}
+ case StackInst::TryEnd:
+ catchIndexStack.pop_back();
+ // fallthrough
case StackInst::BlockEnd:
case StackInst::IfEnd:
- case StackInst::LoopEnd:
- case StackInst::TryEnd: {
+ case StackInst::LoopEnd: {
writer.emitScopeEnd(inst->origin);
break;
}
@@ -2225,7 +2241,7 @@ void StackIRToBinaryWriter::write() {
break;
}
case StackInst::Catch: {
- writer.emitCatch(inst->origin->cast<Try>());
+ writer.emitCatch(inst->origin->cast<Try>(), catchIndexStack.back()++);
break;
}
default: