[LLVMdev] How can I create CallInst with a pointer to function

Andrii Vasyliev andrii.vasyliev at gmail.com
Wed Oct 8 09:56:47 PDT 2008


Hi

I mean when I have in my program pointer to a function how should I
build IR to call the function by the pointer?
Or how can I create llvm::Function with a pointer to a function?
I want to have something like this:

int factorial (int n) { return n==0 ? 1 : n*factorial(n-1); }

typedef int (*intFunc) (int);
intFunc fptr = factorial;

Value * N = ConstantInt::get(Type::Int32Ty,10);
irb.CreateCall(fptr,N);

OR

Function *F = Function::Create(intFuncTy,Function::ExternalLinkage,fptr,myModule);
irb.CreateCall(F,N);

Thanks



More information about the llvm-dev mailing list