Fixed bug with switch conds
[libfirm] / ir / ana2 / ecg.c
index 1f9a092..47bd86e 100644 (file)
@@ -40,6 +40,8 @@
 # include "typalise.h"
 # include "lset.h"
 
+# include "gnu_ext.h"
+
 # define HERE(msg)  fprintf (stdout, "%s:%i %s\n", __FUNCTION__, __LINE__, msg)
 
 /*
@@ -82,7 +84,7 @@ void set_main_ctx (ctx_info_t*);
    ==================== */
 static void append_alloc (graph_info_t *ginfo, ir_node *alloc, type *tp)
 {
-  alloc_info_t *ainfo = xmalloc(sizeof(*ainfo));
+  alloc_info_t *ainfo = xmalloc (sizeof (alloc_info_t));
 
   ainfo->graph = ginfo->graph;
   ainfo->alloc = alloc;
@@ -96,12 +98,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 = xmalloc(sizeof(*nced));
+  callEd_info_t *nced = xmalloc (sizeof (callEd_info_t));
+
+  assert (NULL != callEd);
 
   nced->callEd = callEd;
   nced->prev = ced;
@@ -114,18 +133,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 = xmalloc(sizeof(*cinfo));
-  ir_graph *callEd;
+  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 */
-  for (callEd = lset_first (callEds); callEd; callEd = lset_next(callEds))
+  callEd = lset_first (callEds);
+
+  while (NULL != callEd) {
     cinfo->callEds = append_callEd_info (cinfo->callEds, callEd);
+    callEd = lset_next(callEds);
+  }
+
 }
 
 /**
@@ -133,10 +153,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 = xmalloc (sizeof(*cinfo));
+  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);
@@ -347,17 +365,19 @@ static void ecg_calls_act (ir_node *node, void *env)
 */
 static void ecg_fill_graph_calls (ir_graph *graph)
 {
-  graph_info_t *ginfo = xmalloc(sizeof(*ginfo));
+  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;
@@ -389,7 +409,7 @@ static void ecg_fill_calls (void)
 */
 static ctx_info_t *new_ctx (ir_graph *graph, ir_node *call, ctx_info_t *enc)
 {
-  ctx_info_t *res = xmalloc(sizeof(*res));
+  ctx_info_t *res = xmalloc (sizeof (ctx_info_t));
 
   res->graph = graph;
   res->call = call;
@@ -442,7 +462,7 @@ static void ecg_fill_ctxs_alloc (void)
   graph_info_t *ginfo = graph_infos_list;
 
   while (NULL != ginfo) {
-    ginfo->ctxs = xmalloc(ginfo->n_ctxs * sizeof(*ginfo->ctxs));
+    ginfo->ctxs = xcalloc (ginfo->n_ctxs, sizeof (ctx_info_t *));
 
     /*
       fprintf (stdout, "graph of \"%s\": n_ctxs = %i\n",
@@ -481,7 +501,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;
@@ -514,7 +534,7 @@ static void ecg_fill_ctxs (void)
   /* Grrr, have to add this ctx manually to main.ginfo ... */
   ginfo = ecg_get_info (main_irg);
   ginfo->n_ctxs = 1;
-  ginfo->ctxs = xmalloc(1 * sizeof(*ginfo->ctxs));
+  ginfo->ctxs = xcalloc (1, sizeof (ctx_info_t *));
   ginfo->ctxs [0] = main_ctx;
 
   ecg_fill_ctxs_write (main_irg, main_ctx);
@@ -1078,7 +1098,7 @@ void ecg_report ()
         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>", (void*) graph);
+        fprintf (dot, "\tctx_0x%08x [label=\"<HEAD>", (int) graph);
 
         assert (ginfo->ctxs && "no ctx");
         for (i = 0; i < n_ctxs; i ++) {
@@ -1107,7 +1127,7 @@ void ecg_report ()
 
         fprintf (dot,
                  "\tgraph_0x%08x -> ctx_0x%08x:HEAD [label=\"ctx\", dir=\"none\", style=\"dotted\"];\n",
-                 (void*) graph, (void*) graph);
+                 (int) graph, (int) graph);
       }
     } else {
       fprintf (dot, "\t/* graph is not called */\n");
@@ -1175,6 +1195,18 @@ void ecg_ecg (void)
 
 /*
   $Log$
+  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