[LLVMdev] Python bindings in tree

Gregory Szorc gregory.szorc at gmail.com
Sun Mar 18 21:52:12 PDT 2012


On 3/17/2012 4:14 PM, Anders Waldenborg wrote:
> 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.

The automatic generation of the Python ctypes interfaces using the Clang
Python bindings is pretty friggin cool!

> My local copy also contain a few patches to llvm-c.
> 
> Everything can be found here:
> http://people.0x63.nu/~andersg/llvm-python-bindings/
> 
> 
> * 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.

These are desperately needed by the C API. Can you please submit them?

FWIW, all my work is at
https://github.com/indygreg/llvm/tree/python_bindings/bindings/python.
Parts of Core.h still need love (especially the Value system). I'm doing
some dynamic type creation at run-time using the Value hierarchy.
Somewhat scary stuff, but it does seem to work. I really need a
LLVMGetValueID() API to fetch llvm::Value::getValueID() to enable more
efficient value casting. From some discussion on #llvm, I think people
are receptive to this. The main concern would be that the C API would be
tied to a specific version of the shared library because the value ID
enumeration aren't guaranteed for all of time. But, that contract is
already broken, so I don't think it's a big deal: just something that
needs to be documented. Of course, Python is a dynamic language, so if
there were a C API that exposed the llvm::Value class hierarchy, we
could always have Python dynamically create types at run-time :)

I've also implemented some missing C APIs (such as IR parsing and more
ObjectFile APIs) and have patches awaiting review on the mailing list.

Greg




More information about the llvm-dev mailing list