replaced variable args macros by functions to make it c89 compatible
[libfirm] / ir / ana / cgana.c
index 9f1f313..a750e02 100644 (file)
@@ -1,14 +1,23 @@
-/* -------------------------------------------------------------------
- * $Id$
- * -------------------------------------------------------------------
+/*
+ * Project:     libFIRM
+ * File name:   ir/ana/cgana.c
+ * Purpose:     Intraprozedural analyses to estimate the call graph.
+ * Author:      Hubert Schmid
+ * Modified by:
+ * Created:     09.06.2002
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1999-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
+
+/**
  * Intraprozedurale Analyse zur Abschätzung der Aufrulrelation. Es
  * wird eine Menge von freien Methoden und anschließend die an den
  * Call-Operationen aufrufbaren Methoden bestimmt.
  *
- * Erstellt: Hubert Schmid, 09.06.2002
- * ---------------------------------------------------------------- */
+ */
 
-#include "stdlib.h"
+#include <stdlib.h>
 #include "cgana.h"
 
 
@@ -19,8 +28,8 @@
 #include "irgwalk.h"
 #include "ircons.h"
 #include "irgmod.h"
-#include "xprintf.h"
 #include "irnode.h"
+#include "irflag.h"
 
 #include "dbginfo_t.h"
 
