[BOLT][NFC] Customize endline character for printInstruction(s)

This would be used in `BF::dumpGraph` to dump left-justified text.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D126232
This commit is contained in:
Amir Ayupov 2022-05-24 18:25:40 -07:00
parent 5d8247d4c7
commit 69f87b6c29
2 changed files with 11 additions and 8 deletions

View File

@ -1187,7 +1187,8 @@ public:
uint64_t Offset = 0,
const BinaryFunction *Function = nullptr,
bool PrintMCInst = false, bool PrintMemData = false,
bool PrintRelocations = false) const;
bool PrintRelocations = false,
StringRef Endl = "\n") const;
/// Print a range of instructions.
template <typename Itr>
@ -1195,10 +1196,11 @@ public:
printInstructions(raw_ostream &OS, Itr Begin, Itr End, uint64_t Offset = 0,
const BinaryFunction *Function = nullptr,
bool PrintMCInst = false, bool PrintMemData = false,
bool PrintRelocations = false) const {
bool PrintRelocations = false,
StringRef Endl = "\n") const {
while (Begin != End) {
printInstruction(OS, *Begin, Offset, Function, PrintMCInst, PrintMemData,
PrintRelocations);
PrintRelocations, Endl);
Offset += computeCodeSize(Begin, Begin + 1);
++Begin;
}

View File

@ -1643,9 +1643,10 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
uint64_t Offset,
const BinaryFunction *Function,
bool PrintMCInst, bool PrintMemData,
bool PrintRelocations) const {
bool PrintRelocations,
StringRef Endl) const {
if (MIB->isEHLabel(Instruction)) {
OS << " EH_LABEL: " << *MIB->getTargetSymbol(Instruction) << '\n';
OS << " EH_LABEL: " << *MIB->getTargetSymbol(Instruction) << Endl;
return;
}
OS << format(" %08" PRIx64 ": ", Offset);
@ -1654,7 +1655,7 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
OS << "\t!CFI\t$" << Offset << "\t; ";
if (Function)
printCFI(OS, *Function->getCFIFor(Instruction));
OS << "\n";
OS << Endl;
return;
}
InstPrinter->printInst(&Instruction, 0, "", *STI, OS);
@ -1718,11 +1719,11 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
Function->printRelocations(OS, Offset, Size);
}
OS << "\n";
OS << Endl;
if (PrintMCInst) {
Instruction.dump_pretty(OS, InstPrinter.get());
OS << "\n";
OS << Endl;
}
}