1 //===-- XCoreInstPrinter.cpp - Convert XCore 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 XCore MCInst to a .s file.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "asm-printer"
15 #include "XCoreInstPrinter.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCSymbol.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/raw_ostream.h"
25 #include "XCoreGenAsmWriter.inc"
27 void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
28 OS << StringRef(getRegisterName(RegNo)).lower();
31 void XCoreInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
33 printInstruction(MI, O);
34 printAnnotation(O, Annot);
37 void XCoreInstPrinter::
38 printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
39 report_fatal_error("can't handle InlineJT");
42 void XCoreInstPrinter::
43 printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
44 report_fatal_error("can't handle InlineJT32");
47 static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
49 const MCSymbolRefExpr *SRE;
51 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
52 SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
53 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
54 assert(SRE && CE && "Binary expression must be sym+const.");
55 Offset = CE->getValue();
57 SRE = dyn_cast<MCSymbolRefExpr>(Expr);
58 assert(SRE && "Unexpected MCExpr type.");
60 assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
62 OS << SRE->getSymbol();
71 void XCoreInstPrinter::
72 printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
73 const MCOperand &Op = MI->getOperand(OpNo);
75 printRegName(O, Op.getReg());
84 assert(Op.isExpr() && "unknown operand kind in printOperand");
85 printExpr(Op.getExpr(), O);