77404f831468ddc47a344795163922973a7637ee
[oota-llvm.git] / lib / Target / Sparc / InstPrinter / SparcInstPrinter.cpp
1 //===-- SparcInstPrinter.cpp - Convert Sparc 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 Sparc MCInst to a .s file.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "asm-printer"
15 #include "SparcInstPrinter.h"
16 #include "MCTargetDesc/SparcBaseInfo.h"
17 #include "Sparc.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"
22 using namespace llvm;
23
24 #define GET_INSTRUCTION_NAME
25 #include "SparcGenAsmWriter.inc"
26
27 void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const
28 {
29   OS << '%' << StringRef(getRegisterName(RegNo)).lower();
30 }
31
32 void SparcInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
33                                StringRef Annot)
34 {
35   printInstruction(MI, O);
36   printAnnotation(O, Annot);
37 }
38
39 void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
40                                     raw_ostream &O)
41 {
42   const MCOperand &MO = MI->getOperand (opNum);
43
44   if (MO.isReg()) {
45     printRegName(O, MO.getReg());
46     return ;
47   }
48
49   if (MO.isImm()) {
50     O << (int)MO.getImm();
51     return;
52   }
53
54   assert(MO.isExpr() && "Unknown operand kind in printOperand");
55   MO.getExpr()->print(O);
56 }
57
58 void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
59                                       raw_ostream &O, const char *Modifier)
60 {
61   printOperand(MI, opNum, O);
62
63   // If this is an ADD operand, emit it like normal operands.
64   if (Modifier && !strcmp(Modifier, "arith")) {
65     O << ", ";
66     printOperand(MI, opNum+1, O);
67     return;
68   }
69   const MCOperand &MO = MI->getOperand(opNum+1);
70
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"
75
76   O << "+";
77
78   printOperand(MI, opNum+1, O);
79 }
80
81 void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
82                                      raw_ostream &O)
83 {
84   int CC = (int)MI->getOperand(opNum).getImm();
85   O << SPARCCondCodeToString((SPCC::CondCodes)CC);
86 }
87
88 bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum,
89                                   raw_ostream &O)
90 {
91   assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX.");
92   return true;
93 }