blob: 289d1921d1c3e6b1d1d5788708d37d5d609aa645 [file] [log] [blame]
Chris Lattnerfd603822009-10-19 19:56:26 +00001//===-- ARMInstPrinter.cpp - Convert ARM MCInst to assembly syntax --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class prints an ARM MCInst to a .s file.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "asm-printer"
15#include "ARMInstPrinter.h"
Evan Chengbe740292011-07-23 00:00:19 +000016#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000017#include "MCTargetDesc/ARMAddressingModes.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000018#include "llvm/MC/MCInst.h"
Chris Lattner61d35c22009-10-19 21:21:39 +000019#include "llvm/MC/MCAsmInfo.h"
Chris Lattner6f997762009-10-19 21:53:00 +000020#include "llvm/MC/MCExpr.h"
Johnny Chenc7b65912010-04-16 22:40:20 +000021#include "llvm/ADT/StringExtras.h"
Chris Lattner6f997762009-10-19 21:53:00 +000022#include "llvm/Support/raw_ostream.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000023using namespace llvm;
24
Chris Lattner6274ec42010-10-28 21:37:33 +000025#define GET_INSTRUCTION_NAME
Chris Lattnerfd603822009-10-19 19:56:26 +000026#include "ARMGenAsmWriter.inc"
Chris Lattnerfd603822009-10-19 19:56:26 +000027
Owen Anderson3dac0be2011-08-11 18:41:59 +000028/// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing.
29///
30/// getSORegOffset returns an integer from 0-31, but '0' should actually be printed
31/// 32 as the immediate shouldbe within the range 1-32.
32static unsigned translateShiftImm(unsigned imm) {
33 if (imm == 0)
34 return 32;
35 return imm;
36}
37
James Molloyb9505852011-09-07 17:24:38 +000038
39ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
40 const MCSubtargetInfo &STI) :
41 MCInstPrinter(MAI) {
42 // Initialize the set of available features.
43 setAvailableFeatures(STI.getFeatureBits());
44}
45
Chris Lattner6274ec42010-10-28 21:37:33 +000046StringRef ARMInstPrinter::getOpcodeName(unsigned Opcode) const {
47 return getInstructionName(Opcode);
48}
49
Rafael Espindolacde4ce42011-06-02 02:34:55 +000050void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
51 OS << getRegisterName(RegNo);
Anton Korobeynikov57caad72011-03-05 18:43:32 +000052}
Chris Lattner6274ec42010-10-28 21:37:33 +000053
Chris Lattnerd3740872010-04-04 05:04:31 +000054void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) {
Bill Wendling04863d02010-11-13 10:40:19 +000055 unsigned Opcode = MI->getOpcode();
56
Johnny Chen9e088762010-03-17 17:52:21 +000057 // Check for MOVs and print canonical forms, instead.
Owen Anderson152d4a42011-07-21 23:38:37 +000058 if (Opcode == ARM::MOVsr) {
Jim Grosbache6be85e2010-09-17 22:36:38 +000059 // FIXME: Thumb variants?
Johnny Chen9e088762010-03-17 17:52:21 +000060 const MCOperand &Dst = MI->getOperand(0);
61 const MCOperand &MO1 = MI->getOperand(1);
62 const MCOperand &MO2 = MI->getOperand(2);
63 const MCOperand &MO3 = MI->getOperand(3);
64
65 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()));
Chris Lattner35c33bd2010-04-04 04:47:45 +000066 printSBitModifierOperand(MI, 6, O);
67 printPredicateOperand(MI, 4, O);
Johnny Chen9e088762010-03-17 17:52:21 +000068
69 O << '\t' << getRegisterName(Dst.getReg())
70 << ", " << getRegisterName(MO1.getReg());
71
Owen Anderson152d4a42011-07-21 23:38:37 +000072 O << ", " << getRegisterName(MO2.getReg());
73 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Owen Andersonede042d2011-09-15 18:36:29 +000074
75 if (CommentStream) printAnnotations(MI, *CommentStream);
76
Johnny Chen9e088762010-03-17 17:52:21 +000077 return;
78 }
79
Owen Anderson152d4a42011-07-21 23:38:37 +000080 if (Opcode == ARM::MOVsi) {
81 // FIXME: Thumb variants?
82 const MCOperand &Dst = MI->getOperand(0);
83 const MCOperand &MO1 = MI->getOperand(1);
84 const MCOperand &MO2 = MI->getOperand(2);
85
86 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
87 printSBitModifierOperand(MI, 5, O);
88 printPredicateOperand(MI, 3, O);
89
90 O << '\t' << getRegisterName(Dst.getReg())
91 << ", " << getRegisterName(MO1.getReg());
92
Owen Andersonede042d2011-09-15 18:36:29 +000093 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
94 if (CommentStream) printAnnotations(MI, *CommentStream);
Owen Anderson152d4a42011-07-21 23:38:37 +000095 return;
Owen Andersonede042d2011-09-15 18:36:29 +000096 }
Owen Anderson152d4a42011-07-21 23:38:37 +000097
Owen Anderson3dac0be2011-08-11 18:41:59 +000098 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Andersonede042d2011-09-15 18:36:29 +000099
100 if (CommentStream) printAnnotations(MI, *CommentStream);
Owen Anderson152d4a42011-07-21 23:38:37 +0000101 return;
102 }
103
104
Johnny Chen9e088762010-03-17 17:52:21 +0000105 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000106 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000107 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000108 O << '\t' << "push";
109 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000110 if (Opcode == ARM::t2STMDB_UPD)
111 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000112 O << '\t';
113 printRegisterList(MI, 4, O);
Owen Andersonede042d2011-09-15 18:36:29 +0000114 if (CommentStream) printAnnotations(MI, *CommentStream);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000115 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000116 }
Jim Grosbachf6713912011-08-11 18:07:11 +0000117 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
118 MI->getOperand(3).getImm() == -4) {
119 O << '\t' << "push";
120 printPredicateOperand(MI, 4, O);
121 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
Owen Andersonede042d2011-09-15 18:36:29 +0000122 if (CommentStream) printAnnotations(MI, *CommentStream);
Jim Grosbachf6713912011-08-11 18:07:11 +0000123 return;
124 }
Johnny Chen9e088762010-03-17 17:52:21 +0000125
126 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000127 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000128 MI->getOperand(0).getReg() == ARM::SP) {
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 Andersonede042d2011-09-15 18:36:29 +0000135 if (CommentStream) printAnnotations(MI, *CommentStream);
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 Andersonede042d2011-09-15 18:36:29 +0000143 if (CommentStream) printAnnotations(MI, *CommentStream);
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 Andersonede042d2011-09-15 18:36:29 +0000155 if (CommentStream) printAnnotations(MI, *CommentStream);
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 Andersonede042d2011-09-15 18:36:29 +0000166 if (CommentStream) printAnnotations(MI, *CommentStream);
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 Andersonede042d2011-09-15 18:36:29 +0000185 if (CommentStream) printAnnotations(MI, *CommentStream);
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 Andersonede042d2011-09-15 18:36:29 +0000194 if (CommentStream) printAnnotations(MI, *CommentStream);
Jim Grosbach0780b632011-08-19 23:24:36 +0000195 return;
196 }
197
Chris Lattner35c33bd2010-04-04 04:47:45 +0000198 printInstruction(MI, O);
Owen Andersonede042d2011-09-15 18:36:29 +0000199 if (CommentStream) printAnnotations(MI, *CommentStream);
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");
Chris Lattner8cb9a3b2010-01-18 00:37:40 +0000212 O << *Op.getExpr();
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000213 }
214}
Chris Lattner61d35c22009-10-19 21:21:39 +0000215
Chris Lattner017d9472009-10-20 00:40:56 +0000216// so_reg is a 4-operand unit corresponding to register forms of the A5.1
217// "Addressing Mode 1 - Data-processing operands" forms. This includes:
218// REG 0 0 - e.g. R5
219// REG REG 0,SH_OPC - e.g. R5, ROR R3
220// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000221void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000222 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000223 const MCOperand &MO1 = MI->getOperand(OpNum);
224 const MCOperand &MO2 = MI->getOperand(OpNum+1);
225 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000226
Chris Lattner017d9472009-10-20 00:40:56 +0000227 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000228
Chris Lattner017d9472009-10-20 00:40:56 +0000229 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000230 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
231 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000232 if (ShOpc == ARM_AM::rrx)
233 return;
Owen Anderson152d4a42011-07-21 23:38:37 +0000234
235 O << ' ' << getRegisterName(MO2.getReg());
236 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000237}
Chris Lattner084f87d2009-10-19 21:57:05 +0000238
Owen Anderson152d4a42011-07-21 23:38:37 +0000239void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
240 raw_ostream &O) {
241 const MCOperand &MO1 = MI->getOperand(OpNum);
242 const MCOperand &MO2 = MI->getOperand(OpNum+1);
243
244 O << getRegisterName(MO1.getReg());
245
246 // Print the shift opc.
247 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
248 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
249 if (ShOpc == ARM_AM::rrx)
250 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000251 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000252}
253
254
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000255//===--------------------------------------------------------------------===//
256// Addressing Mode #2
257//===--------------------------------------------------------------------===//
258
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000259void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
260 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000261 const MCOperand &MO1 = MI->getOperand(Op);
262 const MCOperand &MO2 = MI->getOperand(Op+1);
263 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000264
Chris Lattner084f87d2009-10-19 21:57:05 +0000265 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000266
Chris Lattner084f87d2009-10-19 21:57:05 +0000267 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000268 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000269 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000270 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
271 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000272 O << "]";
273 return;
274 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000275
Chris Lattner084f87d2009-10-19 21:57:05 +0000276 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000277 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
278 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000279
Chris Lattner084f87d2009-10-19 21:57:05 +0000280 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
281 O << ", "
282 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
283 << " #" << ShImm;
284 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000285}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000286
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000287void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
288 raw_ostream &O) {
289 const MCOperand &MO1 = MI->getOperand(Op);
290 const MCOperand &MO2 = MI->getOperand(Op+1);
291 const MCOperand &MO3 = MI->getOperand(Op+2);
292
293 O << "[" << getRegisterName(MO1.getReg()) << "], ";
294
295 if (!MO2.getReg()) {
296 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
297 O << '#'
298 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
299 << ImmOffs;
300 return;
301 }
302
303 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
304 << getRegisterName(MO2.getReg());
305
306 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
307 O << ", "
308 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
309 << " #" << ShImm;
310}
311
312void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
313 raw_ostream &O) {
314 const MCOperand &MO1 = MI->getOperand(Op);
315
316 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
317 printOperand(MI, Op, O);
318 return;
319 }
320
321 const MCOperand &MO3 = MI->getOperand(Op+2);
322 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
323
324 if (IdxMode == ARMII::IndexModePost) {
325 printAM2PostIndexOp(MI, Op, O);
326 return;
327 }
328 printAM2PreOrOffsetIndexOp(MI, Op, O);
329}
330
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000331void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000332 unsigned OpNum,
333 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000334 const MCOperand &MO1 = MI->getOperand(OpNum);
335 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000336
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000337 if (!MO1.getReg()) {
338 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000339 O << '#'
340 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
341 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000342 return;
343 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000344
Johnny Chen9e088762010-03-17 17:52:21 +0000345 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
346 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000347
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000348 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
349 O << ", "
350 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
351 << " #" << ShImm;
352}
353
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000354//===--------------------------------------------------------------------===//
355// Addressing Mode #3
356//===--------------------------------------------------------------------===//
357
358void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
359 raw_ostream &O) {
360 const MCOperand &MO1 = MI->getOperand(Op);
361 const MCOperand &MO2 = MI->getOperand(Op+1);
362 const MCOperand &MO3 = MI->getOperand(Op+2);
363
364 O << "[" << getRegisterName(MO1.getReg()) << "], ";
365
366 if (MO2.getReg()) {
367 O << (char)ARM_AM::getAM3Op(MO3.getImm())
368 << getRegisterName(MO2.getReg());
369 return;
370 }
371
372 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
373 O << '#'
374 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
375 << ImmOffs;
376}
377
378void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
379 raw_ostream &O) {
380 const MCOperand &MO1 = MI->getOperand(Op);
381 const MCOperand &MO2 = MI->getOperand(Op+1);
382 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000383
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000384 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000385
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000386 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000387 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000388 << getRegisterName(MO2.getReg()) << ']';
389 return;
390 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000391
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000392 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
393 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000394 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
395 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000396 O << ']';
397}
398
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000399void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
400 raw_ostream &O) {
401 const MCOperand &MO3 = MI->getOperand(Op+2);
402 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
403
404 if (IdxMode == ARMII::IndexModePost) {
405 printAM3PostIndexOp(MI, Op, O);
406 return;
407 }
408 printAM3PreOrOffsetIndexOp(MI, Op, O);
409}
410
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000411void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000412 unsigned OpNum,
413 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000414 const MCOperand &MO1 = MI->getOperand(OpNum);
415 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000416
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000417 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000418 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
419 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000420 return;
421 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000422
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000423 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000424 O << '#'
425 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
426 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000427}
428
Jim Grosbach7ce05792011-08-03 23:50:40 +0000429void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
430 unsigned OpNum,
431 raw_ostream &O) {
432 const MCOperand &MO = MI->getOperand(OpNum);
433 unsigned Imm = MO.getImm();
434 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
435}
436
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000437void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
438 raw_ostream &O) {
439 const MCOperand &MO1 = MI->getOperand(OpNum);
440 const MCOperand &MO2 = MI->getOperand(OpNum+1);
441
Jim Grosbach16578b52011-08-05 16:11:38 +0000442 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000443}
444
Owen Anderson154c41d2011-08-04 18:24:14 +0000445void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
446 unsigned OpNum,
447 raw_ostream &O) {
448 const MCOperand &MO = MI->getOperand(OpNum);
449 unsigned Imm = MO.getImm();
450 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
451}
452
453
Jim Grosbache6913602010-11-03 01:01:43 +0000454void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000455 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000456 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
457 .getImm());
458 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000459}
460
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000461void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000462 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000463 const MCOperand &MO1 = MI->getOperand(OpNum);
464 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000465
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000466 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000467 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000468 return;
469 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000470
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000471 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000472
Owen Anderson0da10cf2011-08-29 19:36:44 +0000473 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
474 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
475 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000476 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000477 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000478 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000479 }
480 O << "]";
481}
482
Chris Lattner35c33bd2010-04-04 04:47:45 +0000483void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
484 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000485 const MCOperand &MO1 = MI->getOperand(OpNum);
486 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000487
Bob Wilson226036e2010-03-20 22:13:40 +0000488 O << "[" << getRegisterName(MO1.getReg());
489 if (MO2.getImm()) {
490 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000491 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000492 }
Bob Wilson226036e2010-03-20 22:13:40 +0000493 O << "]";
494}
495
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000496void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
497 raw_ostream &O) {
498 const MCOperand &MO1 = MI->getOperand(OpNum);
499 O << "[" << getRegisterName(MO1.getReg()) << "]";
500}
501
Bob Wilson226036e2010-03-20 22:13:40 +0000502void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000503 unsigned OpNum,
504 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000505 const MCOperand &MO = MI->getOperand(OpNum);
506 if (MO.getReg() == 0)
507 O << "!";
508 else
509 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000510}
511
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000512void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
513 unsigned OpNum,
514 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000515 const MCOperand &MO = MI->getOperand(OpNum);
516 uint32_t v = ~MO.getImm();
517 int32_t lsb = CountTrailingZeros_32(v);
518 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
519 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
520 O << '#' << lsb << ", #" << width;
521}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000522
Johnny Chen1adc40c2010-08-12 20:46:17 +0000523void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
524 raw_ostream &O) {
525 unsigned val = MI->getOperand(OpNum).getImm();
526 O << ARM_MB::MemBOptToString(val);
527}
528
Bob Wilson22f5dc72010-08-16 18:27:34 +0000529void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000530 raw_ostream &O) {
531 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000532 bool isASR = (ShiftOp & (1 << 5)) != 0;
533 unsigned Amt = ShiftOp & 0x1f;
534 if (isASR)
535 O << ", asr #" << (Amt == 0 ? 32 : Amt);
536 else if (Amt)
537 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000538}
539
Jim Grosbachdde038a2011-07-20 21:40:26 +0000540void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
541 raw_ostream &O) {
542 unsigned Imm = MI->getOperand(OpNum).getImm();
543 if (Imm == 0)
544 return;
545 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
546 O << ", lsl #" << Imm;
547}
548
549void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
550 raw_ostream &O) {
551 unsigned Imm = MI->getOperand(OpNum).getImm();
552 // A shift amount of 32 is encoded as 0.
553 if (Imm == 0)
554 Imm = 32;
555 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
556 O << ", asr #" << Imm;
557}
558
Chris Lattner35c33bd2010-04-04 04:47:45 +0000559void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
560 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000561 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000562 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
563 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000564 O << getRegisterName(MI->getOperand(i).getReg());
565 }
566 O << "}";
567}
Chris Lattner4d152222009-10-19 22:23:04 +0000568
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000569void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
570 raw_ostream &O) {
571 const MCOperand &Op = MI->getOperand(OpNum);
572 if (Op.getImm())
573 O << "be";
574 else
575 O << "le";
576}
577
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000578void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
579 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000580 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000581 O << ARM_PROC::IModToString(Op.getImm());
582}
583
584void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
585 raw_ostream &O) {
586 const MCOperand &Op = MI->getOperand(OpNum);
587 unsigned IFlags = Op.getImm();
588 for (int i=2; i >= 0; --i)
589 if (IFlags & (1 << i))
590 O << ARM_PROC::IFlagsToString(1 << i);
Johnny Chen9e088762010-03-17 17:52:21 +0000591}
592
Chris Lattner35c33bd2010-04-04 04:47:45 +0000593void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
594 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000595 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000596 unsigned SpecRegRBit = Op.getImm() >> 4;
597 unsigned Mask = Op.getImm() & 0xf;
598
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000599 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
600 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
601 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
602 O << "APSR_";
603 switch (Mask) {
604 default: assert(0);
605 case 4: O << "g"; return;
606 case 8: O << "nzcvq"; return;
607 case 12: O << "nzcvqg"; return;
608 }
609 llvm_unreachable("Unexpected mask value!");
610 }
611
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000612 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000613 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000614 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000615 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000616
Johnny Chen9e088762010-03-17 17:52:21 +0000617 if (Mask) {
618 O << '_';
619 if (Mask & 8) O << 'f';
620 if (Mask & 4) O << 's';
621 if (Mask & 2) O << 'x';
622 if (Mask & 1) O << 'c';
623 }
624}
625
Chris Lattner35c33bd2010-04-04 04:47:45 +0000626void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
627 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000628 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
629 if (CC != ARMCC::AL)
630 O << ARMCondCodeToString(CC);
631}
632
Jim Grosbach15d78982010-09-14 22:27:15 +0000633void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000634 unsigned OpNum,
635 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000636 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
637 O << ARMCondCodeToString(CC);
638}
639
Chris Lattner35c33bd2010-04-04 04:47:45 +0000640void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
641 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000642 if (MI->getOperand(OpNum).getReg()) {
643 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
644 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000645 O << 's';
646 }
647}
648
Chris Lattner35c33bd2010-04-04 04:47:45 +0000649void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
650 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000651 O << MI->getOperand(OpNum).getImm();
652}
653
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000654void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
655 raw_ostream &O) {
656 O << "p" << MI->getOperand(OpNum).getImm();
657}
658
659void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
660 raw_ostream &O) {
661 O << "c" << MI->getOperand(OpNum).getImm();
662}
663
Chris Lattner35c33bd2010-04-04 04:47:45 +0000664void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
665 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000666 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000667}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000668
Chris Lattner35c33bd2010-04-04 04:47:45 +0000669void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
670 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000671 O << "#" << MI->getOperand(OpNum).getImm() * 4;
672}
673
674void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
675 raw_ostream &O) {
676 unsigned Imm = MI->getOperand(OpNum).getImm();
677 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000678}
Johnny Chen9e088762010-03-17 17:52:21 +0000679
Chris Lattner35c33bd2010-04-04 04:47:45 +0000680void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
681 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000682 // (3 - the number of trailing zeros) is the number of then / else.
683 unsigned Mask = MI->getOperand(OpNum).getImm();
684 unsigned CondBit0 = Mask >> 4 & 1;
685 unsigned NumTZ = CountTrailingZeros_32(Mask);
686 assert(NumTZ <= 3 && "Invalid IT mask!");
687 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
688 bool T = ((Mask >> Pos) & 1) == CondBit0;
689 if (T)
690 O << 't';
691 else
692 O << 'e';
693 }
694}
695
Chris Lattner35c33bd2010-04-04 04:47:45 +0000696void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
697 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000698 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000699 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000700
701 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000702 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000703 return;
704 }
705
706 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000707 if (unsigned RegNum = MO2.getReg())
708 O << ", " << getRegisterName(RegNum);
709 O << "]";
710}
711
712void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
713 unsigned Op,
714 raw_ostream &O,
715 unsigned Scale) {
716 const MCOperand &MO1 = MI->getOperand(Op);
717 const MCOperand &MO2 = MI->getOperand(Op + 1);
718
719 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
720 printOperand(MI, Op, O);
721 return;
722 }
723
724 O << "[" << getRegisterName(MO1.getReg());
725 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000726 O << ", #" << ImmOffs * Scale;
727 O << "]";
728}
729
Bill Wendlingf4caf692010-12-14 03:36:38 +0000730void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
731 unsigned Op,
732 raw_ostream &O) {
733 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000734}
735
Bill Wendlingf4caf692010-12-14 03:36:38 +0000736void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
737 unsigned Op,
738 raw_ostream &O) {
739 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000740}
741
Bill Wendlingf4caf692010-12-14 03:36:38 +0000742void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
743 unsigned Op,
744 raw_ostream &O) {
745 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000746}
747
Chris Lattner35c33bd2010-04-04 04:47:45 +0000748void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
749 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000750 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000751}
752
Johnny Chen9e088762010-03-17 17:52:21 +0000753// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
754// register with shift forms.
755// REG 0 0 - e.g. R5
756// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000757void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
758 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000759 const MCOperand &MO1 = MI->getOperand(OpNum);
760 const MCOperand &MO2 = MI->getOperand(OpNum+1);
761
762 unsigned Reg = MO1.getReg();
763 O << getRegisterName(Reg);
764
765 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000766 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000767 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
768 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
769 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000770 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000771}
772
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000773void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
774 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000775 const MCOperand &MO1 = MI->getOperand(OpNum);
776 const MCOperand &MO2 = MI->getOperand(OpNum+1);
777
Jim Grosbach3e556122010-10-26 22:37:02 +0000778 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
779 printOperand(MI, OpNum, O);
780 return;
781 }
782
Johnny Chen9e088762010-03-17 17:52:21 +0000783 O << "[" << getRegisterName(MO1.getReg());
784
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000785 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000786 bool isSub = OffImm < 0;
787 // Special value for #-0. All others are normal.
788 if (OffImm == INT32_MIN)
789 OffImm = 0;
790 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000791 O << ", #-" << -OffImm;
792 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000793 O << ", #" << OffImm;
794 O << "]";
795}
796
797void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000798 unsigned OpNum,
799 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000800 const MCOperand &MO1 = MI->getOperand(OpNum);
801 const MCOperand &MO2 = MI->getOperand(OpNum+1);
802
803 O << "[" << getRegisterName(MO1.getReg());
804
805 int32_t OffImm = (int32_t)MO2.getImm();
806 // Don't print +0.
807 if (OffImm < 0)
808 O << ", #-" << -OffImm;
809 else if (OffImm > 0)
810 O << ", #" << OffImm;
811 O << "]";
812}
813
814void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000815 unsigned OpNum,
816 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000817 const MCOperand &MO1 = MI->getOperand(OpNum);
818 const MCOperand &MO2 = MI->getOperand(OpNum+1);
819
820 O << "[" << getRegisterName(MO1.getReg());
821
822 int32_t OffImm = (int32_t)MO2.getImm() / 4;
823 // Don't print +0.
824 if (OffImm < 0)
825 O << ", #-" << -OffImm * 4;
826 else if (OffImm > 0)
827 O << ", #" << OffImm * 4;
828 O << "]";
829}
830
Jim Grosbachb6aed502011-09-09 18:37:27 +0000831void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
832 unsigned OpNum,
833 raw_ostream &O) {
834 const MCOperand &MO1 = MI->getOperand(OpNum);
835 const MCOperand &MO2 = MI->getOperand(OpNum+1);
836
837 O << "[" << getRegisterName(MO1.getReg());
838 if (MO2.getImm())
839 O << ", #" << MO2.getImm() * 4;
840 O << "]";
841}
842
Johnny Chen9e088762010-03-17 17:52:21 +0000843void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000844 unsigned OpNum,
845 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000846 const MCOperand &MO1 = MI->getOperand(OpNum);
847 int32_t OffImm = (int32_t)MO1.getImm();
848 // Don't print +0.
849 if (OffImm < 0)
850 O << "#-" << -OffImm;
851 else if (OffImm > 0)
852 O << "#" << OffImm;
853}
854
855void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000856 unsigned OpNum,
857 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000858 const MCOperand &MO1 = MI->getOperand(OpNum);
859 int32_t OffImm = (int32_t)MO1.getImm() / 4;
860 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000861 if (OffImm != 0) {
862 O << ", ";
863 if (OffImm < 0)
864 O << "#-" << -OffImm * 4;
865 else if (OffImm > 0)
866 O << "#" << OffImm * 4;
867 }
Johnny Chen9e088762010-03-17 17:52:21 +0000868}
869
870void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000871 unsigned OpNum,
872 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000873 const MCOperand &MO1 = MI->getOperand(OpNum);
874 const MCOperand &MO2 = MI->getOperand(OpNum+1);
875 const MCOperand &MO3 = MI->getOperand(OpNum+2);
876
877 O << "[" << getRegisterName(MO1.getReg());
878
879 assert(MO2.getReg() && "Invalid so_reg load / store address!");
880 O << ", " << getRegisterName(MO2.getReg());
881
882 unsigned ShAmt = MO3.getImm();
883 if (ShAmt) {
884 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
885 O << ", lsl #" << ShAmt;
886 }
887 O << "]";
888}
889
Chris Lattner35c33bd2010-04-04 04:47:45 +0000890void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
891 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000892 const MCOperand &MO = MI->getOperand(OpNum);
893 O << '#';
894 if (MO.isFPImm()) {
895 O << (float)MO.getFPImm();
896 } else {
897 union {
898 uint32_t I;
899 float F;
900 } FPUnion;
901
902 FPUnion.I = MO.getImm();
903 O << FPUnion.F;
904 }
Johnny Chen9e088762010-03-17 17:52:21 +0000905}
906
Chris Lattner35c33bd2010-04-04 04:47:45 +0000907void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
908 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000909 const MCOperand &MO = MI->getOperand(OpNum);
910 O << '#';
911 if (MO.isFPImm()) {
912 O << MO.getFPImm();
913 } else {
914 // We expect the binary encoding of a floating point number here.
915 union {
916 uint64_t I;
917 double D;
918 } FPUnion;
919
920 FPUnion.I = MO.getImm();
921 O << FPUnion.D;
922 }
Johnny Chen9e088762010-03-17 17:52:21 +0000923}
924
Bob Wilson1a913ed2010-06-11 21:34:50 +0000925void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
926 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000927 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
928 unsigned EltBits;
929 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Bob Wilson1a913ed2010-06-11 21:34:50 +0000930 O << "#0x" << utohexstr(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000931}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000932
Jim Grosbachf4943352011-07-25 23:09:14 +0000933void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
934 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000935 unsigned Imm = MI->getOperand(OpNum).getImm();
936 O << "#" << Imm + 1;
937}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000938
939void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
940 raw_ostream &O) {
941 unsigned Imm = MI->getOperand(OpNum).getImm();
942 if (Imm == 0)
943 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000944 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000945 switch (Imm) {
946 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +0000947 case 1: O << "8"; break;
948 case 2: O << "16"; break;
949 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000950 }
951}