[LLVMdev] I want to do something moderately insane, please help!

Chris Lattner sabre at nondot.org
Wed Nov 29 17:45:57 PST 2006


On Wed, 29 Nov 2006, Sarah Thompson wrote:
> Sarah Thompson wrote:
>> Yes, this is all a bit nuts, and yes, it's not really how either the
>> interpreter or the jitter was meant to be used, but if I can make this

I welcome moderate insanity :)

> OK, I've answered my own question. What you need to do is export an
> initialisation function that returns a function pointer. You jit the
> initialisation function (by calling it), which also causes the
> address-taken function to be jitted. When you get the pointer back,
> *that* pointer can be called directly from C++, with no performance
> penalty. I think I'll be using this trick quite a bit.

It should be easier than that: instead of calling runFunction, just call 
EE->getPointerToFunction and cast the return pointer to be the appropriate 
function pointer.  getPointerToFunction will cause the function to be 
immediately compiled, and the function pointer is valid unless you 
explicitly release the code.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list