• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/common/globals.h"
12 
13 namespace v8 {
14 namespace internal {
15 namespace wasm {
16 
17 // Binary encoding of the module header.
18 constexpr uint32_t kWasmMagic = 0x6d736100;
19 constexpr uint32_t kWasmVersion = 0x01;
20 
21 // Binary encoding of value and heap types.
22 enum ValueTypeCode : uint8_t {
23   // Current wasm types
24   kVoidCode = 0x40,
25   kI32Code = 0x7f,
26   kI64Code = 0x7e,
27   kF32Code = 0x7d,
28   kF64Code = 0x7c,
29   // Simd proposal
30   kS128Code = 0x7b,
31   // reftypes, typed-funcref, and GC proposals
32   kI8Code = 0x7a,
33   kI16Code = 0x79,
34   kFuncRefCode = 0x70,
35   kExternRefCode = 0x6f,
36   // kAnyCode = 0x6e, // TODO(7748): Implement
37   kEqRefCode = 0x6d,
38   kOptRefCode = 0x6c,
39   kRefCode = 0x6b,
40   kI31RefCode = 0x6a,
41   kRttCode = 0x69,
42   // Exception handling proposal
43   kExnRefCode = 0x68,
44 };
45 // Binary encoding of other types.
46 constexpr uint8_t kWasmFunctionTypeCode = 0x60;
47 constexpr uint8_t kWasmStructTypeCode = 0x5f;
48 constexpr uint8_t kWasmArrayTypeCode = 0x5e;
49 
50 // Binary encoding of import/export kinds.
51 enum ImportExportKindCode : uint8_t {
52   kExternalFunction = 0,
53   kExternalTable = 1,
54   kExternalMemory = 2,
55   kExternalGlobal = 3,
56   kExternalException = 4
57 };
58 
59 enum LimitsFlags : uint8_t {
60   kNoMaximum = 0x00,           // Also valid for table limits.
61   kWithMaximum = 0x01,         // Also valid for table limits.
62   kSharedNoMaximum = 0x02,     // Only valid for memory limits.
63   kSharedWithMaximum = 0x03,   // Only valid for memory limits.
64   kMemory64NoMaximum = 0x04,   // Only valid for memory limits.
65   kMemory64WithMaximum = 0x05  // Only valid for memory limits.
66 };
67 
68 // Flags for data and element segments.
69 enum SegmentFlags : uint8_t {
70   kActiveNoIndex = 0,    // Active segment with a memory/table index of zero.
71   kPassive = 1,          // Passive segment.
72   kActiveWithIndex = 2,  // Active segment with a given memory/table index.
73 };
74 
75 // Binary encoding of sections identifiers.
76 enum SectionCode : int8_t {
77   kUnknownSectionCode = 0,     // code for unknown sections
78   kTypeSectionCode = 1,        // Function signature declarations
79   kImportSectionCode = 2,      // Import declarations
80   kFunctionSectionCode = 3,    // Function declarations
81   kTableSectionCode = 4,       // Indirect function table and others
82   kMemorySectionCode = 5,      // Memory attributes
83   kGlobalSectionCode = 6,      // Global declarations
84   kExportSectionCode = 7,      // Exports
85   kStartSectionCode = 8,       // Start function declaration
86   kElementSectionCode = 9,     // Elements section
87   kCodeSectionCode = 10,       // Function code
88   kDataSectionCode = 11,       // Data segments
89   kDataCountSectionCode = 12,  // Number of data segments
90   kExceptionSectionCode = 13,  // Exception section
91 
92   // The following sections are custom sections, and are identified using a
93   // string rather than an integer. Their enumeration values are not guaranteed
94   // to be consistent.
95   kNameSectionCode,               // Name section (encoded as a string)
96   kSourceMappingURLSectionCode,   // Source Map URL section
97   kDebugInfoSectionCode,          // DWARF section .debug_info
98   kExternalDebugInfoSectionCode,  // Section encoding the external symbol path
99   kCompilationHintsSectionCode,   // Compilation hints section
100 
101   // Helper values
102   kFirstSectionInModule = kTypeSectionCode,
103   kLastKnownModuleSection = kCompilationHintsSectionCode,
104   kFirstUnorderedSection = kDataCountSectionCode,
105 };
106 
107 // Binary encoding of compilation hints.
108 constexpr uint8_t kDefaultCompilationHint = 0x0;
109 constexpr uint8_t kNoCompilationHint = kMaxUInt8;
110 
111 // Binary encoding of name section kinds.
112 enum NameSectionKindCode : uint8_t { kModule = 0, kFunction = 1, kLocal = 2 };
113 
114 constexpr size_t kWasmPageSize = 0x10000;
115 constexpr uint32_t kWasmPageSizeLog2 = 16;
116 static_assert(kWasmPageSize == size_t{1} << kWasmPageSizeLog2, "consistency");
117 
118 // TODO(wasm): Wrap WasmCodePosition in a struct.
119 using WasmCodePosition = int;
120 constexpr WasmCodePosition kNoCodePosition = -1;
121 
122 constexpr uint32_t kExceptionAttribute = 0;
123 
124 constexpr int kAnonymousFuncIndex = -1;
125 
126 // The number of calls to an exported wasm function that will be handled
127 // by the generic wrapper. Once this threshold is reached, a specific wrapper
128 // is to be compiled for the function's signature.
129 constexpr uint32_t kGenericWrapperThreshold = 6;
130 
131 }  // namespace wasm
132 }  // namespace internal
133 }  // namespace v8
134 
135 #endif  // V8_WASM_WASM_CONSTANTS_H_
136