|Search in this site:||
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.
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.
The GCC compiler can be customized or extended (with plugins or MELT extensions) for:
json_packin Jansson library, or
g_object_setin GTK toolkit), or checking some properties at every call of some given function;
pthread_mutex_unlockare balanced in the same function, or that every
fopengets its resulted tested);
CFLAGS += -fplugin=melt -fplugin-arg-melt-extra=extension -fplugin-arg-melt-mode=modein a
Makefile), but don't need to change workflow habits.
MELT is a domain-specific language specifically designed to ease the extension (or customization) of GCC because of the following features:
loop-s in a statically typed manner
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).
|(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
For instance (assuming you have
example.cc in some playground directory) compile
g++ -fdump-tree-all -O -c example.cc. This produce
hundreds of dump files, such as
example.cc.073t.phiopt1 which might contain (like dump files suffixed
(Static Single Assignment) statements, that you can browse using an editor or pager (e.g.
less example.cc.073t.phiopt1 or
However, GCC MELT also provides you with a
graphical probe: you could simply run
-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
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).
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.
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.
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.
MELT is mostly made in France, because its main contributors happen to be French. Of course we welcome any contributor (from any country).
In ChangeLog.MELT entries and in messages, we will refer to these tickets as MELT-SFT (for MELT -Source Forge Ticket).
I am interested in participating to any projects where extending GCC thru MELT is worthwhile.
(non-exhaustive list of references to related tools)
An English-speaking low-traffic technical group (no flamewars, no spam) about GCC MELT is available on
|Subscribe to email@example.com|
|Visit this group|
The old page on GCC MELT is available here.