summaryrefslogtreecommitdiff
path: root/src/wasm-type.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-type.h')
-rw-r--r--src/wasm-type.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/wasm-type.h b/src/wasm-type.h
index c99113317..fa5650a31 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -56,6 +56,7 @@ void destroyAllTypesForTestingPurposesOnly();
// data.
class Type;
class HeapType;
+class RecGroup;
struct Tuple;
struct Signature;
struct Field;
@@ -352,6 +353,9 @@ public:
// number of supertypes in its supertype chain.
size_t getDepth() const;
+ // Get the recursion group for this non-basic type.
+ RecGroup getRecGroup() const;
+
constexpr TypeID getID() const { return id; }
constexpr BasicHeapType getBasic() const {
assert(isBasic() && "Basic heap type expected");
@@ -378,6 +382,30 @@ public:
std::string toString() const;
};
+// A recursion group consisting of one or more HeapTypes. HeapTypes with single
+// members are encoded without using any additional memory, which is why
+// `getHeapTypes` has to return a vector by value; it might have to create one
+// on the fly.
+class RecGroup {
+ uintptr_t id;
+
+public:
+ explicit RecGroup(uintptr_t id) : id(id) {}
+ bool operator==(const RecGroup& other) { return id == other.id; }
+ bool operator!=(const RecGroup& other) { return id != other.id; }
+ size_t size() const;
+
+ struct Iterator : ParentIndexIterator<const RecGroup*, Iterator> {
+ using value_type = HeapType;
+ using pointer = const HeapType*;
+ using reference = const HeapType&;
+ value_type operator*() const;
+ };
+
+ Iterator begin() const { return Iterator{{this, 0}}; }
+ Iterator end() const { return Iterator{{this, size()}}; }
+};
+
typedef std::vector<Type> TypeList;
// Passed by reference rather than by value because it can own an unbounded
@@ -556,6 +584,10 @@ struct TypeBuilder {
// `j`. Does nothing for equirecursive types.
void setSubType(size_t i, size_t j);
+ // Create a new recursion group covering slots [i, i + length). Groups must
+ // not overlap or go out of bounds.
+ void createRecGroup(size_t i, size_t length);
+
// Returns all of the newly constructed heap types. May only be called once
// all of the heap types have been initialized with `setHeapType`. In nominal
// mode, all of the constructed HeapTypes will be fresh and distinct. In