unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: gcc@gcc.gnu.org
Cc: guile-user@gnu.org
Subject: GCC meets Guile at its birthday party
Date: Thu, 16 Feb 2012 12:32:41 +0100	[thread overview]
Message-ID: <87ty2r109y.fsf@inria.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 2544 bytes --]

Hello,

Today is the first anniversary of GNU Guile 2.0 [0].  To celebrate it,
several Guile users took on the challenge to come up in one week with a
neat hack to showcase Guile integration [1].

So I’m happy to announce that this silly challenge gave birth (among
other things) to Guile-GCC, Guile bindings that allow GCC plug-ins to be
written in Guile:

  http://www.fdn.fr/~lcourtes/software/guile/guile-gcc-0.0.tar.gz
  http://www.fdn.fr/~lcourtes/software/guile/guile-gcc-0.0.tar.gz.asc

  SHA1 sums:

    2d46faf75b5ceb62c326f320495aa594479468bf  guile-gcc-0.0.tar.gz
    7f0817e1b8b4a35f0a99602a8d9c1b080fea1851  guile-gcc-0.0.tar.gz.asc

  Repository:

    https://gitorious.org/guile-gcc/guile-gcc

The plug-in currently wraps a small subset of the libcpp, tree, and
cgraph APIs, which was enough to create these plug-ins available in the
distribution:

  • The ‘birthday’ plug-in defines a ‘birthday’ pragma that emits a
    ‘puts’ call.

  • ‘meta’ shows an unprecedented way of doing meta-programming from C.
    It defines two pragmas: one to define a “meta-function”, and one to
    invoke said function at a particular point in the code, with
    specific tree objects as its arguments.

    The ‘examples/meta.c’ file defines a meta-function that generates
    code to print the value of each field of the structure passed as its
    argument.

  • ‘call-graph’ unimaginatively traverses the call graph of the
    compilation unit and emits a ‘dot’ representation of that graph.

The (gcc) module comes with an embedded domain-specific language (EDSL)
that makes it easy to write code-generating code.  For instance:

  (tree loc
    (printf "value is %d (%p)\n" (foo dot "bar") (& foo)))

… expands to (simplified):

  (build-call-expr
    loc
    printf
    (list (build-string-literal "value is %d (%p)\n")
          (build-component-ref loc foo "bar")
          (build-addr foo)))

The bindings currently lack GIMPLE and basic-blocks.  Everyone is
invited to join in and help with this.  :-)

Besides, fun work would include augmenting the tree EDSL so it can build
BIND_EXPRs, VAR_DECLs, COND_EXPRs, etc., and extending Guile’s
(ice-9 match) pattern matcher to support tree and GIMPLE objects, which
would probably be handy.

Feedback welcome!

Thanks,
Ludo’.

[0] http://lists.gnu.org/archive/html/guile-devel/2011-02/msg00173.html
[1] http://lists.gnu.org/archive/html/guile-user/2012-02/msg00019.html

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

                 reply	other threads:[~2012-02-16 11:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=87ty2r109y.fsf@inria.fr \
    --to=ludo@gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=guile-user@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).