backend_marked was a buggy/wrong concept, removed it
[libfirm] / ir / tr / typewalk.c
index 6369474..3a545b6 100644 (file)
  * @brief   Functionality to modify the type graph.
  * @author  Goetz Lindenmaier
  * @version $Id$
- * @summary
+ * @brief
  *
  * 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
  */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
+#include "config.h"
 
+#include <stdlib.h>
 #include <stdio.h>
 
 #include "entity_t.h"
@@ -107,11 +102,13 @@ static void do_type_walk(type_or_ent tore,
                ent = tore.ent;
                if (entity_visited(ent))
                        return;
+               mark_entity_visited(ent);
                break;
        case k_type:
-               tp = skip_tid(tore.typ);
+               tp = tore.typ;
                if (type_visited(tp))
                        return;
+               mark_type_visited(tp);
                break;
        default:
                break;
@@ -124,32 +121,24 @@ static void do_type_walk(type_or_ent tore,
        /* iterate */
        switch (get_kind(tore.ent)) {
        case k_entity:
-               mark_entity_visited(ent);
                cont.typ = get_entity_owner(ent);
                do_type_walk(cont, pre, post, env);
                cont.typ = get_entity_type(ent);
                do_type_walk(cont, pre, post, env);
 
-               if (get_entity_variability(ent) != variability_uninitialized) {
-                       /* walk over the value types */
-                       if (ent->has_initializer) {
-                               walk_initializer(ent->attr.initializer, pre, post, env);
-                       } else if (is_atomic_entity(ent)) {
-                               n = get_atomic_ent_value(ent);
+               /* walk over the value types */
+               if (ent->initializer != NULL) {
+                       walk_initializer(ent->initializer, pre, post, env);
+               } else if (entity_has_compound_ent_values(ent)) {
+                       n_mem = get_compound_ent_n_values(ent);
+                       for (i = 0; i < n_mem; ++i) {
+                               n = get_compound_ent_value(ent, i);
                                irn_type_walker(n, pre, post, env);
-                       } else {
-                               n_mem = get_compound_ent_n_values(ent);
-                               for (i = 0; i < n_mem; ++i) {
-                                       n = get_compound_ent_value(ent, i);
-                                       irn_type_walker(n, pre, post, env);
-                               }
                        }
                }
                break;
        case k_type:
-               mark_type_visited(tp);
                switch (get_type_tpop_code(tp)) {
-
                case tpo_class:
                        n_types = get_class_n_supertypes(tp);
                        for (i = 0; i < n_types; ++i) {
@@ -213,13 +202,13 @@ static void do_type_walk(type_or_ent tore,
                        do_type_walk(cont, pre, post, env);
                        break;
 
+               case tpo_code:
                case tpo_primitive:
-               case tpo_id:
                case tpo_none:
                case tpo_unknown:
                        /* a leave. */
                        break;
-               default:
+               case tpo_uninitialized:
                        assert(0 && "Faulty type");
                        break;
                }
@@ -233,8 +222,6 @@ static void do_type_walk(type_or_ent tore,
        /* execute post method */
        if (post)
                post(tore, env);
-
-       return;
 }
 
 /**  Check whether node contains types or entities as an attribute.
@@ -283,6 +270,29 @@ void type_walk(type_walk_func *pre, type_walk_func *post, void *env) {
        do_type_walk(cont, pre, post, env);
 }
 
+void type_walk_prog(type_walk_func *pre, type_walk_func *post, void *env) {
+       int i, n_irgs = get_irp_n_irgs();
+       type_or_ent cont;
+
+       type_walk(pre, post, env);
+
+       for (i = 0; i < n_irgs; ++i) {
+               ir_graph *irg = get_irp_irg(i);
+               cont.typ = get_irg_frame_type(irg);
+               do_type_walk(cont, pre, post, env);
+
+               cont.typ = get_method_value_param_type(get_entity_type(get_irg_entity(irg)));
+               if(cont.typ)
+                       do_type_walk(cont, pre, post, env);
+       }
+
+       for (i = IR_SEGMENT_FIRST; i <= IR_SEGMENT_LAST; ++i) {
+               cont.typ = get_segment_type((ir_segment_t) i);
+               if(cont.typ)
+                       do_type_walk(cont, pre, post, env);
+       }
+}
+
 void type_walk_irg(ir_graph *irg,
                    type_walk_func *pre,
                    type_walk_func *post,
@@ -319,7 +329,6 @@ void type_walk_irg(ir_graph *irg,
        do_type_walk(cont, pre, post, env);
 
        current_ir_graph = rem;
-       return;
 }
 
 static void type_walk_s2s_2(type_or_ent tore,
@@ -336,11 +345,6 @@ static void type_walk_s2s_2(type_or_ent tore,
                if (entity_visited(tore.ent)) return;
                break;
        case k_type:
-               if (type_id == get_type_tpop(tore.typ)) {
-                       cont.typ = skip_tid(tore.typ);
-                       type_walk_s2s_2(cont, pre, post, env);
-                       return;
-               }
                if (type_visited(tore.typ)) return;
                break;
        default:
@@ -364,7 +368,6 @@ static void type_walk_s2s_2(type_or_ent tore,
                                        /* execute pre method */
                                        if (pre)
                                                pre(tore, env);
-                                       tp = skip_tid(tp);
 
                                        n = get_class_n_subtypes(tp);
                                        for (i = 0; i < n; ++i) {
@@ -384,7 +387,6 @@ static void type_walk_s2s_2(type_or_ent tore,
                        case tpo_enumeration:
                        case tpo_pointer:
                        case tpo_primitive:
-                       case tpo_id:
                                /* dont care */
                                break;
                        default:
@@ -399,7 +401,6 @@ static void type_walk_s2s_2(type_or_ent tore,
                printf(" *** Faulty type or entity! \n");
                break;
        }
-       return;
 }
 
 void type_walk_super2sub(type_walk_func *pre,
@@ -435,11 +436,6 @@ type_walk_super_2(type_or_ent tore,
                        return;
                break;
        case k_type:
-               if (type_id == get_type_tpop(tore.typ)) {
-                       cont.typ = skip_tid(tore.typ);
-                       type_walk_super_2(cont, pre, post, env);
-                       return;
-               }
                if (type_visited(tore.typ))
                        return;
                break;
@@ -459,7 +455,6 @@ type_walk_super_2(type_or_ent tore,
                                        /* execute pre method */
                                        if (pre)
                                                pre(tore, env);
-                                       tp = skip_tid(tp);
 
                                        n = get_class_n_supertypes(tp);
                                        for (i = 0; i < n; ++i) {
@@ -479,7 +474,6 @@ type_walk_super_2(type_or_ent tore,
                        case tpo_enumeration:
                        case tpo_pointer:
                        case tpo_primitive:
-                       case tpo_id:
                                /* don't care */
                                break;
                        default:
@@ -494,7 +488,6 @@ type_walk_super_2(type_or_ent tore,
                printf(" *** Faulty type or entity! \n");
                break;
        }
-       return;
 }
 
 void type_walk_super(type_walk_func *pre,
@@ -540,7 +533,6 @@ class_walk_s2s_2(ir_type *tp,
        if (pre)
                pre(tp, env);
 
-       tp = skip_tid(tp);
        n = get_class_n_subtypes(tp);
        for (i = 0; i < n; ++i) {
                class_walk_s2s_2(get_class_subtype(tp, i), pre, post, env);
@@ -548,8 +540,6 @@ class_walk_s2s_2(ir_type *tp,
        /* execute post method */
        if (post)
                post(tp, env);
-
-       return;
 }
 
 void class_walk_super2sub(class_walk_func *pre,
@@ -603,7 +593,6 @@ void walk_types_entities(ir_type *tp,
        case tpo_enumeration:
        case tpo_pointer:
        case tpo_primitive:
-       case tpo_id:
        default:
                break;
        }