some fixes for xml dumper / still buggy.
[libfirm] / ir / ir / irgwalk.c
index 7221ba3..5b10162 100644 (file)
@@ -1,11 +1,11 @@
 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-** All rights reserved.
-**
-** Author: Boris Boesler
-**
-** traverse an ir graph
-** - execute the pre function before recursion
-** - execute the post function after recursion
+* All rights reserved.
+*
+* Author: Boris Boesler
+*
+* traverse an ir graph
+* - execute the pre function before recursion
+* - execute the post function after recursion
 */
 
 /* $Id$ */
 
 # include <stdlib.h>
 
-# include "irnode.h"
+# include "irnode_t.h"
 # include "irgraph.h" /* visited flag */
 # include "irprog.h"
 # include "irgwalk.h"
+# include "typewalk.h"
 
 # include "eset.h"
 # include "array.h"
 
 /* walk over an interprocedural graph (callgraph). Visits only graphs in irg_set. */
 static void irg_walk_cg(ir_node * node, int visited, eset * irg_set,
-                       irg_walk_func pre, irg_walk_func post, void * env) {
+                       irg_walk_func *pre, irg_walk_func *post, void * env) {
   int i;
   ir_graph * rem = current_ir_graph;
   ir_node * pred;
 
-  assert(node);
+  assert(node && node->kind==k_ir_node);
   if (get_irn_visited(node) >= visited) return;
 
   set_irn_visited(node, visited);
@@ -98,16 +99,17 @@ static void collect_irgs(ir_node * node, eset * irg_set) {
       ir_graph * irg = ent ? get_entity_irg(ent) : NULL;
       if (irg && !eset_contains(irg_set, irg)) {
        eset_insert(irg_set, irg);
-       irg_walk_graph(irg, (irg_walk_func) collect_irgs, NULL, irg_set);
+       irg_walk_graph(irg, (irg_walk_func *) collect_irgs, NULL, irg_set);
       }
     }
   }
 }
 
