Skip to content

Commit 62183c4

Browse files
committed
Add support for annotated disassembly output for X86 and arm.
Per the October 12, 2012 Proposal for annotated disassembly output sent out by Jim Grosbach this set of changes implements this for X86 and arm. The llvm-mc tool now has a -mdis option to produced the marked up disassembly and a couple of small example test cases have been added. rdar://11764962 llvm-svn: 166445
1 parent 929fccd commit 62183c4

File tree

9 files changed

+570
-133
lines changed

9 files changed

+570
-133
lines changed

llvm/include/llvm-c/Disassembler.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
145145
int TagType, LLVMOpInfoCallback GetOpInfo,
146146
LLVMSymbolLookupCallback SymbolLookUp);
147147

148+
/**
149+
* Set the disassembler's options. Returns 1 if it can set the Options and 0
150+
* otherwise.
151+
*/
152+
int LLVMSetDisasmOptions(LLVMDisasmContextRef DC, uint64_t Options);
153+
154+
/* The option to produce marked up assembly. */
155+
#define LLVMDisassembler_Option_UseMarkup 1
156+
148157
/**
149158
* Dispose of a disassembler context.
150159
*/

llvm/include/llvm/MC/MCInstPrinter.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ class MCInstPrinter {
3333
/// The current set of available features.
3434
unsigned AvailableFeatures;
3535

36+
/// True if we are printing marked up assembly.
37+
bool UseMarkup;
38+
3639
/// Utility function for printing annotations.
3740
void printAnnotation(raw_ostream &OS, StringRef Annot);
3841
public:
3942
MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
4043
const MCRegisterInfo &mri)
41-
: CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0) {}
44+
: CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0),
45+
UseMarkup(0) {}
4246

4347
virtual ~MCInstPrinter();
4448

@@ -59,6 +63,9 @@ class MCInstPrinter {
5963

6064
unsigned getAvailableFeatures() const { return AvailableFeatures; }
6165
void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
66+
67+
bool getUseMarkup() const { return UseMarkup; }
68+
void setUseMarkup(bool Value) { UseMarkup = Value; }
6269
};
6370

6471
} // namespace llvm

llvm/lib/MC/MCDisassembler/Disassembler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,17 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes,
184184
}
185185
llvm_unreachable("Invalid DecodeStatus!");
186186
}
187+
188+
//
189+
// LLVMSetDisasmOptions() sets the disassembler's options. It returns 1 if it
190+
// can set all the Options and 0 otherwise.
191+
//
192+
int LLVMSetDisasmOptions(LLVMDisasmContextRef DCR, uint64_t Options){
193+
if (Options & LLVMDisassembler_Option_UseMarkup){
194+
LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR;
195+
MCInstPrinter *IP = DC->getIP();
196+
IP->setUseMarkup(1);
197+
Options &= ~LLVMDisassembler_Option_UseMarkup;
198+
}
199+
return (Options == 0);
200+
}

0 commit comments

Comments
 (0)