LLVM API Documentation

SystemZInstPrinter.cpp
Go to the documentation of this file.
00001 //===-- SystemZInstPrinter.cpp - Convert SystemZ MCInst to assembly syntax ===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "SystemZInstPrinter.h"
00011 #include "llvm/MC/MCExpr.h"
00012 #include "llvm/MC/MCInstrInfo.h"
00013 #include "llvm/Support/raw_ostream.h"
00014 
00015 using namespace llvm;
00016 
00017 #define DEBUG_TYPE "asm-printer"
00018 
00019 #include "SystemZGenAsmWriter.inc"
00020 
00021 void SystemZInstPrinter::printAddress(unsigned Base, int64_t Disp,
00022                                       unsigned Index, raw_ostream &O) {
00023   O << Disp;
00024   if (Base) {
00025     O << '(';
00026     if (Index)
00027       O << '%' << getRegisterName(Index) << ',';
00028     O << '%' << getRegisterName(Base) << ')';
00029   } else
00030     assert(!Index && "Shouldn't have an index without a base");
00031 }
00032 
00033 void SystemZInstPrinter::printOperand(const MCOperand &MO, raw_ostream &O) {
00034   if (MO.isReg())
00035     O << '%' << getRegisterName(MO.getReg());
00036   else if (MO.isImm())
00037     O << MO.getImm();
00038   else if (MO.isExpr())
00039     O << *MO.getExpr();
00040   else
00041     llvm_unreachable("Invalid operand");
00042 }
00043 
00044 void SystemZInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
00045                                    StringRef Annot) {
00046   printInstruction(MI, O);
00047   printAnnotation(O, Annot);
00048 }
00049 
00050 void SystemZInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
00051   O << '%' << getRegisterName(RegNo);
00052 }
00053 
00054 void SystemZInstPrinter::printU4ImmOperand(const MCInst *MI, int OpNum,
00055                                            raw_ostream &O) {
00056   int64_t Value = MI->getOperand(OpNum).getImm();
00057   assert(isUInt<4>(Value) && "Invalid u4imm argument");
00058   O << Value;
00059 }
00060 
00061 void SystemZInstPrinter::printU6ImmOperand(const MCInst *MI, int OpNum,
00062                                            raw_ostream &O) {
00063   int64_t Value = MI->getOperand(OpNum).getImm();
00064   assert(isUInt<6>(Value) && "Invalid u6imm argument");
00065   O << Value;
00066 }
00067 
00068 void SystemZInstPrinter::printS8ImmOperand(const MCInst *MI, int OpNum,
00069                                            raw_ostream &O) {
00070   int64_t Value = MI->getOperand(OpNum).getImm();
00071   assert(isInt<8>(Value) && "Invalid s8imm argument");
00072   O << Value;
00073 }
00074 
00075 void SystemZInstPrinter::printU8ImmOperand(const MCInst *MI, int OpNum,
00076                                            raw_ostream &O) {
00077   int64_t Value = MI->getOperand(OpNum).getImm();
00078   assert(isUInt<8>(Value) && "Invalid u8imm argument");
00079   O << Value;
00080 }
00081 
00082 void SystemZInstPrinter::printS16ImmOperand(const MCInst *MI, int OpNum,
00083                                             raw_ostream &O) {
00084   int64_t Value = MI->getOperand(OpNum).getImm();
00085   assert(isInt<16>(Value) && "Invalid s16imm argument");
00086   O << Value;
00087 }
00088 
00089 void SystemZInstPrinter::printU16ImmOperand(const MCInst *MI, int OpNum,
00090                                             raw_ostream &O) {
00091   int64_t Value = MI->getOperand(OpNum).getImm();
00092   assert(isUInt<16>(Value) && "Invalid u16imm argument");
00093   O << Value;
00094 }
00095 
00096 void SystemZInstPrinter::printS32ImmOperand(const MCInst *MI, int OpNum,
00097                                             raw_ostream &O) {
00098   int64_t Value = MI->getOperand(OpNum).getImm();
00099   assert(isInt<32>(Value) && "Invalid s32imm argument");
00100   O << Value;
00101 }
00102 
00103 void SystemZInstPrinter::printU32ImmOperand(const MCInst *MI, int OpNum,
00104                                             raw_ostream &O) {
00105   int64_t Value = MI->getOperand(OpNum).getImm();
00106   assert(isUInt<32>(Value) && "Invalid u32imm argument");
00107   O << Value;
00108 }
00109 
00110 void SystemZInstPrinter::printAccessRegOperand(const MCInst *MI, int OpNum,
00111                                                raw_ostream &O) {
00112   uint64_t Value = MI->getOperand(OpNum).getImm();
00113   assert(Value < 16 && "Invalid access register number");
00114   O << "%a" << (unsigned int)Value;
00115 }
00116 
00117 void SystemZInstPrinter::printPCRelOperand(const MCInst *MI, int OpNum,
00118                                            raw_ostream &O) {
00119   const MCOperand &MO = MI->getOperand(OpNum);
00120   if (MO.isImm()) {
00121     O << "0x";
00122     O.write_hex(MO.getImm());
00123   } else
00124     O << *MO.getExpr();
00125 }
00126 
00127 void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
00128                                       raw_ostream &O) {
00129   printOperand(MI->getOperand(OpNum), O);
00130 }
00131 
00132 void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
00133                                             raw_ostream &O) {
00134   printAddress(MI->getOperand(OpNum).getReg(),
00135                MI->getOperand(OpNum + 1).getImm(), 0, O);
00136 }
00137 
00138 void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
00139                                              raw_ostream &O) {
00140   printAddress(MI->getOperand(OpNum).getReg(),
00141                MI->getOperand(OpNum + 1).getImm(),
00142                MI->getOperand(OpNum + 2).getReg(), O);
00143 }
00144 
00145 void SystemZInstPrinter::printBDLAddrOperand(const MCInst *MI, int OpNum,
00146                                              raw_ostream &O) {
00147   unsigned Base = MI->getOperand(OpNum).getReg();
00148   uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
00149   uint64_t Length = MI->getOperand(OpNum + 2).getImm();
00150   O << Disp << '(' << Length;
00151   if (Base)
00152     O << ",%" << getRegisterName(Base);
00153   O << ')';
00154 }
00155 
00156 void SystemZInstPrinter::printCond4Operand(const MCInst *MI, int OpNum,
00157                                            raw_ostream &O) {
00158   static const char *const CondNames[] = {
00159     "o", "h", "nle", "l", "nhe", "lh", "ne",
00160     "e", "nlh", "he", "nl", "le", "nh", "no"
00161   };
00162   uint64_t Imm = MI->getOperand(OpNum).getImm();
00163   assert(Imm > 0 && Imm < 15 && "Invalid condition");
00164   O << CondNames[Imm - 1];
00165 }