summaryrefslogtreecommitdiff
path: root/src/wasm-type.h
diff options
context:
space:
mode:
authorFrank Emrich <git@emrich.io>2023-10-25 00:16:12 +0100
committerGitHub <noreply@github.com>2023-10-24 16:16:12 -0700
commit02e5b160a1625ca8e2bf24bff9b4e06d012cf417 (patch)
tree0763490e387856d2cc62eb9a93d3a8d01996b3ec /src/wasm-type.h
parentec8220f4aa556ce39145db13eddd84855b11f76c (diff)
downloadbinaryen-02e5b160a1625ca8e2bf24bff9b4e06d012cf417.tar.gz
binaryen-02e5b160a1625ca8e2bf24bff9b4e06d012cf417.tar.bz2
binaryen-02e5b160a1625ca8e2bf24bff9b4e06d012cf417.zip
Typed Continuations: Add cont type (#5998)
This PR is part of a series that adds basic support for the [typed continuations proposal](https://github.com/wasmfx/specfx). This PR adds continuation types, of the form `(cont $foo)` for some function type `$foo`. The only notable changes affecting existing code are the following: - This is the first `HeapType` which has another `HeapType` (rather than, say, a `Type`) as its immediate child. This required fixes to certain traversals that have a flag for being at the toplevel of a type. - Some shared logic for parsing `HeapType`s has been factored out.
Diffstat (limited to 'src/wasm-type.h')
-rw-r--r--src/wasm-type.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/wasm-type.h b/src/wasm-type.h
index 23ceb9143..0061b9626 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -52,6 +52,7 @@ class Type;
class HeapType;
class RecGroup;
struct Signature;
+struct Continuation;
struct Field;
struct Struct;
struct Array;
@@ -345,6 +346,8 @@ public:
// this signature.
HeapType(Signature signature);
+ HeapType(Continuation cont);
+
// Create a HeapType with the given structure. In equirecursive mode, this may
// be the same as a previous HeapType created with the same contents. In
// nominal mode, this will be a fresh type distinct from all previously
@@ -358,6 +361,7 @@ public:
bool isFunction() const;
bool isData() const;
bool isSignature() const;
+ bool isContinuation() const;
bool isStruct() const;
bool isArray() const;
bool isString() const;
@@ -365,6 +369,8 @@ public:
bool isOpen() const;
Signature getSignature() const;
+ Continuation getContinuation() const;
+
const Struct& getStruct() const;
Array getArray() const;
@@ -476,6 +482,16 @@ struct Signature {
std::string toString() const;
};
+struct Continuation {
+ HeapType type;
+ Continuation(HeapType type) : type(type) {}
+ bool operator==(const Continuation& other) const {
+ return type == other.type;
+ }
+ bool operator!=(const Continuation& other) const { return !(*this == other); }
+ std::string toString() const;
+};
+
struct Field {
Type type;
enum PackedType {
@@ -570,6 +586,7 @@ struct TypeBuilder {
// Sets the heap type at index `i`. May only be called before `build`.
void setHeapType(size_t i, Signature signature);
+ void setHeapType(size_t i, Continuation continuation);
void setHeapType(size_t i, const Struct& struct_);
void setHeapType(size_t i, Struct&& struct_);
void setHeapType(size_t i, Array array);
@@ -640,6 +657,10 @@ struct TypeBuilder {
builder.setHeapType(index, signature);
return *this;
}
+ Entry& operator=(Continuation continuation) {
+ builder.setHeapType(index, continuation);
+ return *this;
+ }
Entry& operator=(const Struct& struct_) {
builder.setHeapType(index, struct_);
return *this;
@@ -687,6 +708,7 @@ std::ostream& operator<<(std::ostream&, HeapType);
std::ostream& operator<<(std::ostream&, HeapType::Printed);
std::ostream& operator<<(std::ostream&, Tuple);
std::ostream& operator<<(std::ostream&, Signature);
+std::ostream& operator<<(std::ostream&, Continuation);
std::ostream& operator<<(std::ostream&, Field);
std::ostream& operator<<(std::ostream&, Struct);
std::ostream& operator<<(std::ostream&, Array);
@@ -704,6 +726,10 @@ template<> class hash<wasm::Signature> {
public:
size_t operator()(const wasm::Signature&) const;
};
+template<> class hash<wasm::Continuation> {
+public:
+ size_t operator()(const wasm::Continuation&) const;
+};
template<> class hash<wasm::Field> {
public:
size_t operator()(const wasm::Field&) const;