Coverage Report

Created: 2025-07-18 06:43

/src/capstonenext/arch/ARM/ARMInstPrinter.c
Line
Count
Source (jump to first uncovered line)
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
103k
#define CONCAT(a, b) CONCAT_(a, b)
48
103k
#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
80.5k
{
66
  // lsr #32 and asr #32 exist, but should be encoded as a 0.
67
80.5k
  CS_ASSERT((imm & ~0x1f) == 0 && "Invalid shift encoding");
68
69
80.5k
  if (imm == 0)
70
5.46k
    return 32;
71
75.1k
  return imm;
72
80.5k
}
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
28.8k
{
79
28.8k
  add_cs_detail(MI, ARM_OP_GROUP_RegImmShift, ShOpc, ShImm);
80
28.8k
  if (ShOpc == ARM_AM_no_shift || (ShOpc == ARM_AM_lsl && !ShImm))
81
738
    return;
82
28.1k
  SStream_concat0(O, ", ");
83
84
28.1k
  CS_ASSERT(!(ShOpc == ARM_AM_ror && !ShImm) && "Cannot have ror #0");
85
28.1k
  SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
86
87
28.1k
  if (ShOpc != ARM_AM_rrx) {
88
25.9k
    SStream_concat0(O, " ");
89
25.9k
    if (getUseMarkup())
90
0
      SStream_concat0(O, "<imm:");
91
25.9k
    SStream_concat(O, "%s%d", "#", translateShiftImm(ShImm));
92
25.9k
    if (getUseMarkup())
93
0
      SStream_concat0(O, ">");
94
25.9k
  }
95
28.1k
}
96
97
static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
98
1.05M
{
99
1.05M
  add_cs_detail(MI, ARM_OP_GROUP_PredicateOperand, OpNum);
100
1.05M
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
101
1.05M
    MCInst_getOperand(MI, (OpNum)));
102
  // Handle the undefined 15 CC value here for printing so we don't abort().
103
1.05M
  if ((unsigned)CC == 15)
104
1.33k
    SStream_concat0(O, "<und>");
105
1.05M
  else if (CC != ARMCC_AL)
106
164k
    SStream_concat0(O, ARMCondCodeToString(CC));
107
1.05M
}
108
109
static void printRegName(SStream *OS, unsigned RegNo)
110
2.49M
{
111
2.49M
  SStream_concat(OS, "%s%s", markup("<reg:"),
112
2.49M
           getRegisterName(RegNo, ARM_NoRegAltName));
113
2.49M
  SStream_concat0(OS, markup(">"));
114
2.49M
}
115
116
static inline void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
117
2.00M
{
118
2.00M
  add_cs_detail(MI, ARM_OP_GROUP_Operand, OpNo);
119
2.00M
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
120
2.00M
  if (MCOperand_isReg(Op)) {
121
1.64M
    unsigned Reg = MCOperand_getReg(Op);
122
1.64M
    printRegName(O, Reg);
123
1.64M
  } else if (MCOperand_isImm(Op)) {
124
359k
    SStream_concat(O, "%s", markup("<imm:"));
125
359k
    SStream_concat1(O, '#');
126
359k
    printInt64(O, MCOperand_getImm(Op));
127
359k
    SStream_concat0(O, markup(">"));
128
359k
  } else {
129
0
    CS_ASSERT_RET(0 && "Expressions are not supported.");
130
0
  }
131
2.00M
}
132
133
static inline void printRegisterList(MCInst *MI, unsigned OpNum, SStream *O)
134
49.8k
{
135
49.8k
  add_cs_detail(MI, ARM_OP_GROUP_RegisterList, OpNum);
136
49.8k
  if (MCInst_getOpcode(MI) != ARM_t2CLRM) {
137
49.7k
  }
138
139
49.8k
  SStream_concat0(O, "{");
140
345k
  for (unsigned i = OpNum, e = MCInst_getNumOperands(MI); i != e; ++i) {
141
295k
    if (i != OpNum)
142
245k
      SStream_concat0(O, ", ");
143
295k
    printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (i))));
144
295k
  }
145
49.8k
  SStream_concat0(O, "}");
146
49.8k
}
147
148
static inline void printSBitModifierOperand(MCInst *MI, unsigned OpNum,
149
              SStream *O)
150
325k
{
151
325k
  add_cs_detail(MI, ARM_OP_GROUP_SBitModifierOperand, OpNum);
152
325k
  if (MCOperand_getReg(MCInst_getOperand(MI, (OpNum)))) {
153
291k
    SStream_concat0(O, "s");
154
291k
  }
155
325k
}
156
157
static inline void printOperandAddr(MCInst *MI, uint64_t Address,
158
            unsigned OpNum, SStream *O)
159
62.7k
{
160
62.7k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
161
62.7k
  if (!MCOperand_isImm(Op) || !MI->csh->PrintBranchImmAsAddress ||
162
62.7k
      getUseMarkup()) {
163
0
    printOperand(MI, OpNum, O);
164
0
    return;
165
0
  }
166
62.7k
  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
62.7k
  uint64_t Offset = ARM_getFeatureBits(MI->csh->mode, ARM_ModeThumb) ? 4 :
170
62.7k
                       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
62.7k
  if (MCInst_getOpcode(MI) == ARM_tBLXi)
178
333
    Address &= ~0x3;
179
180
62.7k
  uint64_t Target = Address + Imm + Offset;
181
182
62.7k
  Target &= 0xffffffff;
183
62.7k
  ARM_set_detail_op_imm(MI, OpNum, ARM_OP_IMM, Target);
184
62.7k
  printUInt64(O, Target);
185
62.7k
}
186
187
static inline void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNum,
188
               SStream *O)
189
25.1k
{
190
25.1k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbLdrLabelOperand, OpNum);
191
25.1k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
192
25.1k
  if (MCOperand_isExpr(MO1)) {
193
    // MO1.getExpr()->print(O, &MAI);
194
0
    return;
195
0
  }
196
197
25.1k
  SStream_concat(O, "%s", markup("<mem:"));
198
25.1k
  SStream_concat0(O, "[pc, ");
199
200
25.1k
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
201
202
  // Special value for #-0. All others are normal.
203
25.1k
  if (OffImm == INT32_MIN)
204
1.17k
    OffImm = 0;
205
25.1k
  SStream_concat(O, "%s", markup("<imm:"));
206
25.1k
  printInt32Bang(O, OffImm);
207
25.1k
  SStream_concat0(O, markup(">"));
208
25.1k
  SStream_concat(O, "%s", "]");
209
25.1k
  SStream_concat0(O, markup(">"));
210
25.1k
}
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.71k
{
219
6.71k
  add_cs_detail(MI, ARM_OP_GROUP_SORegRegOperand, OpNum);
220
6.71k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
221
6.71k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
222
6.71k
  MCOperand *MO3 = MCInst_getOperand(MI, (OpNum + 2));
223
224
6.71k
  printRegName(O, MCOperand_getReg(MO1));
225
226
  // Print the shift opc.
227
6.71k
  ARM_AM_ShiftOpc ShOpc = ARM_AM_getSORegShOp(MCOperand_getImm(MO3));
228
6.71k
  SStream_concat(O, "%s", ", ");
229
6.71k
  SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
230
6.71k
  if (ShOpc == ARM_AM_rrx)
231
0
    return;
232
233
6.71k
  SStream_concat0(O, " ");
234
235
6.71k
  printRegName(O, MCOperand_getReg(MO2));
236
6.71k
}
237
238
static inline void printSORegImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
239
13.0k
{
240
13.0k
  add_cs_detail(MI, ARM_OP_GROUP_SORegImmOperand, OpNum);
241
13.0k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
242
13.0k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
243
244
13.0k
  printRegName(O, MCOperand_getReg(MO1));
245
246
  // Print the shift opc.
247
13.0k
  printRegImmShift(MI, O, ARM_AM_getSORegShOp(MCOperand_getImm(MO2)),
248
13.0k
       ARM_AM_getSORegOffset(MCOperand_getImm(MO2)),
249
13.0k
       getUseMarkup());
250
13.0k
}
251
252
//===--------------------------------------------------------------------===//
253
// Addressing Mode #2
254
//===--------------------------------------------------------------------===//
255
256
static inline void printAM2PreOrOffsetIndexOp(MCInst *MI, unsigned Op,
257
                SStream *O)
258
7.42k
{
259
7.42k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
260
7.42k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
261
7.42k
  MCOperand *MO3 = MCInst_getOperand(MI, (Op + 2));
262
263
7.42k
  SStream_concat(O, "%s", markup("<mem:"));
264
7.42k
  SStream_concat0(O, "[");
265
7.42k
  printRegName(O, MCOperand_getReg(MO1));
266
267
7.42k
  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
7.42k
  SStream_concat0(O, ", ");
283
7.42k
  SStream_concat0(O, ARM_AM_getAddrOpcStr(
284
7.42k
           ARM_AM_getAM2Op(MCOperand_getImm(MO3))));
285
7.42k
  printRegName(O, MCOperand_getReg(MO2));
286
287
7.42k
  printRegImmShift(MI, O, ARM_AM_getAM2ShiftOpc(MCOperand_getImm(MO3)),
288
7.42k
       ARM_AM_getAM2Offset(MCOperand_getImm(MO3)),
289
7.42k
       getUseMarkup());
290
7.42k
  SStream_concat(O, "%s", "]");
291
7.42k
  SStream_concat0(O, markup(">"));
292
7.42k
}
293
294
static inline void printAddrModeTBB(MCInst *MI, unsigned Op, SStream *O)
295
127
{
296
127
  add_cs_detail(MI, ARM_OP_GROUP_AddrModeTBB, Op);
297
127
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
298
127
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
299
127
  SStream_concat(O, "%s", markup("<mem:"));
300
127
  SStream_concat0(O, "[");
301
127
  printRegName(O, MCOperand_getReg(MO1));
302
127
  SStream_concat0(O, ", ");
303
127
  printRegName(O, MCOperand_getReg(MO2));
304
127
  SStream_concat(O, "%s", "]");
305
127
  SStream_concat0(O, markup(">"));
306
127
}
307
308
static inline void printAddrModeTBH(MCInst *MI, unsigned Op, SStream *O)
309
540
{
310
540
  add_cs_detail(MI, ARM_OP_GROUP_AddrModeTBH, Op);
311
540
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
312
540
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
313
540
  SStream_concat(O, "%s", markup("<mem:"));
314
540
  SStream_concat0(O, "[");
315
540
  printRegName(O, MCOperand_getReg(MO1));
316
540
  SStream_concat0(O, ", ");
317
540
  printRegName(O, MCOperand_getReg(MO2));
318
540
  SStream_concat(O, "%s%s%s%s%s", ", lsl ", markup("<imm:"), "#1",
319
540
           markup(">"), "]");
320
540
  SStream_concat0(O, markup(">"));
321
540
}
322
323
static inline void printAddrMode2Operand(MCInst *MI, unsigned Op, SStream *O)
324
7.42k
{
325
7.42k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode2Operand, Op);
326
7.42k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
327
328
7.42k
  if (!MCOperand_isReg(
329
7.42k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
330
0
    printOperand(MI, Op, O);
331
0
    return;
332
0
  }
333
334
7.42k
  printAM2PreOrOffsetIndexOp(MI, Op, O);
335
7.42k
}
336
337
static inline void printAddrMode2OffsetOperand(MCInst *MI, unsigned OpNum,
338
                 SStream *O)
