Coverage Report

Created: 2025-10-12 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/ARM/ARMInstPrinter.c
Line
Count
Source
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//===-- ARMInstPrinter.cpp - Convert ARM MCInst to assembly syntax --------===//
16
//
17
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
18
// See https://llvm.org/LICENSE.txt for license information.
19
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20
//
21
//===----------------------------------------------------------------------===//
22
//
23
// This class prints an ARM MCInst to a .s file.
24
//
25
//===----------------------------------------------------------------------===//
26
27
#include <capstone/arm.h>
28
29
#include <capstone/platform.h>
30
31
#include "../../Mapping.h"
32
#include "../../MCInst.h"
33
#include "../../MCInstPrinter.h"
34
#include "../../MCRegisterInfo.h"
35
#include "../../SStream.h"
36
37
#include "ARMAddressingModes.h"
38
#include "ARMBaseInfo.h"
39
#include "ARMDisassemblerExtension.h"
40
#include "ARMInstPrinter.h"
41
#include "ARMLinkage.h"
42
#include "ARMMapping.h"
43
44
#define GET_BANKEDREG_IMPL
45
#include "ARMGenSystemRegister.inc"
46
47
80.1k
#define CONCAT(a, b) CONCAT_(a, b)
48
80.1k
#define CONCAT_(a, b) a##_##b
49
50
#define DEBUG_TYPE "asm-printer"
51
52
// Static function declarations. These are functions which have the same identifiers
53
// over all architectures. Therefor they need to be static.
54
#ifndef CAPSTONE_DIET
55
static void printCustomAliasOperand(MCInst *MI, uint64_t Address,
56
            unsigned OpIdx, unsigned PrintMethodIdx,
57
            SStream *O);
58
#endif
59
static const char *getRegisterName(unsigned RegNo, unsigned AltIdx);
60
61
/// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing.
62
///
63
/// getSORegOffset returns an integer from 0-31, representing '32' as 0.
64
unsigned translateShiftImm(unsigned imm)
65
57.9k
{
66
  // lsr #32 and asr #32 exist, but should be encoded as a 0.
67
57.9k
  CS_ASSERT((imm & ~0x1f) == 0 && "Invalid shift encoding");
68
69
57.9k
  if (imm == 0)
70
5.61k
    return 32;
71
52.3k
  return imm;
72
57.9k
}
73
74
/// Prints the shift value with an immediate value.
75
static inline void printRegImmShift(MCInst *MI, SStream *O,
76
            ARM_AM_ShiftOpc ShOpc, unsigned ShImm,
77
            bool UseMarkup)
78
19.6k
{
79
19.6k
  add_cs_detail(MI, ARM_OP_GROUP_RegImmShift, ShOpc, ShImm);
80
19.6k
  if (ShOpc == ARM_AM_no_shift || (ShOpc == ARM_AM_lsl && !ShImm))
81
638
    return;
82
19.0k
  SStream_concat0(O, ", ");
83
84
19.0k
  CS_ASSERT(!(ShOpc == ARM_AM_ror && !ShImm) && "Cannot have ror #0");
85
19.0k
  SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
86
87
19.0k
  if (ShOpc != ARM_AM_rrx) {
88
18.4k
    SStream_concat0(O, " ");
89
18.4k
    if (getUseMarkup())
90
0
      SStream_concat0(O, "<imm:");
91
18.4k
    SStream_concat(O, "%s%d", "#", translateShiftImm(ShImm));
92
18.4k
    if (getUseMarkup())
93
0
      SStream_concat0(O, ">");
94
18.4k
  }
95
19.0k
}
96
97
static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
98
762k
{
99
762k
  add_cs_detail(MI, ARM_OP_GROUP_PredicateOperand, OpNum);
100
762k
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
101
762k
    MCInst_getOperand(MI, (OpNum)));
102
  // Handle the undefined 15 CC value here for printing so we don't abort().
103
762k
  if ((unsigned)CC == 15)
104
640
    SStream_concat0(O, "<und>");
105
761k
  else if (CC != ARMCC_AL)
106
124k
    SStream_concat0(O, ARMCondCodeToString(CC));
107
762k
}
108
109
static void printRegName(SStream *OS, unsigned RegNo)
110
3.22M
{
111
3.22M
  SStream_concat(OS, "%s%s", markup("<reg:"),
112
3.22M
           getRegisterName(RegNo, ARM_NoRegAltName));
113
3.22M
  SStream_concat0(OS, markup(">"));
114
3.22M
}
115
116
static inline void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
117
1.45M
{
118
1.45M
  add_cs_detail(MI, ARM_OP_GROUP_Operand, OpNo);
119
1.45M
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
120
1.45M
  if (MCOperand_isReg(Op)) {
121
1.19M
    unsigned Reg = MCOperand_getReg(Op);
122
1.19M
    printRegName(O, Reg);
123
1.19M
  } else if (MCOperand_isImm(Op)) {
124
257k
    SStream_concat(O, "%s", markup("<imm:"));
125
257k
    SStream_concat1(O, '#');
126
257k
    printInt64(O, MCOperand_getImm(Op));
127
257k
    SStream_concat0(O, markup(">"));
128
257k
  } else {
129
0
    CS_ASSERT_RET(0 && "Expressions are not supported.");
130
0
  }
131
1.45M
}
132
133
static inline void printRegisterList(MCInst *MI, unsigned OpNum, SStream *O)
134
36.5k
{
135
36.5k
  add_cs_detail(MI, ARM_OP_GROUP_RegisterList, OpNum);
136
36.5k
  if (MCInst_getOpcode(MI) != ARM_t2CLRM) {
137
36.4k
  }
138
139
36.5k
  SStream_concat0(O, "{");
140
243k
  for (unsigned i = OpNum, e = MCInst_getNumOperands(MI); i != e; ++i) {
141
206k
    if (i != OpNum)
142
169k
      SStream_concat0(O, ", ");
143
206k
    printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (i))));
144
206k
  }
145
36.5k
  SStream_concat0(O, "}");
146
36.5k
}
147
148
static inline void printSBitModifierOperand(MCInst *MI, unsigned OpNum,
149
              SStream *O)
150
238k
{
151
238k
  add_cs_detail(MI, ARM_OP_GROUP_SBitModifierOperand, OpNum);
152
238k
  if (MCOperand_getReg(MCInst_getOperand(MI, (OpNum)))) {
153
212k
    SStream_concat0(O, "s");
154
212k
  }
155
238k
}
156
157
static inline void printOperandAddr(MCInst *MI, uint64_t Address,
158
            unsigned OpNum, SStream *O)
159
47.3k
{
160
47.3k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
161
47.3k
  if (!MCOperand_isImm(Op) || !MI->csh->PrintBranchImmAsAddress ||
162
47.3k
      getUseMarkup()) {
163
0
    printOperand(MI, OpNum, O);
164
0
    return;
165
0
  }
166
47.3k
  int64_t Imm = MCOperand_getImm(Op);
167
  // For ARM instructions the PC offset is 8 bytes, for Thumb instructions it
168
  // is 4 bytes.
169
47.3k
  uint64_t Offset = ARM_getFeatureBits(MI->csh->mode, ARM_ModeThumb) ? 4 :
170
47.3k
                       8;
171
172
  // A Thumb instruction BLX(i) can be 16-bit aligned while targets Arm code
173
  // which is 32-bit aligned. The target address for the case is calculated as
174
  //   targetAddress = Align(PC,4) + imm32;
175
  // where
176
  //   Align(x, y) = y * (x DIV y);
177
47.3k
  if (MCInst_getOpcode(MI) == ARM_tBLXi)
178
285
    Address &= ~0x3;
179
180
47.3k
  uint64_t Target = Address + Imm + Offset;
181
182
47.3k
  Target &= 0xffffffff;
183
47.3k
  ARM_set_detail_op_imm(MI, OpNum, ARM_OP_IMM, Target);
184
47.3k
  printUInt64(O, Target);
185
47.3k
}
186
187
static inline void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNum,
188
               SStream *O)
189
17.0k
{
190
17.0k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbLdrLabelOperand, OpNum);
191
17.0k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
192
17.0k
  if (MCOperand_isExpr(MO1)) {
193
    // MO1.getExpr()->print(O, &MAI);
194
0
    return;
195
0
  }
196
197
17.0k
  SStream_concat(O, "%s", markup("<mem:"));
198
17.0k
  SStream_concat0(O, "[pc, ");
199
200
17.0k
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
201
202
  // Special value for #-0. All others are normal.
203
17.0k
  if (OffImm == INT32_MIN)
204
1.00k
    OffImm = 0;
205
17.0k
  SStream_concat(O, "%s", markup("<imm:"));
206
17.0k
  printInt32Bang(O, OffImm);
207
17.0k
  SStream_concat0(O, markup(">"));
208
17.0k
  SStream_concat(O, "%s", "]");
209
17.0k
  SStream_concat0(O, markup(">"));
210
17.0k
}
211
212
// so_reg is a 4-operand unit corresponding to register forms of the A5.1
213
// "Addressing Mode 1 - Data-processing operands" forms.  This includes:
214
//    REG 0   0           - e.g. R5
215
//    REG REG 0,SH_OPC    - e.g. R5, ROR R3
216
//    REG 0   IMM,SH_OPC  - e.g. R5, LSL #3
217
static inline void printSORegRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
218
6.40k
{
219
6.40k
  add_cs_detail(MI, ARM_OP_GROUP_SORegRegOperand, OpNum);
220
6.40k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
221
6.40k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
222
6.40k
  MCOperand *MO3 = MCInst_getOperand(MI, (OpNum + 2));
223
224
6.40k
  printRegName(O, MCOperand_getReg(MO1));
225
226
  // Print the shift opc.
227
6.40k
  ARM_AM_ShiftOpc ShOpc = ARM_AM_getSORegShOp(MCOperand_getImm(MO3));
228
6.40k
  SStream_concat(O, "%s", ", ");
229
6.40k
  SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
230
6.40k
  if (ShOpc == ARM_AM_rrx)
231
0
    return;
232
233
6.40k
  SStream_concat0(O, " ");
234
235
6.40k
  printRegName(O, MCOperand_getReg(MO2));
236
6.40k
}
237
238
static inline void printSORegImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
239
10.4k
{
240
10.4k
  add_cs_detail(MI, ARM_OP_GROUP_SORegImmOperand, OpNum);
241
10.4k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
242
10.4k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
243
244
10.4k
  printRegName(O, MCOperand_getReg(MO1));
245
246
  // Print the shift opc.
247
10.4k
  printRegImmShift(MI, O, ARM_AM_getSORegShOp(MCOperand_getImm(MO2)),
248
10.4k
       ARM_AM_getSORegOffset(MCOperand_getImm(MO2)),
249
10.4k
       getUseMarkup());
250
10.4k
}
251
252
//===--------------------------------------------------------------------===//
253
// Addressing Mode #2
254
//===--------------------------------------------------------------------===//
255
256
static inline void printAM2PreOrOffsetIndexOp(MCInst *MI, unsigned Op,
257
                SStream *O)
