1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
2 | |* *| |
3 | |* * AVR Disassembler *| |
4 | |* *| |
5 | |* Automatically generated file, do not edit! *| |
6 | |* *| |
7 | \*===----------------------------------------------------------------------===*/ |
8 | |
9 | |
10 | #include "llvm/MC/MCInst.h" |
11 | #include "llvm/MC/MCSubtargetInfo.h" |
12 | #include "llvm/Support/DataTypes.h" |
13 | #include "llvm/Support/Debug.h" |
14 | #include "llvm/Support/LEB128.h" |
15 | #include "llvm/Support/raw_ostream.h" |
16 | #include "llvm/TargetParser/SubtargetFeature.h" |
17 | #include <assert.h> |
18 | |
19 | namespace { |
20 | |
21 | // Helper functions for extracting fields from encoded instructions. |
22 | // InsnType must either be integral or an APInt-like object that must: |
23 | // * be default-constructible and copy-constructible |
24 | // * be constructible from an APInt (this can be private) |
25 | // * Support insertBits(bits, startBit, numBits) |
26 | // * Support extractBitsAsZExtValue(numBits, startBit) |
27 | // * Support the ~, &, ==, and != operators with other objects of the same type |
28 | // * Support the != and bitwise & with uint64_t |
29 | // * Support put (<<) to raw_ostream& |
30 | template <typename InsnType> |
31 | #if defined(_MSC_VER) && !defined(__clang__) |
32 | __declspec(noinline) |
33 | #endif |
34 | static std::enable_if_t<std::is_integral<InsnType>::value, InsnType> |
35 | fieldFromInstruction(const InsnType &insn, unsigned startBit, |
36 | unsigned numBits) { |
37 | assert(startBit + numBits <= 64 && "Cannot support >64-bit extractions!" ); |
38 | assert(startBit + numBits <= (sizeof(InsnType) * 8) && |
39 | "Instruction field out of bounds!" ); |
40 | InsnType fieldMask; |
41 | if (numBits == sizeof(InsnType) * 8) |
42 | fieldMask = (InsnType)(-1LL); |
43 | else |
44 | fieldMask = (((InsnType)1 << numBits) - 1) << startBit; |
45 | return (insn & fieldMask) >> startBit; |
46 | } |
47 | |
48 | template <typename InsnType> |
49 | static std::enable_if_t<!std::is_integral<InsnType>::value, uint64_t> |
50 | fieldFromInstruction(const InsnType &insn, unsigned startBit, |
51 | unsigned numBits) { |
52 | return insn.extractBitsAsZExtValue(numBits, startBit); |
53 | } |
54 | |
55 | // Helper function for inserting bits extracted from an encoded instruction into |
56 | // a field. |
57 | template <typename InsnType> |
58 | static void insertBits(InsnType &field, InsnType bits, unsigned startBit, |
59 | unsigned numBits) { |
60 | if constexpr (std::is_integral<InsnType>::value) { |
61 | assert(startBit + numBits <= sizeof field * 8); |
62 | (void)numBits; |
63 | field |= (InsnType)bits << startBit; |
64 | } else { |
65 | field.insertBits(bits, startBit, numBits); |
66 | } |
67 | } |
68 | |
69 | static bool Check(DecodeStatus &Out, DecodeStatus In) { |
70 | Out = static_cast<DecodeStatus>(Out & In); |
71 | return Out != MCDisassembler::Fail; |
72 | } |
73 | |
74 | static const uint8_t DecoderTable16[] = { |
75 | /* 0 */ MCD::OPC_ExtractField, 14, 2, // Inst{15-14} ... |
76 | /* 3 */ MCD::OPC_FilterValue, 0, 211, 0, // Skip to: 218 |
77 | /* 7 */ MCD::OPC_ExtractField, 12, 2, // Inst{13-12} ... |
78 | /* 10 */ MCD::OPC_FilterValue, 0, 124, 0, // Skip to: 138 |
79 | /* 14 */ MCD::OPC_ExtractField, 10, 2, // Inst{11-10} ... |
80 | /* 17 */ MCD::OPC_FilterValue, 0, 95, 0, // Skip to: 116 |
81 | /* 21 */ MCD::OPC_ExtractField, 8, 2, // Inst{9-8} ... |
82 | /* 24 */ MCD::OPC_FilterValue, 0, 8, 0, // Skip to: 36 |
83 | /* 28 */ MCD::OPC_CheckFieldOrFail, 0, 8, 0, |
84 | /* 32 */ MCD::OPC_Decode, 213, 3, 0, // Opcode: NOP, DecodeIdx: 0 |
85 | /* 36 */ MCD::OPC_FilterValue, 1, 6, 0, // Skip to: 46 |
86 | /* 40 */ MCD::OPC_CheckPredicateOrFail, 0, |
87 | /* 42 */ MCD::OPC_Decode, 208, 3, 1, // Opcode: MOVWRdRr, DecodeIdx: 1 |
88 | /* 46 */ MCD::OPC_FilterValue, 2, 6, 0, // Skip to: 56 |
89 | /* 50 */ MCD::OPC_CheckPredicateOrFail, 1, |
90 | /* 52 */ MCD::OPC_Decode, 210, 3, 2, // Opcode: MULSRdRr, DecodeIdx: 2 |
91 | /* 56 */ MCD::OPC_FilterValueOrFail, 3, |
92 | /* 58 */ MCD::OPC_ExtractField, 3, 1, // Inst{3} ... |
93 | /* 61 */ MCD::OPC_FilterValue, 0, 14, 0, // Skip to: 79 |
94 | /* 65 */ MCD::OPC_CheckPredicate, 1, 41, 0, // Skip to: 110 |
95 | /* 69 */ MCD::OPC_CheckField, 7, 1, 1, 35, 0, // Skip to: 110 |
96 | /* 75 */ MCD::OPC_Decode, 186, 3, 3, // Opcode: FMULS, DecodeIdx: 3 |
97 | /* 79 */ MCD::OPC_FilterValue, 1, 27, 0, // Skip to: 110 |
98 | /* 83 */ MCD::OPC_ExtractField, 7, 1, // Inst{7} ... |
99 | /* 86 */ MCD::OPC_FilterValue, 0, 8, 0, // Skip to: 98 |
100 | /* 90 */ MCD::OPC_CheckPredicate, 1, 16, 0, // Skip to: 110 |
101 | /* 94 */ MCD::OPC_Decode, 185, 3, 3, // Opcode: FMUL, DecodeIdx: 3 |
102 | /* 98 */ MCD::OPC_FilterValue, 1, 8, 0, // Skip to: 110 |
103 | /* 102 */ MCD::OPC_CheckPredicate, 1, 4, 0, // Skip to: 110 |
104 | /* 106 */ MCD::OPC_Decode, 187, 3, 3, // Opcode: FMULSU, DecodeIdx: 3 |
105 | /* 110 */ MCD::OPC_CheckPredicateOrFail, 1, |
106 | /* 112 */ MCD::OPC_Decode, 211, 3, 2, // Opcode: MULSURdRr, DecodeIdx: 2 |
107 | /* 116 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 124 |
108 | /* 120 */ MCD::OPC_Decode, 173, 3, 4, // Opcode: CPCRdRr, DecodeIdx: 4 |
109 | /* 124 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 132 |
110 | /* 128 */ MCD::OPC_Decode, 225, 3, 5, // Opcode: SBCRdRr, DecodeIdx: 5 |
111 | /* 132 */ MCD::OPC_FilterValueOrFail, 3, |
112 | /* 134 */ MCD::OPC_Decode, 150, 3, 5, // Opcode: ADDRdRr, DecodeIdx: 5 |
113 | /* 138 */ MCD::OPC_FilterValue, 1, 33, 0, // Skip to: 175 |
114 | /* 142 */ MCD::OPC_ExtractField, 10, 2, // Inst{11-10} ... |
115 | /* 145 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 153 |
116 | /* 149 */ MCD::OPC_Decode, 176, 3, 4, // Opcode: CPSE, DecodeIdx: 4 |
117 | /* 153 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 161 |
118 | /* 157 */ MCD::OPC_Decode, 175, 3, 4, // Opcode: CPRdRr, DecodeIdx: 4 |
119 | /* 161 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 169 |
120 | /* 165 */ MCD::OPC_Decode, 242, 3, 5, // Opcode: SUBRdRr, DecodeIdx: 5 |
121 | /* 169 */ MCD::OPC_FilterValueOrFail, 3, |
122 | /* 171 */ MCD::OPC_Decode, 149, 3, 5, // Opcode: ADCRdRr, DecodeIdx: 5 |
123 | /* 175 */ MCD::OPC_FilterValue, 2, 33, 0, // Skip to: 212 |
124 | /* 179 */ MCD::OPC_ExtractField, 10, 2, // Inst{11-10} ... |
125 | /* 182 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 190 |
126 | /* 186 */ MCD::OPC_Decode, 153, 3, 5, // Opcode: ANDRdRr, DecodeIdx: 5 |
127 | /* 190 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 198 |
128 | /* 194 */ MCD::OPC_Decode, 184, 3, 5, // Opcode: EORRdRr, DecodeIdx: 5 |
129 | /* 198 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 206 |
130 | /* 202 */ MCD::OPC_Decode, 215, 3, 5, // Opcode: ORRdRr, DecodeIdx: 5 |
131 | /* 206 */ MCD::OPC_FilterValueOrFail, 3, |
132 | /* 208 */ MCD::OPC_Decode, 207, 3, 4, // Opcode: MOVRdRr, DecodeIdx: 4 |
133 | /* 212 */ MCD::OPC_FilterValueOrFail, 3, |
134 | /* 214 */ MCD::OPC_Decode, 174, 3, 6, // Opcode: CPIRdK, DecodeIdx: 6 |
135 | /* 218 */ MCD::OPC_FilterValue, 1, 33, 0, // Skip to: 255 |
136 | /* 222 */ MCD::OPC_ExtractField, 12, 2, // Inst{13-12} ... |
137 | /* 225 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 233 |
138 | /* 229 */ MCD::OPC_Decode, 224, 3, 7, // Opcode: SBCIRdK, DecodeIdx: 7 |
139 | /* 233 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 241 |
140 | /* 237 */ MCD::OPC_Decode, 241, 3, 7, // Opcode: SUBIRdK, DecodeIdx: 7 |
141 | /* 241 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 249 |
142 | /* 245 */ MCD::OPC_Decode, 214, 3, 7, // Opcode: ORIRdK, DecodeIdx: 7 |
143 | /* 249 */ MCD::OPC_FilterValueOrFail, 3, |
144 | /* 251 */ MCD::OPC_Decode, 152, 3, 7, // Opcode: ANDIRdK, DecodeIdx: 7 |
145 | /* 255 */ MCD::OPC_FilterValue, 2, 128, 2, // Skip to: 899 |
146 | /* 259 */ MCD::OPC_ExtractField, 12, 1, // Inst{12} ... |
147 | /* 262 */ MCD::OPC_FilterValue, 0, 171, 0, // Skip to: 437 |
148 | /* 266 */ MCD::OPC_ExtractField, 9, 1, // Inst{9} ... |
149 | /* 269 */ MCD::OPC_FilterValue, 0, 81, 0, // Skip to: 354 |
150 | /* 273 */ MCD::OPC_ExtractField, 0, 2, // Inst{1-0} ... |
151 | /* 276 */ MCD::OPC_FilterValue, 0, 20, 0, // Skip to: 300 |
152 | /* 280 */ MCD::OPC_CheckPredicate, 2, 64, 0, // Skip to: 348 |
153 | /* 284 */ MCD::OPC_CheckField, 13, 1, 0, 58, 0, // Skip to: 348 |
154 | /* 290 */ MCD::OPC_CheckField, 10, 2, 0, 52, 0, // Skip to: 348 |
155 | /* 296 */ MCD::OPC_Decode, 198, 3, 8, // Opcode: LDRdPtr, DecodeIdx: 8 |
156 | /* 300 */ MCD::OPC_FilterValue, 1, 20, 0, // Skip to: 324 |
157 | /* 304 */ MCD::OPC_CheckPredicate, 2, 40, 0, // Skip to: 348 |
158 | /* 308 */ MCD::OPC_CheckField, 13, 1, 0, 34, 0, // Skip to: 348 |
159 | /* 314 */ MCD::OPC_CheckField, 10, 2, 0, 28, 0, // Skip to: 348 |
160 | /* 320 */ MCD::OPC_Decode, 200, 3, 8, // Opcode: LDRdPtrPi, DecodeIdx: 8 |
161 | /* 324 */ MCD::OPC_FilterValue, 2, 20, 0, // Skip to: 348 |
162 | /* 328 */ MCD::OPC_CheckPredicate, 2, 16, 0, // Skip to: 348 |
163 | /* 332 */ MCD::OPC_CheckField, 13, 1, 0, 10, 0, // Skip to: 348 |
164 | /* 338 */ MCD::OPC_CheckField, 10, 2, 0, 4, 0, // Skip to: 348 |
165 | /* 344 */ MCD::OPC_Decode, 199, 3, 8, // Opcode: LDRdPtrPd, DecodeIdx: 8 |
166 | /* 348 */ MCD::OPC_CheckPredicateOrFail, 3, |
167 | /* 350 */ MCD::OPC_Decode, 196, 3, 9, // Opcode: LDDRdPtrQ, DecodeIdx: 9 |
168 | /* 354 */ MCD::OPC_FilterValueOrFail, 1, |
169 | /* 356 */ MCD::OPC_ExtractField, 0, 2, // Inst{1-0} ... |
170 | /* 359 */ MCD::OPC_FilterValue, 0, 20, 0, // Skip to: 383 |
171 | /* 363 */ MCD::OPC_CheckPredicate, 2, 64, 0, // Skip to: 431 |
172 | /* 367 */ MCD::OPC_CheckField, 13, 1, 0, 58, 0, // Skip to: 431 |
173 | /* 373 */ MCD::OPC_CheckField, 10, 2, 0, 52, 0, // Skip to: 431 |
174 | /* 379 */ MCD::OPC_Decode, 238, 3, 8, // Opcode: STPtrRr, DecodeIdx: 8 |
175 | /* 383 */ MCD::OPC_FilterValue, 1, 20, 0, // Skip to: 407 |
176 | /* 387 */ MCD::OPC_CheckPredicate, 2, 40, 0, // Skip to: 431 |
177 | /* 391 */ MCD::OPC_CheckField, 13, 1, 0, 34, 0, // Skip to: 431 |
178 | /* 397 */ MCD::OPC_CheckField, 10, 2, 0, 28, 0, // Skip to: 431 |
179 | /* 403 */ MCD::OPC_Decode, 237, 3, 8, // Opcode: STPtrPiRr, DecodeIdx: 8 |
180 | /* 407 */ MCD::OPC_FilterValue, 2, 20, 0, // Skip to: 431 |
181 | /* 411 */ MCD::OPC_CheckPredicate, 2, 16, 0, // Skip to: 431 |
182 | /* 415 */ MCD::OPC_CheckField, 13, 1, 0, 10, 0, // Skip to: 431 |
183 | /* 421 */ MCD::OPC_CheckField, 10, 2, 0, 4, 0, // Skip to: 431 |
184 | /* 427 */ MCD::OPC_Decode, 236, 3, 8, // Opcode: STPtrPdRr, DecodeIdx: 8 |
185 | /* 431 */ MCD::OPC_CheckPredicateOrFail, 3, |
186 | /* 433 */ MCD::OPC_Decode, 235, 3, 10, // Opcode: STDPtrQRr, DecodeIdx: 10 |
187 | /* 437 */ MCD::OPC_FilterValueOrFail, 1, |
188 | /* 439 */ MCD::OPC_ExtractField, 11, 1, // Inst{11} ... |
189 | /* 442 */ MCD::OPC_FilterValue, 0, 134, 1, // Skip to: 836 |
190 | /* 446 */ MCD::OPC_ExtractField, 13, 1, // Inst{13} ... |
191 | /* 449 */ MCD::OPC_FilterValue, 0, 121, 1, // Skip to: 830 |
192 | /* 453 */ MCD::OPC_ExtractField, 9, 2, // Inst{10-9} ... |
193 | /* 456 */ MCD::OPC_FilterValue, 0, 51, 0, // Skip to: 511 |
194 | /* 460 */ MCD::OPC_ExtractField, 0, 4, // Inst{3-0} ... |
195 | /* 463 */ MCD::OPC_FilterValue, 4, 6, 0, // Skip to: 473 |
196 | /* 467 */ MCD::OPC_CheckPredicateOrFail, 4, |
197 | /* 469 */ MCD::OPC_Decode, 204, 3, 11, // Opcode: LPMRdZ, DecodeIdx: 11 |
198 | /* 473 */ MCD::OPC_FilterValue, 5, 6, 0, // Skip to: 483 |
199 | /* 477 */ MCD::OPC_CheckPredicateOrFail, 4, |
200 | /* 479 */ MCD::OPC_Decode, 205, 3, 11, // Opcode: LPMRdZPi, DecodeIdx: 11 |
201 | /* 483 */ MCD::OPC_FilterValue, 6, 6, 0, // Skip to: 493 |
202 | /* 487 */ MCD::OPC_CheckPredicateOrFail, 5, |
203 | /* 489 */ MCD::OPC_Decode, 182, 3, 11, // Opcode: ELPMRdZ, DecodeIdx: 11 |
204 | /* 493 */ MCD::OPC_FilterValue, 7, 6, 0, // Skip to: 503 |
205 | /* 497 */ MCD::OPC_CheckPredicateOrFail, 5, |
206 | /* 499 */ MCD::OPC_Decode, 183, 3, 11, // Opcode: ELPMRdZPi, DecodeIdx: 11 |
207 | /* 503 */ MCD::OPC_FilterValueOrFail, 15, |
208 | /* 505 */ MCD::OPC_CheckPredicateOrFail, 2, |
209 | /* 507 */ MCD::OPC_Decode, 217, 3, 12, // Opcode: POPRd, DecodeIdx: 12 |
210 | /* 511 */ MCD::OPC_FilterValue, 1, 51, 0, // Skip to: 566 |
211 | /* 515 */ MCD::OPC_ExtractField, 0, 4, // Inst{3-0} ... |
212 | /* 518 */ MCD::OPC_FilterValue, 4, 6, 0, // Skip to: 528 |
213 | /* 522 */ MCD::OPC_CheckPredicateOrFail, 6, |
214 | /* 524 */ MCD::OPC_Decode, 245, 3, 13, // Opcode: XCHZRd, DecodeIdx: 13 |
215 | /* 528 */ MCD::OPC_FilterValue, 5, 6, 0, // Skip to: 538 |
216 | /* 532 */ MCD::OPC_CheckPredicateOrFail, 6, |
217 | /* 534 */ MCD::OPC_Decode, 194, 3, 13, // Opcode: LASZRd, DecodeIdx: 13 |
218 | /* 538 */ MCD::OPC_FilterValue, 6, 6, 0, // Skip to: 548 |
219 | /* 542 */ MCD::OPC_CheckPredicateOrFail, 6, |
220 | /* 544 */ MCD::OPC_Decode, 193, 3, 13, // Opcode: LACZRd, DecodeIdx: 13 |
221 | /* 548 */ MCD::OPC_FilterValue, 7, 6, 0, // Skip to: 558 |
222 | /* 552 */ MCD::OPC_CheckPredicateOrFail, 6, |
223 | /* 554 */ MCD::OPC_Decode, 195, 3, 13, // Opcode: LATZRd, DecodeIdx: 13 |
224 | /* 558 */ MCD::OPC_FilterValueOrFail, 15, |
225 | /* 560 */ MCD::OPC_CheckPredicateOrFail, 2, |
226 | /* 562 */ MCD::OPC_Decode, 218, 3, 12, // Opcode: PUSHRr, DecodeIdx: 12 |
227 | /* 566 */ MCD::OPC_FilterValue, 2, 237, 0, // Skip to: 807 |
228 | /* 570 */ MCD::OPC_ExtractField, 0, 4, // Inst{3-0} ... |
229 | /* 573 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 581 |
230 | /* 577 */ MCD::OPC_Decode, 172, 3, 12, // Opcode: COMRd, DecodeIdx: 12 |
231 | /* 581 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 589 |
232 | /* 585 */ MCD::OPC_Decode, 212, 3, 12, // Opcode: NEGRd, DecodeIdx: 12 |
233 | /* 589 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 597 |
234 | /* 593 */ MCD::OPC_Decode, 243, 3, 12, // Opcode: SWAPRd, DecodeIdx: 12 |
235 | /* 597 */ MCD::OPC_FilterValue, 3, 4, 0, // Skip to: 605 |
236 | /* 601 */ MCD::OPC_Decode, 190, 3, 12, // Opcode: INCRd, DecodeIdx: 12 |
237 | /* 605 */ MCD::OPC_FilterValue, 5, 4, 0, // Skip to: 613 |
238 | /* 609 */ MCD::OPC_Decode, 154, 3, 12, // Opcode: ASRRd, DecodeIdx: 12 |
239 | /* 613 */ MCD::OPC_FilterValue, 6, 4, 0, // Skip to: 621 |
240 | /* 617 */ MCD::OPC_Decode, 206, 3, 12, // Opcode: LSRRd, DecodeIdx: 12 |
241 | /* 621 */ MCD::OPC_FilterValue, 7, 4, 0, // Skip to: 629 |
242 | /* 625 */ MCD::OPC_Decode, 223, 3, 12, // Opcode: RORRd, DecodeIdx: 12 |
243 | /* 629 */ MCD::OPC_FilterValue, 8, 109, 0, // Skip to: 742 |
244 | /* 633 */ MCD::OPC_ExtractField, 7, 2, // Inst{8-7} ... |
245 | /* 636 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 644 |
246 | /* 640 */ MCD::OPC_Decode, 168, 3, 14, // Opcode: BSETs, DecodeIdx: 14 |
247 | /* 644 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 652 |
248 | /* 648 */ MCD::OPC_Decode, 155, 3, 14, // Opcode: BCLRs, DecodeIdx: 14 |
249 | /* 652 */ MCD::OPC_FilterValue, 2, 17, 0, // Skip to: 673 |
250 | /* 656 */ MCD::OPC_ExtractField, 4, 3, // Inst{6-4} ... |
251 | /* 659 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 667 |
252 | /* 663 */ MCD::OPC_Decode, 220, 3, 0, // Opcode: RET, DecodeIdx: 0 |
253 | /* 667 */ MCD::OPC_FilterValueOrFail, 1, |
254 | /* 669 */ MCD::OPC_Decode, 221, 3, 0, // Opcode: RETI, DecodeIdx: 0 |
255 | /* 673 */ MCD::OPC_FilterValueOrFail, 3, |
256 | /* 675 */ MCD::OPC_ExtractField, 4, 3, // Inst{6-4} ... |
257 | /* 678 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 686 |
258 | /* 682 */ MCD::OPC_Decode, 232, 3, 0, // Opcode: SLEEP, DecodeIdx: 0 |
259 | /* 686 */ MCD::OPC_FilterValue, 1, 6, 0, // Skip to: 696 |
260 | /* 690 */ MCD::OPC_CheckPredicateOrFail, 7, |
261 | /* 692 */ MCD::OPC_Decode, 159, 3, 0, // Opcode: BREAK, DecodeIdx: 0 |
262 | /* 696 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 704 |
263 | /* 700 */ MCD::OPC_Decode, 244, 3, 0, // Opcode: WDR, DecodeIdx: 0 |
264 | /* 704 */ MCD::OPC_FilterValue, 4, 6, 0, // Skip to: 714 |
265 | /* 708 */ MCD::OPC_CheckPredicateOrFail, 8, |
266 | /* 710 */ MCD::OPC_Decode, 203, 3, 0, // Opcode: LPM, DecodeIdx: 0 |
267 | /* 714 */ MCD::OPC_FilterValue, 5, 6, 0, // Skip to: 724 |
268 | /* 718 */ MCD::OPC_CheckPredicateOrFail, 9, |
269 | /* 720 */ MCD::OPC_Decode, 181, 3, 0, // Opcode: ELPM, DecodeIdx: 0 |
270 | /* 724 */ MCD::OPC_FilterValue, 6, 6, 0, // Skip to: 734 |
271 | /* 728 */ MCD::OPC_CheckPredicateOrFail, 10, |
272 | /* 730 */ MCD::OPC_Decode, 233, 3, 0, // Opcode: SPM, DecodeIdx: 0 |
273 | /* 734 */ MCD::OPC_FilterValueOrFail, 7, |
274 | /* 736 */ MCD::OPC_CheckPredicateOrFail, 11, |
275 | /* 738 */ MCD::OPC_Decode, 234, 3, 0, // Opcode: SPMZPi, DecodeIdx: 0 |
276 | /* 742 */ MCD::OPC_FilterValue, 9, 41, 0, // Skip to: 787 |
277 | /* 746 */ MCD::OPC_ExtractField, 4, 5, // Inst{8-4} ... |
278 | /* 749 */ MCD::OPC_FilterValue, 0, 6, 0, // Skip to: 759 |
279 | /* 753 */ MCD::OPC_CheckPredicateOrFail, 12, |
280 | /* 755 */ MCD::OPC_Decode, 189, 3, 0, // Opcode: IJMP, DecodeIdx: 0 |
281 | /* 759 */ MCD::OPC_FilterValue, 1, 6, 0, // Skip to: 769 |
282 | /* 763 */ MCD::OPC_CheckPredicateOrFail, 13, |
283 | /* 765 */ MCD::OPC_Decode, 180, 3, 0, // Opcode: EIJMP, DecodeIdx: 0 |
284 | /* 769 */ MCD::OPC_FilterValue, 16, 6, 0, // Skip to: 779 |
285 | /* 773 */ MCD::OPC_CheckPredicateOrFail, 12, |
286 | /* 775 */ MCD::OPC_Decode, 188, 3, 0, // Opcode: ICALL, DecodeIdx: 0 |
287 | /* 779 */ MCD::OPC_FilterValueOrFail, 17, |
288 | /* 781 */ MCD::OPC_CheckPredicateOrFail, 13, |
289 | /* 783 */ MCD::OPC_Decode, 179, 3, 0, // Opcode: EICALL, DecodeIdx: 0 |
290 | /* 787 */ MCD::OPC_FilterValue, 10, 4, 0, // Skip to: 795 |
291 | /* 791 */ MCD::OPC_Decode, 177, 3, 12, // Opcode: DECRd, DecodeIdx: 12 |
292 | /* 795 */ MCD::OPC_FilterValueOrFail, 11, |
293 | /* 797 */ MCD::OPC_CheckPredicateOrFail, 14, |
294 | /* 799 */ MCD::OPC_CheckFieldOrFail, 8, 1, 0, |
295 | /* 803 */ MCD::OPC_Decode, 178, 3, 15, // Opcode: DESK, DecodeIdx: 15 |
296 | /* 807 */ MCD::OPC_FilterValueOrFail, 3, |
297 | /* 809 */ MCD::OPC_ExtractField, 8, 1, // Inst{8} ... |
298 | /* 812 */ MCD::OPC_FilterValue, 0, 6, 0, // Skip to: 822 |
299 | /* 816 */ MCD::OPC_CheckPredicateOrFail, 15, |
300 | /* 818 */ MCD::OPC_Decode, 151, 3, 16, // Opcode: ADIWRdK, DecodeIdx: 16 |
301 | /* 822 */ MCD::OPC_FilterValueOrFail, 1, |
302 | /* 824 */ MCD::OPC_CheckPredicateOrFail, 15, |
303 | /* 826 */ MCD::OPC_Decode, 229, 3, 16, // Opcode: SBIWRdK, DecodeIdx: 16 |
304 | /* 830 */ MCD::OPC_FilterValueOrFail, 1, |
305 | /* 832 */ MCD::OPC_Decode, 191, 3, 17, // Opcode: INRdA, DecodeIdx: 17 |
306 | /* 836 */ MCD::OPC_FilterValueOrFail, 1, |
307 | /* 838 */ MCD::OPC_ExtractField, 13, 1, // Inst{13} ... |
308 | /* 841 */ MCD::OPC_FilterValue, 0, 48, 0, // Skip to: 893 |
309 | /* 845 */ MCD::OPC_ExtractField, 10, 1, // Inst{10} ... |
310 | /* 848 */ MCD::OPC_FilterValue, 0, 33, 0, // Skip to: 885 |
311 | /* 852 */ MCD::OPC_ExtractField, 8, 2, // Inst{9-8} ... |
312 | /* 855 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 863 |
313 | /* 859 */ MCD::OPC_Decode, 171, 3, 18, // Opcode: CBIAb, DecodeIdx: 18 |
314 | /* 863 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 871 |
315 | /* 867 */ MCD::OPC_Decode, 227, 3, 18, // Opcode: SBICAb, DecodeIdx: 18 |
316 | /* 871 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 879 |
317 | /* 875 */ MCD::OPC_Decode, 226, 3, 18, // Opcode: SBIAb, DecodeIdx: 18 |
318 | /* 879 */ MCD::OPC_FilterValueOrFail, 3, |
319 | /* 881 */ MCD::OPC_Decode, 228, 3, 18, // Opcode: SBISAb, DecodeIdx: 18 |
320 | /* 885 */ MCD::OPC_FilterValueOrFail, 1, |
321 | /* 887 */ MCD::OPC_CheckPredicateOrFail, 1, |
322 | /* 889 */ MCD::OPC_Decode, 209, 3, 4, // Opcode: MULRdRr, DecodeIdx: 4 |
323 | /* 893 */ MCD::OPC_FilterValueOrFail, 1, |
324 | /* 895 */ MCD::OPC_Decode, 216, 3, 19, // Opcode: OUTARr, DecodeIdx: 19 |
325 | /* 899 */ MCD::OPC_FilterValueOrFail, 3, |
326 | /* 901 */ MCD::OPC_ExtractField, 12, 2, // Inst{13-12} ... |
327 | /* 904 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 912 |
328 | /* 908 */ MCD::OPC_Decode, 222, 3, 20, // Opcode: RJMPk, DecodeIdx: 20 |
329 | /* 912 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 920 |
330 | /* 916 */ MCD::OPC_Decode, 219, 3, 20, // Opcode: RCALLk, DecodeIdx: 20 |
331 | /* 920 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 928 |
332 | /* 924 */ MCD::OPC_Decode, 197, 3, 6, // Opcode: LDIRdK, DecodeIdx: 6 |
333 | /* 928 */ MCD::OPC_FilterValueOrFail, 3, |
334 | /* 930 */ MCD::OPC_ExtractField, 10, 2, // Inst{11-10} ... |
335 | /* 933 */ MCD::OPC_FilterValue, 0, 39, 0, // Skip to: 976 |
336 | /* 937 */ MCD::OPC_ExtractField, 0, 3, // Inst{2-0} ... |
337 | /* 940 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 948 |
338 | /* 944 */ MCD::OPC_Decode, 162, 3, 21, // Opcode: BRLOk, DecodeIdx: 21 |
339 | /* 948 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 956 |
340 | /* 952 */ MCD::OPC_Decode, 160, 3, 21, // Opcode: BREQk, DecodeIdx: 21 |
341 | /* 956 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 964 |
342 | /* 960 */ MCD::OPC_Decode, 164, 3, 21, // Opcode: BRMIk, DecodeIdx: 21 |
343 | /* 964 */ MCD::OPC_FilterValue, 4, 4, 0, // Skip to: 972 |
344 | /* 968 */ MCD::OPC_Decode, 163, 3, 21, // Opcode: BRLTk, DecodeIdx: 21 |
345 | /* 972 */ MCD::OPC_Decode, 158, 3, 21, // Opcode: BRBSsk, DecodeIdx: 21 |
346 | /* 976 */ MCD::OPC_FilterValue, 1, 39, 0, // Skip to: 1019 |
347 | /* 980 */ MCD::OPC_ExtractField, 0, 3, // Inst{2-0} ... |
348 | /* 983 */ MCD::OPC_FilterValue, 0, 4, 0, // Skip to: 991 |
349 | /* 987 */ MCD::OPC_Decode, 167, 3, 21, // Opcode: BRSHk, DecodeIdx: 21 |
350 | /* 991 */ MCD::OPC_FilterValue, 1, 4, 0, // Skip to: 999 |
351 | /* 995 */ MCD::OPC_Decode, 165, 3, 21, // Opcode: BRNEk, DecodeIdx: 21 |
352 | /* 999 */ MCD::OPC_FilterValue, 2, 4, 0, // Skip to: 1007 |
353 | /* 1003 */ MCD::OPC_Decode, 166, 3, 21, // Opcode: BRPLk, DecodeIdx: 21 |
354 | /* 1007 */ MCD::OPC_FilterValue, 4, 4, 0, // Skip to: 1015 |
355 | /* 1011 */ MCD::OPC_Decode, 161, 3, 21, // Opcode: BRGEk, DecodeIdx: 21 |
356 | /* 1015 */ MCD::OPC_Decode, 157, 3, 21, // Opcode: BRBCsk, DecodeIdx: 21 |
357 | /* 1019 */ MCD::OPC_FilterValue, 2, 25, 0, // Skip to: 1048 |
358 | /* 1023 */ MCD::OPC_ExtractField, 9, 1, // Inst{9} ... |
359 | /* 1026 */ MCD::OPC_FilterValue, 0, 8, 0, // Skip to: 1038 |
360 | /* 1030 */ MCD::OPC_CheckFieldOrFail, 3, 1, 0, |
361 | /* 1034 */ MCD::OPC_Decode, 156, 3, 22, // Opcode: BLD, DecodeIdx: 22 |
362 | /* 1038 */ MCD::OPC_FilterValueOrFail, 1, |
363 | /* 1040 */ MCD::OPC_CheckFieldOrFail, 3, 1, 0, |
364 | /* 1044 */ MCD::OPC_Decode, 169, 3, 23, // Opcode: BST, DecodeIdx: 23 |
365 | /* 1048 */ MCD::OPC_FilterValueOrFail, 3, |
366 | /* 1050 */ MCD::OPC_ExtractField, 9, 1, // Inst{9} ... |
367 | /* 1053 */ MCD::OPC_FilterValue, 0, 8, 0, // Skip to: 1065 |
368 | /* 1057 */ MCD::OPC_CheckFieldOrFail, 3, 1, 0, |
369 | /* 1061 */ MCD::OPC_Decode, 230, 3, 23, // Opcode: SBRCRrB, DecodeIdx: 23 |
370 | /* 1065 */ MCD::OPC_FilterValueOrFail, 1, |
371 | /* 1067 */ MCD::OPC_CheckFieldOrFail, 3, 1, 0, |
372 | /* 1071 */ MCD::OPC_Decode, 231, 3, 23, // Opcode: SBRSRrB, DecodeIdx: 23 |
373 | /* 1075 */ MCD::OPC_Fail, |
374 | 0 |
375 | }; |
376 | |
377 | static const uint8_t DecoderTable32[] = { |
378 | /* 0 */ MCD::OPC_ExtractField, 17, 3, // Inst{19-17} ... |
379 | /* 3 */ MCD::OPC_FilterValue, 0, 29, 0, // Skip to: 36 |
380 | /* 7 */ MCD::OPC_ExtractField, 25, 7, // Inst{31-25} ... |
381 | /* 10 */ MCD::OPC_FilterValue, 72, 10, 0, // Skip to: 24 |
382 | /* 14 */ MCD::OPC_CheckPredicateOrFail, 3, |
383 | /* 16 */ MCD::OPC_CheckFieldOrFail, 16, 1, 0, |
384 | /* 20 */ MCD::OPC_Decode, 201, 3, 24, // Opcode: LDSRdK, DecodeIdx: 24 |
385 | /* 24 */ MCD::OPC_FilterValueOrFail, 73, |
386 | /* 26 */ MCD::OPC_CheckPredicateOrFail, 3, |
387 | /* 28 */ MCD::OPC_CheckFieldOrFail, 16, 1, 0, |
388 | /* 32 */ MCD::OPC_Decode, 239, 3, 25, // Opcode: STSKRr, DecodeIdx: 25 |
389 | /* 36 */ MCD::OPC_FilterValue, 6, 10, 0, // Skip to: 50 |
390 | /* 40 */ MCD::OPC_CheckPredicateOrFail, 16, |
391 | /* 42 */ MCD::OPC_CheckFieldOrFail, 25, 7, 74, |
392 | /* 46 */ MCD::OPC_Decode, 192, 3, 26, // Opcode: JMPk, DecodeIdx: 26 |
393 | /* 50 */ MCD::OPC_FilterValueOrFail, 7, |
394 | /* 52 */ MCD::OPC_CheckPredicateOrFail, 16, |
395 | /* 54 */ MCD::OPC_CheckFieldOrFail, 25, 7, 74, |
396 | /* 58 */ MCD::OPC_Decode, 170, 3, 26, // Opcode: CALLk, DecodeIdx: 26 |
397 | /* 62 */ MCD::OPC_Fail, |
398 | 0 |
399 | }; |
400 | |
401 | static const uint8_t DecoderTableAVRTiny16[] = { |
402 | /* 0 */ MCD::OPC_ExtractField, 11, 5, // Inst{15-11} ... |
403 | /* 3 */ MCD::OPC_FilterValue, 20, 6, 0, // Skip to: 13 |
404 | /* 7 */ MCD::OPC_CheckPredicateOrFail, 17, |
405 | /* 9 */ MCD::OPC_Decode, 202, 3, 27, // Opcode: LDSRdKTiny, DecodeIdx: 27 |
406 | /* 13 */ MCD::OPC_FilterValueOrFail, 21, |
407 | /* 15 */ MCD::OPC_CheckPredicateOrFail, 17, |
408 | /* 17 */ MCD::OPC_Decode, 240, 3, 28, // Opcode: STSKRrTiny, DecodeIdx: 28 |
409 | /* 21 */ MCD::OPC_Fail, |
410 | 0 |
411 | }; |
412 | |
413 | static bool checkDecoderPredicate(unsigned Idx, const FeatureBitset &Bits) { |
414 | switch (Idx) { |
415 | default: llvm_unreachable("Invalid index!" ); |
416 | case 0: |
417 | return (Bits[AVR::FeatureMOVW]); |
418 | case 1: |
419 | return (Bits[AVR::FeatureMultiplication]); |
420 | case 2: |
421 | return (Bits[AVR::FeatureSRAM]); |
422 | case 3: |
423 | return (Bits[AVR::FeatureSRAM] && !Bits[AVR::FeatureTinyEncoding]); |
424 | case 4: |
425 | return (Bits[AVR::FeatureLPMX]); |
426 | case 5: |
427 | return (Bits[AVR::FeatureELPMX]); |
428 | case 6: |
429 | return (Bits[AVR::FeatureRMW]); |
430 | case 7: |
431 | return (Bits[AVR::FeatureBREAK]); |
432 | case 8: |
433 | return (Bits[AVR::FeatureLPM]); |
434 | case 9: |
435 | return (Bits[AVR::FeatureELPM]); |
436 | case 10: |
437 | return (Bits[AVR::FeatureSPM]); |
438 | case 11: |
439 | return (Bits[AVR::FeatureSPMX]); |
440 | case 12: |
441 | return (Bits[AVR::FeatureIJMPCALL]); |
442 | case 13: |
443 | return (Bits[AVR::FeatureEIJMPCALL]); |
444 | case 14: |
445 | return (Bits[AVR::FeatureDES]); |
446 | case 15: |
447 | return (Bits[AVR::FeatureADDSUBIW]); |
448 | case 16: |
449 | return (Bits[AVR::FeatureJMPCALL]); |
450 | case 17: |
451 | return (Bits[AVR::FeatureSRAM] && Bits[AVR::FeatureTinyEncoding]); |
452 | } |
453 | } |
454 | |
455 | // Handling 29 cases. |
456 | template <typename InsnType> |
457 | static DecodeStatus decodeToMCInst(unsigned Idx, DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder, bool &DecodeComplete) { |
458 | DecodeComplete = true; |
459 | using TmpType = std::conditional_t<std::is_integral<InsnType>::value, InsnType, uint64_t>; |
460 | TmpType tmp; |
461 | switch (Idx) { |
462 | default: llvm_unreachable("Invalid index!" ); |
463 | case 0: |
464 | return S; |
465 | case 1: |
466 | if (!Check(S, decodeFMOVWRdRr(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
467 | return S; |
468 | case 2: |
469 | if (!Check(S, decodeFMUL2RdRr(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
470 | return S; |
471 | case 3: |
472 | if (!Check(S, decodeFFMULRdRr(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
473 | return S; |
474 | case 4: |
475 | tmp = fieldFromInstruction(insn, 4, 5); |
476 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
477 | tmp = 0x0; |
478 | insertBits(tmp, fieldFromInstruction(insn, 0, 4), 0, 4); |
479 | insertBits(tmp, fieldFromInstruction(insn, 9, 1), 4, 1); |
480 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
481 | return S; |
482 | case 5: |
483 | tmp = fieldFromInstruction(insn, 4, 5); |
484 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
485 | tmp = fieldFromInstruction(insn, 4, 5); |
486 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
487 | tmp = 0x0; |
488 | insertBits(tmp, fieldFromInstruction(insn, 0, 4), 0, 4); |
489 | insertBits(tmp, fieldFromInstruction(insn, 9, 1), 4, 1); |
490 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
491 | return S; |
492 | case 6: |
493 | tmp = fieldFromInstruction(insn, 4, 4); |
494 | if (!Check(S, DecodeLD8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
495 | tmp = 0x0; |
496 | insertBits(tmp, fieldFromInstruction(insn, 0, 4), 0, 4); |
497 | insertBits(tmp, fieldFromInstruction(insn, 8, 4), 4, 4); |
498 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
499 | return S; |
500 | case 7: |
501 | tmp = fieldFromInstruction(insn, 4, 4); |
502 | if (!Check(S, DecodeLD8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
503 | tmp = fieldFromInstruction(insn, 4, 4); |
504 | if (!Check(S, DecodeLD8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
505 | tmp = 0x0; |
506 | insertBits(tmp, fieldFromInstruction(insn, 0, 4), 0, 4); |
507 | insertBits(tmp, fieldFromInstruction(insn, 8, 4), 4, 4); |
508 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
509 | return S; |
510 | case 8: |
511 | if (!Check(S, decodeLoadStore(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
512 | return S; |
513 | case 9: |
514 | tmp = fieldFromInstruction(insn, 4, 5); |
515 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
516 | tmp = 0x0; |
517 | insertBits(tmp, fieldFromInstruction(insn, 0, 3), 0, 3); |
518 | insertBits(tmp, fieldFromInstruction(insn, 3, 1), 6, 1); |
519 | insertBits(tmp, fieldFromInstruction(insn, 10, 2), 3, 2); |
520 | insertBits(tmp, fieldFromInstruction(insn, 13, 1), 5, 1); |
521 | if (!Check(S, decodeMemri(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
522 | return S; |
523 | case 10: |
524 | tmp = 0x0; |
525 | insertBits(tmp, fieldFromInstruction(insn, 0, 3), 0, 3); |
526 | insertBits(tmp, fieldFromInstruction(insn, 3, 1), 6, 1); |
527 | insertBits(tmp, fieldFromInstruction(insn, 10, 2), 3, 2); |
528 | insertBits(tmp, fieldFromInstruction(insn, 13, 1), 5, 1); |
529 | if (!Check(S, decodeMemri(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
530 | tmp = fieldFromInstruction(insn, 4, 5); |
531 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
532 | return S; |
533 | case 11: |
534 | if (!Check(S, decodeFLPMX(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
535 | return S; |
536 | case 12: |
537 | if (!Check(S, decodeFRd(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
538 | return S; |
539 | case 13: |
540 | tmp = fieldFromInstruction(insn, 4, 5); |
541 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
542 | return S; |
543 | case 14: |
544 | tmp = fieldFromInstruction(insn, 4, 3); |
545 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
546 | return S; |
547 | case 15: |
548 | tmp = fieldFromInstruction(insn, 4, 4); |
549 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
550 | return S; |
551 | case 16: |
552 | if (!Check(S, decodeFWRdK(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
553 | return S; |
554 | case 17: |
555 | if (!Check(S, decodeFIORdA(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
556 | return S; |
557 | case 18: |
558 | if (!Check(S, decodeFIOBIT(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
559 | return S; |
560 | case 19: |
561 | if (!Check(S, decodeFIOARr(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
562 | return S; |
563 | case 20: |
564 | if (!Check(S, decodeFBRk(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
565 | return S; |
566 | case 21: |
567 | if (!Check(S, decodeCondBranch(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; } |
568 | return S; |
569 | case 22: |
570 | tmp = fieldFromInstruction(insn, 4, 5); |
571 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
572 | tmp = fieldFromInstruction(insn, 4, 5); |
573 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
574 | tmp = fieldFromInstruction(insn, 0, 3); |
575 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
576 | return S; |
577 | case 23: |
578 | tmp = fieldFromInstruction(insn, 4, 5); |
579 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
580 | tmp = fieldFromInstruction(insn, 0, 3); |
581 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
582 | return S; |
583 | case 24: |
584 | tmp = fieldFromInstruction(insn, 20, 5); |
585 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
586 | tmp = fieldFromInstruction(insn, 0, 16); |
587 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
588 | return S; |
589 | case 25: |
590 | tmp = fieldFromInstruction(insn, 0, 16); |
591 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
592 | tmp = fieldFromInstruction(insn, 20, 5); |
593 | if (!Check(S, DecodeGPR8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
594 | return S; |
595 | case 26: |
596 | tmp = 0x0; |
597 | insertBits(tmp, fieldFromInstruction(insn, 0, 17), 0, 17); |
598 | insertBits(tmp, fieldFromInstruction(insn, 20, 5), 17, 5); |
599 | if (!Check(S, decodeCallTarget(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
600 | return S; |
601 | case 27: |
602 | tmp = fieldFromInstruction(insn, 4, 4); |
603 | if (!Check(S, DecodeLD8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
604 | tmp = 0x0; |
605 | insertBits(tmp, fieldFromInstruction(insn, 0, 4), 0, 4); |
606 | insertBits(tmp, fieldFromInstruction(insn, 8, 3), 4, 3); |
607 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
608 | return S; |
609 | case 28: |
610 | tmp = 0x0; |
611 | insertBits(tmp, fieldFromInstruction(insn, 0, 4), 0, 4); |
612 | insertBits(tmp, fieldFromInstruction(insn, 8, 3), 4, 3); |
613 | MI.addOperand(Op: MCOperand::createImm(Val: tmp)); |
614 | tmp = fieldFromInstruction(insn, 4, 4); |
615 | if (!Check(S, DecodeLD8RegisterClass(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; } |
616 | return S; |
617 | } |
618 | } |
619 | |
620 | static unsigned decodeNumToSkip(const uint8_t *&Ptr) { |
621 | unsigned NumToSkip = *Ptr++; |
622 | NumToSkip |= (*Ptr++) << 8; |
623 | return NumToSkip; |
624 | } |
625 | |
626 | template <typename InsnType> |
627 | static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, |
628 | InsnType insn, uint64_t Address, |
629 | const MCDisassembler *DisAsm, |
630 | const MCSubtargetInfo &STI) { |
631 | const FeatureBitset &Bits = STI.getFeatureBits(); |
632 | |
633 | const uint8_t *Ptr = DecodeTable; |
634 | uint64_t CurFieldValue = 0; |
635 | DecodeStatus S = MCDisassembler::Success; |
636 | while (true) { |
637 | ptrdiff_t Loc = Ptr - DecodeTable; |
638 | const uint8_t DecoderOp = *Ptr++; |
639 | switch (DecoderOp) { |
640 | default: |
641 | errs() << Loc << ": Unexpected decode table opcode: " |
642 | << (int)DecoderOp << '\n'; |
643 | return MCDisassembler::Fail; |
644 | case MCD::OPC_ExtractField: { |
645 | // Decode the start value. |
646 | unsigned Start = decodeULEB128AndIncUnsafe(p&: Ptr); |
647 | unsigned Len = *Ptr++; |
648 | CurFieldValue = fieldFromInstruction(insn, Start, Len); |
649 | LLVM_DEBUG(dbgs() << Loc << ": OPC_ExtractField(" << Start << ", " |
650 | << Len << "): " << CurFieldValue << "\n" ); |
651 | break; |
652 | } |
653 | case MCD::OPC_FilterValue: |
654 | case MCD::OPC_FilterValueOrFail: { |
655 | bool IsFail = DecoderOp == MCD::OPC_FilterValueOrFail; |
656 | // Decode the field value. |
657 | uint64_t Val = decodeULEB128AndIncUnsafe(p&: Ptr); |
658 | bool Failed = Val != CurFieldValue; |
659 | unsigned NumToSkip = IsFail ? 0 : decodeNumToSkip(Ptr); |
660 | |
661 | // Note: Print NumToSkip even for OPC_FilterValueOrFail to simplify debug |
662 | // prints. |
663 | LLVM_DEBUG({ |
664 | StringRef OpName = IsFail ? "OPC_FilterValueOrFail" : "OPC_FilterValue" ; |
665 | dbgs() << Loc << ": " << OpName << '(' << Val << ", " << NumToSkip |
666 | << ") " << (Failed ? "FAIL:" : "PASS:" ) |
667 | << " continuing at " << (Ptr - DecodeTable) << '\n'; |
668 | }); |
669 | |
670 | // Perform the filter operation. |
671 | if (Failed) { |
672 | if (IsFail) |
673 | return MCDisassembler::Fail; |
674 | Ptr += NumToSkip; |
675 | } |
676 | break; |
677 | } |
678 | case MCD::OPC_CheckField: |
679 | case MCD::OPC_CheckFieldOrFail: { |
680 | bool IsFail = DecoderOp == MCD::OPC_CheckFieldOrFail; |
681 | // Decode the start value. |
682 | unsigned Start = decodeULEB128AndIncUnsafe(p&: Ptr); |
683 | unsigned Len = *Ptr; |
684 | uint64_t FieldValue = fieldFromInstruction(insn, Start, Len); |
685 | // Decode the field value. |
686 | unsigned PtrLen = 0; |
687 | uint64_t ExpectedValue = decodeULEB128(p: ++Ptr, n: &PtrLen); |
688 | Ptr += PtrLen; |
689 | bool Failed = ExpectedValue != FieldValue; |
690 | unsigned NumToSkip = IsFail ? 0 : decodeNumToSkip(Ptr); |
691 | |
692 | LLVM_DEBUG({ |
693 | StringRef OpName = IsFail ? "OPC_CheckFieldOrFail" : "OPC_CheckField" ; |
694 | dbgs() << Loc << ": " << OpName << '(' << Start << ", " << Len << ", " |
695 | << ExpectedValue << ", " << NumToSkip << "): FieldValue = " |
696 | << FieldValue << ", ExpectedValue = " << ExpectedValue << ": " |
697 | << (Failed ? "FAIL\n" : "PASS\n" ); |
698 | }); |
699 | |
700 | // If the actual and expected values don't match, skip or fail. |
701 | if (Failed) { |
702 | if (IsFail) |
703 | return MCDisassembler::Fail; |
704 | Ptr += NumToSkip; |
705 | } |
706 | break; |
707 | } |
708 | case MCD::OPC_CheckPredicate: |
709 | case MCD::OPC_CheckPredicateOrFail: { |
710 | bool IsFail = DecoderOp == MCD::OPC_CheckPredicateOrFail; |
711 | // Decode the Predicate Index value. |
712 | unsigned PIdx = decodeULEB128AndIncUnsafe(p&: Ptr); |
713 | unsigned NumToSkip = IsFail ? 0 : decodeNumToSkip(Ptr); |
714 | // Check the predicate. |
715 | bool Failed = !checkDecoderPredicate(Idx: PIdx, Bits); |
716 | |
717 | LLVM_DEBUG({ |
718 | StringRef OpName = IsFail ? "OPC_CheckPredicateOrFail" : "OPC_CheckPredicate" ; |
719 | dbgs() << Loc << ": " << OpName << '(' << PIdx << ", " << NumToSkip |
720 | << "): " << (Failed ? "FAIL\n" : "PASS\n" ); |
721 | }); |
722 | |
723 | if (Failed) { |
724 | if (IsFail) |
725 | return MCDisassembler::Fail; |
726 | Ptr += NumToSkip; |
727 | } |
728 | break; |
729 | } |
730 | case MCD::OPC_Decode: { |
731 | // Decode the Opcode value. |
732 | unsigned Opc = decodeULEB128AndIncUnsafe(p&: Ptr); |
733 | unsigned DecodeIdx = decodeULEB128AndIncUnsafe(p&: Ptr); |
734 | |
735 | MI.clear(); |
736 | MI.setOpcode(Opc); |
737 | bool DecodeComplete; |
738 | S = decodeToMCInst(DecodeIdx, S, insn, MI, Address, DisAsm, DecodeComplete); |
739 | assert(DecodeComplete); |
740 | |
741 | LLVM_DEBUG(dbgs() << Loc << ": OPC_Decode: opcode " << Opc |
742 | << ", using decoder " << DecodeIdx << ": " |
743 | << (S != MCDisassembler::Fail ? "PASS\n" : "FAIL\n" )); |
744 | return S; |
745 | } |
746 | case MCD::OPC_Fail: { |
747 | LLVM_DEBUG(dbgs() << Loc << ": OPC_Fail\n" ); |
748 | return MCDisassembler::Fail; |
749 | } |
750 | } |
751 | } |
752 | llvm_unreachable("bogosity detected in disassembler state machine!" ); |
753 | } |
754 | |
755 | |
756 | } // namespace |
757 | |