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 -- __________________________________________________________________________ dott. Corrado Zoccolo mailto:czoccolo at gmail.com PhD - Department of Computer Science - University of Pisa, Italy --------------------------------------------------------------------------
On Feb 16, 2009, at 12:24, Corrado Zoccolo wrote:> 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 On Mon, Feb 16, 2009 at 6:24 PM, Corrado Zoccolo <czoccolo at gmail.com> wrote:> 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 > > -- > __________________________________________________________________________ > > dott. Corrado Zoccolo mailto:czoccolo at gmail.com > PhD - Department of Computer Science - University of Pisa, Italy > -------------------------------------------------------------------------- > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
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: http://swig.svn.sourceforge.net/viewvc/swig/branches/gsoc2008-maciekd/Doc/Manual/C.html Regards, Paul
On Monday 16 February 2009 20:04:38 Paul Melis wrote:> 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: > http://swig.svn.sourceforge.net/viewvc/swig/branches/gsoc2008-maciekd/Doc/M >anual/C.htmlThe 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. -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e