placed the call the _get_irn_intra_arity() again into the assert: no need to execute...
[libfirm] / ir / debug / firm_ycomp.c
index 0e9c09b..9c2c937 100644 (file)
@@ -1,13 +1,28 @@
 /*
- * Project:     libFIRM
- * File name:   ir/debug/firm_ycomp.c
- * Purpose:     Connect firm to ycomp
- * Author:      Christian Wuerdig
- * Modified by:
- * Created:     16.11.2006
- * CVS-ID:      $Id$
- * Copyright:   (c) 2001-2006 Universität Karlsruhe
- * Licence:     This file protected by 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      Connect firm to ycomp
+ * @author     Christian Wuerdig
+ * @date       16.11.2006
+ * @version    $Id$
  */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -23,6 +38,7 @@
 #include "iredges.h"
 #include "pset.h"
 #include "obst.h"
+#include "firmnet.h"
 
 #define SEND_BUF_SIZE 256
 #define HASH_EDGE(edge) \
@@ -58,18 +74,19 @@ typedef struct _firm_ycomp_node_realizer_t {
        unsigned   id;
        const char *linecolor;
        const char *fillcolor;
+       const char *textcolor;
        const char *shape;
 } firm_ycomp_node_realizer_t;
 
 static firm_ycomp_node_realizer_t node_realizer[NODE_REALIZER_LAST] = {
-       { NODE_REALIZER_NORMAL,   "black", "white",    "box" },
-       { NODE_REALIZER_PROJ,     "black", "yellow",   "box" },
-       { NODE_REALIZER_BLOCK,    "black", "yellow",   "box" },
-       { NODE_REALIZER_MEM,      "black", "blue",     "box" },
-       { NODE_REALIZER_PHI,      "black", "green",    "box" },
-       { NODE_REALIZER_STARTEND, "black", "blue",     "box" },
-       { NODE_REALIZER_IRG,      "black", "white",    "box" },
-       { NODE_REALIZER_ID,       "black", "darkgrey", "box" },
+       { NODE_REALIZER_NORMAL,   "black", "white",    "black", "box" },
+       { NODE_REALIZER_PROJ,     "black", "yellow",   "black", "box" },
+       { NODE_REALIZER_BLOCK,    "black", "yellow",   "white", "box" },
+       { NODE_REALIZER_MEM,      "black", "blue",     "black", "box" },
+       { NODE_REALIZER_PHI,      "black", "green",    "black", "box" },
+       { NODE_REALIZER_STARTEND, "black", "blue",     "black", "box" },
+       { NODE_REALIZER_IRG,      "black", "white",    "white", "box" },
+       { NODE_REALIZER_ID,       "black", "darkgrey", "black", "box" },
 };
 
 enum _firm_ycomp_edge_realizer_values {
@@ -83,15 +100,16 @@ enum _firm_ycomp_edge_realizer_values {
 typedef struct _firm_ycomp_edge_realizer_t {
        unsigned   id;
        const char *linecolor;
+       const char *textcolor;
        unsigned   thickness;
        const char *style;
 } firm_ycomp_edge_realizer_t;
 
 static firm_ycomp_edge_realizer_t edge_realizer[EDGE_REALIZER_LAST] = {
-       { EDGE_REALIZER_DATA, "black", 1, "continuous" },
-       { EDGE_REALIZER_MEM,  "blue",  1, "continuous" },
-       { EDGE_REALIZER_DEP,  "green", 1, "continuous" },
-       { EDGE_REALIZER_CFG,  "red",   1, "continuous" },
+       { EDGE_REALIZER_DATA, "black", "black", 1, "continuous" },
+       { EDGE_REALIZER_MEM,  "blue",  "black", 1, "continuous" },
+       { EDGE_REALIZER_DEP,  "green", "black", 1, "continuous" },
+       { EDGE_REALIZER_CFG,  "red",   "black", 1, "continuous" },
 };
 
 typedef struct _firm_ycomp_dbg_t {
@@ -152,18 +170,20 @@ static void firm_ycomp_debug_init_realizer(firm_ycomp_dbg_t *dbg) {
        char buf[SEND_BUF_SIZE];
 
        for (i = 0; i < NODE_REALIZER_LAST; ++i) {
-               snprintf(buf, sizeof(buf), "addNodeRealizer \"%u\" \"%s\" \"%s\" \"%s\"\n",
+               snprintf(buf, sizeof(buf), "addNodeRealizer \"%u\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
                        node_realizer[i].id,
                        node_realizer[i].linecolor,
                        node_realizer[i].fillcolor,
+                       node_realizer[i].textcolor,
                        node_realizer[i].shape);
                send_cmd(dbg, buf);
        }
 
        for (i = 0; i < EDGE_REALIZER_LAST; ++i) {
-               snprintf(buf, sizeof(buf), "addEdgeRealizer \"%u\" \"%s\" \"%u\" \"%s\"\n",
+               snprintf(buf, sizeof(buf), "addEdgeRealizer \"%u\" \"%s\" \"%s\" \"%u\" \"%s\"\n",
                        edge_realizer[i].id,
                        edge_realizer[i].linecolor,
+                       edge_realizer[i].textcolor,
                        edge_realizer[i].thickness,
                        edge_realizer[i].style);
                send_cmd(dbg, buf);
@@ -175,7 +195,7 @@ static void firm_ycomp_debug_init_realizer(firm_ycomp_dbg_t *dbg) {
  */
 static INLINE unsigned get_node_realizer(ir_node *node) {
        unsigned realizer;
-       opcode   opc = get_irn_opcode(node);
+       ir_opcode opc = get_irn_opcode(node);
 
        switch (opc) {
                case iro_Block:
@@ -208,12 +228,13 @@ static INLINE unsigned get_edge_realizer(ir_node *src, ir_node *tgt) {
        unsigned realizer;
        ir_mode  *tgt_mode, *src_mode;
 
-       assert(! is_Block(tgt));
+       if (is_Block(tgt) || is_Block(src))
+               return EDGE_REALIZER_CFG;
 
        tgt_mode = get_irn_mode(tgt);
        src_mode = is_Block(src) ? NULL : get_irn_mode(src);
 
-       if (tgt_mode == mode_M || src_mode)
+       if (tgt_mode == mode_M || (src_mode == mode_M && tgt_mode == mode_T))
                realizer = EDGE_REALIZER_MEM;
        else if (tgt_mode == mode_X)
                realizer = EDGE_REALIZER_CFG;
@@ -224,7 +245,7 @@ static INLINE unsigned get_edge_realizer(ir_node *src, ir_node *tgt) {
 }
 
 /**
- * Add new nodes, resp. new blocks in yComp and add input edges.
+ * Hook: Add new nodes, resp. new blocks in yComp and add input edges.
  */
 static void firm_ycomp_debug_new_node(void *context, ir_graph *graph, ir_node *node) {
        firm_ycomp_dbg_t *dbg = context;
@@ -290,13 +311,13 @@ static void firm_ycomp_debug_new_node(void *context, ir_graph *graph, ir_node *n
 /**
  * Clear the old irg if it has some data and create a new one.
  */
-static void firm_ycomp_debug_new_irg(void *context, ir_graph *irg, entity *ent) {
+static void firm_ycomp_debug_new_irg(void *context, ir_graph *irg, ir_entity *ent) {
        firm_ycomp_dbg_t *dbg = context;
        char             buf[SEND_BUF_SIZE];
 
        if (yy_dbg.has_data) {
                send_cmd(dbg, "deleteGraph\n");
-               send_cmd(dbg, "show\n");
+//             send_cmd(dbg, "show\n");
        }
        dbg->has_data = 0;
 
@@ -308,23 +329,23 @@ static void firm_ycomp_debug_new_irg(void *context, ir_graph *irg, entity *ent)
 }
 
 /**
- * Handle set_irn_n calls.
+ * Hook: Handle set_irn_n calls.
  * - set new Block      OR
  * - remove old edge and add new one
  */
 static void firm_ycomp_debug_set_edge(void *context, ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt) {
-       firm_ycomp_dbg_t           *dbg = context;
-       exchange_node_outs_assoc_t *entry, key;
+       firm_ycomp_dbg_t           *dbg   = context;
+       exchange_node_outs_assoc_t *entry = NULL;
+       exchange_node_outs_assoc_t key;
        ycomp_edge_t               *old_edge, *new_edge, edge_key;
        char                       buf[SEND_BUF_SIZE];
-       unsigned                   src_idx, tgt_idx, old_tgt_idx;
+       unsigned                   src_idx, tgt_idx;
 
        if (dbg->in_dead_node_elim)
                return;
 
-       src_idx     = get_irn_node_nr(src);
-       tgt_idx     = get_irn_node_nr(tgt);
-       old_tgt_idx = get_irn_node_nr(old_tgt);
+       src_idx = get_irn_node_nr(src);
+       tgt_idx = get_irn_node_nr(tgt);
 
        /* set_irn_n with pos -1 means: node moves to new block  */
        if (pos < 0) {
@@ -347,25 +368,29 @@ static void firm_ycomp_debug_set_edge(void *context, ir_node *src, int pos, ir_n
                return;
 
        /* check if the old edge exists */
-       edge_key.src = src;
-       edge_key.tgt = old_tgt;
-       edge_key.pos = pos;
-       old_edge     = pset_find(dbg->edges, &edge_key, HASH_EDGE(&edge_key));
+       if (old_tgt) {
+               int old_tgt_idx = get_irn_node_nr(old_tgt);
+
+               edge_key.src = src;
+               edge_key.tgt = old_tgt;
+               edge_key.pos = pos;
+               old_edge     = pset_find(dbg->edges, &edge_key, HASH_EDGE(&edge_key));
 
-       /* check if old target is marked for exchange */
-       key.irn = old_tgt;
-       entry   = pset_find(dbg->exchanged_nodes, &key, HASH_PTR(old_tgt));
+               /* check if old target is marked for exchange */
+               key.irn = old_tgt;
+               entry   = pset_find(dbg->exchanged_nodes, &key, HASH_PTR(old_tgt));
 
-       if (entry) {
-               /* we are called from exchange() */
-               entry->n_out_edges--;
-       }
+               if (entry) {
+                       /* we are called from exchange() */
+                       entry->n_out_edges--;
+               }
 
-       /* delete the old edge if it exists */
-       if (old_edge) {
-               snprintf(buf, sizeof(buf), "deleteEdge \"n%un%up%d\"\n", src_idx, old_tgt_idx, pos);
-               send_cmd(dbg, buf);
-               pset_remove(dbg->edges, old_edge, HASH_EDGE(old_edge));
+               /* delete the old edge if it exists */
+               if (old_edge) {
+                       snprintf(buf, sizeof(buf), "deleteEdge \"n%un%up%d\"\n", src_idx, old_tgt_idx, pos);
+                       send_cmd(dbg, buf);
+                       pset_remove(dbg->edges, old_edge, HASH_EDGE(old_edge));
+               }
        }
 
        if (! new_edge) {
@@ -393,7 +418,7 @@ static void firm_ycomp_debug_set_edge(void *context, ir_node *src, int pos, ir_n
 }
 
 /**
- * Put nodes, about to be exchanged into a set.
+ * Hook: Put nodes, about to be exchanged into a set.
  */
 static void firm_ycomp_debug_exchange(void *context, ir_node *old_node, ir_node *new_node) {
        firm_ycomp_dbg_t           *dbg = context;
@@ -417,7 +442,7 @@ static void firm_ycomp_debug_exchange(void *context, ir_node *old_node, ir_node
 }
 
 /**
- * Remove all old in edges, turn node into id node, add new input edge.
+ * Hook: Remove all old in edges, turn node into id node, add new input edge.
  */
 static void firm_ycomp_debug_turn_into_id(void *context, ir_node *old_node) {
        firm_ycomp_dbg_t           *dbg = context;
@@ -481,7 +506,7 @@ static void firm_ycomp_debug_turn_into_id(void *context, ir_node *old_node) {
 }
 
 /**
- * Just mark start/end of dead node elimination.
+ * Hook: Just mark start/end of dead node elimination.
  */
 static void firm_ycomp_debug_dead_node_elim(void *context, ir_graph *irg, int start) {
        firm_ycomp_dbg_t *dbg  = context;
@@ -491,7 +516,7 @@ static void firm_ycomp_debug_dead_node_elim(void *context, ir_graph *irg, int st
 /**
  * Establish connection to yComp and register all hooks.
  */
-void firm_init_ycomp_debugger(const char *host, uint16_t port) {
+void firm_init_ycomp_debugger(const char *host, unsigned port) {
        static int init_once = 0;
 
        if (init_once)