diff options
author | Alon Zakai <azakai@google.com> | 2022-06-29 18:17:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-29 18:17:32 -0700 |
commit | dde06039e7327351a27a574d37d64f289f420ab2 (patch) | |
tree | 065f4d4a3dade57fe4f3159c981208499908e4bd /src | |
parent | 19f4db6ef5263a578baef7e64bf9c9169bb771e6 (diff) | |
download | binaryen-dde06039e7327351a27a574d37d64f289f420ab2.tar.gz binaryen-dde06039e7327351a27a574d37d64f289f420ab2.tar.bz2 binaryen-dde06039e7327351a27a574d37d64f289f420ab2.zip |
[Strings] Print shorthand types where possible (#4763)
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Print.cpp | 16 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 18 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index c9ef1a224..70e32e5d7 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -274,6 +274,22 @@ static std::ostream& printType(std::ostream& o, Type type, Module* wasm) { TypeNamePrinter(o, wasm).print(rtt.heapType); o << ')'; } else if (type.isRef() && !type.isBasic()) { + auto heapType = type.getHeapType(); + if (type.isNullable() && heapType.isBasic()) { + // Print shorthands for certain nullable basic heap types. + switch (heapType.getBasic()) { + case HeapType::string: + return o << "stringref"; + case HeapType::stringview_wtf8: + return o << "stringview_wtf8"; + case HeapType::stringview_wtf16: + return o << "stringview_wtf16"; + case HeapType::stringview_iter: + return o << "stringview_iter"; + default: + break; + } + } o << "(ref "; if (type.isNullable()) { o << "null "; diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index b79080121..85f3f0cfc 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -2103,11 +2103,27 @@ std::ostream& TypePrinter::print(Type type) { if (type.isTuple()) { print(type.getTuple()); } else if (type.isRef()) { + auto heapType = type.getHeapType(); + if (type.isNullable() && heapType.isBasic()) { + // Print shorthands for certain nullable basic heap types. + switch (heapType.getBasic()) { + case HeapType::string: + return os << "stringref"; + case HeapType::stringview_wtf8: + return os << "stringview_wtf8"; + case HeapType::stringview_wtf16: + return os << "stringview_wtf16"; + case HeapType::stringview_iter: + return os << "stringview_iter"; + default: + break; + } + } os << "(ref "; if (type.isNullable()) { os << "null "; } - printHeapTypeName(type.getHeapType()); + printHeapTypeName(heapType); os << ')'; } else if (type.isRtt()) { print(type.getRtt()); |