[LLVMdev] Runtime JIT: passing function pointers as values?
Chris Lattner
sabre at nondot.org
Sat Dec 1 17:31:38 PST 2007
On Dec 1, 2007, at 7:32 AM, Benjamin Smedberg wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'm a LLVM newbie who's started experimenting with the JIT, and I
> have a
> couple questions relating to LLVM and the runtime JIT: I'm going to
> post
> them as separate messages to avoid getting threads tangled up.
Ok.
> I want to call a C++ function from a function that was JITted at
> runtime.
> I'm starting with HowToUseJIT.cpp as a base for experimentation. Is it
> possible to take the address of the C++ function and pass it to the
> JIT
> directly as a value, rather than referencing the function by a
> symbolic name?
Sure, just cast the pointer value to an integer type (in your C++
code) then pass that value to ConstantInt::get(...);
Then pass the resultant Constant* to ConstantExpr::getIntToPtr(C,
<yourpointertype>);
You now have an LLVM Constant* for your pointer.
-Chris
More information about the llvm-dev
mailing list