blob: 60f92f82d40b0cac3bbb2dd08cfbfb349a118738 [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.
305 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
306 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
307 if (ShOpc == ARM_AM::rrx)
308 return;
Owen Andersone33c95d2011-08-11 18:41:59 +0000309 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson04912702011-07-21 23:38:37 +0000310}
311
312
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000313//===--------------------------------------------------------------------===//
314// Addressing Mode #2
315//===--------------------------------------------------------------------===//
316
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000317void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
318 raw_ostream &O) {
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000319 const MCOperand &MO1 = MI->getOperand(Op);
320 const MCOperand &MO2 = MI->getOperand(Op+1);
321 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000322
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000323 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000324
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000325 if (!MO2.getReg()) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000326 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000327 O << ", #"
Johnny Chen8f3004c2010-03-17 17:52:21 +0000328 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
329 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000330 O << "]";
331 return;
332 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000333
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000334 O << ", "
Johnny Chen8f3004c2010-03-17 17:52:21 +0000335 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
336 << getRegisterName(MO2.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000337
Tim Northover0c97e762012-09-22 11:18:12 +0000338 printRegImmShift(O, ARM_AM::getAM2ShiftOpc(MO3.getImm()),
339 ARM_AM::getAM2Offset(MO3.getImm()));
Chris Lattner7ddfdc42009-10-19 21:57:05 +0000340 O << "]";
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000341}
Chris Lattneref2979b2009-10-19 22:09:23 +0000342
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000343void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
344 raw_ostream &O) {
345 const MCOperand &MO1 = MI->getOperand(Op);
346 const MCOperand &MO2 = MI->getOperand(Op+1);
347 const MCOperand &MO3 = MI->getOperand(Op+2);
348
349 O << "[" << getRegisterName(MO1.getReg()) << "], ";
350
351 if (!MO2.getReg()) {
352 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
353 O << '#'
354 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
355 << ImmOffs;
356 return;
357 }
358
359 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
360 << getRegisterName(MO2.getReg());
361
362 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
363 O << ", "
364 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
365 << " #" << ShImm;
366}
367
Jim Grosbach05541f42011-09-19 22:21:13 +0000368void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
369 raw_ostream &O) {
370 const MCOperand &MO1 = MI->getOperand(Op);
371 const MCOperand &MO2 = MI->getOperand(Op+1);
372 O << "[" << getRegisterName(MO1.getReg()) << ", "
373 << getRegisterName(MO2.getReg()) << "]";
374}
375
376void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
377 raw_ostream &O) {
378 const MCOperand &MO1 = MI->getOperand(Op);
379 const MCOperand &MO2 = MI->getOperand(Op+1);
380 O << "[" << getRegisterName(MO1.getReg()) << ", "
381 << getRegisterName(MO2.getReg()) << ", lsl #1]";
382}
383
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000384void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
385 raw_ostream &O) {
386 const MCOperand &MO1 = MI->getOperand(Op);
387
388 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
389 printOperand(MI, Op, O);
390 return;
391 }
392
393 const MCOperand &MO3 = MI->getOperand(Op+2);
394 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
395
396 if (IdxMode == ARMII::IndexModePost) {
397 printAM2PostIndexOp(MI, Op, O);
398 return;
399 }
400 printAM2PreOrOffsetIndexOp(MI, Op, O);
401}
402
Chris Lattner60d51312009-10-20 06:15:28 +0000403void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000404 unsigned OpNum,
405 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000406 const MCOperand &MO1 = MI->getOperand(OpNum);
407 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000408
Chris Lattner60d51312009-10-20 06:15:28 +0000409 if (!MO1.getReg()) {
410 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +0000411 O << '#'
412 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
413 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000414 return;
415 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000416
Johnny Chen8f3004c2010-03-17 17:52:21 +0000417 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
418 << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000419
Tim Northover0c97e762012-09-22 11:18:12 +0000420 printRegImmShift(O, ARM_AM::getAM2ShiftOpc(MO2.getImm()),
421 ARM_AM::getAM2Offset(MO2.getImm()));
Chris Lattner60d51312009-10-20 06:15:28 +0000422}
423
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000424//===--------------------------------------------------------------------===//
425// Addressing Mode #3
426//===--------------------------------------------------------------------===//
427
428void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
429 raw_ostream &O) {
430 const MCOperand &MO1 = MI->getOperand(Op);
431 const MCOperand &MO2 = MI->getOperand(Op+1);
432 const MCOperand &MO3 = MI->getOperand(Op+2);
433
434 O << "[" << getRegisterName(MO1.getReg()) << "], ";
435
436 if (MO2.getReg()) {
437 O << (char)ARM_AM::getAM3Op(MO3.getImm())
438 << getRegisterName(MO2.getReg());
439 return;
440 }
441
442 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
443 O << '#'
444 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
445 << ImmOffs;
446}
447
448void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
449 raw_ostream &O) {
450 const MCOperand &MO1 = MI->getOperand(Op);
451 const MCOperand &MO2 = MI->getOperand(Op+1);
452 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000453
Chris Lattner60d51312009-10-20 06:15:28 +0000454 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000455
Chris Lattner60d51312009-10-20 06:15:28 +0000456 if (MO2.getReg()) {
Jim Grosbachd3595712011-08-03 23:50:40 +0000457 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattner60d51312009-10-20 06:15:28 +0000458 << getRegisterName(MO2.getReg()) << ']';
459 return;
460 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000461
Silviu Baranga5a719f92012-05-11 09:10:54 +0000462 //If the op is sub we have to print the immediate even if it is 0
463 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
464 ARM_AM::AddrOpc op = ARM_AM::getAM3Op(MO3.getImm());
465
466 if (ImmOffs || (op == ARM_AM::sub))
Chris Lattner60d51312009-10-20 06:15:28 +0000467 O << ", #"
Silviu Baranga5a719f92012-05-11 09:10:54 +0000468 << ARM_AM::getAddrOpcStr(op)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000469 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000470 O << ']';
471}
472
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000473void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
474 raw_ostream &O) {
Jim Grosbach8648c102011-12-19 23:06:24 +0000475 const MCOperand &MO1 = MI->getOperand(Op);
476 if (!MO1.isReg()) { // For label symbolic references.
477 printOperand(MI, Op, O);
478 return;
479 }
480
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +0000481 const MCOperand &MO3 = MI->getOperand(Op+2);
482 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
483
484 if (IdxMode == ARMII::IndexModePost) {
485 printAM3PostIndexOp(MI, Op, O);
486 return;
487 }
488 printAM3PreOrOffsetIndexOp(MI, Op, O);
489}
490
Chris Lattner60d51312009-10-20 06:15:28 +0000491void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000492 unsigned OpNum,
493 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000494 const MCOperand &MO1 = MI->getOperand(OpNum);
495 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000496
Chris Lattner60d51312009-10-20 06:15:28 +0000497 if (MO1.getReg()) {
Jim Grosbachd3595712011-08-03 23:50:40 +0000498 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
499 << getRegisterName(MO1.getReg());
Chris Lattner60d51312009-10-20 06:15:28 +0000500 return;
501 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000502
Chris Lattner60d51312009-10-20 06:15:28 +0000503 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +0000504 O << '#'
505 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
506 << ImmOffs;
Chris Lattner60d51312009-10-20 06:15:28 +0000507}
508
Jim Grosbachd3595712011-08-03 23:50:40 +0000509void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
510 unsigned OpNum,
511 raw_ostream &O) {
512 const MCOperand &MO = MI->getOperand(OpNum);
513 unsigned Imm = MO.getImm();
514 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
515}
516
Jim Grosbachbafce842011-08-05 15:48:21 +0000517void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
518 raw_ostream &O) {
519 const MCOperand &MO1 = MI->getOperand(OpNum);
520 const MCOperand &MO2 = MI->getOperand(OpNum+1);
521
Jim Grosbacha70fbfd52011-08-05 16:11:38 +0000522 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachbafce842011-08-05 15:48:21 +0000523}
524
Owen Andersonce519032011-08-04 18:24:14 +0000525void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
526 unsigned OpNum,
527 raw_ostream &O) {
528 const MCOperand &MO = MI->getOperand(OpNum);
529 unsigned Imm = MO.getImm();
530 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
531}
532
533
Jim Grosbachc6af2b42010-11-03 01:01:43 +0000534void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000535 raw_ostream &O) {
Jim Grosbachc6af2b42010-11-03 01:01:43 +0000536 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
537 .getImm());
538 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattneref2979b2009-10-19 22:09:23 +0000539}
540
Chris Lattner60d51312009-10-20 06:15:28 +0000541void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbache7f7de92010-11-03 01:11:15 +0000542 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000543 const MCOperand &MO1 = MI->getOperand(OpNum);
544 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000545
Chris Lattner60d51312009-10-20 06:15:28 +0000546 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner76c564b2010-04-04 04:47:45 +0000547 printOperand(MI, OpNum, O);
Chris Lattner60d51312009-10-20 06:15:28 +0000548 return;
549 }
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000550
Chris Lattner60d51312009-10-20 06:15:28 +0000551 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000552
Owen Anderson967674d2011-08-29 19:36:44 +0000553 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
554 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
555 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattner60d51312009-10-20 06:15:28 +0000556 O << ", #"
Johnny Chen8f3004c2010-03-17 17:52:21 +0000557 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendlinge84eb992010-11-03 01:49:29 +0000558 << ImmOffs * 4;
Chris Lattner60d51312009-10-20 06:15:28 +0000559 }
560 O << "]";
561}
562
Chris Lattner76c564b2010-04-04 04:47:45 +0000563void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
564 raw_ostream &O) {
Chris Lattner9351e4f2009-10-20 06:22:33 +0000565 const MCOperand &MO1 = MI->getOperand(OpNum);
566 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000567
Bob Wilsonae08a732010-03-20 22:13:40 +0000568 O << "[" << getRegisterName(MO1.getReg());
569 if (MO2.getImm()) {
570 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson0b9aafd2010-07-14 23:54:43 +0000571 O << ", :" << (MO2.getImm() << 3);
Chris Lattner9351e4f2009-10-20 06:22:33 +0000572 }
Bob Wilsonae08a732010-03-20 22:13:40 +0000573 O << "]";
574}
575
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +0000576void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
577 raw_ostream &O) {
578 const MCOperand &MO1 = MI->getOperand(OpNum);
579 O << "[" << getRegisterName(MO1.getReg()) << "]";
580}
581
Bob Wilsonae08a732010-03-20 22:13:40 +0000582void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000583 unsigned OpNum,
584 raw_ostream &O) {
Bob Wilsonae08a732010-03-20 22:13:40 +0000585 const MCOperand &MO = MI->getOperand(OpNum);
586 if (MO.getReg() == 0)
587 O << "!";
588 else
589 O << ", " << getRegisterName(MO.getReg());
Chris Lattner9351e4f2009-10-20 06:22:33 +0000590}
591
Bob Wilsonadd513112010-08-11 23:10:46 +0000592void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
593 unsigned OpNum,
594 raw_ostream &O) {
Chris Lattner9351e4f2009-10-20 06:22:33 +0000595 const MCOperand &MO = MI->getOperand(OpNum);
596 uint32_t v = ~MO.getImm();
597 int32_t lsb = CountTrailingZeros_32(v);
598 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
599 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
600 O << '#' << lsb << ", #" << width;
601}
Chris Lattner60d51312009-10-20 06:15:28 +0000602
Johnny Chen8e8f1c12010-08-12 20:46:17 +0000603void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
604 raw_ostream &O) {
605 unsigned val = MI->getOperand(OpNum).getImm();
606 O << ARM_MB::MemBOptToString(val);
607}
608
Bob Wilson481d7a92010-08-16 18:27:34 +0000609void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsonadd513112010-08-11 23:10:46 +0000610 raw_ostream &O) {
611 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000612 bool isASR = (ShiftOp & (1 << 5)) != 0;
613 unsigned Amt = ShiftOp & 0x1f;
614 if (isASR)
615 O << ", asr #" << (Amt == 0 ? 32 : Amt);
616 else if (Amt)
617 O << ", lsl #" << Amt;
Bob Wilsonadd513112010-08-11 23:10:46 +0000618}
619
Jim Grosbacha288b1c2011-07-20 21:40:26 +0000620void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
621 raw_ostream &O) {
622 unsigned Imm = MI->getOperand(OpNum).getImm();
623 if (Imm == 0)
624 return;
625 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
626 O << ", lsl #" << Imm;
627}
628
629void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
630 raw_ostream &O) {
631 unsigned Imm = MI->getOperand(OpNum).getImm();
632 // A shift amount of 32 is encoded as 0.
633 if (Imm == 0)
634 Imm = 32;
635 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
636 O << ", asr #" << Imm;
637}
638
Chris Lattner76c564b2010-04-04 04:47:45 +0000639void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
640 raw_ostream &O) {
Chris Lattneref2979b2009-10-19 22:09:23 +0000641 O << "{";
Johnny Chen8f3004c2010-03-17 17:52:21 +0000642 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
643 if (i != OpNum) O << ", ";
Chris Lattneref2979b2009-10-19 22:09:23 +0000644 O << getRegisterName(MI->getOperand(i).getReg());
645 }
646 O << "}";
647}
Chris Lattneradd57492009-10-19 22:23:04 +0000648
Jim Grosbach7e72ec62010-10-13 21:00:04 +0000649void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
650 raw_ostream &O) {
651 const MCOperand &Op = MI->getOperand(OpNum);
652 if (Op.getImm())
653 O << "be";
654 else
655 O << "le";
656}
657
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000658void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
659 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000660 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000661 O << ARM_PROC::IModToString(Op.getImm());
662}
663
664void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
665 raw_ostream &O) {
666 const MCOperand &Op = MI->getOperand(OpNum);
667 unsigned IFlags = Op.getImm();
668 for (int i=2; i >= 0; --i)
669 if (IFlags & (1 << i))
670 O << ARM_PROC::IFlagsToString(1 << i);
Owen Anderson10c5b122011-10-05 17:16:40 +0000671
672 if (IFlags == 0)
673 O << "none";
Johnny Chen8f3004c2010-03-17 17:52:21 +0000674}
675
Chris Lattner76c564b2010-04-04 04:47:45 +0000676void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
677 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000678 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000679 unsigned SpecRegRBit = Op.getImm() >> 4;
680 unsigned Mask = Op.getImm() & 0xf;
681
James Molloy21efa7d2011-09-28 14:21:38 +0000682 if (getAvailableFeatures() & ARM::FeatureMClass) {
Kevin Enderbyf1b225d2012-05-17 22:18:01 +0000683 unsigned SYSm = Op.getImm();
684 unsigned Opcode = MI->getOpcode();
685 // For reads of the special registers ignore the "mask encoding" bits
686 // which are only for writes.
687 if (Opcode == ARM::t2MRS_M)
688 SYSm &= 0xff;
689 switch (SYSm) {
Craig Toppere55c5562012-02-07 02:50:20 +0000690 default: llvm_unreachable("Unexpected mask value!");
Kevin Enderbyf1b225d2012-05-17 22:18:01 +0000691 case 0:
692 case 0x800: O << "apsr"; return; // with _nzcvq bits is an alias for aspr
693 case 0x400: O << "apsr_g"; return;
694 case 0xc00: O << "apsr_nzcvqg"; return;
695 case 1:
696 case 0x801: O << "iapsr"; return; // with _nzcvq bits is an alias for iapsr
697 case 0x401: O << "iapsr_g"; return;
698 case 0xc01: O << "iapsr_nzcvqg"; return;
699 case 2:
700 case 0x802: O << "eapsr"; return; // with _nzcvq bits is an alias for eapsr
701 case 0x402: O << "eapsr_g"; return;
702 case 0xc02: O << "eapsr_nzcvqg"; return;
703 case 3:
704 case 0x803: O << "xpsr"; return; // with _nzcvq bits is an alias for xpsr
705 case 0x403: O << "xpsr_g"; return;
706 case 0xc03: O << "xpsr_nzcvqg"; return;
Kevin Enderby6c7279e2012-06-15 22:14:44 +0000707 case 5:
708 case 0x805: O << "ipsr"; return;
709 case 6:
710 case 0x806: O << "epsr"; return;
711 case 7:
712 case 0x807: O << "iepsr"; return;
713 case 8:
714 case 0x808: O << "msp"; return;
715 case 9:
716 case 0x809: O << "psp"; return;
717 case 0x10:
718 case 0x810: O << "primask"; return;
719 case 0x11:
720 case 0x811: O << "basepri"; return;
721 case 0x12:
722 case 0x812: O << "basepri_max"; return;
723 case 0x13:
724 case 0x813: O << "faultmask"; return;
725 case 0x14:
726 case 0x814: O << "control"; return;
James Molloy21efa7d2011-09-28 14:21:38 +0000727 }
728 }
729
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000730 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
731 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
732 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
733 O << "APSR_";
734 switch (Mask) {
Craig Toppere55c5562012-02-07 02:50:20 +0000735 default: llvm_unreachable("Unexpected mask value!");
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000736 case 4: O << "g"; return;
737 case 8: O << "nzcvq"; return;
738 case 12: O << "nzcvqg"; return;
739 }
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000740 }
741
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000742 if (SpecRegRBit)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000743 O << "SPSR";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000744 else
Jim Grosbachd25c2cd2011-07-19 22:45:10 +0000745 O << "CPSR";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000746
Johnny Chen8f3004c2010-03-17 17:52:21 +0000747 if (Mask) {
748 O << '_';
749 if (Mask & 8) O << 'f';
750 if (Mask & 4) O << 's';
751 if (Mask & 2) O << 'x';
752 if (Mask & 1) O << 'c';
753 }
754}
755
Chris Lattner76c564b2010-04-04 04:47:45 +0000756void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
757 raw_ostream &O) {
Chris Lattner19c52202009-10-20 00:42:49 +0000758 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
Kevin Enderbyf0269b42012-03-01 22:13:02 +0000759 // Handle the undefined 15 CC value here for printing so we don't abort().
760 if ((unsigned)CC == 15)
761 O << "<und>";
762 else if (CC != ARMCC::AL)
Chris Lattner19c52202009-10-20 00:42:49 +0000763 O << ARMCondCodeToString(CC);
764}
765
Jim Grosbach29cad6c2010-09-14 22:27:15 +0000766void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000767 unsigned OpNum,
768 raw_ostream &O) {
Johnny Chen0dae1cb2010-03-02 17:57:15 +0000769 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
770 O << ARMCondCodeToString(CC);
771}
772
Chris Lattner76c564b2010-04-04 04:47:45 +0000773void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
774 raw_ostream &O) {
Daniel Dunbara470eac2009-10-20 22:10:05 +0000775 if (MI->getOperand(OpNum).getReg()) {
776 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
777 "Expect ARM CPSR register!");
Chris Lattner85ab6702009-10-20 00:46:11 +0000778 O << 's';
779 }
780}
781
Chris Lattner76c564b2010-04-04 04:47:45 +0000782void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
783 raw_ostream &O) {
Chris Lattner60d51312009-10-20 06:15:28 +0000784 O << MI->getOperand(OpNum).getImm();
785}
786
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000787void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbach69664112011-10-12 16:34:37 +0000788 raw_ostream &O) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000789 O << "p" << MI->getOperand(OpNum).getImm();
790}
791
792void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbach69664112011-10-12 16:34:37 +0000793 raw_ostream &O) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +0000794 O << "c" << MI->getOperand(OpNum).getImm();
795}
796
Jim Grosbach48399582011-10-12 17:34:41 +0000797void ARMInstPrinter::printCoprocOptionImm(const MCInst *MI, unsigned OpNum,
798 raw_ostream &O) {
799 O << "{" << MI->getOperand(OpNum).getImm() << "}";
800}
801
Chris Lattner76c564b2010-04-04 04:47:45 +0000802void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
803 raw_ostream &O) {
Jim Grosbach8a5a6a62010-09-18 00:04:53 +0000804 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattneradd57492009-10-19 22:23:04 +0000805}
Evan Chengb1852592009-11-19 06:57:41 +0000806
Jiangning Liu10dd40e2012-08-02 08:13:13 +0000807void ARMInstPrinter::printAdrLabelOperand(const MCInst *MI, unsigned OpNum,
808 raw_ostream &O) {
809 const MCOperand &MO = MI->getOperand(OpNum);
810
811 if (MO.isExpr()) {
812 O << *MO.getExpr();
813 return;
814 }
815
816 int32_t OffImm = (int32_t)MO.getImm();
817
818 if (OffImm == INT32_MIN)
819 O << "#-0";
820 else if (OffImm < 0)
821 O << "#-" << -OffImm;
822 else
823 O << "#" << OffImm;
824}
825
Chris Lattner76c564b2010-04-04 04:47:45 +0000826void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
827 raw_ostream &O) {
Jim Grosbach46dd4132011-08-17 21:51:27 +0000828 O << "#" << MI->getOperand(OpNum).getImm() * 4;
829}
830
831void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
832 raw_ostream &O) {
833 unsigned Imm = MI->getOperand(OpNum).getImm();
834 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Chengb1852592009-11-19 06:57:41 +0000835}
Johnny Chen8f3004c2010-03-17 17:52:21 +0000836
Chris Lattner76c564b2010-04-04 04:47:45 +0000837void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
838 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000839 // (3 - the number of trailing zeros) is the number of then / else.
840 unsigned Mask = MI->getOperand(OpNum).getImm();
Richard Bartonf435b092012-04-27 08:42:59 +0000841 unsigned Firstcond = MI->getOperand(OpNum-1).getImm();
842 unsigned CondBit0 = Firstcond & 1;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000843 unsigned NumTZ = CountTrailingZeros_32(Mask);
844 assert(NumTZ <= 3 && "Invalid IT mask!");
845 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
846 bool T = ((Mask >> Pos) & 1) == CondBit0;
847 if (T)
848 O << 't';
849 else
850 O << 'e';
851 }
852}
853
Chris Lattner76c564b2010-04-04 04:47:45 +0000854void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
855 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000856 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000857 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000858
859 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner76c564b2010-04-04 04:47:45 +0000860 printOperand(MI, Op, O);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000861 return;
862 }
863
864 O << "[" << getRegisterName(MO1.getReg());
Bill Wendling092a7bd2010-12-14 03:36:38 +0000865 if (unsigned RegNum = MO2.getReg())
866 O << ", " << getRegisterName(RegNum);
867 O << "]";
868}
869
870void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
871 unsigned Op,
872 raw_ostream &O,
873 unsigned Scale) {
874 const MCOperand &MO1 = MI->getOperand(Op);
875 const MCOperand &MO2 = MI->getOperand(Op + 1);
876
877 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
878 printOperand(MI, Op, O);
879 return;
880 }
881
882 O << "[" << getRegisterName(MO1.getReg());
883 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen8f3004c2010-03-17 17:52:21 +0000884 O << ", #" << ImmOffs * Scale;
885 O << "]";
886}
887
Bill Wendling092a7bd2010-12-14 03:36:38 +0000888void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
889 unsigned Op,
890 raw_ostream &O) {
891 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000892}
893
Bill Wendling092a7bd2010-12-14 03:36:38 +0000894void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
895 unsigned Op,
896 raw_ostream &O) {
897 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000898}
899
Bill Wendling092a7bd2010-12-14 03:36:38 +0000900void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
901 unsigned Op,
902 raw_ostream &O) {
903 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000904}
905
Chris Lattner76c564b2010-04-04 04:47:45 +0000906void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
907 raw_ostream &O) {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000908 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen8f3004c2010-03-17 17:52:21 +0000909}
910
Johnny Chen8f3004c2010-03-17 17:52:21 +0000911// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
912// register with shift forms.
913// REG 0 0 - e.g. R5
914// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner76c564b2010-04-04 04:47:45 +0000915void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
916 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000917 const MCOperand &MO1 = MI->getOperand(OpNum);
918 const MCOperand &MO2 = MI->getOperand(OpNum+1);
919
920 unsigned Reg = MO1.getReg();
921 O << getRegisterName(Reg);
922
923 // Print the shift opc.
Johnny Chen8f3004c2010-03-17 17:52:21 +0000924 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson97886d52010-08-05 00:34:42 +0000925 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
926 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
927 if (ShOpc != ARM_AM::rrx)
Owen Andersone33c95d2011-08-11 18:41:59 +0000928 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen8f3004c2010-03-17 17:52:21 +0000929}
930
Jim Grosbache6fe1a02010-10-25 20:00:01 +0000931void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
932 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000933 const MCOperand &MO1 = MI->getOperand(OpNum);
934 const MCOperand &MO2 = MI->getOperand(OpNum+1);
935
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000936 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
937 printOperand(MI, OpNum, O);
938 return;
939 }
940
Johnny Chen8f3004c2010-03-17 17:52:21 +0000941 O << "[" << getRegisterName(MO1.getReg());
942
Jim Grosbach9d2d1f02010-10-27 01:19:41 +0000943 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbach505607e2010-10-28 18:34:10 +0000944 bool isSub = OffImm < 0;
945 // Special value for #-0. All others are normal.
946 if (OffImm == INT32_MIN)
947 OffImm = 0;
948 if (isSub)
Jim Grosbach9d2d1f02010-10-27 01:19:41 +0000949 O << ", #-" << -OffImm;
950 else if (OffImm > 0)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000951 O << ", #" << OffImm;
952 O << "]";
953}
954
955void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000956 unsigned OpNum,
957 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000958 const MCOperand &MO1 = MI->getOperand(OpNum);
959 const MCOperand &MO2 = MI->getOperand(OpNum+1);
960
961 O << "[" << getRegisterName(MO1.getReg());
962
963 int32_t OffImm = (int32_t)MO2.getImm();
964 // Don't print +0.
Owen Andersonfe823652011-09-16 21:08:33 +0000965 if (OffImm == INT32_MIN)
966 O << ", #-0";
967 else if (OffImm < 0)
Johnny Chen8f3004c2010-03-17 17:52:21 +0000968 O << ", #-" << -OffImm;
969 else if (OffImm > 0)
970 O << ", #" << OffImm;
971 O << "]";
972}
973
974void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +0000975 unsigned OpNum,
976 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +0000977 const MCOperand &MO1 = MI->getOperand(OpNum);
978 const MCOperand &MO2 = MI->getOperand(OpNum+1);
979
Jim Grosbach8648c102011-12-19 23:06:24 +0000980 if (!MO1.isReg()) { // For label symbolic references.
981 printOperand(MI, OpNum, O);
982 return;
983 }
984
Johnny Chen8f3004c2010-03-17 17:52:21 +0000985 O << "[" << getRegisterName(MO1.getReg());
986
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000987 int32_t OffImm = (int32_t)MO2.getImm();
988
989 assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
990
Johnny Chen8f3004c2010-03-17 17:52:21 +0000991 // Don't print +0.
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000992 if (OffImm == INT32_MIN)
993 O << ", #-0";
994 else if (OffImm < 0)
995 O << ", #-" << -OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000996 else if (OffImm > 0)
Jiangning Liu6a43bf72012-08-02 08:29:50 +0000997 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +0000998 O << "]";
999}
1000
Jim Grosbacha05627e2011-09-09 18:37:27 +00001001void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
1002 unsigned OpNum,
1003 raw_ostream &O) {
1004 const MCOperand &MO1 = MI->getOperand(OpNum);
1005 const MCOperand &MO2 = MI->getOperand(OpNum+1);
1006
1007 O << "[" << getRegisterName(MO1.getReg());
1008 if (MO2.getImm())
1009 O << ", #" << MO2.getImm() * 4;
1010 O << "]";
1011}
1012
Johnny Chen8f3004c2010-03-17 17:52:21 +00001013void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(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);
1017 int32_t OffImm = (int32_t)MO1.getImm();
1018 // Don't print +0.
1019 if (OffImm < 0)
Owen Anderson737beaf2011-09-23 21:26:40 +00001020 O << ", #-" << -OffImm;
1021 else
1022 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +00001023}
1024
1025void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +00001026 unsigned OpNum,
1027 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +00001028 const MCOperand &MO1 = MI->getOperand(OpNum);
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001029 int32_t OffImm = (int32_t)MO1.getImm();
1030
1031 assert(((OffImm & 0x3) == 0) && "Not a valid immediate!");
1032
Johnny Chen8f3004c2010-03-17 17:52:21 +00001033 // Don't print +0.
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001034 if (OffImm == INT32_MIN)
1035 O << ", #-0";
1036 else if (OffImm < 0)
1037 O << ", #-" << -OffImm;
1038 else if (OffImm > 0)
1039 O << ", #" << OffImm;
Johnny Chen8f3004c2010-03-17 17:52:21 +00001040}
1041
1042void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner76c564b2010-04-04 04:47:45 +00001043 unsigned OpNum,
1044 raw_ostream &O) {
Johnny Chen8f3004c2010-03-17 17:52:21 +00001045 const MCOperand &MO1 = MI->getOperand(OpNum);
1046 const MCOperand &MO2 = MI->getOperand(OpNum+1);
1047 const MCOperand &MO3 = MI->getOperand(OpNum+2);
1048
1049 O << "[" << getRegisterName(MO1.getReg());
1050
1051 assert(MO2.getReg() && "Invalid so_reg load / store address!");
1052 O << ", " << getRegisterName(MO2.getReg());
1053
1054 unsigned ShAmt = MO3.getImm();
1055 if (ShAmt) {
1056 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
1057 O << ", lsl #" << ShAmt;
1058 }
1059 O << "]";
1060}
1061
Jim Grosbachefc761a2011-09-30 00:50:06 +00001062void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
1063 raw_ostream &O) {
Bill Wendling5a13d4f2011-01-26 20:57:43 +00001064 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbachefc761a2011-09-30 00:50:06 +00001065 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen8f3004c2010-03-17 17:52:21 +00001066}
1067
Bob Wilson6eae5202010-06-11 21:34:50 +00001068void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
1069 raw_ostream &O) {
Bob Wilsonc1c6f472010-07-13 04:44:34 +00001070 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
1071 unsigned EltBits;
1072 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Benjamin Kramer69d57cf2011-11-07 21:00:59 +00001073 O << "#0x";
1074 O.write_hex(Val);
Johnny Chenb90b6f12010-04-16 22:40:20 +00001075}
Jim Grosbach801e0a32011-07-22 23:16:18 +00001076
Jim Grosbach475c6db2011-07-25 23:09:14 +00001077void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
1078 raw_ostream &O) {
Jim Grosbach801e0a32011-07-22 23:16:18 +00001079 unsigned Imm = MI->getOperand(OpNum).getImm();
1080 O << "#" << Imm + 1;
1081}
Jim Grosbachd2659132011-07-26 21:28:43 +00001082
1083void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
1084 raw_ostream &O) {
1085 unsigned Imm = MI->getOperand(OpNum).getImm();
1086 if (Imm == 0)
1087 return;
Jim Grosbacha5f7a8c2011-07-26 21:44:37 +00001088 O << ", ror #";
Jim Grosbachd2659132011-07-26 21:28:43 +00001089 switch (Imm) {
1090 default: assert (0 && "illegal ror immediate!");
Jim Grosbach50aafea2011-08-17 23:23:07 +00001091 case 1: O << "8"; break;
1092 case 2: O << "16"; break;
1093 case 3: O << "24"; break;
Jim Grosbachd2659132011-07-26 21:28:43 +00001094 }
1095}
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001096
Jim Grosbachea231912011-12-22 22:19:05 +00001097void ARMInstPrinter::printFBits16(const MCInst *MI, unsigned OpNum,
1098 raw_ostream &O) {
1099 O << "#" << 16 - MI->getOperand(OpNum).getImm();
1100}
1101
1102void ARMInstPrinter::printFBits32(const MCInst *MI, unsigned OpNum,
1103 raw_ostream &O) {
1104 O << "#" << 32 - MI->getOperand(OpNum).getImm();
1105}
1106
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001107void ARMInstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
1108 raw_ostream &O) {
1109 O << "[" << MI->getOperand(OpNum).getImm() << "]";
1110}
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001111
1112void ARMInstPrinter::printVectorListOne(const MCInst *MI, unsigned OpNum,
1113 raw_ostream &O) {
1114 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "}";
1115}
Jim Grosbach2f2e3c42011-10-21 18:54:25 +00001116
Jim Grosbach13a292c2012-03-06 22:01:44 +00001117void ARMInstPrinter::printVectorListTwo(const MCInst *MI, unsigned OpNum,
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001118 raw_ostream &O) {
1119 unsigned Reg = MI->getOperand(OpNum).getReg();
1120 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1121 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_1);
1122 O << "{" << getRegisterName(Reg0) << ", " << getRegisterName(Reg1) << "}";
1123}
1124
Jim Grosbach13a292c2012-03-06 22:01:44 +00001125void ARMInstPrinter::printVectorListTwoSpaced(const MCInst *MI,
1126 unsigned OpNum,
1127 raw_ostream &O) {
Jim Grosbache5307f92012-03-05 21:43:40 +00001128 unsigned Reg = MI->getOperand(OpNum).getReg();
1129 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1130 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_2);
1131 O << "{" << getRegisterName(Reg0) << ", " << getRegisterName(Reg1) << "}";
1132}
1133
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001134void ARMInstPrinter::printVectorListThree(const MCInst *MI, unsigned OpNum,
1135 raw_ostream &O) {
1136 // Normally, it's not safe to use register enum values directly with
1137 // addition to get the next register, but for VFP registers, the
1138 // sort order is guaranteed because they're all of the form D<n>.
1139 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1140 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1141 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1142}
Jim Grosbach846bcff2011-10-21 20:35:01 +00001143
1144void ARMInstPrinter::printVectorListFour(const MCInst *MI, unsigned OpNum,
1145 raw_ostream &O) {
1146 // Normally, it's not safe to use register enum values directly with
1147 // addition to get the next register, but for VFP registers, the
1148 // sort order is guaranteed because they're all of the form D<n>.
1149 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1150 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1151 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1152 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "}";
1153}
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001154
1155void ARMInstPrinter::printVectorListOneAllLanes(const MCInst *MI,
1156 unsigned OpNum,
1157 raw_ostream &O) {
1158 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[]}";
1159}
1160
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001161void ARMInstPrinter::printVectorListTwoAllLanes(const MCInst *MI,
1162 unsigned OpNum,
1163 raw_ostream &O) {
Jim Grosbach13a292c2012-03-06 22:01:44 +00001164 unsigned Reg = MI->getOperand(OpNum).getReg();
1165 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1166 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_1);
1167 O << "{" << getRegisterName(Reg0) << "[], " << getRegisterName(Reg1) << "[]}";
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001168}
Jim Grosbach8d246182011-12-14 19:35:22 +00001169
Jim Grosbachb78403c2012-01-24 23:47:04 +00001170void ARMInstPrinter::printVectorListThreeAllLanes(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() + 1) << "[], "
1178 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[]}";
1179}
1180
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001181void ARMInstPrinter::printVectorListFourAllLanes(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() + 1) << "[], "
1189 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1190 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "[]}";
1191}
1192
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001193void ARMInstPrinter::printVectorListTwoSpacedAllLanes(const MCInst *MI,
1194 unsigned OpNum,
1195 raw_ostream &O) {
Jim Grosbached428bc2012-03-06 23:10:38 +00001196 unsigned Reg = MI->getOperand(OpNum).getReg();
1197 unsigned Reg0 = MRI.getSubReg(Reg, ARM::dsub_0);
1198 unsigned Reg1 = MRI.getSubReg(Reg, ARM::dsub_2);
1199 O << "{" << getRegisterName(Reg0) << "[], " << getRegisterName(Reg1) << "[]}";
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001200}
1201
Jim Grosbachb78403c2012-01-24 23:47:04 +00001202void ARMInstPrinter::printVectorListThreeSpacedAllLanes(const MCInst *MI,
1203 unsigned OpNum,
1204 raw_ostream &O) {
1205 // Normally, it's not safe to use register enum values directly with
1206 // addition to get the next register, but for VFP registers, the
1207 // sort order is guaranteed because they're all of the form D<n>.
1208 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1209 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001210 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[]}";
1211}
1212
1213void ARMInstPrinter::printVectorListFourSpacedAllLanes(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 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "[]}";
Jim Grosbachb78403c2012-01-24 23:47:04 +00001223}
1224
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001225void ARMInstPrinter::printVectorListThreeSpaced(const MCInst *MI,
1226 unsigned OpNum,
1227 raw_ostream &O) {
1228 // Normally, it's not safe to use register enum values directly with
1229 // addition to get the next register, but for VFP registers, the
1230 // sort order is guaranteed because they're all of the form D<n>.
1231 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1232 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1233 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "}";
1234}
Jim Grosbached561fc2012-01-24 00:43:17 +00001235
1236void ARMInstPrinter::printVectorListFourSpaced(const MCInst *MI,
1237 unsigned OpNum,
1238 raw_ostream &O) {
1239 // Normally, it's not safe to use register enum values directly with
1240 // addition to get the next register, but for VFP registers, the
1241 // sort order is guaranteed because they're all of the form D<n>.
1242 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1243 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1244 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << ", "
1245 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "}";
1246}