Hello I am replying to your http://gcc.gnu.org/ml/gcc/2010-03/msg00005.html question on gcc@ list.
> I am trying figure out a way to add an external statement to already > generated function. Is that possible? It could be possible, but it is not very easy. I mean that it is a project for several weeks or perhaps a few months (so don't expect to achieve that in a few days of work). > For example, let's say that if I want to check is function with name > "DoSomething" already generated/parsed (bottom line, does it exist). > Can I do that somehow? And if I can, is there a way to add new > statement (e.g call of some function) into to > body of "DoSomething"? > This situation could for example happen when the "DoSomething" is in > A.c file and the compiler is currently parsing B.c and it needs to > look has DoSomething been already processed in files before (in this > case A.c file). I would suggest to code a plugin (or some other extension) of GCC for that purpose (you could consider coding a MELT extension for that purpose; see below). And you definitely should start from GCC trunk or a recent 4.5 snapshot (anything older is not realistic). You probably need to develop several additional passes, and have them installed thru the plugin machinery (or the MELT infrastructure). The way I see it would be to use GCC in link-time-optimization mode, and to have your transformation coded as an LTO optimization. Perhaps even you might consider running twice your entire build (of your compiled application needing your transformation). The first time (in LTO mode), your pass write enough information on the disk (perhaps in another file, perhaps in a database, perhaps inside the object file using LTO... - I can't figure out the details). The second time, your other pass read back that information, and transform the generated code appropriately. Perhaps with this dual build tree, you might not need LTO (but I am not sure). You might consider using the MELT infrastructure for your needs. Read more about MELT on http://gcc.gnu.org/wiki/MiddleEndLispTranslator & http://gcc.gnu.org/wiki/MELT%20tutorial I don't claim that MELT is enough for your purpose (but if you want to use it, I would be delighted to help you). What MELT provides notably is a powerful lispy dialect to code GCC extensions & passes in. I would imagine that MELT pattern matching facilities should be useful to you to filter the statements you want to detect or transform (but I did not understood all the details of your needs). What MELT does not provide (yet) are high-level hooks to LTO. I actually have not understood what is your exact need and what is your motivation. Be aware that modifying GCC or even coding a GCC plugin is still not a very easy task (even if MELT could help you a little bit). You have to partly understand the internal GCC representations; in particular, take time to read about Tree/Generic & Gimple in http://gcc.gnu.org/onlinedocs/gccint/ Good luck. If you want to use MELT, feel free to ask me (e.g. on this list). 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} ***