Coverage Report

Created: 2025-10-10 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/SystemZ/SystemZInstPrinter.c
Line
Count
Source
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//===- SystemZInstPrinter.cpp - Convert SystemZ 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
#include <ctype.h>
24
#include <stdint.h>
25
#include <stdio.h>
26
#include <string.h>
27
#include <stdlib.h>
28
#include <capstone/platform.h>
29
30
#include "../../MathExtras.h"
31
#include "../../MCAsmInfo.h"
32
33
#include "SystemZMapping.h"
34
#include "SystemZInstPrinter.h"
35
36
21.7k
#define CONCAT(a, b) CONCAT_(a, b)
37
21.7k
#define CONCAT_(a, b) a##_##b
38
39
static void printAddress(const MCAsmInfo *MAI, MCRegister Base,
40
       const MCOperand *DispMO, MCRegister Index, SStream *O);
41
static void printMCOperandMAI(const MCOperand *MO, const MCAsmInfo *MAI,
42
            SStream *O);
43
static void printRegName(const MCInst *MI, SStream *O, MCRegister Reg);
44
static void printInst(MCInst *MI, uint64_t Address, const char *Annot,
45
          SStream *O);
46
static void printOperand(MCInst *MI, int OpNum, SStream *O);
47
static void printU1ImmOperand(MCInst *MI, int OpNum, SStream *O);
48
static void printU2ImmOperand(MCInst *MI, int OpNum, SStream *O);
49
static void printU3ImmOperand(MCInst *MI, int OpNum, SStream *O);
50
static void printU4ImmOperand(MCInst *MI, int OpNum, SStream *O);
51
static void printS8ImmOperand(MCInst *MI, int OpNum, SStream *O);
52
static void printU8ImmOperand(MCInst *MI, int OpNum, SStream *O);
53
static void printU12ImmOperand(MCInst *MI, int OpNum, SStream *O);
54
static void printS16ImmOperand(MCInst *MI, int OpNum, SStream *O);
55
static void printU16ImmOperand(MCInst *MI, int OpNum, SStream *O);
56
static void printS32ImmOperand(MCInst *MI, int OpNum, SStream *O);
57
static void printU32ImmOperand(MCInst *MI, int OpNum, SStream *O);
58
static void printU48ImmOperand(MCInst *MI, int OpNum, SStream *O);
59
static void printBDAddrOperand(MCInst *MI, int OpNum, SStream *O);
60
static void printBDXAddrOperand(MCInst *MI, int OpNum, SStream *O);
61
static void printBDLAddrOperand(MCInst *MI, int OpNum, SStream *O);
62
static void printBDRAddrOperand(MCInst *MI, int OpNum, SStream *O);
63
static void printBDVAddrOperand(MCInst *MI, int OpNum, SStream *O);
64
static void printPCRelOperand(MCInst *MI, uint64_t Address, int OpNum,
65
            SStream *O);
66
static void printPCRelTLSOperand(MCInst *MI, uint64_t Address, int OpNum,
67
         SStream *O);
68
// This forms part of the instruction name rather than the operand list.
69
// Print the mnemonic for a condition-code mask ("ne", "lh", etc.)
70
static void printCond4Operand(MCInst *MI, int OpNum, SStream *O);
71
72
#include "SystemZGenAsmWriter.inc"
73
74
#define DECLARE_printUImmOperand(N) \
75
  static void CONCAT(printUImmOperand, N)(MCInst * MI, int OpNum, \
76
            SStream *O);
77
DECLARE_printUImmOperand(1);
78
DECLARE_printUImmOperand(2);
79
DECLARE_printUImmOperand(3);
80
DECLARE_printUImmOperand(4);
81
DECLARE_printUImmOperand(8);
82
DECLARE_printUImmOperand(12);
83
DECLARE_printUImmOperand(16);
84
DECLARE_printUImmOperand(32);
85
DECLARE_printUImmOperand(48);
86
87
#define DECLARE_printSImmOperand(N) \
88
  static void CONCAT(printSImmOperand, N)(MCInst * MI, int OpNum, \
89
            SStream *O);