339
10.8k
{
340
10.8k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode2OffsetOperand, OpNum);
341
10.8k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
342
10.8k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
343
344
10.8k
  if (!MCOperand_getReg(MO1)) {
345
6.65k
    unsigned ImmOffs = ARM_AM_getAM2Offset(MCOperand_getImm(MO2));
346
6.65k
    SStream_concat(O, "%s", markup("<imm:"));
347
6.65k
    SStream_concat1(O, '#');
348
6.65k
    SStream_concat(O, "%s",
349
6.65k
             ARM_AM_getAddrOpcStr(
350
6.65k
               ARM_AM_getAM2Op(MCOperand_getImm(MO2))));
351
6.65k
    printUInt32(O, ImmOffs);
352
6.65k
    SStream_concat0(O, markup(">"));
353
6.65k
    return;
354
6.65k
  }
355
356
4.15k
  SStream_concat0(O, ARM_AM_getAddrOpcStr(
357
4.15k
           ARM_AM_getAM2Op(MCOperand_getImm(MO2))));
358
4.15k
  printRegName(O, MCOperand_getReg(MO1));
359
360
4.15k
  printRegImmShift(MI, O, ARM_AM_getAM2ShiftOpc(MCOperand_getImm(MO2)),
361
4.15k
       ARM_AM_getAM2Offset(MCOperand_getImm(MO2)),
362
4.15k
       getUseMarkup());
363
4.15k
}
364
365
//===--------------------------------------------------------------------===//
366
// Addressing Mode #3
367
//===--------------------------------------------------------------------===//
368
369
static inline void printAM3PreOrOffsetIndexOp(MCInst *MI, unsigned Op,
370
                SStream *O, bool AlwaysPrintImm0)
371
5.70k
{
372
5.70k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
373
5.70k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
374
5.70k
  MCOperand *MO3 = MCInst_getOperand(MI, (Op + 2));
375
376
5.70k
  SStream_concat(O, "%s", markup("<mem:"));
377
5.70k
  SStream_concat0(O, "[");
378
379
5.70k
  printRegName(O, MCOperand_getReg(MO1));
380
381
5.70k
  if (MCOperand_getReg(MO2)) {
382
2.40k
    SStream_concat(O, "%s", ", ");
383
2.40k
    SStream_concat0(O, ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(
384
2.40k
             MCOperand_getImm(MO3))));
385
2.40k
    printRegName(O, MCOperand_getReg(MO2));
386
2.40k
    SStream_concat1(O, ']');
387
2.40k
    SStream_concat0(O, markup(">"));
388
2.40k
    return;
389
2.40k
  }
390
391
  // If the op is sub we have to print the immediate even if it is 0
392
3.29k
  unsigned ImmOffs = ARM_AM_getAM3Offset(MCOperand_getImm(MO3));
393
3.29k
  ARM_AM_AddrOpc op = ARM_AM_getAM3Op(MCOperand_getImm(MO3));
394
395
3.29k
  if (AlwaysPrintImm0 || ImmOffs || (op == ARM_AM_sub)) {
396
2.93k
    SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), "#",
397
2.93k
             ARM_AM_getAddrOpcStr(op));
398
2.93k
    printUInt32(O, ImmOffs);
399
2.93k
    SStream_concat0(O, markup(">"));
400
2.93k
  }
401
3.29k
  SStream_concat1(O, ']');
402
3.29k
  SStream_concat0(O, markup(">"));
403
3.29k
}
404
405
#define DEFINE_printAddrMode3Operand(AlwaysPrintImm0) \
406
  static inline void CONCAT(printAddrMode3Operand, AlwaysPrintImm0)( \
407
    MCInst * MI, unsigned Op, SStream *O) \
408
5.70k
  { \
409
5.70k
    add_cs_detail(MI, \
410
5.70k
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
5.70k
             AlwaysPrintImm0), \
412
5.70k
            Op, AlwaysPrintImm0); \
413
5.70k
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
5.70k
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
5.70k
\
419
5.70k
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
5.70k
  }
ARMInstPrinter.c:printAddrMode3Operand_0
Line
Count
Source
408
3.02k
  { \
409
3.02k
    add_cs_detail(MI, \
410
3.02k
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
3.02k
             AlwaysPrintImm0), \
412
3.02k
            Op, AlwaysPrintImm0); \
413
3.02k
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
3.02k
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
3.02k
\
419
3.02k
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
3.02k
  }
ARMInstPrinter.c:printAddrMode3Operand_1
Line
Count
Source
408
2.67k
  { \
409
2.67k
    add_cs_detail(MI, \
410
2.67k
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
2.67k
             AlwaysPrintImm0), \
412
2.67k
            Op, AlwaysPrintImm0); \
413
2.67k
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
2.67k
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
2.67k
\
419
2.67k
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
2.67k
  }
421
DEFINE_printAddrMode3Operand(false);
422
DEFINE_printAddrMode3Operand(true);
423
424
static inline void printAddrMode3OffsetOperand(MCInst *MI, unsigned OpNum,
425
                 SStream *O)
426
5.73k
{
427
5.73k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode3OffsetOperand, OpNum);
428
5.73k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
429
5.73k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
430
431
5.73k
  if (MCOperand_getReg(MO1)) {
432
3.60k
    SStream_concat0(O, ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(
433
3.60k
             MCOperand_getImm(MO2))));
434
3.60k
    printRegName(O, MCOperand_getReg(MO1));
435
3.60k
    return;
436
3.60k
  }
437
438
2.13k
  unsigned ImmOffs = ARM_AM_getAM3Offset(MCOperand_getImm(MO2));
439
2.13k
  SStream_concat(O, "%s", markup("<imm:"));
440
2.13k
  SStream_concat1(O, '#');
441
2.13k
  SStream_concat(
442
2.13k
    O, "%s",
443
2.13k
    ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(MCOperand_getImm(MO2))));
444
2.13k
  printUInt32(O, ImmOffs);
445
2.13k
  SStream_concat0(O, markup(">"));
446
2.13k
}
447
448
static inline void printPostIdxImm8Operand(MCInst *MI, unsigned OpNum,
449
             SStream *O)
450
565
{
451
565
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxImm8Operand, OpNum);
452
565
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
453
565
  unsigned Imm = MCOperand_getImm(MO);
454
565
  SStream_concat(O, "%s", markup("<imm:"));
455
565
  SStream_concat1(O, '#');
456
565
  SStream_concat(O, "%s", ((Imm & 256) ? "" : "-"));
457
565
  printUInt32(O, (Imm & 0xff));
458
565
  SStream_concat0(O, markup(">"));
459
565
}
460
461
static inline void printPostIdxRegOperand(MCInst *MI, unsigned OpNum,
462
            SStream *O)
463
1.78k
{
464
1.78k
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxRegOperand, OpNum);
465
1.78k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
466
1.78k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
467
468
1.78k
  SStream_concat0(O, (MCOperand_getImm(MO2) ? "" : "-"));
469
1.78k
  printRegName(O, MCOperand_getReg(MO1));
470
1.78k
}
471
472
static inline void printPostIdxImm8s4Operand(MCInst *MI, unsigned OpNum,
473
               SStream *O)
474
10.4k
{
475
10.4k
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxImm8s4Operand, OpNum);
476
10.4k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
477
10.4k
  unsigned Imm = MCOperand_getImm(MO);
478
10.4k
  SStream_concat(O, "%s", markup("<imm:"));
479
10.4k
  SStream_concat1(O, '#');
480
10.4k
  SStream_concat(O, "%s", ((Imm & 256) ? "" : "-"));
481
10.4k
  printUInt32(O, (Imm & 0xff) << 2);
482
10.4k
  SStream_concat0(O, markup(">"));
483
10.4k
}
484
485
#define DEFINE_printMveAddrModeRQOperand(shift) \
486
  static inline void CONCAT(printMveAddrModeRQOperand, shift)( \
487
    MCInst * MI, unsigned OpNum, SStream *O) \
488
592
  { \
489
592
    add_cs_detail( \
490
592
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
592
      OpNum, shift); \
492
592
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
592
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
592
\
495
592
    SStream_concat(O, "%s", markup("<mem:")); \
496
592
    SStream_concat0(O, "["); \
497
592
    printRegName(O, MCOperand_getReg(MO1)); \
498
592
    SStream_concat0(O, ", "); \
499
592
    printRegName(O, MCOperand_getReg(MO2)); \
500
592
\
501
592
    if (shift > 0) \
502
592
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
512
           getUseMarkup()); \
504
592
\
505
592
    SStream_concat(O, "%s", "]"); \
506
592
    SStream_concat0(O, markup(">")); \
507
592
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_0
Line
Count
Source
488
80
  { \
489
80
    add_cs_detail( \
490
80
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
80
      OpNum, shift); \
492
80
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
80
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
80
\
495
80
    SStream_concat(O, "%s", markup("<mem:")); \
496
80
    SStream_concat0(O, "["); \
497
80
    printRegName(O, MCOperand_getReg(MO1)); \
498
80
    SStream_concat0(O, ", "); \
499
80
    printRegName(O, MCOperand_getReg(MO2)); \
500
80
\
501
80
    if (shift > 0) \
502
80
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
0
           getUseMarkup()); \
504
80
\
505
80
    SStream_concat(O, "%s", "]"); \
506
80
    SStream_concat0(O, markup(">")); \
507
80
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_3
Line
Count
Source
488
205
  { \
489
205
    add_cs_detail( \
490
205
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
205
      OpNum, shift); \
492
205
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
205
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
205
\
495
205
    SStream_concat(O, "%s", markup("<mem:")); \
496
205
    SStream_concat0(O, "["); \
497
205
    printRegName(O, MCOperand_getReg(MO1)); \
498
205
    SStream_concat0(O, ", "); \
499
205
    printRegName(O, MCOperand_getReg(MO2)); \
500
205
\
501
205
    if (shift > 0) \
502
205
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
205
           getUseMarkup()); \
504
205
\
505
205
    SStream_concat(O, "%s", "]"); \
506
205
    SStream_concat0(O, markup(">")); \
507
205
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_1
Line
Count
Source
488
222
  { \
489
222
    add_cs_detail( \
490
222
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
222
      OpNum, shift); \
492
222
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
222
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
222
\
495
222
    SStream_concat(O, "%s", markup("<mem:")); \
496
222
    SStream_concat0(O, "["); \
497
222
    printRegName(O, MCOperand_getReg(MO1)); \
498
222
    SStream_concat0(O, ", "); \
499
222
    printRegName(O, MCOperand_getReg(MO2)); \
500
222
\
501
222
    if (shift > 0) \
502
222
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
222
           getUseMarkup()); \
504
222
\
505
222
    SStream_concat(O, "%s", "]"); \
506
222
    SStream_concat0(O, markup(">")); \
507
222
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_2
Line
Count
Source
488
85
  { \
489
85
    add_cs_detail( \
490
85
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
85
      OpNum, shift); \
492
85
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
85
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
85
\
495
85
    SStream_concat(O, "%s", markup("<mem:")); \
496
85
    SStream_concat0(O, "["); \
497
85
    printRegName(O, MCOperand_getReg(MO1)); \
498
85
    SStream_concat0(O, ", "); \
499
85
    printRegName(O, MCOperand_getReg(MO2)); \
500
85
\
501
85
    if (shift > 0) \
502
85
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
85
           getUseMarkup()); \
504
85
\
505
85
    SStream_concat(O, "%s", "]"); \
506
85
    SStream_concat0(O, markup(">")); \
507
85
  }
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
20.5k
  { \
517
20.5k
    add_cs_detail(MI, \
518
20.5k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
20.5k
             AlwaysPrintImm0), \
520
20.5k
            OpNum, AlwaysPrintImm0); \
521
20.5k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
20.5k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
20.5k
\
524
20.5k
    SStream_concat(O, "%s", markup("<mem:")); \
525
20.5k
    SStream_concat0(O, "["); \
526
20.5k
    printRegName(O, MCOperand_getReg(MO1)); \
527
20.5k
\
528
20.5k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
20.5k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
20.5k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
20.1k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
20.1k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
20.1k
      printUInt32(O, ImmOffs * 4); \
534
20.1k
      SStream_concat0(O, markup(">")); \
