public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Getting more information about functions arguments/locals inmachine description
@ 2002-05-03  9:59 Chris Lattner
  2002-05-05  5:00 ` Alexandre Courbot
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Lattner @ 2002-05-03  9:59 UTC (permalink / raw)
  To: gcc; +Cc: Alexandre Courbot


> I need to know how many arguments/local variables have
> being used and their starting offset on the stack (their size would
> actually help too)

DISCLAIMER: If there _is_ a right way to do it, this isn't it.  When I was
asking similar kinds of questions, there wasn't an "answer" persay, so
this is not much more than a hack.  That said here is what I'm doing to
get similar information (and it works great):

I added a hook earlier in GCC that grabs information from the function
tree as it's being compiled.  Because the arguments from the tree code
have all the information that you need, you can just grab it from there.
Since the argument allocation is target dependant, and this is target
dependant code, you just have to make sure that you transform them
consistently w.r.t the GCC backend.

For (stack allocated) local variables, you can use a function like this to
recursively traverse the blocks in the program, pulling out the
information you need:

static void PrintLocalVars(tree Block) {
  tree decl, subblocks;
  for (decl = BLOCK_VARS(Block); decl != NULL; decl = TREE_CHAIN(decl))
    debug_tree(decl);

  for (subblocks = BLOCK_SUBBLOCKS(Block); subblocks != NULL;
       subblocks = BLOCK_CHAIN(subblocks))
    PrintLocalVars(subblocks);
}

The RTL (accessible via DECL_RTL(decl) in the first loop), will tell you
enough information to know where on the stack it is located.  The type of
the variable will tell you alignment, size, or anything else you need.

Hope this helps,

-Chris

http://www.nondot.org/~sabre/os/
http://www.nondot.org/~sabre/Projects/

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

* RE: Getting more information about functions arguments/locals inmachine description
  2002-05-03  9:59 Getting more information about functions arguments/locals inmachine description Chris Lattner
@ 2002-05-05  5:00 ` Alexandre Courbot
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Courbot @ 2002-05-05  5:00 UTC (permalink / raw)
  To: Chris Lattner; +Cc: gcc

> For (stack allocated) local variables, you can use a function like this to
> recursively traverse the blocks in the program, pulling out the
> information you need:
> 
> static void PrintLocalVars(tree Block) {
>   tree decl, subblocks;
>   for (decl = BLOCK_VARS(Block); decl != NULL; decl = TREE_CHAIN(decl))
>     debug_tree(decl);
> 
>   for (subblocks = BLOCK_SUBBLOCKS(Block); subblocks != NULL;
>        subblocks = BLOCK_CHAIN(subblocks))
>     PrintLocalVars(subblocks);
> }
> 
> The RTL (accessible via DECL_RTL(decl) in the first loop), will tell you
> enough information to know where on the stack it is located.  The type of
> the variable will tell you alignment, size, or anything else you need.
> 
> Hope this helps,

It does help, absolutely! :) I didn't want at first to deal with trees,
but it looks like I have no choice - and it's not as messy as I'd have
expected. Anyway, it does the job well.

One little question remains however: while your function is absolutely
clear, where to call it and what to give it as argument isn't completely
yet. Shall I give it the block of the function, in, say,
ASM_DECLARE_FUNCTION_NAME (as it is given the function's tree node as
argument), to output the locals later in FUNCTION_PROLOGUE? Or is there
a way to call it with the "root" of the program's tree, to retrieve all
the function's variables once and for all? As it makes use of recursion,
I guess the later is the good way, but I don't know when I could call
it, and how to get the program's tree - I'm not yet very familiar with
GCC's internals. Can you extend a little bit on how you use it? Or point
me to the source where you make use of it?

Anyway, thanks for the help - your reply has been a relief to me! :)
Alex.
-- 
http://www.gnurou.org

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

end of thread, other threads:[~2002-05-05 12:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-03  9:59 Getting more information about functions arguments/locals inmachine description Chris Lattner
2002-05-05  5:00 ` Alexandre Courbot

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).