blob: de0a5f9e84ea7866709a10bc4ce4098a764387cd [file] [log] [blame]
Nikolai Bozhenov1cf9c542017-12-07 12:35:02 +00001//===-- 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"
20#include "llvm/Support/raw_ostream.h"
21using namespace llvm;
22
23#define DEBUG_TYPE "asm-printer"
24
25#define PRINT_ALIAS_INSTR
26#include "Nios2GenAsmWriter.inc"
27
28void Nios2InstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
29 OS << getRegisterName(RegNo);
30}
31
32void Nios2InstPrinter::printInst(const MCInst *MI, raw_ostream &O,
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
40void Nios2InstPrinter::printOperand(const MCInst *MI, int OpNo,
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
58void Nios2InstPrinter::printMemOperand(const MCInst *MI, int opNum,
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}