blob: 251b447886ce5d180374fc68c0a5fbe60f93528f [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
225void ARMInstPrinter::printT2AdrLabelOperand(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
236
Chris Lattner017d9472009-10-20 00:40:56 +0000237// so_reg is a 4-operand unit corresponding to register forms of the A5.1
238// "Addressing Mode 1 - Data-processing operands" forms. This includes:
239// REG 0 0 - e.g. R5
240// REG REG 0,SH_OPC - e.g. R5, ROR R3
241// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000242void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000243 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000244 const MCOperand &MO1 = MI->getOperand(OpNum);
245 const MCOperand &MO2 = MI->getOperand(OpNum+1);
246 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000247
Chris Lattner017d9472009-10-20 00:40:56 +0000248 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000249
Chris Lattner017d9472009-10-20 00:40:56 +0000250 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000251 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
252 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000253 if (ShOpc == ARM_AM::rrx)
254 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000255
256 O << ' ' << getRegisterName(MO2.getReg());
257 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000258}
Chris Lattner084f87d2009-10-19 21:57:05 +0000259
Owen Anderson152d4a42011-07-21 23:38:37 +0000260void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
261 raw_ostream &O) {
262 const MCOperand &MO1 = MI->getOperand(OpNum);
263 const MCOperand &MO2 = MI->getOperand(OpNum+1);
264
265 O << getRegisterName(MO1.getReg());
266
267 // Print the shift opc.
268 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
269 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
270 if (ShOpc == ARM_AM::rrx)
271 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000272 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000273}
274
275
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000276//===--------------------------------------------------------------------===//
277// Addressing Mode #2
278//===--------------------------------------------------------------------===//
279
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000280void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
281 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000282 const MCOperand &MO1 = MI->getOperand(Op);
283 const MCOperand &MO2 = MI->getOperand(Op+1);
284 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000285
Chris Lattner084f87d2009-10-19 21:57:05 +0000286 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000287
Chris Lattner084f87d2009-10-19 21:57:05 +0000288 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000289 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000290 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000291 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
292 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000293 O << "]";
294 return;
295 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000296
Chris Lattner084f87d2009-10-19 21:57:05 +0000297 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000298 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
299 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000300
Chris Lattner084f87d2009-10-19 21:57:05 +0000301 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
302 O << ", "
303 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
304 << " #" << ShImm;
305 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000306}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000307
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000308void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
309 raw_ostream &O) {
310 const MCOperand &MO1 = MI->getOperand(Op);
311 const MCOperand &MO2 = MI->getOperand(Op+1);
312 const MCOperand &MO3 = MI->getOperand(Op+2);
313
314 O << "[" << getRegisterName(MO1.getReg()) << "], ";
315
316 if (!MO2.getReg()) {
317 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
318 O << '#'
319 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
320 << ImmOffs;
321 return;
322 }
323
324 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
325 << getRegisterName(MO2.getReg());
326
327 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
328 O << ", "
329 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
330 << " #" << ShImm;
331}
332
Jim Grosbach7f739be2011-09-19 22:21:13 +0000333void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
334 raw_ostream &O) {
335 const MCOperand &MO1 = MI->getOperand(Op);
336 const MCOperand &MO2 = MI->getOperand(Op+1);
337 O << "[" << getRegisterName(MO1.getReg()) << ", "
338 << getRegisterName(MO2.getReg()) << "]";
339}
340
341void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
342 raw_ostream &O) {
343 const MCOperand &MO1 = MI->getOperand(Op);
344 const MCOperand &MO2 = MI->getOperand(Op+1);
345 O << "[" << getRegisterName(MO1.getReg()) << ", "
346 << getRegisterName(MO2.getReg()) << ", lsl #1]";
347}
348
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000349void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
350 raw_ostream &O) {
351 const MCOperand &MO1 = MI->getOperand(Op);
352
353 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
354 printOperand(MI, Op, O);
355 return;
356 }
357
358 const MCOperand &MO3 = MI->getOperand(Op+2);
359 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
360
361 if (IdxMode == ARMII::IndexModePost) {
362 printAM2PostIndexOp(MI, Op, O);
363 return;
364 }
365 printAM2PreOrOffsetIndexOp(MI, Op, O);
366}
367
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000368void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000369 unsigned OpNum,
370 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000371 const MCOperand &MO1 = MI->getOperand(OpNum);
372 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000373
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000374 if (!MO1.getReg()) {
375 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000376 O << '#'
377 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
378 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000379 return;
380 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000381
Johnny Chen9e088762010-03-17 17:52:21 +0000382 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
383 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000384
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000385 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
386 O << ", "
387 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
388 << " #" << ShImm;
389}
390
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000391//===--------------------------------------------------------------------===//
392// Addressing Mode #3
393//===--------------------------------------------------------------------===//
394
395void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
396 raw_ostream &O) {
397 const MCOperand &MO1 = MI->getOperand(Op);
398 const MCOperand &MO2 = MI->getOperand(Op+1);
399 const MCOperand &MO3 = MI->getOperand(Op+2);
400
401 O << "[" << getRegisterName(MO1.getReg()) << "], ";
402
403 if (MO2.getReg()) {
404 O << (char)ARM_AM::getAM3Op(MO3.getImm())
405 << getRegisterName(MO2.getReg());
406 return;
407 }
408
409 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
410 O << '#'
411 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
412 << ImmOffs;
413}
414
415void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
416 raw_ostream &O) {
417 const MCOperand &MO1 = MI->getOperand(Op);
418 const MCOperand &MO2 = MI->getOperand(Op+1);
419 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000420
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000421 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000422
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000423 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000424 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000425 << getRegisterName(MO2.getReg()) << ']';
426 return;
427 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000428
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000429 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
430 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000431 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
432 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000433 O << ']';
434}
435
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000436void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
437 raw_ostream &O) {
438 const MCOperand &MO3 = MI->getOperand(Op+2);
439 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
440
441 if (IdxMode == ARMII::IndexModePost) {
442 printAM3PostIndexOp(MI, Op, O);
443 return;
444 }
445 printAM3PreOrOffsetIndexOp(MI, Op, O);
446}
447
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000448void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000449 unsigned OpNum,
450 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000451 const MCOperand &MO1 = MI->getOperand(OpNum);
452 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000453
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000454 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000455 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
456 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000457 return;
458 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000459
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000460 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000461 O << '#'
462 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
463 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000464}
465
Jim Grosbach7ce05792011-08-03 23:50:40 +0000466void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
467 unsigned OpNum,
468 raw_ostream &O) {
469 const MCOperand &MO = MI->getOperand(OpNum);
470 unsigned Imm = MO.getImm();
471 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
472}
473
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000474void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
475 raw_ostream &O) {
476 const MCOperand &MO1 = MI->getOperand(OpNum);
477 const MCOperand &MO2 = MI->getOperand(OpNum+1);
478
Jim Grosbach16578b52011-08-05 16:11:38 +0000479 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000480}
481
Owen Anderson154c41d2011-08-04 18:24:14 +0000482void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
483 unsigned OpNum,
484 raw_ostream &O) {
485 const MCOperand &MO = MI->getOperand(OpNum);
486 unsigned Imm = MO.getImm();
487 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
488}
489
490
Jim Grosbache6913602010-11-03 01:01:43 +0000491void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000492 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000493 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
494 .getImm());
495 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000496}
497
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000498void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000499 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000500 const MCOperand &MO1 = MI->getOperand(OpNum);
501 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000502
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000503 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000504 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000505 return;
506 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000507
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000508 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000509
Owen Anderson0da10cf2011-08-29 19:36:44 +0000510 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
511 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
512 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000513 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000514 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000515 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000516 }
517 O << "]";
518}
519
Chris Lattner35c33bd2010-04-04 04:47:45 +0000520void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
521 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000522 const MCOperand &MO1 = MI->getOperand(OpNum);
523 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000524
Bob Wilson226036e2010-03-20 22:13:40 +0000525 O << "[" << getRegisterName(MO1.getReg());
526 if (MO2.getImm()) {
527 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000528 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000529 }
Bob Wilson226036e2010-03-20 22:13:40 +0000530 O << "]";
531}
532
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000533void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
534 raw_ostream &O) {
535 const MCOperand &MO1 = MI->getOperand(OpNum);
536 O << "[" << getRegisterName(MO1.getReg()) << "]";
537}
538
Bob Wilson226036e2010-03-20 22:13:40 +0000539void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000540 unsigned OpNum,
541 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000542 const MCOperand &MO = MI->getOperand(OpNum);
543 if (MO.getReg() == 0)
544 O << "!";
545 else
546 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000547}
548
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000549void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
550 unsigned OpNum,
551 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000552 const MCOperand &MO = MI->getOperand(OpNum);
553 uint32_t v = ~MO.getImm();
554 int32_t lsb = CountTrailingZeros_32(v);
555 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
556 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
557 O << '#' << lsb << ", #" << width;
558}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000559
Johnny Chen1adc40c2010-08-12 20:46:17 +0000560void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
561 raw_ostream &O) {
562 unsigned val = MI->getOperand(OpNum).getImm();
563 O << ARM_MB::MemBOptToString(val);
564}
565
Bob Wilson22f5dc72010-08-16 18:27:34 +0000566void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000567 raw_ostream &O) {
568 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000569 bool isASR = (ShiftOp & (1 << 5)) != 0;
570 unsigned Amt = ShiftOp & 0x1f;
571 if (isASR)
572 O << ", asr #" << (Amt == 0 ? 32 : Amt);
573 else if (Amt)
574 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000575}
576
Jim Grosbachdde038a2011-07-20 21:40:26 +0000577void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
578 raw_ostream &O) {
579 unsigned Imm = MI->getOperand(OpNum).getImm();
580 if (Imm == 0)
581 return;
582 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
583 O << ", lsl #" << Imm;
584}
585
586void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
587 raw_ostream &O) {
588 unsigned Imm = MI->getOperand(OpNum).getImm();
589 // A shift amount of 32 is encoded as 0.
590 if (Imm == 0)
591 Imm = 32;
592 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
593 O << ", asr #" << Imm;
594}
595
Chris Lattner35c33bd2010-04-04 04:47:45 +0000596void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
597 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000598 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000599 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
600 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000601 O << getRegisterName(MI->getOperand(i).getReg());
602 }
603 O << "}";
604}
Chris Lattner4d152222009-10-19 22:23:04 +0000605
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000606void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
607 raw_ostream &O) {
608 const MCOperand &Op = MI->getOperand(OpNum);
609 if (Op.getImm())
610 O << "be";
611 else
612 O << "le";
613}
614
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000615void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
616 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000617 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000618 O << ARM_PROC::IModToString(Op.getImm());
619}
620
621void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
622 raw_ostream &O) {
623 const MCOperand &Op = MI->getOperand(OpNum);
624 unsigned IFlags = Op.getImm();
625 for (int i=2; i >= 0; --i)
626 if (IFlags & (1 << i))
627 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000628}
629
Chris Lattner35c33bd2010-04-04 04:47:45 +0000630void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
631 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000632 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000633 unsigned SpecRegRBit = Op.getImm() >> 4;
634 unsigned Mask = Op.getImm() & 0xf;
635
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000636 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
637 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
638 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
639 O << "APSR_";
640 switch (Mask) {
641 default: assert(0);
642 case 4: O << "g"; return;
643 case 8: O << "nzcvq"; return;
644 case 12: O << "nzcvqg"; return;
645 }
646 llvm_unreachable("Unexpected mask value!");
647 }
648
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000649 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000650 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000651 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000652 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000653
Johnny Chen9e088762010-03-17 17:52:21 +0000654 if (Mask) {
655 O << '_';
656 if (Mask & 8) O << 'f';
657 if (Mask & 4) O << 's';
658 if (Mask & 2) O << 'x';
659 if (Mask & 1) O << 'c';
660 }
661}
662
Chris Lattner35c33bd2010-04-04 04:47:45 +0000663void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
664 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000665 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
666 if (CC != ARMCC::AL)
667 O << ARMCondCodeToString(CC);
668}
669
Jim Grosbach15d78982010-09-14 22:27:15 +0000670void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000671 unsigned OpNum,
672 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000673 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
674 O << ARMCondCodeToString(CC);
675}
676
Chris Lattner35c33bd2010-04-04 04:47:45 +0000677void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
678 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000679 if (MI->getOperand(OpNum).getReg()) {
680 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
681 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000682 O << 's';
683 }
684}
685
Chris Lattner35c33bd2010-04-04 04:47:45 +0000686void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
687 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000688 O << MI->getOperand(OpNum).getImm();
689}
690
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000691void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
692 raw_ostream &O) {
693 O << "p" << MI->getOperand(OpNum).getImm();
694}
695
696void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
697 raw_ostream &O) {
698 O << "c" << MI->getOperand(OpNum).getImm();
699}
700
Chris Lattner35c33bd2010-04-04 04:47:45 +0000701void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
702 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000703 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000704}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000705
Chris Lattner35c33bd2010-04-04 04:47:45 +0000706void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
707 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000708 O << "#" << MI->getOperand(OpNum).getImm() * 4;
709}
710
711void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
712 raw_ostream &O) {
713 unsigned Imm = MI->getOperand(OpNum).getImm();
714 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000715}
Johnny Chen9e088762010-03-17 17:52:21 +0000716
Chris Lattner35c33bd2010-04-04 04:47:45 +0000717void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
718 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000719 // (3 - the number of trailing zeros) is the number of then / else.
720 unsigned Mask = MI->getOperand(OpNum).getImm();
721 unsigned CondBit0 = Mask >> 4 & 1;
722 unsigned NumTZ = CountTrailingZeros_32(Mask);
723 assert(NumTZ <= 3 && "Invalid IT mask!");
724 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
725 bool T = ((Mask >> Pos) & 1) == CondBit0;
726 if (T)
727 O << 't';
728 else
729 O << 'e';
730 }
731}
732
Chris Lattner35c33bd2010-04-04 04:47:45 +0000733void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
734 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000735 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000736 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000737
738 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000739 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000740 return;
741 }
742
743 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000744 if (unsigned RegNum = MO2.getReg())
745 O << ", " << getRegisterName(RegNum);
746 O << "]";
747}
748
749void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
750 unsigned Op,
751 raw_ostream &O,
752 unsigned Scale) {
753 const MCOperand &MO1 = MI->getOperand(Op);
754 const MCOperand &MO2 = MI->getOperand(Op + 1);
755
756 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
757 printOperand(MI, Op, O);
758 return;
759 }
760
761 O << "[" << getRegisterName(MO1.getReg());
762 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000763 O << ", #" << ImmOffs * Scale;
764 O << "]";
765}
766
Bill Wendlingf4caf692010-12-14 03:36:38 +0000767void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
768 unsigned Op,
769 raw_ostream &O) {
770 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000771}
772
Bill Wendlingf4caf692010-12-14 03:36:38 +0000773void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
774 unsigned Op,
775 raw_ostream &O) {
776 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000777}
778
Bill Wendlingf4caf692010-12-14 03:36:38 +0000779void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
780 unsigned Op,
781 raw_ostream &O) {
782 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000783}
784
Chris Lattner35c33bd2010-04-04 04:47:45 +0000785void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
786 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000787 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000788}
789
Johnny Chen9e088762010-03-17 17:52:21 +0000790// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
791// register with shift forms.
792// REG 0 0 - e.g. R5
793// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000794void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
795 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000796 const MCOperand &MO1 = MI->getOperand(OpNum);
797 const MCOperand &MO2 = MI->getOperand(OpNum+1);
798
799 unsigned Reg = MO1.getReg();
800 O << getRegisterName(Reg);
801
802 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000803 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000804 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
805 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
806 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000807 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000808}
809
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000810void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
811 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000812 const MCOperand &MO1 = MI->getOperand(OpNum);
813 const MCOperand &MO2 = MI->getOperand(OpNum+1);
814
Jim Grosbach3e556122010-10-26 22:37:02 +0000815 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
816 printOperand(MI, OpNum, O);
817 return;
818 }
819
Johnny Chen9e088762010-03-17 17:52:21 +0000820 O << "[" << getRegisterName(MO1.getReg());
821
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000822 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000823 bool isSub = OffImm < 0;
824 // Special value for #-0. All others are normal.
825 if (OffImm == INT32_MIN)
826 OffImm = 0;
827 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000828 O << ", #-" << -OffImm;
829 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000830 O << ", #" << OffImm;
831 O << "]";
832}
833
834void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000835 unsigned OpNum,
836 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000837 const MCOperand &MO1 = MI->getOperand(OpNum);
838 const MCOperand &MO2 = MI->getOperand(OpNum+1);
839
840 O << "[" << getRegisterName(MO1.getReg());
841
842 int32_t OffImm = (int32_t)MO2.getImm();
843 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000844 if (OffImm == INT32_MIN)
845 O << ", #-0";
846 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000847 O << ", #-" << -OffImm;
848 else if (OffImm > 0)
849 O << ", #" << OffImm;
850 O << "]";
851}
852
853void ARMInstPrinter::printT2AddrModeImm8s4Operand(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() / 4;
862 // Don't print +0.
863 if (OffImm < 0)
864 O << ", #-" << -OffImm * 4;
865 else if (OffImm > 0)
866 O << ", #" << OffImm * 4;
867 O << "]";
868}
869
Jim Grosbachb6aed502011-09-09 18:37:27 +0000870void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
871 unsigned OpNum,
872 raw_ostream &O) {
873 const MCOperand &MO1 = MI->getOperand(OpNum);
874 const MCOperand &MO2 = MI->getOperand(OpNum+1);
875
876 O << "[" << getRegisterName(MO1.getReg());
877 if (MO2.getImm())
878 O << ", #" << MO2.getImm() * 4;
879 O << "]";
880}
881
Johnny Chen9e088762010-03-17 17:52:21 +0000882void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000883 unsigned OpNum,
884 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000885 const MCOperand &MO1 = MI->getOperand(OpNum);
886 int32_t OffImm = (int32_t)MO1.getImm();
887 // Don't print +0.
888 if (OffImm < 0)
889 O << "#-" << -OffImm;
890 else if (OffImm > 0)
891 O << "#" << OffImm;
892}
893
894void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000895 unsigned OpNum,
896 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000897 const MCOperand &MO1 = MI->getOperand(OpNum);
898 int32_t OffImm = (int32_t)MO1.getImm() / 4;
899 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000900 if (OffImm != 0) {
901 O << ", ";
902 if (OffImm < 0)
903 O << "#-" << -OffImm * 4;
904 else if (OffImm > 0)
905 O << "#" << OffImm * 4;
906 }
Johnny Chen9e088762010-03-17 17:52:21 +0000907}
908
909void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000910 unsigned OpNum,
911 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000912 const MCOperand &MO1 = MI->getOperand(OpNum);
913 const MCOperand &MO2 = MI->getOperand(OpNum+1);
914 const MCOperand &MO3 = MI->getOperand(OpNum+2);
915
916 O << "[" << getRegisterName(MO1.getReg());
917
918 assert(MO2.getReg() && "Invalid so_reg load / store address!");
919 O << ", " << getRegisterName(MO2.getReg());
920
921 unsigned ShAmt = MO3.getImm();
922 if (ShAmt) {
923 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
924 O << ", lsl #" << ShAmt;
925 }
926 O << "]";
927}
928
Chris Lattner35c33bd2010-04-04 04:47:45 +0000929void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
930 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000931 const MCOperand &MO = MI->getOperand(OpNum);
932 O << '#';
933 if (MO.isFPImm()) {
934 O << (float)MO.getFPImm();
935 } else {
936 union {
937 uint32_t I;
938 float F;
939 } FPUnion;
940
941 FPUnion.I = MO.getImm();
942 O << FPUnion.F;
943 }
Johnny Chen9e088762010-03-17 17:52:21 +0000944}
945
Chris Lattner35c33bd2010-04-04 04:47:45 +0000946void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
947 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000948 const MCOperand &MO = MI->getOperand(OpNum);
949 O << '#';
950 if (MO.isFPImm()) {
951 O << MO.getFPImm();
952 } else {
953 // We expect the binary encoding of a floating point number here.
954 union {
955 uint64_t I;
956 double D;
957 } FPUnion;
958
959 FPUnion.I = MO.getImm();
960 O << FPUnion.D;
961 }
Johnny Chen9e088762010-03-17 17:52:21 +0000962}
963
Bob Wilson1a913ed2010-06-11 21:34:50 +0000964void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
965 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000966 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
967 unsigned EltBits;
968 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000969 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000970}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000971
Jim Grosbachf4943352011-07-25 23:09:14 +0000972void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
973 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000974 unsigned Imm = MI->getOperand(OpNum).getImm();
975 O << "#" << Imm + 1;
976}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000977
978void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
979 raw_ostream &O) {
980 unsigned Imm = MI->getOperand(OpNum).getImm();
981 if (Imm == 0)
982 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000983 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000984 switch (Imm) {
985 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000986 case 1: O << "8"; break;
987 case 2: O << "16"; break;
988 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000989 }
990}