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 #define PRINT_ALIAS_INSTR
26 #include "SparcGenAsmWriter.inc"
28 void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const
30 OS << '%' << StringRef(getRegisterName(RegNo)).lower();
33 void SparcInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
36 if (!printAliasInstr(MI, O) && !printSparcAliasInstr(MI, O))
37 printInstruction(MI, O);
38 printAnnotation(O, Annot);
41 bool SparcInstPrinter::printSparcAliasInstr(const MCInst *MI, raw_ostream &O)
43 switch (MI->getOpcode()) {
44 default: return false;
47 if (MI->getNumOperands() != 3)
49 if (!MI->getOperand(0).isReg())
51 switch (MI->getOperand(0).getReg()) {
52 default: return false;
53 case SP::G0: // jmp $addr
54 O << "\tjmp "; printMemOperand(MI, 1, O);
56 case SP::O7: // call $addr
57 O << "\tcall "; printMemOperand(MI, 1, O);
64 void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
67 const MCOperand &MO = MI->getOperand (opNum);
70 printRegName(O, MO.getReg());
75 O << (int)MO.getImm();
79 assert(MO.isExpr() && "Unknown operand kind in printOperand");
80 MO.getExpr()->print(O);
83 void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
84 raw_ostream &O, const char *Modifier)
86 printOperand(MI, opNum, O);
88 // If this is an ADD operand, emit it like normal operands.
89 if (Modifier && !strcmp(Modifier, "arith")) {
91 printOperand(MI, opNum+1, O);
94 const MCOperand &MO = MI->getOperand(opNum+1);
96 if (MO.isReg() && MO.getReg() == SP::G0)
97 return; // don't print "+%g0"
98 if (MO.isImm() && MO.getImm() == 0)
99 return; // don't print "+0"
103 printOperand(MI, opNum+1, O);
106 void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
109 int CC = (int)MI->getOperand(opNum).getImm();
110 switch (MI->getOpcode()) {
117 case SP::FMOVQ_FCC: // Make sure CC is a fp conditional flag.
118 CC = (CC < 16) ? (CC + 16) : CC;
121 O << SPARCCondCodeToString((SPCC::CondCodes)CC);
124 bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum,
127 assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX.");