diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h --- a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.h @@ -117,6 +117,8 @@ private: bool HasCustomInstComment; + + void printMarkedUpRegName(raw_ostream &OS, unsigned RegNo); }; } // end namespace llvm diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86ATTInstPrinter.cpp @@ -38,8 +38,17 @@ OS << markup(""); } +// Since printRegName is a const method, we need this non-const version to +// update MarkupState and MarkupSpans. +void X86ATTInstPrinter::printMarkedUpRegName(raw_ostream &OS, unsigned RegNo) { + OS << startMarkup(MarkupType::Reg) << '%' << getRegisterName(RegNo) + << endMarkup(); +} + void X86ATTInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot, const MCSubtargetInfo &STI) { + resetMarkup(OS); + // If verbose assembly is enabled, we can print some informative comments. if (CommentStream) HasCustomInstComment = EmitAnyX86InstComments(MI, *CommentStream, MII); @@ -353,11 +362,11 @@ raw_ostream &O) { const MCOperand &Op = MI->getOperand(OpNo); if (Op.isReg()) { - printRegName(O, Op.getReg()); + printMarkedUpRegName(O, Op.getReg()); } else if (Op.isImm()) { // Print immediates as signed values. int64_t Imm = Op.getImm(); - O << markup(""); + O << startMarkup(MarkupType::Imm) << '$' << formatImm(Imm) << endMarkup(); // TODO: This should be in a helper function in the base class, so it can // be used by other printers. @@ -376,9 +385,9 @@ } } else { assert(Op.isExpr() && "unknown operand kind in printOperand"); - O << markup("print(O, &MAI); - O << markup(">"); + O << endMarkup(); } } @@ -388,7 +397,7 @@ const MCOperand &IndexReg = MI->getOperand(Op + X86::AddrIndexReg); const MCOperand &DispSpec = MI->getOperand(Op + X86::AddrDisp); - O << markup("getOperand(Op + X86::AddrScaleAmt).getImm(); if (ScaleVal != 1) { - O << ',' << markup(""); + O << ',' << startMarkup(MarkupType::Imm) + << ScaleVal // never printed in hex. + << endMarkup(); } } O << ')'; } - O << markup(">"); + O << endMarkup(); } void X86ATTInstPrinter::printSrcIdx(const MCInst *MI, unsigned Op, raw_ostream &O) { - O << markup(""); + O << endMarkup(); } void X86ATTInstPrinter::printDstIdx(const MCInst *MI, unsigned Op, raw_ostream &O) { - O << markup(""); + O << endMarkup(); } void X86ATTInstPrinter::printMemOffset(const MCInst *MI, unsigned Op, raw_ostream &O) { const MCOperand &DispSpec = MI->getOperand(Op); - O << markup("print(O, &MAI); } - O << markup(">"); + O << endMarkup(); } void X86ATTInstPrinter::printU8Imm(const MCInst *MI, unsigned Op, @@ -471,8 +481,8 @@ if (MI->getOperand(Op).isExpr()) return printOperand(MI, Op, O); - O << markup("getOperand(Op).getImm() & 0xff) - << markup(">"); + O << startMarkup(MarkupType::Imm) << '$' + << formatImm(MI->getOperand(Op).getImm() & 0xff) << endMarkup(); } void X86ATTInstPrinter::printSTiRegOperand(const MCInst *MI, unsigned OpNo, @@ -481,7 +491,7 @@ unsigned Reg = Op.getReg(); // Override the default printing to print st(0) instead st. if (Reg == X86::ST0) - OS << markup(""); + OS << startMarkup(MarkupType::Reg) << "%st(0)" << endMarkup(); else - printRegName(OS, Reg); + printMarkedUpRegName(OS, Reg); }