X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana2%2Fpto_name.c;h=8c667b5721c5a0c412dcae64da71e22942fbc26c;hb=38b189871c997acdf0caf0c5a96c4eccfab51ef4;hp=ac64ec62e078c00da79cc3bd98b2a21d0a646030;hpb=f001e5b3cb89f984c977a9f7d4aef02cc3cc56eb;p=libfirm diff --git a/ir/ana2/pto_name.c b/ir/ana2/pto_name.c index ac64ec62e..8c667b572 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 @@ -33,6 +33,7 @@ # include "xmalloc.h" # include "pto_debug.h" +# include "gnu_ext.h" /* Local Defines: */ # define obstack_chunk_alloc xmalloc @@ -50,18 +51,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) +{ + int col_idx = 0; + + if (0 != desc->col_idx) { + return (desc->col_idx); + } + + 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 */ + if (is_Primitive_type (tp) || is_Pointer_type (tp)) { + /* actually, we don't get by by restricting ourselves to pointer types */ return (TRUE); } else { return (FALSE); @@ -97,36 +237,40 @@ static void _collect_fields (type *clazz, struct obstack *obst) The last entry of the array is written NULL. */ static entity **collect_fields (type *clazz) { + struct obstack obst; + int n_fields; + entity ** fields; + void *tmp; + if (NULL != get_type_link (clazz)) { DBGPRINT (3, (stdout, "%s: reusing field list for \"%s\"\n", - __FUNCTION__, get_type_name (clazz))); + __FUNCTION__, + get_type_name (clazz))); return ((entity **) get_type_link (clazz)); } else { DBGPRINT (2, (stdout, "%s: new field list for \"%s\"\n", - __FUNCTION__, get_type_name (clazz))); + __FUNCTION__, + get_type_name (clazz))); } - struct obstack obst; - obstack_init (&obst); _collect_fields (clazz, &obst); /* append terminating NULL */ - int *the_null = NULL; - obstack_ptr_grow (&obst, the_null); + obstack_ptr_grow (&obst, NULL); - int n_fields = obstack_object_size (&obst) / sizeof (void*); + n_fields = obstack_object_size (&obst) / sizeof (void*); - entity ** fields = (entity**) NALLOC (n_fields * sizeof (entity*)); - void *tmp = obstack_finish (&obst); + fields = NALLOC (n_fields * sizeof (entity*)); + tmp = obstack_finish(&obst); memcpy (fields, tmp, n_fields * sizeof (entity*)); obstack_free (&obst, NULL); - set_type_link (clazz, (void*) fields); + set_type_link (clazz, fields); return (fields); } @@ -134,8 +278,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"); @@ -152,21 +300,38 @@ static void pto_name_dump_desc (desc_t *desc, FILE *stream) { type *tp = desc->tp; const char *tp_name = get_type_name (tp); + ir_node *nd; fprintf (stream, "\t/* %s \"%s\" */\n", object == desc->kind ? "Object" : "Array", tp_name); - fprintf (stream, "\tdesc_%i [label=\"
type=\\\"%s\\\"", - desc->id, + fprintf (stream, "\tdesc_%i [label=\"type \\[%i\\]", + desc->id, desc->id); + + if (-1 != desc->ctx) { + fprintf (stream, ", ctx = %i", desc->ctx); + } else { + fprintf (stream, " (global)"); + } + + fprintf (stream, "\\lname=\\\"%s\\\"", tp_name); - ir_node *nd = desc->node; + nd = desc->node; if (NULL != nd) { - fprintf (stream, "|