Coverage Report

Created: 2025-07-09 06:32

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