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/StringRef.h"
16 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCSymbol.h"
19 #include "llvm/Support/Casting.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/raw_ostream.h"
26 #define DEBUG_TYPE "asm-printer"
28 #include "XCoreGenAsmWriter.inc"
30 void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
31 OS << StringRef(getRegisterName(RegNo)).lower();
34 void XCoreInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
35 StringRef Annot, const MCSubtargetInfo &STI) {
36 printInstruction(MI, O);
37 printAnnotation(O, Annot);
40 void XCoreInstPrinter::
41 printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
42 report_fatal_error("can't handle InlineJT");
45 void XCoreInstPrinter::
46 printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
47 report_fatal_error("can't handle InlineJT32");
50 static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
53 const MCSymbolRefExpr *SRE;
55 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
56 SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
57 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
58 assert(SRE && CE && "Binary expression must be sym+const.");
59 Offset = CE->getValue();
61 SRE = dyn_cast<MCSymbolRefExpr>(Expr);
62 assert(SRE && "Unexpected MCExpr type.");
64 assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
66 SRE->getSymbol().print(OS, MAI);
75 void XCoreInstPrinter::
76 printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
77 const MCOperand &Op = MI->getOperand(OpNo);
79 printRegName(O, Op.getReg());
88 assert(Op.isExpr() && "unknown operand kind in printOperand");
89 printExpr(Op.getExpr(), &MAI, O);