<div class="gmail_quote">On Mon, Jan 4, 2010 at 5:41 AM, Kenneth Uildriks <span dir="ltr"><<a href="mailto:kennethuil@gmail.com">kennethuil@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Mon, Jan 4, 2010 at 4:43 AM, Russell Wallace<br>
<<a href="mailto:russell.wallace@gmail.com">russell.wallace@gmail.com</a>> wrote:<br>
> When implementing a language using LLVM as the backend, it is<br>
> necessary to give programs written in that language, access to the C<br>
> standard library functions. The Kaleidoscope tutorial shows how to do<br>
> this for individual functions using extern declarations, but in<br>
> general it would be necessary to have those predefined for the full<br>
> standard library. Presumably these would contain exactly the<br>
> information from the union of C header files. Is there a way, by<br>
> parsing the C header files or otherwise, to obtain this information in<br>
> the format LLVM expects?<br>
><br>
> As an extension of this question, it will be necessary to provide<br>
> access to other libraries written in C. The same question applies<br>
> there: Is there a way, by parsing C header files or otherwise, to<br>
> obtain a list of functions that are defined in a given library, in the<br>
> format LLVM expects?<br>
<br>
</div></div>Usually, this would be defined by the language.  For instance, C# uses<br>
PInvoke to declare functions that are implemented natively in some<br>
other language, and the programmer usually manually writes PInvoke<br>
declarations for whichever library functions he wants to call.<br>
<br>
Many languages try to wrap the standard C libraries and expose<br>
equivalent functionality through the language's own standard library.<br>
This doesn't address third-party libraries, of course.<br>
<br>
At any rate, if you want to consume native libraries in any language<br>
without explicitly declaring each native function, you'll need to<br>
parse the C header files.  Native object files don't have information<br>
about parameters, calling conventions, etc. that your compiler would<br>
need.</blockquote><div><br></div><div>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.<br>
<br>Keir</div></div>