| 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 "src/wasm/wasm-opcodes.h" | 8 #include "src/wasm/wasm-opcodes.h" |
| 9 #include "src/wasm/wasm-result.h" | 9 #include "src/wasm/wasm-result.h" |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 // Static representation of a wasm data segment. | 92 // Static representation of a wasm data segment. |
| 93 struct WasmDataSegment { | 93 struct WasmDataSegment { |
| 94 uint32_t dest_addr; // destination memory address of the data. | 94 uint32_t dest_addr; // destination memory address of the data. |
| 95 uint32_t source_offset; // start offset in the module bytes. | 95 uint32_t source_offset; // start offset in the module bytes. |
| 96 uint32_t source_size; // end offset in the module bytes. | 96 uint32_t source_size; // end offset in the module bytes. |
| 97 bool init; // true if loaded upon instantiation. | 97 bool init; // true if loaded upon instantiation. |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; |
| 101 |
| 100 // Static representation of a module. | 102 // Static representation of a module. |
| 101 struct WasmModule { | 103 struct WasmModule { |
| 102 static const uint8_t kMinMemSize = 12; // Minimum memory size = 4kb | 104 static const uint8_t kMinMemSize = 12; // Minimum memory size = 4kb |
| 103 static const uint8_t kMaxMemSize = 30; // Maximum memory size = 1gb | 105 static const uint8_t kMaxMemSize = 30; // Maximum memory size = 1gb |
| 104 | 106 |
| 105 Isolate* shared_isolate; // isolate for storing shared code. | 107 Isolate* shared_isolate; // isolate for storing shared code. |
| 106 const byte* module_start; // starting address for the module bytes. | 108 const byte* module_start; // starting address for the module bytes. |
| 107 const byte* module_end; // end address for the module bytes. | 109 const byte* module_end; // end address for the module bytes. |
| 108 uint8_t min_mem_size_log2; // minimum size of the memory (log base 2). | 110 uint8_t min_mem_size_log2; // minimum size of the memory (log base 2). |
| 109 uint8_t max_mem_size_log2; // maximum size of the memory (log base 2). | 111 uint8_t max_mem_size_log2; // maximum size of the memory (log base 2). |
| 110 bool mem_export; // true if the memory is exported. | 112 bool mem_export; // true if the memory is exported. |
| 111 bool mem_external; // true if the memory is external. | 113 bool mem_external; // true if the memory is external. |
| 112 int start_function_index; // start function, if any. | 114 int start_function_index; // start function, if any. |
| 115 ModuleOrigin origin; // origin of the module |
| 113 | 116 |
| 114 std::vector<WasmGlobal>* globals; // globals in this module. | 117 std::vector<WasmGlobal>* globals; // globals in this module. |
| 115 std::vector<FunctionSig*>* signatures; // signatures in this module. | 118 std::vector<FunctionSig*>* signatures; // signatures in this module. |
| 116 std::vector<WasmFunction>* functions; // functions in this module. | 119 std::vector<WasmFunction>* functions; // functions in this module. |
| 117 std::vector<WasmDataSegment>* data_segments; // data segments in this module. | 120 std::vector<WasmDataSegment>* data_segments; // data segments in this module. |
| 118 std::vector<uint16_t>* function_table; // function table. | 121 std::vector<uint16_t>* function_table; // function table. |
| 119 std::vector<WasmImport>* import_table; // import table. | 122 std::vector<WasmImport>* import_table; // import table. |
| 120 std::vector<WasmExport>* export_table; // export table. | 123 std::vector<WasmExport>* export_table; // export table. |
| 121 | 124 |
| 122 WasmModule(); | 125 WasmModule(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 172 |
| 170 // forward declaration. | 173 // forward declaration. |
| 171 class WasmLinker; | 174 class WasmLinker; |
| 172 | 175 |
| 173 // Interface provided to the decoder/graph builder which contains only | 176 // Interface provided to the decoder/graph builder which contains only |
| 174 // minimal information about the globals, functions, and function tables. | 177 // minimal information about the globals, functions, and function tables. |
| 175 struct ModuleEnv { | 178 struct ModuleEnv { |
| 176 WasmModule* module; | 179 WasmModule* module; |
| 177 WasmModuleInstance* instance; | 180 WasmModuleInstance* instance; |
| 178 WasmLinker* linker; | 181 WasmLinker* linker; |
| 179 bool asm_js; // true if the module originated from asm.js. | 182 ModuleOrigin origin; |
| 180 | 183 |
| 181 bool IsValidGlobal(uint32_t index) { | 184 bool IsValidGlobal(uint32_t index) { |
| 182 return module && index < module->globals->size(); | 185 return module && index < module->globals->size(); |
| 183 } | 186 } |
| 184 bool IsValidFunction(uint32_t index) { | 187 bool IsValidFunction(uint32_t index) { |
| 185 return module && index < module->functions->size(); | 188 return module && index < module->functions->size(); |
| 186 } | 189 } |
| 187 bool IsValidSignature(uint32_t index) { | 190 bool IsValidSignature(uint32_t index) { |
| 188 return module && index < module->signatures->size(); | 191 return module && index < module->signatures->size(); |
| 189 } | 192 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 204 } | 207 } |
| 205 FunctionSig* GetSignature(uint32_t index) { | 208 FunctionSig* GetSignature(uint32_t index) { |
| 206 DCHECK(IsValidSignature(index)); | 209 DCHECK(IsValidSignature(index)); |
| 207 return module->signatures->at(index); | 210 return module->signatures->at(index); |
| 208 } | 211 } |
| 209 size_t FunctionTableSize() { | 212 size_t FunctionTableSize() { |
| 210 return module && module->function_table ? module->function_table->size() | 213 return module && module->function_table ? module->function_table->size() |
| 211 : 0; | 214 : 0; |
| 212 } | 215 } |
| 213 | 216 |
| 217 bool asm_js() { return origin == kAsmJsOrigin; } |
| 218 |
| 214 Handle<Code> GetFunctionCode(uint32_t index); | 219 Handle<Code> GetFunctionCode(uint32_t index); |
| 215 Handle<Code> GetImportCode(uint32_t index); | 220 Handle<Code> GetImportCode(uint32_t index); |
| 216 Handle<FixedArray> GetFunctionTable(); | 221 Handle<FixedArray> GetFunctionTable(); |
| 217 | 222 |
| 218 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, | 223 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, |
| 219 FunctionSig* sig); | 224 FunctionSig* sig); |
| 220 static compiler::CallDescriptor* GetI32WasmCallDescriptor( | 225 static compiler::CallDescriptor* GetI32WasmCallDescriptor( |
| 221 Zone* zone, compiler::CallDescriptor* descriptor); | 226 Zone* zone, compiler::CallDescriptor* descriptor); |
| 222 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); | 227 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); |
| 223 }; | 228 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 244 | 249 |
| 245 // For testing. Decode, verify, and run the last exported function in the | 250 // For testing. Decode, verify, and run the last exported function in the |
| 246 // given decoded module. | 251 // given decoded module. |
| 247 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); | 252 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); |
| 248 | 253 |
| 249 } // namespace wasm | 254 } // namespace wasm |
| 250 } // namespace internal | 255 } // namespace internal |
| 251 } // namespace v8 | 256 } // namespace v8 |
| 252 | 257 |
| 253 #endif // V8_WASM_MODULE_H_ | 258 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |