LLVM  16.0.0git
LoongArchInstPrinter.cpp
Go to the documentation of this file.
1 //===- LoongArchInstPrinter.cpp - Convert LoongArch MCInst to asm 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 LoongArch MCInst to a .s file.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LoongArchInstPrinter.h"
14 #include "LoongArchBaseInfo.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCRegisterInfo.h"
19 #include "llvm/MC/MCSymbol.h"
20 using namespace llvm;
21 
22 #define DEBUG_TYPE "loongarch-asm-printer"
23 
24 // Include the auto-generated portion of the assembly writer.
25 #define PRINT_ALIAS_INSTR
26 #include "LoongArchGenAsmWriter.inc"
27 
29  StringRef Annot,
30  const MCSubtargetInfo &STI,
31  raw_ostream &O) {
32  if (!printAliasInstr(MI, Address, STI, O))
33  printInstruction(MI, Address, STI, O);
34  printAnnotation(O, Annot);
35 }
36 
37 void LoongArchInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
38  O << '$' << getRegisterName(RegNo);
39 }
40 
41 void LoongArchInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
42  const MCSubtargetInfo &STI,
43  raw_ostream &O) {
44  const MCOperand &MO = MI->getOperand(OpNo);
45 
46  if (MO.isReg()) {
47  printRegName(O, MO.getReg());
48  return;
49  }
50 
51  if (MO.isImm()) {
52  O << MO.getImm();
53  return;
54  }
55 
56  assert(MO.isExpr() && "Unknown operand kind in printOperand");
57  MO.getExpr()->print(O, &MAI);
58 }
59 
60 const char *LoongArchInstPrinter::getRegisterName(unsigned RegNo) {
61  // Default print reg alias name
62  return getRegisterName(RegNo, LoongArch::RegAliasName);
63 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:109
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MCOperand::isReg
bool isReg() const
Definition: MCInst.h:61
llvm::LoongArchInstPrinter::printRegName
void printRegName(raw_ostream &O, unsigned RegNo) const override
Print the assembler register name.
Definition: LoongArchInstPrinter.cpp:37
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::LoongArchInstPrinter::getRegisterName
static const char * getRegisterName(unsigned RegNo)
Definition: LoongArchInstPrinter.cpp:60
llvm::LoongArchInstPrinter::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: LoongArchInstPrinter.cpp:28
llvm::MCOperand::getImm
int64_t getImm() const
Definition: MCInst.h:80
MCSymbol.h
MCInst.h
MCSubtargetInfo.h
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::MCInstPrinter::printAnnotation
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
Definition: MCInstPrinter.cpp:50
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::MCOperand::isImm
bool isImm() const
Definition: MCInst.h:62
uint64_t
llvm::LoongArchInstPrinter::printAliasInstr
bool printAliasInstr(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O)
MCRegisterInfo.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LoongArchInstPrinter.h
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LoongArchBaseInfo.h
llvm::MCOperand::getExpr
const MCExpr * getExpr() const
Definition: MCInst.h:114
llvm::MCOperand::isExpr
bool isExpr() const
Definition: MCInst.h:65
llvm::MCInstPrinter::MAI
const MCAsmInfo & MAI
Definition: MCInstPrinter.h:49
llvm::MCExpr::print
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:41
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::LoongArchInstPrinter::printInstruction
void printInstruction(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O)
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:77
llvm::MCOperand::getReg
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:69