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]

[trunk][patch] Rest of the plugin merge 3/3


This is the last patch left on the branch. It adds support for plugins
having help strings and prints them on --help.

2009-04-16  Rafael Avila de Espindola  <espindola@google.com>

	* common.opt (fhelp): Add Var(help_flag).
	* gcc-plugin.h (plugin_info): Add help.
	* plugin.c (plugin_name_args): Add help.
	(register_plugin_info): Set plugin->help.
	(print_help_one_plugin): New.
	(print_plugins_help): New.
	* plugin.h (print_plugins_help): New.
	* toplev.c (toplev_main): Call print_plugins_help if needed.

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047
diff --git a/gcc/common.opt b/gcc/common.opt
index c6903b6..20dd071 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -39,7 +39,7 @@ Alias for --help=target
 ;; program's insatiable desire to turn options starting with a
 ;; double dash (--) into options starting with a dash f (-f).
 fhelp
-Common
+Common Var(help_flag)
 
 fhelp=
 Common Joined
diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h
index 8627720..6865566 100644
--- a/gcc/gcc-plugin.h
+++ b/gcc/gcc-plugin.h
@@ -64,6 +64,7 @@ struct plugin_pass
 struct plugin_info
 {
   const char *version;
+  const char *help;
 };
 
 /* Function type for the plugin initialization routine. Each plugin module
diff --git a/gcc/plugin.c b/gcc/plugin.c
index f44bbc3..166e177 100644
--- a/gcc/plugin.c
+++ b/gcc/plugin.c
@@ -61,6 +61,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
@@ -460,6 +461,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.
@@ -705,6 +707,49 @@ 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. */
+
+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. */
+
+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.  */
 
diff --git a/gcc/plugin.h b/gcc/plugin.h
index d8cf691..c1f566b 100644
--- a/gcc/plugin.h
+++ b/gcc/plugin.h
@@ -30,6 +30,7 @@ extern bool plugins_active_p (void);
 extern void dump_active_plugins (FILE *);
 extern void debug_active_plugins (void);
 extern void print_plugins_versions (FILE *file, const char *indent);
+extern void print_plugins_help (FILE *file, const char *indent);
 extern void finalize_plugins (void);
 
 #endif /* PLUGIN_H */
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 725c376..0f3d30b 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -2279,6 +2279,9 @@ toplev_main (unsigned int argc, const char **argv)
   if (version_flag)
     print_version (stderr, "");
 
+  if (help_flag)
+    print_plugins_help (stderr, "");
+
   /* Exit early if we can (e.g. -help).  */
   if (!exit_after_options)
     do_compile ();

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