/src/capstonenext/arch/SystemZ/SystemZInstPrinter.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 | | //===- 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 | 27.2k | #define CONCAT(a, b) CONCAT_(a, b) |
37 | 27.2k | #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 | 46.7k | { |
97 | 46.7k | printMCOperandMAI(DispMO, MAI, O); |
98 | 46.7k | if (Base || Index) { |
99 | 34.9k | SStream_concat0(O, "("); |
100 | | |
101 | 34.9k | if (Index) { |
102 | 15.1k | printFormattedRegName(MAI, Index, O); |
103 | 15.1k | SStream_concat0(O, ","); |
104 | 15.1k | } |
105 | 34.9k | if (Base) |
106 | 30.6k | printFormattedRegName(MAI, Base, O); |
107 | 4.26k | else |
108 | 4.26k | SStream_concat0(O, "0"); |
109 | | |
110 | 34.9k | SStream_concat0(O, ")"); |
111 | 34.9k | } |
112 | 46.7k | } |
113 | | |
114 | | static void printMCOperandMAI(const MCOperand *MO, const MCAsmInfo *MAI, |
115 | | SStream *O) |
116 | 53.8k | { |
117 | 53.8k | 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 | 53.8k | } else if (MCOperand_isImm(MO)) |
123 | 53.8k | printInt64(markup_OS(O, Markup_Immediate), |
124 | 53.8k | 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 | 53.8k | } |
130 | | |
131 | | static void printMCOperand(const MCInst *MI, const MCOperand *MO, SStream *O) |
132 | 122k | { |
133 | 122k | if (MCOperand_isReg(MO)) { |
134 | 122k | if (!MCOperand_getReg(MO)) |
135 | 1.38k | SStream_concat0(O, "0"); |
136 | | |
137 | 120k | else |
138 | 120k | printFormattedRegName(&MI->MAI, MCOperand_getReg(MO), |
139 | 120k | O); |
140 | 122k | } 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 | 122k | } |
148 | | |
149 | | void printFormattedRegName(const MCAsmInfo *MAI, MCRegister Reg, SStream *O) |
150 | 172k | { |
151 | 172k | const char *RegName = getRegisterName(Reg); |
152 | 172k | 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 | 172k | SStream_concat1(markup_OS(O, Markup_Register), '%'); |
158 | 172k | SStream_concat0(markup_OS(O, Markup_Register), RegName); |
159 | 172k | } |
160 | | |
161 | | static void printRegName(const MCInst *MI, SStream *O, MCRegister Reg) |
162 | 6.08k | { |
163 | 6.08k | printFormattedRegName(&MI->MAI, Reg, O); |
164 | 6.08k | } |
165 | | |
166 | | static void printInst(MCInst *MI, uint64_t Address, const char *Annot, |
167 | | SStream *O) |
168 | 86.8k | { |
169 | 86.8k | printInstruction(MI, Address, O); |
170 | 86.8k | } |
171 | | |
172 | | #define DEFINE_printUImmOperand(N) \ |
173 | | void CONCAT(printUImmOperand, N)(MCInst * MI, int OpNum, SStream *O) \ |
174 | 24.0k | { \ |
175 | 24.0k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ |
176 | 24.0k | if (MCOperand_isExpr(MO)) { \ |
177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ |
178 | 0 | return; \ |
179 | 0 | } \ |
180 | 24.0k | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ |
181 | 24.0k | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ |
182 | 24.0k | printUInt64(markup_OS(O, Markup_Immediate), Value); \ |
183 | 24.0k | } SystemZInstPrinter.c:printUImmOperand_4 Line | Count | Source | 174 | 14.1k | { \ | 175 | 14.1k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 14.1k | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 14.1k | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 14.1k | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 14.1k | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 14.1k | } |
SystemZInstPrinter.c:printUImmOperand_16 Line | Count | Source | 174 | 1.27k | { \ | 175 | 1.27k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 1.27k | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 1.27k | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 1.27k | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 1.27k | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 1.27k | } |
SystemZInstPrinter.c:printUImmOperand_32 Line | Count | Source | 174 | 647 | { \ | 175 | 647 | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 647 | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 647 | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 647 | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 647 | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 647 | } |
Unexecuted instantiation: SystemZInstPrinter.c:printUImmOperand_48 SystemZInstPrinter.c:printUImmOperand_8 Line | Count | Source | 174 | 5.27k | { \ | 175 | 5.27k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 5.27k | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 5.27k | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 5.27k | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 5.27k | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 5.27k | } |
SystemZInstPrinter.c:printUImmOperand_2 Line | Count | Source | 174 | 724 | { \ | 175 | 724 | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 724 | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 724 | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 724 | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 724 | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 724 | } |
SystemZInstPrinter.c:printUImmOperand_1 Line | Count | Source | 174 | 1.39k | { \ | 175 | 1.39k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 1.39k | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 1.39k | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 1.39k | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 1.39k | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 1.39k | } |
SystemZInstPrinter.c:printUImmOperand_12 Line | Count | Source | 174 | 119 | { \ | 175 | 119 | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 119 | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 119 | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 119 | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 119 | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 119 | } |
SystemZInstPrinter.c:printUImmOperand_3 Line | Count | Source | 174 | 459 | { \ | 175 | 459 | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 176 | 459 | if (MCOperand_isExpr(MO)) { \ | 177 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 178 | 0 | return; \ | 179 | 0 | } \ | 180 | 459 | uint64_t Value = (uint64_t)(MCOperand_getImm(MO)); \ | 181 | 459 | CS_ASSERT((isUIntN(N, Value) && "Invalid uimm argument")); \ | 182 | 459 | printUInt64(markup_OS(O, Markup_Immediate), Value); \ | 183 | 459 | } |
|
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.18k | { \ |
197 | 3.18k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ |
198 | 3.18k | if (MCOperand_isExpr(MO)) { \ |
199 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ |
200 | 0 | return; \ |
201 | 0 | } \ |
202 | 3.18k | int64_t Value = \ |
203 | 3.18k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \ |
204 | 3.18k | if (N == 8) \ |
205 | 3.18k | printInt8(markup_OS(O, Markup_Immediate), Value); \ |
206 | 3.18k | else if (N == 16) \ |
207 | 2.48k | printInt16(markup_OS(O, Markup_Immediate), Value); \ |
208 | 2.48k | else if (N == 32) \ |
209 | 860 | printInt32(markup_OS(O, Markup_Immediate), Value); \ |
210 | 860 | else \ |
211 | 860 | CS_ASSERT(0 && "Unreachable"); \ |
212 | 3.18k | } SystemZInstPrinter.c:printSImmOperand_8 Line | Count | Source | 196 | 693 | { \ | 197 | 693 | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 198 | 693 | if (MCOperand_isExpr(MO)) { \ | 199 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 200 | 0 | return; \ | 201 | 0 | } \ | 202 | 693 | int64_t Value = \ | 203 | 693 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \ | 204 | 693 | if (N == 8) \ | 205 | 693 | printInt8(markup_OS(O, Markup_Immediate), Value); \ | 206 | 693 | 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 | 693 | } |
SystemZInstPrinter.c:printSImmOperand_16 Line | Count | Source | 196 | 1.62k | { \ | 197 | 1.62k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 198 | 1.62k | if (MCOperand_isExpr(MO)) { \ | 199 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 200 | 0 | return; \ | 201 | 0 | } \ | 202 | 1.62k | int64_t Value = \ | 203 | 1.62k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \ | 204 | 1.62k | if (N == 8) \ | 205 | 1.62k | printInt8(markup_OS(O, Markup_Immediate), Value); \ | 206 | 1.62k | else if (N == 16) \ | 207 | 1.62k | printInt16(markup_OS(O, Markup_Immediate), Value); \ | 208 | 1.62k | else if (N == 32) \ | 209 | 0 | printInt32(markup_OS(O, Markup_Immediate), Value); \ | 210 | 0 | else \ | 211 | 0 | CS_ASSERT(0 && "Unreachable"); \ | 212 | 1.62k | } |
SystemZInstPrinter.c:printSImmOperand_32 Line | Count | Source | 196 | 860 | { \ | 197 | 860 | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \ | 198 | 860 | if (MCOperand_isExpr(MO)) { \ | 199 | 0 | printExpr(O, MCOperand_getExpr(MO)); \ | 200 | 0 | return; \ | 201 | 0 | } \ | 202 | 860 | int64_t Value = \ | 203 | 860 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \ | 204 | 860 | if (N == 8) \ | 205 | 860 | printInt8(markup_OS(O, Markup_Immediate), Value); \ | 206 | 860 | else if (N == 16) \ | 207 | 860 | printInt16(markup_OS(O, Markup_Immediate), Value); \ | 208 | 860 | else if (N == 32) \ | 209 | 860 | printInt32(markup_OS(O, Markup_Immediate), Value); \ | 210 | 860 | else \ | 211 | 860 | CS_ASSERT(0 && "Unreachable"); \ | 212 | 860 | } |
|
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.39k | { |
219 | 1.39k | add_cs_detail(MI, SystemZ_OP_GROUP_U1ImmOperand, OpNum); |
220 | 1.39k | CONCAT(printUImmOperand, 1)(MI, OpNum, O); |
221 | 1.39k | } |
222 | | |
223 | | static void printU2ImmOperand(MCInst *MI, int OpNum, SStream *O) |
224 | 724 | { |
225 | 724 | add_cs_detail(MI, SystemZ_OP_GROUP_U2ImmOperand, OpNum); |
226 | 724 | CONCAT(printUImmOperand, 2)(MI, OpNum, O); |
227 | 724 | } |
228 | | |
229 | | static void printU3ImmOperand(MCInst *MI, int OpNum, SStream *O) |
230 | 459 | { |
231 | 459 | add_cs_detail(MI, SystemZ_OP_GROUP_U3ImmOperand, OpNum); |
232 | 459 | CONCAT(printUImmOperand, 3)(MI, OpNum, O); |
233 | 459 | } |
234 | | |
235 | | static void printU4ImmOperand(MCInst *MI, int OpNum, SStream *O) |
236 | 14.1k | { |
237 | 14.1k | add_cs_detail(MI, SystemZ_OP_GROUP_U4ImmOperand, OpNum); |
238 | 14.1k | CONCAT(printUImmOperand, 4)(MI, OpNum, O); |
239 | 14.1k | } |
240 | | |
241 | | static void printS8ImmOperand(MCInst *MI, int OpNum, SStream *O) |
242 | 693 | { |
243 | 693 | add_cs_detail(MI, SystemZ_OP_GROUP_S8ImmOperand, OpNum); |
244 | 693 | CONCAT(printSImmOperand, 8)(MI, OpNum, O); |
245 | 693 | } |
246 | | |
247 | | static void printU8ImmOperand(MCInst *MI, int OpNum, SStream *O) |
248 | 5.27k | { |
249 | 5.27k | add_cs_detail(MI, SystemZ_OP_GROUP_U8ImmOperand, OpNum); |
250 | 5.27k | CONCAT(printUImmOperand, 8)(MI, OpNum, O); |
251 | 5.27k | } |
252 | | |
253 | | static void printU12ImmOperand(MCInst *MI, int OpNum, SStream *O) |
254 | 119 | { |
255 | 119 | add_cs_detail(MI, SystemZ_OP_GROUP_U12ImmOperand, OpNum); |
256 | 119 | CONCAT(printUImmOperand, 12)(MI, OpNum, O); |
257 | 119 | } |
258 | | |
259 | | static void printS16ImmOperand(MCInst *MI, int OpNum, SStream *O) |
260 | 1.62k | { |
261 | 1.62k | add_cs_detail(MI, SystemZ_OP_GROUP_S16ImmOperand, OpNum); |
262 | 1.62k | CONCAT(printSImmOperand, 16)(MI, OpNum, O); |
263 | 1.62k | } |
264 | | |
265 | | static void printU16ImmOperand(MCInst *MI, int OpNum, SStream *O) |
266 | 1.27k | { |
267 | 1.27k | add_cs_detail(MI, SystemZ_OP_GROUP_U16ImmOperand, OpNum); |
268 | 1.27k | CONCAT(printUImmOperand, 16)(MI, OpNum, O); |
269 | 1.27k | } |
270 | | |
271 | | static void printS32ImmOperand(MCInst *MI, int OpNum, SStream *O) |
272 | 860 | { |
273 | 860 | add_cs_detail(MI, SystemZ_OP_GROUP_S32ImmOperand, OpNum); |
274 | 860 | CONCAT(printSImmOperand, 32)(MI, OpNum, O); |
275 | 860 | } |
276 | | |
277 | | static void printU32ImmOperand(MCInst *MI, int OpNum, SStream *O) |
278 | 647 | { |
279 | 647 | add_cs_detail(MI, SystemZ_OP_GROUP_U32ImmOperand, OpNum); |
280 | 647 | CONCAT(printUImmOperand, 32)(MI, OpNum, O); |
281 | 647 | } |
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 | 3.36k | { |
292 | 3.36k | add_cs_detail(MI, SystemZ_OP_GROUP_PCRelOperand, OpNum); |
293 | 3.36k | MCOperand *MO = MCInst_getOperand(MI, (OpNum)); |
294 | 3.36k | if (MCOperand_isImm(MO)) { |
295 | 3.36k | printInt64(O, MCOperand_getImm(MO)); |
296 | 3.36k | } else |
297 | 0 | printExpr(O, MCOperand_getExpr(MO)); |
298 | 3.36k | } |
299 | | |
300 | | static void printPCRelTLSOperand(MCInst *MI, uint64_t Address, int OpNum, |
301 | | SStream *O) |
302 | 109 | { |
303 | | // Output the PC-relative operand. |
304 | 109 | printPCRelOperand(MI, MI->address, OpNum, O); |
305 | | |
306 | | // Output the TLS marker if present. |
307 | 109 | if ((unsigned)OpNum + 1 < MCInst_getNumOperands(MI)) { |
308 | | // Expressions not supported |
309 | 0 | } |
310 | 109 | } |
311 | | |
312 | | static void printOperand(MCInst *MI, int OpNum, SStream *O) |
313 | 122k | { |
314 | 122k | add_cs_detail(MI, SystemZ_OP_GROUP_Operand, OpNum); |
315 | 122k | printMCOperand(MI, MCInst_getOperand(MI, (OpNum)), O); |
316 | 122k | } |
317 | | |
318 | | static void printBDAddrOperand(MCInst *MI, int OpNum, SStream *O) |
319 | 24.8k | { |
320 | 24.8k | add_cs_detail(MI, SystemZ_OP_GROUP_BDAddrOperand, OpNum); |
321 | 24.8k | printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))), |
322 | 24.8k | MCInst_getOperand(MI, (OpNum + 1)), 0, O); |
323 | 24.8k | } |
324 | | |
325 | | static void printBDXAddrOperand(MCInst *MI, int OpNum, SStream *O) |
326 | 21.3k | { |
327 | 21.3k | add_cs_detail(MI, SystemZ_OP_GROUP_BDXAddrOperand, OpNum); |
328 | 21.3k | printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))), |
329 | 21.3k | MCInst_getOperand(MI, (OpNum + 1)), |
330 | 21.3k | MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2))), O); |
331 | 21.3k | } |
332 | | |
333 | | static void printBDLAddrOperand(MCInst *MI, int OpNum, SStream *O) |
334 | 6.72k | { |
335 | 6.72k | add_cs_detail(MI, SystemZ_OP_GROUP_BDLAddrOperand, OpNum); |
336 | 6.72k | unsigned Base = MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); |
337 | 6.72k | MCOperand *DispMO = MCInst_getOperand(MI, (OpNum + 1)); |
338 | 6.72k | uint64_t Length = MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 2))); |
339 | 6.72k | printMCOperandMAI(DispMO, &MI->MAI, O); |
340 | 6.72k | SStream_concat1(O, '('); |
341 | 6.72k | printUInt64(O, Length); |
342 | 6.72k | if (Base) { |
343 | 5.38k | SStream_concat0(O, ","); |
344 | 5.38k | printRegName(MI, O, Base); |
345 | 5.38k | } |
346 | 6.72k | SStream_concat0(O, ")"); |
347 | 6.72k | } |
348 | | |
349 | | static void printBDRAddrOperand(MCInst *MI, int OpNum, SStream *O) |
350 | 416 | { |
351 | 416 | add_cs_detail(MI, SystemZ_OP_GROUP_BDRAddrOperand, OpNum); |
352 | 416 | unsigned Base = MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); |
353 | 416 | MCOperand *DispMO = MCInst_getOperand(MI, (OpNum + 1)); |
354 | 416 | unsigned Length = MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2))); |
355 | 416 | printMCOperandMAI(DispMO, &MI->MAI, O); |
356 | 416 | SStream_concat0(O, "("); |
357 | 416 | printRegName(MI, O, Length); |
358 | 416 | if (Base) { |
359 | 288 | SStream_concat0(O, ","); |
360 | 288 | printRegName(MI, O, Base); |
361 | 288 | } |
362 | 416 | SStream_concat0(O, ")"); |
363 | 416 | } |
364 | | |
365 | | static void printBDVAddrOperand(MCInst *MI, int OpNum, SStream *O) |
366 | 549 | { |
367 | 549 | add_cs_detail(MI, SystemZ_OP_GROUP_BDVAddrOperand, OpNum); |
368 | 549 | printAddress(&MI->MAI, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))), |
369 | 549 | MCInst_getOperand(MI, (OpNum + 1)), |
370 | 549 | MCOperand_getReg(MCInst_getOperand(MI, (OpNum + 2))), O); |
371 | 549 | } |
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 | 53.6k | { |
387 | 53.6k | return getRegisterName(RegNo); |
388 | 53.6k | } |
389 | | |
390 | | void SystemZ_LLVM_printInstruction(MCInst *MI, const char *Annotation, |
391 | | SStream *O) |
392 | 86.8k | { |
393 | 86.8k | printInst(MI, MI->address, Annotation, O); |
394 | 86.8k | } |