added tpop flags
[libfirm] / ir / ana / cgana.c
index 3748b42..ae09efc 100644 (file)
  *
  */
 #ifdef HAVE_CONFIG_H
-# include <config.h>
+# include "config.h"
+#endif
+
+#ifdef HAVE_STRING_H
+# include <string.h>
 #endif
 
-#include <stdlib.h>
 #include "cgana.h"
 #include "rta.h"
 
+#include "xmalloc.h"
 #include "irnode_t.h"
 #include "irmode_t.h"
 #include "irprog_t.h"
@@ -133,6 +137,8 @@ static entity *get_inherited_methods_implementation(entity *inh_meth) {
  */
 static void collect_impls(entity *method, eset *set, int *size, bool *open) {
   int i;
+  entity *impl;
+
 #if 0
   if (get_entity_peculiarity(method) == peculiarity_existent) {
     if ((get_entity_visibility(method) == visibility_external_allocated)
@@ -184,13 +190,13 @@ static void collect_impls(entity *method, eset *set, int *size, bool *open) {
      remember that there are more methods called. */
   /* @@@ We could also add unknown_entity, or the entities with the
      unknown irgs.  The first case would result in the exact same
-     behaviour: all unknown irgs are represented by the one and only
+     behavior: all unknown irgs are represented by the one and only
      unknown entity. If we add all entities, we known the number of
      entities possibly called, and whether there are real unknown
      entities, i.e, such not represented in the type description.
-     This would be better for an analyses: it could rule out more
+     This would be better for an analysis: it could rule out more
      cases. */
-  entity *impl = method;
+  impl = method;
   if (get_entity_peculiarity(method) == peculiarity_inherited)
     impl = get_inherited_methods_implementation(method);
 
@@ -249,7 +255,7 @@ static entity ** get_impl_methods(entity * method) {
   return arr;
 }
 
-/** Analyse address computations.
+/** Analyze address computations.
  *
  *  - If the node is a SymConst(name) replace it by SymConst(ent) if possible.
  *  - If the node is a Sel:
@@ -268,17 +274,19 @@ static void sel_methods_walker(ir_node * node, void *env) {
     if (get_SymConst_kind(node) == symconst_addr_name) {
       pmap_entry * entry = pmap_find(ldname_map, (void *) get_SymConst_name(node));
       if (entry != NULL) { /* Method is declared in the compiled code */
-       entity * ent = entry->value;
-       if (get_opt_normalize() && (get_entity_visibility(ent) != visibility_external_allocated)) { /* Meth. is defined */
-         set_irg_current_block(current_ir_graph, get_nodes_block(node));
-         ir_node *new_node = copy_const_value(get_atomic_ent_value(ent));
+           entity * ent = entry->value;
+           if (get_opt_normalize() && (get_entity_visibility(ent) != visibility_external_allocated)) { /* Meth. is defined */
+          ir_node *new_node;
+
+             set_irg_current_block(current_ir_graph, get_nodes_block(node));
+             new_node = copy_const_value(get_atomic_ent_value(ent));
 
-         DBG_OPT_CSTEVAL(node, new_node);
+             DBG_OPT_CSTEVAL(node, new_node);
 
-         assert(get_entity_irg(ent));
-         DDMN(new_node);
-         exchange(node, new_node);
-       }
+             assert(get_entity_irg(ent));
+             DDMN(new_node);
+             exchange(node, new_node);
+           }
       }
     }
   }
@@ -319,10 +327,10 @@ static void sel_methods_walker(ir_node * node, void *env) {
         /* Gib eine Warnung aus wenn die Entitaet eine Beschreibung ist
            fuer die es keine Implementierung gibt. */
         if (get_entity_peculiarity(ent) == peculiarity_description) {
-         /* This is possible:  We call a method in a dead part of the program. */
+          /* This is possible:  We call a method in a dead part of the program. */
         } else {
-         DDMN(node);
-         assert(0);  /* Why should this happen ??? */
+             DDMN(node);
+             assert(0);  /* Why should this happen ??? */
           //exchange(node, new_Bad());
         }
       } else {
@@ -369,9 +377,10 @@ static void sel_methods_init(void) {
 
   assert(entities == NULL);
   entities = eset_create();
-  for (i = get_irp_n_allirgs() - 1; i >= 0; --i) {
-    entity * ent = get_irg_entity(get_irp_allirg(i));
-    /* Nur extern sichtbare Methode können überhaupt mit SymConst
+  for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+    ir_graph *irg = get_irp_irg(i);
+    entity * ent = get_irg_entity(irg);
+    /* Nur extern sichtbare Methoden können überhaupt mit SymConst
      * aufgerufen werden. */
     if (get_entity_visibility(ent) != visibility_local) {
       pmap_insert(ldname_map, (void *) get_entity_ld_ident(ent), ent);
@@ -623,9 +632,9 @@ static void remove_Tuples(ir_node * proj, void * env) {
 static void callee_ana(void) {
   int i;
   /* Alle Graphen analysieren. */
-  for (i = get_irp_n_allirgs() - 1; i >= 0; --i) {
-    irg_walk_graph(get_irp_allirg(i), callee_walker, remove_Tuples, NULL);
-    set_irg_callee_info_state(get_irp_allirg(i), irg_callee_info_consistent);
+  for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+    irg_walk_graph(get_irp_irg(i), callee_walker, remove_Tuples, NULL);
+    set_irg_callee_info_state(get_irp_irg(i), irg_callee_info_consistent);
   }
   set_irp_callee_info_state(irg_callee_info_consistent);
 }
@@ -785,8 +794,8 @@ static entity ** get_free_methods(void)
   entity ** arr = NEW_ARR_F(entity *, 0);
   entity * ent;
 
-  for (i = get_irp_n_allirgs() - 1; i >= 0; --i) {
-    ir_graph * irg = get_irp_allirg(i);
+  for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+    ir_graph * irg = get_irp_irg(i);
     entity * ent = get_irg_entity(irg);
     /* insert "external visible" methods. */
     if (get_entity_visibility(ent) != visibility_local) {
@@ -798,8 +807,8 @@ static entity ** get_free_methods(void)
   }
 
   /* insert sticky methods, too */
-  for (i = get_irp_n_allirgs() - 1; i >= 0; --i) {
-    ir_graph * irg = get_irp_allirg(i);
+  for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+    ir_graph * irg = get_irp_irg(i);
     entity * ent = get_irg_entity(irg);
     /* insert "external visible" methods. */
     if (get_entity_stickyness (ent) == stickyness_sticky) {
@@ -831,7 +840,7 @@ void cgana(int *length, entity ***free_methods) {
 
   /* Convert the flexible array to an array that can be handled
      by standard C. */
-  p = (entity **)malloc(sizeof(*p) * ARR_LEN(free_meths));
+  p = xmalloc(sizeof(*p) * ARR_LEN(free_meths));
   memcpy(p, free_meths, ARR_LEN(free_meths) * sizeof(*p));
 
   *length       = ARR_LEN(free_meths);