LLVM  7.0.0svn
Wasm.h
Go to the documentation of this file.
1 //===- Wasm.h - Wasm object file format -------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines manifest constants for the wasm object file format.
11 // See: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_BINARYFORMAT_WASM_H
16 #define LLVM_BINARYFORMAT_WASM_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 
20 namespace llvm {
21 namespace wasm {
22 
23 // Object file magic string.
24 const char WasmMagic[] = {'\0', 'a', 's', 'm'};
25 // Wasm binary format version
26 const uint32_t WasmVersion = 0x1;
27 // Wasm uses a 64k page size
28 const uint32_t WasmPageSize = 65536;
29 
33 };
34 
35 struct WasmSignature {
36  std::vector<int32_t> ParamTypes;
37  int32_t ReturnType;
38 };
39 
40 struct WasmExport {
44 };
45 
46 struct WasmLimits {
50 };
51 
52 struct WasmTable {
53  int32_t ElemType;
55 };
56 
57 struct WasmInitExpr {
58  uint8_t Opcode;
59  union {
60  int32_t Int32;
61  int64_t Int64;
62  int32_t Float32;
63  int64_t Float64;
65  } Value;
66 };
67 
68 struct WasmGlobal {
70  int32_t Type;
71  bool Mutable;
73 };
74 
75 struct WasmImport {
79  union {
84  };
85 };
86 
87 struct WasmLocalDecl {
88  int32_t Type;
90 };
91 
92 struct WasmFunction {
94  std::vector<WasmLocalDecl> Locals;
98  StringRef Name; // from the "names" section
99  StringRef Comdat; // from the "comdat info" section
100 };
101 
109  StringRef Comdat; // from the "comdat info" section
110 };
111 
115  std::vector<uint32_t> Functions;
116 };
117 
119  uint32_t Type; // The type of the relocation.
120  uint32_t Index; // Index into function or global index space.
121  uint64_t Offset; // Offset from the start of the section.
122  int64_t Addend; // A value to add to the symbol.
123 };
124 
125 struct WasmInitFunc {
128 };
129 
133 };
134 
137  std::vector<WasmInitFunc> InitFunctions;
138 };
139 
140 enum : unsigned {
141  WASM_SEC_CUSTOM = 0, // Custom / User-defined section
142  WASM_SEC_TYPE = 1, // Function signature declarations
143  WASM_SEC_IMPORT = 2, // Import declarations
144  WASM_SEC_FUNCTION = 3, // Function declarations
145  WASM_SEC_TABLE = 4, // Indirect function table and other tables
146  WASM_SEC_MEMORY = 5, // Memory attributes
147  WASM_SEC_GLOBAL = 6, // Global declarations
148  WASM_SEC_EXPORT = 7, // Exports
149  WASM_SEC_START = 8, // Start function declaration
150  WASM_SEC_ELEM = 9, // Elements section
151  WASM_SEC_CODE = 10, // Function bodies (code)
152  WASM_SEC_DATA = 11 // Data segments
153 };
154 
155 // Type immediate encodings used in various contexts.
156 enum {
157  WASM_TYPE_I32 = -0x01,
158  WASM_TYPE_I64 = -0x02,
159  WASM_TYPE_F32 = -0x03,
160  WASM_TYPE_F64 = -0x04,
162  WASM_TYPE_FUNC = -0x20,
163  WASM_TYPE_NORESULT = -0x40, // for blocks with no result values
164 };
165 
166 // Kinds of externals (for imports and exports).
167 enum : unsigned {
172 };
173 
174 // Opcodes used in initializer expressions.
175 enum : unsigned {
182 };
183 
184 enum : unsigned {
186 };
187 
188 // Subset of types that a value can have
189 enum class ValType {
190  I32 = WASM_TYPE_I32,
191  I64 = WASM_TYPE_I64,
192  F32 = WASM_TYPE_F32,
193  F64 = WASM_TYPE_F64,
194 };
195 
196 // Kind codes used in the custom "name" section
197 enum : unsigned {
200 };
201 
202 // Kind codes used in the custom "linking" section
203 enum : unsigned {
209 };
210 
211 // Kind codes used in the custom "linking" section in the WASM_COMDAT_INFO
212 enum : unsigned {
215 };
216 
217 const unsigned WASM_SYMBOL_BINDING_MASK = 0x3;
218 const unsigned WASM_SYMBOL_VISIBILITY_MASK = 0x4;
219 
220 const unsigned WASM_SYMBOL_BINDING_GLOBAL = 0x0;
221 const unsigned WASM_SYMBOL_BINDING_WEAK = 0x1;
222 const unsigned WASM_SYMBOL_BINDING_LOCAL = 0x2;
223 const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0;
224 const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4;
225 
226 #define WASM_RELOC(name, value) name = value,
227 
228 enum : unsigned {
229 #include "WasmRelocs.def"
230 };
231 
232 #undef WASM_RELOC
233 
234 struct Global {
236  bool Mutable;
237 
238  // The initial value for this global is either the value of an imported
239  // global, in which case InitialModule and InitialName specify the global
240  // import, or a value, in which case InitialModule is empty and InitialValue
241  // holds the value.
244  uint64_t InitialValue;
245 };
246 
247 } // end namespace wasm
248 } // end namespace llvm
249 
250 #endif
std::vector< WasmInitFunc > InitFunctions
Definition: Wasm.h:137
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
const unsigned WASM_SYMBOL_BINDING_LOCAL
Definition: Wasm.h:222
ValType Type
Definition: Wasm.h:235
StringRef InitialModule
Definition: Wasm.h:242
WasmTable Table
Definition: Wasm.h:82
StringRef Module
Definition: Wasm.h:76
const uint32_t WasmVersion
Definition: Wasm.h:26
ArrayRef< uint8_t > Content
Definition: Wasm.h:105
ArrayRef< uint8_t > Body
Definition: Wasm.h:95
uint32_t Initial
Definition: Wasm.h:48
const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT
Definition: Wasm.h:223
uint32_t SigIndex
Definition: Wasm.h:80
WasmLimits Memory
Definition: Wasm.h:83
std::vector< uint32_t > Functions
Definition: Wasm.h:115
uint32_t Kind
Definition: Wasm.h:78
const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN
Definition: Wasm.h:224
uint32_t Flags
Definition: Wasm.h:47
const unsigned WASM_SYMBOL_BINDING_WEAK
Definition: Wasm.h:221
uint32_t CodeSectionOffset
Definition: Wasm.h:96
StringRef Name
Definition: Wasm.h:98
WasmInitExpr Offset
Definition: Wasm.h:104
const unsigned WASM_SYMBOL_VISIBILITY_MASK
Definition: Wasm.h:218
uint32_t Kind
Definition: Wasm.h:42
const char WasmMagic[]
Definition: Wasm.h:24
WasmInitExpr InitExpr
Definition: Wasm.h:72
WasmGlobal Global
Definition: Wasm.h:81
const unsigned WASM_SYMBOL_BINDING_GLOBAL
Definition: Wasm.h:220
uint64_t InitialValue
Definition: Wasm.h:244
StringRef Comdat
Definition: Wasm.h:99
WasmLimits Limits
Definition: Wasm.h:54
const unsigned WASM_SYMBOL_BINDING_MASK
Definition: Wasm.h:217
int32_t ElemType
Definition: Wasm.h:53
StringRef InitialName
Definition: Wasm.h:243
uint32_t Index
Definition: Wasm.h:43
std::vector< int32_t > ParamTypes
Definition: Wasm.h:36
LLVM Value Representation.
Definition: Value.h:73
uint32_t Index
Definition: Wasm.h:69
StringRef Name
Definition: Wasm.h:41
const uint32_t WasmPageSize
Definition: Wasm.h:28
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
uint32_t FunctionIndex
Definition: Wasm.h:127
std::vector< WasmLocalDecl > Locals
Definition: Wasm.h:94
WasmInitExpr Offset
Definition: Wasm.h:114
uint32_t Maximum
Definition: Wasm.h:49
StringRef Field
Definition: Wasm.h:77