Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: src/wasm/wasm-module.h

Issue 1765843002: wasm: use strings for section names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix some encoding. A few tests still fail. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
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, string).
32 #define FOR_EACH_WASM_SECTION_TYPE(F) \ 32 #define FOR_EACH_WASM_SECTION_TYPE(F) \
33 F(kDeclMemory, "memory") \ 33 F(Memory, "memory") \
34 F(kDeclSignatures, "signatures") \ 34 F(Signatures, "signatures") \
35 F(kDeclFunctions, "functions") \ 35 F(Functions, "functions") \
36 F(kDeclGlobals, "globals") \ 36 F(Globals, "globals") \
37 F(kDeclDataSegments, "data_segments") \ 37 F(DataSegments, "data_segments") \
38 F(kDeclFunctionTable, "function_table") \ 38 F(FunctionTable, "function_table") \
39 F(kDeclEnd, "end") \ 39 F(End, "end") \
40 F(kDeclStartFunction, "start_function") \ 40 F(StartFunction, "start_function") \
41 F(kDeclImportTable, "import_table") \ 41 F(ImportTable, "import_table") \
42 F(kDeclExportTable, "export_table") 42 F(ExportTable, "export_table")
43 43
44 enum WasmSectionDeclCode : uint32_t { 44 // Contants for the above section types: {LEB128 length, characters...}.
45 #define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y'
46 #define WASM_SECTION_SIGNATURES \
47 10, 's', 'i', 'g', 'n', 'a', 't', 'u', 'r', 'e', 's'
48 #define WASM_SECTION_FUNCTIONS 9, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 's'
49 #define WASM_SECTION_GLOBALS 7, 'g', 'l', 'o', 'b', 'a', 'l', 's'
50 #define WASM_SECTION_DATA_SEGMENTS \
51 13, 'd', 'a', 't', 'a', '_', 's', 'e', 'g', 'm', 'e', 'n', 't', 's'
52 #define WASM_SECTION_FUNCTION_TABLE \
53 14, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', '_', 't', 'a', 'b', 'l', 'e'
54 #define WASM_SECTION_END 3, 'e', 'n', 'd'
55 #define WASM_SECTION_START_FUNCTION \
56 14, 's', 't', 'a', 'r', 't', '_', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n'
57 #define WASM_SECTION_IMPORT_TABLE \
58 12, 'i', 'm', 'p', 'o', 'r', 't', '_', 't', 'a', 'b', 'l', 'e'
59 #define WASM_SECTION_EXPORT_TABLE \
60 12, 'e', 'x', 'p', 'o', 'r', 't', '_', 't', 'a', 'b', 'l', 'e'
61
62 // Constants for the above section headers' size (LEB128 + characters).
63 #define WASM_SECTION_MEMORY_SIZE ((size_t)7)
64 #define WASM_SECTION_SIGNATURES_SIZE ((size_t)11)
65 #define WASM_SECTION_FUNCTIONS_SIZE ((size_t)10)
66 #define WASM_SECTION_GLOBALS_SIZE ((size_t)8)
67 #define WASM_SECTION_DATA_SEGMENTS_SIZE ((size_t)14)
68 #define WASM_SECTION_FUNCTION_TABLE_SIZE ((size_t)15)
69 #define WASM_SECTION_END_SIZE ((size_t)4)
70 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)15)
71 #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)13)
72 #define WASM_SECTION_EXPORT_TABLE_SIZE ((size_t)13)
73
74 struct WasmSection {
75 enum class Code : uint32_t {
45 #define F(enumerator, string) enumerator, 76 #define F(enumerator, string) enumerator,
46 FOR_EACH_WASM_SECTION_TYPE(F) 77 FOR_EACH_WASM_SECTION_TYPE(F)
47 #undef F 78 #undef F
48 kMaxModuleSectionCode 79 Max
80 };
81 static WasmSection::Code begin();
82 static WasmSection::Code end();
83 static WasmSection::Code next(WasmSection::Code code);
84 static const char* getName(Code code);
85 static size_t getNameLength(Code code);
49 }; 86 };
50 87
51 enum WasmFunctionDeclBit { 88 enum WasmFunctionDeclBit {
52 kDeclFunctionName = 0x01, 89 kDeclFunctionName = 0x01,
53 kDeclFunctionImport = 0x02, 90 kDeclFunctionImport = 0x02,
54 kDeclFunctionLocals = 0x04, 91 kDeclFunctionLocals = 0x04,
55 kDeclFunctionExport = 0x08 92 kDeclFunctionExport = 0x08
56 }; 93 };
57 94
58 // Constants for fixed-size elements within a module. 95 // Constants for fixed-size elements within a module.
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 293
257 // For testing. Decode, verify, and run the last exported function in the 294 // For testing. Decode, verify, and run the last exported function in the
258 // given decoded module. 295 // given decoded module.
259 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); 296 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module);
260 297
261 } // namespace wasm 298 } // namespace wasm
262 } // namespace internal 299 } // namespace internal
263 } // namespace v8 300 } // namespace v8
264 301
265 #endif // V8_WASM_MODULE_H_ 302 #endif // V8_WASM_MODULE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698