diff options
author | Fangrui Song <maskray@google.com> | 2019-04-15 13:32:41 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-04-15 13:32:41 +0000 |
commit | b688a200e4c47bd2915f3fd3f5afcb4928f9a0fb (patch) | |
tree | bd9d2245111db8145990736d627f65894772b790 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 5e13cd2e61cb187f28d743c15141333530cc1adf (diff) | |
download | llvm-b688a200e4c47bd2915f3fd3f5afcb4928f9a0fb.zip llvm-b688a200e4c47bd2915f3fd3f5afcb4928f9a0fb.tar.gz llvm-b688a200e4c47bd2915f3fd3f5afcb4928f9a0fb.tar.bz2 |
[llvm-objdump] Align instructions to a tab stop in disassembly output
Summary:
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.
Reviewers: rupprecht, jhenderson, grimar
Reviewed By: jhenderson
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60376
llvm-svn: 358405
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 3ae72c7..0722db0 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -605,12 +605,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 |