535
20.1k
    } \
536
20.5k
    SStream_concat(O, "%s", "]"); \
537
20.5k
    SStream_concat0(O, markup(">")); \
538
20.5k
  }
ARMInstPrinter.c:printAddrMode5Operand_0
Line
Count
Source
516
9.69k
  { \
517
9.69k
    add_cs_detail(MI, \
518
9.69k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
9.69k
             AlwaysPrintImm0), \
520
9.69k
            OpNum, AlwaysPrintImm0); \
521
9.69k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
9.69k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
9.69k
\
524
9.69k
    SStream_concat(O, "%s", markup("<mem:")); \
525
9.69k
    SStream_concat0(O, "["); \
526
9.69k
    printRegName(O, MCOperand_getReg(MO1)); \
527
9.69k
\
528
9.69k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
9.69k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
9.69k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
9.28k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
9.28k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
9.28k
      printUInt32(O, ImmOffs * 4); \
534
9.28k
      SStream_concat0(O, markup(">")); \
535
9.28k
    } \
536
9.69k
    SStream_concat(O, "%s", "]"); \
537
9.69k
    SStream_concat0(O, markup(">")); \
538
9.69k
  }
ARMInstPrinter.c:printAddrMode5Operand_1
Line
Count
Source
516
10.8k
  { \
517
10.8k
    add_cs_detail(MI, \
518
10.8k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
10.8k
             AlwaysPrintImm0), \
520
10.8k
            OpNum, AlwaysPrintImm0); \
521
10.8k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
10.8k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
10.8k
\
524
10.8k
    SStream_concat(O, "%s", markup("<mem:")); \
525
10.8k
    SStream_concat0(O, "["); \
526
10.8k
    printRegName(O, MCOperand_getReg(MO1)); \
527
10.8k
\
528
10.8k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
10.8k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
10.8k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
10.8k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
10.8k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
10.8k
      printUInt32(O, ImmOffs * 4); \
534
10.8k
      SStream_concat0(O, markup(">")); \
535
10.8k
    } \
536
10.8k
    SStream_concat(O, "%s", "]"); \
537
10.8k
    SStream_concat0(O, markup(">")); \
538
10.8k
  }
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
901
  { \
546
901
    add_cs_detail(MI, \
547
901
            CONCAT(ARM_OP_GROUP_AddrMode5FP16Operand, \
548
901
             AlwaysPrintImm0), \
549
901
            OpNum, AlwaysPrintImm0); \
550
901
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
551
901
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
552
901
\
553
901
    if (!MCOperand_isReg(MO1)) { \
554
0
      printOperand(MI, OpNum, O); \
555
0
      return; \
556
0
    } \
557
901
\
558
901
    SStream_concat(O, "%s", markup("<mem:")); \
559
901
    SStream_concat0(O, "["); \
560
901
    printRegName(O, MCOperand_getReg(MO1)); \
561
901
\
562
901
    unsigned ImmOffs = \
563
901
      ARM_AM_getAM5FP16Offset(MCOperand_getImm(MO2)); \
564
901
    unsigned Op = ARM_AM_getAM5FP16Op(MCOperand_getImm(MO2)); \
565
901
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
566
582
      SStream_concat( \
567
582
        O, "%s%s%s%s", ", ", markup("<imm:"), "#", \
568
582
        ARM_AM_getAddrOpcStr(ARM_AM_getAM5FP16Op( \
569
582
          MCOperand_getImm(MO2)))); \
570
582
      printUInt32(O, ImmOffs * 2); \
571
582
      SStream_concat0(O, markup(">")); \
572
582
    } \
573
901
    SStream_concat(O, "%s", "]"); \
574
901
    SStream_concat0(O, markup(">")); \
575
901
  }
576
DEFINE_printAddrMode5FP16Operand(false);
577
578
static inline void printAddrMode6Operand(MCInst *MI, unsigned OpNum, SStream *O)
579
55.2k
{
580
55.2k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode6Operand, OpNum);
581
55.2k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
582
55.2k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
583
584
55.2k
  SStream_concat(O, "%s", markup("<mem:"));
585
55.2k
  SStream_concat0(O, "[");
586
55.2k
  printRegName(O, MCOperand_getReg(MO1));
587
55.2k
  if (MCOperand_getImm(MO2)) {
588
25.1k
    SStream_concat(O, "%s", ":");
589
25.1k
    printInt64(O, ((uint32_t)MCOperand_getImm(MO2)) << 3);
590
25.1k
  }
591
55.2k
  SStream_concat(O, "%s", "]");
592
55.2k
  SStream_concat0(O, markup(">"));
593
55.2k
}
594
595
static inline void printAddrMode7Operand(MCInst *MI, unsigned OpNum, SStream *O)
596
45.6k
{
597
45.6k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode7Operand, OpNum);
598
45.6k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
599
45.6k
  SStream_concat(O, "%s", markup("<mem:"));
600
45.6k
  SStream_concat0(O, "[");
601
45.6k
  printRegName(O, MCOperand_getReg(MO1));
602
45.6k
  SStream_concat(O, "%s", "]");
603
45.6k
  SStream_concat0(O, markup(">"));
604
45.6k
}
605
606
static inline void printAddrMode6OffsetOperand(MCInst *MI, unsigned OpNum,
607
                 SStream *O)
608
18.8k
{
609
18.8k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode6OffsetOperand, OpNum);
610
18.8k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
611
18.8k
  if (MCOperand_getReg(MO) == 0)
612
5.63k
    SStream_concat0(O, "!");
613
13.2k
  else {
614
13.2k
    SStream_concat0(O, ", ");
615
13.2k
    printRegName(O, MCOperand_getReg(MO));
616
13.2k
  }
617
18.8k
}
618
619
static inline void printBitfieldInvMaskImmOperand(MCInst *MI, unsigned OpNum,
620
              SStream *O)
621
1.13k
{
622
1.13k
  add_cs_detail(MI, ARM_OP_GROUP_BitfieldInvMaskImmOperand, OpNum);
623
1.13k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
624
1.13k
  uint32_t v = ~MCOperand_getImm(MO);
625
1.13k
  int32_t lsb = CountTrailingZeros_32(v);
626
1.13k
  int32_t width = (32 - countLeadingZeros(v)) - lsb;
627
628
1.13k
  SStream_concat(O, "%s", markup("<imm:"));
629
1.13k
  SStream_concat1(O, '#');
630
1.13k
  printInt32(O, lsb);
631
1.13k
  SStream_concat(O, "%s%s%s", markup(">"), ", ", markup("<imm:"));
632
1.13k
  printInt32Bang(O, width);
633
1.13k
  SStream_concat0(O, markup(">"));
634
1.13k
}
635
636
static inline void printMemBOption(MCInst *MI, unsigned OpNum, SStream *O)
637
3.91k
{
638
3.91k
  add_cs_detail(MI, ARM_OP_GROUP_MemBOption, OpNum);
639
3.91k
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
640
3.91k
  SStream_concat0(O, ARM_MB_MemBOptToString(
641
3.91k
           val, ARM_getFeatureBits(MI->csh->mode,
642
3.91k
                 ARM_HasV8Ops)));
643
3.91k
}
644
645
static inline void printInstSyncBOption(MCInst *MI, unsigned OpNum, SStream *O)
646
944
{
647
944
  add_cs_detail(MI, ARM_OP_GROUP_InstSyncBOption, OpNum);
648
944
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
649
944
  SStream_concat0(O, ARM_ISB_InstSyncBOptToString(val));
650
944
}
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
2.24k
{
661
2.24k
  add_cs_detail(MI, ARM_OP_GROUP_ShiftImmOperand, OpNum);
662
2.24k
  unsigned ShiftOp = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
663
2.24k
  bool isASR = (ShiftOp & (1 << 5)) != 0;
664
2.24k
  unsigned Amt = ShiftOp & 0x1f;
665
2.24k
  if (isASR) {
666
924
    SStream_concat(O, "%s%s%s", ", asr ", markup("<imm:"), "#");
667
924
    printUInt32(O, Amt == 0 ? 32 : Amt);
668
924
    SStream_concat0(O, markup(">"));
669
1.31k
  } else if (Amt) {
670
882
    SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
671
882
    printUInt32(O, Amt);
672
882
    SStream_concat0(O, markup(">"));
673
882
  }
674
2.24k
}
675
676
static inline void printPKHLSLShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
677
484
{
678
484
  add_cs_detail(MI, ARM_OP_GROUP_PKHLSLShiftImm, OpNum);
679
484
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
680
484
  if (Imm == 0)
681
338
    return;
682
683
146
  SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
684
146
  printUInt32(O, Imm);
685
146
  SStream_concat0(O, markup(">"));
686
146
}
687
688
static inline void printPKHASRShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
689
1.03k
{
690
1.03k
  add_cs_detail(MI, ARM_OP_GROUP_PKHASRShiftImm, OpNum);
691
1.03k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
692
  // A shift amount of 32 is encoded as 0.
693
1.03k
  if (Imm == 0)
694
334
    Imm = 32;
695
696
1.03k
  SStream_concat(O, "%s%s%s", ", asr ", markup("<imm:"), "#");
697
1.03k
  printUInt32(O, Imm);
698
1.03k
  SStream_concat0(O, markup(">"));
699
1.03k
}
700
701
static inline void printGPRPairOperand(MCInst *MI, unsigned OpNum, SStream *O)
702
770
{
703
770
  add_cs_detail(MI, ARM_OP_GROUP_GPRPairOperand, OpNum);
704
770
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
705
770
  printRegName(O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_0));
706
770
  SStream_concat0(O, ", ");
707
770
  printRegName(O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_1));
