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 #include "XCoreInstPrinter.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/raw_ostream.h"
24 #define DEBUG_TYPE "asm-printer"
26 #include "XCoreGenAsmWriter.inc"
28 void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
29 OS << StringRef(getRegisterName(RegNo)).lower();
32 void XCoreInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
33 StringRef Annot, const MCSubtargetInfo &STI) {
34 printInstruction(MI, O);
35 printAnnotation(O, Annot);
38 void XCoreInstPrinter::
39 printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
40 report_fatal_error("can't handle InlineJT");
43 void XCoreInstPrinter::
44 printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
45 report_fatal_error("can't handle InlineJT32");
48 static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
51 const MCSymbolRefExpr *SRE;
53 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
54 SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
55 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
56 assert(SRE && CE && "Binary expression must be sym+const.");
57 Offset = CE->getValue();
59 SRE = dyn_cast<MCSymbolRefExpr>(Expr);
60 assert(SRE && "Unexpected MCExpr type.");
62 assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
64 SRE->getSymbol().print(OS, MAI);
73 void XCoreInstPrinter::
74 printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
75 const MCOperand &Op = MI->getOperand(OpNo);
77 printRegName(O, Op.getReg());
86 assert(Op.isExpr() && "unknown operand kind in printOperand");
87 printExpr(Op.getExpr(), &MAI, O);