about header file parsing

Basile Starynkevitch basile@starynkevitch.net
Tue Jan 1 00:00:00 GMT 2019


On 1/8/19 11:50 AM, akrl@sdf.org wrote:
> Hi all,
> I have a basic question.
> Is there a way to ask libgccjit to parse a conventional .h file?

I have asked a very similar question in 
https://gcc.gnu.org/ml/jit/2015-q2/msg00093.html

> Or alternatively is there a way to have an header file parsed and
> converted in the equivalent libgccjit api calls?
> I ask this because I noticed that, if you jit some code that have to
> inter-operate with non jitted code, maintaining two duplicated definitions
> of all data structures can be quite painful if these are not trivial.
> Alternatively what's the suggested work flow?

I am not sure there is one yet, in practice.

A possible work-around (not entirely trivial) might be to do the 
"opposite": use GCC itself to parse the header file, and write your GCC 
plugin extracting all the relevant information for your particular usage 
of libgccjit. I have no idea how easy that can be for you.

I am not even sure if all the features of C (including some common 
extensions accepted by GCC) are usable from libgccjit. Perhaps bit 
fields and computed gotos like `goto *ptr` and statement expressions 
like `({int x=0; while (y>0) x+=f(y--); x;})` are not easily achievable 
in libgccjit.


Still another thing could be to use LTO: you'll compile your C file with 
GCC using -flto, you'll do LIBGCCJIT things, and the final executable 
sould be compiled and linked with -flto.

Cheers.

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



More information about the Jit mailing list