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]

[plugins] Change plugin_init signature


Hi,
Currently plugin_init passes almost every field from plugin_name_args to plugin_init, instead of modifying it to pass full_name I believe it is better to pass the struct itself.


The main purpose of this patch is to allow my plugin to figure out the pathname of the plugin as it were passed to GCC.

This should futureproof the plugin_init function such that every time a new field is added to plugin_name_args struct, it doesn't require changing plugin_init to pass that new bit of information.


2009-05-20 Taras Glek <tglek@mozilla.com>


gcc/ChangeLog
* plugin.c (try_init_one_plugin): Updated to new plugin_init API.
* gcc-plugin.h (plugin_init): Updated signature.
* gcc-plugin.h (plugin_name_args): Moved to this header.
* doc/plugins.texi (plugin_init): Updated documention to reflect API change.
* doc/plugins.texi (plugin_name_args): Added to documention.
gcc/testsuite/ChangeLog
* gcc.dg/plugin/selfassign.c (plugin_init): Updated to new plugin_init signature.
* g++.dg/plugin/selfassign.c (plugin_init): Updated to new plugin_init signature.
* g++.dg/plugin/dumb_plugin.c (plugin_init): Updated to new plugin_init signature.
* g++.dg/plugin/attribute_plugin.c (plugin_init): Updated to new plugin_init signature.


diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi
--- a/gcc/doc/plugins.texi
+++ b/gcc/doc/plugins.texi
@@ -41,11 +41,23 @@ This function is called from @code{compi
 the parser.  The arguments to @code{plugin_init} are:
 
 @itemize @bullet
-@item @code{plugin_name}: Name of the plugin.
-@item @code{argc}: Number of arguments specified with @option{-fplugin-arg-...}.
-@item @code{argv}: Array of @code{argc} key-value pairs.
+@item @code{plugin_info}: Plugin invocation information.
+@item @code{version}: GCC version.
 @end itemize
 
+The @code{plugin_info} struct is defined as follows:
+
+@smallexample
+struct plugin_name_args
+@{
+  char *base_name;              /* Short name of the plugin (filename without .so suffix). */
+  const char *full_name;        /* Path to the plugin as specified with -fplugin=. */
+  int argc;                     /* Number of arguments specified with -fplugin-arg-.... */
+  struct plugin_argument *argv; /* Array of ARGC key-value pairs. */
+  const char *version;          /* Version string provided by plugin. */
+  const char *help;             /* Help string provided by plugin. */
+@}
+@end smallexample
 If initialization fails, @code{plugin_init} must return a non-zero
 value.  Otherwise, it should return 0.
 
@@ -120,7 +132,8 @@ struct plugin_pass
 
 /* Sample plugin code that registers a new pass.  */
 int
-plugin_init (const char *plugin_name, int argc, struct plugin_argument *argv)
+plugin_init (struct plugin_name_args *plugin_info,
+             struct plugin_gcc_version *version)
 @{
   struct plugin_pass pass_info;
 
@@ -131,7 +144,7 @@ plugin_init (const char *plugin_name, in
   ...
 
   /* Register the new pass.  */
-  register_callback (plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
+  register_callback (plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
 
   ...
 @}
diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
--- a/gcc/gcc-plugin.h
+++ b/gcc/gcc-plugin.h
@@ -79,6 +79,17 @@ struct plugin_gcc_version
   const char *configuration_arguments;
 };
 
+/* Object that keeps track of the plugin name and its arguments. */
+struct plugin_name_args
+{
+  char *base_name;              /* Short name of the plugin (filename without .so suffix). */
+  const char *full_name;        /* Path to the plugin as specified with -fplugin=. */
+  int argc;                     /* Number of arguments specified with -fplugin-arg-... */
+  struct plugin_argument *argv; /* Array of ARGC key-value pairs. */
+  const char *version;          /* Version string provided by plugin. */
+  const char *help;             /* Help string provided by plugin. */
+};
+
 /* The default version check. Compares every field in VERSION. */
 
 extern bool plugin_default_version_check (struct plugin_gcc_version *,
@@ -88,21 +99,18 @@ extern bool plugin_default_version_check
    should define this as an externally-visible function with name
    "plugin_init."
 
-   PLUGIN_NAME - name of the plugin (useful for error reporting)
-   VERSION     - the plugin_gcc_version symbol of the plugin itself.
-   ARGC        - the size of the ARGV array
-   ARGV        - an array of key-value argument pair
+   PLUGIN_INFO - plugin invocation information.
+   VERSION     - the plugin_gcc_version symbol of GCC.
 
    Returns 0 if initialization finishes successfully.  */
 
-typedef int (*plugin_init_func) (const char *plugin_name,
-                                 struct plugin_gcc_version *version,
-                                 int argc, struct plugin_argument *argv);
+typedef int (*plugin_init_func) (struct plugin_name_args *plugin_info,
+                                 struct plugin_gcc_version *version);
 
 /* Declaration for "plugin_init" function so that it doesn't need to be
    duplicated in every plugin.  */
-extern int plugin_init (const char *, struct plugin_gcc_version *version,
-			int, struct plugin_argument *);
+extern int plugin_init (struct plugin_name_args *plugin_info,
+                        struct plugin_gcc_version *version);
 
 /* Function type for a plugin callback routine.
 
diff --git a/gcc/plugin.c b/gcc/plugin.c
--- a/gcc/plugin.c
+++ b/gcc/plugin.c
@@ -54,19 +54,6 @@ const char *plugin_event_name[] =
   "PLUGIN_EVENT_LAST"
 };
 
-/* Object that keeps track of the plugin name and its arguments
-   when parsing the command-line options -fplugin=/path/to/NAME.so and
-   -fplugin-arg-NAME-<key>[=<value>].  */
-struct plugin_name_args
-{
-  char *base_name;
-  const char *full_name;
-  int argc;
-  struct plugin_argument *argv;
-  const char *version;
-  const char *help;
-};
-
 /* Hash table for the plugin_name_args objects created during command-line
    parsing.  */
 static htab_t plugin_name_args_tab = NULL;
@@ -596,8 +583,7 @@ try_init_one_plugin (struct plugin_name_
     }
 
   /* Call the plugin-provided initialization routine with the arguments.  */
-  if ((*plugin_init) (plugin->base_name, &gcc_version, plugin->argc,
-		      plugin->argv))
+  if ((*plugin_init) (plugin, &gcc_version))
     {
       error ("Fail to initialize plugin %s", plugin->full_name);
       return false;
diff --git a/gcc/testsuite/g++.dg/plugin/attribute_plugin.c b/gcc/testsuite/g++.dg/plugin/attribute_plugin.c
--- a/gcc/testsuite/g++.dg/plugin/attribute_plugin.c
+++ b/gcc/testsuite/g++.dg/plugin/attribute_plugin.c
@@ -54,10 +54,10 @@ handle_pre_generic (void *event_data, vo
 }
 
 int
-plugin_init (const char *plugin_name,
-             struct plugin_gcc_version *version,
-             int argc, struct plugin_argument *argv)
+plugin_init (struct plugin_name_args *plugin_info,
+             struct plugin_gcc_version *version)
 {
+  const char *plugin_name = plugin_info->base_name;
   register_callback (plugin_name, PLUGIN_CXX_CP_PRE_GENERICIZE,
                      handle_pre_generic, NULL);
 
diff --git a/gcc/testsuite/g++.dg/plugin/dumb_plugin.c b/gcc/testsuite/g++.dg/plugin/dumb_plugin.c
--- a/gcc/testsuite/g++.dg/plugin/dumb_plugin.c
+++ b/gcc/testsuite/g++.dg/plugin/dumb_plugin.c
@@ -78,11 +78,13 @@ static struct gimple_opt_pass pass_dumb_
    both of which determine where the plugin pass should be inserted.  */
 
 int
-plugin_init (const char *plugin_name,
-             struct plugin_gcc_version *version __attribute__((unused)),
-             int argc, struct plugin_argument *argv)
+plugin_init (struct plugin_name_args *plugin_info,
+             struct plugin_gcc_version *version)
 {
   struct plugin_pass pass_info;
+  const char *plugin_name = plugin_info->base_name;
+  int argc = plugin_info->argc;
+  struct plugin_argument *argv = plugin_info->argv;
   char *ref_pass_name = NULL;
   int ref_instance_number = 0;
   int i;
diff --git a/gcc/testsuite/g++.dg/plugin/selfassign.c b/gcc/testsuite/g++.dg/plugin/selfassign.c
--- a/gcc/testsuite/g++.dg/plugin/selfassign.c
+++ b/gcc/testsuite/g++.dg/plugin/selfassign.c
@@ -294,10 +294,13 @@ static struct gimple_opt_pass pass_warn_
    Note that this function needs to be named exactly "plugin_init".  */
 
 int
-plugin_init (const char *plugin_name, struct plugin_gcc_version *version,
-	     int argc, struct plugin_argument *argv)
+plugin_init (struct plugin_name_args *plugin_info,
+             struct plugin_gcc_version *version)
 {
   struct plugin_pass pass_info;
+  const char *plugin_name = plugin_info->base_name;
+  int argc = plugin_info->argc;
+  struct plugin_argument *argv = plugin_info->argv;
   bool enabled = true;
   int i;
 
diff --git a/gcc/testsuite/gcc.dg/plugin/selfassign.c b/gcc/testsuite/gcc.dg/plugin/selfassign.c
--- a/gcc/testsuite/gcc.dg/plugin/selfassign.c
+++ b/gcc/testsuite/gcc.dg/plugin/selfassign.c
@@ -294,10 +294,13 @@ static struct gimple_opt_pass pass_warn_
    Note that this function needs to be named exactly "plugin_init".  */
 
 int
-plugin_init (const char *plugin_name, struct plugin_gcc_version *version,
-	     int argc, struct plugin_argument *argv)
+plugin_init (struct plugin_name_args *plugin_info,
+             struct plugin_gcc_version *version)
 {
   struct plugin_pass pass_info;
+  const char *plugin_name = plugin_info->base_name;
+  int argc = plugin_info->argc;
+  struct plugin_argument *argv = plugin_info->argv;
   bool enabled = true;
   int i;
 

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