1 //===-- ARMInstPrinter.cpp - Convert ARM MCInst to assembly syntax --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class prints an ARM MCInst to a .s file.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "asm-printer"
15 #include "ARMInstPrinter.h"
16 #include "ARMAddressingModes.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include "ARMGenInstrNames.inc"
24 // Include the auto-generated portion of the assembly writer.
25 #define MachineInstr MCInst
26 #define ARMAsmPrinter ARMInstPrinter // FIXME: REMOVE.
27 #define NO_ASM_WRITER_BOILERPLATE
28 #include "ARMGenAsmWriter.inc"
32 void ARMInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
34 void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
35 const char *Modifier) {
36 // FIXME: TURN ASSERT ON.
37 //assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
39 const MCOperand &Op = MI->getOperand(OpNo);
41 O << getRegisterName(Op.getReg());
42 } else if (Op.isImm()) {
43 O << '#' << Op.getImm();
45 assert(Op.isExpr() && "unknown operand kind in printOperand");
46 Op.getExpr()->print(O, &MAI);
50 static void printSOImm(raw_ostream &O, int64_t V, bool VerboseAsm,
51 const MCAsmInfo *MAI) {
52 // Break it up into two parts that make up a shifter immediate.
53 V = ARM_AM::getSOImmVal(V);
54 assert(V != -1 && "Not a valid so_imm value!");
56 unsigned Imm = ARM_AM::getSOImmValImm(V);
57 unsigned Rot = ARM_AM::getSOImmValRot(V);
59 // Print low-level immediate formation info, per
60 // A5.1.3: "Data-processing operands - Immediate".
62 O << "#" << Imm << ", " << Rot;
63 // Pretty printed version.
65 O << ' ' << MAI->getCommentString()
66 << ' ' << (int)ARM_AM::rotr32(Imm, Rot);
73 /// printSOImmOperand - SOImm is 4-bit rotate amount in bits 8-11 with 8-bit
74 /// immediate in bits 0-7.
75 void ARMInstPrinter::printSOImmOperand(const MCInst *MI, unsigned OpNum) {
76 const MCOperand &MO = MI->getOperand(OpNum);
77 assert(MO.isImm() && "Not a valid so_imm value!");
78 printSOImm(O, MO.getImm(), VerboseAsm, &MAI);