Creating Function Pointers in LLVM

I am writing my first LLVM sample. I am trying to create a small LLVM module consisting of a function that takes a function name and returns a pointer to it. The problem is that I do not know how to create function pointers in LLVM. I have a Function object by calling getDeclaration(...) . Is there any way to get a pointer to it?

+4
source share
1 answer

A function is a GlobalValue, so it is a pointer in itself. In the meantime, you can use the LLVM C ++ backend to generate C ++ API calls that recreate the IR that you submit to llc.

For example, feed the following code at http://llvm.org/demo :

 void foo(int (*bar)(int)); int factorial(int X); int main(int argc, char **argv) { foo(factorial); } 

Make sure that the β€œShow LLVM C ++ API Code” checkbox is selected, and you will see the corresponding LLVM IR and ++ C API calls, which will create it again.

+5
source

Source: https://habr.com/ru/post/1345520/


All Articles