Benjamin Smedberg
2007-Dec-01 15:32 UTC
[LLVMdev] Runtime JIT: passing function pointers as values?
-----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. 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 at smedbergs.us http://benjamin.smedbergs.us/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHUX5zSSwGp5sTYNkRAmA8AJ0VDsrIlzpJNE+zUg6sH9VsD2GZ5wCgjVOS xkMrt2mAL1sX8iUUhcRAz9o=R/IP -----END PGP SIGNATURE-----
Chris Lattner
2007-Dec-02 01:31 UTC
[LLVMdev] Runtime JIT: passing function pointers as values?
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