Added a way to see arguments passed to the GCC command line.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Sat, 4 Sep 2010 00:32:39 +0000 (20:32 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Sat, 4 Sep 2010 00:32:39 +0000 (20:32 -0400)
src/aop-main.c
src/aop.h

index f25ba94fe10e7bcf2ce0cd8e4eca3e821c09b95b..49c1f7eed0777fcf8ded8f6aa6286532d48f2d80 100644 (file)
@@ -60,6 +60,9 @@
 
 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
@@ -151,6 +154,41 @@ aop_join_on_copy (struct aop_pointcut *pc, int copy, join_callback callback,
   }
 }
 
+/**
+ * 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;
@@ -249,6 +287,12 @@ plugin_init (struct plugin_name_args *plugin_info,
 
   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 ();
index 050f7b5755937abff5f93e867ee8df7ce5f13468..fb322dc605294e2299139c68ca22dc9164751fd6 100644 (file)
--- a/src/aop.h
+++ b/src/aop.h
@@ -289,6 +289,7 @@ extern struct aop_dynval *aop_capture_assigned_value (struct aop_joinpoint *jp);
 extern int aop_write_c_header (const char *filename, const char *guard,
                               const char *license, const char *preamble);
 
+extern const char *aop_get_arg_value (const char *key);
 
 /**
  * \defgroup scope_val aop_capture_lhs_var_scope() Return Values