258
3.62k
{
259
3.62k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
260
3.62k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
261
3.62k
  MCOperand *MO3 = MCInst_getOperand(MI, (Op + 2));
262
263
3.62k
  SStream_concat(O, "%s", markup("<mem:"));
264
3.62k
  SStream_concat0(O, "[");
265
3.62k
  printRegName(O, MCOperand_getReg(MO1));
266
267
3.62k
  if (!MCOperand_getReg(MO2)) {
268
0
    if (ARM_AM_getAM2Offset(
269
0
          MCOperand_getImm(MO3))) { // Don't print +0.
270
0
      SStream_concat(
271
0
        O, "%s%s%s", ", ", markup("<imm:"), "#",
272
0
        ARM_AM_getAddrOpcStr(
273
0
          ARM_AM_getAM2Op(MCOperand_getImm(MO3))),
274
0
        ARM_AM_getAM2Offset(MCOperand_getImm(MO3)));
275
0
      SStream_concat0(O, markup(">"));
276
0
    }
277
0
    SStream_concat(O, "%s", "]");
278
0
    SStream_concat0(O, markup(">"));
279
0
    return;
280
0
  }
281
282
3.62k
  SStream_concat0(O, ", ");
283
3.62k
  SStream_concat0(O, ARM_AM_getAddrOpcStr(
284
3.62k
           ARM_AM_getAM2Op(MCOperand_getImm(MO3))));
285
3.62k
  printRegName(O, MCOperand_getReg(MO2));
286
287
3.62k
  printRegImmShift(MI, O, ARM_AM_getAM2ShiftOpc(MCOperand_getImm(MO3)),
288
3.62k
       ARM_AM_getAM2Offset(MCOperand_getImm(MO3)),
289
3.62k
       getUseMarkup());
290
3.62k
  SStream_concat(O, "%s", "]");
291
3.62k
  SStream_concat0(O, markup(">"));
292
3.62k
}
293
294
static inline void printAddrModeTBB(MCInst *MI, unsigned Op, SStream *O)
295
109
{
296
109
  add_cs_detail(MI, ARM_OP_GROUP_AddrModeTBB, Op);
297
109
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
298
109
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
299
109
  SStream_concat(O, "%s", markup("<mem:"));
300
109
  SStream_concat0(O, "[");
301
109
  printRegName(O, MCOperand_getReg(MO1));
302
109
  SStream_concat0(O, ", ");
303
109
  printRegName(O, MCOperand_getReg(MO2));
304
109
  SStream_concat(O, "%s", "]");
305
109
  SStream_concat0(O, markup(">"));
306
109
}
307
308
static inline void printAddrModeTBH(MCInst *MI, unsigned Op, SStream *O)
309
546
{
310
546
  add_cs_detail(MI, ARM_OP_GROUP_AddrModeTBH, Op);
311
546
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
312
546
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
313
546
  SStream_concat(O, "%s", markup("<mem:"));
314
546
  SStream_concat0(O, "[");
315
546
  printRegName(O, MCOperand_getReg(MO1));
316
546
  SStream_concat0(O, ", ");
317
546
  printRegName(O, MCOperand_getReg(MO2));
318
546
  SStream_concat(O, "%s%s%s%s%s", ", lsl ", markup("<imm:"), "#1",
319
546
           markup(">"), "]");
320
546
  SStream_concat0(O, markup(">"));
321
546
}
322
323
static inline void printAddrMode2Operand(MCInst *MI, unsigned Op, SStream *O)
324
10.1k
{
325
10.1k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode2Operand, Op);
326
10.1k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
327
328
10.1k
  if (!MCOperand_isReg(
329
10.1k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
330
0
    printOperand(MI, Op, O);
331
0
    return;
332
0
  }
333
334
10.1k
  printAM2PreOrOffsetIndexOp(MI, Op, O);
335
10.1k
}
336
337
static inline void printAddrMode2OffsetOperand(MCInst *MI, unsigned OpNum,
338
                 SStream *O)
339
8.18k
{
340
8.18k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode2OffsetOperand, OpNum);
341
8.18k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
342
8.18k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
343
344
8.18k
  if (!MCOperand_getReg(MO1)) {
345
4.96k
    unsigned ImmOffs = ARM_AM_getAM2Offset(MCOperand_getImm(MO2));
346
4.96k
    SStream_concat(O, "%s", markup("<imm:"));
347
4.96k
    SStream_concat1(O, '#');
348
4.96k
    SStream_concat(O, "%s",
349
4.96k
             ARM_AM_getAddrOpcStr(
350
4.96k
               ARM_AM_getAM2Op(MCOperand_getImm(MO2))));
351
4.96k
    printUInt32(O, ImmOffs);
352
4.96k
    SStream_concat0(O, markup(">"));
353
4.96k
    return;
354
4.96k
  }
355
356
3.22k
  SStream_concat0(O, ARM_AM_getAddrOpcStr(
357
3.22k
           ARM_AM_getAM2Op(MCOperand_getImm(MO2))));
358
3.22k
  printRegName(O, MCOperand_getReg(MO1));
359
360
3.22k
  printRegImmShift(MI, O, ARM_AM_getAM2ShiftOpc(MCOperand_getImm(MO2)),
361
3.22k
       ARM_AM_getAM2Offset(MCOperand_getImm(MO2)),
362
3.22k
       getUseMarkup());
363
3.22k
}
364
365
//===--------------------------------------------------------------------===//
366
// Addressing Mode #3
367
//===--------------------------------------------------------------------===//
368
369
static inline void printAM3PreOrOffsetIndexOp(MCInst *MI, unsigned Op,
370
                SStream *O, bool AlwaysPrintImm0)
371
4.74k
{
372
4.74k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
373
4.74k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
374
4.74k
  MCOperand *MO3 = MCInst_getOperand(MI, (Op + 2));
375
376
4.74k
  SStream_concat(O, "%s", markup("<mem:"));
377
4.74k
  SStream_concat0(O, "[");
378
379
4.74k
  printRegName(O, MCOperand_getReg(MO1));
380
381
4.74k
  if (MCOperand_getReg(MO2)) {
382
1.94k
    SStream_concat(O, "%s", ", ");
383
1.94k
    SStream_concat0(O, ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(
384
1.94k
             MCOperand_getImm(MO3))));
385
1.94k
    printRegName(O, MCOperand_getReg(MO2));
386
1.94k
    SStream_concat1(O, ']');
387
1.94k
    SStream_concat0(O, markup(">"));
388
1.94k
    return;
389
1.94k
  }
390
391
  // If the op is sub we have to print the immediate even if it is 0
392
2.79k
  unsigned ImmOffs = ARM_AM_getAM3Offset(MCOperand_getImm(MO3));
393
2.79k
  ARM_AM_AddrOpc op = ARM_AM_getAM3Op(MCOperand_getImm(MO3));
394
395
2.79k
  if (AlwaysPrintImm0 || ImmOffs || (op == ARM_AM_sub)) {
396
2.58k
    SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), "#",
397
2.58k
             ARM_AM_getAddrOpcStr(op));
398
2.58k
    printUInt32(O, ImmOffs);
399
2.58k
    SStream_concat0(O, markup(">"));
400
2.58k
  }
401
2.79k
  SStream_concat1(O, ']');
402
2.79k
  SStream_concat0(O, markup(">"));
403
2.79k
}
404
405
#define DEFINE_printAddrMode3Operand(AlwaysPrintImm0) \
406
  static inline void CONCAT(printAddrMode3Operand, AlwaysPrintImm0)( \
407
    MCInst * MI, unsigned Op, SStream *O) \
408
4.74k
  { \
409
4.74k
    add_cs_detail(MI, \
410
4.74k
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
4.74k
             AlwaysPrintImm0), \
412
4.74k
            Op, AlwaysPrintImm0); \
413
4.74k
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
4.74k
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
4.74k
\
419
4.74k
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
4.74k
  }
ARMInstPrinter.c:printAddrMode3Operand_0
Line
Count
Source
408
3.20k
  { \
409
3.20k
    add_cs_detail(MI, \
410
3.20k
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
3.20k
             AlwaysPrintImm0), \
412
3.20k
            Op, AlwaysPrintImm0); \
413
3.20k
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
3.20k
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
3.20k
\
419
3.20k
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
3.20k
  }
ARMInstPrinter.c:printAddrMode3Operand_1
Line
Count
Source
408
1.54k
  { \
409
1.54k
    add_cs_detail(MI, \
410
1.54k
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
1.54k
             AlwaysPrintImm0), \
412
1.54k
            Op, AlwaysPrintImm0); \
413
1.54k
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
1.54k
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
1.54k
\
419
1.54k
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
1.54k
  }
421
DEFINE_printAddrMode3Operand(false);
422
DEFINE_printAddrMode3Operand(true);
423
424
static inline void printAddrMode3OffsetOperand(MCInst *MI, unsigned OpNum,
425
                 SStream *O)
426
3.22k
{
427
3.22k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode3OffsetOperand, OpNum);
428
3.22k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
429
3.22k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
430
431
3.22k
  if (MCOperand_getReg(MO1)) {
432
1.46k
    SStream_concat0(O, ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(
433
1.46k
             MCOperand_getImm(MO2))));
434
1.46k
    printRegName(O, MCOperand_getReg(MO1));
435
1.46k
    return;
436
1.46k
  }
437
438
1.76k
  unsigned ImmOffs = ARM_AM_getAM3Offset(MCOperand_getImm(MO2));
439
1.76k
  SStream_concat(O, "%s", markup("<imm:"));
440
1.76k
  SStream_concat1(O, '#');
441
1.76k
  SStream_concat(
442
1.76k
    O, "%s",
443
1.76k
    ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(MCOperand_getImm(MO2))));
444
1.76k
  printUInt32(O, ImmOffs);
445
1.76k
  SStream_concat0(O, markup(">"));
446
1.76k
}
447
448
static inline void printPostIdxImm8Operand(MCInst *MI, unsigned OpNum,
449
             SStream *O)
450
308
{
451
308
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxImm8Operand, OpNum);
452
308
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
453
308
  unsigned Imm = MCOperand_getImm(MO);
454
308
  SStream_concat(O, "%s", markup("<imm:"));
455
308
  SStream_concat1(O, '#');
456
308
  SStream_concat(O, "%s", ((Imm & 256) ? "" : "-"));
457
308
  printUInt32(O, (Imm & 0xff));
458
308
  SStream_concat0(O, markup(">"));
459
308
}
460
461
static inline void printPostIdxRegOperand(MCInst *MI, unsigned OpNum,
462
            SStream *O)
463
2.27k
{
464
2.27k
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxRegOperand, OpNum);
465
2.27k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
466
2.27k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
467
468
2.27k
  SStream_concat0(O, (MCOperand_getImm(MO2) ? "" : "-"));
469
2.27k
  printRegName(O, MCOperand_getReg(MO1));
470
2.27k
}
471
472
static inline void printPostIdxImm8s4Operand(MCInst *MI, unsigned OpNum,
473
               SStream *O)
474
7.84k
{
475
7.84k
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxImm8s4Operand, OpNum);
476
7.84k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
477
7.84k
  unsigned Imm = MCOperand_getImm(MO);
478
7.84k
  SStream_concat(O, "%s", markup("<imm:"));
479
7.84k
  SStream_concat1(O, '#');
480
7.84k
  SStream_concat(O, "%s", ((Imm & 256) ? "" : "-"));
481
7.84k
  printUInt32(O, (Imm & 0xff) << 2);
482
7.84k
  SStream_concat0(O, markup(">"));
483
7.84k
}
484
485
#define DEFINE_printMveAddrModeRQOperand(shift) \
486
  static inline void CONCAT(printMveAddrModeRQOperand, shift)( \
487
    MCInst * MI, unsigned OpNum, SStream *O) \
488
178
  { \
489
178
    add_cs_detail( \
490
178
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
178
      OpNum, shift); \
492
178
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
178
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
178
\
495
178
    SStream_concat(O, "%s", markup("<mem:")); \
496
178
    SStream_concat0(O, "["); \
497
178
    printRegName(O, MCOperand_getReg(MO1)); \
498
178
    SStream_concat0(O, ", "); \
499
178
    printRegName(O, MCOperand_getReg(MO2)); \
500
178
\
501
178
    if (shift > 0) \
502
178
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
123
           getUseMarkup()); \
504
178
\
505
178
    SStream_concat(O, "%s", "]"); \
506
178
    SStream_concat0(O, markup(">")); \
507
178
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_0
Line
Count
Source
488
55
  { \
489
55
    add_cs_detail( \
490
55
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
55
      OpNum, shift); \
492
55
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
55
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
55
\
495
55
    SStream_concat(O, "%s", markup("<mem:")); \
496
55
    SStream_concat0(O, "["); \
497
55
    printRegName(O, MCOperand_getReg(MO1)); \
498
55
    SStream_concat0(O, ", "); \
499
55
    printRegName(O, MCOperand_getReg(MO2)); \
500
55
\
501
55
    if (shift > 0) \
502
55
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
0
           getUseMarkup()); \
504
55
\
505
55
    SStream_concat(O, "%s", "]"); \
506
55
    SStream_concat0(O, markup(">")); \
