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"
18 #include "MCTargetDesc/SparcBaseInfo.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCSymbol.h"
22 #include "llvm/Support/raw_ostream.h"
25 #define GET_INSTRUCTION_NAME
26 // Uncomment the following line once we are ready to use MCAsmWriter.
27 //#include "SparcGenAsmWriter.inc"
29 void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const
31 OS << '%' << StringRef(getRegisterName(RegNo)).lower();
34 void SparcInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
37 printInstruction(MI, O);
38 printAnnotation(O, Annot);
41 void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
44 const MCOperand &MO = MI->getOperand (opNum);
47 printRegName(O, MO.getReg());
52 O << (int)MO.getImm();
56 assert(MO.isExpr() && "Unknown operand kind in printOperand");
57 MO.getExpr()->print(O);
60 void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
61 raw_ostream &O, const char *Modifier)
63 printOperand(MI, opNum, O);
65 // If this is an ADD operand, emit it like normal operands.
66 if (Modifier && !strcmp(Modifier, "arith")) {
68 printOperand(MI, opNum+1, O);
71 const MCOperand &MO = MI->getOperand(opNum+1);
73 if (MO.isReg() && MO.getReg() == SP::G0)
74 return; // don't print "+%g0"
75 if (MO.isImm() && MO.getImm() == 0)
76 return; // don't print "+0"
80 printOperand(MI, opNum+1, O);
83 void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
86 int CC = (int)MI->getOperand(opNum).getImm();
87 O << SPARCCondCodeToString((SPCC::CondCodes)CC);
90 bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum,
93 assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX.");