blob: 6453604b3093d568ef418adca28c5c65e778ca17 [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
Chris Lattnerd3740872010-04-04 05:04:31 +000054void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) {
Bill Wendling04863d02010-11-13 10:40:19 +000055 unsigned Opcode = MI->getOpcode();
56
Johnny Chen9e088762010-03-17 17:52:21 +000057 // Check for MOVs and print canonical forms, instead.
Owen Anderson152d4a42011-07-21 23:38:37 +000058 if (Opcode == ARM::MOVsr) {
Jim Grosbache6be85e2010-09-17 22:36:38 +000059 // FIXME: Thumb variants?
Johnny Chen9e088762010-03-17 17:52:21 +000060 const MCOperand &Dst = MI->getOperand(0);
61 const MCOperand &MO1 = MI->getOperand(1);
62 const MCOperand &MO2 = MI->getOperand(2);
63 const MCOperand &MO3 = MI->getOperand(3);
64
65 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner35c33bd2010-04-04 04:47:45 +000066 printSBitModifierOperand(MI, 6, O);
67 printPredicateOperand(MI, 4, O);
Johnny Chen9e088762010-03-17 17:52:21 +000068
69 O << '\t' << getRegisterName(Dst.getReg())
70 << ", " << getRegisterName(MO1.getReg());
71
Owen Anderson152d4a42011-07-21 23:38:37 +000072 O << ", " << getRegisterName(MO2.getReg());
73 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Johnny Chen9e088762010-03-17 17:52:21 +000074 return;
75 }
76
Owen Anderson152d4a42011-07-21 23:38:37 +000077 if (Opcode == ARM::MOVsi) {
78 // FIXME: Thumb variants?
79 const MCOperand &Dst = MI->getOperand(0);
80 const MCOperand &MO1 = MI->getOperand(1);
81 const MCOperand &MO2 = MI->getOperand(2);
82
83 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
84 printSBitModifierOperand(MI, 5, O);
85 printPredicateOperand(MI, 3, O);
86
87 O << '\t' << getRegisterName(Dst.getReg())
88 << ", " << getRegisterName(MO1.getReg());
89
90 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx)
91 return;
92
Owen Anderson3dac0be2011-08-11 18:41:59 +000093 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +000094 return;
95 }
96
97
Johnny Chen9e088762010-03-17 17:52:21 +000098 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +000099 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000100 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000101 O << '\t' << "push";
102 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000103 if (Opcode == ARM::t2STMDB_UPD)
104 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000105 O << '\t';
106 printRegisterList(MI, 4, O);
107 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000108 }
Jim Grosbachf6713912011-08-11 18:07:11 +0000109 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
110 MI->getOperand(3).getImm() == -4) {
111 O << '\t' << "push";
112 printPredicateOperand(MI, 4, O);
113 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
114 return;
115 }
Johnny Chen9e088762010-03-17 17:52:21 +0000116
117 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000118 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000119 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000120 O << '\t' << "pop";
121 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000122 if (Opcode == ARM::t2LDMIA_UPD)
123 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000124 O << '\t';
125 printRegisterList(MI, 4, O);
126 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000127 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000128 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
129 MI->getOperand(4).getImm() == 4) {
130 O << '\t' << "pop";
131 printPredicateOperand(MI, 5, O);
132 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
133 return;
134 }
135
Johnny Chen9e088762010-03-17 17:52:21 +0000136
137 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000138 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000139 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000140 O << '\t' << "vpush";
141 printPredicateOperand(MI, 2, O);
142 O << '\t';
143 printRegisterList(MI, 4, O);
144 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000145 }
146
147 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000148 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000149 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000150 O << '\t' << "vpop";
151 printPredicateOperand(MI, 2, O);
152 O << '\t';
153 printRegisterList(MI, 4, O);
154 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000155 }
156
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000157 if (Opcode == ARM::tLDMIA) {
Owen Anderson565a0362011-07-18 23:25:34 +0000158 bool Writeback = true;
159 unsigned BaseReg = MI->getOperand(0).getReg();
160 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
161 if (MI->getOperand(i).getReg() == BaseReg)
162 Writeback = false;
163 }
164
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000165 O << "\tldm";
Owen Anderson565a0362011-07-18 23:25:34 +0000166
167 printPredicateOperand(MI, 1, O);
168 O << '\t' << getRegisterName(BaseReg);
169 if (Writeback) O << "!";
170 O << ", ";
171 printRegisterList(MI, 3, O);
172 return;
173 }
174
Jim Grosbach0780b632011-08-19 23:24:36 +0000175 // Thumb1 NOP
176 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
177 MI->getOperand(1).getReg() == ARM::R8) {
178 O << "\tnop";
Jim Grosbachdf9ce6b2011-08-24 20:06:14 +0000179 printPredicateOperand(MI, 2, O);
Jim Grosbach0780b632011-08-19 23:24:36 +0000180 return;
181 }
182
Chris Lattner35c33bd2010-04-04 04:47:45 +0000183 printInstruction(MI, O);
Bill Wendling04863d02010-11-13 10:40:19 +0000184}
Chris Lattnerfd603822009-10-19 19:56:26 +0000185
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000186void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000187 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000188 const MCOperand &Op = MI->getOperand(OpNo);
189 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000190 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000191 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000192 } else if (Op.isImm()) {
193 O << '#' << Op.getImm();
194 } else {
195 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000196 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000197 }
198}
Chris Lattner61d35c22009-10-19 21:21:39 +0000199
Chris Lattner017d9472009-10-20 00:40:56 +0000200// so_reg is a 4-operand unit corresponding to register forms of the A5.1
201// "Addressing Mode 1 - Data-processing operands" forms. This includes:
202// REG 0 0 - e.g. R5
203// REG REG 0,SH_OPC - e.g. R5, ROR R3
204// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000205void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000206 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000207 const MCOperand &MO1 = MI->getOperand(OpNum);
208 const MCOperand &MO2 = MI->getOperand(OpNum+1);
209 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000210
Chris Lattner017d9472009-10-20 00:40:56 +0000211 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000212
Chris Lattner017d9472009-10-20 00:40:56 +0000213 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000214 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
215 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000216 if (ShOpc == ARM_AM::rrx)
217 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000218
219 O << ' ' << getRegisterName(MO2.getReg());
220 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000221}
Chris Lattner084f87d2009-10-19 21:57:05 +0000222
Owen Anderson152d4a42011-07-21 23:38:37 +0000223void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
224 raw_ostream &O) {
225 const MCOperand &MO1 = MI->getOperand(OpNum);
226 const MCOperand &MO2 = MI->getOperand(OpNum+1);
227
228 O << getRegisterName(MO1.getReg());
229
230 // Print the shift opc.
231 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
232 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
233 if (ShOpc == ARM_AM::rrx)
234 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000235 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000236}
237
238
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000239//===--------------------------------------------------------------------===//
240// Addressing Mode #2
241//===--------------------------------------------------------------------===//
242
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000243void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
244 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000245 const MCOperand &MO1 = MI->getOperand(Op);
246 const MCOperand &MO2 = MI->getOperand(Op+1);
247 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000248
Chris Lattner084f87d2009-10-19 21:57:05 +0000249 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000250
Chris Lattner084f87d2009-10-19 21:57:05 +0000251 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000252 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000253 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000254 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
255 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000256 O << "]";
257 return;
258 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000259
Chris Lattner084f87d2009-10-19 21:57:05 +0000260 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000261 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
262 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000263
Chris Lattner084f87d2009-10-19 21:57:05 +0000264 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
265 O << ", "
266 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
267 << " #" << ShImm;
268 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000269}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000270
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000271void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
272 raw_ostream &O) {
273 const MCOperand &MO1 = MI->getOperand(Op);
274 const MCOperand &MO2 = MI->getOperand(Op+1);
275 const MCOperand &MO3 = MI->getOperand(Op+2);
276
277 O << "[" << getRegisterName(MO1.getReg()) << "], ";
278
279 if (!MO2.getReg()) {
280 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
281 O << '#'
282 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
283 << ImmOffs;
284 return;
285 }
286
287 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
288 << getRegisterName(MO2.getReg());
289
290 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
291 O << ", "
292 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
293 << " #" << ShImm;
294}
295
296void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
297 raw_ostream &O) {
298 const MCOperand &MO1 = MI->getOperand(Op);
299
300 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
301 printOperand(MI, Op, O);
302 return;
303 }
304
305 const MCOperand &MO3 = MI->getOperand(Op+2);
306 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
307
308 if (IdxMode == ARMII::IndexModePost) {
309 printAM2PostIndexOp(MI, Op, O);
310 return;
311 }
312 printAM2PreOrOffsetIndexOp(MI, Op, O);
313}
314
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000315void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000316 unsigned OpNum,
317 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000318 const MCOperand &MO1 = MI->getOperand(OpNum);
319 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000320
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000321 if (!MO1.getReg()) {
322 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000323 O << '#'
324 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
325 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000326 return;
327 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000328
Johnny Chen9e088762010-03-17 17:52:21 +0000329 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
330 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000331
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000332 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
333 O << ", "
334 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
335 << " #" << ShImm;
336}
337
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000338//===--------------------------------------------------------------------===//
339// Addressing Mode #3
340//===--------------------------------------------------------------------===//
341
342void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
343 raw_ostream &O) {
344 const MCOperand &MO1 = MI->getOperand(Op);
345 const MCOperand &MO2 = MI->getOperand(Op+1);
346 const MCOperand &MO3 = MI->getOperand(Op+2);
347
348 O << "[" << getRegisterName(MO1.getReg()) << "], ";
349
350 if (MO2.getReg()) {
351 O << (char)ARM_AM::getAM3Op(MO3.getImm())
352 << getRegisterName(MO2.getReg());
353 return;
354 }
355
356 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
357 O << '#'
358 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
359 << ImmOffs;
360}
361
362void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
363 raw_ostream &O) {
364 const MCOperand &MO1 = MI->getOperand(Op);
365 const MCOperand &MO2 = MI->getOperand(Op+1);
366 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000367
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000368 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000369
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000370 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000371 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000372 << getRegisterName(MO2.getReg()) << ']';
373 return;
374 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000375
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000376 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
377 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000378 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
379 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000380 O << ']';
381}
382
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000383void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
384 raw_ostream &O) {
385 const MCOperand &MO3 = MI->getOperand(Op+2);
386 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
387
388 if (IdxMode == ARMII::IndexModePost) {
389 printAM3PostIndexOp(MI, Op, O);
390 return;
391 }
392 printAM3PreOrOffsetIndexOp(MI, Op, O);
393}
394
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000395void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000396 unsigned OpNum,
397 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000398 const MCOperand &MO1 = MI->getOperand(OpNum);
399 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000400
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000401 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000402 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
403 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000404 return;
405 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000406
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000407 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000408 O << '#'
409 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
410 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000411}
412
Jim Grosbach7ce05792011-08-03 23:50:40 +0000413void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
414 unsigned OpNum,
415 raw_ostream &O) {
416 const MCOperand &MO = MI->getOperand(OpNum);
417 unsigned Imm = MO.getImm();
418 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
419}
420
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000421void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
422 raw_ostream &O) {
423 const MCOperand &MO1 = MI->getOperand(OpNum);
424 const MCOperand &MO2 = MI->getOperand(OpNum+1);
425
Jim Grosbach16578b52011-08-05 16:11:38 +0000426 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000427}
428
Owen Anderson154c41d2011-08-04 18:24:14 +0000429void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
430 unsigned OpNum,
431 raw_ostream &O) {
432 const MCOperand &MO = MI->getOperand(OpNum);
433 unsigned Imm = MO.getImm();
434 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
435}
436
437
Jim Grosbache6913602010-11-03 01:01:43 +0000438void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000439 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000440 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
441 .getImm());
442 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000443}
444
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000445void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000446 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000447 const MCOperand &MO1 = MI->getOperand(OpNum);
448 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000449
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000450 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000451 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000452 return;
453 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000454
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000455 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000456
Owen Anderson0da10cf2011-08-29 19:36:44 +0000457 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
458 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
459 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000460 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000461 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000462 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000463 }
464 O << "]";
465}
466
Chris Lattner35c33bd2010-04-04 04:47:45 +0000467void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
468 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000469 const MCOperand &MO1 = MI->getOperand(OpNum);
470 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000471
Bob Wilson226036e2010-03-20 22:13:40 +0000472 O << "[" << getRegisterName(MO1.getReg());
473 if (MO2.getImm()) {
474 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000475 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000476 }
Bob Wilson226036e2010-03-20 22:13:40 +0000477 O << "]";
478}
479
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000480void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
481 raw_ostream &O) {
482 const MCOperand &MO1 = MI->getOperand(OpNum);
483 O << "[" << getRegisterName(MO1.getReg()) << "]";
484}
485
Bob Wilson226036e2010-03-20 22:13:40 +0000486void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000487 unsigned OpNum,
488 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000489 const MCOperand &MO = MI->getOperand(OpNum);
490 if (MO.getReg() == 0)
491 O << "!";
492 else
493 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000494}
495
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000496void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
497 unsigned OpNum,
498 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000499 const MCOperand &MO = MI->getOperand(OpNum);
500 uint32_t v = ~MO.getImm();
501 int32_t lsb = CountTrailingZeros_32(v);
502 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
503 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
504 O << '#' << lsb << ", #" << width;
505}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000506
Johnny Chen1adc40c2010-08-12 20:46:17 +0000507void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
508 raw_ostream &O) {
509 unsigned val = MI->getOperand(OpNum).getImm();
510 O << ARM_MB::MemBOptToString(val);
511}
512
Bob Wilson22f5dc72010-08-16 18:27:34 +0000513void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000514 raw_ostream &O) {
515 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000516 bool isASR = (ShiftOp & (1 << 5)) != 0;
517 unsigned Amt = ShiftOp & 0x1f;
518 if (isASR)
519 O << ", asr #" << (Amt == 0 ? 32 : Amt);
520 else if (Amt)
521 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000522}
523
Jim Grosbachdde038a2011-07-20 21:40:26 +0000524void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
525 raw_ostream &O) {
526 unsigned Imm = MI->getOperand(OpNum).getImm();
527 if (Imm == 0)
528 return;
529 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
530 O << ", lsl #" << Imm;
531}
532
533void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
534 raw_ostream &O) {
535 unsigned Imm = MI->getOperand(OpNum).getImm();
536 // A shift amount of 32 is encoded as 0.
537 if (Imm == 0)
538 Imm = 32;
539 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
540 O << ", asr #" << Imm;
541}
542
Chris Lattner35c33bd2010-04-04 04:47:45 +0000543void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
544 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000545 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000546 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
547 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000548 O << getRegisterName(MI->getOperand(i).getReg());
549 }
550 O << "}";
551}
Chris Lattner4d152222009-10-19 22:23:04 +0000552
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000553void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
554 raw_ostream &O) {
555 const MCOperand &Op = MI->getOperand(OpNum);
556 if (Op.getImm())
557 O << "be";
558 else
559 O << "le";
560}
561
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000562void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
563 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000564 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000565 O << ARM_PROC::IModToString(Op.getImm());
566}
567
568void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
569 raw_ostream &O) {
570 const MCOperand &Op = MI->getOperand(OpNum);
571 unsigned IFlags = Op.getImm();
572 for (int i=2; i >= 0; --i)
573 if (IFlags & (1 << i))
574 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000575}
576
Chris Lattner35c33bd2010-04-04 04:47:45 +0000577void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
578 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000579 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000580 unsigned SpecRegRBit = Op.getImm() >> 4;
581 unsigned Mask = Op.getImm() & 0xf;
582
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000583 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
584 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
585 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
586 O << "APSR_";
587 switch (Mask) {
588 default: assert(0);
589 case 4: O << "g"; return;
590 case 8: O << "nzcvq"; return;
591 case 12: O << "nzcvqg"; return;
592 }
593 llvm_unreachable("Unexpected mask value!");
594 }
595
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000596 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000597 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000598 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000599 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000600
Johnny Chen9e088762010-03-17 17:52:21 +0000601 if (Mask) {
602 O << '_';
603 if (Mask & 8) O << 'f';
604 if (Mask & 4) O << 's';
605 if (Mask & 2) O << 'x';
606 if (Mask & 1) O << 'c';
607 }
608}
609
Chris Lattner35c33bd2010-04-04 04:47:45 +0000610void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
611 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000612 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
613 if (CC != ARMCC::AL)
614 O << ARMCondCodeToString(CC);
615}
616
Jim Grosbach15d78982010-09-14 22:27:15 +0000617void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000618 unsigned OpNum,
619 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000620 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
621 O << ARMCondCodeToString(CC);
622}
623
Chris Lattner35c33bd2010-04-04 04:47:45 +0000624void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
625 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000626 if (MI->getOperand(OpNum).getReg()) {
627 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
628 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000629 O << 's';
630 }
631}
632
Chris Lattner35c33bd2010-04-04 04:47:45 +0000633void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
634 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000635 O << MI->getOperand(OpNum).getImm();
636}
637
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000638void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
639 raw_ostream &O) {
640 O << "p" << MI->getOperand(OpNum).getImm();
641}
642
643void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
644 raw_ostream &O) {
645 O << "c" << MI->getOperand(OpNum).getImm();
646}
647
Chris Lattner35c33bd2010-04-04 04:47:45 +0000648void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
649 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000650 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000651}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000652
Chris Lattner35c33bd2010-04-04 04:47:45 +0000653void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
654 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000655 O << "#" << MI->getOperand(OpNum).getImm() * 4;
656}
657
658void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
659 raw_ostream &O) {
660 unsigned Imm = MI->getOperand(OpNum).getImm();
661 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000662}
Johnny Chen9e088762010-03-17 17:52:21 +0000663
Chris Lattner35c33bd2010-04-04 04:47:45 +0000664void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
665 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000666 // (3 - the number of trailing zeros) is the number of then / else.
667 unsigned Mask = MI->getOperand(OpNum).getImm();
668 unsigned CondBit0 = Mask >> 4 & 1;
669 unsigned NumTZ = CountTrailingZeros_32(Mask);
670 assert(NumTZ <= 3 && "Invalid IT mask!");
671 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
672 bool T = ((Mask >> Pos) & 1) == CondBit0;
673 if (T)
674 O << 't';
675 else
676 O << 'e';
677 }
678}
679
Chris Lattner35c33bd2010-04-04 04:47:45 +0000680void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
681 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000682 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000683 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000684
685 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000686 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000687 return;
688 }
689
690 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000691 if (unsigned RegNum = MO2.getReg())
692 O << ", " << getRegisterName(RegNum);
693 O << "]";
694}
695
696void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
697 unsigned Op,
698 raw_ostream &O,
699 unsigned Scale) {
700 const MCOperand &MO1 = MI->getOperand(Op);
701 const MCOperand &MO2 = MI->getOperand(Op + 1);
702
703 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
704 printOperand(MI, Op, O);
705 return;
706 }
707
708 O << "[" << getRegisterName(MO1.getReg());
709 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000710 O << ", #" << ImmOffs * Scale;
711 O << "]";
712}
713
Bill Wendlingf4caf692010-12-14 03:36:38 +0000714void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
715 unsigned Op,
716 raw_ostream &O) {
717 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000718}
719
Bill Wendlingf4caf692010-12-14 03:36:38 +0000720void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
721 unsigned Op,
722 raw_ostream &O) {
723 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000724}
725
Bill Wendlingf4caf692010-12-14 03:36:38 +0000726void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
727 unsigned Op,
728 raw_ostream &O) {
729 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000730}
731
Chris Lattner35c33bd2010-04-04 04:47:45 +0000732void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
733 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000734 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000735}
736
Johnny Chen9e088762010-03-17 17:52:21 +0000737// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
738// register with shift forms.
739// REG 0 0 - e.g. R5
740// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000741void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
742 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000743 const MCOperand &MO1 = MI->getOperand(OpNum);
744 const MCOperand &MO2 = MI->getOperand(OpNum+1);
745
746 unsigned Reg = MO1.getReg();
747 O << getRegisterName(Reg);
748
749 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000750 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000751 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
752 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
753 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000754 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000755}
756
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000757void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
758 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000759 const MCOperand &MO1 = MI->getOperand(OpNum);
760 const MCOperand &MO2 = MI->getOperand(OpNum+1);
761
Jim Grosbach3e556122010-10-26 22:37:02 +0000762 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
763 printOperand(MI, OpNum, O);
764 return;
765 }
766
Johnny Chen9e088762010-03-17 17:52:21 +0000767 O << "[" << getRegisterName(MO1.getReg());
768
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000769 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000770 bool isSub = OffImm < 0;
771 // Special value for #-0. All others are normal.
772 if (OffImm == INT32_MIN)
773 OffImm = 0;
774 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000775 O << ", #-" << -OffImm;
776 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000777 O << ", #" << OffImm;
778 O << "]";
779}
780
781void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000782 unsigned OpNum,
783 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000784 const MCOperand &MO1 = MI->getOperand(OpNum);
785 const MCOperand &MO2 = MI->getOperand(OpNum+1);
786
787 O << "[" << getRegisterName(MO1.getReg());
788
789 int32_t OffImm = (int32_t)MO2.getImm();
790 // Don't print +0.
791 if (OffImm < 0)
792 O << ", #-" << -OffImm;
793 else if (OffImm > 0)
794 O << ", #" << OffImm;
795 O << "]";
796}
797
798void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000799 unsigned OpNum,
800 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000801 const MCOperand &MO1 = MI->getOperand(OpNum);
802 const MCOperand &MO2 = MI->getOperand(OpNum+1);
803
804 O << "[" << getRegisterName(MO1.getReg());
805
806 int32_t OffImm = (int32_t)MO2.getImm() / 4;
807 // Don't print +0.
808 if (OffImm < 0)
809 O << ", #-" << -OffImm * 4;
810 else if (OffImm > 0)
811 O << ", #" << OffImm * 4;
812 O << "]";
813}
814
Jim Grosbachb6aed502011-09-09 18:37:27 +0000815void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
816 unsigned OpNum,
817 raw_ostream &O) {
818 const MCOperand &MO1 = MI->getOperand(OpNum);
819 const MCOperand &MO2 = MI->getOperand(OpNum+1);
820
821 O << "[" << getRegisterName(MO1.getReg());
822 if (MO2.getImm())
823 O << ", #" << MO2.getImm() * 4;
824 O << "]";
825}
826
Johnny Chen9e088762010-03-17 17:52:21 +0000827void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000828 unsigned OpNum,
829 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000830 const MCOperand &MO1 = MI->getOperand(OpNum);
831 int32_t OffImm = (int32_t)MO1.getImm();
832 // Don't print +0.
833 if (OffImm < 0)
834 O << "#-" << -OffImm;
835 else if (OffImm > 0)
836 O << "#" << OffImm;
837}
838
839void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000840 unsigned OpNum,
841 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000842 const MCOperand &MO1 = MI->getOperand(OpNum);
843 int32_t OffImm = (int32_t)MO1.getImm() / 4;
844 // Don't print +0.
845 if (OffImm < 0)
846 O << "#-" << -OffImm * 4;
847 else if (OffImm > 0)
848 O << "#" << OffImm * 4;
849}
850
851void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000852 unsigned OpNum,
853 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000854 const MCOperand &MO1 = MI->getOperand(OpNum);
855 const MCOperand &MO2 = MI->getOperand(OpNum+1);
856 const MCOperand &MO3 = MI->getOperand(OpNum+2);
857
858 O << "[" << getRegisterName(MO1.getReg());
859
860 assert(MO2.getReg() && "Invalid so_reg load / store address!");
861 O << ", " << getRegisterName(MO2.getReg());
862
863 unsigned ShAmt = MO3.getImm();
864 if (ShAmt) {
865 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
866 O << ", lsl #" << ShAmt;
867 }
868 O << "]";
869}
870
Chris Lattner35c33bd2010-04-04 04:47:45 +0000871void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
872 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000873 const MCOperand &MO = MI->getOperand(OpNum);
874 O << '#';
875 if (MO.isFPImm()) {
876 O << (float)MO.getFPImm();
877 } else {
878 union {
879 uint32_t I;
880 float F;
881 } FPUnion;
882
883 FPUnion.I = MO.getImm();
884 O << FPUnion.F;
885 }
Johnny Chen9e088762010-03-17 17:52:21 +0000886}
887
Chris Lattner35c33bd2010-04-04 04:47:45 +0000888void ARMInstPrinter::printVFPf64ImmOperand(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 << MO.getFPImm();
894 } else {
895 // We expect the binary encoding of a floating point number here.
896 union {
897 uint64_t I;
898 double D;
899 } FPUnion;
900
901 FPUnion.I = MO.getImm();
902 O << FPUnion.D;
903 }
Johnny Chen9e088762010-03-17 17:52:21 +0000904}
905
Bob Wilson1a913ed2010-06-11 21:34:50 +0000906void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
907 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000908 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
909 unsigned EltBits;
910 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000911 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000912}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000913
Jim Grosbachf4943352011-07-25 23:09:14 +0000914void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
915 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000916 unsigned Imm = MI->getOperand(OpNum).getImm();
917 O << "#" << Imm + 1;
918}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000919
920void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
921 raw_ostream &O) {
922 unsigned Imm = MI->getOperand(OpNum).getImm();
923 if (Imm == 0)
924 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000925 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000926 switch (Imm) {
927 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000928 case 1: O << "8"; break;
929 case 2: O << "16"; break;
930 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000931 }
932}