blob: e70f8460d6f1e016096a16d5faea7c64af6c1fc5 [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);
Johnny Chen9e088762010-03-17 17:52:21 +0000627}
628
Chris Lattner35c33bd2010-04-04 04:47:45 +0000629void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
630 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000631 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000632 unsigned SpecRegRBit = Op.getImm() >> 4;
633 unsigned Mask = Op.getImm() & 0xf;
634
James Molloyacad68d2011-09-28 14:21:38 +0000635 if (getAvailableFeatures() & ARM::FeatureMClass) {
636 switch (Op.getImm()) {
637 default: assert(0 && "Unexpected mask value!");
638 case 0: O << "apsr"; return;
639 case 1: O << "iapsr"; return;
640 case 2: O << "eapsr"; return;
641 case 3: O << "xpsr"; return;
642 case 5: O << "ipsr"; return;
643 case 6: O << "epsr"; return;
644 case 7: O << "iepsr"; return;
645 case 8: O << "msp"; return;
646 case 9: O << "psp"; return;
647 case 16: O << "primask"; return;
648 case 17: O << "basepri"; return;
649 case 18: O << "basepri_max"; return;
650 case 19: O << "faultmask"; return;
651 case 20: O << "control"; return;
652 }
653 }
654
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000655 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
656 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
657 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
658 O << "APSR_";
659 switch (Mask) {
660 default: assert(0);
661 case 4: O << "g"; return;
662 case 8: O << "nzcvq"; return;
663 case 12: O << "nzcvqg"; return;
664 }
665 llvm_unreachable("Unexpected mask value!");
666 }
667
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000668 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000669 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000670 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000671 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000672
Johnny Chen9e088762010-03-17 17:52:21 +0000673 if (Mask) {
674 O << '_';
675 if (Mask & 8) O << 'f';
676 if (Mask & 4) O << 's';
677 if (Mask & 2) O << 'x';
678 if (Mask & 1) O << 'c';
679 }
680}
681
Chris Lattner35c33bd2010-04-04 04:47:45 +0000682void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
683 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000684 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
685 if (CC != ARMCC::AL)
686 O << ARMCondCodeToString(CC);
687}
688
Jim Grosbach15d78982010-09-14 22:27:15 +0000689void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000690 unsigned OpNum,
691 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000692 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
693 O << ARMCondCodeToString(CC);
694}
695
Chris Lattner35c33bd2010-04-04 04:47:45 +0000696void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
697 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000698 if (MI->getOperand(OpNum).getReg()) {
699 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
700 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000701 O << 's';
702 }
703}
704
Chris Lattner35c33bd2010-04-04 04:47:45 +0000705void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
706 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000707 O << MI->getOperand(OpNum).getImm();
708}
709
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000710void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
711 raw_ostream &O) {
712 O << "p" << MI->getOperand(OpNum).getImm();
713}
714
715void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
716 raw_ostream &O) {
717 O << "c" << MI->getOperand(OpNum).getImm();
718}
719
Chris Lattner35c33bd2010-04-04 04:47:45 +0000720void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
721 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000722 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000723}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000724
Chris Lattner35c33bd2010-04-04 04:47:45 +0000725void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
726 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000727 O << "#" << MI->getOperand(OpNum).getImm() * 4;
728}
729
730void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
731 raw_ostream &O) {
732 unsigned Imm = MI->getOperand(OpNum).getImm();
733 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000734}
Johnny Chen9e088762010-03-17 17:52:21 +0000735
Chris Lattner35c33bd2010-04-04 04:47:45 +0000736void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
737 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000738 // (3 - the number of trailing zeros) is the number of then / else.
739 unsigned Mask = MI->getOperand(OpNum).getImm();
740 unsigned CondBit0 = Mask >> 4 & 1;
741 unsigned NumTZ = CountTrailingZeros_32(Mask);
742 assert(NumTZ <= 3 && "Invalid IT mask!");
743 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
744 bool T = ((Mask >> Pos) & 1) == CondBit0;
745 if (T)
746 O << 't';
747 else
748 O << 'e';
749 }
750}
751
Chris Lattner35c33bd2010-04-04 04:47:45 +0000752void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
753 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000754 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000755 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000756
757 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000758 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000759 return;
760 }
761
762 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000763 if (unsigned RegNum = MO2.getReg())
764 O << ", " << getRegisterName(RegNum);
765 O << "]";
766}
767
768void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
769 unsigned Op,
770 raw_ostream &O,
771 unsigned Scale) {
772 const MCOperand &MO1 = MI->getOperand(Op);
773 const MCOperand &MO2 = MI->getOperand(Op + 1);
774
775 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
776 printOperand(MI, Op, O);
777 return;
778 }
779
780 O << "[" << getRegisterName(MO1.getReg());
781 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000782 O << ", #" << ImmOffs * Scale;
783 O << "]";
784}
785
Bill Wendlingf4caf692010-12-14 03:36:38 +0000786void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
787 unsigned Op,
788 raw_ostream &O) {
789 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000790}
791
Bill Wendlingf4caf692010-12-14 03:36:38 +0000792void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
793 unsigned Op,
794 raw_ostream &O) {
795 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000796}
797
Bill Wendlingf4caf692010-12-14 03:36:38 +0000798void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
799 unsigned Op,
800 raw_ostream &O) {
801 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000802}
803
Chris Lattner35c33bd2010-04-04 04:47:45 +0000804void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
805 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000806 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000807}
808
Johnny Chen9e088762010-03-17 17:52:21 +0000809// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
810// register with shift forms.
811// REG 0 0 - e.g. R5
812// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000813void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
814 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000815 const MCOperand &MO1 = MI->getOperand(OpNum);
816 const MCOperand &MO2 = MI->getOperand(OpNum+1);
817
818 unsigned Reg = MO1.getReg();
819 O << getRegisterName(Reg);
820
821 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000822 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000823 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
824 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
825 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000826 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000827}
828
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000829void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
830 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000831 const MCOperand &MO1 = MI->getOperand(OpNum);
832 const MCOperand &MO2 = MI->getOperand(OpNum+1);
833
Jim Grosbach3e556122010-10-26 22:37:02 +0000834 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
835 printOperand(MI, OpNum, O);
836 return;
837 }
838
Johnny Chen9e088762010-03-17 17:52:21 +0000839 O << "[" << getRegisterName(MO1.getReg());
840
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000841 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000842 bool isSub = OffImm < 0;
843 // Special value for #-0. All others are normal.
844 if (OffImm == INT32_MIN)
845 OffImm = 0;
846 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000847 O << ", #-" << -OffImm;
848 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000849 O << ", #" << OffImm;
850 O << "]";
851}
852
853void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000854 unsigned OpNum,
855 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000856 const MCOperand &MO1 = MI->getOperand(OpNum);
857 const MCOperand &MO2 = MI->getOperand(OpNum+1);
858
859 O << "[" << getRegisterName(MO1.getReg());
860
861 int32_t OffImm = (int32_t)MO2.getImm();
862 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000863 if (OffImm == INT32_MIN)
864 O << ", #-0";
865 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000866 O << ", #-" << -OffImm;
867 else if (OffImm > 0)
868 O << ", #" << OffImm;
869 O << "]";
870}
871
872void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000873 unsigned OpNum,
874 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000875 const MCOperand &MO1 = MI->getOperand(OpNum);
876 const MCOperand &MO2 = MI->getOperand(OpNum+1);
877
878 O << "[" << getRegisterName(MO1.getReg());
879
880 int32_t OffImm = (int32_t)MO2.getImm() / 4;
881 // Don't print +0.
882 if (OffImm < 0)
883 O << ", #-" << -OffImm * 4;
884 else if (OffImm > 0)
885 O << ", #" << OffImm * 4;
886 O << "]";
887}
888
Jim Grosbachb6aed502011-09-09 18:37:27 +0000889void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
890 unsigned OpNum,
891 raw_ostream &O) {
892 const MCOperand &MO1 = MI->getOperand(OpNum);
893 const MCOperand &MO2 = MI->getOperand(OpNum+1);
894
895 O << "[" << getRegisterName(MO1.getReg());
896 if (MO2.getImm())
897 O << ", #" << MO2.getImm() * 4;
898 O << "]";
899}
900
Johnny Chen9e088762010-03-17 17:52:21 +0000901void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000902 unsigned OpNum,
903 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000904 const MCOperand &MO1 = MI->getOperand(OpNum);
905 int32_t OffImm = (int32_t)MO1.getImm();
906 // Don't print +0.
907 if (OffImm < 0)
Owen Anderson0781c1f2011-09-23 21:26:40 +0000908 O << ", #-" << -OffImm;
909 else
910 O << ", #" << OffImm;
Johnny Chen9e088762010-03-17 17:52:21 +0000911}
912
913void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000914 unsigned OpNum,
915 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000916 const MCOperand &MO1 = MI->getOperand(OpNum);
917 int32_t OffImm = (int32_t)MO1.getImm() / 4;
918 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000919 if (OffImm != 0) {
920 O << ", ";
921 if (OffImm < 0)
922 O << "#-" << -OffImm * 4;
923 else if (OffImm > 0)
924 O << "#" << OffImm * 4;
925 }
Johnny Chen9e088762010-03-17 17:52:21 +0000926}
927
928void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000929 unsigned OpNum,
930 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000931 const MCOperand &MO1 = MI->getOperand(OpNum);
932 const MCOperand &MO2 = MI->getOperand(OpNum+1);
933 const MCOperand &MO3 = MI->getOperand(OpNum+2);
934
935 O << "[" << getRegisterName(MO1.getReg());
936
937 assert(MO2.getReg() && "Invalid so_reg load / store address!");
938 O << ", " << getRegisterName(MO2.getReg());
939
940 unsigned ShAmt = MO3.getImm();
941 if (ShAmt) {
942 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
943 O << ", lsl #" << ShAmt;
944 }
945 O << "]";
946}
947
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000948void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
949 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000950 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000951 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000952}
953
Bob Wilson1a913ed2010-06-11 21:34:50 +0000954void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
955 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000956 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
957 unsigned EltBits;
958 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000959 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000960}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000961
Jim Grosbachf4943352011-07-25 23:09:14 +0000962void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
963 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000964 unsigned Imm = MI->getOperand(OpNum).getImm();
965 O << "#" << Imm + 1;
966}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000967
968void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
969 raw_ostream &O) {
970 unsigned Imm = MI->getOperand(OpNum).getImm();
971 if (Imm == 0)
972 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000973 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000974 switch (Imm) {
975 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000976 case 1: O << "8"; break;
977 case 2: O << "16"; break;
978 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000979 }
980}