make firm compilable with a c++ compiler
[libfirm] / ir / ana / structure.c
index b48f36d..704af94 100644 (file)
@@ -113,7 +113,7 @@ void set_block_region(ir_node *block, ir_region *reg)
  */
 ir_region *get_irn_region(ir_node *n)
 {
-       if (is_no_Block(n))
+       if (!is_Block(n))
                n = get_nodes_block(n);
        return get_block_region(n);
 }
@@ -123,7 +123,7 @@ ir_region *get_irn_region(ir_node *n)
  */
 int is_region(const void *thing)
 {
-       const firm_kind *kind = thing;
+       const firm_kind *kind = (const firm_kind*) thing;
        return *kind == k_ir_region;
 }
 
@@ -225,7 +225,7 @@ static void dfs_walk(ir_graph *irg, walk_env *env)
        ir_region *reg;
 
        current_ir_graph = irg;
-       reg              = get_irn_link(get_irg_start_block(irg));
+       reg              = (ir_region*) get_irn_link(get_irg_start_block(irg));
 
        env->premax  = 0;
        env->postmax = 0;
@@ -239,7 +239,7 @@ static void dfs_walk(ir_graph *irg, walk_env *env)
  */
 static void wrap_BasicBlocks(ir_node *block, void *ctx)
 {
-       walk_env *env = ctx;
+       walk_env *env = (walk_env*) ctx;
        ir_region *reg;
 
        /* Allocate a Block wrapper */
@@ -268,8 +268,8 @@ static void wrap_BasicBlocks(ir_node *block, void *ctx)
  */
 static void update_BasicBlock_regions(ir_node *blk, void *ctx)
 {
-       walk_env *env = ctx;
-       ir_region *reg = get_irn_link(blk);
+       walk_env *env = (walk_env*) ctx;
+       ir_region *reg = (ir_region*) get_irn_link(blk);
        int i, j, len;
 
        if (blk == env->start_block) {
@@ -280,7 +280,7 @@ static void update_BasicBlock_regions(ir_node *blk, void *ctx)
                reg->pred = NEW_ARR_D(ir_region *, env->obst, len);
                for (i = j = 0; i < len; ++i) {
                        ir_node *pred = get_Block_cfgpred_block(blk, i);
-                       reg->pred[j++] = get_irn_link(pred);
+                       reg->pred[j++] = (ir_region*) get_irn_link(pred);
                }
                ARR_SHRINKLEN(reg->pred, j);
        }
@@ -289,7 +289,7 @@ static void update_BasicBlock_regions(ir_node *blk, void *ctx)
        reg->succ = NEW_ARR_D(ir_region *, env->obst, len);
        for (i = j = 0; i < len; ++i) {
                ir_node *succ = get_Block_cfg_out(blk, i);
-               reg->succ[j++] = get_irn_link(succ);
+               reg->succ[j++] = (ir_region*) get_irn_link(succ);
        }
        ARR_SHRINKLEN(reg->succ, j);
 }  /* update_BasicBlock_regions */
@@ -327,7 +327,7 @@ static ir_region *new_Sequence(struct obstack *obst, ir_region *nset, int nset_l
                nset = next;
                reg->parts[i].region = nset;
                nset->parent = reg;
-               next = nset->link;
+               next = (ir_region*) nset->link;
                nset->link = NULL;
        }
 
@@ -396,13 +396,14 @@ static ir_region *new_IfThen(struct obstack *obst, ir_region *if_b, ir_region *t
  * Create a new Switch/case region.
  */
 static ir_region *new_SwitchCase(struct obstack *obst, ir_region_kind type, ir_region *head, ir_region *exit,
-                                 ir_region *cases, int cases_len) {
+                                 ir_region *cases, int cases_len)
+{
        ir_region *reg, *c, *n;
        int i;
        int add = 1;
 
        /* check, if the exit block is in the list */
-       for (c = cases; c != NULL; c = c->link) {
+       for (c = cases; c != NULL; c = (ir_region*) c->link) {
                if (c == exit) {
                        add = 0;
                        break;
@@ -417,7 +418,7 @@ static ir_region *new_SwitchCase(struct obstack *obst, ir_region_kind type, ir_r
        reg->parts[0].region = head; head->parent = reg;
        i = 1;
        for (c = cases; c != NULL; c = n) {
-               n = c->link;
+               n = (ir_region*) c->link;
                if (c != exit) {
                        reg->parts[i++].region = c;
                        c->parent = reg;
@@ -513,7 +514,7 @@ static ir_region *new_RepeatLoop(struct obstack *obst, ir_region *head, ir_regio
 static ir_region *new_WhileLoop(struct obstack *obst, ir_region *head)
 {
        ir_region *reg, *succ;
-       ir_region *body = head->link;
+       ir_region *body = (ir_region*) head->link;
        int i, j, len;
 
        head->link = NULL;
@@ -558,7 +559,7 @@ static ir_region *new_NaturalLoop(struct obstack *obst, ir_region *head)
        int i, j, k, len, n_pred, n_succ;
 
        /* count number of parts */
-       for (len = 0, c = head; c != NULL; c = c->link)
+       for (len = 0, c = head; c != NULL; c = (ir_region*) c->link)
                ++len;
 
        ALLOC_REG(obst, reg, ir_rk_WhileLoop);
@@ -570,7 +571,7 @@ static ir_region *new_NaturalLoop(struct obstack *obst, ir_region *head)
        for (i = 0, c = head; c != NULL; c = n) {
                reg->parts[i++].region = c;
                c->parent = reg;
-               n = c->link;
+               n = (ir_region*) c->link;
                c->link = NULL;
        }
 
@@ -591,9 +592,9 @@ static ir_region *new_NaturalLoop(struct obstack *obst, ir_region *head)
        /* count number of succs */
        n_succ = 0;
        for (j = 0; j < len; ++j) {
-               ir_region *c = reg->parts[j].region;
-               for (i = get_region_n_succs(c) - 1; i >= 0; --i) {
-                       ir_region *succ = get_region_succ(c, i);
+               ir_region *pc = reg->parts[j].region;
+               for (i = get_region_n_succs(pc) - 1; i >= 0; --i) {
+                       ir_region *succ = get_region_succ(pc, i);
                        if (succ->parent != reg)
                                ++n_succ;
                }
@@ -601,9 +602,9 @@ static ir_region *new_NaturalLoop(struct obstack *obst, ir_region *head)
        reg->succ = NEW_ARR_D(ir_region *, obst, n_succ);
        k = 0;
        for (j = 0; j < len; ++j) {
-               ir_region *c = reg->parts[j].region;
-               for (i = get_region_n_succs(c) - 1; i >= 0; --i) {
-                       ir_region *succ = get_region_succ(c, i);
+               ir_region *pc = reg->parts[j].region;
+               for (i = get_region_n_succs(pc) - 1; i >= 0; --i) {
+                       ir_region *succ = get_region_succ(pc, i);
                        if (succ->parent != reg)
                                reg->succ[k++] = succ;
                }
@@ -661,7 +662,7 @@ static struct ir_region *reverse_list(ir_region *n)
        ir_region *prev = NULL, *next;
 
        for (; n; n = next) {
-               next = n->link;
+               next = (ir_region*) n->link;
                n->link = prev;
                prev = n;
        }
@@ -702,8 +703,8 @@ static ir_region *find_cyclic_region(ir_region *node)
                                }
                        }
                        /* reverse the list. */
-                       last = rem->link;
-                       rem->link = reverse_list(rem->link);
+                       last = (ir_region*) rem->link;
+                       rem->link = reverse_list((ir_region*) rem->link);
                }
        }
 
@@ -736,7 +737,7 @@ static ir_region *cyclic_region_type(struct obstack *obst, ir_region *node)
        list = find_cyclic_region(node);
 
        if (list->link) {
-               if (!LINK(list)->link && get_region_n_succs(list->link) == 1) {
+               if (!LINK(list)->link && get_region_n_succs((ir_region*) list->link) == 1) {
                        /* only one body block with only one successor (the head) */
                        return new_WhileLoop(obst, list);
                }
@@ -755,7 +756,7 @@ static void clear_list(ir_region *list)
        ir_region *next;
 
        for (next = list; next; list = next) {
-               next = list->link;
+               next = (ir_region*) list->link;
                list->link = NULL;
        }
 }
@@ -842,7 +843,7 @@ static ir_region *acyclic_region_type(struct obstack *obst, ir_region *node)
        }
        /* check for Switch, case */
        if (k > 0) {
-               ir_region *exit = NULL;
+               ir_region *rexit = NULL;
                nset = NULL; nset_len = 0;
                p = 0;
                for (i = k - 1; i >= 0; --i) {
@@ -850,7 +851,7 @@ static ir_region *acyclic_region_type(struct obstack *obst, ir_region *node)
                        ADD_LIST(nset, n);
                        if (get_region_n_succs(n) != 1) {
                                /* must be the exit */
-                               exit = n;
+                               rexit = n;
                                ++p;
                                if (p > 1)
                                        break;
@@ -862,25 +863,25 @@ static ir_region *acyclic_region_type(struct obstack *obst, ir_region *node)
                        ir_region *pos_exit_2 = NULL;
 
                        /* find the exit */
-                       for (m = nset; m != NULL; m = m->link) {
+                       for (m = (ir_region*) nset; m != NULL; m = (ir_region*) m->link) {
                                if (get_region_n_succs(m) != 1) {
                                        /* must be the exit block */
-                                       if (exit == NULL) {
-                                               exit = m;
-                                       } else if (exit != m) {
+                                       if (rexit == NULL) {
+                                               rexit = m;
+                                       } else if (rexit != m) {
                                                /* two exits */
-                                               exit = NULL;
+                                               rexit = NULL;
                                                break;
                                        }
                                } else {
                                        ir_region *succ = get_region_succ(m, 0);
 
                                        if (succ->link == NULL) {
-                                               if (exit == NULL) {
+                                               if (rexit == NULL) {
                                                        if (succ == pos_exit_1)
-                                                               exit = succ;
+                                                               rexit = succ;
                                                        else if (succ == pos_exit_2)
-                                                               exit = succ;
+                                                               rexit = succ;
                                                        else if (pos_exit_1 == NULL)
                                                                pos_exit_1 = succ;
                                                        else if (pos_exit_2 == NULL)
@@ -889,24 +890,24 @@ static ir_region *acyclic_region_type(struct obstack *obst, ir_region *node)
                                                                /* more than two possible exits */
                                                                break;
                                                        }
-                                               } else if (exit != succ) {
+                                               } else if (rexit != succ) {
                                                        /* two exits */
-                                                       exit = NULL;
+                                                       rexit = NULL;
                                                        break;
                                                }
                                        }
                                }
                        }
-                       if (exit != NULL) {
+                       if (rexit != NULL) {
                                /* do the checks */
-                               for (n = nset; n != NULL; n = n->link) {
+                               for (n = (ir_region*) nset; n != NULL; n = (ir_region*) n->link) {
                                        ir_region *succ;
-                                       if (n == exit) {
+                                       if (n == rexit) {
                                                /* good, default fall through */
                                                continue;
                                        }
                                        succ = get_region_succ(n, 0);
-                                       if (succ == exit) {
+                                       if (succ == rexit) {
                                                /* good, switch to exit */
                                                continue;
                                        }
@@ -921,7 +922,7 @@ static ir_region *acyclic_region_type(struct obstack *obst, ir_region *node)
 
                                if (n == NULL) {
                                        /* detected */
-                                       return new_SwitchCase(obst, kind, node, exit, nset, nset_len);
+                                       return new_SwitchCase(obst, kind, node, rexit, nset, nset_len);
                                }
                        }
                }
@@ -1046,8 +1047,6 @@ ir_reg_tree *construct_region_tree(ir_graph *irg)
 
        DB((dbg, LEVEL_1, "Structural analysis on %+F starts...\n", irg));
 
-       dump_ir_block_graph(irg, "-structure_start");
-
        /* we need dominance info */
        assure_doms(irg);
        /* and out edges */