public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Intermediate representation
@ 2009-06-08  6:34 Nicolas COLLIN
  2009-06-08 11:07 ` Ian Lance Taylor
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas COLLIN @ 2009-06-08  6:34 UTC (permalink / raw)
  To: gcc

Hello,
I want to go through the entire internal tree in GCC but I have a 
problem with functions.
Indeed I would like to know the declarations and functions called by a 
function.
I assume I have to go into the function's scope but I don't know how.
I read the source code but I didn't find anything.

Thanks.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Intermediate representation
  2009-06-08  6:34 Intermediate representation Nicolas COLLIN
@ 2009-06-08 11:07 ` Ian Lance Taylor
  0 siblings, 0 replies; 16+ messages in thread
From: Ian Lance Taylor @ 2009-06-08 11:07 UTC (permalink / raw)
  To: Nicolas COLLIN; +Cc: gcc

Nicolas COLLIN <nicolas.collin@fr.thalesgroup.com> writes:

> I want to go through the entire internal tree in GCC but I have a
> problem with functions.
> Indeed I would like to know the declarations and functions called by a
> function.
> I assume I have to go into the function's scope but I don't know how.
> I read the source code but I didn't find anything.

As what point in the compilation process do you want to do that?

After the conversion to GIMPLE, and assuming you have the function decl,
you just walk through the GIMPLE code looking for GIMPLE_CALLs.  To see
the declarations look at the GIMPLE_BINDs.

Ian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Intermediate representation
  2009-06-08 12:11 Nicolas COLLIN
@ 2009-06-08 14:22 ` Ian Lance Taylor
  0 siblings, 0 replies; 16+ messages in thread
From: Ian Lance Taylor @ 2009-06-08 14:22 UTC (permalink / raw)
  To: Nicolas COLLIN; +Cc: gcc

Nicolas COLLIN <nicolas.collin@fr.thalesgroup.com> writes:

>  In my version DECL_SAVED_TREE is defined as :
> #define DECL_SAVED_TREE(NODE)        DECL_MEMFUNC_POINTER_TO (NODE)
> I just looked at DECL_MEMFUNC and it doesn't do what I want.
> Then I don't know how to get the statements in the FUNCTION_DECL I got.

You must be working with gcc before 4.0.  I don't know what to suggest,
except that it will be easier if you work with current gcc.

Ian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Intermediate representation
@ 2009-06-08 12:11 Nicolas COLLIN
  2009-06-08 14:22 ` Ian Lance Taylor
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas COLLIN @ 2009-06-08 12:11 UTC (permalink / raw)
  To: gcc

  In my version DECL_SAVED_TREE is defined as :
#define DECL_SAVED_TREE(NODE)        DECL_MEMFUNC_POINTER_TO (NODE)
I just looked at DECL_MEMFUNC and it doesn't do what I want.
Then I don't know how to get the statements in the FUNCTION_DECL I got.

Nicolas COLLIN

Ian Lance Taylor a écrit :

Nicolas COLLIN <nicolas.collin@fr.thalesgroup.com> writes:

In fact, I go through the tree in the function finish_decl in the file gcc/cp/
decl.c
I see every decl and struct in the tree, but my problem is with the node
FUNCTION_DECL : I don't know how to get every statements in it. I tried the
macro DECL_SAVED_TREE but it doesn't work. Maybe because the version I use is
older than the version you describe in the doc , could you give me the source
code of the precedent macro, thus I 'll may be able to see what goes wrong.


Please reply to the mailing list, not just to me.

You can only look at the statements after parsing the function is
complete.  At that time DECL_SAVED_TREE should contain a valid value.

Ian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Intermediate representation
  2009-05-26 22:47 Nicolas COLLIN
@ 2009-05-27  5:15 ` Dave Korn
  0 siblings, 0 replies; 16+ messages in thread
From: Dave Korn @ 2009-05-27  5:15 UTC (permalink / raw)
  To: Nicolas COLLIN; +Cc: gcc

Nicolas COLLIN wrote:
> Hello again,
> 
> I 'm still working on egcs 1.1 and the function cp_namespace_decls is
> not implemented in.

  Well, the definition is very simple

tree
cp_namespace_decls (tree ns)
{
  return NAMESPACE_LEVEL (ns)->names;
}

and NAMESPACE_LEVEL exists in egcs-1.1, so why not try back-porting it?

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Intermediate representation
@ 2009-05-27  2:48 Nicolas COLLIN
  0 siblings, 0 replies; 16+ messages in thread
From: Nicolas COLLIN @ 2009-05-27  2:48 UTC (permalink / raw)
  To: gcc

Hello again,

to answer your question my code's purpose is to write a kind of tree in 
a file, the main arborescence is the classes, their method (with 
parameters, return type, ...), their attributes, etc... it will also 
recognize some new keywords I will introduce thanks to "__attribute__".
In this condition, where is the best place to put my code please ?

Thank you a lot, I would haven't made any progress without your help.

Nicolas COLLIN

Dave Korn a écrit :

 Bear in mind that global_namespace only exists in the C++ compiler
'cc1plus', so if you access it directly in toplev.c, the plain C compiler
'cc1' will fail to build with a link error.  This might or might not matter to
you for your purposes, but it's better for that reason to keep any code that
needs to understand about anything to do with C++ in the /cp/ subdirectory.

  Without knowing what your code does, I can't say where is the best place to
put it.  The flow of control is that compile_file in gcc/toplev.c calls to the
language-specific parser yyparse, which then calls into hooks in the
language-specific files in gcc/ or gcc/cp/, ending eventually in finish_decl
in either gcc/c-decl.c or gcc/cp/decl.c, where it calls rest_of_compilation to
hand off the tree representation to the mid/backend for translation to
assembler code.

  So, the C++ specific finish_decl would be one good place to add code that
needs to analyse the trees.  Bear in mind that by the time you see them there,
some elementary optimisations like constant folding may already have been
performed, so you might not see what exactly reflects the form of the original
sources.


    cheers,
      DaveK


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Intermediate representation
@ 2009-05-26 22:47 Nicolas COLLIN
  2009-05-27  5:15 ` Dave Korn
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas COLLIN @ 2009-05-26 22:47 UTC (permalink / raw)
  To: gcc

Hello again,

I 'm still working on egcs 1.1 and the function cp_namespace_decls is 
not implemented in.
I just want to get the classes and functions implemented in my source 
code and I tried to get them with the function gettags but I think I 
didn't understand something. I tried to read some things about the 
bindings in the file decl.c but I didn't get a thing. What does it do ? 
Have I to use it to get what I want ?

Thanks.

Nicolas COLLIN

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Intermediate representation
  2009-05-14 16:03 Nicolas COLLIN
@ 2009-05-14 17:05 ` Ian Lance Taylor
  0 siblings, 0 replies; 16+ messages in thread
From: Ian Lance Taylor @ 2009-05-14 17:05 UTC (permalink / raw)
  To: Nicolas COLLIN; +Cc: gcc

Nicolas COLLIN <nicolas.collin@fr.thalesgroup.com> writes:

> I read that there is a variable global_namespace, I searched for it
> but I didn't find anything. Would you know how I can get the root ?

global_namespace is specific to the C++ frontend.  It is defined in
cp/name-lookup.c.

I'm not sure what you mean by "the root," but not that gcc does not have
a global symbol table.

> There is a variable tree decl among parameters of the function
> rest_of_compilation, I found out it's a function decl most of time,
> but can I the whole tree from it ?

The representation of the body of the function is in DECL_SAVED_TREE of
the function decl.

> How can I get the parent of a tree ? Maybe the field CONTEXT ?

I don't know what you mean by "the parent."  DECL_CONTEXT will tell you
where a decl is defined (see the comment above DECL_CONTEXT in tree.h),
TYPE_CONTEXT will tell you where a type is defined.

Ian

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Intermediate representation
@ 2009-05-14 16:03 Nicolas COLLIN
  2009-05-14 17:05 ` Ian Lance Taylor
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas COLLIN @ 2009-05-14 16:03 UTC (permalink / raw)
  To: gcc

