blob: ef4069913407c8a2b8704b4ea33db5cbcd2ceb43 [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
Chris Lattner6274ec42010-10-28 21:37:33 +000028StringRef ARMInstPrinter::getOpcodeName(unsigned Opcode) const {
29 return getInstructionName(Opcode);
30}
31
Rafael Espindolacde4ce42011-06-02 02:34:55 +000032void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
33 OS << getRegisterName(RegNo);
Anton Korobeynikov57caad72011-03-05 18:43:32 +000034}
Chris Lattner6274ec42010-10-28 21:37:33 +000035
Chris Lattnerd3740872010-04-04 05:04:31 +000036void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) {
Bill Wendling04863d02010-11-13 10:40:19 +000037 unsigned Opcode = MI->getOpcode();
38
Johnny Chen9e088762010-03-17 17:52:21 +000039 // Check for MOVs and print canonical forms, instead.
Owen Anderson152d4a42011-07-21 23:38:37 +000040 if (Opcode == ARM::MOVsr) {
Jim Grosbache6be85e2010-09-17 22:36:38 +000041 // FIXME: Thumb variants?
Johnny Chen9e088762010-03-17 17:52:21 +000042 const MCOperand &Dst = MI->getOperand(0);
43 const MCOperand &MO1 = MI->getOperand(1);
44 const MCOperand &MO2 = MI->getOperand(2);
45 const MCOperand &MO3 = MI->getOperand(3);
46
47 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner35c33bd2010-04-04 04:47:45 +000048 printSBitModifierOperand(MI, 6, O);
49 printPredicateOperand(MI, 4, O);
Johnny Chen9e088762010-03-17 17:52:21 +000050
51 O << '\t' << getRegisterName(Dst.getReg())
52 << ", " << getRegisterName(MO1.getReg());
53
Owen Anderson152d4a42011-07-21 23:38:37 +000054 O << ", " << getRegisterName(MO2.getReg());
55 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Johnny Chen9e088762010-03-17 17:52:21 +000056 return;
57 }
58
Owen Anderson152d4a42011-07-21 23:38:37 +000059 if (Opcode == ARM::MOVsi) {
60 // FIXME: Thumb variants?
61 const MCOperand &Dst = MI->getOperand(0);
62 const MCOperand &MO1 = MI->getOperand(1);
63 const MCOperand &MO2 = MI->getOperand(2);
64
65 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
66 printSBitModifierOperand(MI, 5, O);
67 printPredicateOperand(MI, 3, O);
68
69 O << '\t' << getRegisterName(Dst.getReg())
70 << ", " << getRegisterName(MO1.getReg());
71
72 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx)
73 return;
74
75 O << ", #" << ARM_AM::getSORegOffset(MO2.getImm());
76 return;
77 }
78
79
Johnny Chen9e088762010-03-17 17:52:21 +000080 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +000081 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +000082 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +000083 O << '\t' << "push";
84 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +000085 if (Opcode == ARM::t2STMDB_UPD)
86 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +000087 O << '\t';
88 printRegisterList(MI, 4, O);
89 return;
Johnny Chen9e088762010-03-17 17:52:21 +000090 }
91
92 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +000093 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +000094 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +000095 O << '\t' << "pop";
96 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +000097 if (Opcode == ARM::t2LDMIA_UPD)
98 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +000099 O << '\t';
100 printRegisterList(MI, 4, O);
101 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000102 }
103
104 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000105 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000106 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000107 O << '\t' << "vpush";
108 printPredicateOperand(MI, 2, O);
109 O << '\t';
110 printRegisterList(MI, 4, O);
111 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000112 }
113
114 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000115 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000116 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000117 O << '\t' << "vpop";
118 printPredicateOperand(MI, 2, O);
119 O << '\t';
120 printRegisterList(MI, 4, O);
121 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000122 }
123
Owen Anderson565a0362011-07-18 23:25:34 +0000124 if (Opcode == ARM::tLDMIA || Opcode == ARM::tSTMIA) {
125 bool Writeback = true;
126 unsigned BaseReg = MI->getOperand(0).getReg();
127 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
128 if (MI->getOperand(i).getReg() == BaseReg)
129 Writeback = false;
130 }
131
132 if (Opcode == ARM::tLDMIA)
133 O << "\tldmia";
134 else if (Opcode == ARM::tSTMIA)
135 O << "\tstmia";
136 else
137 llvm_unreachable("Unknown opcode!");
138
139 printPredicateOperand(MI, 1, O);
140 O << '\t' << getRegisterName(BaseReg);
141 if (Writeback) O << "!";
142 O << ", ";
143 printRegisterList(MI, 3, O);
144 return;
145 }
146
Chris Lattner35c33bd2010-04-04 04:47:45 +0000147 printInstruction(MI, O);
Bill Wendling04863d02010-11-13 10:40:19 +0000148}
Chris Lattnerfd603822009-10-19 19:56:26 +0000149
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000150void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000151 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000152 const MCOperand &Op = MI->getOperand(OpNo);
153 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000154 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000155 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000156 } else if (Op.isImm()) {
157 O << '#' << Op.getImm();
158 } else {
159 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000160 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000161 }
162}
Chris Lattner61d35c22009-10-19 21:21:39 +0000163
Chris Lattner017d9472009-10-20 00:40:56 +0000164// so_reg is a 4-operand unit corresponding to register forms of the A5.1
165// "Addressing Mode 1 - Data-processing operands" forms. This includes:
166// REG 0 0 - e.g. R5
167// REG REG 0,SH_OPC - e.g. R5, ROR R3
168// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000169void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000170 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000171 const MCOperand &MO1 = MI->getOperand(OpNum);
172 const MCOperand &MO2 = MI->getOperand(OpNum+1);
173 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000174
Chris Lattner017d9472009-10-20 00:40:56 +0000175 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000176
Chris Lattner017d9472009-10-20 00:40:56 +0000177 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000178 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
179 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000180 if (ShOpc == ARM_AM::rrx)
181 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000182
183 O << ' ' << getRegisterName(MO2.getReg());
184 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000185}
Chris Lattner084f87d2009-10-19 21:57:05 +0000186
Owen Anderson152d4a42011-07-21 23:38:37 +0000187void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
188 raw_ostream &O) {
189 const MCOperand &MO1 = MI->getOperand(OpNum);
190 const MCOperand &MO2 = MI->getOperand(OpNum+1);
191
192 O << getRegisterName(MO1.getReg());
193
194 // Print the shift opc.
195 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
196 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
197 if (ShOpc == ARM_AM::rrx)
198 return;
199 O << " #" << ARM_AM::getSORegOffset(MO2.getImm());
200}
201
202
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000203//===--------------------------------------------------------------------===//
204// Addressing Mode #2
205//===--------------------------------------------------------------------===//
206
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000207void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
208 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000209 const MCOperand &MO1 = MI->getOperand(Op);
210 const MCOperand &MO2 = MI->getOperand(Op+1);
211 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000212
Chris Lattner084f87d2009-10-19 21:57:05 +0000213 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000214
Chris Lattner084f87d2009-10-19 21:57:05 +0000215 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000216 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000217 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000218 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
219 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000220 O << "]";
221 return;
222 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000223
Chris Lattner084f87d2009-10-19 21:57:05 +0000224 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000225 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
226 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000227
Chris Lattner084f87d2009-10-19 21:57:05 +0000228 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
229 O << ", "
230 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
231 << " #" << ShImm;
232 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000233}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000234
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000235void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
236 raw_ostream &O) {
237 const MCOperand &MO1 = MI->getOperand(Op);
238 const MCOperand &MO2 = MI->getOperand(Op+1);
239 const MCOperand &MO3 = MI->getOperand(Op+2);
240
241 O << "[" << getRegisterName(MO1.getReg()) << "], ";
242
243 if (!MO2.getReg()) {
244 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
245 O << '#'
246 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
247 << ImmOffs;
248 return;
249 }
250
251 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
252 << getRegisterName(MO2.getReg());
253
254 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
255 O << ", "
256 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
257 << " #" << ShImm;
258}
259
260void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
261 raw_ostream &O) {
262 const MCOperand &MO1 = MI->getOperand(Op);
263
264 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
265 printOperand(MI, Op, O);
266 return;
267 }
268
269 const MCOperand &MO3 = MI->getOperand(Op+2);
270 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
271
272 if (IdxMode == ARMII::IndexModePost) {
273 printAM2PostIndexOp(MI, Op, O);
274 return;
275 }
276 printAM2PreOrOffsetIndexOp(MI, Op, O);
277}
278
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000279void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000280 unsigned OpNum,
281 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000282 const MCOperand &MO1 = MI->getOperand(OpNum);
283 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000284
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000285 if (!MO1.getReg()) {
286 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000287 O << '#'
288 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
289 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000290 return;
291 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000292
Johnny Chen9e088762010-03-17 17:52:21 +0000293 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
294 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000295
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000296 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
297 O << ", "
298 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
299 << " #" << ShImm;
300}
301
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000302//===--------------------------------------------------------------------===//
303// Addressing Mode #3
304//===--------------------------------------------------------------------===//
305
306void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
307 raw_ostream &O) {
308 const MCOperand &MO1 = MI->getOperand(Op);
309 const MCOperand &MO2 = MI->getOperand(Op+1);
310 const MCOperand &MO3 = MI->getOperand(Op+2);
311
312 O << "[" << getRegisterName(MO1.getReg()) << "], ";
313
314 if (MO2.getReg()) {
315 O << (char)ARM_AM::getAM3Op(MO3.getImm())
316 << getRegisterName(MO2.getReg());
317 return;
318 }
319
320 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
321 O << '#'
322 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
323 << ImmOffs;
324}
325
326void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
327 raw_ostream &O) {
328 const MCOperand &MO1 = MI->getOperand(Op);
329 const MCOperand &MO2 = MI->getOperand(Op+1);
330 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000331
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000332 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000333
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000334 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000335 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000336 << getRegisterName(MO2.getReg()) << ']';
337 return;
338 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000339
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000340 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
341 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000342 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
343 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000344 O << ']';
345}
346
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000347void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
348 raw_ostream &O) {
349 const MCOperand &MO3 = MI->getOperand(Op+2);
350 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
351
352 if (IdxMode == ARMII::IndexModePost) {
353 printAM3PostIndexOp(MI, Op, O);
354 return;
355 }
356 printAM3PreOrOffsetIndexOp(MI, Op, O);
357}
358
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000359void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000360 unsigned OpNum,
361 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000362 const MCOperand &MO1 = MI->getOperand(OpNum);
363 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000364
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000365 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000366 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
367 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000368 return;
369 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000370
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000371 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000372 O << '#'
373 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
374 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000375}
376
Jim Grosbach7ce05792011-08-03 23:50:40 +0000377void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
378 unsigned OpNum,
379 raw_ostream &O) {
380 const MCOperand &MO = MI->getOperand(OpNum);
381 unsigned Imm = MO.getImm();
382 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
383}
384
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000385void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
386 raw_ostream &O) {
387 const MCOperand &MO1 = MI->getOperand(OpNum);
388 const MCOperand &MO2 = MI->getOperand(OpNum+1);
389
Jim Grosbach16578b52011-08-05 16:11:38 +0000390 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000391}
392
Owen Anderson154c41d2011-08-04 18:24:14 +0000393void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
394 unsigned OpNum,
395 raw_ostream &O) {
396 const MCOperand &MO = MI->getOperand(OpNum);
397 unsigned Imm = MO.getImm();
398 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
399}
400
401
Jim Grosbache6913602010-11-03 01:01:43 +0000402void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000403 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000404 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
405 .getImm());
406 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000407}
408
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000409void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000410 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000411 const MCOperand &MO1 = MI->getOperand(OpNum);
412 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000413
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000414 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000415 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000416 return;
417 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000418
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000419 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000420
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000421 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
422 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000423 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000424 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000425 }
426 O << "]";
427}
428
Chris Lattner35c33bd2010-04-04 04:47:45 +0000429void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
430 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000431 const MCOperand &MO1 = MI->getOperand(OpNum);
432 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000433
Bob Wilson226036e2010-03-20 22:13:40 +0000434 O << "[" << getRegisterName(MO1.getReg());
435 if (MO2.getImm()) {
436 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000437 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000438 }
Bob Wilson226036e2010-03-20 22:13:40 +0000439 O << "]";
440}
441
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000442void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
443 raw_ostream &O) {
444 const MCOperand &MO1 = MI->getOperand(OpNum);
445 O << "[" << getRegisterName(MO1.getReg()) << "]";
446}
447
Bob Wilson226036e2010-03-20 22:13:40 +0000448void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000449 unsigned OpNum,
450 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000451 const MCOperand &MO = MI->getOperand(OpNum);
452 if (MO.getReg() == 0)
453 O << "!";
454 else
455 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000456}
457
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000458void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
459 unsigned OpNum,
460 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000461 const MCOperand &MO = MI->getOperand(OpNum);
462 uint32_t v = ~MO.getImm();
463 int32_t lsb = CountTrailingZeros_32(v);
464 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
465 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
466 O << '#' << lsb << ", #" << width;
467}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000468
Johnny Chen1adc40c2010-08-12 20:46:17 +0000469void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
470 raw_ostream &O) {
471 unsigned val = MI->getOperand(OpNum).getImm();
472 O << ARM_MB::MemBOptToString(val);
473}
474
Bob Wilson22f5dc72010-08-16 18:27:34 +0000475void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000476 raw_ostream &O) {
477 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000478 bool isASR = (ShiftOp & (1 << 5)) != 0;
479 unsigned Amt = ShiftOp & 0x1f;
480 if (isASR)
481 O << ", asr #" << (Amt == 0 ? 32 : Amt);
482 else if (Amt)
483 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000484}
485
Jim Grosbachdde038a2011-07-20 21:40:26 +0000486void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
487 raw_ostream &O) {
488 unsigned Imm = MI->getOperand(OpNum).getImm();
489 if (Imm == 0)
490 return;
491 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
492 O << ", lsl #" << Imm;
493}
494
495void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
496 raw_ostream &O) {
497 unsigned Imm = MI->getOperand(OpNum).getImm();
498 // A shift amount of 32 is encoded as 0.
499 if (Imm == 0)
500 Imm = 32;
501 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
502 O << ", asr #" << Imm;
503}
504
Chris Lattner35c33bd2010-04-04 04:47:45 +0000505void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
506 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000507 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000508 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
509 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000510 O << getRegisterName(MI->getOperand(i).getReg());
511 }
512 O << "}";
513}
Chris Lattner4d152222009-10-19 22:23:04 +0000514
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000515void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
516 raw_ostream &O) {
517 const MCOperand &Op = MI->getOperand(OpNum);
518 if (Op.getImm())
519 O << "be";
520 else
521 O << "le";
522}
523
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000524void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
525 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000526 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000527 O << ARM_PROC::IModToString(Op.getImm());
528}
529
530void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
531 raw_ostream &O) {
532 const MCOperand &Op = MI->getOperand(OpNum);
533 unsigned IFlags = Op.getImm();
534 for (int i=2; i >= 0; --i)
535 if (IFlags & (1 << i))
536 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000537}
538
Chris Lattner35c33bd2010-04-04 04:47:45 +0000539void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
540 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000541 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000542 unsigned SpecRegRBit = Op.getImm() >> 4;
543 unsigned Mask = Op.getImm() & 0xf;
544
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000545 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
546 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
547 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
548 O << "APSR_";
549 switch (Mask) {
550 default: assert(0);
551 case 4: O << "g"; return;
552 case 8: O << "nzcvq"; return;
553 case 12: O << "nzcvqg"; return;
554 }
555 llvm_unreachable("Unexpected mask value!");
556 }
557
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000558 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000559 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000560 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000561 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000562
Johnny Chen9e088762010-03-17 17:52:21 +0000563 if (Mask) {
564 O << '_';
565 if (Mask & 8) O << 'f';
566 if (Mask & 4) O << 's';
567 if (Mask & 2) O << 'x';
568 if (Mask & 1) O << 'c';
569 }
570}
571
Chris Lattner35c33bd2010-04-04 04:47:45 +0000572void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
573 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000574 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
575 if (CC != ARMCC::AL)
576 O << ARMCondCodeToString(CC);
577}
578
Jim Grosbach15d78982010-09-14 22:27:15 +0000579void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000580 unsigned OpNum,
581 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000582 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
583 O << ARMCondCodeToString(CC);
584}
585
Chris Lattner35c33bd2010-04-04 04:47:45 +0000586void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
587 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000588 if (MI->getOperand(OpNum).getReg()) {
589 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
590 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000591 O << 's';
592 }
593}
594
Chris Lattner35c33bd2010-04-04 04:47:45 +0000595void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
596 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000597 O << MI->getOperand(OpNum).getImm();
598}
599
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000600void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
601 raw_ostream &O) {
602 O << "p" << MI->getOperand(OpNum).getImm();
603}
604
605void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
606 raw_ostream &O) {
607 O << "c" << MI->getOperand(OpNum).getImm();
608}
609
Chris Lattner35c33bd2010-04-04 04:47:45 +0000610void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
611 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000612 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000613}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000614
Chris Lattner35c33bd2010-04-04 04:47:45 +0000615void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
616 raw_ostream &O) {
Johnny Chen541ba7d2010-01-25 22:13:10 +0000617 O << "#" << MI->getOperand(OpNum).getImm() * 4;
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000618}
Johnny Chen9e088762010-03-17 17:52:21 +0000619
Chris Lattner35c33bd2010-04-04 04:47:45 +0000620void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
621 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000622 // (3 - the number of trailing zeros) is the number of then / else.
623 unsigned Mask = MI->getOperand(OpNum).getImm();
624 unsigned CondBit0 = Mask >> 4 & 1;
625 unsigned NumTZ = CountTrailingZeros_32(Mask);
626 assert(NumTZ <= 3 && "Invalid IT mask!");
627 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
628 bool T = ((Mask >> Pos) & 1) == CondBit0;
629 if (T)
630 O << 't';
631 else
632 O << 'e';
633 }
634}
635
Chris Lattner35c33bd2010-04-04 04:47:45 +0000636void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
637 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000638 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000639 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000640
641 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000642 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000643 return;
644 }
645
646 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000647 if (unsigned RegNum = MO2.getReg())
648 O << ", " << getRegisterName(RegNum);
649 O << "]";
650}
651
652void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
653 unsigned Op,
654 raw_ostream &O,
655 unsigned Scale) {
656 const MCOperand &MO1 = MI->getOperand(Op);
657 const MCOperand &MO2 = MI->getOperand(Op + 1);
658
659 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
660 printOperand(MI, Op, O);
661 return;
662 }
663
664 O << "[" << getRegisterName(MO1.getReg());
665 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000666 O << ", #" << ImmOffs * Scale;
667 O << "]";
668}
669
Bill Wendlingf4caf692010-12-14 03:36:38 +0000670void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
671 unsigned Op,
672 raw_ostream &O) {
673 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000674}
675
Bill Wendlingf4caf692010-12-14 03:36:38 +0000676void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
677 unsigned Op,
678 raw_ostream &O) {
679 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000680}
681
Bill Wendlingf4caf692010-12-14 03:36:38 +0000682void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
683 unsigned Op,
684 raw_ostream &O) {
685 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000686}
687
Chris Lattner35c33bd2010-04-04 04:47:45 +0000688void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
689 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000690 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000691}
692
Johnny Chen9e088762010-03-17 17:52:21 +0000693// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
694// register with shift forms.
695// REG 0 0 - e.g. R5
696// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000697void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
698 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000699 const MCOperand &MO1 = MI->getOperand(OpNum);
700 const MCOperand &MO2 = MI->getOperand(OpNum+1);
701
702 unsigned Reg = MO1.getReg();
703 O << getRegisterName(Reg);
704
705 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000706 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000707 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
708 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
709 if (ShOpc != ARM_AM::rrx)
710 O << " #" << ARM_AM::getSORegOffset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000711}
712
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000713void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
714 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000715 const MCOperand &MO1 = MI->getOperand(OpNum);
716 const MCOperand &MO2 = MI->getOperand(OpNum+1);
717
Jim Grosbach3e556122010-10-26 22:37:02 +0000718 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
719 printOperand(MI, OpNum, O);
720 return;
721 }
722
Johnny Chen9e088762010-03-17 17:52:21 +0000723 O << "[" << getRegisterName(MO1.getReg());
724
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000725 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000726 bool isSub = OffImm < 0;
727 // Special value for #-0. All others are normal.
728 if (OffImm == INT32_MIN)
729 OffImm = 0;
730 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000731 O << ", #-" << -OffImm;
732 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000733 O << ", #" << OffImm;
734 O << "]";
735}
736
737void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000738 unsigned OpNum,
739 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000740 const MCOperand &MO1 = MI->getOperand(OpNum);
741 const MCOperand &MO2 = MI->getOperand(OpNum+1);
742
743 O << "[" << getRegisterName(MO1.getReg());
744
745 int32_t OffImm = (int32_t)MO2.getImm();
746 // Don't print +0.
747 if (OffImm < 0)
748 O << ", #-" << -OffImm;
749 else if (OffImm > 0)
750 O << ", #" << OffImm;
751 O << "]";
752}
753
754void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000755 unsigned OpNum,
756 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000757 const MCOperand &MO1 = MI->getOperand(OpNum);
758 const MCOperand &MO2 = MI->getOperand(OpNum+1);
759
760 O << "[" << getRegisterName(MO1.getReg());
761
762 int32_t OffImm = (int32_t)MO2.getImm() / 4;
763 // Don't print +0.
764 if (OffImm < 0)
765 O << ", #-" << -OffImm * 4;
766 else if (OffImm > 0)
767 O << ", #" << OffImm * 4;
768 O << "]";
769}
770
771void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(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 int32_t OffImm = (int32_t)MO1.getImm();
776 // Don't print +0.
777 if (OffImm < 0)
778 O << "#-" << -OffImm;
779 else if (OffImm > 0)
780 O << "#" << OffImm;
781}
782
783void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000784 unsigned OpNum,
785 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000786 const MCOperand &MO1 = MI->getOperand(OpNum);
787 int32_t OffImm = (int32_t)MO1.getImm() / 4;
788 // Don't print +0.
789 if (OffImm < 0)
790 O << "#-" << -OffImm * 4;
791 else if (OffImm > 0)
792 O << "#" << OffImm * 4;
793}
794
795void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000796 unsigned OpNum,
797 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000798 const MCOperand &MO1 = MI->getOperand(OpNum);
799 const MCOperand &MO2 = MI->getOperand(OpNum+1);
800 const MCOperand &MO3 = MI->getOperand(OpNum+2);
801
802 O << "[" << getRegisterName(MO1.getReg());
803
804 assert(MO2.getReg() && "Invalid so_reg load / store address!");
805 O << ", " << getRegisterName(MO2.getReg());
806
807 unsigned ShAmt = MO3.getImm();
808 if (ShAmt) {
809 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
810 O << ", lsl #" << ShAmt;
811 }
812 O << "]";
813}
814
Chris Lattner35c33bd2010-04-04 04:47:45 +0000815void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
816 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000817 const MCOperand &MO = MI->getOperand(OpNum);
818 O << '#';
819 if (MO.isFPImm()) {
820 O << (float)MO.getFPImm();
821 } else {
822 union {
823 uint32_t I;
824 float F;
825 } FPUnion;
826
827 FPUnion.I = MO.getImm();
828 O << FPUnion.F;
829 }
Johnny Chen9e088762010-03-17 17:52:21 +0000830}
831
Chris Lattner35c33bd2010-04-04 04:47:45 +0000832void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
833 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000834 const MCOperand &MO = MI->getOperand(OpNum);
835 O << '#';
836 if (MO.isFPImm()) {
837 O << MO.getFPImm();
838 } else {
839 // We expect the binary encoding of a floating point number here.
840 union {
841 uint64_t I;
842 double D;
843 } FPUnion;
844
845 FPUnion.I = MO.getImm();
846 O << FPUnion.D;
847 }
Johnny Chen9e088762010-03-17 17:52:21 +0000848}
849
Bob Wilson1a913ed2010-06-11 21:34:50 +0000850void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
851 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000852 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
853 unsigned EltBits;
854 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000855 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000856}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000857
Jim Grosbachf4943352011-07-25 23:09:14 +0000858void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
859 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000860 unsigned Imm = MI->getOperand(OpNum).getImm();
861 O << "#" << Imm + 1;
862}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000863
864void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
865 raw_ostream &O) {
866 unsigned Imm = MI->getOperand(OpNum).getImm();
867 if (Imm == 0)
868 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000869 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000870 switch (Imm) {
871 default: assert (0 && "illegal ror immediate!");
872 case 1: O << "8\n"; break;
873 case 2: O << "16\n"; break;
874 case 3: O << "24\n"; break;
875 }
876}