[LLVMdev] How to get a return type of a function with LLVM-C API

Gordon Henriksen gordonhenriksen at mac.com
Thu May 22 07:33:32 PDT 2008


You're trying to apply an operation on a Type to a Value; that's no  
good, as you say. So you want the return type of the type of the  
function. But the function value itself is of type %function*, so you  
have to 'dereference' the type first:

LLVMGetReturnType(LLVMGetElementType(LLVMTypeOf(F)))

This may help to clarify: http://llvm.org/docs/ProgrammersManual.html#coreclasses

On May 22, 2008, at 10:07, Syoyo Fujita wrote:

> Hi LLVM-ers,
>
> I am trying to get a return type of a function(from bitcode file)  
> with LLVM-C API, but there seems no appropriate API to do that.
>
> I've tried to do that with following code,
>
> ----
>
> LLVMModuleRef           M;
> LLVMMemoryBufferRef     MemBuf;
> LLVMValueRef            F;         // Function
> LLVMTypeRef             RetTy;
> char                   *ErrStr;
>
> //
> // -- Load shader module
> //
> ret = LLVMCreateMemoryBufferWithContentsOfFile(
>          input,
>         &MemBuf,    // [out]
>         &ErrStr);   // [out]
>
> ret = LLVMParseBitcode(
>          MemBuf,
>         &M,         // [out]
>         &ErrStr);   // [out]
>
> F = LLVMGetFirstFunction(M);
>
> RetTy = LLVMGetReturnType(F);   // NG! Can't do this
>
> ----
>
> How can I do that?
> (I am using HEAD version of llvm)
>
> And is there a tutorial or document for LLVM C API?
>
>
> Thanks in advance. _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



— Gordon

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


More information about the llvm-dev mailing list