507
55
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_3
Line
Count
Source
488
18
  { \
489
18
    add_cs_detail( \
490
18
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
18
      OpNum, shift); \
492
18
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
18
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
18
\
495
18
    SStream_concat(O, "%s", markup("<mem:")); \
496
18
    SStream_concat0(O, "["); \
497
18
    printRegName(O, MCOperand_getReg(MO1)); \
498
18
    SStream_concat0(O, ", "); \
499
18
    printRegName(O, MCOperand_getReg(MO2)); \
500
18
\
501
18
    if (shift > 0) \
502
18
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
18
           getUseMarkup()); \
504
18
\
505
18
    SStream_concat(O, "%s", "]"); \
506
18
    SStream_concat0(O, markup(">")); \
507
18
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_1
Line
Count
Source
488
95
  { \
489
95
    add_cs_detail( \
490
95
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
95
      OpNum, shift); \
492
95
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
95
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
95
\
495
95
    SStream_concat(O, "%s", markup("<mem:")); \
496
95
    SStream_concat0(O, "["); \
497
95
    printRegName(O, MCOperand_getReg(MO1)); \
498
95
    SStream_concat0(O, ", "); \
499
95
    printRegName(O, MCOperand_getReg(MO2)); \
500
95
\
501
95
    if (shift > 0) \
502
95
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
95
           getUseMarkup()); \
504
95
\
505
95
    SStream_concat(O, "%s", "]"); \
506
95
    SStream_concat0(O, markup(">")); \
507
95
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_2
Line
Count
Source
488
10
  { \
489
10
    add_cs_detail( \
490
10
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
10
      OpNum, shift); \
492
10
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
10
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
10
\
495
10
    SStream_concat(O, "%s", markup("<mem:")); \
496
10
    SStream_concat0(O, "["); \
497
10
    printRegName(O, MCOperand_getReg(MO1)); \
498
10
    SStream_concat0(O, ", "); \
499
10
    printRegName(O, MCOperand_getReg(MO2)); \
500
10
\
501
10
    if (shift > 0) \
502
10
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
10
           getUseMarkup()); \
504
10
\
505
10
    SStream_concat(O, "%s", "]"); \
506
10
    SStream_concat0(O, markup(">")); \
507
10
  }
508
DEFINE_printMveAddrModeRQOperand(0);
509
DEFINE_printMveAddrModeRQOperand(3);
510
DEFINE_printMveAddrModeRQOperand(1);
511
DEFINE_printMveAddrModeRQOperand(2);
512
513
#define DEFINE_printAddrMode5Operand(AlwaysPrintImm0) \
514
  static inline void CONCAT(printAddrMode5Operand, AlwaysPrintImm0)( \
515
    MCInst * MI, unsigned OpNum, SStream *O) \
516
15.9k
  { \
517
15.9k
    add_cs_detail(MI, \
518
15.9k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
15.9k
             AlwaysPrintImm0), \
520
15.9k
            OpNum, AlwaysPrintImm0); \
521
15.9k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
15.9k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
15.9k
\
524
15.9k
    SStream_concat(O, "%s", markup("<mem:")); \
525
15.9k
    SStream_concat0(O, "["); \
526
15.9k
    printRegName(O, MCOperand_getReg(MO1)); \
527
15.9k
\
528
15.9k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
15.9k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
15.9k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
15.6k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
15.6k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
15.6k
      printUInt32(O, ImmOffs * 4); \
534
15.6k
      SStream_concat0(O, markup(">")); \
535
15.6k
    } \
536
15.9k
    SStream_concat(O, "%s", "]"); \
537
15.9k
    SStream_concat0(O, markup(">")); \
538
15.9k
  }
ARMInstPrinter.c:printAddrMode5Operand_0
Line
Count
Source
516
8.02k
  { \
517
8.02k
    add_cs_detail(MI, \
518
8.02k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
8.02k
             AlwaysPrintImm0), \
520
8.02k
            OpNum, AlwaysPrintImm0); \
521
8.02k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
8.02k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
8.02k
\
524
8.02k
    SStream_concat(O, "%s", markup("<mem:")); \
525
8.02k
    SStream_concat0(O, "["); \
526
8.02k
    printRegName(O, MCOperand_getReg(MO1)); \
527
8.02k
\
528
8.02k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
8.02k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
8.02k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
7.72k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
7.72k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
7.72k
      printUInt32(O, ImmOffs * 4); \
534
7.72k
      SStream_concat0(O, markup(">")); \
535
7.72k
    } \
536
8.02k
    SStream_concat(O, "%s", "]"); \
537
8.02k
    SStream_concat0(O, markup(">")); \
538
8.02k
  }
ARMInstPrinter.c:printAddrMode5Operand_1
Line
Count
Source
516
7.90k
  { \
517
7.90k
    add_cs_detail(MI, \
518
7.90k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
7.90k
             AlwaysPrintImm0), \
520
7.90k
            OpNum, AlwaysPrintImm0); \
521
7.90k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
7.90k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
7.90k
\
524
7.90k
    SStream_concat(O, "%s", markup("<mem:")); \
525
7.90k
    SStream_concat0(O, "["); \
526
7.90k
    printRegName(O, MCOperand_getReg(MO1)); \
527
7.90k
\
528
7.90k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
7.90k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
7.90k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
7.90k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
7.90k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
7.90k
      printUInt32(O, ImmOffs * 4); \
534
7.90k
      SStream_concat0(O, markup(">")); \
535
7.90k
    } \
536
7.90k
    SStream_concat(O, "%s", "]"); \
537
7.90k
    SStream_concat0(O, markup(">")); \
538
7.90k
  }
539
DEFINE_printAddrMode5Operand(false);
540
DEFINE_printAddrMode5Operand(true);
541
542
#define DEFINE_printAddrMode5FP16Operand(AlwaysPrintImm0) \
543
  static inline void CONCAT(printAddrMode5FP16Operand, AlwaysPrintImm0)( \
544
    MCInst * MI, unsigned OpNum, SStream *O) \
545
360
  { \
546
360
    add_cs_detail(MI, \
547
360
            CONCAT(ARM_OP_GROUP_AddrMode5FP16Operand, \
548
360
             AlwaysPrintImm0), \
549
360
            OpNum, AlwaysPrintImm0); \
550
360
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
551
360
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
552
360
\
553
360
    if (!MCOperand_isReg(MO1)) { \
554
0
      printOperand(MI, OpNum, O); \
555
0
      return; \
556
0
    } \
557
360
\
558
360
    SStream_concat(O, "%s", markup("<mem:")); \
559
360
    SStream_concat0(O, "["); \
560
360
    printRegName(O, MCOperand_getReg(MO1)); \
561
360
\
562
360
    unsigned ImmOffs = \
563
360
      ARM_AM_getAM5FP16Offset(MCOperand_getImm(MO2)); \
564
360
    unsigned Op = ARM_AM_getAM5FP16Op(MCOperand_getImm(MO2)); \
565
360
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
566
285
      SStream_concat( \
567
285
        O, "%s%s%s%s", ", ", markup("<imm:"), "#", \
568
285
        ARM_AM_getAddrOpcStr(ARM_AM_getAM5FP16Op( \
569
285
          MCOperand_getImm(MO2)))); \
570
285
      printUInt32(O, ImmOffs * 2); \
571
285
      SStream_concat0(O, markup(">")); \
572
285
    } \
573
360
    SStream_concat(O, "%s", "]"); \
574
360
    SStream_concat0(O, markup(">")); \
575
360
  }
576
DEFINE_printAddrMode5FP16Operand(false);
577
578
static inline void printAddrMode6Operand(MCInst *MI, unsigned OpNum, SStream *O)
579
33.8k
{
580
33.8k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode6Operand, OpNum);
581
33.8k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
582
33.8k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
583
584
33.8k
  SStream_concat(O, "%s", markup("<mem:"));
585
33.8k
  SStream_concat0(O, "[");
586
33.8k
  printRegName(O, MCOperand_getReg(MO1));
587
33.8k
  if (MCOperand_getImm(MO2)) {
588
14.5k
    SStream_concat(O, "%s", ":");
589
14.5k
    printInt64(O, ((uint32_t)MCOperand_getImm(MO2)) << 3);
590
14.5k
  }
591
33.8k
  SStream_concat(O, "%s", "]");
592
33.8k
  SStream_concat0(O, markup(">"));
593
33.8k
}
594
595
static inline void printAddrMode7Operand(MCInst *MI, unsigned OpNum, SStream *O)
596
32.3k
{
597
32.3k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode7Operand, OpNum);
598
32.3k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
599
32.3k
  SStream_concat(O, "%s", markup("<mem:"));
600
32.3k
  SStream_concat0(O, "[");
601
32.3k
  printRegName(O, MCOperand_getReg(MO1));
602
32.3k
  SStream_concat(O, "%s", "]");
603
32.3k
  SStream_concat0(O, markup(">"));
604
32.3k
}
605
606
static inline void printAddrMode6OffsetOperand(MCInst *MI, unsigned OpNum,
607
                 SStream *O)
608
11.7k
{
609
11.7k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode6OffsetOperand, OpNum);
610
11.7k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
611
11.7k
  if (MCOperand_getReg(MO) == 0)
612
2.44k
    SStream_concat0(O, "!");
613
9.26k
  else {
614
9.26k
    SStream_concat0(O, ", ");
615
9.26k
    printRegName(O, MCOperand_getReg(MO));
616
9.26k
  }
617
11.7k
}
618
619
static inline void printBitfieldInvMaskImmOperand(MCInst *MI, unsigned OpNum,
620
              SStream *O)
621
1.08k
{
622
1.08k
  add_cs_detail(MI, ARM_OP_GROUP_BitfieldInvMaskImmOperand, OpNum);
623
1.08k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
624
1.08k
  uint32_t v = ~MCOperand_getImm(MO);
625
1.08k
  int32_t lsb = CountTrailingZeros_32(v);
626
1.08k
  int32_t width = (32 - countLeadingZeros(v)) - lsb;
627
628
1.08k
  SStream_concat(O, "%s", markup("<imm:"));
629
1.08k
  SStream_concat1(O, '#');
630
1.08k
  printInt32(O, lsb);
631
1.08k
  SStream_concat(O, "%s%s%s", markup(">"), ", ", markup("<imm:"));
632
1.08k
  printInt32Bang(O, width);
633
1.08k
  SStream_concat0(O, markup(">"));
634
1.08k
}
635
636
static inline void printMemBOption(MCInst *MI, unsigned OpNum, SStream *O)
637
2.48k
{
638
2.48k
  add_cs_detail(MI, ARM_OP_GROUP_MemBOption, OpNum);
639
2.48k
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
640
2.48k
  SStream_concat0(O, ARM_MB_MemBOptToString(
641
2.48k
           val, ARM_getFeatureBits(MI->csh->mode,
642
2.48k
                 ARM_HasV8Ops)));
643
2.48k
}
644
645
static inline void printInstSyncBOption(MCInst *MI, unsigned OpNum, SStream *O)
646
3.76k
{
647
3.76k
  add_cs_detail(MI, ARM_OP_GROUP_InstSyncBOption, OpNum);
648
3.76k
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
649
3.76k
  SStream_concat0(O, ARM_ISB_InstSyncBOptToString(val));
650
3.76k
}
651
652
static inline void printTraceSyncBOption(MCInst *MI, unsigned OpNum, SStream *O)
653
0
{
654
0
  add_cs_detail(MI, ARM_OP_GROUP_TraceSyncBOption, OpNum);
655
0
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
656
0
  SStream_concat0(O, ARM_TSB_TraceSyncBOptToString(val));
657
0
}
658
659
static inline void printShiftImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
660
1.48k
{
661
1.48k
  add_cs_detail(MI, ARM_OP_GROUP_ShiftImmOperand, OpNum);
662
1.48k
  unsigned ShiftOp = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
663
1.48k
  bool isASR = (ShiftOp & (1 << 5)) != 0;
664
1.48k
  unsigned Amt = ShiftOp & 0x1f;
665
1.48k
  if (isASR) {
666
363
    SStream_concat(O, "%s%s%s", ", asr ", markup("<imm:"), "#");
667
363
    printUInt32(O, Amt == 0 ? 32 : Amt);
668
363
    SStream_concat0(O, markup(">"));
669
1.12k
  } else if (Amt) {
670
599
    SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
671
599
    printUInt32(O, Amt);
672
599
    SStream_concat0(O, markup(">"));
673
599
  }
674
1.48k
}
675
676
static inline void printPKHLSLShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
677
301
{
678
301
  add_cs_detail(MI, ARM_OP_GROUP_PKHLSLShiftImm, OpNum);
679
301
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
680
301
  if (Imm == 0)
681
170
    return;
682
683
131
  SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
684
131
  printUInt32(O, Imm);
685
131
  SStream_concat0(O, markup(">"));
686
131
}
687
688
static inline void printPKHASRShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
689
235
{
690
235
  add_cs_detail(MI, ARM_OP_GROUP_PKHASRShiftImm, OpNum);
691
235
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
692
  // A shift amount of 32 is encoded as 0.
693
235
  if (Imm == 0)
694
88
    Imm = 32;
695
696
235
  SStream_concat(O, "%s%s%s", ", asr ", markup("<imm:"), "#");
697
235
  printUInt32(O, Imm);
698
235
  SStream_concat0(O, markup(">"));
699
235
}
700
701
static inline void printGPRPairOperand(MCInst *MI, unsigned OpNum, SStream *O)
702
352
{
703
352
  add_cs_detail(MI, ARM_OP_GROUP_GPRPairOperand, OpNum);
704
352
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
705
352
  printRegName(O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_0));
