[llvm] [llvm-objdump] Add the --visualize-jumps option (PR #74858)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 09:02:24 PST 2023


================
@@ -471,32 +473,93 @@ static bool getHidden(RelocationRef RelRef) {
   return false;
 }
 
-/// Get the column at which we want to start printing the instruction
-/// disassembly, taking into account anything which appears to the left of it.
-unsigned objdump::getInstStartColumn(const MCSubtargetInfo &STI) {
-  return !ShowRawInsn ? 16 : STI.getTargetTriple().isX86() ? 40 : 24;
+static int ControlFlowColumnWidth = 0;
+void objdump::setControlFlowColumnWidth(int Width) {
+  ControlFlowColumnWidth = Width;
 }
 
-static void AlignToInstStartColumn(size_t Start, const MCSubtargetInfo &STI,
-                                   raw_ostream &OS) {
-  // 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 = getInstStartColumn(STI);
-  unsigned Column = OS.tell() - Start;
-  OS.indent(Column < TabStop - 1 ? TabStop - 1 - Column : 7 - Column % 8);
+unsigned EncodingColumnWidth(Triple const &Triple) {
+  switch (Triple.getArch()) {
+  case Triple::x86:
+  case Triple::x86_64:
+    return 30;
+  default:
+    return 14;
+  }
+}
+
+unsigned objdump::GetColumnIndent(MCSubtargetInfo const &STI,
+                                  DisassemblyColumn Col) {
+  unsigned Indent = 0;
+
+  if (Col == DisassemblyColumn::Address)
+    return Indent;
+
+  // Address: 8 chars of address, followed by ": "
+  Indent += 10;
+
+  if (Col == DisassemblyColumn::ControlFlow)
+    return Indent;
+
+  // Control-flow graph: depends on function, disabled by default.
+  Indent += ControlFlowColumnWidth;
+
+  if (Col == DisassemblyColumn::Encoding)
+    return Indent;
+
+  // Encoding: depends on architecture
+  if (ShowRawInsn)
+      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).
+  Indent = alignTo(Indent, 8);
+  if (Col == DisassemblyColumn::Assembly) {
+    return Indent;
+  }
----------------
nickdesaulniers wrote:

remove braces for single statement ifs.

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


More information about the llvm-commits mailing list