OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_WASM_MODULE_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/api.h" | 10 #include "src/api.h" |
11 #include "src/handles.h" | 11 #include "src/handles.h" |
12 #include "src/parsing/preparse-data.h" | 12 #include "src/parsing/preparse-data.h" |
13 | 13 |
14 #include "src/wasm/wasm-opcodes.h" | 14 #include "src/wasm/wasm-opcodes.h" |
15 #include "src/wasm/wasm-result.h" | 15 #include "src/wasm/wasm-result.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 namespace compiler { | 20 namespace compiler { |
21 class CallDescriptor; | 21 class CallDescriptor; |
22 class WasmCompilationUnit; | 22 class WasmCompilationUnit; |
23 } | 23 } |
24 | 24 |
25 namespace wasm { | 25 namespace wasm { |
26 const size_t kMaxModuleSize = 1024 * 1024 * 1024; | 26 const size_t kMaxModuleSize = 1024 * 1024 * 1024; |
27 const size_t kMaxFunctionSize = 128 * 1024; | 27 const size_t kMaxFunctionSize = 128 * 1024; |
28 const size_t kMaxStringSize = 256; | 28 const size_t kMaxStringSize = 256; |
29 const uint32_t kWasmMagic = 0x6d736100; | 29 const uint32_t kWasmMagic = 0x6d736100; |
30 const uint32_t kWasmVersion = 0x0b; | 30 const uint32_t kWasmVersion = 0x0c; |
31 const uint8_t kWasmFunctionTypeForm = 0x40; | 31 const uint8_t kWasmFunctionTypeForm = 0x40; |
32 const uint8_t kWasmAnyFunctionTypeForm = 0x20; | |
32 | 33 |
33 // WebAssembly sections are named as strings in the binary format, but | 34 enum WasmSectionCode { |
34 // internally V8 uses an enum to handle them. | 35 kUnknownSectionCode = 0, // code for unknown sections |
35 // | 36 kTypeSectionCode = 1, // Function signature declarations |
bradnelson
2016/09/23 11:36:01
Yeah! bye strings...
titzer
2016/09/23 12:07:30
Acknowledged.
| |
36 // Entries have the form F(enumerator, string). | 37 kImportSectionCode = 2, // Import declarations |
37 #define FOR_EACH_WASM_SECTION_TYPE(F) \ | 38 kFunctionSectionCode = 3, // Function declarations |
38 F(Signatures, 1, "type") \ | 39 kTableSectionCode = 4, // Indirect function table and other tables |
39 F(ImportTable, 2, "import") \ | 40 kMemorySectionCode = 5, // Memory attributes |
40 F(FunctionSignatures, 3, "function") \ | 41 kGlobalSectionCode = 6, // Global declarations |
41 F(FunctionTable, 4, "table") \ | 42 kExportSectionCode = 7, // Exports |
42 F(Memory, 5, "memory") \ | 43 kStartSectionCode = 8, // Start function declaration |
43 F(ExportTable, 6, "export") \ | 44 kElementSectionCode = 9, // Elements section |
44 F(StartFunction, 7, "start") \ | 45 kCodeSectionCode = 10, // Function code |
45 F(FunctionBodies, 8, "code") \ | 46 kDataSectionCode = 11, // Data segments |
46 F(DataSegments, 9, "data") \ | 47 kNameSectionCode = 12, // Name section (encoded as a string) |
47 F(Names, 10, "name") \ | 48 }; |
48 F(Globals, 0, "global") \ | |
49 F(End, 0, "end") | |
50 | 49 |
51 // Contants for the above section types: {LEB128 length, characters...}. | 50 inline bool IsValidSectionCode(uint8_t byte) { |
52 #define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y' | 51 return kTypeSectionCode <= byte && byte <= kDataSectionCode; |
53 #define WASM_SECTION_SIGNATURES 4, 't', 'y', 'p', 'e' | 52 } |
54 #define WASM_SECTION_GLOBALS 6, 'g', 'l', 'o', 'b', 'a', 'l' | |
55 #define WASM_SECTION_DATA_SEGMENTS 4, 'd', 'a', 't', 'a' | |
56 #define WASM_SECTION_FUNCTION_TABLE 5, 't', 'a', 'b', 'l', 'e' | |
57 #define WASM_SECTION_END 3, 'e', 'n', 'd' | |
58 #define WASM_SECTION_START_FUNCTION 5, 's', 't', 'a', 'r', 't' | |
59 #define WASM_SECTION_IMPORT_TABLE 6, 'i', 'm', 'p', 'o', 'r', 't' | |
60 #define WASM_SECTION_EXPORT_TABLE 6, 'e', 'x', 'p', 'o', 'r', 't' | |
61 #define WASM_SECTION_FUNCTION_SIGNATURES \ | |
62 8, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n' | |
63 #define WASM_SECTION_FUNCTION_BODIES 4, 'c', 'o', 'd', 'e' | |
64 #define WASM_SECTION_NAMES 4, 'n', 'a', 'm', 'e' | |
65 | 53 |
66 // Constants for the above section headers' size (LEB128 + characters). | 54 const char* SectionName(WasmSectionCode code); |
67 #define WASM_SECTION_MEMORY_SIZE ((size_t)7) | 55 |
68 #define WASM_SECTION_SIGNATURES_SIZE ((size_t)5) | 56 static const char* kNameString = "name"; |
69 #define WASM_SECTION_GLOBALS_SIZE ((size_t)7) | 57 static const size_t kNameStringLength = 4; |
70 #define WASM_SECTION_DATA_SEGMENTS_SIZE ((size_t)5) | |
71 #define WASM_SECTION_FUNCTION_TABLE_SIZE ((size_t)6) | |
72 #define WASM_SECTION_END_SIZE ((size_t)4) | |
73 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)6) | |
74 #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)7) | |
75 #define WASM_SECTION_EXPORT_TABLE_SIZE ((size_t)7) | |
76 #define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)9) | |
77 #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)5) | |
78 #define WASM_SECTION_NAMES_SIZE ((size_t)5) | |
79 | 58 |
80 class WasmDebugInfo; | 59 class WasmDebugInfo; |
81 | 60 |
82 struct WasmSection { | 61 // Constants for fixed-size elements within a module. |
83 enum class Code : uint32_t { | 62 static const uint32_t kMaxReturnCount = 1; |
84 #define F(enumerator, order, string) enumerator, | 63 static const uint8_t kResizableMaximumFlag = 1; |
85 FOR_EACH_WASM_SECTION_TYPE(F) | 64 static const int32_t kInvalidFunctionIndex = -1; |
86 #undef F | 65 |
87 Max | 66 enum WasmExternalKind { |
88 }; | 67 kExternalFunction = 0, |
89 static WasmSection::Code begin(); | 68 kExternalTable = 1, |
90 static WasmSection::Code end(); | 69 kExternalMemory = 2, |
91 static WasmSection::Code next(WasmSection::Code code); | 70 kExternalGlobal = 3 |
92 static const char* getName(Code code); | |
93 static int getOrder(Code code); | |
94 static size_t getNameLength(Code code); | |
95 static WasmSection::Code lookup(const byte* string, uint32_t length); | |
96 }; | 71 }; |
97 | 72 |
98 enum WasmFunctionDeclBit { | 73 // Representation of an initializer expression. |
99 kDeclFunctionName = 0x01, | 74 struct WasmInitExpr { |
100 kDeclFunctionExport = 0x08 | 75 enum WasmInitKind { |
76 kNone, | |
77 kGlobalIndex, | |
78 kI32Const, | |
79 kI64Const, | |
80 kF32Const, | |
81 kF64Const | |
82 } kind; | |
83 | |
84 union { | |
85 int32_t i32_const; | |
86 int64_t i64_const; | |
87 float f32_const; | |
88 double f64_const; | |
89 uint32_t global_index; | |
90 } val; | |
101 }; | 91 }; |
102 | 92 |
103 // Constants for fixed-size elements within a module. | 93 #define NO_INIT \ |
104 static const size_t kDeclMemorySize = 3; | 94 { \ |
105 static const size_t kDeclDataSegmentSize = 13; | 95 WasmInitExpr::kNone, { 0u } \ |
106 | 96 } |
107 static const uint32_t kMaxReturnCount = 1; | |
108 | 97 |
109 // Static representation of a WASM function. | 98 // Static representation of a WASM function. |
110 struct WasmFunction { | 99 struct WasmFunction { |
111 FunctionSig* sig; // signature of the function. | 100 FunctionSig* sig; // signature of the function. |
112 uint32_t func_index; // index into the function table. | 101 uint32_t func_index; // index into the function table. |
113 uint32_t sig_index; // index into the signature table. | 102 uint32_t sig_index; // index into the signature table. |
114 uint32_t name_offset; // offset in the module bytes of the name, if any. | 103 uint32_t name_offset; // offset in the module bytes of the name, if any. |
115 uint32_t name_length; // length in bytes of the name. | 104 uint32_t name_length; // length in bytes of the name. |
116 uint32_t code_start_offset; // offset in the module bytes of code start. | 105 uint32_t code_start_offset; // offset in the module bytes of code start. |
117 uint32_t code_end_offset; // offset in the module bytes of code end. | 106 uint32_t code_end_offset; // offset in the module bytes of code end. |
118 }; | 107 bool imported; |
119 | 108 bool exported; |
120 // Static representation of an imported WASM function. | |
121 struct WasmImport { | |
122 FunctionSig* sig; // signature of the function. | |
123 uint32_t sig_index; // index into the signature table. | |
124 uint32_t module_name_offset; // offset in module bytes of the module name. | |
125 uint32_t module_name_length; // length in bytes of the module name. | |
126 uint32_t function_name_offset; // offset in module bytes of the import name. | |
127 uint32_t function_name_length; // length in bytes of the import name. | |
128 }; | |
129 | |
130 // Static representation of an exported WASM function. | |
131 struct WasmExport { | |
132 uint32_t func_index; // index into the function table. | |
133 uint32_t name_offset; // offset in module bytes of the name to export. | |
134 uint32_t name_length; // length in bytes of the exported name. | |
135 }; | 109 }; |
136 | 110 |
137 // Static representation of a wasm global variable. | 111 // Static representation of a wasm global variable. |
138 struct WasmGlobal { | 112 struct WasmGlobal { |
139 uint32_t name_offset; // offset in the module bytes of the name, if any. | |
140 uint32_t name_length; // length in bytes of the global name. | |
141 LocalType type; // type of the global. | 113 LocalType type; // type of the global. |
142 uint32_t offset; // offset from beginning of globals area. | 114 bool mutability; // {true} if mutable. |
143 bool exported; // true if this global is exported. | 115 WasmInitExpr init; // the initialization expression of the global. |
116 uint32_t offset; // offset into global memory. | |
117 bool imported; // true if imported. | |
118 bool exported; // true if exported. | |
144 }; | 119 }; |
145 | 120 |
146 // Static representation of a wasm data segment. | 121 // Static representation of a wasm data segment. |
147 struct WasmDataSegment { | 122 struct WasmDataSegment { |
148 uint32_t dest_addr; // destination memory address of the data. | 123 WasmInitExpr dest_addr; // destination memory address of the data. |
149 uint32_t source_offset; // start offset in the module bytes. | 124 uint32_t source_offset; // start offset in the module bytes. |
150 uint32_t source_size; // end offset in the module bytes. | 125 uint32_t source_size; // end offset in the module bytes. |
151 bool init; // true if loaded upon instantiation. | |
152 }; | 126 }; |
153 | 127 |
154 // Static representation of a wasm indirect call table. | 128 // Static representation of a wasm indirect call table. |
155 struct WasmIndirectFunctionTable { | 129 struct WasmIndirectFunctionTable { |
156 uint32_t size; // initial table size. | 130 uint32_t size; // initial table size. |
157 uint32_t max_size; // maximum table size. | 131 uint32_t max_size; // maximum table size. |
158 std::vector<uint16_t> values; // function table. | 132 std::vector<int32_t> values; // function table, -1 indicating invalid. |
133 bool imported; // true if imported. | |
134 bool exported; // true if exported. | |
135 }; | |
136 | |
137 // Static representation of how to initialize a table. | |
138 struct WasmTableInit { | |
139 uint32_t table_index; | |
140 WasmInitExpr offset; | |
141 std::vector<uint32_t> entries; | |
142 }; | |
143 | |
144 // Static representation of a WASM import. | |
145 struct WasmImport { | |
146 uint32_t module_name_length; // length in bytes of the module name. | |
147 uint32_t module_name_offset; // offset in module bytes of the module name. | |
148 uint32_t field_name_length; // length in bytes of the import name. | |
149 uint32_t field_name_offset; // offset in module bytes of the import name. | |
150 WasmExternalKind kind; // kind of the import. | |
151 uint32_t index; // index into the respective space. | |
152 }; | |
153 | |
154 // Static representation of a WASM export. | |
155 struct WasmExport { | |
156 uint32_t name_length; // length in bytes of the exported name. | |
157 uint32_t name_offset; // offset in module bytes of the name to export. | |
158 WasmExternalKind kind; // kind of the export. | |
159 uint32_t index; // index into the respective space. | |
159 }; | 160 }; |
160 | 161 |
161 enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; | 162 enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; |
162 | 163 |
163 // Static representation of a module. | 164 // Static representation of a module. |
164 struct WasmModule { | 165 struct WasmModule { |
165 static const uint32_t kPageSize = 0x10000; // Page size, 64kb. | 166 static const uint32_t kPageSize = 0x10000; // Page size, 64kb. |
167 static const uint32_t kMaxLegalPages = 65536; // Maximum legal pages | |
166 static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb | 168 static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb |
167 static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb | 169 static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb |
168 | 170 |
169 const byte* module_start; // starting address for the module bytes. | 171 const byte* module_start; // starting address for the module bytes. |
170 const byte* module_end; // end address for the module bytes. | 172 const byte* module_end; // end address for the module bytes. |
171 uint32_t min_mem_pages; // minimum size of the memory in 64k pages. | 173 uint32_t min_mem_pages; // minimum size of the memory in 64k pages. |
172 uint32_t max_mem_pages; // maximum size of the memory in 64k pages. | 174 uint32_t max_mem_pages; // maximum size of the memory in 64k pages. |
173 bool mem_export; // true if the memory is exported. | 175 bool mem_export; // true if the memory is exported. |
174 bool mem_external; // true if the memory is external. | |
175 // TODO(wasm): reconcile start function index being an int with | 176 // TODO(wasm): reconcile start function index being an int with |
176 // the fact that we index on uint32_t, so we may technically not be | 177 // the fact that we index on uint32_t, so we may technically not be |
177 // able to represent some start_function_index -es. | 178 // able to represent some start_function_index -es. |
178 int start_function_index; // start function, if any. | 179 int start_function_index; // start function, if any. |
179 ModuleOrigin origin; // origin of the module | 180 ModuleOrigin origin; // origin of the module |
180 | 181 |
181 std::vector<WasmGlobal> globals; // globals in this module. | 182 std::vector<WasmGlobal> globals; // globals in this module. |
182 uint32_t globals_size; // size of globals table. | 183 uint32_t globals_size; // size of globals table. |
184 uint32_t num_imported_functions; // number of imported functions. | |
185 uint32_t num_declared_functions; // number of declared functions. | |
186 uint32_t num_exported_functions; // number of exported functions. | |
183 std::vector<FunctionSig*> signatures; // signatures in this module. | 187 std::vector<FunctionSig*> signatures; // signatures in this module. |
184 std::vector<WasmFunction> functions; // functions in this module. | 188 std::vector<WasmFunction> functions; // functions in this module. |
185 std::vector<WasmDataSegment> data_segments; // data segments in this module. | 189 std::vector<WasmDataSegment> data_segments; // data segments in this module. |
186 std::vector<WasmIndirectFunctionTable> function_tables; // function tables. | 190 std::vector<WasmIndirectFunctionTable> function_tables; // function tables. |
187 std::vector<WasmImport> import_table; // import table. | 191 std::vector<WasmImport> import_table; // import table. |
188 std::vector<WasmExport> export_table; // export table. | 192 std::vector<WasmExport> export_table; // export table. |
193 std::vector<WasmTableInit> table_inits; // initializations of tables | |
189 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we | 194 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we |
190 // use on the try bots, semaphore::Wait() can return while some compilation | 195 // use on the try bots, semaphore::Wait() can return while some compilation |
191 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned | 196 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned |
192 // up right after semaphore::Wait() returns, then this can cause an | 197 // up right after semaphore::Wait() returns, then this can cause an |
193 // invalid-semaphore error in the compilation tasks. | 198 // invalid-semaphore error in the compilation tasks. |
194 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots | 199 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots |
195 // switch to libc-2.21 or higher. | 200 // switch to libc-2.21 or higher. |
196 std::unique_ptr<base::Semaphore> pending_tasks; | 201 std::unique_ptr<base::Semaphore> pending_tasks; |
197 | 202 |
198 WasmModule() : WasmModule(nullptr) {} | 203 WasmModule() : WasmModule(nullptr) {} |
(...skipping 28 matching lines...) Expand all Loading... | |
227 } | 232 } |
228 | 233 |
229 // Checks the given offset range is contained within the module bytes. | 234 // Checks the given offset range is contained within the module bytes. |
230 bool BoundsCheck(uint32_t start, uint32_t end) const { | 235 bool BoundsCheck(uint32_t start, uint32_t end) const { |
231 size_t size = module_end - module_start; | 236 size_t size = module_end - module_start; |
232 return start <= size && end <= size; | 237 return start <= size && end <= size; |
233 } | 238 } |
234 | 239 |
235 // Creates a new instantiation of the module in the given isolate. | 240 // Creates a new instantiation of the module in the given isolate. |
236 static MaybeHandle<JSObject> Instantiate(Isolate* isolate, | 241 static MaybeHandle<JSObject> Instantiate(Isolate* isolate, |
242 ErrorThrower* thrower, | |
237 Handle<JSObject> module_object, | 243 Handle<JSObject> module_object, |
238 Handle<JSReceiver> ffi, | 244 Handle<JSReceiver> ffi, |
239 Handle<JSArrayBuffer> memory); | 245 Handle<JSArrayBuffer> memory); |
240 | 246 |
241 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, | 247 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, |
242 ErrorThrower* thrower) const; | 248 ErrorThrower* thrower) const; |
243 | 249 |
244 private: | 250 private: |
245 DISALLOW_COPY_AND_ASSIGN(WasmModule); | 251 DISALLOW_COPY_AND_ASSIGN(WasmModule); |
246 }; | 252 }; |
247 | 253 |
248 // An instantiated WASM module, including memory, function table, etc. | 254 // An instantiated WASM module, including memory, function table, etc. |
249 struct WasmModuleInstance { | 255 struct WasmModuleInstance { |
250 const WasmModule* module; // static representation of the module. | 256 const WasmModule* module; // static representation of the module. |
251 // -- Heap allocated -------------------------------------------------------- | 257 // -- Heap allocated -------------------------------------------------------- |
252 Handle<JSObject> js_object; // JavaScript module object. | 258 Handle<JSObject> js_object; // JavaScript module object. |
253 Handle<Context> context; // JavaScript native context. | 259 Handle<Context> context; // JavaScript native context. |
254 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. | 260 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. |
255 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. | 261 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. |
256 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. | 262 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. |
257 std::vector<Handle<Code>> function_code; // code objects for each function. | 263 std::vector<Handle<Code>> function_code; // code objects for each function. |
258 std::vector<Handle<Code>> import_code; // code objects for each import. | |
259 // -- raw memory ------------------------------------------------------------ | 264 // -- raw memory ------------------------------------------------------------ |
260 byte* mem_start; // start of linear memory. | 265 byte* mem_start; // start of linear memory. |
261 uint32_t mem_size; // size of the linear memory. | 266 uint32_t mem_size; // size of the linear memory. |
262 // -- raw globals ----------------------------------------------------------- | 267 // -- raw globals ----------------------------------------------------------- |
263 byte* globals_start; // start of the globals area. | 268 byte* globals_start; // start of the globals area. |
264 | 269 |
265 explicit WasmModuleInstance(const WasmModule* m) | 270 explicit WasmModuleInstance(const WasmModule* m) |
266 : module(m), | 271 : module(m), |
267 function_tables(m->function_tables.size()), | 272 function_tables(m->function_tables.size()), |
268 function_code(m->functions.size()), | 273 function_code(m->functions.size()), |
269 import_code(m->import_table.size()), | |
270 mem_start(nullptr), | 274 mem_start(nullptr), |
271 mem_size(0), | 275 mem_size(0), |
272 globals_start(nullptr) {} | 276 globals_start(nullptr) {} |
273 }; | 277 }; |
274 | 278 |
275 // Interface provided to the decoder/graph builder which contains only | 279 // Interface provided to the decoder/graph builder which contains only |
276 // minimal information about the globals, functions, and function tables. | 280 // minimal information about the globals, functions, and function tables. |
277 struct ModuleEnv { | 281 struct ModuleEnv { |
278 const WasmModule* module; | 282 const WasmModule* module; |
279 WasmModuleInstance* instance; | 283 WasmModuleInstance* instance; |
280 ModuleOrigin origin; | 284 ModuleOrigin origin; |
281 // TODO(mtrofin): remove this once we introduce WASM_DIRECT_CALL | |
282 // reloc infos. | |
283 std::vector<Handle<Code>> placeholders; | |
284 | 285 |
285 bool IsValidGlobal(uint32_t index) const { | 286 bool IsValidGlobal(uint32_t index) const { |
286 return module && index < module->globals.size(); | 287 return module && index < module->globals.size(); |
287 } | 288 } |
288 bool IsValidFunction(uint32_t index) const { | 289 bool IsValidFunction(uint32_t index) const { |
289 return module && index < module->functions.size(); | 290 return module && index < module->functions.size(); |
290 } | 291 } |
291 bool IsValidSignature(uint32_t index) const { | 292 bool IsValidSignature(uint32_t index) const { |
292 return module && index < module->signatures.size(); | 293 return module && index < module->signatures.size(); |
293 } | 294 } |
294 bool IsValidImport(uint32_t index) const { | |
295 return module && index < module->import_table.size(); | |
296 } | |
297 bool IsValidTable(uint32_t index) const { | 295 bool IsValidTable(uint32_t index) const { |
298 return module && index < module->function_tables.size(); | 296 return module && index < module->function_tables.size(); |
299 } | 297 } |
300 LocalType GetGlobalType(uint32_t index) { | 298 LocalType GetGlobalType(uint32_t index) { |
301 DCHECK(IsValidGlobal(index)); | 299 DCHECK(IsValidGlobal(index)); |
302 return module->globals[index].type; | 300 return module->globals[index].type; |
303 } | 301 } |
304 FunctionSig* GetFunctionSignature(uint32_t index) { | 302 FunctionSig* GetFunctionSignature(uint32_t index) { |
305 DCHECK(IsValidFunction(index)); | 303 DCHECK(IsValidFunction(index)); |
306 return module->functions[index].sig; | 304 return module->functions[index].sig; |
307 } | 305 } |
308 FunctionSig* GetImportSignature(uint32_t index) { | |
309 DCHECK(IsValidImport(index)); | |
310 return module->import_table[index].sig; | |
311 } | |
312 FunctionSig* GetSignature(uint32_t index) { | 306 FunctionSig* GetSignature(uint32_t index) { |
313 DCHECK(IsValidSignature(index)); | 307 DCHECK(IsValidSignature(index)); |
314 return module->signatures[index]; | 308 return module->signatures[index]; |
315 } | 309 } |
316 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { | 310 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { |
317 DCHECK(IsValidTable(index)); | 311 DCHECK(IsValidTable(index)); |
318 return &module->function_tables[index]; | 312 return &module->function_tables[index]; |
319 } | 313 } |
320 | 314 |
321 bool asm_js() { return origin == kAsmJsOrigin; } | 315 bool asm_js() { return origin == kAsmJsOrigin; } |
322 | 316 |
323 Handle<Code> GetCodeOrPlaceholder(uint32_t index) const; | 317 Handle<Code> GetFunctionCode(uint32_t index) { |
324 Handle<Code> GetImportCode(uint32_t index); | 318 DCHECK_NOT_NULL(instance); |
319 return instance->function_code[index]; | |
320 } | |
325 | 321 |
326 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, | 322 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, |
327 FunctionSig* sig); | 323 FunctionSig* sig); |
328 static compiler::CallDescriptor* GetI32WasmCallDescriptor( | 324 static compiler::CallDescriptor* GetI32WasmCallDescriptor( |
329 Zone* zone, compiler::CallDescriptor* descriptor); | 325 Zone* zone, compiler::CallDescriptor* descriptor); |
330 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); | 326 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); |
331 }; | 327 }; |
332 | 328 |
333 // A helper for printing out the names of functions. | 329 // A helper for printing out the names of functions. |
334 struct WasmFunctionName { | 330 struct WasmFunctionName { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, | 397 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, |
402 Handle<FixedArray> compiled_module, | 398 Handle<FixedArray> compiled_module, |
403 ModuleOrigin origin); | 399 ModuleOrigin origin); |
404 | 400 |
405 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, | 401 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, |
406 const byte* start, | 402 const byte* start, |
407 const byte* end, | 403 const byte* end, |
408 ErrorThrower* thrower, | 404 ErrorThrower* thrower, |
409 ModuleOrigin origin); | 405 ModuleOrigin origin); |
410 | 406 |
407 // Get the number of imported functions for a WASM instance. | |
408 uint32_t GetNumImportedFunctions(Handle<JSObject> wasm_object); | |
409 | |
411 // Assumed to be called with a code object associated to a wasm module instance. | 410 // Assumed to be called with a code object associated to a wasm module instance. |
412 // Intended to be called from runtime functions. | 411 // Intended to be called from runtime functions. |
413 // Returns undefined if the runtime support was not setup, nullptr if the | 412 // Returns undefined if the runtime support was not setup, nullptr if the |
414 // instance | 413 // instance |
415 // was collected, or the instance object owning the Code object | 414 // was collected, or the instance object owning the Code object |
416 Object* GetOwningWasmInstance(Object* undefined, Code* code); | 415 Object* GetOwningWasmInstance(Object* undefined, Code* code); |
417 | 416 |
418 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 417 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
419 Handle<JSObject> instance); | 418 Handle<JSObject> instance); |
420 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); | 419 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); |
421 | 420 |
422 namespace testing { | 421 namespace testing { |
423 | 422 |
424 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, | 423 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, |
425 int instance_count); | 424 int instance_count); |
426 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 425 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
427 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 426 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
428 | 427 |
429 } // namespace testing | 428 } // namespace testing |
430 } // namespace wasm | 429 } // namespace wasm |
431 } // namespace internal | 430 } // namespace internal |
432 } // namespace v8 | 431 } // namespace v8 |
433 | 432 |
434 #endif // V8_WASM_MODULE_H_ | 433 #endif // V8_WASM_MODULE_H_ |
OLD | NEW |