29
29
#include " wabt/opcode.h"
30
30
#include " wabt/type-checker.h"
31
31
32
- #include " wabt/binary-reader.h" // For TypeMut.
33
-
34
32
namespace wabt {
35
33
36
34
struct ValidateOptions {
@@ -43,7 +41,11 @@ struct ValidateOptions {
43
41
class SharedValidator {
44
42
public:
45
43
WABT_DISALLOW_COPY_AND_ASSIGN (SharedValidator);
44
+ using TypeEntry = TypeChecker::TypeEntry;
46
45
using FuncType = TypeChecker::FuncType;
46
+ using StructType = TypeChecker::StructType;
47
+ using ArrayType = TypeChecker::ArrayType;
48
+ using RecursiveRange = TypeChecker::RecursiveRange;
47
49
SharedValidator (Errors*, const ValidateOptions& options);
48
50
49
51
// TODO: Move into SharedValidator?
@@ -63,16 +65,28 @@ class SharedValidator {
63
65
64
66
Index GetLocalCount () const ;
65
67
68
+ // The canonical index of a type is the index of the first type,
69
+ // which is equal to the original type. The canonical index is
70
+ // always less or equal than type_index.
71
+ Index GetCanonicalTypeIndex (Index type_index);
72
+
66
73
Result EndModule ();
67
74
75
+ Result OnRecursiveType (Index first_type_index, Index type_count);
68
76
Result OnFuncType (const Location&,
69
77
Index param_count,
70
78
const Type* param_types,
71
79
Index result_count,
72
80
const Type* result_types,
73
- Index type_index);
74
- Result OnStructType (const Location&, Index field_count, TypeMut* fields);
75
- Result OnArrayType (const Location&, TypeMut field);
81
+ Index type_index,
82
+ GCTypeExtension* gc_ext);
83
+ Result OnStructType (const Location&,
84
+ Index field_count,
85
+ TypeMut* fields,
86
+ GCTypeExtension* gc_ext);
87
+ Result OnArrayType (const Location&,
88
+ TypeMut field,
89
+ GCTypeExtension* gc_ext);
76
90
77
91
Result OnFunction (const Location&, Var sig_var);
78
92
Result OnTable (const Location&, Type elem_type, const Limits&, bool , bool );
@@ -225,20 +239,6 @@ class SharedValidator {
225
239
Result OnUnreachable (const Location&);
226
240
227
241
private:
228
- struct StructType {
229
- StructType () = default ;
230
- StructType (const TypeMutVector& fields) : fields(fields) {}
231
-
232
- TypeMutVector fields;
233
- };
234
-
235
- struct ArrayType {
236
- ArrayType () = default ;
237
- ArrayType (TypeMut field) : field(field) {}
238
-
239
- TypeMut field;
240
- };
241
-
242
242
struct TableType {
243
243
TableType () = default ;
244
244
TableType (Type element, Limits limits) : element(element), limits(limits) {}
@@ -292,7 +292,11 @@ class SharedValidator {
292
292
Type actual,
293
293
Type expected,
294
294
const char * desc);
295
- Result CheckReferenceType (const Location&, Type type, const char * desc);
295
+ Result CheckReferenceType (const Location&,
296
+ Type type,
297
+ Index end_index,
298
+ const char * desc);
299
+ Result CheckGCTypeExtension (const Location&, GCTypeExtension* gc_ext);
296
300
Result CheckLimits (const Location&,
297
301
const Limits&,
298
302
uint64_t absolute_max,
@@ -337,17 +341,16 @@ class SharedValidator {
337
341
void RestoreLocalRefs (Result result);
338
342
void IgnoreLocalRefs ();
339
343
344
+ Index GetEndIndex ();
345
+
340
346
ValidateOptions options_;
341
347
Errors* errors_;
342
348
TypeChecker typechecker_; // TODO: Move into SharedValidator.
343
349
// Cached for access by OnTypecheckerError.
344
350
Location expr_loc_ = Location(kInvalidOffset );
345
351
bool in_init_expr_ = false ;
346
352
347
- Index num_types_ = 0 ;
348
- std::map<Index, FuncType> func_types_;
349
- std::map<Index, StructType> struct_types_;
350
- std::map<Index, ArrayType> array_types_;
353
+ TypeChecker::TypeFields type_fields_;
351
354
352
355
std::vector<FuncType> funcs_; // Includes imported and defined.
353
356
std::vector<TableType> tables_; // Includes imported and defined.
@@ -358,6 +361,9 @@ class SharedValidator {
358
361
Index starts_ = 0 ;
359
362
Index num_imported_globals_ = 0 ;
360
363
Index data_segments_ = 0 ;
364
+ Index last_rec_type_end_ = 0 ;
365
+ // Recursive type checks may enter to infinite loop for invalid values.
366
+ Result type_validation_result_ = Result::Ok;
361
367
362
368
// Includes parameters, since this is only used for validating
363
369
// local.{get,set,tee} instructions.
0 commit comments