add printing support for SOImm operands, getting us to:
[oota-llvm.git] / lib / Target / ARM / AsmPrinter / ARMInstPrinter.cpp
1 //===-- 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"
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"
23 using namespace llvm;
24
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"
30 #undef MachineInstr
31 #undef ARMAsmPrinter
32
33 void ARMInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
34
35 void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
36                                   const char *Modifier) {
37   assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
38   
39   const MCOperand &Op = MI->getOperand(OpNo);
40   if (Op.isReg()) {
41     O << getRegisterName(Op.getReg());
42   } else if (Op.isImm()) {
43     O << '#' << Op.getImm();
44   } else {
45     assert(Op.isExpr() && "unknown operand kind in printOperand");
46     assert(0 && "UNIMP");
47     //O << '$';
48     //Op.getExpr()->print(O, &MAI);
49   }
50 }
51
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!");
57   
58   unsigned Imm = ARM_AM::getSOImmValImm(V);
59   unsigned Rot = ARM_AM::getSOImmValRot(V);
60   
61   // Print low-level immediate formation info, per
62   // A5.1.3: "Data-processing operands - Immediate".
63   if (Rot) {
64     O << "#" << Imm << ", " << Rot;
65     // Pretty printed version.
66     if (VerboseAsm)
67       O << ' ' << MAI->getCommentString()
68       << ' ' << (int)ARM_AM::rotr32(Imm, Rot);
69   } else {
70     O << "#" << Imm;
71   }
72 }
73
74
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);
81 }