V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
wasm-constants.h
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_WASM_WASM_CONSTANTS_H_
6 #define V8_WASM_WASM_CONSTANTS_H_
7 
8 #include <cstddef>
9 #include <cstdint>
10 
11 namespace v8 {
12 namespace internal {
13 namespace wasm {
14 
15 // Binary encoding of the module header.
16 constexpr uint32_t kWasmMagic = 0x6d736100;
17 constexpr uint32_t kWasmVersion = 0x01;
18 
19 // Binary encoding of local types.
20 enum ValueTypeCode : uint8_t {
21  kLocalVoid = 0x40,
22  kLocalI32 = 0x7f,
23  kLocalI64 = 0x7e,
24  kLocalF32 = 0x7d,
25  kLocalF64 = 0x7c,
26  kLocalS128 = 0x7b,
27  kLocalAnyFunc = 0x70,
28  kLocalAnyRef = 0x6f,
29  kLocalExceptRef = 0x68,
30 };
31 // Binary encoding of other types.
32 constexpr uint8_t kWasmFunctionTypeCode = 0x60;
33 
34 // Binary encoding of import/export kinds.
35 enum ImportExportKindCode : uint8_t {
36  kExternalFunction = 0,
37  kExternalTable = 1,
38  kExternalMemory = 2,
39  kExternalGlobal = 3,
40  kExternalException = 4
41 };
42 
43 // Binary encoding of maximum and shared flags for memories.
44 enum MaximumFlag : uint8_t { kNoMaximumFlag = 0, kHasMaximumFlag = 1 };
45 
46 enum MemoryFlags : uint8_t {
47  kNoMaximum = 0,
48  kMaximum = 1,
49  kSharedNoMaximum = 2,
50  kSharedAndMaximum = 3
51 };
52 
53 // Flags for data and element segments.
54 enum SegmentFlags : uint8_t {
55  kActiveNoIndex = 0, // Active segment with a memory/table index of zero.
56  kPassive = 1, // Passive segment.
57  kActiveWithIndex = 2, // Active segment with a given memory/table index.
58 };
59 
60 // Binary encoding of sections identifiers.
61 enum SectionCode : int8_t {
62  kUnknownSectionCode = 0, // code for unknown sections
63  kTypeSectionCode = 1, // Function signature declarations
64  kImportSectionCode = 2, // Import declarations
65  kFunctionSectionCode = 3, // Function declarations
66  kTableSectionCode = 4, // Indirect function table and other tables
67  kMemorySectionCode = 5, // Memory attributes
68  kGlobalSectionCode = 6, // Global declarations
69  kExportSectionCode = 7, // Exports
70  kStartSectionCode = 8, // Start function declaration
71  kElementSectionCode = 9, // Elements section
72  kCodeSectionCode = 10, // Function code
73  kDataSectionCode = 11, // Data segments
74  kNameSectionCode = 12, // Name section (encoded as a string)
75  kExceptionSectionCode = 13, // Exception section
76  kSourceMappingURLSectionCode = 14, // Source Map URL section
77 
78  // Helper values
79  kFirstSectionInModule = kTypeSectionCode,
80  kLastKnownModuleSection = kSourceMappingURLSectionCode,
81  kFirstUnorderedSection = kNameSectionCode,
82 };
83 
84 // Binary encoding of name section kinds.
85 enum NameSectionKindCode : uint8_t { kModule = 0, kFunction = 1, kLocal = 2 };
86 
87 constexpr size_t kWasmPageSize = 0x10000;
88 constexpr uint32_t kWasmPageSizeLog2 = 16;
89 static_assert(kWasmPageSize == size_t{1} << kWasmPageSizeLog2, "consistency");
90 
91 // TODO(wasm): Wrap WasmCodePosition in a struct.
92 using WasmCodePosition = int;
93 constexpr WasmCodePosition kNoCodePosition = -1;
94 
95 constexpr uint32_t kExceptionAttribute = 0;
96 
97 } // namespace wasm
98 } // namespace internal
99 } // namespace v8
100 
101 #endif // V8_WASM_WASM_CONSTANTS_H_
Definition: libplatform.h:13