summaryrefslogtreecommitdiff
path: root/src/shared-validator.h
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2020-03-16 17:24:37 -0700
committerGitHub <noreply@github.com>2020-03-16 17:24:37 -0700
commit5467faf5cd52ba2da3e331e6c950a3860c559010 (patch)
tree9531fd3cdce64776c1713fff52782073f4d7934b /src/shared-validator.h
parent261dfdd75d8199298c9e0143e351322cc79c996a (diff)
downloadwabt-5467faf5cd52ba2da3e331e6c950a3860c559010.tar.gz
wabt-5467faf5cd52ba2da3e331e6c950a3860c559010.tar.bz2
wabt-5467faf5cd52ba2da3e331e6c950a3860c559010.zip
Parse struct fields (#1355)
This allows the following field formats: * `(struct (field $name i32))` * `(struct (field $name (mut i32)))` * `(struct (field i32))` * `(struct (field (mut i32)))` * `(struct (mut i32))` * `(struct i32)`
Diffstat (limited to 'src/shared-validator.h')
-rw-r--r--src/shared-validator.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/shared-validator.h b/src/shared-validator.h
index 4ecaeabc..abd4196e 100644
--- a/src/shared-validator.h
+++ b/src/shared-validator.h
@@ -17,6 +17,7 @@
#ifndef WABT_SHARED_VALIDATOR_H_
#define WABT_SHARED_VALIDATOR_H_
+#include <map>
#include <set>
#include <string>
#include <vector>
@@ -28,6 +29,8 @@
#include "src/opcode.h"
#include "src/type-checker.h"
+#include "src/binary-reader.h" // For TypeMut.
+
namespace wabt {
struct ValidateOptions {
@@ -63,6 +66,7 @@ class SharedValidator {
const Type* param_types,
Index result_count,
const Type* result_types);
+ Result OnStructType(const Location&, Index field_count, TypeMut* fields);
Result OnFunction(const Location&, Var sig_var);
Result OnTable(const Location&, Type elem_type, const Limits&);
@@ -169,10 +173,21 @@ class SharedValidator {
private:
struct FuncType {
+ FuncType() = default;
+ FuncType(const TypeVector& params, const TypeVector& results)
+ : params(params), results(results) {}
+
TypeVector params;
TypeVector results;
};
+ struct StructType {
+ StructType() = default;
+ StructType(const TypeMutVector& fields) : fields(fields) {}
+
+ TypeMutVector fields;
+ };
+
struct TableType {
TableType() = default;
TableType(Type element, Limits limits) : element(element), limits(limits) {}
@@ -231,7 +246,7 @@ class SharedValidator {
const std::vector<T>& values,
T* out,
const char* desc);
- Result CheckTypeIndex(Var sig_var, FuncType* out = nullptr);
+ Result CheckFuncTypeIndex(Var sig_var, FuncType* out = nullptr);
Result CheckFuncIndex(Var func_var, FuncType* out = nullptr);
Result CheckTableIndex(Var table_var, TableType* out = nullptr);
Result CheckMemoryIndex(Var memory_var, MemoryType* out = nullptr);
@@ -257,7 +272,10 @@ class SharedValidator {
// Cached for access by OnTypecheckerError.
const Location* expr_loc_ = nullptr;
- std::vector<FuncType> types_;
+ Index num_types_ = 0;
+ std::map<Index, FuncType> func_types_;
+ std::map<Index, StructType> struct_types_;
+
std::vector<FuncType> funcs_; // Includes imported and defined.
std::vector<TableType> tables_; // Includes imported and defined.
std::vector<MemoryType> memories_; // Includes imported and defined.