@@ -43,6 +43,7 @@ struct ValidateOptions {
4343class SharedValidator {
4444 public:
4545 WABT_DISALLOW_COPY_AND_ASSIGN (SharedValidator);
46+ using FuncType = TypeChecker::FuncType;
4647 SharedValidator (Errors*, const ValidateOptions& options);
4748
4849 // TODO: Move into SharedValidator?
@@ -72,7 +73,6 @@ class SharedValidator {
7273 Index type_index);
7374 Result OnStructType (const Location&, Index field_count, TypeMut* fields);
7475 Result OnArrayType (const Location&, TypeMut field);
75- Result EndTypeSection ();
7676
7777 Result OnFunction (const Location&, Var sig_var);
7878 Result OnTable (const Location&, Type elem_type, const Limits&);
@@ -141,7 +141,7 @@ class SharedValidator {
141141 Result EndBrTable (const Location&);
142142 Result OnCall (const Location&, Var func_var);
143143 Result OnCallIndirect (const Location&, Var sig_var, Var table_var);
144- Result OnCallRef (const Location&, Index* function_type_index );
144+ Result OnCallRef (const Location&, Var function_type_var );
145145 Result OnCatch (const Location&, Var tag_var, bool is_catch_all);
146146 Result OnCompare (const Location&, Opcode);
147147 Result OnConst (const Location&, Type);
@@ -178,7 +178,7 @@ class SharedValidator {
178178 Result OnNop (const Location&);
179179 Result OnRefFunc (const Location&, Var func_var);
180180 Result OnRefIsNull (const Location&);
181- Result OnRefNull (const Location&, Type type );
181+ Result OnRefNull (const Location&, Var func_type_var );
182182 Result OnRethrow (const Location&, Var depth);
183183 Result OnReturnCall (const Location&, Var func_var);
184184 Result OnReturnCallIndirect (const Location&, Var sig_var, Var table_var);
@@ -221,18 +221,6 @@ class SharedValidator {
221221 Result OnUnreachable (const Location&);
222222
223223 private:
224- struct FuncType {
225- FuncType () = default ;
226- FuncType (const TypeVector& params,
227- const TypeVector& results,
228- Index type_index)
229- : params(params), results(results), type_index(type_index) {}
230-
231- TypeVector params;
232- TypeVector results;
233- Index type_index;
234- };
235-
236224 struct StructType {
237225 StructType () = default ;
238226 StructType (const TypeMutVector& fields) : fields(fields) {}
@@ -289,6 +277,11 @@ class SharedValidator {
289277 Index end;
290278 };
291279
280+ struct LocalReferenceMap {
281+ Type type;
282+ Index bit_index;
283+ };
284+
292285 bool ValidInitOpcode (Opcode opcode) const ;
293286 Result CheckInstr (Opcode opcode, const Location& loc);
294287 Result CheckType (const Location&,
@@ -336,6 +329,10 @@ class SharedValidator {
336329
337330 TypeVector ToTypeVector (Index count, const Type* types);
338331
332+ void SaveLocalRefs ();
333+ void RestoreLocalRefs (Result result);
334+ void IgnoreLocalRefs ();
335+
339336 ValidateOptions options_;
340337 Errors* errors_;
341338 TypeChecker typechecker_; // TODO: Move into SharedValidator.
@@ -361,6 +358,8 @@ class SharedValidator {
361358 // Includes parameters, since this is only used for validating
362359 // local.{get,set,tee} instructions.
363360 std::vector<LocalDecl> locals_;
361+ std::map<Index, LocalReferenceMap> local_refs_map_;
362+ std::vector<bool > local_ref_is_set_;
364363
365364 std::set<std::string> export_names_; // Used to check for duplicates.
366365 std::set<Index> declared_funcs_; // TODO: optimize?
0 commit comments