diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-type.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index e46e0c6ae..2c7c3e232 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1450,6 +1450,33 @@ bool HeapType::isSubType(HeapType left, HeapType right) { return SubTyper().isSubType(left, right); } +std::vector<Type> HeapType::getTypeChildren() const { + if (isBasic()) { + return {}; + } + if (isStruct()) { + std::vector<Type> children; + for (auto& field : getStruct().fields) { + children.push_back(field.type); + } + return children; + } + if (isArray()) { + return {getArray().element.type}; + } + if (isSignature()) { + std::vector<Type> children; + auto sig = getSignature(); + for (auto tuple : {sig.params, sig.results}) { + for (auto t : tuple) { + children.push_back(t); + } + } + return children; + } + WASM_UNREACHABLE("unexpected kind"); +} + std::vector<HeapType> HeapType::getHeapTypeChildren() const { HeapTypeChildCollector collector; collector.walkRoot(const_cast<HeapType*>(this)); |