blob: 33db90eb15a0bd76aa3c5a2d660976251c90203c [file] [log] [blame]
Chris Lattnerfd603822009-10-19 19:56:26 +00001//===-- ARMInstPrinter.cpp - Convert ARM MCInst to assembly syntax --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class prints an ARM MCInst to a .s file.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "asm-printer"
Chris Lattner413ae252009-10-20 00:42:49 +000015#include "ARM.h" // FIXME: FACTOR ENUMS BETTER.
Chris Lattnerfd603822009-10-19 19:56:26 +000016#include "ARMInstPrinter.h"
Chris Lattner61d35c22009-10-19 21:21:39 +000017#include "ARMAddressingModes.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000018#include "llvm/MC/MCInst.h"
Chris Lattner61d35c22009-10-19 21:21:39 +000019#include "llvm/MC/MCAsmInfo.h"
Chris Lattner6f997762009-10-19 21:53:00 +000020#include "llvm/MC/MCExpr.h"
21#include "llvm/Support/raw_ostream.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000022using namespace llvm;
23
24// Include the auto-generated portion of the assembly writer.
25#define MachineInstr MCInst
26#define ARMAsmPrinter ARMInstPrinter // FIXME: REMOVE.
Chris Lattnerfd603822009-10-19 19:56:26 +000027#include "ARMGenAsmWriter.inc"
28#undef MachineInstr
29#undef ARMAsmPrinter
30
Johnny Chen9e088762010-03-17 17:52:21 +000031static unsigned NextReg(unsigned Reg) {
32 switch (Reg) {
Daniel Dunbar6b7c2cf2010-03-19 03:18:23 +000033 default:
34 assert(0 && "Unexpected register enum");
35
Johnny Chen9e088762010-03-17 17:52:21 +000036 case ARM::D0:
37 return ARM::D1;
38 case ARM::D1:
39 return ARM::D2;
40 case ARM::D2:
41 return ARM::D3;
42 case ARM::D3:
43 return ARM::D4;
44 case ARM::D4:
45 return ARM::D5;
46 case ARM::D5:
47 return ARM::D6;
48 case ARM::D6:
49 return ARM::D7;
50 case ARM::D7:
51 return ARM::D8;
52 case ARM::D8:
53 return ARM::D9;
54 case ARM::D9:
55 return ARM::D10;
56 case ARM::D10:
57 return ARM::D11;
58 case ARM::D11:
59 return ARM::D12;
60 case ARM::D12:
61 return ARM::D13;
62 case ARM::D13:
63 return ARM::D14;
64 case ARM::D14:
65 return ARM::D15;
66 case ARM::D15:
67 return ARM::D16;
68 case ARM::D16:
69 return ARM::D17;
70 case ARM::D17:
71 return ARM::D18;
72 case ARM::D18:
73 return ARM::D19;
74 case ARM::D19:
75 return ARM::D20;
76 case ARM::D20:
77 return ARM::D21;
78 case ARM::D21:
79 return ARM::D22;
80 case ARM::D22:
81 return ARM::D23;
82 case ARM::D23:
83 return ARM::D24;
84 case ARM::D24:
85 return ARM::D25;
86 case ARM::D25:
87 return ARM::D26;
88 case ARM::D26:
89 return ARM::D27;
90 case ARM::D27:
91 return ARM::D28;
92 case ARM::D28:
93 return ARM::D29;
94 case ARM::D29:
95 return ARM::D30;
96 case ARM::D30:
97 return ARM::D31;
Johnny Chen9e088762010-03-17 17:52:21 +000098 }
99}
100
101void ARMInstPrinter::printInst(const MCInst *MI) {
102 // Check for MOVs and print canonical forms, instead.
103 if (MI->getOpcode() == ARM::MOVs) {
104 const MCOperand &Dst = MI->getOperand(0);
105 const MCOperand &MO1 = MI->getOperand(1);
106 const MCOperand &MO2 = MI->getOperand(2);
107 const MCOperand &MO3 = MI->getOperand(3);
108
109 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
110 printSBitModifierOperand(MI, 6);
111 printPredicateOperand(MI, 4);
112
113 O << '\t' << getRegisterName(Dst.getReg())
114 << ", " << getRegisterName(MO1.getReg());
115
116 if (ARM_AM::getSORegShOp(MO3.getImm()) == ARM_AM::rrx)
117 return;
118
119 O << ", ";
120
121 if (MO2.getReg()) {
122 O << getRegisterName(MO2.getReg());
123 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
124 } else {
125 O << "#" << ARM_AM::getSORegOffset(MO3.getImm());
126 }
127 return;
128 }
129
130 // A8.6.123 PUSH
131 if ((MI->getOpcode() == ARM::STM_UPD || MI->getOpcode() == ARM::t2STM_UPD) &&
132 MI->getOperand(0).getReg() == ARM::SP) {
133 const MCOperand &MO1 = MI->getOperand(2);
134 if (ARM_AM::getAM4SubMode(MO1.getImm()) == ARM_AM::db) {
135 O << '\t' << "push";
136 printPredicateOperand(MI, 3);
137 O << '\t';
138 printRegisterList(MI, 5);
139 return;
140 }
141 }
142
143 // A8.6.122 POP
144 if ((MI->getOpcode() == ARM::LDM_UPD || MI->getOpcode() == ARM::t2LDM_UPD) &&
145 MI->getOperand(0).getReg() == ARM::SP) {
146 const MCOperand &MO1 = MI->getOperand(2);
147 if (ARM_AM::getAM4SubMode(MO1.getImm()) == ARM_AM::ia) {
148 O << '\t' << "pop";
149 printPredicateOperand(MI, 3);
150 O << '\t';
151 printRegisterList(MI, 5);
152 return;
153 }
154 }
155
156 // A8.6.355 VPUSH
157 if ((MI->getOpcode() == ARM::VSTMS_UPD || MI->getOpcode() ==ARM::VSTMD_UPD) &&
158 MI->getOperand(0).getReg() == ARM::SP) {
159 const MCOperand &MO1 = MI->getOperand(2);
160 if (ARM_AM::getAM5SubMode(MO1.getImm()) == ARM_AM::db) {
161 O << '\t' << "vpush";
162 printPredicateOperand(MI, 3);
163 O << '\t';
164 printRegisterList(MI, 5);
165 return;
166 }
167 }
168
169 // A8.6.354 VPOP
170 if ((MI->getOpcode() == ARM::VLDMS_UPD || MI->getOpcode() ==ARM::VLDMD_UPD) &&
171 MI->getOperand(0).getReg() == ARM::SP) {
172 const MCOperand &MO1 = MI->getOperand(2);
173 if (ARM_AM::getAM5SubMode(MO1.getImm()) == ARM_AM::ia) {
174 O << '\t' << "vpop";
175 printPredicateOperand(MI, 3);
176 O << '\t';
177 printRegisterList(MI, 5);
178 return;
179 }
180 }
181
182 printInstruction(MI);
183 }
Chris Lattnerfd603822009-10-19 19:56:26 +0000184
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000185void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
186 const char *Modifier) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000187 const MCOperand &Op = MI->getOperand(OpNo);
188 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000189 unsigned Reg = Op.getReg();
190 if (Modifier && strcmp(Modifier, "dregpair") == 0) {
Johnny Chen9e088762010-03-17 17:52:21 +0000191 O << '{' << getRegisterName(Reg) << ", "
192 << getRegisterName(NextReg(Reg)) << '}';
193#if 0
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000194 // FIXME: Breaks e.g. ARM/vmul.ll.
195 assert(0);
196 /*
197 unsigned DRegLo = TRI->getSubReg(Reg, 5); // arm_dsubreg_0
198 unsigned DRegHi = TRI->getSubReg(Reg, 6); // arm_dsubreg_1
199 O << '{'
200 << getRegisterName(DRegLo) << ',' << getRegisterName(DRegHi)
201 << '}';*/
Johnny Chen9e088762010-03-17 17:52:21 +0000202#endif
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000203 } else if (Modifier && strcmp(Modifier, "lane") == 0) {
204 assert(0);
205 /*
206 unsigned RegNum = ARMRegisterInfo::getRegisterNumbering(Reg);
207 unsigned DReg = TRI->getMatchingSuperReg(Reg, RegNum & 1 ? 2 : 1,
208 &ARM::DPR_VFP2RegClass);
209 O << getRegisterName(DReg) << '[' << (RegNum & 1) << ']';
210 */
211 } else {
212 O << getRegisterName(Reg);
213 }
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000214 } else if (Op.isImm()) {
Daniel Dunbar6b7c2cf2010-03-19 03:18:23 +0000215 assert((Modifier && !strcmp(Modifier, "call")) ||
Johnny Chen9e088762010-03-17 17:52:21 +0000216 ((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported"));
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000217 O << '#' << Op.getImm();
218 } else {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000219 assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000220 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000221 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000222 }
223}
Chris Lattner61d35c22009-10-19 21:21:39 +0000224
225static void printSOImm(raw_ostream &O, int64_t V, bool VerboseAsm,
226 const MCAsmInfo *MAI) {
227 // Break it up into two parts that make up a shifter immediate.
228 V = ARM_AM::getSOImmVal(V);
229 assert(V != -1 && "Not a valid so_imm value!");
230
231 unsigned Imm = ARM_AM::getSOImmValImm(V);
232 unsigned Rot = ARM_AM::getSOImmValRot(V);
233
234 // Print low-level immediate formation info, per
235 // A5.1.3: "Data-processing operands - Immediate".
236 if (Rot) {
237 O << "#" << Imm << ", " << Rot;
238 // Pretty printed version.
239 if (VerboseAsm)
240 O << ' ' << MAI->getCommentString()
241 << ' ' << (int)ARM_AM::rotr32(Imm, Rot);
242 } else {
243 O << "#" << Imm;
244 }
245}
246
247
248/// printSOImmOperand - SOImm is 4-bit rotate amount in bits 8-11 with 8-bit
249/// immediate in bits 0-7.
250void ARMInstPrinter::printSOImmOperand(const MCInst *MI, unsigned OpNum) {
251 const MCOperand &MO = MI->getOperand(OpNum);
252 assert(MO.isImm() && "Not a valid so_imm value!");
253 printSOImm(O, MO.getImm(), VerboseAsm, &MAI);
254}
Chris Lattner084f87d2009-10-19 21:57:05 +0000255
Chris Lattner017d9472009-10-20 00:40:56 +0000256/// printSOImm2PartOperand - SOImm is broken into two pieces using a 'mov'
257/// followed by an 'orr' to materialize.
258void ARMInstPrinter::printSOImm2PartOperand(const MCInst *MI, unsigned OpNum) {
259 // FIXME: REMOVE this method.
260 abort();
261}
262
263// so_reg is a 4-operand unit corresponding to register forms of the A5.1
264// "Addressing Mode 1 - Data-processing operands" forms. This includes:
265// REG 0 0 - e.g. R5
266// REG REG 0,SH_OPC - e.g. R5, ROR R3
267// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
268void ARMInstPrinter::printSORegOperand(const MCInst *MI, unsigned OpNum) {
269 const MCOperand &MO1 = MI->getOperand(OpNum);
270 const MCOperand &MO2 = MI->getOperand(OpNum+1);
271 const MCOperand &MO3 = MI->getOperand(OpNum+2);
272
273 O << getRegisterName(MO1.getReg());
274
275 // Print the shift opc.
276 O << ", "
277 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()))
278 << ' ';
279
280 if (MO2.getReg()) {
281 O << getRegisterName(MO2.getReg());
282 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
283 } else {
284 O << "#" << ARM_AM::getSORegOffset(MO3.getImm());
285 }
286}
Chris Lattner084f87d2009-10-19 21:57:05 +0000287
288
289void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op) {
290 const MCOperand &MO1 = MI->getOperand(Op);
291 const MCOperand &MO2 = MI->getOperand(Op+1);
292 const MCOperand &MO3 = MI->getOperand(Op+2);
293
294 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
295 printOperand(MI, Op);
296 return;
297 }
298
299 O << "[" << getRegisterName(MO1.getReg());
300
301 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000302 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000303 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000304 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
305 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000306 O << "]";
307 return;
308 }
309
310 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000311 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
312 << getRegisterName(MO2.getReg());
Chris Lattner084f87d2009-10-19 21:57:05 +0000313
314 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
315 O << ", "
316 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
317 << " #" << ShImm;
318 O << "]";
319}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000320
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000321void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
322 unsigned OpNum) {
323 const MCOperand &MO1 = MI->getOperand(OpNum);
324 const MCOperand &MO2 = MI->getOperand(OpNum+1);
325
326 if (!MO1.getReg()) {
327 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
328 assert(ImmOffs && "Malformed indexed load / store!");
Johnny Chen9e088762010-03-17 17:52:21 +0000329 O << '#'
330 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
331 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000332 return;
333 }
334
Johnny Chen9e088762010-03-17 17:52:21 +0000335 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
336 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000337
338 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
339 O << ", "
340 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
341 << " #" << ShImm;
342}
343
344void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned OpNum) {
345 const MCOperand &MO1 = MI->getOperand(OpNum);
346 const MCOperand &MO2 = MI->getOperand(OpNum+1);
347 const MCOperand &MO3 = MI->getOperand(OpNum+2);
348
349 O << '[' << getRegisterName(MO1.getReg());
350
351 if (MO2.getReg()) {
352 O << ", " << (char)ARM_AM::getAM3Op(MO3.getImm())
353 << getRegisterName(MO2.getReg()) << ']';
354 return;
355 }
356
357 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
358 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000359 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
360 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000361 O << ']';
362}
363
364void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
365 unsigned OpNum) {
366 const MCOperand &MO1 = MI->getOperand(OpNum);
367 const MCOperand &MO2 = MI->getOperand(OpNum+1);
368
369 if (MO1.getReg()) {
370 O << (char)ARM_AM::getAM3Op(MO2.getImm())
371 << getRegisterName(MO1.getReg());
372 return;
373 }
374
375 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
376 assert(ImmOffs && "Malformed indexed load / store!");
Johnny Chen9e088762010-03-17 17:52:21 +0000377 O << '#'
378 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
379 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000380}
381
Chris Lattnere306d8d2009-10-19 22:09:23 +0000382
383void ARMInstPrinter::printAddrMode4Operand(const MCInst *MI, unsigned OpNum,
384 const char *Modifier) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000385 const MCOperand &MO2 = MI->getOperand(OpNum+1);
386 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MO2.getImm());
Chris Lattner306d14f2009-10-19 23:31:43 +0000387 if (Modifier && strcmp(Modifier, "submode") == 0) {
Bob Wilsonea7f22c2010-03-16 16:19:07 +0000388 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattner306d14f2009-10-19 23:31:43 +0000389 } else if (Modifier && strcmp(Modifier, "wide") == 0) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000390 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MO2.getImm());
391 if (Mode == ARM_AM::ia)
392 O << ".w";
393 } else {
394 printOperand(MI, OpNum);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000395 }
396}
397
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000398void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
399 const char *Modifier) {
400 const MCOperand &MO1 = MI->getOperand(OpNum);
401 const MCOperand &MO2 = MI->getOperand(OpNum+1);
402
403 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
404 printOperand(MI, OpNum);
405 return;
406 }
407
408 if (Modifier && strcmp(Modifier, "submode") == 0) {
409 ARM_AM::AMSubMode Mode = ARM_AM::getAM5SubMode(MO2.getImm());
Jim Grosbache5165492009-11-09 00:11:35 +0000410 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000411 return;
412 } else if (Modifier && strcmp(Modifier, "base") == 0) {
413 // Used for FSTM{D|S} and LSTM{D|S} operations.
414 O << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000415 return;
416 }
417
418 O << "[" << getRegisterName(MO1.getReg());
419
420 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
421 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000422 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000423 << ImmOffs*4;
424 }
425 O << "]";
426}
427
Chris Lattner235e2f62009-10-20 06:22:33 +0000428void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum) {
429 const MCOperand &MO1 = MI->getOperand(OpNum);
430 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Bob Wilsona43e6bf2010-03-16 23:01:13 +0000431 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Chris Lattner235e2f62009-10-20 06:22:33 +0000432
Bob Wilsona43e6bf2010-03-16 23:01:13 +0000433 // FIXME: No support yet for specifying alignment.
434 O << '[' << getRegisterName(MO1.getReg()) << ']';
435
436 if (ARM_AM::getAM6WBFlag(MO3.getImm())) {
437 if (MO2.getReg() == 0)
438 O << '!';
439 else
440 O << ", " << getRegisterName(MO2.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000441 }
442}
443
444void ARMInstPrinter::printAddrModePCOperand(const MCInst *MI, unsigned OpNum,
445 const char *Modifier) {
446 assert(0 && "FIXME: Implement printAddrModePCOperand");
447}
448
449void ARMInstPrinter::printBitfieldInvMaskImmOperand (const MCInst *MI,
450 unsigned OpNum) {
451 const MCOperand &MO = MI->getOperand(OpNum);
452 uint32_t v = ~MO.getImm();
453 int32_t lsb = CountTrailingZeros_32(v);
454 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
455 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
456 O << '#' << lsb << ", #" << width;
457}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000458
Chris Lattnere306d8d2009-10-19 22:09:23 +0000459void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum) {
460 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000461 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
462 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000463 O << getRegisterName(MI->getOperand(i).getReg());
464 }
465 O << "}";
466}
Chris Lattner4d152222009-10-19 22:23:04 +0000467
Johnny Chen9e088762010-03-17 17:52:21 +0000468void ARMInstPrinter::printCPSOptionOperand(const MCInst *MI, unsigned OpNum) {
469 const MCOperand &Op = MI->getOperand(OpNum);
470 unsigned option = Op.getImm();
471 unsigned mode = option & 31;
472 bool changemode = option >> 5 & 1;
473 unsigned AIF = option >> 6 & 7;
474 unsigned imod = option >> 9 & 3;
475 if (imod == 2)
476 O << "ie";
477 else if (imod == 3)
478 O << "id";
479 O << '\t';
480 if (imod > 1) {
481 if (AIF & 4) O << 'a';
482 if (AIF & 2) O << 'i';
483 if (AIF & 1) O << 'f';
484 if (AIF > 0 && changemode) O << ", ";
485 }
486 if (changemode)
487 O << '#' << mode;
488}
489
490void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum) {
491 const MCOperand &Op = MI->getOperand(OpNum);
492 unsigned Mask = Op.getImm();
493 if (Mask) {
494 O << '_';
495 if (Mask & 8) O << 'f';
496 if (Mask & 4) O << 's';
497 if (Mask & 2) O << 'x';
498 if (Mask & 1) O << 'c';
499 }
500}
501
502void ARMInstPrinter::printNegZeroOperand(const MCInst *MI, unsigned OpNum){
503 const MCOperand &Op = MI->getOperand(OpNum);
504 O << '#';
505 if (Op.getImm() < 0)
506 O << '-' << (-Op.getImm() - 1);
507 else
508 O << Op.getImm();
509}
510
Chris Lattner413ae252009-10-20 00:42:49 +0000511void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum) {
512 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
513 if (CC != ARMCC::AL)
514 O << ARMCondCodeToString(CC);
515}
516
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000517void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
518 unsigned OpNum) {
519 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
520 O << ARMCondCodeToString(CC);
521}
522
Chris Lattner233917c2009-10-20 00:46:11 +0000523void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum){
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000524 if (MI->getOperand(OpNum).getReg()) {
525 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
526 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000527 O << 's';
528 }
529}
530
531
Chris Lattner4d152222009-10-19 22:23:04 +0000532
Chris Lattnera70e6442009-10-19 22:33:05 +0000533void ARMInstPrinter::printCPInstOperand(const MCInst *MI, unsigned OpNum,
534 const char *Modifier) {
535 // FIXME: remove this.
536 abort();
537}
Chris Lattner4d152222009-10-19 22:23:04 +0000538
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000539void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum) {
540 O << MI->getOperand(OpNum).getImm();
541}
542
543
Chris Lattner4d152222009-10-19 22:23:04 +0000544void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum) {
545 // FIXME: remove this.
546 abort();
547}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000548
549void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum) {
Johnny Chen541ba7d2010-01-25 22:13:10 +0000550 O << "#" << MI->getOperand(OpNum).getImm() * 4;
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000551}
Johnny Chen9e088762010-03-17 17:52:21 +0000552
553void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum) {
554 // (3 - the number of trailing zeros) is the number of then / else.
555 unsigned Mask = MI->getOperand(OpNum).getImm();
556 unsigned CondBit0 = Mask >> 4 & 1;
557 unsigned NumTZ = CountTrailingZeros_32(Mask);
558 assert(NumTZ <= 3 && "Invalid IT mask!");
559 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
560 bool T = ((Mask >> Pos) & 1) == CondBit0;
561 if (T)
562 O << 't';
563 else
564 O << 'e';
565 }
566}
567
568void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op)
569{
570 const MCOperand &MO1 = MI->getOperand(Op);
571 const MCOperand &MO2 = MI->getOperand(Op+1);
572 O << "[" << getRegisterName(MO1.getReg());
573 O << ", " << getRegisterName(MO2.getReg()) << "]";
574}
575
576void ARMInstPrinter::printThumbAddrModeRI5Operand(const MCInst *MI, unsigned Op,
577 unsigned Scale) {
578 const MCOperand &MO1 = MI->getOperand(Op);
579 const MCOperand &MO2 = MI->getOperand(Op+1);
580 const MCOperand &MO3 = MI->getOperand(Op+2);
581
582 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
583 printOperand(MI, Op);
584 return;
585 }
586
587 O << "[" << getRegisterName(MO1.getReg());
588 if (MO3.getReg())
589 O << ", " << getRegisterName(MO3.getReg());
590 else if (unsigned ImmOffs = MO2.getImm())
591 O << ", #" << ImmOffs * Scale;
592 O << "]";
593}
594
595void ARMInstPrinter::printThumbAddrModeS1Operand(const MCInst *MI, unsigned Op)
596{
597 printThumbAddrModeRI5Operand(MI, Op, 1);
598}
599
600void ARMInstPrinter::printThumbAddrModeS2Operand(const MCInst *MI, unsigned Op)
601{
602 printThumbAddrModeRI5Operand(MI, Op, 2);
603}
604
605void ARMInstPrinter::printThumbAddrModeS4Operand(const MCInst *MI, unsigned Op)
606{
607 printThumbAddrModeRI5Operand(MI, Op, 4);
608}
609
610void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI,unsigned Op) {
611 const MCOperand &MO1 = MI->getOperand(Op);
612 const MCOperand &MO2 = MI->getOperand(Op+1);
613 O << "[" << getRegisterName(MO1.getReg());
614 if (unsigned ImmOffs = MO2.getImm())
615 O << ", #" << ImmOffs*4;
616 O << "]";
617}
618
619void ARMInstPrinter::printTBAddrMode(const MCInst *MI, unsigned OpNum) {
620 O << "[pc, " << getRegisterName(MI->getOperand(OpNum).getReg());
621 if (MI->getOpcode() == ARM::t2TBH)
622 O << ", lsl #1";
623 O << ']';
624}
625
626// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
627// register with shift forms.
628// REG 0 0 - e.g. R5
629// REG IMM, SH_OPC - e.g. R5, LSL #3
630void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum) {
631 const MCOperand &MO1 = MI->getOperand(OpNum);
632 const MCOperand &MO2 = MI->getOperand(OpNum+1);
633
634 unsigned Reg = MO1.getReg();
635 O << getRegisterName(Reg);
636
637 // Print the shift opc.
638 O << ", "
639 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()))
640 << " ";
641
642 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
643 O << "#" << ARM_AM::getSORegOffset(MO2.getImm());
644}
645
646void ARMInstPrinter::printT2AddrModeImm12Operand(const MCInst *MI,
647 unsigned OpNum) {
648 const MCOperand &MO1 = MI->getOperand(OpNum);
649 const MCOperand &MO2 = MI->getOperand(OpNum+1);
650
651 O << "[" << getRegisterName(MO1.getReg());
652
653 unsigned OffImm = MO2.getImm();
654 if (OffImm) // Don't print +0.
655 O << ", #" << OffImm;
656 O << "]";
657}
658
659void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
660 unsigned OpNum) {
661 const MCOperand &MO1 = MI->getOperand(OpNum);
662 const MCOperand &MO2 = MI->getOperand(OpNum+1);
663
664 O << "[" << getRegisterName(MO1.getReg());
665
666 int32_t OffImm = (int32_t)MO2.getImm();
667 // Don't print +0.
668 if (OffImm < 0)
669 O << ", #-" << -OffImm;
670 else if (OffImm > 0)
671 O << ", #" << OffImm;
672 O << "]";
673}
674
675void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
676 unsigned OpNum) {
677 const MCOperand &MO1 = MI->getOperand(OpNum);
678 const MCOperand &MO2 = MI->getOperand(OpNum+1);
679
680 O << "[" << getRegisterName(MO1.getReg());
681
682 int32_t OffImm = (int32_t)MO2.getImm() / 4;
683 // Don't print +0.
684 if (OffImm < 0)
685 O << ", #-" << -OffImm * 4;
686 else if (OffImm > 0)
687 O << ", #" << OffImm * 4;
688 O << "]";
689}
690
691void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
692 unsigned OpNum) {
693 const MCOperand &MO1 = MI->getOperand(OpNum);
694 int32_t OffImm = (int32_t)MO1.getImm();
695 // Don't print +0.
696 if (OffImm < 0)
697 O << "#-" << -OffImm;
698 else if (OffImm > 0)
699 O << "#" << OffImm;
700}
701
702void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
703 unsigned OpNum) {
704 const MCOperand &MO1 = MI->getOperand(OpNum);
705 int32_t OffImm = (int32_t)MO1.getImm() / 4;
706 // Don't print +0.
707 if (OffImm < 0)
708 O << "#-" << -OffImm * 4;
709 else if (OffImm > 0)
710 O << "#" << OffImm * 4;
711}
712
713void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
714 unsigned OpNum) {
715 const MCOperand &MO1 = MI->getOperand(OpNum);
716 const MCOperand &MO2 = MI->getOperand(OpNum+1);
717 const MCOperand &MO3 = MI->getOperand(OpNum+2);
718
719 O << "[" << getRegisterName(MO1.getReg());
720
721 assert(MO2.getReg() && "Invalid so_reg load / store address!");
722 O << ", " << getRegisterName(MO2.getReg());
723
724 unsigned ShAmt = MO3.getImm();
725 if (ShAmt) {
726 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
727 O << ", lsl #" << ShAmt;
728 }
729 O << "]";
730}
731
732void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum) {
733 O << '#' << MI->getOperand(OpNum).getImm();
734}
735
736void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum) {
737 O << '#' << MI->getOperand(OpNum).getImm();
738}
739