@@ -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,13 @@ class SharedValidator {
289277 Index end;
290278 };
291279
280+ struct LocalReferenceMap {
281+ Type type;
282+ // An index for a single bit value, which represents that
283+ // the corresponding local reference has been set before.
284+ size_t local_ref_is_set;
285+ };
286+
292287 bool ValidInitOpcode (Opcode opcode) const ;
293288 Result CheckInstr (Opcode opcode, const Location& loc);
294289 Result CheckType (const Location&,
@@ -336,6 +331,10 @@ class SharedValidator {
336331
337332 TypeVector ToTypeVector (Index count, const Type* types);
338333
334+ void SaveLocalRefs ();
335+ void RestoreLocalRefs (Result result);
336+ void IgnoreLocalRefs ();
337+
339338 ValidateOptions options_;
340339 Errors* errors_;
341340 TypeChecker typechecker_; // TODO: Move into SharedValidator.
@@ -361,6 +360,8 @@ class SharedValidator {
361360 // Includes parameters, since this is only used for validating
362361 // local.{get,set,tee} instructions.
363362 std::vector<LocalDecl> locals_;
363+ std::map<Index, LocalReferenceMap> local_refs_map_;
364+ std::vector<bool > local_ref_is_set_;
364365
365366 std::set<std::string> export_names_; // Used to check for duplicates.
366367 std::set<Index> declared_funcs_; // TODO: optimize?
0 commit comments