about header file parsing
Marc Nieper-Wißkirchen
marc.nieper@gmail.com
Tue Jan 1 00:00:00 GMT 2019
Am Mi., 9. Jan. 2019 um 17:11 Uhr schrieb akrl <akrl@sdf.org>:
>
> Marc Nieper-Wißkirchen <marc.nieper@gmail.com> writes:
>
> > 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
>
> So if I undertand correctly: the problem you are raising about defines is
> about naming in the sense that to use an API under defines you'll
> need to use the the preprocessed expanded names in libgccjit?
Exactly. (Of course, more complicated APIs in form of C header files
are conceivable.)
> If this is the case I still think the tool would be useful.
What one could do (without having to take a look into the header file,
which is good because the internals are not part of the API) would be
to amend the header file by an extra stub. In the case of the EOF
example, one couid put
static int const jit_eof = EOF;
in this stub. When the header file and the stub have been processed by
our hypothetical tool, the context will have been populated with
`jit_eof' (and we rely on the compiler to optimize away the static
variable).
In the case of gmp.h, where, for example, mpq_numref is a macro, the
stub would contain a definition like:
static inline void jit_mpq_numref (mpq_t rop, const mpq_t op)
{
mpq_numref (rop, op);
}
And so on...
-- Marc
> Andrea
>
> --
> akrl@sdf.org
More information about the Jit
mailing list