90
DECLARE_printSImmOperand(8);
91
DECLARE_printSImmOperand(16);
92
DECLARE_printSImmOperand(32);
93
94
static void printAddress(const MCAsmInfo *MAI, MCRegister Base,
95
       const MCOperand *DispMO, MCRegister Index, SStream *O)
96
31.4k
{
97
31.4k
  printMCOperandMAI(DispMO, MAI, O);
98
31.4k
  if (Base || Index) {
99
23.2k
    SStream_concat0(O, "(");
100
101
23.2k
    if (Index) {
102
10.1k
      printFormattedRegName(MAI, Index, O);
103
10.1k
      SStream_concat0(O, ",");
104
10.1k
    }
105
23.2k
    if (Base)
106
20.2k
      printFormattedRegName(MAI, Base, O);
107
3.00k
    else
108
3.00k
      SStream_concat0(O, "0");
109
110
23.2k
    SStream_concat0(O, ")");
111
23.2k
  }
112
31.4k
}
113
114
static void printMCOperandMAI(const MCOperand *MO, const MCAsmInfo *MAI,
115
            SStream *O)
116
35.7k
{
117
35.7k
  if (MCOperand_isReg(MO)) {
118
0
    if (!MCOperand_getReg(MO))
119
0
      SStream_concat1(O, '0');
120
0
    else
121
0
      printFormattedRegName(MAI, MCOperand_getReg(MO), O);
122
35.7k
  } else if (MCOperand_isImm(MO))
123
35.7k
    printInt64(markup_OS(O, Markup_Immediate),
124
35.7k
         MCOperand_getImm(MO));
125
0
  else if (MCOperand_isExpr(MO))
126
0
    printExpr(O, MCOperand_getExpr(MO));
127
0
  else
128
0
    CS_ASSERT(0 && "Invalid operand");
129
35.7k
}
130
131
static void printMCOperand(const MCInst *MI, const MCOperand *MO, SStream *O)
132
79.4k
{
133
79.4k
  if (MCOperand_isReg(MO)) {
134
79.4k
    if (!MCOperand_getReg(MO))
135
688
      SStream_concat0(O, "0");
136
137
78.8k
    else
138
78.8k
      printFormattedRegName(&MI->MAI, MCOperand_getReg(MO),
139
78.8k
                O);
140
79.4k
  } else if (MCOperand_isImm(MO))
141
0
    printInt64(markup_OS(O, Markup_Immediate),
142
0
         MCOperand_getImm(MO));
143
0
  else if (MCOperand_isExpr(MO))
144
0
    printExpr(O, MCOperand_getExpr(MO));
145
0
  else
146
0
    CS_ASSERT_RET(0 && "Invalid operand");
147
79.4k
}
148
149
void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg, SStream *O)
150
112k
{
151
112k
  const char *RegName = getRegisterName(Reg);
152
112k
  if (MAI->assemblerDialect == SYSTEMZASMDIALECT_AD_ATT) {
153
    // Skip register prefix so that only register number is left
154
0
    CS_ASSERT((isalpha(RegName[0]) && isdigit(RegName[1])));
155
0
    SStream_concat0(markup_OS(O, Markup_Register), (RegName + 1));
156
0
  } else
157
112k
    SStream_concat1(markup_OS(O, Markup_Register), '%');
158
112k
  SStream_concat0(markup_OS(O, Markup_Register), RegName);
159
112k
}
160
161
static void printRegName(const MCInst *MI, SStream *O, MCRegister Reg)
162
3.10k
{
163
3.10k
  printFormattedRegName(&MI->MAI, Reg, O);
164
3.10k
}
165
166
static void printInst(MCInst *MI, uint64_t Address, const char *Annot,
167
          SStream *O)
