This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: plugin event for C/C++ declarations


On Wed, 28 Apr 2010, Brian Hackett wrote:

> On Wed, Apr 28, 2010 at 5:46 AM, Diego Novillo <dnovillo@google.com> wrote:
> > On 4/27/10 15:43 , Brian Hackett wrote:
> >
> >> Hmm, I don't see a way for this to avoid using a global variable,
> >
> > I wanted to avoid introducing a *new* one actually. ?But I had forgotten
> > that we don't already have one for -fplugin.
> >
> >> 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.
> >
> > OK with the changes Richard suggested for the ChangeLog entry and:
> >
> >
> >> +/* True iff at least one plugin has been added. */
> >> +extern bool flag_plugin_added;
> >
> > Move the declaration inside invoke_plugin_callbacks? ?This will at least
> > prevent other functions outside plugin.c from trying to access it.
> >
> >
> > Diego.
> >
> 
> Hi, here is an updated patch incorporating this change.  For this
> patch 'make bootstrap' works for me on x86_64 linux (plugin support)
> and x86_64 darwin (no plugin support), and the plugin regressions
> pass.

Thanks.

I fixed minor formatting issues (two spaces after a '.' in a comment)
and committed it to trunk as rev. 158896.

Do you have a copyright assignment on file with the FSF?  If you
want to continue to contribute you should get one.

Thanks,
Richard.

> Brian
> 
> gcc/ChangeLog:   Brian Hackett   <bhackett1024@gmail.com>
> 
> 	* plugin.h (invoke_plugin_callbacks): New inline function.
> 	* plugin.c (flag_plugin_added): New global flag.
> 	(add_new_plugin): Initialize above flag.
> 	(invoke_plugin_callbacks): Rename to ...
> 	(invoke_plugin_callbacks_full): ... this.
> 
> Index: gcc/plugin.c
> ===================================================================
> --- gcc/plugin.c	(revision 158822)
> +++ 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 158822)
> +++ 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,30 @@ extern void print_plugins_versions (FILE
>  extern void print_plugins_help (FILE *file, const char *indent);
>  extern void finalize_plugins (void);
> 
> +/* 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
> +
> +  /* True iff at least one plugin has been added. */
> +  extern bool flag_plugin_added;
> +
> +  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);
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]