1

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

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.