blob: 153f68d62c8f726e87577e9af4787b6747f3a537 [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
Chris Lattner6274ec42010-10-28 21:37:33 +000038StringRef ARMInstPrinter::getOpcodeName(unsigned Opcode) const {
39 return getInstructionName(Opcode);
40}
41
Rafael Espindolacde4ce42011-06-02 02:34:55 +000042void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
43 OS << getRegisterName(RegNo);
Anton Korobeynikov57caad72011-03-05 18:43:32 +000044}
Chris Lattner6274ec42010-10-28 21:37:33 +000045
Chris Lattnerd3740872010-04-04 05:04:31 +000046void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) {
Bill Wendling04863d02010-11-13 10:40:19 +000047 unsigned Opcode = MI->getOpcode();
48
Johnny Chen9e088762010-03-17 17:52:21 +000049 // Check for MOVs and print canonical forms, instead.
Owen Anderson152d4a42011-07-21 23:38:37 +000050 if (Opcode == ARM::MOVsr) {
Jim Grosbache6be85e2010-09-17 22:36:38 +000051 // FIXME: Thumb variants?
Johnny Chen9e088762010-03-17 17:52:21 +000052 const MCOperand &Dst = MI->getOperand(0);
53 const MCOperand &MO1 = MI->getOperand(1);
54 const MCOperand &MO2 = MI->getOperand(2);
55 const MCOperand &MO3 = MI->getOperand(3);
56
57 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner35c33bd2010-04-04 04:47:45 +000058 printSBitModifierOperand(MI, 6, O);
59 printPredicateOperand(MI, 4, O);
Johnny Chen9e088762010-03-17 17:52:21 +000060
61 O << '\t' << getRegisterName(Dst.getReg())
62 << ", " << getRegisterName(MO1.getReg());
63
Owen Anderson152d4a42011-07-21 23:38:37 +000064 O << ", " << getRegisterName(MO2.getReg());
65 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Johnny Chen9e088762010-03-17 17:52:21 +000066 return;
67 }
68
Owen Anderson152d4a42011-07-21 23:38:37 +000069 if (Opcode == ARM::MOVsi) {
70 // FIXME: Thumb variants?
71 const MCOperand &Dst = MI->getOperand(0);
72 const MCOperand &MO1 = MI->getOperand(1);
73 const MCOperand &MO2 = MI->getOperand(2);
74
75 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
76 printSBitModifierOperand(MI, 5, O);
77 printPredicateOperand(MI, 3, O);
78
79 O << '\t' << getRegisterName(Dst.getReg())
80 << ", " << getRegisterName(MO1.getReg());
81
82 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx)
83 return;
84
Owen Anderson3dac0be2011-08-11 18:41:59 +000085 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +000086 return;
87 }
88
89
Johnny Chen9e088762010-03-17 17:52:21 +000090 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +000091 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +000092 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +000093 O << '\t' << "push";
94 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +000095 if (Opcode == ARM::t2STMDB_UPD)
96 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +000097 O << '\t';
98 printRegisterList(MI, 4, O);
99 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000100 }
Jim Grosbachf6713912011-08-11 18:07:11 +0000101 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
102 MI->getOperand(3).getImm() == -4) {
103 O << '\t' << "push";
104 printPredicateOperand(MI, 4, O);
105 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
106 return;
107 }
Johnny Chen9e088762010-03-17 17:52:21 +0000108
109 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000110 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000111 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000112 O << '\t' << "pop";
113 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000114 if (Opcode == ARM::t2LDMIA_UPD)
115 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000116 O << '\t';
117 printRegisterList(MI, 4, O);
118 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000119 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000120 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
121 MI->getOperand(4).getImm() == 4) {
122 O << '\t' << "pop";
123 printPredicateOperand(MI, 5, O);
124 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
125 return;
126 }
127
Johnny Chen9e088762010-03-17 17:52:21 +0000128
129 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000130 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000131 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000132 O << '\t' << "vpush";
133 printPredicateOperand(MI, 2, O);
134 O << '\t';
135 printRegisterList(MI, 4, O);
136 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000137 }
138
139 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000140 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000141 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000142 O << '\t' << "vpop";
143 printPredicateOperand(MI, 2, O);
144 O << '\t';
145 printRegisterList(MI, 4, O);
146 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000147 }
148
Owen Anderson565a0362011-07-18 23:25:34 +0000149 if (Opcode == ARM::tLDMIA || Opcode == ARM::tSTMIA) {
150 bool Writeback = true;
151 unsigned BaseReg = MI->getOperand(0).getReg();
152 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
153 if (MI->getOperand(i).getReg() == BaseReg)
154 Writeback = false;
155 }
156
157 if (Opcode == ARM::tLDMIA)
Jim Grosbach93b3eff2011-08-18 21:50:53 +0000158 O << "\tldm";
Owen Anderson565a0362011-07-18 23:25:34 +0000159 else if (Opcode == ARM::tSTMIA)
Jim Grosbach93b3eff2011-08-18 21:50:53 +0000160 O << "\tstm";
Owen Anderson565a0362011-07-18 23:25:34 +0000161 else
162 llvm_unreachable("Unknown opcode!");
163
164 printPredicateOperand(MI, 1, O);
165 O << '\t' << getRegisterName(BaseReg);
166 if (Writeback) O << "!";
167 O << ", ";
168 printRegisterList(MI, 3, O);
169 return;
170 }
171
Jim Grosbach0780b632011-08-19 23:24:36 +0000172 // Thumb1 NOP
173 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
174 MI->getOperand(1).getReg() == ARM::R8) {
175 O << "\tnop";
176 return;
177 }
178
Chris Lattner35c33bd2010-04-04 04:47:45 +0000179 printInstruction(MI, O);
Bill Wendling04863d02010-11-13 10:40:19 +0000180}
Chris Lattnerfd603822009-10-19 19:56:26 +0000181
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000182void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000183 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000184 const MCOperand &Op = MI->getOperand(OpNo);
185 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000186 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000187 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000188 } else if (Op.isImm()) {
189 O << '#' << Op.getImm();
190 } else {
191 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000192 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000193 }
194}
Chris Lattner61d35c22009-10-19 21:21:39 +0000195
Chris Lattner017d9472009-10-20 00:40:56 +0000196// so_reg is a 4-operand unit corresponding to register forms of the A5.1
197// "Addressing Mode 1 - Data-processing operands" forms. This includes:
198// REG 0 0 - e.g. R5
199// REG REG 0,SH_OPC - e.g. R5, ROR R3
200// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000201void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000202 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000203 const MCOperand &MO1 = MI->getOperand(OpNum);
204 const MCOperand &MO2 = MI->getOperand(OpNum+1);
205 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000206
Chris Lattner017d9472009-10-20 00:40:56 +0000207 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000208
Chris Lattner017d9472009-10-20 00:40:56 +0000209 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000210 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
211 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000212 if (ShOpc == ARM_AM::rrx)
213 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000214
215 O << ' ' << getRegisterName(MO2.getReg());
216 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000217}
Chris Lattner084f87d2009-10-19 21:57:05 +0000218
Owen Anderson152d4a42011-07-21 23:38:37 +0000219void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
220 raw_ostream &O) {
221 const MCOperand &MO1 = MI->getOperand(OpNum);
222 const MCOperand &MO2 = MI->getOperand(OpNum+1);
223
224 O << getRegisterName(MO1.getReg());
225
226 // Print the shift opc.
227 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
228 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
229 if (ShOpc == ARM_AM::rrx)
230 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000231 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000232}
233
234
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000235//===--------------------------------------------------------------------===//
236// Addressing Mode #2
237//===--------------------------------------------------------------------===//
238
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000239void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
240 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000241 const MCOperand &MO1 = MI->getOperand(Op);
242 const MCOperand &MO2 = MI->getOperand(Op+1);
243 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000244
Chris Lattner084f87d2009-10-19 21:57:05 +0000245 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000246
Chris Lattner084f87d2009-10-19 21:57:05 +0000247 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000248 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000249 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000250 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
251 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000252 O << "]";
253 return;
254 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000255
Chris Lattner084f87d2009-10-19 21:57:05 +0000256 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000257 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
258 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000259
Chris Lattner084f87d2009-10-19 21:57:05 +0000260 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
261 O << ", "
262 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
263 << " #" << ShImm;
264 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000265}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000266
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000267void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
268 raw_ostream &O) {
269 const MCOperand &MO1 = MI->getOperand(Op);
270 const MCOperand &MO2 = MI->getOperand(Op+1);
271 const MCOperand &MO3 = MI->getOperand(Op+2);
272
273 O << "[" << getRegisterName(MO1.getReg()) << "], ";
274
275 if (!MO2.getReg()) {
276 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
277 O << '#'
278 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
279 << ImmOffs;
280 return;
281 }
282
283 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
284 << getRegisterName(MO2.getReg());
285
286 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
287 O << ", "
288 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
289 << " #" << ShImm;
290}
291
292void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
293 raw_ostream &O) {
294 const MCOperand &MO1 = MI->getOperand(Op);
295
296 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
297 printOperand(MI, Op, O);
298 return;
299 }
300
301 const MCOperand &MO3 = MI->getOperand(Op+2);
302 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
303
304 if (IdxMode == ARMII::IndexModePost) {
305 printAM2PostIndexOp(MI, Op, O);
306 return;
307 }
308 printAM2PreOrOffsetIndexOp(MI, Op, O);
309}
310
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000311void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000312 unsigned OpNum,
313 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000314 const MCOperand &MO1 = MI->getOperand(OpNum);
315 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000316
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000317 if (!MO1.getReg()) {
318 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000319 O << '#'
320 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
321 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000322 return;
323 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000324
Johnny Chen9e088762010-03-17 17:52:21 +0000325 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
326 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000327
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000328 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
329 O << ", "
330 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
331 << " #" << ShImm;
332}
333
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000334//===--------------------------------------------------------------------===//
335// Addressing Mode #3
336//===--------------------------------------------------------------------===//
337
338void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
339 raw_ostream &O) {
340 const MCOperand &MO1 = MI->getOperand(Op);
341 const MCOperand &MO2 = MI->getOperand(Op+1);
342 const MCOperand &MO3 = MI->getOperand(Op+2);
343
344 O << "[" << getRegisterName(MO1.getReg()) << "], ";
345
346 if (MO2.getReg()) {
347 O << (char)ARM_AM::getAM3Op(MO3.getImm())
348 << getRegisterName(MO2.getReg());
349 return;
350 }
351
352 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
353 O << '#'
354 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
355 << ImmOffs;
356}
357
358void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
359 raw_ostream &O) {
360 const MCOperand &MO1 = MI->getOperand(Op);
361 const MCOperand &MO2 = MI->getOperand(Op+1);
362 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000363
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000364 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000365
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000366 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000367 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000368 << getRegisterName(MO2.getReg()) << ']';
369 return;
370 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000371
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000372 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
373 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000374 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
375 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000376 O << ']';
377}
378
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000379void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
380 raw_ostream &O) {
381 const MCOperand &MO3 = MI->getOperand(Op+2);
382 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
383
384 if (IdxMode == ARMII::IndexModePost) {
385 printAM3PostIndexOp(MI, Op, O);
386 return;
387 }
388 printAM3PreOrOffsetIndexOp(MI, Op, O);
389}
390
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000391void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000392 unsigned OpNum,
393 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000394 const MCOperand &MO1 = MI->getOperand(OpNum);
395 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000396
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000397 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000398 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
399 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000400 return;
401 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000402
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000403 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000404 O << '#'
405 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
406 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000407}
408
Jim Grosbach7ce05792011-08-03 23:50:40 +0000409void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
410 unsigned OpNum,
411 raw_ostream &O) {
412 const MCOperand &MO = MI->getOperand(OpNum);
413 unsigned Imm = MO.getImm();
414 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
415}
416
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000417void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
418 raw_ostream &O) {
419 const MCOperand &MO1 = MI->getOperand(OpNum);
420 const MCOperand &MO2 = MI->getOperand(OpNum+1);
421
Jim Grosbach16578b52011-08-05 16:11:38 +0000422 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000423}
424
Owen Anderson154c41d2011-08-04 18:24:14 +0000425void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
426 unsigned OpNum,
427 raw_ostream &O) {
428 const MCOperand &MO = MI->getOperand(OpNum);
429 unsigned Imm = MO.getImm();
430 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
431}
432
433
Jim Grosbache6913602010-11-03 01:01:43 +0000434void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000435 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000436 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
437 .getImm());
438 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000439}
440
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000441void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000442 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000443 const MCOperand &MO1 = MI->getOperand(OpNum);
444 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000445
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000446 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000447 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000448 return;
449 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000450
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000451 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000452
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000453 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
454 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000455 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000456 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000457 }
458 O << "]";
459}
460
Chris Lattner35c33bd2010-04-04 04:47:45 +0000461void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
462 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000463 const MCOperand &MO1 = MI->getOperand(OpNum);
464 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000465
Bob Wilson226036e2010-03-20 22:13:40 +0000466 O << "[" << getRegisterName(MO1.getReg());
467 if (MO2.getImm()) {
468 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000469 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000470 }
Bob Wilson226036e2010-03-20 22:13:40 +0000471 O << "]";
472}
473
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000474void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
475 raw_ostream &O) {
476 const MCOperand &MO1 = MI->getOperand(OpNum);
477 O << "[" << getRegisterName(MO1.getReg()) << "]";
478}
479
Bob Wilson226036e2010-03-20 22:13:40 +0000480void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000481 unsigned OpNum,
482 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000483 const MCOperand &MO = MI->getOperand(OpNum);
484 if (MO.getReg() == 0)
485 O << "!";
486 else
487 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000488}
489
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000490void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
491 unsigned OpNum,
492 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000493 const MCOperand &MO = MI->getOperand(OpNum);
494 uint32_t v = ~MO.getImm();
495 int32_t lsb = CountTrailingZeros_32(v);
496 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
497 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
498 O << '#' << lsb << ", #" << width;
499}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000500
Johnny Chen1adc40c2010-08-12 20:46:17 +0000501void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
502 raw_ostream &O) {
503 unsigned val = MI->getOperand(OpNum).getImm();
504 O << ARM_MB::MemBOptToString(val);
505}
506
Bob Wilson22f5dc72010-08-16 18:27:34 +0000507void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000508 raw_ostream &O) {
509 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000510 bool isASR = (ShiftOp & (1 << 5)) != 0;
511 unsigned Amt = ShiftOp & 0x1f;
512 if (isASR)
513 O << ", asr #" << (Amt == 0 ? 32 : Amt);
514 else if (Amt)
515 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000516}
517
Jim Grosbachdde038a2011-07-20 21:40:26 +0000518void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
519 raw_ostream &O) {
520 unsigned Imm = MI->getOperand(OpNum).getImm();
521 if (Imm == 0)
522 return;
523 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
524 O << ", lsl #" << Imm;
525}
526
527void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
528 raw_ostream &O) {
529 unsigned Imm = MI->getOperand(OpNum).getImm();
530 // A shift amount of 32 is encoded as 0.
531 if (Imm == 0)
532 Imm = 32;
533 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
534 O << ", asr #" << Imm;
535}
536
Chris Lattner35c33bd2010-04-04 04:47:45 +0000537void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
538 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000539 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000540 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
541 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000542 O << getRegisterName(MI->getOperand(i).getReg());
543 }
544 O << "}";
545}
Chris Lattner4d152222009-10-19 22:23:04 +0000546
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000547void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
548 raw_ostream &O) {
549 const MCOperand &Op = MI->getOperand(OpNum);
550 if (Op.getImm())
551 O << "be";
552 else
553 O << "le";
554}
555
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000556void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
557 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000558 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000559 O << ARM_PROC::IModToString(Op.getImm());
560}
561
562void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
563 raw_ostream &O) {
564 const MCOperand &Op = MI->getOperand(OpNum);
565 unsigned IFlags = Op.getImm();
566 for (int i=2; i >= 0; --i)
567 if (IFlags & (1 << i))
568 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000569}
570
Chris Lattner35c33bd2010-04-04 04:47:45 +0000571void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
572 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000573 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000574 unsigned SpecRegRBit = Op.getImm() >> 4;
575 unsigned Mask = Op.getImm() & 0xf;
576
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000577 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
578 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
579 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
580 O << "APSR_";
581 switch (Mask) {
582 default: assert(0);
583 case 4: O << "g"; return;
584 case 8: O << "nzcvq"; return;
585 case 12: O << "nzcvqg"; return;
586 }
587 llvm_unreachable("Unexpected mask value!");
588 }
589
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000590 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000591 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000592 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000593 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000594
Johnny Chen9e088762010-03-17 17:52:21 +0000595 if (Mask) {
596 O << '_';
597 if (Mask & 8) O << 'f';
598 if (Mask & 4) O << 's';
599 if (Mask & 2) O << 'x';
600 if (Mask & 1) O << 'c';
601 }
602}
603
Chris Lattner35c33bd2010-04-04 04:47:45 +0000604void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
605 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000606 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
607 if (CC != ARMCC::AL)
608 O << ARMCondCodeToString(CC);
609}
610
Jim Grosbach15d78982010-09-14 22:27:15 +0000611void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000612 unsigned OpNum,
613 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000614 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
615 O << ARMCondCodeToString(CC);
616}
617
Chris Lattner35c33bd2010-04-04 04:47:45 +0000618void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
619 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000620 if (MI->getOperand(OpNum).getReg()) {
621 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
622 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000623 O << 's';
624 }
625}
626
Chris Lattner35c33bd2010-04-04 04:47:45 +0000627void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
628 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000629 O << MI->getOperand(OpNum).getImm();
630}
631
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000632void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
633 raw_ostream &O) {
634 O << "p" << MI->getOperand(OpNum).getImm();
635}
636
637void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
638 raw_ostream &O) {
639 O << "c" << MI->getOperand(OpNum).getImm();
640}
641
Chris Lattner35c33bd2010-04-04 04:47:45 +0000642void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
643 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000644 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000645}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000646
Chris Lattner35c33bd2010-04-04 04:47:45 +0000647void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
648 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000649 O << "#" << MI->getOperand(OpNum).getImm() * 4;
650}
651
652void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
653 raw_ostream &O) {
654 unsigned Imm = MI->getOperand(OpNum).getImm();
655 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000656}
Johnny Chen9e088762010-03-17 17:52:21 +0000657
Chris Lattner35c33bd2010-04-04 04:47:45 +0000658void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
659 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000660 // (3 - the number of trailing zeros) is the number of then / else.
661 unsigned Mask = MI->getOperand(OpNum).getImm();
662 unsigned CondBit0 = Mask >> 4 & 1;
663 unsigned NumTZ = CountTrailingZeros_32(Mask);
664 assert(NumTZ <= 3 && "Invalid IT mask!");
665 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
666 bool T = ((Mask >> Pos) & 1) == CondBit0;
667 if (T)
668 O << 't';
669 else
670 O << 'e';
671 }
672}
673
Chris Lattner35c33bd2010-04-04 04:47:45 +0000674void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
675 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000676 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000677 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000678
679 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000680 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000681 return;
682 }
683
684 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000685 if (unsigned RegNum = MO2.getReg())
686 O << ", " << getRegisterName(RegNum);
687 O << "]";
688}
689
690void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
691 unsigned Op,
692 raw_ostream &O,
693 unsigned Scale) {
694 const MCOperand &MO1 = MI->getOperand(Op);
695 const MCOperand &MO2 = MI->getOperand(Op + 1);
696
697 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
698 printOperand(MI, Op, O);
699 return;
700 }
701
702 O << "[" << getRegisterName(MO1.getReg());
703 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000704 O << ", #" << ImmOffs * Scale;
705 O << "]";
706}
707
Bill Wendlingf4caf692010-12-14 03:36:38 +0000708void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
709 unsigned Op,
710 raw_ostream &O) {
711 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000712}
713
Bill Wendlingf4caf692010-12-14 03:36:38 +0000714void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
715 unsigned Op,
716 raw_ostream &O) {
717 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000718}
719
Bill Wendlingf4caf692010-12-14 03:36:38 +0000720void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
721 unsigned Op,
722 raw_ostream &O) {
723 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000724}
725
Chris Lattner35c33bd2010-04-04 04:47:45 +0000726void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
727 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000728 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000729}
730
Johnny Chen9e088762010-03-17 17:52:21 +0000731// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
732// register with shift forms.
733// REG 0 0 - e.g. R5
734// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000735void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
736 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000737 const MCOperand &MO1 = MI->getOperand(OpNum);
738 const MCOperand &MO2 = MI->getOperand(OpNum+1);
739
740 unsigned Reg = MO1.getReg();
741 O << getRegisterName(Reg);
742
743 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000744 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000745 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
746 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
747 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000748 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000749}
750
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000751void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
752 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000753 const MCOperand &MO1 = MI->getOperand(OpNum);
754 const MCOperand &MO2 = MI->getOperand(OpNum+1);
755
Jim Grosbach3e556122010-10-26 22:37:02 +0000756 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
757 printOperand(MI, OpNum, O);
758 return;
759 }
760
Johnny Chen9e088762010-03-17 17:52:21 +0000761 O << "[" << getRegisterName(MO1.getReg());
762
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000763 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000764 bool isSub = OffImm < 0;
765 // Special value for #-0. All others are normal.
766 if (OffImm == INT32_MIN)
767 OffImm = 0;
768 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000769 O << ", #-" << -OffImm;
770 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000771 O << ", #" << OffImm;
772 O << "]";
773}
774
775void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000776 unsigned OpNum,
777 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000778 const MCOperand &MO1 = MI->getOperand(OpNum);
779 const MCOperand &MO2 = MI->getOperand(OpNum+1);
780
781 O << "[" << getRegisterName(MO1.getReg());
782
783 int32_t OffImm = (int32_t)MO2.getImm();
784 // Don't print +0.
785 if (OffImm < 0)
786 O << ", #-" << -OffImm;
787 else if (OffImm > 0)
788 O << ", #" << OffImm;
789 O << "]";
790}
791
792void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000793 unsigned OpNum,
794 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000795 const MCOperand &MO1 = MI->getOperand(OpNum);
796 const MCOperand &MO2 = MI->getOperand(OpNum+1);
797
798 O << "[" << getRegisterName(MO1.getReg());
799
800 int32_t OffImm = (int32_t)MO2.getImm() / 4;
801 // Don't print +0.
802 if (OffImm < 0)
803 O << ", #-" << -OffImm * 4;
804 else if (OffImm > 0)
805 O << ", #" << OffImm * 4;
806 O << "]";
807}
808
809void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000810 unsigned OpNum,
811 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000812 const MCOperand &MO1 = MI->getOperand(OpNum);
813 int32_t OffImm = (int32_t)MO1.getImm();
814 // Don't print +0.
815 if (OffImm < 0)
816 O << "#-" << -OffImm;
817 else if (OffImm > 0)
818 O << "#" << OffImm;
819}
820
821void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000822 unsigned OpNum,
823 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000824 const MCOperand &MO1 = MI->getOperand(OpNum);
825 int32_t OffImm = (int32_t)MO1.getImm() / 4;
826 // Don't print +0.
827 if (OffImm < 0)
828 O << "#-" << -OffImm * 4;
829 else if (OffImm > 0)
830 O << "#" << OffImm * 4;
831}
832
833void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000834 unsigned OpNum,
835 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000836 const MCOperand &MO1 = MI->getOperand(OpNum);
837 const MCOperand &MO2 = MI->getOperand(OpNum+1);
838 const MCOperand &MO3 = MI->getOperand(OpNum+2);
839
840 O << "[" << getRegisterName(MO1.getReg());
841
842 assert(MO2.getReg() && "Invalid so_reg load / store address!");
843 O << ", " << getRegisterName(MO2.getReg());
844
845 unsigned ShAmt = MO3.getImm();
846 if (ShAmt) {
847 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
848 O << ", lsl #" << ShAmt;
849 }
850 O << "]";
851}
852
Chris Lattner35c33bd2010-04-04 04:47:45 +0000853void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
854 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000855 const MCOperand &MO = MI->getOperand(OpNum);
856 O << '#';
857 if (MO.isFPImm()) {
858 O << (float)MO.getFPImm();
859 } else {
860 union {
861 uint32_t I;
862 float F;
863 } FPUnion;
864
865 FPUnion.I = MO.getImm();
866 O << FPUnion.F;
867 }
Johnny Chen9e088762010-03-17 17:52:21 +0000868}
869
Chris Lattner35c33bd2010-04-04 04:47:45 +0000870void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
871 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000872 const MCOperand &MO = MI->getOperand(OpNum);
873 O << '#';
874 if (MO.isFPImm()) {
875 O << MO.getFPImm();
876 } else {
877 // We expect the binary encoding of a floating point number here.
878 union {
879 uint64_t I;
880 double D;
881 } FPUnion;
882
883 FPUnion.I = MO.getImm();
884 O << FPUnion.D;
885 }
Johnny Chen9e088762010-03-17 17:52:21 +0000886}
887
Bob Wilson1a913ed2010-06-11 21:34:50 +0000888void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
889 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000890 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
891 unsigned EltBits;
892 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000893 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000894}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000895
Jim Grosbachf4943352011-07-25 23:09:14 +0000896void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
897 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000898 unsigned Imm = MI->getOperand(OpNum).getImm();
899 O << "#" << Imm + 1;
900}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000901
902void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
903 raw_ostream &O) {
904 unsigned Imm = MI->getOperand(OpNum).getImm();
905 if (Imm == 0)
906 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000907 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000908 switch (Imm) {
909 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000910 case 1: O << "8"; break;
911 case 2: O << "16"; break;
912 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000913 }
914}