On 05/11/2010 11:34 AM, wolfgang8...@gmx.de wrote:
Hello All,
I want to know if it is possible to modify AST of the C/C++-Language.
You can modify a middle end representation of source program. I am not
sure if it always should be called an AST.
What I would like to do is to add some arguments to some function calls or add
statements somewhere in the tree.
My suggestion would be to code a GCC pass as a plugin, working on some
GIMPLE representation (I don't know if you need or want it to be in SSA
form or not). The GIMPLE representation is the language & target
"neutral" intermediate representations used inside the middle end of GCC
(and common to every front-end = C, C++, Ada, Fortran & to every target
system = x86, ARM, ...).
The MELT plugin & infrastructure is precisely targeted towards this kind
of extensions.
MELT is a lispy domain specific language designed to easily code
transformations on GIMPLE (& other middle-end) representations. It is
also a plugin (& a GCC branch) implementation. So it seems to be suited
to your needs (which I don't understand well in details).
The main features of MELT are
* a powerful pattern matching facility
* a lispy language (translated to C suitable for GCC internals) with
higher-order (anonymous) functions, objects, garbage collection, &
ability to mix small C code chunks inside the MELT code.
For more about MELT, look at
http://gcc.gnu.org/wiki/MiddleEndLispTranslator or even better ask me
(on the gcc@ mailing list).
Alternatively, you could code your specific pass in plain C in an
ordinary plugin.
If you use MELT or if you code a plugin in C, you need to learn more
about GCC internal representations (notably GIMPLE & Tree/Generic) and
passes.
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***