blob: 0a0f1d07b53cf658f2e9a64def67dae189687946 [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 Anderson98c5dda2011-09-15 23:38:46 +000075 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +000093 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +000098 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000112 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000120 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000133 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000141 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000153 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000164 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000183 if (CommentStream) printAnnotation(*CommentStream, 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 Anderson98c5dda2011-09-15 23:38:46 +0000192 if (CommentStream) printAnnotation(*CommentStream, Annot);
Jim Grosbach0780b632011-08-19 23:24:36 +0000193 return;
194 }
195
Chris Lattner35c33bd2010-04-04 04:47:45 +0000196 printInstruction(MI, O);
Owen Anderson98c5dda2011-09-15 23:38:46 +0000197 if (CommentStream) printAnnotation(*CommentStream, 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
310void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
311 raw_ostream &O) {
312 const MCOperand &MO1 = MI->getOperand(Op);
313
314 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
315 printOperand(MI, Op, O);
316 return;
317 }
318
319 const MCOperand &MO3 = MI->getOperand(Op+2);
320 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
321
322 if (IdxMode == ARMII::IndexModePost) {
323 printAM2PostIndexOp(MI, Op, O);
324 return;
325 }
326 printAM2PreOrOffsetIndexOp(MI, Op, O);
327}
328
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000329void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000330 unsigned OpNum,
331 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000332 const MCOperand &MO1 = MI->getOperand(OpNum);
333 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000334
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000335 if (!MO1.getReg()) {
336 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000337 O << '#'
338 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
339 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000340 return;
341 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000342
Johnny Chen9e088762010-03-17 17:52:21 +0000343 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
344 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000345
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000346 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
347 O << ", "
348 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
349 << " #" << ShImm;
350}
351
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000352//===--------------------------------------------------------------------===//
353// Addressing Mode #3
354//===--------------------------------------------------------------------===//
355
356void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
357 raw_ostream &O) {
358 const MCOperand &MO1 = MI->getOperand(Op);
359 const MCOperand &MO2 = MI->getOperand(Op+1);
360 const MCOperand &MO3 = MI->getOperand(Op+2);
361
362 O << "[" << getRegisterName(MO1.getReg()) << "], ";
363
364 if (MO2.getReg()) {
365 O << (char)ARM_AM::getAM3Op(MO3.getImm())
366 << getRegisterName(MO2.getReg());
367 return;
368 }
369
370 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
371 O << '#'
372 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
373 << ImmOffs;
374}
375
376void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
377 raw_ostream &O) {
378 const MCOperand &MO1 = MI->getOperand(Op);
379 const MCOperand &MO2 = MI->getOperand(Op+1);
380 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000381
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000382 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000383
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000384 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000385 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000386 << getRegisterName(MO2.getReg()) << ']';
387 return;
388 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000389
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000390 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
391 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000392 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
393 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000394 O << ']';
395}
396
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000397void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
398 raw_ostream &O) {
399 const MCOperand &MO3 = MI->getOperand(Op+2);
400 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
401
402 if (IdxMode == ARMII::IndexModePost) {
403 printAM3PostIndexOp(MI, Op, O);
404 return;
405 }
406 printAM3PreOrOffsetIndexOp(MI, Op, O);
407}
408
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000409void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000410 unsigned OpNum,
411 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000412 const MCOperand &MO1 = MI->getOperand(OpNum);
413 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000414
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000415 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000416 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
417 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000418 return;
419 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000420
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000421 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000422 O << '#'
423 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
424 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000425}
426
Jim Grosbach7ce05792011-08-03 23:50:40 +0000427void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
428 unsigned OpNum,
429 raw_ostream &O) {
430 const MCOperand &MO = MI->getOperand(OpNum);
431 unsigned Imm = MO.getImm();
432 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
433}
434
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000435void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
436 raw_ostream &O) {
437 const MCOperand &MO1 = MI->getOperand(OpNum);
438 const MCOperand &MO2 = MI->getOperand(OpNum+1);
439
Jim Grosbach16578b52011-08-05 16:11:38 +0000440 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000441}
442
Owen Anderson154c41d2011-08-04 18:24:14 +0000443void ARMInstPrinter::printPostIdxImm8s4Operand(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) << 2);
449}
450
451
Jim Grosbache6913602010-11-03 01:01:43 +0000452void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000453 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000454 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
455 .getImm());
456 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000457}
458
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000459void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000460 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000461 const MCOperand &MO1 = MI->getOperand(OpNum);
462 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000463
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000464 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000465 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000466 return;
467 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000468
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000469 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000470
Owen Anderson0da10cf2011-08-29 19:36:44 +0000471 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
472 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
473 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000474 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000475 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000476 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000477 }
478 O << "]";
479}
480
Chris Lattner35c33bd2010-04-04 04:47:45 +0000481void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
482 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000483 const MCOperand &MO1 = MI->getOperand(OpNum);
484 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000485
Bob Wilson226036e2010-03-20 22:13:40 +0000486 O << "[" << getRegisterName(MO1.getReg());
487 if (MO2.getImm()) {
488 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000489 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000490 }
Bob Wilson226036e2010-03-20 22:13:40 +0000491 O << "]";
492}
493
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000494void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
495 raw_ostream &O) {
496 const MCOperand &MO1 = MI->getOperand(OpNum);
497 O << "[" << getRegisterName(MO1.getReg()) << "]";
498}
499
Bob Wilson226036e2010-03-20 22:13:40 +0000500void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000501 unsigned OpNum,
502 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000503 const MCOperand &MO = MI->getOperand(OpNum);
504 if (MO.getReg() == 0)
505 O << "!";
506 else
507 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000508}
509
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000510void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
511 unsigned OpNum,
512 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000513 const MCOperand &MO = MI->getOperand(OpNum);
514 uint32_t v = ~MO.getImm();
515 int32_t lsb = CountTrailingZeros_32(v);
516 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
517 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
518 O << '#' << lsb << ", #" << width;
519}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000520
Johnny Chen1adc40c2010-08-12 20:46:17 +0000521void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
522 raw_ostream &O) {
523 unsigned val = MI->getOperand(OpNum).getImm();
524 O << ARM_MB::MemBOptToString(val);
525}
526
Bob Wilson22f5dc72010-08-16 18:27:34 +0000527void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000528 raw_ostream &O) {
529 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000530 bool isASR = (ShiftOp & (1 << 5)) != 0;
531 unsigned Amt = ShiftOp & 0x1f;
532 if (isASR)
533 O << ", asr #" << (Amt == 0 ? 32 : Amt);
534 else if (Amt)
535 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000536}
537
Jim Grosbachdde038a2011-07-20 21:40:26 +0000538void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
539 raw_ostream &O) {
540 unsigned Imm = MI->getOperand(OpNum).getImm();
541 if (Imm == 0)
542 return;
543 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
544 O << ", lsl #" << Imm;
545}
546
547void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
548 raw_ostream &O) {
549 unsigned Imm = MI->getOperand(OpNum).getImm();
550 // A shift amount of 32 is encoded as 0.
551 if (Imm == 0)
552 Imm = 32;
553 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
554 O << ", asr #" << Imm;
555}
556
Chris Lattner35c33bd2010-04-04 04:47:45 +0000557void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
558 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000559 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000560 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
561 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000562 O << getRegisterName(MI->getOperand(i).getReg());
563 }
564 O << "}";
565}
Chris Lattner4d152222009-10-19 22:23:04 +0000566
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000567void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
568 raw_ostream &O) {
569 const MCOperand &Op = MI->getOperand(OpNum);
570 if (Op.getImm())
571 O << "be";
572 else
573 O << "le";
574}
575
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000576void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
577 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000578 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000579 O << ARM_PROC::IModToString(Op.getImm());
580}
581
582void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
583 raw_ostream &O) {
584 const MCOperand &Op = MI->getOperand(OpNum);
585 unsigned IFlags = Op.getImm();
586 for (int i=2; i >= 0; --i)
587 if (IFlags & (1 << i))
588 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000589}
590
Chris Lattner35c33bd2010-04-04 04:47:45 +0000591void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
592 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000593 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000594 unsigned SpecRegRBit = Op.getImm() >> 4;
595 unsigned Mask = Op.getImm() & 0xf;
596
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000597 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
598 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
599 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
600 O << "APSR_";
601 switch (Mask) {
602 default: assert(0);
603 case 4: O << "g"; return;
604 case 8: O << "nzcvq"; return;
605 case 12: O << "nzcvqg"; return;
606 }
607 llvm_unreachable("Unexpected mask value!");
608 }
609
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000610 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000611 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000612 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000613 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000614
Johnny Chen9e088762010-03-17 17:52:21 +0000615 if (Mask) {
616 O << '_';
617 if (Mask & 8) O << 'f';
618 if (Mask & 4) O << 's';
619 if (Mask & 2) O << 'x';
620 if (Mask & 1) O << 'c';
621 }
622}
623
Chris Lattner35c33bd2010-04-04 04:47:45 +0000624void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
625 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000626 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
627 if (CC != ARMCC::AL)
628 O << ARMCondCodeToString(CC);
629}
630
Jim Grosbach15d78982010-09-14 22:27:15 +0000631void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000632 unsigned OpNum,
633 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000634 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
635 O << ARMCondCodeToString(CC);
636}
637
Chris Lattner35c33bd2010-04-04 04:47:45 +0000638void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
639 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000640 if (MI->getOperand(OpNum).getReg()) {
641 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
642 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000643 O << 's';
644 }
645}
646
Chris Lattner35c33bd2010-04-04 04:47:45 +0000647void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
648 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000649 O << MI->getOperand(OpNum).getImm();
650}
651
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000652void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
653 raw_ostream &O) {
654 O << "p" << MI->getOperand(OpNum).getImm();
655}
656
657void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
658 raw_ostream &O) {
659 O << "c" << MI->getOperand(OpNum).getImm();
660}
661
Chris Lattner35c33bd2010-04-04 04:47:45 +0000662void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
663 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000664 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000665}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000666
Chris Lattner35c33bd2010-04-04 04:47:45 +0000667void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
668 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000669 O << "#" << MI->getOperand(OpNum).getImm() * 4;
670}
671
672void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
673 raw_ostream &O) {
674 unsigned Imm = MI->getOperand(OpNum).getImm();
675 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000676}
Johnny Chen9e088762010-03-17 17:52:21 +0000677
Chris Lattner35c33bd2010-04-04 04:47:45 +0000678void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
679 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000680 // (3 - the number of trailing zeros) is the number of then / else.
681 unsigned Mask = MI->getOperand(OpNum).getImm();
682 unsigned CondBit0 = Mask >> 4 & 1;
683 unsigned NumTZ = CountTrailingZeros_32(Mask);
684 assert(NumTZ <= 3 && "Invalid IT mask!");
685 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
686 bool T = ((Mask >> Pos) & 1) == CondBit0;
687 if (T)
688 O << 't';
689 else
690 O << 'e';
691 }
692}
693
Chris Lattner35c33bd2010-04-04 04:47:45 +0000694void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
695 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000696 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000697 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000698
699 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000700 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000701 return;
702 }
703
704 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000705 if (unsigned RegNum = MO2.getReg())
706 O << ", " << getRegisterName(RegNum);
707 O << "]";
708}
709
710void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
711 unsigned Op,
712 raw_ostream &O,
713 unsigned Scale) {
714 const MCOperand &MO1 = MI->getOperand(Op);
715 const MCOperand &MO2 = MI->getOperand(Op + 1);
716
717 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
718 printOperand(MI, Op, O);
719 return;
720 }
721
722 O << "[" << getRegisterName(MO1.getReg());
723 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000724 O << ", #" << ImmOffs * Scale;
725 O << "]";
726}
727
Bill Wendlingf4caf692010-12-14 03:36:38 +0000728void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
729 unsigned Op,
730 raw_ostream &O) {
731 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000732}
733
Bill Wendlingf4caf692010-12-14 03:36:38 +0000734void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
735 unsigned Op,
736 raw_ostream &O) {
737 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000738}
739
Bill Wendlingf4caf692010-12-14 03:36:38 +0000740void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
741 unsigned Op,
742 raw_ostream &O) {
743 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000744}
745
Chris Lattner35c33bd2010-04-04 04:47:45 +0000746void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
747 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000748 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000749}
750
Johnny Chen9e088762010-03-17 17:52:21 +0000751// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
752// register with shift forms.
753// REG 0 0 - e.g. R5
754// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000755void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
756 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000757 const MCOperand &MO1 = MI->getOperand(OpNum);
758 const MCOperand &MO2 = MI->getOperand(OpNum+1);
759
760 unsigned Reg = MO1.getReg();
761 O << getRegisterName(Reg);
762
763 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000764 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000765 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
766 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
767 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000768 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000769}
770
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000771void ARMInstPrinter::printAddrModeImm12Operand(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
Jim Grosbach3e556122010-10-26 22:37:02 +0000776 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
777 printOperand(MI, OpNum, O);
778 return;
779 }
780
Johnny Chen9e088762010-03-17 17:52:21 +0000781 O << "[" << getRegisterName(MO1.getReg());
782
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000783 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000784 bool isSub = OffImm < 0;
785 // Special value for #-0. All others are normal.
786 if (OffImm == INT32_MIN)
787 OffImm = 0;
788 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000789 O << ", #-" << -OffImm;
790 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000791 O << ", #" << OffImm;
792 O << "]";
793}
794
795void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000796 unsigned OpNum,
797 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000798 const MCOperand &MO1 = MI->getOperand(OpNum);
799 const MCOperand &MO2 = MI->getOperand(OpNum+1);
800
801 O << "[" << getRegisterName(MO1.getReg());
802
803 int32_t OffImm = (int32_t)MO2.getImm();
804 // Don't print +0.
805 if (OffImm < 0)
806 O << ", #-" << -OffImm;
807 else if (OffImm > 0)
808 O << ", #" << OffImm;
809 O << "]";
810}
811
812void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000813 unsigned OpNum,
814 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000815 const MCOperand &MO1 = MI->getOperand(OpNum);
816 const MCOperand &MO2 = MI->getOperand(OpNum+1);
817
818 O << "[" << getRegisterName(MO1.getReg());
819
820 int32_t OffImm = (int32_t)MO2.getImm() / 4;
821 // Don't print +0.
822 if (OffImm < 0)
823 O << ", #-" << -OffImm * 4;
824 else if (OffImm > 0)
825 O << ", #" << OffImm * 4;
826 O << "]";
827}
828
Jim Grosbachb6aed502011-09-09 18:37:27 +0000829void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
830 unsigned OpNum,
831 raw_ostream &O) {
832 const MCOperand &MO1 = MI->getOperand(OpNum);
833 const MCOperand &MO2 = MI->getOperand(OpNum+1);
834
835 O << "[" << getRegisterName(MO1.getReg());
836 if (MO2.getImm())
837 O << ", #" << MO2.getImm() * 4;
838 O << "]";
839}
840
Johnny Chen9e088762010-03-17 17:52:21 +0000841void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000842 unsigned OpNum,
843 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000844 const MCOperand &MO1 = MI->getOperand(OpNum);
845 int32_t OffImm = (int32_t)MO1.getImm();
846 // Don't print +0.
847 if (OffImm < 0)
848 O << "#-" << -OffImm;
849 else if (OffImm > 0)
850 O << "#" << OffImm;
851}
852
853void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(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 int32_t OffImm = (int32_t)MO1.getImm() / 4;
858 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000859 if (OffImm != 0) {
860 O << ", ";
861 if (OffImm < 0)
862 O << "#-" << -OffImm * 4;
863 else if (OffImm > 0)
864 O << "#" << OffImm * 4;
865 }
Johnny Chen9e088762010-03-17 17:52:21 +0000866}
867
868void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000869 unsigned OpNum,
870 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000871 const MCOperand &MO1 = MI->getOperand(OpNum);
872 const MCOperand &MO2 = MI->getOperand(OpNum+1);
873 const MCOperand &MO3 = MI->getOperand(OpNum+2);
874
875 O << "[" << getRegisterName(MO1.getReg());
876
877 assert(MO2.getReg() && "Invalid so_reg load / store address!");
878 O << ", " << getRegisterName(MO2.getReg());
879
880 unsigned ShAmt = MO3.getImm();
881 if (ShAmt) {
882 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
883 O << ", lsl #" << ShAmt;
884 }
885 O << "]";
886}
887
Chris Lattner35c33bd2010-04-04 04:47:45 +0000888void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
889 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000890 const MCOperand &MO = MI->getOperand(OpNum);
891 O << '#';
892 if (MO.isFPImm()) {
893 O << (float)MO.getFPImm();
894 } else {
895 union {
896 uint32_t I;
897 float F;
898 } FPUnion;
899
900 FPUnion.I = MO.getImm();
901 O << FPUnion.F;
902 }
Johnny Chen9e088762010-03-17 17:52:21 +0000903}
904
Chris Lattner35c33bd2010-04-04 04:47:45 +0000905void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
906 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000907 const MCOperand &MO = MI->getOperand(OpNum);
908 O << '#';
909 if (MO.isFPImm()) {
910 O << MO.getFPImm();
911 } else {
912 // We expect the binary encoding of a floating point number here.
913 union {
914 uint64_t I;
915 double D;
916 } FPUnion;
917
918 FPUnion.I = MO.getImm();
919 O << FPUnion.D;
920 }
Johnny Chen9e088762010-03-17 17:52:21 +0000921}
922
Bob Wilson1a913ed2010-06-11 21:34:50 +0000923void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
924 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000925 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
926 unsigned EltBits;
927 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000928 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000929}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000930
Jim Grosbachf4943352011-07-25 23:09:14 +0000931void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
932 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000933 unsigned Imm = MI->getOperand(OpNum).getImm();
934 O << "#" << Imm + 1;
935}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000936
937void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
938 raw_ostream &O) {
939 unsigned Imm = MI->getOperand(OpNum).getImm();
940 if (Imm == 0)
941 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000942 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000943 switch (Imm) {
944 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000945 case 1: O << "8"; break;
946 case 2: O << "16"; break;
947 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000948 }
949}