| 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 10 matching lines...) Expand all Loading... |
| 21 namespace wasm { | 21 namespace wasm { |
| 22 const size_t kMaxModuleSize = 1024 * 1024 * 1024; | 22 const size_t kMaxModuleSize = 1024 * 1024 * 1024; |
| 23 const size_t kMaxFunctionSize = 128 * 1024; | 23 const size_t kMaxFunctionSize = 128 * 1024; |
| 24 const size_t kMaxStringSize = 256; | 24 const size_t kMaxStringSize = 256; |
| 25 const uint32_t kWasmMagic = 0x6d736100; | 25 const uint32_t kWasmMagic = 0x6d736100; |
| 26 const uint32_t kWasmVersion = 0x0a; | 26 const uint32_t kWasmVersion = 0x0a; |
| 27 | 27 |
| 28 // WebAssembly sections are named as strings in the binary format, but | 28 // WebAssembly sections are named as strings in the binary format, but |
| 29 // internally V8 uses an enum to handle them. | 29 // internally V8 uses an enum to handle them. |
| 30 // | 30 // |
| 31 // Entries have the form F(enumerator, string). | 31 // Entries have the form F(enumerator, order, string). |
| 32 #define FOR_EACH_WASM_SECTION_TYPE(F) \ | 32 #define FOR_EACH_WASM_SECTION_TYPE(F) \ |
| 33 F(Memory, "memory") \ | 33 F(Signatures, 1, "signatures") \ |
| 34 F(Signatures, "signatures") \ | 34 F(ImportTable, 2, "import_table") \ |
| 35 F(Functions, "functions") \ | 35 F(FunctionSignatures, 3, "function_signatures") \ |
| 36 F(Globals, "globals") \ | 36 F(FunctionTable, 4, "function_table") \ |
| 37 F(DataSegments, "data_segments") \ | 37 F(Memory, 5, "memory") \ |
| 38 F(FunctionTable, "function_table") \ | 38 F(ExportTable, 6, "export_table") \ |
| 39 F(End, "end") \ | 39 F(StartFunction, 7, "start_function") \ |
| 40 F(StartFunction, "start_function") \ | 40 F(FunctionBodies, 8, "function_bodies") \ |
| 41 F(ImportTable, "import_table") \ | 41 F(DataSegments, 9, "data_segments") \ |
| 42 F(ExportTable, "export_table") \ | 42 F(Names, 10, "names") \ |
| 43 F(FunctionSignatures, "function_signatures") \ | 43 F(Globals, 0, "globals") \ |
| 44 F(FunctionBodies, "function_bodies") \ | 44 F(Functions, 0, "functions") \ |
| 45 F(Names, "names") | 45 F(End, 0, "end") |
| 46 | 46 |
| 47 // Contants for the above section types: {LEB128 length, characters...}. | 47 // Contants for the above section types: {LEB128 length, characters...}. |
| 48 #define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y' | 48 #define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y' |
| 49 #define WASM_SECTION_SIGNATURES \ | 49 #define WASM_SECTION_SIGNATURES \ |
| 50 10, 's', 'i', 'g', 'n', 'a', 't', 'u', 'r', 'e', 's' | 50 10, 's', 'i', 'g', 'n', 'a', 't', 'u', 'r', 'e', 's' |
| 51 #define WASM_SECTION_FUNCTIONS 9, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 's' | 51 #define WASM_SECTION_FUNCTIONS 9, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 's' |
| 52 #define WASM_SECTION_GLOBALS 7, 'g', 'l', 'o', 'b', 'a', 'l', 's' | 52 #define WASM_SECTION_GLOBALS 7, 'g', 'l', 'o', 'b', 'a', 'l', 's' |
| 53 #define WASM_SECTION_DATA_SEGMENTS \ | 53 #define WASM_SECTION_DATA_SEGMENTS \ |
| 54 13, 'd', 'a', 't', 'a', '_', 's', 'e', 'g', 'm', 'e', 'n', 't', 's' | 54 13, 'd', 'a', 't', 'a', '_', 's', 'e', 'g', 'm', 'e', 'n', 't', 's' |
| 55 #define WASM_SECTION_FUNCTION_TABLE \ | 55 #define WASM_SECTION_FUNCTION_TABLE \ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 78 #define WASM_SECTION_END_SIZE ((size_t)4) | 78 #define WASM_SECTION_END_SIZE ((size_t)4) |
| 79 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)15) | 79 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)15) |
| 80 #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)13) | 80 #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)13) |
| 81 #define WASM_SECTION_EXPORT_TABLE_SIZE ((size_t)13) | 81 #define WASM_SECTION_EXPORT_TABLE_SIZE ((size_t)13) |
| 82 #define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)20) | 82 #define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)20) |
| 83 #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)16) | 83 #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)16) |
| 84 #define WASM_SECTION_NAMES_SIZE ((size_t)6) | 84 #define WASM_SECTION_NAMES_SIZE ((size_t)6) |
| 85 | 85 |
| 86 struct WasmSection { | 86 struct WasmSection { |
| 87 enum class Code : uint32_t { | 87 enum class Code : uint32_t { |
| 88 #define F(enumerator, string) enumerator, | 88 #define F(enumerator, order, string) enumerator, |
| 89 FOR_EACH_WASM_SECTION_TYPE(F) | 89 FOR_EACH_WASM_SECTION_TYPE(F) |
| 90 #undef F | 90 #undef F |
| 91 Max | 91 Max |
| 92 }; | 92 }; |
| 93 static WasmSection::Code begin(); | 93 static WasmSection::Code begin(); |
| 94 static WasmSection::Code end(); | 94 static WasmSection::Code end(); |
| 95 static WasmSection::Code next(WasmSection::Code code); | 95 static WasmSection::Code next(WasmSection::Code code); |
| 96 static const char* getName(Code code); | 96 static const char* getName(Code code); |
| 97 static int getOrder(Code code); |
| 97 static size_t getNameLength(Code code); | 98 static size_t getNameLength(Code code); |
| 99 static WasmSection::Code lookup(const byte* string, uint32_t length); |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 enum WasmFunctionDeclBit { | 102 enum WasmFunctionDeclBit { |
| 101 kDeclFunctionName = 0x01, | 103 kDeclFunctionName = 0x01, |
| 102 kDeclFunctionImport = 0x02, | 104 kDeclFunctionImport = 0x02, |
| 103 kDeclFunctionLocals = 0x04, | 105 kDeclFunctionLocals = 0x04, |
| 104 kDeclFunctionExport = 0x08 | 106 kDeclFunctionExport = 0x08 |
| 105 }; | 107 }; |
| 106 | 108 |
| 107 // Constants for fixed-size elements within a module. | 109 // Constants for fixed-size elements within a module. |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 318 |
| 317 // For testing. Decode, verify, and run the last exported function in the | 319 // For testing. Decode, verify, and run the last exported function in the |
| 318 // given decoded module. | 320 // given decoded module. |
| 319 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); | 321 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); |
| 320 | 322 |
| 321 } // namespace wasm | 323 } // namespace wasm |
| 322 } // namespace internal | 324 } // namespace internal |
| 323 } // namespace v8 | 325 } // namespace v8 |
| 324 | 326 |
| 325 #endif // V8_WASM_MODULE_H_ | 327 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |