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

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: Silence compiler warning 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
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 F(kDeclFunctionSignatures, "function_signatures") \ 43 F(FunctionSignatures, "function_signatures") \
44 F(kDeclFunctionBodies, "function_bodies") \ 44 F(FunctionBodies, "function_bodies") \
45 F(kDeclNames, "names") 45 F(Names, "names")
46 46
47 enum WasmSectionDeclCode : uint32_t { 47 // Contants for the above section types: {LEB128 length, characters...}.
48 #define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y'
49 #define WASM_SECTION_SIGNATURES \
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'
52 #define WASM_SECTION_GLOBALS 7, 'g', 'l', 'o', 'b', 'a', 'l', 's'
53 #define WASM_SECTION_DATA_SEGMENTS \
54 13, 'd', 'a', 't', 'a', '_', 's', 'e', 'g', 'm', 'e', 'n', 't', 's'
55 #define WASM_SECTION_FUNCTION_TABLE \
56 14, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', '_', 't', 'a', 'b', 'l', 'e'
57 #define WASM_SECTION_END 3, 'e', 'n', 'd'
58 #define WASM_SECTION_START_FUNCTION \
59 14, 's', 't', 'a', 'r', 't', '_', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n'
60 #define WASM_SECTION_IMPORT_TABLE \
61 12, 'i', 'm', 'p', 'o', 'r', 't', '_', 't', 'a', 'b', 'l', 'e'
62 #define WASM_SECTION_EXPORT_TABLE \
63 12, 'e', 'x', 'p', 'o', 'r', 't', '_', 't', 'a', 'b', 'l', 'e'
64 #define WASM_SECTION_FUNCTION_SIGNATURES \
65 19, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', '_', 's', 'i', 'g', 'n', 'a', \
66 't', 'u', 'r', 'e', 's'
67 #define WASM_SECTION_FUNCTION_BODIES \
68 15, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', '_', 'b', 'o', 'd', 'i', 'e', 's'
69 #define WASM_SECTION_NAMES 5, 'n', 'a', 'm', 'e', 's'
70
71 // Constants for the above section headers' size (LEB128 + characters).
72 #define WASM_SECTION_MEMORY_SIZE ((size_t)7)
73 #define WASM_SECTION_SIGNATURES_SIZE ((size_t)11)
74 #define WASM_SECTION_FUNCTIONS_SIZE ((size_t)10)
75 #define WASM_SECTION_GLOBALS_SIZE ((size_t)8)
76 #define WASM_SECTION_DATA_SEGMENTS_SIZE ((size_t)14)
77 #define WASM_SECTION_FUNCTION_TABLE_SIZE ((size_t)15)
78 #define WASM_SECTION_END_SIZE ((size_t)4)
79 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)15)
80 #define WASM_SECTION_IMPORT_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)
83 #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)16)
84 #define WASM_SECTION_NAMES_SIZE ((size_t)6)
85
86 struct WasmSection {
87 enum class Code : uint32_t {
48 #define F(enumerator, string) enumerator, 88 #define F(enumerator, string) enumerator,
49 FOR_EACH_WASM_SECTION_TYPE(F) 89 FOR_EACH_WASM_SECTION_TYPE(F)
50 #undef F 90 #undef F
51 kMaxModuleSectionCode 91 Max
92 };
93 static WasmSection::Code begin();
94 static WasmSection::Code end();
95 static WasmSection::Code next(WasmSection::Code code);
96 static const char* getName(Code code);
97 static size_t getNameLength(Code code);
52 }; 98 };
53 99
54 enum WasmFunctionDeclBit { 100 enum WasmFunctionDeclBit {
55 kDeclFunctionName = 0x01, 101 kDeclFunctionName = 0x01,
56 kDeclFunctionImport = 0x02, 102 kDeclFunctionImport = 0x02,
57 kDeclFunctionLocals = 0x04, 103 kDeclFunctionLocals = 0x04,
58 kDeclFunctionExport = 0x08 104 kDeclFunctionExport = 0x08
59 }; 105 };
60 106
61 // Constants for fixed-size elements within a module. 107 // Constants for fixed-size elements within a module.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 316
271 // For testing. Decode, verify, and run the last exported function in the 317 // For testing. Decode, verify, and run the last exported function in the
272 // given decoded module. 318 // given decoded module.
273 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); 319 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module);
274 320
275 } // namespace wasm 321 } // namespace wasm
276 } // namespace internal 322 } // namespace internal
277 } // namespace v8 323 } // namespace v8
278 324
279 #endif // V8_WASM_MODULE_H_ 325 #endif // V8_WASM_MODULE_H_
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698