708
770
}
709
710
static inline void printSetendOperand(MCInst *MI, unsigned OpNum, SStream *O)
711
136
{
712
136
  add_cs_detail(MI, ARM_OP_GROUP_SetendOperand, OpNum);
713
136
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
714
136
  if (MCOperand_getImm(Op))
715
66
    SStream_concat0(O, "be");
716
70
  else
717
70
    SStream_concat0(O, "le");
718
136
}
719
720
static inline void printCPSIMod(MCInst *MI, unsigned OpNum, SStream *O)
721
2.12k
{
722
2.12k
  add_cs_detail(MI, ARM_OP_GROUP_CPSIMod, OpNum);
723
2.12k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
724
2.12k
  SStream_concat0(O, ARM_PROC_IModToString(MCOperand_getImm(Op)));
725
2.12k
}
726
727
static inline void printCPSIFlag(MCInst *MI, unsigned OpNum, SStream *O)
728
2.12k
{
729
2.12k
  add_cs_detail(MI, ARM_OP_GROUP_CPSIFlag, OpNum);
730
2.12k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
731
2.12k
  unsigned IFlags = MCOperand_getImm(Op);
732
8.49k
  for (int i = 2; i >= 0; --i)
733
6.37k
    if (IFlags & (1 << i))
734
2.06k
      SStream_concat0(O, ARM_PROC_IFlagsToString(1 << i));
735
736
2.12k
  if (IFlags == 0)
737
672
    SStream_concat0(O, "none");
738
2.12k
}
739
740
static inline void printMSRMaskOperand(MCInst *MI, unsigned OpNum, SStream *O)
741
9.05k
{
742
9.05k
  add_cs_detail(MI, ARM_OP_GROUP_MSRMaskOperand, OpNum);
743
9.05k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
744
745
9.05k
  if (ARM_getFeatureBits(MI->csh->mode, ARM_FeatureMClass)) {
746
8.34k
    unsigned SYSm = MCOperand_getImm(Op) & 0xFFF; // 12-bit SYSm
747
8.34k
    unsigned Opcode = MCInst_getOpcode(MI);
748
749
    // For writes, handle extended mask bits if the DSP extension is
750
    // present.
751
8.34k
    if (Opcode == ARM_t2MSR_M &&
752
8.34k
        ARM_getFeatureBits(MI->csh->mode, ARM_FeatureDSP)) {
753
7.06k
      const ARMSysReg_MClassSysReg *TheReg =
754
7.06k
        ARMSysReg_lookupMClassSysRegBy12bitSYSmValue(
755
7.06k
          SYSm);
756
7.06k
      if (TheReg && MClassSysReg_isInRequiredFeatures(
757
1.72k
                TheReg, ARM_FeatureDSP)) {
758
480
        SStream_concat0(O, TheReg->Name);
759
480
        return;
760
480
      }
761
7.06k
    }
762
763
    // Handle the basic 8-bit mask.
764
7.86k
    SYSm &= 0xff;
765
7.86k
    if (Opcode == ARM_t2MSR_M &&
766
7.86k
        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
6.58k
      const ARMSysReg_MClassSysReg *TheReg =
770
6.58k
        ARMSysReg_lookupMClassSysRegAPSRNonDeprecated(
771
6.58k
          SYSm);
772
6.58k
      if (TheReg) {
773
435
        SStream_concat0(O, TheReg->Name);
774
435
        return;
775
435
      }
776
6.58k
    }
777
778
7.43k
    const ARMSysReg_MClassSysReg *TheReg =
779
7.43k
      ARMSysReg_lookupMClassSysRegBy8bitSYSmValue(SYSm);
780
7.43k
    if (TheReg) {
781
6.52k
      SStream_concat0(O, TheReg->Name);
782
6.52k
      return;
783
6.52k
    }
784
785
910
    printUInt32(O, SYSm);
786
787
910
    return;
788
7.43k
  }
789
790
  // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
791
  // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
792
708
  unsigned SpecRegRBit = MCOperand_getImm(Op) >> 4;
793
708
  unsigned Mask = MCOperand_getImm(Op) & 0xf;
794
795
708
  if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
796
389
    SStream_concat0(O, "apsr_");
797
389
    switch (Mask) {
798
0
    default:
799
0
      CS_ASSERT_RET(0 && "Unexpected mask value!");
800
115
    case 4:
801
115
      SStream_concat0(O, "g");
802
115
      return;
803
68
    case 8:
804
68
      SStream_concat0(O, "nzcvq");
805
68
      return;
806
206
    case 12:
807
206
      SStream_concat0(O, "nzcvqg");
808
206
      return;
809
389
    }
810
389
  }
811
812
319
  if (SpecRegRBit)
813
189
    SStream_concat0(O, "spsr");
814
130
  else
815
130
    SStream_concat0(O, "cpsr");
816
817
319
  if (Mask) {
818
246
    SStream_concat0(O, "_");
819
820
246
    if (Mask & 8)
821
133
      SStream_concat0(O, "f");
822
823
246
    if (Mask & 4)
824
79
      SStream_concat0(O, "s");
825
826
246
    if (Mask & 2)
827
155
      SStream_concat0(O, "x");
828
829
246
    if (Mask & 1)
830
123
      SStream_concat0(O, "c");
831
246
  }
832
319
}
833
834
static inline void printBankedRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
835
432
{
836
432
  add_cs_detail(MI, ARM_OP_GROUP_BankedRegOperand, OpNum);
837
432
  uint32_t Banked = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
838
432
  const ARMBankedReg_BankedReg *TheReg =
839
432
    ARMBankedReg_lookupBankedRegByEncoding(Banked);
840
841
432
  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
432
  SStream_concat0(O, Name);
847
432
}
848
849
static inline void printMandatoryPredicateOperand(MCInst *MI, unsigned OpNum,
850
              SStream *O)
851
24.8k
{
852
24.8k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryPredicateOperand, OpNum);
853
24.8k
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
854
24.8k
    MCInst_getOperand(MI, (OpNum)));
855
24.8k
  SStream_concat0(O, ARMCondCodeToString(CC));
856
24.8k
}
857
858
static inline void
859
printMandatoryRestrictedPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
860
12.7k
{
861
12.7k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryRestrictedPredicateOperand,
862
12.7k
          OpNum);
863
12.7k
  if ((ARMCC_CondCodes)MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) ==
864
12.7k
      ARMCC_HS)
865
1.49k
    SStream_concat0(O, "cs");
866
11.2k
  else
867
11.2k
    printMandatoryPredicateOperand(MI, OpNum, O);
868
12.7k
}
869
870
static inline void
871
printMandatoryInvertedPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
872
1.12k
{
873
1.12k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryInvertedPredicateOperand,
874
1.12k
          OpNum);
875
1.12k
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
876
1.12k
    MCInst_getOperand(MI, (OpNum)));
877
1.12k
  SStream_concat0(O, ARMCondCodeToString(ARMCC_getOppositeCondition(CC)));
878
1.12k
}
879
880
static inline void printNoHashImmediate(MCInst *MI, unsigned OpNum, SStream *O)
881
45.8k
{
882
45.8k
  add_cs_detail(MI, ARM_OP_GROUP_NoHashImmediate, OpNum);
883
45.8k
  printInt64(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
884
45.8k
}
885
886
static inline void printPImmediate(MCInst *MI, unsigned OpNum, SStream *O)
887
74.9k
{
888
74.9k
  add_cs_detail(MI, ARM_OP_GROUP_PImmediate, OpNum);
889
74.9k
  SStream_concat(O, "%s%d", "p",
890
74.9k
           MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
891
74.9k
}
892
893
static inline void printCImmediate(MCInst *MI, unsigned OpNum, SStream *O)
894
137k
{
895
137k
  add_cs_detail(MI, ARM_OP_GROUP_CImmediate, OpNum);
896
137k
  SStream_concat(O, "%s%d", "c",
897
137k
           MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
898
137k
}
899
900
static inline void printCoprocOptionImm(MCInst *MI, unsigned OpNum, SStream *O)
901
5.72k
{
902
5.72k
  add_cs_detail(MI, ARM_OP_GROUP_CoprocOptionImm, OpNum);
903
5.72k
  SStream_concat(O, "%s", "{");
904
5.72k
  printInt64(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
905
5.72k
  SStream_concat0(O, "}");
906
5.72k
}
907
908
#define DEFINE_printAdrLabelOperand(scale) \
909
  static inline void CONCAT(printAdrLabelOperand, scale)( \
910
    MCInst * MI, unsigned OpNum, SStream *O) \
911
17.4k
  { \
912
17.4k
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_AdrLabelOperand, scale), \
913
17.4k
            OpNum, scale); \
914
17.4k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
915
17.4k
\
916
17.4k
    if (MCOperand_isExpr(MO)) { \
917
0
      return; \
918
0
    } \
919
17.4k
\
920
17.4k
    int32_t OffImm = (uint32_t)MCOperand_getImm(MO) << scale; \
921
17.4k
\
922
17.4k
    SStream_concat0(O, markup("<imm:")); \
923
17.4k
    if (OffImm == INT32_MIN) \
924
17.4k
      SStream_concat0(O, "#-0"); \
925
17.4k
    else if (OffImm < 0) { \
926
346
      printInt32Bang(O, OffImm); \
927
17.1k
    } else { \
928
17.1k
      printInt32Bang(O, OffImm); \
929
17.1k
    } \
930
17.4k
    SStream_concat0(O, markup(">")); \
931
17.4k
  }
ARMInstPrinter.c:printAdrLabelOperand_0
Line
Count
Source
911
619
  { \
912
619
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_AdrLabelOperand, scale), \
913
619
            OpNum, scale); \
914
619
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
915
619
\
916
619
    if (MCOperand_isExpr(MO)) { \
917
0
      return; \
918
0
    } \
919
619
\
920
619
    int32_t OffImm = (uint32_t)MCOperand_getImm(MO) << scale; \
921
619
\
922
619
    SStream_concat0(O, markup("<imm:")); \
923
619
    if (OffImm == INT32_MIN) \
924
619
      SStream_concat0(O, "#-0"); \
925
619
    else if (OffImm < 0) { \
926
346
      printInt32Bang(O, OffImm); \
927
346
    } else { \
928
273
      printInt32Bang(O, OffImm); \
929
273
    } \
930
619
    SStream_concat0(O, markup(">")); \
931
619
  }
ARMInstPrinter.c:printAdrLabelOperand_2
Line
Count
Source
911
16.8k
  { \
912
16.8k
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_AdrLabelOperand, scale), \
913
16.8k
            OpNum, scale); \
914
16.8k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
915
16.8k
\
916
16.8k
    if (MCOperand_isExpr(MO)) { \
917
0
      return; \
918
0
    } \
919
16.8k
\
920
16.8k
    int32_t OffImm = (uint32_t)MCOperand_getImm(MO) << scale; \
921
16.8k
\
922
16.8k
    SStream_concat0(O, markup("<imm:")); \
923
16.8k
    if (OffImm == INT32_MIN) \
924
16.8k
      SStream_concat0(O, "#-0"); \
925
16.8k
    else if (OffImm < 0) { \
926
0
      printInt32Bang(O, OffImm); \
927
16.8k
    } else { \
928
16.8k
      printInt32Bang(O, OffImm); \
929
16.8k
    } \
930
16.8k
    SStream_concat0(O, markup(">")); \
931
16.8k
  }
932
DEFINE_printAdrLabelOperand(0);
933
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
16.8k
  { \
939
16.8k
    CONCAT(printAdrLabelOperand, scale)(MI, OpNum, O); \
940
16.8k
  }
941
DEFINE_printAdrLabelOperandAddr(2);
942
943
static inline void printThumbS4ImmOperand(MCInst *MI, unsigned OpNum,
944
            SStream *O)
945
20.5k
{
946
20.5k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbS4ImmOperand, OpNum);
947
20.5k
  SStream_concat(O, "%s", markup("<imm:"));
948
20.5k
  printInt64Bang(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) * 4);
949
20.5k
  SStream_concat0(O, markup(">"));
950
20.5k
}
951
952
static inline void printThumbSRImm(MCInst *MI, unsigned OpNum, SStream *O)
953
56.9k
{
954
56.9k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbSRImm, OpNum);
955
56.9k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
956
56.9k
  SStream_concat(O, "%s", markup("<imm:"));
957
56.9k
  printUInt32Bang(O, (Imm == 0 ? 32 : Imm));
958
56.9k
  SStream_concat0(O, markup(">"));
959
56.9k
}
960
961
static inline void printThumbITMask(MCInst *MI, unsigned OpNum, SStream *O)
962
13.2k
{
963
13.2k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbITMask, OpNum);
964
  // (3 - the number of trailing zeros) is the number of then / else.
965
13.2k
  unsigned Mask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
966
13.2k
  unsigned NumTZ = CountTrailingZeros_32(Mask);
967
968
48.9k
  for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
969
35.7k
    if ((Mask >> Pos) & 1)
970
12.3k
      SStream_concat0(O, "e");
971
972
23.4k
    else
973
23.4k
      SStream_concat0(O, "t");
974
35.7k
  }
975
13.2k
}
976
977
static inline void printThumbAddrModeRROperand(MCInst *MI, unsigned Op,
978
                 SStream *O)
979
29.3k
{
980
29.3k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeRROperand, Op);
981
29.3k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
982
29.3k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
983
984
29.3k
  if (!MCOperand_isReg(
985
29.3k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
986
0
    printOperand(MI, Op, O);
987
0
    return;
988
0
  }
989
990
29.3k
  SStream_concat(O, "%s", markup("<mem:"));
991
29.3k
  SStream_concat0(O, "[");
992
29.3k
  printRegName(O, MCOperand_getReg(MO1));
993
29.3k
  unsigned RegNum = MCOperand_getReg(MO2);
994
29.3k
  if (RegNum) {
995
29.3k
    SStream_concat0(O, ", ");
996
29.3k
    printRegName(O, RegNum);
997
29.3k
  }
998
29.3k
  SStream_concat(O, "%s", "]");
999
29.3k
  SStream_concat0(O, markup(">"));
1000
29.3k
}
1001
1002
static inline void printThumbAddrModeImm5SOperand(MCInst *MI, unsigned Op,
1003
              SStream *O, unsigned Scale)
