public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: akrl <akrl@sdf.org>
Cc: jit@gcc.gnu.org
Subject: Re: about header file parsing
Date: Tue, 01 Jan 2019 00:00:00 -0000	[thread overview]
Message-ID: <1547046923.7788.103.camel@redhat.com> (raw)
In-Reply-To: <xjf1s5mnkyf.fsf@sdf.org>

On Wed, 2019-01-09 at 11:12 +0000, akrl wrote:
> On  8 January 2019 18:21, David Malcolm <dmalcolm@redhat.com> wrote:
> 
>     On Tue, 2019-01-08 at 10:50 +0000, akrl@sdf.org wrote:
>     > Hi all,
>     > I have a basic question.
>     > Is there a way to ask libgccjit to parse a conventional .h
> file?
>     
>     Sadly, no.
>     
>     > Or alternatively is there a way to have an header file parsed
> and
>     > converted in the equivalent libgccjit api calls?
>     
>     Having a standard way to do this would be useful.
>     
>     > 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.
>     
>     I agree that this is a nuisance.
>     
>     > Alternatively what's the suggested work flow?
>     
>     One idea I came up with was to use libabigail:
>       https://sourceware.org/libabigail/
>     to generate an ABI description e.g. via abidw:
>       https://sourceware.org/libabigail/manual/abidw.html
>     which emits an XML file, and then have a pre-canned way of
> populating a
>     gcc_jit_context from such an abigail ABI representation.
>     
>     This code doesn't exist yet, though (but would just need writing
> once).
>     
>     Dave
>     
>     > Best Regards
>     >   Andrea
>     >
> 
> I think the idea of having something like a gcc plugin that once is
> parsed
> compiles the subset of supported C to the necessary libgccjit code
> would be
> useful to have for this cases but also educative for learning how to
> use the
> library.

I really like this idea.

Code using this plugin is going to want e.g. to access fields of
structs, globals, etc, so it needs a way to:
(a) populate a gcc_jit_context with those entities from the parsed C, 
(b) have a way for client code to get at those entities.

As a concrete use-case, I attempted to use libgccjit to write a JIT-
compiler for CPython, and found myself writing tedious error-prone code
by hand to express the <Python.h> header:
https://github.com/davidmalcolm/coconut/blob/master/coconut/compiler.py

(ugh!)

This client code was written in Python, using the Python bindings to
libgccjit, rather than directly using the <libgccjit.h> C API.

So presumably the plugin ought to support writing out the
representation in some simple serialized format, and have a way to get
at it from the various languages that bind libgccjit.

Or maybe it's simplest to start with getting at the reflected IR from
C?  (I'm thinking aloud here)

[Ideally it would support parsing C++ also, but clearly that's some big
feature-creep: I attempted to write a JIT for GNU Octave, which is
implemented in C++, and ran into the same issue as above: lots of hand-
written reflection of the classes and globals.   Probably best to focus
on a plugin for the C frontend for now.]

> 
> Would be this something that is upstreamable in some form?

Maybe eventually, but given that libgccjit is part of gcc and thus has
a one-year release cycle, it feels like something that would best be a
3rd-party project for now.

Any takers?  (my day job is bug-fixing gcc 9 right now)

Dave

> Bests
> 
>   Andrea

  reply	other threads:[~2019-01-09 15:16 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-01  0:00 akrl
2019-01-01  0:00 ` Basile Starynkevitch
2019-01-01  0:00   ` Marc Nieper-Wißkirchen
2019-01-01  0:00   ` Marc Nieper-Wißkirchen
2019-01-01  0:00     ` Marc Nieper-Wißkirchen
2019-01-01  0:00       ` David Malcolm
2019-01-01  0:00         ` Marc Nieper-Wißkirchen
2019-01-01  0:00           ` akrl
2019-01-01  0:00             ` David Malcolm
2019-01-01  0:00               ` akrl
2019-01-01  0:00                 ` Marc Nieper-Wißkirchen
2019-01-01  0:00                   ` akrl
2019-01-01  0:00                     ` Marc Nieper-Wißkirchen
2019-01-01  0:00                       ` akrl
2019-01-01  0:00                         ` Marc Nieper-Wißkirchen
2019-01-01  0:00                           ` akrl
2019-01-01  0:00           ` David Malcolm
2019-01-01  0:00 ` David Malcolm
2019-01-01  0:00   ` akrl
2019-01-01  0:00     ` David Malcolm [this message]
2019-01-01  0:00       ` akrl
2019-01-01  0:00         ` David Malcolm
2019-01-01  0:00     ` Basile Starynkevitch
2019-01-01  0:00       ` akrl
2019-01-01  0:00         ` Basile Starynkevitch
2019-01-01  0:00           ` David Malcolm
2019-01-01  0:00             ` Marc Nieper-Wißkirchen
2019-01-01  0:00               ` Basile Starynkevitch
2019-01-01  0:00               ` akrl
2019-01-01  0:00                 ` Marc Nieper-Wißkirchen
2019-01-01  0:00       ` David Malcolm
     [not found] <df8944b7-1fbe-b56f-cc48-ab926d0cb5ad@starynkevitch.net>
2019-01-01  0:00 ` Basile Starynkevitch
2019-01-01  0:00   ` Marc Nieper-Wißkirchen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1547046923.7788.103.camel@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=akrl@sdf.org \
    --cc=jit@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).