diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h @@ -13,6 +13,7 @@ #ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H #define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H +#include "SystemZMCAsmInfo.h" #include "llvm/MC/MCInstPrinter.h" #include @@ -32,15 +33,21 @@ static const char *getRegisterName(unsigned RegNo); // Print an address with the given base, displacement and index. - static void printAddress(unsigned Base, int64_t Disp, unsigned Index, - raw_ostream &O); + static void printAddress(const MCAsmInfo *MAI, unsigned Base, int64_t Disp, + unsigned Index, raw_ostream &O); // Print the given operand. static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, raw_ostream &O); + static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo, + raw_ostream &O); + // Override MCInstPrinter. - void printRegName(raw_ostream &O, unsigned RegNo) const override; + inline void printRegName(raw_ostream &O, unsigned RegNo) const override { + printFormattedRegName(&MAI, RegNo, O); + } + void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override; diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp @@ -23,18 +23,19 @@ #include "SystemZGenAsmWriter.inc" -void SystemZInstPrinter::printAddress(unsigned Base, int64_t Disp, - unsigned Index, raw_ostream &O) { +void SystemZInstPrinter::printAddress(const MCAsmInfo *MAI, unsigned Base, + int64_t Disp, unsigned Index, + raw_ostream &O) { O << Disp; if (Base || Index) { O << '('; if (Index) { - O << '%' << getRegisterName(Index); + printFormattedRegName(MAI, Index, O); if (Base) O << ','; } if (Base) - O << '%' << getRegisterName(Base); + printFormattedRegName(MAI, Base, O); O << ')'; } } @@ -45,7 +46,7 @@ if (!MO.getReg()) O << '0'; else - O << '%' << getRegisterName(MO.getReg()); + printFormattedRegName(MAI, MO.getReg(), O); } else if (MO.isImm()) O << MO.getImm(); @@ -55,6 +56,17 @@ llvm_unreachable("Invalid operand"); } +void SystemZInstPrinter::printFormattedRegName(const MCAsmInfo *MAI, + unsigned RegNo, raw_ostream &O) { + const char *RegName = getRegisterName(RegNo); + if (MAI->getAssemblerDialect() == AD_HLASM) { + // Skip register prefix so that only register number is left + assert(isalpha(RegName[0]) && isdigit(RegName[1])); + O << (RegName + 1); + } else + O << '%' << RegName; +} + void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) { @@ -62,10 +74,6 @@ printAnnotation(O, Annot); } -void SystemZInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const { - O << '%' << getRegisterName(RegNo); -} - template static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { int64_t Value = MI->getOperand(OpNum).getImm(); @@ -186,13 +194,13 @@ void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printAddress(MI->getOperand(OpNum).getReg(), + printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1).getImm(), 0, O); } void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printAddress(MI->getOperand(OpNum).getReg(), + printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1).getImm(), MI->getOperand(OpNum + 2).getReg(), O); } @@ -203,8 +211,10 @@ uint64_t Disp = MI->getOperand(OpNum + 1).getImm(); uint64_t Length = MI->getOperand(OpNum + 2).getImm(); O << Disp << '(' << Length; - if (Base) - O << ",%" << getRegisterName(Base); + if (Base) { + O << ","; + printRegName(O, Base); + } O << ')'; } @@ -213,15 +223,18 @@ unsigned Base = MI->getOperand(OpNum).getReg(); uint64_t Disp = MI->getOperand(OpNum + 1).getImm(); unsigned Length = MI->getOperand(OpNum + 2).getReg(); - O << Disp << "(%" << getRegisterName(Length); - if (Base) - O << ",%" << getRegisterName(Base); + O << Disp << "("; + printRegName(O, Length); + if (Base) { + O << ","; + printRegName(O, Base); + } O << ')'; } void SystemZInstPrinter::printBDVAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printAddress(MI->getOperand(OpNum).getReg(), + printAddress(&MAI, MI->getOperand(OpNum).getReg(), MI->getOperand(OpNum + 1).getImm(), MI->getOperand(OpNum + 2).getReg(), O); } diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp --- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp +++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp @@ -739,7 +739,7 @@ unsigned OpNo, const char *ExtraCode, raw_ostream &OS) { - SystemZInstPrinter::printAddress(MI->getOperand(OpNo).getReg(), + SystemZInstPrinter::printAddress(MAI, MI->getOperand(OpNo).getReg(), MI->getOperand(OpNo + 1).getImm(), MI->getOperand(OpNo + 2).getReg(), OS); return false;