diff options
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index c597028be..ba3981e21 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -141,6 +141,11 @@ struct TypeName { TypeName(Type type) : type(type) {} }; +struct HeapTypeName { + HeapType type; + HeapTypeName(HeapType type) : type(type) {} +}; + std::ostream& operator<<(std::ostream& os, TypeName typeName) { auto type = typeName.type; if (type.isRef() && !type.isBasic()) { @@ -160,6 +165,16 @@ std::ostream& operator<<(std::ostream& os, TypeName typeName) { return os << SExprType(typeName.type); } +std::ostream& operator<<(std::ostream& os, HeapTypeName typeName) { + auto type = typeName.type; + if (type.isSignature()) { + os << SigName(type.getSignature()); + } else { + os << type; + } + return os; +} + } // anonymous namespace // Printing "unreachable" as a instruction prefix type is not valid in wasm text @@ -2348,10 +2363,10 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { WASM_UNREACHABLE("TODO (gc): array.len"); } // Module-level visitors - void handleSignature(Signature curr, Name* funcName = nullptr) { + void handleSignature(Signature curr, Name name = Name()) { o << "(func"; - if (funcName) { - o << " $" << *funcName; + if (name.is()) { + o << " $" << name; } if (curr.params.size() > 0) { o << maybeSpace; @@ -2375,6 +2390,13 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { } o << ")"; } + void handleHeapType(HeapType type) { + if (type.isSignature()) { + handleSignature(type.getSignature()); + } else { + WASM_UNREACHABLE("unsupported heap type"); + } + } void visitExport(Export* curr) { o << '('; printMedium(o, "export "); @@ -2453,7 +2475,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { lastPrintedLocation = {0, 0, 0}; o << '('; emitImportHeader(curr); - handleSignature(curr->sig, &curr->name); + handleSignature(curr->sig, curr->name); o << ')'; o << maybeNewLine; } @@ -2702,15 +2724,15 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { printName(curr->name, o); } incIndent(); - std::vector<Signature> signatures; - std::unordered_map<Signature, Index> indices; - ModuleUtils::collectSignatures(*curr, signatures, indices); - for (auto sig : signatures) { + std::vector<HeapType> types; + std::unordered_map<HeapType, Index> indices; + ModuleUtils::collectHeapTypes(*curr, types, indices); + for (auto type : types) { doIndent(o, indent); o << '('; printMedium(o, "type") << ' '; - o << SigName(sig) << ' '; - handleSignature(sig); + o << HeapTypeName(type) << ' '; + handleHeapType(type); o << ")" << maybeNewLine; } ModuleUtils::iterImportedMemories( |