diff options
author | espindola <espindola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-06-29 21:17:40 +0000 |
---|---|---|
committer | espindola <espindola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-06-29 21:17:40 +0000 |
commit | 275b769bf477e9dd3d9b7a9855a8919c40d503bb (patch) | |
tree | 63398d650a9579870dc5c29493d49d49e66f87cb | |
parent | 91cf6ba3f39e8d8ae45283cb3af328c1583eeb75 (diff) | |
download | gcc-275b769bf477e9dd3d9b7a9855a8919c40d503bb.tar.gz |
2009-06-29 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149064 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/doc/plugins.texi | 1 | ||||
-rw-r--r-- | gcc/gcc-plugin.h | 1 | ||||
-rw-r--r-- | gcc/plugin.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/plugin/plugin.exp | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/plugin/start_unit-test-1.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/plugin/start_unit_plugin.c | 66 | ||||
-rw-r--r-- | gcc/toplev.c | 1 |
8 files changed, 89 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ecc41cb034c..1566160373c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2009-06-29 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. + 2009-06-29 Eric Botcazou <ebotcazou@adacore.com> * tree.c (process_call_operands): Propagate TREE_READONLY from the diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi index c5efc81c6d5..4dfb159c883 100644 --- a/gcc/doc/plugins.texi +++ b/gcc/doc/plugins.texi @@ -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. */ @}; diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h index 1588bca372c..9fbdc91af25 100644 --- a/gcc/gcc-plugin.h +++ b/gcc/gcc-plugin.h @@ -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. */ }; diff --git a/gcc/plugin.c b/gcc/plugin.c index 396850a3a97..f6578505b88 100644 --- a/gcc/plugin.c +++ b/gcc/plugin.c @@ -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_name, 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_event event, void *gcc_data) switch (event) { case PLUGIN_FINISH_TYPE: + case PLUGIN_START_UNIT: case PLUGIN_FINISH_UNIT: case PLUGIN_CXX_CP_PRE_GENERICIZE: case PLUGIN_ATTRIBUTES: diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index be6d7ab1243..3122fa8dc3e 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -50,6 +50,7 @@ set plugin_test_list [list \ { selfassign.c self-assign-test-1.c self-assign-test-2.c } \ { ggcplug.c ggcplug-test-1.c } \ { one_time_plugin.c one_time-test-1.c } \ + { start_unit_plugin.c start_unit-test-1.c } \ ] foreach plugin_test $plugin_test_list { diff --git a/gcc/testsuite/gcc.dg/plugin/start_unit-test-1.c b/gcc/testsuite/gcc.dg/plugin/start_unit-test-1.c new file mode 100644 index 00000000000..4cd8a40f441 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/start_unit-test-1.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +int main (int argc, char **argv) +{ + return 0; +} diff --git a/gcc/testsuite/gcc.dg/plugin/start_unit_plugin.c b/gcc/testsuite/gcc.dg/plugin/start_unit_plugin.c new file mode 100644 index 00000000000..5b16e84a432 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/start_unit_plugin.c @@ -0,0 +1,66 @@ +/* This plugin tests the correct operation of a PLUGIN_START_UNIT callback. + * By the time a PLUGIN_START_UNIT callback is invoked, the frontend + * initialization should have completed. At least the different *_type_nodes + * should have been created. This plugin creates an artifical global + * interger variable. + * +*/ +#include "gcc-plugin.h" +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "toplev.h" +#include "basic-block.h" +#include "gimple.h" +#include "tree.h" +#include "tree-pass.h" +#include "intl.h" + +int plugin_is_GPL_compatible; +static tree fake_var = NULL; + +static bool +gate_start_unit (void) +{ + return true; +} + +static void start_unit_callback (void *gcc_data, void *user_data) +{ + if (integer_type_node) { + fake_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, + get_identifier ("_fake_var_"), + integer_type_node); + TREE_PUBLIC (fake_var) = 1; + DECL_ARTIFICIAL (fake_var) = 1; + } +} + +static void finish_unit_callback (void *gcc_data, void *user_data) +{ + if (fake_var == NULL) { + printf ("fake_var not created \n"); + return; + } + if (TREE_CODE (fake_var) != VAR_DECL) { + printf ("fake_var not a VAR_DECL \n"); + return; + } + if (TREE_CODE (TREE_TYPE (fake_var)) != INTEGER_TYPE) { + printf ("fake_var not INTEGER_TYPE \n"); + return; + } + if (DECL_ARTIFICIAL (fake_var) == 0) { + printf ("fake_var not ARTIFICIAL \n"); + return; + } +} + +int plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL); + register_callback ("finish_unit", PLUGIN_FINISH_UNIT, &finish_unit_callback, NULL); + return 0; +} diff --git a/gcc/toplev.c b/gcc/toplev.c index 483623882bf..2bd392becc1 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -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); |