public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Accessing Global variables
@ 2012-03-26 14:45 zahed khurasani
  2012-03-26 20:54 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: zahed khurasani @ 2012-03-26 14:45 UTC (permalink / raw)
  To: gcc-help

Hi,

I know that we can access the function parameters using DECL_ARGUMENTS
and similary we can use gimple_bind_vars to access other variable
declarations attached to a bind expression. But how about Global
definitions? How can I access variables defined outside the scope of
any function.

Thanks for your help.

Zahed

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Accessing Global variables
  2012-03-26 14:45 Accessing Global variables zahed khurasani
@ 2012-03-26 20:54 ` Ian Lance Taylor
  2012-03-27 19:00   ` zahed khurasani
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2012-03-26 20:54 UTC (permalink / raw)
  To: zahed khurasani; +Cc: gcc-help

zahed khurasani <sdzahed@gmail.com> writes:

> I know that we can access the function parameters using DECL_ARGUMENTS
> and similary we can use gimple_bind_vars to access other variable
> declarations attached to a bind expression. But how about Global
> definitions? How can I access variables defined outside the scope of
> any function.

Access in what way?

GCC doesn't really have a symbol table--that is, outside of the parser,
you can't really look up global variables by name.  But you should be
able to use the cgraph to traverse all the global variables.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Accessing Global variables
  2012-03-26 20:54 ` Ian Lance Taylor
@ 2012-03-27 19:00   ` zahed khurasani
  0 siblings, 0 replies; 3+ messages in thread
From: zahed khurasani @ 2012-03-27 19:00 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Thanks for the help Ian. By global variables access I meant to access
the VAR_DECL nodes that have global scope.

I've figured out how to do this. I am using
BLOCK_VARS(DECL_INITIAL(DECL_CONTEXT(current_function_decl)). I am
hoping this will work in all cases.

Regards,
Zahed

On Mon, Mar 26, 2012 at 4:54 PM, Ian Lance Taylor <iant@google.com> wrote:
> zahed khurasani <sdzahed@gmail.com> writes:
>
>> I know that we can access the function parameters using DECL_ARGUMENTS
>> and similary we can use gimple_bind_vars to access other variable
>> declarations attached to a bind expression. But how about Global
>> definitions? How can I access variables defined outside the scope of
>> any function.
>
> Access in what way?
>
> GCC doesn't really have a symbol table--that is, outside of the parser,
> you can't really look up global variables by name.  But you should be
> able to use the cgraph to traverse all the global variables.
>
> Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-03-27 19:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26 14:45 Accessing Global variables zahed khurasani
2012-03-26 20:54 ` Ian Lance Taylor
2012-03-27 19:00   ` zahed khurasani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).