[llvm] [llvm-objdump] Add the --visualize-jumps option (PR #74858)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 8 08:25:29 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 435ba72afda756183a1ddc7a3a160152ad630951 8edb1fdbb74d754080c00bf2ba5ec32b21782cc8 -- llvm/lib/Support/FormattedStream.cpp llvm/tools/llvm-objdump/SourcePrinter.cpp llvm/tools/llvm-objdump/SourcePrinter.h llvm/tools/llvm-objdump/XCOFFDump.cpp llvm/tools/llvm-objdump/llvm-objdump.cpp llvm/tools/llvm-objdump/llvm-objdump.h llvm/unittests/Support/formatted_raw_ostream_test.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/tools/llvm-objdump/SourcePrinter.cpp b/llvm/tools/llvm-objdump/SourcePrinter.cpp
index 0d4f68b214..749d4e780c 100644
--- a/llvm/tools/llvm-objdump/SourcePrinter.cpp
+++ b/llvm/tools/llvm-objdump/SourcePrinter.cpp
@@ -508,18 +508,15 @@ SourcePrinter::SourcePrinter(const object::ObjectFile *Obj,
// TODO Light/dark shades? 256-color terminals?
const raw_ostream::Colors LineColors[] = {
- raw_ostream::RED,
- raw_ostream::GREEN,
- raw_ostream::YELLOW,
- raw_ostream::BLUE,
- raw_ostream::MAGENTA,
- raw_ostream::CYAN,
+ raw_ostream::RED, raw_ostream::GREEN, raw_ostream::YELLOW,
+ raw_ostream::BLUE, raw_ostream::MAGENTA, raw_ostream::CYAN,
};
void ControlFlowPrinter::addEdge(uint64_t From, uint64_t To) {
auto It = Targets.find(To);
if (It == Targets.end())
- It = Targets.insert(std::make_pair(To, ControlFlowTarget(To, PickColor()))).first;
+ It = Targets.insert(std::make_pair(To, ControlFlowTarget(To, PickColor())))
+ .first;
It->second.addSource(From);
}
@@ -552,12 +549,11 @@ void ControlFlowPrinter::finalise() {
MaxColumn = std::max(MaxColumn, Column);
#if 1
- LLVM_DEBUG(
- dbgs() << "Target: 0x" << Twine::utohexstr(T->Target) << " (" << T->Length()
- << ") Column " << Column << ":\n";
- for (auto Source : T->Sources)
- dbgs() << " Source: 0x" << Twine::utohexstr(Source) << "\n";
- );
+ LLVM_DEBUG(dbgs() << "Target: 0x" << Twine::utohexstr(T->Target) << " ("
+ << T->Length() << ") Column " << Column << ":\n";
+ for (auto Source
+ : T->Sources) dbgs()
+ << " Source: 0x" << Twine::utohexstr(Source) << "\n";);
#endif
}
@@ -565,8 +561,8 @@ void ControlFlowPrinter::finalise() {
}
const char *ControlFlowPrinter::getLineChar(LineChar C) const {
- bool IsASCII =
- (OutputMode & VisualizeJumpsMode::CharsMask) == VisualizeJumpsMode::CharsASCII;
+ bool IsASCII = (OutputMode & VisualizeJumpsMode::CharsMask) ==
+ VisualizeJumpsMode::CharsASCII;
switch (C) {
case LineChar::Horiz:
return IsASCII ? "-" : (const char *)u8"\u2500";
diff --git a/llvm/tools/llvm-objdump/SourcePrinter.h b/llvm/tools/llvm-objdump/SourcePrinter.h
index c311277121..44fdb8ab7f 100644
--- a/llvm/tools/llvm-objdump/SourcePrinter.h
+++ b/llvm/tools/llvm-objdump/SourcePrinter.h
@@ -174,7 +174,7 @@ enum VisualizeJumpsMode : int {
ColorAuto = 0x1,
Color3Bit,
- //Color8Bit, // TODO GNU objdump can use more colors in 256-color terminals
+ // Color8Bit, // TODO GNU objdump can use more colors in 256-color terminals
CharsASCII = 0x10,
CharsUnicode = 0x20,
@@ -183,7 +183,6 @@ enum VisualizeJumpsMode : int {
CharsMask = 0xf0,
};
-
extern const raw_ostream::Colors LineColors[6];
class ControlFlowPrinter {
@@ -194,7 +193,8 @@ class ControlFlowPrinter {
raw_ostream::Colors Color;
ControlFlowTarget(uint64_t Target, raw_ostream::Colors Color)
- : Target(Target), Column(~0U), Color(Color), High(Target), Low(Target) {}
+ : Target(Target), Column(~0U), Color(Color), High(Target), Low(Target) {
+ }
ControlFlowTarget(const ControlFlowTarget &) = delete;
ControlFlowTarget(ControlFlowTarget &&) = default;
@@ -241,11 +241,11 @@ class ControlFlowPrinter {
int NextColorIdx;
raw_ostream::Colors PickColor() {
- if ((OutputMode & VisualizeJumpsMode::ColorMask) ==
- VisualizeJumpsMode::Off)
+ if ((OutputMode & VisualizeJumpsMode::ColorMask) == VisualizeJumpsMode::Off)
return raw_ostream::RESET;
auto Ret = LineColors[NextColorIdx];
- NextColorIdx = (NextColorIdx + 1) % (sizeof(LineColors) / sizeof(LineColors[0]));
+ NextColorIdx =
+ (NextColorIdx + 1) % (sizeof(LineColors) / sizeof(LineColors[0]));
return Ret;
}
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 9cfd126072..a41ca6d21e 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -509,7 +509,7 @@ unsigned objdump::GetColumnIndent(MCSubtargetInfo const &STI,
// Encoding: depends on architecture
if (ShowRawInsn)
- Indent += EncodingColumnWidth(STI.getTargetTriple());
+ Indent += EncodingColumnWidth(STI.getTargetTriple());
// Special case for assembly string: the assembly printer uses tabs, so we
// need to ensure we start the instruction on a tab stop (multiple of 8).
@@ -543,7 +543,7 @@ void objdump::IndentToColumn(MCSubtargetInfo const &STI,
if (Col == DisassemblyColumn::Assembly) {
TargetIndent -= 1;
if (TargetIndent < CurrentIndent)
- TargetIndent = alignTo(CurrentIndent + 1, 8) - 1;
+ TargetIndent = alignTo(CurrentIndent + 1, 8) - 1;
}
if (TargetIndent > CurrentIndent)
@@ -1359,14 +1359,12 @@ collectBBAddrMapLabels(const std::unordered_map<uint64_t, BBAddrMap> &AddrToBBAd
}
}
-static void
-collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA,
- MCDisassembler *DisAsm, MCInstPrinter *IP,
- const MCSubtargetInfo *STI, uint64_t SectionAddr,
- uint64_t Start, uint64_t End,
- std::unordered_map<uint64_t, std::string> &Labels,
- ControlFlowPrinter &CFP,
- std::vector<RelocationRef> &Relocs) {
+static void collectLocalBranchTargets(
+ ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA, MCDisassembler *DisAsm,
+ MCInstPrinter *IP, const MCSubtargetInfo *STI, uint64_t SectionAddr,
+ uint64_t Start, uint64_t End,
+ std::unordered_map<uint64_t, std::string> &Labels, ControlFlowPrinter &CFP,
+ std::vector<RelocationRef> &Relocs) {
if (MIA)
MIA->resetState();
@@ -1952,7 +1950,6 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
Start -= SectionAddr;
End -= SectionAddr;
-
formatted_raw_ostream FOS(outs());
if (!PrintedSection) {
@@ -3394,7 +3391,8 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
if (DisassemblyColor == ColorOutput::Invalid)
invalidArgValue(A);
}
- if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_visualize_jumps, OBJDUMP_visualize_jumps_EQ)) {
+ if (const opt::Arg *A = InputArgs.getLastArg(OBJDUMP_visualize_jumps,
+ OBJDUMP_visualize_jumps_EQ)) {
if (A->getOption().matches(OBJDUMP_visualize_jumps)) {
// --visualize-jumps without an argument default to unicode, auto-color.
VisualizeJumps = (VisualizeJumpsMode)(VisualizeJumpsMode::CharsUnicode |
``````````
</details>
https://github.com/llvm/llvm-project/pull/74858
More information about the llvm-commits
mailing list