LLVM  7.0.0
Nios2InstPrinter.cpp
Go to the documentation of this file.
1 //===-- Nios2InstPrinter.cpp - Convert Nios2 MCInst to assembly syntax-----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class prints an Nios2 MCInst to a .s file.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Nios2InstPrinter.h"
15 
16 #include "Nios2InstrInfo.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCInstrInfo.h"
21 using namespace llvm;
22 
23 #define DEBUG_TYPE "asm-printer"
24 
25 #define PRINT_ALIAS_INSTR
26 #include "Nios2GenAsmWriter.inc"
27 
28 void Nios2InstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
29  OS << getRegisterName(RegNo);
30 }
31 
33  StringRef Annot, const MCSubtargetInfo &STI) {
34  // Try to print any aliases first.
35  if (!printAliasInstr(MI, STI, O))
36  printInstruction(MI, STI, O);
37  printAnnotation(O, Annot);
38 }
39 
41  const MCSubtargetInfo &STI,
42  raw_ostream &O) {
43  const MCOperand &Op = MI->getOperand(OpNo);
44  if (Op.isReg()) {
45  printRegName(O, Op.getReg());
46  return;
47  }
48 
49  if (Op.isImm()) {
50  O << Op.getImm();
51  return;
52  }
53 
54  assert(Op.isExpr() && "unknown operand kind in printOperand");
55  Op.getExpr()->print(O, &MAI, true);
56 }
57 
59  const MCSubtargetInfo &STI,
60  raw_ostream &O, const char *Modifier) {
61  // Load/Store memory operands -- imm($reg)
62  printOperand(MI, opNum + 1, STI, O);
63  O << "(";
64  printOperand(MI, opNum, STI, O);
65  O << ")";
66 }
bool isImm() const
Definition: MCInst.h:59
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isReg() const
Definition: MCInst.h:58
void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot, const MCSubtargetInfo &STI) override
Print the specified MCInst to the specified raw_ostream.
void printMemOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &OS, const char *Modifier=nullptr)
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:65
const MCExpr * getExpr() const
Definition: MCInst.h:96
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
int64_t getImm() const
Definition: MCInst.h:76
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
bool printAliasInstr(const MCInst *MI, const MCSubtargetInfo &STI, raw_ostream &O)
void printOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &OS)
bool isExpr() const
Definition: MCInst.h:61
void printInstruction(const MCInst *MI, const MCSubtargetInfo &STI, raw_ostream &O)
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
const MCAsmInfo & MAI
Definition: MCInstPrinter.h:46
void printRegName(raw_ostream &OS, unsigned RegNo) const override
Print the assembler register name.
Generic base class for all target subtargets.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
static const char * getRegisterName(unsigned RegNo)