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/ErrorHandling.h"
21 #include "llvm/Support/FormattedStream.h"
22 #include "ARMGenInstrNames.inc"
25 // Include the auto-generated portion of the assembly writer.
26 #define MachineInstr MCInst
27 #define ARMAsmPrinter ARMInstPrinter // FIXME: REMOVE.
28 #define NO_ASM_WRITER_BOILERPLATE
29 #include "ARMGenAsmWriter.inc"
33 void ARMInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
35 void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
36 const char *Modifier) {
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");
48 //Op.getExpr()->print(O, &MAI);
52 static void printSOImm(raw_ostream &O, int64_t V, bool VerboseAsm,
53 const MCAsmInfo *MAI) {
54 // Break it up into two parts that make up a shifter immediate.
55 V = ARM_AM::getSOImmVal(V);
56 assert(V != -1 && "Not a valid so_imm value!");
58 unsigned Imm = ARM_AM::getSOImmValImm(V);
59 unsigned Rot = ARM_AM::getSOImmValRot(V);
61 // Print low-level immediate formation info, per
62 // A5.1.3: "Data-processing operands - Immediate".
64 O << "#" << Imm << ", " << Rot;
65 // Pretty printed version.
67 O << ' ' << MAI->getCommentString()
68 << ' ' << (int)ARM_AM::rotr32(Imm, Rot);
75 /// printSOImmOperand - SOImm is 4-bit rotate amount in bits 8-11 with 8-bit
76 /// immediate in bits 0-7.
77 void ARMInstPrinter::printSOImmOperand(const MCInst *MI, unsigned OpNum) {
78 const MCOperand &MO = MI->getOperand(OpNum);
79 assert(MO.isImm() && "Not a valid so_imm value!");
80 printSOImm(O, MO.getImm(), VerboseAsm, &MAI);