blob: df79603cb0f3321124c1c4b86aa530e003b543fd [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///
Jim Grosbach01208d52011-10-12 16:36:01 +000030/// getSORegOffset returns an integer from 0-31, representing '32' as 0.
Owen Anderson3dac0be2011-08-11 18:41:59 +000031static unsigned translateShiftImm(unsigned imm) {
32 if (imm == 0)
33 return 32;
34 return imm;
35}
36
James Molloyb9505852011-09-07 17:24:38 +000037
38ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
39 const MCSubtargetInfo &STI) :
40 MCInstPrinter(MAI) {
41 // Initialize the set of available features.
42 setAvailableFeatures(STI.getFeatureBits());
43}
44
Chris Lattner6274ec42010-10-28 21:37:33 +000045StringRef ARMInstPrinter::getOpcodeName(unsigned Opcode) const {
46 return getInstructionName(Opcode);
47}
48
Rafael Espindolacde4ce42011-06-02 02:34:55 +000049void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
50 OS << getRegisterName(RegNo);
Anton Korobeynikov57caad72011-03-05 18:43:32 +000051}
Chris Lattner6274ec42010-10-28 21:37:33 +000052
Owen Anderson98c5dda2011-09-15 23:38:46 +000053void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
54 StringRef Annot) {
Bill Wendling04863d02010-11-13 10:40:19 +000055 unsigned Opcode = MI->getOpcode();
56
Johnny Chen9e088762010-03-17 17:52:21 +000057 // Check for MOVs and print canonical forms, instead.
Owen Anderson152d4a42011-07-21 23:38:37 +000058 if (Opcode == ARM::MOVsr) {
Jim Grosbache6be85e2010-09-17 22:36:38 +000059 // FIXME: Thumb variants?
Johnny Chen9e088762010-03-17 17:52:21 +000060 const MCOperand &Dst = MI->getOperand(0);
61 const MCOperand &MO1 = MI->getOperand(1);
62 const MCOperand &MO2 = MI->getOperand(2);
63 const MCOperand &MO3 = MI->getOperand(3);
64
65 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner35c33bd2010-04-04 04:47:45 +000066 printSBitModifierOperand(MI, 6, O);
67 printPredicateOperand(MI, 4, O);
Johnny Chen9e088762010-03-17 17:52:21 +000068
69 O << '\t' << getRegisterName(Dst.getReg())
70 << ", " << getRegisterName(MO1.getReg());
71
Owen Anderson152d4a42011-07-21 23:38:37 +000072 O << ", " << getRegisterName(MO2.getReg());
73 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Owen Anderson519020a2011-09-21 17:58:45 +000074 printAnnotation(O, Annot);
Johnny Chen9e088762010-03-17 17:52:21 +000075 return;
76 }
77
Owen Anderson152d4a42011-07-21 23:38:37 +000078 if (Opcode == ARM::MOVsi) {
79 // FIXME: Thumb variants?
80 const MCOperand &Dst = MI->getOperand(0);
81 const MCOperand &MO1 = MI->getOperand(1);
82 const MCOperand &MO2 = MI->getOperand(2);
83
84 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
85 printSBitModifierOperand(MI, 5, O);
86 printPredicateOperand(MI, 3, O);
87
88 O << '\t' << getRegisterName(Dst.getReg())
89 << ", " << getRegisterName(MO1.getReg());
90
Owen Andersonede042d2011-09-15 18:36:29 +000091 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
Owen Anderson519020a2011-09-21 17:58:45 +000092 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000093 return;
Owen Andersonede042d2011-09-15 18:36:29 +000094 }
Owen Anderson152d4a42011-07-21 23:38:37 +000095
Owen Anderson3dac0be2011-08-11 18:41:59 +000096 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson519020a2011-09-21 17:58:45 +000097 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000098 return;
99 }
100
101
Johnny Chen9e088762010-03-17 17:52:21 +0000102 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000103 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000104 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000105 O << '\t' << "push";
106 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000107 if (Opcode == ARM::t2STMDB_UPD)
108 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000109 O << '\t';
110 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000111 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000112 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000113 }
Jim Grosbachf6713912011-08-11 18:07:11 +0000114 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
115 MI->getOperand(3).getImm() == -4) {
116 O << '\t' << "push";
117 printPredicateOperand(MI, 4, O);
118 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000119 printAnnotation(O, Annot);
Jim Grosbachf6713912011-08-11 18:07:11 +0000120 return;
121 }
Johnny Chen9e088762010-03-17 17:52:21 +0000122
123 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000124 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000125 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000126 O << '\t' << "pop";
127 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000128 if (Opcode == ARM::t2LDMIA_UPD)
129 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000130 O << '\t';
131 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000132 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000133 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000134 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000135 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
136 MI->getOperand(4).getImm() == 4) {
137 O << '\t' << "pop";
138 printPredicateOperand(MI, 5, O);
139 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000140 printAnnotation(O, Annot);
Jim Grosbachf8fce712011-08-11 17:35:48 +0000141 return;
142 }
143
Johnny Chen9e088762010-03-17 17:52:21 +0000144
145 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000146 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000147 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000148 O << '\t' << "vpush";
149 printPredicateOperand(MI, 2, O);
150 O << '\t';
151 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000152 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000153 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000154 }
155
156 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000157 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000158 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000159 O << '\t' << "vpop";
160 printPredicateOperand(MI, 2, O);
161 O << '\t';
162 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000163 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000164 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000165 }
166
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000167 if (Opcode == ARM::tLDMIA) {
Owen Anderson565a0362011-07-18 23:25:34 +0000168 bool Writeback = true;
169 unsigned BaseReg = MI->getOperand(0).getReg();
170 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
171 if (MI->getOperand(i).getReg() == BaseReg)
172 Writeback = false;
173 }
174
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000175 O << "\tldm";
Owen Anderson565a0362011-07-18 23:25:34 +0000176
177 printPredicateOperand(MI, 1, O);
178 O << '\t' << getRegisterName(BaseReg);
179 if (Writeback) O << "!";
180 O << ", ";
181 printRegisterList(MI, 3, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000182 printAnnotation(O, Annot);
Owen Anderson565a0362011-07-18 23:25:34 +0000183 return;
184 }
185
Jim Grosbach0780b632011-08-19 23:24:36 +0000186 // Thumb1 NOP
187 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
188 MI->getOperand(1).getReg() == ARM::R8) {
189 O << "\tnop";
Jim Grosbachdf9ce6b2011-08-24 20:06:14 +0000190 printPredicateOperand(MI, 2, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000191 printAnnotation(O, Annot);
Jim Grosbach0780b632011-08-19 23:24:36 +0000192 return;
193 }
194
Chris Lattner35c33bd2010-04-04 04:47:45 +0000195 printInstruction(MI, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000196 printAnnotation(O, Annot);
Bill Wendling04863d02010-11-13 10:40:19 +0000197}
Chris Lattnerfd603822009-10-19 19:56:26 +0000198
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000199void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000200 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000201 const MCOperand &Op = MI->getOperand(OpNo);
202 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000203 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000204 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000205 } else if (Op.isImm()) {
206 O << '#' << Op.getImm();
207 } else {
208 assert(Op.isExpr() && "unknown operand kind in printOperand");
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000209 // If a symbolic branch target was added as a constant expression then print
210 // that address in hex.
211 const MCConstantExpr *BranchTarget = dyn_cast<MCConstantExpr>(Op.getExpr());
212 int64_t Address;
213 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
214 O << "0x";
215 O.write_hex(Address);
216 }
217 else {
218 // Otherwise, just print the expression.
219 O << *Op.getExpr();
220 }
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000221 }
222}
Chris Lattner61d35c22009-10-19 21:21:39 +0000223
Owen Andersone1368722011-09-21 23:44:46 +0000224void ARMInstPrinter::printT2LdrLabelOperand(const MCInst *MI, unsigned OpNum,
225 raw_ostream &O) {
226 const MCOperand &MO1 = MI->getOperand(OpNum);
227 if (MO1.isExpr())
228 O << *MO1.getExpr();
229 else if (MO1.isImm())
230 O << "[pc, #" << MO1.getImm() << "]";
231 else
232 llvm_unreachable("Unknown LDR label operand?");
233}
234
Chris Lattner017d9472009-10-20 00:40:56 +0000235// so_reg is a 4-operand unit corresponding to register forms of the A5.1
236// "Addressing Mode 1 - Data-processing operands" forms. This includes:
237// REG 0 0 - e.g. R5
238// REG REG 0,SH_OPC - e.g. R5, ROR R3
239// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000240void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000241 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000242 const MCOperand &MO1 = MI->getOperand(OpNum);
243 const MCOperand &MO2 = MI->getOperand(OpNum+1);
244 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000245
Chris Lattner017d9472009-10-20 00:40:56 +0000246 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000247
Chris Lattner017d9472009-10-20 00:40:56 +0000248 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000249 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
250 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000251 if (ShOpc == ARM_AM::rrx)
252 return;
Jim Grosbach293a5f62011-10-21 16:56:40 +0000253
Owen Anderson152d4a42011-07-21 23:38:37 +0000254 O << ' ' << getRegisterName(MO2.getReg());
255 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000256}
Chris Lattner084f87d2009-10-19 21:57:05 +0000257
Owen Anderson152d4a42011-07-21 23:38:37 +0000258void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
259 raw_ostream &O) {
260 const MCOperand &MO1 = MI->getOperand(OpNum);
261 const MCOperand &MO2 = MI->getOperand(OpNum+1);
262
263 O << getRegisterName(MO1.getReg());
264
265 // Print the shift opc.
266 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
267 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
268 if (ShOpc == ARM_AM::rrx)
269 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000270 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000271}
272
273
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000274//===--------------------------------------------------------------------===//
275// Addressing Mode #2
276//===--------------------------------------------------------------------===//
277
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000278void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
279 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000280 const MCOperand &MO1 = MI->getOperand(Op);
281 const MCOperand &MO2 = MI->getOperand(Op+1);
282 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000283
Chris Lattner084f87d2009-10-19 21:57:05 +0000284 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000285
Chris Lattner084f87d2009-10-19 21:57:05 +0000286 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000287 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000288 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000289 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
290 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000291 O << "]";
292 return;
293 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000294
Chris Lattner084f87d2009-10-19 21:57:05 +0000295 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000296 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
297 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000298
Chris Lattner084f87d2009-10-19 21:57:05 +0000299 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
300 O << ", "
301 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
302 << " #" << ShImm;
303 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000304}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000305
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000306void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
307 raw_ostream &O) {
308 const MCOperand &MO1 = MI->getOperand(Op);
309 const MCOperand &MO2 = MI->getOperand(Op+1);
310 const MCOperand &MO3 = MI->getOperand(Op+2);
311
312 O << "[" << getRegisterName(MO1.getReg()) << "], ";
313
314 if (!MO2.getReg()) {
315 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
316 O << '#'
317 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
318 << ImmOffs;
319 return;
320 }
321
322 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
323 << getRegisterName(MO2.getReg());
324
325 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
326 O << ", "
327 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
328 << " #" << ShImm;
329}
330
Jim Grosbach7f739be2011-09-19 22:21:13 +0000331void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
332 raw_ostream &O) {
333 const MCOperand &MO1 = MI->getOperand(Op);
334 const MCOperand &MO2 = MI->getOperand(Op+1);
335 O << "[" << getRegisterName(MO1.getReg()) << ", "
336 << getRegisterName(MO2.getReg()) << "]";
337}
338
339void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
340 raw_ostream &O) {
341 const MCOperand &MO1 = MI->getOperand(Op);
342 const MCOperand &MO2 = MI->getOperand(Op+1);
343 O << "[" << getRegisterName(MO1.getReg()) << ", "
344 << getRegisterName(MO2.getReg()) << ", lsl #1]";
345}
346
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000347void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
348 raw_ostream &O) {
349 const MCOperand &MO1 = MI->getOperand(Op);
350
351 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
352 printOperand(MI, Op, O);
353 return;
354 }
355
356 const MCOperand &MO3 = MI->getOperand(Op+2);
357 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
358
359 if (IdxMode == ARMII::IndexModePost) {
360 printAM2PostIndexOp(MI, Op, O);
361 return;
362 }
363 printAM2PreOrOffsetIndexOp(MI, Op, O);
364}
365
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000366void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000367 unsigned OpNum,
368 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000369 const MCOperand &MO1 = MI->getOperand(OpNum);
370 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000371
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000372 if (!MO1.getReg()) {
373 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000374 O << '#'
375 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
376 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000377 return;
378 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000379
Johnny Chen9e088762010-03-17 17:52:21 +0000380 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
381 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000382
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000383 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
384 O << ", "
385 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
386 << " #" << ShImm;
387}
388
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000389//===--------------------------------------------------------------------===//
390// Addressing Mode #3
391//===--------------------------------------------------------------------===//
392
393void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
394 raw_ostream &O) {
395 const MCOperand &MO1 = MI->getOperand(Op);
396 const MCOperand &MO2 = MI->getOperand(Op+1);
397 const MCOperand &MO3 = MI->getOperand(Op+2);
398
399 O << "[" << getRegisterName(MO1.getReg()) << "], ";
400
401 if (MO2.getReg()) {
402 O << (char)ARM_AM::getAM3Op(MO3.getImm())
403 << getRegisterName(MO2.getReg());
404 return;
405 }
406
407 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
408 O << '#'
409 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
410 << ImmOffs;
411}
412
413void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
414 raw_ostream &O) {
415 const MCOperand &MO1 = MI->getOperand(Op);
416 const MCOperand &MO2 = MI->getOperand(Op+1);
417 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000418
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000419 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000420
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000421 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000422 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000423 << getRegisterName(MO2.getReg()) << ']';
424 return;
425 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000426
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000427 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
428 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000429 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
430 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000431 O << ']';
432}
433
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000434void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
435 raw_ostream &O) {
436 const MCOperand &MO3 = MI->getOperand(Op+2);
437 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
438
439 if (IdxMode == ARMII::IndexModePost) {
440 printAM3PostIndexOp(MI, Op, O);
441 return;
442 }
443 printAM3PreOrOffsetIndexOp(MI, Op, O);
444}
445
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000446void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000447 unsigned OpNum,
448 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000449 const MCOperand &MO1 = MI->getOperand(OpNum);
450 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000451
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000452 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000453 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
454 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000455 return;
456 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000457
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000458 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000459 O << '#'
460 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
461 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000462}
463
Jim Grosbach7ce05792011-08-03 23:50:40 +0000464void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
465 unsigned OpNum,
466 raw_ostream &O) {
467 const MCOperand &MO = MI->getOperand(OpNum);
468 unsigned Imm = MO.getImm();
469 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
470}
471
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000472void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
473 raw_ostream &O) {
474 const MCOperand &MO1 = MI->getOperand(OpNum);
475 const MCOperand &MO2 = MI->getOperand(OpNum+1);
476
Jim Grosbach16578b52011-08-05 16:11:38 +0000477 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000478}
479
Owen Anderson154c41d2011-08-04 18:24:14 +0000480void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
481 unsigned OpNum,
482 raw_ostream &O) {
483 const MCOperand &MO = MI->getOperand(OpNum);
484 unsigned Imm = MO.getImm();
485 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
486}
487
488
Jim Grosbache6913602010-11-03 01:01:43 +0000489void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000490 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000491 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
492 .getImm());
493 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000494}
495
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000496void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000497 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000498 const MCOperand &MO1 = MI->getOperand(OpNum);
499 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000500
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000501 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000502 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000503 return;
504 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000505
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000506 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000507
Owen Anderson0da10cf2011-08-29 19:36:44 +0000508 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
509 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
510 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000511 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000512 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000513 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000514 }
515 O << "]";
516}
517
Chris Lattner35c33bd2010-04-04 04:47:45 +0000518void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
519 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000520 const MCOperand &MO1 = MI->getOperand(OpNum);
521 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000522
Bob Wilson226036e2010-03-20 22:13:40 +0000523 O << "[" << getRegisterName(MO1.getReg());
524 if (MO2.getImm()) {
525 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000526 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000527 }
Bob Wilson226036e2010-03-20 22:13:40 +0000528 O << "]";
529}
530
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000531void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
532 raw_ostream &O) {
533 const MCOperand &MO1 = MI->getOperand(OpNum);
534 O << "[" << getRegisterName(MO1.getReg()) << "]";
535}
536
Bob Wilson226036e2010-03-20 22:13:40 +0000537void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000538 unsigned OpNum,
539 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000540 const MCOperand &MO = MI->getOperand(OpNum);
541 if (MO.getReg() == 0)
542 O << "!";
543 else
544 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000545}
546
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000547void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
548 unsigned OpNum,
549 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000550 const MCOperand &MO = MI->getOperand(OpNum);
551 uint32_t v = ~MO.getImm();
552 int32_t lsb = CountTrailingZeros_32(v);
553 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
554 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
555 O << '#' << lsb << ", #" << width;
556}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000557
Johnny Chen1adc40c2010-08-12 20:46:17 +0000558void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
559 raw_ostream &O) {
560 unsigned val = MI->getOperand(OpNum).getImm();
561 O << ARM_MB::MemBOptToString(val);
562}
563
Bob Wilson22f5dc72010-08-16 18:27:34 +0000564void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000565 raw_ostream &O) {
566 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000567 bool isASR = (ShiftOp & (1 << 5)) != 0;
568 unsigned Amt = ShiftOp & 0x1f;
569 if (isASR)
570 O << ", asr #" << (Amt == 0 ? 32 : Amt);
571 else if (Amt)
572 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000573}
574
Jim Grosbachdde038a2011-07-20 21:40:26 +0000575void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
576 raw_ostream &O) {
577 unsigned Imm = MI->getOperand(OpNum).getImm();
578 if (Imm == 0)
579 return;
580 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
581 O << ", lsl #" << Imm;
582}
583
584void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
585 raw_ostream &O) {
586 unsigned Imm = MI->getOperand(OpNum).getImm();
587 // A shift amount of 32 is encoded as 0.
588 if (Imm == 0)
589 Imm = 32;
590 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
591 O << ", asr #" << Imm;
592}
593
Chris Lattner35c33bd2010-04-04 04:47:45 +0000594void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
595 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000596 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000597 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
598 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000599 O << getRegisterName(MI->getOperand(i).getReg());
600 }
601 O << "}";
602}
Chris Lattner4d152222009-10-19 22:23:04 +0000603
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000604void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
605 raw_ostream &O) {
606 const MCOperand &Op = MI->getOperand(OpNum);
607 if (Op.getImm())
608 O << "be";
609 else
610 O << "le";
611}
612
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000613void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
614 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000615 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000616 O << ARM_PROC::IModToString(Op.getImm());
617}
618
619void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
620 raw_ostream &O) {
621 const MCOperand &Op = MI->getOperand(OpNum);
622 unsigned IFlags = Op.getImm();
623 for (int i=2; i >= 0; --i)
624 if (IFlags & (1 << i))
625 O << ARM_PROC::IFlagsToString(1 << i);
Owen Anderson2dbb46a2011-10-05 17:16:40 +0000626
627 if (IFlags == 0)
628 O << "none";
Johnny Chen9e088762010-03-17 17:52:21 +0000629}
630
Chris Lattner35c33bd2010-04-04 04:47:45 +0000631void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
632 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000633 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000634 unsigned SpecRegRBit = Op.getImm() >> 4;
635 unsigned Mask = Op.getImm() & 0xf;
636
James Molloyacad68d2011-09-28 14:21:38 +0000637 if (getAvailableFeatures() & ARM::FeatureMClass) {
638 switch (Op.getImm()) {
639 default: assert(0 && "Unexpected mask value!");
640 case 0: O << "apsr"; return;
641 case 1: O << "iapsr"; return;
642 case 2: O << "eapsr"; return;
643 case 3: O << "xpsr"; return;
644 case 5: O << "ipsr"; return;
645 case 6: O << "epsr"; return;
646 case 7: O << "iepsr"; return;
647 case 8: O << "msp"; return;
648 case 9: O << "psp"; return;
649 case 16: O << "primask"; return;
650 case 17: O << "basepri"; return;
651 case 18: O << "basepri_max"; return;
652 case 19: O << "faultmask"; return;
653 case 20: O << "control"; return;
654 }
655 }
656
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000657 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
658 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
659 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
660 O << "APSR_";
661 switch (Mask) {
662 default: assert(0);
663 case 4: O << "g"; return;
664 case 8: O << "nzcvq"; return;
665 case 12: O << "nzcvqg"; return;
666 }
667 llvm_unreachable("Unexpected mask value!");
668 }
669
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000670 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000671 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000672 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000673 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000674
Johnny Chen9e088762010-03-17 17:52:21 +0000675 if (Mask) {
676 O << '_';
677 if (Mask & 8) O << 'f';
678 if (Mask & 4) O << 's';
679 if (Mask & 2) O << 'x';
680 if (Mask & 1) O << 'c';
681 }
682}
683
Chris Lattner35c33bd2010-04-04 04:47:45 +0000684void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
685 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000686 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
687 if (CC != ARMCC::AL)
688 O << ARMCondCodeToString(CC);
689}
690
Jim Grosbach15d78982010-09-14 22:27:15 +0000691void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000692 unsigned OpNum,
693 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000694 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
695 O << ARMCondCodeToString(CC);
696}
697
Chris Lattner35c33bd2010-04-04 04:47:45 +0000698void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
699 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000700 if (MI->getOperand(OpNum).getReg()) {
701 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
702 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000703 O << 's';
704 }
705}
706
Chris Lattner35c33bd2010-04-04 04:47:45 +0000707void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
708 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000709 O << MI->getOperand(OpNum).getImm();
710}
711
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000712void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbachbc9c8022011-10-12 16:34:37 +0000713 raw_ostream &O) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000714 O << "p" << MI->getOperand(OpNum).getImm();
715}
716
717void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbachbc9c8022011-10-12 16:34:37 +0000718 raw_ostream &O) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000719 O << "c" << MI->getOperand(OpNum).getImm();
720}
721
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000722void ARMInstPrinter::printCoprocOptionImm(const MCInst *MI, unsigned OpNum,
723 raw_ostream &O) {
724 O << "{" << MI->getOperand(OpNum).getImm() << "}";
725}
726
Chris Lattner35c33bd2010-04-04 04:47:45 +0000727void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
728 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000729 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000730}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000731
Chris Lattner35c33bd2010-04-04 04:47:45 +0000732void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
733 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000734 O << "#" << MI->getOperand(OpNum).getImm() * 4;
735}
736
737void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
738 raw_ostream &O) {
739 unsigned Imm = MI->getOperand(OpNum).getImm();
740 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000741}
Johnny Chen9e088762010-03-17 17:52:21 +0000742
Chris Lattner35c33bd2010-04-04 04:47:45 +0000743void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
744 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000745 // (3 - the number of trailing zeros) is the number of then / else.
746 unsigned Mask = MI->getOperand(OpNum).getImm();
747 unsigned CondBit0 = Mask >> 4 & 1;
748 unsigned NumTZ = CountTrailingZeros_32(Mask);
749 assert(NumTZ <= 3 && "Invalid IT mask!");
750 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
751 bool T = ((Mask >> Pos) & 1) == CondBit0;
752 if (T)
753 O << 't';
754 else
755 O << 'e';
756 }
757}
758
Chris Lattner35c33bd2010-04-04 04:47:45 +0000759void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
760 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000761 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000762 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000763
764 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000765 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000766 return;
767 }
768
769 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000770 if (unsigned RegNum = MO2.getReg())
771 O << ", " << getRegisterName(RegNum);
772 O << "]";
773}
774
775void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
776 unsigned Op,
777 raw_ostream &O,
778 unsigned Scale) {
779 const MCOperand &MO1 = MI->getOperand(Op);
780 const MCOperand &MO2 = MI->getOperand(Op + 1);
781
782 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
783 printOperand(MI, Op, O);
784 return;
785 }
786
787 O << "[" << getRegisterName(MO1.getReg());
788 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000789 O << ", #" << ImmOffs * Scale;
790 O << "]";
791}
792
Bill Wendlingf4caf692010-12-14 03:36:38 +0000793void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
794 unsigned Op,
795 raw_ostream &O) {
796 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000797}
798
Bill Wendlingf4caf692010-12-14 03:36:38 +0000799void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
800 unsigned Op,
801 raw_ostream &O) {
802 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000803}
804
Bill Wendlingf4caf692010-12-14 03:36:38 +0000805void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
806 unsigned Op,
807 raw_ostream &O) {
808 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000809}
810
Chris Lattner35c33bd2010-04-04 04:47:45 +0000811void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
812 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000813 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000814}
815
Johnny Chen9e088762010-03-17 17:52:21 +0000816// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
817// register with shift forms.
818// REG 0 0 - e.g. R5
819// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000820void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
821 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000822 const MCOperand &MO1 = MI->getOperand(OpNum);
823 const MCOperand &MO2 = MI->getOperand(OpNum+1);
824
825 unsigned Reg = MO1.getReg();
826 O << getRegisterName(Reg);
827
828 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000829 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000830 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
831 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
832 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000833 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000834}
835
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000836void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
837 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000838 const MCOperand &MO1 = MI->getOperand(OpNum);
839 const MCOperand &MO2 = MI->getOperand(OpNum+1);
840
Jim Grosbach3e556122010-10-26 22:37:02 +0000841 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
842 printOperand(MI, OpNum, O);
843 return;
844 }
845
Johnny Chen9e088762010-03-17 17:52:21 +0000846 O << "[" << getRegisterName(MO1.getReg());
847
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000848 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000849 bool isSub = OffImm < 0;
850 // Special value for #-0. All others are normal.
851 if (OffImm == INT32_MIN)
852 OffImm = 0;
853 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000854 O << ", #-" << -OffImm;
855 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000856 O << ", #" << OffImm;
857 O << "]";
858}
859
860void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000861 unsigned OpNum,
862 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000863 const MCOperand &MO1 = MI->getOperand(OpNum);
864 const MCOperand &MO2 = MI->getOperand(OpNum+1);
865
866 O << "[" << getRegisterName(MO1.getReg());
867
868 int32_t OffImm = (int32_t)MO2.getImm();
869 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000870 if (OffImm == INT32_MIN)
871 O << ", #-0";
872 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000873 O << ", #-" << -OffImm;
874 else if (OffImm > 0)
875 O << ", #" << OffImm;
876 O << "]";
877}
878
879void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000880 unsigned OpNum,
881 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000882 const MCOperand &MO1 = MI->getOperand(OpNum);
883 const MCOperand &MO2 = MI->getOperand(OpNum+1);
884
885 O << "[" << getRegisterName(MO1.getReg());
886
887 int32_t OffImm = (int32_t)MO2.getImm() / 4;
888 // Don't print +0.
889 if (OffImm < 0)
890 O << ", #-" << -OffImm * 4;
891 else if (OffImm > 0)
892 O << ", #" << OffImm * 4;
893 O << "]";
894}
895
Jim Grosbachb6aed502011-09-09 18:37:27 +0000896void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
897 unsigned OpNum,
898 raw_ostream &O) {
899 const MCOperand &MO1 = MI->getOperand(OpNum);
900 const MCOperand &MO2 = MI->getOperand(OpNum+1);
901
902 O << "[" << getRegisterName(MO1.getReg());
903 if (MO2.getImm())
904 O << ", #" << MO2.getImm() * 4;
905 O << "]";
906}
907
Johnny Chen9e088762010-03-17 17:52:21 +0000908void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000909 unsigned OpNum,
910 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000911 const MCOperand &MO1 = MI->getOperand(OpNum);
912 int32_t OffImm = (int32_t)MO1.getImm();
913 // Don't print +0.
914 if (OffImm < 0)
Owen Anderson0781c1f2011-09-23 21:26:40 +0000915 O << ", #-" << -OffImm;
916 else
917 O << ", #" << OffImm;
Johnny Chen9e088762010-03-17 17:52:21 +0000918}
919
920void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000921 unsigned OpNum,
922 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000923 const MCOperand &MO1 = MI->getOperand(OpNum);
924 int32_t OffImm = (int32_t)MO1.getImm() / 4;
925 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000926 if (OffImm != 0) {
927 O << ", ";
928 if (OffImm < 0)
929 O << "#-" << -OffImm * 4;
930 else if (OffImm > 0)
931 O << "#" << OffImm * 4;
932 }
Johnny Chen9e088762010-03-17 17:52:21 +0000933}
934
935void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000936 unsigned OpNum,
937 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000938 const MCOperand &MO1 = MI->getOperand(OpNum);
939 const MCOperand &MO2 = MI->getOperand(OpNum+1);
940 const MCOperand &MO3 = MI->getOperand(OpNum+2);
941
942 O << "[" << getRegisterName(MO1.getReg());
943
944 assert(MO2.getReg() && "Invalid so_reg load / store address!");
945 O << ", " << getRegisterName(MO2.getReg());
946
947 unsigned ShAmt = MO3.getImm();
948 if (ShAmt) {
949 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
950 O << ", lsl #" << ShAmt;
951 }
952 O << "]";
953}
954
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000955void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
956 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000957 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000958 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000959}
960
Bob Wilson1a913ed2010-06-11 21:34:50 +0000961void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
962 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000963 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
964 unsigned EltBits;
965 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000966 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000967}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000968
Jim Grosbachf4943352011-07-25 23:09:14 +0000969void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
970 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000971 unsigned Imm = MI->getOperand(OpNum).getImm();
972 O << "#" << Imm + 1;
973}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000974
975void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
976 raw_ostream &O) {
977 unsigned Imm = MI->getOperand(OpNum).getImm();
978 if (Imm == 0)
979 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000980 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000981 switch (Imm) {
982 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000983 case 1: O << "8"; break;
984 case 2: O << "16"; break;
985 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000986 }
987}
Jim Grosbach460a9052011-10-07 23:56:00 +0000988
989void ARMInstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
990 raw_ostream &O) {
991 O << "[" << MI->getOperand(OpNum).getImm() << "]";
992}
Jim Grosbach862019c2011-10-18 23:02:30 +0000993
994void ARMInstPrinter::printVectorListOne(const MCInst *MI, unsigned OpNum,
995 raw_ostream &O) {
996 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "}";
997}
Jim Grosbach280dfad2011-10-21 18:54:25 +0000998
999void ARMInstPrinter::printVectorListTwo(const MCInst *MI, unsigned OpNum,
1000 raw_ostream &O) {
1001 // Normally, it's not safe to use register enum values directly with
1002 // addition to get the next register, but for VFP registers, the
1003 // sort order is guaranteed because they're all of the form D<n>.
1004 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1005 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "}";
1006}
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001007
1008void ARMInstPrinter::printVectorListThree(const MCInst *MI, unsigned OpNum,
1009 raw_ostream &O) {
1010 // Normally, it's not safe to use register enum values directly with
1011 // addition to get the next register, but for VFP registers, the
1012 // sort order is guaranteed because they're all of the form D<n>.
1013 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1014 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1015 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1016}