706
352
  SStream_concat0(O, ", ");
707
352
  printRegName(O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_1));
708
352
}
709
710
static inline void printSetendOperand(MCInst *MI, unsigned OpNum, SStream *O)
711
86
{
712
86
  add_cs_detail(MI, ARM_OP_GROUP_SetendOperand, OpNum);
713
86
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
714
86
  if (MCOperand_getImm(Op))
715
20
    SStream_concat0(O, "be");
716
66
  else
717
66
    SStream_concat0(O, "le");
718
86
}
719
720
static inline void printCPSIMod(MCInst *MI, unsigned OpNum, SStream *O)
721
720
{
722
720
  add_cs_detail(MI, ARM_OP_GROUP_CPSIMod, OpNum);
723
720
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
724
720
  SStream_concat0(O, ARM_PROC_IModToString(MCOperand_getImm(Op)));
725
720
}
726
727
static inline void printCPSIFlag(MCInst *MI, unsigned OpNum, SStream *O)
728
720
{
729
720
  add_cs_detail(MI, ARM_OP_GROUP_CPSIFlag, OpNum);
730
720
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
731
720
  unsigned IFlags = MCOperand_getImm(Op);
732
2.88k
  for (int i = 2; i >= 0; --i)
733
2.16k
    if (IFlags & (1 << i))
734
947
      SStream_concat0(O, ARM_PROC_IFlagsToString(1 << i));
735
736
720
  if (IFlags == 0)
737
202
    SStream_concat0(O, "none");
738
720
}
739
740
static inline void printMSRMaskOperand(MCInst *MI, unsigned OpNum, SStream *O)
741
5.28k
{
742
5.28k
  add_cs_detail(MI, ARM_OP_GROUP_MSRMaskOperand, OpNum);
743
5.28k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
744
745
5.28k
  if (ARM_getFeatureBits(MI->csh->mode, ARM_FeatureMClass)) {
746
4.14k
    unsigned SYSm = MCOperand_getImm(Op) & 0xFFF; // 12-bit SYSm
747
4.14k
    unsigned Opcode = MCInst_getOpcode(MI);
748
749
    // For writes, handle extended mask bits if the DSP extension is
750
    // present.
751
4.14k
    if (Opcode == ARM_t2MSR_M &&
752
3.22k
        ARM_getFeatureBits(MI->csh->mode, ARM_FeatureDSP)) {
753
3.22k
      const ARMSysReg_MClassSysReg *TheReg =
754
3.22k
        ARMSysReg_lookupMClassSysRegBy12bitSYSmValue(
755
3.22k
          SYSm);
756
3.22k
      if (TheReg && MClassSysReg_isInRequiredFeatures(
757
1.24k
                TheReg, ARM_FeatureDSP)) {
758
185
        SStream_concat0(O, TheReg->Name);
759
185
        return;
760
185
      }
761
3.22k
    }
762
763
    // Handle the basic 8-bit mask.
764
3.95k
    SYSm &= 0xff;
765
3.95k
    if (Opcode == ARM_t2MSR_M &&
766
3.03k
        ARM_getFeatureBits(MI->csh->mode, ARM_HasV7Ops)) {
767
      // ARMv7-M deprecates using MSR APSR without a _<bits> qualifier as
768
      // an alias for MSR APSR_nzcvq.
769
3.03k
      const ARMSysReg_MClassSysReg *TheReg =
770
3.03k
        ARMSysReg_lookupMClassSysRegAPSRNonDeprecated(
771
3.03k
          SYSm);
772
3.03k
      if (TheReg) {
773
590
        SStream_concat0(O, TheReg->Name);
774
590
        return;
775
590
      }
776
3.03k
    }
777
778
3.36k
    const ARMSysReg_MClassSysReg *TheReg =
779
3.36k
      ARMSysReg_lookupMClassSysRegBy8bitSYSmValue(SYSm);
780
3.36k
    if (TheReg) {
781
3.04k
      SStream_concat0(O, TheReg->Name);
782
3.04k
      return;
783
3.04k
    }
784
785
321
    printUInt32(O, SYSm);
786
787
321
    return;
788
3.36k
  }
789
790
  // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
791
  // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
792
1.14k
  unsigned SpecRegRBit = MCOperand_getImm(Op) >> 4;
793
1.14k
  unsigned Mask = MCOperand_getImm(Op) & 0xf;
794
795
1.14k
  if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
796
266
    SStream_concat0(O, "apsr_");
797
266
    switch (Mask) {
798
0
    default:
799
0
      CS_ASSERT_RET(0 && "Unexpected mask value!");
800
24
    case 4:
801
24
      SStream_concat0(O, "g");
802
24
      return;
803
32
    case 8:
804
32
      SStream_concat0(O, "nzcvq");
805
32
      return;
806
210
    case 12:
807
210
      SStream_concat0(O, "nzcvqg");
808
210
      return;
809
266
    }
810
266
  }
811
812
881
  if (SpecRegRBit)
813
578
    SStream_concat0(O, "spsr");
814
303
  else
815
303
    SStream_concat0(O, "cpsr");
816
817
881
  if (Mask) {
818
367
    SStream_concat0(O, "_");
819
820
367
    if (Mask & 8)
821
283
      SStream_concat0(O, "f");
822
823
367
    if (Mask & 4)
824
332
      SStream_concat0(O, "s");
825
826
367
    if (Mask & 2)
827
318
      SStream_concat0(O, "x");
828
829
367
    if (Mask & 1)
830
275
      SStream_concat0(O, "c");
831
367
  }
832
881
}
833
834
static inline void printBankedRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
835
1.08k
{
836
1.08k
  add_cs_detail(MI, ARM_OP_GROUP_BankedRegOperand, OpNum);
837
1.08k
  uint32_t Banked = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
838
1.08k
  const ARMBankedReg_BankedReg *TheReg =
839
1.08k
    ARMBankedReg_lookupBankedRegByEncoding(Banked);
840
841
1.08k
  const char *Name = TheReg->Name;
842
843
  // uint32_t isSPSR = (Banked & 0x20) >> 5;
844
  // if (isSPSR)
845
  //  Name.replace(0, 4, "SPSR"); // convert 'spsr_' to 'SPSR_'
846
1.08k
  SStream_concat0(O, Name);
847
1.08k
}
848
849
static inline void printMandatoryPredicateOperand(MCInst *MI, unsigned OpNum,
850
              SStream *O)
851
16.0k
{
852
16.0k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryPredicateOperand, OpNum);
853
16.0k
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
854
16.0k
    MCInst_getOperand(MI, (OpNum)));
855
16.0k
  SStream_concat0(O, ARMCondCodeToString(CC));
856
16.0k
}
857
858
static inline void
859
printMandatoryRestrictedPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
860
9.38k
{
861
9.38k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryRestrictedPredicateOperand,
862
9.38k
          OpNum);
863
9.38k
  if ((ARMCC_CondCodes)MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) ==
864
9.38k
      ARMCC_HS)
865
1.51k
    SStream_concat0(O, "cs");
866
7.87k
  else
867
7.87k
    printMandatoryPredicateOperand(MI, OpNum, O);
868
9.38k
}
869
870
static inline void
871
printMandatoryInvertedPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
872
1.53k
{
873
1.53k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryInvertedPredicateOperand,
874
1.53k
          OpNum);
875
1.53k
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
876
1.53k
    MCInst_getOperand(MI, (OpNum)));
877
1.53k
  SStream_concat0(O, ARMCondCodeToString(ARMCC_getOppositeCondition(CC)));
878
1.53k
}
879
880
static inline void printNoHashImmediate(MCInst *MI, unsigned OpNum, SStream *O)
881
27.1k
{
882
27.1k
  add_cs_detail(MI, ARM_OP_GROUP_NoHashImmediate, OpNum);
883
27.1k
  printInt64(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
884
27.1k
}
885
886
static inline void printPImmediate(MCInst *MI, unsigned OpNum, SStream *O)
887
56.6k
{
888
56.6k
  add_cs_detail(MI, ARM_OP_GROUP_PImmediate, OpNum);
889
56.6k
  SStream_concat(O, "%s%d", "p",
890
56.6k
           MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
891
56.6k
}
892
893
static inline void printCImmediate(MCInst *MI, unsigned OpNum, SStream *O)
894
104k
{
895
104k
  add_cs_detail(MI, ARM_OP_GROUP_CImmediate, OpNum);
896
104k
  SStream_concat(O, "%s%d", "c",
897
104k
           MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
898
104k
}
899
900
static inline void printCoprocOptionImm(MCInst *MI, unsigned OpNum, SStream *O)
901
3.55k
{
902
3.55k
  add_cs_detail(MI, ARM_OP_GROUP_CoprocOptionImm, OpNum);
903
3.55k
  SStream_concat(O, "%s", "{");
904
3.55k
  printInt64(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
905
3.55k
  SStream_concat0(O, "}");
906
3.55k
}
907
908
#define DEFINE_printAdrLabelOperand(scale) \
909
  static inline void CONCAT(printAdrLabelOperand, scale)( \
910
    MCInst * MI, unsigned OpNum, SStream *O) \
911
14.1k
  { \
912
14.1k
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_AdrLabelOperand, scale), \
913
14.1k
            OpNum, scale); \
914
14.1k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
915
14.1k
\
916
14.1k
    if (MCOperand_isExpr(MO)) { \
917
0
      return; \
918
0
    } \
919
14.1k
\
920
14.1k
    int32_t OffImm = (uint32_t)MCOperand_getImm(MO) << scale; \
921
14.1k
\
922
14.1k
    SStream_concat0(O, markup("<imm:")); \
923
14.1k
    if (OffImm == INT32_MIN) \
924
14.1k
      SStream_concat0(O, "#-0"); \
925
14.1k
    else if (OffImm < 0) { \
926
171
      printInt32Bang(O, OffImm); \
927
13.9k
    } else { \
928
13.9k
      printInt32Bang(O, OffImm); \
929
13.9k
    } \
930
14.1k
    SStream_concat0(O, markup(">")); \
931
14.1k
  }
932
479
DEFINE_printAdrLabelOperand(0);
933
13.6k
DEFINE_printAdrLabelOperand(2);
934
935
#define DEFINE_printAdrLabelOperandAddr(scale) \
936
  static inline void CONCAT(printAdrLabelOperandAddr, scale)( \
937
    MCInst * MI, uint64_t Address, unsigned OpNum, SStream *O) \
938
13.6k
  { \
939
13.6k
    CONCAT(printAdrLabelOperand, scale)(MI, OpNum, O); \
940
13.6k
  }
941
DEFINE_printAdrLabelOperandAddr(2);
942
943
static inline void printThumbS4ImmOperand(MCInst *MI, unsigned OpNum,
944
            SStream *O)
945
16.7k
{
946
16.7k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbS4ImmOperand, OpNum);
947
16.7k
  SStream_concat(O, "%s", markup("<imm:"));
948
16.7k
  printInt64Bang(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) * 4);
949
16.7k
  SStream_concat0(O, markup(">"));
950
16.7k
}
951
952
static inline void printThumbSRImm(MCInst *MI, unsigned OpNum, SStream *O)
953
40.3k
{
954
40.3k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbSRImm, OpNum);
955
40.3k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
956
40.3k
  SStream_concat(O, "%s", markup("<imm:"));
