blob: b0b1dbbefa90df02f8a17ea5e98f149fc5987a4e [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"
21#include "llvm/Support/raw_ostream.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000022using namespace llvm;
23
Chris Lattner6274ec42010-10-28 21:37:33 +000024#define GET_INSTRUCTION_NAME
Chris Lattnerfd603822009-10-19 19:56:26 +000025#include "ARMGenAsmWriter.inc"
Chris Lattnerfd603822009-10-19 19:56:26 +000026
Owen Anderson3dac0be2011-08-11 18:41:59 +000027/// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing.
28///
Jim Grosbach01208d52011-10-12 16:36:01 +000029/// getSORegOffset returns an integer from 0-31, representing '32' as 0.
Owen Anderson3dac0be2011-08-11 18:41:59 +000030static unsigned translateShiftImm(unsigned imm) {
31 if (imm == 0)
32 return 32;
33 return imm;
34}
35
James Molloyb9505852011-09-07 17:24:38 +000036
37ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
38 const MCSubtargetInfo &STI) :
39 MCInstPrinter(MAI) {
40 // Initialize the set of available features.
41 setAvailableFeatures(STI.getFeatureBits());
42}
43
Chris Lattner6274ec42010-10-28 21:37:33 +000044StringRef ARMInstPrinter::getOpcodeName(unsigned Opcode) const {
45 return getInstructionName(Opcode);
46}
47
Rafael Espindolacde4ce42011-06-02 02:34:55 +000048void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
49 OS << getRegisterName(RegNo);
Anton Korobeynikov57caad72011-03-05 18:43:32 +000050}
Chris Lattner6274ec42010-10-28 21:37:33 +000051
Owen Anderson98c5dda2011-09-15 23:38:46 +000052void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
53 StringRef Annot) {
Bill Wendling04863d02010-11-13 10:40:19 +000054 unsigned Opcode = MI->getOpcode();
55
Johnny Chen9e088762010-03-17 17:52:21 +000056 // Check for MOVs and print canonical forms, instead.
Owen Anderson152d4a42011-07-21 23:38:37 +000057 if (Opcode == ARM::MOVsr) {
Jim Grosbache6be85e2010-09-17 22:36:38 +000058 // FIXME: Thumb variants?
Johnny Chen9e088762010-03-17 17:52:21 +000059 const MCOperand &Dst = MI->getOperand(0);
60 const MCOperand &MO1 = MI->getOperand(1);
61 const MCOperand &MO2 = MI->getOperand(2);
62 const MCOperand &MO3 = MI->getOperand(3);
63
64 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner35c33bd2010-04-04 04:47:45 +000065 printSBitModifierOperand(MI, 6, O);
66 printPredicateOperand(MI, 4, O);
Johnny Chen9e088762010-03-17 17:52:21 +000067
68 O << '\t' << getRegisterName(Dst.getReg())
69 << ", " << getRegisterName(MO1.getReg());
70
Owen Anderson152d4a42011-07-21 23:38:37 +000071 O << ", " << getRegisterName(MO2.getReg());
72 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Owen Anderson519020a2011-09-21 17:58:45 +000073 printAnnotation(O, Annot);
Johnny Chen9e088762010-03-17 17:52:21 +000074 return;
75 }
76
Owen Anderson152d4a42011-07-21 23:38:37 +000077 if (Opcode == ARM::MOVsi) {
78 // FIXME: Thumb variants?
79 const MCOperand &Dst = MI->getOperand(0);
80 const MCOperand &MO1 = MI->getOperand(1);
81 const MCOperand &MO2 = MI->getOperand(2);
82
83 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
84 printSBitModifierOperand(MI, 5, O);
85 printPredicateOperand(MI, 3, O);
86
87 O << '\t' << getRegisterName(Dst.getReg())
88 << ", " << getRegisterName(MO1.getReg());
89
Owen Andersonede042d2011-09-15 18:36:29 +000090 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
Owen Anderson519020a2011-09-21 17:58:45 +000091 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000092 return;
Owen Andersonede042d2011-09-15 18:36:29 +000093 }
Owen Anderson152d4a42011-07-21 23:38:37 +000094
Owen Anderson3dac0be2011-08-11 18:41:59 +000095 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson519020a2011-09-21 17:58:45 +000096 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000097 return;
98 }
99
100
Johnny Chen9e088762010-03-17 17:52:21 +0000101 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000102 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Owen Anderson81550dc2011-11-02 18:03:14 +0000103 MI->getOperand(0).getReg() == ARM::SP &&
104 MI->getNumOperands() > 5) {
105 // Should only print PUSH if there are at least two registers in the list.
Bill Wendling73fe34a2010-11-16 01:16:36 +0000106 O << '\t' << "push";
107 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000108 if (Opcode == ARM::t2STMDB_UPD)
109 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000110 O << '\t';
111 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000112 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000113 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000114 }
Jim Grosbachf6713912011-08-11 18:07:11 +0000115 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
116 MI->getOperand(3).getImm() == -4) {
117 O << '\t' << "push";
118 printPredicateOperand(MI, 4, O);
119 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000120 printAnnotation(O, Annot);
Jim Grosbachf6713912011-08-11 18:07:11 +0000121 return;
122 }
Johnny Chen9e088762010-03-17 17:52:21 +0000123
124 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000125 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Owen Anderson81550dc2011-11-02 18:03:14 +0000126 MI->getOperand(0).getReg() == ARM::SP &&
127 MI->getNumOperands() > 5) {
128 // Should only print POP if there are at least two registers in the list.
Bill Wendling73fe34a2010-11-16 01:16:36 +0000129 O << '\t' << "pop";
130 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000131 if (Opcode == ARM::t2LDMIA_UPD)
132 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000133 O << '\t';
134 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000135 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000136 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000137 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000138 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
139 MI->getOperand(4).getImm() == 4) {
140 O << '\t' << "pop";
141 printPredicateOperand(MI, 5, O);
142 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000143 printAnnotation(O, Annot);
Jim Grosbachf8fce712011-08-11 17:35:48 +0000144 return;
145 }
146
Johnny Chen9e088762010-03-17 17:52:21 +0000147
148 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000149 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000150 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000151 O << '\t' << "vpush";
152 printPredicateOperand(MI, 2, O);
153 O << '\t';
154 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000155 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000156 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000157 }
158
159 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000160 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000161 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000162 O << '\t' << "vpop";
163 printPredicateOperand(MI, 2, O);
164 O << '\t';
165 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000166 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000167 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000168 }
169
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000170 if (Opcode == ARM::tLDMIA) {
Owen Anderson565a0362011-07-18 23:25:34 +0000171 bool Writeback = true;
172 unsigned BaseReg = MI->getOperand(0).getReg();
173 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
174 if (MI->getOperand(i).getReg() == BaseReg)
175 Writeback = false;
176 }
177
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000178 O << "\tldm";
Owen Anderson565a0362011-07-18 23:25:34 +0000179
180 printPredicateOperand(MI, 1, O);
181 O << '\t' << getRegisterName(BaseReg);
182 if (Writeback) O << "!";
183 O << ", ";
184 printRegisterList(MI, 3, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000185 printAnnotation(O, Annot);
Owen Anderson565a0362011-07-18 23:25:34 +0000186 return;
187 }
188
Jim Grosbach0780b632011-08-19 23:24:36 +0000189 // Thumb1 NOP
190 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
191 MI->getOperand(1).getReg() == ARM::R8) {
192 O << "\tnop";
Jim Grosbachdf9ce6b2011-08-24 20:06:14 +0000193 printPredicateOperand(MI, 2, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000194 printAnnotation(O, Annot);
Jim Grosbach0780b632011-08-19 23:24:36 +0000195 return;
196 }
197
Chris Lattner35c33bd2010-04-04 04:47:45 +0000198 printInstruction(MI, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000199 printAnnotation(O, Annot);
Bill Wendling04863d02010-11-13 10:40:19 +0000200}
Chris Lattnerfd603822009-10-19 19:56:26 +0000201
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000202void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000203 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000204 const MCOperand &Op = MI->getOperand(OpNo);
205 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000206 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000207 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000208 } else if (Op.isImm()) {
209 O << '#' << Op.getImm();
210 } else {
211 assert(Op.isExpr() && "unknown operand kind in printOperand");
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000212 // If a symbolic branch target was added as a constant expression then print
213 // that address in hex.
214 const MCConstantExpr *BranchTarget = dyn_cast<MCConstantExpr>(Op.getExpr());
215 int64_t Address;
216 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
217 O << "0x";
218 O.write_hex(Address);
219 }
220 else {
221 // Otherwise, just print the expression.
222 O << *Op.getExpr();
223 }
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000224 }
225}
Chris Lattner61d35c22009-10-19 21:21:39 +0000226
Owen Andersone1368722011-09-21 23:44:46 +0000227void ARMInstPrinter::printT2LdrLabelOperand(const MCInst *MI, unsigned OpNum,
228 raw_ostream &O) {
229 const MCOperand &MO1 = MI->getOperand(OpNum);
230 if (MO1.isExpr())
231 O << *MO1.getExpr();
232 else if (MO1.isImm())
233 O << "[pc, #" << MO1.getImm() << "]";
234 else
235 llvm_unreachable("Unknown LDR label operand?");
236}
237
Chris Lattner017d9472009-10-20 00:40:56 +0000238// so_reg is a 4-operand unit corresponding to register forms of the A5.1
239// "Addressing Mode 1 - Data-processing operands" forms. This includes:
240// REG 0 0 - e.g. R5
241// REG REG 0,SH_OPC - e.g. R5, ROR R3
242// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000243void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000244 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000245 const MCOperand &MO1 = MI->getOperand(OpNum);
246 const MCOperand &MO2 = MI->getOperand(OpNum+1);
247 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000248
Chris Lattner017d9472009-10-20 00:40:56 +0000249 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000250
Chris Lattner017d9472009-10-20 00:40:56 +0000251 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000252 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
253 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000254 if (ShOpc == ARM_AM::rrx)
255 return;
Jim Grosbach293a5f62011-10-21 16:56:40 +0000256
Owen Anderson152d4a42011-07-21 23:38:37 +0000257 O << ' ' << getRegisterName(MO2.getReg());
258 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000259}
Chris Lattner084f87d2009-10-19 21:57:05 +0000260
Owen Anderson152d4a42011-07-21 23:38:37 +0000261void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
262 raw_ostream &O) {
263 const MCOperand &MO1 = MI->getOperand(OpNum);
264 const MCOperand &MO2 = MI->getOperand(OpNum+1);
265
266 O << getRegisterName(MO1.getReg());
267
268 // Print the shift opc.
269 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
270 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
271 if (ShOpc == ARM_AM::rrx)
272 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000273 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000274}
275
276
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000277//===--------------------------------------------------------------------===//
278// Addressing Mode #2
279//===--------------------------------------------------------------------===//
280
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000281void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
282 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000283 const MCOperand &MO1 = MI->getOperand(Op);
284 const MCOperand &MO2 = MI->getOperand(Op+1);
285 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000286
Chris Lattner084f87d2009-10-19 21:57:05 +0000287 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000288
Chris Lattner084f87d2009-10-19 21:57:05 +0000289 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000290 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000291 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000292 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
293 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000294 O << "]";
295 return;
296 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000297
Chris Lattner084f87d2009-10-19 21:57:05 +0000298 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000299 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
300 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000301
Chris Lattner084f87d2009-10-19 21:57:05 +0000302 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
303 O << ", "
304 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
305 << " #" << ShImm;
306 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000307}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000308
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000309void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
310 raw_ostream &O) {
311 const MCOperand &MO1 = MI->getOperand(Op);
312 const MCOperand &MO2 = MI->getOperand(Op+1);
313 const MCOperand &MO3 = MI->getOperand(Op+2);
314
315 O << "[" << getRegisterName(MO1.getReg()) << "], ";
316
317 if (!MO2.getReg()) {
318 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
319 O << '#'
320 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
321 << ImmOffs;
322 return;
323 }
324
325 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
326 << getRegisterName(MO2.getReg());
327
328 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
329 O << ", "
330 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
331 << " #" << ShImm;
332}
333
Jim Grosbach7f739be2011-09-19 22:21:13 +0000334void ARMInstPrinter::printAddrModeTBB(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 O << "[" << getRegisterName(MO1.getReg()) << ", "
339 << getRegisterName(MO2.getReg()) << "]";
340}
341
342void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
343 raw_ostream &O) {
344 const MCOperand &MO1 = MI->getOperand(Op);
345 const MCOperand &MO2 = MI->getOperand(Op+1);
346 O << "[" << getRegisterName(MO1.getReg()) << ", "
347 << getRegisterName(MO2.getReg()) << ", lsl #1]";
348}
349
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000350void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
351 raw_ostream &O) {
352 const MCOperand &MO1 = MI->getOperand(Op);
353
354 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
355 printOperand(MI, Op, O);
356 return;
357 }
358
359 const MCOperand &MO3 = MI->getOperand(Op+2);
360 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
361
362 if (IdxMode == ARMII::IndexModePost) {
363 printAM2PostIndexOp(MI, Op, O);
364 return;
365 }
366 printAM2PreOrOffsetIndexOp(MI, Op, O);
367}
368
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000369void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000370 unsigned OpNum,
371 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000372 const MCOperand &MO1 = MI->getOperand(OpNum);
373 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000374
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000375 if (!MO1.getReg()) {
376 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000377 O << '#'
378 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
379 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000380 return;
381 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000382
Johnny Chen9e088762010-03-17 17:52:21 +0000383 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
384 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000385
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000386 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
387 O << ", "
388 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
389 << " #" << ShImm;
390}
391
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000392//===--------------------------------------------------------------------===//
393// Addressing Mode #3
394//===--------------------------------------------------------------------===//
395
396void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
397 raw_ostream &O) {
398 const MCOperand &MO1 = MI->getOperand(Op);
399 const MCOperand &MO2 = MI->getOperand(Op+1);
400 const MCOperand &MO3 = MI->getOperand(Op+2);
401
402 O << "[" << getRegisterName(MO1.getReg()) << "], ";
403
404 if (MO2.getReg()) {
405 O << (char)ARM_AM::getAM3Op(MO3.getImm())
406 << getRegisterName(MO2.getReg());
407 return;
408 }
409
410 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
411 O << '#'
412 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
413 << ImmOffs;
414}
415
416void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
417 raw_ostream &O) {
418 const MCOperand &MO1 = MI->getOperand(Op);
419 const MCOperand &MO2 = MI->getOperand(Op+1);
420 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000421
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000422 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000423
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000424 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000425 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000426 << getRegisterName(MO2.getReg()) << ']';
427 return;
428 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000429
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000430 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
431 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000432 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
433 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000434 O << ']';
435}
436
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000437void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
438 raw_ostream &O) {
Jim Grosbach2f196742011-12-19 23:06:24 +0000439 const MCOperand &MO1 = MI->getOperand(Op);
440 if (!MO1.isReg()) { // For label symbolic references.
441 printOperand(MI, Op, O);
442 return;
443 }
444
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000445 const MCOperand &MO3 = MI->getOperand(Op+2);
446 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
447
448 if (IdxMode == ARMII::IndexModePost) {
449 printAM3PostIndexOp(MI, Op, O);
450 return;
451 }
452 printAM3PreOrOffsetIndexOp(MI, Op, O);
453}
454
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000455void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000456 unsigned OpNum,
457 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000458 const MCOperand &MO1 = MI->getOperand(OpNum);
459 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000460
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000461 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000462 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
463 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000464 return;
465 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000466
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000467 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000468 O << '#'
469 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
470 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000471}
472
Jim Grosbach7ce05792011-08-03 23:50:40 +0000473void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
474 unsigned OpNum,
475 raw_ostream &O) {
476 const MCOperand &MO = MI->getOperand(OpNum);
477 unsigned Imm = MO.getImm();
478 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
479}
480
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000481void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
482 raw_ostream &O) {
483 const MCOperand &MO1 = MI->getOperand(OpNum);
484 const MCOperand &MO2 = MI->getOperand(OpNum+1);
485
Jim Grosbach16578b52011-08-05 16:11:38 +0000486 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000487}
488
Owen Anderson154c41d2011-08-04 18:24:14 +0000489void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
490 unsigned OpNum,
491 raw_ostream &O) {
492 const MCOperand &MO = MI->getOperand(OpNum);
493 unsigned Imm = MO.getImm();
494 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
495}
496
497
Jim Grosbache6913602010-11-03 01:01:43 +0000498void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000499 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000500 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
501 .getImm());
502 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000503}
504
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000505void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000506 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000507 const MCOperand &MO1 = MI->getOperand(OpNum);
508 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000509
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000510 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000511 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000512 return;
513 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000514
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000515 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000516
Owen Anderson0da10cf2011-08-29 19:36:44 +0000517 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
518 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
519 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000520 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000521 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000522 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000523 }
524 O << "]";
525}
526
Chris Lattner35c33bd2010-04-04 04:47:45 +0000527void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
528 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000529 const MCOperand &MO1 = MI->getOperand(OpNum);
530 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000531
Bob Wilson226036e2010-03-20 22:13:40 +0000532 O << "[" << getRegisterName(MO1.getReg());
533 if (MO2.getImm()) {
534 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000535 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000536 }
Bob Wilson226036e2010-03-20 22:13:40 +0000537 O << "]";
538}
539
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000540void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
541 raw_ostream &O) {
542 const MCOperand &MO1 = MI->getOperand(OpNum);
543 O << "[" << getRegisterName(MO1.getReg()) << "]";
544}
545
Bob Wilson226036e2010-03-20 22:13:40 +0000546void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000547 unsigned OpNum,
548 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000549 const MCOperand &MO = MI->getOperand(OpNum);
550 if (MO.getReg() == 0)
551 O << "!";
552 else
553 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000554}
555
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000556void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
557 unsigned OpNum,
558 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000559 const MCOperand &MO = MI->getOperand(OpNum);
560 uint32_t v = ~MO.getImm();
561 int32_t lsb = CountTrailingZeros_32(v);
562 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
563 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
564 O << '#' << lsb << ", #" << width;
565}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000566
Johnny Chen1adc40c2010-08-12 20:46:17 +0000567void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
568 raw_ostream &O) {
569 unsigned val = MI->getOperand(OpNum).getImm();
570 O << ARM_MB::MemBOptToString(val);
571}
572
Bob Wilson22f5dc72010-08-16 18:27:34 +0000573void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000574 raw_ostream &O) {
575 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000576 bool isASR = (ShiftOp & (1 << 5)) != 0;
577 unsigned Amt = ShiftOp & 0x1f;
578 if (isASR)
579 O << ", asr #" << (Amt == 0 ? 32 : Amt);
580 else if (Amt)
581 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000582}
583
Jim Grosbachdde038a2011-07-20 21:40:26 +0000584void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
585 raw_ostream &O) {
586 unsigned Imm = MI->getOperand(OpNum).getImm();
587 if (Imm == 0)
588 return;
589 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
590 O << ", lsl #" << Imm;
591}
592
593void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
594 raw_ostream &O) {
595 unsigned Imm = MI->getOperand(OpNum).getImm();
596 // A shift amount of 32 is encoded as 0.
597 if (Imm == 0)
598 Imm = 32;
599 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
600 O << ", asr #" << Imm;
601}
602
Chris Lattner35c33bd2010-04-04 04:47:45 +0000603void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
604 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000605 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000606 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
607 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000608 O << getRegisterName(MI->getOperand(i).getReg());
609 }
610 O << "}";
611}
Chris Lattner4d152222009-10-19 22:23:04 +0000612
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000613void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
614 raw_ostream &O) {
615 const MCOperand &Op = MI->getOperand(OpNum);
616 if (Op.getImm())
617 O << "be";
618 else
619 O << "le";
620}
621
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000622void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
623 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000624 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000625 O << ARM_PROC::IModToString(Op.getImm());
626}
627
628void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
629 raw_ostream &O) {
630 const MCOperand &Op = MI->getOperand(OpNum);
631 unsigned IFlags = Op.getImm();
632 for (int i=2; i >= 0; --i)
633 if (IFlags & (1 << i))
634 O << ARM_PROC::IFlagsToString(1 << i);
Owen Anderson2dbb46a2011-10-05 17:16:40 +0000635
636 if (IFlags == 0)
637 O << "none";
Johnny Chen9e088762010-03-17 17:52:21 +0000638}
639
Chris Lattner35c33bd2010-04-04 04:47:45 +0000640void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
641 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000642 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000643 unsigned SpecRegRBit = Op.getImm() >> 4;
644 unsigned Mask = Op.getImm() & 0xf;
645
James Molloyacad68d2011-09-28 14:21:38 +0000646 if (getAvailableFeatures() & ARM::FeatureMClass) {
647 switch (Op.getImm()) {
Craig Topperbc219812012-02-07 02:50:20 +0000648 default: llvm_unreachable("Unexpected mask value!");
James Molloyacad68d2011-09-28 14:21:38 +0000649 case 0: O << "apsr"; return;
650 case 1: O << "iapsr"; return;
651 case 2: O << "eapsr"; return;
652 case 3: O << "xpsr"; return;
653 case 5: O << "ipsr"; return;
654 case 6: O << "epsr"; return;
655 case 7: O << "iepsr"; return;
656 case 8: O << "msp"; return;
657 case 9: O << "psp"; return;
658 case 16: O << "primask"; return;
659 case 17: O << "basepri"; return;
660 case 18: O << "basepri_max"; return;
661 case 19: O << "faultmask"; return;
662 case 20: O << "control"; return;
663 }
664 }
665
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000666 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
667 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
668 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
669 O << "APSR_";
670 switch (Mask) {
Craig Topperbc219812012-02-07 02:50:20 +0000671 default: llvm_unreachable("Unexpected mask value!");
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000672 case 4: O << "g"; return;
673 case 8: O << "nzcvq"; return;
674 case 12: O << "nzcvqg"; return;
675 }
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000676 }
677
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000678 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000679 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000680 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000681 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000682
Johnny Chen9e088762010-03-17 17:52:21 +0000683 if (Mask) {
684 O << '_';
685 if (Mask & 8) O << 'f';
686 if (Mask & 4) O << 's';
687 if (Mask & 2) O << 'x';
688 if (Mask & 1) O << 'c';
689 }
690}
691
Chris Lattner35c33bd2010-04-04 04:47:45 +0000692void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
693 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000694 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
Kevin Enderbyb0578512012-03-01 22:13:02 +0000695 // Handle the undefined 15 CC value here for printing so we don't abort().
696 if ((unsigned)CC == 15)
697 O << "<und>";
698 else if (CC != ARMCC::AL)
Chris Lattner413ae252009-10-20 00:42:49 +0000699 O << ARMCondCodeToString(CC);
700}
701
Jim Grosbach15d78982010-09-14 22:27:15 +0000702void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000703 unsigned OpNum,
704 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000705 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
706 O << ARMCondCodeToString(CC);
707}
708
Chris Lattner35c33bd2010-04-04 04:47:45 +0000709void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
710 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000711 if (MI->getOperand(OpNum).getReg()) {
712 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
713 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000714 O << 's';
715 }
716}
717
Chris Lattner35c33bd2010-04-04 04:47:45 +0000718void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
719 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000720 O << MI->getOperand(OpNum).getImm();
721}
722
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000723void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbachbc9c8022011-10-12 16:34:37 +0000724 raw_ostream &O) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000725 O << "p" << MI->getOperand(OpNum).getImm();
726}
727
728void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbachbc9c8022011-10-12 16:34:37 +0000729 raw_ostream &O) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000730 O << "c" << MI->getOperand(OpNum).getImm();
731}
732
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000733void ARMInstPrinter::printCoprocOptionImm(const MCInst *MI, unsigned OpNum,
734 raw_ostream &O) {
735 O << "{" << MI->getOperand(OpNum).getImm() << "}";
736}
737
Chris Lattner35c33bd2010-04-04 04:47:45 +0000738void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
739 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000740 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000741}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000742
Chris Lattner35c33bd2010-04-04 04:47:45 +0000743void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
744 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000745 O << "#" << MI->getOperand(OpNum).getImm() * 4;
746}
747
748void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
749 raw_ostream &O) {
750 unsigned Imm = MI->getOperand(OpNum).getImm();
751 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000752}
Johnny Chen9e088762010-03-17 17:52:21 +0000753
Chris Lattner35c33bd2010-04-04 04:47:45 +0000754void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
755 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000756 // (3 - the number of trailing zeros) is the number of then / else.
757 unsigned Mask = MI->getOperand(OpNum).getImm();
758 unsigned CondBit0 = Mask >> 4 & 1;
759 unsigned NumTZ = CountTrailingZeros_32(Mask);
760 assert(NumTZ <= 3 && "Invalid IT mask!");
761 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
762 bool T = ((Mask >> Pos) & 1) == CondBit0;
763 if (T)
764 O << 't';
765 else
766 O << 'e';
767 }
768}
769
Chris Lattner35c33bd2010-04-04 04:47:45 +0000770void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
771 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000772 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000773 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000774
775 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000776 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000777 return;
778 }
779
780 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000781 if (unsigned RegNum = MO2.getReg())
782 O << ", " << getRegisterName(RegNum);
783 O << "]";
784}
785
786void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
787 unsigned Op,
788 raw_ostream &O,
789 unsigned Scale) {
790 const MCOperand &MO1 = MI->getOperand(Op);
791 const MCOperand &MO2 = MI->getOperand(Op + 1);
792
793 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
794 printOperand(MI, Op, O);
795 return;
796 }
797
798 O << "[" << getRegisterName(MO1.getReg());
799 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000800 O << ", #" << ImmOffs * Scale;
801 O << "]";
802}
803
Bill Wendlingf4caf692010-12-14 03:36:38 +0000804void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
805 unsigned Op,
806 raw_ostream &O) {
807 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000808}
809
Bill Wendlingf4caf692010-12-14 03:36:38 +0000810void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
811 unsigned Op,
812 raw_ostream &O) {
813 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000814}
815
Bill Wendlingf4caf692010-12-14 03:36:38 +0000816void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
817 unsigned Op,
818 raw_ostream &O) {
819 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000820}
821
Chris Lattner35c33bd2010-04-04 04:47:45 +0000822void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
823 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000824 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000825}
826
Johnny Chen9e088762010-03-17 17:52:21 +0000827// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
828// register with shift forms.
829// REG 0 0 - e.g. R5
830// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000831void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
832 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000833 const MCOperand &MO1 = MI->getOperand(OpNum);
834 const MCOperand &MO2 = MI->getOperand(OpNum+1);
835
836 unsigned Reg = MO1.getReg();
837 O << getRegisterName(Reg);
838
839 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000840 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000841 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
842 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
843 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000844 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000845}
846
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000847void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
848 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000849 const MCOperand &MO1 = MI->getOperand(OpNum);
850 const MCOperand &MO2 = MI->getOperand(OpNum+1);
851
Jim Grosbach3e556122010-10-26 22:37:02 +0000852 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
853 printOperand(MI, OpNum, O);
854 return;
855 }
856
Johnny Chen9e088762010-03-17 17:52:21 +0000857 O << "[" << getRegisterName(MO1.getReg());
858
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000859 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000860 bool isSub = OffImm < 0;
861 // Special value for #-0. All others are normal.
862 if (OffImm == INT32_MIN)
863 OffImm = 0;
864 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000865 O << ", #-" << -OffImm;
866 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000867 O << ", #" << OffImm;
868 O << "]";
869}
870
871void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000872 unsigned OpNum,
873 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000874 const MCOperand &MO1 = MI->getOperand(OpNum);
875 const MCOperand &MO2 = MI->getOperand(OpNum+1);
876
877 O << "[" << getRegisterName(MO1.getReg());
878
879 int32_t OffImm = (int32_t)MO2.getImm();
880 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000881 if (OffImm == INT32_MIN)
882 O << ", #-0";
883 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000884 O << ", #-" << -OffImm;
885 else if (OffImm > 0)
886 O << ", #" << OffImm;
887 O << "]";
888}
889
890void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000891 unsigned OpNum,
892 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000893 const MCOperand &MO1 = MI->getOperand(OpNum);
894 const MCOperand &MO2 = MI->getOperand(OpNum+1);
895
Jim Grosbach2f196742011-12-19 23:06:24 +0000896 if (!MO1.isReg()) { // For label symbolic references.
897 printOperand(MI, OpNum, O);
898 return;
899 }
900
Johnny Chen9e088762010-03-17 17:52:21 +0000901 O << "[" << getRegisterName(MO1.getReg());
902
903 int32_t OffImm = (int32_t)MO2.getImm() / 4;
904 // Don't print +0.
905 if (OffImm < 0)
906 O << ", #-" << -OffImm * 4;
907 else if (OffImm > 0)
908 O << ", #" << OffImm * 4;
909 O << "]";
910}
911
Jim Grosbachb6aed502011-09-09 18:37:27 +0000912void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
913 unsigned OpNum,
914 raw_ostream &O) {
915 const MCOperand &MO1 = MI->getOperand(OpNum);
916 const MCOperand &MO2 = MI->getOperand(OpNum+1);
917
918 O << "[" << getRegisterName(MO1.getReg());
919 if (MO2.getImm())
920 O << ", #" << MO2.getImm() * 4;
921 O << "]";
922}
923
Johnny Chen9e088762010-03-17 17:52:21 +0000924void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000925 unsigned OpNum,
926 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000927 const MCOperand &MO1 = MI->getOperand(OpNum);
928 int32_t OffImm = (int32_t)MO1.getImm();
929 // Don't print +0.
930 if (OffImm < 0)
Owen Anderson0781c1f2011-09-23 21:26:40 +0000931 O << ", #-" << -OffImm;
932 else
933 O << ", #" << OffImm;
Johnny Chen9e088762010-03-17 17:52:21 +0000934}
935
936void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000937 unsigned OpNum,
938 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000939 const MCOperand &MO1 = MI->getOperand(OpNum);
940 int32_t OffImm = (int32_t)MO1.getImm() / 4;
941 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000942 if (OffImm != 0) {
943 O << ", ";
944 if (OffImm < 0)
945 O << "#-" << -OffImm * 4;
946 else if (OffImm > 0)
947 O << "#" << OffImm * 4;
948 }
Johnny Chen9e088762010-03-17 17:52:21 +0000949}
950
951void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000952 unsigned OpNum,
953 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000954 const MCOperand &MO1 = MI->getOperand(OpNum);
955 const MCOperand &MO2 = MI->getOperand(OpNum+1);
956 const MCOperand &MO3 = MI->getOperand(OpNum+2);
957
958 O << "[" << getRegisterName(MO1.getReg());
959
960 assert(MO2.getReg() && "Invalid so_reg load / store address!");
961 O << ", " << getRegisterName(MO2.getReg());
962
963 unsigned ShAmt = MO3.getImm();
964 if (ShAmt) {
965 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
966 O << ", lsl #" << ShAmt;
967 }
968 O << "]";
969}
970
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000971void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
972 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000973 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000974 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000975}
976
Bob Wilson1a913ed2010-06-11 21:34:50 +0000977void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
978 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000979 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
980 unsigned EltBits;
981 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Benjamin Kramer70be28a2011-11-07 21:00:59 +0000982 O << "#0x";
983 O.write_hex(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000984}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000985
Jim Grosbachf4943352011-07-25 23:09:14 +0000986void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
987 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000988 unsigned Imm = MI->getOperand(OpNum).getImm();
989 O << "#" << Imm + 1;
990}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000991
992void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
993 raw_ostream &O) {
994 unsigned Imm = MI->getOperand(OpNum).getImm();
995 if (Imm == 0)
996 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000997 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000998 switch (Imm) {
999 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +00001000 case 1: O << "8"; break;
1001 case 2: O << "16"; break;
1002 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +00001003 }
1004}
Jim Grosbach460a9052011-10-07 23:56:00 +00001005
Jim Grosbach4050bc42011-12-22 22:19:05 +00001006void ARMInstPrinter::printFBits16(const MCInst *MI, unsigned OpNum,
1007 raw_ostream &O) {
1008 O << "#" << 16 - MI->getOperand(OpNum).getImm();
1009}
1010
1011void ARMInstPrinter::printFBits32(const MCInst *MI, unsigned OpNum,
1012 raw_ostream &O) {
1013 O << "#" << 32 - MI->getOperand(OpNum).getImm();
1014}
1015
Jim Grosbach460a9052011-10-07 23:56:00 +00001016void ARMInstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
1017 raw_ostream &O) {
1018 O << "[" << MI->getOperand(OpNum).getImm() << "]";
1019}
Jim Grosbach862019c2011-10-18 23:02:30 +00001020
1021void ARMInstPrinter::printVectorListOne(const MCInst *MI, unsigned OpNum,
1022 raw_ostream &O) {
1023 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "}";
1024}
Jim Grosbach280dfad2011-10-21 18:54:25 +00001025
1026void ARMInstPrinter::printVectorListTwo(const MCInst *MI, unsigned OpNum,
1027 raw_ostream &O) {
1028 // Normally, it's not safe to use register enum values directly with
1029 // addition to get the next register, but for VFP registers, the
1030 // sort order is guaranteed because they're all of the form D<n>.
1031 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1032 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "}";
1033}
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001034
1035void ARMInstPrinter::printVectorListThree(const MCInst *MI, unsigned OpNum,
1036 raw_ostream &O) {
1037 // Normally, it's not safe to use register enum values directly with
1038 // addition to get the next register, but for VFP registers, the
1039 // sort order is guaranteed because they're all of the form D<n>.
1040 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1041 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1042 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1043}
Jim Grosbachb6310312011-10-21 20:35:01 +00001044
1045void ARMInstPrinter::printVectorListFour(const MCInst *MI, unsigned OpNum,
1046 raw_ostream &O) {
1047 // Normally, it's not safe to use register enum values directly with
1048 // addition to get the next register, but for VFP registers, the
1049 // sort order is guaranteed because they're all of the form D<n>.
1050 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1051 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1052 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1053 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "}";
1054}
Jim Grosbach98b05a52011-11-30 01:09:44 +00001055
1056void ARMInstPrinter::printVectorListOneAllLanes(const MCInst *MI,
1057 unsigned OpNum,
1058 raw_ostream &O) {
1059 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[]}";
1060}
1061
Jim Grosbach13af2222011-11-30 18:21:25 +00001062void ARMInstPrinter::printVectorListTwoAllLanes(const MCInst *MI,
1063 unsigned OpNum,
1064 raw_ostream &O) {
1065 // Normally, it's not safe to use register enum values directly with
1066 // addition to get the next register, but for VFP registers, the
1067 // sort order is guaranteed because they're all of the form D<n>.
1068 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1069 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[]}";
1070}
Jim Grosbache90ac9b2011-12-14 19:35:22 +00001071
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001072void ARMInstPrinter::printVectorListThreeAllLanes(const MCInst *MI,
1073 unsigned OpNum,
1074 raw_ostream &O) {
1075 // Normally, it's not safe to use register enum values directly with
1076 // addition to get the next register, but for VFP registers, the
1077 // sort order is guaranteed because they're all of the form D<n>.
1078 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1079 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1080 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[]}";
1081}
1082
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001083void ARMInstPrinter::printVectorListFourAllLanes(const MCInst *MI,
1084 unsigned OpNum,
1085 raw_ostream &O) {
1086 // Normally, it's not safe to use register enum values directly with
1087 // addition to get the next register, but for VFP registers, the
1088 // sort order is guaranteed because they're all of the form D<n>.
1089 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1090 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1091 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1092 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "[]}";
1093}
1094
Jim Grosbache90ac9b2011-12-14 19:35:22 +00001095void ARMInstPrinter::printVectorListTwoSpaced(const MCInst *MI, unsigned OpNum,
1096 raw_ostream &O) {
1097 // Normally, it's not safe to use register enum values directly with
1098 // addition to get the next register, but for VFP registers, the
1099 // sort order is guaranteed because they're all of the form D<n>.
1100 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1101 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1102}
1103
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001104void ARMInstPrinter::printVectorListTwoSpacedAllLanes(const MCInst *MI,
1105 unsigned OpNum,
1106 raw_ostream &O) {
1107 // Normally, it's not safe to use register enum values directly with
1108 // addition to get the next register, but for VFP registers, the
1109 // sort order is guaranteed because they're all of the form D<n>.
1110 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1111 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[]}";
1112}
1113
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001114void ARMInstPrinter::printVectorListThreeSpacedAllLanes(const MCInst *MI,
1115 unsigned OpNum,
1116 raw_ostream &O) {
1117 // Normally, it's not safe to use register enum values directly with
1118 // addition to get the next register, but for VFP registers, the
1119 // sort order is guaranteed because they're all of the form D<n>.
1120 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1121 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001122 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[]}";
1123}
1124
1125void ARMInstPrinter::printVectorListFourSpacedAllLanes(const MCInst *MI,
1126 unsigned OpNum,
1127 raw_ostream &O) {
1128 // Normally, it's not safe to use register enum values directly with
1129 // addition to get the next register, but for VFP registers, the
1130 // sort order is guaranteed because they're all of the form D<n>.
1131 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1132 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1133 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[], "
1134 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "[]}";
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001135}
1136
Jim Grosbachc387fc62012-01-23 23:20:46 +00001137void ARMInstPrinter::printVectorListThreeSpaced(const MCInst *MI,
1138 unsigned OpNum,
1139 raw_ostream &O) {
1140 // Normally, it's not safe to use register enum values directly with
1141 // addition to get the next register, but for VFP registers, the
1142 // sort order is guaranteed because they're all of the form D<n>.
1143 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1144 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1145 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "}";
1146}
Jim Grosbach8abe7e32012-01-24 00:43:17 +00001147
1148void ARMInstPrinter::printVectorListFourSpaced(const MCInst *MI,
1149 unsigned OpNum,
1150 raw_ostream &O) {
1151 // Normally, it's not safe to use register enum values directly with
1152 // addition to get the next register, but for VFP registers, the
1153 // sort order is guaranteed because they're all of the form D<n>.
1154 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1155 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1156 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << ", "
1157 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "}";
1158}