diff options
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 7bcf23b8e..5bdf84aba 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -2582,7 +2582,10 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { void handleSignature(HeapType curr, Name name = Name()) { Signature sig = curr.getSignature(); - if (!name.is() && getTypeSystem() == TypeSystem::Nominal) { + bool hasSupertype = + !name.is() && (getTypeSystem() == TypeSystem::Nominal || + getTypeSystem() == TypeSystem::Isorecursive); + if (hasSupertype) { o << "(func_subtype"; } else { o << "(func"; @@ -2612,7 +2615,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } o << ')'; } - if (!name.is() && getTypeSystem() == TypeSystem::Nominal) { + if (hasSupertype) { o << ' '; printSupertypeOr(curr, "func"); } @@ -2638,21 +2641,25 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { } } void handleArray(HeapType curr) { - if (getTypeSystem() == TypeSystem::Nominal) { + bool hasSupertype = getTypeSystem() == TypeSystem::Nominal || + getTypeSystem() == TypeSystem::Isorecursive; + if (hasSupertype) { o << "(array_subtype "; } else { o << "(array "; } handleFieldBody(curr.getArray().element); - if (getTypeSystem() == TypeSystem::Nominal) { + if (hasSupertype) { o << ' '; printSupertypeOr(curr, "data"); } o << ')'; } void handleStruct(HeapType curr) { + bool hasSupertype = getTypeSystem() == TypeSystem::Nominal || + getTypeSystem() == TypeSystem::Isorecursive; const auto& fields = curr.getStruct().fields; - if (getTypeSystem() == TypeSystem::Nominal) { + if (hasSupertype) { o << "(struct_subtype "; } else { o << "(struct "; @@ -2669,7 +2676,7 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { o << ')'; sep = " "; } - if (getTypeSystem() == TypeSystem::Nominal) { + if (hasSupertype) { o << ' '; printSupertypeOr(curr, "data"); } @@ -2779,7 +2786,8 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { o << '('; printMajor(o, "func "); printName(curr->name, o); - if (getTypeSystem() == TypeSystem::Nominal) { + if (getTypeSystem() == TypeSystem::Nominal || + getTypeSystem() == TypeSystem::Isorecursive) { o << " (type "; printHeapType(o, curr->type, currModule) << ')'; } @@ -3064,10 +3072,32 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { printName(curr->name, o); } incIndent(); + // Use the same type order as the binary output would even though there is // no code size benefit in the text format. auto indexedTypes = ModuleUtils::getOptimizedIndexedHeapTypes(*curr); + std::optional<RecGroup> currGroup; + bool nontrivialGroup = false; + auto finishGroup = [&]() { + if (nontrivialGroup) { + decIndent(); + o << maybeNewLine; + } + }; for (auto type : indexedTypes.types) { + RecGroup newGroup = type.getRecGroup(); + if (!currGroup || *currGroup != newGroup) { + if (currGroup) { + finishGroup(); + } + currGroup = newGroup; + nontrivialGroup = currGroup->size() > 1; + if (nontrivialGroup) { + doIndent(o, indent); + o << "(rec "; + incIndent(); + } + } doIndent(o, indent); o << '('; printMedium(o, "type") << ' '; @@ -3076,6 +3106,8 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> { handleHeapType(type); o << ")" << maybeNewLine; } + finishGroup(); + ModuleUtils::iterImportedMemories( *curr, [&](Memory* memory) { visitMemory(memory); }); ModuleUtils::iterImportedTables(*curr, |