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