Skip to content

Conversation

@jroelofs
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the llvm:mc Machine (object) code label Oct 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 18, 2024

@llvm/pr-subscribers-mc

Author: Jon Roelofs (jroelofs)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/112980.diff

2 Files Affected:

  • (modified) llvm/include/llvm-c/Disassembler.h (+3-1)
  • (modified) llvm/lib/MC/MCDisassembler/Disassembler.cpp (+7)
diff --git a/llvm/include/llvm-c/Disassembler.h b/llvm/include/llvm-c/Disassembler.h
index b1cb35da6687a8..4bc6b04dd6eaf7 100644
--- a/llvm/include/llvm-c/Disassembler.h
+++ b/llvm/include/llvm-c/Disassembler.h
@@ -79,8 +79,10 @@ int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
 #define LLVMDisassembler_Option_AsmPrinterVariant 4
 /* The option to set comment on instructions */
 #define LLVMDisassembler_Option_SetInstrComments 8
-  /* The option to print latency information alongside instructions */
+/* The option to print latency information alongside instructions */
 #define LLVMDisassembler_Option_PrintLatency 16
+/* The option to print in color */
+#define LLVMDisassembler_Option_Color 32
 
 /**
  * Dispose of a disassembler context.
diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
index 5e5a163c290244..21fdb035bb1371 100644
--- a/llvm/lib/MC/MCDisassembler/Disassembler.cpp
+++ b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
@@ -343,5 +343,12 @@ int LLVMSetDisasmOptions(LLVMDisasmContextRef DCR, uint64_t Options){
     DC->addOptions(LLVMDisassembler_Option_PrintLatency);
     Options &= ~LLVMDisassembler_Option_PrintLatency;
   }
+  if (Options & LLVMDisassembler_Option_Color) {
+    LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR);
+    MCInstPrinter *IP = DC->getIP();
+    IP->setUseColor(true);
+    DC->addOptions(LLVMDisassembler_Option_Color);
+    Options &= ~LLVMDisassembler_Option_Color;
+  }
   return (Options == 0);
 }

@jroelofs jroelofs merged commit 709116c into llvm:main Oct 18, 2024
5 of 7 checks passed
@jroelofs jroelofs deleted the jroelofs/color-disassemble branch October 18, 2024 22:31
jroelofs added a commit to swiftlang/llvm-project that referenced this pull request Oct 18, 2024
jroelofs added a commit to swiftlang/llvm-project that referenced this pull request Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:mc Machine (object) code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants