#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[] =
int argc;
struct plugin_argument *argv;
const char *version;
+ const char *help;
};
/* Hash table for the plugin_name_args objects created during command-line
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.
}
/* 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;
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. */
{
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;
+}