1
votes

How can I pass a pointer to function to another function? I have a function like this:

std::string PRINT_STATE_NAME(pPrintState func);

where pPrintState is a typedef like this:

typedef void (*pPrintState)(std::string* buffer);

So I JITed pPrintState and have its llvm::FunctionType available.

Next I want to call PRINT_STATE_NAME() as defined above from llvm C++ API. Unfortunately I can't figure out what parameter to pass to the call instruction. Atm I made an llvm::GlobalVariable with inner type of converted pPrintState. But what should I pass as initializer? Or am I completely on the wrong track here? Any help is appreciated! Thanks!

1

1 Answers

1
votes

You need to obtain the address of pPrintState (the JIT'ed one, via getPointerToFunction() or getPointerToNamedFunction()) cast this address (as integer) to pPrintState and pass as an argument.