Chromium Code Reviews| 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 |
| 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 { |
|
ahaas
2016/09/19 11:02:38
This looks like an WasmInitValue and not like a Wa
titzer
2016/09/19 11:37:03
That's up for discussion in the design repo, but a
| |
| 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 \ |
|
ahaas
2016/09/19 11:02:38
Wouldn't this definition fit better into wasm-macr
titzer
2016/09/19 11:37:03
It's actually used in the module decoder. wasm-mac
| |
| 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. |
| 166 static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb | 167 static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb |
| 167 static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb | 168 static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb |
| 168 | 169 |
| 169 const byte* module_start; // starting address for the module bytes. | 170 const byte* module_start; // starting address for the module bytes. |
| 170 const byte* module_end; // end address for the module bytes. | 171 const byte* module_end; // end address for the module bytes. |
| 171 uint32_t min_mem_pages; // minimum size of the memory in 64k pages. | 172 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. | 173 uint32_t max_mem_pages; // maximum size of the memory in 64k pages. |
| 173 bool mem_export; // true if the memory is exported. | 174 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 | 175 // 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 | 176 // the fact that we index on uint32_t, so we may technically not be |
| 177 // able to represent some start_function_index -es. | 177 // able to represent some start_function_index -es. |
| 178 int start_function_index; // start function, if any. | 178 int start_function_index; // start function, if any. |
| 179 ModuleOrigin origin; // origin of the module | 179 ModuleOrigin origin; // origin of the module |
| 180 | 180 |
| 181 std::vector<WasmGlobal> globals; // globals in this module. | 181 std::vector<WasmGlobal> globals; // globals in this module. |
| 182 uint32_t globals_size; // size of globals table. | 182 uint32_t globals_size; // size of globals table. |
| 183 uint32_t num_imported_functions; // number of imported functions. | |
| 184 uint32_t num_declared_functions; // number of declared functions. | |
| 185 uint32_t num_exported_functions; // number of exported functions. | |
| 183 std::vector<FunctionSig*> signatures; // signatures in this module. | 186 std::vector<FunctionSig*> signatures; // signatures in this module. |
| 184 std::vector<WasmFunction> functions; // functions in this module. | 187 std::vector<WasmFunction> functions; // functions in this module. |
| 185 std::vector<WasmDataSegment> data_segments; // data segments in this module. | 188 std::vector<WasmDataSegment> data_segments; // data segments in this module. |
| 186 std::vector<WasmIndirectFunctionTable> function_tables; // function tables. | 189 std::vector<WasmIndirectFunctionTable> function_tables; // function tables. |
| 187 std::vector<WasmImport> import_table; // import table. | 190 std::vector<WasmImport> import_table; // import table. |
| 188 std::vector<WasmExport> export_table; // export table. | 191 std::vector<WasmExport> export_table; // export table. |
| 192 std::vector<WasmTableInit> table_inits; // initializations of tables | |
| 189 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we | 193 // 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 | 194 // use on the try bots, semaphore::Wait() can return while some compilation |
| 191 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned | 195 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned |
| 192 // up right after semaphore::Wait() returns, then this can cause an | 196 // up right after semaphore::Wait() returns, then this can cause an |
| 193 // invalid-semaphore error in the compilation tasks. | 197 // invalid-semaphore error in the compilation tasks. |
| 194 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots | 198 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots |
| 195 // switch to libc-2.21 or higher. | 199 // switch to libc-2.21 or higher. |
| 196 std::unique_ptr<base::Semaphore> pending_tasks; | 200 std::unique_ptr<base::Semaphore> pending_tasks; |
| 197 | 201 |
| 198 WasmModule() : WasmModule(nullptr) {} | 202 WasmModule() : WasmModule(nullptr) {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 // An instantiated WASM module, including memory, function table, etc. | 252 // An instantiated WASM module, including memory, function table, etc. |
| 249 struct WasmModuleInstance { | 253 struct WasmModuleInstance { |
| 250 const WasmModule* module; // static representation of the module. | 254 const WasmModule* module; // static representation of the module. |
| 251 // -- Heap allocated -------------------------------------------------------- | 255 // -- Heap allocated -------------------------------------------------------- |
| 252 Handle<JSObject> js_object; // JavaScript module object. | 256 Handle<JSObject> js_object; // JavaScript module object. |
| 253 Handle<Context> context; // JavaScript native context. | 257 Handle<Context> context; // JavaScript native context. |
| 254 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. | 258 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. |
| 255 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. | 259 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. |
| 256 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. | 260 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. |
| 257 std::vector<Handle<Code>> function_code; // code objects for each function. | 261 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 ------------------------------------------------------------ | 262 // -- raw memory ------------------------------------------------------------ |
| 260 byte* mem_start; // start of linear memory. | 263 byte* mem_start; // start of linear memory. |
| 261 uint32_t mem_size; // size of the linear memory. | 264 uint32_t mem_size; // size of the linear memory. |
| 262 // -- raw globals ----------------------------------------------------------- | 265 // -- raw globals ----------------------------------------------------------- |
| 263 byte* globals_start; // start of the globals area. | 266 byte* globals_start; // start of the globals area. |
| 264 | 267 |
| 265 explicit WasmModuleInstance(const WasmModule* m) | 268 explicit WasmModuleInstance(const WasmModule* m) |
| 266 : module(m), | 269 : module(m), |
| 267 function_tables(m->function_tables.size()), | 270 function_tables(m->function_tables.size()), |
| 268 function_code(m->functions.size()), | 271 function_code(m->functions.size()), |
| 269 import_code(m->import_table.size()), | |
| 270 mem_start(nullptr), | 272 mem_start(nullptr), |
| 271 mem_size(0), | 273 mem_size(0), |
| 272 globals_start(nullptr) {} | 274 globals_start(nullptr) {} |
| 273 }; | 275 }; |
| 274 | 276 |
| 275 // Interface provided to the decoder/graph builder which contains only | 277 // Interface provided to the decoder/graph builder which contains only |
| 276 // minimal information about the globals, functions, and function tables. | 278 // minimal information about the globals, functions, and function tables. |
| 277 struct ModuleEnv { | 279 struct ModuleEnv { |
| 278 const WasmModule* module; | 280 const WasmModule* module; |
| 279 WasmModuleInstance* instance; | 281 WasmModuleInstance* instance; |
| 280 ModuleOrigin origin; | 282 ModuleOrigin origin; |
| 281 // TODO(mtrofin): remove this once we introduce WASM_DIRECT_CALL | |
| 282 // reloc infos. | |
| 283 std::vector<Handle<Code>> placeholders; | |
| 284 | 283 |
| 285 bool IsValidGlobal(uint32_t index) const { | 284 bool IsValidGlobal(uint32_t index) const { |
| 286 return module && index < module->globals.size(); | 285 return module && index < module->globals.size(); |
| 287 } | 286 } |
| 288 bool IsValidFunction(uint32_t index) const { | 287 bool IsValidFunction(uint32_t index) const { |
| 289 return module && index < module->functions.size(); | 288 return module && index < module->functions.size(); |
| 290 } | 289 } |
| 291 bool IsValidSignature(uint32_t index) const { | 290 bool IsValidSignature(uint32_t index) const { |
| 292 return module && index < module->signatures.size(); | 291 return module && index < module->signatures.size(); |
| 293 } | 292 } |
| 294 bool IsValidImport(uint32_t index) const { | |
| 295 return module && index < module->import_table.size(); | |
| 296 } | |
| 297 bool IsValidTable(uint32_t index) const { | 293 bool IsValidTable(uint32_t index) const { |
| 298 return module && index < module->function_tables.size(); | 294 return module && index < module->function_tables.size(); |
| 299 } | 295 } |
| 300 LocalType GetGlobalType(uint32_t index) { | 296 LocalType GetGlobalType(uint32_t index) { |
| 301 DCHECK(IsValidGlobal(index)); | 297 DCHECK(IsValidGlobal(index)); |
| 302 return module->globals[index].type; | 298 return module->globals[index].type; |
| 303 } | 299 } |
| 304 FunctionSig* GetFunctionSignature(uint32_t index) { | 300 FunctionSig* GetFunctionSignature(uint32_t index) { |
| 305 DCHECK(IsValidFunction(index)); | 301 DCHECK(IsValidFunction(index)); |
| 306 return module->functions[index].sig; | 302 return module->functions[index].sig; |
| 307 } | 303 } |
| 308 FunctionSig* GetImportSignature(uint32_t index) { | |
| 309 DCHECK(IsValidImport(index)); | |
| 310 return module->import_table[index].sig; | |
| 311 } | |
| 312 FunctionSig* GetSignature(uint32_t index) { | 304 FunctionSig* GetSignature(uint32_t index) { |
| 313 DCHECK(IsValidSignature(index)); | 305 DCHECK(IsValidSignature(index)); |
| 314 return module->signatures[index]; | 306 return module->signatures[index]; |
| 315 } | 307 } |
| 316 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { | 308 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { |
| 317 DCHECK(IsValidTable(index)); | 309 DCHECK(IsValidTable(index)); |
| 318 return &module->function_tables[index]; | 310 return &module->function_tables[index]; |
| 319 } | 311 } |
| 320 | 312 |
| 321 bool asm_js() { return origin == kAsmJsOrigin; } | 313 bool asm_js() { return origin == kAsmJsOrigin; } |
| 322 | 314 |
| 323 Handle<Code> GetCodeOrPlaceholder(uint32_t index) const; | 315 Handle<Code> GetFunctionCode(uint32_t index) { |
| 324 Handle<Code> GetImportCode(uint32_t index); | 316 DCHECK_NOT_NULL(instance); |
| 317 return instance->function_code[index]; | |
| 318 } | |
| 325 | 319 |
| 326 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, | 320 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, |
| 327 FunctionSig* sig); | 321 FunctionSig* sig); |
| 328 static compiler::CallDescriptor* GetI32WasmCallDescriptor( | 322 static compiler::CallDescriptor* GetI32WasmCallDescriptor( |
| 329 Zone* zone, compiler::CallDescriptor* descriptor); | 323 Zone* zone, compiler::CallDescriptor* descriptor); |
| 330 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); | 324 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); |
| 331 }; | 325 }; |
| 332 | 326 |
| 333 // A helper for printing out the names of functions. | 327 // A helper for printing out the names of functions. |
| 334 struct WasmFunctionName { | 328 struct WasmFunctionName { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, | 395 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, |
| 402 Handle<FixedArray> compiled_module, | 396 Handle<FixedArray> compiled_module, |
| 403 ModuleOrigin origin); | 397 ModuleOrigin origin); |
| 404 | 398 |
| 405 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, | 399 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, |
| 406 const byte* start, | 400 const byte* start, |
| 407 const byte* end, | 401 const byte* end, |
| 408 ErrorThrower* thrower, | 402 ErrorThrower* thrower, |
| 409 ModuleOrigin origin); | 403 ModuleOrigin origin); |
| 410 | 404 |
| 405 uint32_t GetNumImportedFunctions(Handle<JSObject> wasm_object); | |
| 406 | |
| 411 // Assumed to be called with a code object associated to a wasm module instance. | 407 // Assumed to be called with a code object associated to a wasm module instance. |
| 412 // Intended to be called from runtime functions. | 408 // Intended to be called from runtime functions. |
| 413 // Returns undefined if the runtime support was not setup, nullptr if the | 409 // Returns undefined if the runtime support was not setup, nullptr if the |
| 414 // instance | 410 // instance |
| 415 // was collected, or the instance object owning the Code object | 411 // was collected, or the instance object owning the Code object |
| 416 Object* GetOwningWasmInstance(Object* undefined, Code* code); | 412 Object* GetOwningWasmInstance(Object* undefined, Code* code); |
| 417 | 413 |
| 418 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 414 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
| 419 Handle<JSObject> instance); | 415 Handle<JSObject> instance); |
| 420 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); | 416 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); |
| 421 | 417 |
| 422 namespace testing { | 418 namespace testing { |
| 423 | 419 |
| 424 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, | 420 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, |
| 425 int instance_count); | 421 int instance_count); |
| 426 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 422 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
| 427 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 423 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
| 428 | 424 |
| 429 } // namespace testing | 425 } // namespace testing |
| 430 } // namespace wasm | 426 } // namespace wasm |
| 431 } // namespace internal | 427 } // namespace internal |
| 432 } // namespace v8 | 428 } // namespace v8 |
| 433 | 429 |
| 434 #endif // V8_WASM_MODULE_H_ | 430 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |