public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "krik_evrywear at hotmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug plugins/50889] New: PLUGIN_FINISH_UNIT arrives a bit to late for really high-level (AST-based) in-memory code transformation/instrumentation Date: Thu, 27 Oct 2011 20:41:00 -0000 [thread overview] Message-ID: <bug-50889-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50889 Bug #: 50889 Summary: PLUGIN_FINISH_UNIT arrives a bit to late for really high-level (AST-based) in-memory code transformation/instrumentation Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: plugins AssignedTo: unassigned@gcc.gnu.org ReportedBy: krik_evrywear@hotmail.com The PLUGIN_FINISH_UNIT callback is called in toplev.c at line 668 (in version 4.6.2 of gcc), at the very end of the compile_file () function. Unfortunately, it seems to mean the heavy work of lowering the AST is already done by the time it reaches this callback, and to the point to having almost finished emitting the assembly code, as suggested by the comment and statement just after the callback call: /* This must be at the end. Some target ports emit end of file directives into the assembly file here, and hence we can not output anything to the assembly file after this point. */ targetm.asm_out.file_end (); At least that's the way I understand it, I'm very new to gcc. That's way too late to do some high-level transformations on the AST before it gets lowered and, thus, the "new" (freshly in-memory modified) code gets included into the lower phases of the process. I've come to this basic conclusion after having checked the work the interesting functions called by the parse_file () hook do, and having checked against the way GCC-XML has modified gcc 4.2.1 to call its own hook to browse through the high-level AST generated when gcc has finished parsing the source file. I would like to request adding a simple additional callback type, something like "PLUGIN_PREFINISH_UNIT", "PLUGIN_PRE_FINISH_UNIT", "PLUGIN_FINISH_PARSE_UNIT" or whatever name suits, which would be called at line 585 (still talking against version 4.6.2), just before the "if (flag_syntax_only || flag_wpa)" line, that's the best place I can spot (and the one looking the more logical to me). It's just a matter of adding a few lines here and there (code and docs). I could appropriately alter a checked-out revision of version 4.7.0, or whatever is called the "trunk" for now, if it's ok and it can help this gets implemented. As to the reason why, for example, I would like to automatically add a companion variable to some variables based on their type, through a plugin. Which is not safe to do with some naive look-up, and far from trivial to do otherwise because of redoing what gcc already does very much that I could ever do, that's parsing the source code. Doing this with a plugin would heavily simplify and help the analysis, and thus the insertion at proper place in the AST. For completeness, I should mention it seems to me the bug 44968 ("structs saved (in a vector) during PLUGIN_FINISH_TYPE are mangled by the time of PLUGIN_FINISH_UNIT") is a bit related to this request, as the author seems to have expected the AST would be the raw one, not an already lowered one.
next reply other threads:[~2011-10-27 20:41 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-10-27 20:41 krik_evrywear at hotmail dot com [this message] 2011-10-27 20:47 ` [Bug plugins/50889] " pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-50889-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).