-
Notifications
You must be signed in to change notification settings - Fork 780
Add support for (ref ...) / (ref null ...) constructs #2562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,24 +36,43 @@ namespace wabt { | |
|
|
||
| struct Module; | ||
|
|
||
| enum class VarType { | ||
| // VarType (16 bit) and the opt_type_ (16 bit) | ||
| // fields of Var forms a 32 bit field. | ||
| enum class VarType : uint16_t { | ||
zherczeg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Index, | ||
| Name, | ||
| }; | ||
|
|
||
| struct Var { | ||
| // Var can represent variables or types. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a major internal change. It does not increase the size of Var. I think it is better than constructing a Var/Type pair. |
||
|
|
||
| // Represent a variable: | ||
| // has_opt_type() is false | ||
| // Only used by wast-parser | ||
|
|
||
| // Represent a type: | ||
| // has_opt_type() is true, is_index() is true | ||
| // type can be get by to_type() | ||
| // Binary reader only constructs this variant | ||
|
|
||
| // Represent both a variable and a type: | ||
| // has_opt_type() is true, is_name() is true | ||
| // A reference, which index is unknown | ||
| // Only used by wast-parser | ||
|
|
||
| explicit Var(); | ||
| explicit Var(Index index, const Location& loc); | ||
| explicit Var(std::string_view name, const Location& loc); | ||
| explicit Var(Type type, const Location& loc); | ||
| Var(Var&&); | ||
| Var(const Var&); | ||
| Var& operator=(const Var&); | ||
| Var& operator=(Var&&); | ||
| ~Var(); | ||
|
|
||
| VarType type() const { return type_; } | ||
| bool is_index() const { return type_ == VarType::Index; } | ||
| bool is_name() const { return type_ == VarType::Name; } | ||
| bool has_opt_type() const { return opt_type_ < 0; } | ||
|
|
||
| Index index() const { | ||
| assert(is_index()); | ||
|
|
@@ -63,17 +82,25 @@ struct Var { | |
| assert(is_name()); | ||
| return name_; | ||
| } | ||
| Type::Enum opt_type() const { | ||
| assert(has_opt_type()); | ||
| return static_cast<Type::Enum>(opt_type_); | ||
| } | ||
|
|
||
| void set_index(Index); | ||
| void set_name(std::string&&); | ||
| void set_name(std::string_view); | ||
| void set_opt_type(Type::Enum); | ||
zherczeg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Type to_type() const; | ||
|
|
||
| Location loc; | ||
|
|
||
| private: | ||
| void Destroy(); | ||
|
|
||
| VarType type_; | ||
| // Can be set to Type::Enum types, Type::Any represent no optional type. | ||
| int16_t opt_type_; | ||
zherczeg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| union { | ||
| Index index_; | ||
| std::string name_; | ||
|
|
@@ -155,6 +182,7 @@ struct Const { | |
| } | ||
| void set_funcref() { From<uintptr_t>(Type::FuncRef, 0); } | ||
| void set_externref(uintptr_t x) { From(Type::ExternRef, x); } | ||
| void set_extern(uintptr_t x) { From(Type(Type::ExternRef, Type::ReferenceNonNull), x); } | ||
| void set_null(Type type) { From<uintptr_t>(type, kRefNullBits); } | ||
|
|
||
| bool is_expected_nan(int lane = 0) const { | ||
|
|
@@ -537,10 +565,10 @@ using MemoryCopyExpr = MemoryBinaryExpr<ExprType::MemoryCopy>; | |
| template <ExprType TypeEnum> | ||
| class RefTypeExpr : public ExprMixin<TypeEnum> { | ||
| public: | ||
| RefTypeExpr(Type type, const Location& loc = Location()) | ||
| RefTypeExpr(Var type, const Location& loc = Location()) | ||
| : ExprMixin<TypeEnum>(loc), type(type) {} | ||
|
|
||
| Type type; | ||
| Var type; | ||
| }; | ||
|
|
||
| using RefNullExpr = RefTypeExpr<ExprType::RefNull>; | ||
|
|
@@ -662,8 +690,8 @@ using MemoryInitExpr = MemoryVarExpr<ExprType::MemoryInit>; | |
|
|
||
| class SelectExpr : public ExprMixin<ExprType::Select> { | ||
| public: | ||
| SelectExpr(TypeVector type, const Location& loc = Location()) | ||
| : ExprMixin<ExprType::Select>(loc), result_type(type) {} | ||
| SelectExpr(const Location& loc = Location()) | ||
| : ExprMixin<ExprType::Select>(loc) {} | ||
| TypeVector result_type; | ||
| }; | ||
|
|
||
|
|
@@ -727,9 +755,7 @@ class CallRefExpr : public ExprMixin<ExprType::CallRef> { | |
| explicit CallRefExpr(const Location& loc = Location()) | ||
| : ExprMixin<ExprType::CallRef>(loc) {} | ||
|
|
||
| // This field is setup only during Validate phase, | ||
| // so keep that in mind when you use it. | ||
zherczeg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Var function_type_index; | ||
| Var sig_type; | ||
| }; | ||
|
|
||
| template <ExprType TypeEnum> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.