blob: 277d44cfacac718bb5fa05a857741270bd9cf1a7 [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 Anderson317eaf12011-09-21 00:25:23 +000075 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +000093 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +000098 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000112 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000120 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000133 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000141 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000153 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000164 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000183 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000192 if (CommentStream) 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 Anderson317eaf12011-09-21 00:25:23 +0000197 if (CommentStream) 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
Chris Lattner017d9472009-10-20 00:40:56 +0000214// so_reg is a 4-operand unit corresponding to register forms of the A5.1
215// "Addressing Mode 1 - Data-processing operands" forms. This includes:
216// REG 0 0 - e.g. R5
217// REG REG 0,SH_OPC - e.g. R5, ROR R3
218// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000219void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000220 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000221 const MCOperand &MO1 = MI->getOperand(OpNum);
222 const MCOperand &MO2 = MI->getOperand(OpNum+1);
223 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000224
Chris Lattner017d9472009-10-20 00:40:56 +0000225 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000226
Chris Lattner017d9472009-10-20 00:40:56 +0000227 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000228 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
229 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000230 if (ShOpc == ARM_AM::rrx)
231 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000232
233 O << ' ' << getRegisterName(MO2.getReg());
234 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000235}
Chris Lattner084f87d2009-10-19 21:57:05 +0000236
Owen Anderson152d4a42011-07-21 23:38:37 +0000237void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
238 raw_ostream &O) {
239 const MCOperand &MO1 = MI->getOperand(OpNum);
240 const MCOperand &MO2 = MI->getOperand(OpNum+1);
241
242 O << getRegisterName(MO1.getReg());
243
244 // Print the shift opc.
245 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
246 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
247 if (ShOpc == ARM_AM::rrx)
248 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000249 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000250}
251
252
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000253//===--------------------------------------------------------------------===//
254// Addressing Mode #2
255//===--------------------------------------------------------------------===//
256
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000257void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
258 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000259 const MCOperand &MO1 = MI->getOperand(Op);
260 const MCOperand &MO2 = MI->getOperand(Op+1);
261 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000262
Chris Lattner084f87d2009-10-19 21:57:05 +0000263 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000264
Chris Lattner084f87d2009-10-19 21:57:05 +0000265 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000266 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000267 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000268 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
269 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000270 O << "]";
271 return;
272 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000273
Chris Lattner084f87d2009-10-19 21:57:05 +0000274 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000275 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
276 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000277
Chris Lattner084f87d2009-10-19 21:57:05 +0000278 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
279 O << ", "
280 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
281 << " #" << ShImm;
282 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000283}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000284
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000285void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
286 raw_ostream &O) {
287 const MCOperand &MO1 = MI->getOperand(Op);
288 const MCOperand &MO2 = MI->getOperand(Op+1);
289 const MCOperand &MO3 = MI->getOperand(Op+2);
290
291 O << "[" << getRegisterName(MO1.getReg()) << "], ";
292
293 if (!MO2.getReg()) {
294 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
295 O << '#'
296 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
297 << ImmOffs;
298 return;
299 }
300
301 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
302 << getRegisterName(MO2.getReg());
303
304 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
305 O << ", "
306 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
307 << " #" << ShImm;
308}
309
Jim Grosbach7f739be2011-09-19 22:21:13 +0000310void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
311 raw_ostream &O) {
312 const MCOperand &MO1 = MI->getOperand(Op);
313 const MCOperand &MO2 = MI->getOperand(Op+1);
314 O << "[" << getRegisterName(MO1.getReg()) << ", "
315 << getRegisterName(MO2.getReg()) << "]";
316}
317
318void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
319 raw_ostream &O) {
320 const MCOperand &MO1 = MI->getOperand(Op);
321 const MCOperand &MO2 = MI->getOperand(Op+1);
322 O << "[" << getRegisterName(MO1.getReg()) << ", "
323 << getRegisterName(MO2.getReg()) << ", lsl #1]";
324}
325
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000326void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
327 raw_ostream &O) {
328 const MCOperand &MO1 = MI->getOperand(Op);
329
330 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
331 printOperand(MI, Op, O);
332 return;
333 }
334
335 const MCOperand &MO3 = MI->getOperand(Op+2);
336 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
337
338 if (IdxMode == ARMII::IndexModePost) {
339 printAM2PostIndexOp(MI, Op, O);
340 return;
341 }
342 printAM2PreOrOffsetIndexOp(MI, Op, O);
343}
344
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000345void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000346 unsigned OpNum,
347 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000348 const MCOperand &MO1 = MI->getOperand(OpNum);
349 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000350
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000351 if (!MO1.getReg()) {
352 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000353 O << '#'
354 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
355 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000356 return;
357 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000358
Johnny Chen9e088762010-03-17 17:52:21 +0000359 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
360 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000361
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000362 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
363 O << ", "
364 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
365 << " #" << ShImm;
366}
367
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000368//===--------------------------------------------------------------------===//
369// Addressing Mode #3
370//===--------------------------------------------------------------------===//
371
372void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
373 raw_ostream &O) {
374 const MCOperand &MO1 = MI->getOperand(Op);
375 const MCOperand &MO2 = MI->getOperand(Op+1);
376 const MCOperand &MO3 = MI->getOperand(Op+2);
377
378 O << "[" << getRegisterName(MO1.getReg()) << "], ";
379
380 if (MO2.getReg()) {
381 O << (char)ARM_AM::getAM3Op(MO3.getImm())
382 << getRegisterName(MO2.getReg());
383 return;
384 }
385
386 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
387 O << '#'
388 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
389 << ImmOffs;
390}
391
392void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
393 raw_ostream &O) {
394 const MCOperand &MO1 = MI->getOperand(Op);
395 const MCOperand &MO2 = MI->getOperand(Op+1);
396 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000397
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000398 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000399
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000400 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000401 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000402 << getRegisterName(MO2.getReg()) << ']';
403 return;
404 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000405
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000406 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
407 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000408 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
409 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000410 O << ']';
411}
412
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000413void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
414 raw_ostream &O) {
415 const MCOperand &MO3 = MI->getOperand(Op+2);
416 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
417
418 if (IdxMode == ARMII::IndexModePost) {
419 printAM3PostIndexOp(MI, Op, O);
420 return;
421 }
422 printAM3PreOrOffsetIndexOp(MI, Op, O);
423}
424
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000425void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000426 unsigned OpNum,
427 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000428 const MCOperand &MO1 = MI->getOperand(OpNum);
429 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000430
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000431 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000432 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
433 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000434 return;
435 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000436
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000437 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000438 O << '#'
439 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
440 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000441}
442
Jim Grosbach7ce05792011-08-03 23:50:40 +0000443void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
444 unsigned OpNum,
445 raw_ostream &O) {
446 const MCOperand &MO = MI->getOperand(OpNum);
447 unsigned Imm = MO.getImm();
448 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
449}
450
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000451void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
452 raw_ostream &O) {
453 const MCOperand &MO1 = MI->getOperand(OpNum);
454 const MCOperand &MO2 = MI->getOperand(OpNum+1);
455
Jim Grosbach16578b52011-08-05 16:11:38 +0000456 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000457}
458
Owen Anderson154c41d2011-08-04 18:24:14 +0000459void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
460 unsigned OpNum,
461 raw_ostream &O) {
462 const MCOperand &MO = MI->getOperand(OpNum);
463 unsigned Imm = MO.getImm();
464 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
465}
466
467
Jim Grosbache6913602010-11-03 01:01:43 +0000468void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000469 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000470 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
471 .getImm());
472 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000473}
474
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000475void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000476 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000477 const MCOperand &MO1 = MI->getOperand(OpNum);
478 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000479
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000480 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000481 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000482 return;
483 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000484
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000485 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000486
Owen Anderson0da10cf2011-08-29 19:36:44 +0000487 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
488 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
489 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000490 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000491 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000492 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000493 }
494 O << "]";
495}
496
Chris Lattner35c33bd2010-04-04 04:47:45 +0000497void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
498 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000499 const MCOperand &MO1 = MI->getOperand(OpNum);
500 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000501
Bob Wilson226036e2010-03-20 22:13:40 +0000502 O << "[" << getRegisterName(MO1.getReg());
503 if (MO2.getImm()) {
504 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000505 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000506 }
Bob Wilson226036e2010-03-20 22:13:40 +0000507 O << "]";
508}
509
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000510void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
511 raw_ostream &O) {
512 const MCOperand &MO1 = MI->getOperand(OpNum);
513 O << "[" << getRegisterName(MO1.getReg()) << "]";
514}
515
Bob Wilson226036e2010-03-20 22:13:40 +0000516void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000517 unsigned OpNum,
518 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000519 const MCOperand &MO = MI->getOperand(OpNum);
520 if (MO.getReg() == 0)
521 O << "!";
522 else
523 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000524}
525
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000526void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
527 unsigned OpNum,
528 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000529 const MCOperand &MO = MI->getOperand(OpNum);
530 uint32_t v = ~MO.getImm();
531 int32_t lsb = CountTrailingZeros_32(v);
532 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
533 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
534 O << '#' << lsb << ", #" << width;
535}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000536
Johnny Chen1adc40c2010-08-12 20:46:17 +0000537void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
538 raw_ostream &O) {
539 unsigned val = MI->getOperand(OpNum).getImm();
540 O << ARM_MB::MemBOptToString(val);
541}
542
Bob Wilson22f5dc72010-08-16 18:27:34 +0000543void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000544 raw_ostream &O) {
545 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000546 bool isASR = (ShiftOp & (1 << 5)) != 0;
547 unsigned Amt = ShiftOp & 0x1f;
548 if (isASR)
549 O << ", asr #" << (Amt == 0 ? 32 : Amt);
550 else if (Amt)
551 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000552}
553
Jim Grosbachdde038a2011-07-20 21:40:26 +0000554void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
555 raw_ostream &O) {
556 unsigned Imm = MI->getOperand(OpNum).getImm();
557 if (Imm == 0)
558 return;
559 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
560 O << ", lsl #" << Imm;
561}
562
563void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
564 raw_ostream &O) {
565 unsigned Imm = MI->getOperand(OpNum).getImm();
566 // A shift amount of 32 is encoded as 0.
567 if (Imm == 0)
568 Imm = 32;
569 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
570 O << ", asr #" << Imm;
571}
572
Chris Lattner35c33bd2010-04-04 04:47:45 +0000573void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
574 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000575 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000576 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
577 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000578 O << getRegisterName(MI->getOperand(i).getReg());
579 }
580 O << "}";
581}
Chris Lattner4d152222009-10-19 22:23:04 +0000582
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000583void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
584 raw_ostream &O) {
585 const MCOperand &Op = MI->getOperand(OpNum);
586 if (Op.getImm())
587 O << "be";
588 else
589 O << "le";
590}
591
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000592void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
593 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000594 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000595 O << ARM_PROC::IModToString(Op.getImm());
596}
597
598void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
599 raw_ostream &O) {
600 const MCOperand &Op = MI->getOperand(OpNum);
601 unsigned IFlags = Op.getImm();
602 for (int i=2; i >= 0; --i)
603 if (IFlags & (1 << i))
604 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000605}
606
Chris Lattner35c33bd2010-04-04 04:47:45 +0000607void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
608 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000609 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000610 unsigned SpecRegRBit = Op.getImm() >> 4;
611 unsigned Mask = Op.getImm() & 0xf;
612
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000613 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
614 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
615 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
616 O << "APSR_";
617 switch (Mask) {
618 default: assert(0);
619 case 4: O << "g"; return;
620 case 8: O << "nzcvq"; return;
621 case 12: O << "nzcvqg"; return;
622 }
623 llvm_unreachable("Unexpected mask value!");
624 }
625
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000626 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000627 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000628 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000629 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000630
Johnny Chen9e088762010-03-17 17:52:21 +0000631 if (Mask) {
632 O << '_';
633 if (Mask & 8) O << 'f';
634 if (Mask & 4) O << 's';
635 if (Mask & 2) O << 'x';
636 if (Mask & 1) O << 'c';
637 }
638}
639
Chris Lattner35c33bd2010-04-04 04:47:45 +0000640void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
641 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000642 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
643 if (CC != ARMCC::AL)
644 O << ARMCondCodeToString(CC);
645}
646
Jim Grosbach15d78982010-09-14 22:27:15 +0000647void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000648 unsigned OpNum,
649 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000650 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
651 O << ARMCondCodeToString(CC);
652}
653
Chris Lattner35c33bd2010-04-04 04:47:45 +0000654void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
655 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000656 if (MI->getOperand(OpNum).getReg()) {
657 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
658 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000659 O << 's';
660 }
661}
662
Chris Lattner35c33bd2010-04-04 04:47:45 +0000663void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
664 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000665 O << MI->getOperand(OpNum).getImm();
666}
667
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000668void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
669 raw_ostream &O) {
670 O << "p" << MI->getOperand(OpNum).getImm();
671}
672
673void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
674 raw_ostream &O) {
675 O << "c" << MI->getOperand(OpNum).getImm();
676}
677
Chris Lattner35c33bd2010-04-04 04:47:45 +0000678void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
679 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000680 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000681}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000682
Chris Lattner35c33bd2010-04-04 04:47:45 +0000683void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
684 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000685 O << "#" << MI->getOperand(OpNum).getImm() * 4;
686}
687
688void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
689 raw_ostream &O) {
690 unsigned Imm = MI->getOperand(OpNum).getImm();
691 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000692}
Johnny Chen9e088762010-03-17 17:52:21 +0000693
Chris Lattner35c33bd2010-04-04 04:47:45 +0000694void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
695 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000696 // (3 - the number of trailing zeros) is the number of then / else.
697 unsigned Mask = MI->getOperand(OpNum).getImm();
698 unsigned CondBit0 = Mask >> 4 & 1;
699 unsigned NumTZ = CountTrailingZeros_32(Mask);
700 assert(NumTZ <= 3 && "Invalid IT mask!");
701 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
702 bool T = ((Mask >> Pos) & 1) == CondBit0;
703 if (T)
704 O << 't';
705 else
706 O << 'e';
707 }
708}
709
Chris Lattner35c33bd2010-04-04 04:47:45 +0000710void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
711 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000712 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000713 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000714
715 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000716 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000717 return;
718 }
719
720 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000721 if (unsigned RegNum = MO2.getReg())
722 O << ", " << getRegisterName(RegNum);
723 O << "]";
724}
725
726void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
727 unsigned Op,
728 raw_ostream &O,
729 unsigned Scale) {
730 const MCOperand &MO1 = MI->getOperand(Op);
731 const MCOperand &MO2 = MI->getOperand(Op + 1);
732
733 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
734 printOperand(MI, Op, O);
735 return;
736 }
737
738 O << "[" << getRegisterName(MO1.getReg());
739 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000740 O << ", #" << ImmOffs * Scale;
741 O << "]";
742}
743
Bill Wendlingf4caf692010-12-14 03:36:38 +0000744void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
745 unsigned Op,
746 raw_ostream &O) {
747 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000748}
749
Bill Wendlingf4caf692010-12-14 03:36:38 +0000750void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
751 unsigned Op,
752 raw_ostream &O) {
753 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000754}
755
Bill Wendlingf4caf692010-12-14 03:36:38 +0000756void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
757 unsigned Op,
758 raw_ostream &O) {
759 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000760}
761
Chris Lattner35c33bd2010-04-04 04:47:45 +0000762void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
763 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000764 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000765}
766
Johnny Chen9e088762010-03-17 17:52:21 +0000767// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
768// register with shift forms.
769// REG 0 0 - e.g. R5
770// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000771void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
772 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000773 const MCOperand &MO1 = MI->getOperand(OpNum);
774 const MCOperand &MO2 = MI->getOperand(OpNum+1);
775
776 unsigned Reg = MO1.getReg();
777 O << getRegisterName(Reg);
778
779 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000780 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000781 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
782 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
783 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000784 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000785}
786
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000787void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
788 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000789 const MCOperand &MO1 = MI->getOperand(OpNum);
790 const MCOperand &MO2 = MI->getOperand(OpNum+1);
791
Jim Grosbach3e556122010-10-26 22:37:02 +0000792 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
793 printOperand(MI, OpNum, O);
794 return;
795 }
796
Johnny Chen9e088762010-03-17 17:52:21 +0000797 O << "[" << getRegisterName(MO1.getReg());
798
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000799 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000800 bool isSub = OffImm < 0;
801 // Special value for #-0. All others are normal.
802 if (OffImm == INT32_MIN)
803 OffImm = 0;
804 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000805 O << ", #-" << -OffImm;
806 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000807 O << ", #" << OffImm;
808 O << "]";
809}
810
811void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000812 unsigned OpNum,
813 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000814 const MCOperand &MO1 = MI->getOperand(OpNum);
815 const MCOperand &MO2 = MI->getOperand(OpNum+1);
816
817 O << "[" << getRegisterName(MO1.getReg());
818
819 int32_t OffImm = (int32_t)MO2.getImm();
820 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000821 if (OffImm == INT32_MIN)
822 O << ", #-0";
823 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000824 O << ", #-" << -OffImm;
825 else if (OffImm > 0)
826 O << ", #" << OffImm;
827 O << "]";
828}
829
830void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000831 unsigned OpNum,
832 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000833 const MCOperand &MO1 = MI->getOperand(OpNum);
834 const MCOperand &MO2 = MI->getOperand(OpNum+1);
835
836 O << "[" << getRegisterName(MO1.getReg());
837
838 int32_t OffImm = (int32_t)MO2.getImm() / 4;
839 // Don't print +0.
840 if (OffImm < 0)
841 O << ", #-" << -OffImm * 4;
842 else if (OffImm > 0)
843 O << ", #" << OffImm * 4;
844 O << "]";
845}
846
Jim Grosbachb6aed502011-09-09 18:37:27 +0000847void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
848 unsigned OpNum,
849 raw_ostream &O) {
850 const MCOperand &MO1 = MI->getOperand(OpNum);
851 const MCOperand &MO2 = MI->getOperand(OpNum+1);
852
853 O << "[" << getRegisterName(MO1.getReg());
854 if (MO2.getImm())
855 O << ", #" << MO2.getImm() * 4;
856 O << "]";
857}
858
Johnny Chen9e088762010-03-17 17:52:21 +0000859void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000860 unsigned OpNum,
861 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000862 const MCOperand &MO1 = MI->getOperand(OpNum);
863 int32_t OffImm = (int32_t)MO1.getImm();
864 // Don't print +0.
865 if (OffImm < 0)
866 O << "#-" << -OffImm;
867 else if (OffImm > 0)
868 O << "#" << OffImm;
869}
870
871void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000872 unsigned OpNum,
873 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000874 const MCOperand &MO1 = MI->getOperand(OpNum);
875 int32_t OffImm = (int32_t)MO1.getImm() / 4;
876 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000877 if (OffImm != 0) {
878 O << ", ";
879 if (OffImm < 0)
880 O << "#-" << -OffImm * 4;
881 else if (OffImm > 0)
882 O << "#" << OffImm * 4;
883 }
Johnny Chen9e088762010-03-17 17:52:21 +0000884}
885
886void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000887 unsigned OpNum,
888 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000889 const MCOperand &MO1 = MI->getOperand(OpNum);
890 const MCOperand &MO2 = MI->getOperand(OpNum+1);
891 const MCOperand &MO3 = MI->getOperand(OpNum+2);
892
893 O << "[" << getRegisterName(MO1.getReg());
894
895 assert(MO2.getReg() && "Invalid so_reg load / store address!");
896 O << ", " << getRegisterName(MO2.getReg());
897
898 unsigned ShAmt = MO3.getImm();
899 if (ShAmt) {
900 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
901 O << ", lsl #" << ShAmt;
902 }
903 O << "]";
904}
905
Chris Lattner35c33bd2010-04-04 04:47:45 +0000906void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
907 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000908 const MCOperand &MO = MI->getOperand(OpNum);
909 O << '#';
910 if (MO.isFPImm()) {
911 O << (float)MO.getFPImm();
912 } else {
913 union {
914 uint32_t I;
915 float F;
916 } FPUnion;
917
918 FPUnion.I = MO.getImm();
919 O << FPUnion.F;
920 }
Johnny Chen9e088762010-03-17 17:52:21 +0000921}
922
Chris Lattner35c33bd2010-04-04 04:47:45 +0000923void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
924 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000925 const MCOperand &MO = MI->getOperand(OpNum);
926 O << '#';
927 if (MO.isFPImm()) {
928 O << MO.getFPImm();
929 } else {
930 // We expect the binary encoding of a floating point number here.
931 union {
932 uint64_t I;
933 double D;
934 } FPUnion;
935
936 FPUnion.I = MO.getImm();
937 O << FPUnion.D;
938 }
Johnny Chen9e088762010-03-17 17:52:21 +0000939}
940
Bob Wilson1a913ed2010-06-11 21:34:50 +0000941void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
942 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000943 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
944 unsigned EltBits;
945 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000946 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000947}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000948
Jim Grosbachf4943352011-07-25 23:09:14 +0000949void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
950 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000951 unsigned Imm = MI->getOperand(OpNum).getImm();
952 O << "#" << Imm + 1;
953}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000954
955void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
956 raw_ostream &O) {
957 unsigned Imm = MI->getOperand(OpNum).getImm();
958 if (Imm == 0)
959 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000960 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000961 switch (Imm) {
962 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000963 case 1: O << "8"; break;
964 case 2: O << "16"; break;
965 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000966 }
967}