@@ -43,6 +43,7 @@ struct ValidateOptions {
43
43
class SharedValidator {
44
44
public:
45
45
WABT_DISALLOW_COPY_AND_ASSIGN (SharedValidator);
46
+ using FuncType = TypeChecker::FuncType;
46
47
SharedValidator (Errors*, const ValidateOptions& options);
47
48
48
49
// TODO: Move into SharedValidator?
@@ -141,7 +142,7 @@ class SharedValidator {
141
142
Result EndBrTable (const Location&);
142
143
Result OnCall (const Location&, Var func_var);
143
144
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 );
145
146
Result OnCatch (const Location&, Var tag_var, bool is_catch_all);
146
147
Result OnCompare (const Location&, Opcode);
147
148
Result OnConst (const Location&, Type);
@@ -178,7 +179,7 @@ class SharedValidator {
178
179
Result OnNop (const Location&);
179
180
Result OnRefFunc (const Location&, Var func_var);
180
181
Result OnRefIsNull (const Location&);
181
- Result OnRefNull (const Location&, Type type );
182
+ Result OnRefNull (const Location&, Var func_type_var );
182
183
Result OnRethrow (const Location&, Var depth);
183
184
Result OnReturnCall (const Location&, Var func_var);
184
185
Result OnReturnCallIndirect (const Location&, Var sig_var, Var table_var);
@@ -221,18 +222,6 @@ class SharedValidator {
221
222
Result OnUnreachable (const Location&);
222
223
223
224
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
-
236
225
struct StructType {
237
226
StructType () = default ;
238
227
StructType (const TypeMutVector& fields) : fields(fields) {}
@@ -289,6 +278,25 @@ class SharedValidator {
289
278
Index end;
290
279
};
291
280
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
+
292
300
bool ValidInitOpcode (Opcode opcode) const ;
293
301
Result CheckInstr (Opcode opcode, const Location& loc);
294
302
Result CheckType (const Location&,
@@ -336,6 +344,10 @@ class SharedValidator {
336
344
337
345
TypeVector ToTypeVector (Index count, const Type* types);
338
346
347
+ void SaveLocalRefs ();
348
+ void RestoreLocalRefs (Result result);
349
+ void IgnoreLocalRefs ();
350
+
339
351
ValidateOptions options_;
340
352
Errors* errors_;
341
353
TypeChecker typechecker_; // TODO: Move into SharedValidator.
@@ -361,6 +373,8 @@ class SharedValidator {
361
373
// Includes parameters, since this is only used for validating
362
374
// local.{get,set,tee} instructions.
363
375
std::vector<LocalDecl> locals_;
376
+ std::map<Index, LocalReferenceMap> local_refs_map_;
377
+ std::vector<bool > local_ref_is_set_;
364
378
365
379
std::set<std::string> export_names_; // Used to check for duplicates.
366
380
std::set<Index> declared_funcs_; // TODO: optimize?
0 commit comments