blob: a8008faa84036319efb1c38ff89a15b1d3add1d4 [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 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000103 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
104 MI->getOperand(4).getImm() == 4) {
105 O << '\t' << "pop";
106 printPredicateOperand(MI, 5, O);
107 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
108 return;
109 }
110
Johnny Chen9e088762010-03-17 17:52:21 +0000111
112 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000113 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000114 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000115 O << '\t' << "vpush";
116 printPredicateOperand(MI, 2, O);
117 O << '\t';
118 printRegisterList(MI, 4, O);
119 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000120 }
121
122 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000123 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000124 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000125 O << '\t' << "vpop";
126 printPredicateOperand(MI, 2, O);
127 O << '\t';
128 printRegisterList(MI, 4, O);
129 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000130 }
131
Owen Anderson565a0362011-07-18 23:25:34 +0000132 if (Opcode == ARM::tLDMIA || Opcode == ARM::tSTMIA) {
133 bool Writeback = true;
134 unsigned BaseReg = MI->getOperand(0).getReg();
135 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
136 if (MI->getOperand(i).getReg() == BaseReg)
137 Writeback = false;
138 }
139
140 if (Opcode == ARM::tLDMIA)
141 O << "\tldmia";
142 else if (Opcode == ARM::tSTMIA)
143 O << "\tstmia";
144 else
145 llvm_unreachable("Unknown opcode!");
146
147 printPredicateOperand(MI, 1, O);
148 O << '\t' << getRegisterName(BaseReg);
149 if (Writeback) O << "!";
150 O << ", ";
151 printRegisterList(MI, 3, O);
152 return;
153 }
154
Chris Lattner35c33bd2010-04-04 04:47:45 +0000155 printInstruction(MI, O);
Bill Wendling04863d02010-11-13 10:40:19 +0000156}
Chris Lattnerfd603822009-10-19 19:56:26 +0000157
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000158void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000159 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000160 const MCOperand &Op = MI->getOperand(OpNo);
161 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000162 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000163 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000164 } else if (Op.isImm()) {
165 O << '#' << Op.getImm();
166 } else {
167 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000168 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000169 }
170}
Chris Lattner61d35c22009-10-19 21:21:39 +0000171
Chris Lattner017d9472009-10-20 00:40:56 +0000172// so_reg is a 4-operand unit corresponding to register forms of the A5.1
173// "Addressing Mode 1 - Data-processing operands" forms. This includes:
174// REG 0 0 - e.g. R5
175// REG REG 0,SH_OPC - e.g. R5, ROR R3
176// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000177void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000178 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000179 const MCOperand &MO1 = MI->getOperand(OpNum);
180 const MCOperand &MO2 = MI->getOperand(OpNum+1);
181 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000182
Chris Lattner017d9472009-10-20 00:40:56 +0000183 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000184
Chris Lattner017d9472009-10-20 00:40:56 +0000185 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000186 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
187 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000188 if (ShOpc == ARM_AM::rrx)
189 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000190
191 O << ' ' << getRegisterName(MO2.getReg());
192 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000193}
Chris Lattner084f87d2009-10-19 21:57:05 +0000194
Owen Anderson152d4a42011-07-21 23:38:37 +0000195void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
196 raw_ostream &O) {
197 const MCOperand &MO1 = MI->getOperand(OpNum);
198 const MCOperand &MO2 = MI->getOperand(OpNum+1);
199
200 O << getRegisterName(MO1.getReg());
201
202 // Print the shift opc.
203 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
204 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
205 if (ShOpc == ARM_AM::rrx)
206 return;
207 O << " #" << ARM_AM::getSORegOffset(MO2.getImm());
208}
209
210
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000211//===--------------------------------------------------------------------===//
212// Addressing Mode #2
213//===--------------------------------------------------------------------===//
214
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000215void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
216 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000217 const MCOperand &MO1 = MI->getOperand(Op);
218 const MCOperand &MO2 = MI->getOperand(Op+1);
219 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000220
Chris Lattner084f87d2009-10-19 21:57:05 +0000221 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000222
Chris Lattner084f87d2009-10-19 21:57:05 +0000223 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000224 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000225 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000226 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
227 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000228 O << "]";
229 return;
230 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000231
Chris Lattner084f87d2009-10-19 21:57:05 +0000232 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000233 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
234 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000235
Chris Lattner084f87d2009-10-19 21:57:05 +0000236 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
237 O << ", "
238 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
239 << " #" << ShImm;
240 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000241}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000242
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000243void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
244 raw_ostream &O) {
245 const MCOperand &MO1 = MI->getOperand(Op);
246 const MCOperand &MO2 = MI->getOperand(Op+1);
247 const MCOperand &MO3 = MI->getOperand(Op+2);
248
249 O << "[" << getRegisterName(MO1.getReg()) << "], ";
250
251 if (!MO2.getReg()) {
252 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
253 O << '#'
254 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
255 << ImmOffs;
256 return;
257 }
258
259 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
260 << getRegisterName(MO2.getReg());
261
262 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
263 O << ", "
264 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
265 << " #" << ShImm;
266}
267
268void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
269 raw_ostream &O) {
270 const MCOperand &MO1 = MI->getOperand(Op);
271
272 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
273 printOperand(MI, Op, O);
274 return;
275 }
276
277 const MCOperand &MO3 = MI->getOperand(Op+2);
278 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
279
280 if (IdxMode == ARMII::IndexModePost) {
281 printAM2PostIndexOp(MI, Op, O);
282 return;
283 }
284 printAM2PreOrOffsetIndexOp(MI, Op, O);
285}
286
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000287void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000288 unsigned OpNum,
289 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000290 const MCOperand &MO1 = MI->getOperand(OpNum);
291 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000292
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000293 if (!MO1.getReg()) {
294 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000295 O << '#'
296 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
297 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000298 return;
299 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000300
Johnny Chen9e088762010-03-17 17:52:21 +0000301 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
302 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000303
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000304 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
305 O << ", "
306 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
307 << " #" << ShImm;
308}
309
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000310//===--------------------------------------------------------------------===//
311// Addressing Mode #3
312//===--------------------------------------------------------------------===//
313
314void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
315 raw_ostream &O) {
316 const MCOperand &MO1 = MI->getOperand(Op);
317 const MCOperand &MO2 = MI->getOperand(Op+1);
318 const MCOperand &MO3 = MI->getOperand(Op+2);
319
320 O << "[" << getRegisterName(MO1.getReg()) << "], ";
321
322 if (MO2.getReg()) {
323 O << (char)ARM_AM::getAM3Op(MO3.getImm())
324 << getRegisterName(MO2.getReg());
325 return;
326 }
327
328 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
329 O << '#'
330 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
331 << ImmOffs;
332}
333
334void ARMInstPrinter::printAM3PreOrOffsetIndexOp(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);
Jim Grosbach15d78982010-09-14 22:27:15 +0000339
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000340 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000341
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000342 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000343 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000344 << getRegisterName(MO2.getReg()) << ']';
345 return;
346 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000347
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000348 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
349 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000350 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
351 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000352 O << ']';
353}
354
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000355void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
356 raw_ostream &O) {
357 const MCOperand &MO3 = MI->getOperand(Op+2);
358 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
359
360 if (IdxMode == ARMII::IndexModePost) {
361 printAM3PostIndexOp(MI, Op, O);
362 return;
363 }
364 printAM3PreOrOffsetIndexOp(MI, Op, O);
365}
366
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000367void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000368 unsigned OpNum,
369 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000370 const MCOperand &MO1 = MI->getOperand(OpNum);
371 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000372
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000373 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000374 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
375 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000376 return;
377 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000378
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000379 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000380 O << '#'
381 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
382 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000383}
384
Jim Grosbach7ce05792011-08-03 23:50:40 +0000385void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
386 unsigned OpNum,
387 raw_ostream &O) {
388 const MCOperand &MO = MI->getOperand(OpNum);
389 unsigned Imm = MO.getImm();
390 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
391}
392
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000393void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
394 raw_ostream &O) {
395 const MCOperand &MO1 = MI->getOperand(OpNum);
396 const MCOperand &MO2 = MI->getOperand(OpNum+1);
397
Jim Grosbach16578b52011-08-05 16:11:38 +0000398 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000399}
400
Owen Anderson154c41d2011-08-04 18:24:14 +0000401void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
402 unsigned OpNum,
403 raw_ostream &O) {
404 const MCOperand &MO = MI->getOperand(OpNum);
405 unsigned Imm = MO.getImm();
406 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
407}
408
409
Jim Grosbache6913602010-11-03 01:01:43 +0000410void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000411 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000412 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
413 .getImm());
414 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000415}
416
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000417void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000418 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000419 const MCOperand &MO1 = MI->getOperand(OpNum);
420 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000421
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000422 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000423 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000424 return;
425 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000426
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000427 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000428
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000429 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
430 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000431 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000432 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000433 }
434 O << "]";
435}
436
Chris Lattner35c33bd2010-04-04 04:47:45 +0000437void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
438 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000439 const MCOperand &MO1 = MI->getOperand(OpNum);
440 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000441
Bob Wilson226036e2010-03-20 22:13:40 +0000442 O << "[" << getRegisterName(MO1.getReg());
443 if (MO2.getImm()) {
444 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000445 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000446 }
Bob Wilson226036e2010-03-20 22:13:40 +0000447 O << "]";
448}
449
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000450void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
451 raw_ostream &O) {
452 const MCOperand &MO1 = MI->getOperand(OpNum);
453 O << "[" << getRegisterName(MO1.getReg()) << "]";
454}
455
Bob Wilson226036e2010-03-20 22:13:40 +0000456void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000457 unsigned OpNum,
458 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000459 const MCOperand &MO = MI->getOperand(OpNum);
460 if (MO.getReg() == 0)
461 O << "!";
462 else
463 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000464}
465
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000466void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
467 unsigned OpNum,
468 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000469 const MCOperand &MO = MI->getOperand(OpNum);
470 uint32_t v = ~MO.getImm();
471 int32_t lsb = CountTrailingZeros_32(v);
472 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
473 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
474 O << '#' << lsb << ", #" << width;
475}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000476
Johnny Chen1adc40c2010-08-12 20:46:17 +0000477void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
478 raw_ostream &O) {
479 unsigned val = MI->getOperand(OpNum).getImm();
480 O << ARM_MB::MemBOptToString(val);
481}
482
Bob Wilson22f5dc72010-08-16 18:27:34 +0000483void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000484 raw_ostream &O) {
485 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000486 bool isASR = (ShiftOp & (1 << 5)) != 0;
487 unsigned Amt = ShiftOp & 0x1f;
488 if (isASR)
489 O << ", asr #" << (Amt == 0 ? 32 : Amt);
490 else if (Amt)
491 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000492}
493
Jim Grosbachdde038a2011-07-20 21:40:26 +0000494void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
495 raw_ostream &O) {
496 unsigned Imm = MI->getOperand(OpNum).getImm();
497 if (Imm == 0)
498 return;
499 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
500 O << ", lsl #" << Imm;
501}
502
503void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
504 raw_ostream &O) {
505 unsigned Imm = MI->getOperand(OpNum).getImm();
506 // A shift amount of 32 is encoded as 0.
507 if (Imm == 0)
508 Imm = 32;
509 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
510 O << ", asr #" << Imm;
511}
512
Chris Lattner35c33bd2010-04-04 04:47:45 +0000513void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
514 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000515 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000516 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
517 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000518 O << getRegisterName(MI->getOperand(i).getReg());
519 }
520 O << "}";
521}
Chris Lattner4d152222009-10-19 22:23:04 +0000522
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000523void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
524 raw_ostream &O) {
525 const MCOperand &Op = MI->getOperand(OpNum);
526 if (Op.getImm())
527 O << "be";
528 else
529 O << "le";
530}
531
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000532void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
533 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000534 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000535 O << ARM_PROC::IModToString(Op.getImm());
536}
537
538void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
539 raw_ostream &O) {
540 const MCOperand &Op = MI->getOperand(OpNum);
541 unsigned IFlags = Op.getImm();
542 for (int i=2; i >= 0; --i)
543 if (IFlags & (1 << i))
544 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000545}
546
Chris Lattner35c33bd2010-04-04 04:47:45 +0000547void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
548 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000549 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000550 unsigned SpecRegRBit = Op.getImm() >> 4;
551 unsigned Mask = Op.getImm() & 0xf;
552
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000553 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
554 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
555 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
556 O << "APSR_";
557 switch (Mask) {
558 default: assert(0);
559 case 4: O << "g"; return;
560 case 8: O << "nzcvq"; return;
561 case 12: O << "nzcvqg"; return;
562 }
563 llvm_unreachable("Unexpected mask value!");
564 }
565
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000566 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000567 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000568 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000569 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000570
Johnny Chen9e088762010-03-17 17:52:21 +0000571 if (Mask) {
572 O << '_';
573 if (Mask & 8) O << 'f';
574 if (Mask & 4) O << 's';
575 if (Mask & 2) O << 'x';
576 if (Mask & 1) O << 'c';
577 }
578}
579
Chris Lattner35c33bd2010-04-04 04:47:45 +0000580void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
581 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000582 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
583 if (CC != ARMCC::AL)
584 O << ARMCondCodeToString(CC);
585}
586
Jim Grosbach15d78982010-09-14 22:27:15 +0000587void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000588 unsigned OpNum,
589 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000590 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
591 O << ARMCondCodeToString(CC);
592}
593
Chris Lattner35c33bd2010-04-04 04:47:45 +0000594void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
595 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000596 if (MI->getOperand(OpNum).getReg()) {
597 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
598 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000599 O << 's';
600 }
601}
602
Chris Lattner35c33bd2010-04-04 04:47:45 +0000603void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
604 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000605 O << MI->getOperand(OpNum).getImm();
606}
607
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000608void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
609 raw_ostream &O) {
610 O << "p" << MI->getOperand(OpNum).getImm();
611}
612
613void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
614 raw_ostream &O) {
615 O << "c" << MI->getOperand(OpNum).getImm();
616}
617
Chris Lattner35c33bd2010-04-04 04:47:45 +0000618void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
619 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000620 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000621}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000622
Chris Lattner35c33bd2010-04-04 04:47:45 +0000623void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
624 raw_ostream &O) {
Johnny Chen541ba7d2010-01-25 22:13:10 +0000625 O << "#" << MI->getOperand(OpNum).getImm() * 4;
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000626}
Johnny Chen9e088762010-03-17 17:52:21 +0000627
Chris Lattner35c33bd2010-04-04 04:47:45 +0000628void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
629 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000630 // (3 - the number of trailing zeros) is the number of then / else.
631 unsigned Mask = MI->getOperand(OpNum).getImm();
632 unsigned CondBit0 = Mask >> 4 & 1;
633 unsigned NumTZ = CountTrailingZeros_32(Mask);
634 assert(NumTZ <= 3 && "Invalid IT mask!");
635 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
636 bool T = ((Mask >> Pos) & 1) == CondBit0;
637 if (T)
638 O << 't';
639 else
640 O << 'e';
641 }
642}
643
Chris Lattner35c33bd2010-04-04 04:47:45 +0000644void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
645 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000646 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000647 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000648
649 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000650 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000651 return;
652 }
653
654 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000655 if (unsigned RegNum = MO2.getReg())
656 O << ", " << getRegisterName(RegNum);
657 O << "]";
658}
659
660void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
661 unsigned Op,
662 raw_ostream &O,
663 unsigned Scale) {
664 const MCOperand &MO1 = MI->getOperand(Op);
665 const MCOperand &MO2 = MI->getOperand(Op + 1);
666
667 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
668 printOperand(MI, Op, O);
669 return;
670 }
671
672 O << "[" << getRegisterName(MO1.getReg());
673 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000674 O << ", #" << ImmOffs * Scale;
675 O << "]";
676}
677
Bill Wendlingf4caf692010-12-14 03:36:38 +0000678void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
679 unsigned Op,
680 raw_ostream &O) {
681 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000682}
683
Bill Wendlingf4caf692010-12-14 03:36:38 +0000684void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
685 unsigned Op,
686 raw_ostream &O) {
687 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000688}
689
Bill Wendlingf4caf692010-12-14 03:36:38 +0000690void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
691 unsigned Op,
692 raw_ostream &O) {
693 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000694}
695
Chris Lattner35c33bd2010-04-04 04:47:45 +0000696void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
697 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000698 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000699}
700
Johnny Chen9e088762010-03-17 17:52:21 +0000701// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
702// register with shift forms.
703// REG 0 0 - e.g. R5
704// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000705void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
706 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000707 const MCOperand &MO1 = MI->getOperand(OpNum);
708 const MCOperand &MO2 = MI->getOperand(OpNum+1);
709
710 unsigned Reg = MO1.getReg();
711 O << getRegisterName(Reg);
712
713 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000714 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000715 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
716 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
717 if (ShOpc != ARM_AM::rrx)
718 O << " #" << ARM_AM::getSORegOffset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000719}
720
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000721void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
722 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000723 const MCOperand &MO1 = MI->getOperand(OpNum);
724 const MCOperand &MO2 = MI->getOperand(OpNum+1);
725
Jim Grosbach3e556122010-10-26 22:37:02 +0000726 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
727 printOperand(MI, OpNum, O);
728 return;
729 }
730
Johnny Chen9e088762010-03-17 17:52:21 +0000731 O << "[" << getRegisterName(MO1.getReg());
732
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000733 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000734 bool isSub = OffImm < 0;
735 // Special value for #-0. All others are normal.
736 if (OffImm == INT32_MIN)
737 OffImm = 0;
738 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000739 O << ", #-" << -OffImm;
740 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000741 O << ", #" << OffImm;
742 O << "]";
743}
744
745void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000746 unsigned OpNum,
747 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000748 const MCOperand &MO1 = MI->getOperand(OpNum);
749 const MCOperand &MO2 = MI->getOperand(OpNum+1);
750
751 O << "[" << getRegisterName(MO1.getReg());
752
753 int32_t OffImm = (int32_t)MO2.getImm();
754 // Don't print +0.
755 if (OffImm < 0)
756 O << ", #-" << -OffImm;
757 else if (OffImm > 0)
758 O << ", #" << OffImm;
759 O << "]";
760}
761
762void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000763 unsigned OpNum,
764 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000765 const MCOperand &MO1 = MI->getOperand(OpNum);
766 const MCOperand &MO2 = MI->getOperand(OpNum+1);
767
768 O << "[" << getRegisterName(MO1.getReg());
769
770 int32_t OffImm = (int32_t)MO2.getImm() / 4;
771 // Don't print +0.
772 if (OffImm < 0)
773 O << ", #-" << -OffImm * 4;
774 else if (OffImm > 0)
775 O << ", #" << OffImm * 4;
776 O << "]";
777}
778
779void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000780 unsigned OpNum,
781 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000782 const MCOperand &MO1 = MI->getOperand(OpNum);
783 int32_t OffImm = (int32_t)MO1.getImm();
784 // Don't print +0.
785 if (OffImm < 0)
786 O << "#-" << -OffImm;
787 else if (OffImm > 0)
788 O << "#" << OffImm;
789}
790
791void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000792 unsigned OpNum,
793 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000794 const MCOperand &MO1 = MI->getOperand(OpNum);
795 int32_t OffImm = (int32_t)MO1.getImm() / 4;
796 // Don't print +0.
797 if (OffImm < 0)
798 O << "#-" << -OffImm * 4;
799 else if (OffImm > 0)
800 O << "#" << OffImm * 4;
801}
802
803void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000804 unsigned OpNum,
805 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000806 const MCOperand &MO1 = MI->getOperand(OpNum);
807 const MCOperand &MO2 = MI->getOperand(OpNum+1);
808 const MCOperand &MO3 = MI->getOperand(OpNum+2);
809
810 O << "[" << getRegisterName(MO1.getReg());
811
812 assert(MO2.getReg() && "Invalid so_reg load / store address!");
813 O << ", " << getRegisterName(MO2.getReg());
814
815 unsigned ShAmt = MO3.getImm();
816 if (ShAmt) {
817 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
818 O << ", lsl #" << ShAmt;
819 }
820 O << "]";
821}
822
Chris Lattner35c33bd2010-04-04 04:47:45 +0000823void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
824 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000825 const MCOperand &MO = MI->getOperand(OpNum);
826 O << '#';
827 if (MO.isFPImm()) {
828 O << (float)MO.getFPImm();
829 } else {
830 union {
831 uint32_t I;
832 float F;
833 } FPUnion;
834
835 FPUnion.I = MO.getImm();
836 O << FPUnion.F;
837 }
Johnny Chen9e088762010-03-17 17:52:21 +0000838}
839
Chris Lattner35c33bd2010-04-04 04:47:45 +0000840void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
841 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000842 const MCOperand &MO = MI->getOperand(OpNum);
843 O << '#';
844 if (MO.isFPImm()) {
845 O << MO.getFPImm();
846 } else {
847 // We expect the binary encoding of a floating point number here.
848 union {
849 uint64_t I;
850 double D;
851 } FPUnion;
852
853 FPUnion.I = MO.getImm();
854 O << FPUnion.D;
855 }
Johnny Chen9e088762010-03-17 17:52:21 +0000856}
857
Bob Wilson1a913ed2010-06-11 21:34:50 +0000858void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
859 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000860 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
861 unsigned EltBits;
862 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000863 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000864}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000865
Jim Grosbachf4943352011-07-25 23:09:14 +0000866void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
867 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000868 unsigned Imm = MI->getOperand(OpNum).getImm();
869 O << "#" << Imm + 1;
870}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000871
872void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
873 raw_ostream &O) {
874 unsigned Imm = MI->getOperand(OpNum).getImm();
875 if (Imm == 0)
876 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000877 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000878 switch (Imm) {
879 default: assert (0 && "illegal ror immediate!");
880 case 1: O << "8\n"; break;
881 case 2: O << "16\n"; break;
882 case 3: O << "24\n"; break;
883 }
884}