I would like to have my IR call a function which exists in the host program (the one which is creating the ExecutionEngine). I don't see from the docs on Linker, ExecutionEngine, or Module how I would go about doing this. That is, I have a function like this in my C++ code: void callback( int64_t object, int32_t value ); I would like to produce IR which links back to this function and thus can call back into the hosting code. The IR is built at runtime in the same program hosting this function. I use the JIT execution engine and then call runFunction. -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 259 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121112/5f76e40d/attachment.sig>
Hi, On 12/11/12 20:05, edA-qa mort-ora-y wrote:> I would like to have my IR call a function which exists in the host > program (the one which is creating the ExecutionEngine). I don't see > from the docs on Linker, ExecutionEngine, or Module how I would go about > doing this. > > That is, I have a function like this in my C++ code: > void callback( int64_t object, int32_t value ); > I would like to produce IR which links back to this function and thus > can call back into the hosting code. > > The IR is built at runtime in the same program hosting this function. I > use the JIT execution engine and then call runFunction.if you add a declaration for your callback in the IR, and add some calls to it, the symbol should be automatically resolved by the JIT as far as I know (you may need to have built with libffi support). Ciao, Duncan.
On 13/11/12 09:12, Duncan Sands wrote:> if you add a declaration for your callback in the IR, and add some calls > to it, the symbol should be automatically resolved by the JIT as far as I > know (you may need to have built with libffi support).Great! I guess this also explains why printf was working in my test programs. I just assumed the JIT exposed libc automatically, but it appears it links against the current symbol table. I guess this also means the address space is actually shared. So if I pass pointers of the functions into the JIT should it also work? -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 259 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121113/ff21d3a4/attachment.sig>