diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-type-printing.h | 28 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 6 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/wasm-type-printing.h b/src/wasm-type-printing.h index 685d488fd..3a8740350 100644 --- a/src/wasm-type-printing.h +++ b/src/wasm-type-printing.h @@ -24,6 +24,7 @@ #include "support/name.h" #include "support/utilities.h" #include "wasm-type.h" +#include "wasm.h" namespace wasm { @@ -93,6 +94,33 @@ struct IndexedTypeNameGenerator } }; +// Prints heap types stored in a module, falling back to the given +// FallbackGenerator if the module does not have a name for type type. +template<typename FallbackGenerator = DefaultTypeNameGenerator> +struct ModuleTypeNameGenerator + : TypeNameGeneratorBase<ModuleTypeNameGenerator<FallbackGenerator>> { + const Module& wasm; + DefaultTypeNameGenerator defaultGenerator; + FallbackGenerator& fallback; + + ModuleTypeNameGenerator(const Module& wasm, FallbackGenerator& fallback) + : wasm(wasm), fallback(fallback) {} + + // TODO: Use C++20 `requires` to clean this up. + template<class T = FallbackGenerator> + ModuleTypeNameGenerator( + const Module& wasm, + std::enable_if_t<std::is_same_v<T, DefaultTypeNameGenerator>>* = nullptr) + : ModuleTypeNameGenerator(wasm, defaultGenerator) {} + + TypeNames getNames(HeapType type) { + if (auto it = wasm.typeNames.find(type); it != wasm.typeNames.end()) { + return it->second; + } + return fallback.getNames(type); + } +}; + } // namespace wasm #endif // wasm_wasm_type_printing_h diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 64fd07759..e5493c8d1 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1867,6 +1867,10 @@ std::ostream& TypePrinter::print(HeapType type) { } } + os << "(type "; + printHeapTypeName(type); + os << " "; + if (isTemp(type)) { os << "(; temp ;) "; } @@ -1885,7 +1889,7 @@ std::ostream& TypePrinter::print(HeapType type) { } else { WASM_UNREACHABLE("unexpected type"); } - return os; + return os << ")"; } std::ostream& TypePrinter::print(const Tuple& tuple) { |