blob: af04355e94f6b9189077b9496bab5f083f701927 [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 }
Jim Grosbachf6713912011-08-11 18:07:11 +000091 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
92 MI->getOperand(3).getImm() == -4) {
93 O << '\t' << "push";
94 printPredicateOperand(MI, 4, O);
95 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
96 return;
97 }
Johnny Chen9e088762010-03-17 17:52:21 +000098
99 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000100 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000101 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000102 O << '\t' << "pop";
103 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000104 if (Opcode == ARM::t2LDMIA_UPD)
105 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000106 O << '\t';
107 printRegisterList(MI, 4, O);
108 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000109 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000110 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
111 MI->getOperand(4).getImm() == 4) {
112 O << '\t' << "pop";
113 printPredicateOperand(MI, 5, O);
114 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
115 return;
116 }
117
Johnny Chen9e088762010-03-17 17:52:21 +0000118
119 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000120 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000121 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000122 O << '\t' << "vpush";
123 printPredicateOperand(MI, 2, O);
124 O << '\t';
125 printRegisterList(MI, 4, O);
126 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000127 }
128
129 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000130 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_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' << "vpop";
133 printPredicateOperand(MI, 2, O);
134 O << '\t';
135 printRegisterList(MI, 4, O);
136 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000137 }
138
Owen Anderson565a0362011-07-18 23:25:34 +0000139 if (Opcode == ARM::tLDMIA || Opcode == ARM::tSTMIA) {
140 bool Writeback = true;
141 unsigned BaseReg = MI->getOperand(0).getReg();
142 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
143 if (MI->getOperand(i).getReg() == BaseReg)
144 Writeback = false;
145 }
146
147 if (Opcode == ARM::tLDMIA)
148 O << "\tldmia";
149 else if (Opcode == ARM::tSTMIA)
150 O << "\tstmia";
151 else
152 llvm_unreachable("Unknown opcode!");
153
154 printPredicateOperand(MI, 1, O);
155 O << '\t' << getRegisterName(BaseReg);
156 if (Writeback) O << "!";
157 O << ", ";
158 printRegisterList(MI, 3, O);
159 return;
160 }
161
Chris Lattner35c33bd2010-04-04 04:47:45 +0000162 printInstruction(MI, O);
Bill Wendling04863d02010-11-13 10:40:19 +0000163}
Chris Lattnerfd603822009-10-19 19:56:26 +0000164
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000165void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000166 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000167 const MCOperand &Op = MI->getOperand(OpNo);
168 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000169 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000170 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000171 } else if (Op.isImm()) {
172 O << '#' << Op.getImm();
173 } else {
174 assert(Op.isExpr() && "unknown operand kind in printOperand");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000175 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000176 }
177}
Chris Lattner61d35c22009-10-19 21:21:39 +0000178
Chris Lattner017d9472009-10-20 00:40:56 +0000179// so_reg is a 4-operand unit corresponding to register forms of the A5.1
180// "Addressing Mode 1 - Data-processing operands" forms. This includes:
181// REG 0 0 - e.g. R5
182// REG REG 0,SH_OPC - e.g. R5, ROR R3
183// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000184void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000185 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000186 const MCOperand &MO1 = MI->getOperand(OpNum);
187 const MCOperand &MO2 = MI->getOperand(OpNum+1);
188 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000189
Chris Lattner017d9472009-10-20 00:40:56 +0000190 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000191
Chris Lattner017d9472009-10-20 00:40:56 +0000192 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000193 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
194 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000195 if (ShOpc == ARM_AM::rrx)
196 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000197
198 O << ' ' << getRegisterName(MO2.getReg());
199 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000200}
Chris Lattner084f87d2009-10-19 21:57:05 +0000201
Owen Anderson152d4a42011-07-21 23:38:37 +0000202void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
203 raw_ostream &O) {
204 const MCOperand &MO1 = MI->getOperand(OpNum);
205 const MCOperand &MO2 = MI->getOperand(OpNum+1);
206
207 O << getRegisterName(MO1.getReg());
208
209 // Print the shift opc.
210 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
211 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
212 if (ShOpc == ARM_AM::rrx)
213 return;
214 O << " #" << ARM_AM::getSORegOffset(MO2.getImm());
215}
216
217
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000218//===--------------------------------------------------------------------===//
219// Addressing Mode #2
220//===--------------------------------------------------------------------===//
221
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000222void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
223 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000224 const MCOperand &MO1 = MI->getOperand(Op);
225 const MCOperand &MO2 = MI->getOperand(Op+1);
226 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000227
Chris Lattner084f87d2009-10-19 21:57:05 +0000228 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000229
Chris Lattner084f87d2009-10-19 21:57:05 +0000230 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000231 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
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 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000235 O << "]";
236 return;
237 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000238
Chris Lattner084f87d2009-10-19 21:57:05 +0000239 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000240 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
241 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000242
Chris Lattner084f87d2009-10-19 21:57:05 +0000243 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
244 O << ", "
245 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
246 << " #" << ShImm;
247 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000248}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000249
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000250void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
251 raw_ostream &O) {
252 const MCOperand &MO1 = MI->getOperand(Op);
253 const MCOperand &MO2 = MI->getOperand(Op+1);
254 const MCOperand &MO3 = MI->getOperand(Op+2);
255
256 O << "[" << getRegisterName(MO1.getReg()) << "], ";
257
258 if (!MO2.getReg()) {
259 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
260 O << '#'
261 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
262 << ImmOffs;
263 return;
264 }
265
266 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
267 << getRegisterName(MO2.getReg());
268
269 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
270 O << ", "
271 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
272 << " #" << ShImm;
273}
274
275void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
276 raw_ostream &O) {
277 const MCOperand &MO1 = MI->getOperand(Op);
278
279 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
280 printOperand(MI, Op, O);
281 return;
282 }
283
284 const MCOperand &MO3 = MI->getOperand(Op+2);
285 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
286
287 if (IdxMode == ARMII::IndexModePost) {
288 printAM2PostIndexOp(MI, Op, O);
289 return;
290 }
291 printAM2PreOrOffsetIndexOp(MI, Op, O);
292}
293
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000294void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000295 unsigned OpNum,
296 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000297 const MCOperand &MO1 = MI->getOperand(OpNum);
298 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000299
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000300 if (!MO1.getReg()) {
301 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000302 O << '#'
303 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
304 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000305 return;
306 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000307
Johnny Chen9e088762010-03-17 17:52:21 +0000308 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
309 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000310
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000311 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
312 O << ", "
313 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
314 << " #" << ShImm;
315}
316
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000317//===--------------------------------------------------------------------===//
318// Addressing Mode #3
319//===--------------------------------------------------------------------===//
320
321void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
322 raw_ostream &O) {
323 const MCOperand &MO1 = MI->getOperand(Op);
324 const MCOperand &MO2 = MI->getOperand(Op+1);
325 const MCOperand &MO3 = MI->getOperand(Op+2);
326
327 O << "[" << getRegisterName(MO1.getReg()) << "], ";
328
329 if (MO2.getReg()) {
330 O << (char)ARM_AM::getAM3Op(MO3.getImm())
331 << getRegisterName(MO2.getReg());
332 return;
333 }
334
335 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
336 O << '#'
337 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
338 << ImmOffs;
339}
340
341void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
342 raw_ostream &O) {
343 const MCOperand &MO1 = MI->getOperand(Op);
344 const MCOperand &MO2 = MI->getOperand(Op+1);
345 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000346
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000347 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000348
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000349 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000350 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000351 << getRegisterName(MO2.getReg()) << ']';
352 return;
353 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000354
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000355 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
356 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000357 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
358 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000359 O << ']';
360}
361
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000362void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
363 raw_ostream &O) {
364 const MCOperand &MO3 = MI->getOperand(Op+2);
365 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
366
367 if (IdxMode == ARMII::IndexModePost) {
368 printAM3PostIndexOp(MI, Op, O);
369 return;
370 }
371 printAM3PreOrOffsetIndexOp(MI, Op, O);
372}
373
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000374void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000375 unsigned OpNum,
376 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000377 const MCOperand &MO1 = MI->getOperand(OpNum);
378 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000379
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000380 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000381 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
382 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000383 return;
384 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000385
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000386 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000387 O << '#'
388 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
389 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000390}
391
Jim Grosbach7ce05792011-08-03 23:50:40 +0000392void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
393 unsigned OpNum,
394 raw_ostream &O) {
395 const MCOperand &MO = MI->getOperand(OpNum);
396 unsigned Imm = MO.getImm();
397 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
398}
399
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000400void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
401 raw_ostream &O) {
402 const MCOperand &MO1 = MI->getOperand(OpNum);
403 const MCOperand &MO2 = MI->getOperand(OpNum+1);
404
Jim Grosbach16578b52011-08-05 16:11:38 +0000405 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000406}
407
Owen Anderson154c41d2011-08-04 18:24:14 +0000408void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
409 unsigned OpNum,
410 raw_ostream &O) {
411 const MCOperand &MO = MI->getOperand(OpNum);
412 unsigned Imm = MO.getImm();
413 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
414}
415
416
Jim Grosbache6913602010-11-03 01:01:43 +0000417void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000418 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000419 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
420 .getImm());
421 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000422}
423
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000424void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000425 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000426 const MCOperand &MO1 = MI->getOperand(OpNum);
427 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000428
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000429 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000430 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000431 return;
432 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000433
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000434 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000435
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000436 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
437 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000438 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000439 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000440 }
441 O << "]";
442}
443
Chris Lattner35c33bd2010-04-04 04:47:45 +0000444void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
445 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000446 const MCOperand &MO1 = MI->getOperand(OpNum);
447 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000448
Bob Wilson226036e2010-03-20 22:13:40 +0000449 O << "[" << getRegisterName(MO1.getReg());
450 if (MO2.getImm()) {
451 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000452 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000453 }
Bob Wilson226036e2010-03-20 22:13:40 +0000454 O << "]";
455}
456
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000457void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
458 raw_ostream &O) {
459 const MCOperand &MO1 = MI->getOperand(OpNum);
460 O << "[" << getRegisterName(MO1.getReg()) << "]";
461}
462
Bob Wilson226036e2010-03-20 22:13:40 +0000463void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000464 unsigned OpNum,
465 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000466 const MCOperand &MO = MI->getOperand(OpNum);
467 if (MO.getReg() == 0)
468 O << "!";
469 else
470 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000471}
472
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000473void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
474 unsigned OpNum,
475 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000476 const MCOperand &MO = MI->getOperand(OpNum);
477 uint32_t v = ~MO.getImm();
478 int32_t lsb = CountTrailingZeros_32(v);
479 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
480 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
481 O << '#' << lsb << ", #" << width;
482}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000483
Johnny Chen1adc40c2010-08-12 20:46:17 +0000484void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
485 raw_ostream &O) {
486 unsigned val = MI->getOperand(OpNum).getImm();
487 O << ARM_MB::MemBOptToString(val);
488}
489
Bob Wilson22f5dc72010-08-16 18:27:34 +0000490void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000491 raw_ostream &O) {
492 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000493 bool isASR = (ShiftOp & (1 << 5)) != 0;
494 unsigned Amt = ShiftOp & 0x1f;
495 if (isASR)
496 O << ", asr #" << (Amt == 0 ? 32 : Amt);
497 else if (Amt)
498 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000499}
500
Jim Grosbachdde038a2011-07-20 21:40:26 +0000501void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
502 raw_ostream &O) {
503 unsigned Imm = MI->getOperand(OpNum).getImm();
504 if (Imm == 0)
505 return;
506 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
507 O << ", lsl #" << Imm;
508}
509
510void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
511 raw_ostream &O) {
512 unsigned Imm = MI->getOperand(OpNum).getImm();
513 // A shift amount of 32 is encoded as 0.
514 if (Imm == 0)
515 Imm = 32;
516 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
517 O << ", asr #" << Imm;
518}
519
Chris Lattner35c33bd2010-04-04 04:47:45 +0000520void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
521 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000522 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000523 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
524 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000525 O << getRegisterName(MI->getOperand(i).getReg());
526 }
527 O << "}";
528}
Chris Lattner4d152222009-10-19 22:23:04 +0000529
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000530void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
531 raw_ostream &O) {
532 const MCOperand &Op = MI->getOperand(OpNum);
533 if (Op.getImm())
534 O << "be";
535 else
536 O << "le";
537}
538
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000539void ARMInstPrinter::printCPSIMod(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 Lopesa2b6e412011-02-14 13:09:44 +0000542 O << ARM_PROC::IModToString(Op.getImm());
543}
544
545void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
546 raw_ostream &O) {
547 const MCOperand &Op = MI->getOperand(OpNum);
548 unsigned IFlags = Op.getImm();
549 for (int i=2; i >= 0; --i)
550 if (IFlags & (1 << i))
551 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000552}
553
Chris Lattner35c33bd2010-04-04 04:47:45 +0000554void ARMInstPrinter::printMSRMaskOperand(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 Lopes584bf7b2011-02-18 19:45:59 +0000557 unsigned SpecRegRBit = Op.getImm() >> 4;
558 unsigned Mask = Op.getImm() & 0xf;
559
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000560 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
561 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
562 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
563 O << "APSR_";
564 switch (Mask) {
565 default: assert(0);
566 case 4: O << "g"; return;
567 case 8: O << "nzcvq"; return;
568 case 12: O << "nzcvqg"; return;
569 }
570 llvm_unreachable("Unexpected mask value!");
571 }
572
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000573 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000574 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000575 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000576 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000577
Johnny Chen9e088762010-03-17 17:52:21 +0000578 if (Mask) {
579 O << '_';
580 if (Mask & 8) O << 'f';
581 if (Mask & 4) O << 's';
582 if (Mask & 2) O << 'x';
583 if (Mask & 1) O << 'c';
584 }
585}
586
Chris Lattner35c33bd2010-04-04 04:47:45 +0000587void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
588 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000589 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
590 if (CC != ARMCC::AL)
591 O << ARMCondCodeToString(CC);
592}
593
Jim Grosbach15d78982010-09-14 22:27:15 +0000594void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000595 unsigned OpNum,
596 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000597 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
598 O << ARMCondCodeToString(CC);
599}
600
Chris Lattner35c33bd2010-04-04 04:47:45 +0000601void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
602 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000603 if (MI->getOperand(OpNum).getReg()) {
604 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
605 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000606 O << 's';
607 }
608}
609
Chris Lattner35c33bd2010-04-04 04:47:45 +0000610void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
611 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000612 O << MI->getOperand(OpNum).getImm();
613}
614
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000615void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
616 raw_ostream &O) {
617 O << "p" << MI->getOperand(OpNum).getImm();
618}
619
620void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
621 raw_ostream &O) {
622 O << "c" << MI->getOperand(OpNum).getImm();
623}
624
Chris Lattner35c33bd2010-04-04 04:47:45 +0000625void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
626 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000627 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000628}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000629
Chris Lattner35c33bd2010-04-04 04:47:45 +0000630void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
631 raw_ostream &O) {
Johnny Chen541ba7d2010-01-25 22:13:10 +0000632 O << "#" << MI->getOperand(OpNum).getImm() * 4;
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000633}
Johnny Chen9e088762010-03-17 17:52:21 +0000634
Chris Lattner35c33bd2010-04-04 04:47:45 +0000635void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
636 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000637 // (3 - the number of trailing zeros) is the number of then / else.
638 unsigned Mask = MI->getOperand(OpNum).getImm();
639 unsigned CondBit0 = Mask >> 4 & 1;
640 unsigned NumTZ = CountTrailingZeros_32(Mask);
641 assert(NumTZ <= 3 && "Invalid IT mask!");
642 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
643 bool T = ((Mask >> Pos) & 1) == CondBit0;
644 if (T)
645 O << 't';
646 else
647 O << 'e';
648 }
649}
650
Chris Lattner35c33bd2010-04-04 04:47:45 +0000651void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
652 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000653 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000654 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000655
656 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000657 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000658 return;
659 }
660
661 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000662 if (unsigned RegNum = MO2.getReg())
663 O << ", " << getRegisterName(RegNum);
664 O << "]";
665}
666
667void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
668 unsigned Op,
669 raw_ostream &O,
670 unsigned Scale) {
671 const MCOperand &MO1 = MI->getOperand(Op);
672 const MCOperand &MO2 = MI->getOperand(Op + 1);
673
674 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
675 printOperand(MI, Op, O);
676 return;
677 }
678
679 O << "[" << getRegisterName(MO1.getReg());
680 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000681 O << ", #" << ImmOffs * Scale;
682 O << "]";
683}
684
Bill Wendlingf4caf692010-12-14 03:36:38 +0000685void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
686 unsigned Op,
687 raw_ostream &O) {
688 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000689}
690
Bill Wendlingf4caf692010-12-14 03:36:38 +0000691void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
692 unsigned Op,
693 raw_ostream &O) {
694 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000695}
696
Bill Wendlingf4caf692010-12-14 03:36:38 +0000697void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
698 unsigned Op,
699 raw_ostream &O) {
700 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000701}
702
Chris Lattner35c33bd2010-04-04 04:47:45 +0000703void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
704 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000705 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000706}
707
Johnny Chen9e088762010-03-17 17:52:21 +0000708// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
709// register with shift forms.
710// REG 0 0 - e.g. R5
711// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000712void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
713 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000714 const MCOperand &MO1 = MI->getOperand(OpNum);
715 const MCOperand &MO2 = MI->getOperand(OpNum+1);
716
717 unsigned Reg = MO1.getReg();
718 O << getRegisterName(Reg);
719
720 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000721 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000722 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
723 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
724 if (ShOpc != ARM_AM::rrx)
725 O << " #" << ARM_AM::getSORegOffset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000726}
727
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000728void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
729 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000730 const MCOperand &MO1 = MI->getOperand(OpNum);
731 const MCOperand &MO2 = MI->getOperand(OpNum+1);
732
Jim Grosbach3e556122010-10-26 22:37:02 +0000733 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
734 printOperand(MI, OpNum, O);
735 return;
736 }
737
Johnny Chen9e088762010-03-17 17:52:21 +0000738 O << "[" << getRegisterName(MO1.getReg());
739
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000740 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000741 bool isSub = OffImm < 0;
742 // Special value for #-0. All others are normal.
743 if (OffImm == INT32_MIN)
744 OffImm = 0;
745 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000746 O << ", #-" << -OffImm;
747 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000748 O << ", #" << OffImm;
749 O << "]";
750}
751
752void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000753 unsigned OpNum,
754 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000755 const MCOperand &MO1 = MI->getOperand(OpNum);
756 const MCOperand &MO2 = MI->getOperand(OpNum+1);
757
758 O << "[" << getRegisterName(MO1.getReg());
759
760 int32_t OffImm = (int32_t)MO2.getImm();
761 // Don't print +0.
762 if (OffImm < 0)
763 O << ", #-" << -OffImm;
764 else if (OffImm > 0)
765 O << ", #" << OffImm;
766 O << "]";
767}
768
769void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000770 unsigned OpNum,
771 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000772 const MCOperand &MO1 = MI->getOperand(OpNum);
773 const MCOperand &MO2 = MI->getOperand(OpNum+1);
774
775 O << "[" << getRegisterName(MO1.getReg());
776
777 int32_t OffImm = (int32_t)MO2.getImm() / 4;
778 // Don't print +0.
779 if (OffImm < 0)
780 O << ", #-" << -OffImm * 4;
781 else if (OffImm > 0)
782 O << ", #" << OffImm * 4;
783 O << "]";
784}
785
786void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000787 unsigned OpNum,
788 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000789 const MCOperand &MO1 = MI->getOperand(OpNum);
790 int32_t OffImm = (int32_t)MO1.getImm();
791 // Don't print +0.
792 if (OffImm < 0)
793 O << "#-" << -OffImm;
794 else if (OffImm > 0)
795 O << "#" << OffImm;
796}
797
798void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000799 unsigned OpNum,
800 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000801 const MCOperand &MO1 = MI->getOperand(OpNum);
802 int32_t OffImm = (int32_t)MO1.getImm() / 4;
803 // Don't print +0.
804 if (OffImm < 0)
805 O << "#-" << -OffImm * 4;
806 else if (OffImm > 0)
807 O << "#" << OffImm * 4;
808}
809
810void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000811 unsigned OpNum,
812 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000813 const MCOperand &MO1 = MI->getOperand(OpNum);
814 const MCOperand &MO2 = MI->getOperand(OpNum+1);
815 const MCOperand &MO3 = MI->getOperand(OpNum+2);
816
817 O << "[" << getRegisterName(MO1.getReg());
818
819 assert(MO2.getReg() && "Invalid so_reg load / store address!");
820 O << ", " << getRegisterName(MO2.getReg());
821
822 unsigned ShAmt = MO3.getImm();
823 if (ShAmt) {
824 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
825 O << ", lsl #" << ShAmt;
826 }
827 O << "]";
828}
829
Chris Lattner35c33bd2010-04-04 04:47:45 +0000830void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
831 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000832 const MCOperand &MO = MI->getOperand(OpNum);
833 O << '#';
834 if (MO.isFPImm()) {
835 O << (float)MO.getFPImm();
836 } else {
837 union {
838 uint32_t I;
839 float F;
840 } FPUnion;
841
842 FPUnion.I = MO.getImm();
843 O << FPUnion.F;
844 }
Johnny Chen9e088762010-03-17 17:52:21 +0000845}
846
Chris Lattner35c33bd2010-04-04 04:47:45 +0000847void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
848 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000849 const MCOperand &MO = MI->getOperand(OpNum);
850 O << '#';
851 if (MO.isFPImm()) {
852 O << MO.getFPImm();
853 } else {
854 // We expect the binary encoding of a floating point number here.
855 union {
856 uint64_t I;
857 double D;
858 } FPUnion;
859
860 FPUnion.I = MO.getImm();
861 O << FPUnion.D;
862 }
Johnny Chen9e088762010-03-17 17:52:21 +0000863}
864
Bob Wilson1a913ed2010-06-11 21:34:50 +0000865void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
866 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000867 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
868 unsigned EltBits;
869 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000870 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000871}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000872
Jim Grosbachf4943352011-07-25 23:09:14 +0000873void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
874 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000875 unsigned Imm = MI->getOperand(OpNum).getImm();
876 O << "#" << Imm + 1;
877}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000878
879void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
880 raw_ostream &O) {
881 unsigned Imm = MI->getOperand(OpNum).getImm();
882 if (Imm == 0)
883 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000884 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000885 switch (Imm) {
886 default: assert (0 && "illegal ror immediate!");
887 case 1: O << "8\n"; break;
888 case 2: O << "16\n"; break;
889 case 3: O << "24\n"; break;
890 }
891}