summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2022-09-22 18:00:50 -0500
committerGitHub <noreply@github.com>2022-09-22 16:00:50 -0700
commit58bedde3ac54f82657d5de092e7142ffb2ff735c (patch)
treee486638a92aeca615439bbcd11b540f4913b98a1 /src/passes/Print.cpp
parentb1ba25732c1a02ae3da726c4b01ca3825ef969ef (diff)
downloadbinaryen-58bedde3ac54f82657d5de092e7142ffb2ff735c.tar.gz
binaryen-58bedde3ac54f82657d5de092e7142ffb2ff735c.tar.bz2
binaryen-58bedde3ac54f82657d5de092e7142ffb2ff735c.zip
Add a type annotation to return_call_ref (#5068)
The GC spec has been updated to have heap type annotations on call_ref and return_call_ref. To avoid breaking users, we will have a graceful, multi-step upgrade to the annotated version of call_ref, but since return_call_ref has no users yet, update it in a single step.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index d1e08e0ec..04d487c08 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2043,9 +2043,31 @@ struct PrintExpressionContents
void visitI31Get(I31Get* curr) {
printMedium(o, curr->signed_ ? "i31.get_s" : "i31.get_u");
}
+
+ // If we cannot print a valid unreachable instruction (say, a struct.get,
+ // where if the ref is unreachable, we don't know what heap type to print),
+ // then print the children in a block, which is good enough as this
+ // instruction is never reached anyhow.
+ //
+ // This function checks if the input is in fact unreachable, and if so, begins
+ // to emit a replacement for it and returns true.
+ bool printUnreachableReplacement(Expression* curr) {
+ if (curr->type == Type::unreachable) {
+ printMedium(o, "block");
+ return true;
+ }
+ return false;
+ }
+
void visitCallRef(CallRef* curr) {
if (curr->isReturn) {
- printMedium(o, "return_call_ref");
+ if (printUnreachableReplacement(curr->target)) {
+ return;
+ }
+ printMedium(o, "return_call_ref ");
+ assert(curr->target->type != Type::unreachable);
+ // TODO: Workaround if target has bottom type.
+ printHeapType(o, curr->target->type.getHeapType(), wasm);
} else {
printMedium(o, "call_ref");
}
@@ -2106,22 +2128,6 @@ struct PrintExpressionContents
}
printName(curr->name, o);
}
-
- // If we cannot print a valid unreachable instruction (say, a struct.get,
- // where if the ref is unreachable, we don't know what heap type to print),
- // then print the children in a block, which is good enough as this
- // instruction is never reached anyhow.
- //
- // This function checks if the input is in fact unreachable, and if so, begins
- // to emit a replacement for it and returns true.
- bool printUnreachableReplacement(Expression* curr) {
- if (curr->type == Type::unreachable) {
- printMedium(o, "block");
- return true;
- }
- return false;
- }
-
void visitStructNew(StructNew* curr) {
if (printUnreachableReplacement(curr)) {
return;
@@ -2748,6 +2754,13 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
}
decIndent();
}
+ void visitCallRef(CallRef* curr) {
+ if (curr->isReturn) {
+ maybePrintUnreachableReplacement(curr, curr->target->type);
+ } else {
+ visitExpression(curr);
+ }
+ }
void visitStructNew(StructNew* curr) {
maybePrintUnreachableReplacement(curr, curr->type);
}