]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
common.opt (fhelp): Add Var(help_flag).
authorRafael Avila de Espindola <espindola@google.com>
Thu, 16 Apr 2009 14:31:45 +0000 (14:31 +0000)
committerRafael Espindola <espindola@gcc.gnu.org>
Thu, 16 Apr 2009 14:31:45 +0000 (14:31 +0000)
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.

From-SVN: r146195

gcc/ChangeLog
gcc/common.opt
gcc/gcc-plugin.h
gcc/plugin.c
gcc/plugin.h
gcc/toplev.c

index b442ef00f416f9ea39bacb141f242b4fbbaa65f2..04eb70a1d361395692be9a56e7909e5953127327 100644 (file)
@@ -1,3 +1,14 @@
+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.
+
 2009-04-16  Richard Guenther  <rguenther@suse.de>
 
        * gimple.c (gimple_copy): Do not clear addresses_taken bitmap.
index c6903b60d71b0a5f6d061d89a473b6b205851c98..20dd071cd7cdbb91079ca991b15a3127a4d5c415 100644 (file)
@@ -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
index 8627720acd23221f3988b4f38737d7e1039788f5..6865566472f20edbc888ac39af4de670ff41b60b 100644 (file)
@@ -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
index 95297a7d395f4fd14e8152d1af47d959cb415d07..4d4addd3bd8f77885a48a321a6ed9a4e517d369c 100644 (file)
@@ -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
@@ -461,6 +462,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.
@@ -708,6 +710,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.  */
 
index d8cf6919a4a9d058c42f0bdf4de5e343712db40b..c1f566ba80f20795caaca1649ac7eab7fe4e5272 100644 (file)
@@ -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 */
index 725c3762767035c985adb5e71b766eb1dc376cda..0f3d30b3b6331d73a670f8db595d8dfa07b75b8a 100644 (file)
@@ -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 ();