Runtime JIT: passing function pointers as values?

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.

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?

That is, a class analagous to "ConstantInt" but for pointers:
"ConstantPtr::get(MyFunctionType, &MyCPPFunction)"

- --BDS

- --

Benjamin Smedberg
Platform Guru
Mozilla Corporation
benjamin@smedbergs.us
http://benjamin.smedbergs.us/

-----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