[llvm-dev] How to implement function pointer? (original) (raw)

Philip Pfaffe via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 26 04:50:08 PST 2019


Hi Yafei,

a Value whose type is a FunctionType is a function pointer. You use FunctionType::get to create such a type given the return type and the argument types. Or you call foo->getType() if foo is a Function* :)

Cheers, Philip

On Tue, Feb 26, 2019 at 12:41 PM Yafei Liu <yfliu at mobvoi.com> wrote:

Hi Philip, Isn't function pointer a pointer first? I checked FunctionType and still have no idea about how to do this, can you show me which api in FunctionType should I use?

On Tue, Feb 26, 2019 at 7:18 PM Philip Pfaffe <philip.pfaffe at gmail.com> wrote:

Hi Yafei,

you're looking for the [FunctionType](_ _http://llvm.org/doxygen/classllvm11FunctionType.html). Cheers, Philip On Tue, Feb 26, 2019 at 11:15 AM Yafei Liu via llvm-dev <_ _llvm-dev at lists.llvm.org> wrote:

Hi, I'm learning to use llvm api to generate IR code, I got two good tutorials, https://llvm.org/docs/tutorial/ and https://www.ibm.com/developerworks/library/os-createcompilerllvm1/index.html, but non of those showed how to implement a function pointer(or at least there is but I didn't find out).

For example I got a c style code like this: int foo(int i) { return ++i; } int (*p)(int); int main() { p = foo; p(3); } I turn it into IR code and found the sytex of a function pointer is: @p = global i32 (i32)* null, align 8 I tried play with llvm::PointerType but I cannot get the sytex, so could anyone teach me how to do this?


LLVM Developers mailing list llvm-dev at lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190226/5911a037/attachment.html>



More information about the llvm-dev mailing list