5 #ifndef V8_WASM_WASM_MODULE_H_ 6 #define V8_WASM_WASM_MODULE_H_ 10 #include "src/globals.h" 11 #include "src/handles.h" 12 #include "src/vector.h" 13 #include "src/wasm/signature-map.h" 14 #include "src/wasm/wasm-constants.h" 15 #include "src/wasm/wasm-opcodes.h" 21 class WasmModuleObject;
25 using WasmName = Vector<const char>;
34 : offset_(offset), length_(length) {
35 DCHECK_IMPLIES(offset_ == 0, length_ == 0);
36 DCHECK_LE(offset_, offset_ + length_);
39 uint32_t offset()
const {
return offset_; }
40 uint32_t length()
const {
return length_; }
41 uint32_t end_offset()
const {
return offset_ + length_; }
42 bool is_empty()
const {
return length_ == 0; }
43 bool is_set()
const {
return offset_ != 0; }
89 : dest_addr(dest_addr), active(
true) {}
101 MOVE_ONLY_WITH_DEFAULT_CONSTRUCTORS(
WasmTable);
102 ValueType
type = kWasmStmt;
105 bool has_maximum_size =
false;
107 std::vector<int32_t> values;
108 bool imported =
false;
109 bool exported =
false;
118 : table_index(table_index), offset(offset), active(
true) {}
125 std::vector<uint32_t> entries;
133 ImportExportKindCode kind;
140 ImportExportKindCode kind;
144 enum ModuleOrigin : uint8_t { kWasmOrigin, kAsmJsOrigin };
146 #define SELECT_WASM_COUNTER(counters, origin, prefix, suffix) \ 147 ((origin) == kWasmOrigin ? (counters)->prefix##_wasm_##suffix() \ 148 : (counters)->prefix##_asm_##suffix()) 150 struct ModuleWireBytes;
156 std::unique_ptr<Zone> signature_zone;
159 bool has_shared_memory =
false;
160 bool has_maximum_pages =
false;
161 bool has_memory =
false;
162 bool mem_export =
false;
163 int start_function_index = -1;
165 std::vector<WasmGlobal> globals;
169 uint32_t num_imported_mutable_globals = 0;
170 uint32_t num_imported_functions = 0;
171 uint32_t num_declared_functions = 0;
172 uint32_t num_exported_functions = 0;
174 std::vector<FunctionSig*> signatures;
175 std::vector<uint32_t> signature_ids;
176 std::vector<WasmFunction> functions;
177 std::vector<WasmDataSegment> data_segments;
178 std::vector<WasmTable> tables;
179 std::vector<WasmImport> import_table;
180 std::vector<WasmExport> export_table;
181 std::vector<WasmException> exceptions;
182 std::vector<WasmTableInit> table_inits;
185 ModuleOrigin origin = kWasmOrigin;
186 mutable std::unique_ptr<std::unordered_map<uint32_t, WireBytesRef>>
188 std::string source_map_url;
190 explicit WasmModule(std::unique_ptr<Zone> signature_zone =
nullptr);
194 void AddFunctionNameForTesting(
int function_index,
WireBytesRef name);
197 size_t EstimateStoredSize(
const WasmModule* module);
205 : module_bytes_(module_bytes) {}
207 : module_bytes_(start, static_cast<int>(end - start)) {
208 DCHECK_GE(kMaxInt, end - start);
221 return offset <= size && length <= size - offset;
225 return module_bytes_.SubVector(function->code.offset(),
226 function->code.end_offset());
230 const byte* start()
const {
return module_bytes_.start(); }
231 const byte* end()
const {
return module_bytes_.end(); }
232 size_t length()
const {
return module_bytes_.length(); }
241 : function_(
function), name_(name) {}
258 V8_EXPORT_PRIVATE
bool IsWasmCodegenAllowed(
Isolate* isolate,
279 template <
int kMaxLen = 50>
281 static_assert(kMaxLen >= 4,
"minimum length is 4 (length of '...' plus one)");
284 template <
typename T>
292 : start_(start), length_(std::min(kMaxLen, static_cast<int>(len))) {
293 if (len > static_cast<size_t>(kMaxLen)) {
294 memcpy(buffer_, start, kMaxLen - 3);
295 memset(buffer_ + kMaxLen - 3,
'.', 3);
300 const char* start()
const {
return start_; }
302 int length()
const {
return length_; }
307 char buffer_[kMaxLen];
314 #endif // V8_WASM_WASM_MODULE_H_