[Darwin][Driver][clang] apple-none-macho orders the resource directory after internal...
[llvm-project.git] / llvm / lib / Target / XCore / MCTargetDesc / XCoreInstPrinter.cpp
blob707c4a790872805d4c6a88c704a49338ef0fb500
1 //===-- XCoreInstPrinter.cpp - Convert XCore MCInst to assembly syntax ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This class prints an XCore MCInst to a .s file.
11 //===----------------------------------------------------------------------===//
13 #include "XCoreInstPrinter.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCRegister.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"
22 #include <cassert>
24 using namespace llvm;
26 #define DEBUG_TYPE "asm-printer"
28 #include "XCoreGenAsmWriter.inc"
30 void XCoreInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) {
31 OS << StringRef(getRegisterName(Reg)).lower();
34 void XCoreInstPrinter::printInst(const MCInst *MI, uint64_t Address,
35 StringRef Annot, const MCSubtargetInfo &STI,
36 raw_ostream &O) {
37 printInstruction(MI, Address, O);
38 printAnnotation(O, Annot);
41 void XCoreInstPrinter::
42 printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
43 report_fatal_error("can't handle InlineJT");
46 void XCoreInstPrinter::
47 printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
48 report_fatal_error("can't handle InlineJT32");
51 static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
52 raw_ostream &OS) {
53 int Offset = 0;
54 const MCSymbolRefExpr *SRE;
56 if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
57 SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
58 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
59 assert(SRE && CE && "Binary expression must be sym+const.");
60 Offset = CE->getValue();
61 } else {
62 SRE = dyn_cast<MCSymbolRefExpr>(Expr);
63 assert(SRE && "Unexpected MCExpr type.");
65 assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
67 SRE->getSymbol().print(OS, MAI);
69 if (Offset) {
70 if (Offset > 0)
71 OS << '+';
72 OS << Offset;
76 void XCoreInstPrinter::
77 printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
78 const MCOperand &Op = MI->getOperand(OpNo);
79 if (Op.isReg()) {
80 printRegName(O, Op.getReg());
81 return;
84 if (Op.isImm()) {
85 O << Op.getImm();
86 return;
89 assert(Op.isExpr() && "unknown operand kind in printOperand");
90 printExpr(Op.getExpr(), &MAI, O);