From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25130 invoked by alias); 12 May 2009 13:13:13 -0000 Received: (qmail 25113 invoked by uid 22791); 12 May 2009 13:13:12 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from ey-out-1920.google.com (HELO ey-out-1920.google.com) (74.125.78.145) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 May 2009 13:13:06 +0000 Received: by ey-out-1920.google.com with SMTP id 3so6769eyh.14 for ; Tue, 12 May 2009 06:13:03 -0700 (PDT) Received: by 10.216.73.197 with SMTP id v47mr4002889wed.12.1242133983284; Tue, 12 May 2009 06:13:03 -0700 (PDT) Received: from ?192.168.2.99? (cpc2-cmbg8-0-0-cust61.cmbg.cable.ntl.com [82.6.108.62]) by mx.google.com with ESMTPS id t12sm2780511gvd.6.2009.05.12.06.13.00 (version=SSLv3 cipher=RC4-MD5); Tue, 12 May 2009 06:13:01 -0700 (PDT) Message-ID: <4A09788A.4070201@gmail.com> Date: Tue, 12 May 2009 15:59:00 -0000 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: Nicolas COLLIN CC: gcc@gcc.gnu.org Subject: Re: Intermediate representation References: <4A0962D0.9030902@fr.thalesgroup.com> In-Reply-To: <4A0962D0.9030902@fr.thalesgroup.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-05/txt/msg00303.txt.bz2 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.) cheers, DaveK