1004
180k
{
1005
180k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
1006
180k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
1007
1008
180k
  if (!MCOperand_isReg(
1009
180k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
1010
0
    printOperand(MI, Op, O);
1011
0
    return;
1012
0
  }
1013
1014
180k
  SStream_concat(O, "%s", markup("<mem:"));
1015
180k
  SStream_concat0(O, "[");
1016
180k
  printRegName(O, MCOperand_getReg(MO1));
1017
180k
  unsigned ImmOffs = MCOperand_getImm(MO2);
1018
180k
  if (ImmOffs) {
1019
168k
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
1020
168k
    printUInt32Bang(O, ImmOffs * Scale);
1021
168k
    SStream_concat0(O, markup(">"));
1022
168k
  }
1023
180k
  SStream_concat(O, "%s", "]");
1024
180k
  SStream_concat0(O, markup(">"));
1025
180k
}
1026
1027
static inline void printThumbAddrModeImm5S1Operand(MCInst *MI, unsigned Op,
1028
               SStream *O)
1029
49.8k
{
1030
49.8k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S1Operand, Op);
1031
49.8k
  printThumbAddrModeImm5SOperand(MI, Op, O, 1);
1032
49.8k
}
1033
1034
static inline void printThumbAddrModeImm5S2Operand(MCInst *MI, unsigned Op,
1035
               SStream *O)
1036
48.3k
{
1037
48.3k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S2Operand, Op);
1038
48.3k
  printThumbAddrModeImm5SOperand(MI, Op, O, 2);
1039
48.3k
}
1040
1041
static inline void printThumbAddrModeImm5S4Operand(MCInst *MI, unsigned Op,
1042
               SStream *O)
1043
56.1k
{
1044
56.1k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S4Operand, Op);
1045
56.1k
  printThumbAddrModeImm5SOperand(MI, Op, O, 4);
1046
56.1k
}
1047
1048
static inline void printThumbAddrModeSPOperand(MCInst *MI, unsigned Op,
1049
                 SStream *O)
1050
25.7k
{
1051
25.7k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeSPOperand, Op);
1052
25.7k
  printThumbAddrModeImm5SOperand(MI, Op, O, 4);
1053
25.7k
}
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
3.72k
{
1061
3.72k
  add_cs_detail(MI, ARM_OP_GROUP_T2SOOperand, OpNum);
1062
3.72k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1063
3.72k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1064
1065
3.72k
  unsigned Reg = MCOperand_getReg(MO1);
1066
3.72k
  printRegName(O, Reg);
1067
1068
  // Print the shift opc.
1069
1070
3.72k
  printRegImmShift(MI, O, ARM_AM_getSORegShOp(MCOperand_getImm(MO2)),
1071
3.72k
       ARM_AM_getSORegOffset(MCOperand_getImm(MO2)),
1072
3.72k
       getUseMarkup());
1073
3.72k
}
1074
1075
#define DEFINE_printAddrModeImm12Operand(AlwaysPrintImm0) \
1076
  static inline void CONCAT(printAddrModeImm12Operand, AlwaysPrintImm0)( \
1077
    MCInst * MI, unsigned OpNum, SStream *O) \
1078
10.9k
  { \
1079
10.9k
    add_cs_detail(MI, \
1080
10.9k
            CONCAT(ARM_OP_GROUP_AddrModeImm12Operand, \
1081
10.9k
             AlwaysPrintImm0), \
1082
10.9k
            OpNum, AlwaysPrintImm0); \
1083
10.9k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1084
10.9k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1085
10.9k
\
1086
10.9k
    if (!MCOperand_isReg(MO1)) { \
1087
0
      printOperand(MI, OpNum, O); \
1088
0
      return; \
1089
0
    } \
1090
10.9k
\
1091
10.9k
    SStream_concat(O, "%s", markup("<mem:")); \
1092
10.9k
    SStream_concat0(O, "["); \
1093
10.9k
    printRegName(O, MCOperand_getReg(MO1)); \
1094
10.9k
\
1095
10.9k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1096
10.9k
    bool isSub = OffImm < 0; \
1097
10.9k
\
1098
10.9k
    if (OffImm == INT32_MIN) \
1099
10.9k
      OffImm = 0; \
1100
10.9k
    if (isSub) { \
1101
3.62k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1102
3.62k
      printInt32Bang(O, OffImm); \
1103
3.62k
      SStream_concat0(O, markup(">")); \
1104
7.31k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1105
7.13k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1106
7.13k
      printInt32Bang(O, OffImm); \
1107
7.13k
      SStream_concat0(O, markup(">")); \
1108
7.13k
    } \
1109
10.9k
    SStream_concat(O, "%s", "]"); \
1110
10.9k
    SStream_concat0(O, markup(">")); \
1111
10.9k
  }
ARMInstPrinter.c:printAddrModeImm12Operand_0
Line
Count
Source
1078
5.80k
  { \
1079
5.80k
    add_cs_detail(MI, \
1080
5.80k
            CONCAT(ARM_OP_GROUP_AddrModeImm12Operand, \
1081
5.80k
             AlwaysPrintImm0), \
1082
5.80k
            OpNum, AlwaysPrintImm0); \
1083
5.80k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1084
5.80k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1085
5.80k
\
1086
5.80k
    if (!MCOperand_isReg(MO1)) { \
1087
0
      printOperand(MI, OpNum, O); \
1088
0
      return; \
1089
0
    } \
1090
5.80k
\
1091
5.80k
    SStream_concat(O, "%s", markup("<mem:")); \
1092
5.80k
    SStream_concat0(O, "["); \
1093
5.80k
    printRegName(O, MCOperand_getReg(MO1)); \
1094
5.80k
\
1095
5.80k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1096
5.80k
    bool isSub = OffImm < 0; \
1097
5.80k
\
1098
5.80k
    if (OffImm == INT32_MIN) \
1099
5.80k
      OffImm = 0; \
1100
5.80k
    if (isSub) { \
1101
1.52k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1102
1.52k
      printInt32Bang(O, OffImm); \
1103
1.52k
      SStream_concat0(O, markup(">")); \
1104
4.28k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1105
4.09k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1106
4.09k
      printInt32Bang(O, OffImm); \
1107
4.09k
      SStream_concat0(O, markup(">")); \
1108
4.09k
    } \
1109
5.80k
    SStream_concat(O, "%s", "]"); \
1110
5.80k
    SStream_concat0(O, markup(">")); \
1111
5.80k
  }
ARMInstPrinter.c:printAddrModeImm12Operand_1
Line
Count
Source
1078
5.13k
  { \
1079
5.13k
    add_cs_detail(MI, \
1080
5.13k
            CONCAT(ARM_OP_GROUP_AddrModeImm12Operand, \
1081
5.13k
             AlwaysPrintImm0), \
1082
5.13k
            OpNum, AlwaysPrintImm0); \
1083
5.13k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1084
5.13k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1085
5.13k
\
1086
5.13k
    if (!MCOperand_isReg(MO1)) { \
1087
0
      printOperand(MI, OpNum, O); \
1088
0
      return; \
1089
0
    } \
1090
5.13k
\
1091
5.13k
    SStream_concat(O, "%s", markup("<mem:")); \
1092
5.13k
    SStream_concat0(O, "["); \
1093
5.13k
    printRegName(O, MCOperand_getReg(MO1)); \
1094
5.13k
\
1095
5.13k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1096
5.13k
    bool isSub = OffImm < 0; \
1097
5.13k
\
1098
5.13k
    if (OffImm == INT32_MIN) \
1099
5.13k
      OffImm = 0; \
1100
5.13k
    if (isSub) { \
1101
2.09k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1102
2.09k
      printInt32Bang(O, OffImm); \
1103
2.09k
      SStream_concat0(O, markup(">")); \
1104
3.03k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1105
3.03k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1106
3.03k
      printInt32Bang(O, OffImm); \
1107
3.03k
      SStream_concat0(O, markup(">")); \
1108
3.03k
    } \
1109
5.13k
    SStream_concat(O, "%s", "]"); \
1110
5.13k
    SStream_concat0(O, markup(">")); \
1111
5.13k
  }
1112
DEFINE_printAddrModeImm12Operand(false);
1113
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
14.6k
  { \
1120
14.6k
    add_cs_detail(MI, \
1121
14.6k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8Operand, \
1122
14.6k
             AlwaysPrintImm0), \
1123
14.6k
            OpNum, AlwaysPrintImm0); \
1124
14.6k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1125
14.6k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1126
14.6k
\
1127
14.6k
    SStream_concat(O, "%s", markup("<mem:")); \
1128
14.6k
    SStream_concat0(O, "["); \
1129
14.6k
    printRegName(O, MCOperand_getReg(MO1)); \
1130
14.6k
\
1131
14.6k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1132
14.6k
    bool isSub = OffImm < 0; \
1133
14.6k
\
1134
14.6k
    if (OffImm == INT32_MIN) \
1135
14.6k
      OffImm = 0; \
1136
14.6k
    if (isSub) { \
1137
9.42k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1138
9.42k
      printInt32Bang(O, OffImm); \
1139
9.42k
      SStream_concat0(O, markup(">")); \
1140
9.42k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1141
4.26k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1142
4.26k
      printInt32Bang(O, OffImm); \
1143
4.26k
      SStream_concat0(O, markup(">")); \
1144
4.26k
    } \
1145
14.6k
    SStream_concat(O, "%s", "]"); \
1146
14.6k
    SStream_concat0(O, markup(">")); \
1147
14.6k
  }
ARMInstPrinter.c:printT2AddrModeImm8Operand_0
Line
Count
Source
1119
10.6k
  { \
1120
10.6k
    add_cs_detail(MI, \
1121
10.6k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8Operand, \
1122
10.6k
             AlwaysPrintImm0), \
1123
10.6k
            OpNum, AlwaysPrintImm0); \
1124
10.6k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1125
10.6k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1126
10.6k
\
1127
10.6k
    SStream_concat(O, "%s", markup("<mem:")); \
1128
10.6k
    SStream_concat0(O, "["); \
1129
10.6k
    printRegName(O, MCOperand_getReg(MO1)); \
1130
10.6k
\
1131
10.6k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1132
10.6k
    bool isSub = OffImm < 0; \
1133
10.6k
\
1134
10.6k
    if (OffImm == INT32_MIN) \
1135
10.6k
      OffImm = 0; \
1136
10.6k
    if (isSub) { \
1137
6.67k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1138
6.67k
      printInt32Bang(O, OffImm); \
1139
6.67k
      SStream_concat0(O, markup(">")); \
1140
6.67k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1141
2.97k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1142
2.97k
      printInt32Bang(O, OffImm); \
1143
2.97k
      SStream_concat0(O, markup(">")); \
1144
2.97k
    } \
1145
10.6k
    SStream_concat(O, "%s", "]"); \
1146
10.6k
    SStream_concat0(O, markup(">")); \
1147
10.6k
  }
ARMInstPrinter.c:printT2AddrModeImm8Operand_1
Line
Count
Source
1119
4.03k
  { \
1120
4.03k
    add_cs_detail(MI, \
1121
4.03k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8Operand, \
1122
4.03k
             AlwaysPrintImm0), \
1123
4.03k
            OpNum, AlwaysPrintImm0); \
1124
4.03k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1125
4.03k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1126
4.03k
\
1127
4.03k
    SStream_concat(O, "%s", markup("<mem:")); \
1128
4.03k
    SStream_concat0(O, "["); \
1129
4.03k
    printRegName(O, MCOperand_getReg(MO1)); \
