Index: llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h =================================================================== --- llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h +++ llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.h @@ -33,16 +33,14 @@ static const char *getRegisterName(unsigned RegNo); // Print an address with the given base, displacement and index. - static void printAddress(const MCAsmInfo *MAI, unsigned Base, - const MCOperand &DispMO, unsigned Index, - raw_ostream &O); + void printAddress(const MCAsmInfo *MAI, unsigned Base, + const MCOperand &DispMO, unsigned Index, raw_ostream &O); // Print the given operand. - static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, - raw_ostream &O); + void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, raw_ostream &O); - static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo, - raw_ostream &O); + void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo, + raw_ostream &O) const; // Override MCInstPrinter. inline void printRegName(raw_ostream &O, unsigned RegNo) const override { Index: llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp =================================================================== --- llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp +++ llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp @@ -49,7 +49,7 @@ printFormattedRegName(MAI, MO.getReg(), O); } else if (MO.isImm()) - O << MO.getImm(); + O << markup(""); else if (MO.isExpr()) MO.getExpr()->print(O, MAI); else @@ -57,14 +57,15 @@ } void SystemZInstPrinter::printFormattedRegName(const MCAsmInfo *MAI, - unsigned RegNo, raw_ostream &O) { + unsigned RegNo, + raw_ostream &O) const { 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); + O << markup(""); } else - O << '%' << RegName; + O << markup(""); } void SystemZInstPrinter::printInst(const MCInst *MI, uint64_t Address, @@ -75,90 +76,101 @@ } template -static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { +static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O, + bool UseMarkup) { int64_t Value = MI->getOperand(OpNum).getImm(); assert(isUInt(Value) && "Invalid uimm argument"); + if (UseMarkup) + O << ""; } template -static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { +static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O, + bool UseMarkup) { int64_t Value = MI->getOperand(OpNum).getImm(); assert(isInt(Value) && "Invalid simm argument"); + if (UseMarkup) + O << ""; } void SystemZInstPrinter::printU1ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<1>(MI, OpNum, O); + printUImmOperand<1>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU2ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<2>(MI, OpNum, O); + printUImmOperand<2>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU3ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<3>(MI, OpNum, O); + printUImmOperand<3>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU4ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<4>(MI, OpNum, O); + printUImmOperand<4>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU6ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<6>(MI, OpNum, O); + printUImmOperand<6>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printS8ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printSImmOperand<8>(MI, OpNum, O); + printSImmOperand<8>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU8ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<8>(MI, OpNum, O); + printUImmOperand<8>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU12ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<12>(MI, OpNum, O); + printUImmOperand<12>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printS16ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printSImmOperand<16>(MI, OpNum, O); + printSImmOperand<16>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU16ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<16>(MI, OpNum, O); + printUImmOperand<16>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printS32ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printSImmOperand<32>(MI, OpNum, O); + printSImmOperand<32>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU32ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<32>(MI, OpNum, O); + printUImmOperand<32>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printU48ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) { - printUImmOperand<48>(MI, OpNum, O); + printUImmOperand<48>(MI, OpNum, O, UseMarkup); } void SystemZInstPrinter::printPCRelOperand(const MCInst *MI, int OpNum, raw_ostream &O) { const MCOperand &MO = MI->getOperand(OpNum); if (MO.isImm()) { - O << "0x"; + O << markup(""); } else MO.getExpr()->print(O, &MAI); } Index: llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp =================================================================== --- llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp +++ llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp @@ -785,6 +785,49 @@ OutStreamer->emitValue(Expr, Size); } +static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo, + raw_ostream &OS) { + const char *RegName = SystemZInstPrinter::getRegisterName(RegNo); + if (MAI->getAssemblerDialect() == AD_HLASM) { + // Skip register prefix so that only register number is left + assert(isalpha(RegName[0]) && isdigit(RegName[1])); + OS << (RegName + 1); + } else + OS << '%'; +} + +static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI, + raw_ostream &OS) { + if (MCOp.isReg()) { + if (!MCOp.getReg()) + OS << '0'; + else + printFormattedRegName(MAI, MCOp.getReg(), OS); + } else if (MCOp.isImm()) + OS << MCOp.getImm(); + else if (MCOp.isExpr()) + MCOp.getExpr()->print(OS, MAI); + else + llvm_unreachable("Invalid operand"); +} + +static void printAddress(const MCAsmInfo *MAI, unsigned Base, + const MCOperand &DispMO, unsigned Index, + raw_ostream &OS) { + printOperand(DispMO, MAI, OS); + if (Base || Index) { + OS << '('; + if (Index) { + printFormattedRegName(MAI, Index, OS); + if (Base) + OS << ','; + } + if (Base) + printFormattedRegName(MAI, Base, OS); + OS << ')'; + } +} + bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) { @@ -802,7 +845,7 @@ SystemZMCInstLower Lower(MF->getContext(), *this); MCOp = Lower.lowerOperand(MO); } - SystemZInstPrinter::printOperand(MCOp, MAI, OS); + printOperand(MCOp, MAI, OS); return false; } @@ -810,10 +853,9 @@ unsigned OpNo, const char *ExtraCode, raw_ostream &OS) { - SystemZInstPrinter:: - printAddress(MAI, MI->getOperand(OpNo).getReg(), - MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()), - MI->getOperand(OpNo + 2).getReg(), OS); + printAddress(MAI, MI->getOperand(OpNo).getReg(), + MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()), + MI->getOperand(OpNo + 2).getReg(), OS); return false; } Index: llvm/test/MC/Disassembler/SystemZ/marked-up.txt =================================================================== --- /dev/null +++ llvm/test/MC/Disassembler/SystemZ/marked-up.txt @@ -0,0 +1,10 @@ +# RUN: llvm-mc --mdis %s -triple=s390x-linux-gnu -mcpu=zEC12 2>&1 | FileCheck %s + +# CHECK: blr +0x07 0x4a +# CHECK: lrl , +0xc4 0xfd 0x00 0x00 0x00 0x47 +# CHECK: stc , +0x42 0x00 0x0f 0xff +# CHECK: trace , , () +0x99 0x00 0x10 0x00