957
40.3k
  printUInt32Bang(O, (Imm == 0 ? 32 : Imm));
958
40.3k
  SStream_concat0(O, markup(">"));
959
40.3k
}
960
961
static inline void printThumbITMask(MCInst *MI, unsigned OpNum, SStream *O)
962
7.40k
{
963
7.40k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbITMask, OpNum);
964
  // (3 - the number of trailing zeros) is the number of then / else.
965
7.40k
  unsigned Mask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
966
7.40k
  unsigned NumTZ = CountTrailingZeros_32(Mask);
967
968
26.7k
  for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
969
19.3k
    if ((Mask >> Pos) & 1)
970
6.55k
      SStream_concat0(O, "e");
971
972
12.7k
    else
973
12.7k
      SStream_concat0(O, "t");
974
19.3k
  }
975
7.40k
}
976
977
static inline void printThumbAddrModeRROperand(MCInst *MI, unsigned Op,
978
                 SStream *O)
979
25.4k
{
980
25.4k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeRROperand, Op);
981
25.4k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
982
25.4k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
983
984
25.4k
  if (!MCOperand_isReg(
985
25.4k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
986
0
    printOperand(MI, Op, O);
987
0
    return;
988
0
  }
989
990
25.4k
  SStream_concat(O, "%s", markup("<mem:"));
991
25.4k
  SStream_concat0(O, "[");
992
25.4k
  printRegName(O, MCOperand_getReg(MO1));
993
25.4k
  unsigned RegNum = MCOperand_getReg(MO2);
994
25.4k
  if (RegNum) {
995
25.4k
    SStream_concat0(O, ", ");
996
25.4k
    printRegName(O, RegNum);
997
25.4k
  }
998
25.4k
  SStream_concat(O, "%s", "]");
999
25.4k
  SStream_concat0(O, markup(">"));
1000
25.4k
}
1001
1002
static inline void printThumbAddrModeImm5SOperand(MCInst *MI, unsigned Op,
1003
              SStream *O, unsigned Scale)
1004
130k
{
1005
130k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
1006
130k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
1007
1008
130k
  if (!MCOperand_isReg(
1009
130k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
1010
0
    printOperand(MI, Op, O);
1011
0
    return;
1012
0
  }
1013
1014
130k
  SStream_concat(O, "%s", markup("<mem:"));
1015
130k
  SStream_concat0(O, "[");
1016
130k
  printRegName(O, MCOperand_getReg(MO1));
1017
130k
  unsigned ImmOffs = MCOperand_getImm(MO2);
1018
130k
  if (ImmOffs) {
1019
122k
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
1020
122k
    printUInt32Bang(O, ImmOffs * Scale);
1021
122k
    SStream_concat0(O, markup(">"));
1022
122k
  }
1023
130k
  SStream_concat(O, "%s", "]");
1024
130k
  SStream_concat0(O, markup(">"));
1025
130k
}
1026
1027
static inline void printThumbAddrModeImm5S1Operand(MCInst *MI, unsigned Op,
1028
               SStream *O)
1029
50.9k
{
1030
50.9k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S1Operand, Op);
1031
50.9k
  printThumbAddrModeImm5SOperand(MI, Op, O, 1);
1032
50.9k
}
1033
1034
static inline void printThumbAddrModeImm5S2Operand(MCInst *MI, unsigned Op,
1035
               SStream *O)
1036
58.9k
{
1037
58.9k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S2Operand, Op);
1038
58.9k
  printThumbAddrModeImm5SOperand(MI, Op, O, 2);
1039
58.9k
}
1040
1041
static inline void printThumbAddrModeImm5S4Operand(MCInst *MI, unsigned Op,
1042
               SStream *O)
1043
72.2k
{
1044
72.2k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S4Operand, Op);
1045
72.2k
  printThumbAddrModeImm5SOperand(MI, Op, O, 4);
1046
72.2k
}
1047
1048
static inline void printThumbAddrModeSPOperand(MCInst *MI, unsigned Op,
1049
                 SStream *O)
1050
38.5k
{
1051
38.5k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeSPOperand, Op);
1052
38.5k
  printThumbAddrModeImm5SOperand(MI, Op, O, 4);
1053
38.5k
}
1054
1055
// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
1056
// register with shift forms.
1057
// REG 0   0           - e.g. R5
1058
// REG IMM, SH_OPC     - e.g. R5, LSL #3
1059
static inline void printT2SOOperand(MCInst *MI, unsigned OpNum, SStream *O)
1060
2.26k
{
1061
2.26k
  add_cs_detail(MI, ARM_OP_GROUP_T2SOOperand, OpNum);
1062
2.26k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1063
2.26k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1064
1065
2.26k
  unsigned Reg = MCOperand_getReg(MO1);
1066
2.26k
  printRegName(O, Reg);
1067
1068
  // Print the shift opc.
1069
1070
2.26k
  printRegImmShift(MI, O, ARM_AM_getSORegShOp(MCOperand_getImm(MO2)),
1071
2.26k
       ARM_AM_getSORegOffset(MCOperand_getImm(MO2)),
1072
2.26k
       getUseMarkup());
1073
2.26k
}
1074
1075
#define DEFINE_printAddrModeImm12Operand(AlwaysPrintImm0) \
1076
  static inline void CONCAT(printAddrModeImm12Operand, AlwaysPrintImm0)( \
1077
    MCInst * MI, unsigned OpNum, SStream *O) \
1078
8.80k
  { \
1079
8.80k
    add_cs_detail(MI, \
1080
8.80k
            CONCAT(ARM_OP_GROUP_AddrModeImm12Operand, \
1081
8.80k
             AlwaysPrintImm0), \
1082
8.80k
            OpNum, AlwaysPrintImm0); \
1083
8.80k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1084
8.80k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1085
8.80k
\
1086
8.80k
    if (!MCOperand_isReg(MO1)) { \
1087
0
      printOperand(MI, OpNum, O); \
1088
0
      return; \
1089
0
    } \
1090
8.80k
\
1091
8.80k
    SStream_concat(O, "%s", markup("<mem:")); \
1092
8.80k
    SStream_concat0(O, "["); \
1093
8.80k
    printRegName(O, MCOperand_getReg(MO1)); \
1094
8.80k
\
1095
8.80k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1096
8.80k
    bool isSub = OffImm < 0; \
1097
8.80k
\
1098
8.80k
    if (OffImm == INT32_MIN) \
1099
8.80k
      OffImm = 0; \
1100
8.80k
    if (isSub) { \
1101
4.07k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1102
4.07k
      printInt32Bang(O, OffImm); \
1103
4.07k
      SStream_concat0(O, markup(">")); \
1104
4.73k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1105
4.44k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1106
4.44k
      printInt32Bang(O, OffImm); \
1107
4.44k
      SStream_concat0(O, markup(">")); \
1108
4.44k
    } \
1109
8.80k
    SStream_concat(O, "%s", "]"); \
1110
8.80k
    SStream_concat0(O, markup(">")); \
1111
8.80k
  }
1112
5.69k
DEFINE_printAddrModeImm12Operand(false);
1113
3.11k
DEFINE_printAddrModeImm12Operand(true);
1114
1115
#define DEFINE_printT2AddrModeImm8Operand(AlwaysPrintImm0) \
1116
  static inline void CONCAT(printT2AddrModeImm8Operand, \
1117
          AlwaysPrintImm0)(MCInst * MI, \
1118
               unsigned OpNum, SStream *O) \
1119
10.2k
  { \
1120
10.2k
    add_cs_detail(MI, \
1121
10.2k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8Operand, \
1122
10.2k
             AlwaysPrintImm0), \
1123
10.2k
            OpNum, AlwaysPrintImm0); \
1124
10.2k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1125
10.2k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1126
10.2k
\
1127
10.2k
    SStream_concat(O, "%s", markup("<mem:")); \
1128
10.2k
    SStream_concat0(O, "["); \
1129
10.2k
    printRegName(O, MCOperand_getReg(MO1)); \
1130
10.2k
\
1131
10.2k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1132
10.2k
    bool isSub = OffImm < 0; \
1133
10.2k
\
1134
10.2k
    if (OffImm == INT32_MIN) \
1135
10.2k
      OffImm = 0; \
1136
10.2k
    if (isSub) { \
1137
5.71k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1138
5.71k
      printInt32Bang(O, OffImm); \
1139
5.71k
      SStream_concat0(O, markup(">")); \
1140
5.71k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1141
3.95k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1142
3.95k
      printInt32Bang(O, OffImm); \
1143
3.95k
      SStream_concat0(O, markup(">")); \
1144
3.95k
    } \
1145
10.2k
    SStream_concat(O, "%s", "]"); \
1146
10.2k
    SStream_concat0(O, markup(">")); \
1147
10.2k
  }
1148
2.94k
DEFINE_printT2AddrModeImm8Operand(true);
1149
7.29k
DEFINE_printT2AddrModeImm8Operand(false);
1150
1151
#define DEFINE_printT2AddrModeImm8s4Operand(AlwaysPrintImm0) \
1152
  static inline void CONCAT(printT2AddrModeImm8s4Operand, \
1153
          AlwaysPrintImm0)(MCInst * MI, \
1154
               unsigned OpNum, SStream *O) \
1155
7.46k
  { \
1156
7.46k
    add_cs_detail(MI, \
1157
7.46k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8s4Operand, \
1158
7.46k
             AlwaysPrintImm0), \
1159
7.46k
            OpNum, AlwaysPrintImm0); \
1160
7.46k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1161
7.46k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1162
7.46k
\
1163
7.46k
    if (!MCOperand_isReg(MO1)) { \
1164
0
      printOperand(MI, OpNum, O); \
1165
0
      return; \
1166
0
    } \
1167
7.46k
\
1168
7.46k
    SStream_concat(O, "%s", markup("<mem:")); \
1169
7.46k
    SStream_concat0(O, "["); \
1170
7.46k
    printRegName(O, MCOperand_getReg(MO1)); \
1171
7.46k
\
1172
7.46k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1173
7.46k
    bool isSub = OffImm < 0; \
1174
7.46k
\
1175
7.46k
    if (OffImm == INT32_MIN) \
1176
7.46k
      OffImm = 0; \
1177
7.46k
    if (isSub) { \
1178
3.40k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1179
3.40k
      printInt32Bang(O, OffImm); \
1180
3.40k
      SStream_concat0(O, markup(">")); \
1181
4.05k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1182
4.02k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1183
4.02k
      printInt32Bang(O, OffImm); \
1184
4.02k
      SStream_concat0(O, markup(">")); \
1185
4.02k
    } \
1186
7.46k
    SStream_concat(O, "%s", "]"); \
1187
7.46k
    SStream_concat0(O, markup(">")); \
1188
7.46k
  }
1189
1190
1.42k
DEFINE_printT2AddrModeImm8s4Operand(false);
1191
6.03k
DEFINE_printT2AddrModeImm8s4Operand(true);
1192
1193
static inline void printT2AddrModeImm0_1020s4Operand(MCInst *MI, unsigned OpNum,
1194
                 SStream *O)
1195
760
{
1196
760
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm0_1020s4Operand, OpNum);
1197
760
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1198
760
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1199
1200
760
  SStream_concat(O, "%s", markup("<mem:"));
1201
760
  SStream_concat0(O, "[");
1202
760
  printRegName(O, MCOperand_getReg(MO1));
1203
760
  if (MCOperand_getImm(MO2)) {
1204
698
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
1205
698
    printInt64Bang(O, (int32_t)(MCOperand_getImm(MO2) * 4));
1206
698
    SStream_concat0(O, markup(">"));
1207
698
  }
1208
760
  SStream_concat(O, "%s", "]");
1209
760
  SStream_concat0(O, markup(">"));
1210
760
}
1211
1212
static inline void printT2AddrModeImm8OffsetOperand(MCInst *MI, unsigned OpNum,
1213
                SStream *O)
1214
1.82k
{
1215
1.82k
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm8OffsetOperand, OpNum);
1216
1.82k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1217
1.82k
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
1218
1.82k
  SStream_concat(O, "%s", ", ");
