Commit 78bf7bd0 by Olatunji Ruwase Committed by Rafael Espindola

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
parent 20460eb9
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
......
......@@ -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. */
@};
......
......@@ -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. */
};
......
......@@ -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:
......
......@@ -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 {
......
/* { dg-do compile } */
/* { dg-options "-O" } */
int main (int argc, char **argv)
{
return 0;
}
/* 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;
}
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment