]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/llvm/lib/Target/SystemZ/InstPrinter/SystemZInstPrinter.cpp
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / llvm / lib / Target / SystemZ / InstPrinter / SystemZInstPrinter.cpp
1 //===-- SystemZInstPrinter.cpp - Convert SystemZ 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 #define DEBUG_TYPE "asm-printer"
11
12 #include "SystemZInstPrinter.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCInstrInfo.h"
15 #include "llvm/Support/raw_ostream.h"
16
17 using namespace llvm;
18
19 #include "SystemZGenAsmWriter.inc"
20
21 void SystemZInstPrinter::printAddress(unsigned Base, int64_t Disp,
22                                       unsigned Index, raw_ostream &O) {
23   O << Disp;
24   if (Base) {
25     O << '(';
26     if (Index)
27       O << '%' << getRegisterName(Index) << ',';
28     O << '%' << getRegisterName(Base) << ')';
29   } else
30     assert(!Index && "Shouldn't have an index without a base");
31 }
32
33 void SystemZInstPrinter::printOperand(const MCOperand &MO, raw_ostream &O) {
34   if (MO.isReg())
35     O << '%' << getRegisterName(MO.getReg());
36   else if (MO.isImm())
37     O << MO.getImm();
38   else if (MO.isExpr())
39     O << *MO.getExpr();
40   else
41     llvm_unreachable("Invalid operand");
42 }
43
44 void SystemZInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
45                                    StringRef Annot) {
46   printInstruction(MI, O);
47   printAnnotation(O, Annot);
48 }
49
50 void SystemZInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
51   O << '%' << getRegisterName(RegNo);
52 }
53
54 void SystemZInstPrinter::printU4ImmOperand(const MCInst *MI, int OpNum,
55                                            raw_ostream &O) {
56   int64_t Value = MI->getOperand(OpNum).getImm();
57   assert(isUInt<4>(Value) && "Invalid u4imm argument");
58   O << Value;
59 }
60
61 void SystemZInstPrinter::printU6ImmOperand(const MCInst *MI, int OpNum,
62                                            raw_ostream &O) {
63   int64_t Value = MI->getOperand(OpNum).getImm();
64   assert(isUInt<6>(Value) && "Invalid u6imm argument");
65   O << Value;
66 }
67
68 void SystemZInstPrinter::printS8ImmOperand(const MCInst *MI, int OpNum,
69                                            raw_ostream &O) {
70   int64_t Value = MI->getOperand(OpNum).getImm();
71   assert(isInt<8>(Value) && "Invalid s8imm argument");
72   O << Value;
73 }
74
75 void SystemZInstPrinter::printU8ImmOperand(const MCInst *MI, int OpNum,
76                                            raw_ostream &O) {
77   int64_t Value = MI->getOperand(OpNum).getImm();
78   assert(isUInt<8>(Value) && "Invalid u8imm argument");
79   O << Value;
80 }
81
82 void SystemZInstPrinter::printS16ImmOperand(const MCInst *MI, int OpNum,
83                                             raw_ostream &O) {
84   int64_t Value = MI->getOperand(OpNum).getImm();
85   assert(isInt<16>(Value) && "Invalid s16imm argument");
86   O << Value;
87 }
88
89 void SystemZInstPrinter::printU16ImmOperand(const MCInst *MI, int OpNum,
90                                             raw_ostream &O) {
91   int64_t Value = MI->getOperand(OpNum).getImm();
92   assert(isUInt<16>(Value) && "Invalid u16imm argument");
93   O << Value;
94 }
95
96 void SystemZInstPrinter::printS32ImmOperand(const MCInst *MI, int OpNum,
97                                             raw_ostream &O) {
98   int64_t Value = MI->getOperand(OpNum).getImm();
99   assert(isInt<32>(Value) && "Invalid s32imm argument");
100   O << Value;
101 }
102
103 void SystemZInstPrinter::printU32ImmOperand(const MCInst *MI, int OpNum,
104                                             raw_ostream &O) {
105   int64_t Value = MI->getOperand(OpNum).getImm();
106   assert(isUInt<32>(Value) && "Invalid u32imm argument");
107   O << Value;
108 }
109
110 void SystemZInstPrinter::printAccessRegOperand(const MCInst *MI, int OpNum,
111                                                raw_ostream &O) {
112   uint64_t Value = MI->getOperand(OpNum).getImm();
113   assert(Value < 16 && "Invalid access register number");
114   O << "%a" << (unsigned int)Value;
115 }
116
117 void SystemZInstPrinter::printCallOperand(const MCInst *MI, int OpNum,
118                                           raw_ostream &O) {
119   printOperand(MI, OpNum, O);
120   O << "@PLT";
121 }
122
123 void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
124                                       raw_ostream &O) {
125   printOperand(MI->getOperand(OpNum), O);
126 }
127
128 void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
129                                             raw_ostream &O) {
130   printAddress(MI->getOperand(OpNum).getReg(),
131                MI->getOperand(OpNum + 1).getImm(), 0, O);
132 }
133
134 void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
135                                              raw_ostream &O) {
136   printAddress(MI->getOperand(OpNum).getReg(),
137                MI->getOperand(OpNum + 1).getImm(),
138                MI->getOperand(OpNum + 2).getReg(), O);
139 }
140
141 void SystemZInstPrinter::printCond4Operand(const MCInst *MI, int OpNum,
142                                            raw_ostream &O) {
143   static const char *const CondNames[] = {
144     "o", "h", "nle", "l", "nhe", "lh", "ne",
145     "e", "nlh", "he", "nl", "le", "nh", "no"
146   };
147   uint64_t Imm = MI->getOperand(OpNum).getImm();
148   assert(Imm > 0 && Imm < 15 && "Invalid condition");
149   O << CondNames[Imm - 1];
150 }