[LLVMdev] Using LLVM with Ada

Duncan Sands baldrick at free.fr
Tue Aug 31 09:55:15 PDT 2010

Hi Enrico,

> However, I would be interested in calling different llvm tools in a
> non-transparent way. For example I would like to call llvm-gcc to obtain
> the LLVM intermediate representation of a compilation module
> (e.g., llvm-gcc -c hello.adb) and then invoke different llvm tools.

you should add -emit-llvm to the command line (or optimized at -O4 or
above), for example
   llvm-gcc -c hello.adb -emit-llvm -o hello.bc
results in LLVM bitcode in hello.bc.  You don't have to name the output
hello.bc, but it is traditional to use the .bc extension for bitcode.

> The problem is that I do not know how to include the information
> from the .ali files generated by gnat. In the lack of such information
> llvmc (for example) is not able to find a proper main for my program and
> raises an undefined reference error.

The main program is generated by "gnatbind".  You can just run gnatbind
by hand to produce the main program which you can then also compile to
bitcode using llvm-gcc.  You can link everything together to get one huge
module containing bitcode for your entire program if you like (good for
doing link-time optimization).  If you make use of the gold plugin (see
http://llvm.org/docs/GoldPlugin.html) then this is all very easy, otherwise
you will have to play around a little bit to get this working nicely with

By the way, I never used llvmc myself, just the usual tools (llvm-ld or
llvm-link, opt, llc) by hand.

> I was wandering if it is actually possible to exploit the LLVM framework in
> such a sequential manner as it is for C programs.

It is.



More information about the llvm-dev mailing list