ARM: use natural LLVM IR for vshll instructions
[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 "Sparc.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/Support/raw_ostream.h"
21 using namespace llvm;
22
23 #define GET_INSTRUCTION_NAME
24 #define PRINT_ALIAS_INSTR
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   if (!printAliasInstr(MI, O) && !printSparcAliasInstr(MI, O))
36     printInstruction(MI, O);
37   printAnnotation(O, Annot);
38 }
39
40 bool SparcInstPrinter::printSparcAliasInstr(const MCInst *MI, raw_ostream &O)
41 {
42   switch (MI->getOpcode()) {
43   default: return false;
44   case SP::JMPLrr:
45   case SP::JMPLri: {
46     if (MI->getNumOperands() != 3)
47       return false;
48     if (!MI->getOperand(0).isReg())
49       return false;
50     switch (MI->getOperand(0).getReg()) {
51     default: return false;
52     case SP::G0: // jmp $addr
53       O << "\tjmp "; printMemOperand(MI, 1, O);
54       return true;
55     case SP::O7: // call $addr
56       O << "\tcall "; printMemOperand(MI, 1, O);
57       return true;
58     }
59   }
60   }
61 }
62
63 void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
64                                     raw_ostream &O)
65 {
66   const MCOperand &MO = MI->getOperand (opNum);
67
68   if (MO.isReg()) {
69     printRegName(O, MO.getReg());
70     return ;
71   }
72
73   if (MO.isImm()) {
74     O << (int)MO.getImm();
75     return;
76   }
77
78   assert(MO.isExpr() && "Unknown operand kind in printOperand");
79   MO.getExpr()->print(O);
80 }
81
82 void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
83                                       raw_ostream &O, const char *Modifier)
84 {
85   printOperand(MI, opNum, O);
86
87   // If this is an ADD operand, emit it like normal operands.
88   if (Modifier && !strcmp(Modifier, "arith")) {
89     O << ", ";
90     printOperand(MI, opNum+1, O);
91     return;
92   }
93   const MCOperand &MO = MI->getOperand(opNum+1);
94
95   if (MO.isReg() && MO.getReg() == SP::G0)
96     return;   // don't print "+%g0"
97   if (MO.isImm() && MO.getImm() == 0)
98     return;   // don't print "+0"
99
100   O << "+";
101
102   printOperand(MI, opNum+1, O);
103 }
104
105 void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
106                                      raw_ostream &O)
107 {
108   int CC = (int)MI->getOperand(opNum).getImm();
109   switch (MI->getOpcode()) {
110   default: break;
111   case SP::FBCOND:
112   case SP::MOVFCCrr:
113   case SP::MOVFCCri:
114   case SP::FMOVS_FCC:
115   case SP::FMOVD_FCC:
116   case SP::FMOVQ_FCC:  // Make sure CC is a fp conditional flag.
117     CC = (CC < 16) ? (CC + 16) : CC;
118     break;
119   }
120   O << SPARCCondCodeToString((SPCC::CondCodes)CC);
121 }
122
123 bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum,
124                                   raw_ostream &O)
125 {
126   assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX.");
127   return true;
128 }