diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-10-14 14:11:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-14 21:11:59 +0000 |
commit | bf665976b1526ca7cf11bacf5745563dfe193206 (patch) | |
tree | a6bb2cf0fa5d1972fe55f872418665778e00dde5 /src/passes/Print.cpp | |
parent | d592bad2b8fa777dab9682d2d2e47f9957c8051d (diff) | |
download | binaryen-bf665976b1526ca7cf11bacf5745563dfe193206.tar.gz binaryen-bf665976b1526ca7cf11bacf5745563dfe193206.tar.bz2 binaryen-bf665976b1526ca7cf11bacf5745563dfe193206.zip |
Switch from "extends" to M4 nominal syntax (#4248)
Switch from "extends" to M4 nominal syntax
Change all test inputs from using the old (extends $super) syntax to using the
new *_subtype syntax for their inputs and also update the printer to emit the
new syntax. Add a new test explicitly testing the old notation to make sure it
keeps working until we remove support for it.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index abea90117..fee59ce3b 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2510,9 +2510,22 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { visitExpression(curr); } // Module-level visitors + void printSupertypeOr(HeapType curr, std::string noSuper) { + HeapType super; + if (curr.getSuperType(super)) { + TypeNamePrinter(o, currModule).print(super); + } else { + o << noSuper; + } + } + void handleSignature(HeapType curr, Name name = Name()) { Signature sig = curr.getSignature(); - o << "(func"; + if (!name.is() && getTypeSystem() == TypeSystem::Nominal) { + o << "(func_subtype"; + } else { + o << "(func"; + } if (name.is()) { o << " $" << name; } @@ -2538,6 +2551,10 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } o << ')'; } + if (!name.is() && getTypeSystem() == TypeSystem::Nominal) { + o << ' '; + printSupertypeOr(curr, "func"); + } o << ")"; } void handleFieldBody(const Field& field) { @@ -2560,13 +2577,25 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } } void handleArray(HeapType curr) { - o << "(array "; + if (getTypeSystem() == TypeSystem::Nominal) { + o << "(array_subtype "; + } else { + o << "(array "; + } handleFieldBody(curr.getArray().element); + if (getTypeSystem() == TypeSystem::Nominal) { + o << ' '; + printSupertypeOr(curr, "data"); + } o << ')'; } void handleStruct(HeapType curr) { const auto& fields = curr.getStruct().fields; - o << "(struct "; + if (getTypeSystem() == TypeSystem::Nominal) { + o << "(struct_subtype "; + } else { + o << "(struct "; + } auto sep = ""; for (Index i = 0; i < fields.size(); i++) { o << sep << "(field "; @@ -2579,9 +2608,13 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { o << ')'; sep = " "; } + if (getTypeSystem() == TypeSystem::Nominal) { + o << ' '; + printSupertypeOr(curr, "data"); + } o << ')'; } - void handleHeapType(HeapType type, Module* module) { + void handleHeapType(HeapType type) { if (type.isSignature()) { handleSignature(type); } else if (type.isArray()) { @@ -2591,12 +2624,6 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } else { o << type; } - HeapType super; - if (type.getSuperType(super)) { - o << " (extends "; - TypeNamePrinter(o, module).print(super); - o << ')'; - } } void visitExport(Export* curr) { o << '('; @@ -2981,7 +3008,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { printMedium(o, "type") << ' '; TypeNamePrinter(o, curr).print(type); o << ' '; - handleHeapType(type, curr); + handleHeapType(type); o << ")" << maybeNewLine; } ModuleUtils::iterImportedMemories( |