This is the mail archive of the 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

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

  for (subblocks = BLOCK_SUBBLOCKS(Block); subblocks != NULL;
       subblocks = BLOCK_CHAIN(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,


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