LLVM  14.0.0git
XCoreInstPrinter.cpp
Go to the documentation of this file.
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.
10 //
11 //===----------------------------------------------------------------------===//
12 
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/MCSymbol.h"
18 #include "llvm/Support/Casting.h"
21 #include <cassert>
22 
23 using namespace llvm;
24 
25 #define DEBUG_TYPE "asm-printer"
26 
27 #include "XCoreGenAsmWriter.inc"
28 
29 void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
30  OS << StringRef(getRegisterName(RegNo)).lower();
31 }
32 
34  StringRef Annot, const MCSubtargetInfo &STI,
35  raw_ostream &O) {
37  printAnnotation(O, Annot);
38 }
39 
40 void XCoreInstPrinter::
41 printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
42  report_fatal_error("can't handle InlineJT");
43 }
44 
45 void XCoreInstPrinter::
46 printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
47  report_fatal_error("can't handle InlineJT32");
48 }
49 
50 static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
51  raw_ostream &OS) {
52  int Offset = 0;
53  const MCSymbolRefExpr *SRE;
54 
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();
60  } else {
61  SRE = dyn_cast<MCSymbolRefExpr>(Expr);
62  assert(SRE && "Unexpected MCExpr type.");
63  }
65 
66  SRE->getSymbol().print(OS, MAI);
67 
68  if (Offset) {
69  if (Offset > 0)
70  OS << '+';
71  OS << Offset;
72  }
73 }
74 
75 void XCoreInstPrinter::
76 printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
77  const MCOperand &Op = MI->getOperand(OpNo);
78  if (Op.isReg()) {
79  printRegName(O, Op.getReg());
80  return;
81  }
82 
83  if (Op.isImm()) {
84  O << Op.getImm();
85  return;
86  }
87 
88  assert(Op.isExpr() && "unknown operand kind in printOperand");
89  printExpr(Op.getExpr(), &MAI, O);
90 }
llvm::MCSymbolRefExpr::getKind
VariantKind getKind() const
Definition: MCExpr.h:400
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
StringRef.h
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
printExpr
static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI, raw_ostream &OS)
Definition: XCoreInstPrinter.cpp:50
llvm::XCoreInstPrinter::printInstruction
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O)
ErrorHandling.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::XCoreInstPrinter::printInst
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override
Print the specified MCInst to the specified raw_ostream.
Definition: XCoreInstPrinter.cpp:33
XCoreInstPrinter.h
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCBinaryExpr
Binary assembler expressions.
Definition: MCExpr.h:480
MCSymbol.h
MCInst.h
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:398
llvm::MCSymbol::print
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59
llvm::MCInstPrinter::printAnnotation
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
Definition: MCInstPrinter.cpp:49
llvm::MCConstantExpr
Definition: MCExpr.h:144
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:192
uint64_t
llvm::XCoreInstPrinter::getRegisterName
static const char * getRegisterName(unsigned RegNo)
llvm::StringRef::lower
LLVM_NODISCARD std::string lower() const
Definition: StringRef.cpp:105
llvm::HighlightColor::Address
@ Address
llvm::XCoreInstPrinter::printRegName
void printRegName(raw_ostream &OS, unsigned RegNo) const override
Print the assembler register name.
Definition: XCoreInstPrinter.cpp:29
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:321
Casting.h
llvm::MCInstPrinter::MAI
const MCAsmInfo & MAI
Definition: MCInstPrinter.h:49
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
raw_ostream.h
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35