[LLVMdev] X86 Disassembler

Sean Callanan scallanan at apple.com
Thu Sep 3 17:25:48 PDT 2009

I was away doing other things for a while, but I have an API patch  
separated out, which (in addition to being much smaller than past  
megapatches) corrects two issues Chris identified in his most recent  
set of patches:

- First, it makes the API a good deal simpler.  Now, you can  
instantiate a single MCDisassembler and, each time you want an  
instruction disassembled, you can simply pass it a MemoryRegion, an  
offset, and an MCInst to populate.

- Second, it adds MCDisassembler to the list of things you can get  
from a TargetMachine, so you don't have to #include something from lib/ 
Target/X86 just to use the X86 disassembler.

Please let me know what you think of this API.  Thanks for your time.


I have included Chris's previous comments below.

On Aug 22, 2009, at 4:31 PM, Chris Lattner wrote:
> The MCDisassembler API is also somewhat strange to me.  Right now it  
> is designed to analyze a memory region when constructed and contain  
> them.  It seems that there is a more useful low level API which  
> would look something like this:
> class MCDisassembler {
> public:
>  virtual ~MCDisassembler();
>  /// DisassembleInstruction - Disassemble the first instruction in  
> the specified region, printing the disassembled instruction to the  
> specified raw_ostream, and returning the size of the instruction in  
> bytes.  On error, this returns zero and fills in ErrorInfo with a  
> human readable description of the error.
>  virtual unsigned DisassembleInstruction(MemoryObject &region,  
> raw_ostream &OS, std::string &ErrorInfo) = 0;
> }
> Having this sort of stateless API means that higher level clients  
> (which are stateful) can be built on top of them without adding  
> overhead to clients who don't care about the state.

> Instead of doing something like this, the X86 disassembler should  
> register itself as part of the "Target" API the same way that  
> asmprinters, MCAsmInfo, targets, etc do.  The X86 specific  
> disassembler should go in lib/Target/X86/Disassembler.  Take a look  
> at how the Target/X86/AsmParser stuff registers itself for a good  
> example.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090903/16292849/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-disassembler-api.diff
Type: application/octet-stream
Size: 10632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090903/16292849/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090903/16292849/attachment-0001.html>

More information about the llvm-dev mailing list