summaryrefslogtreecommitdiff
path: root/chromium/v8/src/wasm/wasm-module-builder.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/v8/src/wasm/wasm-module-builder.h')
-rw-r--r--chromium/v8/src/wasm/wasm-module-builder.h122
1 files changed, 103 insertions, 19 deletions
diff --git a/chromium/v8/src/wasm/wasm-module-builder.h b/chromium/v8/src/wasm/wasm-module-builder.h
index db2091cdba8..7ba140775d8 100644
--- a/chromium/v8/src/wasm/wasm-module-builder.h
+++ b/chromium/v8/src/wasm/wasm-module-builder.h
@@ -207,6 +207,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
WasmModuleBuilder* builder() const { return builder_; }
uint32_t func_index() { return func_index_; }
+ uint32_t sig_index() { return signature_index_; }
inline FunctionSig* signature();
private:
@@ -245,6 +246,68 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
WasmModuleBuilder(const WasmModuleBuilder&) = delete;
WasmModuleBuilder& operator=(const WasmModuleBuilder&) = delete;
+ // Static representation of wasm element segment (table initializer). This is
+ // different than the version in wasm-module.h.
+ class WasmElemSegment {
+ public:
+ // asm.js gives function indices starting with the first non-imported
+ // function.
+ enum FunctionIndexingMode {
+ kRelativeToImports,
+ kRelativeToDeclaredFunctions
+ };
+ enum Status {
+ kStatusActive, // copied automatically during instantiation.
+ kStatusPassive, // copied explicitly after instantiation.
+ kStatusDeclarative // purely declarative and never copied.
+ };
+ struct Entry {
+ enum Kind { kGlobalGetEntry, kRefFuncEntry, kRefNullEntry } kind;
+ uint32_t index;
+ Entry(Kind kind, uint32_t index) : kind(kind), index(index) {}
+ Entry() : kind(kRefNullEntry), index(0) {}
+ };
+
+ // Construct an active segment.
+ WasmElemSegment(Zone* zone, ValueType type, uint32_t table_index,
+ WasmInitExpr offset)
+ : type(type),
+ table_index(table_index),
+ offset(std::move(offset)),
+ entries(zone),
+ status(kStatusActive) {
+ DCHECK(IsValidOffsetKind(offset.kind()));
+ }
+
+ // Construct a passive or declarative segment, which has no table
+ // index or offset.
+ WasmElemSegment(Zone* zone, ValueType type, bool declarative)
+ : type(type),
+ table_index(0),
+ entries(zone),
+ status(declarative ? kStatusDeclarative : kStatusPassive) {
+ DCHECK(IsValidOffsetKind(offset.kind()));
+ }
+
+ MOVE_ONLY_NO_DEFAULT_CONSTRUCTOR(WasmElemSegment);
+
+ ValueType type;
+ uint32_t table_index;
+ WasmInitExpr offset;
+ FunctionIndexingMode indexing_mode = kRelativeToImports;
+ ZoneVector<Entry> entries;
+ Status status;
+
+ private:
+ // This ensures no {WasmInitExpr} with subexpressions is used, which would
+ // cause a memory leak because those are stored in an std::vector. Such
+ // offset would also be mistyped.
+ bool IsValidOffsetKind(WasmInitExpr::Operator kind) {
+ return kind == WasmInitExpr::kI32Const ||
+ kind == WasmInitExpr::kGlobalGet;
+ }
+ };
+
// Building methods.
uint32_t AddImport(base::Vector<const char> name, FunctionSig* sig,
base::Vector<const char> module = {});
@@ -255,16 +318,27 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
bool mutability,
base::Vector<const char> module = {});
void AddDataSegment(const byte* data, uint32_t size, uint32_t dest);
- uint32_t AddSignature(FunctionSig* sig);
+ // Add an element segment to this {WasmModuleBuilder}. {segment}'s enties
+ // have to be initialized.
+ void AddElementSegment(WasmElemSegment segment);
+ // Helper method to create an active segment with one function. Assumes that
+ // table segment at {table_index} is typed as funcref.
+ void SetIndirectFunction(uint32_t table_index, uint32_t index_in_table,
+ uint32_t direct_function_index,
+ WasmElemSegment::FunctionIndexingMode indexing_mode);
+ // Increase the starting size of the table at {table_index} by {count}. Also
+ // increases the maximum table size if needed. Returns the former starting
+ // size, or the maximum uint32_t value if the maximum table size has been
+ // exceeded.
+ uint32_t IncreaseTableMinSize(uint32_t table_index, uint32_t count);
+ // Adds the signature to the module if it does not already exist.
+ uint32_t AddSignature(FunctionSig* sig, uint32_t supertype = kNoSuperType);
+ // Does not deduplicate function signatures.
+ uint32_t ForceAddSignature(FunctionSig* sig,
+ uint32_t supertype = kNoSuperType);
uint32_t AddException(FunctionSig* type);
- uint32_t AddStructType(StructType* type);
- uint32_t AddArrayType(ArrayType* type);
- // In the current implementation, it's supported to have uninitialized slots
- // at the beginning and/or end of the indirect function table, as long as
- // the filled slots form a contiguous block in the middle.
- uint32_t AllocateIndirectFunctions(uint32_t count);
- void SetIndirectFunction(uint32_t indirect, uint32_t direct);
- void SetMaxTableSize(uint32_t max);
+ uint32_t AddStructType(StructType* type, uint32_t supertype = kNoSuperType);
+ uint32_t AddArrayType(ArrayType* type, uint32_t supertype = kNoSuperType);
uint32_t AddTable(ValueType type, uint32_t min_size);
uint32_t AddTable(ValueType type, uint32_t min_size, uint32_t max_size);
uint32_t AddTable(ValueType type, uint32_t min_size, uint32_t max_size,
@@ -288,10 +362,17 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
Zone* zone() { return zone_; }
+ ValueType GetTableType(uint32_t index) { return tables_[index].type; }
+
+ bool IsSignature(uint32_t index) {
+ return types_[index].kind == Type::kFunctionSig;
+ }
+
FunctionSig* GetSignature(uint32_t index) {
DCHECK(types_[index].kind == Type::kFunctionSig);
return types_[index].sig;
}
+
bool IsStructType(uint32_t index) {
return types_[index].kind == Type::kStructType;
}
@@ -304,10 +385,15 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
}
ArrayType* GetArrayType(uint32_t index) { return types_[index].array_type; }
+ WasmFunctionBuilder* GetFunction(uint32_t index) { return functions_[index]; }
int NumExceptions() { return static_cast<int>(exceptions_.size()); }
int NumTypes() { return static_cast<int>(types_.size()); }
+ int NumTables() { return static_cast<int>(tables_.size()); }
+
+ int NumFunctions() { return static_cast<int>(functions_.size()); }
+
FunctionSig* GetExceptionType(int index) {
return types_[exceptions_[index]].sig;
}
@@ -317,13 +403,14 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
private:
struct Type {
enum Kind { kFunctionSig, kStructType, kArrayType };
- explicit Type(FunctionSig* signature)
- : kind(kFunctionSig), sig(signature) {}
- explicit Type(StructType* struct_type)
- : kind(kStructType), struct_type(struct_type) {}
- explicit Type(ArrayType* array_type)
- : kind(kArrayType), array_type(array_type) {}
+ explicit Type(FunctionSig* signature, uint32_t supertype)
+ : kind(kFunctionSig), supertype(supertype), sig(signature) {}
+ explicit Type(StructType* struct_type, uint32_t supertype)
+ : kind(kStructType), supertype(supertype), struct_type(struct_type) {}
+ explicit Type(ArrayType* array_type, uint32_t supertype)
+ : kind(kArrayType), supertype(supertype), array_type(array_type) {}
Kind kind;
+ uint32_t supertype;
union {
FunctionSig* sig;
StructType* struct_type;
@@ -380,12 +467,11 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
ZoneVector<WasmFunctionBuilder*> functions_;
ZoneVector<WasmTable> tables_;
ZoneVector<WasmDataSegment> data_segments_;
- ZoneVector<uint32_t> indirect_functions_;
+ ZoneVector<WasmElemSegment> element_segments_;
ZoneVector<WasmGlobal> globals_;
ZoneVector<int> exceptions_;
ZoneUnorderedMap<FunctionSig, uint32_t> signature_map_;
int start_function_index_;
- uint32_t max_table_size_ = 0;
uint32_t min_memory_size_;
uint32_t max_memory_size_;
bool has_max_memory_size_;
@@ -393,8 +479,6 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
#if DEBUG
// Once AddExportedImport is called, no more imports can be added.
bool adding_imports_allowed_ = true;
- // Indirect functions must be allocated before adding extra tables.
- bool allocating_indirect_functions_allowed_ = true;
#endif
};