| 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" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // Static representation of a wasm data segment. | 144 // Static representation of a wasm data segment. |
| 145 struct WasmDataSegment { | 145 struct WasmDataSegment { |
| 146 uint32_t dest_addr; // destination memory address of the data. | 146 uint32_t dest_addr; // destination memory address of the data. |
| 147 uint32_t source_offset; // start offset in the module bytes. | 147 uint32_t source_offset; // start offset in the module bytes. |
| 148 uint32_t source_size; // end offset in the module bytes. | 148 uint32_t source_size; // end offset in the module bytes. |
| 149 bool init; // true if loaded upon instantiation. | 149 bool init; // true if loaded upon instantiation. |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 // Static representation of a wasm indirect call table. | 152 // Static representation of a wasm indirect call table. |
| 153 struct WasmIndirectFunctionTable { | 153 struct WasmIndirectFunctionTable { |
| 154 bool isDefault; // true if table should be used as default. |
| 155 FunctionSig* sig; // signature of the table. |
| 156 uint32_t sig_index; // index into the signature table. |
| 154 uint32_t size; // initial table size. | 157 uint32_t size; // initial table size. |
| 155 uint32_t max_size; // maximum table size. | 158 uint32_t max_size; // maximum table size. |
| 156 std::vector<uint16_t> values; // function table. | 159 std::vector<uint16_t> values; // function table. |
| 157 }; | 160 }; |
| 158 | 161 |
| 159 enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; | 162 enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; |
| 160 | 163 |
| 161 // Static representation of a module. | 164 // Static representation of a module. |
| 162 struct WasmModule { | 165 struct WasmModule { |
| 163 static const uint32_t kPageSize = 0x10000; // Page size, 64kb. | 166 static const uint32_t kPageSize = 0x10000; // Page size, 64kb. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return module->globals[index].type; | 303 return module->globals[index].type; |
| 301 } | 304 } |
| 302 FunctionSig* GetFunctionSignature(uint32_t index) { | 305 FunctionSig* GetFunctionSignature(uint32_t index) { |
| 303 DCHECK(IsValidFunction(index)); | 306 DCHECK(IsValidFunction(index)); |
| 304 return module->functions[index].sig; | 307 return module->functions[index].sig; |
| 305 } | 308 } |
| 306 FunctionSig* GetImportSignature(uint32_t index) { | 309 FunctionSig* GetImportSignature(uint32_t index) { |
| 307 DCHECK(IsValidImport(index)); | 310 DCHECK(IsValidImport(index)); |
| 308 return module->import_table[index].sig; | 311 return module->import_table[index].sig; |
| 309 } | 312 } |
| 313 FunctionSig* GetTableSignature(uint32_t index) { |
| 314 DCHECK(IsValidSignature(index)); |
| 315 return module->function_tables[index].sig; |
| 316 } |
| 310 FunctionSig* GetSignature(uint32_t index) { | 317 FunctionSig* GetSignature(uint32_t index) { |
| 311 DCHECK(IsValidSignature(index)); | 318 DCHECK(IsValidSignature(index)); |
| 312 return module->signatures[index]; | 319 return module->signatures[index]; |
| 313 } | 320 } |
| 314 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { | 321 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { |
| 315 DCHECK(IsValidTable(index)); | 322 DCHECK(IsValidTable(index)); |
| 316 return &module->function_tables[index]; | 323 return &module->function_tables[index]; |
| 317 } | 324 } |
| 318 | 325 |
| 319 bool asm_js() { return origin == kAsmJsOrigin; } | 326 bool asm_js() { return origin == kAsmJsOrigin; } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // Constructs a single function table as a FixedArray of double size, | 396 // Constructs a single function table as a FixedArray of double size, |
| 390 // populating it with function signature indices and function indices. | 397 // populating it with function signature indices and function indices. |
| 391 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, | 398 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, |
| 392 const WasmModule* module); | 399 const WasmModule* module); |
| 393 | 400 |
| 394 // Populates a function table by replacing function indices with handles to | 401 // Populates a function table by replacing function indices with handles to |
| 395 // the compiled code. | 402 // the compiled code. |
| 396 void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, | 403 void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, |
| 397 const std::vector<Handle<Code>>* code_table); | 404 const std::vector<Handle<Code>>* code_table); |
| 398 | 405 |
| 406 bool isAnyFuncType(FunctionSig* sig); |
| 407 |
| 399 namespace testing { | 408 namespace testing { |
| 400 | 409 |
| 401 // Decode, verify, and run the function labeled "main" in the | 410 // Decode, verify, and run the function labeled "main" in the |
| 402 // given encoded module. The module should have no imports. | 411 // given encoded module. The module should have no imports. |
| 403 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 412 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
| 404 const byte* module_end, bool asm_js = false); | 413 const byte* module_end, bool asm_js = false); |
| 405 | 414 |
| 406 } // namespace testing | 415 } // namespace testing |
| 407 } // namespace wasm | 416 } // namespace wasm |
| 408 } // namespace internal | 417 } // namespace internal |
| 409 } // namespace v8 | 418 } // namespace v8 |
| 410 | 419 |
| 411 #endif // V8_WASM_MODULE_H_ | 420 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |