blob: d637929b296b73066bb6088e5520b4127a925346 [file] [log] [blame]
Chris Lattnerfd603822009-10-19 19:56:26 +00001//===-- ARMInstPrinter.cpp - Convert ARM MCInst to assembly syntax --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class prints an ARM MCInst to a .s file.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "asm-printer"
15#include "ARMInstPrinter.h"
Evan Chengbe740292011-07-23 00:00:19 +000016#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000017#include "MCTargetDesc/ARMAddressingModes.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000018#include "llvm/MC/MCInst.h"
Chris Lattner61d35c22009-10-19 21:21:39 +000019#include "llvm/MC/MCAsmInfo.h"
Chris Lattner6f997762009-10-19 21:53:00 +000020#include "llvm/MC/MCExpr.h"
Johnny Chenc7b65912010-04-16 22:40:20 +000021#include "llvm/ADT/StringExtras.h"
Chris Lattner6f997762009-10-19 21:53:00 +000022#include "llvm/Support/raw_ostream.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000023using namespace llvm;
24
Chris Lattner6274ec42010-10-28 21:37:33 +000025#define GET_INSTRUCTION_NAME
Chris Lattnerfd603822009-10-19 19:56:26 +000026#include "ARMGenAsmWriter.inc"
Chris Lattnerfd603822009-10-19 19:56:26 +000027
Owen Anderson3dac0be2011-08-11 18:41:59 +000028/// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing.
29///
30/// getSORegOffset returns an integer from 0-31, but '0' should actually be printed
31/// 32 as the immediate shouldbe within the range 1-32.
32static unsigned translateShiftImm(unsigned imm) {
33 if (imm == 0)
34 return 32;
35 return imm;
36}
37
James Molloyb9505852011-09-07 17:24:38 +000038
39ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
40 const MCSubtargetInfo &STI) :
41 MCInstPrinter(MAI) {
42 // Initialize the set of available features.
43 setAvailableFeatures(STI.getFeatureBits());
44}
45
Chris Lattner6274ec42010-10-28 21:37:33 +000046StringRef ARMInstPrinter::getOpcodeName(unsigned Opcode) const {
47 return getInstructionName(Opcode);
48}
49
Rafael Espindolacde4ce42011-06-02 02:34:55 +000050void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
51 OS << getRegisterName(RegNo);
Anton Korobeynikov57caad72011-03-05 18:43:32 +000052}
Chris Lattner6274ec42010-10-28 21:37:33 +000053
Owen Anderson98c5dda2011-09-15 23:38:46 +000054void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
55 StringRef Annot) {
Bill Wendling04863d02010-11-13 10:40:19 +000056 unsigned Opcode = MI->getOpcode();
57
Johnny Chen9e088762010-03-17 17:52:21 +000058 // Check for MOVs and print canonical forms, instead.
Owen Anderson152d4a42011-07-21 23:38:37 +000059 if (Opcode == ARM::MOVsr) {
Jim Grosbache6be85e2010-09-17 22:36:38 +000060 // FIXME: Thumb variants?
Johnny Chen9e088762010-03-17 17:52:21 +000061 const MCOperand &Dst = MI->getOperand(0);
62 const MCOperand &MO1 = MI->getOperand(1);
63 const MCOperand &MO2 = MI->getOperand(2);
64 const MCOperand &MO3 = MI->getOperand(3);
65
66 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner35c33bd2010-04-04 04:47:45 +000067 printSBitModifierOperand(MI, 6, O);
68 printPredicateOperand(MI, 4, O);
Johnny Chen9e088762010-03-17 17:52:21 +000069
70 O << '\t' << getRegisterName(Dst.getReg())
71 << ", " << getRegisterName(MO1.getReg());
72
Owen Anderson152d4a42011-07-21 23:38:37 +000073 O << ", " << getRegisterName(MO2.getReg());
74 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Owen Anderson519020a2011-09-21 17:58:45 +000075 printAnnotation(O, Annot);
Johnny Chen9e088762010-03-17 17:52:21 +000076 return;
77 }
78
Owen Anderson152d4a42011-07-21 23:38:37 +000079 if (Opcode == ARM::MOVsi) {
80 // FIXME: Thumb variants?
81 const MCOperand &Dst = MI->getOperand(0);
82 const MCOperand &MO1 = MI->getOperand(1);
83 const MCOperand &MO2 = MI->getOperand(2);
84
85 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
86 printSBitModifierOperand(MI, 5, O);
87 printPredicateOperand(MI, 3, O);
88
89 O << '\t' << getRegisterName(Dst.getReg())
90 << ", " << getRegisterName(MO1.getReg());
91
Owen Andersonede042d2011-09-15 18:36:29 +000092 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
Owen Anderson519020a2011-09-21 17:58:45 +000093 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000094 return;
Owen Andersonede042d2011-09-15 18:36:29 +000095 }
Owen Anderson152d4a42011-07-21 23:38:37 +000096
Owen Anderson3dac0be2011-08-11 18:41:59 +000097 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson519020a2011-09-21 17:58:45 +000098 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000099 return;
100 }
101
102
Johnny Chen9e088762010-03-17 17:52:21 +0000103 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000104 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000105 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000106 O << '\t' << "push";
107 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000108 if (Opcode == ARM::t2STMDB_UPD)
109 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000110 O << '\t';
111 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000112 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000113 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000114 }
Jim Grosbachf6713912011-08-11 18:07:11 +0000115 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
116 MI->getOperand(3).getImm() == -4) {
117 O << '\t' << "push";
118 printPredicateOperand(MI, 4, O);
119 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000120 printAnnotation(O, Annot);
Jim Grosbachf6713912011-08-11 18:07:11 +0000121 return;
122 }
Johnny Chen9e088762010-03-17 17:52:21 +0000123
124 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000125 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000126 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000127 O << '\t' << "pop";
128 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000129 if (Opcode == ARM::t2LDMIA_UPD)
130 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000131 O << '\t';
132 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000133 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000134 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000135 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000136 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
137 MI->getOperand(4).getImm() == 4) {
138 O << '\t' << "pop";
139 printPredicateOperand(MI, 5, O);
140 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000141 printAnnotation(O, Annot);
Jim Grosbachf8fce712011-08-11 17:35:48 +0000142 return;
143 }
144
Johnny Chen9e088762010-03-17 17:52:21 +0000145
146 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000147 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000148 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000149 O << '\t' << "vpush";
150 printPredicateOperand(MI, 2, O);
151 O << '\t';
152 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000153 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000154 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000155 }
156
157 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000158 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000159 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000160 O << '\t' << "vpop";
161 printPredicateOperand(MI, 2, O);
162 O << '\t';
163 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000164 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000165 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000166 }
167
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000168 if (Opcode == ARM::tLDMIA) {
Owen Anderson565a0362011-07-18 23:25:34 +0000169 bool Writeback = true;
170 unsigned BaseReg = MI->getOperand(0).getReg();
171 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
172 if (MI->getOperand(i).getReg() == BaseReg)
173 Writeback = false;
174 }
175
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000176 O << "\tldm";
Owen Anderson565a0362011-07-18 23:25:34 +0000177
178 printPredicateOperand(MI, 1, O);
179 O << '\t' << getRegisterName(BaseReg);
180 if (Writeback) O << "!";
181 O << ", ";
182 printRegisterList(MI, 3, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000183 printAnnotation(O, Annot);
Owen Anderson565a0362011-07-18 23:25:34 +0000184 return;
185 }
186
Jim Grosbach0780b632011-08-19 23:24:36 +0000187 // Thumb1 NOP
188 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
189 MI->getOperand(1).getReg() == ARM::R8) {
190 O << "\tnop";
Jim Grosbachdf9ce6b2011-08-24 20:06:14 +0000191 printPredicateOperand(MI, 2, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000192 printAnnotation(O, Annot);
Jim Grosbach0780b632011-08-19 23:24:36 +0000193 return;
194 }
195
Chris Lattner35c33bd2010-04-04 04:47:45 +0000196 printInstruction(MI, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000197 printAnnotation(O, Annot);
Bill Wendling04863d02010-11-13 10:40:19 +0000198}
Chris Lattnerfd603822009-10-19 19:56:26 +0000199
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000200void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000201 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000202 const MCOperand &Op = MI->getOperand(OpNo);
203 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000204 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000205 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000206 } else if (Op.isImm()) {
207 O << '#' << Op.getImm();
208 } else {
209 assert(Op.isExpr() && "unknown operand kind in printOperand");
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000210 // If a symbolic branch target was added as a constant expression then print
211 // that address in hex.
212 const MCConstantExpr *BranchTarget = dyn_cast<MCConstantExpr>(Op.getExpr());
213 int64_t Address;
214 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
215 O << "0x";
216 O.write_hex(Address);
217 }
218 else {
219 // Otherwise, just print the expression.
220 O << *Op.getExpr();
221 }
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000222 }
223}
Chris Lattner61d35c22009-10-19 21:21:39 +0000224
Owen Andersone1368722011-09-21 23:44:46 +0000225void ARMInstPrinter::printT2LdrLabelOperand(const MCInst *MI, unsigned OpNum,
226 raw_ostream &O) {
227 const MCOperand &MO1 = MI->getOperand(OpNum);
228 if (MO1.isExpr())
229 O << *MO1.getExpr();
230 else if (MO1.isImm())
231 O << "[pc, #" << MO1.getImm() << "]";
232 else
233 llvm_unreachable("Unknown LDR label operand?");
234}
235
Chris Lattner017d9472009-10-20 00:40:56 +0000236// so_reg is a 4-operand unit corresponding to register forms of the A5.1
237// "Addressing Mode 1 - Data-processing operands" forms. This includes:
238// REG 0 0 - e.g. R5
239// REG REG 0,SH_OPC - e.g. R5, ROR R3
240// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000241void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000242 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000243 const MCOperand &MO1 = MI->getOperand(OpNum);
244 const MCOperand &MO2 = MI->getOperand(OpNum+1);
245 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000246
Chris Lattner017d9472009-10-20 00:40:56 +0000247 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000248
Chris Lattner017d9472009-10-20 00:40:56 +0000249 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000250 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
251 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000252 if (ShOpc == ARM_AM::rrx)
253 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000254
255 O << ' ' << getRegisterName(MO2.getReg());
256 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000257}
Chris Lattner084f87d2009-10-19 21:57:05 +0000258
Owen Anderson152d4a42011-07-21 23:38:37 +0000259void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
260 raw_ostream &O) {
261 const MCOperand &MO1 = MI->getOperand(OpNum);
262 const MCOperand &MO2 = MI->getOperand(OpNum+1);
263
264 O << getRegisterName(MO1.getReg());
265
266 // Print the shift opc.
267 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
268 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
269 if (ShOpc == ARM_AM::rrx)
270 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000271 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000272}
273
274
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000275//===--------------------------------------------------------------------===//
276// Addressing Mode #2
277//===--------------------------------------------------------------------===//
278
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000279void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
280 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000281 const MCOperand &MO1 = MI->getOperand(Op);
282 const MCOperand &MO2 = MI->getOperand(Op+1);
283 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000284
Chris Lattner084f87d2009-10-19 21:57:05 +0000285 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000286
Chris Lattner084f87d2009-10-19 21:57:05 +0000287 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000288 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000289 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000290 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
291 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000292 O << "]";
293 return;
294 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000295
Chris Lattner084f87d2009-10-19 21:57:05 +0000296 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000297 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
298 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000299
Chris Lattner084f87d2009-10-19 21:57:05 +0000300 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
301 O << ", "
302 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
303 << " #" << ShImm;
304 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000305}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000306
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000307void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
308 raw_ostream &O) {
309 const MCOperand &MO1 = MI->getOperand(Op);
310 const MCOperand &MO2 = MI->getOperand(Op+1);
311 const MCOperand &MO3 = MI->getOperand(Op+2);
312
313 O << "[" << getRegisterName(MO1.getReg()) << "], ";
314
315 if (!MO2.getReg()) {
316 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
317 O << '#'
318 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
319 << ImmOffs;
320 return;
321 }
322
323 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
324 << getRegisterName(MO2.getReg());
325
326 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
327 O << ", "
328 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
329 << " #" << ShImm;
330}
331
Jim Grosbach7f739be2011-09-19 22:21:13 +0000332void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
333 raw_ostream &O) {
334 const MCOperand &MO1 = MI->getOperand(Op);
335 const MCOperand &MO2 = MI->getOperand(Op+1);
336 O << "[" << getRegisterName(MO1.getReg()) << ", "
337 << getRegisterName(MO2.getReg()) << "]";
338}
339
340void ARMInstPrinter::printAddrModeTBH(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()) << ", lsl #1]";
346}
347
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000348void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
349 raw_ostream &O) {
350 const MCOperand &MO1 = MI->getOperand(Op);
351
352 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
353 printOperand(MI, Op, O);
354 return;
355 }
356
357 const MCOperand &MO3 = MI->getOperand(Op+2);
358 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
359
360 if (IdxMode == ARMII::IndexModePost) {
361 printAM2PostIndexOp(MI, Op, O);
362 return;
363 }
364 printAM2PreOrOffsetIndexOp(MI, Op, O);
365}
366
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000367void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000368 unsigned OpNum,
369 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000370 const MCOperand &MO1 = MI->getOperand(OpNum);
371 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000372
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000373 if (!MO1.getReg()) {
374 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000375 O << '#'
376 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
377 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000378 return;
379 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000380
Johnny Chen9e088762010-03-17 17:52:21 +0000381 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
382 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000383
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000384 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
385 O << ", "
386 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
387 << " #" << ShImm;
388}
389
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000390//===--------------------------------------------------------------------===//
391// Addressing Mode #3
392//===--------------------------------------------------------------------===//
393
394void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
395 raw_ostream &O) {
396 const MCOperand &MO1 = MI->getOperand(Op);
397 const MCOperand &MO2 = MI->getOperand(Op+1);
398 const MCOperand &MO3 = MI->getOperand(Op+2);
399
400 O << "[" << getRegisterName(MO1.getReg()) << "], ";
401
402 if (MO2.getReg()) {
403 O << (char)ARM_AM::getAM3Op(MO3.getImm())
404 << getRegisterName(MO2.getReg());
405 return;
406 }
407
408 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
409 O << '#'
410 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
411 << ImmOffs;
412}
413
414void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
415 raw_ostream &O) {
416 const MCOperand &MO1 = MI->getOperand(Op);
417 const MCOperand &MO2 = MI->getOperand(Op+1);
418 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000419
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000420 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000421
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000422 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000423 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000424 << getRegisterName(MO2.getReg()) << ']';
425 return;
426 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000427
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000428 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
429 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000430 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
431 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000432 O << ']';
433}
434
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000435void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
436 raw_ostream &O) {
437 const MCOperand &MO3 = MI->getOperand(Op+2);
438 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
439
440 if (IdxMode == ARMII::IndexModePost) {
441 printAM3PostIndexOp(MI, Op, O);
442 return;
443 }
444 printAM3PreOrOffsetIndexOp(MI, Op, O);
445}
446
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000447void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000448 unsigned OpNum,
449 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000450 const MCOperand &MO1 = MI->getOperand(OpNum);
451 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000452
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000453 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000454 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
455 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000456 return;
457 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000458
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000459 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000460 O << '#'
461 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
462 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000463}
464
Jim Grosbach7ce05792011-08-03 23:50:40 +0000465void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
466 unsigned OpNum,
467 raw_ostream &O) {
468 const MCOperand &MO = MI->getOperand(OpNum);
469 unsigned Imm = MO.getImm();
470 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
471}
472
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000473void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
474 raw_ostream &O) {
475 const MCOperand &MO1 = MI->getOperand(OpNum);
476 const MCOperand &MO2 = MI->getOperand(OpNum+1);
477
Jim Grosbach16578b52011-08-05 16:11:38 +0000478 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000479}
480
Owen Anderson154c41d2011-08-04 18:24:14 +0000481void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
482 unsigned OpNum,
483 raw_ostream &O) {
484 const MCOperand &MO = MI->getOperand(OpNum);
485 unsigned Imm = MO.getImm();
486 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
487}
488
489
Jim Grosbache6913602010-11-03 01:01:43 +0000490void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000491 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000492 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
493 .getImm());
494 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000495}
496
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000497void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000498 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000499 const MCOperand &MO1 = MI->getOperand(OpNum);
500 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000501
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000502 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000503 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000504 return;
505 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000506
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000507 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000508
Owen Anderson0da10cf2011-08-29 19:36:44 +0000509 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
510 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
511 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000512 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000513 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000514 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000515 }
516 O << "]";
517}
518
Chris Lattner35c33bd2010-04-04 04:47:45 +0000519void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
520 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000521 const MCOperand &MO1 = MI->getOperand(OpNum);
522 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000523
Bob Wilson226036e2010-03-20 22:13:40 +0000524 O << "[" << getRegisterName(MO1.getReg());
525 if (MO2.getImm()) {
526 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000527 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000528 }
Bob Wilson226036e2010-03-20 22:13:40 +0000529 O << "]";
530}
531
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000532void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
533 raw_ostream &O) {
534 const MCOperand &MO1 = MI->getOperand(OpNum);
535 O << "[" << getRegisterName(MO1.getReg()) << "]";
536}
537
Bob Wilson226036e2010-03-20 22:13:40 +0000538void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000539 unsigned OpNum,
540 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000541 const MCOperand &MO = MI->getOperand(OpNum);
542 if (MO.getReg() == 0)
543 O << "!";
544 else
545 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000546}
547
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000548void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
549 unsigned OpNum,
550 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000551 const MCOperand &MO = MI->getOperand(OpNum);
552 uint32_t v = ~MO.getImm();
553 int32_t lsb = CountTrailingZeros_32(v);
554 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
555 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
556 O << '#' << lsb << ", #" << width;
557}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000558
Johnny Chen1adc40c2010-08-12 20:46:17 +0000559void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
560 raw_ostream &O) {
561 unsigned val = MI->getOperand(OpNum).getImm();
562 O << ARM_MB::MemBOptToString(val);
563}
564
Bob Wilson22f5dc72010-08-16 18:27:34 +0000565void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000566 raw_ostream &O) {
567 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000568 bool isASR = (ShiftOp & (1 << 5)) != 0;
569 unsigned Amt = ShiftOp & 0x1f;
570 if (isASR)
571 O << ", asr #" << (Amt == 0 ? 32 : Amt);
572 else if (Amt)
573 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000574}
575
Jim Grosbachdde038a2011-07-20 21:40:26 +0000576void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
577 raw_ostream &O) {
578 unsigned Imm = MI->getOperand(OpNum).getImm();
579 if (Imm == 0)
580 return;
581 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
582 O << ", lsl #" << Imm;
583}
584
585void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
586 raw_ostream &O) {
587 unsigned Imm = MI->getOperand(OpNum).getImm();
588 // A shift amount of 32 is encoded as 0.
589 if (Imm == 0)
590 Imm = 32;
591 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
592 O << ", asr #" << Imm;
593}
594
Chris Lattner35c33bd2010-04-04 04:47:45 +0000595void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
596 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000597 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000598 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
599 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000600 O << getRegisterName(MI->getOperand(i).getReg());
601 }
602 O << "}";
603}
Chris Lattner4d152222009-10-19 22:23:04 +0000604
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000605void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
606 raw_ostream &O) {
607 const MCOperand &Op = MI->getOperand(OpNum);
608 if (Op.getImm())
609 O << "be";
610 else
611 O << "le";
612}
613
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000614void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
615 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000616 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000617 O << ARM_PROC::IModToString(Op.getImm());
618}
619
620void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
621 raw_ostream &O) {
622 const MCOperand &Op = MI->getOperand(OpNum);
623 unsigned IFlags = Op.getImm();
624 for (int i=2; i >= 0; --i)
625 if (IFlags & (1 << i))
626 O << ARM_PROC::IFlagsToString(1 << i);
Owen Anderson2dbb46a2011-10-05 17:16:40 +0000627
628 if (IFlags == 0)
629 O << "none";
Johnny Chen9e088762010-03-17 17:52:21 +0000630}
631
Chris Lattner35c33bd2010-04-04 04:47:45 +0000632void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
633 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000634 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000635 unsigned SpecRegRBit = Op.getImm() >> 4;
636 unsigned Mask = Op.getImm() & 0xf;
637
James Molloyacad68d2011-09-28 14:21:38 +0000638 if (getAvailableFeatures() & ARM::FeatureMClass) {
639 switch (Op.getImm()) {
640 default: assert(0 && "Unexpected mask value!");
641 case 0: O << "apsr"; return;
642 case 1: O << "iapsr"; return;
643 case 2: O << "eapsr"; return;
644 case 3: O << "xpsr"; return;
645 case 5: O << "ipsr"; return;
646 case 6: O << "epsr"; return;
647 case 7: O << "iepsr"; return;
648 case 8: O << "msp"; return;
649 case 9: O << "psp"; return;
650 case 16: O << "primask"; return;
651 case 17: O << "basepri"; return;
652 case 18: O << "basepri_max"; return;
653 case 19: O << "faultmask"; return;
654 case 20: O << "control"; return;
655 }
656 }
657
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000658 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
659 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
660 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
661 O << "APSR_";
662 switch (Mask) {
663 default: assert(0);
664 case 4: O << "g"; return;
665 case 8: O << "nzcvq"; return;
666 case 12: O << "nzcvqg"; return;
667 }
668 llvm_unreachable("Unexpected mask value!");
669 }
670
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000671 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000672 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000673 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000674 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000675
Johnny Chen9e088762010-03-17 17:52:21 +0000676 if (Mask) {
677 O << '_';
678 if (Mask & 8) O << 'f';
679 if (Mask & 4) O << 's';
680 if (Mask & 2) O << 'x';
681 if (Mask & 1) O << 'c';
682 }
683}
684
Chris Lattner35c33bd2010-04-04 04:47:45 +0000685void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
686 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000687 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
688 if (CC != ARMCC::AL)
689 O << ARMCondCodeToString(CC);
690}
691
Jim Grosbach15d78982010-09-14 22:27:15 +0000692void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000693 unsigned OpNum,
694 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000695 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
696 O << ARMCondCodeToString(CC);
697}
698
Chris Lattner35c33bd2010-04-04 04:47:45 +0000699void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
700 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000701 if (MI->getOperand(OpNum).getReg()) {
702 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
703 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000704 O << 's';
705 }
706}
707
Chris Lattner35c33bd2010-04-04 04:47:45 +0000708void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
709 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000710 O << MI->getOperand(OpNum).getImm();
711}
712
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000713void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
714 raw_ostream &O) {
715 O << "p" << MI->getOperand(OpNum).getImm();
716}
717
718void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
719 raw_ostream &O) {
720 O << "c" << MI->getOperand(OpNum).getImm();
721}
722
Chris Lattner35c33bd2010-04-04 04:47:45 +0000723void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
724 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000725 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000726}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000727
Chris Lattner35c33bd2010-04-04 04:47:45 +0000728void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
729 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000730 O << "#" << MI->getOperand(OpNum).getImm() * 4;
731}
732
733void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
734 raw_ostream &O) {
735 unsigned Imm = MI->getOperand(OpNum).getImm();
736 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000737}
Johnny Chen9e088762010-03-17 17:52:21 +0000738
Chris Lattner35c33bd2010-04-04 04:47:45 +0000739void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
740 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000741 // (3 - the number of trailing zeros) is the number of then / else.
742 unsigned Mask = MI->getOperand(OpNum).getImm();
743 unsigned CondBit0 = Mask >> 4 & 1;
744 unsigned NumTZ = CountTrailingZeros_32(Mask);
745 assert(NumTZ <= 3 && "Invalid IT mask!");
746 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
747 bool T = ((Mask >> Pos) & 1) == CondBit0;
748 if (T)
749 O << 't';
750 else
751 O << 'e';
752 }
753}
754
Chris Lattner35c33bd2010-04-04 04:47:45 +0000755void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
756 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000757 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000758 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000759
760 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000761 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000762 return;
763 }
764
765 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000766 if (unsigned RegNum = MO2.getReg())
767 O << ", " << getRegisterName(RegNum);
768 O << "]";
769}
770
771void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
772 unsigned Op,
773 raw_ostream &O,
774 unsigned Scale) {
775 const MCOperand &MO1 = MI->getOperand(Op);
776 const MCOperand &MO2 = MI->getOperand(Op + 1);
777
778 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
779 printOperand(MI, Op, O);
780 return;
781 }
782
783 O << "[" << getRegisterName(MO1.getReg());
784 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000785 O << ", #" << ImmOffs * Scale;
786 O << "]";
787}
788
Bill Wendlingf4caf692010-12-14 03:36:38 +0000789void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
790 unsigned Op,
791 raw_ostream &O) {
792 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000793}
794
Bill Wendlingf4caf692010-12-14 03:36:38 +0000795void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
796 unsigned Op,
797 raw_ostream &O) {
798 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000799}
800
Bill Wendlingf4caf692010-12-14 03:36:38 +0000801void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
802 unsigned Op,
803 raw_ostream &O) {
804 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000805}
806
Chris Lattner35c33bd2010-04-04 04:47:45 +0000807void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
808 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000809 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000810}
811
Johnny Chen9e088762010-03-17 17:52:21 +0000812// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
813// register with shift forms.
814// REG 0 0 - e.g. R5
815// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000816void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
817 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000818 const MCOperand &MO1 = MI->getOperand(OpNum);
819 const MCOperand &MO2 = MI->getOperand(OpNum+1);
820
821 unsigned Reg = MO1.getReg();
822 O << getRegisterName(Reg);
823
824 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000825 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000826 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
827 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
828 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000829 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000830}
831
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000832void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
833 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000834 const MCOperand &MO1 = MI->getOperand(OpNum);
835 const MCOperand &MO2 = MI->getOperand(OpNum+1);
836
Jim Grosbach3e556122010-10-26 22:37:02 +0000837 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
838 printOperand(MI, OpNum, O);
839 return;
840 }
841
Johnny Chen9e088762010-03-17 17:52:21 +0000842 O << "[" << getRegisterName(MO1.getReg());
843
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000844 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000845 bool isSub = OffImm < 0;
846 // Special value for #-0. All others are normal.
847 if (OffImm == INT32_MIN)
848 OffImm = 0;
849 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000850 O << ", #-" << -OffImm;
851 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000852 O << ", #" << OffImm;
853 O << "]";
854}
855
856void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000857 unsigned OpNum,
858 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000859 const MCOperand &MO1 = MI->getOperand(OpNum);
860 const MCOperand &MO2 = MI->getOperand(OpNum+1);
861
862 O << "[" << getRegisterName(MO1.getReg());
863
864 int32_t OffImm = (int32_t)MO2.getImm();
865 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000866 if (OffImm == INT32_MIN)
867 O << ", #-0";
868 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000869 O << ", #-" << -OffImm;
870 else if (OffImm > 0)
871 O << ", #" << OffImm;
872 O << "]";
873}
874
875void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000876 unsigned OpNum,
877 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000878 const MCOperand &MO1 = MI->getOperand(OpNum);
879 const MCOperand &MO2 = MI->getOperand(OpNum+1);
880
881 O << "[" << getRegisterName(MO1.getReg());
882
883 int32_t OffImm = (int32_t)MO2.getImm() / 4;
884 // Don't print +0.
885 if (OffImm < 0)
886 O << ", #-" << -OffImm * 4;
887 else if (OffImm > 0)
888 O << ", #" << OffImm * 4;
889 O << "]";
890}
891
Jim Grosbachb6aed502011-09-09 18:37:27 +0000892void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
893 unsigned OpNum,
894 raw_ostream &O) {
895 const MCOperand &MO1 = MI->getOperand(OpNum);
896 const MCOperand &MO2 = MI->getOperand(OpNum+1);
897
898 O << "[" << getRegisterName(MO1.getReg());
899 if (MO2.getImm())
900 O << ", #" << MO2.getImm() * 4;
901 O << "]";
902}
903
Johnny Chen9e088762010-03-17 17:52:21 +0000904void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000905 unsigned OpNum,
906 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000907 const MCOperand &MO1 = MI->getOperand(OpNum);
908 int32_t OffImm = (int32_t)MO1.getImm();
909 // Don't print +0.
910 if (OffImm < 0)
Owen Anderson0781c1f2011-09-23 21:26:40 +0000911 O << ", #-" << -OffImm;
912 else
913 O << ", #" << OffImm;
Johnny Chen9e088762010-03-17 17:52:21 +0000914}
915
916void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000917 unsigned OpNum,
918 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000919 const MCOperand &MO1 = MI->getOperand(OpNum);
920 int32_t OffImm = (int32_t)MO1.getImm() / 4;
921 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000922 if (OffImm != 0) {
923 O << ", ";
924 if (OffImm < 0)
925 O << "#-" << -OffImm * 4;
926 else if (OffImm > 0)
927 O << "#" << OffImm * 4;
928 }
Johnny Chen9e088762010-03-17 17:52:21 +0000929}
930
931void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000932 unsigned OpNum,
933 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000934 const MCOperand &MO1 = MI->getOperand(OpNum);
935 const MCOperand &MO2 = MI->getOperand(OpNum+1);
936 const MCOperand &MO3 = MI->getOperand(OpNum+2);
937
938 O << "[" << getRegisterName(MO1.getReg());
939
940 assert(MO2.getReg() && "Invalid so_reg load / store address!");
941 O << ", " << getRegisterName(MO2.getReg());
942
943 unsigned ShAmt = MO3.getImm();
944 if (ShAmt) {
945 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
946 O << ", lsl #" << ShAmt;
947 }
948 O << "]";
949}
950
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000951void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
952 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000953 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000954 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000955}
956
Bob Wilson1a913ed2010-06-11 21:34:50 +0000957void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
958 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000959 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
960 unsigned EltBits;
961 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000962 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000963}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000964
Jim Grosbachf4943352011-07-25 23:09:14 +0000965void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
966 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000967 unsigned Imm = MI->getOperand(OpNum).getImm();
968 O << "#" << Imm + 1;
969}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000970
971void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
972 raw_ostream &O) {
973 unsigned Imm = MI->getOperand(OpNum).getImm();
974 if (Imm == 0)
975 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000976 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000977 switch (Imm) {
978 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000979 case 1: O << "8"; break;
980 case 2: O << "16"; break;
981 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000982 }
983}
Jim Grosbach460a9052011-10-07 23:56:00 +0000984
985void ARMInstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
986 raw_ostream &O) {
987 O << "[" << MI->getOperand(OpNum).getImm() << "]";
988}