[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


================
@@ -166,6 +169,115 @@ class SourcePrinter {
                                StringRef Delimiter = "; ");
 };
 
+struct VisualizeJumpsMode {
+  enum Chars_t { Off, ASCII, Unicode };
+  enum Colors_t { BlackAndWhite, ThreeBit, Auto };
+
+  Chars_t Chars;
+  Colors_t Colors;
+
+  VisualizeJumpsMode() : Chars(Off), Colors(BlackAndWhite) {}
+  VisualizeJumpsMode(Chars_t Chars, Colors_t Colors)
+      : Chars(Chars), Colors(Colors) {}
+
+  static VisualizeJumpsMode GetDefault() {
+    return VisualizeJumpsMode(Unicode, Auto);
+  }
+
+  bool enabled() const { return Chars != Off; }
+  bool color_enabled() const { return enabled() && Colors != BlackAndWhite; }
+  bool unicode_enabled() const { return Chars == Unicode; }
+
+  void ResolveAutoColor(raw_ostream &OS) {
+    if (Colors == Auto)
+      Colors = OS.has_colors() ? ThreeBit : BlackAndWhite;
+  }
+};
+
+class ControlFlowPrinter {
+  struct ControlFlowTarget {
+    uint64_t Target;
+    SmallVector<uint64_t, 4> Sources;
+    int Column;
+    raw_ostream::Colors Color;
+
+    ControlFlowTarget(uint64_t Target, raw_ostream::Colors Color)
+        : Target(Target), Column(~0U), Color(Color), High(Target), Low(Target) {
+    }
+    ControlFlowTarget(const ControlFlowTarget &) = delete;
+    ControlFlowTarget(ControlFlowTarget &&) = default;
+
+    void addSource(uint64_t Source) {
+      Sources.push_back(Source);
+      Low = std::min(Low, Source);
+      High = std::max(High, Source);
+    }
+
+    uint64_t Length() const { return High - Low; }
----------------
jh7370 wrote:

The functions in this class all use the [wrong naming style](https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly).

https://github.com/llvm/llvm-project/pull/74858


More information about the llvm-commits mailing list