168
57.9k
{
169
57.9k
  printInstruction(MI, Address, O);
170
57.9k
}
171
172
#define DEFINE_printUImmOperand(N) \
173
  void CONCAT(printUImmOperand, N)(MCInst * MI, int OpNum, SStream *O) \
174
18.6k
  { \
175
18.6k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
18.6k
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
18.6k
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
18.6k
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
18.6k
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
18.6k
  }
SystemZInstPrinter.c:printUImmOperand_4
Line
Count
Source
174
10.0k
  { \
175
10.0k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
10.0k
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
10.0k
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
10.0k
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
10.0k
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
10.0k
  }
SystemZInstPrinter.c:printUImmOperand_16
Line
Count
Source
174
616
  { \
175
616
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
616
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
616
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
616
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
616
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
616
  }
SystemZInstPrinter.c:printUImmOperand_32
Line
Count
Source
174
467
  { \
175
467
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
467
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
467
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
467
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
467
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
467
  }
Unexecuted instantiation: SystemZInstPrinter.c:printUImmOperand_48
SystemZInstPrinter.c:printUImmOperand_8
Line
Count
Source
174
4.97k
  { \
175
4.97k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
4.97k
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
4.97k
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
4.97k
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
4.97k
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
4.97k
  }
SystemZInstPrinter.c:printUImmOperand_2
Line
Count
Source
174
638
  { \
175
638
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
638
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
638
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
638
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
638
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
638
  }
SystemZInstPrinter.c:printUImmOperand_1
Line
Count
Source
174
1.22k
  { \
175
1.22k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
1.22k
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
1.22k
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
1.22k
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
1.22k
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
1.22k
  }
SystemZInstPrinter.c:printUImmOperand_12
Line
Count
Source
174
229
  { \
175
229
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
229
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
229
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
229
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
229
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
229
  }
SystemZInstPrinter.c:printUImmOperand_3
Line
Count
Source
174
467
  { \
175
467
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
176
467
    if (MCOperand_isExpr(MO)) { \
177
0
      printExpr(O, MCOperand_getExpr(MO)); \
178
0
      return; \
179
0
    } \
180
467
    uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \
181
467
    CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \
182
467
    printUInt64(markup_OS(O, Markup_Immediate), Value); \
183
467
  }
184
DEFINE_printUImmOperand(1);
185
DEFINE_printUImmOperand(2);
186
DEFINE_printUImmOperand(3);
187
DEFINE_printUImmOperand(4);
188
DEFINE_printUImmOperand(8);
189
DEFINE_printUImmOperand(12);
190
DEFINE_printUImmOperand(16);
191
DEFINE_printUImmOperand(32);
192
DEFINE_printUImmOperand(48);
193
194
#define DEFINE_printSImmOperand(N) \
195
  void CONCAT(printSImmOperand, N)(MCInst * MI, int OpNum, SStream *O) \
196
3.08k
  { \
197
3.08k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
198
3.08k
    if (MCOperand_isExpr(MO)) { \
199
0
      printExpr(O, MCOperand_getExpr(MO)); \
200
0
      return; \
201
0
    } \
202
3.08k
    int64_t Value = \
203
3.08k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
204
3.08k
    if (N == 8) \
205
3.08k
      printInt8(markup_OS(O, Markup_Immediate), Value); \
206
3.08k
    else if (N == 16) \
207
2.20k
      printInt16(markup_OS(O, Markup_Immediate), Value); \
208
2.20k
    else if (N == 32) \
209
1.06k
      printInt32(markup_OS(O, Markup_Immediate), Value); \
210
1.06k
    else \
211
1.06k
      CS_ASSERT(0 && "Unreachable"); \
212
3.08k
  }
