1 //===-- SparcInstPrinter.cpp - Convert Sparc MCInst to assembly 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 Sparc MCInst to a .s file.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "asm-printer"
15 #include "SparcInstPrinter.h"
16 #include "MCTargetDesc/SparcBaseInfo.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCSymbol.h"
21 #include "llvm/Support/raw_ostream.h"
24 #define GET_INSTRUCTION_NAME
25 #include "SparcGenAsmWriter.inc"
27 void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const
29 OS << '%' << StringRef(getRegisterName(RegNo)).lower();
32 void SparcInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
35 printInstruction(MI, O);
36 printAnnotation(O, Annot);
39 void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
42 const MCOperand &MO = MI->getOperand (opNum);
45 printRegName(O, MO.getReg());
50 O << (int)MO.getImm();
54 assert(MO.isExpr() && "Unknown operand kind in printOperand");
55 MO.getExpr()->print(O);
58 void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
59 raw_ostream &O, const char *Modifier)
61 printOperand(MI, opNum, O);
63 // If this is an ADD operand, emit it like normal operands.
64 if (Modifier && !strcmp(Modifier, "arith")) {
66 printOperand(MI, opNum+1, O);
69 const MCOperand &MO = MI->getOperand(opNum+1);
71 if (MO.isReg() && MO.getReg() == SP::G0)
72 return; // don't print "+%g0"
73 if (MO.isImm() && MO.getImm() == 0)
74 return; // don't print "+0"
78 printOperand(MI, opNum+1, O);
81 void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
84 int CC = (int)MI->getOperand(opNum).getImm();
85 O << SPARCCondCodeToString((SPCC::CondCodes)CC);
88 bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum,
91 assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX.");