This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: plugin event for C/C++ declarations
On Tue, Apr 27, 2010 at 9:03 AM, Richard Guenther <rguenther@suse.de> wrote:
> On Tue, 27 Apr 2010, Diego Novillo wrote:
>
>> On 4/27/10 11:54 , Richard Guenther wrote:
>>
>> > Yes, preferably not as a function but a global variable directly.
>>
>> Ugh, please no more global variables.
>
> ;) ?Works for me as well (it's slightly uncomfortable at -O0 ...)
>
> Richard.
>
Hmm, I don't see a way for this to avoid using a global variable,
there's no state saved for whether a plugin has been added that is not
internal to plugin.c. The patch below (seems to build, need to test
regr) adds a flag_plugin_added; alternatively plugin_name_args_tab
could be extern'ed in plugin.h but there's no reason for anything
outside plugin.c to access this structure's internals.
Brian
gcc/ChangeLog: Brian Hackett <bhackett1024@gmail.com>
* plugin.h: Change invoke_plugin_callbacks to be an inline wrapper.
Add flag_plugin_added for use by wrapper.
* plugin.c: Define above flag.
* (add_new_plugin): Initialize above flag.
* (invoke_plugin_callbacks): Rename to invoke_plugin_callbacks_full.
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c (revision 158789)
+++ gcc/plugin.c (working copy)
@@ -86,6 +86,8 @@ struct callback_info
static struct callback_info *plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC];
static struct callback_info **plugin_callbacks = plugin_callbacks_init;
+/* For invoke_plugin_callbacks(), see plugin.h */
+bool flag_plugin_added = false;
#ifdef ENABLE_PLUGIN
/* Each plugin should define an initialization function with exactly
@@ -137,6 +139,8 @@ add_new_plugin (const char* plugin_name)
bool name_is_short;
const char *pc;
+ flag_plugin_added = true;
+
/* Replace short names by their full path when relevant. */
name_is_short = !IS_ABSOLUTE_PATH (plugin_name);
for (pc = plugin_name; name_is_short && *pc; pc++)
@@ -483,16 +487,11 @@ unregister_callback (const char *plugin_
return PLUGEVT_NO_CALLBACK;
}
-/* Called from inside GCC. Invoke all plug-in callbacks registered with
- the specified event.
- Return PLUGEVT_SUCCESS if at least one callback was called,
- PLUGEVT_NO_CALLBACK if there was no callback.
-
- EVENT - the event identifier
- GCC_DATA - event-specific data provided by the compiler */
+/* Invoke all plugin callbacks registered with the specified event,
+ called from invoke_plugin_callbacks(). */
int
-invoke_plugin_callbacks (int event, void *gcc_data)
+invoke_plugin_callbacks_full (int event, void *gcc_data)
{
int retval = PLUGEVT_SUCCESS;
Index: gcc/plugin.h
===================================================================
--- gcc/plugin.h (revision 158789)
+++ gcc/plugin.h (working copy)
@@ -26,7 +26,7 @@ struct attribute_spec;
extern void add_new_plugin (const char *);
extern void parse_plugin_arg_opt (const char *);
-extern int invoke_plugin_callbacks (int, void *);
+extern int invoke_plugin_callbacks_full (int, void *);
extern void initialize_plugins (void);
extern bool plugins_active_p (void);
extern void dump_active_plugins (FILE *);
@@ -35,6 +35,27 @@ extern void print_plugins_versions (FILE
extern void print_plugins_help (FILE *file, const char *indent);
extern void finalize_plugins (void);
+/* True iff at least one plugin has been added. */
+extern bool flag_plugin_added;
+
+/* Called from inside GCC. Invoke all plugin callbacks registered with
+ the specified event.
+ Return PLUGEVT_SUCCESS if at least one callback was called,
+ PLUGEVT_NO_CALLBACK if there was no callback.
+
+ EVENT - the event identifier
+ GCC_DATA - event-specific data provided by the compiler */
+
+static inline int
+invoke_plugin_callbacks (int event, void *gcc_data)
+{
+#ifdef ENABLE_PLUGIN
+ if (flag_plugin_added)
+ return invoke_plugin_callbacks_full (event, gcc_data);
+#endif
+ return PLUGEVT_NO_CALLBACK;
+}
+
/* In attribs.c. */
extern void register_attribute (const struct attribute_spec *attr);