[LLVMdev] Cast Pointer Address to Functions

Caldarale, Charles R Chuck.Caldarale at unisys.com
Mon Jun 18 19:38:01 PDT 2012


> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Xin Tong
> Subject: [LLVMdev] Cast Pointer Address to Functions

> I have a function address held in an uint64_t. I would like to cast
> the function address to a function prototype and create a call to the
> function in LLVM. How could I do this ?

This is what works for us:

    std::vector<Type*> margs;
    FunctionType* fType;
    PointerType* pm3_routine;
    Value* m3func;
    Value* result;

    margs.resize(1);
    margs[0] = I64;
    fType = FunctionType::get(I32, margs, false);
    pm3_routine = PointerType::get(fType, 0);
 
    m3func = Builder.CreateIntToPtr(I64_Const((uint64_t)pFunc), pm3_routine, "pm3func");
    result = Builder.CreateCall(m3func, parameter, "m3func");

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.





More information about the llvm-dev mailing list