[LLVMdev] Hello World

Félix Cloutier felixcca at yahoo.ca
Thu Jun 24 22:49:18 PDT 2010


> Felix,
> 
> It really depends on what you are doing with the JIT.
> 
> In my case, I have a scripting language that has a limited set of base data types. I wanted to be able to trivially interface to new C++ methods and classes, so I'm interfacing to C++ classes by creating external definitions much like the way Kaleidoscope accesses external C functions. I only have to deal with a few types so I can do the name mangling automatically pretty easily without having to do too much work. If you are just dealing with relatively simple functions it's not too hard. See section 5.1.2 of the document here:
> 
> http://www.codesourcery.com/public/cxx-abi/abi.html 
> 
> for details on the mangling, if you are targeting the Itanium ABI which is the gcc/clang default ABI for X86-64.
What I want to do is simple enough. My program only has to interface with a fixed set of methods known at compile-time.

My hack simply consists of determining the actual function address from a method pointer, then using dladdr to find out what its name is. But as Eli suggested, since I've got the function pointer already, I'd be better off using ExecutionEngine::addGlobalMapping.

> I have found the following suggestion (made by someone on the llvm IRC channel) to figure out how LLVM IR works extremely helpful. First, I write a small sample code in C or C++ which I then compile into LLVM IR using:
> 
> /usr/local/bin/clang++ -S -O0 -emit-llvm source.cpp
> 
> where source.cpp  contains my sample C++ code or 
> 
> /usr/local/bin/clang -S -O0 -emit-llvm source.c 
> 
> for C code.
> 
> I suggest building clang and LLVM from trunk if you are going to be doing much with C++ as 2.7's C++ support is not near as good as trunk's. 
> 
> Once you've decided exactly what LLVM IR you want. You can see how to use the IRBuilder to create it using the very handy:
> 
> /usr/local/bin/llc -march=cpp source.s
> 
> which creates a file called source.s.cpp which contains the C++ which will create the LLVM IR found in source.s.
> 
> I hope that helps.
> 
Yup, that's what I've been doing (though I've been doing it through the web interface of the LLVM website). 

Thanks for your help!

Félix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100625/c24ca0a0/attachment.html>


More information about the llvm-dev mailing list