From 7ab7a989a5cd6602442d89b1f4119c26050bdf90 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Fri, 3 Sep 2010 20:32:39 -0400 Subject: [PATCH] Added a way to see arguments passed to the GCC command line. --- src/aop-main.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/aop.h | 1 + 2 files changed, 45 insertions(+) diff --git a/src/aop-main.c b/src/aop-main.c index f25ba94..49c1f7e 100644 --- a/src/aop-main.c +++ b/src/aop-main.c @@ -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: + * + * -fplugin-arg-${BASENAME}-${KEY}=${VALUE} + * + * 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 + * libfoo.so, its basename will be foo. + * + * 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 last 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 (); diff --git a/src/aop.h b/src/aop.h index 050f7b5..fb322dc 100644 --- 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 -- 2.43.0