Skip to content

Commit 62a02aa

Browse files
committed
[llvm-c][MC] Expose color printing via LLVMSetDisasmOptions (llvm#112980)
(cherry picked from commit 709116c)
1 parent 75a14f1 commit 62a02aa

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/include/llvm-c/Disassembler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
7979
#define LLVMDisassembler_Option_AsmPrinterVariant 4
8080
/* The option to set comment on instructions */
8181
#define LLVMDisassembler_Option_SetInstrComments 8
82-
/* The option to print latency information alongside instructions */
82+
/* The option to print latency information alongside instructions */
8383
#define LLVMDisassembler_Option_PrintLatency 16
84+
/* The option to print in color */
85+
#define LLVMDisassembler_Option_Color 32
8486

8587
/**
8688
* Dispose of a disassembler context.

llvm/lib/MC/MCDisassembler/Disassembler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
277277
SmallVector<char, 64> InsnStr;
278278
raw_svector_ostream OS(InsnStr);
279279
formatted_raw_ostream FormattedOS(OS);
280+
281+
if (DC->getOptions() & LLVMDisassembler_Option_Color) {
282+
FormattedOS.enable_colors(true);
283+
IP->setUseColor(true);
284+
}
285+
280286
IP->printInst(&Inst, PC, AnnotationsStr, *DC->getSubtargetInfo(),
281287
FormattedOS);
282288

@@ -343,5 +349,10 @@ int LLVMSetDisasmOptions(LLVMDisasmContextRef DCR, uint64_t Options){
343349
DC->addOptions(LLVMDisassembler_Option_PrintLatency);
344350
Options &= ~LLVMDisassembler_Option_PrintLatency;
345351
}
352+
if (Options & LLVMDisassembler_Option_Color) {
353+
LLVMDisasmContext *DC = static_cast<LLVMDisasmContext *>(DCR);
354+
DC->addOptions(LLVMDisassembler_Option_Color);
355+
Options &= ~LLVMDisassembler_Option_Color;
356+
}
346357
return (Options == 0);
347358
}

0 commit comments

Comments
 (0)