1219
1.82k
  SStream_concat0(O, markup("<imm:"));
1220
1.82k
  if (OffImm == INT32_MIN)
1221
946
    SStream_concat0(O, "#-0");
1222
876
  else if (OffImm < 0) {
1223
470
    printInt32Bang(O, OffImm);
1224
470
  } else {
1225
406
    printInt32Bang(O, OffImm);
1226
406
  }
1227
1.82k
  SStream_concat0(O, markup(">"));
1228
1.82k
}
1229
1230
static inline void
1231
printT2AddrModeImm8s4OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O)
1232
2.70k
{
1233
2.70k
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm8s4OffsetOperand, OpNum);
1234
2.70k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1235
2.70k
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
1236
1237
2.70k
  SStream_concat(O, "%s", ", ");
1238
2.70k
  SStream_concat0(O, markup("<imm:"));
1239
2.70k
  if (OffImm == INT32_MIN)
1240
228
    SStream_concat0(O, "#-0");
1241
2.47k
  else if (OffImm < 0) {
1242
340
    printInt32Bang(O, OffImm);
1243
2.13k
  } else {
1244
2.13k
    printInt32Bang(O, OffImm);
1245
2.13k
  }
1246
2.70k
  SStream_concat0(O, markup(">"));
1247
2.70k
}
1248
1249
static inline void printT2AddrModeSoRegOperand(MCInst *MI, unsigned OpNum,
1250
                 SStream *O)
1251
852
{
1252
852
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeSoRegOperand, OpNum);
1253
852
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1254
852
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1255
852
  MCOperand *MO3 = MCInst_getOperand(MI, (OpNum + 2));
1256
1257
852
  SStream_concat(O, "%s", markup("<mem:"));
1258
852
  SStream_concat0(O, "[");
1259
852
  printRegName(O, MCOperand_getReg(MO1));
1260
1261
852
  SStream_concat0(O, ", ");
1262
852
  printRegName(O, MCOperand_getReg(MO2));
1263
1264
852
  unsigned ShAmt = MCOperand_getImm(MO3);
1265
852
  if (ShAmt) {
1266
485
    SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
1267
485
    printUInt32(O, ShAmt);
1268
485
    SStream_concat0(O, markup(">"));
1269
485
  }
1270
852
  SStream_concat(O, "%s", "]");
1271
852
  SStream_concat0(O, markup(">"));
1272
852
}
1273
1274
static inline void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1275
457
{
1276
457
  add_cs_detail(MI, ARM_OP_GROUP_FPImmOperand, OpNum);
1277
457
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1278
457
  SStream_concat(O, "%s", markup("<imm:"));
1279
457
  printFloatBang(O, ARM_AM_getFPImmFloat(MCOperand_getImm(MO)));
1280
457
  SStream_concat0(O, markup(">"));
1281
457
}
1282
1283
static inline void printVMOVModImmOperand(MCInst *MI, unsigned OpNum,
1284
            SStream *O)
1285
2.04k
{
1286
2.04k
  add_cs_detail(MI, ARM_OP_GROUP_VMOVModImmOperand, OpNum);
1287
2.04k
  unsigned EncodedImm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1288
2.04k
  unsigned EltBits;
1289
2.04k
  uint64_t Val = ARM_AM_decodeVMOVModImm(EncodedImm, &EltBits);
1290
2.04k
  SStream_concat(O, "%s", markup("<imm:"));
1291
2.04k
  printUInt64Bang(O, Val);
1292
2.04k
  SStream_concat0(O, markup(">"));
1293
2.04k
}
1294
1295
static inline void printImmPlusOneOperand(MCInst *MI, unsigned OpNum,
1296
            SStream *O)
1297
1.43k
{
1298
1.43k
  add_cs_detail(MI, ARM_OP_GROUP_ImmPlusOneOperand, OpNum);
1299
1.43k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1300
1.43k
  SStream_concat(O, "%s", markup("<imm:"));
1301
1.43k
  printUInt32Bang(O, Imm + 1);
1302
1.43k
  SStream_concat0(O, markup(">"));
1303
1.43k
}
1304
1305
static inline void printRotImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1306
1.03k
{
1307
1.03k
  add_cs_detail(MI, ARM_OP_GROUP_RotImmOperand, OpNum);
1308
1.03k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1309
1.03k
  if (Imm == 0)
1310
123
    return;
1311
1312
915
  SStream_concat(O, "%s%s%s%d", ", ror ", markup("<imm:"), "#", 8 * Imm);
1313
915
  SStream_concat0(O, markup(">"));
1314
915
}
1315
1316
static inline void printModImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1317
7.66k
{
1318
7.66k
  add_cs_detail(MI, ARM_OP_GROUP_ModImmOperand, OpNum);
1319
7.66k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
1320
1321
  // Support for fixups (MCFixup)
1322
7.66k
  if (MCOperand_isExpr(Op)) {
1323
0
    printOperand(MI, OpNum, O);
1324
0
    return;
1325
0
  }
1326
1327
7.66k
  unsigned Bits = MCOperand_getImm(Op) & 0xFF;
1328
7.66k
  unsigned Rot = (MCOperand_getImm(Op) & 0xF00) >> 7;
1329
1330
7.66k
  bool PrintUnsigned = false;
1331
7.66k
  switch (MCInst_getOpcode(MI)) {
1332
372
  case ARM_MOVi:
1333
    // Movs to PC should be treated unsigned
1334
372
    PrintUnsigned =
1335
372
      (MCOperand_getReg(MCInst_getOperand(MI, (OpNum - 1))) ==
1336
372
       ARM_PC);
1337
372
    break;
1338
704
  case ARM_MSRi:
1339
    // Movs to special registers should be treated unsigned
1340
704
    PrintUnsigned = true;
1341
704
    break;
1342
7.66k
  }
1343
1344
7.66k
  int32_t Rotated = ARM_AM_rotr32(Bits, Rot);
1345
7.66k
  if (ARM_AM_getSOImmVal(Rotated) == MCOperand_getImm(Op)) {
1346
    // #rot has the least possible value
1347
5.32k
    SStream_concat(O, "%s", "#");
1348
5.32k
    SStream_concat0(O, markup("<imm:"));
1349
5.32k
    if (PrintUnsigned)
1350
432
      printUInt32(O, (uint32_t)(Rotated));
1351
4.89k
    else
1352
4.89k
      printInt32(O, Rotated);
1353
5.32k
    SStream_concat0(O, markup(">"));
1354
5.32k
    return;
1355
5.32k
  }
1356
1357
  // Explicit #bits, #rot implied
1358
2.33k
  SStream_concat(O, "%s%s%u", "#", markup("<imm:"), Bits);
1359
2.33k
  SStream_concat(O, "%s%s%s%u", markup(">"), ", #", markup("<imm:"), Rot);
1360
2.33k
  SStream_concat0(O, markup(">"));
1361
2.33k
}
1362
1363
static inline void printFBits16(MCInst *MI, unsigned OpNum, SStream *O)
1364
583
{
1365
583
  add_cs_detail(MI, ARM_OP_GROUP_FBits16, OpNum);
1366
583
  SStream_concat(O, "%s%s", markup("<imm:"), "#");
1367
583
  SStream_concat(O, "%d",
1368
583
           16 - MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1369
583
  SStream_concat0(O, markup(">"));
1370
583
}
1371
1372
static inline void printFBits32(MCInst *MI, unsigned OpNum, SStream *O)
1373
328
{
1374
328
  add_cs_detail(MI, ARM_OP_GROUP_FBits32, OpNum);
1375
328
  SStream_concat(O, "%s%s", markup("<imm:"), "#");
1376
328
  printInt64(O, 32 - MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1377
328
  SStream_concat0(O, markup(">"));
1378
328
}
1379
1380
static inline void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O)
1381
6.33k
{
1382
6.33k
  add_cs_detail(MI, ARM_OP_GROUP_VectorIndex, OpNum);
1383
6.33k
  SStream_concat(O, "%s", "[");
1384
6.33k
  printInt64(O,
1385
6.33k
       (int32_t)MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1386
6.33k
  SStream_concat0(O, "]");
1387
6.33k
}
1388
1389
static inline void printVectorListOne(MCInst *MI, unsigned OpNum, SStream *O)
1390
2.31k
{
1391
2.31k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListOne, OpNum);
1392
2.31k
  SStream_concat0(O, "{");
1393
2.31k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1394
2.31k
  SStream_concat0(O, "}");
1395
2.31k
}
1396
1397
static inline void printVectorListTwo(MCInst *MI, unsigned OpNum, SStream *O)
1398
4.55k
{
1399
4.55k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwo, OpNum);
1400
4.55k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1401
4.55k
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1402
4.55k
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1);
1403
4.55k
  SStream_concat0(O, "{");
1404
4.55k
  printRegName(O, Reg0);
1405
4.55k
  SStream_concat0(O, ", ");
1406
4.55k
  printRegName(O, Reg1);
1407
4.55k
  SStream_concat0(O, "}");
1408
4.55k
}
1409
1410
static inline void printVectorListTwoSpaced(MCInst *MI, unsigned OpNum,
1411
              SStream *O)
1412
2.33k
{
1413
2.33k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoSpaced, OpNum);
1414
2.33k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1415
2.33k
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1416
2.33k
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2);
1417
2.33k
  SStream_concat0(O, "{");
1418
2.33k
  printRegName(O, Reg0);
1419
2.33k
  SStream_concat0(O, ", ");
1420
2.33k
  printRegName(O, Reg1);
1421
2.33k
  SStream_concat0(O, "}");
1422
2.33k
}
1423
1424
static inline void printVectorListThree(MCInst *MI, unsigned OpNum, SStream *O)
1425
2.04k
{
1426
2.04k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThree, OpNum);
1427
  // Normally, it's not safe to use register enum values directly with
1428
  // addition to get the next register, but for VFP registers, the
1429
  // sort order is guaranteed because they're all of the form D<n>.
1430
2.04k
  SStream_concat0(O, "{");
1431
2.04k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1432
2.04k
  SStream_concat0(O, ", ");
1433
2.04k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1434
2.04k
  SStream_concat0(O, ", ");
1435
2.04k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1436
2.04k
  SStream_concat0(O, "}");
1437
2.04k
}
1438
1439
static inline void printVectorListFour(MCInst *MI, unsigned OpNum, SStream *O)
1440
3.54k
{
1441
3.54k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFour, OpNum);
1442
  // Normally, it's not safe to use register enum values directly with
1443
  // addition to get the next register, but for VFP registers, the
1444
  // sort order is guaranteed because they're all of the form D<n>.
1445
3.54k
  SStream_concat0(O, "{");
1446
3.54k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1447
3.54k
  SStream_concat0(O, ", ");
1448
3.54k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1449
3.54k
  SStream_concat0(O, ", ");
1450
3.54k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1451
3.54k
  SStream_concat0(O, ", ");
1452
3.54k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 3);
1453
3.54k
  SStream_concat0(O, "}");
1454
3.54k
}
1455
1456
static inline void printVectorListOneAllLanes(MCInst *MI, unsigned OpNum,
1457
                SStream *O)
1458
90
{
1459
90
  add_cs_detail(MI, ARM_OP_GROUP_VectorListOneAllLanes, OpNum);
1460
90
  SStream_concat0(O, "{");
1461
90
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1462
90
  SStream_concat0(O, "[]}");
1463
90
}
1464
1465
static inline void printVectorListTwoAllLanes(MCInst *MI, unsigned OpNum,
1466
                SStream *O)
1467
944
{
1468
944
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoAllLanes, OpNum);
1469
944
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1470
944
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1471
944
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1);
1472
944
  SStream_concat0(O, "{");
1473
944
  printRegName(O, Reg0);
1474
944
  SStream_concat0(O, "[], ");
1475
944
  printRegName(O, Reg1);
1476
944
  SStream_concat0(O, "[]}");
1477
944
}
1478
1479
static inline void printVectorListThreeAllLanes(MCInst *MI, unsigned OpNum,
1480
            SStream *O)
1481
0
{
1482
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThreeAllLanes, OpNum);
1483
  // Normally, it's not safe to use register enum values directly with
