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
18namespace mlir {
20 /// Byte encodings for Wasm instructions.
21 struct OpCode {
22 // Control instructions.
23 static constexpr std::byte block{0x02};
24 static constexpr std::byte loop{0x03};
25 static constexpr std::byte ifOpCode{0x04};
26 static constexpr std::byte elseOpCode{0x05};
27 static constexpr std::byte branchIf{0x0D};
28 static constexpr std::byte call{0x10};
29
30 // Locals, globals, constants.
31 static constexpr std::byte localGet{0x20};
32 static constexpr std::byte localSet{0x21};
33 static constexpr std::byte localTee{0x22};
34 static constexpr std::byte globalGet{0x23};
35 static constexpr std::byte constI32{0x41};
36 static constexpr std::byte constI64{0x42};
37 static constexpr std::byte constFP32{0x43};
38 static constexpr std::byte constFP64{0x44};
39
40 // Comparisons.
41 static constexpr std::byte eqzI32{0x45};
42 static constexpr std::byte eqI32{0x46};
43 static constexpr std::byte neI32{0x47};
44 static constexpr std::byte ltSI32{0x48};
45 static constexpr std::byte ltUI32{0x49};
46 static constexpr std::byte gtSI32{0x4A};
47 static constexpr std::byte gtUI32{0x4B};
48 static constexpr std::byte leSI32{0x4C};
49 static constexpr std::byte leUI32{0x4D};
50 static constexpr std::byte geSI32{0x4E};
51 static constexpr std::byte geUI32{0x4F};
52 static constexpr std::byte eqzI64{0x50};
53 static constexpr std::byte eqI64{0x51};
54 static constexpr std::byte neI64{0x52};
55 static constexpr std::byte ltSI64{0x53};
56 static constexpr std::byte ltUI64{0x54};
57 static constexpr std::byte gtSI64{0x55};
58 static constexpr std::byte gtUI64{0x56};
59 static constexpr std::byte leSI64{0x57};
60 static constexpr std::byte leUI64{0x58};
61 static constexpr std::byte geSI64{0x59};
62 static constexpr std::byte geUI64{0x5A};
63 static constexpr std::byte eqF32{0x5B};
64 static constexpr std::byte neF32{0x5C};
65 static constexpr std::byte ltF32{0x5D};
66 static constexpr std::byte gtF32{0x5E};
67 static constexpr std::byte leF32{0x5F};
68 static constexpr std::byte geF32{0x60};
69 static constexpr std::byte eqF64{0x61};
70 static constexpr std::byte neF64{0x62};
71 static constexpr std::byte ltF64{0x63};
72 static constexpr std::byte gtF64{0x64};
73 static constexpr std::byte leF64{0x65};
74 static constexpr std::byte geF64{0x66};
75
76 // Numeric operations.
77 static constexpr std::byte clzI32{0x67};
78 static constexpr std::byte ctzI32{0x68};
79 static constexpr std::byte popcntI32{0x69};
80 static constexpr std::byte addI32{0x6A};
81 static constexpr std::byte subI32{0x6B};
82 static constexpr std::byte mulI32{0x6C};
83 static constexpr std::byte divSI32{0x6d};
84 static constexpr std::byte divUI32{0x6e};
85 static constexpr std::byte remSI32{0x6f};
86 static constexpr std::byte remUI32{0x70};
87 static constexpr std::byte andI32{0x71};
88 static constexpr std::byte orI32{0x72};
89 static constexpr std::byte xorI32{0x73};
90 static constexpr std::byte shlI32{0x74};
91 static constexpr std::byte shrSI32{0x75};
92 static constexpr std::byte shrUI32{0x76};
93 static constexpr std::byte rotlI32{0x77};
94 static constexpr std::byte rotrI32{0x78};
95 static constexpr std::byte clzI64{0x79};
96 static constexpr std::byte ctzI64{0x7A};
97 static constexpr std::byte popcntI64{0x7B};
98 static constexpr std::byte addI64{0x7C};
99 static constexpr std::byte subI64{0x7D};
100 static constexpr std::byte mulI64{0x7E};
101 static constexpr std::byte divSI64{0x7F};
102 static constexpr std::byte divUI64{0x80};
103 static constexpr std::byte remSI64{0x81};
104 static constexpr std::byte remUI64{0x82};
105 static constexpr std::byte andI64{0x83};
106 static constexpr std::byte orI64{0x84};
107 static constexpr std::byte xorI64{0x85};
108 static constexpr std::byte shlI64{0x86};
109 static constexpr std::byte shrSI64{0x87};
110 static constexpr std::byte shrUI64{0x88};
111 static constexpr std::byte rotlI64{0x89};
112 static constexpr std::byte rotrI64{0x8A};
113 static constexpr std::byte absF32{0x8B};
114 static constexpr std::byte negF32{0x8C};
115 static constexpr std::byte ceilF32{0x8D};
116 static constexpr std::byte floorF32{0x8E};
117 static constexpr std::byte truncF32{0x8F};
118 static constexpr std::byte sqrtF32{0x91};
119 static constexpr std::byte addF32{0x92};
120 static constexpr std::byte subF32{0x93};
121 static constexpr std::byte mulF32{0x94};
122 static constexpr std::byte divF32{0x95};
123 static constexpr std::byte minF32{0x96};
124 static constexpr std::byte maxF32{0x97};
125 static constexpr std::byte copysignF32{0x98};
126 static constexpr std::byte absF64{0x99};
127 static constexpr std::byte negF64{0x9A};
128 static constexpr std::byte ceilF64{0x9B};
129 static constexpr std::byte floorF64{0x9C};
130 static constexpr std::byte truncF64{0x9D};
131 static constexpr std::byte sqrtF64{0x9F};
132 static constexpr std::byte addF64{0xA0};
133 static constexpr std::byte subF64{0xA1};
134 static constexpr std::byte mulF64{0xA2};
135 static constexpr std::byte divF64{0xA3};
136 static constexpr std::byte minF64{0xA4};
137 static constexpr std::byte maxF64{0xA5};
138 static constexpr std::byte copysignF64{0xA6};
139 static constexpr std::byte wrap{0xA7};
140
141 // Conversion operations
142 static constexpr std::byte extendS{0xAC};
143 static constexpr std::byte extendU{0xAD};
144 static constexpr std::byte convertSI32F32{0xB2};
145 static constexpr std::byte convertUI32F32{0xB3};
146 static constexpr std::byte convertSI64F32{0xB4};
147 static constexpr std::byte convertUI64F32{0xB5};
148
149 static constexpr std::byte demoteF64ToF32{0xB6};
150
151 static constexpr std::byte convertSI32F64{0xB7};
152 static constexpr std::byte convertUI32F64{0xB8};
153 static constexpr std::byte convertSI64F64{0xB9};
154 static constexpr std::byte convertUI64F64{0xBA};
155
156 static constexpr std::byte promoteF32ToF64{0xBB};
157 static constexpr std::byte reinterpretF32AsI32{0xBC};
158 static constexpr std::byte reinterpretF64AsI64{0xBD};
159 static constexpr std::byte reinterpretI32AsF32{0xBE};
160 static constexpr std::byte reinterpretI64AsF64{0xBF};
161
162 static constexpr std::byte extendI328S{0xC0};
163 static constexpr std::byte extendI3216S{0xC1};
164 static constexpr std::byte extendI648S{0xC2};
165 static constexpr std::byte extendI6416S{0xC3};
166 static constexpr std::byte extendI6432S{0xC4};
167 };
168
169 /// Byte encodings of types in Wasm binaries
170 struct Type {
171 static constexpr std::byte emptyBlockType{0x40};
172 static constexpr std::byte funcType{0x60};
173 static constexpr std::byte externRef{0x6F};
174 static constexpr std::byte funcRef{0x70};
175 static constexpr std::byte v128{0x7B};
176 static constexpr std::byte f64{0x7C};
177 static constexpr std::byte f32{0x7D};
178 static constexpr std::byte i64{0x7E};
179 static constexpr std::byte i32{0x7F};
180 };
181
182 /// Byte encodings of Wasm imports.
183 struct Import {
184 static constexpr std::byte typeID{0x00};
185 static constexpr std::byte tableType{0x01};
186 static constexpr std::byte memType{0x02};
187 static constexpr std::byte globalType{0x03};
188 };
189
190 /// Byte encodings for Wasm limits.
191 struct LimitHeader {
192 static constexpr std::byte lowLimitOnly{0x00};
193 static constexpr std::byte bothLimits{0x01};
194 };
195
196 /// Byte encodings describing the mutability of globals.
198 static constexpr std::byte isConst{0x00};
199 static constexpr std::byte isMutable{0x01};
200 };
201
202 /// Byte encodings describing Wasm exports.
203 struct Export {
204 static constexpr std::byte function{0x00};
205 static constexpr std::byte table{0x01};
206 static constexpr std::byte memory{0x02};
207 static constexpr std::byte global{0x03};
208 };
209
210 static constexpr std::byte endByte{0x0B};
211};
212} // namespace mlir
213
214#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
static constexpr std::byte function
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
Byte encodings for Wasm instructions.
static constexpr std::byte neF32
static constexpr std::byte extendI3216S
static constexpr std::byte gtSI32
static constexpr std::byte ctzI64
static constexpr std::byte neI64
static constexpr std::byte geSI32
static constexpr std::byte convertSI64F32
static constexpr std::byte andI64
static constexpr std::byte shlI32
static constexpr std::byte mulF32
static constexpr std::byte convertSI32F64
static constexpr std::byte rotlI32
static constexpr std::byte ceilF32
static constexpr std::byte addF32
static constexpr std::byte ltSI32
static constexpr std::byte divF64
static constexpr std::byte divUI64
static constexpr std::byte maxF64
static constexpr std::byte geUI64
static constexpr std::byte truncF32
static constexpr std::byte sqrtF32
static constexpr std::byte leUI32
static constexpr std::byte subF64
static constexpr std::byte neI32
static constexpr std::byte addI64
static constexpr std::byte extendI328S
static constexpr std::byte gtF32
static constexpr std::byte shrSI32
static constexpr std::byte geUI32
static constexpr std::byte reinterpretF64AsI64
static constexpr std::byte rotrI64
static constexpr std::byte orI64
static constexpr std::byte divSI32
static constexpr std::byte minF32
static constexpr std::byte eqzI64
static constexpr std::byte globalGet
static constexpr std::byte absF64
static constexpr std::byte elseOpCode
static constexpr std::byte leSI64
static constexpr std::byte promoteF32ToF64
static constexpr std::byte ltUI32
static constexpr std::byte eqzI32
static constexpr std::byte truncF64
static constexpr std::byte rotlI64
static constexpr std::byte negF64
static constexpr std::byte popcntI32
static constexpr std::byte ltF32
static constexpr std::byte convertSI64F64
static constexpr std::byte extendU
static constexpr std::byte extendI648S
static constexpr std::byte orI32
static constexpr std::byte eqI64
static constexpr std::byte xorI32
static constexpr std::byte reinterpretI32AsF32
static constexpr std::byte divSI64
static constexpr std::byte divUI32
static constexpr std::byte neF64
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 eqF32
static constexpr std::byte copysignF32
static constexpr std::byte clzI64
static constexpr std::byte gtUI32
static constexpr std::byte geF64
static constexpr std::byte remUI64
static constexpr std::byte convertUI32F32
static constexpr std::byte andI32
static constexpr std::byte subF32
static constexpr std::byte ctzI32
static constexpr std::byte demoteF64ToF32
static constexpr std::byte constI64
static constexpr std::byte leF32
static constexpr std::byte extendI6416S
static constexpr std::byte subI64
static constexpr std::byte leSI32
static constexpr std::byte subI32
static constexpr std::byte constFP64
static constexpr std::byte mulI64
static constexpr std::byte localTee
static constexpr std::byte ifOpCode
static constexpr std::byte block
static constexpr std::byte convertUI32F64
static constexpr std::byte absF32
static constexpr std::byte addI32
static constexpr std::byte ltSI64
static constexpr std::byte convertUI64F32
static constexpr std::byte floorF64
static constexpr std::byte call
static constexpr std::byte convertUI64F64
static constexpr std::byte gtUI64
static constexpr std::byte localGet
static constexpr std::byte clzI32
static constexpr std::byte eqF64
static constexpr std::byte extendI6432S
static constexpr std::byte extendS
static constexpr std::byte branchIf
static constexpr std::byte localSet
static constexpr std::byte ltF64
static constexpr std::byte sqrtF64
static constexpr std::byte loop
static constexpr std::byte gtF64
static constexpr std::byte reinterpretF32AsI32
static constexpr std::byte gtSI64
static constexpr std::byte constI32
static constexpr std::byte remSI32
static constexpr std::byte geSI64
static constexpr std::byte shrSI64
static constexpr std::byte negF32
static constexpr std::byte ltUI64
static constexpr std::byte mulI32
static constexpr std::byte reinterpretI64AsF64
static constexpr std::byte constFP32
static constexpr std::byte xorI64
static constexpr std::byte leUI64
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 convertSI32F32
static constexpr std::byte eqI32
static constexpr std::byte leF64
static constexpr std::byte geF32
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