[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: about header file parsing




On 1/9/19 4:52 PM, Marc Nieper-Wißkirchen wrote:
How would you handle, for example, gmp's header file?
https://gmplib.org/repo/gmp/file/default/gmp-h.in

Almost all of the public API is behind #define's. So even if the
gcc_jit_context is filled with the functions that are declared in the
header, one still needs to know the ABI of GMP to know which functions
to call.

In order to make it work in the general case (if this is at all
possible), I think one has to turn the C frontend of GCC into a
library (like libgccjit has turned the GCC middle/backend into a
library). This hypothetical library X has its own context K that is
populated by expanding and parsing the relevant header files.

In this context K, we can then ask for expansion of strings of C
tokens (e.g. in expression or statement context). Library X then
returns the expansion in term of, say, a C-specific GENERIC tree,
which can then be converted into/wrapped into a gcc_jit_object.

-- Marc



AndI (Basile) wrote:

in practice C macros are very important (and a lot of API for C are
using macros, see also macros such as WIFEXITED in wait(2) on some
Linux
system).

We have to admit that C and libgccjit are different "languages" (even
if
conceptually very close). And a C API is not exactly a set of
"objects"
that libgccjit can handle.
They're not the same, but it is important that libgccjit be able to
interoperate well with C APIs.


I'm not sure that general goal is reasonable. libgccjit is already able to interoperate with a library written in C. Unfortunately, a C API is not just a library, but also macros (such as EOF or WIFEXITED), and we cannot expect libgccjit to deal with these.


On Linux libgccjit is already capable to call any function in some ELF library which uses the C calling conventions, and that is already excellent.

And that limitation is not particular to libgccjit: any implementor of some interpreter or compiler has to deal specially with C macros, and handle them in an ad-hoc way.

We have to admit that in general C APIs are complex beasts, even if most of the time they are "simple" enough.

Regards

--
Basile STARYNKEVITCH   == http://starynkevitch.net/Basile
opinions are mine only - les opinions sont seulement miennes
Bourg La Reine, France