blob: c421f1cda46e8d63ec314cd0cca4a0d4fb314a0c [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
Owen Anderson0da10cf2011-08-29 19:36:44 +0000449 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
450 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
451 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000452 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000453 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000454 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000455 }
456 O << "]";
457}
458
Chris Lattner35c33bd2010-04-04 04:47:45 +0000459void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
460 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000461 const MCOperand &MO1 = MI->getOperand(OpNum);
462 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000463
Bob Wilson226036e2010-03-20 22:13:40 +0000464 O << "[" << getRegisterName(MO1.getReg());
465 if (MO2.getImm()) {
466 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000467 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000468 }
Bob Wilson226036e2010-03-20 22:13:40 +0000469 O << "]";
470}
471
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000472void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
473 raw_ostream &O) {
474 const MCOperand &MO1 = MI->getOperand(OpNum);
475 O << "[" << getRegisterName(MO1.getReg()) << "]";
476}
477
Bob Wilson226036e2010-03-20 22:13:40 +0000478void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000479 unsigned OpNum,
480 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000481 const MCOperand &MO = MI->getOperand(OpNum);
482 if (MO.getReg() == 0)
483 O << "!";
484 else
485 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000486}
487
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000488void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
489 unsigned OpNum,
490 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000491 const MCOperand &MO = MI->getOperand(OpNum);
492 uint32_t v = ~MO.getImm();
493 int32_t lsb = CountTrailingZeros_32(v);
494 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
495 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
496 O << '#' << lsb << ", #" << width;
497}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000498
Johnny Chen1adc40c2010-08-12 20:46:17 +0000499void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
500 raw_ostream &O) {
501 unsigned val = MI->getOperand(OpNum).getImm();
502 O << ARM_MB::MemBOptToString(val);
503}
504
Bob Wilson22f5dc72010-08-16 18:27:34 +0000505void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000506 raw_ostream &O) {
507 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000508 bool isASR = (ShiftOp & (1 << 5)) != 0;
509 unsigned Amt = ShiftOp & 0x1f;
510 if (isASR)
511 O << ", asr #" << (Amt == 0 ? 32 : Amt);
512 else if (Amt)
513 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000514}
515
Jim Grosbachdde038a2011-07-20 21:40:26 +0000516void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
517 raw_ostream &O) {
518 unsigned Imm = MI->getOperand(OpNum).getImm();
519 if (Imm == 0)
520 return;
521 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
522 O << ", lsl #" << Imm;
523}
524
525void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
526 raw_ostream &O) {
527 unsigned Imm = MI->getOperand(OpNum).getImm();
528 // A shift amount of 32 is encoded as 0.
529 if (Imm == 0)
530 Imm = 32;
531 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
532 O << ", asr #" << Imm;
533}
534
Chris Lattner35c33bd2010-04-04 04:47:45 +0000535void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
536 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000537 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000538 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
539 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000540 O << getRegisterName(MI->getOperand(i).getReg());
541 }
542 O << "}";
543}
Chris Lattner4d152222009-10-19 22:23:04 +0000544
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000545void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
546 raw_ostream &O) {
547 const MCOperand &Op = MI->getOperand(OpNum);
548 if (Op.getImm())
549 O << "be";
550 else
551 O << "le";
552}
553
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000554void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
555 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000556 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000557 O << ARM_PROC::IModToString(Op.getImm());
558}
559
560void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
561 raw_ostream &O) {
562 const MCOperand &Op = MI->getOperand(OpNum);
563 unsigned IFlags = Op.getImm();
564 for (int i=2; i >= 0; --i)
565 if (IFlags & (1 << i))
566 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000567}
568
Chris Lattner35c33bd2010-04-04 04:47:45 +0000569void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
570 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000571 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000572 unsigned SpecRegRBit = Op.getImm() >> 4;
573 unsigned Mask = Op.getImm() & 0xf;
574
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000575 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
576 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
577 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
578 O << "APSR_";
579 switch (Mask) {
580 default: assert(0);
581 case 4: O << "g"; return;
582 case 8: O << "nzcvq"; return;
583 case 12: O << "nzcvqg"; return;
584 }
585 llvm_unreachable("Unexpected mask value!");
586 }
587
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000588 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000589 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000590 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000591 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000592
Johnny Chen9e088762010-03-17 17:52:21 +0000593 if (Mask) {
594 O << '_';
595 if (Mask & 8) O << 'f';
596 if (Mask & 4) O << 's';
597 if (Mask & 2) O << 'x';
598 if (Mask & 1) O << 'c';
599 }
600}
601
Chris Lattner35c33bd2010-04-04 04:47:45 +0000602void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
603 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000604 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
605 if (CC != ARMCC::AL)
606 O << ARMCondCodeToString(CC);
607}
608
Jim Grosbach15d78982010-09-14 22:27:15 +0000609void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000610 unsigned OpNum,
611 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000612 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
613 O << ARMCondCodeToString(CC);
614}
615
Chris Lattner35c33bd2010-04-04 04:47:45 +0000616void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
617 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000618 if (MI->getOperand(OpNum).getReg()) {
619 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
620 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000621 O << 's';
622 }
623}
624
Chris Lattner35c33bd2010-04-04 04:47:45 +0000625void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
626 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000627 O << MI->getOperand(OpNum).getImm();
628}
629
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000630void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
631 raw_ostream &O) {
632 O << "p" << MI->getOperand(OpNum).getImm();
633}
634
635void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
636 raw_ostream &O) {
637 O << "c" << MI->getOperand(OpNum).getImm();
638}
639
Chris Lattner35c33bd2010-04-04 04:47:45 +0000640void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
641 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000642 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000643}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000644
Chris Lattner35c33bd2010-04-04 04:47:45 +0000645void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
646 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000647 O << "#" << MI->getOperand(OpNum).getImm() * 4;
648}
649
650void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
651 raw_ostream &O) {
652 unsigned Imm = MI->getOperand(OpNum).getImm();
653 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000654}
Johnny Chen9e088762010-03-17 17:52:21 +0000655
Chris Lattner35c33bd2010-04-04 04:47:45 +0000656void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
657 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000658 // (3 - the number of trailing zeros) is the number of then / else.
659 unsigned Mask = MI->getOperand(OpNum).getImm();
660 unsigned CondBit0 = Mask >> 4 & 1;
661 unsigned NumTZ = CountTrailingZeros_32(Mask);
662 assert(NumTZ <= 3 && "Invalid IT mask!");
663 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
664 bool T = ((Mask >> Pos) & 1) == CondBit0;
665 if (T)
666 O << 't';
667 else
668 O << 'e';
669 }
670}
671
Chris Lattner35c33bd2010-04-04 04:47:45 +0000672void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
673 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000674 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000675 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000676
677 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000678 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000679 return;
680 }
681
682 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000683 if (unsigned RegNum = MO2.getReg())
684 O << ", " << getRegisterName(RegNum);
685 O << "]";
686}
687
688void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
689 unsigned Op,
690 raw_ostream &O,
691 unsigned Scale) {
692 const MCOperand &MO1 = MI->getOperand(Op);
693 const MCOperand &MO2 = MI->getOperand(Op + 1);
694
695 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
696 printOperand(MI, Op, O);
697 return;
698 }
699
700 O << "[" << getRegisterName(MO1.getReg());
701 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000702 O << ", #" << ImmOffs * Scale;
703 O << "]";
704}
705
Bill Wendlingf4caf692010-12-14 03:36:38 +0000706void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
707 unsigned Op,
708 raw_ostream &O) {
709 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000710}
711
Bill Wendlingf4caf692010-12-14 03:36:38 +0000712void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
713 unsigned Op,
714 raw_ostream &O) {
715 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000716}
717
Bill Wendlingf4caf692010-12-14 03:36:38 +0000718void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
719 unsigned Op,
720 raw_ostream &O) {
721 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000722}
723
Chris Lattner35c33bd2010-04-04 04:47:45 +0000724void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
725 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000726 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000727}
728
Johnny Chen9e088762010-03-17 17:52:21 +0000729// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
730// register with shift forms.
731// REG 0 0 - e.g. R5
732// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000733void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
734 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000735 const MCOperand &MO1 = MI->getOperand(OpNum);
736 const MCOperand &MO2 = MI->getOperand(OpNum+1);
737
738 unsigned Reg = MO1.getReg();
739 O << getRegisterName(Reg);
740
741 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000742 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000743 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
744 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
745 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000746 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000747}
748
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000749void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
750 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000751 const MCOperand &MO1 = MI->getOperand(OpNum);
752 const MCOperand &MO2 = MI->getOperand(OpNum+1);
753
Jim Grosbach3e556122010-10-26 22:37:02 +0000754 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
755 printOperand(MI, OpNum, O);
756 return;
757 }
758
Johnny Chen9e088762010-03-17 17:52:21 +0000759 O << "[" << getRegisterName(MO1.getReg());
760
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000761 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000762 bool isSub = OffImm < 0;
763 // Special value for #-0. All others are normal.
764 if (OffImm == INT32_MIN)
765 OffImm = 0;
766 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000767 O << ", #-" << -OffImm;
768 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000769 O << ", #" << OffImm;
770 O << "]";
771}
772
773void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000774 unsigned OpNum,
775 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000776 const MCOperand &MO1 = MI->getOperand(OpNum);
777 const MCOperand &MO2 = MI->getOperand(OpNum+1);
778
779 O << "[" << getRegisterName(MO1.getReg());
780
781 int32_t OffImm = (int32_t)MO2.getImm();
782 // Don't print +0.
783 if (OffImm < 0)
784 O << ", #-" << -OffImm;
785 else if (OffImm > 0)
786 O << ", #" << OffImm;
787 O << "]";
788}
789
790void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000791 unsigned OpNum,
792 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000793 const MCOperand &MO1 = MI->getOperand(OpNum);
794 const MCOperand &MO2 = MI->getOperand(OpNum+1);
795
796 O << "[" << getRegisterName(MO1.getReg());
797
798 int32_t OffImm = (int32_t)MO2.getImm() / 4;
799 // Don't print +0.
800 if (OffImm < 0)
801 O << ", #-" << -OffImm * 4;
802 else if (OffImm > 0)
803 O << ", #" << OffImm * 4;
804 O << "]";
805}
806
807void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000808 unsigned OpNum,
809 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000810 const MCOperand &MO1 = MI->getOperand(OpNum);
811 int32_t OffImm = (int32_t)MO1.getImm();
812 // Don't print +0.
813 if (OffImm < 0)
814 O << "#-" << -OffImm;
815 else if (OffImm > 0)
816 O << "#" << OffImm;
817}
818
819void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000820 unsigned OpNum,
821 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000822 const MCOperand &MO1 = MI->getOperand(OpNum);
823 int32_t OffImm = (int32_t)MO1.getImm() / 4;
824 // Don't print +0.
825 if (OffImm < 0)
826 O << "#-" << -OffImm * 4;
827 else if (OffImm > 0)
828 O << "#" << OffImm * 4;
829}
830
831void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000832 unsigned OpNum,
833 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000834 const MCOperand &MO1 = MI->getOperand(OpNum);
835 const MCOperand &MO2 = MI->getOperand(OpNum+1);
836 const MCOperand &MO3 = MI->getOperand(OpNum+2);
837
838 O << "[" << getRegisterName(MO1.getReg());
839
840 assert(MO2.getReg() && "Invalid so_reg load / store address!");
841 O << ", " << getRegisterName(MO2.getReg());
842
843 unsigned ShAmt = MO3.getImm();
844 if (ShAmt) {
845 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
846 O << ", lsl #" << ShAmt;
847 }
848 O << "]";
849}
850
Chris Lattner35c33bd2010-04-04 04:47:45 +0000851void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
852 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000853 const MCOperand &MO = MI->getOperand(OpNum);
854 O << '#';
855 if (MO.isFPImm()) {
856 O << (float)MO.getFPImm();
857 } else {
858 union {
859 uint32_t I;
860 float F;
861 } FPUnion;
862
863 FPUnion.I = MO.getImm();
864 O << FPUnion.F;
865 }
Johnny Chen9e088762010-03-17 17:52:21 +0000866}
867
Chris Lattner35c33bd2010-04-04 04:47:45 +0000868void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
869 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000870 const MCOperand &MO = MI->getOperand(OpNum);
871 O << '#';
872 if (MO.isFPImm()) {
873 O << MO.getFPImm();
874 } else {
875 // We expect the binary encoding of a floating point number here.
876 union {
877 uint64_t I;
878 double D;
879 } FPUnion;
880
881 FPUnion.I = MO.getImm();
882 O << FPUnion.D;
883 }
Johnny Chen9e088762010-03-17 17:52:21 +0000884}
885
Bob Wilson1a913ed2010-06-11 21:34:50 +0000886void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
887 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000888 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
889 unsigned EltBits;
890 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000891 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000892}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000893
Jim Grosbachf4943352011-07-25 23:09:14 +0000894void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
895 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000896 unsigned Imm = MI->getOperand(OpNum).getImm();
897 O << "#" << Imm + 1;
898}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000899
900void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
901 raw_ostream &O) {
902 unsigned Imm = MI->getOperand(OpNum).getImm();
903 if (Imm == 0)
904 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000905 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000906 switch (Imm) {
907 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000908 case 1: O << "8"; break;
909 case 2: O << "16"; break;
910 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000911 }
912}