LLVM  4.0.0
Support/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_SUPPORT_WASM_H
16 #define LLVM_SUPPORT_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 = 0xd;
27 
31 };
32 
33 struct WasmSection {
34  uint32_t Type; // Section type (See below)
35  uint32_t Offset; // Offset with in the file
36  StringRef Name; // Section name (User-defined sections only)
37  ArrayRef<uint8_t> Content; // Section content
38 };
39 
40 enum : unsigned {
41  WASM_SEC_USER = 0, // User-defined section
42  WASM_SEC_TYPE = 1, // Function signature declarations
43  WASM_SEC_IMPORT = 2, // Import declarations
44  WASM_SEC_FUNCTION = 3, // Function declarations
45  WASM_SEC_TABLE = 4, // Indirect function table and other tables
46  WASM_SEC_MEMORY = 5, // Memory attributes
47  WASM_SEC_GLOBAL = 6, // Global declarations
48  WASM_SEC_EXPORT = 7, // Exports
49  WASM_SEC_START = 8, // Start function declaration
50  WASM_SEC_ELEM = 9, // Elements section
51  WASM_SEC_CODE = 10, // Function bodies (code)
52  WASM_SEC_DATA = 11 // Data segments
53 };
54 
55 // Type immediate encodings used in various contexts.
56 enum : unsigned {
57  WASM_TYPE_I32 = 0x7f,
58  WASM_TYPE_I64 = 0x7e,
59  WASM_TYPE_F32 = 0x7d,
60  WASM_TYPE_F64 = 0x7c,
63  WASM_TYPE_NORESULT = 0x40, // for blocks with no result values
64 };
65 
66 // Kinds of externals (for imports and exports).
67 enum : unsigned {
72 };
73 
74 // Opcodes used in initializer expressions.
75 enum : unsigned {
82 };
83 
84 } // end namespace wasm
85 } // end namespace llvm
86 
87 #endif
ArrayRef< uint8_t > Content
Definition: Support/Wasm.h:37
const uint32_t WasmVersion
Definition: Support/Wasm.h:26
const char WasmMagic[]
Definition: Support/Wasm.h:24
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47