LLVM C bindings

Hi,
I find the C bindings for LLVM very useful, since they allow to invoke
LLVM from a wider set of software tools (i.e. llvm-py uses it to
export llvm to python).
Unfortunately, it seems that llvm-c interface lacks major
functionalities, e.g. getting a pointer to a jit-ted function.
It is easy to write a small c++ wrapper to expose the functionality
that one wants (llvm-py does it for the many optimization passes not
available through c binding), but I wonder if it is possible to have a
simpler & cleaner solution, i.e. automatically generating C bindings
from c++ classes.
Or am I missing some obvious way to have the aforementioned
functionality in C without writing wrappers?

Thanks,
Corrado

I find the C bindings for LLVM very useful, since they allow to invoke LLVM from a wider set of software tools (i.e. llvm-py uses it to export llvm to python).
Unfortunately, it seems that llvm-c interface lacks major functionalities, e.g. getting a pointer to a jit-ted function.

Enhancements to the bindings are welcomed. If you have a patch to add desired functionality, please submit it.

It is easy to write a small c++ wrapper to expose the functionality that one wants (llvm-py does it for the many optimization passes not available through c binding), but I wonder if it is possible to have a simpler & cleaner solution, i.e. automatically generating C bindings from c++ classes.

If you have a successful generated binding, you're welcome to publish and/or submit it. I think a degree of editorial discretion in the bindings is advisable, but completeness might outweigh that consideration.

Or am I missing some obvious way to have the aforementioned functionality in C without writing wrappers?

Nope.

— Gordon

The API function that gives you a pointer to the jit-ed function will
be available in the next release of LLVM.
You're not the only only one who's missed it.

But I wish the Pass Manager API was more complete. I might do that if
I have a some time left over.

  -- Lennart

Corrado Zoccolo wrote:

Unfortunately, it seems that llvm-c interface lacks major
functionalities, e.g. getting a pointer to a jit-ted function.
It is easy to write a small c++ wrapper to expose the functionality
that one wants (llvm-py does it for the many optimization passes not
available through c binding), but I wonder if it is possible to have a
simpler & cleaner solution, i.e. automatically generating C bindings
from c++ classes.
  

SWIG (www.swig.org) recently added a C output mode, that is capable of
generating a C API for a C++ one.
It was a Summer of Code project, so I'm not sure how mature it is. The
docs are here:

Regards,
Paul

Corrado Zoccolo wrote:
> Unfortunately, it seems that llvm-c interface lacks major
> functionalities, e.g. getting a pointer to a jit-ted function.

Yes. I similarly found that tail calls, sret and parts of first-class structs
are not usable from OCaml and much of the functionality was not implemented
in the C API in LLVM 2.4.

SWIG (www.swig.org) recently added a C output mode, that is capable of
generating a C API for a C++ one.
It was a Summer of Code project, so I'm not sure how mature it is. The
docs are here:
SWIG download | SourceForge.net
anual/C.html

The generation of this FFI code should certainly be automated. However, if the
necessary tools are not yet stable perhaps it would be wise to consider
looser bindings such as XML-RPC? I assume there are tools that can examine a
C++ API from headers in order to create an XML-RPC server automatically?

An XML-RPC API would be trivial to use and extend from languages like OCaml
and Python and the interface code should not require any maintenance at all.