Hello.
Thank you for your help, now I understand much better how it works.
At last I began to make some source code to explore the tree, indeed the 
macros are still the same except some.
But I have some questions again ...
I read that there is a variable global_namespace, I searched for it but 
I didn't find anything. Would you know how I can get the root ?
There is a variable tree decl among parameters of the function 
rest_of_compilation, I found out it's a function decl most of time, but 
can I the whole tree from it ?
How can I get the parent of a tree ? Maybe the field CONTEXT ?

I know there is a lot of questions again, I'm sorry.
Thank you again for your help.

Nicolas COLLIN

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Intermediate representation
  2009-05-12 12:03 Nicolas COLLIN
@ 2009-05-12 15:59 ` Dave Korn
  0 siblings, 0 replies; 16+ messages in thread
From: Dave Korn @ 2009-05-12 15:59 UTC (permalink / raw)
  To: Nicolas COLLIN; +Cc: gcc

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Intermediate representation
@ 2009-05-12 12:03 Nicolas COLLIN
  2009-05-12 15:59 ` Dave Korn
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas COLLIN @ 2009-05-12 12:03 UTC (permalink / raw)
  To: gcc

Hello.
First I apologize for my english but I'm french and sometimes I make 
mistakes.

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.
I'm sorry to bother you with this but I searched a long time over the 
net and didn't find any clue about the way to do it.

Thank you very much.

Nicolas COLLIN

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: intermediate representation
  2006-02-27  6:58 intermediate representation Mateusz Berezecki
@ 2006-02-27 23:36 ` Jim Wilson
  0 siblings, 0 replies; 16+ messages in thread
From: Jim Wilson @ 2006-02-27 23:36 UTC (permalink / raw)
  To: Mateusz Berezecki; +Cc: gcc

Mateusz Berezecki wrote:
> I'm new to GCC and I'd appreciate if somebody could point me to _all_
> files which are responsible for intermediate representation and
> constructing it.

See the internals documentation, for instance:
     http://gcc.gnu.org/onlinedocs/gccint/Passes.html#Passes

We have two ILs, a high level one (gimple), and a low level one (rtl), 
and the details for each is different.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* intermediate representation
@ 2006-02-27  6:58 Mateusz Berezecki
  2006-02-27 23:36 ` Jim Wilson
  0 siblings, 1 reply; 16+ messages in thread
From: Mateusz Berezecki @ 2006-02-27  6:58 UTC (permalink / raw)
  To: gcc

Hello List,

I'm a fresh subscriber to this list :-)

I'm new to GCC and I'd appreciate if somebody could point me to _all_
files which are responsible for intermediate representation and
constructing it. I don't want to miss
any files which may be crucial and GCC codebase seems to be quite... big.

My other question is about intermediate representation as well.
Is intermediate form generated during all compiler passes or _after_
all compiler passes are done?



kind regards
Mateusz Berezecki

^ permalink raw reply	[flat|nested] 16+ messages in thread

* intermediate representation
@ 2002-08-22  3:48 Aleksandar Zivkovic
  0 siblings, 0 replies; 16+ messages in thread
From: Aleksandar Zivkovic @ 2002-08-22  3:48 UTC (permalink / raw)
  To: gcc

Hello there
-----------
Maybe you can help me!

Im having an idea to make something like function call graph and to put it
in a separate section of the elf output.

                                  (f1,f2)
                                   ...
					    (fn,fm).

So, I need to walk through the trees, but I cant find the place where are
they stored! I found a function called walk_tree in /cp directory,
but what to put as a root argument. There's a wood of code but I cant see
the trees (!!!).

Thanks


Aleksandar Zivkovic
MicronasNIT
Novi Sad ,Yugoslavia



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: intermediate representation
  2002-03-05 13:25 Felix Deschamps
