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 #define DEBUG_TYPE "asm-printer"
12 #include "SystemZInstPrinter.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCInstrInfo.h"
15 #include "llvm/Support/raw_ostream.h"
19 #include "SystemZGenAsmWriter.inc"
21 void SystemZInstPrinter::printAddress(unsigned Base, int64_t Disp,
22 unsigned Index, raw_ostream &O) {
27 O << '%' << getRegisterName(Index) << ',';
28 O << '%' << getRegisterName(Base) << ')';
30 assert(!Index && "Shouldn't have an index without a base");
33 void SystemZInstPrinter::printOperand(const MCOperand &MO, raw_ostream &O) {
35 O << '%' << getRegisterName(MO.getReg());
41 llvm_unreachable("Invalid operand");
44 void SystemZInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
46 printInstruction(MI, O);
47 printAnnotation(O, Annot);
50 void SystemZInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
51 O << '%' << getRegisterName(RegNo);
54 void SystemZInstPrinter::printU4ImmOperand(const MCInst *MI, int OpNum,
56 int64_t Value = MI->getOperand(OpNum).getImm();
57 assert(isUInt<4>(Value) && "Invalid u4imm argument");
61 void SystemZInstPrinter::printU6ImmOperand(const MCInst *MI, int OpNum,
63 int64_t Value = MI->getOperand(OpNum).getImm();
64 assert(isUInt<6>(Value) && "Invalid u6imm argument");
68 void SystemZInstPrinter::printS8ImmOperand(const MCInst *MI, int OpNum,
70 int64_t Value = MI->getOperand(OpNum).getImm();
71 assert(isInt<8>(Value) && "Invalid s8imm argument");
75 void SystemZInstPrinter::printU8ImmOperand(const MCInst *MI, int OpNum,
77 int64_t Value = MI->getOperand(OpNum).getImm();
78 assert(isUInt<8>(Value) && "Invalid u8imm argument");
82 void SystemZInstPrinter::printS16ImmOperand(const MCInst *MI, int OpNum,
84 int64_t Value = MI->getOperand(OpNum).getImm();
85 assert(isInt<16>(Value) && "Invalid s16imm argument");
89 void SystemZInstPrinter::printU16ImmOperand(const MCInst *MI, int OpNum,
91 int64_t Value = MI->getOperand(OpNum).getImm();
92 assert(isUInt<16>(Value) && "Invalid u16imm argument");
96 void SystemZInstPrinter::printS32ImmOperand(const MCInst *MI, int OpNum,
98 int64_t Value = MI->getOperand(OpNum).getImm();
99 assert(isInt<32>(Value) && "Invalid s32imm argument");
103 void SystemZInstPrinter::printU32ImmOperand(const MCInst *MI, int OpNum,
105 int64_t Value = MI->getOperand(OpNum).getImm();
106 assert(isUInt<32>(Value) && "Invalid u32imm argument");
110 void SystemZInstPrinter::printAccessRegOperand(const MCInst *MI, int OpNum,
112 uint64_t Value = MI->getOperand(OpNum).getImm();
113 assert(Value < 16 && "Invalid access register number");
114 O << "%a" << (unsigned int)Value;
117 void SystemZInstPrinter::printPCRelOperand(const MCInst *MI, int OpNum,
119 const MCOperand &MO = MI->getOperand(OpNum);
122 O.write_hex(MO.getImm());
127 void SystemZInstPrinter::printCallOperand(const MCInst *MI, int OpNum,
129 const MCOperand &MO = MI->getOperand(OpNum);
132 O.write_hex(MO.getImm());
139 void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
141 printOperand(MI->getOperand(OpNum), O);
144 void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
146 printAddress(MI->getOperand(OpNum).getReg(),
147 MI->getOperand(OpNum + 1).getImm(), 0, O);
150 void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
152 printAddress(MI->getOperand(OpNum).getReg(),
153 MI->getOperand(OpNum + 1).getImm(),
154 MI->getOperand(OpNum + 2).getReg(), O);
157 void SystemZInstPrinter::printBDLAddrOperand(const MCInst *MI, int OpNum,
159 unsigned Base = MI->getOperand(OpNum).getReg();
160 uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
161 uint64_t Length = MI->getOperand(OpNum + 2).getImm();
162 O << Disp << '(' << Length;
164 O << ",%" << getRegisterName(Base);
168 void SystemZInstPrinter::printCond4Operand(const MCInst *MI, int OpNum,
170 static const char *const CondNames[] = {
171 "o", "h", "nle", "l", "nhe", "lh", "ne",
172 "e", "nlh", "he", "nl", "le", "nh", "no"
174 uint64_t Imm = MI->getOperand(OpNum).getImm();
175 assert(Imm > 0 && Imm < 15 && "Invalid condition");
176 O << CondNames[Imm - 1];