This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch][plugin] Add PLUGIN_START_UNIT
- From: Olatunji Ruwase <tjruwase at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 22 Jun 2009 16:14:46 -0700
- Subject: [patch][plugin] Add PLUGIN_START_UNIT
Hello,
This patch adds PLUGIN_START_UNIT callbacks.
PLUGIN_START_UNIT callbacks allow plugins to initialize state for
each translation unit, before it is compiled.
For example, plugins like mudflap create artificial variables/types
and expect type trees (*_type_node) have been created.
Therefore PLUGIN_START_UNIT callbacks are invoked after all the
frontend initialization but before code compilation.
The patch bootstraps on x86_64-unknown-linux-gnu target and has no
test suite regressions.
Thank you
tunji
2009-06-22 Olatunji Ruwase <tjruwase@google.com>
* doc/plugins.texi: Document PLUGIN_START_UNIT.
* toplev.c (compile_file): Call PLUGIN_START_UNIT.
* gcc-plugin.h (PLUGIN_START_UNIT): Added new event.
* plugin.c (plugin_event_name): Added PLUGIN_START_UNIT.
(register_callback): Handle PLUGIN_START_UNIT.
(invoke_plugin_callbacks): Handle PLUGIN_START_UNIT.
Index: gcc/doc/plugins.texi
===================================================================
--- gcc/doc/plugins.texi (revision 148809)
+++ gcc/doc/plugins.texi (working copy)
@@ -134,6 +134,7 @@ enum plugin_event
PLUGIN_GGC_END, /* Called at end of GGC. */
PLUGIN_REGISTER_GGC_ROOTS, /* Register an extra GGC root table. */
PLUGIN_ATTRIBUTES, /* Called during attribute registration */
+ PLUGIN_START_UNIT, /* Called before processing a
translation unit. */
PLUGIN_EVENT_LAST /* Dummy event used for indexing callback
array. */
@};
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c (revision 148809)
+++ gcc/toplev.c (working copy)
@@ -1017,6 +1017,7 @@ compile_file (void)
init_final (main_input_filename);
coverage_init (aux_base_name);
statistics_init ();
+ invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
timevar_push (TV_PARSE);
/* Stop timing and print the times. */
Index: gcc/gcc-plugin.h
===================================================================
--- gcc/gcc-plugin.h (revision 148809)
+++ gcc/gcc-plugin.h (working copy)
@@ -41,6 +41,7 @@ enum plugin_event
PLUGIN_GGC_END, /* Called at end of GGC. */
PLUGIN_REGISTER_GGC_ROOTS, /* Register an extra GGC root table. */
PLUGIN_ATTRIBUTES, /* Called during attribute registration. */
+ PLUGIN_START_UNIT, /* Called before processing a
translation unit. */
PLUGIN_EVENT_LAST /* Dummy event used for indexing callback
array. */
};
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c (revision 148809)
+++ gcc/plugin.c (working copy)
@@ -57,6 +57,7 @@ const char *plugin_event_name[] =
"PLUGIN_GGC_MARKING",
"PLUGIN_GGC_END",
"PLUGIN_REGISTER_GGC_ROOTS",
+ "PLUGIN_START_UNIT",
"PLUGIN_EVENT_LAST"
};
@@ -499,6 +500,7 @@ register_callback (const char *plugin_na
ggc_register_root_tab ((const struct ggc_root_tab*) user_data);
break;
case PLUGIN_FINISH_TYPE:
+ case PLUGIN_START_UNIT:
case PLUGIN_FINISH_UNIT:
case PLUGIN_CXX_CP_PRE_GENERICIZE:
case PLUGIN_GGC_START:
@@ -544,6 +546,7 @@ invoke_plugin_callbacks (enum plugin_eve
switch (event)
{
case PLUGIN_FINISH_TYPE:
+ case PLUGIN_START_UNIT:
case PLUGIN_FINISH_UNIT:
case PLUGIN_CXX_CP_PRE_GENERICIZE:
case PLUGIN_ATTRIBUTES: