Hi,

In file "c-pragma.c" I try to implement my custom pragma handler where
I try to traverse the statements within the function where the pragma
is detected. To implement the traversal I used the implementation of
"cgraph_create_edges" function as reference (in cgraphunit.c file).

My code is as given below:

CASE 1:
void handle_pragma_tes(cpp_reader *ARG_UNUSED(dummy))
{
   basic_block bb;
   block_stmt_iterator bsi;
   struct function *this_cfun;

   /* below I pass a the tree of the current_function_decl a global
variable in tree.h */
   this_cfun = DECL_STRUCT_FUNCTION(current_function_decl);
   FOR_EACH_BB_FN(bb, this_cfun) /* Crashes here, Also tried with
FOR_EACH_BB */
       for (bsi = bsi_start(bb); !bsi_end_p(bsi); bsi_next(&bsi))
       {
              bsi_stmt(bsi);
       }
   bsi = bsi_for_stmt(current_function_decl); /* Crashes right here */
}

Later I tried to obtain just block statement iterator (bsi) for the
current function's block by calling the function "bsi_for_stmt(tree)".
The given code is bellow:

CASE2:

void handle_pragma_tes(cpp_reader *ARG_UNUSED(dummy))
{
   block_stmt_iterator bsi;
   bsi = bsi_for_stmt(current_function_decl); /* Crashes right here */
}

I could not figure out what could be the problem. I would appreciate
your help to make this run..

Thanks,
Ferad Zyulkyarov



On 12/5/06, Revital1 Eres <[EMAIL PROTECTED]> wrote:

> I try to change the front-end tree structure of a c/c++ program as a
> side effect of execution of a pragma. The operations that are involved
> is to walk through in a tree (i.e "C" block), insertion of a tree
> (i.e. statement, block, declaration) in the abstract syntax tree and
> deletion of a tree (i.e. statement, block, declaration).

You can access the function's tree through it's call-graph node. (the
call-graph
node has a pointer to the function's tree declaration), than use
block_stmt_iterator (bsi) to iterate through the function's basic blocks;
each statement in the basic block can be recursively traversed via
walk_tree () function.  (see cgraph_create_edges () in cgraphunit.c).
build1 () function (tree.h) can be used to construct a new tree node.

Hope it helps,
Revital


Reply via email to