added test whether constant entity belongs to description. if so the
[libfirm] / ir / tr / typewalk.c
index ba91689..8291cb4 100644 (file)
@@ -1,12 +1,12 @@
 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-** All rights reserved.
-**
-** Author: Goetz Lindenmaier
-**
-** traverse the type information.  The walker walks the whole ir graph
-** to find the distinct type trees in the type graph forest.
-** - execute the pre function before recursion
-** - execute the post function after recursion
+* All rights reserved.
+*
+* Author: Goetz Lindenmaier
+*
+* traverse the type information.  The walker walks the whole ir graph
+* to find the distinct type trees in the type graph forest.
+* - execute the pre function before recursion
+* - execute the post function after recursion
 */
 
 /* $Id$ */
@@ -35,9 +35,9 @@ typedef struct type_walk_env {
 } type_walk_env;
 
 
-void type_walk_2(type_or_ent *tore,
-              void (pre)(type_or_ent*, void*),
-              void (post)(type_or_ent*, void*),
+static void type_walk_2(type_or_ent *tore,
+              void (*pre)(type_or_ent*, void*),
+              void (*post)(type_or_ent*, void*),
               void *env)
 {
   int i;
@@ -142,7 +142,9 @@ void type_walk_2(type_or_ent *tore,
   return;
 }
 
-void start_type_walk(ir_node *node, void *env) {
+/**  Check wether node contains types or entities as an attribute.
+     If so start a walk over that information. */
+static void start_type_walk(ir_node *node, void *env) {
   void *pre  = ((type_walk_env *)env)->pre;
   void *post = ((type_walk_env *)env)->post;
   void *envi = ((type_walk_env *)env)->env;
@@ -186,31 +188,45 @@ void type_walk(void (pre)(type_or_ent*, void*),
 }
 
 void type_walk_irg (ir_graph *irg,
-                   void (pre)(type_or_ent*, void*),
-                   void (post)(type_or_ent*, void*),
+                   void (*pre)(type_or_ent*, void*),
+                   void (*post)(type_or_ent*, void*),
                    void *env)
 {
+  ir_graph *rem = current_ir_graph;
   /* this is needed to pass the parameters to the walker that actually
      walks the type information */
-  type_walk_env* type_env;
-  type_env = (type_walk_env *) malloc (sizeof(type_walk_env));
-  type_env->pre = pre;
-  type_env->post = post;
-  type_env->env = env;
-
+  type_walk_env type_env;
+
+  type_env.pre  = pre;
+  type_env.post = post;
+  type_env.env  = env;
+
+  current_ir_graph = irg;
+
+  /* We walk over the irg to find all irnodes that contain an attribute
+     with type information.  If we find one we call a type walker to
+     touch the reachable type information.
+     The same type can be referenced by several irnodes.  To avoid
+     repeated visits of the same type node we must decrease the
+     type visited flag for each walk.  This is done in start_type_walk().
+     Here we initially increase the flag.  We only call type_walk_2 that does
+     not increase the flag.
+  */
   ++type_visited;
-  irg_walk(get_irg_end(irg), start_type_walk, NULL, type_env);
+  irg_walk(get_irg_end(irg), start_type_walk, NULL, &type_env);
 
   type_walk_2((type_or_ent *)get_irg_ent(irg), pre, post, env);
 
-  free(type_env);
+  type_walk_2((type_or_ent *)get_irg_frame_type(irg), pre, post, env);
+
+  current_ir_graph = rem;
   return;
 }
 
-void type_walk_s2s_2(type_or_ent *tore,
-                    void (pre)(type_or_ent*, void*),
-                    void (post)(type_or_ent*, void*),
-                    void *env)
+static void type_walk_s2s_2(type_or_ent *tore,
+                           void (*pre)(type_or_ent*, void*),
+                           void (*post)(type_or_ent*, void*),
+                           void *env)
 {
   int i;
 
@@ -283,9 +299,11 @@ void type_walk_s2s_2(type_or_ent *tore,
   return;
 }
 
-void type_walk_super2sub(void (pre)(type_or_ent*, void*),
-                        void (post)(type_or_ent*, void*),
-                        void *env) {
+void type_walk_super2sub(
+                 void (*pre)(type_or_ent*, void*),
+                 void (*post)(type_or_ent*, void*),
+                 void *env)
+{
   int i;
   type *tp;
   ++type_visited;
@@ -298,11 +316,11 @@ void type_walk_super2sub(void (pre)(type_or_ent*, void*),
 
 /*****************************************************************************/
 
-static
-void type_walk_super_2(type_or_ent *tore,
-                      void (pre)(type_or_ent*, void*),
-                      void (post)(type_or_ent*, void*),
-                      void *env)
+static void
+type_walk_super_2(type_or_ent *tore,
+                 void (*pre)(type_or_ent*, void*),
+                 void (*post)(type_or_ent*, void*),
+                 void *env)
 {
   int i;
 
@@ -371,9 +389,10 @@ void type_walk_super_2(type_or_ent *tore,
   return;
 }
 
-void type_walk_super(void (pre)(type_or_ent*, void*),
-                    void (post)(type_or_ent*, void*),
-                    void *env) {
+void type_walk_super(
+                 void (*pre)(type_or_ent*, void*),
+                 void (*post)(type_or_ent*, void*),
+                 void *env) {
   int i;
   type *tp;
   ++type_visited;
@@ -387,10 +406,11 @@ void type_walk_super(void (pre)(type_or_ent*, void*),
 /*****************************************************************************/
 
 
-void class_walk_s2s_2(type *tp,
-                    void (pre)(type*, void*),
-                    void (post)(type*, void*),
-                    void *env)
+static void
+class_walk_s2s_2(type *tp,
+                void (*pre)(type*, void*),
+                void (*post)(type*, void*),
+                void *env)
 {
   int i;
 
@@ -422,9 +442,11 @@ void class_walk_s2s_2(type *tp,
 }
 
 #if 0
-void class_walk_super2sub(void (pre)(type*, void*),
-                         void (post)(type*, void*),
-                         void *env) {
+void class_walk_super2sub(
+                 void (*pre)(type*, void*),
+                 void (*post)(type*, void*),
+                 void *env)
+{
   int i;
   type *tp;
 
@@ -441,9 +463,11 @@ void class_walk_super2sub(void (pre)(type*, void*),
   }
 }
 #endif
-void class_walk_super2sub(void (pre)(type*, void*),
-                         void (post)(type*, void*),
-                         void *env) {
+void class_walk_super2sub(
+                 void (*pre)(type*, void*),
+                 void (post)(type*, void*),
+                 void *env)
+{
   int i;
   type *tp;
 
@@ -462,9 +486,11 @@ void class_walk_super2sub(void (pre)(type*, void*),
 
 
 /* Walks over all entities in the type */
-void walk_types_entities(type *tp,
-                        void (doit)(entity*, void*),
-                        void *env) {
+void walk_types_entities(
+                 type *tp,
+                 void (*doit)(entity*, void*),
+                 void *env)
+{
   int i;
   switch(get_type_tpop_code(tp)) {
   case tpo_class: {