summaryrefslogtreecommitdiff
path: root/src/passes/Print.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-07-06 12:27:06 -0400
committerGitHub <noreply@github.com>2023-07-06 09:27:06 -0700
commit58db9e41a9b14d1efefdb96547954cbbf9633a74 (patch)
tree81be7bb610d43a40597c275f872ad2b84c488ccf /src/passes/Print.cpp
parentf806751623cb7341f8f151d392c52e090579dfbf (diff)
downloadbinaryen-58db9e41a9b14d1efefdb96547954cbbf9633a74.tar.gz
binaryen-58db9e41a9b14d1efefdb96547954cbbf9633a74.tar.bz2
binaryen-58db9e41a9b14d1efefdb96547954cbbf9633a74.zip
Print supertype declarations using the standard format (#5801)
Use the standard "(sub $super ...)" format instead of the non-standard "XXX_supertype ... $super" format. In a follow-on PR implementing final types, this will allow us to print and parse the standard text format for final types right away with a smaller diff.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r--src/passes/Print.cpp44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index ab5ef514f..5d49ad900 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2943,12 +2943,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
void handleSignature(HeapType curr, Name name = Name()) {
Signature sig = curr.getSignature();
- bool hasSupertype = !name.is() && !!curr.getSuperType();
- if (hasSupertype) {
- o << "(func_subtype";
- } else {
- o << "(func";
- }
+ o << "(func";
if (name.is()) {
o << " $" << name;
if (currModule && currModule->features.hasGC()) {
@@ -2978,10 +2973,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
}
o << ')';
}
- if (hasSupertype) {
- o << ' ';
- printSupertypeOr(curr, "func");
- }
o << ")";
}
void handleFieldBody(const Field& field) {
@@ -3004,27 +2995,13 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
}
}
void handleArray(HeapType curr) {
- bool hasSupertype = !!curr.getSuperType();
- if (hasSupertype) {
- o << "(array_subtype ";
- } else {
- o << "(array ";
- }
+ o << "(array ";
handleFieldBody(curr.getArray().element);
- if (hasSupertype) {
- o << ' ';
- printSupertypeOr(curr, "data");
- }
o << ')';
}
void handleStruct(HeapType curr) {
- bool hasSupertype = !!curr.getSuperType();
const auto& fields = curr.getStruct().fields;
- if (hasSupertype) {
- o << "(struct_subtype ";
- } else {
- o << "(struct ";
- }
+ o << "(struct ";
auto sep = "";
for (Index i = 0; i < fields.size(); i++) {
o << sep << "(field ";
@@ -3037,13 +3014,17 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
o << ')';
sep = " ";
}
- if (hasSupertype) {
- o << ' ';
- printSupertypeOr(curr, "data");
- }
o << ')';
}
void handleHeapType(HeapType type) {
+ bool hasSuper = false;
+ // TODO: Consider finality once we support that.
+ if (auto super = type.getSuperType()) {
+ hasSuper = true;
+ o << "(sub ";
+ TypeNamePrinter(o, currModule).print(*super);
+ o << ' ';
+ }
if (type.isSignature()) {
handleSignature(type);
} else if (type.isArray()) {
@@ -3053,6 +3034,9 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
} else {
o << type;
}
+ if (hasSuper) {
+ o << ')';
+ }
}
void visitExport(Export* curr) {
o << '(';