summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp50
-rw-r--r--src/passes/StackIR.cpp1
-rw-r--r--src/wasm/wasm-stack.cpp4
3 files changed, 43 insertions, 12 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 91e44d397..67deac35c 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2478,7 +2478,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
printExpressionContents(curr);
incIndent();
doIndent(o, indent);
- o << "(do";
+ o << '(';
+ printMedium(o, "do");
incIndent();
maybePrintImplicitBlock(curr->body, true);
decIndent();
@@ -2486,7 +2487,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
for (size_t i = 0; i < curr->catchEvents.size(); i++) {
doIndent(o, indent);
printDebugDelimiterLocation(curr, i);
- o << "(catch ";
+ o << '(';
+ printMedium(o, "catch ");
printName(curr->catchEvents[i], o);
incIndent();
maybePrintImplicitBlock(curr->catchBodies[i], true);
@@ -3268,15 +3270,23 @@ printStackInst(StackInst* inst, std::ostream& o, Function* func) {
case StackInst::IfEnd:
case StackInst::LoopEnd:
case StackInst::TryEnd: {
- o << "end (" << inst->type << ')';
+ printMedium(o, "end");
+ o << " ;; type: ";
+ printTypeName(o, inst->type);
break;
}
case StackInst::IfElse: {
- o << "else";
+ printMedium(o, "else");
break;
}
case StackInst::Catch: {
- o << "catch";
+ // Because StackInst does not have info on which catch within a try this
+ // is, we can't print the event name.
+ printMedium(o, "catch");
+ break;
+ }
+ case StackInst::CatchAll: {
+ printMedium(o, "catch_all");
break;
}
default:
@@ -3293,6 +3303,9 @@ printStackIR(StackIR* ir, std::ostream& o, Function* func) {
o << ' ';
}
};
+
+ // Stack to track indices of catches within a try
+ SmallVector<Index, 4> catchIndexStack;
for (Index i = 0; i < (*ir).size(); i++) {
auto* inst = (*ir)[i];
if (!inst) {
@@ -3309,35 +3322,48 @@ printStackIR(StackIR* ir, std::ostream& o, Function* func) {
PrintExpressionContents(func, o).visit(inst->origin);
break;
}
+ case StackInst::TryBegin:
+ catchIndexStack.push_back(0);
+ // fallthrough
case StackInst::BlockBegin:
case StackInst::IfBegin:
- case StackInst::LoopBegin:
- case StackInst::TryBegin: {
+ case StackInst::LoopBegin: {
doIndent();
PrintExpressionContents(func, o).visit(inst->origin);
indent++;
break;
}
+ case StackInst::TryEnd:
+ catchIndexStack.pop_back();
+ // fallthrough
case StackInst::BlockEnd:
case StackInst::IfEnd:
- case StackInst::LoopEnd:
- case StackInst::TryEnd: {
+ case StackInst::LoopEnd: {
indent--;
doIndent();
- o << "end";
+ printMedium(o, "end");
break;
}
case StackInst::IfElse: {
indent--;
doIndent();
- o << "else";
+ printMedium(o, "else");
indent++;
break;
}
case StackInst::Catch: {
indent--;
doIndent();
- o << "catch";
+ printMedium(o, "catch ");
+ Try* curr = inst->origin->cast<Try>();
+ printName(curr->catchEvents[catchIndexStack.back()++], o);
+ indent++;
+ break;
+ }
+ case StackInst::CatchAll: {
+ indent--;
+ doIndent();
+ printMedium(o, "catch_all");
indent++;
break;
}
diff --git a/src/passes/StackIR.cpp b/src/passes/StackIR.cpp
index ee2062b3d..0732a6499 100644
--- a/src/passes/StackIR.cpp
+++ b/src/passes/StackIR.cpp
@@ -257,6 +257,7 @@ private:
case StackInst::IfEnd:
case StackInst::LoopEnd:
case StackInst::Catch:
+ case StackInst::CatchAll:
case StackInst::TryEnd: {
return true;
}
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index cb8702d0c..95cb4a44c 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2316,6 +2316,10 @@ void StackIRToBinaryWriter::write() {
writer.emitCatch(inst->origin->cast<Try>(), catchIndexStack.back()++);
break;
}
+ case StackInst::CatchAll: {
+ writer.emitCatchAll(inst->origin->cast<Try>());
+ break;
+ }
default:
WASM_UNREACHABLE("unexpected op");
}