SystemZInstPrinter.c:printSImmOperand_8
Line
Count
Source
196
873
  { \
197
873
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
198
873
    if (MCOperand_isExpr(MO)) { \
199
0
      printExpr(O, MCOperand_getExpr(MO)); \
200
0
      return; \
201
0
    } \
202
873
    int64_t Value = \
203
873
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
204
873
    if (N == 8) \
205
873
      printInt8(markup_OS(O, Markup_Immediate), Value); \
206
873
    else if (N == 16) \
207
0
      printInt16(markup_OS(O, Markup_Immediate), Value); \
208
0
    else if (N == 32) \
209
0
      printInt32(markup_OS(O, Markup_Immediate), Value); \
210
0
    else \
211
0
      CS_ASSERT(0 && "Unreachable"); \
212
873
  }
SystemZInstPrinter.c:printSImmOperand_16
Line
Count
Source
196
1.14k
  { \
197
1.14k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
198
1.14k
    if (MCOperand_isExpr(MO)) { \
199
0
      printExpr(O, MCOperand_getExpr(MO)); \
200
0
      return; \
201
0
    } \
202
1.14k
    int64_t Value = \
203
1.14k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
204
1.14k
    if (N == 8) \
205
1.14k
      printInt8(markup_OS(O, Markup_Immediate), Value); \
206
1.14k
    else if (N == 16) \
207
1.14k
      printInt16(markup_OS(O, Markup_Immediate), Value); \
208
1.14k
    else if (N == 32) \
209
0
      printInt32(markup_OS(O, Markup_Immediate), Value); \
210
0
    else \
211
0
      CS_ASSERT(0 && "Unreachable"); \
212
1.14k
  }
SystemZInstPrinter.c:printSImmOperand_32
Line
Count
Source
196
1.06k
  { \
197
1.06k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
198
1.06k
    if (MCOperand_isExpr(MO)) { \
199
0
      printExpr(O, MCOperand_getExpr(MO)); \
200
0
      return; \
201
0
    } \
202
1.06k
    int64_t Value = \
203
1.06k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
204
1.06k
    if (N == 8) \
205
1.06k
      printInt8(markup_OS(O, Markup_Immediate), Value); \
206
1.06k
    else if (N == 16) \
207
1.06k
      printInt16(markup_OS(O, Markup_Immediate), Value); \
208
1.06k
    else if (N == 32) \
209
1.06k
      printInt32(markup_OS(O, Markup_Immediate), Value); \
210
1.06k
    else \
211
1.06k
      CS_ASSERT(0 && "Unreachable"); \
212
1.06k
  }
