blob: f3e29f80b8f8c737d7722462f58f0700961d57ed [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");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000210 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000211 }
212}
Chris Lattner61d35c22009-10-19 21:21:39 +0000213
Owen Andersone1368722011-09-21 23:44:46 +0000214void ARMInstPrinter::printT2LdrLabelOperand(const MCInst *MI, unsigned OpNum,
215 raw_ostream &O) {
216 const MCOperand &MO1 = MI->getOperand(OpNum);
217 if (MO1.isExpr())
218 O << *MO1.getExpr();
219 else if (MO1.isImm())
220 O << "[pc, #" << MO1.getImm() << "]";
221 else
222 llvm_unreachable("Unknown LDR label operand?");
223}
224
Chris Lattner017d9472009-10-20 00:40:56 +0000225// so_reg is a 4-operand unit corresponding to register forms of the A5.1
226// "Addressing Mode 1 - Data-processing operands" forms. This includes:
227// REG 0 0 - e.g. R5
228// REG REG 0,SH_OPC - e.g. R5, ROR R3
229// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000230void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000231 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000232 const MCOperand &MO1 = MI->getOperand(OpNum);
233 const MCOperand &MO2 = MI->getOperand(OpNum+1);
234 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000235
Chris Lattner017d9472009-10-20 00:40:56 +0000236 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000237
Chris Lattner017d9472009-10-20 00:40:56 +0000238 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000239 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
240 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000241 if (ShOpc == ARM_AM::rrx)
242 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000243
244 O << ' ' << getRegisterName(MO2.getReg());
245 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000246}
Chris Lattner084f87d2009-10-19 21:57:05 +0000247
Owen Anderson152d4a42011-07-21 23:38:37 +0000248void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
249 raw_ostream &O) {
250 const MCOperand &MO1 = MI->getOperand(OpNum);
251 const MCOperand &MO2 = MI->getOperand(OpNum+1);
252
253 O << getRegisterName(MO1.getReg());
254
255 // Print the shift opc.
256 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
257 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
258 if (ShOpc == ARM_AM::rrx)
259 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000260 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000261}
262
263
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000264//===--------------------------------------------------------------------===//
265// Addressing Mode #2
266//===--------------------------------------------------------------------===//
267
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000268void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
269 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000270 const MCOperand &MO1 = MI->getOperand(Op);
271 const MCOperand &MO2 = MI->getOperand(Op+1);
272 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000273
Chris Lattner084f87d2009-10-19 21:57:05 +0000274 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000275
Chris Lattner084f87d2009-10-19 21:57:05 +0000276 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000277 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000278 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000279 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
280 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000281 O << "]";
282 return;
283 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000284
Chris Lattner084f87d2009-10-19 21:57:05 +0000285 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000286 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
287 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000288
Chris Lattner084f87d2009-10-19 21:57:05 +0000289 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
290 O << ", "
291 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
292 << " #" << ShImm;
293 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000294}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000295
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000296void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
297 raw_ostream &O) {
298 const MCOperand &MO1 = MI->getOperand(Op);
299 const MCOperand &MO2 = MI->getOperand(Op+1);
300 const MCOperand &MO3 = MI->getOperand(Op+2);
301
302 O << "[" << getRegisterName(MO1.getReg()) << "], ";
303
304 if (!MO2.getReg()) {
305 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
306 O << '#'
307 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
308 << ImmOffs;
309 return;
310 }
311
312 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
313 << getRegisterName(MO2.getReg());
314
315 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
316 O << ", "
317 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
318 << " #" << ShImm;
319}
320
Jim Grosbach7f739be2011-09-19 22:21:13 +0000321void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
322 raw_ostream &O) {
323 const MCOperand &MO1 = MI->getOperand(Op);
324 const MCOperand &MO2 = MI->getOperand(Op+1);
325 O << "[" << getRegisterName(MO1.getReg()) << ", "
326 << getRegisterName(MO2.getReg()) << "]";
327}
328
329void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
330 raw_ostream &O) {
331 const MCOperand &MO1 = MI->getOperand(Op);
332 const MCOperand &MO2 = MI->getOperand(Op+1);
333 O << "[" << getRegisterName(MO1.getReg()) << ", "
334 << getRegisterName(MO2.getReg()) << ", lsl #1]";
335}
336
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000337void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
338 raw_ostream &O) {
339 const MCOperand &MO1 = MI->getOperand(Op);
340
341 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
342 printOperand(MI, Op, O);
343 return;
344 }
345
346 const MCOperand &MO3 = MI->getOperand(Op+2);
347 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
348
349 if (IdxMode == ARMII::IndexModePost) {
350 printAM2PostIndexOp(MI, Op, O);
351 return;
352 }
353 printAM2PreOrOffsetIndexOp(MI, Op, O);
354}
355
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000356void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000357 unsigned OpNum,
358 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000359 const MCOperand &MO1 = MI->getOperand(OpNum);
360 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000361
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000362 if (!MO1.getReg()) {
363 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000364 O << '#'
365 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
366 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000367 return;
368 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000369
Johnny Chen9e088762010-03-17 17:52:21 +0000370 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
371 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000372
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000373 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
374 O << ", "
375 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
376 << " #" << ShImm;
377}
378
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000379//===--------------------------------------------------------------------===//
380// Addressing Mode #3
381//===--------------------------------------------------------------------===//
382
383void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
384 raw_ostream &O) {
385 const MCOperand &MO1 = MI->getOperand(Op);
386 const MCOperand &MO2 = MI->getOperand(Op+1);
387 const MCOperand &MO3 = MI->getOperand(Op+2);
388
389 O << "[" << getRegisterName(MO1.getReg()) << "], ";
390
391 if (MO2.getReg()) {
392 O << (char)ARM_AM::getAM3Op(MO3.getImm())
393 << getRegisterName(MO2.getReg());
394 return;
395 }
396
397 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
398 O << '#'
399 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
400 << ImmOffs;
401}
402
403void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
404 raw_ostream &O) {
405 const MCOperand &MO1 = MI->getOperand(Op);
406 const MCOperand &MO2 = MI->getOperand(Op+1);
407 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000408
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000409 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000410
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000411 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000412 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000413 << getRegisterName(MO2.getReg()) << ']';
414 return;
415 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000416
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000417 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
418 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000419 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
420 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000421 O << ']';
422}
423
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000424void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
425 raw_ostream &O) {
426 const MCOperand &MO3 = MI->getOperand(Op+2);
427 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
428
429 if (IdxMode == ARMII::IndexModePost) {
430 printAM3PostIndexOp(MI, Op, O);
431 return;
432 }
433 printAM3PreOrOffsetIndexOp(MI, Op, O);
434}
435
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000436void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000437 unsigned OpNum,
438 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000439 const MCOperand &MO1 = MI->getOperand(OpNum);
440 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000441
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000442 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000443 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
444 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000445 return;
446 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000447
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000448 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000449 O << '#'
450 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
451 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000452}
453
Jim Grosbach7ce05792011-08-03 23:50:40 +0000454void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
455 unsigned OpNum,
456 raw_ostream &O) {
457 const MCOperand &MO = MI->getOperand(OpNum);
458 unsigned Imm = MO.getImm();
459 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
460}
461
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000462void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
463 raw_ostream &O) {
464 const MCOperand &MO1 = MI->getOperand(OpNum);
465 const MCOperand &MO2 = MI->getOperand(OpNum+1);
466
Jim Grosbach16578b52011-08-05 16:11:38 +0000467 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000468}
469
Owen Anderson154c41d2011-08-04 18:24:14 +0000470void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
471 unsigned OpNum,
472 raw_ostream &O) {
473 const MCOperand &MO = MI->getOperand(OpNum);
474 unsigned Imm = MO.getImm();
475 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
476}
477
478
Jim Grosbache6913602010-11-03 01:01:43 +0000479void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000480 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000481 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
482 .getImm());
483 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000484}
485
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000486void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000487 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000488 const MCOperand &MO1 = MI->getOperand(OpNum);
489 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000490
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000491 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000492 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000493 return;
494 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000495
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000496 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000497
Owen Anderson0da10cf2011-08-29 19:36:44 +0000498 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
499 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
500 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000501 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000502 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000503 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000504 }
505 O << "]";
506}
507
Chris Lattner35c33bd2010-04-04 04:47:45 +0000508void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
509 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000510 const MCOperand &MO1 = MI->getOperand(OpNum);
511 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000512
Bob Wilson226036e2010-03-20 22:13:40 +0000513 O << "[" << getRegisterName(MO1.getReg());
514 if (MO2.getImm()) {
515 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000516 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000517 }
Bob Wilson226036e2010-03-20 22:13:40 +0000518 O << "]";
519}
520
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000521void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
522 raw_ostream &O) {
523 const MCOperand &MO1 = MI->getOperand(OpNum);
524 O << "[" << getRegisterName(MO1.getReg()) << "]";
525}
526
Bob Wilson226036e2010-03-20 22:13:40 +0000527void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000528 unsigned OpNum,
529 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000530 const MCOperand &MO = MI->getOperand(OpNum);
531 if (MO.getReg() == 0)
532 O << "!";
533 else
534 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000535}
536
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000537void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
538 unsigned OpNum,
539 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000540 const MCOperand &MO = MI->getOperand(OpNum);
541 uint32_t v = ~MO.getImm();
542 int32_t lsb = CountTrailingZeros_32(v);
543 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
544 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
545 O << '#' << lsb << ", #" << width;
546}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000547
Johnny Chen1adc40c2010-08-12 20:46:17 +0000548void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
549 raw_ostream &O) {
550 unsigned val = MI->getOperand(OpNum).getImm();
551 O << ARM_MB::MemBOptToString(val);
552}
553
Bob Wilson22f5dc72010-08-16 18:27:34 +0000554void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000555 raw_ostream &O) {
556 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000557 bool isASR = (ShiftOp & (1 << 5)) != 0;
558 unsigned Amt = ShiftOp & 0x1f;
559 if (isASR)
560 O << ", asr #" << (Amt == 0 ? 32 : Amt);
561 else if (Amt)
562 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000563}
564
Jim Grosbachdde038a2011-07-20 21:40:26 +0000565void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
566 raw_ostream &O) {
567 unsigned Imm = MI->getOperand(OpNum).getImm();
568 if (Imm == 0)
569 return;
570 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
571 O << ", lsl #" << Imm;
572}
573
574void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
575 raw_ostream &O) {
576 unsigned Imm = MI->getOperand(OpNum).getImm();
577 // A shift amount of 32 is encoded as 0.
578 if (Imm == 0)
579 Imm = 32;
580 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
581 O << ", asr #" << Imm;
582}
583
Chris Lattner35c33bd2010-04-04 04:47:45 +0000584void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
585 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000586 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000587 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
588 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000589 O << getRegisterName(MI->getOperand(i).getReg());
590 }
591 O << "}";
592}
Chris Lattner4d152222009-10-19 22:23:04 +0000593
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000594void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
595 raw_ostream &O) {
596 const MCOperand &Op = MI->getOperand(OpNum);
597 if (Op.getImm())
598 O << "be";
599 else
600 O << "le";
601}
602
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000603void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
604 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000605 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000606 O << ARM_PROC::IModToString(Op.getImm());
607}
608
609void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
610 raw_ostream &O) {
611 const MCOperand &Op = MI->getOperand(OpNum);
612 unsigned IFlags = Op.getImm();
613 for (int i=2; i >= 0; --i)
614 if (IFlags & (1 << i))
615 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000616}
617
Chris Lattner35c33bd2010-04-04 04:47:45 +0000618void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
619 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000620 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000621 unsigned SpecRegRBit = Op.getImm() >> 4;
622 unsigned Mask = Op.getImm() & 0xf;
623
James Molloyacad68d2011-09-28 14:21:38 +0000624 if (getAvailableFeatures() & ARM::FeatureMClass) {
625 switch (Op.getImm()) {
626 default: assert(0 && "Unexpected mask value!");
627 case 0: O << "apsr"; return;
628 case 1: O << "iapsr"; return;
629 case 2: O << "eapsr"; return;
630 case 3: O << "xpsr"; return;
631 case 5: O << "ipsr"; return;
632 case 6: O << "epsr"; return;
633 case 7: O << "iepsr"; return;
634 case 8: O << "msp"; return;
635 case 9: O << "psp"; return;
636 case 16: O << "primask"; return;
637 case 17: O << "basepri"; return;
638 case 18: O << "basepri_max"; return;
639 case 19: O << "faultmask"; return;
640 case 20: O << "control"; return;
641 }
642 }
643
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000644 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
645 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
646 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
647 O << "APSR_";
648 switch (Mask) {
649 default: assert(0);
650 case 4: O << "g"; return;
651 case 8: O << "nzcvq"; return;
652 case 12: O << "nzcvqg"; return;
653 }
654 llvm_unreachable("Unexpected mask value!");
655 }
656
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000657 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000658 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000659 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000660 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000661
Johnny Chen9e088762010-03-17 17:52:21 +0000662 if (Mask) {
663 O << '_';
664 if (Mask & 8) O << 'f';
665 if (Mask & 4) O << 's';
666 if (Mask & 2) O << 'x';
667 if (Mask & 1) O << 'c';
668 }
669}
670
Chris Lattner35c33bd2010-04-04 04:47:45 +0000671void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
672 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000673 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
674 if (CC != ARMCC::AL)
675 O << ARMCondCodeToString(CC);
676}
677
Jim Grosbach15d78982010-09-14 22:27:15 +0000678void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000679 unsigned OpNum,
680 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000681 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
682 O << ARMCondCodeToString(CC);
683}
684
Chris Lattner35c33bd2010-04-04 04:47:45 +0000685void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
686 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000687 if (MI->getOperand(OpNum).getReg()) {
688 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
689 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000690 O << 's';
691 }
692}
693
Chris Lattner35c33bd2010-04-04 04:47:45 +0000694void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
695 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000696 O << MI->getOperand(OpNum).getImm();
697}
698
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000699void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
700 raw_ostream &O) {
701 O << "p" << MI->getOperand(OpNum).getImm();
702}
703
704void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
705 raw_ostream &O) {
706 O << "c" << MI->getOperand(OpNum).getImm();
707}
708
Chris Lattner35c33bd2010-04-04 04:47:45 +0000709void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
710 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000711 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000712}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000713
Chris Lattner35c33bd2010-04-04 04:47:45 +0000714void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
715 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000716 O << "#" << MI->getOperand(OpNum).getImm() * 4;
717}
718
719void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
720 raw_ostream &O) {
721 unsigned Imm = MI->getOperand(OpNum).getImm();
722 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000723}
Johnny Chen9e088762010-03-17 17:52:21 +0000724
Chris Lattner35c33bd2010-04-04 04:47:45 +0000725void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
726 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000727 // (3 - the number of trailing zeros) is the number of then / else.
728 unsigned Mask = MI->getOperand(OpNum).getImm();
729 unsigned CondBit0 = Mask >> 4 & 1;
730 unsigned NumTZ = CountTrailingZeros_32(Mask);
731 assert(NumTZ <= 3 && "Invalid IT mask!");
732 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
733 bool T = ((Mask >> Pos) & 1) == CondBit0;
734 if (T)
735 O << 't';
736 else
737 O << 'e';
738 }
739}
740
Chris Lattner35c33bd2010-04-04 04:47:45 +0000741void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
742 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000743 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000744 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000745
746 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000747 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000748 return;
749 }
750
751 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000752 if (unsigned RegNum = MO2.getReg())
753 O << ", " << getRegisterName(RegNum);
754 O << "]";
755}
756
757void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
758 unsigned Op,
759 raw_ostream &O,
760 unsigned Scale) {
761 const MCOperand &MO1 = MI->getOperand(Op);
762 const MCOperand &MO2 = MI->getOperand(Op + 1);
763
764 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
765 printOperand(MI, Op, O);
766 return;
767 }
768
769 O << "[" << getRegisterName(MO1.getReg());
770 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000771 O << ", #" << ImmOffs * Scale;
772 O << "]";
773}
774
Bill Wendlingf4caf692010-12-14 03:36:38 +0000775void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
776 unsigned Op,
777 raw_ostream &O) {
778 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000779}
780
Bill Wendlingf4caf692010-12-14 03:36:38 +0000781void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
782 unsigned Op,
783 raw_ostream &O) {
784 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000785}
786
Bill Wendlingf4caf692010-12-14 03:36:38 +0000787void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
788 unsigned Op,
789 raw_ostream &O) {
790 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000791}
792
Chris Lattner35c33bd2010-04-04 04:47:45 +0000793void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
794 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000795 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000796}
797
Johnny Chen9e088762010-03-17 17:52:21 +0000798// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
799// register with shift forms.
800// REG 0 0 - e.g. R5
801// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000802void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
803 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000804 const MCOperand &MO1 = MI->getOperand(OpNum);
805 const MCOperand &MO2 = MI->getOperand(OpNum+1);
806
807 unsigned Reg = MO1.getReg();
808 O << getRegisterName(Reg);
809
810 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000811 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000812 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
813 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
814 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000815 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000816}
817
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000818void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
819 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000820 const MCOperand &MO1 = MI->getOperand(OpNum);
821 const MCOperand &MO2 = MI->getOperand(OpNum+1);
822
Jim Grosbach3e556122010-10-26 22:37:02 +0000823 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
824 printOperand(MI, OpNum, O);
825 return;
826 }
827
Johnny Chen9e088762010-03-17 17:52:21 +0000828 O << "[" << getRegisterName(MO1.getReg());
829
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000830 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000831 bool isSub = OffImm < 0;
832 // Special value for #-0. All others are normal.
833 if (OffImm == INT32_MIN)
834 OffImm = 0;
835 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000836 O << ", #-" << -OffImm;
837 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000838 O << ", #" << OffImm;
839 O << "]";
840}
841
842void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000843 unsigned OpNum,
844 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000845 const MCOperand &MO1 = MI->getOperand(OpNum);
846 const MCOperand &MO2 = MI->getOperand(OpNum+1);
847
848 O << "[" << getRegisterName(MO1.getReg());
849
850 int32_t OffImm = (int32_t)MO2.getImm();
851 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000852 if (OffImm == INT32_MIN)
853 O << ", #-0";
854 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000855 O << ", #-" << -OffImm;
856 else if (OffImm > 0)
857 O << ", #" << OffImm;
858 O << "]";
859}
860
861void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000862 unsigned OpNum,
863 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000864 const MCOperand &MO1 = MI->getOperand(OpNum);
865 const MCOperand &MO2 = MI->getOperand(OpNum+1);
866
867 O << "[" << getRegisterName(MO1.getReg());
868
869 int32_t OffImm = (int32_t)MO2.getImm() / 4;
870 // Don't print +0.
871 if (OffImm < 0)
872 O << ", #-" << -OffImm * 4;
873 else if (OffImm > 0)
874 O << ", #" << OffImm * 4;
875 O << "]";
876}
877
Jim Grosbachb6aed502011-09-09 18:37:27 +0000878void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
879 unsigned OpNum,
880 raw_ostream &O) {
881 const MCOperand &MO1 = MI->getOperand(OpNum);
882 const MCOperand &MO2 = MI->getOperand(OpNum+1);
883
884 O << "[" << getRegisterName(MO1.getReg());
885 if (MO2.getImm())
886 O << ", #" << MO2.getImm() * 4;
887 O << "]";
888}
889
Johnny Chen9e088762010-03-17 17:52:21 +0000890void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000891 unsigned OpNum,
892 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000893 const MCOperand &MO1 = MI->getOperand(OpNum);
894 int32_t OffImm = (int32_t)MO1.getImm();
895 // Don't print +0.
896 if (OffImm < 0)
Owen Anderson0781c1f2011-09-23 21:26:40 +0000897 O << ", #-" << -OffImm;
898 else
899 O << ", #" << OffImm;
Johnny Chen9e088762010-03-17 17:52:21 +0000900}
901
902void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000903 unsigned OpNum,
904 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000905 const MCOperand &MO1 = MI->getOperand(OpNum);
906 int32_t OffImm = (int32_t)MO1.getImm() / 4;
907 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000908 if (OffImm != 0) {
909 O << ", ";
910 if (OffImm < 0)
911 O << "#-" << -OffImm * 4;
912 else if (OffImm > 0)
913 O << "#" << OffImm * 4;
914 }
Johnny Chen9e088762010-03-17 17:52:21 +0000915}
916
917void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000918 unsigned OpNum,
919 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000920 const MCOperand &MO1 = MI->getOperand(OpNum);
921 const MCOperand &MO2 = MI->getOperand(OpNum+1);
922 const MCOperand &MO3 = MI->getOperand(OpNum+2);
923
924 O << "[" << getRegisterName(MO1.getReg());
925
926 assert(MO2.getReg() && "Invalid so_reg load / store address!");
927 O << ", " << getRegisterName(MO2.getReg());
928
929 unsigned ShAmt = MO3.getImm();
930 if (ShAmt) {
931 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
932 O << ", lsl #" << ShAmt;
933 }
934 O << "]";
935}
936
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000937void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
938 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000939 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000940 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000941}
942
Bob Wilson1a913ed2010-06-11 21:34:50 +0000943void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
944 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000945 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
946 unsigned EltBits;
947 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000948 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000949}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000950
Jim Grosbachf4943352011-07-25 23:09:14 +0000951void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
952 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000953 unsigned Imm = MI->getOperand(OpNum).getImm();
954 O << "#" << Imm + 1;
955}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000956
957void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
958 raw_ostream &O) {
959 unsigned Imm = MI->getOperand(OpNum).getImm();
960 if (Imm == 0)
961 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000962 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000963 switch (Imm) {
964 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000965 case 1: O << "8"; break;
966 case 2: O << "16"; break;
967 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000968 }
969}