1484
  // addition to get the next register, but for VFP registers, the
1485
  // sort order is guaranteed because they're all of the form D<n>.
1486
0
  SStream_concat0(O, "{");
1487
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1488
0
  SStream_concat0(O, "[], ");
1489
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1490
0
  SStream_concat0(O, "[], ");
1491
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1492
0
  SStream_concat0(O, "[]}");
1493
0
}
1494
1495
static inline void printVectorListFourAllLanes(MCInst *MI, unsigned OpNum,
1496
                 SStream *O)
1497
0
{
1498
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFourAllLanes, OpNum);
1499
  // Normally, it's not safe to use register enum values directly with
1500
  // addition to get the next register, but for VFP registers, the
1501
  // sort order is guaranteed because they're all of the form D<n>.
1502
0
  SStream_concat0(O, "{");
1503
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1504
0
  SStream_concat0(O, "[], ");
1505
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1506
0
  SStream_concat0(O, "[], ");
1507
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1508
0
  SStream_concat0(O, "[], ");
1509
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 3);
1510
0
  SStream_concat0(O, "[]}");
1511
0
}
1512
1513
static inline void printVectorListTwoSpacedAllLanes(MCInst *MI, unsigned OpNum,
1514
                SStream *O)
1515
875
{
1516
875
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoSpacedAllLanes, OpNum);
1517
875
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1518
875
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1519
875
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2);
1520
875
  SStream_concat0(O, "{");
1521
875
  printRegName(O, Reg0);
1522
875
  SStream_concat0(O, "[], ");
1523
875
  printRegName(O, Reg1);
1524
875
  SStream_concat0(O, "[]}");
1525
875
}
1526
1527
static inline void
1528
printVectorListThreeSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O)
1529
0
{
1530
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThreeSpacedAllLanes, OpNum);
1531
  // Normally, it's not safe to use register enum values directly with
1532
  // addition to get the next register, but for VFP registers, the
1533
  // sort order is guaranteed because they're all of the form D<n>.
1534
0
  SStream_concat0(O, "{");
1535
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1536
0
  SStream_concat0(O, "[], ");
1537
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1538
0
  SStream_concat0(O, "[], ");
1539
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1540
0
  SStream_concat0(O, "[]}");
1541
0
}
1542
1543
static inline void printVectorListFourSpacedAllLanes(MCInst *MI, unsigned OpNum,
1544
                 SStream *O)
1545
0
{
1546
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFourSpacedAllLanes, OpNum);
1547
  // Normally, it's not safe to use register enum values directly with
1548
  // addition to get the next register, but for VFP registers, the
1549
  // sort order is guaranteed because they're all of the form D<n>.
1550
0
  SStream_concat0(O, "{");
1551
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1552
0
  SStream_concat0(O, "[], ");
1553
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1554
0
  SStream_concat0(O, "[], ");
1555
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1556
0
  SStream_concat0(O, "[], ");
1557
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 6);
1558
0
  SStream_concat0(O, "[]}");
1559
0
}
1560
1561
static inline void printVectorListThreeSpaced(MCInst *MI, unsigned OpNum,
1562
                SStream *O)
1563
0
{
1564
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThreeSpaced, OpNum);
1565
  // Normally, it's not safe to use register enum values directly with
1566
  // addition to get the next register, but for VFP registers, the
1567
  // sort order is guaranteed because they're all of the form D<n>.
1568
0
  SStream_concat0(O, "{");
1569
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1570
0
  SStream_concat0(O, ", ");
1571
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1572
0
  SStream_concat0(O, ", ");
1573
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1574
0
  SStream_concat0(O, "}");
1575
0
}
1576
1577
static inline void printVectorListFourSpaced(MCInst *MI, unsigned OpNum,
1578
               SStream *O)
1579
0
{
1580
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFourSpaced, OpNum);
1581
  // Normally, it's not safe to use register enum values directly with
1582
  // addition to get the next register, but for VFP registers, the
1583
  // sort order is guaranteed because they're all of the form D<n>.
1584
0
  SStream_concat0(O, "{");
1585
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1586
0
  SStream_concat0(O, ", ");
1587
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1588
0
  SStream_concat0(O, ", ");
1589
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1590
0
  SStream_concat0(O, ", ");
1591
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 6);
1592
0
  SStream_concat0(O, "}");
1593
0
}
1594
1595
#define DEFINE_printMVEVectorList(NumRegs) \
1596
  static inline void CONCAT(printMVEVectorList, NumRegs)( \
1597
    MCInst * MI, unsigned OpNum, SStream *O) \
1598
1.55k
  { \
1599
1.55k
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
1.55k
            OpNum, NumRegs); \
1601
1.55k
    unsigned Reg = \
1602
1.55k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
1.55k
    const char *Prefix = "{"; \
1604
6.13k
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
4.57k
      SStream_concat0(O, Prefix); \
1606
4.57k
      printRegName( \
1607
4.57k
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
4.57k
                  ARM_qsub_0 + i)); \
1609
4.57k
      Prefix = ", "; \
1610
4.57k
    } \
1611
1.55k
    SStream_concat0(O, "}"); \
1612
1.55k
  }
ARMInstPrinter.c:printMVEVectorList_2
Line
Count
Source
1598
825
  { \
1599
825
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
825
            OpNum, NumRegs); \
1601
825
    unsigned Reg = \
1602
825
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
825
    const char *Prefix = "{"; \
1604
2.47k
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
1.65k
      SStream_concat0(O, Prefix); \
1606
1.65k
      printRegName( \
1607
1.65k
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
1.65k
                  ARM_qsub_0 + i)); \
1609
1.65k
      Prefix = ", "; \
1610
1.65k
    } \
1611
825
    SStream_concat0(O, "}"); \
1612
825
  }
ARMInstPrinter.c:printMVEVectorList_4
Line
Count
Source
1598
731
  { \
1599
731
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
731
            OpNum, NumRegs); \
1601
731
    unsigned Reg = \
1602
731
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
731
    const char *Prefix = "{"; \
1604
3.65k
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
2.92k
      SStream_concat0(O, Prefix); \
1606
2.92k
      printRegName( \
1607
2.92k
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
2.92k
                  ARM_qsub_0 + i)); \
1609
2.92k
      Prefix = ", "; \
1610
2.92k
    } \
1611
731
    SStream_concat0(O, "}"); \
1612
731
  }
1613
DEFINE_printMVEVectorList(2) DEFINE_printMVEVectorList(4)
1614
1615
#define DEFINE_printComplexRotationOp(Angle, Remainder) \
1616
  static inline void CONCAT(printComplexRotationOp, \
1617
          CONCAT(Angle, Remainder))( \
1618
    MCInst * MI, unsigned OpNo, SStream *O) \
1619
3.01k
  { \
1620
3.01k
    add_cs_detail( \
1621
3.01k
      MI, \
1622
3.01k
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
3.01k
             Remainder), \
1624
3.01k
      OpNo, Angle, Remainder); \
1625
3.01k
    unsigned Val = \
1626
3.01k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
3.01k
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
3.01k
  }
ARMInstPrinter.c:printComplexRotationOp_90_0
Line
Count
Source
1619
1.55k
  { \
1620
1.55k
    add_cs_detail( \
1621
1.55k
      MI, \
1622
1.55k
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
1.55k
             Remainder), \
1624
1.55k
      OpNo, Angle, Remainder); \
1625
1.55k
    unsigned Val = \
1626
1.55k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
1.55k
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
1.55k
  }
ARMInstPrinter.c:printComplexRotationOp_180_90
Line
Count
Source
1619
1.45k
  { \
1620
1.45k
    add_cs_detail( \
1621
1.45k
      MI, \
1622
1.45k
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
1.45k
             Remainder), \
1624
1.45k
      OpNo, Angle, Remainder); \
1625
1.45k
    unsigned Val = \
1626
1.45k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
1.45k
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
1.45k
  }
1629
  DEFINE_printComplexRotationOp(90, 0) DEFINE_printComplexRotationOp(180,
1630
                     90)
1631
1632
    static inline void printVPTPredicateOperand(MCInst *MI,
1633
                  unsigned OpNum,
1634
                  SStream *O)
1635
26.1k
{
1636
26.1k
  add_cs_detail(MI, ARM_OP_GROUP_VPTPredicateOperand, OpNum);
1637
26.1k
  ARMVCC_VPTCodes CC = (ARMVCC_VPTCodes)MCOperand_getImm(
1638
26.1k
    MCInst_getOperand(MI, (OpNum)));
1639
26.1k
  if (CC != ARMVCC_None)
1640
2.62k
    SStream_concat0(O, ARMVPTPredToString(CC));
1641
26.1k
}
1642
1643
static inline void printVPTMask(MCInst *MI, unsigned OpNum, SStream *O)
1644
6.85k
{
1645
6.85k
  add_cs_detail(MI, ARM_OP_GROUP_VPTMask, OpNum);
1646
  // (3 - the number of trailing zeroes) is the number of them / else.
1647
6.85k
  unsigned Mask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1648
6.85k
  unsigned NumTZ = CountTrailingZeros_32(Mask);
1649
1650
24.7k
  for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
1651
17.8k
    bool T = ((Mask >> Pos) & 1) == 0;
1652
17.8k
    if (T)
1653
10.1k
      SStream_concat0(O, "t");
1654
1655
7.72k
    else
1656
7.72k
      SStream_concat0(O, "e");
1657
17.8k
  }
1658
6.85k
}
1659
1660
static inline void printMveSaturateOp(MCInst *MI, unsigned OpNum, SStream *O)
1661
0
{
1662
0
  add_cs_detail(MI, ARM_OP_GROUP_MveSaturateOp, OpNum);
1663
0
  uint32_t Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1664
1665
0
  printUInt32Bang(O, (Val == 1 ? 48 : 64));
1666
0
}
1667
1668
#define PRINT_ALIAS_INSTR
1669
#include "ARMGenAsmWriter.inc"
1670
1671
static void printInst(MCInst *MI, SStream *O, void *info)
1672
889k
{
1673
889k
  bool isAlias = false;
1674
889k
  bool useAliasDetails = map_use_alias_details(MI);
1675
889k
  map_set_fill_detail_ops(MI, useAliasDetails);
1676
889k
  unsigned Opcode = MCInst_getOpcode(MI);
1677
889k
  uint64_t Address = MI->address;
1678
1679
889k
  switch (Opcode) {
1680
  // Check for MOVs and print canonical forms, instead.
1681
521
  case ARM_MOVsr: {
1682
521
    isAlias = true;
1683
521
    MCInst_setIsAlias(MI, isAlias);
1684
    // FIXME: Thumb variants?
1685
521
    MCOperand *MO3 = MCInst_getOperand(MI, (3));
1686
1687
521
    SStream_concat1(O, ' ');
1688
521
    SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp(
1689
521
             MCOperand_getImm(MO3))));
1690
521
    printSBitModifierOperand(MI, 6, O);
1691
521
    printPredicateOperand(MI, 4, O);
1692
1693
521
    SStream_concat0(O, " ");
1694
1695
521
    printOperand(MI, 0, O);
1696
521
    SStream_concat0(O, ", ");
1697
521
    printOperand(MI, 1, O);
1698
1699
521
    SStream_concat0(O, ", ");
1700
521
    printOperand(MI, 2, O);
1701
1702
521
    if (useAliasDetails)
1703
521
      return;
1704
0
    else
1705
0
      goto add_real_detail;
1706
521
  }
1707
1708
1.76k
  case ARM_MOVsi: {
1709
1.76k
    isAlias = true;
1710
1.76k
    MCInst_setIsAlias(MI, isAlias);
1711
    // FIXME: Thumb variants?
1712
1.76k
    MCOperand *MO2 = MCInst_getOperand(MI, (2));
1713
1714
1.76k
    SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp(
1715
1.76k
             MCOperand_getImm(MO2))));
1716
1.76k
    printSBitModifierOperand(MI, 5, O);
1717
1.76k
    printPredicateOperand(MI, 3, O);
1718
1719
1.76k
    SStream_concat0(O, " ");
1720
1721
1.76k
    printOperand(MI, 0, O);
1722
1.76k
    SStream_concat0(O, ", ");
1723
1.76k
    printOperand(MI, 1, O);
