This is the mail archive of the gcc-help@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]

how to dumping out function name and its parameters from gcc's AST?


Hi, hackers,

I am now try to dump our AST from gcc 3.4.0 for c programming language.
Currently, I'd like to dump out the function name and its parameters if
any.

For example, for a function call to the function foo like "foo(a, b, c)" ,
I would like "foo, a, b, c" dumped out.

My instrumented code into gcc's c-decl.c is

switch (TREE_CODE(expr)){
case CALL_EXPR:
printf("%s", IDENTIFIER_POINTER(DECL_NAME(TREE_OPERAND(expr, 0), 0))));
tree paralist = TREE_VALUE(TREE_OPERAND(expr, 1));
tree para = TREE_CHAIN(paralist);
while(para != NULL_TREE){
printf("%s", IDENTIFIER_POINTER(DECL_NAME(para)));
para = TREE_CHAIN(para);
}

but it failed to give the correct parameter names while function name is
correct. So what's wrong? I know in cases like foo(i+j, p+q), it is
undefined what to dump out but just want to know in the simple case foo(i,
j) how to dump foo, i, j if possible.

btw, for an expression "expr" with TREE_CODE as CALL_EXPR, what is the
type of TREE_OPERAND(expr, 0) and TREE_OPERAND(expr, 1); As documented in
tree.def, they are function and paralist, but what are their TREE_CODES?

Also, given one tree type variable, like tree tmp, how can I know its
TREE_CODE? Do we have some methods to print its type out?

many thanks to your patience. If you are not clear about what I mean, do
let me know.

thanks again,
Chao


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