blob: cfb5b92d0c0f5907630f92647d3b78d49606ca80 [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,
Jim Grosbachc6449b62012-03-05 19:33:20 +000038 const MCRegisterInfo &MRI,
James Molloyb9505852011-09-07 17:24:38 +000039 const MCSubtargetInfo &STI) :
Jim Grosbachc6449b62012-03-05 19:33:20 +000040 MCInstPrinter(MAI, MRI) {
James Molloyb9505852011-09-07 17:24:38 +000041 // Initialize the set of available features.
42 setAvailableFeatures(STI.getFeatureBits());
43}
44
Chris Lattner6274ec42010-10-28 21:37:33 +000045StringRef ARMInstPrinter::getOpcodeName(unsigned Opcode) const {
46 return getInstructionName(Opcode);
47}
48
Rafael Espindolacde4ce42011-06-02 02:34:55 +000049void ARMInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
50 OS << getRegisterName(RegNo);
Anton Korobeynikov57caad72011-03-05 18:43:32 +000051}
Chris Lattner6274ec42010-10-28 21:37:33 +000052
Owen Anderson98c5dda2011-09-15 23:38:46 +000053void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
54 StringRef Annot) {
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 Anderson519020a2011-09-21 17:58:45 +000074 printAnnotation(O, Annot);
Johnny Chen9e088762010-03-17 17:52:21 +000075 return;
76 }
77
Owen Anderson152d4a42011-07-21 23:38:37 +000078 if (Opcode == ARM::MOVsi) {
79 // FIXME: Thumb variants?
80 const MCOperand &Dst = MI->getOperand(0);
81 const MCOperand &MO1 = MI->getOperand(1);
82 const MCOperand &MO2 = MI->getOperand(2);
83
84 O << '\t' << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()));
85 printSBitModifierOperand(MI, 5, O);
86 printPredicateOperand(MI, 3, O);
87
88 O << '\t' << getRegisterName(Dst.getReg())
89 << ", " << getRegisterName(MO1.getReg());
90
Owen Andersonede042d2011-09-15 18:36:29 +000091 if (ARM_AM::getSORegShOp(MO2.getImm()) == ARM_AM::rrx) {
Owen Anderson519020a2011-09-21 17:58:45 +000092 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000093 return;
Owen Andersonede042d2011-09-15 18:36:29 +000094 }
Owen Anderson152d4a42011-07-21 23:38:37 +000095
Owen Anderson3dac0be2011-08-11 18:41:59 +000096 O << ", #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson519020a2011-09-21 17:58:45 +000097 printAnnotation(O, Annot);
Owen Anderson152d4a42011-07-21 23:38:37 +000098 return;
99 }
100
101
Johnny Chen9e088762010-03-17 17:52:21 +0000102 // A8.6.123 PUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000103 if ((Opcode == ARM::STMDB_UPD || Opcode == ARM::t2STMDB_UPD) &&
Owen Anderson81550dc2011-11-02 18:03:14 +0000104 MI->getOperand(0).getReg() == ARM::SP &&
105 MI->getNumOperands() > 5) {
106 // Should only print PUSH if there are at least two registers in the list.
Bill Wendling73fe34a2010-11-16 01:16:36 +0000107 O << '\t' << "push";
108 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000109 if (Opcode == ARM::t2STMDB_UPD)
110 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000111 O << '\t';
112 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000113 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000114 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000115 }
Jim Grosbachf6713912011-08-11 18:07:11 +0000116 if (Opcode == ARM::STR_PRE_IMM && MI->getOperand(2).getReg() == ARM::SP &&
117 MI->getOperand(3).getImm() == -4) {
118 O << '\t' << "push";
119 printPredicateOperand(MI, 4, O);
120 O << "\t{" << getRegisterName(MI->getOperand(1).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000121 printAnnotation(O, Annot);
Jim Grosbachf6713912011-08-11 18:07:11 +0000122 return;
123 }
Johnny Chen9e088762010-03-17 17:52:21 +0000124
125 // A8.6.122 POP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000126 if ((Opcode == ARM::LDMIA_UPD || Opcode == ARM::t2LDMIA_UPD) &&
Owen Anderson81550dc2011-11-02 18:03:14 +0000127 MI->getOperand(0).getReg() == ARM::SP &&
128 MI->getNumOperands() > 5) {
129 // Should only print POP if there are at least two registers in the list.
Bill Wendling73fe34a2010-11-16 01:16:36 +0000130 O << '\t' << "pop";
131 printPredicateOperand(MI, 2, O);
Jim Grosbach41ad0c42010-12-03 20:33:01 +0000132 if (Opcode == ARM::t2LDMIA_UPD)
133 O << ".w";
Bill Wendling73fe34a2010-11-16 01:16:36 +0000134 O << '\t';
135 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000136 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000137 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000138 }
Jim Grosbachf8fce712011-08-11 17:35:48 +0000139 if (Opcode == ARM::LDR_POST_IMM && MI->getOperand(2).getReg() == ARM::SP &&
140 MI->getOperand(4).getImm() == 4) {
141 O << '\t' << "pop";
142 printPredicateOperand(MI, 5, O);
143 O << "\t{" << getRegisterName(MI->getOperand(0).getReg()) << "}";
Owen Anderson519020a2011-09-21 17:58:45 +0000144 printAnnotation(O, Annot);
Jim Grosbachf8fce712011-08-11 17:35:48 +0000145 return;
146 }
147
Johnny Chen9e088762010-03-17 17:52:21 +0000148
149 // A8.6.355 VPUSH
Bill Wendling73fe34a2010-11-16 01:16:36 +0000150 if ((Opcode == ARM::VSTMSDB_UPD || Opcode == ARM::VSTMDDB_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000151 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000152 O << '\t' << "vpush";
153 printPredicateOperand(MI, 2, O);
154 O << '\t';
155 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000156 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000157 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000158 }
159
160 // A8.6.354 VPOP
Bill Wendling73fe34a2010-11-16 01:16:36 +0000161 if ((Opcode == ARM::VLDMSIA_UPD || Opcode == ARM::VLDMDIA_UPD) &&
Johnny Chen9e088762010-03-17 17:52:21 +0000162 MI->getOperand(0).getReg() == ARM::SP) {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000163 O << '\t' << "vpop";
164 printPredicateOperand(MI, 2, O);
165 O << '\t';
166 printRegisterList(MI, 4, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000167 printAnnotation(O, Annot);
Bill Wendling73fe34a2010-11-16 01:16:36 +0000168 return;
Johnny Chen9e088762010-03-17 17:52:21 +0000169 }
170
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000171 if (Opcode == ARM::tLDMIA) {
Owen Anderson565a0362011-07-18 23:25:34 +0000172 bool Writeback = true;
173 unsigned BaseReg = MI->getOperand(0).getReg();
174 for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
175 if (MI->getOperand(i).getReg() == BaseReg)
176 Writeback = false;
177 }
178
Jim Grosbachcefe4c92011-08-23 17:41:15 +0000179 O << "\tldm";
Owen Anderson565a0362011-07-18 23:25:34 +0000180
181 printPredicateOperand(MI, 1, O);
182 O << '\t' << getRegisterName(BaseReg);
183 if (Writeback) O << "!";
184 O << ", ";
185 printRegisterList(MI, 3, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000186 printAnnotation(O, Annot);
Owen Anderson565a0362011-07-18 23:25:34 +0000187 return;
188 }
189
Jim Grosbach0780b632011-08-19 23:24:36 +0000190 // Thumb1 NOP
191 if (Opcode == ARM::tMOVr && MI->getOperand(0).getReg() == ARM::R8 &&
192 MI->getOperand(1).getReg() == ARM::R8) {
193 O << "\tnop";
Jim Grosbachdf9ce6b2011-08-24 20:06:14 +0000194 printPredicateOperand(MI, 2, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000195 printAnnotation(O, Annot);
Jim Grosbach0780b632011-08-19 23:24:36 +0000196 return;
197 }
198
Chris Lattner35c33bd2010-04-04 04:47:45 +0000199 printInstruction(MI, O);
Owen Anderson519020a2011-09-21 17:58:45 +0000200 printAnnotation(O, Annot);
Bill Wendling04863d02010-11-13 10:40:19 +0000201}
Chris Lattnerfd603822009-10-19 19:56:26 +0000202
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000203void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000204 raw_ostream &O) {
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000205 const MCOperand &Op = MI->getOperand(OpNo);
206 if (Op.isReg()) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000207 unsigned Reg = Op.getReg();
Jim Grosbach35636282010-10-06 21:22:32 +0000208 O << getRegisterName(Reg);
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000209 } else if (Op.isImm()) {
210 O << '#' << Op.getImm();
211 } else {
212 assert(Op.isExpr() && "unknown operand kind in printOperand");
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000213 // If a symbolic branch target was added as a constant expression then print
214 // that address in hex.
215 const MCConstantExpr *BranchTarget = dyn_cast<MCConstantExpr>(Op.getExpr());
216 int64_t Address;
217 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
218 O << "0x";
219 O.write_hex(Address);
220 }
221 else {
222 // Otherwise, just print the expression.
223 O << *Op.getExpr();
224 }
Chris Lattner8bc86cb2009-10-19 20:59:55 +0000225 }
226}
Chris Lattner61d35c22009-10-19 21:21:39 +0000227
Owen Andersone1368722011-09-21 23:44:46 +0000228void ARMInstPrinter::printT2LdrLabelOperand(const MCInst *MI, unsigned OpNum,
229 raw_ostream &O) {
230 const MCOperand &MO1 = MI->getOperand(OpNum);
231 if (MO1.isExpr())
232 O << *MO1.getExpr();
233 else if (MO1.isImm())
234 O << "[pc, #" << MO1.getImm() << "]";
235 else
236 llvm_unreachable("Unknown LDR label operand?");
237}
238
Chris Lattner017d9472009-10-20 00:40:56 +0000239// so_reg is a 4-operand unit corresponding to register forms of the A5.1
240// "Addressing Mode 1 - Data-processing operands" forms. This includes:
241// REG 0 0 - e.g. R5
242// REG REG 0,SH_OPC - e.g. R5, ROR R3
243// REG 0 IMM,SH_OPC - e.g. R5, LSL #3
Owen Anderson152d4a42011-07-21 23:38:37 +0000244void ARMInstPrinter::printSORegRegOperand(const MCInst *MI, unsigned OpNum,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000245 raw_ostream &O) {
Chris Lattner017d9472009-10-20 00:40:56 +0000246 const MCOperand &MO1 = MI->getOperand(OpNum);
247 const MCOperand &MO2 = MI->getOperand(OpNum+1);
248 const MCOperand &MO3 = MI->getOperand(OpNum+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000249
Chris Lattner017d9472009-10-20 00:40:56 +0000250 O << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000251
Chris Lattner017d9472009-10-20 00:40:56 +0000252 // Print the shift opc.
Bob Wilson1d9125a2010-08-05 00:34:42 +0000253 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO3.getImm());
254 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
Jim Grosbache8606dc2011-07-13 17:50:29 +0000255 if (ShOpc == ARM_AM::rrx)
256 return;
Jim Grosbach293a5f62011-10-21 16:56:40 +0000257
Owen Anderson152d4a42011-07-21 23:38:37 +0000258 O << ' ' << getRegisterName(MO2.getReg());
259 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
Chris Lattner017d9472009-10-20 00:40:56 +0000260}
Chris Lattner084f87d2009-10-19 21:57:05 +0000261
Owen Anderson152d4a42011-07-21 23:38:37 +0000262void ARMInstPrinter::printSORegImmOperand(const MCInst *MI, unsigned OpNum,
263 raw_ostream &O) {
264 const MCOperand &MO1 = MI->getOperand(OpNum);
265 const MCOperand &MO2 = MI->getOperand(OpNum+1);
266
267 O << getRegisterName(MO1.getReg());
268
269 // Print the shift opc.
270 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
271 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
272 if (ShOpc == ARM_AM::rrx)
273 return;
Owen Anderson3dac0be2011-08-11 18:41:59 +0000274 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Owen Anderson152d4a42011-07-21 23:38:37 +0000275}
276
277
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000278//===--------------------------------------------------------------------===//
279// Addressing Mode #2
280//===--------------------------------------------------------------------===//
281
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000282void ARMInstPrinter::printAM2PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
283 raw_ostream &O) {
Chris Lattner084f87d2009-10-19 21:57:05 +0000284 const MCOperand &MO1 = MI->getOperand(Op);
285 const MCOperand &MO2 = MI->getOperand(Op+1);
286 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000287
Chris Lattner084f87d2009-10-19 21:57:05 +0000288 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000289
Chris Lattner084f87d2009-10-19 21:57:05 +0000290 if (!MO2.getReg()) {
Johnny Chen9e088762010-03-17 17:52:21 +0000291 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
Chris Lattner084f87d2009-10-19 21:57:05 +0000292 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000293 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
294 << ARM_AM::getAM2Offset(MO3.getImm());
Chris Lattner084f87d2009-10-19 21:57:05 +0000295 O << "]";
296 return;
297 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000298
Chris Lattner084f87d2009-10-19 21:57:05 +0000299 O << ", "
Johnny Chen9e088762010-03-17 17:52:21 +0000300 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
301 << getRegisterName(MO2.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000302
Chris Lattner084f87d2009-10-19 21:57:05 +0000303 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
304 O << ", "
305 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
306 << " #" << ShImm;
307 O << "]";
Jim Grosbach15d78982010-09-14 22:27:15 +0000308}
Chris Lattnere306d8d2009-10-19 22:09:23 +0000309
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000310void ARMInstPrinter::printAM2PostIndexOp(const MCInst *MI, unsigned Op,
311 raw_ostream &O) {
312 const MCOperand &MO1 = MI->getOperand(Op);
313 const MCOperand &MO2 = MI->getOperand(Op+1);
314 const MCOperand &MO3 = MI->getOperand(Op+2);
315
316 O << "[" << getRegisterName(MO1.getReg()) << "], ";
317
318 if (!MO2.getReg()) {
319 unsigned ImmOffs = ARM_AM::getAM2Offset(MO3.getImm());
320 O << '#'
321 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
322 << ImmOffs;
323 return;
324 }
325
326 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
327 << getRegisterName(MO2.getReg());
328
329 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
330 O << ", "
331 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
332 << " #" << ShImm;
333}
334
Jim Grosbach7f739be2011-09-19 22:21:13 +0000335void ARMInstPrinter::printAddrModeTBB(const MCInst *MI, unsigned Op,
336 raw_ostream &O) {
337 const MCOperand &MO1 = MI->getOperand(Op);
338 const MCOperand &MO2 = MI->getOperand(Op+1);
339 O << "[" << getRegisterName(MO1.getReg()) << ", "
340 << getRegisterName(MO2.getReg()) << "]";
341}
342
343void ARMInstPrinter::printAddrModeTBH(const MCInst *MI, unsigned Op,
344 raw_ostream &O) {
345 const MCOperand &MO1 = MI->getOperand(Op);
346 const MCOperand &MO2 = MI->getOperand(Op+1);
347 O << "[" << getRegisterName(MO1.getReg()) << ", "
348 << getRegisterName(MO2.getReg()) << ", lsl #1]";
349}
350
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000351void ARMInstPrinter::printAddrMode2Operand(const MCInst *MI, unsigned Op,
352 raw_ostream &O) {
353 const MCOperand &MO1 = MI->getOperand(Op);
354
355 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
356 printOperand(MI, Op, O);
357 return;
358 }
359
360 const MCOperand &MO3 = MI->getOperand(Op+2);
361 unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm());
362
363 if (IdxMode == ARMII::IndexModePost) {
364 printAM2PostIndexOp(MI, Op, O);
365 return;
366 }
367 printAM2PreOrOffsetIndexOp(MI, Op, O);
368}
369
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000370void ARMInstPrinter::printAddrMode2OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000371 unsigned OpNum,
372 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000373 const MCOperand &MO1 = MI->getOperand(OpNum);
374 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000375
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000376 if (!MO1.getReg()) {
377 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000378 O << '#'
379 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
380 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000381 return;
382 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000383
Johnny Chen9e088762010-03-17 17:52:21 +0000384 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
385 << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000386
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000387 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
388 O << ", "
389 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
390 << " #" << ShImm;
391}
392
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000393//===--------------------------------------------------------------------===//
394// Addressing Mode #3
395//===--------------------------------------------------------------------===//
396
397void ARMInstPrinter::printAM3PostIndexOp(const MCInst *MI, unsigned Op,
398 raw_ostream &O) {
399 const MCOperand &MO1 = MI->getOperand(Op);
400 const MCOperand &MO2 = MI->getOperand(Op+1);
401 const MCOperand &MO3 = MI->getOperand(Op+2);
402
403 O << "[" << getRegisterName(MO1.getReg()) << "], ";
404
405 if (MO2.getReg()) {
406 O << (char)ARM_AM::getAM3Op(MO3.getImm())
407 << getRegisterName(MO2.getReg());
408 return;
409 }
410
411 unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm());
412 O << '#'
413 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
414 << ImmOffs;
415}
416
417void ARMInstPrinter::printAM3PreOrOffsetIndexOp(const MCInst *MI, unsigned Op,
418 raw_ostream &O) {
419 const MCOperand &MO1 = MI->getOperand(Op);
420 const MCOperand &MO2 = MI->getOperand(Op+1);
421 const MCOperand &MO3 = MI->getOperand(Op+2);
Jim Grosbach15d78982010-09-14 22:27:15 +0000422
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000423 O << '[' << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000424
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000425 if (MO2.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000426 O << ", " << getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000427 << getRegisterName(MO2.getReg()) << ']';
428 return;
429 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000430
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000431 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
432 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000433 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
434 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000435 O << ']';
436}
437
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000438void ARMInstPrinter::printAddrMode3Operand(const MCInst *MI, unsigned Op,
439 raw_ostream &O) {
Jim Grosbach2f196742011-12-19 23:06:24 +0000440 const MCOperand &MO1 = MI->getOperand(Op);
441 if (!MO1.isReg()) { // For label symbolic references.
442 printOperand(MI, Op, O);
443 return;
444 }
445
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000446 const MCOperand &MO3 = MI->getOperand(Op+2);
447 unsigned IdxMode = ARM_AM::getAM3IdxMode(MO3.getImm());
448
449 if (IdxMode == ARMII::IndexModePost) {
450 printAM3PostIndexOp(MI, Op, O);
451 return;
452 }
453 printAM3PreOrOffsetIndexOp(MI, Op, O);
454}
455
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000456void ARMInstPrinter::printAddrMode3OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000457 unsigned OpNum,
458 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000459 const MCOperand &MO1 = MI->getOperand(OpNum);
460 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000461
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000462 if (MO1.getReg()) {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000463 O << getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
464 << getRegisterName(MO1.getReg());
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000465 return;
466 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000467
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000468 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000469 O << '#'
470 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
471 << ImmOffs;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000472}
473
Jim Grosbach7ce05792011-08-03 23:50:40 +0000474void ARMInstPrinter::printPostIdxImm8Operand(const MCInst *MI,
475 unsigned OpNum,
476 raw_ostream &O) {
477 const MCOperand &MO = MI->getOperand(OpNum);
478 unsigned Imm = MO.getImm();
479 O << '#' << ((Imm & 256) ? "" : "-") << (Imm & 0xff);
480}
481
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000482void ARMInstPrinter::printPostIdxRegOperand(const MCInst *MI, unsigned OpNum,
483 raw_ostream &O) {
484 const MCOperand &MO1 = MI->getOperand(OpNum);
485 const MCOperand &MO2 = MI->getOperand(OpNum+1);
486
Jim Grosbach16578b52011-08-05 16:11:38 +0000487 O << (MO2.getImm() ? "" : "-") << getRegisterName(MO1.getReg());
Jim Grosbachca8c70b2011-08-05 15:48:21 +0000488}
489
Owen Anderson154c41d2011-08-04 18:24:14 +0000490void ARMInstPrinter::printPostIdxImm8s4Operand(const MCInst *MI,
491 unsigned OpNum,
492 raw_ostream &O) {
493 const MCOperand &MO = MI->getOperand(OpNum);
494 unsigned Imm = MO.getImm();
495 O << '#' << ((Imm & 256) ? "" : "-") << ((Imm & 0xff) << 2);
496}
497
498
Jim Grosbache6913602010-11-03 01:01:43 +0000499void ARMInstPrinter::printLdStmModeOperand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000500 raw_ostream &O) {
Jim Grosbache6913602010-11-03 01:01:43 +0000501 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MI->getOperand(OpNum)
502 .getImm());
503 O << ARM_AM::getAMSubModeStr(Mode);
Chris Lattnere306d8d2009-10-19 22:09:23 +0000504}
505
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000506void ARMInstPrinter::printAddrMode5Operand(const MCInst *MI, unsigned OpNum,
Jim Grosbach0a2287b2010-11-03 01:11:15 +0000507 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000508 const MCOperand &MO1 = MI->getOperand(OpNum);
509 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000510
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000511 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000512 printOperand(MI, OpNum, O);
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000513 return;
514 }
Jim Grosbach15d78982010-09-14 22:27:15 +0000515
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000516 O << "[" << getRegisterName(MO1.getReg());
Jim Grosbach15d78982010-09-14 22:27:15 +0000517
Owen Anderson0da10cf2011-08-29 19:36:44 +0000518 unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm());
519 unsigned Op = ARM_AM::getAM5Op(MO2.getImm());
520 if (ImmOffs || Op == ARM_AM::sub) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000521 O << ", #"
Johnny Chen9e088762010-03-17 17:52:21 +0000522 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000523 << ImmOffs * 4;
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000524 }
525 O << "]";
526}
527
Chris Lattner35c33bd2010-04-04 04:47:45 +0000528void ARMInstPrinter::printAddrMode6Operand(const MCInst *MI, unsigned OpNum,
529 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000530 const MCOperand &MO1 = MI->getOperand(OpNum);
531 const MCOperand &MO2 = MI->getOperand(OpNum+1);
Jim Grosbach15d78982010-09-14 22:27:15 +0000532
Bob Wilson226036e2010-03-20 22:13:40 +0000533 O << "[" << getRegisterName(MO1.getReg());
534 if (MO2.getImm()) {
535 // FIXME: Both darwin as and GNU as violate ARM docs here.
Bob Wilson273ff312010-07-14 23:54:43 +0000536 O << ", :" << (MO2.getImm() << 3);
Chris Lattner235e2f62009-10-20 06:22:33 +0000537 }
Bob Wilson226036e2010-03-20 22:13:40 +0000538 O << "]";
539}
540
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000541void ARMInstPrinter::printAddrMode7Operand(const MCInst *MI, unsigned OpNum,
542 raw_ostream &O) {
543 const MCOperand &MO1 = MI->getOperand(OpNum);
544 O << "[" << getRegisterName(MO1.getReg()) << "]";
545}
546
Bob Wilson226036e2010-03-20 22:13:40 +0000547void ARMInstPrinter::printAddrMode6OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000548 unsigned OpNum,
549 raw_ostream &O) {
Bob Wilson226036e2010-03-20 22:13:40 +0000550 const MCOperand &MO = MI->getOperand(OpNum);
551 if (MO.getReg() == 0)
552 O << "!";
553 else
554 O << ", " << getRegisterName(MO.getReg());
Chris Lattner235e2f62009-10-20 06:22:33 +0000555}
556
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000557void ARMInstPrinter::printBitfieldInvMaskImmOperand(const MCInst *MI,
558 unsigned OpNum,
559 raw_ostream &O) {
Chris Lattner235e2f62009-10-20 06:22:33 +0000560 const MCOperand &MO = MI->getOperand(OpNum);
561 uint32_t v = ~MO.getImm();
562 int32_t lsb = CountTrailingZeros_32(v);
563 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
564 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
565 O << '#' << lsb << ", #" << width;
566}
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000567
Johnny Chen1adc40c2010-08-12 20:46:17 +0000568void ARMInstPrinter::printMemBOption(const MCInst *MI, unsigned OpNum,
569 raw_ostream &O) {
570 unsigned val = MI->getOperand(OpNum).getImm();
571 O << ARM_MB::MemBOptToString(val);
572}
573
Bob Wilson22f5dc72010-08-16 18:27:34 +0000574void ARMInstPrinter::printShiftImmOperand(const MCInst *MI, unsigned OpNum,
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000575 raw_ostream &O) {
576 unsigned ShiftOp = MI->getOperand(OpNum).getImm();
Jim Grosbach580f4a92011-07-25 22:20:28 +0000577 bool isASR = (ShiftOp & (1 << 5)) != 0;
578 unsigned Amt = ShiftOp & 0x1f;
579 if (isASR)
580 O << ", asr #" << (Amt == 0 ? 32 : Amt);
581 else if (Amt)
582 O << ", lsl #" << Amt;
Bob Wilsoneaf1c982010-08-11 23:10:46 +0000583}
584
Jim Grosbachdde038a2011-07-20 21:40:26 +0000585void ARMInstPrinter::printPKHLSLShiftImm(const MCInst *MI, unsigned OpNum,
586 raw_ostream &O) {
587 unsigned Imm = MI->getOperand(OpNum).getImm();
588 if (Imm == 0)
589 return;
590 assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!");
591 O << ", lsl #" << Imm;
592}
593
594void ARMInstPrinter::printPKHASRShiftImm(const MCInst *MI, unsigned OpNum,
595 raw_ostream &O) {
596 unsigned Imm = MI->getOperand(OpNum).getImm();
597 // A shift amount of 32 is encoded as 0.
598 if (Imm == 0)
599 Imm = 32;
600 assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!");
601 O << ", asr #" << Imm;
602}
603
Chris Lattner35c33bd2010-04-04 04:47:45 +0000604void ARMInstPrinter::printRegisterList(const MCInst *MI, unsigned OpNum,
605 raw_ostream &O) {
Chris Lattnere306d8d2009-10-19 22:09:23 +0000606 O << "{";
Johnny Chen9e088762010-03-17 17:52:21 +0000607 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
608 if (i != OpNum) O << ", ";
Chris Lattnere306d8d2009-10-19 22:09:23 +0000609 O << getRegisterName(MI->getOperand(i).getReg());
610 }
611 O << "}";
612}
Chris Lattner4d152222009-10-19 22:23:04 +0000613
Jim Grosbachb3af5de2010-10-13 21:00:04 +0000614void ARMInstPrinter::printSetendOperand(const MCInst *MI, unsigned OpNum,
615 raw_ostream &O) {
616 const MCOperand &Op = MI->getOperand(OpNum);
617 if (Op.getImm())
618 O << "be";
619 else
620 O << "le";
621}
622
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000623void ARMInstPrinter::printCPSIMod(const MCInst *MI, unsigned OpNum,
624 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000625 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000626 O << ARM_PROC::IModToString(Op.getImm());
627}
628
629void ARMInstPrinter::printCPSIFlag(const MCInst *MI, unsigned OpNum,
630 raw_ostream &O) {
631 const MCOperand &Op = MI->getOperand(OpNum);
632 unsigned IFlags = Op.getImm();
633 for (int i=2; i >= 0; --i)
634 if (IFlags & (1 << i))
635 O << ARM_PROC::IFlagsToString(1 << i);
Owen Anderson2dbb46a2011-10-05 17:16:40 +0000636
637 if (IFlags == 0)
638 O << "none";
Johnny Chen9e088762010-03-17 17:52:21 +0000639}
640
Chris Lattner35c33bd2010-04-04 04:47:45 +0000641void ARMInstPrinter::printMSRMaskOperand(const MCInst *MI, unsigned OpNum,
642 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000643 const MCOperand &Op = MI->getOperand(OpNum);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000644 unsigned SpecRegRBit = Op.getImm() >> 4;
645 unsigned Mask = Op.getImm() & 0xf;
646
James Molloyacad68d2011-09-28 14:21:38 +0000647 if (getAvailableFeatures() & ARM::FeatureMClass) {
648 switch (Op.getImm()) {
Craig Topperbc219812012-02-07 02:50:20 +0000649 default: llvm_unreachable("Unexpected mask value!");
James Molloyacad68d2011-09-28 14:21:38 +0000650 case 0: O << "apsr"; return;
651 case 1: O << "iapsr"; return;
652 case 2: O << "eapsr"; return;
653 case 3: O << "xpsr"; return;
654 case 5: O << "ipsr"; return;
655 case 6: O << "epsr"; return;
656 case 7: O << "iepsr"; return;
657 case 8: O << "msp"; return;
658 case 9: O << "psp"; return;
659 case 16: O << "primask"; return;
660 case 17: O << "basepri"; return;
661 case 18: O << "basepri_max"; return;
662 case 19: O << "faultmask"; return;
663 case 20: O << "control"; return;
664 }
665 }
666
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000667 // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
668 // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
669 if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
670 O << "APSR_";
671 switch (Mask) {
Craig Topperbc219812012-02-07 02:50:20 +0000672 default: llvm_unreachable("Unexpected mask value!");
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000673 case 4: O << "g"; return;
674 case 8: O << "nzcvq"; return;
675 case 12: O << "nzcvqg"; return;
676 }
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000677 }
678
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000679 if (SpecRegRBit)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000680 O << "SPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000681 else
Jim Grosbachb29b4dd2011-07-19 22:45:10 +0000682 O << "CPSR";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000683
Johnny Chen9e088762010-03-17 17:52:21 +0000684 if (Mask) {
685 O << '_';
686 if (Mask & 8) O << 'f';
687 if (Mask & 4) O << 's';
688 if (Mask & 2) O << 'x';
689 if (Mask & 1) O << 'c';
690 }
691}
692
Chris Lattner35c33bd2010-04-04 04:47:45 +0000693void ARMInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum,
694 raw_ostream &O) {
Chris Lattner413ae252009-10-20 00:42:49 +0000695 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
Kevin Enderbyb0578512012-03-01 22:13:02 +0000696 // Handle the undefined 15 CC value here for printing so we don't abort().
697 if ((unsigned)CC == 15)
698 O << "<und>";
699 else if (CC != ARMCC::AL)
Chris Lattner413ae252009-10-20 00:42:49 +0000700 O << ARMCondCodeToString(CC);
701}
702
Jim Grosbach15d78982010-09-14 22:27:15 +0000703void ARMInstPrinter::printMandatoryPredicateOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000704 unsigned OpNum,
705 raw_ostream &O) {
Johnny Chen9d3acaa2010-03-02 17:57:15 +0000706 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
707 O << ARMCondCodeToString(CC);
708}
709
Chris Lattner35c33bd2010-04-04 04:47:45 +0000710void ARMInstPrinter::printSBitModifierOperand(const MCInst *MI, unsigned OpNum,
711 raw_ostream &O) {
Daniel Dunbara7cc6522009-10-20 22:10:05 +0000712 if (MI->getOperand(OpNum).getReg()) {
713 assert(MI->getOperand(OpNum).getReg() == ARM::CPSR &&
714 "Expect ARM CPSR register!");
Chris Lattner233917c2009-10-20 00:46:11 +0000715 O << 's';
716 }
717}
718
Chris Lattner35c33bd2010-04-04 04:47:45 +0000719void ARMInstPrinter::printNoHashImmediate(const MCInst *MI, unsigned OpNum,
720 raw_ostream &O) {
Chris Lattnerbf16faa2009-10-20 06:15:28 +0000721 O << MI->getOperand(OpNum).getImm();
722}
723
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000724void ARMInstPrinter::printPImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbachbc9c8022011-10-12 16:34:37 +0000725 raw_ostream &O) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000726 O << "p" << MI->getOperand(OpNum).getImm();
727}
728
729void ARMInstPrinter::printCImmediate(const MCInst *MI, unsigned OpNum,
Jim Grosbachbc9c8022011-10-12 16:34:37 +0000730 raw_ostream &O) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +0000731 O << "c" << MI->getOperand(OpNum).getImm();
732}
733
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000734void ARMInstPrinter::printCoprocOptionImm(const MCInst *MI, unsigned OpNum,
735 raw_ostream &O) {
736 O << "{" << MI->getOperand(OpNum).getImm() << "}";
737}
738
Chris Lattner35c33bd2010-04-04 04:47:45 +0000739void ARMInstPrinter::printPCLabel(const MCInst *MI, unsigned OpNum,
740 raw_ostream &O) {
Jim Grosbachd30cfde2010-09-18 00:04:53 +0000741 llvm_unreachable("Unhandled PC-relative pseudo-instruction!");
Chris Lattner4d152222009-10-19 22:23:04 +0000742}
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000743
Chris Lattner35c33bd2010-04-04 04:47:45 +0000744void ARMInstPrinter::printThumbS4ImmOperand(const MCInst *MI, unsigned OpNum,
745 raw_ostream &O) {
Jim Grosbach70939ee2011-08-17 21:51:27 +0000746 O << "#" << MI->getOperand(OpNum).getImm() * 4;
747}
748
749void ARMInstPrinter::printThumbSRImm(const MCInst *MI, unsigned OpNum,
750 raw_ostream &O) {
751 unsigned Imm = MI->getOperand(OpNum).getImm();
752 O << "#" << (Imm == 0 ? 32 : Imm);
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000753}
Johnny Chen9e088762010-03-17 17:52:21 +0000754
Chris Lattner35c33bd2010-04-04 04:47:45 +0000755void ARMInstPrinter::printThumbITMask(const MCInst *MI, unsigned OpNum,
756 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000757 // (3 - the number of trailing zeros) is the number of then / else.
758 unsigned Mask = MI->getOperand(OpNum).getImm();
759 unsigned CondBit0 = Mask >> 4 & 1;
760 unsigned NumTZ = CountTrailingZeros_32(Mask);
761 assert(NumTZ <= 3 && "Invalid IT mask!");
762 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
763 bool T = ((Mask >> Pos) & 1) == CondBit0;
764 if (T)
765 O << 't';
766 else
767 O << 'e';
768 }
769}
770
Chris Lattner35c33bd2010-04-04 04:47:45 +0000771void ARMInstPrinter::printThumbAddrModeRROperand(const MCInst *MI, unsigned Op,
772 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000773 const MCOperand &MO1 = MI->getOperand(Op);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000774 const MCOperand &MO2 = MI->getOperand(Op + 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000775
776 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
Chris Lattner35c33bd2010-04-04 04:47:45 +0000777 printOperand(MI, Op, O);
Johnny Chen9e088762010-03-17 17:52:21 +0000778 return;
779 }
780
781 O << "[" << getRegisterName(MO1.getReg());
Bill Wendlingf4caf692010-12-14 03:36:38 +0000782 if (unsigned RegNum = MO2.getReg())
783 O << ", " << getRegisterName(RegNum);
784 O << "]";
785}
786
787void ARMInstPrinter::printThumbAddrModeImm5SOperand(const MCInst *MI,
788 unsigned Op,
789 raw_ostream &O,
790 unsigned Scale) {
791 const MCOperand &MO1 = MI->getOperand(Op);
792 const MCOperand &MO2 = MI->getOperand(Op + 1);
793
794 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
795 printOperand(MI, Op, O);
796 return;
797 }
798
799 O << "[" << getRegisterName(MO1.getReg());
800 if (unsigned ImmOffs = MO2.getImm())
Johnny Chen9e088762010-03-17 17:52:21 +0000801 O << ", #" << ImmOffs * Scale;
802 O << "]";
803}
804
Bill Wendlingf4caf692010-12-14 03:36:38 +0000805void ARMInstPrinter::printThumbAddrModeImm5S1Operand(const MCInst *MI,
806 unsigned Op,
807 raw_ostream &O) {
808 printThumbAddrModeImm5SOperand(MI, Op, O, 1);
Johnny Chen9e088762010-03-17 17:52:21 +0000809}
810
Bill Wendlingf4caf692010-12-14 03:36:38 +0000811void ARMInstPrinter::printThumbAddrModeImm5S2Operand(const MCInst *MI,
812 unsigned Op,
813 raw_ostream &O) {
814 printThumbAddrModeImm5SOperand(MI, Op, O, 2);
Johnny Chen9e088762010-03-17 17:52:21 +0000815}
816
Bill Wendlingf4caf692010-12-14 03:36:38 +0000817void ARMInstPrinter::printThumbAddrModeImm5S4Operand(const MCInst *MI,
818 unsigned Op,
819 raw_ostream &O) {
820 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000821}
822
Chris Lattner35c33bd2010-04-04 04:47:45 +0000823void ARMInstPrinter::printThumbAddrModeSPOperand(const MCInst *MI, unsigned Op,
824 raw_ostream &O) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000825 printThumbAddrModeImm5SOperand(MI, Op, O, 4);
Johnny Chen9e088762010-03-17 17:52:21 +0000826}
827
Johnny Chen9e088762010-03-17 17:52:21 +0000828// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
829// register with shift forms.
830// REG 0 0 - e.g. R5
831// REG IMM, SH_OPC - e.g. R5, LSL #3
Chris Lattner35c33bd2010-04-04 04:47:45 +0000832void ARMInstPrinter::printT2SOOperand(const MCInst *MI, unsigned OpNum,
833 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000834 const MCOperand &MO1 = MI->getOperand(OpNum);
835 const MCOperand &MO2 = MI->getOperand(OpNum+1);
836
837 unsigned Reg = MO1.getReg();
838 O << getRegisterName(Reg);
839
840 // Print the shift opc.
Johnny Chen9e088762010-03-17 17:52:21 +0000841 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
Bob Wilson1d9125a2010-08-05 00:34:42 +0000842 ARM_AM::ShiftOpc ShOpc = ARM_AM::getSORegShOp(MO2.getImm());
843 O << ", " << ARM_AM::getShiftOpcStr(ShOpc);
844 if (ShOpc != ARM_AM::rrx)
Owen Anderson3dac0be2011-08-11 18:41:59 +0000845 O << " #" << translateShiftImm(ARM_AM::getSORegOffset(MO2.getImm()));
Johnny Chen9e088762010-03-17 17:52:21 +0000846}
847
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000848void ARMInstPrinter::printAddrModeImm12Operand(const MCInst *MI, unsigned OpNum,
849 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000850 const MCOperand &MO1 = MI->getOperand(OpNum);
851 const MCOperand &MO2 = MI->getOperand(OpNum+1);
852
Jim Grosbach3e556122010-10-26 22:37:02 +0000853 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
854 printOperand(MI, OpNum, O);
855 return;
856 }
857
Johnny Chen9e088762010-03-17 17:52:21 +0000858 O << "[" << getRegisterName(MO1.getReg());
859
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000860 int32_t OffImm = (int32_t)MO2.getImm();
Jim Grosbachab682a22010-10-28 18:34:10 +0000861 bool isSub = OffImm < 0;
862 // Special value for #-0. All others are normal.
863 if (OffImm == INT32_MIN)
864 OffImm = 0;
865 if (isSub)
Jim Grosbach77aee8e2010-10-27 01:19:41 +0000866 O << ", #-" << -OffImm;
867 else if (OffImm > 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000868 O << ", #" << OffImm;
869 O << "]";
870}
871
872void ARMInstPrinter::printT2AddrModeImm8Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000873 unsigned OpNum,
874 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000875 const MCOperand &MO1 = MI->getOperand(OpNum);
876 const MCOperand &MO2 = MI->getOperand(OpNum+1);
877
878 O << "[" << getRegisterName(MO1.getReg());
879
880 int32_t OffImm = (int32_t)MO2.getImm();
881 // Don't print +0.
Owen Anderson705b48f2011-09-16 21:08:33 +0000882 if (OffImm == INT32_MIN)
883 O << ", #-0";
884 else if (OffImm < 0)
Johnny Chen9e088762010-03-17 17:52:21 +0000885 O << ", #-" << -OffImm;
886 else if (OffImm > 0)
887 O << ", #" << OffImm;
888 O << "]";
889}
890
891void ARMInstPrinter::printT2AddrModeImm8s4Operand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000892 unsigned OpNum,
893 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000894 const MCOperand &MO1 = MI->getOperand(OpNum);
895 const MCOperand &MO2 = MI->getOperand(OpNum+1);
896
Jim Grosbach2f196742011-12-19 23:06:24 +0000897 if (!MO1.isReg()) { // For label symbolic references.
898 printOperand(MI, OpNum, O);
899 return;
900 }
901
Johnny Chen9e088762010-03-17 17:52:21 +0000902 O << "[" << getRegisterName(MO1.getReg());
903
904 int32_t OffImm = (int32_t)MO2.getImm() / 4;
905 // Don't print +0.
906 if (OffImm < 0)
907 O << ", #-" << -OffImm * 4;
908 else if (OffImm > 0)
909 O << ", #" << OffImm * 4;
910 O << "]";
911}
912
Jim Grosbachb6aed502011-09-09 18:37:27 +0000913void ARMInstPrinter::printT2AddrModeImm0_1020s4Operand(const MCInst *MI,
914 unsigned OpNum,
915 raw_ostream &O) {
916 const MCOperand &MO1 = MI->getOperand(OpNum);
917 const MCOperand &MO2 = MI->getOperand(OpNum+1);
918
919 O << "[" << getRegisterName(MO1.getReg());
920 if (MO2.getImm())
921 O << ", #" << MO2.getImm() * 4;
922 O << "]";
923}
924
Johnny Chen9e088762010-03-17 17:52:21 +0000925void ARMInstPrinter::printT2AddrModeImm8OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000926 unsigned OpNum,
927 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000928 const MCOperand &MO1 = MI->getOperand(OpNum);
929 int32_t OffImm = (int32_t)MO1.getImm();
930 // Don't print +0.
931 if (OffImm < 0)
Owen Anderson0781c1f2011-09-23 21:26:40 +0000932 O << ", #-" << -OffImm;
933 else
934 O << ", #" << OffImm;
Johnny Chen9e088762010-03-17 17:52:21 +0000935}
936
937void ARMInstPrinter::printT2AddrModeImm8s4OffsetOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000938 unsigned OpNum,
939 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000940 const MCOperand &MO1 = MI->getOperand(OpNum);
941 int32_t OffImm = (int32_t)MO1.getImm() / 4;
942 // Don't print +0.
Owen Anderson7782a582011-09-13 20:46:26 +0000943 if (OffImm != 0) {
944 O << ", ";
945 if (OffImm < 0)
946 O << "#-" << -OffImm * 4;
947 else if (OffImm > 0)
948 O << "#" << OffImm * 4;
949 }
Johnny Chen9e088762010-03-17 17:52:21 +0000950}
951
952void ARMInstPrinter::printT2AddrModeSoRegOperand(const MCInst *MI,
Chris Lattner35c33bd2010-04-04 04:47:45 +0000953 unsigned OpNum,
954 raw_ostream &O) {
Johnny Chen9e088762010-03-17 17:52:21 +0000955 const MCOperand &MO1 = MI->getOperand(OpNum);
956 const MCOperand &MO2 = MI->getOperand(OpNum+1);
957 const MCOperand &MO3 = MI->getOperand(OpNum+2);
958
959 O << "[" << getRegisterName(MO1.getReg());
960
961 assert(MO2.getReg() && "Invalid so_reg load / store address!");
962 O << ", " << getRegisterName(MO2.getReg());
963
964 unsigned ShAmt = MO3.getImm();
965 if (ShAmt) {
966 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
967 O << ", lsl #" << ShAmt;
968 }
969 O << "]";
970}
971
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000972void ARMInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
973 raw_ostream &O) {
Bill Wendling8cb415e2011-01-26 20:57:43 +0000974 const MCOperand &MO = MI->getOperand(OpNum);
Jim Grosbach4ebbf7b2011-09-30 00:50:06 +0000975 O << '#' << ARM_AM::getFPImmFloat(MO.getImm());
Johnny Chen9e088762010-03-17 17:52:21 +0000976}
977
Bob Wilson1a913ed2010-06-11 21:34:50 +0000978void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,
979 raw_ostream &O) {
Bob Wilson6dce00c2010-07-13 04:44:34 +0000980 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
981 unsigned EltBits;
982 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
Benjamin Kramer70be28a2011-11-07 21:00:59 +0000983 O << "#0x";
984 O.write_hex(Val);
Johnny Chenc7b65912010-04-16 22:40:20 +0000985}
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000986
Jim Grosbachf4943352011-07-25 23:09:14 +0000987void ARMInstPrinter::printImmPlusOneOperand(const MCInst *MI, unsigned OpNum,
988 raw_ostream &O) {
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000989 unsigned Imm = MI->getOperand(OpNum).getImm();
990 O << "#" << Imm + 1;
991}
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000992
993void ARMInstPrinter::printRotImmOperand(const MCInst *MI, unsigned OpNum,
994 raw_ostream &O) {
995 unsigned Imm = MI->getOperand(OpNum).getImm();
996 if (Imm == 0)
997 return;
Jim Grosbach45f39292011-07-26 21:44:37 +0000998 O << ", ror #";
Jim Grosbach85bfd3b2011-07-26 21:28:43 +0000999 switch (Imm) {
1000 default: assert (0 && "illegal ror immediate!");
Jim Grosbach2f815c02011-08-17 23:23:07 +00001001 case 1: O << "8"; break;
1002 case 2: O << "16"; break;
1003 case 3: O << "24"; break;
Jim Grosbach85bfd3b2011-07-26 21:28:43 +00001004 }
1005}
Jim Grosbach460a9052011-10-07 23:56:00 +00001006
Jim Grosbach4050bc42011-12-22 22:19:05 +00001007void ARMInstPrinter::printFBits16(const MCInst *MI, unsigned OpNum,
1008 raw_ostream &O) {
1009 O << "#" << 16 - MI->getOperand(OpNum).getImm();
1010}
1011
1012void ARMInstPrinter::printFBits32(const MCInst *MI, unsigned OpNum,
1013 raw_ostream &O) {
1014 O << "#" << 32 - MI->getOperand(OpNum).getImm();
1015}
1016
Jim Grosbach460a9052011-10-07 23:56:00 +00001017void ARMInstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
1018 raw_ostream &O) {
1019 O << "[" << MI->getOperand(OpNum).getImm() << "]";
1020}
Jim Grosbach862019c2011-10-18 23:02:30 +00001021
1022void ARMInstPrinter::printVectorListOne(const MCInst *MI, unsigned OpNum,
1023 raw_ostream &O) {
1024 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "}";
1025}
Jim Grosbach280dfad2011-10-21 18:54:25 +00001026
1027void ARMInstPrinter::printVectorListTwo(const MCInst *MI, unsigned OpNum,
1028 raw_ostream &O) {
1029 // Normally, it's not safe to use register enum values directly with
1030 // addition to get the next register, but for VFP registers, the
1031 // sort order is guaranteed because they're all of the form D<n>.
1032 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1033 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "}";
1034}
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001035
1036void ARMInstPrinter::printVectorListThree(const MCInst *MI, unsigned OpNum,
1037 raw_ostream &O) {
1038 // Normally, it's not safe to use register enum values directly with
1039 // addition to get the next register, but for VFP registers, the
1040 // sort order is guaranteed because they're all of the form D<n>.
1041 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1042 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1043 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1044}
Jim Grosbachb6310312011-10-21 20:35:01 +00001045
1046void ARMInstPrinter::printVectorListFour(const MCInst *MI, unsigned OpNum,
1047 raw_ostream &O) {
1048 // Normally, it's not safe to use register enum values directly with
1049 // addition to get the next register, but for VFP registers, the
1050 // sort order is guaranteed because they're all of the form D<n>.
1051 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1052 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << ", "
1053 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1054 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "}";
1055}
Jim Grosbach98b05a52011-11-30 01:09:44 +00001056
1057void ARMInstPrinter::printVectorListOneAllLanes(const MCInst *MI,
1058 unsigned OpNum,
1059 raw_ostream &O) {
1060 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[]}";
1061}
1062
Jim Grosbach13af2222011-11-30 18:21:25 +00001063void ARMInstPrinter::printVectorListTwoAllLanes(const MCInst *MI,
1064 unsigned OpNum,
1065 raw_ostream &O) {
1066 // Normally, it's not safe to use register enum values directly with
1067 // addition to get the next register, but for VFP registers, the
1068 // sort order is guaranteed because they're all of the form D<n>.
1069 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1070 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[]}";
1071}
Jim Grosbache90ac9b2011-12-14 19:35:22 +00001072
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001073void ARMInstPrinter::printVectorListThreeAllLanes(const MCInst *MI,
1074 unsigned OpNum,
1075 raw_ostream &O) {
1076 // Normally, it's not safe to use register enum values directly with
1077 // addition to get the next register, but for VFP registers, the
1078 // sort order is guaranteed because they're all of the form D<n>.
1079 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1080 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1081 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[]}";
1082}
1083
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001084void ARMInstPrinter::printVectorListFourAllLanes(const MCInst *MI,
1085 unsigned OpNum,
1086 raw_ostream &O) {
1087 // Normally, it's not safe to use register enum values directly with
1088 // addition to get the next register, but for VFP registers, the
1089 // sort order is guaranteed because they're all of the form D<n>.
1090 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1091 << getRegisterName(MI->getOperand(OpNum).getReg() + 1) << "[], "
1092 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1093 << getRegisterName(MI->getOperand(OpNum).getReg() + 3) << "[]}";
1094}
1095
Jim Grosbache90ac9b2011-12-14 19:35:22 +00001096void ARMInstPrinter::printVectorListTwoSpaced(const MCInst *MI, unsigned OpNum,
1097 raw_ostream &O) {
1098 // Normally, it's not safe to use register enum values directly with
1099 // addition to get the next register, but for VFP registers, the
1100 // sort order is guaranteed because they're all of the form D<n>.
1101 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1102 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "}";
1103}
1104
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001105void ARMInstPrinter::printVectorListTwoSpacedAllLanes(const MCInst *MI,
1106 unsigned OpNum,
1107 raw_ostream &O) {
1108 // Normally, it's not safe to use register enum values directly with
1109 // addition to get the next register, but for VFP registers, the
1110 // sort order is guaranteed because they're all of the form D<n>.
1111 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1112 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[]}";
1113}
1114
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001115void ARMInstPrinter::printVectorListThreeSpacedAllLanes(const MCInst *MI,
1116 unsigned OpNum,
1117 raw_ostream &O) {
1118 // Normally, it's not safe to use register enum values directly with
1119 // addition to get the next register, but for VFP registers, the
1120 // sort order is guaranteed because they're all of the form D<n>.
1121 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1122 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001123 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[]}";
1124}
1125
1126void ARMInstPrinter::printVectorListFourSpacedAllLanes(const MCInst *MI,
1127 unsigned OpNum,
1128 raw_ostream &O) {
1129 // Normally, it's not safe to use register enum values directly with
1130 // addition to get the next register, but for VFP registers, the
1131 // sort order is guaranteed because they're all of the form D<n>.
1132 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << "[], "
1133 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << "[], "
1134 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "[], "
1135 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "[]}";
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001136}
1137
Jim Grosbachc387fc62012-01-23 23:20:46 +00001138void ARMInstPrinter::printVectorListThreeSpaced(const MCInst *MI,
1139 unsigned OpNum,
1140 raw_ostream &O) {
1141 // Normally, it's not safe to use register enum values directly with
1142 // addition to get the next register, but for VFP registers, the
1143 // sort order is guaranteed because they're all of the form D<n>.
1144 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1145 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1146 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << "}";
1147}
Jim Grosbach8abe7e32012-01-24 00:43:17 +00001148
1149void ARMInstPrinter::printVectorListFourSpaced(const MCInst *MI,
1150 unsigned OpNum,
1151 raw_ostream &O) {
1152 // Normally, it's not safe to use register enum values directly with
1153 // addition to get the next register, but for VFP registers, the
1154 // sort order is guaranteed because they're all of the form D<n>.
1155 O << "{" << getRegisterName(MI->getOperand(OpNum).getReg()) << ", "
1156 << getRegisterName(MI->getOperand(OpNum).getReg() + 2) << ", "
1157 << getRegisterName(MI->getOperand(OpNum).getReg() + 4) << ", "
1158 << getRegisterName(MI->getOperand(OpNum).getReg() + 6) << "}";
1159}