Thanks Basile Starynkevitch for the useful reply.

On 6/15/14, Basile Starynkevitch <bas...@starynkevitch.net> wrote:
> On Sun, 2014-06-15 at 02:40 +0530, Mohsin Khan wrote:
>> Hi,
>> I'm working on a gcc plugin project. I had a doubt, can somebody help
>> me on this.
>
> [no need to ask on gcc-help@; plugins are definitely gcc internals
> related and should better be discussed on gcc@gcc.gnu.org]
>
>> Can we write a plugin (which works after a pass like cfg or any other)
>> which can modify the source code of .C file, for example insert
>> comments before function definitions or insert a new IF Block in the
>> .C file. And after modification it writes the entire modified code to
>> a new .C file. Is this type of plugin possible in GCC. If yes, please
>> tell me how and if No, please tell me why.
>
> If your source file does not contain any #line directive, a GCC plugin
> (or a MELT extension, see http://gcc-melt.org/ for more) is able to get
> the source code position of every Gimple instruction. (But did you think
> about instruction obtained by some macro expansions?).
>
> With that information, you can indeed transform the C source as you
> wish. It might not be simple (you need to build an editor-like internal
> represention of each line of the source code).
>
> However, modifying the Gimple representation (without modifying any C++
> source file) is probably simpler.
>
> What exactly do you want to achieve? Are you sure that a source to
> source transformation is worthwhile -given that you can transform
> internal GCC representations like Gimples-?
>
> 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 mine, sont seulement les miennes} ***
>
>
>

Reply via email to