| 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 15 matching lines...) Expand all Loading... |
| 26 enum WasmSectionDeclCode { | 26 enum WasmSectionDeclCode { |
| 27 kDeclMemory = 0x00, | 27 kDeclMemory = 0x00, |
| 28 kDeclSignatures = 0x01, | 28 kDeclSignatures = 0x01, |
| 29 kDeclFunctions = 0x02, | 29 kDeclFunctions = 0x02, |
| 30 kDeclGlobals = 0x03, | 30 kDeclGlobals = 0x03, |
| 31 kDeclDataSegments = 0x04, | 31 kDeclDataSegments = 0x04, |
| 32 kDeclFunctionTable = 0x05, | 32 kDeclFunctionTable = 0x05, |
| 33 kDeclEnd = 0x06, | 33 kDeclEnd = 0x06, |
| 34 kDeclStartFunction = 0x07, | 34 kDeclStartFunction = 0x07, |
| 35 kDeclImportTable = 0x08, | 35 kDeclImportTable = 0x08, |
| 36 kDeclExportTable = 0x09, |
| 36 kDeclWLL = 0x11, | 37 kDeclWLL = 0x11, |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 static const int kMaxModuleSectionCode = 0x11; | 40 static const int kMaxModuleSectionCode = 0x11; |
| 40 | 41 |
| 41 enum WasmFunctionDeclBit { | 42 enum WasmFunctionDeclBit { |
| 42 kDeclFunctionName = 0x01, | 43 kDeclFunctionName = 0x01, |
| 43 kDeclFunctionImport = 0x02, | 44 kDeclFunctionImport = 0x02, |
| 44 kDeclFunctionLocals = 0x04, | 45 kDeclFunctionLocals = 0x04, |
| 45 kDeclFunctionExport = 0x08 | 46 kDeclFunctionExport = 0x08 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 // Static representation of an imported WASM function. | 70 // Static representation of an imported WASM function. |
| 70 struct WasmImport { | 71 struct WasmImport { |
| 71 FunctionSig* sig; // signature of the function. | 72 FunctionSig* sig; // signature of the function. |
| 72 uint16_t sig_index; // index into the signature table. | 73 uint16_t sig_index; // index into the signature table. |
| 73 uint32_t module_name_offset; // offset in module bytes of the module name. | 74 uint32_t module_name_offset; // offset in module bytes of the module name. |
| 74 uint32_t function_name_offset; // offset in module bytes of the import name. | 75 uint32_t function_name_offset; // offset in module bytes of the import name. |
| 75 }; | 76 }; |
| 76 | 77 |
| 78 // Static representation of an exported WASM function. |
| 79 struct WasmExport { |
| 80 uint16_t func_index; // index into the function table. |
| 81 uint32_t name_offset; // offset in module bytes of the name to export. |
| 82 }; |
| 83 |
| 77 // Static representation of a wasm global variable. | 84 // Static representation of a wasm global variable. |
| 78 struct WasmGlobal { | 85 struct WasmGlobal { |
| 79 uint32_t name_offset; // offset in the module bytes of the name, if any. | 86 uint32_t name_offset; // offset in the module bytes of the name, if any. |
| 80 MachineType type; // type of the global. | 87 MachineType type; // type of the global. |
| 81 uint32_t offset; // offset from beginning of globals area. | 88 uint32_t offset; // offset from beginning of globals area. |
| 82 bool exported; // true if this global is exported. | 89 bool exported; // true if this global is exported. |
| 83 }; | 90 }; |
| 84 | 91 |
| 85 // Static representation of a wasm data segment. | 92 // Static representation of a wasm data segment. |
| 86 struct WasmDataSegment { | 93 struct WasmDataSegment { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 103 bool mem_export; // true if the memory is exported. | 110 bool mem_export; // true if the memory is exported. |
| 104 bool mem_external; // true if the memory is external. | 111 bool mem_external; // true if the memory is external. |
| 105 int start_function_index; // start function, if any. | 112 int start_function_index; // start function, if any. |
| 106 | 113 |
| 107 std::vector<WasmGlobal>* globals; // globals in this module. | 114 std::vector<WasmGlobal>* globals; // globals in this module. |
| 108 std::vector<FunctionSig*>* signatures; // signatures in this module. | 115 std::vector<FunctionSig*>* signatures; // signatures in this module. |
| 109 std::vector<WasmFunction>* functions; // functions in this module. | 116 std::vector<WasmFunction>* functions; // functions in this module. |
| 110 std::vector<WasmDataSegment>* data_segments; // data segments in this module. | 117 std::vector<WasmDataSegment>* data_segments; // data segments in this module. |
| 111 std::vector<uint16_t>* function_table; // function table. | 118 std::vector<uint16_t>* function_table; // function table. |
| 112 std::vector<WasmImport>* import_table; // import table. | 119 std::vector<WasmImport>* import_table; // import table. |
| 120 std::vector<WasmExport>* export_table; // export table. |
| 113 | 121 |
| 114 WasmModule(); | 122 WasmModule(); |
| 115 ~WasmModule(); | 123 ~WasmModule(); |
| 116 | 124 |
| 117 // Get a pointer to a string stored in the module bytes representing a name. | 125 // Get a pointer to a string stored in the module bytes representing a name. |
| 118 const char* GetName(uint32_t offset) const { | 126 const char* GetName(uint32_t offset) const { |
| 119 if (offset == 0) return "<?>"; // no name. | 127 if (offset == 0) return "<?>"; // no name. |
| 120 CHECK(BoundsCheck(offset, offset + 1)); | 128 CHECK(BoundsCheck(offset, offset + 1)); |
| 121 return reinterpret_cast<const char*>(module_start + offset); | 129 return reinterpret_cast<const char*>(module_start + offset); |
| 122 } | 130 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 244 |
| 237 // For testing. Decode, verify, and run the last exported function in the | 245 // For testing. Decode, verify, and run the last exported function in the |
| 238 // given decoded module. | 246 // given decoded module. |
| 239 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); | 247 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); |
| 240 | 248 |
| 241 } // namespace wasm | 249 } // namespace wasm |
| 242 } // namespace internal | 250 } // namespace internal |
| 243 } // namespace v8 | 251 } // namespace v8 |
| 244 | 252 |
| 245 #endif // V8_WASM_MODULE_H_ | 253 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |