1 //===-- SystemZInstPrinter.cpp - Convert SystemZ 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 #include "SystemZInstPrinter.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCInst.h"
13 #include "llvm/MC/MCInstrInfo.h"
14 #include "llvm/MC/MCSymbol.h"
15 #include "llvm/Support/ErrorHandling.h"
16 #include "llvm/Support/raw_ostream.h"
20 #define DEBUG_TYPE "asm-printer"
22 #include "SystemZGenAsmWriter.inc"
24 void SystemZInstPrinter::printAddress(unsigned Base, int64_t Disp,
25 unsigned Index, raw_ostream &O) {
30 O << '%' << getRegisterName(Index);
35 O << '%' << getRegisterName(Base);
40 void SystemZInstPrinter::printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
43 O << '%' << getRegisterName(MO.getReg());
47 MO.getExpr()->print(O, MAI);
49 llvm_unreachable("Invalid operand");
52 void SystemZInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
54 const MCSubtargetInfo &STI) {
55 printInstruction(MI, O);
56 printAnnotation(O, Annot);
59 void SystemZInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
60 O << '%' << getRegisterName(RegNo);
64 void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
65 int64_t Value = MI->getOperand(OpNum).getImm();
66 assert(isUInt<N>(Value) && "Invalid uimm argument");
71 void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
72 int64_t Value = MI->getOperand(OpNum).getImm();
73 assert(isInt<N>(Value) && "Invalid simm argument");
77 void SystemZInstPrinter::printU1ImmOperand(const MCInst *MI, int OpNum,
79 printUImmOperand<1>(MI, OpNum, O);
82 void SystemZInstPrinter::printU2ImmOperand(const MCInst *MI, int OpNum,
84 printUImmOperand<2>(MI, OpNum, O);
87 void SystemZInstPrinter::printU3ImmOperand(const MCInst *MI, int OpNum,
89 printUImmOperand<3>(MI, OpNum, O);
92 void SystemZInstPrinter::printU4ImmOperand(const MCInst *MI, int OpNum,
94 printUImmOperand<4>(MI, OpNum, O);
97 void SystemZInstPrinter::printU6ImmOperand(const MCInst *MI, int OpNum,
99 printUImmOperand<6>(MI, OpNum, O);
102 void SystemZInstPrinter::printS8ImmOperand(const MCInst *MI, int OpNum,
104 printSImmOperand<8>(MI, OpNum, O);
107 void SystemZInstPrinter::printU8ImmOperand(const MCInst *MI, int OpNum,
109 printUImmOperand<8>(MI, OpNum, O);
112 void SystemZInstPrinter::printU12ImmOperand(const MCInst *MI, int OpNum,
114 printUImmOperand<12>(MI, OpNum, O);
117 void SystemZInstPrinter::printS16ImmOperand(const MCInst *MI, int OpNum,
119 printSImmOperand<16>(MI, OpNum, O);
122 void SystemZInstPrinter::printU16ImmOperand(const MCInst *MI, int OpNum,
124 printUImmOperand<16>(MI, OpNum, O);
127 void SystemZInstPrinter::printS32ImmOperand(const MCInst *MI, int OpNum,
129 printSImmOperand<32>(MI, OpNum, O);
132 void SystemZInstPrinter::printU32ImmOperand(const MCInst *MI, int OpNum,
134 printUImmOperand<32>(MI, OpNum, O);
137 void SystemZInstPrinter::printAccessRegOperand(const MCInst *MI, int OpNum,
139 uint64_t Value = MI->getOperand(OpNum).getImm();
140 assert(Value < 16 && "Invalid access register number");
141 O << "%a" << (unsigned int)Value;
144 void SystemZInstPrinter::printPCRelOperand(const MCInst *MI, int OpNum,
146 const MCOperand &MO = MI->getOperand(OpNum);
149 O.write_hex(MO.getImm());
151 MO.getExpr()->print(O, &MAI);
154 void SystemZInstPrinter::printPCRelTLSOperand(const MCInst *MI, int OpNum,
156 // Output the PC-relative operand.
157 printPCRelOperand(MI, OpNum, O);
159 // Output the TLS marker if present.
160 if ((unsigned)OpNum + 1 < MI->getNumOperands()) {
161 const MCOperand &MO = MI->getOperand(OpNum + 1);
162 const MCSymbolRefExpr &refExp = cast<MCSymbolRefExpr>(*MO.getExpr());
163 switch (refExp.getKind()) {
164 case MCSymbolRefExpr::VK_TLSGD:
167 case MCSymbolRefExpr::VK_TLSLDM:
171 llvm_unreachable("Unexpected symbol kind");
173 O << refExp.getSymbol().getName();
177 void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
179 printOperand(MI->getOperand(OpNum), &MAI, O);
182 void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
184 printAddress(MI->getOperand(OpNum).getReg(),
185 MI->getOperand(OpNum + 1).getImm(), 0, O);
188 void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
190 printAddress(MI->getOperand(OpNum).getReg(),
191 MI->getOperand(OpNum + 1).getImm(),
192 MI->getOperand(OpNum + 2).getReg(), O);
195 void SystemZInstPrinter::printBDLAddrOperand(const MCInst *MI, int OpNum,
197 unsigned Base = MI->getOperand(OpNum).getReg();
198 uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
199 uint64_t Length = MI->getOperand(OpNum + 2).getImm();
200 O << Disp << '(' << Length;
202 O << ",%" << getRegisterName(Base);
206 void SystemZInstPrinter::printBDVAddrOperand(const MCInst *MI, int OpNum,
208 printAddress(MI->getOperand(OpNum).getReg(),
209 MI->getOperand(OpNum + 1).getImm(),
210 MI->getOperand(OpNum + 2).getReg(), O);
213 void SystemZInstPrinter::printCond4Operand(const MCInst *MI, int OpNum,
215 static const char *const CondNames[] = {
216 "o", "h", "nle", "l", "nhe", "lh", "ne",
217 "e", "nlh", "he", "nl", "le", "nh", "no"
219 uint64_t Imm = MI->getOperand(OpNum).getImm();
220 assert(Imm > 0 && Imm < 15 && "Invalid condition");
221 O << CondNames[Imm - 1];