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?
@@ -65,14 +67,21 @@ class SharedValidator {
65
67
66
68
Result EndModule ();
67
69
70
+ Result OnRecursiveType (Index first_type_index, Index type_count);
68
71
Result OnFuncType (const Location&,
69
72
Index param_count,
70
73
const Type* param_types,
71
74
Index result_count,
72
75
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);
76
+ Index type_index,
77
+ GCTypeExtension* gc_ext);
78
+ Result OnStructType (const Location&,
79
+ Index field_count,
80
+ TypeMut* fields,
81
+ GCTypeExtension* gc_ext);
82
+ Result OnArrayType (const Location&,
83
+ TypeMut field,
84
+ GCTypeExtension* gc_ext);
76
85
77
86
Result OnFunction (const Location&, Var sig_var);
78
87
Result OnTable (const Location&, Type elem_type, const Limits&, bool , bool );
@@ -225,20 +234,6 @@ class SharedValidator {
225
234
Result OnUnreachable (const Location&);
226
235
227
236
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
237
struct TableType {
243
238
TableType () = default ;
244
239
TableType (Type element, Limits limits) : element(element), limits(limits) {}
@@ -292,7 +287,11 @@ class SharedValidator {
292
287
Type actual,
293
288
Type expected,
294
289
const char * desc);
295
- Result CheckReferenceType (const Location&, Type type, const char * desc);
290
+ Result CheckReferenceType (const Location&,
291
+ Type type,
292
+ Index end_index,
293
+ const char * desc);
294
+ Result CheckGCTypeExtension (const Location&, GCTypeExtension* gc_ext);
296
295
Result CheckLimits (const Location&,
297
296
const Limits&,
298
297
uint64_t absolute_max,
@@ -337,17 +336,16 @@ class SharedValidator {
337
336
void RestoreLocalRefs (Result result);
338
337
void IgnoreLocalRefs ();
339
338
339
+ Index GetEndIndex ();
340
+
340
341
ValidateOptions options_;
341
342
Errors* errors_;
342
343
TypeChecker typechecker_; // TODO: Move into SharedValidator.
343
344
// Cached for access by OnTypecheckerError.
344
345
Location expr_loc_ = Location(kInvalidOffset );
345
346
bool in_init_expr_ = false ;
346
347
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_;
348
+ TypeChecker::TypeFields type_fields_;
351
349
352
350
std::vector<FuncType> funcs_; // Includes imported and defined.
353
351
std::vector<TableType> tables_; // Includes imported and defined.
@@ -358,6 +356,9 @@ class SharedValidator {
358
356
Index starts_ = 0 ;
359
357
Index num_imported_globals_ = 0 ;
360
358
Index data_segments_ = 0 ;
359
+ Index last_rec_type_end_ = 0 ;
360
+ // Recursive type checks may enter to infinite loop for invalid values.
361
+ Result type_validation_result_ = Result::Ok;
361
362
362
363
// Includes parameters, since this is only used for validating
363
364
// local.{get,set,tee} instructions.
0 commit comments