This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Intermediate representation

Nicolas COLLIN wrote:
> Hello.

  Hi again Nicolas,

> I have to create a file containing some informations by processing C++
> code source for work.
> But why create a whole lexical analyzer while I can use the intermediate
> representation tree of GCC ?
> To do it, I'm going to introduce a fonction in GCC which analyze the
> intermediate representation tree used by GCC and create a file
> containing all of the informations I need.
> I read all the informations I found about the tree and now my problem is
> that I don't know how to introduce this very function into GCC (I
> haven't found anything about it over the net).
> What is the best way to do it ? Create a new "back-end" ? I read about
> it and I don't think it could work. Can I put it into the source code
> instead ? If so, where can I put it ?
> I work on egcs1.1, but I know that the tree is implemented in, so it can
> work.

  It is a shame you are stuck using such an old version of the compiler, in
modern GCC we have just added a plugin feature which is ideal for your
purpose.  In such old GCC, there is nothing like that.

  A back-end is not the way to do this.  The back-ends only get to see parts
of the semantic info that the mid-end presents to them to drive instruction
selection.  I think what you probably want to do is call your code from
somewhere around the top of rest_of_compilation() in gcc/toplev.c, and it will
get a chance to process the trees for all the functions and data items
declared in the program.

  Note that you'll have to cope with seeing each item one by one on separate
calls to your function.  If that's a problem you'll need to figure out a way
to maintain state between the consecutive calls, which won't be difficult, but
just in case you were expecting it, you should know that there is no one time
at which the compiler keeps the entire tree representation of all functions
and declarations in memory at the same time.  (I don't know exactly when the
-funit-at-a-time option was introduced into GCC, but I'm fairly sure it wasn't
in EGCS.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]