213
DEFINE_printSImmOperand(8);
214
DEFINE_printSImmOperand(16);
215
DEFINE_printSImmOperand(32);
216
217
static void printU1ImmOperand(MCInst *MI, int OpNum, SStream *O)
218
1.22k
{
219
1.22k
  add_cs_detail(MI, SystemZ_OP_GROUP_U1ImmOperand, OpNum);
220
1.22k
  CONCAT(printUImmOperand, 1)(MI, OpNum, O);
221
1.22k
}
222
223
static void printU2ImmOperand(MCInst *MI, int OpNum, SStream *O)
224
638
{
225
638
  add_cs_detail(MI, SystemZ_OP_GROUP_U2ImmOperand, OpNum);
226
638
  CONCAT(printUImmOperand, 2)(MI, OpNum, O);
227
638
}
228
229
static void printU3ImmOperand(MCInst *MI, int OpNum, SStream *O)
230
467
{
231
467
  add_cs_detail(MI, SystemZ_OP_GROUP_U3ImmOperand, OpNum);
232
467
  CONCAT(printUImmOperand, 3)(MI, OpNum, O);
233
467
}
234
235
static void printU4ImmOperand(MCInst *MI, int OpNum, SStream *O)
236
10.0k
{
237
10.0k
  add_cs_detail(MI, SystemZ_OP_GROUP_U4ImmOperand, OpNum);
238
10.0k
  CONCAT(printUImmOperand, 4)(MI, OpNum, O);
239
10.0k
}
240
241
static void printS8ImmOperand(MCInst *MI, int OpNum, SStream *O)
242
873
{
243
873
  add_cs_detail(MI, SystemZ_OP_GROUP_S8ImmOperand, OpNum);
244
873
  CONCAT(printSImmOperand, 8)(MI, OpNum, O);
245
873
}
246
247
static void printU8ImmOperand(MCInst *MI, int OpNum, SStream *O)
248
4.97k
{
249
4.97k
  add_cs_detail(MI, SystemZ_OP_GROUP_U8ImmOperand, OpNum);
250
4.97k
  CONCAT(printUImmOperand, 8)(MI, OpNum, O);
251
4.97k
}
252
253
static void printU12ImmOperand(MCInst *MI, int OpNum, SStream *O)
254
229
{
255
229
  add_cs_detail(MI, SystemZ_OP_GROUP_U12ImmOperand, OpNum);
256
229
  CONCAT(printUImmOperand, 12)(MI, OpNum, O);
257
229
}
258
259
static void printS16ImmOperand(MCInst *MI, int OpNum, SStream *O)
260
1.14k
{
261
1.14k
  add_cs_detail(MI, SystemZ_OP_GROUP_S16ImmOperand, OpNum);
262
1.14k
  CONCAT(printSImmOperand, 16)(MI, OpNum, O);
263
1.14k
}
264
265
static void printU16ImmOperand(MCInst *MI, int OpNum, SStream *O)
266
616
{
267
616
  add_cs_detail(MI, SystemZ_OP_GROUP_U16ImmOperand, OpNum);
268
616
  CONCAT(printUImmOperand, 16)(MI, OpNum, O);
269
616
}
270
271
static void printS32ImmOperand(MCInst *MI, int OpNum, SStream *O)
272
1.06k
{
273
1.06k
  add_cs_detail(MI, SystemZ_OP_GROUP_S32ImmOperand, OpNum);
274
1.06k
  CONCAT(printSImmOperand, 32)(MI, OpNum, O);
275
1.06k
}
276
277
static void printU32ImmOperand(MCInst *MI, int OpNum, SStream *O)
278
467
{
279
467
  add_cs_detail(MI, SystemZ_OP_GROUP_U32ImmOperand, OpNum);
280
467
  CONCAT(printUImmOperand, 32)(MI, OpNum, O);
281
467
}
282
283
static void printU48ImmOperand(MCInst *MI, int OpNum, SStream *O)
284
0
{
285
0
  add_cs_detail(MI, SystemZ_OP_GROUP_U48ImmOperand, OpNum);
286
0
  CONCAT(printUImmOperand, 48)(MI, OpNum, O);
287
0
}
288
289
static void printPCRelOperand(MCInst *MI, uint64_t Address, int OpNum,
290
            SStream *O)
291
2.43k
{
292
2.43k
  add_cs_detail(MI, SystemZ_OP_GROUP_PCRelOperand, OpNum);
293
2.43k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
294
2.43k
  if (MCOperand_isImm(MO)) {
295
2.43k
    printInt64(O, MCOperand_getImm(MO));
296
2.43k
  } else
297
0
    printExpr(O, MCOperand_getExpr(MO));
298
2.43k
}
299
300
static void printPCRelTLSOperand(MCInst *MI, uint64_t Address, int OpNum,
301
         SStream *O)
302
76
{
303
  // Output the PC-relative operand.
304
76
  printPCRelOperand(MI, MI->address, OpNum, O);
305
306
  // Output the TLS marker if present.
307
76
  if ((unsigned)OpNum + 1 < MCInst_getNumOperands(MI)) {
308
    // Expressions not supported
309
0
  }
310
76
}
311
312
static void printOperand(MCInst *MI, int OpNum, SStream *O)
313
130k
{
314
130k
  add_cs_detail(MI, SystemZ_OP_GROUP_Operand, OpNum);
315
130k
  printMCOperand(MI, MCInst_getOperand(MI, (OpNum)), O);
316
130k
}
317
318
static void printBDAddrOperand(MCInst *MI, int OpNum, SStream *O)
319
22.3k
{
320
22.3k
  add_cs_detail(MI, SystemZ_OP_GROUP_BDAddrOperand, OpNum);
321
22.3k
  printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))),