@ 2002-03-05 14:06 ` Diego Novillo
  0 siblings, 0 replies; 16+ messages in thread
From: Diego Novillo @ 2002-03-05 14:06 UTC (permalink / raw)
  To: Felix Deschamps; +Cc: gcc

On Tue, 05 Mar 2002, Felix Deschamps wrote:

> To the gcc maintainers: 
>    
> I have started developing an application that will take as
> input a code syntax tree that can then be used for code
> browsing purposes.  The nature of the application ( which is
> 
The ast-optimizer-branch has experimental code to dump the trees
in various formats.  You may also find -fdump-tree useful.  The
ast branch adds a few more variations of -fdump-tree.

Diego.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* intermediate representation
@ 2002-03-05 13:25 Felix Deschamps
  2002-03-05 14:06 ` Diego Novillo
  0 siblings, 1 reply; 16+ messages in thread
From: Felix Deschamps @ 2002-03-05 13:25 UTC (permalink / raw)
  To: gcc

To the gcc maintainers: 
   
I have started developing an application that will take as input a code syntax tree that can then
be used for code browsing purposes.  The nature of the application ( which is detailed in the next
paragraph ) is such that it would be desirable to have gcc output the syntax tree generated in the
parsing pass to a file in a way similar to the way that debug dump files are generated for the
different compiler passes.  I have already written a few functions that convert the syntax tree
into both XML and binary format, but before i went any further with it i wanted to find out
weather or not any such functionality is planned to be included in future releases of gcc ( or
whether or not the code i am writing could be used for other projects, or has already been written
by someone else. )

The reason i want to be able to have gcc output the file ( and not write an application that
simply uses the gcc code for tree generation ) is as follows. Most of the code i have been doing
in the last few years has been on the windows platform. After encountering no small amount of blue
screens, unexplained reboots, and a plethora of other ever-increasing headaches,  i find myself
gravitating more and more towards using linux and other open source software. ( I hardly ever boot
up to windows at home any more. ) In the last couple of months i have begun delving into the
sources for gnome-ximian, anjuta and other such projects. I love studying code and finding out how
something is done , but i often find myself pouring through the makefiles, readme files and info
pages just to know where to start reading the code. So i started thinking that it would be useful
to have an application that took a make file, ran it with the appropriate installation and
configuration switches and ultimately output the overall program structure in a point and click
fashion ( in a way similar to the way that anjuta provides for it's projects. ) I would also want
code that created html browsing similar to the linux navigation project, and/or create hierarchy
charts, automatic documentation, etc.  I have found several apps that address the issue to some
extent, but nothing i have found has quite matched what i wanted, so i set out to write my own. 
Since gcc is the compiler normally used for all these projects, it would be very easy pass another
flag to it to output the syntax tree for all the translation units, then use this information to
create the desired output (be it the html code, class hierarchy, code translation, etc.)  

I hope not to have taken up too much of your valuable time, and i hope that my ideas are not to
crazy. I would greatly appreciate any direction or information you could give me with this issue,
and i would be more than willing to help in any projects that i might be of help. Thank you.


Felix Deschamps

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-06-08 14:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-08  6:34 Intermediate representation Nicolas COLLIN
2009-06-08 11:07 ` Ian Lance Taylor
  -- strict thread matches above, loose matches on Subject: below --
2009-06-08 12:11 Nicolas COLLIN
2009-06-08 14:22 ` Ian Lance Taylor
2009-05-27  2:48 Nicolas COLLIN
2009-05-26 22:47 Nicolas COLLIN
2009-05-27  5:15 ` Dave Korn
2009-05-14 16:03 Nicolas COLLIN
2009-05-14 17:05 ` Ian Lance Taylor
2009-05-12 12:03 Nicolas COLLIN
2009-05-12 15:59 ` Dave Korn
2006-02-27  6:58 intermediate representation Mateusz Berezecki
2006-02-27 23:36 ` Jim Wilson
2002-08-22  3:48 Aleksandar Zivkovic
2002-03-05 13:25 Felix Deschamps
2002-03-05 14:06 ` Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).