hooch
hooch

Reputation: 1175

Llvm C++ API pass Pointer to Function to another Function

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!

Upvotes: 1

Views: 302

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

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.

Upvotes: 1

Related Questions