[LLVMdev] C library function declarations

Keir Mierle mierle at gmail.com
Mon Jan 4 06:40:58 PST 2010

On Mon, Jan 4, 2010 at 5:41 AM, Kenneth Uildriks <kennethuil at gmail.com>wrote:

> 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?
> 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.

You may want to consider leveraging Clang to parse existing headers. It's
still not trivial to get everything working as you described, but by
leveraging Clang at least you don't have to parse C yourself.

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

More information about the llvm-dev mailing list