[LLVMdev] C library function declarations
Kenneth Uildriks
kennethuil at gmail.com
Mon Jan 4 05:41:35 PST 2010
On Mon, Jan 4, 2010 at 4:43 AM, Russell Wallace
<russell.wallace at gmail.com> wrote:
> When implementing a language using LLVM as the backend, it is
> necessary to give programs written in that language, access to the C
> standard library functions. The Kaleidoscope tutorial shows how to do
> this for individual functions using extern declarations, but in
> general it would be necessary to have those predefined for the full
> standard library. Presumably these would contain exactly the
> information from the union of C header files. Is there a way, by
> parsing the C header files or otherwise, to obtain this information in
> the format LLVM expects?
>
> As an extension of this question, it will be necessary to provide
> access to other libraries written in C. The same question applies
> there: Is there a way, by parsing C header files or otherwise, to
> obtain a list of functions that are defined in a given library, in the
> format LLVM expects?
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
Usually, this would be defined by the language. For instance, C# uses
PInvoke to declare functions that are implemented natively in some
other language, and the programmer usually manually writes PInvoke
declarations for whichever library functions he wants to call.
Many languages try to wrap the standard C libraries and expose
equivalent functionality through the language's own standard library.
This doesn't address third-party libraries, of course.
At any rate, if you want to consume native libraries in any language
without explicitly declaring each native function, you'll need to
parse the C header files. Native object files don't have information
about parameters, calling conventions, etc. that your compiler would
need.
More information about the llvm-dev
mailing list