1130
4.03k
\
1131
4.03k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1132
4.03k
    bool isSub = OffImm < 0; \
1133
4.03k
\
1134
4.03k
    if (OffImm == INT32_MIN) \
1135
4.03k
      OffImm = 0; \
1136
4.03k
    if (isSub) { \
1137
2.74k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1138
2.74k
      printInt32Bang(O, OffImm); \
1139
2.74k
      SStream_concat0(O, markup(">")); \
1140
2.74k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1141
1.28k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1142
1.28k
      printInt32Bang(O, OffImm); \
1143
1.28k
      SStream_concat0(O, markup(">")); \
1144
1.28k
    } \
1145
4.03k
    SStream_concat(O, "%s", "]"); \
1146
4.03k
    SStream_concat0(O, markup(">")); \
1147
4.03k
  }
1148
DEFINE_printT2AddrModeImm8Operand(true);
1149
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
9.96k
  { \
1156
9.96k
    add_cs_detail(MI, \
1157
9.96k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8s4Operand, \
1158
9.96k
             AlwaysPrintImm0), \
1159
9.96k
            OpNum, AlwaysPrintImm0); \
1160
9.96k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1161
9.96k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1162
9.96k
\
1163
9.96k
    if (!MCOperand_isReg(MO1)) { \
1164
0
      printOperand(MI, OpNum, O); \
1165
0
      return; \
1166
0
    } \
1167
9.96k
\
1168
9.96k
    SStream_concat(O, "%s", markup("<mem:")); \
1169
9.96k
    SStream_concat0(O, "["); \
1170
9.96k
    printRegName(O, MCOperand_getReg(MO1)); \
1171
9.96k
\
1172
9.96k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1173
9.96k
    bool isSub = OffImm < 0; \
1174
9.96k
\
1175
9.96k
    if (OffImm == INT32_MIN) \
1176
9.96k
      OffImm = 0; \
1177
9.96k
    if (isSub) { \
1178
4.94k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1179
4.94k
      printInt32Bang(O, OffImm); \
1180
4.94k
      SStream_concat0(O, markup(">")); \
1181
5.02k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1182
4.82k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1183
4.82k
      printInt32Bang(O, OffImm); \
1184
4.82k
      SStream_concat0(O, markup(">")); \
1185
4.82k
    } \
1186
9.96k
    SStream_concat(O, "%s", "]"); \
1187
9.96k
    SStream_concat0(O, markup(">")); \
1188
9.96k
  }
ARMInstPrinter.c:printT2AddrModeImm8s4Operand_0
Line
Count
Source
1155
2.32k
  { \
1156
2.32k
    add_cs_detail(MI, \
1157
2.32k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8s4Operand, \
1158
2.32k
             AlwaysPrintImm0), \
1159
2.32k
            OpNum, AlwaysPrintImm0); \
1160
2.32k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1161
2.32k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1162
2.32k
\
1163
2.32k
    if (!MCOperand_isReg(MO1)) { \
1164
0
      printOperand(MI, OpNum, O); \
1165
0
      return; \
1166
0
    } \
1167
2.32k
\
1168
2.32k
    SStream_concat(O, "%s", markup("<mem:")); \
1169
2.32k
    SStream_concat0(O, "["); \
1170
2.32k
    printRegName(O, MCOperand_getReg(MO1)); \
1171
2.32k
\
1172
2.32k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1173
2.32k
    bool isSub = OffImm < 0; \
1174
2.32k
\
1175
2.32k
    if (OffImm == INT32_MIN) \
1176
2.32k
      OffImm = 0; \
1177
2.32k
    if (isSub) { \
1178
1.19k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1179
1.19k
      printInt32Bang(O, OffImm); \
1180
1.19k
      SStream_concat0(O, markup(">")); \
1181
1.19k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1182
926
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1183
926
      printInt32Bang(O, OffImm); \
1184
926
      SStream_concat0(O, markup(">")); \
1185
926
    } \
1186
2.32k
    SStream_concat(O, "%s", "]"); \
1187
2.32k
    SStream_concat0(O, markup(">")); \
1188
2.32k
  }
ARMInstPrinter.c:printT2AddrModeImm8s4Operand_1
Line
Count
Source
1155
7.64k
  { \
1156
7.64k
    add_cs_detail(MI, \
1157
7.64k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8s4Operand, \
1158
7.64k
             AlwaysPrintImm0), \
1159
7.64k
            OpNum, AlwaysPrintImm0); \
1160
7.64k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1161
7.64k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1162
7.64k
\
1163
7.64k
    if (!MCOperand_isReg(MO1)) { \
1164
0
      printOperand(MI, OpNum, O); \
1165
0
      return; \
1166
0
    } \
1167
7.64k
\
1168
7.64k
    SStream_concat(O, "%s", markup("<mem:")); \
1169
7.64k
    SStream_concat0(O, "["); \
1170
7.64k
    printRegName(O, MCOperand_getReg(MO1)); \
1171
7.64k
\
1172
7.64k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1173
7.64k
    bool isSub = OffImm < 0; \
1174
7.64k
\
1175
7.64k
    if (OffImm == INT32_MIN) \
1176
7.64k
      OffImm = 0; \
1177
7.64k
    if (isSub) { \
1178
3.74k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1179
3.74k
      printInt32Bang(O, OffImm); \
1180
3.74k
      SStream_concat0(O, markup(">")); \
1181
3.89k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1182
3.89k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1183
3.89k
      printInt32Bang(O, OffImm); \
1184
3.89k
      SStream_concat0(O, markup(">")); \
1185
3.89k
    } \
1186
7.64k
    SStream_concat(O, "%s", "]"); \
1187
7.64k
    SStream_concat0(O, markup(">")); \
1188
7.64k
  }
1189
1190
DEFINE_printT2AddrModeImm8s4Operand(false);
1191
DEFINE_printT2AddrModeImm8s4Operand(true);
1192
1193
static inline void printT2AddrModeImm0_1020s4Operand(MCInst *MI, unsigned OpNum,
1194
                 SStream *O)
1195
564
{
1196
564
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm0_1020s4Operand, OpNum);
1197
564
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1198
564
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1199
1200
564
  SStream_concat(O, "%s", markup("<mem:"));
1201
564
  SStream_concat0(O, "[");
1202
564
  printRegName(O, MCOperand_getReg(MO1));
1203
564
  if (MCOperand_getImm(MO2)) {
1204
433
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
1205
433
    printInt64Bang(O, (int32_t)(MCOperand_getImm(MO2) * 4));
1206
433
    SStream_concat0(O, markup(">"));
1207
433
  }
1208
564
  SStream_concat(O, "%s", "]");
1209
564
  SStream_concat0(O, markup(">"));
1210
564
}
1211
1212
static inline void printT2AddrModeImm8OffsetOperand(MCInst *MI, unsigned OpNum,
1213
                SStream *O)
1214
2.89k
{
1215
2.89k
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm8OffsetOperand, OpNum);
1216
2.89k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1217
2.89k
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
1218
2.89k
  SStream_concat(O, "%s", ", ");
1219
2.89k
  SStream_concat0(O, markup("<imm:"));
1220
2.89k
  if (OffImm == INT32_MIN)
1221
706
    SStream_concat0(O, "#-0");
1222
2.18k
  else if (OffImm < 0) {
1223
1.19k
    printInt32Bang(O, OffImm);
1224
1.19k
  } else {
1225
995
    printInt32Bang(O, OffImm);
1226
995
  }
1227
2.89k
  SStream_concat0(O, markup(">"));
1228
2.89k
}
1229
1230
static inline void
1231
printT2AddrModeImm8s4OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O)
1232
3.12k
{
1233
3.12k
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm8s4OffsetOperand, OpNum);
1234
3.12k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1235
3.12k
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
1236
1237
3.12k
  SStream_concat(O, "%s", ", ");
1238
3.12k
  SStream_concat0(O, markup("<imm:"));
1239
3.12k
  if (OffImm == INT32_MIN)
1240
677
    SStream_concat0(O, "#-0");
1241
2.44k
  else if (OffImm < 0) {
1242
773
    printInt32Bang(O, OffImm);
1243
1.67k
  } else {
1244
1.67k
    printInt32Bang(O, OffImm);
1245
1.67k
  }
1246
3.12k
  SStream_concat0(O, markup(">"));
1247
3.12k
}
1248
1249
static inline void printT2AddrModeSoRegOperand(MCInst *MI, unsigned OpNum,
1250
                 SStream *O)
1251
2.29k
{
1252
2.29k
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeSoRegOperand, OpNum);
1253
2.29k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1254
2.29k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1255
2.29k
  MCOperand *MO3 = MCInst_getOperand(MI, (OpNum + 2));
1256
1257
2.29k
  SStream_concat(O, "%s", markup("<mem:"));
1258
2.29k
  SStream_concat0(O, "[");
1259
2.29k
  printRegName(O, MCOperand_getReg(MO1));
1260
1261
2.29k
  SStream_concat0(O, ", ");
1262
2.29k
  printRegName(O, MCOperand_getReg(MO2));
1263
1264
2.29k
  unsigned ShAmt = MCOperand_getImm(MO3);
1265
2.29k
  if (ShAmt) {
1266
1.12k
    SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
1267
1.12k
    printUInt32(O, ShAmt);
1268
1.12k
    SStream_concat0(O, markup(">"));
1269
1.12k
  }
1270
2.29k
  SStream_concat(O, "%s", "]");
1271
2.29k
  SStream_concat0(O, markup(">"));
1272
2.29k
}
1273
1274
static inline void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1275
884
{
1276
884
  add_cs_detail(MI, ARM_OP_GROUP_FPImmOperand, OpNum);
1277
884
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1278
884
  SStream_concat(O, "%s", markup("<imm:"));
1279
884
  printFloatBang(O, ARM_AM_getFPImmFloat(MCOperand_getImm(MO)));
1280
884
  SStream_concat0(O, markup(">"));
1281
884
}
1282
1283
static inline void printVMOVModImmOperand(MCInst *MI, unsigned OpNum,
1284
            SStream *O)
1285
4.07k
{
1286
4.07k
  add_cs_detail(MI, ARM_OP_GROUP_VMOVModImmOperand, OpNum);
1287
4.07k
  unsigned EncodedImm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1288
4.07k
  unsigned EltBits;
1289
4.07k
  uint64_t Val = ARM_AM_decodeVMOVModImm(EncodedImm, &EltBits);
1290
4.07k
  SStream_concat(O, "%s", markup("<imm:"));
1291
4.07k
  printUInt64Bang(O, Val);
1292
4.07k
  SStream_concat0(O, markup(">"));
1293
4.07k
}
1294
1295
static inline void printImmPlusOneOperand(MCInst *MI, unsigned OpNum,
1296
            SStream *O)
