1 //===-- RISCVInstPrinter.cpp - Convert RISCV MCInst to asm syntax ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class prints an RISCV MCInst to a .s file.
12 //===----------------------------------------------------------------------===//
14 #include "RISCVInstPrinter.h"
15 #include "MCTargetDesc/RISCVBaseInfo.h"
16 #include "MCTargetDesc/RISCVMCExpr.h"
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/MC/MCSymbol.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/FormattedStream.h"
28 #define DEBUG_TYPE "asm-printer"
30 // Include the auto-generated portion of the assembly writer.
31 #define PRINT_ALIAS_INSTR
32 #include "RISCVGenAsmWriter.inc"
34 // Include the auto-generated portion of the compress emitter.
35 #define GEN_UNCOMPRESS_INSTR
36 #include "RISCVGenCompressInstEmitter.inc"
39 NoAliases("riscv-no-aliases",
40 cl::desc("Disable the emission of assembler pseudo instructions"),
44 void RISCVInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
45 StringRef Annot, const MCSubtargetInfo &STI) {
47 const MCInst *NewMI = MI;
48 MCInst UncompressedMI;
50 Res = uncompressInst(UncompressedMI, *MI, MRI, STI);
52 NewMI = const_cast<MCInst*>(&UncompressedMI);
53 if (NoAliases || !printAliasInstr(NewMI, STI, O))
54 printInstruction(NewMI, STI, O);
55 printAnnotation(O, Annot);
58 void RISCVInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
59 O << getRegisterName(RegNo);
62 void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
63 const MCSubtargetInfo &STI,
64 raw_ostream &O, const char *Modifier) {
65 assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
66 const MCOperand &MO = MI->getOperand(OpNo);
69 printRegName(O, MO.getReg());
78 assert(MO.isExpr() && "Unknown operand kind in printOperand");
79 MO.getExpr()->print(O, &MAI);
82 void RISCVInstPrinter::printFenceArg(const MCInst *MI, unsigned OpNo,
83 const MCSubtargetInfo &STI,
85 unsigned FenceArg = MI->getOperand(OpNo).getImm();
86 if ((FenceArg & RISCVFenceField::I) != 0)
88 if ((FenceArg & RISCVFenceField::O) != 0)
90 if ((FenceArg & RISCVFenceField::R) != 0)
92 if ((FenceArg & RISCVFenceField::W) != 0)
96 void RISCVInstPrinter::printFRMArg(const MCInst *MI, unsigned OpNo,
97 const MCSubtargetInfo &STI,
100 static_cast<RISCVFPRndMode::RoundingMode>(MI->getOperand(OpNo).getImm());
101 O << RISCVFPRndMode::roundingModeToString(FRMArg);