This is the mail archive of the gcc@gcc.gnu.org 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]

Hacking GCC in a clean way



Hi!

I have been hacking GCC source code in order to extract C++ class information.
To do this, I had to hack GCC in a simple but ugly way:
I coded everything in the lang_finish() function of gcc/cp/lex.c
I needed to access the internal tree, and extract the information I wanted.
So in this lex.c file, I added those line:

struct binding_level {
  tree names;
};

then have the root of the tree by_:

extern struct binding_level *current_binding_level;

then run throught the tree with:

tree names=current_binding_level->names;
while (names) {
  // process the node here ...

  names = TREE_CHAIN(names);
}

I also had to remove the 'static' qualifier on current_binding_level
in the file gcc/cp/decl.c

OK! this works, but I suppose there must be a cleaner way to do what I want to do.
I should not have to 'extern' a 'static' variable. I look through the documentation
(http://gcc.gnu.org/onlinedocs/) finding a lot of information about the tree structure,
but nothing such as how to 'cleanly' hack GCC, nor any mention to a plug-in API for
hackers to use. Wouldn't it be so much easier to have a clean API for doing special treatment,
as well as well know processing stage point where those 'plugins' would be called ?

Anyway. I primarily would like to know how to cleanly hack GCC: where do I get the tree pointer,
where do I get the tree structure declared from, and which internal function should contain my hack
(when the tree is fully build).

Thanks in advance,

Adrien



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