GCC MELT
gcc-melt.org

About GCC MELT

Executive Summary: (printable)
Customizing your GCC compiler with MELT extensions (2 pages / one sheet, PDF, in english).
Votre compilateur GCC sur mesure avec MELT (1 page, PDF, in french - en français)
(march, 28th, 2014) talk on GCC plugins through the MELT example (Linux Foundation Collaboration Summit, California, USA)

NEW! (august 31th, 2014) MELT 1.1.2 plugin release for GCC 4.8 and 4.9 downloadable, please ugrade.

Overview

GCC MELT is a high-level domain specific language for extending or customizing the Gnu Compiler Collection (i.e. gcc, g++, gfortran, gnat, gccgo, gobjc, ...). It is implemented as a GCC plugin (for GNU/Linux systems, with GCC 4.7, 4.8 or later) in a free software (under GPLv3+ license and FSF copyright).
GCC MELT targets advanced GCC users developing, compiling, improving, evaluating, maintaining, or designing important software (coded in C, C++, Fortran, Ada, Go, Objective C or any language supported by a recent straight- or cross- GCC compiler). For such power users, spending a few days or weeks to customize or extend their compiler for their specific needs is worthwhile, and GCC MELT should lower the required effort, because coding in MELT a GCC extension is much easier than manually developping a GCC plugin in C or C++ (these are efficient languages, but not well fit to easily work on compiler's internal representations).

GCC MELT (since MELT 1.0) can also be used to explore the internal representations of the GCC compiler when it is working on your files, see here. For example, you could find all calls to malloc with a constant size greater than 48 bytes, or all assignments to some next fields of struct-ure whose name contains point (and such searches are not possible with textual tools like grep; they have to be made at the Gimple level inside the compiler).

GCC MELT (that is, your daily GCC [cross-] compiler augmented with the MELT [meta-] plugin and your own extensions) could be the foundational block of some Industry Specific Software Development Kit for e.g. embedded, GUI, or low-level software. Please contact us for more information.

GCC MELT uses existing GCC plugin hooks to work on GCC internal middle-end representations, notably GCC Generic Trees and GCC Gimples, and the control flow graph. These powerful internal representations are common to all source languages accepted by GCC, so your extension coded in MELT will be able to handle any source code compiled by GCC. In addition, the (crude) GCC MELT probe provides a graphical interface to interactively query some internal GCC representations.

Probably, GCC MELT won't be very useful to casual GCC users working on tiny programming projects, unless they simply use some existing GCC extensions already developed with GCC MELT.

Why customize or extend GCC?

The GCC compiler can be customized or extended (with plugins or MELT extensions) for:

From the GCC user's point of view, a customization of GCC is easier to use than external tools. He/She needs only to add extra compilation flags (.e.g. CFLAGS += -fplugin=melt -fplugin-arg-melt-extra=extension -fplugin-arg-melt-mode=mode in a Makefile), but don't need to change workflow habits.

How MELT helps to extend GCC?

MELT is a domain-specific language specifically designed to ease the extension (or customization) of GCC because of the following features:

The above powerful features of MELT lower the cost of customizing GCC, hence enabling you to leverage on GCC powerful abilities with GCC MELT. However, even using MELT you need to understand some of GCC internals.

The emitted C or C++ code is carefully generated to fit into what your GCC plugin interface expects (GCC switched from C to C++ in its 4.7 version, and GCC MELT is careful to generate a code acceptable by your version of GCC).

Looking into GCC internal representations with the GCC MELT probe

the MELT 0.9.7-post-snap-r192893 probe
on its gcc/melt-runtime.c
reduced image of probe
(click on the picture to get the full view)

A practical way to understand more on main GCC internal representations is to have a relevant (small) source code (e.g. in C, C++, Fortran, or Ada, etc), then compile it with the -fdump-tree-all.

For instance (assuming you have some example.cc in some playground directory) compile with g++ -fdump-tree-all -O -c example.cc. This produce hundreds of dump files, such as perhaps example.cc.073t.phiopt1 which might contain (like dump files suffixed .phiopt*) a dump of Gimple/SSA (Static Single Assignment) statements, that you can browse using an editor or pager (e.g. less example.cc.073t.phiopt1 or gedit example.cc.073t.phiopt1).

However, GCC MELT also provides you with a graphical probe: you could simply run gcc -fplugin=melt -fplugin-arg-melt-mode=probe -O -c example.cc and see a graphical window, with the ability to interactively look at GCC internal representations tied to a particular source code location. The probe is a small (GtkMM or PyQt) GUI application communicating, thru asynchronous textual pipes, with a MELT enhanced GCC compiler.

The GCC MELT graphical probe may interest any people curious of GCC internal representations.

the probe is deprecated in MELT 1.1. In the future a web interface may appear (with the MELT monitor).


Download and install GCC MELT

GCC MELT is downloadable here (under GPLv3 license, for GNU/Linux systems with a recent GCC), where you can get installation instructions, and also examples of code written in MELT.

Please download and install GCC MELT before reading other material.

Documentation

GCC MELT has some documentation here , where you can get tutorial, and also reference about MELT, with publications and slides of talks given on it.

Contribute to GCC MELT (and related tools)

GCC MELT is an improvement to GCC itself, so follows the same contribution policies as the GCC compiler. In particular, it demands the same legal prerequisites (which take a lot of time). We cannot accept even small patches without your contribution belonging legally to the FSF (as GCC MELT does).

Thanks to (in alphabetical order) Romain Geissler, Emmanuel Haucourt, Alexandre Lissy, Jérémie Salvucci, Pierre Vittet for their contributions to GCC MELT.

French flag   MELT is mostly made in France, because its main contributors happen to be French. Of course we welcome any contributor (from any country).

Contact information

My (=Basile Starynkevitch) work at CEA, LIST on GCC MELT has been partially funded by DGCIS French public agency thru various projects.

Please contact me by email at Basile dot Starynkevitch at cea dot fr for industrial contracts (thru CEA, LIST) or collaborative research projects related to GCC MELT

Reporting bugs and wishes

Please reports bugs and wishes on the gcc-melt@googlegroups.com and also on SourceForge GCC MELT tickets system.

In ChangeLog.MELT entries and in messages, we will refer to these tickets as MELT-SFT (for MELT -Source Forge Ticket).

Participating to projects

I am interested in participating to any projects where extending GCC thru MELT is worthwhile.

Related tools

(non-exhaustive list of references to related tools)

Mailing list (discussion group)

An English-speaking low-traffic technical group (no flamewars, no spam) about GCC MELT is available on

Google Groups
Subscribe to gcc-melt@googlegroups.com
Email:
Visit this group


The old page on GCC MELT is available here.