On 5/31/07, Seema S. Ravandale <[EMAIL PROTECTED]> wrote:
> On 5/31/07, Seema S. Ravandale <[EMAIL PROTECTED]> wrote:
>> Hi...
>> This is Seema here. I am working on GCC in IITB as research fellow.
>>
>> Actually i am trying to find out scope information of a variable.
>
>> But i
>> didnt find any information within "decl" data structure of a variable.
>
> It's there, it's in DECL_CONTEXT.
>
> DECL_CONTEXT (var) == NULL if it is global scope
> otherwise
> DECL_CONTEXT (var) == a FUNCTION_DECL which is the variable's scope.
>
>> somewhere i read that "level # attribute" gives the inforamtion about
>> scope. but i am looking at "decl" details just after lowering of GIMPLE
>> and that field is NULL.
>>
>> Is there any other way to find out scope of variable?? Is there any
>> information in "decl" data structure so that i can access symbol table
>> entry??
>

Ok.. i got it context thing.
But what about a variables declared in same functions but in different
scope.

We promote these to function local scope.

 In gimple, for every new scope there is new BIND_EXPR, having its
own var_list and stmt_list.
This is a temporary artifact, not something you should depend on :)
I have seen the details of lowered gimple data structure.
Now how to find out scope of variable "b"??

It is function local scope.

You cannot discover the original scope of the variable (note that this
is similar to what other compilers do).


And one more thing:
Sometimes GCC creates local version of global variable, I mean for every
use of global var say "a", local variable "a.0", "a.1"..  are initialised
to "a" just before use.

Yes, because the global must be re-read after stores that may affect it.
Globals are treated as if they were memory operations, and are only
allowed where other memory operations are.

and in case of local variables, when local var are used as array index,
same temporary variables are created.

e.g

int a=0;
int main()
{
    int c=0;
    int array[10];
    array[c]=a;
}

In Gimple/Generic

array[c] = a;
this  sentance is going to be replaced as:

c.0 = c;
a.1 = a;
array[c.0]=a.1;


so how to decide, tempory of kind c.0 correspond to var "c", not looking
at name??

You can't, and it's not clear why you would want to.
These are compiler generated artificial variables.  They don't really
"correspond" to anything, they just happen to be initialized with a
certain value.  This may change due to various optimizations.

is there some inforamtion in "decl" data structure to access
symbol table??

It's not clear why you want to try to get at the source language scope
or the original expression that caused a temporary generation, from
the middle-end.

If you explain why you are trying to get this (IE what problem you are
trying to solve), we can probably be more helpful.

Reply via email to