@@ -40,13 +49,13 @@ static eset * entities = NULL;
  * übergebenene (dynamischen) Typ überschreibt. */
 static entity * get_implementation(type * class, entity * method) {
   int i;
-  if (get_entity_peculiarity(method) != description &&
+  if (get_entity_peculiarity(method) != peculiarity_description &&
       get_entity_owner(method) == class) {
     return method;
   }
   for (i = get_entity_n_overwrittenby(method) - 1; i >= 0; --i) {
     entity * e = get_entity_overwrittenby(method, i);
-    if (get_entity_peculiarity(e) != description && get_entity_owner(e) == class) {
+    if (get_entity_peculiarity(e) != peculiarity_description && get_entity_owner(e) == class) {
       return e;
     }
   }
@@ -57,6 +66,7 @@ static entity * get_implementation(type * class, entity * method) {
     }
   }
   assert(0 && "implemenation not found");
+  return NULL;
 }
 
 /* Returns the entity that contains the implementation of the inherited
@@ -67,10 +77,15 @@ entity *get_inherited_methods_implementation(entity *inh_meth) {
   assert(addr && "constant entity without value");
 
   if (get_irn_op(addr) == op_Const) {
-    impl_meth = get_tv_entity(get_Const_tarval(addr));
+    impl_meth = tarval_to_entity(get_Const_tarval(addr));
+  } else {
+    assert(0 && "Complex constant values not supported -- adress of method should be straight constant!");
+  }
+  if (impl_meth && (get_entity_peculiarity(impl_meth) != peculiarity_existent)) {
+    printf("this_meth: "); DDMEO(inh_meth);
+    printf("impl meth: "); DDMEO(impl_meth);
+    assert(!impl_meth || get_entity_peculiarity(impl_meth) == peculiarity_existent);
   }
-
-  assert(!impl_meth || get_entity_peculiarity(impl_meth) == existent);
   return impl_meth? impl_meth : inh_meth;
 }
 
@@ -84,8 +99,8 @@ entity *get_inherited_methods_implementation(entity *inh_meth) {
    Cycle-free, therefore must terminate. */
 void collect_impls(entity *method, eset *set, int *size, bool *open) {
   int i;
-  if (get_entity_peculiarity(method) == existent) {
-    if (get_entity_visibility(method) == external_allocated) {
+  if (get_entity_peculiarity(method) == peculiarity_existent) {
+    if (get_entity_visibility(method) == visibility_external_allocated) {
       assert(get_entity_irg(method) == NULL);
       *open = true;
     } else {
@@ -96,10 +111,10 @@ void collect_impls(entity *method, eset *set, int *size, bool *open) {
       }
     }
   }
-  if (get_entity_peculiarity(method) == inherited) {
+  if (get_entity_peculiarity(method) == peculiarity_inherited) {
     entity *impl_ent = get_inherited_methods_implementation(method);
     assert(impl_ent && "no implementation for inherited entity");
-    if (get_entity_visibility(impl_ent) == external_allocated) {
+    if (get_entity_visibility(impl_ent) == visibility_external_allocated) {
       assert(get_entity_irg(impl_ent) == NULL);
       *open = true;
     } else {
@@ -178,12 +193,12 @@ static void sel_methods_walker(ir_node * node, pmap * ldname_map) {
       pmap_entry * entry = pmap_find(ldname_map, (void *) get_SymConst_ptrinfo(node));
       if (entry != NULL) { /* Method is declared in the compiled code */
        entity * ent = entry->value;
-       if (get_opt_normalize() && (get_entity_visibility(ent) != external_allocated)) { /* Meth. is defined */
+       if (get_opt_normalize() && (get_entity_visibility(ent) != visibility_external_allocated)) { /* Meth. is defined */
          ir_node *new_node;
          assert(get_entity_irg(ent));
          set_irg_current_block(current_ir_graph, get_nodes_Block(node));
          new_node = new_d_Const(get_irn_dbg_info(node),
-                                mode_P, tarval_P_from_entity(ent));       DBG_OPT_NORMALIZE;
+                                mode_P_mach, new_tarval_from_entity(ent, mode_P_mach));       DBG_OPT_NORMALIZE;
          exchange(node, new_node);
        }
       }
@@ -195,14 +210,14 @@ static void sel_methods_walker(ir_node * node, pmap * ldname_map) {
        (get_irn_op(skip_Proj(get_Sel_ptr(node))) == op_Alloc)) {
       ir_node *new_node;
       /* We know which method will be called, no dispatch necessary. */
-      assert(get_entity_peculiarity(ent) != description);
+      assert(get_entity_peculiarity(ent) != peculiarity_description);
       set_irg_current_block(current_ir_graph, get_nodes_Block(node));
       /* @@@ Is this correct?? Alloc could reference a subtype of the owner
         of Sel that overwrites the method referenced in Sel. */
       new_node = copy_const_value(get_atomic_ent_value(ent));              DBG_OPT_POLY_ALLOC;
       exchange (node, new_node);
     } else {
-      assert(get_entity_peculiarity(ent) != inherited);
+      assert(get_entity_peculiarity(ent) != peculiarity_inherited);
       if (!eset_contains(entities, ent)) {
        /* Entity noch nicht behandelt. Alle (intern oder extern)
         * implementierten Methoden suchen, die diese Entity
@@ -216,11 +231,11 @@ static void sel_methods_walker(ir_node * node, pmap * ldname_map) {
         * ausführbar und nicht erreichbar. */
        /* Gib eine Warnung aus wenn die Entitaet eine Beschreibung ist
           fuer die es keine Implementierung gibt. */
-       if (get_entity_peculiarity(ent) == description) {
+       if (get_entity_peculiarity(ent) == peculiarity_description) {
          /* @@@ GL Methode um Fehler anzuzeigen aufrufen! */
-         xprintf("WARNING: Calling method description %I in method %I which has "
-                 "no implementation!\n", get_entity_ident(ent),
-                 get_entity_ident(get_irg_ent(current_ir_graph)));
+         printf("WARNING: Calling method description %s in method %s which has "
+                 "no implementation!\n", get_entity_name(ent),
+                 get_entity_name(get_irg_ent(current_ir_graph)));
        } else {
          exchange(node, new_Bad());
        }
@@ -268,7 +283,7 @@ static void sel_methods_init(void) {
     entity * ent = get_irg_ent(get_irp_irg(i));
     /* Nur extern sichtbare Methode können überhaupt mit SymConst
      * aufgerufen werden. */
-    if (get_entity_visibility(ent) != local) {
+    if (get_entity_visibility(ent) != visibility_local) {
       pmap_insert(ldname_map, (void *) get_entity_ld_ident(ent), ent);
     }
   }
@@ -381,7 +396,7 @@ static void callee_ana_proj(ir_node * node, long n, eset * methods) {
 static void callee_ana_node(ir_node * node, eset * methods) {
   int i;
 
-  assert((get_irn_mode(node) == mode_P) || is_Bad(node));
+  assert(mode_is_reference(get_irn_mode(node)) || is_Bad(node));
   /* rekursion verhindern */
   if (get_irn_link(node) == MARK) {
     /* already visited */
@@ -397,9 +412,9 @@ static void callee_ana_node(ir_node * node, eset * methods) {
 
   case iro_Const: {
     /* interne Methode */
-    entity * ent = get_Const_tarval(node)->u.P.ent;
+    entity * ent = tarval_to_entity(get_Const_tarval(node));
     assert(ent && is_method_type(get_entity_type(ent)));
-    if (get_entity_visibility(ent) != external_allocated) {
+    if (get_entity_visibility(ent) != visibility_external_allocated) {
       assert(get_entity_irg(ent));
       eset_insert(methods, ent);
     } else {
@@ -549,7 +564,7 @@ static void free_mark_proj(ir_node * node, long n, eset * set) {
 
 static void free_mark(ir_node * node, eset * set) {
   int i;
-  assert(get_irn_mode(node) == mode_P);
+  assert(mode_is_reference(get_irn_mode(node)));
   if (get_irn_link(node) == MARK) {
     return; /* already visited */
   }
@@ -569,9 +584,11 @@ static void free_mark(ir_node * node, eset * set) {
     break;
   case iro_Const: {
     tarval * val = get_Const_tarval(node);
-    entity * ent = val->u.P.ent;
-    if (ent != NULL && is_method_type(get_entity_type(ent))) {
-      eset_insert(set, ent);
+    if (tarval_is_entity(val)) { /* filter null pointer */
+      entity * ent = tarval_to_entity(val);
+      if (is_method_type(get_entity_type(ent))) {
+        eset_insert(set, ent);
+      }
     }
     break;
   }
@@ -617,7 +634,7 @@ static void free_ana_walker(ir_node * node, eset * set) {
     set_irn_link(node, MARK);
     for (i = get_Call_arity(node) - 1; i >= 0; --i) {
       ir_node * pred = get_Call_param(node, i);
-      if (get_irn_mode(pred) == mode_P) {
+      if (mode_is_reference(get_irn_mode(pred))) {
        free_mark(pred, set);
       }
     }
@@ -628,7 +645,7 @@ static void free_ana_walker(ir_node * node, eset * set) {
     set_irn_link(node, MARK);
     for (i = get_irn_arity(node) - 1; i >= 0; --i) {
       ir_node * pred = get_irn_n(node, i);
-      if (get_irn_mode(pred) == mode_P) {
+      if (mode_is_reference(get_irn_mode(pred))) {
        free_mark(pred, set);
       }
     }
@@ -652,7 +669,7 @@ static entity ** get_free_methods(void) {
     ir_graph * irg = get_irp_irg(i);
     entity * ent = get_irg_ent(irg);
     /* insert "external visible" methods. */
-    if (get_entity_visibility(ent) != local) {
+    if (get_entity_visibility(ent) != visibility_local) {
       eset_insert(set, ent);
     }
     irg_walk_graph(irg, NULL, (irg_walk_func *) free_ana_walker, set);