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 namespace v8 {
9 namespace internal {
10 namespace wasm {
11 
12 // Binary encoding of the module header.
13 constexpr uint32_t kWasmMagic = 0x6d736100;
14 constexpr uint32_t kWasmVersion = 0x01;
15 
16 // Binary encoding of local types.
17 enum ValueTypeCode : uint8_t {
18   kLocalVoid = 0x40,
19   kLocalI32 = 0x7f,
20   kLocalI64 = 0x7e,
21   kLocalF32 = 0x7d,
22   kLocalF64 = 0x7c,
23   kLocalS128 = 0x7b,
24   kLocalAnyRef = 0x6f
25 };
26 // Binary encoding of other types.
27 constexpr uint8_t kWasmFunctionTypeCode = 0x60;
28 constexpr uint8_t kWasmAnyFunctionTypeCode = 0x70;
29 
30 // Binary encoding of import/export kinds.
31 enum ImportExportKindCode : uint8_t {
32   kExternalFunction = 0,
33   kExternalTable = 1,
34   kExternalMemory = 2,
35   kExternalGlobal = 3
36 };
37 
38 // Binary encoding of maximum and shared flags for memories.
39 enum MaximumFlag : uint8_t { kNoMaximumFlag = 0, kHasMaximumFlag = 1 };
40 
41 enum MemoryFlags : uint8_t {
42   kNoMaximum = 0,
43   kMaximum = 1,
44   kSharedNoMaximum = 2,
45   kSharedAndMaximum = 3
46 };
47 
48 // Binary encoding of sections identifiers.
49 enum SectionCode : int8_t {
50   kUnknownSectionCode = 0,     // code for unknown sections
51   kTypeSectionCode = 1,        // Function signature declarations
52   kImportSectionCode = 2,      // Import declarations
53   kFunctionSectionCode = 3,    // Function declarations
54   kTableSectionCode = 4,       // Indirect function table and other tables
55   kMemorySectionCode = 5,      // Memory attributes
56   kGlobalSectionCode = 6,      // Global declarations
57   kExportSectionCode = 7,      // Exports
58   kStartSectionCode = 8,       // Start function declaration
59   kElementSectionCode = 9,     // Elements section
60   kCodeSectionCode = 10,       // Function code
61   kDataSectionCode = 11,       // Data segments
62   kNameSectionCode = 12,       // Name section (encoded as a string)
63   kExceptionSectionCode = 13,  // Exception section
64 
65   // Helper values
66   kFirstSectionInModule = kTypeSectionCode,
67   kLastKnownModuleSection = kExceptionSectionCode,
68 };
69 
70 // Binary encoding of name section kinds.
71 enum NameSectionKindCode : uint8_t { kModule = 0, kFunction = 1, kLocal = 2 };
72 
73 constexpr uint32_t kWasmPageSize = 0x10000;
74 constexpr int kInvalidExceptionTag = -1;
75 
76 // TODO(wasm): Wrap WasmCodePosition in a struct.
77 using WasmCodePosition = int;
78 constexpr WasmCodePosition kNoCodePosition = -1;
79 
80 }  // namespace wasm
81 }  // namespace internal
82 }  // namespace v8
83 
84 #endif  // V8_WASM_WASM_CONSTANTS_H_
85