blob: 88798716cd15339f3ebe252d4f3cae0fc55e32bf [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) {
Tim Northover0c97e762012-09-22 11:18:12 +000032 // lsr #32 and asr #32 exist, but should be encoded as a 0.
33 assert((imm & ~0x1f) == 0 && "Invalid shift encoding");
34
Owen Andersone33c95d2011-08-11 18:41:59 +000035 if (imm == 0)
36 return 32;
37 return imm;
38}
39
Tim Northover0c97e762012-09-22 11:18:12 +000040/// Prints the shift value with an immediate value.
41static void printRegImmShift(raw_ostream &O, ARM_AM::ShiftOpc ShOpc,
42 unsigned ShImm) {
43 if (ShOpc == ARM_AM::no_shift || (ShOpc == ARM_AM::lsl && !ShImm))
44 return;
45 O << ", ";
46
47 assert (!(ShOpc == ARM_AM::ror && !ShImm) && "Cannot have ror #0");
48 O << getShiftOpcStr(ShOpc);
49
50 if (ShOpc != ARM_AM::rrx)
51 O << " #" << translateShiftImm(ShImm);
52}
James Molloy4c493e82011-09-07 17:24:38 +000053
54ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
Craig Topper54bfde72012-04-02 06:09:36 +000055 const MCInstrInfo &MII,
Jim Grosbachfd93a592012-03-05 19:33:20 +000056 const MCRegisterInfo &MRI,
James Molloy4c493e82011-09-07 17:24:38 +000057 const MCSubtargetInfo &STI) :
Craig Topper54bfde72012-04-02 06:09:36 +000058 MCInstPrinter(MAI, MII, MRI) {
James Molloy4c493e82011-09-07 17:24:38 +000059 // Initialize the set of available features.
60 setAvailableFeatures(STI.getFeatureBits());
61}
62
Rafael Espindolad6860522011-06-02 02:34:55 +000063void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
64 OS << getRegisterName(RegNo);
Anton Korobeynikove7410dd2011-03-05 18:43:32 +000065}
Chris Lattnerf20f7982010-10-28 21:37:33 +000066
Owen Andersona0c3b972011-09-15 23:38:46 +000067void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
68 StringRef Annot) {
Bill Wendlingf2fa04a2010-11-13 10:40:19 +000069 unsigned Opcode = MI->getOpcode();
70
Jim Grosbachcb540f52012-06-18 19:45:50 +000071 // Check for HINT instructions w/ canonical names.
72 if (Opcode == ARM::HINT || Opcode == ARM::t2HINT) {
73 switch (MI->getOperand(0).getImm()) {
74 case 0: O << "\tnop"; break;
75 case 1: O << "\tyield"; break;
76 case 2: O << "\twfe"; break;
77 case 3: O << "\twfi"; break;
78 case 4: O << "\tsev"; break;
79 default:
80 // Anything else should just print normally.
81 printInstruction(MI, O);
82 printAnnotation(O, Annot);
83 return;
84 }
85 printPredicateOperand(MI, 1, O);
86 if (Opcode == ARM::t2HINT)
87 O << ".w";
88 printAnnotation(O, Annot);
89 return;
90 }
91
Johnny Chen8f3004c2010-03-17 17:52:21 +000092 // Check for MOVs and print canonical forms, instead.
Owen Anderson04912702011-07-21 23:38:37 +000093 if (Opcode == ARM::MOVsr) {
Jim Grosbach7a6c37d2010-09-17 22:36:38 +000094 // FIXME: Thumb variants?
Johnny Chen8f3004c2010-03-17 17:52:21 +000095 const MCOperand &Dst = MI->getOperand(0);
96 const MCOperand &MO1 = MI->getOperand(1);
97 const MCOperand &MO2 = MI->getOperand(2);
98 const MCOperand &MO3 = MI->getOperand(3);
99
100 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner76c564b2010-04-04 04:47:45 +0000101 printSBitModifierOperand(MI, 6, O);
102 printPredicateOperand(MI, 4, O);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000103
104 O << '\t' << getRegisterName(Dst.getReg())
105 << ", " << getRegisterName(MO1.getReg());
106
Owen Anderson04912702011-07-21 23:38:37 +0000107 O << ", " << getRegisterName(MO2.getReg());
108 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000109 printAnnotation(O, Annot);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000110 return;
111 }
112
Owen Anderson04912702011-07-21 23:38:37 +0000113 if (Opcode == ARM::MOVsi) {
114 // FIXME: Thumb variants?
115 const MCOperand &Dst = MI->getOperand(0);
116 const MCOperand &MO1 = MI->getOperand(1);
117 const MCOperand &MO2 = MI->getOperand(2);
118
119 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
120 printSBitModifierOperand(MI, 5, O);
121 printPredicateOperand(MI, 3, O);
122
123 O << '\t' << getRegisterName(Dst.getReg())
124 << ", " << getRegisterName(MO1.getReg());
125
Owen Andersond1814792011-09-15 18:36:29 +0000126 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000127 printAnnotation(O, Annot);
Owen Anderson04912702011-07-21 23:38:37 +0000128 return;
Owen Andersond1814792011-09-15 18:36:29 +0000129 }
Owen Anderson04912702011-07-21 23:38:37 +0000130
Owen Andersone33c95d2011-08-11 18:41:59 +0000131 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000132 printAnnotation(O, Annot);
Owen Anderson04912702011-07-21 23:38:37 +0000133 return;
134 }
135
136
Johnny Chen8f3004c2010-03-17 17:52:21 +0000137 // A8.6.123 PUSH
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000138 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Owen Andersonfbb704f2011-11-02 18:03:14 +0000139 MI->getOperand(0).getReg() == ARM::SP &&
140 MI->getNumOperands() > 5) {
141 // Should only print PUSH if there are at least two registers in the list.
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000142 O << '\t' << "push";
143 printPredicateOperand(MI, 2, O);
Jim Grosbachca7eaaa2010-12-03 20:33:01 +0000144 if (Opcode == ARM::t2STMDB_UPD)
145 O << ".w";
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000146 O << '\t';
147 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000148 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000149 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000150 }
Jim Grosbach27ad83d2011-08-11 18:07:11 +0000151 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
152 MI->getOperand(3).getImm() == -4) {
153 O << '\t' << "push";
154 printPredicateOperand(MI, 4, O);
155 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000156 printAnnotation(O, Annot);
Jim Grosbach27ad83d2011-08-11 18:07:11 +0000157 return;
158 }
Johnny Chen8f3004c2010-03-17 17:52:21 +0000159
160 // A8.6.122 POP
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000161 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Owen Andersonfbb704f2011-11-02 18:03:14 +0000162 MI->getOperand(0).getReg() == ARM::SP &&
163 MI->getNumOperands() > 5) {
164 // Should only print POP if there are at least two registers in the list.
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000165 O << '\t' << "pop";
166 printPredicateOperand(MI, 2, O);
Jim Grosbachca7eaaa2010-12-03 20:33:01 +0000167 if (Opcode == ARM::t2LDMIA_UPD)
168 O << ".w";
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000169 O << '\t';
170 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000171 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000172 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000173 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000174 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
175 MI->getOperand(4).getImm() == 4) {
176 O << '\t' << "pop";
177 printPredicateOperand(MI, 5, O);
178 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000179 printAnnotation(O, Annot);
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000180 return;
181 }
182
Johnny Chen8f3004c2010-03-17 17:52:21 +0000183
184 // A8.6.355 VPUSH
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000185 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen8f3004c2010-03-17 17:52:21 +0000186 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000187 O << '\t' << "vpush";
188 printPredicateOperand(MI, 2, O);
189 O << '\t';
190 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000191 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000192 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000193 }
194
195 // A8.6.354 VPOP
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000196 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen8f3004c2010-03-17 17:52:21 +0000197 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000198 O << '\t' << "vpop";
199 printPredicateOperand(MI, 2, O);
200 O << '\t';
201 printRegisterList(MI, 4, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000202 printAnnotation(O, Annot);
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000203 return;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000204 }
205
Jim Grosbache364ad52011-08-23 17:41:15 +0000206 if (Opcode == ARM::tLDMIA) {
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000207 bool Writeback = true;
208 unsigned BaseReg = MI->getOperand(0).getReg();
209 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
210 if (MI->getOperand(i).getReg() == BaseReg)
211 Writeback = false;
212 }
213
Jim Grosbache364ad52011-08-23 17:41:15 +0000214 O << "\tldm";
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000215
216 printPredicateOperand(MI, 1, O);
217 O << '\t' << getRegisterName(BaseReg);
218 if (Writeback) O << "!";
219 O << ", ";
220 printRegisterList(MI, 3, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000221 printAnnotation(O, Annot);
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000222 return;
223 }
224
Jim Grosbach25977222011-08-19 23:24:36 +0000225 // Thumb1 NOP
226 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
227 MI->getOperand(1).getReg() == ARM::R8) {
228 O << "\tnop";
Jim Grosbachaf2f8272011-08-24 20:06:14 +0000229 printPredicateOperand(MI, 2, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000230 printAnnotation(O, Annot);
Jim Grosbach25977222011-08-19 23:24:36 +0000231 return;
232 }
233
Chris Lattner76c564b2010-04-04 04:47:45 +0000234 printInstruction(MI, O);
Owen Andersonbcc3fad2011-09-21 17:58:45 +0000235 printAnnotation(O, Annot);
Bill Wendlingf2fa04a2010-11-13 10:40:19 +0000236}
Chris Lattnera2907782009-10-19 19:56:26 +0000237
Chris Lattner93e3ef62009-10-19 20:59:55 +0000238void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000239 raw_ostream &O) {
Chris Lattner93e3ef62009-10-19 20:59:55 +0000240 const MCOperand &Op = MI->getOperand(OpNo);
241 if (Op.isReg()) {
Chris Lattner60d51312009-10-20 06:15:28 +0000242 unsigned Reg = Op.getReg();
Jim Grosbach2c950272010-10-06 21:22:32 +0000243 O << getRegisterName(Reg);
Chris Lattner93e3ef62009-10-19 20:59:55 +0000244 } else if (Op.isImm()) {
245 O << '#' << Op.getImm();
246 } else {
247 assert(Op.isExpr() && "unknown operand kind in printOperand");
Kevin Enderby5dcda642011-10-04 22:44:48 +0000248 // If a symbolic branch target was added as a constant expression then print
Kevin Enderbyc407cc72012-04-13 18:46:37 +0000249 // that address in hex. And only print 32 unsigned bits for the address.
Kevin Enderby5dcda642011-10-04 22:44:48 +0000250 const MCConstantExpr *BranchTarget = dyn_cast<MCConstantExpr>(Op.getExpr());
251 int64_t Address;
252 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
253 O << "0x";
Kevin Enderbyc407cc72012-04-13 18:46:37 +0000254 O.write_hex((uint32_t)Address);
Kevin Enderby5dcda642011-10-04 22:44:48 +0000255 }
256 else {
257 // Otherwise, just print the expression.
258 O << *Op.getExpr();
259 }
Chris Lattner93e3ef62009-10-19 20:59:55 +0000260 }
261}
Chris Lattner89d47202009-10-19 21:21:39 +0000262
Owen Andersonf52c68f2011-09-21 23:44:46 +0000263void ARMInstPrinter::printT2LdrLabelOperand(const MCInst *MI, unsigned OpNum,
264 raw_ostream &O) {
265 const MCOperand &MO1 = MI->getOperand(OpNum);
266 if (MO1.isExpr())
267 O << *MO1.getExpr();
268 else if (MO1.isImm())
269 O << "[pc, #" << MO1.getImm() << "]";
270 else
271 llvm_unreachable("Unknown LDR label operand?");
272}
273
Chris Lattner2f69ed82009-10-20 00:40:56 +0000274// so_reg is a 4-operand unit corresponding to register forms of the A5.1
275// "Addressing Mode 1 - Data-processing operands" forms. This includes:
276// REG 0 0 - e.g. R5
277// REG REG 0,SH_OPC - e.g. R5, ROR R3
278// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson04912702011-07-21 23:38:37 +0000279void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner76c564b2010-04-04 04:47:45 +0000280 raw_ostream &O) {
Chris Lattner2f69ed82009-10-20 00:40:56 +0000281 const MCOperand &MO1 = MI->getOperand(OpNum);
282 const MCOperand &MO2 = MI->getOperand(OpNum+1);
283 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000284
Chris Lattner2f69ed82009-10-20 00:40:56 +0000285 O << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000286
Chris Lattner2f69ed82009-10-20 00:40:56 +0000287 // Print the shift opc.
Bob Wilson97886d52010-08-05 00:34:42 +0000288 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
289 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000290 if (ShOpc == ARM_AM::rrx)
291 return;
Jim Grosbach20cb5052011-10-21 16:56:40 +0000292
Owen Anderson04912702011-07-21 23:38:37 +0000293 O << ' ' << getRegisterName(MO2.getReg());
294 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner2f69ed82009-10-20 00:40:56 +0000295}
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000296
Owen Anderson04912702011-07-21 23:38:37 +0000297void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
298 raw_ostream &O) {
299 const MCOperand &MO1 = MI->getOperand(OpNum);
300 const MCOperand &MO2 = MI->getOperand(OpNum+1);
301
302 O << getRegisterName(MO1.getReg());
303
304 // Print the shift opc.
Tim Northover2fdbdc52012-09-22 11:18:19 +0000305 printRegImmShift(O, ARM_AM::getSORegShOp(MO2.getImm()),
306 ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson04912702011-07-21 23:38:37 +0000307}
308
309
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000310//===--------------------------------------------------------------------===//
311// Addressing Mode #2
312//===--------------------------------------------------------------------===//
313
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000314void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
315 raw_ostream &O) {
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000316 const MCOperand &MO1 = MI->getOperand(Op);
317 const MCOperand &MO2 = MI->getOperand(Op+1);
318 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000319
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000320 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000321
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000322 if (!MO2.getReg()) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000323 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000324 O << ", #"
Johnny Chen8f3004c2010-03-17 17:52:21 +0000325 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
326 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000327 O << "]";
328 return;
329 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000330
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000331 O << ", "
Johnny Chen8f3004c2010-03-17 17:52:21 +0000332 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
333 << getRegisterName(MO2.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000334
Tim Northover0c97e762012-09-22 11:18:12 +0000335 printRegImmShift(O, ARM_AM::getAM2ShiftOpc(MO3.getImm()),
336 ARM_AM::getAM2Offset(MO3.getImm()));
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000337 O << "]";
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000338}
Chris Lattneref2979b2009-10-19 22:09:23 +0000339
Jim Grosbach05541f42011-09-19 22:21:13 +0000340void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
341 raw_ostream &O) {
342 const MCOperand &MO1 = MI->getOperand(Op);
343 const MCOperand &MO2 = MI->getOperand(Op+1);
344 O << "[" << getRegisterName(MO1.getReg()) << ", "
345 << getRegisterName(MO2.getReg()) << "]";
346}
347
348void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
349 raw_ostream &O) {
350 const MCOperand &MO1 = MI->getOperand(Op);
351 const MCOperand &MO2 = MI->getOperand(Op+1);
352 O << "[" << getRegisterName(MO1.getReg()) << ", "
353 << getRegisterName(MO2.getReg()) << ", lsl #1]";
354}
355
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000356void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
357 raw_ostream &O) {
358 const MCOperand &MO1 = MI->getOperand(Op);
359
360 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
361 printOperand(MI, Op, O);
362 return;
363 }
364
365 const MCOperand &MO3 = MI->getOperand(Op+2);
366 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
Tim Northover2fdbdc52012-09-22 11:18:19 +0000367 assert(IdxMode != ARMII::IndexModePost &&
368 "Should be pre or offset index op");
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000369
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000370 printAM2PreOrOffsetIndexOp(MI, Op, O);
371}
372
Chris Lattner60d51312009-10-20 06:15:28 +0000373void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000374 unsigned OpNum,
375 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000376 const MCOperand &MO1 = MI->getOperand(OpNum);
377 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000378
Chris Lattner60d51312009-10-20 06:15:28 +0000379 if (!MO1.getReg()) {
380 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +0000381 O << '#'
382 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
383 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000384 return;
385 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000386
Johnny Chen8f3004c2010-03-17 17:52:21 +0000387 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
388 << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000389
Tim Northover0c97e762012-09-22 11:18:12 +0000390 printRegImmShift(O, ARM_AM::getAM2ShiftOpc(MO2.getImm()),
391 ARM_AM::getAM2Offset(MO2.getImm()));
Chris Lattner60d51312009-10-20 06:15:28 +0000392}
393
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000394//===--------------------------------------------------------------------===//
395// Addressing Mode #3
396//===--------------------------------------------------------------------===//
397
398void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
399 raw_ostream &O) {
400 const MCOperand &MO1 = MI->getOperand(Op);
401 const MCOperand &MO2 = MI->getOperand(Op+1);
402 const MCOperand &MO3 = MI->getOperand(Op+2);
403
404 O << "[" << getRegisterName(MO1.getReg()) << "], ";
405
406 if (MO2.getReg()) {
407 O << (char)ARM_AM::getAM3Op(MO3.getImm())
408 << getRegisterName(MO2.getReg());
409 return;
410 }
411
412 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
413 O << '#'
414 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
415 << ImmOffs;
416}
417
418void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
419 raw_ostream &O) {
420 const MCOperand &MO1 = MI->getOperand(Op);
421 const MCOperand &MO2 = MI->getOperand(Op+1);
422 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000423
Chris Lattner60d51312009-10-20 06:15:28 +0000424 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000425
Chris Lattner60d51312009-10-20 06:15:28 +0000426 if (MO2.getReg()) {
Jim Grosbachd3595712011-08-03 23:50:40 +0000427 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattner60d51312009-10-20 06:15:28 +0000428 << getRegisterName(MO2.getReg()) << ']';
429 return;
430 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000431
Silviu Baranga5a719f92012-05-11 09:10:54 +0000432 //If the op is sub we have to print the immediate even if it is 0
433 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
434 ARM_AM::AddrOpc op = ARM_AM::getAM3Op(MO3.getImm());
435
436 if (ImmOffs || (op == ARM_AM::sub))
Chris Lattner60d51312009-10-20 06:15:28 +0000437 O << ", #"
Silviu Baranga5a719f92012-05-11 09:10:54 +0000438 << ARM_AM::getAddrOpcStr(op)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000439 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000440 O << ']';
441}
442
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000443void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
444 raw_ostream &O) {
Jim Grosbach8648c102011-12-19 23:06:24 +0000445 const MCOperand &MO1 = MI->getOperand(Op);
446 if (!MO1.isReg()) { // For label symbolic references.
447 printOperand(MI, Op, O);
448 return;
449 }
450
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000451 const MCOperand &MO3 = MI->getOperand(Op+2);
452 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
453
454 if (IdxMode == ARMII::IndexModePost) {
455 printAM3PostIndexOp(MI, Op, O);
456 return;
457 }
458 printAM3PreOrOffsetIndexOp(MI, Op, O);
459}
460
Chris Lattner60d51312009-10-20 06:15:28 +0000461void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000462 unsigned OpNum,
463 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000464 const MCOperand &MO1 = MI->getOperand(OpNum);
465 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000466
Chris Lattner60d51312009-10-20 06:15:28 +0000467 if (MO1.getReg()) {
Jim Grosbachd3595712011-08-03 23:50:40 +0000468 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
469 << getRegisterName(MO1.getReg());
Chris Lattner60d51312009-10-20 06:15:28 +0000470 return;
471 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000472
Chris Lattner60d51312009-10-20 06:15:28 +0000473 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +0000474 O << '#'
475 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
476 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000477}
478
Jim Grosbachd3595712011-08-03 23:50:40 +0000479void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
480 unsigned OpNum,
481 raw_ostream &O) {
482 const MCOperand &MO = MI->getOperand(OpNum);
483 unsigned Imm = MO.getImm();
484 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
485}
486
Jim Grosbachbafce842011-08-05 15:48:21 +0000487void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
488 raw_ostream &O) {
489 const MCOperand &MO1 = MI->getOperand(OpNum);
490 const MCOperand &MO2 = MI->getOperand(OpNum+1);
491
Jim Grosbacha70fbfd52011-08-05 16:11:38 +0000492 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachbafce842011-08-05 15:48:21 +0000493}
494
Owen Andersonce519032011-08-04 18:24:14 +0000495void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
496 unsigned OpNum,
497 raw_ostream &O) {
498 const MCOperand &MO = MI->getOperand(OpNum);
499 unsigned Imm = MO.getImm();
500 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
501}
502
503
Jim Grosbachc6af2b42010-11-03 01:01:43 +0000504void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000505 raw_ostream &O) {
Jim Grosbachc6af2b42010-11-03 01:01:43 +0000506 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
507 .getImm());
508 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattneref2979b2009-10-19 22:09:23 +0000509}
510
Chris Lattner60d51312009-10-20 06:15:28 +0000511void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000512 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000513 const MCOperand &MO1 = MI->getOperand(OpNum);
514 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000515
Chris Lattner60d51312009-10-20 06:15:28 +0000516 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner76c564b2010-04-04 04:47:45 +0000517 printOperand(MI, OpNum, O);
Chris Lattner60d51312009-10-20 06:15:28 +0000518 return;
519 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000520
Chris Lattner60d51312009-10-20 06:15:28 +0000521 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000522
Owen Anderson967674d2011-08-29 19:36:44 +0000523 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
524 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
525 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattner60d51312009-10-20 06:15:28 +0000526 O << ", #"
Johnny Chen8f3004c2010-03-17 17:52:21 +0000527 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendlinge84eb992010-11-03 01:49:29 +0000528 << ImmOffs * 4;
Chris Lattner60d51312009-10-20 06:15:28 +0000529 }
530 O << "]";
531}
532
Chris Lattner76c564b2010-04-04 04:47:45 +0000533void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
534 raw_ostream &O) {
Chris Lattner9351e4f2009-10-20 06:22:33 +0000535 const MCOperand &MO1 = MI->getOperand(OpNum);
536 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000537
Bob Wilsonae08a732010-03-20 22:13:40 +0000538 O << "[" << getRegisterName(MO1.getReg());
539 if (MO2.getImm()) {
540 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson0b9aafd2010-07-14 23:54:43 +0000541 O << ", :" << (MO2.getImm() << 3);
Chris Lattner9351e4f2009-10-20 06:22:33 +0000542 }
Bob Wilsonae08a732010-03-20 22:13:40 +0000543 O << "]";
544}
545
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +0000546void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
547 raw_ostream &O) {
548 const MCOperand &MO1 = MI->getOperand(OpNum);
549 O << "[" << getRegisterName(MO1.getReg()) << "]";
550}
551
Bob Wilsonae08a732010-03-20 22:13:40 +0000552void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000553 unsigned OpNum,
554 raw_ostream &O) {
Bob Wilsonae08a732010-03-20 22:13:40 +0000555 const MCOperand &MO = MI->getOperand(OpNum);
556 if (MO.getReg() == 0)
557 O << "!";
558 else
559 O << ", " << getRegisterName(MO.getReg());
Chris Lattner9351e4f2009-10-20 06:22:33 +0000560}
561
Bob Wilsonadd513112010-08-11 23:10:46 +0000562void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
563 unsigned OpNum,
564 raw_ostream &O) {
Chris Lattner9351e4f2009-10-20 06:22:33 +0000565 const MCOperand &MO = MI->getOperand(OpNum);
566 uint32_t v = ~MO.getImm();
567 int32_t lsb = CountTrailingZeros_32(v);
568 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
569 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
570 O << '#' << lsb << ", #" << width;
571}
Chris Lattner60d51312009-10-20 06:15:28 +0000572
Johnny Chen8e8f1c12010-08-12 20:46:17 +0000573void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
574 raw_ostream &O) {
575 unsigned val = MI->getOperand(OpNum).getImm();
576 O << ARM_MB::MemBOptToString(val);
577}
578
Bob Wilson481d7a92010-08-16 18:27:34 +0000579void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsonadd513112010-08-11 23:10:46 +0000580 raw_ostream &O) {
581 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000582 bool isASR = (ShiftOp & (1 << 5)) != 0;
583 unsigned Amt = ShiftOp & 0x1f;
584 if (isASR)
585 O << ", asr #" << (Amt == 0 ? 32 : Amt);
586 else if (Amt)
587 O << ", lsl #" << Amt;
Bob Wilsonadd513112010-08-11 23:10:46 +0000588}
589
Jim Grosbacha288b1c2011-07-20 21:40:26 +0000590void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
591 raw_ostream &O) {
592 unsigned Imm = MI->getOperand(OpNum).getImm();
593 if (Imm == 0)
594 return;
595 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
596 O << ", lsl #" << Imm;
597}
598
599void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
600 raw_ostream &O) {
601 unsigned Imm = MI->getOperand(OpNum).getImm();
602 // A shift amount of 32 is encoded as 0.
603 if (Imm == 0)
604 Imm = 32;
605 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
606 O << ", asr #" << Imm;
607}
608
Chris Lattner76c564b2010-04-04 04:47:45 +0000609void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
610 raw_ostream &O) {
Chris Lattneref2979b2009-10-19 22:09:23 +0000611 O << "{";
Johnny Chen8f3004c2010-03-17 17:52:21 +0000612 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
613 if (i != OpNum) O << ", ";
Chris Lattneref2979b2009-10-19 22:09:23 +0000614 O << getRegisterName(MI->getOperand(i).getReg());
615 }
616 O << "}";
617}
Chris Lattneradd57492009-10-19 22:23:04 +0000618
Jim Grosbach7e72ec62010-10-13 21:00:04 +0000619void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
620 raw_ostream &O) {
621 const MCOperand &Op = MI->getOperand(OpNum);
622 if (Op.getImm())
623 O << "be";
624 else
625 O << "le";
626}
627
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000628void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
629 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000630 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000631 O << ARM_PROC::IModToString(Op.getImm());
632}
633
634void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
635 raw_ostream &O) {
636 const MCOperand &Op = MI->getOperand(OpNum);
637 unsigned IFlags = Op.getImm();
638 for (int i=2; i >= 0; --i)
639 if (IFlags & (1 << i))
640 O << ARM_PROC::IFlagsToString(1 << i);
Owen Anderson10c5b122011-10-05 17:16:40 +0000641
642 if (IFlags == 0)
643 O << "none";
Johnny Chen8f3004c2010-03-17 17:52:21 +0000644}
645
Chris Lattner76c564b2010-04-04 04:47:45 +0000646void ARMInstPrinter::printMSRMaskOperand(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 Lopes9cd43972011-02-18 19:45:59 +0000649 unsigned SpecRegRBit = Op.getImm() >> 4;
650 unsigned Mask = Op.getImm() & 0xf;
651
James Molloy21efa7d2011-09-28 14:21:38 +0000652 if (getAvailableFeatures() & ARM::FeatureMClass) {
Kevin Enderbyf1b225d2012-05-17 22:18:01 +0000653 unsigned SYSm = Op.getImm();
654 unsigned Opcode = MI->getOpcode();
655 // For reads of the special registers ignore the "mask encoding" bits
656 // which are only for writes.
657 if (Opcode == ARM::t2MRS_M)
658 SYSm &= 0xff;
659 switch (SYSm) {
Craig Toppere55c5562012-02-07 02:50:20 +0000660 default: llvm_unreachable("Unexpected mask value!");
Kevin Enderbyf1b225d2012-05-17 22:18:01 +0000661 case 0:
662 case 0x800: O << "apsr"; return; // with _nzcvq bits is an alias for aspr
663 case 0x400: O << "apsr_g"; return;
664 case 0xc00: O << "apsr_nzcvqg"; return;
665 case 1:
666 case 0x801: O << "iapsr"; return; // with _nzcvq bits is an alias for iapsr
667 case 0x401: O << "iapsr_g"; return;
668 case 0xc01: O << "iapsr_nzcvqg"; return;
669 case 2:
670 case 0x802: O << "eapsr"; return; // with _nzcvq bits is an alias for eapsr
671 case 0x402: O << "eapsr_g"; return;
672 case 0xc02: O << "eapsr_nzcvqg"; return;
673 case 3:
674 case 0x803: O << "xpsr"; return; // with _nzcvq bits is an alias for xpsr
675 case 0x403: O << "xpsr_g"; return;
676 case 0xc03: O << "xpsr_nzcvqg"; return;
Kevin Enderby6c7279e2012-06-15 22:14:44 +0000677 case 5:
678 case 0x805: O << "ipsr"; return;
679 case 6:
680 case 0x806: O << "epsr"; return;
681 case 7:
682 case 0x807: O << "iepsr"; return;
683 case 8:
684 case 0x808: O << "msp"; return;
685 case 9:
686 case 0x809: O << "psp"; return;
687 case 0x10:
688 case 0x810: O << "primask"; return;
689 case 0x11:
690 case 0x811: O << "basepri"; return;
691 case 0x12:
692 case 0x812: O << "basepri_max"; return;
693 case 0x13:
694 case 0x813: O << "faultmask"; return;
695 case 0x14:
696 case 0x814: O << "control"; return;
James Molloy21efa7d2011-09-28 14:21:38 +0000697 }
698 }
699
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000700 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
701 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
702 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
703 O << "APSR_";
704 switch (Mask) {
Craig Toppere55c5562012-02-07 02:50:20 +0000705 default: llvm_unreachable("Unexpected mask value!");
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000706 case 4: O << "g"; return;
707 case 8: O << "nzcvq"; return;
708 case 12: O << "nzcvqg"; return;
709 }
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000710 }
711
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000712 if (SpecRegRBit)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000713 O << "SPSR";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000714 else
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000715 O << "CPSR";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000716
Johnny Chen8f3004c2010-03-17 17:52:21 +0000717 if (Mask) {
718 O << '_';
719 if (Mask & 8) O << 'f';
720 if (Mask & 4) O << 's';
721 if (Mask & 2) O << 'x';
722 if (Mask & 1) O << 'c';
723 }
724}
725
Chris Lattner76c564b2010-04-04 04:47:45 +0000726void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
727 raw_ostream &O) {
Chris Lattner19c52202009-10-20 00:42:49 +0000728 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
Kevin Enderbyf0269b42012-03-01 22:13:02 +0000729 // Handle the undefined 15 CC value here for printing so we don't abort().
730 if ((unsigned)CC == 15)
731 O << "<und>";
732 else if (CC != ARMCC::AL)
Chris Lattner19c52202009-10-20 00:42:49 +0000733 O << ARMCondCodeToString(CC);
734}
735
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000736void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000737 unsigned OpNum,
738 raw_ostream &O) {
Johnny Chen0dae1cb2010-03-02 17:57:15 +0000739 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
740 O << ARMCondCodeToString(CC);
741}
742
Chris Lattner76c564b2010-04-04 04:47:45 +0000743void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
744 raw_ostream &O) {
Daniel Dunbara470eac2009-10-20 22:10:05 +0000745 if (MI->getOperand(OpNum).getReg()) {
746 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
747 "Expect ARM CPSR register!");
Chris Lattner85ab6702009-10-20 00:46:11 +0000748 O << 's';
749 }
750}
751
Chris Lattner76c564b2010-04-04 04:47:45 +0000752void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
753 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000754 O << MI->getOperand(OpNum).getImm();
755}
756
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000757void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbach69664112011-10-12 16:34:37 +0000758 raw_ostream &O) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000759 O << "p" << MI->getOperand(OpNum).getImm();
760}
761
762void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbach69664112011-10-12 16:34:37 +0000763 raw_ostream &O) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000764 O << "c" << MI->getOperand(OpNum).getImm();
765}
766
Jim Grosbach48399582011-10-12 17:34:41 +0000767void ARMInstPrinter::printCoprocOptionImm(const MCInst *MI, unsigned OpNum,
768 raw_ostream &O) {
769 O << "{" << MI->getOperand(OpNum).getImm() << "}";
770}
771
Chris Lattner76c564b2010-04-04 04:47:45 +0000772void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
773 raw_ostream &O) {
Jim Grosbach8a5a6a62010-09-18 00:04:53 +0000774 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattneradd57492009-10-19 22:23:04 +0000775}
Evan Chengb1852592009-11-19 06:57:41 +0000776
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000777void ARMInstPrinter::printAdrLabelOperand(const MCInst *MI, unsigned OpNum,
778 raw_ostream &O) {
779 const MCOperand &MO = MI->getOperand(OpNum);
780
781 if (MO.isExpr()) {
782 O << *MO.getExpr();
783 return;
784 }
785
786 int32_t OffImm = (int32_t)MO.getImm();
787
788 if (OffImm == INT32_MIN)
789 O << "#-0";
790 else if (OffImm < 0)
791 O << "#-" << -OffImm;
792 else
793 O << "#" << OffImm;
794}
795
Chris Lattner76c564b2010-04-04 04:47:45 +0000796void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
797 raw_ostream &O) {
Jim Grosbach46dd4132011-08-17 21:51:27 +0000798 O << "#" << MI->getOperand(OpNum).getImm() * 4;
799}
800
801void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
802 raw_ostream &O) {
803 unsigned Imm = MI->getOperand(OpNum).getImm();
804 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Chengb1852592009-11-19 06:57:41 +0000805}
Johnny Chen8f3004c2010-03-17 17:52:21 +0000806
Chris Lattner76c564b2010-04-04 04:47:45 +0000807void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
808 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000809 // (3 - the number of trailing zeros) is the number of then / else.
810 unsigned Mask = MI->getOperand(OpNum).getImm();
Richard Bartonf435b092012-04-27 08:42:59 +0000811 unsigned Firstcond = MI->getOperand(OpNum-1).getImm();
812 unsigned CondBit0 = Firstcond & 1;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000813 unsigned NumTZ = CountTrailingZeros_32(Mask);
814 assert(NumTZ <= 3 && "Invalid IT mask!");
815 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
816 bool T = ((Mask >> Pos) & 1) == CondBit0;
817 if (T)
818 O << 't';
819 else
820 O << 'e';
821 }
822}
823
Chris Lattner76c564b2010-04-04 04:47:45 +0000824void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
825 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000826 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000827 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000828
829 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner76c564b2010-04-04 04:47:45 +0000830 printOperand(MI, Op, O);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000831 return;
832 }
833
834 O << "[" << getRegisterName(MO1.getReg());
Bill Wendling092a7bd2010-12-14 03:36:38 +0000835 if (unsigned RegNum = MO2.getReg())
836 O << ", " << getRegisterName(RegNum);
837 O << "]";
838}
839
840void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
841 unsigned Op,
842 raw_ostream &O,
843 unsigned Scale) {
844 const MCOperand &MO1 = MI->getOperand(Op);
845 const MCOperand &MO2 = MI->getOperand(Op + 1);
846
847 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
848 printOperand(MI, Op, O);
849 return;
850 }
851
852 O << "[" << getRegisterName(MO1.getReg());
853 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen8f3004c2010-03-17 17:52:21 +0000854 O << ", #" << ImmOffs * Scale;
855 O << "]";
856}
857
Bill Wendling092a7bd2010-12-14 03:36:38 +0000858void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
859 unsigned Op,
860 raw_ostream &O) {
861 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000862}
863
Bill Wendling092a7bd2010-12-14 03:36:38 +0000864void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
865 unsigned Op,
866 raw_ostream &O) {
867 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000868}
869
Bill Wendling092a7bd2010-12-14 03:36:38 +0000870void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
871 unsigned Op,
872 raw_ostream &O) {
873 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000874}
875
Chris Lattner76c564b2010-04-04 04:47:45 +0000876void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
877 raw_ostream &O) {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000878 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000879}
880
Johnny Chen8f3004c2010-03-17 17:52:21 +0000881// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
882// register with shift forms.
883// REG 0 0 - e.g. R5
884// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner76c564b2010-04-04 04:47:45 +0000885void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
886 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000887 const MCOperand &MO1 = MI->getOperand(OpNum);
888 const MCOperand &MO2 = MI->getOperand(OpNum+1);
889
890 unsigned Reg = MO1.getReg();
891 O << getRegisterName(Reg);
892
893 // Print the shift opc.
Johnny Chen8f3004c2010-03-17 17:52:21 +0000894 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Tim Northover2fdbdc52012-09-22 11:18:19 +0000895 printRegImmShift(O, ARM_AM::getSORegShOp(MO2.getImm()),
896 ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen8f3004c2010-03-17 17:52:21 +0000897}
898
Jim Grosbache6fe1a02010-10-25 20:00:01 +0000899void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
900 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000901 const MCOperand &MO1 = MI->getOperand(OpNum);
902 const MCOperand &MO2 = MI->getOperand(OpNum+1);
903
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000904 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
905 printOperand(MI, OpNum, O);
906 return;
907 }
908
Johnny Chen8f3004c2010-03-17 17:52:21 +0000909 O << "[" << getRegisterName(MO1.getReg());
910
Jim Grosbach9d2d1f02010-10-27 01:19:41 +0000911 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbach505607e2010-10-28 18:34:10 +0000912 bool isSub = OffImm < 0;
913 // Special value for #-0. All others are normal.
914 if (OffImm == INT32_MIN)
915 OffImm = 0;
916 if (isSub)
Jim Grosbach9d2d1f02010-10-27 01:19:41 +0000917 O << ", #-" << -OffImm;
918 else if (OffImm > 0)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000919 O << ", #" << OffImm;
920 O << "]";
921}
922
923void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000924 unsigned OpNum,
925 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000926 const MCOperand &MO1 = MI->getOperand(OpNum);
927 const MCOperand &MO2 = MI->getOperand(OpNum+1);
928
929 O << "[" << getRegisterName(MO1.getReg());
930
931 int32_t OffImm = (int32_t)MO2.getImm();
932 // Don't print +0.
Owen Andersonfe823652011-09-16 21:08:33 +0000933 if (OffImm == INT32_MIN)
934 O << ", #-0";
935 else if (OffImm < 0)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000936 O << ", #-" << -OffImm;
937 else if (OffImm > 0)
938 O << ", #" << OffImm;
939 O << "]";
940}
941
942void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000943 unsigned OpNum,
944 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000945 const MCOperand &MO1 = MI->getOperand(OpNum);
946 const MCOperand &MO2 = MI->getOperand(OpNum+1);
947
Jim Grosbach8648c102011-12-19 23:06:24 +0000948 if (!MO1.isReg()) { // For label symbolic references.
949 printOperand(MI, OpNum, O);
950 return;
951 }
952
Johnny Chen8f3004c2010-03-17 17:52:21 +0000953 O << "[" << getRegisterName(MO1.getReg());
954
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000955 int32_t OffImm = (int32_t)MO2.getImm();
956
957 assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
958
Johnny Chen8f3004c2010-03-17 17:52:21 +0000959 // Don't print +0.
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000960 if (OffImm == INT32_MIN)
961 O << ", #-0";
962 else if (OffImm < 0)
963 O << ", #-" << -OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000964 else if (OffImm > 0)
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000965 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000966 O << "]";
967}
968
Jim Grosbacha05627e2011-09-09 18:37:27 +0000969void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
970 unsigned OpNum,
971 raw_ostream &O) {
972 const MCOperand &MO1 = MI->getOperand(OpNum);
973 const MCOperand &MO2 = MI->getOperand(OpNum+1);
974
975 O << "[" << getRegisterName(MO1.getReg());
976 if (MO2.getImm())
977 O << ", #" << MO2.getImm() * 4;
978 O << "]";
979}
980
Johnny Chen8f3004c2010-03-17 17:52:21 +0000981void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000982 unsigned OpNum,
983 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000984 const MCOperand &MO1 = MI->getOperand(OpNum);
985 int32_t OffImm = (int32_t)MO1.getImm();
986 // Don't print +0.
987 if (OffImm < 0)
Owen Anderson737beaf2011-09-23 21:26:40 +0000988 O << ", #-" << -OffImm;
989 else
990 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000991}
992
993void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000994 unsigned OpNum,
995 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000996 const MCOperand &MO1 = MI->getOperand(OpNum);
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000997 int32_t OffImm = (int32_t)MO1.getImm();
998
999 assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
1000
Johnny Chen8f3004c2010-03-17 17:52:21 +00001001 // Don't print +0.
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001002 if (OffImm == INT32_MIN)
1003 O << ", #-0";
1004 else if (OffImm < 0)
1005 O << ", #-" << -OffImm;
1006 else if (OffImm > 0)
1007 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +00001008}
1009
1010void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +00001011 unsigned OpNum,
1012 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +00001013 const MCOperand &MO1 = MI->getOperand(OpNum);
1014 const MCOperand &MO2 = MI->getOperand(OpNum+1);
1015 const MCOperand &MO3 = MI->getOperand(OpNum+2);
1016
1017 O << "[" << getRegisterName(MO1.getReg());
1018
1019 assert(MO2.getReg() && "Invalid so_reg load / store address!");
1020 O << ", " << getRegisterName(MO2.getReg());
1021
1022 unsigned ShAmt = MO3.getImm();
1023 if (ShAmt) {
1024 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
1025 O << ", lsl #" << ShAmt;
1026 }
1027 O << "]";
1028}
1029
Jim Grosbachefc761a2011-09-30 00:50:06 +00001030void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
1031 raw_ostream &O) {
Bill Wendling5a13d4f2011-01-26 20:57:43 +00001032 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbachefc761a2011-09-30 00:50:06 +00001033 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +00001034}
1035
Bob Wilson6eae5202010-06-11 21:34:50 +00001036void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
1037 raw_ostream &O) {
Bob Wilsonc1c6f472010-07-13 04:44:34 +00001038 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
1039 unsigned EltBits;
1040 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Benjamin Kramer69d57cf2011-11-07 21:00:59 +00001041 O << "#0x";
1042 O.write_hex(Val);
Johnny Chenb90b6f12010-04-16 22:40:20 +00001043}
Jim Grosbach801e0a32011-07-22 23:16:18 +00001044
Jim Grosbach475c6db2011-07-25 23:09:14 +00001045void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
1046 raw_ostream &O) {
Jim Grosbach801e0a32011-07-22 23:16:18 +00001047 unsigned Imm = MI->getOperand(OpNum).getImm();
1048 O << "#" << Imm + 1;
1049}
Jim Grosbachd2659132011-07-26 21:28:43 +00001050
1051void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
1052 raw_ostream &O) {
1053 unsigned Imm = MI->getOperand(OpNum).getImm();
1054 if (Imm == 0)
1055 return;
Jim Grosbacha5f7a8c2011-07-26 21:44:37 +00001056 O << ", ror #";
Jim Grosbachd2659132011-07-26 21:28:43 +00001057 switch (Imm) {
1058 default: assert (0 && "illegal ror immediate!");
Jim Grosbach50aafea2011-08-17 23:23:07 +00001059 case 1: O << "8"; break;
1060 case 2: O << "16"; break;
1061 case 3: O << "24"; break;
Jim Grosbachd2659132011-07-26 21:28:43 +00001062 }
1063}
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001064
Jim Grosbachea231912011-12-22 22:19:05 +00001065void ARMInstPrinter::printFBits16(const MCInst *MI, unsigned OpNum,
1066 raw_ostream &O) {
1067 O << "#" << 16 - MI->getOperand(OpNum).getImm();
1068}
1069
1070void ARMInstPrinter::printFBits32(const MCInst *MI, unsigned OpNum,
1071 raw_ostream &O) {
1072 O << "#" << 32 - MI->getOperand(OpNum).getImm();
1073}
1074
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001075void ARMInstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
1076 raw_ostream &O) {
1077 O << "[" << MI->getOperand(OpNum).getImm() << "]";
1078}
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001079
1080void ARMInstPrinter::printVectorListOne(const MCInst *MI, unsigned OpNum,
1081 raw_ostream &O) {
1082 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "}";
1083}
Jim Grosbach2f2e3c42011-10-21 18:54:25 +00001084
Jim Grosbach13a292c2012-03-06 22:01:44 +00001085void ARMInstPrinter::printVectorListTwo(const MCInst *MI, unsigned OpNum,
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001086 raw_ostream &O) {
1087 unsigned Reg = MI->getOperand(OpNum).getReg();
1088 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1089 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_1);
1090 O << "{" << getRegisterName(Reg0) << ", " << getRegisterName(Reg1) << "}";
1091}
1092
Jim Grosbach13a292c2012-03-06 22:01:44 +00001093void ARMInstPrinter::printVectorListTwoSpaced(const MCInst *MI,
1094 unsigned OpNum,
1095 raw_ostream &O) {
Jim Grosbache5307f92012-03-05 21:43:40 +00001096 unsigned Reg = MI->getOperand(OpNum).getReg();
1097 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1098 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_2);
1099 O << "{" << getRegisterName(Reg0) << ", " << getRegisterName(Reg1) << "}";
1100}
1101
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001102void ARMInstPrinter::printVectorListThree(const MCInst *MI, unsigned OpNum,
1103 raw_ostream &O) {
1104 // Normally, it's not safe to use register enum values directly with
1105 // addition to get the next register, but for VFP registers, the
1106 // sort order is guaranteed because they're all of the form D<n>.
1107 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1108 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1109 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1110}
Jim Grosbach846bcff2011-10-21 20:35:01 +00001111
1112void ARMInstPrinter::printVectorListFour(const MCInst *MI, unsigned OpNum,
1113 raw_ostream &O) {
1114 // Normally, it's not safe to use register enum values directly with
1115 // addition to get the next register, but for VFP registers, the
1116 // sort order is guaranteed because they're all of the form D<n>.
1117 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1118 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1119 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1120 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "}";
1121}
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001122
1123void ARMInstPrinter::printVectorListOneAllLanes(const MCInst *MI,
1124 unsigned OpNum,
1125 raw_ostream &O) {
1126 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[]}";
1127}
1128
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001129void ARMInstPrinter::printVectorListTwoAllLanes(const MCInst *MI,
1130 unsigned OpNum,
1131 raw_ostream &O) {
Jim Grosbach13a292c2012-03-06 22:01:44 +00001132 unsigned Reg = MI->getOperand(OpNum).getReg();
1133 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1134 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_1);
1135 O << "{" << getRegisterName(Reg0) << "[], " << getRegisterName(Reg1) << "[]}";
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001136}
Jim Grosbach8d246182011-12-14 19:35:22 +00001137
Jim Grosbachb78403c2012-01-24 23:47:04 +00001138void ARMInstPrinter::printVectorListThreeAllLanes(const MCInst *MI,
1139 unsigned OpNum,
1140 raw_ostream &O) {
1141 // Normally, it's not safe to use register enum values directly with
1142 // addition to get the next register, but for VFP registers, the
1143 // sort order is guaranteed because they're all of the form D<n>.
1144 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1145 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1146 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[]}";
1147}
1148
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001149void ARMInstPrinter::printVectorListFourAllLanes(const MCInst *MI,
1150 unsigned OpNum,
1151 raw_ostream &O) {
1152 // Normally, it's not safe to use register enum values directly with
1153 // addition to get the next register, but for VFP registers, the
1154 // sort order is guaranteed because they're all of the form D<n>.
1155 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1156 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1157 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1158 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "[]}";
1159}
1160
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001161void ARMInstPrinter::printVectorListTwoSpacedAllLanes(const MCInst *MI,
1162 unsigned OpNum,
1163 raw_ostream &O) {
Jim Grosbached428bc2012-03-06 23:10:38 +00001164 unsigned Reg = MI->getOperand(OpNum).getReg();
1165 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1166 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_2);
1167 O << "{" << getRegisterName(Reg0) << "[], " << getRegisterName(Reg1) << "[]}";
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001168}
1169
Jim Grosbachb78403c2012-01-24 23:47:04 +00001170void ARMInstPrinter::printVectorListThreeSpacedAllLanes(const MCInst *MI,
1171 unsigned OpNum,
1172 raw_ostream &O) {
1173 // Normally, it's not safe to use register enum values directly with
1174 // addition to get the next register, but for VFP registers, the
1175 // sort order is guaranteed because they're all of the form D<n>.
1176 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1177 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001178 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[]}";
1179}
1180
1181void ARMInstPrinter::printVectorListFourSpacedAllLanes(const MCInst *MI,
1182 unsigned OpNum,
1183 raw_ostream &O) {
1184 // Normally, it's not safe to use register enum values directly with
1185 // addition to get the next register, but for VFP registers, the
1186 // sort order is guaranteed because they're all of the form D<n>.
1187 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1188 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1189 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[], "
1190 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "[]}";
Jim Grosbachb78403c2012-01-24 23:47:04 +00001191}
1192
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001193void ARMInstPrinter::printVectorListThreeSpaced(const MCInst *MI,
1194 unsigned OpNum,
1195 raw_ostream &O) {
1196 // Normally, it's not safe to use register enum values directly with
1197 // addition to get the next register, but for VFP registers, the
1198 // sort order is guaranteed because they're all of the form D<n>.
1199 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1200 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1201 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "}";
1202}
Jim Grosbached561fc2012-01-24 00:43:17 +00001203
1204void ARMInstPrinter::printVectorListFourSpaced(const MCInst *MI,
1205 unsigned OpNum,
1206 raw_ostream &O) {
1207 // Normally, it's not safe to use register enum values directly with
1208 // addition to get the next register, but for VFP registers, the
1209 // sort order is guaranteed because they're all of the form D<n>.
1210 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1211 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1212 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << ", "
1213 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "}";
1214}