[llvm] [llvm-objdump] Add the --visualize-jumps option (PR #74858)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 14 01:01:43 PST 2023
================
@@ -503,5 +506,188 @@ SourcePrinter::SourcePrinter(const object::ObjectFile *Obj,
Symbolizer.reset(new symbolize::LLVMSymbolizer(SymbolizerOpts));
}
+// 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::Colors ControlFlowPrinter::PickColor() {
+ if (!OutputMode.color_enabled())
+ return raw_ostream::RESET;
+ auto Ret = LineColors[NextColorIdx];
+ NextColorIdx =
+ (NextColorIdx + 1) % (sizeof(LineColors) / sizeof(LineColors[0]));
+ return Ret;
+}
+
+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->second.addSource(From);
+}
+
+void ControlFlowPrinter::finalise() {
+ if (!OutputMode.enabled()) {
+ setControlFlowColumnWidth(0);
+ return;
+ }
+
+ SmallVector<ControlFlowTarget *> SortedTargets;
+ for (auto &[Addr, Info] : Targets) {
+ SortedTargets.push_back(&Info);
+ }
+ std::sort(SortedTargets.begin(), SortedTargets.end(),
+ [](ControlFlowTarget *LHS, ControlFlowTarget *RHS) {
+ return LHS->Length() < RHS->Length();
+ });
+
+ // FIXME This is O(n^3) in the worst case, can we do better?
+ for (auto &T : SortedTargets) {
----------------
jh7370 wrote:
[Too much `auto`.](https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable)
Applies in a few other places too.
https://github.com/llvm/llvm-project/pull/74858
More information about the llvm-commits
mailing list