aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorOlatunji Ruwase <tjruwase@google.com>2009-06-29 21:17:40 +0000
committerRafael Espindola <espindola@gcc.gnu.org>2009-06-29 21:17:40 +0000
commit78bf7bd0fc9a82aff98874e0ff3e12a329f920ab (patch)
tree63398d650a9579870dc5c29493d49d49e66f87cb /gcc
parent20460eb94863954cf7ebdc7bf2193038ac0b781a (diff)
downloadgcc-78bf7bd0fc9a82aff98874e0ff3e12a329f920ab.zip
gcc-78bf7bd0fc9a82aff98874e0ff3e12a329f920ab.tar.gz
gcc-78bf7bd0fc9a82aff98874e0ff3e12a329f920ab.tar.bz2
plugins.texi: Document PLUGIN_START_UNIT.
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. From-SVN: r149064
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/doc/plugins.texi1
-rw-r--r--gcc/gcc-plugin.h1
-rw-r--r--gcc/plugin.c3
-rw-r--r--gcc/testsuite/gcc.dg/plugin/plugin.exp1
-rw-r--r--gcc/testsuite/gcc.dg/plugin/start_unit-test-1.c7
-rw-r--r--gcc/testsuite/gcc.dg/plugin/start_unit_plugin.c66
-rw-r--r--gcc/toplev.c1
8 files changed, 89 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ecc41cb..1566160 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 c5efc81..4dfb159 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 1588bca..9fbdc91 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 396850a..f657850 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 be6d7ab..3122fa8 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 0000000..4cd8a40
--- /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 0000000..5b16e84
--- /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 4836238..2bd392b 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);