Skip to content

Commit 5ad90cb

Browse files
authored
Use standard type printing for BINARYEN_PRINT_FULL (#7447)
`printTypeOrName`, used to print types for BINARYEN_PRINT_FULL and a few other niche use cases, previously had bespoke printing for references that did not follow the standard format. To improve the output and reduce the number of ways we print types, change it to use the standard printing utility.
1 parent e0c20f3 commit 5ad90cb

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/passes/Print.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ std::ostream& printLocal(Index index, Function* func, std::ostream& o) {
8282
// Print a name from the type section, if available. Otherwise print the type
8383
// normally.
8484
void printTypeOrName(Type type, std::ostream& o, Module* wasm) {
85-
if (type.isRef() && wasm) {
86-
auto heapType = type.getHeapType();
87-
auto iter = wasm->typeNames.find(heapType);
88-
if (iter != wasm->typeNames.end()) {
89-
o << iter->second.name;
90-
if (type.isNullable()) {
91-
o << " null";
85+
struct Printer : TypeNameGeneratorBase<Printer> {
86+
Module* wasm;
87+
DefaultTypeNameGenerator fallback;
88+
Printer(Module* wasm) : wasm(wasm) {}
89+
TypeNames getNames(HeapTypeDef type) {
90+
if (wasm) {
91+
if (auto it = wasm->typeNames.find(type); it != wasm->typeNames.end()) {
92+
return it->second;
93+
}
9294
}
93-
return;
95+
return fallback.getNames(type);
9496
}
95-
}
96-
97-
// No luck with a name, just print the test as best we can.
98-
o << type;
97+
} print{wasm};
98+
o << print(type);
9999
}
100100

101101
} // anonymous namespace

test/lit/passes/gsi-debug.wast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
;; CHECK-NEXT: ;;@
4848
;; CHECK-NEXT: (ref.as_non_null
4949
;; CHECK-NEXT: ;;@ local.c:30:3
50-
;; CHECK-NEXT: (local.get $struct) (; struct null ;)
51-
;; CHECK-NEXT: ) (; struct ;)
50+
;; CHECK-NEXT: (local.get $struct) (; (ref null $struct) ;)
51+
;; CHECK-NEXT: ) (; (ref $struct) ;)
5252
;; CHECK-NEXT: ;;@
53-
;; CHECK-NEXT: (global.get $global1) (; struct ;)
53+
;; CHECK-NEXT: (global.get $global1) (; (ref $struct) ;)
5454
;; CHECK-NEXT: ) (; i32 ;)
5555
;; CHECK-NEXT: ) (; i32 ;)
5656
;; CHECK-NEXT: ) (; none ;)

0 commit comments

Comments
 (0)