blob: 8393e241284d5f210b4afcb134b2755e02b885d1 [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"
Chris Lattner61d35c22009-10-19 21:21:39 +000016#include "ARMAddressingModes.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000017#include "llvm/MC/MCInst.h"
Chris Lattner61d35c22009-10-19 21:21:39 +000018#include "llvm/MC/MCAsmInfo.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000019//#include "llvm/MC/MCExpr.h"
20//#include "llvm/Support/ErrorHandling.h"
21#include "llvm/Support/FormattedStream.h"
22#include "ARMGenInstrNames.inc"
23using 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
33void ARMInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
34
Chris Lattner8bc86cb2009-10-19 20:59:55 +000035void 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}
Chris Lattner61d35c22009-10-19 21:21:39 +000051
52static 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.
77void 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}