@@ -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?
@@ -141,7 +142,7 @@ class SharedValidator {
141142 Result EndBrTable (const Location&);
142143 Result OnCall (const Location&, Var func_var);
143144 Result OnCallIndirect (const Location&, Var sig_var, Var table_var);
144- Result OnCallRef (const Location&, Index* function_type_index );
145+ Result OnCallRef (const Location&, Var function_type_var );
145146 Result OnCatch (const Location&, Var tag_var, bool is_catch_all);
146147 Result OnCompare (const Location&, Opcode);
147148 Result OnConst (const Location&, Type);
@@ -178,7 +179,7 @@ class SharedValidator {
178179 Result OnNop (const Location&);
179180 Result OnRefFunc (const Location&, Var func_var);
180181 Result OnRefIsNull (const Location&);
181- Result OnRefNull (const Location&, Type type );
182+ Result OnRefNull (const Location&, Var func_type_var );
182183 Result OnRethrow (const Location&, Var depth);
183184 Result OnReturnCall (const Location&, Var func_var);
184185 Result OnReturnCallIndirect (const Location&, Var sig_var, Var table_var);
@@ -221,18 +222,6 @@ class SharedValidator {
221222 Result OnUnreachable (const Location&);
222223
223224 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-
236225 struct StructType {
237226 StructType () = default ;
238227 StructType (const TypeMutVector& fields) : fields(fields) {}
@@ -289,6 +278,25 @@ class SharedValidator {
289278 Index end;
290279 };
291280
281+ struct LocalReferenceMap {
282+ Type type;
283+ Index bit_index;
284+ };
285+
286+ struct RecursionDetector {
287+ RecursionDetector (SharedValidator *validator)
288+ : validator(validator) {}
289+
290+ SharedValidator *validator;
291+ bool recursion_found = false ;
292+ Index iteration = 0 ;
293+ std::map<Index, Index> processed_func_types;
294+ std::vector<Index> visited_func_types;
295+
296+ Result CheckRecursion (Type type,
297+ const char * desc);
298+ };
299+
292300 bool ValidInitOpcode (Opcode opcode) const ;
293301 Result CheckInstr (Opcode opcode, const Location& loc);
294302 Result CheckType (const Location&,
@@ -336,6 +344,10 @@ class SharedValidator {
336344
337345 TypeVector ToTypeVector (Index count, const Type* types);
338346
347+ void SaveLocalRefs ();
348+ void RestoreLocalRefs (Result result);
349+ void IgnoreLocalRefs ();
350+
339351 ValidateOptions options_;
340352 Errors* errors_;
341353 TypeChecker typechecker_; // TODO: Move into SharedValidator.
@@ -361,6 +373,8 @@ class SharedValidator {
361373 // Includes parameters, since this is only used for validating
362374 // local.{get,set,tee} instructions.
363375 std::vector<LocalDecl> locals_;
376+ std::map<Index, LocalReferenceMap> local_refs_map_;
377+ std::vector<bool > local_ref_is_set_;
364378
365379 std::set<std::string> export_names_; // Used to check for duplicates.
366380 std::set<Index> declared_funcs_; // TODO: optimize?
0 commit comments