1297
2.07k
{
1298
2.07k
  add_cs_detail(MI, ARM_OP_GROUP_ImmPlusOneOperand, OpNum);
1299
2.07k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1300
2.07k
  SStream_concat(O, "%s", markup("<imm:"));
1301
2.07k
  printUInt32Bang(O, Imm + 1);
1302
2.07k
  SStream_concat0(O, markup(">"));
1303
2.07k
}
1304
1305
static inline void printRotImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1306
1.54k
{
1307
1.54k
  add_cs_detail(MI, ARM_OP_GROUP_RotImmOperand, OpNum);
1308
1.54k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1309
1.54k
  if (Imm == 0)
1310
189
    return;
1311
1312
1.36k
  SStream_concat(O, "%s%s%s%d", ", ror ", markup("<imm:"), "#", 8 * Imm);
1313
1.36k
  SStream_concat0(O, markup(">"));
1314
1.36k
}
1315
1316
static inline void printModImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1317
7.71k
{
1318
7.71k
  add_cs_detail(MI, ARM_OP_GROUP_ModImmOperand, OpNum);
1319
7.71k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
1320
1321
  // Support for fixups (MCFixup)
1322
7.71k
  if (MCOperand_isExpr(Op)) {
1323
0
    printOperand(MI, OpNum, O);
1324
0
    return;
1325
0
  }
1326
1327
7.71k
  unsigned Bits = MCOperand_getImm(Op) & 0xFF;
1328
7.71k
  unsigned Rot = (MCOperand_getImm(Op) & 0xF00) >> 7;
1329
1330
7.71k
  bool PrintUnsigned = false;
1331
7.71k
  switch (MCInst_getOpcode(MI)) {
1332
422
  case ARM_MOVi:
1333
    // Movs to PC should be treated unsigned
1334
422
    PrintUnsigned =
1335
422
      (MCOperand_getReg(MCInst_getOperand(MI, (OpNum - 1))) ==
1336
422
       ARM_PC);
1337
422
    break;
1338
453
  case ARM_MSRi:
1339
    // Movs to special registers should be treated unsigned
1340
453
    PrintUnsigned = true;
1341
453
    break;
1342
7.71k
  }
1343
1344
7.71k
  int32_t Rotated = ARM_AM_rotr32(Bits, Rot);
1345
7.71k
  if (ARM_AM_getSOImmVal(Rotated) == MCOperand_getImm(Op)) {
1346
    // #rot has the least possible value
1347
5.85k
    SStream_concat(O, "%s", "#");
1348
5.85k
    SStream_concat0(O, markup("<imm:"));
1349
5.85k
    if (PrintUnsigned)
1350
347
      printUInt32(O, (uint32_t)(Rotated));
1351
5.50k
    else
1352
5.50k
      printInt32(O, Rotated);
1353
5.85k
    SStream_concat0(O, markup(">"));
1354
5.85k
    return;
1355
5.85k
  }
1356
1357
  // Explicit #bits, #rot implied
1358
1.86k
  SStream_concat(O, "%s%s%u", "#", markup("<imm:"), Bits);
1359
1.86k
  SStream_concat(O, "%s%s%s%u", markup(">"), ", #", markup("<imm:"), Rot);
1360
1.86k
  SStream_concat0(O, markup(">"));
1361
1.86k
}
1362
1363
static inline void printFBits16(MCInst *MI, unsigned OpNum, SStream *O)
1364
1.80k
{
1365
1.80k
  add_cs_detail(MI, ARM_OP_GROUP_FBits16, OpNum);
1366
1.80k
  SStream_concat(O, "%s%s", markup("<imm:"), "#");
1367
1.80k
  SStream_concat(O, "%d",
1368
1.80k
           16 - MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1369
1.80k
  SStream_concat0(O, markup(">"));
1370
1.80k
}
1371
1372
static inline void printFBits32(MCInst *MI, unsigned OpNum, SStream *O)
1373
1.18k
{
1374
1.18k
  add_cs_detail(MI, ARM_OP_GROUP_FBits32, OpNum);
1375
1.18k
  SStream_concat(O, "%s%s", markup("<imm:"), "#");
1376
1.18k
  printInt64(O, 32 - MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1377
1.18k
  SStream_concat0(O, markup(">"));
1378
1.18k
}
1379
1380
static inline void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O)
1381
12.4k
{
1382
12.4k
  add_cs_detail(MI, ARM_OP_GROUP_VectorIndex, OpNum);
1383
12.4k
  SStream_concat(O, "%s", "[");
1384
12.4k
  printInt64(O,
1385
12.4k
       (int32_t)MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1386
12.4k
  SStream_concat0(O, "]");
1387
12.4k
}
1388
1389
static inline void printVectorListOne(MCInst *MI, unsigned OpNum, SStream *O)
1390
3.05k
{
1391
3.05k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListOne, OpNum);
1392
3.05k
  SStream_concat0(O, "{");
1393
3.05k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1394
3.05k
  SStream_concat0(O, "}");
1395
3.05k
}
1396
1397
static inline void printVectorListTwo(MCInst *MI, unsigned OpNum, SStream *O)
1398
8.03k
{
1399
8.03k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwo, OpNum);
1400
8.03k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1401
8.03k
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1402
8.03k
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1);
1403
8.03k
  SStream_concat0(O, "{");
1404
8.03k
  printRegName(O, Reg0);
1405
8.03k
  SStream_concat0(O, ", ");
1406
8.03k
  printRegName(O, Reg1);
1407
8.03k
  SStream_concat0(O, "}");
1408
8.03k
}
1409
1410
static inline void printVectorListTwoSpaced(MCInst *MI, unsigned OpNum,
1411
              SStream *O)
1412
2.85k
{
1413
2.85k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoSpaced, OpNum);
1414
2.85k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1415
2.85k
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1416
2.85k
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2);
1417
2.85k
  SStream_concat0(O, "{");
1418
2.85k
  printRegName(O, Reg0);
1419
2.85k
  SStream_concat0(O, ", ");
1420
2.85k
  printRegName(O, Reg1);
1421
2.85k
  SStream_concat0(O, "}");
1422
2.85k
}
1423
1424
static inline void printVectorListThree(MCInst *MI, unsigned OpNum, SStream *O)
1425
4.37k
{
1426
4.37k
  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
4.37k
  SStream_concat0(O, "{");
1431
4.37k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1432
4.37k
  SStream_concat0(O, ", ");
1433
4.37k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1434
4.37k
  SStream_concat0(O, ", ");
1435
4.37k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1436
4.37k
  SStream_concat0(O, "}");
1437
4.37k
}
1438
1439
static inline void printVectorListFour(MCInst *MI, unsigned OpNum, SStream *O)
1440
6.10k
{
1441
6.10k
  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
6.10k
  SStream_concat0(O, "{");
1446
6.10k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1447
6.10k
  SStream_concat0(O, ", ");
1448
6.10k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1449
6.10k
  SStream_concat0(O, ", ");
1450
6.10k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1451
6.10k
  SStream_concat0(O, ", ");
1452
6.10k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 3);
1453
6.10k
  SStream_concat0(O, "}");
1454
6.10k
}
1455
1456
static inline void printVectorListOneAllLanes(MCInst *MI, unsigned OpNum,
1457
                SStream *O)
1458
395
{
1459
395
  add_cs_detail(MI, ARM_OP_GROUP_VectorListOneAllLanes, OpNum);
1460
395
  SStream_concat0(O, "{");
1461
395
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1462
395
  SStream_concat0(O, "[]}");
1463
395
}
1464
1465
static inline void printVectorListTwoAllLanes(MCInst *MI, unsigned OpNum,
1466
                SStream *O)
1467
1.23k
{
1468
1.23k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoAllLanes, OpNum);
1469
1.23k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1470
1.23k
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1471
1.23k
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1);
1472
1.23k
  SStream_concat0(O, "{");
1473
1.23k
  printRegName(O, Reg0);
1474
1.23k
  SStream_concat0(O, "[], ");
1475
1.23k
  printRegName(O, Reg1);
1476
1.23k
  SStream_concat0(O, "[]}");
1477
1.23k
}
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
922
{
1516
922
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoSpacedAllLanes, OpNum);
1517
922
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1518
922
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1519
922
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2);
1520
922
  SStream_concat0(O, "{");
1521
922
  printRegName(O, Reg0);
1522
922
  SStream_concat0(O, "[], ");
1523
922
  printRegName(O, Reg1);
1524
922
  SStream_concat0(O, "[]}");
1525
922
}
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
2.78k
  { \
1599
2.78k
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
2.78k
            OpNum, NumRegs); \
1601
2.78k
    unsigned Reg = \
1602
2.78k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
2.78k
    const char *Prefix = "{"; \
1604
12.6k
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
9.90k
      SStream_concat0(O, Prefix); \
1606
9.90k
      printRegName( \
1607
9.90k
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
9.90k
                  ARM_qsub_0 + i)); \
1609
9.90k
      Prefix = ", "; \
1610
9.90k
    } \
1611
2.78k
    SStream_concat0(O, "}"); \
1612
2.78k
  }
ARMInstPrinter.c:printMVEVectorList_2
Line
Count
Source
1598
620
  { \
1599
620
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
620
            OpNum, NumRegs); \
1601
620
    unsigned Reg = \
1602
620
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
620
    const char *Prefix = "{"; \
1604
1.86k
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
1.24k
      SStream_concat0(O, Prefix); \
1606
1.24k
      printRegName( \
1607
1.24k
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
1.24k
                  ARM_qsub_0 + i)); \
1609
1.24k
      Prefix = ", "; \
1610
1.24k
    } \
1611
620
    SStream_concat0(O, "}"); \
1612
620
  }
ARMInstPrinter.c:printMVEVectorList_4
Line
Count
Source
1598
2.16k
  { \
1599
2.16k
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
2.16k
            OpNum, NumRegs); \
1601
2.16k
    unsigned Reg = \
1602
2.16k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
2.16k
    const char *Prefix = "{"; \
1604
10.8k
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
8.66k
      SStream_concat0(O, Prefix); \
1606
8.66k
      printRegName( \
1607
8.66k
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
8.66k
                  ARM_qsub_0 + i)); \
1609
8.66k
      Prefix = ", "; \
1610
8.66k
    } \
1611
2.16k
    SStream_concat0(O, "}"); \
1612
2.16k
  }
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.46k
  { \
1620
3.46k
    add_cs_detail( \
1621
3.46k
      MI, \
1622
3.46k
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
3.46k
             Remainder), \
1624
3.46k
      OpNo, Angle, Remainder); \
1625
3.46k
    unsigned Val = \
1626
3.46k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
3.46k
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
3.46k
  }
ARMInstPrinter.c:printComplexRotationOp_90_0
Line
Count
Source
1619
2.25k
  { \
1620
2.25k
    add_cs_detail( \
1621
2.25k
      MI, \
1622
2.25k
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
2.25k
             Remainder), \
1624
2.25k
      OpNo, Angle, Remainder); \
1625
2.25k
    unsigned Val = \
1626
2.25k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
2.25k
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
2.25k
  }
ARMInstPrinter.c:printComplexRotationOp_180_90
Line
Count
Source
1619
1.21k
  { \
1620
1.21k
    add_cs_detail( \
1621
1.21k
      MI, \
1622
1.21k
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
1.21k
             Remainder), \
1624
1.21k
      OpNo, Angle, Remainder); \
1625
1.21k
    unsigned Val = \
1626
1.21k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
1.21k
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
1.21k
  }
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
37.5k
{
1636
37.5k
  add_cs_detail(MI, ARM_OP_GROUP_VPTPredicateOperand, OpNum);
1637
37.5k
  ARMVCC_VPTCodes CC = (ARMVCC_VPTCodes)MCOperand_getImm(
1638
37.5k
    MCInst_getOperand(MI, (OpNum)));
1639
37.5k
  if (CC != ARMVCC_None)
1640
4.66k
    SStream_concat0(O, ARMVPTPredToString(CC));
1641
37.5k
}
1642
1643
static inline void printVPTMask(MCInst *MI, unsigned OpNum, SStream *O)
1644
8.63k
{
1645
8.63k
  add_cs_detail(MI, ARM_OP_GROUP_VPTMask, OpNum);
1646
  // (3 - the number of trailing zeroes) is the number of them / else.
1647
8.63k
  unsigned Mask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1648
8.63k
  unsigned NumTZ = CountTrailingZeros_32(Mask);
1649
1650
30.7k
  for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
1651
22.1k
    bool T = ((Mask >> Pos) & 1) == 0;
1652
22.1k
    if (T)
1653
12.8k
      SStream_concat0(O, "t");
1654
1655
9.29k
    else
1656
9.29k
      SStream_concat0(O, "e");
1657
22.1k
  }
