This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Retrieving argument value from __attribute__
- From: naga raj <gnuuser dot raj at gmail dot com>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 25 Feb 2013 18:58:55 +0530
- Subject: Retrieving argument value from __attribute__
Hi All,
I am working on Microblaze port. I have a requirement in which user
will declare a handler number in the function prototype as below
ex: void matrix_const(int ) __attribute__((svc_handler(777)));
So my requirement is whenever the matrix_const function is called
then the compiler has to store the attribute value (777) in to a
temporary register(R18) after which user will have his own
implementation of jump tables using r18 register.
To support this I have added it to attribute_spec with req_handler
as "svc_handler_attribute"
static tree
svc_handler_attribute (tree *node ATTRIBUTE_UNUSED,
tree name,
tree args,
int flags ATTRIBUTE_UNUSED,
bool *no_add_attrs)
{
tree value = TREE_VALUE (args);
HOST_WIDE_INT value1 = TREE_INT_CST_LOW (TREE_VALUE (args));
if (TREE_CODE (value) != INTEGER_CST)
{
warning (OPT_Wattributes,
"argument of %qE attribute is not a string constant",
name);
*no_add_attrs = true;
}
return NULL_TREE;
}
With the above handler I am able to extract 777 to value1 variable,
but I think this function will only be called when parsing the
function prototype.
My requirement is to store 777 when matrix_const function is called,
but I was able to find only the type of __attribute__ i.e
svc_handler with below function.
static int
microblaze_svc_handler_function_p (tree func)
{
tree a;
if (TREE_CODE (func) != FUNCTION_DECL)
return 0;
warning (OPT_Wattributes,"argument of %d attribute is not a string
constant", value1->name);
a = lookup_attribute ("svc_handler", DECL_ATTRIBUTES (func));
return a != NULL_TREE;
}
I am calling this function in "compute_frame_size (HOST_WIDE_INT size)"....
My question is how to find the argument value(777) using
"microblaze_svc_handler_function_p" ?? Do we have any ATTRIBUTE
related function to do this.
Please suggest a solution/document by which we can extract the
argument value...
Thanks in Advance,
Nagaraju