blob: 8b9109ec9868130fbc362265cbd3e5d554adf955 [file] [log] [blame]
Chris Lattnera2907782009-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"
15#include "ARMInstPrinter.h"
Evan Chengad5f4852011-07-23 00:00:19 +000016#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chenga20cde32011-07-20 23:34:39 +000017#include "MCTargetDesc/ARMAddressingModes.h"
Chris Lattnera2907782009-10-19 19:56:26 +000018#include "llvm/MC/MCInst.h"
Chris Lattner89d47202009-10-19 21:21:39 +000019#include "llvm/MC/MCAsmInfo.h"
Chris Lattner889a6212009-10-19 21:53:00 +000020#include "llvm/MC/MCExpr.h"
Craig Topperdab9e352012-04-02 07:01:04 +000021#include "llvm/MC/MCInstrInfo.h"
Jim Grosbachc988e0c2012-03-05 19:33:30 +000022#include "llvm/MC/MCRegisterInfo.h"
Chris Lattner889a6212009-10-19 21:53:00 +000023#include "llvm/Support/raw_ostream.h"
Chris Lattnera2907782009-10-19 19:56:26 +000024using namespace llvm;
25
Chris Lattnera2907782009-10-19 19:56:26 +000026#include "ARMGenAsmWriter.inc"
Chris Lattnera2907782009-10-19 19:56:26 +000027
Owen Andersone33c95d2011-08-11 18:41:59 +000028/// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing.
29///
Jim Grosbachd74c0e72011-10-12 16:36:01 +000030/// getSORegOffset returns an integer from 0-31, representing '32' as 0.
Owen Andersone33c95d2011-08-11 18:41:59 +000031static unsigned translateShiftImm(unsigned imm) {
32 if (imm == 0)
33 return 32;
34 return imm;
35}
36
James Molloy4c493e82011-09-07 17:24:38 +000037
38ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
Craig Topper54bfde72012-04-02 06:09:36 +000039 const MCInstrInfo &MII,
Jim Grosbachfd93a592012-03-05 19:33:20 +000040 const MCRegisterInfo &MRI,
James Molloy4c493e82011-09-07 17:24:38 +000041 const MCSubtargetInfo &STI) :
Craig Topper54bfde72012-04-02 06:09:36 +000042 MCInstPrinter(MAI, MII, MRI) {
James Molloy4c493e82011-09-07 17:24:38 +000043 // Initialize the set of available features.
44 setAvailableFeatures(STI.getFeatureBits());
45}
46
Rafael Espindolad6860522011-06-02 02:34:55 +000047void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
48 OS << getRegisterName(RegNo);
Anton Korobeynikove7410dd2011-03-05 18:43:32 +000049}
Chris Lattnerf20f7982010-10-28 21:37:33 +000050
Owen Andersona0c3b972011-09-15 23:38:46 +000051void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
52 StringRef Annot) {
Bill Wendlingf2fa04a2010-11-13 10:40:19 +000053 unsigned Opcode = MI->getOpcode();
54
Jim Grosbachcb540f52012-06-18 19:45:50 +000055 // Check for HINT instructions w/ canonical names.
56 if (Opcode == ARM::HINT || Opcode == ARM::t2HINT) {
57 switch (MI->getOperand(0).getImm()) {
58 case 0: O << "\tnop"; break;
59 case 1: O << "\tyield"; break;
60 case 2: O << "\twfe"; break;
61 case 3: O << "\twfi"; break;
62 case 4: O << "\tsev"; break;
63 default:
64 // Anything else should just print normally.
65 printInstruction(MI, O);
66 printAnnotation(O, Annot);
67 return;
68 }
69 printPredicateOperand(MI, 1, O);
70 if (Opcode == ARM::t2HINT)
71 O << ".w";
72 printAnnotation(O, Annot);
73 return;
74 }
75
Johnny Chen8f3004c2010-03-17 17:52:21 +000076 // Check for MOVs and print canonical forms, instead.
Owen Anderson04912702011-07-21 23:38:37 +000077 if (Opcode == ARM::MOVsr) {
Jim Grosbach7a6c37d2010-09-17 22:36:38 +000078 // FIXME: Thumb variants?
Johnny Chen8f3004c2010-03-17 17:52:21 +000079 const MCOperand &Dst = MI->getOperand(0);
80 const MCOperand &MO1 = MI->getOperand(1);
81 const MCOperand &MO2 = MI->getOperand(2);
82 const MCOperand &MO3 = MI->getOperand(3);
83
84 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner76c564b2010-04-04 04:47:45 +000085 printSBitModifierOperand(MI, 6, O);
86 printPredicateOperand(MI, 4, O);
Johnny Chen8f3004c2010-03-17 17:52:21 +000087
88 O << '\t' << getRegisterName(Dst.getReg())
89 << ", " << getRegisterName(MO1.getReg());
90
Owen Anderson04912702011-07-21 23:38:37 +000091 O << ", " << getRegisterName(MO2.getReg());
92 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Owen Andersonbcc3fad2011-09-21 17:58:45 +000093 printAnnotation(O, Annot);
Johnny Chen8f3004c2010-03-17 17:52:21 +000094 return;
95 }
96
Owen Anderson04912702011-07-21 23:38:37 +000097 if (Opcode == ARM::MOVsi) {
98 // FIXME: Thumb variants?
99 const MCOperand &Dst = MI->getOperand(0);
100 const MCOperand &MO1 = MI->getOperand(1);
101 const MCOperand &MO2 = MI->getOperand(2);
102
103 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
104 printSBitModifierOperand(MI, 5, O);
105 printPredicateOperand(MI, 3, O);
106
107 O << '\t' << getRegisterName(Dst.getReg())
108 << ", " << getRegisterName(MO1.getReg());
109
Owen Andersond1814792011-09-15 18:36:29 +0000110 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000111 printAnnotation(O, Annot);
Owen Anderson04912702011-07-21 23:38:37 +0000112 return;
Owen Andersond1814792011-09-15 18:36:29 +0000113 }
Owen Anderson04912702011-07-21 23:38:37 +0000114
Owen Andersone33c95d2011-08-11 18:41:59 +0000115 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000116 printAnnotation(O, Annot);
Owen Anderson04912702011-07-21 23:38:37 +0000117 return;
118 }
119
120
Johnny Chen8f3004c2010-03-17 17:52:21 +0000121 // A8.6.123 PUSH
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000122 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Owen Andersonfbb704f2011-11-02 18:03:14 +0000123 MI->getOperand(0).getReg() == ARM::SP &&
124 MI->getNumOperands() > 5) {
125 // Should only print PUSH if there are at least two registers in the list.
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000126 O << '\t' << "push";
127 printPredicateOperand(MI, 2, O);
Jim Grosbachca7eaaa2010-12-03 20:33:01 +0000128 if (Opcode == ARM::t2STMDB_UPD)
129 O << ".w";
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000130 O << '\t';
131 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000132 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000133 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000134 }
Jim Grosbach27ad83d2011-08-11 18:07:11 +0000135 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
136 MI->getOperand(3).getImm() == -4) {
137 O << '\t' << "push";
138 printPredicateOperand(MI, 4, O);
139 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000140 printAnnotation(O, Annot);
Jim Grosbach27ad83d2011-08-11 18:07:11 +0000141 return;
142 }
Johnny Chen8f3004c2010-03-17 17:52:21 +0000143
144 // A8.6.122 POP
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000145 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Owen Andersonfbb704f2011-11-02 18:03:14 +0000146 MI->getOperand(0).getReg() == ARM::SP &&
147 MI->getNumOperands() > 5) {
148 // Should only print POP if there are at least two registers in the list.
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000149 O << '\t' << "pop";
150 printPredicateOperand(MI, 2, O);
Jim Grosbachca7eaaa2010-12-03 20:33:01 +0000151 if (Opcode == ARM::t2LDMIA_UPD)
152 O << ".w";
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000153 O << '\t';
154 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000155 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000156 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000157 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000158 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
159 MI->getOperand(4).getImm() == 4) {
160 O << '\t' << "pop";
161 printPredicateOperand(MI, 5, O);
162 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000163 printAnnotation(O, Annot);
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000164 return;
165 }
166
Johnny Chen8f3004c2010-03-17 17:52:21 +0000167
168 // A8.6.355 VPUSH
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000169 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen8f3004c2010-03-17 17:52:21 +0000170 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000171 O << '\t' << "vpush";
172 printPredicateOperand(MI, 2, O);
173 O << '\t';
174 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000175 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000176 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000177 }
178
179 // A8.6.354 VPOP
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000180 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen8f3004c2010-03-17 17:52:21 +0000181 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000182 O << '\t' << "vpop";
183 printPredicateOperand(MI, 2, O);
184 O << '\t';
185 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000186 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000187 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000188 }
189
Jim Grosbache364ad52011-08-23 17:41:15 +0000190 if (Opcode == ARM::tLDMIA) {
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000191 bool Writeback = true;
192 unsigned BaseReg = MI->getOperand(0).getReg();
193 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
194 if (MI->getOperand(i).getReg() == BaseReg)
195 Writeback = false;
196 }
197
Jim Grosbache364ad52011-08-23 17:41:15 +0000198 O << "\tldm";
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000199
200 printPredicateOperand(MI, 1, O);
201 O << '\t' << getRegisterName(BaseReg);
202 if (Writeback) O << "!";
203 O << ", ";
204 printRegisterList(MI, 3, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000205 printAnnotation(O, Annot);
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000206 return;
207 }
208
Jim Grosbach25977222011-08-19 23:24:36 +0000209 // Thumb1 NOP
210 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
211 MI->getOperand(1).getReg() == ARM::R8) {
212 O << "\tnop";
Jim Grosbachaf2f8272011-08-24 20:06:14 +0000213 printPredicateOperand(MI, 2, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000214 printAnnotation(O, Annot);
Jim Grosbach25977222011-08-19 23:24:36 +0000215 return;
216 }
217
Chris Lattner76c564b2010-04-04 04:47:45 +0000218 printInstruction(MI, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000219 printAnnotation(O, Annot);
Bill Wendlingf2fa04a2010-11-13 10:40:19 +0000220}
Chris Lattnera2907782009-10-19 19:56:26 +0000221
Chris Lattner93e3ef62009-10-19 20:59:55 +0000222void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000223 raw_ostream &O) {
Chris Lattner93e3ef62009-10-19 20:59:55 +0000224 const MCOperand &Op = MI->getOperand(OpNo);
225 if (Op.isReg()) {
Chris Lattner60d51312009-10-20 06:15:28 +0000226 unsigned Reg = Op.getReg();
Jim Grosbach2c950272010-10-06 21:22:32 +0000227 O << getRegisterName(Reg);
Chris Lattner93e3ef62009-10-19 20:59:55 +0000228 } else if (Op.isImm()) {
229 O << '#' << Op.getImm();
230 } else {
231 assert(Op.isExpr() && "unknown operand kind in printOperand");
Kevin Enderby5dcda642011-10-04 22:44:48 +0000232 // If a symbolic branch target was added as a constant expression then print
Kevin Enderbyc407cc72012-04-13 18:46:37 +0000233 // that address in hex. And only print 32 unsigned bits for the address.
Kevin Enderby5dcda642011-10-04 22:44:48 +0000234 const MCConstantExpr *BranchTarget = dyn_cast<MCConstantExpr>(Op.getExpr());
235 int64_t Address;
236 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
237 O << "0x";
Kevin Enderbyc407cc72012-04-13 18:46:37 +0000238 O.write_hex((uint32_t)Address);
Kevin Enderby5dcda642011-10-04 22:44:48 +0000239 }
240 else {
241 // Otherwise, just print the expression.
242 O << *Op.getExpr();
243 }
Chris Lattner93e3ef62009-10-19 20:59:55 +0000244 }
245}
Chris Lattner89d47202009-10-19 21:21:39 +0000246
Owen Andersonf52c68f2011-09-21 23:44:46 +0000247void ARMInstPrinter::printT2LdrLabelOperand(const MCInst *MI, unsigned OpNum,
248 raw_ostream &O) {
249 const MCOperand &MO1 = MI->getOperand(OpNum);
250 if (MO1.isExpr())
251 O << *MO1.getExpr();
252 else if (MO1.isImm())
253 O << "[pc, #" << MO1.getImm() << "]";
254 else
255 llvm_unreachable("Unknown LDR label operand?");
256}
257
Chris Lattner2f69ed82009-10-20 00:40:56 +0000258// so_reg is a 4-operand unit corresponding to register forms of the A5.1
259// "Addressing Mode 1 - Data-processing operands" forms. This includes:
260// REG 0 0 - e.g. R5
261// REG REG 0,SH_OPC - e.g. R5, ROR R3
262// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson04912702011-07-21 23:38:37 +0000263void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner76c564b2010-04-04 04:47:45 +0000264 raw_ostream &O) {
Chris Lattner2f69ed82009-10-20 00:40:56 +0000265 const MCOperand &MO1 = MI->getOperand(OpNum);
266 const MCOperand &MO2 = MI->getOperand(OpNum+1);
267 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000268
Chris Lattner2f69ed82009-10-20 00:40:56 +0000269 O << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000270
Chris Lattner2f69ed82009-10-20 00:40:56 +0000271 // Print the shift opc.
Bob Wilson97886d52010-08-05 00:34:42 +0000272 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
273 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000274 if (ShOpc == ARM_AM::rrx)
275 return;
Jim Grosbach20cb5052011-10-21 16:56:40 +0000276
Owen Anderson04912702011-07-21 23:38:37 +0000277 O << ' ' << getRegisterName(MO2.getReg());
278 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner2f69ed82009-10-20 00:40:56 +0000279}
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000280
Owen Anderson04912702011-07-21 23:38:37 +0000281void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
282 raw_ostream &O) {
283 const MCOperand &MO1 = MI->getOperand(OpNum);
284 const MCOperand &MO2 = MI->getOperand(OpNum+1);
285
286 O << getRegisterName(MO1.getReg());
287
288 // Print the shift opc.
289 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
290 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
291 if (ShOpc == ARM_AM::rrx)
292 return;
Owen Andersone33c95d2011-08-11 18:41:59 +0000293 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson04912702011-07-21 23:38:37 +0000294}
295
296
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000297//===--------------------------------------------------------------------===//
298// Addressing Mode #2
299//===--------------------------------------------------------------------===//
300
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000301void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
302 raw_ostream &O) {
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000303 const MCOperand &MO1 = MI->getOperand(Op);
304 const MCOperand &MO2 = MI->getOperand(Op+1);
305 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000306
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000307 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000308
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000309 if (!MO2.getReg()) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000310 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000311 O << ", #"
Johnny Chen8f3004c2010-03-17 17:52:21 +0000312 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
313 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000314 O << "]";
315 return;
316 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000317
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000318 O << ", "
Johnny Chen8f3004c2010-03-17 17:52:21 +0000319 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
320 << getRegisterName(MO2.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000321
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000322 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
323 O << ", "
324 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
325 << " #" << ShImm;
326 O << "]";
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000327}
Chris Lattneref2979b2009-10-19 22:09:23 +0000328
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000329void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
330 raw_ostream &O) {
331 const MCOperand &MO1 = MI->getOperand(Op);
332 const MCOperand &MO2 = MI->getOperand(Op+1);
333 const MCOperand &MO3 = MI->getOperand(Op+2);
334
335 O << "[" << getRegisterName(MO1.getReg()) << "], ";
336
337 if (!MO2.getReg()) {
338 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
339 O << '#'
340 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
341 << ImmOffs;
342 return;
343 }
344
345 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
346 << getRegisterName(MO2.getReg());
347
348 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
349 O << ", "
350 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
351 << " #" << ShImm;
352}
353
Jim Grosbach05541f42011-09-19 22:21:13 +0000354void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
355 raw_ostream &O) {
356 const MCOperand &MO1 = MI->getOperand(Op);
357 const MCOperand &MO2 = MI->getOperand(Op+1);
358 O << "[" << getRegisterName(MO1.getReg()) << ", "
359 << getRegisterName(MO2.getReg()) << "]";
360}
361
362void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
363 raw_ostream &O) {
364 const MCOperand &MO1 = MI->getOperand(Op);
365 const MCOperand &MO2 = MI->getOperand(Op+1);
366 O << "[" << getRegisterName(MO1.getReg()) << ", "
367 << getRegisterName(MO2.getReg()) << ", lsl #1]";
368}
369
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000370void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
371 raw_ostream &O) {
372 const MCOperand &MO1 = MI->getOperand(Op);
373
374 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
375 printOperand(MI, Op, O);
376 return;
377 }
378
379 const MCOperand &MO3 = MI->getOperand(Op+2);
380 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
381
382 if (IdxMode == ARMII::IndexModePost) {
383 printAM2PostIndexOp(MI, Op, O);
384 return;
385 }
386 printAM2PreOrOffsetIndexOp(MI, Op, O);
387}
388
Chris Lattner60d51312009-10-20 06:15:28 +0000389void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000390 unsigned OpNum,
391 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000392 const MCOperand &MO1 = MI->getOperand(OpNum);
393 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000394
Chris Lattner60d51312009-10-20 06:15:28 +0000395 if (!MO1.getReg()) {
396 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +0000397 O << '#'
398 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
399 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000400 return;
401 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000402
Johnny Chen8f3004c2010-03-17 17:52:21 +0000403 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
404 << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000405
Chris Lattner60d51312009-10-20 06:15:28 +0000406 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
407 O << ", "
408 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
409 << " #" << ShImm;
410}
411
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000412//===--------------------------------------------------------------------===//
413// Addressing Mode #3
414//===--------------------------------------------------------------------===//
415
416void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
417 raw_ostream &O) {
418 const MCOperand &MO1 = MI->getOperand(Op);
419 const MCOperand &MO2 = MI->getOperand(Op+1);
420 const MCOperand &MO3 = MI->getOperand(Op+2);
421
422 O << "[" << getRegisterName(MO1.getReg()) << "], ";
423
424 if (MO2.getReg()) {
425 O << (char)ARM_AM::getAM3Op(MO3.getImm())
426 << getRegisterName(MO2.getReg());
427 return;
428 }
429
430 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
431 O << '#'
432 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
433 << ImmOffs;
434}
435
436void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
437 raw_ostream &O) {
438 const MCOperand &MO1 = MI->getOperand(Op);
439 const MCOperand &MO2 = MI->getOperand(Op+1);
440 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000441
Chris Lattner60d51312009-10-20 06:15:28 +0000442 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000443
Chris Lattner60d51312009-10-20 06:15:28 +0000444 if (MO2.getReg()) {
Jim Grosbachd3595712011-08-03 23:50:40 +0000445 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattner60d51312009-10-20 06:15:28 +0000446 << getRegisterName(MO2.getReg()) << ']';
447 return;
448 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000449
Silviu Baranga5a719f92012-05-11 09:10:54 +0000450 //If the op is sub we have to print the immediate even if it is 0
451 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
452 ARM_AM::AddrOpc op = ARM_AM::getAM3Op(MO3.getImm());
453
454 if (ImmOffs || (op == ARM_AM::sub))
Chris Lattner60d51312009-10-20 06:15:28 +0000455 O << ", #"
Silviu Baranga5a719f92012-05-11 09:10:54 +0000456 << ARM_AM::getAddrOpcStr(op)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000457 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000458 O << ']';
459}
460
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000461void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
462 raw_ostream &O) {
Jim Grosbach8648c102011-12-19 23:06:24 +0000463 const MCOperand &MO1 = MI->getOperand(Op);
464 if (!MO1.isReg()) { // For label symbolic references.
465 printOperand(MI, Op, O);
466 return;
467 }
468
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000469 const MCOperand &MO3 = MI->getOperand(Op+2);
470 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
471
472 if (IdxMode == ARMII::IndexModePost) {
473 printAM3PostIndexOp(MI, Op, O);
474 return;
475 }
476 printAM3PreOrOffsetIndexOp(MI, Op, O);
477}
478
Chris Lattner60d51312009-10-20 06:15:28 +0000479void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000480 unsigned OpNum,
481 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000482 const MCOperand &MO1 = MI->getOperand(OpNum);
483 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000484
Chris Lattner60d51312009-10-20 06:15:28 +0000485 if (MO1.getReg()) {
Jim Grosbachd3595712011-08-03 23:50:40 +0000486 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
487 << getRegisterName(MO1.getReg());
Chris Lattner60d51312009-10-20 06:15:28 +0000488 return;
489 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000490
Chris Lattner60d51312009-10-20 06:15:28 +0000491 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +0000492 O << '#'
493 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
494 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000495}
496
Jim Grosbachd3595712011-08-03 23:50:40 +0000497void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
498 unsigned OpNum,
499 raw_ostream &O) {
500 const MCOperand &MO = MI->getOperand(OpNum);
501 unsigned Imm = MO.getImm();
502 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
503}
504
Jim Grosbachbafce842011-08-05 15:48:21 +0000505void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
506 raw_ostream &O) {
507 const MCOperand &MO1 = MI->getOperand(OpNum);
508 const MCOperand &MO2 = MI->getOperand(OpNum+1);
509
Jim Grosbacha70fbfd52011-08-05 16:11:38 +0000510 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachbafce842011-08-05 15:48:21 +0000511}
512
Owen Andersonce519032011-08-04 18:24:14 +0000513void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
514 unsigned OpNum,
515 raw_ostream &O) {
516 const MCOperand &MO = MI->getOperand(OpNum);
517 unsigned Imm = MO.getImm();
518 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
519}
520
521
Jim Grosbachc6af2b42010-11-03 01:01:43 +0000522void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000523 raw_ostream &O) {
Jim Grosbachc6af2b42010-11-03 01:01:43 +0000524 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
525 .getImm());
526 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattneref2979b2009-10-19 22:09:23 +0000527}
528
Chris Lattner60d51312009-10-20 06:15:28 +0000529void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000530 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000531 const MCOperand &MO1 = MI->getOperand(OpNum);
532 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000533
Chris Lattner60d51312009-10-20 06:15:28 +0000534 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner76c564b2010-04-04 04:47:45 +0000535 printOperand(MI, OpNum, O);
Chris Lattner60d51312009-10-20 06:15:28 +0000536 return;
537 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000538
Chris Lattner60d51312009-10-20 06:15:28 +0000539 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000540
Owen Anderson967674d2011-08-29 19:36:44 +0000541 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
542 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
543 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattner60d51312009-10-20 06:15:28 +0000544 O << ", #"
Johnny Chen8f3004c2010-03-17 17:52:21 +0000545 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendlinge84eb992010-11-03 01:49:29 +0000546 << ImmOffs * 4;
Chris Lattner60d51312009-10-20 06:15:28 +0000547 }
548 O << "]";
549}
550
Chris Lattner76c564b2010-04-04 04:47:45 +0000551void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
552 raw_ostream &O) {
Chris Lattner9351e4f2009-10-20 06:22:33 +0000553 const MCOperand &MO1 = MI->getOperand(OpNum);
554 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000555
Bob Wilsonae08a732010-03-20 22:13:40 +0000556 O << "[" << getRegisterName(MO1.getReg());
557 if (MO2.getImm()) {
558 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson0b9aafd2010-07-14 23:54:43 +0000559 O << ", :" << (MO2.getImm() << 3);
Chris Lattner9351e4f2009-10-20 06:22:33 +0000560 }
Bob Wilsonae08a732010-03-20 22:13:40 +0000561 O << "]";
562}
563
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +0000564void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
565 raw_ostream &O) {
566 const MCOperand &MO1 = MI->getOperand(OpNum);
567 O << "[" << getRegisterName(MO1.getReg()) << "]";
568}
569
Bob Wilsonae08a732010-03-20 22:13:40 +0000570void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000571 unsigned OpNum,
572 raw_ostream &O) {
Bob Wilsonae08a732010-03-20 22:13:40 +0000573 const MCOperand &MO = MI->getOperand(OpNum);
574 if (MO.getReg() == 0)
575 O << "!";
576 else
577 O << ", " << getRegisterName(MO.getReg());
Chris Lattner9351e4f2009-10-20 06:22:33 +0000578}
579
Bob Wilsonadd513112010-08-11 23:10:46 +0000580void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
581 unsigned OpNum,
582 raw_ostream &O) {
Chris Lattner9351e4f2009-10-20 06:22:33 +0000583 const MCOperand &MO = MI->getOperand(OpNum);
584 uint32_t v = ~MO.getImm();
585 int32_t lsb = CountTrailingZeros_32(v);
586 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
587 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
588 O << '#' << lsb << ", #" << width;
589}
Chris Lattner60d51312009-10-20 06:15:28 +0000590
Johnny Chen8e8f1c12010-08-12 20:46:17 +0000591void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
592 raw_ostream &O) {
593 unsigned val = MI->getOperand(OpNum).getImm();
594 O << ARM_MB::MemBOptToString(val);
595}
596
Bob Wilson481d7a92010-08-16 18:27:34 +0000597void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsonadd513112010-08-11 23:10:46 +0000598 raw_ostream &O) {
599 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000600 bool isASR = (ShiftOp & (1 << 5)) != 0;
601 unsigned Amt = ShiftOp & 0x1f;
602 if (isASR)
603 O << ", asr #" << (Amt == 0 ? 32 : Amt);
604 else if (Amt)
605 O << ", lsl #" << Amt;
Bob Wilsonadd513112010-08-11 23:10:46 +0000606}
607
Jim Grosbacha288b1c2011-07-20 21:40:26 +0000608void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
609 raw_ostream &O) {
610 unsigned Imm = MI->getOperand(OpNum).getImm();
611 if (Imm == 0)
612 return;
613 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
614 O << ", lsl #" << Imm;
615}
616
617void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
618 raw_ostream &O) {
619 unsigned Imm = MI->getOperand(OpNum).getImm();
620 // A shift amount of 32 is encoded as 0.
621 if (Imm == 0)
622 Imm = 32;
623 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
624 O << ", asr #" << Imm;
625}
626
Chris Lattner76c564b2010-04-04 04:47:45 +0000627void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
628 raw_ostream &O) {
Chris Lattneref2979b2009-10-19 22:09:23 +0000629 O << "{";
Johnny Chen8f3004c2010-03-17 17:52:21 +0000630 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
631 if (i != OpNum) O << ", ";
Chris Lattneref2979b2009-10-19 22:09:23 +0000632 O << getRegisterName(MI->getOperand(i).getReg());
633 }
634 O << "}";
635}
Chris Lattneradd57492009-10-19 22:23:04 +0000636
Jim Grosbach7e72ec62010-10-13 21:00:04 +0000637void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
638 raw_ostream &O) {
639 const MCOperand &Op = MI->getOperand(OpNum);
640 if (Op.getImm())
641 O << "be";
642 else
643 O << "le";
644}
645
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000646void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
647 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000648 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000649 O << ARM_PROC::IModToString(Op.getImm());
650}
651
652void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
653 raw_ostream &O) {
654 const MCOperand &Op = MI->getOperand(OpNum);
655 unsigned IFlags = Op.getImm();
656 for (int i=2; i >= 0; --i)
657 if (IFlags & (1 << i))
658 O << ARM_PROC::IFlagsToString(1 << i);
Owen Anderson10c5b122011-10-05 17:16:40 +0000659
660 if (IFlags == 0)
661 O << "none";
Johnny Chen8f3004c2010-03-17 17:52:21 +0000662}
663
Chris Lattner76c564b2010-04-04 04:47:45 +0000664void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
665 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000666 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000667 unsigned SpecRegRBit = Op.getImm() >> 4;
668 unsigned Mask = Op.getImm() & 0xf;
669
James Molloy21efa7d2011-09-28 14:21:38 +0000670 if (getAvailableFeatures() & ARM::FeatureMClass) {
Kevin Enderbyf1b225d2012-05-17 22:18:01 +0000671 unsigned SYSm = Op.getImm();
672 unsigned Opcode = MI->getOpcode();
673 // For reads of the special registers ignore the "mask encoding" bits
674 // which are only for writes.
675 if (Opcode == ARM::t2MRS_M)
676 SYSm &= 0xff;
677 switch (SYSm) {
Craig Toppere55c5562012-02-07 02:50:20 +0000678 default: llvm_unreachable("Unexpected mask value!");
Kevin Enderbyf1b225d2012-05-17 22:18:01 +0000679 case 0:
680 case 0x800: O << "apsr"; return; // with _nzcvq bits is an alias for aspr
681 case 0x400: O << "apsr_g"; return;
682 case 0xc00: O << "apsr_nzcvqg"; return;
683 case 1:
684 case 0x801: O << "iapsr"; return; // with _nzcvq bits is an alias for iapsr
685 case 0x401: O << "iapsr_g"; return;
686 case 0xc01: O << "iapsr_nzcvqg"; return;
687 case 2:
688 case 0x802: O << "eapsr"; return; // with _nzcvq bits is an alias for eapsr
689 case 0x402: O << "eapsr_g"; return;
690 case 0xc02: O << "eapsr_nzcvqg"; return;
691 case 3:
692 case 0x803: O << "xpsr"; return; // with _nzcvq bits is an alias for xpsr
693 case 0x403: O << "xpsr_g"; return;
694 case 0xc03: O << "xpsr_nzcvqg"; return;
Kevin Enderby6c7279e2012-06-15 22:14:44 +0000695 case 5:
696 case 0x805: O << "ipsr"; return;
697 case 6:
698 case 0x806: O << "epsr"; return;
699 case 7:
700 case 0x807: O << "iepsr"; return;
701 case 8:
702 case 0x808: O << "msp"; return;
703 case 9:
704 case 0x809: O << "psp"; return;
705 case 0x10:
706 case 0x810: O << "primask"; return;
707 case 0x11:
708 case 0x811: O << "basepri"; return;
709 case 0x12:
710 case 0x812: O << "basepri_max"; return;
711 case 0x13:
712 case 0x813: O << "faultmask"; return;
713 case 0x14:
714 case 0x814: O << "control"; return;
James Molloy21efa7d2011-09-28 14:21:38 +0000715 }
716 }
717
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000718 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
719 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
720 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
721 O << "APSR_";
722 switch (Mask) {
Craig Toppere55c5562012-02-07 02:50:20 +0000723 default: llvm_unreachable("Unexpected mask value!");
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000724 case 4: O << "g"; return;
725 case 8: O << "nzcvq"; return;
726 case 12: O << "nzcvqg"; return;
727 }
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000728 }
729
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000730 if (SpecRegRBit)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000731 O << "SPSR";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000732 else
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000733 O << "CPSR";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000734
Johnny Chen8f3004c2010-03-17 17:52:21 +0000735 if (Mask) {
736 O << '_';
737 if (Mask & 8) O << 'f';
738 if (Mask & 4) O << 's';
739 if (Mask & 2) O << 'x';
740 if (Mask & 1) O << 'c';
741 }
742}
743
Chris Lattner76c564b2010-04-04 04:47:45 +0000744void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
745 raw_ostream &O) {
Chris Lattner19c52202009-10-20 00:42:49 +0000746 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
Kevin Enderbyf0269b42012-03-01 22:13:02 +0000747 // Handle the undefined 15 CC value here for printing so we don't abort().
748 if ((unsigned)CC == 15)
749 O << "<und>";
750 else if (CC != ARMCC::AL)
Chris Lattner19c52202009-10-20 00:42:49 +0000751 O << ARMCondCodeToString(CC);
752}
753
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000754void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000755 unsigned OpNum,
756 raw_ostream &O) {
Johnny Chen0dae1cb2010-03-02 17:57:15 +0000757 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
758 O << ARMCondCodeToString(CC);
759}
760
Chris Lattner76c564b2010-04-04 04:47:45 +0000761void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
762 raw_ostream &O) {
Daniel Dunbara470eac2009-10-20 22:10:05 +0000763 if (MI->getOperand(OpNum).getReg()) {
764 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
765 "Expect ARM CPSR register!");
Chris Lattner85ab6702009-10-20 00:46:11 +0000766 O << 's';
767 }
768}
769
Chris Lattner76c564b2010-04-04 04:47:45 +0000770void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
771 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000772 O << MI->getOperand(OpNum).getImm();
773}
774
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000775void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbach69664112011-10-12 16:34:37 +0000776 raw_ostream &O) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000777 O << "p" << MI->getOperand(OpNum).getImm();
778}
779
780void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbach69664112011-10-12 16:34:37 +0000781 raw_ostream &O) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000782 O << "c" << MI->getOperand(OpNum).getImm();
783}
784
Jim Grosbach48399582011-10-12 17:34:41 +0000785void ARMInstPrinter::printCoprocOptionImm(const MCInst *MI, unsigned OpNum,
786 raw_ostream &O) {
787 O << "{" << MI->getOperand(OpNum).getImm() << "}";
788}
789
Chris Lattner76c564b2010-04-04 04:47:45 +0000790void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
791 raw_ostream &O) {
Jim Grosbach8a5a6a62010-09-18 00:04:53 +0000792 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattneradd57492009-10-19 22:23:04 +0000793}
Evan Chengb1852592009-11-19 06:57:41 +0000794
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000795void ARMInstPrinter::printAdrLabelOperand(const MCInst *MI, unsigned OpNum,
796 raw_ostream &O) {
797 const MCOperand &MO = MI->getOperand(OpNum);
798
799 if (MO.isExpr()) {
800 O << *MO.getExpr();
801 return;
802 }
803
804 int32_t OffImm = (int32_t)MO.getImm();
805
806 if (OffImm == INT32_MIN)
807 O << "#-0";
808 else if (OffImm < 0)
809 O << "#-" << -OffImm;
810 else
811 O << "#" << OffImm;
812}
813
Chris Lattner76c564b2010-04-04 04:47:45 +0000814void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
815 raw_ostream &O) {
Jim Grosbach46dd4132011-08-17 21:51:27 +0000816 O << "#" << MI->getOperand(OpNum).getImm() * 4;
817}
818
819void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
820 raw_ostream &O) {
821 unsigned Imm = MI->getOperand(OpNum).getImm();
822 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Chengb1852592009-11-19 06:57:41 +0000823}
Johnny Chen8f3004c2010-03-17 17:52:21 +0000824
Chris Lattner76c564b2010-04-04 04:47:45 +0000825void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
826 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000827 // (3 - the number of trailing zeros) is the number of then / else.
828 unsigned Mask = MI->getOperand(OpNum).getImm();
Richard Bartonf435b092012-04-27 08:42:59 +0000829 unsigned Firstcond = MI->getOperand(OpNum-1).getImm();
830 unsigned CondBit0 = Firstcond & 1;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000831 unsigned NumTZ = CountTrailingZeros_32(Mask);
832 assert(NumTZ <= 3 && "Invalid IT mask!");
833 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
834 bool T = ((Mask >> Pos) & 1) == CondBit0;
835 if (T)
836 O << 't';
837 else
838 O << 'e';
839 }
840}
841
Chris Lattner76c564b2010-04-04 04:47:45 +0000842void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
843 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000844 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000845 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000846
847 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner76c564b2010-04-04 04:47:45 +0000848 printOperand(MI, Op, O);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000849 return;
850 }
851
852 O << "[" << getRegisterName(MO1.getReg());
Bill Wendling092a7bd2010-12-14 03:36:38 +0000853 if (unsigned RegNum = MO2.getReg())
854 O << ", " << getRegisterName(RegNum);
855 O << "]";
856}
857
858void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
859 unsigned Op,
860 raw_ostream &O,
861 unsigned Scale) {
862 const MCOperand &MO1 = MI->getOperand(Op);
863 const MCOperand &MO2 = MI->getOperand(Op + 1);
864
865 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
866 printOperand(MI, Op, O);
867 return;
868 }
869
870 O << "[" << getRegisterName(MO1.getReg());
871 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen8f3004c2010-03-17 17:52:21 +0000872 O << ", #" << ImmOffs * Scale;
873 O << "]";
874}
875
Bill Wendling092a7bd2010-12-14 03:36:38 +0000876void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
877 unsigned Op,
878 raw_ostream &O) {
879 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000880}
881
Bill Wendling092a7bd2010-12-14 03:36:38 +0000882void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
883 unsigned Op,
884 raw_ostream &O) {
885 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000886}
887
Bill Wendling092a7bd2010-12-14 03:36:38 +0000888void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
889 unsigned Op,
890 raw_ostream &O) {
891 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000892}
893
Chris Lattner76c564b2010-04-04 04:47:45 +0000894void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
895 raw_ostream &O) {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000896 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000897}
898
Johnny Chen8f3004c2010-03-17 17:52:21 +0000899// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
900// register with shift forms.
901// REG 0 0 - e.g. R5
902// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner76c564b2010-04-04 04:47:45 +0000903void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
904 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000905 const MCOperand &MO1 = MI->getOperand(OpNum);
906 const MCOperand &MO2 = MI->getOperand(OpNum+1);
907
908 unsigned Reg = MO1.getReg();
909 O << getRegisterName(Reg);
910
911 // Print the shift opc.
Johnny Chen8f3004c2010-03-17 17:52:21 +0000912 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson97886d52010-08-05 00:34:42 +0000913 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
914 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
915 if (ShOpc != ARM_AM::rrx)
Owen Andersone33c95d2011-08-11 18:41:59 +0000916 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen8f3004c2010-03-17 17:52:21 +0000917}
918
Jim Grosbache6fe1a02010-10-25 20:00:01 +0000919void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
920 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000921 const MCOperand &MO1 = MI->getOperand(OpNum);
922 const MCOperand &MO2 = MI->getOperand(OpNum+1);
923
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000924 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
925 printOperand(MI, OpNum, O);
926 return;
927 }
928
Johnny Chen8f3004c2010-03-17 17:52:21 +0000929 O << "[" << getRegisterName(MO1.getReg());
930
Jim Grosbach9d2d1f02010-10-27 01:19:41 +0000931 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbach505607e2010-10-28 18:34:10 +0000932 bool isSub = OffImm < 0;
933 // Special value for #-0. All others are normal.
934 if (OffImm == INT32_MIN)
935 OffImm = 0;
936 if (isSub)
Jim Grosbach9d2d1f02010-10-27 01:19:41 +0000937 O << ", #-" << -OffImm;
938 else if (OffImm > 0)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000939 O << ", #" << OffImm;
940 O << "]";
941}
942
943void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000944 unsigned OpNum,
945 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000946 const MCOperand &MO1 = MI->getOperand(OpNum);
947 const MCOperand &MO2 = MI->getOperand(OpNum+1);
948
949 O << "[" << getRegisterName(MO1.getReg());
950
951 int32_t OffImm = (int32_t)MO2.getImm();
952 // Don't print +0.
Owen Andersonfe823652011-09-16 21:08:33 +0000953 if (OffImm == INT32_MIN)
954 O << ", #-0";
955 else if (OffImm < 0)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000956 O << ", #-" << -OffImm;
957 else if (OffImm > 0)
958 O << ", #" << OffImm;
959 O << "]";
960}
961
962void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000963 unsigned OpNum,
964 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000965 const MCOperand &MO1 = MI->getOperand(OpNum);
966 const MCOperand &MO2 = MI->getOperand(OpNum+1);
967
Jim Grosbach8648c102011-12-19 23:06:24 +0000968 if (!MO1.isReg()) { // For label symbolic references.
969 printOperand(MI, OpNum, O);
970 return;
971 }
972
Johnny Chen8f3004c2010-03-17 17:52:21 +0000973 O << "[" << getRegisterName(MO1.getReg());
974
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000975 int32_t OffImm = (int32_t)MO2.getImm();
976
977 assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
978
Johnny Chen8f3004c2010-03-17 17:52:21 +0000979 // Don't print +0.
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000980 if (OffImm == INT32_MIN)
981 O << ", #-0";
982 else if (OffImm < 0)
983 O << ", #-" << -OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000984 else if (OffImm > 0)
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000985 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000986 O << "]";
987}
988
Jim Grosbacha05627e2011-09-09 18:37:27 +0000989void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
990 unsigned OpNum,
991 raw_ostream &O) {
992 const MCOperand &MO1 = MI->getOperand(OpNum);
993 const MCOperand &MO2 = MI->getOperand(OpNum+1);
994
995 O << "[" << getRegisterName(MO1.getReg());
996 if (MO2.getImm())
997 O << ", #" << MO2.getImm() * 4;
998 O << "]";
999}
1000
Johnny Chen8f3004c2010-03-17 17:52:21 +00001001void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +00001002 unsigned OpNum,
1003 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +00001004 const MCOperand &MO1 = MI->getOperand(OpNum);
1005 int32_t OffImm = (int32_t)MO1.getImm();
1006 // Don't print +0.
1007 if (OffImm < 0)
Owen Anderson737beaf2011-09-23 21:26:40 +00001008 O << ", #-" << -OffImm;
1009 else
1010 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +00001011}
1012
1013void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +00001014 unsigned OpNum,
1015 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +00001016 const MCOperand &MO1 = MI->getOperand(OpNum);
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001017 int32_t OffImm = (int32_t)MO1.getImm();
1018
1019 assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
1020
Johnny Chen8f3004c2010-03-17 17:52:21 +00001021 // Don't print +0.
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001022 if (OffImm == INT32_MIN)
1023 O << ", #-0";
1024 else if (OffImm < 0)
1025 O << ", #-" << -OffImm;
1026 else if (OffImm > 0)
1027 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +00001028}
1029
1030void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +00001031 unsigned OpNum,
1032 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +00001033 const MCOperand &MO1 = MI->getOperand(OpNum);
1034 const MCOperand &MO2 = MI->getOperand(OpNum+1);
1035 const MCOperand &MO3 = MI->getOperand(OpNum+2);
1036
1037 O << "[" << getRegisterName(MO1.getReg());
1038
1039 assert(MO2.getReg() && "Invalid so_reg load / store address!");
1040 O << ", " << getRegisterName(MO2.getReg());
1041
1042 unsigned ShAmt = MO3.getImm();
1043 if (ShAmt) {
1044 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
1045 O << ", lsl #" << ShAmt;
1046 }
1047 O << "]";
1048}
1049
Jim Grosbachefc761a2011-09-30 00:50:06 +00001050void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
1051 raw_ostream &O) {
Bill Wendling5a13d4f2011-01-26 20:57:43 +00001052 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbachefc761a2011-09-30 00:50:06 +00001053 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +00001054}
1055
Bob Wilson6eae5202010-06-11 21:34:50 +00001056void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
1057 raw_ostream &O) {
Bob Wilsonc1c6f472010-07-13 04:44:34 +00001058 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
1059 unsigned EltBits;
1060 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Benjamin Kramer69d57cf2011-11-07 21:00:59 +00001061 O << "#0x";
1062 O.write_hex(Val);
Johnny Chenb90b6f12010-04-16 22:40:20 +00001063}
Jim Grosbach801e0a32011-07-22 23:16:18 +00001064
Jim Grosbach475c6db2011-07-25 23:09:14 +00001065void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
1066 raw_ostream &O) {
Jim Grosbach801e0a32011-07-22 23:16:18 +00001067 unsigned Imm = MI->getOperand(OpNum).getImm();
1068 O << "#" << Imm + 1;
1069}
Jim Grosbachd2659132011-07-26 21:28:43 +00001070
1071void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
1072 raw_ostream &O) {
1073 unsigned Imm = MI->getOperand(OpNum).getImm();
1074 if (Imm == 0)
1075 return;
Jim Grosbacha5f7a8c2011-07-26 21:44:37 +00001076 O << ", ror #";
Jim Grosbachd2659132011-07-26 21:28:43 +00001077 switch (Imm) {
1078 default: assert (0 && "illegal ror immediate!");
Jim Grosbach50aafea2011-08-17 23:23:07 +00001079 case 1: O << "8"; break;
1080 case 2: O << "16"; break;
1081 case 3: O << "24"; break;
Jim Grosbachd2659132011-07-26 21:28:43 +00001082 }
1083}
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001084
Jim Grosbachea231912011-12-22 22:19:05 +00001085void ARMInstPrinter::printFBits16(const MCInst *MI, unsigned OpNum,
1086 raw_ostream &O) {
1087 O << "#" << 16 - MI->getOperand(OpNum).getImm();
1088}
1089
1090void ARMInstPrinter::printFBits32(const MCInst *MI, unsigned OpNum,
1091 raw_ostream &O) {
1092 O << "#" << 32 - MI->getOperand(OpNum).getImm();
1093}
1094
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001095void ARMInstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
1096 raw_ostream &O) {
1097 O << "[" << MI->getOperand(OpNum).getImm() << "]";
1098}
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001099
1100void ARMInstPrinter::printVectorListOne(const MCInst *MI, unsigned OpNum,
1101 raw_ostream &O) {
1102 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "}";
1103}
Jim Grosbach2f2e3c42011-10-21 18:54:25 +00001104
Jim Grosbach13a292c2012-03-06 22:01:44 +00001105void ARMInstPrinter::printVectorListTwo(const MCInst *MI, unsigned OpNum,
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001106 raw_ostream &O) {
1107 unsigned Reg = MI->getOperand(OpNum).getReg();
1108 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1109 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_1);
1110 O << "{" << getRegisterName(Reg0) << ", " << getRegisterName(Reg1) << "}";
1111}
1112
Jim Grosbach13a292c2012-03-06 22:01:44 +00001113void ARMInstPrinter::printVectorListTwoSpaced(const MCInst *MI,
1114 unsigned OpNum,
1115 raw_ostream &O) {
Jim Grosbache5307f92012-03-05 21:43:40 +00001116 unsigned Reg = MI->getOperand(OpNum).getReg();
1117 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1118 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_2);
1119 O << "{" << getRegisterName(Reg0) << ", " << getRegisterName(Reg1) << "}";
1120}
1121
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001122void ARMInstPrinter::printVectorListThree(const MCInst *MI, unsigned OpNum,
1123 raw_ostream &O) {
1124 // Normally, it's not safe to use register enum values directly with
1125 // addition to get the next register, but for VFP registers, the
1126 // sort order is guaranteed because they're all of the form D<n>.
1127 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1128 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1129 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1130}
Jim Grosbach846bcff2011-10-21 20:35:01 +00001131
1132void ARMInstPrinter::printVectorListFour(const MCInst *MI, unsigned OpNum,
1133 raw_ostream &O) {
1134 // Normally, it's not safe to use register enum values directly with
1135 // addition to get the next register, but for VFP registers, the
1136 // sort order is guaranteed because they're all of the form D<n>.
1137 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1138 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1139 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1140 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "}";
1141}
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001142
1143void ARMInstPrinter::printVectorListOneAllLanes(const MCInst *MI,
1144 unsigned OpNum,
1145 raw_ostream &O) {
1146 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[]}";
1147}
1148
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001149void ARMInstPrinter::printVectorListTwoAllLanes(const MCInst *MI,
1150 unsigned OpNum,
1151 raw_ostream &O) {
Jim Grosbach13a292c2012-03-06 22:01:44 +00001152 unsigned Reg = MI->getOperand(OpNum).getReg();
1153 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1154 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_1);
1155 O << "{" << getRegisterName(Reg0) << "[], " << getRegisterName(Reg1) << "[]}";
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001156}
Jim Grosbach8d246182011-12-14 19:35:22 +00001157
Jim Grosbachb78403c2012-01-24 23:47:04 +00001158void ARMInstPrinter::printVectorListThreeAllLanes(const MCInst *MI,
1159 unsigned OpNum,
1160 raw_ostream &O) {
1161 // Normally, it's not safe to use register enum values directly with
1162 // addition to get the next register, but for VFP registers, the
1163 // sort order is guaranteed because they're all of the form D<n>.
1164 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1165 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1166 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[]}";
1167}
1168
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001169void ARMInstPrinter::printVectorListFourAllLanes(const MCInst *MI,
1170 unsigned OpNum,
1171 raw_ostream &O) {
1172 // Normally, it's not safe to use register enum values directly with
1173 // addition to get the next register, but for VFP registers, the
1174 // sort order is guaranteed because they're all of the form D<n>.
1175 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1176 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1177 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1178 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "[]}";
1179}
1180
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001181void ARMInstPrinter::printVectorListTwoSpacedAllLanes(const MCInst *MI,
1182 unsigned OpNum,
1183 raw_ostream &O) {
Jim Grosbached428bc2012-03-06 23:10:38 +00001184 unsigned Reg = MI->getOperand(OpNum).getReg();
1185 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1186 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_2);
1187 O << "{" << getRegisterName(Reg0) << "[], " << getRegisterName(Reg1) << "[]}";
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001188}
1189
Jim Grosbachb78403c2012-01-24 23:47:04 +00001190void ARMInstPrinter::printVectorListThreeSpacedAllLanes(const MCInst *MI,
1191 unsigned OpNum,
1192 raw_ostream &O) {
1193 // Normally, it's not safe to use register enum values directly with
1194 // addition to get the next register, but for VFP registers, the
1195 // sort order is guaranteed because they're all of the form D<n>.
1196 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1197 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001198 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[]}";
1199}
1200
1201void ARMInstPrinter::printVectorListFourSpacedAllLanes(const MCInst *MI,
1202 unsigned OpNum,
1203 raw_ostream &O) {
1204 // Normally, it's not safe to use register enum values directly with
1205 // addition to get the next register, but for VFP registers, the
1206 // sort order is guaranteed because they're all of the form D<n>.
1207 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1208 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1209 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[], "
1210 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "[]}";
Jim Grosbachb78403c2012-01-24 23:47:04 +00001211}
1212
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001213void ARMInstPrinter::printVectorListThreeSpaced(const MCInst *MI,
1214 unsigned OpNum,
1215 raw_ostream &O) {
1216 // Normally, it's not safe to use register enum values directly with
1217 // addition to get the next register, but for VFP registers, the
1218 // sort order is guaranteed because they're all of the form D<n>.
1219 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1220 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1221 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "}";
1222}
Jim Grosbached561fc2012-01-24 00:43:17 +00001223
1224void ARMInstPrinter::printVectorListFourSpaced(const MCInst *MI,
1225 unsigned OpNum,
1226 raw_ostream &O) {
1227 // Normally, it's not safe to use register enum values directly with
1228 // addition to get the next register, but for VFP registers, the
1229 // sort order is guaranteed because they're all of the form D<n>.
1230 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1231 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1232 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << ", "
1233 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "}";
1234}