1658
8.63k
}
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
1.23M
{
1673
1.23M
  bool isAlias = false;
1674
1.23M
  bool useAliasDetails = map_use_alias_details(MI);
1675
1.23M
  map_set_fill_detail_ops(MI, useAliasDetails);
1676
1.23M
  unsigned Opcode = MCInst_getOpcode(MI);
1677
1.23M
  uint64_t Address = MI->address;
1678
1679
1.23M
  switch (Opcode) {
1680
  // Check for MOVs and print canonical forms, instead.
1681
452
  case ARM_MOVsr: {
1682
452
    isAlias = true;
1683
452
    MCInst_setIsAlias(MI, isAlias);
1684
    // FIXME: Thumb variants?
1685
452
    MCOperand *MO3 = MCInst_getOperand(MI, (3));
1686
1687
452
    SStream_concat1(O, ' ');
1688
452
    SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp(
1689
452
             MCOperand_getImm(MO3))));
1690
452
    printSBitModifierOperand(MI, 6, O);
1691
452
    printPredicateOperand(MI, 4, O);
1692
1693
452
    SStream_concat0(O, " ");
1694
1695
452
    printOperand(MI, 0, O);
1696
452
    SStream_concat0(O, ", ");
1697
452
    printOperand(MI, 1, O);
1698
1699
452
    SStream_concat0(O, ", ");
1700
452
    printOperand(MI, 2, O);
1701
1702
452
    if (useAliasDetails)
1703
452
      return;
1704
0
    else
1705
0
      goto add_real_detail;
1706
452
  }
1707
1708
1.77k
  case ARM_MOVsi: {
1709
1.77k
    isAlias = true;
1710
1.77k
    MCInst_setIsAlias(MI, isAlias);
1711
    // FIXME: Thumb variants?
1712
1.77k
    MCOperand *MO2 = MCInst_getOperand(MI, (2));
1713
1714
1.77k
    SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp(
1715
1.77k
             MCOperand_getImm(MO2))));
1716
1.77k
    printSBitModifierOperand(MI, 5, O);
1717
1.77k
    printPredicateOperand(MI, 3, O);
1718
1719
1.77k
    SStream_concat0(O, " ");
1720
1721
1.77k
    printOperand(MI, 0, O);
1722
1.77k
    SStream_concat0(O, ", ");
1723
1.77k
    printOperand(MI, 1, O);
1724
1725
1.77k
    if (ARM_AM_getSORegShOp(MCOperand_getImm(MO2)) == ARM_AM_rrx) {
1726
41
      if (useAliasDetails)
1727
41
        return;
1728
0
      else
1729
0
        goto add_real_detail;
1730
41
    }
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
538
  case ARM_STMDB_UPD:
1744
869
  case ARM_t2STMDB_UPD:
1745
869
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP &&
1746
869
        MCInst_getNumOperands(MI) > 5) {
1747
280
      isAlias = true;
1748
280
      MCInst_setIsAlias(MI, isAlias);
1749
      // Should only print PUSH if there are at least two registers in the
1750
      // list.
1751
280
      SStream_concat0(O, "push");
1752
280
      printPredicateOperand(MI, 2, O);
1753
280
      if (Opcode == ARM_t2STMDB_UPD)
1754
69
        SStream_concat0(O, ".w");
1755
280
      SStream_concat0(O, " ");
1756
1757
280
      printRegisterList(MI, 4, O);
1758
280
      if (useAliasDetails)
1759
280
        return;
1760
0
      else
1761
0
        goto add_real_detail;
1762
280
    } else
1763
589
      break;
1764
1765
2.01k
  case ARM_STR_PRE_IMM:
1766
2.01k
    if (MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP &&
1767
2.01k
        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
2.01k
      break;
1782
1783
  // A8.6.122 POP
1784
611
  case ARM_LDMIA_UPD:
1785
911
  case ARM_t2LDMIA_UPD:
1786
911
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP &&
1787
911
        MCInst_getNumOperands(MI) > 5) {
1788
263
      isAlias = true;
1789
263
      MCInst_setIsAlias(MI, isAlias);
1790
      // Should only print POP if there are at least two registers in the
1791
      // list.
1792
263
      SStream_concat0(O, "pop");
1793
263
      printPredicateOperand(MI, 2, O);
1794
263
      if (Opcode == ARM_t2LDMIA_UPD)
1795
188
        SStream_concat0(O, ".w");
1796
263
      SStream_concat0(O, " ");
1797
1798
263
      printRegisterList(MI, 4, O);
1799
263
      if (useAliasDetails)
1800
263
        return;
1801
0
      else
1802
0
        goto add_real_detail;
1803
263
    } else
1804
648
      break;
1805
1806
723
  case ARM_LDR_POST_IMM:
1807
723
    if ((MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP) &&
1808
723
        ((ARM_AM_getAM2Offset(MCOperand_getImm(
1809
252
            MCInst_getOperand(MI, (4)))) == 4))) {
1810
34
      isAlias = true;
1811
34
      MCInst_setIsAlias(MI, isAlias);
1812
34
      SStream_concat0(O, "pop");
1813
34
      printPredicateOperand(MI, 5, O);
1814
34
      SStream_concat0(O, " {");
1815
34
      printOperand(MI, 0, O);
1816
34
      SStream_concat0(O, "}");
1817
34
      if (useAliasDetails)
1818
34
        return;
1819
0
      else
1820
0
        goto add_real_detail;
1821
34
    } else
1822
689
      break;
1823
627
  case ARM_t2LDR_POST:
1824
627
    if ((MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP) &&
1825
627
        (Opcode == ARM_t2LDR_POST &&
1826
561
         (MCOperand_getImm(MCInst_getOperand(MI, (3))) == 4))) {
1827
200
      isAlias = true;
1828
200
      MCInst_setIsAlias(MI, isAlias);
1829
200
      SStream_concat0(O, "pop");
1830
200
      printPredicateOperand(MI, 4, O);
1831
200
      SStream_concat0(O, " {");
1832
200
      printOperand(MI, 0, O);
1833
200
      SStream_concat0(O, "}");
1834
200
      if (useAliasDetails)
1835
200
        return;
1836
0
      else
1837
0
        goto add_real_detail;
1838
200
    } else
1839
427
      break;
1840
1841
  // A8.6.355 VPUSH
1842
288
  case ARM_VSTMSDB_UPD:
1843
384
  case ARM_VSTMDDB_UPD:
1844
384
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP) {
1845
64
      isAlias = true;
1846
64
      MCInst_setIsAlias(MI, isAlias);
1847
64
      SStream_concat0(O, "vpush");
1848
64
      printPredicateOperand(MI, 2, O);
1849
64
      SStream_concat0(O, " ");
1850
1851
64
      printRegisterList(MI, 4, O);
1852
64
      if (useAliasDetails)
1853
64
        return;
1854
0
      else
1855
0
        goto add_real_detail;
1856
64
    } else
1857
320
      break;
1858
1859
  // A8.6.354 VPOP
1860
542
  case ARM_VLDMSIA_UPD:
1861
645
  case ARM_VLDMDIA_UPD:
1862
645
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP) {
1863
83
      isAlias = true;
1864
83
      MCInst_setIsAlias(MI, isAlias);
1865
83
      SStream_concat1(O, ' ');
1866
83
      SStream_concat0(O, "vpop");
1867
83
      printPredicateOperand(MI, 2, O);
1868
83
      SStream_concat0(O, " ");
1869
1870
83
      printRegisterList(MI, 4, O);
1871
83
      if (useAliasDetails)
1872
83
        return;
1873
0
      else
1874
0
        goto add_real_detail;
1875
83
    } else
1876
562
      break;
1877
1878
13.5k
  case ARM_tLDMIA: {
1879
13.5k
    isAlias = true;
1880
13.5k
    MCInst_setIsAlias(MI, isAlias);
1881
13.5k
    bool Writeback = true;
1882
13.5k
    unsigned BaseReg = MCOperand_getReg(MCInst_getOperand(MI, (0)));
1883
73.6k
    for (unsigned i = 3; i < MCInst_getNumOperands(MI); ++i) {
1884
60.1k
      if (MCOperand_getReg(MCInst_getOperand(MI, (i))) ==
1885
60.1k
          BaseReg)
1886
6.71k
        Writeback = false;
1887
60.1k
    }
1888
1889
13.5k
    SStream_concat0(O, "ldm");
1890
1891
13.5k
    printPredicateOperand(MI, 1, O);
1892
13.5k
    SStream_concat0(O, " ");
1893
1894
13.5k
    printOperand(MI, 0, O);
1895
13.5k
    if (Writeback) {
1896
6.82k
      SStream_concat0(O, "!");
1897
6.82k
    }
1898
13.5k
    SStream_concat0(O, ", ");
1899
13.5k
    printRegisterList(MI, 3, O);
1900
13.5k
    if (useAliasDetails)
1901
13.5k
      return;
1902
0
    else
1903
0
      goto add_real_detail;
1904
13.5k
  }
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
215
  case ARM_LDREXD:
1913
631
  case ARM_STREXD:
1914
701
  case ARM_LDAEXD:
1915
770
  case ARM_STLEXD: {
1916
770
    const MCRegisterClass *MRC =
1917
770
      MCRegisterInfo_getRegClass(MI->MRI, ARM_GPRRegClassID);
1918
770
    bool isStore = Opcode == ARM_STREXD || Opcode == ARM_STLEXD;
1919
770
    unsigned Reg = MCOperand_getReg(
1920
770
      MCInst_getOperand(MI, isStore ? 1 : 0));
1921
1922
770
    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
770
    break;
1950
770
  }
1951
770
  case ARM_TSB:
1952
77
  case ARM_t2TSB:
1953
77
    isAlias = true;
1954
77
    MCInst_setIsAlias(MI, isAlias);
1955
1956
77
    SStream_concat0(O, " tsb csync");
1957
77
    if (useAliasDetails)
1958
77
      return;
1959
0
    else
1960
0
      goto add_real_detail;
1961
1.28k
  case ARM_t2DSB:
1962
1.28k
    isAlias = true;
1963
1.28k
    MCInst_setIsAlias(MI, isAlias);
1964
1965
1.28k
    switch (MCOperand_getImm(MCInst_getOperand(MI, (0)))) {
1966
1.15k
    default:
1967
1.15k
      if (!printAliasInstr(MI, Address, O))
1968
1.15k
        printInstruction(MI, Address, O);
1969
1.15k
      break;
1970
66
    case 0:
1971
66
      SStream_concat0(O, " ssbb");
1972
66
      break;
1973
67
    case 4:
1974
67
      SStream_concat0(O, " pssbb");
1975
67
      break;
1976
1.28k
    };
1977
1.28k
    if (useAliasDetails)
1978
1.28k
      return;
1979
0
    else
1980
0
      goto add_real_detail;
1981
1.23M
  }
1982
1983
1.21M
  if (!isAlias)
1984
1.21M
    isAlias |= printAliasInstr(MI, Address, O);
1985
1986
1.21M
add_real_detail:
1987
1.21M
  MCInst_setIsAlias(MI, isAlias);
1988
1.21M
  if (!isAlias || !useAliasDetails) {
1989
1.21M
    map_set_fill_detail_ops(MI, !(isAlias && useAliasDetails));
1990
1.21M
    if (isAlias)
1991
0
      SStream_Close(O);
1992
1.21M
    printInstruction(MI, Address, O);
1993
1.21M
    if (isAlias)
1994
0
      SStream_Open(O);
1995
1.21M
  }
1996
1.21M
}
1997
1998
const char *ARM_LLVM_getRegisterName(unsigned RegNo, unsigned AltIdx)
1999
803k
{
2000
803k
  return getRegisterName(RegNo, AltIdx);
2001
803k
}
2002
2003
void ARM_LLVM_printInstruction(MCInst *MI, SStream *O,
2004
             void * /* MCRegisterInfo* */ info)
2005
1.23M
{
2006
1.23M
  printInst(MI, O, info);
2007
1.23M
}