Syoyo Fujita
2008-May-22 14:07 UTC
[LLVMdev] How to get a return type of a function with LLVM-C API
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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080522/048206ee/attachment.html>
Gordon Henriksen
2008-May-22 14:33 UTC
[LLVMdev] How to get a return type of a function with LLVM-C API
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>
Matthijs Kooijman
2008-May-22 15:02 UTC
[LLVMdev] How to get a return type of a function with LLVM-C API
Hi Syoyo,> 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.From my memory, this info is stored in the function type, so you could look at the function's type and get the info there. Looking the the API docs [1], I find that there is a simple method on Function called getReturnType(). You should thus be able to do: Type* rt = F->getReturnType(); Good luck, Matthijs [1]: http://llvm.org/doxygen/classllvm_1_1Function.html -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080522/295ddde9/attachment.sig>
Syoyo Fujita
2008-May-23 15:36 UTC
[LLVMdev] How to get a return type of a function with LLVM-C API
Hi Gordon and Matthjis, I got the return type of the function in success with the way Gordon explained. RetTy = LLVMGetReturnType(LLVMGetElementType(LLVMTypeOf(F))) Thanks a lot! -- Syoyo On Thu, May 22, 2008 at 11:33 PM, Gordon Henriksen <gordonhenriksen at mac.com>> wrote: > 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 Fri, May 23, 2008 at 12:02 AM, Matthijs Kooijman <matthijs at stdin.nl> wrote:> Hi Syoyo, > > > 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. > From my memory, this info is stored in the function type, so you could look > at > the function's type and get the info there. > > Looking the the API docs [1], I find that there is a simple method on > Function > called getReturnType(). You should thus be able to do: > Type* rt = F->getReturnType(); > > Good luck, > > Matthijs > > [1]: http://llvm.org/doxygen/classllvm_1_1Function.html >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080524/e22d4ef9/attachment.html>