MLIR  22.0.0git
WasmBinaryEncoding.h
Go to the documentation of this file.
1 //===- WasmBinaryEncoding.h - Byte encodings for Wasm binary format ===----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 // Define various flags used to encode instructions, types, etc. in
8 // WebAssembly binary format.
9 //
10 // These encodings are defined in the WebAssembly binary format specification.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef MLIR_TARGET_WASMBINARYENCODING
14 #define MLIR_TARGET_WASMBINARYENCODING
15 
16 #include <cstddef>
17 
18 namespace mlir {
20  /// Byte encodings for Wasm instructions.
21  struct OpCode {
22  // Locals, globals, constants.
23  static constexpr std::byte localGet{0x20};
24  static constexpr std::byte localSet{0x21};
25  static constexpr std::byte localTee{0x22};
26  static constexpr std::byte globalGet{0x23};
27  static constexpr std::byte constI32{0x41};
28  static constexpr std::byte constI64{0x42};
29  static constexpr std::byte constFP32{0x43};
30  static constexpr std::byte constFP64{0x44};
31 
32  // Numeric operations.
33  static constexpr std::byte clzI32{0x67};
34  static constexpr std::byte ctzI32{0x68};
35  static constexpr std::byte popcntI32{0x69};
36  static constexpr std::byte addI32{0x6A};
37  static constexpr std::byte subI32{0x6B};
38  static constexpr std::byte mulI32{0x6C};
39  static constexpr std::byte divSI32{0x6d};
40  static constexpr std::byte divUI32{0x6e};
41  static constexpr std::byte remSI32{0x6f};
42  static constexpr std::byte remUI32{0x70};
43  static constexpr std::byte andI32{0x71};
44  static constexpr std::byte orI32{0x72};
45  static constexpr std::byte xorI32{0x73};
46  static constexpr std::byte shlI32{0x74};
47  static constexpr std::byte shrSI32{0x75};
48  static constexpr std::byte shrUI32{0x76};
49  static constexpr std::byte rotlI32{0x77};
50  static constexpr std::byte rotrI32{0x78};
51  static constexpr std::byte clzI64{0x79};
52  static constexpr std::byte ctzI64{0x7A};
53  static constexpr std::byte popcntI64{0x7B};
54  static constexpr std::byte addI64{0x7C};
55  static constexpr std::byte subI64{0x7D};
56  static constexpr std::byte mulI64{0x7E};
57  static constexpr std::byte divSI64{0x7F};
58  static constexpr std::byte divUI64{0x80};
59  static constexpr std::byte remSI64{0x81};
60  static constexpr std::byte remUI64{0x82};
61  static constexpr std::byte andI64{0x83};
62  static constexpr std::byte orI64{0x84};
63  static constexpr std::byte xorI64{0x85};
64  static constexpr std::byte shlI64{0x86};
65  static constexpr std::byte shrSI64{0x87};
66  static constexpr std::byte shrUI64{0x88};
67  static constexpr std::byte rotlI64{0x89};
68  static constexpr std::byte rotrI64{0x8A};
69  static constexpr std::byte absF32{0x8B};
70  static constexpr std::byte negF32{0x8C};
71  static constexpr std::byte ceilF32{0x8D};
72  static constexpr std::byte floorF32{0x8E};
73  static constexpr std::byte truncF32{0x8F};
74  static constexpr std::byte sqrtF32{0x91};
75  static constexpr std::byte addF32{0x92};
76  static constexpr std::byte subF32{0x93};
77  static constexpr std::byte mulF32{0x94};
78  static constexpr std::byte divF32{0x95};
79  static constexpr std::byte minF32{0x96};
80  static constexpr std::byte maxF32{0x97};
81  static constexpr std::byte copysignF32{0x98};
82  static constexpr std::byte absF64{0x99};
83  static constexpr std::byte negF64{0x9A};
84  static constexpr std::byte ceilF64{0x9B};
85  static constexpr std::byte floorF64{0x9C};
86  static constexpr std::byte truncF64{0x9D};
87  static constexpr std::byte sqrtF64{0x9F};
88  static constexpr std::byte addF64{0xA0};
89  static constexpr std::byte subF64{0xA1};
90  static constexpr std::byte mulF64{0xA2};
91  static constexpr std::byte divF64{0xA3};
92  static constexpr std::byte minF64{0xA4};
93  static constexpr std::byte maxF64{0xA5};
94  static constexpr std::byte copysignF64{0xA6};
95  static constexpr std::byte wrap{0xA7};
96  };
97 
98  /// Byte encodings of types in Wasm binaries
99  struct Type {
100  static constexpr std::byte emptyBlockType{0x40};
101  static constexpr std::byte funcType{0x60};
102  static constexpr std::byte externRef{0x6F};
103  static constexpr std::byte funcRef{0x70};
104  static constexpr std::byte v128{0x7B};
105  static constexpr std::byte f64{0x7C};
106  static constexpr std::byte f32{0x7D};
107  static constexpr std::byte i64{0x7E};
108  static constexpr std::byte i32{0x7F};
109  };
110 
111  /// Byte encodings of Wasm imports.
112  struct Import {
113  static constexpr std::byte typeID{0x00};
114  static constexpr std::byte tableType{0x01};
115  static constexpr std::byte memType{0x02};
116  static constexpr std::byte globalType{0x03};
117  };
118 
119  /// Byte encodings for Wasm limits.
120  struct LimitHeader {
121  static constexpr std::byte lowLimitOnly{0x00};
122  static constexpr std::byte bothLimits{0x01};
123  };
124 
125  /// Byte encodings describing the mutability of globals.
127  static constexpr std::byte isConst{0x00};
128  static constexpr std::byte isMutable{0x01};
129  };
130 
131  /// Byte encodings describing Wasm exports.
132  struct Export {
133  static constexpr std::byte function{0x00};
134  static constexpr std::byte table{0x01};
135  static constexpr std::byte memory{0x02};
136  static constexpr std::byte global{0x03};
137  };
138 
139  static constexpr std::byte endByte{0x0B};
140 };
141 } // namespace mlir
142 
143 #endif
Include the generated interface declarations.
Byte encodings describing Wasm exports.
static constexpr std::byte memory
static constexpr std::byte table
static constexpr std::byte global
Byte encodings describing the mutability of globals.
Byte encodings of Wasm imports.
static constexpr std::byte memType
static constexpr std::byte typeID
static constexpr std::byte tableType
static constexpr std::byte globalType
Byte encodings for Wasm limits.
static constexpr std::byte lowLimitOnly
static constexpr std::byte bothLimits
Byte encodings for Wasm instructions.
static constexpr std::byte ctzI64
static constexpr std::byte andI64
static constexpr std::byte shlI32
static constexpr std::byte mulF32
static constexpr std::byte rotlI32
static constexpr std::byte ceilF32
static constexpr std::byte addF32
static constexpr std::byte divF64
static constexpr std::byte divUI64
static constexpr std::byte maxF64
static constexpr std::byte truncF32
static constexpr std::byte sqrtF32
static constexpr std::byte subF64
static constexpr std::byte addI64
static constexpr std::byte shrSI32
static constexpr std::byte rotrI64
static constexpr std::byte orI64
static constexpr std::byte divSI32
static constexpr std::byte minF32
static constexpr std::byte globalGet
static constexpr std::byte absF64
static constexpr std::byte truncF64
static constexpr std::byte rotlI64
static constexpr std::byte negF64
static constexpr std::byte popcntI32
static constexpr std::byte orI32
static constexpr std::byte xorI32
static constexpr std::byte divSI64
static constexpr std::byte divUI32
static constexpr std::byte divF32
static constexpr std::byte shrUI32
static constexpr std::byte shrUI64
static constexpr std::byte copysignF64
static constexpr std::byte rotrI32
static constexpr std::byte copysignF32
static constexpr std::byte clzI64
static constexpr std::byte remUI64
static constexpr std::byte andI32
static constexpr std::byte subF32
static constexpr std::byte ctzI32
static constexpr std::byte constI64
static constexpr std::byte subI64
static constexpr std::byte subI32
static constexpr std::byte constFP64
static constexpr std::byte mulI64
static constexpr std::byte localTee
static constexpr std::byte absF32
static constexpr std::byte addI32
static constexpr std::byte floorF64
static constexpr std::byte localGet
static constexpr std::byte clzI32
static constexpr std::byte localSet
static constexpr std::byte sqrtF64
static constexpr std::byte constI32
static constexpr std::byte remSI32
static constexpr std::byte shrSI64
static constexpr std::byte negF32
static constexpr std::byte mulI32
static constexpr std::byte constFP32
static constexpr std::byte xorI64
static constexpr std::byte popcntI64
static constexpr std::byte shlI64
static constexpr std::byte wrap
static constexpr std::byte maxF32
static constexpr std::byte mulF64
static constexpr std::byte remSI64
static constexpr std::byte ceilF64
static constexpr std::byte remUI32
static constexpr std::byte minF64
static constexpr std::byte floorF32
static constexpr std::byte addF64
Byte encodings of types in Wasm binaries.
static constexpr std::byte externRef
static constexpr std::byte i32
static constexpr std::byte funcType
static constexpr std::byte i64
static constexpr std::byte emptyBlockType
static constexpr std::byte funcRef
static constexpr std::byte v128
static constexpr std::byte f64
static constexpr std::byte f32
static constexpr std::byte endByte