blob: 8b44aa29ff3e156cea140384f40e7ba971a5a0b2 [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
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000149 if (Opcode == ARM::tLDMIA) {
Owen Anderson565a0362011-07-18 23:25:34 +0000150 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
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000157 O << "\tldm";
Owen Anderson565a0362011-07-18 23:25:34 +0000158
159 printPredicateOperand(MI, 1, O);
160 O << '\t' << getRegisterName(BaseReg);
161 if (Writeback) O << "!";
162 O << ", ";
163 printRegisterList(MI, 3, O);
164 return;
165 }
166
Jim Grosbach0780b632011-08-19 23:24:36 +0000167 // Thumb1 NOP
168 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
169 MI->getOperand(1).getReg() == ARM::R8) {
170 O << "\tnop";
Jim Grosbachdf9ce6b2011-08-24 20:06:14 +0000171 printPredicateOperand(MI, 2, O);
Jim Grosbach0780b632011-08-19 23:24:36 +0000172 return;
173 }
174
Chris Lattner35c33bd2010-04-04 04:47:45 +0000175 printInstruction(MI, O);
Bill Wendling04863d02010-11-13 10:40:19 +0000176}
Chris Lattnerfd603822009-10-19 19:56:26 +0000177
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000178void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000179 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000180 const MCOperand &Op = MI->getOperand(OpNo);
181 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000182 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000183 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000184 } else if (Op.isImm()) {
185 O << '#' << Op.getImm();
186 } else {
187 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000188 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000189 }
190}
Chris Lattner61d35c22009-10-19 21:21:39 +0000191
Chris Lattner017d9472009-10-20 00:40:56 +0000192// so_reg is a 4-operand unit corresponding to register forms of the A5.1
193// "Addressing Mode 1 - Data-processing operands" forms. This includes:
194// REG 0 0 - e.g. R5
195// REG REG 0,SH_OPC - e.g. R5, ROR R3
196// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000197void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000198 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000199 const MCOperand &MO1 = MI->getOperand(OpNum);
200 const MCOperand &MO2 = MI->getOperand(OpNum+1);
201 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000202
Chris Lattner017d9472009-10-20 00:40:56 +0000203 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000204
Chris Lattner017d9472009-10-20 00:40:56 +0000205 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000206 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
207 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000208 if (ShOpc == ARM_AM::rrx)
209 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000210
211 O << ' ' << getRegisterName(MO2.getReg());
212 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000213}
Chris Lattner084f87d2009-10-19 21:57:05 +0000214
Owen Anderson152d4a42011-07-21 23:38:37 +0000215void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
216 raw_ostream &O) {
217 const MCOperand &MO1 = MI->getOperand(OpNum);
218 const MCOperand &MO2 = MI->getOperand(OpNum+1);
219
220 O << getRegisterName(MO1.getReg());
221
222 // Print the shift opc.
223 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
224 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
225 if (ShOpc == ARM_AM::rrx)
226 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000227 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000228}
229
230
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000231//===--------------------------------------------------------------------===//
232// Addressing Mode #2
233//===--------------------------------------------------------------------===//
234
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000235void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
236 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000237 const MCOperand &MO1 = MI->getOperand(Op);
238 const MCOperand &MO2 = MI->getOperand(Op+1);
239 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000240
Chris Lattner084f87d2009-10-19 21:57:05 +0000241 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000242
Chris Lattner084f87d2009-10-19 21:57:05 +0000243 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000244 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000245 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000246 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
247 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000248 O << "]";
249 return;
250 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000251
Chris Lattner084f87d2009-10-19 21:57:05 +0000252 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000253 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
254 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000255
Chris Lattner084f87d2009-10-19 21:57:05 +0000256 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
257 O << ", "
258 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
259 << " #" << ShImm;
260 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000261}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000262
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000263void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
264 raw_ostream &O) {
265 const MCOperand &MO1 = MI->getOperand(Op);
266 const MCOperand &MO2 = MI->getOperand(Op+1);
267 const MCOperand &MO3 = MI->getOperand(Op+2);
268
269 O << "[" << getRegisterName(MO1.getReg()) << "], ";
270
271 if (!MO2.getReg()) {
272 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
273 O << '#'
274 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
275 << ImmOffs;
276 return;
277 }
278
279 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
280 << getRegisterName(MO2.getReg());
281
282 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
283 O << ", "
284 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
285 << " #" << ShImm;
286}
287
288void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
289 raw_ostream &O) {
290 const MCOperand &MO1 = MI->getOperand(Op);
291
292 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
293 printOperand(MI, Op, O);
294 return;
295 }
296
297 const MCOperand &MO3 = MI->getOperand(Op+2);
298 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
299
300 if (IdxMode == ARMII::IndexModePost) {
301 printAM2PostIndexOp(MI, Op, O);
302 return;
303 }
304 printAM2PreOrOffsetIndexOp(MI, Op, O);
305}
306
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000307void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000308 unsigned OpNum,
309 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000310 const MCOperand &MO1 = MI->getOperand(OpNum);
311 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000312
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000313 if (!MO1.getReg()) {
314 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000315 O << '#'
316 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
317 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000318 return;
319 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000320
Johnny Chen9e088762010-03-17 17:52:21 +0000321 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
322 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000323
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000324 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
325 O << ", "
326 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
327 << " #" << ShImm;
328}
329
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000330//===--------------------------------------------------------------------===//
331// Addressing Mode #3
332//===--------------------------------------------------------------------===//
333
334void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
335 raw_ostream &O) {
336 const MCOperand &MO1 = MI->getOperand(Op);
337 const MCOperand &MO2 = MI->getOperand(Op+1);
338 const MCOperand &MO3 = MI->getOperand(Op+2);
339
340 O << "[" << getRegisterName(MO1.getReg()) << "], ";
341
342 if (MO2.getReg()) {
343 O << (char)ARM_AM::getAM3Op(MO3.getImm())
344 << getRegisterName(MO2.getReg());
345 return;
346 }
347
348 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
349 O << '#'
350 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
351 << ImmOffs;
352}
353
354void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
355 raw_ostream &O) {
356 const MCOperand &MO1 = MI->getOperand(Op);
357 const MCOperand &MO2 = MI->getOperand(Op+1);
358 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000359
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000360 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000361
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000362 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000363 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000364 << getRegisterName(MO2.getReg()) << ']';
365 return;
366 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000367
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000368 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
369 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000370 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
371 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000372 O << ']';
373}
374
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000375void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
376 raw_ostream &O) {
377 const MCOperand &MO3 = MI->getOperand(Op+2);
378 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
379
380 if (IdxMode == ARMII::IndexModePost) {
381 printAM3PostIndexOp(MI, Op, O);
382 return;
383 }
384 printAM3PreOrOffsetIndexOp(MI, Op, O);
385}
386
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000387void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000388 unsigned OpNum,
389 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000390 const MCOperand &MO1 = MI->getOperand(OpNum);
391 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000392
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000393 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000394 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
395 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000396 return;
397 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000398
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000399 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000400 O << '#'
401 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
402 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000403}
404
Jim Grosbach7ce05792011-08-03 23:50:40 +0000405void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
406 unsigned OpNum,
407 raw_ostream &O) {
408 const MCOperand &MO = MI->getOperand(OpNum);
409 unsigned Imm = MO.getImm();
410 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
411}
412
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000413void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
414 raw_ostream &O) {
415 const MCOperand &MO1 = MI->getOperand(OpNum);
416 const MCOperand &MO2 = MI->getOperand(OpNum+1);
417
Jim Grosbach16578b52011-08-05 16:11:38 +0000418 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000419}
420
Owen Anderson154c41d2011-08-04 18:24:14 +0000421void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
422 unsigned OpNum,
423 raw_ostream &O) {
424 const MCOperand &MO = MI->getOperand(OpNum);
425 unsigned Imm = MO.getImm();
426 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
427}
428
429
Jim Grosbache6913602010-11-03 01:01:43 +0000430void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000431 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000432 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
433 .getImm());
434 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000435}
436
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000437void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000438 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000439 const MCOperand &MO1 = MI->getOperand(OpNum);
440 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000441
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000442 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000443 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000444 return;
445 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000446
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000447 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000448
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000449 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
450 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000451 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000452 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000453 }
454 O << "]";
455}
456
Chris Lattner35c33bd2010-04-04 04:47:45 +0000457void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
458 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000459 const MCOperand &MO1 = MI->getOperand(OpNum);
460 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000461
Bob Wilson226036e2010-03-20 22:13:40 +0000462 O << "[" << getRegisterName(MO1.getReg());
463 if (MO2.getImm()) {
464 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000465 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000466 }
Bob Wilson226036e2010-03-20 22:13:40 +0000467 O << "]";
468}
469
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000470void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
471 raw_ostream &O) {
472 const MCOperand &MO1 = MI->getOperand(OpNum);
473 O << "[" << getRegisterName(MO1.getReg()) << "]";
474}
475
Bob Wilson226036e2010-03-20 22:13:40 +0000476void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000477 unsigned OpNum,
478 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000479 const MCOperand &MO = MI->getOperand(OpNum);
480 if (MO.getReg() == 0)
481 O << "!";
482 else
483 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000484}
485
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000486void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
487 unsigned OpNum,
488 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000489 const MCOperand &MO = MI->getOperand(OpNum);
490 uint32_t v = ~MO.getImm();
491 int32_t lsb = CountTrailingZeros_32(v);
492 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
493 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
494 O << '#' << lsb << ", #" << width;
495}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000496
Johnny Chen1adc40c2010-08-12 20:46:17 +0000497void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
498 raw_ostream &O) {
499 unsigned val = MI->getOperand(OpNum).getImm();
500 O << ARM_MB::MemBOptToString(val);
501}
502
Bob Wilson22f5dc72010-08-16 18:27:34 +0000503void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000504 raw_ostream &O) {
505 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000506 bool isASR = (ShiftOp & (1 << 5)) != 0;
507 unsigned Amt = ShiftOp & 0x1f;
508 if (isASR)
509 O << ", asr #" << (Amt == 0 ? 32 : Amt);
510 else if (Amt)
511 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000512}
513
Jim Grosbachdde038a2011-07-20 21:40:26 +0000514void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
515 raw_ostream &O) {
516 unsigned Imm = MI->getOperand(OpNum).getImm();
517 if (Imm == 0)
518 return;
519 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
520 O << ", lsl #" << Imm;
521}
522
523void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
524 raw_ostream &O) {
525 unsigned Imm = MI->getOperand(OpNum).getImm();
526 // A shift amount of 32 is encoded as 0.
527 if (Imm == 0)
528 Imm = 32;
529 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
530 O << ", asr #" << Imm;
531}
532
Chris Lattner35c33bd2010-04-04 04:47:45 +0000533void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
534 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000535 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000536 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
537 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000538 O << getRegisterName(MI->getOperand(i).getReg());
539 }
540 O << "}";
541}
Chris Lattner4d152222009-10-19 22:23:04 +0000542
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000543void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
544 raw_ostream &O) {
545 const MCOperand &Op = MI->getOperand(OpNum);
546 if (Op.getImm())
547 O << "be";
548 else
549 O << "le";
550}
551
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000552void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
553 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000554 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000555 O << ARM_PROC::IModToString(Op.getImm());
556}
557
558void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
559 raw_ostream &O) {
560 const MCOperand &Op = MI->getOperand(OpNum);
561 unsigned IFlags = Op.getImm();
562 for (int i=2; i >= 0; --i)
563 if (IFlags & (1 << i))
564 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000565}
566
Chris Lattner35c33bd2010-04-04 04:47:45 +0000567void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
568 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000569 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000570 unsigned SpecRegRBit = Op.getImm() >> 4;
571 unsigned Mask = Op.getImm() & 0xf;
572
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000573 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
574 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
575 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
576 O << "APSR_";
577 switch (Mask) {
578 default: assert(0);
579 case 4: O << "g"; return;
580 case 8: O << "nzcvq"; return;
581 case 12: O << "nzcvqg"; return;
582 }
583 llvm_unreachable("Unexpected mask value!");
584 }
585
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000586 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000587 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000588 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000589 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000590
Johnny Chen9e088762010-03-17 17:52:21 +0000591 if (Mask) {
592 O << '_';
593 if (Mask & 8) O << 'f';
594 if (Mask & 4) O << 's';
595 if (Mask & 2) O << 'x';
596 if (Mask & 1) O << 'c';
597 }
598}
599
Chris Lattner35c33bd2010-04-04 04:47:45 +0000600void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
601 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000602 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
603 if (CC != ARMCC::AL)
604 O << ARMCondCodeToString(CC);
605}
606
Jim Grosbach15d78982010-09-14 22:27:15 +0000607void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000608 unsigned OpNum,
609 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000610 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
611 O << ARMCondCodeToString(CC);
612}
613
Chris Lattner35c33bd2010-04-04 04:47:45 +0000614void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
615 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000616 if (MI->getOperand(OpNum).getReg()) {
617 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
618 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000619 O << 's';
620 }
621}
622
Chris Lattner35c33bd2010-04-04 04:47:45 +0000623void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
624 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000625 O << MI->getOperand(OpNum).getImm();
626}
627
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000628void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
629 raw_ostream &O) {
630 O << "p" << MI->getOperand(OpNum).getImm();
631}
632
633void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
634 raw_ostream &O) {
635 O << "c" << MI->getOperand(OpNum).getImm();
636}
637
Chris Lattner35c33bd2010-04-04 04:47:45 +0000638void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
639 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000640 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000641}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000642
Chris Lattner35c33bd2010-04-04 04:47:45 +0000643void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
644 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000645 O << "#" << MI->getOperand(OpNum).getImm() * 4;
646}
647
648void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
649 raw_ostream &O) {
650 unsigned Imm = MI->getOperand(OpNum).getImm();
651 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000652}
Johnny Chen9e088762010-03-17 17:52:21 +0000653
Chris Lattner35c33bd2010-04-04 04:47:45 +0000654void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
655 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000656 // (3 - the number of trailing zeros) is the number of then / else.
657 unsigned Mask = MI->getOperand(OpNum).getImm();
658 unsigned CondBit0 = Mask >> 4 & 1;
659 unsigned NumTZ = CountTrailingZeros_32(Mask);
660 assert(NumTZ <= 3 && "Invalid IT mask!");
661 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
662 bool T = ((Mask >> Pos) & 1) == CondBit0;
663 if (T)
664 O << 't';
665 else
666 O << 'e';
667 }
668}
669
Chris Lattner35c33bd2010-04-04 04:47:45 +0000670void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
671 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000672 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000673 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000674
675 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000676 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000677 return;
678 }
679
680 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000681 if (unsigned RegNum = MO2.getReg())
682 O << ", " << getRegisterName(RegNum);
683 O << "]";
684}
685
686void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
687 unsigned Op,
688 raw_ostream &O,
689 unsigned Scale) {
690 const MCOperand &MO1 = MI->getOperand(Op);
691 const MCOperand &MO2 = MI->getOperand(Op + 1);
692
693 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
694 printOperand(MI, Op, O);
695 return;
696 }
697
698 O << "[" << getRegisterName(MO1.getReg());
699 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000700 O << ", #" << ImmOffs * Scale;
701 O << "]";
702}
703
Bill Wendlingf4caf692010-12-14 03:36:38 +0000704void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
705 unsigned Op,
706 raw_ostream &O) {
707 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000708}
709
Bill Wendlingf4caf692010-12-14 03:36:38 +0000710void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
711 unsigned Op,
712 raw_ostream &O) {
713 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000714}
715
Bill Wendlingf4caf692010-12-14 03:36:38 +0000716void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
717 unsigned Op,
718 raw_ostream &O) {
719 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000720}
721
Chris Lattner35c33bd2010-04-04 04:47:45 +0000722void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
723 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000724 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000725}
726
Johnny Chen9e088762010-03-17 17:52:21 +0000727// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
728// register with shift forms.
729// REG 0 0 - e.g. R5
730// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000731void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
732 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000733 const MCOperand &MO1 = MI->getOperand(OpNum);
734 const MCOperand &MO2 = MI->getOperand(OpNum+1);
735
736 unsigned Reg = MO1.getReg();
737 O << getRegisterName(Reg);
738
739 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000740 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000741 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
742 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
743 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000744 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000745}
746
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000747void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
748 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000749 const MCOperand &MO1 = MI->getOperand(OpNum);
750 const MCOperand &MO2 = MI->getOperand(OpNum+1);
751
Jim Grosbach3e556122010-10-26 22:37:02 +0000752 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
753 printOperand(MI, OpNum, O);
754 return;
755 }
756
Johnny Chen9e088762010-03-17 17:52:21 +0000757 O << "[" << getRegisterName(MO1.getReg());
758
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000759 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000760 bool isSub = OffImm < 0;
761 // Special value for #-0. All others are normal.
762 if (OffImm == INT32_MIN)
763 OffImm = 0;
764 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000765 O << ", #-" << -OffImm;
766 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000767 O << ", #" << OffImm;
768 O << "]";
769}
770
771void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000772 unsigned OpNum,
773 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000774 const MCOperand &MO1 = MI->getOperand(OpNum);
775 const MCOperand &MO2 = MI->getOperand(OpNum+1);
776
777 O << "[" << getRegisterName(MO1.getReg());
778
779 int32_t OffImm = (int32_t)MO2.getImm();
780 // Don't print +0.
781 if (OffImm < 0)
782 O << ", #-" << -OffImm;
783 else if (OffImm > 0)
784 O << ", #" << OffImm;
785 O << "]";
786}
787
788void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000789 unsigned OpNum,
790 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000791 const MCOperand &MO1 = MI->getOperand(OpNum);
792 const MCOperand &MO2 = MI->getOperand(OpNum+1);
793
794 O << "[" << getRegisterName(MO1.getReg());
795
796 int32_t OffImm = (int32_t)MO2.getImm() / 4;
797 // Don't print +0.
798 if (OffImm < 0)
799 O << ", #-" << -OffImm * 4;
800 else if (OffImm > 0)
801 O << ", #" << OffImm * 4;
802 O << "]";
803}
804
805void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000806 unsigned OpNum,
807 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000808 const MCOperand &MO1 = MI->getOperand(OpNum);
809 int32_t OffImm = (int32_t)MO1.getImm();
810 // Don't print +0.
811 if (OffImm < 0)
812 O << "#-" << -OffImm;
813 else if (OffImm > 0)
814 O << "#" << OffImm;
815}
816
817void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000818 unsigned OpNum,
819 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000820 const MCOperand &MO1 = MI->getOperand(OpNum);
821 int32_t OffImm = (int32_t)MO1.getImm() / 4;
822 // Don't print +0.
823 if (OffImm < 0)
824 O << "#-" << -OffImm * 4;
825 else if (OffImm > 0)
826 O << "#" << OffImm * 4;
827}
828
829void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000830 unsigned OpNum,
831 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000832 const MCOperand &MO1 = MI->getOperand(OpNum);
833 const MCOperand &MO2 = MI->getOperand(OpNum+1);
834 const MCOperand &MO3 = MI->getOperand(OpNum+2);
835
836 O << "[" << getRegisterName(MO1.getReg());
837
838 assert(MO2.getReg() && "Invalid so_reg load / store address!");
839 O << ", " << getRegisterName(MO2.getReg());
840
841 unsigned ShAmt = MO3.getImm();
842 if (ShAmt) {
843 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
844 O << ", lsl #" << ShAmt;
845 }
846 O << "]";
847}
848
Chris Lattner35c33bd2010-04-04 04:47:45 +0000849void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
850 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000851 const MCOperand &MO = MI->getOperand(OpNum);
852 O << '#';
853 if (MO.isFPImm()) {
854 O << (float)MO.getFPImm();
855 } else {
856 union {
857 uint32_t I;
858 float F;
859 } FPUnion;
860
861 FPUnion.I = MO.getImm();
862 O << FPUnion.F;
863 }
Johnny Chen9e088762010-03-17 17:52:21 +0000864}
865
Chris Lattner35c33bd2010-04-04 04:47:45 +0000866void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
867 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000868 const MCOperand &MO = MI->getOperand(OpNum);
869 O << '#';
870 if (MO.isFPImm()) {
871 O << MO.getFPImm();
872 } else {
873 // We expect the binary encoding of a floating point number here.
874 union {
875 uint64_t I;
876 double D;
877 } FPUnion;
878
879 FPUnion.I = MO.getImm();
880 O << FPUnion.D;
881 }
Johnny Chen9e088762010-03-17 17:52:21 +0000882}
883
Bob Wilson1a913ed2010-06-11 21:34:50 +0000884void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
885 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000886 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
887 unsigned EltBits;
888 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000889 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000890}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000891
Jim Grosbachf4943352011-07-25 23:09:14 +0000892void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
893 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000894 unsigned Imm = MI->getOperand(OpNum).getImm();
895 O << "#" << Imm + 1;
896}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000897
898void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
899 raw_ostream &O) {
900 unsigned Imm = MI->getOperand(OpNum).getImm();
901 if (Imm == 0)
902 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000903 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000904 switch (Imm) {
905 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000906 case 1: O << "8"; break;
907 case 2: O << "16"; break;
908 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000909 }
910}