LLVM 20.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/MCRegister.h"
18#include "llvm/MC/MCSymbol.h"
22#include <cassert>
23
24using namespace llvm;
25
26#define DEBUG_TYPE "asm-printer"
27
28#include "XCoreGenAsmWriter.inc"
29
32}
33
35 StringRef Annot, const MCSubtargetInfo &STI,
36 raw_ostream &O) {
38 printAnnotation(O, Annot);
39}
40
41void XCoreInstPrinter::
42printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
43 report_fatal_error("can't handle InlineJT");
44}
45
46void XCoreInstPrinter::
47printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
48 report_fatal_error("can't handle InlineJT32");
49}
50
51static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
52 raw_ostream &OS) {
53 int Offset = 0;
54 const MCSymbolRefExpr *SRE;
55
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.");
64 }
66
67 SRE->getSymbol().print(OS, MAI);
68
69 if (Offset) {
70 if (Offset > 0)
71 OS << '+';
72 OS << Offset;
73 }
74}
75
76void XCoreInstPrinter::
77printOperand(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;
82 }
83
84 if (Op.isImm()) {
85 O << Op.getImm();
86 return;
87 }
88
89 assert(Op.isExpr() && "unknown operand kind in printOperand");
90 printExpr(Op.getExpr(), &MAI, O);
91}
static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI, raw_ostream &OS)
IRTranslator LLVM IR MI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file contains the declaration of the XCoreInstPrinter class, which is used to print XCore MCInst...
This class represents an Operation in the Expression.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Binary assembler expressions.
Definition: MCExpr.h:488
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
const MCAsmInfo & MAI
Definition: MCInstPrinter.h:51
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:188
const MCSymbol & getSymbol() const
Definition: MCExpr.h:406
VariantKind getKind() const
Definition: MCExpr.h:408
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:58
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string lower() const
Definition: StringRef.cpp:111
void printRegName(raw_ostream &OS, MCRegister Reg) const override
Print the assembler register name.
static const char * getRegisterName(MCRegister Reg)
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O)
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167