[LLVMdev] Hello World

Félix Cloutier felixcca at yahoo.ca
Thu Jun 24 12:16:53 PDT 2010

Hello everyone,

I've been watching LLVM since about a year now, and I thought it was finally time I'd do something with it. So I've got my hands dirty with a cool project (who knows? maybe I'll end up releasing it), but since I'm fairly new to the whole thing, there are still a number of things I'm not too sure about.

First, the way we create instructions confuses me a little. My best experience with factory-like patterns is the JavaScript DOM interface, where you'd do like document.createElement, mess with the new element, then put it back somewhere doing node.appendChild. However, seeing the results from llvm2cpp, it looks like simply creating an instruction is enough to put it somewhere (at the end of the specified basic block, I suppose) unless no parameter is specified. Skimming through the classes reference, I see no 'obvious' way to add an existing "orphan" instruction to a block. What would it be?

Also, I'd like to integrate C++ method calls to my jitted code. From what I've seen in the Kaleidoscope tutorial it's easy to use external C functions but there's nothing about C++ functions or methods. Problem is, since their names are mangled, it won't be as easy as C for C functions. What I was really looking for was a way to create a Function object from a function pointer. I think I understand why it can't be that simple (LLVM really needs a function name, and function pointers don't have that) so I've made a funny hack with dladdr to get the name of a method at runtime, but just in case I really missed something I'll ask you guys: is there a "standard", LLVM-backed way to make a Function object from a function or method with C++ linkage? (I know I could also make an extern "C" function to wrap the call, but that's not quite as fun).

Thanks for your help!

Félix Cloutier

More information about the llvm-dev mailing list