diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-type.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 1b8d7d0f1..68d7f732b 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1219,6 +1219,47 @@ std::optional<HeapType> HeapType::getDeclaredSuperType() const { return {}; } +std::optional<HeapType> HeapType::getSuperType() const { + auto ret = getDeclaredSuperType(); + if (ret) { + return ret; + } + + // There may be a basic supertype. + if (isBasic()) { + switch (getBasic()) { + case ext: + case noext: + case func: + case nofunc: + case any: + case none: + case string: + case stringview_wtf8: + case stringview_wtf16: + case stringview_iter: + return {}; + case eq: + return any; + case i31: + case struct_: + case array: + return eq; + } + } + + auto* info = getHeapTypeInfo(*this); + switch (info->kind) { + case HeapTypeInfo::SignatureKind: + return func; + case HeapTypeInfo::StructKind: + return struct_; + case HeapTypeInfo::ArrayKind: + return array; + } + WASM_UNREACHABLE("unexpected kind"); +} + size_t HeapType::getDepth() const { size_t depth = 0; std::optional<HeapType> super; |