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::printOperand(const MCInst *MI, int OpNum,
129 printOperand(MI->getOperand(OpNum), O);
132 void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
134 printAddress(MI->getOperand(OpNum).getReg(),
135 MI->getOperand(OpNum + 1).getImm(), 0, O);
138 void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
140 printAddress(MI->getOperand(OpNum).getReg(),
141 MI->getOperand(OpNum + 1).getImm(),
142 MI->getOperand(OpNum + 2).getReg(), O);
145 void SystemZInstPrinter::printBDLAddrOperand(const MCInst *MI, int OpNum,
147 unsigned Base = MI->getOperand(OpNum).getReg();
148 uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
149 uint64_t Length = MI->getOperand(OpNum + 2).getImm();
150 O << Disp << '(' << Length;
152 O << ",%" << getRegisterName(Base);
156 void SystemZInstPrinter::printCond4Operand(const MCInst *MI, int OpNum,
158 static const char *const CondNames[] = {
159 "o", "h", "nle", "l", "nhe", "lh", "ne",
160 "e", "nlh", "he", "nl", "le", "nh", "no"
162 uint64_t Imm = MI->getOperand(OpNum).getImm();
163 assert(Imm > 0 && Imm < 15 && "Invalid condition");
164 O << CondNames[Imm - 1];