This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Getting more information about functions arguments/localsinmachine description


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]