322
22.3k
         MCInst_getOperand(MI, (OpNum + 1)), 0, O);
323
22.3k
}
324
325
static void printBDXAddrOperand(MCInst *MI, int OpNum, SStream *O)
326
19.7k
{
327
19.7k
  add_cs_detail(MI, SystemZ_OP_GROUP_BDXAddrOperand, OpNum);
328
19.7k
  printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))),
329
19.7k
         MCInst_getOperand(MI, (OpNum + 1)),
330
19.7k
         MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2))), O);
331
19.7k
}
332
333
static void printBDLAddrOperand(MCInst *MI, int OpNum, SStream *O)
334
4.06k
{
335
4.06k
  add_cs_detail(MI, SystemZ_OP_GROUP_BDLAddrOperand, OpNum);
336
4.06k
  unsigned Base = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
337
4.06k
  MCOperand *DispMO = MCInst_getOperand(MI, (OpNum + 1));
338
4.06k
  uint64_t Length = MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 2)));
339
4.06k
  printMCOperandMAI(DispMO, &MI->MAI, O);
340
4.06k
  SStream_concat1(O, '(');
341
4.06k
  printUInt64(O, Length);
342
4.06k
  if (Base) {
343
2.73k
    SStream_concat0(O, ",");
344
2.73k
    printRegName(MI, O, Base);
345
2.73k
  }
346
4.06k
  SStream_concat0(O, ")");
347
4.06k
}
348
349
static void printBDRAddrOperand(MCInst *MI, int OpNum, SStream *O)
350
221
{
351
221
  add_cs_detail(MI, SystemZ_OP_GROUP_BDRAddrOperand, OpNum);
352
221
  unsigned Base = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
353
221
  MCOperand *DispMO = MCInst_getOperand(MI, (OpNum + 1));
354
221
  unsigned Length = MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2)));
355
221
  printMCOperandMAI(DispMO, &MI->MAI, O);
356
221
  SStream_concat0(O, "(");
357
221
  printRegName(MI, O, Length);
358
221
  if (Base) {
359
152
    SStream_concat0(O, ",");
360
152
    printRegName(MI, O, Base);
361
152
  }
362
221
  SStream_concat0(O, ")");
363
221
}
364
365
static void printBDVAddrOperand(MCInst *MI, int OpNum, SStream *O)
366
1.49k
{
367
1.49k
  add_cs_detail(MI, SystemZ_OP_GROUP_BDVAddrOperand, OpNum);
368
1.49k
  printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))),
369
1.49k
         MCInst_getOperand(MI, (OpNum + 1)),
370
1.49k
         MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2))), O);
371
1.49k
}
372
373
static void printCond4Operand(MCInst *MI, int OpNum, SStream *O)
374
0
{
375
0
  add_cs_detail(MI, SystemZ_OP_GROUP_Cond4Operand, OpNum);
376
0
  static const char *const CondNames[] = { "o", "h",  "nle", "l",
377
0
             "nhe", "lh", "ne",  "e",
378
0
             "nlh", "he", "nl",  "le",
379
0
             "nh",  "no" };
380
0
  uint64_t Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
381
0
  CS_ASSERT((Imm > 0 && Imm < 15 && "Invalid condition"));
382
0
  SStream_concat0(O, CondNames[Imm - 1]);
383
0
}
384
385
const char *SystemZ_LLVM_getRegisterName(unsigned RegNo)
386
35.9k
{
387
35.9k
  return getRegisterName(RegNo);
388
35.9k
}
389
390
void SystemZ_LLVM_printInstruction(MCInst *MI, const char *Annotation,
391
           SStream *O)
392
57.9k
{
393
57.9k
  printInst(MI, MI->address, Annotation, O);
394
57.9k
}