This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
How to repeat AST/Generic analysis
- From: "xunilwithkrow" <xunilwithkrow at gmail dot com>
- To: "gcc-help" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 6 Jul 2009 13:39:48 +0800
- Subject: How to repeat AST/Generic analysis
Hi,
As we all know, usually, when we compile a souce file, there is one-pass or multiple-pass AST/Generic analysis, but when I say I want to repeat AST analysis , it's not about I intend to have multiple pass analysis. In this point, I'd like to repeat the whole thing even it's multiple pass.
So my problem is in c program when I find some kind of struct object is initialized in "compound literial " way, I want to do some change to the type itself. the scenario is much like:
struct Foo {
int* a;
char b;
int c;
...
};
........
int main(void) {
struct Foo tmp = { NULL, 'b', 10 ... }; // compound literial initialization
.....
}
When I find a object called tmp with type Foo, I intend to do some change in Foo itself ( in AST level). But as I skim gcc source code, I found the call order like this:
(Gcc-4.2.4 c-parser.c )
c_parser_declaration_or_fndef {
........
c_parser_declspecs // line 1264 deal with the struct Foo declaration
........
c_parser_initializer // line 1341 deal with the object tmp declaration
.......
}
Here you can see the problem, when I found tmp declaration, I already can't do nothing about struct Foo. So if you guys have any better idea to let me do the change, just let me know : )
Or I get an idea which is repeating AST analysis. In first analysis, I record such struct type to a list when I found the compound literial case. Then I can do change to these type in second AST analysis.
How to repeat ? First, I get the call stack:
main () main.c
toplev_main () toplev.c
general_init () toplev.c
decode_options () toplev.c
do_compile() toplev.c
compile_file() toplev.c
lang_hooks.parse_file () toplev.c
c_parse_file () c-parser.c
c_parser_tranlation_unit () c-parser.c
c_parser_external_declaration () c-parser.c
c_parser_declaration_or_fndef () c-parser.c
finish_function () c-decl.c
Then I tried to add second AST analysis from toplev_main () to c_parser_file () with doubling the next level call, for example, in do_compile () , I let compile_file () called twice , then I all get " segmentation fault" from crtstuff.c line 348
CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, frame_dummy)
I learn some knowledge about crtstuff.c but can't get the point. So my problem is what this crtstuff.c really is , why double calling causes error and most important thing, How to repeat analysis safely ?
Thanks
2009-07-06