allow specification of names for in parameters in spec file
[libfirm] / ir / ana2 / ecg.c
index 71eed28..6b3c7d7 100644 (file)
@@ -1,21 +1,37 @@
 /* -*- c -*- */
 
 /*
- * Project:     libFIRM
- * File name:   ir/ana/ecg.c
- * Purpose:     Extended Call Graph
- * Author:      Florian
- * Modified by:
- * Created:     14.09.2004
- * CVS-ID:      $Id$
- * Copyright:   (c) 1999-2004 Universität Karlsruhe
- * Licence:     This file is protected by the GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
  */
 
+/**
+ * @file
+ * @brief    Extended Call Graph
+ * @author   Florian
+ * @date     14.09.2004
+ * @version  $Id$
+ */
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
+#include <assert.h>
+
 /**
    Erweiterter Aufrufgraph.
 */
@@ -28,6 +44,8 @@
 #include "irvrfy.h"
 #include "trvrfy.h"
 #include "xmalloc.h"
+#include "irdump.h"
+#include "irprog_t.h"
 
 # ifndef TRUE
 #  define TRUE 1
@@ -40,6 +58,8 @@
 # include "typalise.h"
 # include "lset.h"
 
+# include "gnu_ext.h"
+
 # define HERE(msg)  fprintf (stdout, "%s:%i %s\n", __FUNCTION__, __LINE__, msg)
 
 /*
@@ -72,7 +92,7 @@ static int _depth = 0;
 static int _max_depth = 0;
 
 static int _max_callEds = 0;
-static entity* _max_callEds_callR = NULL;
+static ir_entity* _max_callEds_callR = NULL;
 
 /* Protos */
 void set_main_ctx (ctx_info_t*);
@@ -80,9 +100,9 @@ void set_main_ctx (ctx_info_t*);
 /* ====================
    Alloc stuff
    ==================== */
