@@ -36,7 +36,7 @@ namespace wabt {
36
36
37
37
struct Module ;
38
38
39
- enum class VarType {
39
+ enum class VarType : uint16_t {
40
40
Index,
41
41
Name,
42
42
};
@@ -45,6 +45,7 @@ struct Var {
45
45
explicit Var ();
46
46
explicit Var (Index index, const Location& loc);
47
47
explicit Var (std::string_view name, const Location& loc);
48
+ explicit Var (Type type, const Location& loc);
48
49
Var (Var&&);
49
50
Var (const Var&);
50
51
Var& operator =(const Var&);
@@ -54,6 +55,7 @@ struct Var {
54
55
VarType type () const { return type_; }
55
56
bool is_index () const { return type_ == VarType::Index; }
56
57
bool is_name () const { return type_ == VarType::Name; }
58
+ bool has_opt_type () const { return opt_type_ < 0 ; }
57
59
58
60
Index index () const {
59
61
assert (is_index ());
@@ -63,17 +65,25 @@ struct Var {
63
65
assert (is_name ());
64
66
return name_;
65
67
}
68
+ Type::Enum opt_type () const {
69
+ assert (has_opt_type ());
70
+ return static_cast <Type::Enum>(opt_type_);
71
+ }
66
72
67
73
void set_index (Index);
68
74
void set_name (std::string&&);
69
75
void set_name (std::string_view);
76
+ void set_opt_type (Type::Enum);
77
+ Type to_type () const ;
70
78
71
79
Location loc;
72
80
73
81
private:
74
82
void Destroy ();
75
83
76
84
VarType type_;
85
+ // Can be set to Type::Enum types, 0 represent no optional type.
86
+ int16_t opt_type_;
77
87
union {
78
88
Index index_;
79
89
std::string name_;
@@ -544,10 +554,10 @@ using MemoryCopyExpr = MemoryBinaryExpr<ExprType::MemoryCopy>;
544
554
template <ExprType TypeEnum>
545
555
class RefTypeExpr : public ExprMixin <TypeEnum> {
546
556
public:
547
- RefTypeExpr (Type type, const Location& loc = Location())
557
+ RefTypeExpr (Var type, const Location& loc = Location())
548
558
: ExprMixin<TypeEnum>(loc), type(type) {}
549
559
550
- Type type;
560
+ Var type;
551
561
};
552
562
553
563
using RefNullExpr = RefTypeExpr<ExprType::RefNull>;
@@ -734,9 +744,7 @@ class CallRefExpr : public ExprMixin<ExprType::CallRef> {
734
744
explicit CallRefExpr (const Location& loc = Location())
735
745
: ExprMixin<ExprType::CallRef>(loc) {}
736
746
737
- // This field is setup only during Validate phase,
738
- // so keep that in mind when you use it.
739
- Var function_type_index;
747
+ Var function_type;
740
748
};
741
749
742
750
template <ExprType TypeEnum>
@@ -924,6 +932,8 @@ struct Func {
924
932
925
933
std::string name;
926
934
FuncDeclaration decl;
935
+ // Contains references with unknown indicies.
936
+ TypeVector local_type_list;
927
937
LocalTypes local_types;
928
938
BindingHash bindings;
929
939
ExprList exprs;
@@ -941,7 +951,7 @@ struct Global {
941
951
explicit Global (std::string_view name) : name(name) {}
942
952
943
953
std::string name;
944
- Type type = Type::Void ;
954
+ Var type;
945
955
bool mutable_ = false ;
946
956
ExprList init_expr;
947
957
};
0 commit comments