From: Florian Liekweg Date: Mon, 6 Dec 2004 12:52:09 +0000 (+0000) Subject: colorize name dump X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=891f9324d9d7883a8854370be024af3280558423;p=libfirm colorize name dump [r4572] --- diff --git a/ir/ana2/pto_name.c b/ir/ana2/pto_name.c index ac64ec62e..92cc4b3a9 100644 --- a/ir/ana2/pto_name.c +++ b/ir/ana2/pto_name.c @@ -12,9 +12,9 @@ Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +# ifdef HAVE_CONFIG_H +# include "config.h" +# endif /* pto_name: Names for abstract objects @@ -50,18 +50,157 @@ static desc_t *all_descs = NULL; static int name_id = 0; +# define PTO_COLOR + +# ifdef PTO_COLOR +static int last_col_idx = 0; + /* Local Prototypes: */ +static int pto_name_alloc_color (desc_t*); +static void pto_name_set_color (desc_t*, int); +# endif /* defined PTO_COLOR */ /* =================================================== Local Implementation: =================================================== */ +# ifdef PTO_COLOR +/* set a nice color to an object descriptor */ +static void pto_name_set_obj_color (obj_desc_t *obj_desc, int col_idx) +{ + int i; + + for (i = 0; i < obj_desc->n_fields; i ++) { + qset_t *ptos = obj_desc->values [i]; + + desc_t *tgt = (desc_t*) qset_start (ptos); + + while (NULL != tgt) { + pto_name_set_color (tgt, col_idx); + + tgt = (desc_t*) qset_next (ptos); + } + } +} + +/* set a nice color to an array descriptor */ +static void pto_name_set_arr_color (arr_desc_t *arr_desc, int col_idx) +{ + qset_t *ptos = arr_desc->value; + + desc_t *tgt = (desc_t*) qset_start (ptos); + + while (NULL != tgt) { + pto_name_set_color (tgt, col_idx); + + tgt = (desc_t*) qset_next (ptos); + } +} + +/* set a nice color to a descriptor */ +static void pto_name_set_color (desc_t *desc, int col_idx) +{ + /* assert (0 == desc->col_idx); */ + + desc->col_idx = col_idx; + + if (FALSE == desc->visit) { + desc->visit = TRUE; + if (object == desc->kind) { + pto_name_set_obj_color ((obj_desc_t*) desc, col_idx); + } else if (array == desc->kind) { + pto_name_set_arr_color ((arr_desc_t*) desc, col_idx); + } + + desc->visit = FALSE; + } +} + + +/* allocate nice colors for an object descriptor */ +static int pto_name_alloc_obj_color (obj_desc_t *obj_desc) +{ + int i; + int col_idx = 0; + + for (i = 0; (0 == col_idx) && (i < obj_desc->n_fields); i ++) { + qset_t *ptos = obj_desc->values [i]; + desc_t *tgt = (desc_t*) qset_start (ptos); + + while ((0 == col_idx) && (NULL != tgt)) { + col_idx = pto_name_alloc_color (tgt); + + tgt = (desc_t*) qset_next (ptos); + } + } + + return (col_idx); +} + +/* allocate nice colors for an array descriptor */ +static int pto_name_alloc_arr_color (arr_desc_t *arr_desc) +{ + int col_idx = 0; + + qset_t *ptos = arr_desc->value; + + desc_t *tgt = (desc_t*) qset_start (ptos); + + while ((NULL != tgt) && (0 == col_idx)) { + col_idx = pto_name_alloc_color (tgt); + tgt = (desc_t*) qset_next (ptos); + } + + return (col_idx); +} + +/* allocate nice colors for the given descriptor */ +static int pto_name_alloc_color (desc_t *desc) +{ + if (0 != desc->col_idx) { + return (desc->col_idx); + } + + int col_idx = 0; + + if (FALSE == desc->visit) { + desc->visit = TRUE; + if (object == desc->kind) { + col_idx = pto_name_alloc_obj_color ((obj_desc_t*) desc); + } else if (array == desc->kind) { + col_idx = pto_name_alloc_arr_color ((arr_desc_t*) desc); + } + desc->visit = FALSE; + } + + if (0 == col_idx) { + col_idx = ++ last_col_idx; + } + + pto_name_set_color (desc, col_idx); + + return (col_idx); +} + +/* allocate nice colors */ +static void pto_name_alloc_colors (void) +{ + desc_t *desc = all_descs; + + while (NULL != desc) { + pto_name_alloc_color (desc); + + desc = desc->prev; + } +} +# endif /* defined PTO_COLOR */ + /* See whether the given entity is a field. */ static int is_field (entity *ent) { type *tp = get_entity_type (ent); if (is_primitive_type (tp) || is_pointer_type (tp)) { - /* actually, we could get by by restricting ourselves to pointer types */ + /* actually, we don't get by by restricting ourselves to pointer types */ return (TRUE); } else { return (FALSE); @@ -134,8 +273,12 @@ static entity **collect_fields (type *clazz) /* Write the intro text for a name dump into the given stream */ static void pto_name_dump_start (FILE *stream) { +# ifdef PTO_COLOR + pto_name_alloc_colors (); +# endif /* defined PTO_COLOR */ + fprintf (stream, "digraph \"Names\" {\n"); - fprintf (stream, "\tgraph [rankdir=\"LR\", ordering=\"out\"];\n"); + fprintf (stream, "\tgraph [rankdir=\"LR\", ordering=\"out\", size=\"11,7\", rotate=\"90\"];\n"); fprintf (stream, "\tnode [shape=\"record\", style=\"filled\"];\n"); fprintf (stream, "\tedge [color=\"black\"];\n"); fprintf (stream, "\n"); @@ -157,16 +300,25 @@ static void pto_name_dump_desc (desc_t *desc, FILE *stream) object == desc->kind ? "Object" : "Array", tp_name); - fprintf (stream, "\tdesc_%i [label=\"type=\\\"%s\\\"", + fprintf (stream, "\tdesc_%i [label=\"type \\[%i\\]\\lname=\\\"%s\\\"", + desc->id, desc->id, tp_name); ir_node *nd = desc->node; if (NULL != nd) { - fprintf (stream, "|node=%s\\[%li\\]", + ir_graph *graph = get_irn_irg (nd); + entity *method = get_irg_entity (graph); + const char *ent_name = get_entity_name (method); + const char *own_name = get_type_name (get_entity_owner (method)); + + fprintf (stream, "\\lnode=%s\\[%li\\]", get_op_name (get_irn_op (nd)), get_irn_node_nr (nd)); + fprintf (stream, "\\lgraph=\\\"%s.%s\\\"", + own_name, + ent_name); } if (desc->kind == object) { @@ -174,9 +326,13 @@ static void pto_name_dump_desc (desc_t *desc, FILE *stream) int i; for (i = 0; i < obj_desc->n_fields; i ++) { - const char *ent_name = get_entity_name (obj_desc->fields [i]); + entity *field = obj_desc->fields [i]; + + if (is_pointer_type (get_entity_type (field))) { + const char *ent_name = get_entity_name (field); - fprintf (stream, "|<%i>%s", i, ent_name); + fprintf (stream, "|<%i>%s", i, ent_name); + } } } else if (array == desc->kind) { arr_desc_t *arr_desc = (arr_desc_t*) desc; @@ -186,7 +342,54 @@ static void pto_name_dump_desc (desc_t *desc, FILE *stream) assert (0 && "invalid descriptor"); } - fprintf (stream, "\"];\n"); + /* end label string */ + fprintf (stream, "\""); + +# ifdef PTO_COLOR + int col_idx = desc->col_idx; + float hue = (float) col_idx / (float) last_col_idx; + float sat = 1.000; /* 0.300 .. 1.000 */ + float val = 1.000; /* 0.300 .. 1.000 */ + +# define MAX_COLORS 12 + if (last_col_idx > MAX_COLORS) { + /* too many colors ... vary value too */ + float div = (float) MAX_COLORS / (float) last_col_idx; + + sat = (div * ((col_idx / MAX_COLORS))); + val = (div * ((col_idx / MAX_COLORS))); + + col_idx = col_idx % MAX_COLORS; + hue = (float) col_idx / (float) MAX_COLORS; + } +# undef MAX_COLORS + + // re-adjust sat and val + { + const float sat_min = 0.200; /* 0.200 .. 0.400 */ + const float val_min = 0.300; /* 0.300 .. 0.400 */ + + sat = sat_min + ((1.0 - sat_min) * sat); + val = val_min + ((1.0 - val_min) * val); + } + + fprintf (stream, ", color=\"%01.3f, %01.3f, %01.3f\"", hue, sat, val); + + char *fontcolor; + + if ((hue > 0.3) && (sat < 0.5)) { + fontcolor = "white"; + } else if (sat < 0.4) { + fontcolor = "white"; + } else { + fontcolor = "black"; + } + + fprintf (stream, ", fontcolor=\"%s\"", fontcolor); +# endif /* defined PTO_COLOR */ + + /* end attributes */ + fprintf (stream, "];\n"); fprintf (stream, "\n"); /* now the edges */ @@ -291,7 +494,9 @@ desc_t *new_name (type *tp, ir_node *node) } desc->id = name_id ++; + desc->col_idx = 0; desc->tp = tp; + desc->visit = FALSE; desc->node = node; desc->prev = all_descs; @@ -323,6 +528,8 @@ desc_t *new_ent_name (entity *ent) obj_glob = (obj_desc_t*) NALLOC (sizeof (obj_desc_t)); obj_glob->id = name_id ++; + obj_glob->col_idx = 0; + obj_glob->visit = FALSE; obj_glob->kind = object; obj_glob->tp = get_glob_type (); obj_glob->node = NULL; @@ -424,8 +631,8 @@ void pto_name_cleanup () /* $Log$ - Revision 1.5 2004/12/02 16:17:51 beck - fixed config.h include + Revision 1.6 2004/12/06 12:52:09 liekweg + colorize name dump Revision 1.4 2004/11/30 15:49:27 liekweg include 'dump' diff --git a/ir/ana2/pto_name.h b/ir/ana2/pto_name.h index 86c79f621..cbc28f389 100644 --- a/ir/ana2/pto_name.h +++ b/ir/ana2/pto_name.h @@ -38,6 +38,8 @@ typedef enum desc_kind_enum { typedef struct desc_str { int id; + int visit; + int col_idx; desc_kind_t kind; type *tp; ir_node *node; /* allocation node */ @@ -48,6 +50,8 @@ typedef struct desc_str typedef struct obj_desc_str { int id; + int visit; + int col_idx; desc_kind_t kind; type *tp; ir_node *node; /* allocation node */ @@ -62,6 +66,8 @@ typedef struct obj_desc_str typedef struct arr_desc_str { int id; + int visit; + int col_idx; desc_kind_t kind; type *tp; ir_node *node; /* allocation node */ @@ -102,6 +108,9 @@ void pto_name_cleanup (void); /* $Log$ + Revision 1.5 2004/12/06 12:52:09 liekweg + colorize name dump + Revision 1.4 2004/11/30 15:49:27 liekweg include 'dump'