Hi,
How do I create function pointers in LLVM? Is it possible to assign a
function to a function pointer?
Thanks
Hi,
How do I create function pointers in LLVM? Is it possible to assign a
function to a function pointer?
Thanks
This is really easy with LLVM: a Function *is* a function pointer. Thus the following is perfectly legal:
%FP = global void ()* null
implementation
void %func() {
store void ()* %func, void ()** %FP
call void %caller( void ()* %func )
ret void
}
void %caller(void ()* %fp2) {
call void %fp2( )
ret void
}
... etc. You can even play fun games that you can't in C (at least without casting). For example, you can have a function return a pointer to itself:
%FPTy = type %FPTy* ()
implementation
%FPTy* %func() {
ret %FPTy* %func
}
-Chris