-static void append_alloc (graph_info_t *ginfo, ir_node *alloc, type *tp)
+static void append_alloc (graph_info_t *ginfo, ir_node *alloc, ir_type *tp)
 {
-  alloc_info_t *ainfo = (alloc_info_t*) xmalloc (sizeof (alloc_info_t));
+  alloc_info_t *ainfo = xmalloc (sizeof (alloc_info_t));
 
   ainfo->graph = ginfo->graph;
   ainfo->alloc = alloc;
@@ -96,12 +116,29 @@ static void append_alloc (graph_info_t *ginfo, ir_node *alloc, type *tp)
 /* ====================
    CallEd stuff
    ==================== */
+/**
+   Create a new call info struct from the given values.
+*/
+static call_info_t *new_call_info (ir_node *call,
+                                   callEd_info_t *callEds,
+                                   call_info_t *prev)
+{
+  call_info_t *cinfo = xmalloc (sizeof (call_info_t));
+  cinfo->call = call;
+  cinfo->callEds = callEds;
+  cinfo->prev = prev;
+
+  return (cinfo);
+}
+
 /**
    Append the given callEd to the given callEd info.
 */
 static callEd_info_t *append_callEd_info (callEd_info_t *ced, ir_graph *callEd)
 {
-  callEd_info_t *nced = (callEd_info_t*) xmalloc (sizeof (sizeof (callEd_info_t)));
+  callEd_info_t *nced = xmalloc (sizeof (callEd_info_t));
+
+  assert (NULL != callEd);
 
   nced->callEd = callEd;
   nced->prev = ced;
@@ -114,21 +151,19 @@ static callEd_info_t *append_callEd_info (callEd_info_t *ced, ir_graph *callEd)
 */
 static void append_calls (graph_info_t *info, ir_node *call, lset_t *callEds)
 {
-  call_info_t *cinfo = (call_info_t*) xmalloc (sizeof (call_info_t));
+  ir_graph *callEd = NULL;
+  call_info_t *cinfo = new_call_info (call, NULL, info->calls);
 
-  /* setup */
-  cinfo->call = call;
-  cinfo->prev = info->calls;
   info->calls = cinfo;
-  cinfo->callEds = NULL;
 
   /* enter */
-  ir_graph *callEd = lset_first (callEds);
-  while (callEd) {
-    cinfo->callEds = append_callEd_info (cinfo->callEds, callEd);
+  callEd = lset_first (callEds);
 
-    callEd = lset_next (callEds);
+  while (NULL != callEd) {
+    cinfo->callEds = append_callEd_info (cinfo->callEds, callEd);
+    callEd = lset_next(callEds);
   }
+
 }
 
 /**
@@ -136,10 +171,8 @@ static void append_calls (graph_info_t *info, ir_node *call, lset_t *callEds)
 */
 static void append_call (graph_info_t *info, ir_node *call, ir_graph *callEd)
 {
-  call_info_t *cinfo = (call_info_t*) xmalloc (sizeof (call_info_t));
+  call_info_t *cinfo = new_call_info (call, NULL, info->calls);
 
-  cinfo->call = call;
-  cinfo->prev = info->calls;
   info->calls = cinfo;
 
   cinfo->callEds = append_callEd_info (cinfo->callEds, callEd);
@@ -149,7 +182,7 @@ static void append_call (graph_info_t *info, ir_node *call, ir_graph *callEd)
    Given a method, find the firm graph that implements that method.
    Return NULL for abstract and native methods.
 */
-static ir_graph *_get_implementing_graph (entity *method)
+static ir_graph *_get_implementing_graph (ir_entity *method)
 {
   ir_graph *graph = NULL;
 
@@ -180,7 +213,7 @@ static ir_graph *_get_implementing_graph (entity *method)
     assert (!graph);
 
     for (i = 0; (NULL == graph) && (i < n_over); i ++) {
-      entity *over = get_entity_overwrites (method, i);
+      ir_entity *over = get_entity_overwrites (method, i);
 
       graph = _get_implementing_graph (over);
     }
@@ -195,7 +228,7 @@ static ir_graph *_get_implementing_graph (entity *method)
 /**
    Collect all graphs of 'method' in the given set.
 */
-static void _collect_implementing_graphs (entity *method, lset_t *set)
+static void _collect_implementing_graphs (ir_entity *method, lset_t *set)
 {
   /* search DOWN-wards in clazz hierarchy */
   int i;
@@ -211,7 +244,7 @@ static void _collect_implementing_graphs (entity *method, lset_t *set)
   }
 
   for (i = 0; i < n_over; i ++) {
-    entity *over = get_entity_overwrittenby (method, i);
+    ir_entity *over = get_entity_overwrittenby (method, i);
 
     _collect_implementing_graphs (over, set);
   }
@@ -221,8 +254,12 @@ static void _collect_implementing_graphs (entity *method, lset_t *set)
 /**
    Collect all graphs that could possibly be executed when 'method' is called.
 */
-static lset_t *get_implementing_graphs (entity *method, ir_node *select)
+static lset_t *get_implementing_graphs (ir_entity *method, ir_node *select)
 {
+  /* const char *name = get_entity_name (method); */
+  /* fprintf (stdout, "%s (ent %s)\n", __FUNCTION__, name); */
+
+  int n_graphs;
   lset_t *set = lset_create ();
   {
     ir_graph *impl = _get_implementing_graph (method);
@@ -243,22 +280,57 @@ static lset_t *get_implementing_graphs (entity *method, ir_node *select)
   }
 
   /* void *tmp = lset_first (set); */
-  int n_graphs = lset_n_entries (set);
+  n_graphs = lset_n_entries (set);
+
+
+  if (visibility_external_allocated != get_entity_visibility (method)) {
+    if (0 == n_graphs) {
+      ir_graph *graph = get_irn_irg (select);
 
+      dump_ir_block_graph (graph, "-typealise");
+
+      /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */
+      assert (n_graphs && "no graphs for method");
+    }
+  }
   /* typalise select_in */
   if (do_typalise) {
     ir_node *select_in = get_Sel_ptr (select);
     typalise_t *ta = typalise (select_in);
-    assert (ta && "typalise failed (go figure)");
-
-    /* const char *res = ta_name (ta); */
+    /* assert (ta && "typalise failed (go figure)"); */
 
-    /* fprintf (stdout, "typalyse res = %s\n", res); */
+    /*
+    fprintf (stdout, "typalyse res = ");
+
+    if (NULL != ta) {
+      if (type_invalid == ta->kind) {
+        fprintf (stdout, "invalid");
+      } else if (type_exact == ta->kind) {
+        const char *name = get_type_name (ta->res.type);
+
+        fprintf (stdout, "exact [");
+        fprintf (stdout, "%s", name);
+        fprintf (stdout, "]\n");
+      } else if (type_types == ta->kind) {
+        fprintf (stdout, "types [");
+        fprintf (stdout, "...");
+        fprintf (stdout, "]\n");
+      } else if (type_type == ta->kind) {
+        const char *name = get_type_name (ta->res.type);
+        fprintf (stdout, "type [");
+        fprintf (stdout, "%s", name);
+        fprintf (stdout, "]\n");
+      }
+    } else {
+      fprintf (stdout, "(null)\n");
+    }
+    */
 
     if (1 != n_graphs) {
-      set = filter_for_ta (set, ta);
+      int n_filtered_graphs;
 
-      int n_filtered_graphs = lset_n_entries (set);
+      set = filter_for_ta (set, ta);
+      n_filtered_graphs = lset_n_entries (set);
 
       /*
         fprintf (stdout, "%s: %02d %02d\n",
@@ -269,6 +341,17 @@ static lset_t *get_implementing_graphs (entity *method, ir_node *select)
       */
       n_graphs = n_filtered_graphs;
     }
+
+    if (visibility_external_allocated != get_entity_visibility (method)) {
+      if (0 == n_graphs) {
+        ir_graph *graph = get_irn_irg (select);
+
+        dump_ir_block_graph (graph, "-ecg");
+        /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */
+        assert (n_graphs && "no graphs for method");
+      }
+    }
+
   }
 
   if (n_graphs > _max_callEds) {
@@ -277,14 +360,22 @@ static lset_t *get_implementing_graphs (entity *method, ir_node *select)
   }
 
 
-  if (visibility_external_allocated != get_entity_visibility (method)) {
-    if (0 == n_graphs) {
-      /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */
-      assert (n_graphs && "no graphs for method");
-    }
+  return (set);
+}
+
+/**
+   Determine whether a call is actually a call or if it is being
+   abused for some b/d-ed reason.
+*/
+static int call_is_call (ir_node *call, ir_node *ptr)
+{
+  if (op_SymConst != get_irn_op (ptr)) {
+    return (TRUE);
+  } else if (get_SymConst_kind (ptr) != symconst_addr_name) {
+    return (TRUE);
   }
 
-  return (set);
+  return (FALSE);
 }
 
 /**
@@ -292,23 +383,33 @@ static lset_t *get_implementing_graphs (entity *method, ir_node *select)
 */
 static void ecg_calls_act (ir_node *node, void *env)
 {
-  opcode op = get_irn_opcode (node);
+  ir_op *op = get_irn_op(node);
   graph_info_t *graph_info = (graph_info_t*) env;
 
-  if (iro_Call == op) {         /* CALL */
-    entity *ent = NULL;
+  if (op_Call == op) {         /* CALL */
+    ir_entity *ent = NULL;
     ir_node *ptr = get_Call_ptr (node);
 
+    if (!call_is_call (node, ptr)) {
+      /*
+      fprintf (stdout, "not a call: %s[%li]\n",
+               get_op_name (get_irn_op (node)),
+               get_irn_node_nr (node)); */
+      return;
+    }
+
     /* CALL SEL */
-    if (iro_Sel == get_irn_opcode (ptr)) {
+    if (op_Sel == get_irn_op (ptr)) {
+      lset_t *graphs;
       ent = get_Sel_entity (ptr);
-      lset_t *graphs = get_implementing_graphs (ent, ptr);
+      graphs = get_implementing_graphs (ent, ptr);
 
       append_calls (graph_info, node, graphs);
-    } else if (iro_SymConst == get_irn_opcode (ptr)) {
+    } else if (op_SymConst == get_irn_op (ptr)) {
       if (get_SymConst_kind (ptr) == symconst_addr_ent) {
+        ir_graph *graph;
         ent = get_SymConst_entity (ptr);
-        ir_graph *graph = get_entity_irg (ent);
+        graph = get_entity_irg (ent);
 
         if (graph) {
           append_call (graph_info, node, graph);
@@ -331,8 +432,8 @@ static void ecg_calls_act (ir_node *node, void *env)
       DDMN (ptr);
       assert (0 && "Unexpected address expression");
     }
-  } else if (iro_Alloc == op) {
-    type *tp = get_Alloc_type (node);
+  } else if (op_Alloc == op) {
+    ir_type *tp = get_Alloc_type (node);
     /* const char *name = get_type_name (tp); */
 
     append_alloc (graph_info, node, tp);
@@ -346,17 +447,19 @@ static void ecg_calls_act (ir_node *node, void *env)
 */
 static void ecg_fill_graph_calls (ir_graph *graph)
 {
-  graph_info_t *ginfo = (graph_info_t*) xmalloc (sizeof (graph_info_t));
+  graph_info_t *ginfo = xmalloc (sizeof (graph_info_t));
 
   /* memset (ginfo, 0x00, sizeof (graph_info_t)); */
   assert (ginfo != graph_infos_list);
 
-  ginfo->graph  = graph;
-  ginfo->calls  = NULL;
-  ginfo->ecg_seen = 0;
-  ginfo->ctxs   = NULL;
-  ginfo->n_ctxs = 0;
-  ginfo->prev   = NULL;
+  ginfo->graph       = graph;
+  ginfo->calls       = NULL;
+  ginfo->allocs      = NULL;
+  ginfo->ctxs        = NULL;
+  ginfo->n_ctxs      = 0;
+  ginfo->ecg_seen    = 0;
+  ginfo->allocs_seen = 0;
+  ginfo->prev        = NULL;
 
   /* link up into global list */
   ginfo->prev = graph_infos_list;
@@ -408,9 +511,9 @@ static void ecg_fill_ctxs_count (ir_graph *graph)
 
   /* count how many ctxs we have per graph */
   if (0 == ginfo->ecg_seen) {
+    call_info_t *cinfo = ginfo->calls;
 
     ginfo->ecg_seen = 1;
-    call_info_t *cinfo = ginfo->calls;
 
     while (NULL != cinfo) {
       callEd_info_t *ced = cinfo->callEds;
@@ -422,7 +525,7 @@ static void ecg_fill_ctxs_count (ir_graph *graph)
         graph_info_t *callEd_info = ecg_get_info (callEd_graph);
         callEd_info->n_ctxs ++;
 
-        /* Calling graph -> callEd_graph */
+        /* CallR graph -> CallEd_graph */
         ecg_fill_ctxs_count (callEd_graph);
 
         ced = ced->prev;
@@ -441,7 +544,7 @@ static void ecg_fill_ctxs_alloc (void)
   graph_info_t *ginfo = graph_infos_list;
 
   while (NULL != ginfo) {
-    ginfo->ctxs = (ctx_info_t **) xmalloc (ginfo->n_ctxs * sizeof (ctx_info_t*));
+    ginfo->ctxs = xcalloc (ginfo->n_ctxs, sizeof (ctx_info_t *));
 
     /*
       fprintf (stdout, "graph of \"%s\": n_ctxs = %i\n",
@@ -463,8 +566,8 @@ static void ecg_fill_ctxs_write (ir_graph *graph, ctx_info_t *enc_ctx)
 
   /* enter a new ctx for all callEds along the call edges of this graph */
   if (0 == ginfo->ecg_seen) {
-    ginfo->ecg_seen = 1;
     call_info_t *cinfo = ginfo->calls;
+    ginfo->ecg_seen = 1;
 
     while (NULL != cinfo) {
       callEd_info_t *ced = cinfo->callEds;
@@ -480,7 +583,7 @@ static void ecg_fill_ctxs_write (ir_graph *graph, ctx_info_t *enc_ctx)
         callEd_info->ctxs [callEd_info->n_ctxs] = ctx;
         callEd_info->n_ctxs ++;
 
-        /* Calling graph -> callEd_graph */
+        /* CallR graph -> callEd_graph */
         ecg_fill_ctxs_write (callEd_graph, ctx);
 
         ced = ced->prev;
@@ -498,18 +601,22 @@ static void ecg_fill_ctxs_write (ir_graph *graph, ctx_info_t *enc_ctx)
 */
 static void ecg_fill_ctxs (void)
 {
+  ctx_info_t *main_ctx;
+  ir_graph *main_irg;
+  graph_info_t *ginfo;
+
   ecg_fill_ctxs_count (get_irp_main_irg ());
   ecg_fill_ctxs_alloc ();
 
-  ctx_info_t *main_ctx = new_ctx (get_irp_main_irg (), NULL, NULL);
-  ir_graph *main_irg = get_irp_main_irg ();
+  main_ctx = new_ctx (get_irp_main_irg (), NULL, NULL);
+  main_irg = get_irp_main_irg ();
 
   set_main_ctx (main_ctx);
 
   /* Grrr, have to add this ctx manually to main.ginfo ... */
-  graph_info_t *ginfo = ecg_get_info (main_irg);
+  ginfo = ecg_get_info (main_irg);
   ginfo->n_ctxs = 1;
-  ginfo->ctxs = (ctx_info_t **) xmalloc (1 * sizeof (ctx_info_t*));
+  ginfo->ctxs = xcalloc (1, sizeof (ctx_info_t *));
   ginfo->ctxs [0] = main_ctx;
 
   ecg_fill_ctxs_write (main_irg, main_ctx);
@@ -523,10 +630,10 @@ static void ecg_fill_ctxs (void)
 */
 void ecg_print_ctx (ctx_info_t *ctx, FILE *stream)
 {
-  entity *ent = get_irg_ent (ctx->graph);
+  ir_entity *ent = get_irg_entity(ctx->graph);
   ir_node *call = ctx->call;
-  const char *ent_name = (char*) get_entity_name (ent);
-  const char *own_name = (char*) get_type_name (get_entity_owner (ent));
+  const char *ent_name = get_entity_name (ent);
+  const char *own_name = get_type_name (get_entity_owner (ent));
 
   fprintf (stream, "CTX[%i](%s.%s->%s[%li])",
            ctx->id, own_name, ent_name,
@@ -687,6 +794,9 @@ callEd_info_t *ecg_get_callEd_info (ir_node *call)
 */
 static int ecg_ecg_graph (FILE *dot, ir_graph *graph)
 {
+  int graph_no;
+  call_info_t *cinfo;
+  alloc_info_t *ainfo;
   const char *name = get_irg_entity (graph) ?
     get_entity_name (get_irg_entity (graph)) : "noEntity";
   const char *color =
@@ -709,7 +819,7 @@ static int ecg_ecg_graph (FILE *dot, ir_graph *graph)
 
   assert (0L <= _graphs);
 
-  const int graph_no = _graphs ++;
+  graph_no = _graphs ++;
   ginfo->ecg_seen = graph_no;
 
   fprintf (dot, "\t/* Graph of \"%s.%s\" */\n",
@@ -730,7 +840,7 @@ static int ecg_ecg_graph (FILE *dot, ir_graph *graph)
     return (graph_no);
   }
 
-  call_info_t *cinfo = ginfo->calls;
+  cinfo = ginfo->calls;
   while (NULL != cinfo) {
     ir_node *call = cinfo->call;
     callEd_info_t *ced = cinfo->callEds;
@@ -768,7 +878,7 @@ static int ecg_ecg_graph (FILE *dot, ir_graph *graph)
   } /* done all calls (graph) */
 
   /* now the allocs */
-  alloc_info_t *ainfo = ecg_get_alloc_info (graph);
+  ainfo = ecg_get_alloc_info (graph);
   if (ainfo) {
     fprintf (dot, "\t/* now the allocs */\n");
   } else {
@@ -796,12 +906,12 @@ static int ecg_ecg_graph (FILE *dot, ir_graph *graph)
 
   /* write table of ctxs */
   {
-    fprintf (dot, "\tctx_%i [label=\"<HEAD>", graph_no);
-
     int i;
     const int max_ctxs = 30;
     const int n_ctxs = (ginfo->n_ctxs > max_ctxs) ? max_ctxs : ginfo->n_ctxs;
 
+    fprintf (dot, "\tctx_%i [label=\"<HEAD>", graph_no);
+
     assert (ginfo->ctxs && "no ctx");
     for (i = 0; i < n_ctxs; i ++) {
       ctx_info_t *ctx_info = ginfo->ctxs [i];
@@ -847,6 +957,8 @@ static char spaces [BUF_SIZE];
 
 static void ecg_ecg_count (ir_graph *graph)
 {
+  int graph_no;
+  call_info_t *cinfo;
   graph_info_t *ginfo = (graph_info_t*) pmap_get (graph_infos, graph);
 
   if (0 != ginfo->ecg_seen) {
@@ -872,7 +984,7 @@ static void ecg_ecg_count (ir_graph *graph)
     }
   */
 
-  const int graph_no = _graphs ++;
+  graph_no = _graphs ++;
   ginfo->ecg_seen = graph_no;
 
   fprintf (stdout, "%sMethod \"%s.%s\"\n",
@@ -880,7 +992,7 @@ static void ecg_ecg_count (ir_graph *graph)
            get_type_name (get_entity_owner (get_irg_entity (graph))),
            get_entity_name (get_irg_entity (graph)));
 
-  call_info_t *cinfo = ginfo->calls;
+  cinfo = ginfo->calls;
   while (NULL != cinfo) {
 
     callEd_info_t *ced = cinfo->callEds;
@@ -919,6 +1031,10 @@ void ecg_init (int typalise)
 {
   do_typalise = typalise;
 
+  if (typalise) {
+    typalise_init ();
+  }
+
   graph_infos = pmap_create ();
 
   ecg_fill_calls ();
@@ -929,12 +1045,12 @@ void ecg_init (int typalise)
 /**
    Clean up our mess.
 */
-void ecg_cleanup ()
+void ecg_cleanup (void)
 {
-  return;
-
   int i;
 
+  return;
+
   for (i = 0; i < get_irp_n_irgs (); i++) {
     ir_graph *graph = get_irp_irg (i);
 
@@ -942,10 +1058,10 @@ void ecg_cleanup ()
     call_info_t *cinfo = info->calls;
 
     while (NULL != cinfo) {
-      cinfo->call = NULL;
-
       callEd_info_t *ced = cinfo->callEds;
 
+      cinfo->call = NULL;
+
       while (NULL != ced) {
         callEd_info_t *nced = ced->prev;
         free (ced);
@@ -981,84 +1097,127 @@ void ecg_report ()
   FILE *dot = fopen ("calls.dot", "w");
 
   fprintf (dot, "digraph \"calls\" {\n");
-  fprintf (dot, "\tgraph [rankdir=\"LR\", ordering=\"out\"];\n");
-  fprintf (dot, "\tnode [shape = \"record\", style = \"filled\"];\n");
-  fprintf (dot, "\tedge [color = \"black\"];\n");
-  fprintf (dot, "\n");
-  fprintf (dot, "\tsize = \"11, 7\";\n");
-  fprintf (dot, "\trotate = \"90\";\n");
-  fprintf (dot, "\tratio = \"fill\";\n");
+  fprintf (dot, "\tgraph [rankdir=\"LR\", ordering=\"out\", size=\"11, 7\", rotate=\"90\", ratio=\"fill\"];\n");
+  fprintf (dot, "\tnode [shape=\"record\", style=\"filled\"];\n");
+  fprintf (dot, "\tedge [color=\"black\"];\n");
   fprintf (dot, "\n");
 
   for (i = 0; i < get_irp_n_irgs (); i++) {
     ir_graph *graph = get_irp_irg (i);
-    graph_info_t *info = (graph_info_t*) pmap_get (graph_infos, graph);
+    graph_info_t *ginfo = (graph_info_t*) pmap_get (graph_infos, graph);
 
-    const char *name = get_irg_entity (graph) ?
-      get_entity_name (get_irg_entity (graph)) : "noEntity";
+    if (0 != ginfo->n_ctxs) {
+      call_info_t *cinfo;
+      alloc_info_t *ainfo;
 
-    const char *oname = get_type_name
-      (get_entity_owner (get_irg_entity (graph)));
+      const char *name = get_irg_entity (graph) ?
+        get_entity_name (get_irg_entity (graph)) : "noEntity";
 
-    const char *color =
-      (get_entity_stickyness
-       (get_irg_entity (graph)) == stickyness_sticky) ?
-      "red3" : "lightyellow";
+      const char *oname = get_type_name
+        (get_entity_owner (get_irg_entity (graph)));
 
-    fprintf (dot, "\t/* graph_0x%08x (\"%s\") */\n", (int) graph, name);
-    fprintf (dot,
-             "\tgraph_0x%08x [label=\"%s\\l%s\", color=\"%s\"];\n",
-             (int) graph, oname, name, color);
-    fprintf (dot, "\n");
+      const char *color =
+        (get_entity_stickyness
+         (get_irg_entity (graph)) == stickyness_sticky) ?
+        "red3" : "lightyellow";
 
-    call_info_t *cinfo = info->calls;
-    if (cinfo) {
-      fprintf (dot, "\t/* now the calls */\n");
-    } else {
-      fprintf (dot, "\t/* no calls, nothing to see, move along! */\n");
-    }
+      fprintf (dot, "\t/* graph_0x%08x (\"%s\") */\n", (int) graph, name);
+      fprintf (dot,
+               "\tgraph_0x%08x [label=\"%s\\l%s\", color=\"%s\"];\n",
+               (int) graph, oname, name, color);
+      fprintf (dot, "\n");
 
-    while (NULL != cinfo) {
-      ir_node *call = cinfo->call;
+      cinfo = ginfo->calls;
+      if (cinfo) {
+        fprintf (dot, "\t/* now the calls */\n");
+      } else {
+        fprintf (dot, "\t/* no calls, nothing to see, move along! */\n");
+      }
 
-      fprintf (dot, "\t/* call_0x%08x */\n", (int) call);
-      fprintf (dot, "\tcall_0x%08x [label=\"call\\[%li\\]\\l0x%08x\"];\n",
-               (int) call, get_irn_node_nr (call), (int) call);
-      fprintf (dot, "\tgraph_0x%08x -> call_0x%08x;\n",
-               (int) graph, (int) call);
+      while (NULL != cinfo) {
+        callEd_info_t *ced;
+        ir_node *call = cinfo->call;
+
+        fprintf (dot, "\t/* call_0x%08x */\n", (int) call);
+        fprintf (dot, "\tcall_0x%08x [label=\"call\\[%li\\]\", shape=\"ellipse\", color=\"lightblue\"];\n",
+                 (int) call, get_irn_node_nr (call));
+        fprintf (dot, "\tgraph_0x%08x -> call_0x%08x;\n",
+                 (int) graph, (int) call);
+
+        ced = cinfo->callEds;
+        while (NULL != ced) {
+          fprintf (dot, "\tcall_0x%08x -> graph_0x%08x;\n",
+                   (int) call, (int) ced->callEd);
+          ced = ced->prev;
+        }
+        fprintf (dot, "\n");
 
-      callEd_info_t *ced = cinfo->callEds;
-      while (NULL != ced) {
-        fprintf (dot, "\tcall_0x%08x -> graph_0x%08x;\n",
-                 (int) call, (int) ced->callEd);
-        ced = ced->prev;
+        cinfo = cinfo->prev;
       }
       fprintf (dot, "\n");
 
-      cinfo = cinfo->prev;
-    }
-    fprintf (dot, "\n");
+      ainfo = ginfo->allocs;
+      if (ainfo) {
+        fprintf (dot, "\t/* now the allocs */\n");
+      } else {
+        fprintf (dot, "\t/* no allocs */\n");
+      }
 
-    alloc_info_t *ainfo = info->allocs;
-    if (ainfo) {
-      fprintf (dot, "\t/* now the allocs */\n");
-    } else {
-      fprintf (dot, "\t/* no allocs */\n");
-    }
+      /* allocs */
+      while (NULL != ainfo) {
+        ir_node *alloc = ainfo->alloc;
+        const char *name = get_type_name (ainfo->tp);
+        const char *color = "red1";
 
+        fprintf (dot, "\talloc_0x%08x [label=\"%s\", color=\"%s\"];\n",
+                 (int) alloc, name, color);
+        fprintf (dot, "\tgraph_0x%08x -> alloc_0x%08x;\n",
+                 (int) graph, (int) alloc);
 
-    while (NULL != ainfo) {
-      ir_node *alloc = ainfo->alloc;
-      const char *name = get_type_name (ainfo->tp);
-      const char *color = "green3";
+        ainfo = ainfo->prev;
+      }
 
-      fprintf (dot, "\talloc_0x%08x [label=\"%s\", color=\"%s\"];\n",
-               (int) alloc, name, color);
-      fprintf (dot, "\tgraph_0x%08x -> alloc_0x%08x;\n",
-               (int) graph, (int) alloc);
+      /* ctxs */
+      {
+        int i;
+        const int max_ctxs = 30;
+        const int n_ctxs = (ginfo->n_ctxs > max_ctxs) ? max_ctxs : ginfo->n_ctxs;
+
+        fprintf (dot, "\t/* now the ctxs */\n");
+        fprintf (dot, "\tctx_0x%08x [label=\"<HEAD>", (int) graph);
+
+        assert (ginfo->ctxs && "no ctx");
+        for (i = 0; i < n_ctxs; i ++) {
+          ctx_info_t *ctx_info = ginfo->ctxs [i];
+
+          if (NULL != ctx_info->enc) {
+            fprintf (dot, "ctx_info \\[%i\\] = ctx\\[%i\\-\\>%i\\]\\l",
+                     i,
+                     ctx_info->id,
+                     ctx_info->enc->id);
+          } else {
+            fprintf (dot, "ctx_info \\[%i\\] = ctx\\[%i\\]\\l",
+                     i, ctx_info->id);
+          }
+
+          if (i+1 != n_ctxs) {
+            fprintf (dot, "|");
+          }
+        }
 
-      ainfo = ainfo->prev;
-    }
+        if (0 < ginfo->n_ctxs - max_ctxs) {
+          fprintf (dot, "(%i more)\\l", ginfo->n_ctxs - max_ctxs);
+        }
+
+        fprintf (dot, "\", color=\"green3\"];\n");
+
+        fprintf (dot,
+                 "\tgraph_0x%p -> ctx_0x%p:HEAD [label=\"ctx\", dir=\"none\", style=\"dotted\"];\n",
+                 graph, graph);
+      }
+    } else {
+      fprintf (dot, "\t/* graph is not called */\n");
+    } /* end all graphs */
   }
   fprintf (dot, "}\n");
 
@@ -1073,13 +1232,14 @@ void ecg_report ()
 /**
    Experimental:  Print the ecg
 */
-void ecg_ecg ()
+void ecg_ecg (void)
 {
+  FILE *dot;
+  ir_graph *main_graph = get_irp_main_irg ();
+
   _graphs = 0;
   _calls  = 0;
 
-  ir_graph *main_graph = get_irp_main_irg ();
-
   /*
     memset (spaces, '.', BUF_SIZE);
     spaces [BUF_SIZE-1] = '\0';
@@ -1094,16 +1254,13 @@ void ecg_ecg ()
   _graphs = 0;
   _calls  = 0;
 
-  FILE *dot = fopen ("ecg.dot", "w");
+  dot = fopen ("ecg.dot", "w");
 
   fprintf (dot, "digraph \"ecg\" {\n");
-  fprintf (dot, "\tnode [shape = \"record\", style = \"filled\"];\n");
-  fprintf (dot, "\tedge [color = \"black\"];\n");
+  fprintf (dot, "\tgraph [rankdir=\"LR\", ordering=\"out\", size=\"11, 7\", rotate=\"90\", ratio=\"fill\"];\n");
+  fprintf (dot, "\tnode [shape=\"record\", style=\"filled\"];\n");
+  fprintf (dot, "\tedge [color=\"black\"];\n");
   fprintf (dot, "\n");
-  fprintf (dot, "\tsize = \"11, 7\";\n");
-  fprintf (dot, "\trotate = \"90\";\n");
-  fprintf (dot, "\tratio = \"fill\";\n");
-  fprintf (dot, "\trankdir = \"LR\";\n");
   fprintf (dot, "\n");
 
   /* ir_graph *main_graph = get_irp_main_irg (); */
@@ -1123,7 +1280,46 @@ void ecg_ecg ()
 \f
 
 /*
-  $Log$
+  $Log: ecg.c,v $
+  Revision 1.23  2006/12/13 19:46:47  beck
+  rename type entity into ir_entity
+
+  Revision 1.22  2006/01/13 22:55:03  beck
+  renamed all types 'type' to 'ir_type'
+
+  Revision 1.21  2005/12/31 15:58:57  beck
+  added missing includes
+
+  Revision 1.20  2005/12/05 12:01:06  beck
+  needed include added
+
+  Revision 1.19  2005/03/22 13:55:51  liekweg
+  Need to initialise typalise now
+
+  Revision 1.18  2005/01/14 14:14:43  liekweg
+  fix gnu extension
+
+  Revision 1.17  2005/01/14 13:34:25  liekweg
+  Factor out call_info_t ctor; fix mallocs; fix initialisation
+
+  Revision 1.16  2005/01/10 17:26:34  liekweg
+  fixup printfs, don't put environments on the stack
+
+  Revision 1.15  2004/12/23 15:40:03  beck
+  used new xcalloc
+
+  Revision 1.14  2004/12/22 14:43:14  beck
+  made allocations C-like
+
+  Revision 1.13  2004/12/21 14:21:16  beck
+  removed C99 constructs
+
+  Revision 1.12  2004/12/20 17:34:34  liekweg
+  fix recursion handling
+
+  Revision 1.11  2004/12/15 09:18:18  liekweg
+  pto_name.c
+
   Revision 1.10  2004/12/06 12:55:06  liekweg
   actually iterate