diff options
author | Fangrui Song <maskray@google.com> | 2019-04-16 03:56:55 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-04-16 03:56:55 +0000 |
commit | fa860ff733c9b88a1989b95a787670480fb162de (patch) | |
tree | ed704c3c16c9fe65f2522f6b18271dff8077616e /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | f10065b68bedff2ae133711123d6d77628d7a0d6 (diff) | |
download | llvm-fa860ff733c9b88a1989b95a787670480fb162de.zip llvm-fa860ff733c9b88a1989b95a787670480fb162de.tar.gz llvm-fa860ff733c9b88a1989b95a787670480fb162de.tar.bz2 |
[llvm-objdump] Align instructions to a tab stop in disassembly output
This relands D60376/rL358405, with the difference: sed 'y/\t/ /' -> tr '\t' ' '
BSD sed doesn't support escape characters for the 'y' command.
I didn't use it in rL358405 because it was not listed at
https://llvm.org/docs/GettingStarted.html#software but it
should be available.
Original description:
In GNU objdump, -w/--wide aligns instructions in the disassembly output.
This patch does the same to llvm-objdump. However, we always use the
wide format (-w/--wide is ignored), because the narrow format
(instructions are misaligned) is probably not very useful.
In llvm-readobj, we made a similar decision: always use the wide format,
accept but ignore -W/--wide.
To save some columns, we change the tab before hex bytes (controlled by
--[no-]show-raw-insn) to a space.
llvm-svn: 358474
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 2606d9b..9568d34 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -595,12 +595,25 @@ public: std::vector<RelocationRef> *Rels = nullptr) { if (SP && (PrintSource || PrintLines)) SP->printSourceLine(OS, Address); - if (!NoLeadingAddr) - OS << format("%8" PRIx64 ":", Address.Address); - if (!NoShowRawInsn) { - OS << "\t"; - dumpBytes(Bytes, OS); + + { + formatted_raw_ostream FOS(OS); + if (!NoLeadingAddr) + FOS << format("%8" PRIx64 ":", Address.Address); + if (!NoShowRawInsn) { + FOS << ' '; + dumpBytes(Bytes, FOS); + } + FOS.flush(); + // The output of printInst starts with a tab. Print some spaces so that + // the tab has 1 column and advances to the target tab stop. + unsigned TabStop = NoShowRawInsn ? 16 : 40; + unsigned Column = FOS.getColumn(); + FOS.indent(Column < TabStop - 1 ? TabStop - 1 - Column : 7 - Column % 8); + + // The dtor calls flush() to ensure the indent comes before printInst(). } + if (MI) IP.printInst(MI, OS, "", STI); else |