-void irg_walk_2(ir_node *node, irg_walk_func pre, irg_walk_func post, void * env)
+static void
+irg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
 {
   int i;
-  assert(node);
+  assert(node && node->kind==k_ir_node);
 
   if (get_irn_visited(node) < get_irg_visited(current_ir_graph)) {
     set_irn_visited(node, get_irg_visited(current_ir_graph));
@@ -125,16 +127,16 @@ void irg_walk_2(ir_node *node, irg_walk_func pre, irg_walk_func post, void * env
 }
 
 
-void irg_walk(ir_node *node, irg_walk_func pre, irg_walk_func post, void *env)
+void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
 {
-  assert(node);
+  assert(node  && node->kind==k_ir_node);
   if (interprocedural_view) {
     eset * irg_set = eset_create();
     int visited;
     ir_graph * irg;
     interprocedural_view = false;
     eset_insert(irg_set, current_ir_graph);
-    irg_walk(node, (irg_walk_func) collect_irgs, NULL, irg_set);
+    irg_walk(node, (irg_walk_func *) collect_irgs, NULL, irg_set);
     interprocedural_view = true;
     visited = get_max_irg_visited() + 1;
     irg_walk_cg(node, visited, irg_set, pre, post, env);
@@ -150,7 +152,7 @@ void irg_walk(ir_node *node, irg_walk_func pre, irg_walk_func post, void *env)
 }
 
 
-void irg_walk_graph(ir_graph *irg, irg_walk_func pre, irg_walk_func post, void *env) {
+void irg_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env) {
   ir_graph * rem = current_ir_graph;
   current_ir_graph = irg;
   irg_walk(get_irg_end(irg), pre, post, env);
@@ -160,7 +162,7 @@ void irg_walk_graph(ir_graph *irg, irg_walk_func pre, irg_walk_func post, void *
 /* Executes irg_walk(end, pre, post, env) for all irgraphs in irprog.
    Sets current_ir_graph properly for each walk.  Conserves current
    current_ir_graph. */
-void all_irg_walk(irg_walk_func pre, irg_walk_func post, void *env) {
+void all_irg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) {
   int i;
   ir_graph *irg, *rem;
 
@@ -197,7 +199,8 @@ switch_irg (ir_node *n, int index) {
   return old_current;
 }
 
-void cg_walk_2(ir_node *node, irg_walk_func pre, irg_walk_func post, void * env)
+static void
+cg_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void * env)
 {
   int i;
   ir_graph *rem = NULL;
@@ -223,7 +226,7 @@ void cg_walk_2(ir_node *node, irg_walk_func pre, irg_walk_func post, void * env)
 
 
 /* Walks all irgs in interprocedural view.  Visits each node only once. */
-void cg_walk(irg_walk_func pre, irg_walk_func post, void *env) {
+void cg_walk(irg_walk_func *pre, irg_walk_func *post, void *env) {
   int i;
   ir_graph *rem = current_ir_graph;
   int rem_view = interprocedural_view;
@@ -255,7 +258,7 @@ void cg_walk(irg_walk_func pre, irg_walk_func post, void *env) {
 /***************************************************************************/
 
 /* Walks back from n until it finds a real cf op. */
-ir_node *get_cf_op(ir_node *n) {
+static ir_node *get_cf_op(ir_node *n) {
   ir_node *pred;
 
   n = skip_nop(n);
@@ -268,7 +271,7 @@ ir_node *get_cf_op(ir_node *n) {
   return skip_Proj(n);
 }
 
-void irg_block_walk_2(ir_node *node, irg_walk_func pre, irg_walk_func post, void *env)
+static void irg_block_walk_2(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
 {
   int i;
   assert(get_irn_opcode(node) == iro_Block);
@@ -299,7 +302,7 @@ void irg_block_walk_2(ir_node *node, irg_walk_func pre, irg_walk_func post, void
 
 /* walks only over Block nodes in the graph.  Has it's own visited
    flag, so that it can be interleaved with the other walker.         */
-void irg_block_walk(ir_node *node, irg_walk_func pre, irg_walk_func post, void *env)
+void irg_block_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
 {
   ir_node *block, *pred;
   int i;
@@ -323,8 +326,8 @@ void irg_block_walk(ir_node *node, irg_walk_func pre, irg_walk_func post, void *
 }
 
 
-void irg_block_walk_graph(ir_graph *irg, irg_walk_func pre,
-                         irg_walk_func post, void *env) {
+void irg_block_walk_graph(ir_graph *irg, irg_walk_func *pre,
+                         irg_walk_func *post, void *env) {
   ir_graph * rem = current_ir_graph;
   current_ir_graph = irg;
   irg_block_walk(get_irg_end(irg), pre, post, env);
@@ -334,13 +337,13 @@ void irg_block_walk_graph(ir_graph *irg, irg_walk_func pre,
 /********************************************************************/
 
 typedef struct walk_env {
-  void *pre;
-  void *post;
+  irg_walk_func *pre;
+  irg_walk_func *post;
   void *env;
 } walk_env;
 
 /* Walk to all constant expressions in this entity. */
-void walk_entity(entity *ent, void *env) {
+static void walk_entity(entity *ent, void *env) {
   walk_env *my_env = (walk_env *)env;
   if (get_entity_variability(ent) != uninitialized) {
     if (is_atomic_entity(ent)) {
@@ -355,7 +358,7 @@ void walk_entity(entity *ent, void *env) {
 }
 
 /* Walks over all code in const_code_irg. */
-void walk_const_code(irg_walk_func pre, irg_walk_func post, void *env) {
+void walk_const_code(irg_walk_func *pre, irg_walk_func *post, void *env) {
   int i, j;
   walk_env my_env;
 
@@ -368,11 +371,11 @@ void walk_const_code(irg_walk_func pre, irg_walk_func post, void *env) {
   my_env.env = env;
 
   /* Walk all types that can contain constant entities.  */
-  walk_types_entities(get_glob_type(), &walk_entity, &env);
+  walk_types_entities(get_glob_type(), &walk_entity, &my_env);
   for (i = 0; i < get_irp_n_types(); i++)
-    walk_types_entities(get_irp_type(i), &walk_entity, &env);
+    walk_types_entities(get_irp_type(i), &walk_entity, &my_env);
   for (i = 0; i < get_irp_n_irgs(); i++)
-    walk_types_entities(get_irg_frame_type(get_irp_irg(i)), &walk_entity, &env);
+    walk_types_entities(get_irg_frame_type(get_irp_irg(i)), &walk_entity, &my_env);
 
   /* Walk constant array bounds. */
   for (i = 0; i < get_irp_n_types(); i++) {
@@ -422,11 +425,6 @@ void walk_const_code(irg_walk_func pre, irg_walk_func post, void *env) {
 /** }                                                              **/
 /********************************************************************/
 
-/* Allocates some necessary datastructures. */
-void init_ip_walk ();
-/* Frees some necessary datastructures. */
-void finish_ip_walk();
-
 /* Call for i in {0|-1 ... get_irn_arity(n)}.
    If n is a conventional node returns the same node as get_irn_n(n, i).
    If the predecessors of n are in the callee of the procedure n belongs
@@ -513,13 +511,13 @@ ir_node * pop_callsite(ir_graph *callee) {
 
 /* Initialization routines ******************************************/
 
-void init_ip_walk () {
+void init_ip_walk (void) {
   int i;
   for (i = 0; i < get_irp_n_irgs(); i++)
     new_callsite_stack(get_irp_irg(i));
 }
 
-void finish_ip_walk() {
+void finish_ip_walk(void) {
   int i;
   for (i = 0; i < get_irp_n_irgs(); i++)
     free_callsite_stack(get_irp_irg(i));