OSDN Git Service

2009-05-08 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / plugin.c
index 95297a7..dec336d 100644 (file)
@@ -38,6 +38,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "plugin.h"
 #include "timevar.h"
+#ifdef ENABLE_PLUGIN
+#include "plugin-version.h"
+#endif
 
 /* Event names as strings.  Keep in sync with enum plugin_event.  */
 const char *plugin_event_name[] =
@@ -61,6 +64,7 @@ struct plugin_name_args
   int argc;
   struct plugin_argument *argv;
   const char *version;
+  const char *help;
 };
 
 /* Hash table for the plugin_name_args objects created during command-line
@@ -461,6 +465,7 @@ register_plugin_info (const char* name, struct plugin_info *info)
   void **slot = htab_find_slot (plugin_name_args_tab, name, NO_INSERT);
   struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
   plugin->version = info->version;
+  plugin->help = info->help;
 }
 
 /* Called from the plugin's initialization code. Register a single callback.
@@ -589,7 +594,8 @@ try_init_one_plugin (struct plugin_name_args *plugin)
     }
 
   /* Call the plugin-provided initialization routine with the arguments.  */
-  if ((*plugin_init) (plugin->base_name, plugin->argc, plugin->argv))
+  if ((*plugin_init) (plugin->base_name, &gcc_version, plugin->argc,
+                     plugin->argv))
     {
       error ("Fail to initialize plugin %s", plugin->full_name);
       return false;
@@ -708,6 +714,51 @@ print_plugins_versions (FILE *file, const char *indent)
   htab_traverse_noresize (plugin_name_args_tab, print_version_one_plugin, &opt);
 }
 
+/* Print help for one plugin. SLOT is the hash table slot. DATA is the
+   argument to htab_traverse_noresize. */
+
+static int
+print_help_one_plugin (void **slot, void *data)
+{
+  struct print_options *opt = (struct print_options *) data;
+  struct plugin_name_args *plugin = (struct plugin_name_args *) *slot;
+  const char *help = plugin->help ? plugin->help : "No help available .";
+
+  char *dup = xstrdup (help);
+  char *p, *nl;
+  fprintf (opt->file, " %s%s:\n", opt->indent, plugin->base_name);
+
+  for (p = nl = dup; nl; p = nl)
+    {
+      nl = strchr (nl, '\n');
+      if (nl)
+       {
+         *nl = '\0';
+         nl++;
+       }
+      fprintf (opt->file, "   %s %s\n", opt->indent, p);
+    }
+
+  free (dup);
+  return 1;
+}
+
+/* Print help for each plugin. The output goes to FILE and every line starts
+   with INDENT. */
+
+void
+print_plugins_help (FILE *file, const char *indent)
+{
+  struct print_options opt;
+  opt.file = file;
+  opt.indent = indent;
+  if (!plugin_name_args_tab || htab_elements (plugin_name_args_tab) == 0)
+    return;
+
+  fprintf (file, "%sHelp for the loaded plugins:\n", indent);
+  htab_traverse_noresize (plugin_name_args_tab, print_help_one_plugin, &opt);
+}
+
 
 /* Return true if plugins have been loaded.  */
 
@@ -758,3 +809,26 @@ debug_active_plugins (void)
 {
   dump_active_plugins (stderr);
 }
+
+/* The default version check. Compares every field in VERSION. */
+
+bool
+plugin_default_version_check (struct plugin_gcc_version *gcc_version,
+                             struct plugin_gcc_version *plugin_version)
+{
+  if (!gcc_version || !plugin_version)
+    return false;
+
+  if (strcmp (gcc_version->basever, plugin_version->basever))
+    return false;
+  if (strcmp (gcc_version->datestamp, plugin_version->datestamp))
+    return false;
+  if (strcmp (gcc_version->devphase, plugin_version->devphase))
+    return false;
+  if (strcmp (gcc_version->revision, plugin_version->revision))
+    return false;
+  if (strcmp (gcc_version->configuration_arguments,
+             plugin_version->configuration_arguments))
+    return false;
+  return true;
+}