1724
1725
1.76k
    if (ARM_AM_getSORegShOp(MCOperand_getImm(MO2)) == ARM_AM_rrx) {
1726
27
      if (useAliasDetails)
1727
27
        return;
1728
0
      else
1729
0
        goto add_real_detail;
1730
27
    }
1731
1732
1.73k
    SStream_concat(O, "%s%s%s%d", ", ", markup("<imm:"), "#",
1733
1.73k
             translateShiftImm(ARM_AM_getSORegOffset(
1734
1.73k
               MCOperand_getImm(MO2))));
1735
1.73k
    SStream_concat0(O, markup(">"));
1736
1.73k
    if (useAliasDetails)
1737
1.73k
      return;
1738
0
    else
1739
0
      goto add_real_detail;
1740
1.73k
  }
1741
1742
  // A8.6.123 PUSH
1743
527
  case ARM_STMDB_UPD:
1744
658
  case ARM_t2STMDB_UPD:
1745
658
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP &&
1746
253
        MCInst_getNumOperands(MI) > 5) {
1747
218
      isAlias = true;
1748
218
      MCInst_setIsAlias(MI, isAlias);
1749
      // Should only print PUSH if there are at least two registers in the
1750
      // list.
1751
218
      SStream_concat0(O, "push");
1752
218
      printPredicateOperand(MI, 2, O);
1753
218
      if (Opcode == ARM_t2STMDB_UPD)
1754
73
        SStream_concat0(O, ".w");
1755
218
      SStream_concat0(O, " ");
1756
1757
218
      printRegisterList(MI, 4, O);
1758
218
      if (useAliasDetails)
1759
218
        return;
1760
0
      else
1761
0
        goto add_real_detail;
1762
218
    } else
1763
440
      break;
1764
1765
824
  case ARM_STR_PRE_IMM:
1766
824
    if (MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP &&
1767
79
        MCOperand_getImm(MCInst_getOperand(MI, (3))) == -4) {
1768
0
      isAlias = true;
1769
0
      MCInst_setIsAlias(MI, isAlias);
1770
0
      SStream_concat1(O, ' ');
1771
0
      SStream_concat0(O, "push");
1772
0
      printPredicateOperand(MI, 4, O);
1773
0
      SStream_concat0(O, " {");
1774
0
      printOperand(MI, 1, O);
1775
0
      SStream_concat0(O, "}");
1776
0
      if (useAliasDetails)
1777
0
        return;
1778
0
      else
1779
0
        goto add_real_detail;
1780
0
    } else
1781
824
      break;
1782
1783
  // A8.6.122 POP
1784
466
  case ARM_LDMIA_UPD:
1785
958
  case ARM_t2LDMIA_UPD:
1786
958
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP &&
1787
629
        MCInst_getNumOperands(MI) > 5) {
1788
556
      isAlias = true;
1789
556
      MCInst_setIsAlias(MI, isAlias);
1790
      // Should only print POP if there are at least two registers in the
1791
      // list.
1792
556
      SStream_concat0(O, "pop");
1793
556
      printPredicateOperand(MI, 2, O);
1794
556
      if (Opcode == ARM_t2LDMIA_UPD)
1795
325
        SStream_concat0(O, ".w");
1796
556
      SStream_concat0(O, " ");
1797
1798
556
      printRegisterList(MI, 4, O);
1799
556
      if (useAliasDetails)
1800
556
        return;
1801
0
      else
1802
0
        goto add_real_detail;
1803
556
    } else
1804
402
      break;
1805
1806
803
  case ARM_LDR_POST_IMM:
1807
803
    if ((MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP) &&
1808
324
        ((ARM_AM_getAM2Offset(MCOperand_getImm(
1809
324
            MCInst_getOperand(MI, (4)))) == 4))) {
1810
74
      isAlias = true;
1811
74
      MCInst_setIsAlias(MI, isAlias);
1812
74
      SStream_concat0(O, "pop");
1813
74
      printPredicateOperand(MI, 5, O);
1814
74
      SStream_concat0(O, " {");
1815
74
      printOperand(MI, 0, O);
1816
74
      SStream_concat0(O, "}");
1817
74
      if (useAliasDetails)
1818
74
        return;
1819
0
      else
1820
0
        goto add_real_detail;
1821
74
    } else
1822
729
      break;
1823
176
  case ARM_t2LDR_POST:
1824
176
    if ((MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP) &&
1825
48
        (Opcode == ARM_t2LDR_POST &&
1826
48
         (MCOperand_getImm(MCInst_getOperand(MI, (3))) == 4))) {
1827
10
      isAlias = true;
1828
10
      MCInst_setIsAlias(MI, isAlias);
1829
10
      SStream_concat0(O, "pop");
1830
10
      printPredicateOperand(MI, 4, O);
1831
10
      SStream_concat0(O, " {");
1832
10
      printOperand(MI, 0, O);
1833
10
      SStream_concat0(O, "}");
1834
10
      if (useAliasDetails)
1835
10
        return;
1836
0
      else
1837
0
        goto add_real_detail;
1838
10
    } else
1839
166
      break;
1840
1841
  // A8.6.355 VPUSH
1842
142
  case ARM_VSTMSDB_UPD:
1843
428
  case ARM_VSTMDDB_UPD:
1844
428
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP) {
1845
78
      isAlias = true;
1846
78
      MCInst_setIsAlias(MI, isAlias);
1847
78
      SStream_concat0(O, "vpush");
1848
78
      printPredicateOperand(MI, 2, O);
1849
78
      SStream_concat0(O, " ");
1850
1851
78
      printRegisterList(MI, 4, O);
1852
78
      if (useAliasDetails)
1853
78
        return;
1854
0
      else
1855
0
        goto add_real_detail;
1856
78
    } else
1857
350
      break;
1858
1859
  // A8.6.354 VPOP
1860
94
  case ARM_VLDMSIA_UPD:
1861
246
  case ARM_VLDMDIA_UPD:
1862
246
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP) {
1863
177
      isAlias = true;
1864
177
      MCInst_setIsAlias(MI, isAlias);
1865
177
      SStream_concat1(O, ' ');
1866
177
      SStream_concat0(O, "vpop");
1867
177
      printPredicateOperand(MI, 2, O);
1868
177
      SStream_concat0(O, " ");
1869
1870
177
      printRegisterList(MI, 4, O);
1871
177
      if (useAliasDetails)
1872
177
        return;
1873
0
      else
1874
0
        goto add_real_detail;
1875
177
    } else
1876
69
      break;
1877
1878
11.3k
  case ARM_tLDMIA: {
1879
11.3k
    isAlias = true;
1880
11.3k
    MCInst_setIsAlias(MI, isAlias);
1881
11.3k
    bool Writeback = true;
1882
11.3k
    unsigned BaseReg = MCOperand_getReg(MCInst_getOperand(MI, (0)));
1883
63.4k
    for (unsigned i = 3; i < MCInst_getNumOperands(MI); ++i) {
1884
52.0k
      if (MCOperand_getReg(MCInst_getOperand(MI, (i))) ==
1885
52.0k
          BaseReg)
1886
6.16k
        Writeback = false;
1887
52.0k
    }
1888
1889
11.3k
    SStream_concat0(O, "ldm");
1890
1891
11.3k
    printPredicateOperand(MI, 1, O);
1892
11.3k
    SStream_concat0(O, " ");
1893
1894
11.3k
    printOperand(MI, 0, O);
1895
11.3k
    if (Writeback) {
1896
5.19k
      SStream_concat0(O, "!");
1897
5.19k
    }
1898
11.3k
    SStream_concat0(O, ", ");
1899
11.3k
    printRegisterList(MI, 3, O);
1900
11.3k
    if (useAliasDetails)
1901
11.3k
      return;
1902
0
    else
1903
0
      goto add_real_detail;
1904
11.3k
  }
1905
1906
  // Combine 2 GPRs from disassember into a GPRPair to match with instr def.
1907
  // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
1908
  // a single GPRPair reg operand is used in the .td file to replace the two
1909
  // GPRs. However, when decoding them, the two GRPs cannot be automatically
1910
  // expressed as a GPRPair, so we have to manually merge them.
1911
  // FIXME: We would really like to be able to tablegen'erate this.
1912
68
  case ARM_LDREXD:
1913
148
  case ARM_STREXD:
1914
281
  case ARM_LDAEXD:
1915
352
  case ARM_STLEXD: {
1916
352
    const MCRegisterClass *MRC =
1917
352
      MCRegisterInfo_getRegClass(MI->MRI, ARM_GPRRegClassID);
1918
352
    bool isStore = Opcode == ARM_STREXD || Opcode == ARM_STLEXD;
1919
352
    unsigned Reg = MCOperand_getReg(
1920
352
      MCInst_getOperand(MI, isStore ? 1 : 0));
1921
1922
352
    if (MCRegisterClass_contains(MRC, Reg)) {
1923
0
      MCInst NewMI;
1924
1925
0
      MCInst_Init(&NewMI, CS_ARCH_ARM);
1926
0
      MCInst_setOpcode(&NewMI, Opcode);
1927
1928
0
      if (isStore)
1929
0
        MCInst_addOperand2(&NewMI,
1930
0
               MCInst_getOperand(MI, 0));
1931
1932
0
      MCOperand_CreateReg0(
1933
0
        &NewMI,
1934
0
        MCRegisterInfo_getMatchingSuperReg(
1935
0
          MI->MRI, Reg, ARM_gsub_0,
1936
0
          MCRegisterInfo_getRegClass(
1937
0
            MI->MRI,
1938
0
            ARM_GPRPairRegClassID)));
1939
1940
      // Copy the rest operands into NewMI.
1941
0
      for (unsigned i = isStore ? 3 : 2;
1942
0
           i < MCInst_getNumOperands(MI); ++i)
1943
0
        MCInst_addOperand2(&NewMI,
1944
0
               MCInst_getOperand(MI, i));
1945
1946
0
      printInstruction(&NewMI, Address, O);
1947
0
      return;
1948
0
    }
1949
352
    break;
1950
352
  }
1951
352
  case ARM_TSB:
1952
131
  case ARM_t2TSB:
1953
131
    isAlias = true;
1954
131
    MCInst_setIsAlias(MI, isAlias);
1955
1956
131
    SStream_concat0(O, " tsb csync");
1957
131
    if (useAliasDetails)
1958
131
      return;
1959
0
    else
1960
0
      goto add_real_detail;
1961
887
  case ARM_t2DSB:
1962
887
    isAlias = true;
1963
887
    MCInst_setIsAlias(MI, isAlias);
1964
1965
887
    switch (MCOperand_getImm(MCInst_getOperand(MI, (0)))) {
1966
834
    default:
1967
834
      if (!printAliasInstr(MI, Address, O))
1968
834
        printInstruction(MI, Address, O);
1969
834
      break;
1970
39
    case 0:
1971
39
      SStream_concat0(O, " ssbb");
1972
39
      break;
1973
14
    case 4:
1974
14
      SStream_concat0(O, " pssbb");
1975
14
      break;
1976
887
    };
1977
887
    if (useAliasDetails)
1978
887
      return;
1979
0
    else
1980
0
      goto add_real_detail;
1981
889k
  }
1982
1983
873k
  if (!isAlias)
1984
873k
    isAlias |= printAliasInstr(MI, Address, O);
1985
1986
873k
add_real_detail:
1987
873k
  MCInst_setIsAlias(MI, isAlias);
1988
873k
  if (!isAlias || !useAliasDetails) {
1989
869k
    map_set_fill_detail_ops(MI, !(isAlias && useAliasDetails));
1990
869k
    if (isAlias)
1991
0
      SStream_Close(O);
1992
869k
    printInstruction(MI, Address, O);
1993
869k
    if (isAlias)
1994
0
      SStream_Open(O);
1995
869k
  }
1996
873k
}
1997
1998
const char *ARM_LLVM_getRegisterName(unsigned RegNo, unsigned AltIdx)
1999
572k
{
2000
572k
  return getRegisterName(RegNo, AltIdx);
2001
572k
}
2002
2003
void ARM_LLVM_printInstruction(MCInst *MI, SStream *O,
2004
             void * /* MCRegisterInfo* */ info)
2005
889k
{
2006
889k
  printInst(MI, O, info);
2007
889k
}