Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.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
33
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 }
65 assert(SRE->getSpecifier() == 0);
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}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI, raw_ostream &OS)
IRTranslator LLVM IR MI
This file contains the declaration of the XCoreInstPrinter class, which is used to print XCore MCInst...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
Binary assembler expressions.
Definition MCExpr.h:299
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
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
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:190
const MCSymbol & getSymbol() const
Definition MCExpr.h:227
uint16_t getSpecifier() const
Definition MCExpr.h:233
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition MCSymbol.cpp:59
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM_ABI std::string lower() const
static const char * getRegisterName(MCRegister Reg)
void printRegName(raw_ostream &OS, MCRegister Reg) override
Print the assembler register name.
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:53
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
DWARFExpression::Operation Op