blob: 961b0576b09a89143645a6105dfc8dad42c86cf2 [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)
158 O << "\tldmia";
159 else if (Opcode == ARM::tSTMIA)
160 O << "\tstmia";
161 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
Chris Lattner35c33bd2010-04-04 04:47:45 +0000172 printInstruction(MI, O);
Bill Wendling04863d02010-11-13 10:40:19 +0000173}
Chris Lattnerfd603822009-10-19 19:56:26 +0000174
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000175void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000176 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000177 const MCOperand &Op = MI->getOperand(OpNo);
178 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000179 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000180 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000181 } else if (Op.isImm()) {
182 O << '#' << Op.getImm();
183 } else {
184 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000185 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000186 }
187}
Chris Lattner61d35c22009-10-19 21:21:39 +0000188
Chris Lattner017d9472009-10-20 00:40:56 +0000189// so_reg is a 4-operand unit corresponding to register forms of the A5.1
190// "Addressing Mode 1 - Data-processing operands" forms. This includes:
191// REG 0 0 - e.g. R5
192// REG REG 0,SH_OPC - e.g. R5, ROR R3
193// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000194void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000195 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000196 const MCOperand &MO1 = MI->getOperand(OpNum);
197 const MCOperand &MO2 = MI->getOperand(OpNum+1);
198 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000199
Chris Lattner017d9472009-10-20 00:40:56 +0000200 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000201
Chris Lattner017d9472009-10-20 00:40:56 +0000202 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000203 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
204 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000205 if (ShOpc == ARM_AM::rrx)
206 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000207
208 O << ' ' << getRegisterName(MO2.getReg());
209 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000210}
Chris Lattner084f87d2009-10-19 21:57:05 +0000211
Owen Anderson152d4a42011-07-21 23:38:37 +0000212void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
213 raw_ostream &O) {
214 const MCOperand &MO1 = MI->getOperand(OpNum);
215 const MCOperand &MO2 = MI->getOperand(OpNum+1);
216
217 O << getRegisterName(MO1.getReg());
218
219 // Print the shift opc.
220 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
221 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
222 if (ShOpc == ARM_AM::rrx)
223 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000224 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000225}
226
227
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000228//===--------------------------------------------------------------------===//
229// Addressing Mode #2
230//===--------------------------------------------------------------------===//
231
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000232void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
233 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000234 const MCOperand &MO1 = MI->getOperand(Op);
235 const MCOperand &MO2 = MI->getOperand(Op+1);
236 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000237
Chris Lattner084f87d2009-10-19 21:57:05 +0000238 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000239
Chris Lattner084f87d2009-10-19 21:57:05 +0000240 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000241 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000242 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000243 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
244 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000245 O << "]";
246 return;
247 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000248
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 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000252
Chris Lattner084f87d2009-10-19 21:57:05 +0000253 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
254 O << ", "
255 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
256 << " #" << ShImm;
257 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000258}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000259
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000260void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
261 raw_ostream &O) {
262 const MCOperand &MO1 = MI->getOperand(Op);
263 const MCOperand &MO2 = MI->getOperand(Op+1);
264 const MCOperand &MO3 = MI->getOperand(Op+2);
265
266 O << "[" << getRegisterName(MO1.getReg()) << "], ";
267
268 if (!MO2.getReg()) {
269 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
270 O << '#'
271 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
272 << ImmOffs;
273 return;
274 }
275
276 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
277 << getRegisterName(MO2.getReg());
278
279 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
280 O << ", "
281 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
282 << " #" << ShImm;
283}
284
285void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
286 raw_ostream &O) {
287 const MCOperand &MO1 = MI->getOperand(Op);
288
289 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
290 printOperand(MI, Op, O);
291 return;
292 }
293
294 const MCOperand &MO3 = MI->getOperand(Op+2);
295 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
296
297 if (IdxMode == ARMII::IndexModePost) {
298 printAM2PostIndexOp(MI, Op, O);
299 return;
300 }
301 printAM2PreOrOffsetIndexOp(MI, Op, O);
302}
303
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000304void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000305 unsigned OpNum,
306 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000307 const MCOperand &MO1 = MI->getOperand(OpNum);
308 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000309
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000310 if (!MO1.getReg()) {
311 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000312 O << '#'
313 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
314 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000315 return;
316 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000317
Johnny Chen9e088762010-03-17 17:52:21 +0000318 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
319 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000320
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000321 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
322 O << ", "
323 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
324 << " #" << ShImm;
325}
326
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000327//===--------------------------------------------------------------------===//
328// Addressing Mode #3
329//===--------------------------------------------------------------------===//
330
331void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
332 raw_ostream &O) {
333 const MCOperand &MO1 = MI->getOperand(Op);
334 const MCOperand &MO2 = MI->getOperand(Op+1);
335 const MCOperand &MO3 = MI->getOperand(Op+2);
336
337 O << "[" << getRegisterName(MO1.getReg()) << "], ";
338
339 if (MO2.getReg()) {
340 O << (char)ARM_AM::getAM3Op(MO3.getImm())
341 << getRegisterName(MO2.getReg());
342 return;
343 }
344
345 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
346 O << '#'
347 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
348 << ImmOffs;
349}
350
351void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
352 raw_ostream &O) {
353 const MCOperand &MO1 = MI->getOperand(Op);
354 const MCOperand &MO2 = MI->getOperand(Op+1);
355 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000356
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000357 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000358
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000359 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000360 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000361 << getRegisterName(MO2.getReg()) << ']';
362 return;
363 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000364
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000365 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
366 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000367 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
368 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000369 O << ']';
370}
371
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000372void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
373 raw_ostream &O) {
374 const MCOperand &MO3 = MI->getOperand(Op+2);
375 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
376
377 if (IdxMode == ARMII::IndexModePost) {
378 printAM3PostIndexOp(MI, Op, O);
379 return;
380 }
381 printAM3PreOrOffsetIndexOp(MI, Op, O);
382}
383
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000384void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000385 unsigned OpNum,
386 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000387 const MCOperand &MO1 = MI->getOperand(OpNum);
388 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000389
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000390 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000391 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
392 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000393 return;
394 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000395
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000396 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000397 O << '#'
398 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
399 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000400}
401
Jim Grosbach7ce05792011-08-03 23:50:40 +0000402void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
403 unsigned OpNum,
404 raw_ostream &O) {
405 const MCOperand &MO = MI->getOperand(OpNum);
406 unsigned Imm = MO.getImm();
407 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
408}
409
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000410void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
411 raw_ostream &O) {
412 const MCOperand &MO1 = MI->getOperand(OpNum);
413 const MCOperand &MO2 = MI->getOperand(OpNum+1);
414
Jim Grosbach16578b52011-08-05 16:11:38 +0000415 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000416}
417
Owen Anderson154c41d2011-08-04 18:24:14 +0000418void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
419 unsigned OpNum,
420 raw_ostream &O) {
421 const MCOperand &MO = MI->getOperand(OpNum);
422 unsigned Imm = MO.getImm();
423 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
424}
425
426
Jim Grosbache6913602010-11-03 01:01:43 +0000427void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000428 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000429 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
430 .getImm());
431 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000432}
433
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000434void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000435 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000436 const MCOperand &MO1 = MI->getOperand(OpNum);
437 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000438
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000439 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000440 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000441 return;
442 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000443
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000444 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000445
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000446 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
447 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000448 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000449 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000450 }
451 O << "]";
452}
453
Chris Lattner35c33bd2010-04-04 04:47:45 +0000454void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
455 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000456 const MCOperand &MO1 = MI->getOperand(OpNum);
457 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000458
Bob Wilson226036e2010-03-20 22:13:40 +0000459 O << "[" << getRegisterName(MO1.getReg());
460 if (MO2.getImm()) {
461 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000462 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000463 }
Bob Wilson226036e2010-03-20 22:13:40 +0000464 O << "]";
465}
466
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000467void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
468 raw_ostream &O) {
469 const MCOperand &MO1 = MI->getOperand(OpNum);
470 O << "[" << getRegisterName(MO1.getReg()) << "]";
471}
472
Bob Wilson226036e2010-03-20 22:13:40 +0000473void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000474 unsigned OpNum,
475 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000476 const MCOperand &MO = MI->getOperand(OpNum);
477 if (MO.getReg() == 0)
478 O << "!";
479 else
480 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000481}
482
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000483void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
484 unsigned OpNum,
485 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000486 const MCOperand &MO = MI->getOperand(OpNum);
487 uint32_t v = ~MO.getImm();
488 int32_t lsb = CountTrailingZeros_32(v);
489 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
490 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
491 O << '#' << lsb << ", #" << width;
492}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000493
Johnny Chen1adc40c2010-08-12 20:46:17 +0000494void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
495 raw_ostream &O) {
496 unsigned val = MI->getOperand(OpNum).getImm();
497 O << ARM_MB::MemBOptToString(val);
498}
499
Bob Wilson22f5dc72010-08-16 18:27:34 +0000500void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000501 raw_ostream &O) {
502 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000503 bool isASR = (ShiftOp & (1 << 5)) != 0;
504 unsigned Amt = ShiftOp & 0x1f;
505 if (isASR)
506 O << ", asr #" << (Amt == 0 ? 32 : Amt);
507 else if (Amt)
508 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000509}
510
Jim Grosbachdde038a2011-07-20 21:40:26 +0000511void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
512 raw_ostream &O) {
513 unsigned Imm = MI->getOperand(OpNum).getImm();
514 if (Imm == 0)
515 return;
516 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
517 O << ", lsl #" << Imm;
518}
519
520void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
521 raw_ostream &O) {
522 unsigned Imm = MI->getOperand(OpNum).getImm();
523 // A shift amount of 32 is encoded as 0.
524 if (Imm == 0)
525 Imm = 32;
526 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
527 O << ", asr #" << Imm;
528}
529
Chris Lattner35c33bd2010-04-04 04:47:45 +0000530void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
531 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000532 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000533 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
534 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000535 O << getRegisterName(MI->getOperand(i).getReg());
536 }
537 O << "}";
538}
Chris Lattner4d152222009-10-19 22:23:04 +0000539
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000540void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
541 raw_ostream &O) {
542 const MCOperand &Op = MI->getOperand(OpNum);
543 if (Op.getImm())
544 O << "be";
545 else
546 O << "le";
547}
548
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000549void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
550 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000551 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000552 O << ARM_PROC::IModToString(Op.getImm());
553}
554
555void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
556 raw_ostream &O) {
557 const MCOperand &Op = MI->getOperand(OpNum);
558 unsigned IFlags = Op.getImm();
559 for (int i=2; i >= 0; --i)
560 if (IFlags & (1 << i))
561 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000562}
563
Chris Lattner35c33bd2010-04-04 04:47:45 +0000564void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
565 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000566 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000567 unsigned SpecRegRBit = Op.getImm() >> 4;
568 unsigned Mask = Op.getImm() & 0xf;
569
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000570 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
571 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
572 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
573 O << "APSR_";
574 switch (Mask) {
575 default: assert(0);
576 case 4: O << "g"; return;
577 case 8: O << "nzcvq"; return;
578 case 12: O << "nzcvqg"; return;
579 }
580 llvm_unreachable("Unexpected mask value!");
581 }
582
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000583 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000584 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000585 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000586 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000587
Johnny Chen9e088762010-03-17 17:52:21 +0000588 if (Mask) {
589 O << '_';
590 if (Mask & 8) O << 'f';
591 if (Mask & 4) O << 's';
592 if (Mask & 2) O << 'x';
593 if (Mask & 1) O << 'c';
594 }
595}
596
Chris Lattner35c33bd2010-04-04 04:47:45 +0000597void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
598 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000599 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
600 if (CC != ARMCC::AL)
601 O << ARMCondCodeToString(CC);
602}
603
Jim Grosbach15d78982010-09-14 22:27:15 +0000604void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000605 unsigned OpNum,
606 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000607 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
608 O << ARMCondCodeToString(CC);
609}
610
Chris Lattner35c33bd2010-04-04 04:47:45 +0000611void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
612 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000613 if (MI->getOperand(OpNum).getReg()) {
614 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
615 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000616 O << 's';
617 }
618}
619
Chris Lattner35c33bd2010-04-04 04:47:45 +0000620void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
621 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000622 O << MI->getOperand(OpNum).getImm();
623}
624
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000625void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
626 raw_ostream &O) {
627 O << "p" << MI->getOperand(OpNum).getImm();
628}
629
630void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
631 raw_ostream &O) {
632 O << "c" << MI->getOperand(OpNum).getImm();
633}
634
Chris Lattner35c33bd2010-04-04 04:47:45 +0000635void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
636 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000637 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000638}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000639
Chris Lattner35c33bd2010-04-04 04:47:45 +0000640void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
641 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000642 O << "#" << MI->getOperand(OpNum).getImm() * 4;
643}
644
645void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
646 raw_ostream &O) {
647 unsigned Imm = MI->getOperand(OpNum).getImm();
648 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000649}
Johnny Chen9e088762010-03-17 17:52:21 +0000650
Chris Lattner35c33bd2010-04-04 04:47:45 +0000651void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
652 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000653 // (3 - the number of trailing zeros) is the number of then / else.
654 unsigned Mask = MI->getOperand(OpNum).getImm();
655 unsigned CondBit0 = Mask >> 4 & 1;
656 unsigned NumTZ = CountTrailingZeros_32(Mask);
657 assert(NumTZ <= 3 && "Invalid IT mask!");
658 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
659 bool T = ((Mask >> Pos) & 1) == CondBit0;
660 if (T)
661 O << 't';
662 else
663 O << 'e';
664 }
665}
666
Chris Lattner35c33bd2010-04-04 04:47:45 +0000667void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
668 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000669 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000670 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000671
672 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000673 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000674 return;
675 }
676
677 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000678 if (unsigned RegNum = MO2.getReg())
679 O << ", " << getRegisterName(RegNum);
680 O << "]";
681}
682
683void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
684 unsigned Op,
685 raw_ostream &O,
686 unsigned Scale) {
687 const MCOperand &MO1 = MI->getOperand(Op);
688 const MCOperand &MO2 = MI->getOperand(Op + 1);
689
690 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
691 printOperand(MI, Op, O);
692 return;
693 }
694
695 O << "[" << getRegisterName(MO1.getReg());
696 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000697 O << ", #" << ImmOffs * Scale;
698 O << "]";
699}
700
Bill Wendlingf4caf692010-12-14 03:36:38 +0000701void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
702 unsigned Op,
703 raw_ostream &O) {
704 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000705}
706
Bill Wendlingf4caf692010-12-14 03:36:38 +0000707void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
708 unsigned Op,
709 raw_ostream &O) {
710 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000711}
712
Bill Wendlingf4caf692010-12-14 03:36:38 +0000713void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
714 unsigned Op,
715 raw_ostream &O) {
716 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000717}
718
Chris Lattner35c33bd2010-04-04 04:47:45 +0000719void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
720 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000721 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000722}
723
Johnny Chen9e088762010-03-17 17:52:21 +0000724// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
725// register with shift forms.
726// REG 0 0 - e.g. R5
727// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000728void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
729 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000730 const MCOperand &MO1 = MI->getOperand(OpNum);
731 const MCOperand &MO2 = MI->getOperand(OpNum+1);
732
733 unsigned Reg = MO1.getReg();
734 O << getRegisterName(Reg);
735
736 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000737 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000738 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
739 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
740 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000741 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000742}
743
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000744void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
745 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000746 const MCOperand &MO1 = MI->getOperand(OpNum);
747 const MCOperand &MO2 = MI->getOperand(OpNum+1);
748
Jim Grosbach3e556122010-10-26 22:37:02 +0000749 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
750 printOperand(MI, OpNum, O);
751 return;
752 }
753
Johnny Chen9e088762010-03-17 17:52:21 +0000754 O << "[" << getRegisterName(MO1.getReg());
755
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000756 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000757 bool isSub = OffImm < 0;
758 // Special value for #-0. All others are normal.
759 if (OffImm == INT32_MIN)
760 OffImm = 0;
761 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000762 O << ", #-" << -OffImm;
763 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000764 O << ", #" << OffImm;
765 O << "]";
766}
767
768void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000769 unsigned OpNum,
770 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000771 const MCOperand &MO1 = MI->getOperand(OpNum);
772 const MCOperand &MO2 = MI->getOperand(OpNum+1);
773
774 O << "[" << getRegisterName(MO1.getReg());
775
776 int32_t OffImm = (int32_t)MO2.getImm();
777 // Don't print +0.
778 if (OffImm < 0)
779 O << ", #-" << -OffImm;
780 else if (OffImm > 0)
781 O << ", #" << OffImm;
782 O << "]";
783}
784
785void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000786 unsigned OpNum,
787 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000788 const MCOperand &MO1 = MI->getOperand(OpNum);
789 const MCOperand &MO2 = MI->getOperand(OpNum+1);
790
791 O << "[" << getRegisterName(MO1.getReg());
792
793 int32_t OffImm = (int32_t)MO2.getImm() / 4;
794 // Don't print +0.
795 if (OffImm < 0)
796 O << ", #-" << -OffImm * 4;
797 else if (OffImm > 0)
798 O << ", #" << OffImm * 4;
799 O << "]";
800}
801
802void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000803 unsigned OpNum,
804 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000805 const MCOperand &MO1 = MI->getOperand(OpNum);
806 int32_t OffImm = (int32_t)MO1.getImm();
807 // Don't print +0.
808 if (OffImm < 0)
809 O << "#-" << -OffImm;
810 else if (OffImm > 0)
811 O << "#" << OffImm;
812}
813
814void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000815 unsigned OpNum,
816 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000817 const MCOperand &MO1 = MI->getOperand(OpNum);
818 int32_t OffImm = (int32_t)MO1.getImm() / 4;
819 // Don't print +0.
820 if (OffImm < 0)
821 O << "#-" << -OffImm * 4;
822 else if (OffImm > 0)
823 O << "#" << OffImm * 4;
824}
825
826void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000827 unsigned OpNum,
828 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000829 const MCOperand &MO1 = MI->getOperand(OpNum);
830 const MCOperand &MO2 = MI->getOperand(OpNum+1);
831 const MCOperand &MO3 = MI->getOperand(OpNum+2);
832
833 O << "[" << getRegisterName(MO1.getReg());
834
835 assert(MO2.getReg() && "Invalid so_reg load / store address!");
836 O << ", " << getRegisterName(MO2.getReg());
837
838 unsigned ShAmt = MO3.getImm();
839 if (ShAmt) {
840 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
841 O << ", lsl #" << ShAmt;
842 }
843 O << "]";
844}
845
Chris Lattner35c33bd2010-04-04 04:47:45 +0000846void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
847 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000848 const MCOperand &MO = MI->getOperand(OpNum);
849 O << '#';
850 if (MO.isFPImm()) {
851 O << (float)MO.getFPImm();
852 } else {
853 union {
854 uint32_t I;
855 float F;
856 } FPUnion;
857
858 FPUnion.I = MO.getImm();
859 O << FPUnion.F;
860 }
Johnny Chen9e088762010-03-17 17:52:21 +0000861}
862
Chris Lattner35c33bd2010-04-04 04:47:45 +0000863void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
864 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000865 const MCOperand &MO = MI->getOperand(OpNum);
866 O << '#';
867 if (MO.isFPImm()) {
868 O << MO.getFPImm();
869 } else {
870 // We expect the binary encoding of a floating point number here.
871 union {
872 uint64_t I;
873 double D;
874 } FPUnion;
875
876 FPUnion.I = MO.getImm();
877 O << FPUnion.D;
878 }
Johnny Chen9e088762010-03-17 17:52:21 +0000879}
880
Bob Wilson1a913ed2010-06-11 21:34:50 +0000881void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
882 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000883 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
884 unsigned EltBits;
885 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000886 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000887}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000888
Jim Grosbachf4943352011-07-25 23:09:14 +0000889void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
890 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000891 unsigned Imm = MI->getOperand(OpNum).getImm();
892 O << "#" << Imm + 1;
893}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000894
895void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
896 raw_ostream &O) {
897 unsigned Imm = MI->getOperand(OpNum).getImm();
898 if (Imm == 0)
899 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000900 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000901 switch (Imm) {
902 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000903 case 1: O << "8"; break;
904 case 2: O << "16"; break;
905 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000906 }
907}