static const char *aop_plugin_name;
+static const struct plugin_argument *plugin_argv;
+static int plugin_argc;
+
/* This code regimplifies the current function. Regimplification
fixes broken GIMPLE invariants. */
static void
}
}
+/**
+ * Find the value for a command-line argument passed to the plug-in.
+ * You can pass a key/value argument to your plug-in on the GCC
+ * command line like this:
+ *
+ * <code>-fplugin-arg-${BASENAME}-${KEY}=${VALUE}</code>
+ *
+ * where ${BASENAME} is the base name of your plug-in, which GCC
+ * determines from the plug-in's file name. If your plug-in is named
+ * <code>libfoo.so</code>, its basename will be <code>foo</code>.
+ *
+ * If you want to be able to pass arguments to your plug-in, the
+ * plug-in's file name must not have any hyphens. This is a
+ * restriction of GCC.
+ *
+ * \param key The argument key.
+ * \return If the user passed an argument with the specified key to
+ * this plug-in, aop_get_arg_value() returns the associated value.
+ * Otherwise, it returns NULL. If the user passed multiple arguments
+ * with the specified key, aop_get_arg_value() returns the value that
+ * was <i>last</i> on the command line.
+ */
+const char *
+aop_get_arg_value (const char *key)
+{
+ int i;
+ const char *value = NULL;
+
+ for (i = 0; i < plugin_argc; i++)
+ if (strcmp(key, plugin_argv[i].key) == 0)
+ value = plugin_argv[i].value;
+
+ return value;
+}
+
/* Store a list of all struct opt_pass objects we create so that we
can free them at cleanup time. */
typedef struct opt_pass *aop_pass;
aop_plugin_name = plugin_info->base_name;
+ /* GCC will destroy the plugin_info object when this init function
+ finishes but will not destroy the arguments vector. This
+ behavior is documented, so we can rely on it. */
+ plugin_argc = plugin_info->argc;
+ plugin_argv = plugin_info->argv;
+
/* Initialization for aop-type.c and aop-header.c. */
init_type_table ();
init_prototype_table ();