[LLVMdev] Python bindings in tree

Anders Waldenborg anders at 0x63.nu
Sat Mar 17 16:14:43 PDT 2012


At Fri, 16 Mar 2012 14:12:08 +0100,
Christoph Grenz wrote:
> 
> Hello,
> 
> Am Donnerstag, 15. März 2012, 21:15:02 schrieb Gregory Szorc:
> > There was some talk on IRC last week about desire for Python bindings to
> > LLVM's Object.h C interface. So, I coded up some and you can now find
> > some Python bindings in trunk at bindings/python. Currently, the
> > interfaces for Object.h and Disassembler.h are implemented.
> 
> 
> FYI:
> 
> I recently startet working on Python3 bindings for LLVM 3 as all bindings I 
> could find were for LLVM 2.x and up to Python 2.6.
> I used Cython for easier coding and already ported a big part of Core.h 
> including all Type and Value classes.

FYI:

I've also been working on new python bindings.

My bindings are written using ctypes (just like the in-tree
clang/cindex bindings). Most of Core.h is bound, and stuff from
ExecutionEngine.h, Analysis, BitReader, BitWriter. The have fairly
good test coverage (using nosetests). The ctypes definitions are
generated from the header files using the clang python bindings.


My local copy also contain a few patches to llvm-c.

Everything can be found here:
http://people.0x63.nu/~andersg/llvm-python-bindings/


* 0001-Fix-class-hierarchy-indentation-in-LLVM_FOR_EACH_VAL.patch
* 0029-Trivial-copy-paste-error-in-LangRef.patch
  These are just cosmetic stuff that I stumbled upon

* 0004-Add-LLVMPrintModule-to-llvm-c.patch
  Adds a new LLVMPrintModule function which is similar to
  LLVMDumpModule but dumps to a string instead of stdout.

* 0005-Add-LLVMCreateMemoryBufferFromData-to-llvm-c.patch
  Adds LLVMCreateMemoryBufferFromData function.

* 0015-LLVMMessageRef.patch
  Adds a "typedef char *LLVMMessageRef;". Which may seem useless. But
  it acts as documentation. All functions that return a string that
  should be freed with LLVMDisposeMessage are changed to use this type
  instead.

* bindings-python.tar.gz
  The bindings/python/ directory.
  There are some hardcoded paths and hacks here and there.





More information about the llvm-dev mailing list