blob: 41be859ce0d2a9699208eca06720a7a43a095986 [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 Lattner6f997762009-10-19 21:53:00 +000019#include "llvm/MC/MCExpr.h"
20#include "llvm/Support/raw_ostream.h"
Chris Lattnerfd603822009-10-19 19:56:26 +000021#include "ARMGenInstrNames.inc"
22using namespace llvm;
23
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"
29#undef MachineInstr
30#undef ARMAsmPrinter
31
32void ARMInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
33
Chris Lattner8bc86cb2009-10-19 20:59:55 +000034void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
35 const char *Modifier) {
Chris Lattner6f997762009-10-19 21:53:00 +000036 // FIXME: TURN ASSERT ON.
37 //assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
Chris Lattner8bc86cb2009-10-19 20:59:55 +000038
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");
Chris Lattner6f997762009-10-19 21:53:00 +000046 Op.getExpr()->print(O, &MAI);
Chris Lattner8bc86cb2009-10-19 20:59:55 +000047 }
48}
Chris Lattner61d35c22009-10-19 21:21:39 +000049
50static 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!");
55
56 unsigned Imm = ARM_AM::getSOImmValImm(V);
57 unsigned Rot = ARM_AM::getSOImmValRot(V);
58
59 // Print low-level immediate formation info, per
60 // A5.1.3: "Data-processing operands - Immediate".
61 if (Rot) {
62 O << "#" << Imm << ", " << Rot;
63 // Pretty printed version.
64 if (VerboseAsm)
65 O << ' ' << MAI->getCommentString()
66 << ' ' << (int)ARM_AM::rotr32(Imm, Rot);
67 } else {
68 O << "#" << Imm;
69 }
70}
71
72
73/// printSOImmOperand - SOImm is 4-bit rotate amount in bits 8-11 with 8-bit
74/// immediate in bits 0-7.
75void 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);
79}