Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-c][MC] Expose color printing via LLVMSetDisasmOptions #112980

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/include/llvm-c/Disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/MC/MCDisassembler/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
SmallVector<char, 64> InsnStr;
raw_svector_ostream OS(InsnStr);
formatted_raw_ostream FormattedOS(OS);

if (DC->getOptions() & LLVMDisassembler_Option_Color) {
FormattedOS.enable_colors(true);
IP->setUseColor(true);
}

IP->printInst(&Inst, PC, AnnotationsStr, *DC->getSubtargetInfo(),
FormattedOS);

Expand Down Expand Up @@ -343,5 +349,10 @@ 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);
DC->addOptions(LLVMDisassembler_Option_Color);
Options &= ~LLVMDisassembler_Option_Color;
}
return (Options == 0);
}
Loading