Manipulating the tree Structure

Daniel Berlin
Mon Mar 12 18:02:00 GMT 2007

On 3/12/07, Andrea Callia D'Iddio <> wrote:
> Great! thank you! I tested with your code and it works... but I'm
> still a bit confused.
> Could you help me with this simple example?
> Suppose that I obtained a tree structure with the following command:
> tree stmt = bsi_stmt (si);
> and suppose I want to execute the following task:
> For each tree statement t:
>   IF t is an assignment, then output variable name

In 4.3 (earlier replace GIMPLE_MODIFY_STMT with MODIFY_EXPR)

tree lhs = TREE_OPERAND (t, 0);
tree rhs = TREE_OPERAND (t, 1);

  print_generic_expr (stderr, lhs, 0);
  print_generic_expr (stderr, rhs, 0);
>   ELSE IF t is an IF statement then output the IF condition
else if TREE_CODE (t) == COND_EXPR)
tree condition = COND_EXPR_COND (t);
print_generic_expr (stderr, condition, 0);

>   ELSE ...
> how can I do this task?

Really, this isn't that hard
> Can you give me some reference?

Look at any existing tree-ssa-*.c pass

They all do this in a myriad of ways.

More information about the Gcc mailing list