From 4e8a56afc72bd6c3ad90158eeb9975d3fa37c604 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Thu, 9 Jan 2003 16:54:23 +0000 Subject: [PATCH] Added function to dump classgraph [r586] --- ir/ir/irdump.c | 126 ++++++++++++++++++++++++++++++++++++------------- ir/ir/irdump.h | 23 +++++++++ 2 files changed, 116 insertions(+), 33 deletions(-) diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index cf71cd457..5f7b6c960 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -59,7 +59,7 @@ #define ENT_OWN_EDGE_ATTR "class: 4 label: \"owner\" color: black" #define METH_PAR_EDGE_ATTR "class: 5 label: \"param %d\" color: green" #define METH_RES_EDGE_ATTR "class: 6 label: \"res %d\" color: green" -#define TYPE_SUPER_EDGE_ATTR "class: 7 label: \"supertype\" color: blue" +#define TYPE_SUPER_EDGE_ATTR "class: 7 label: \"supertype\" color: red" #define UNION_EDGE_ATTR "class: 8 label: \"component\" color: blue" #define PTR_PTS_TO_EDGE_ATTR "class: 9 label: \"points to\" color:green" #define ARR_ELT_TYPE_EDGE_ATTR "class: 10 label: \"arr elt tp\" color:green" @@ -804,6 +804,41 @@ static void print_type_node(type *tp) { xfprintf (F, "}\n"); } +void dump_entity_node(entity *ent) { + xfprintf (F, "node: {title: \"%p\" ", ent); + xfprintf (F, DEFAULT_TYPE_ATTRIBUTE); + xfprintf (F, "label: "); + xfprintf (F, "\"ent %I\" " ENTITY_NODE_ATTR , get_entity_ident(ent)); + switch (get_entity_allocation(ent)) { + case dynamic_allocated: fprintf (F, " info1:\"dynamic allocated\n"); break; + case automatic_allocated: fprintf (F, " info1:\"automatic allocated\n"); break; + case static_allocated: fprintf (F, " info1:\"static allocated\n"); break; + } + switch (get_entity_visibility(ent)) { + case local: fprintf (F, "local\n"); break; + case external_visible: fprintf (F, "external_visible\n"); break; + case external_allocated: fprintf (F, "external_allocate\n"); break; + } + switch (get_entity_variability(ent)) { + case uninitialized: fprintf (F, "uninitialized\n");break; + case initialized: fprintf (F, "initialized\n"); break; + case part_constant: fprintf (F, "part_constant\n");break; + case constant: fprintf (F, "constant\n"); break; + } + switch (get_entity_volatility(ent)) { + case non_volatile: fprintf (F, "non_volatile\n"); break; + case is_volatile: fprintf (F, "is_volatile\n"); break; + } + switch (get_entity_peculiarity(ent)) { + case description: fprintf (F, "description\n"); break; + case inherited: fprintf (F, "inherited\n"); break; + case existent: fprintf (F, "existent\n"); break; + } + if (is_method_type(get_entity_type(ent))) + xfprintf (F, "\n irg = %p ", get_entity_irg(ent)); + xfprintf(F, "\"}\n"); +} + /* dumps a type or entity and it's edges. */ static void dump_type_info (type_or_ent *tore, void *env) { @@ -817,38 +852,7 @@ dump_type_info (type_or_ent *tore, void *env) { entity *ent = (entity *)tore; ir_node *value; /* The node */ - xfprintf (F, "node: {title: \"%p\" ", tore); - xfprintf (F, DEFAULT_TYPE_ATTRIBUTE); - xfprintf (F, "label: "); - xfprintf (F, "\"ent %I\" " ENTITY_NODE_ATTR , get_entity_ident(ent)); - switch (get_entity_allocation(ent)) { - case dynamic_allocated: fprintf (F, " info1:\"dynamic allocated\n"); break; - case automatic_allocated: fprintf (F, " info1:\"automatic allocated\n"); break; - case static_allocated: fprintf (F, " info1:\"static allocated\n"); break; - } - switch (get_entity_visibility(ent)) { - case local: fprintf (F, "local\n"); break; - case external_visible: fprintf (F, "external_visible\n"); break; - case external_allocated: fprintf (F, "external_allocate\n"); break; - } - switch (get_entity_variability(ent)) { - case uninitialized: fprintf (F, "uninitialized\n");break; - case initialized: fprintf (F, "initialized\n"); break; - case part_constant: fprintf (F, "part_constant\n");break; - case constant: fprintf (F, "constant\n"); break; - } - switch (get_entity_volatility(ent)) { - case non_volatile: fprintf (F, "non_volatile\n"); break; - case is_volatile: fprintf (F, "is_volatile\n"); break; - } - switch (get_entity_peculiarity(ent)) { - case description: fprintf (F, "description\n"); break; - case inherited: fprintf (F, "inherited\n"); break; - case existent: fprintf (F, "existent\n"); break; - } - if (is_method_type(get_entity_type(ent))) - xfprintf (F, "\n irg = %p ", get_entity_irg(ent)); - xfprintf(F, "\"}\n"); + dump_entity_node(ent); /* The Edges */ /* skip this to reduce graph. Member edge of type is parallel to this edge. * xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" " @@ -956,6 +960,51 @@ dump_type_info (type_or_ent *tore, void *env) { } /* switch kind_or_entity */ } +/* dumps a class type node and a superclass edge. + If env != null dumps entities of classes and overwrites edges. */ +static void +dump_class_hierarchy_node (type_or_ent *tore, void *env) { + int i = 0; /* to shutup gcc */ + + /* dump this type or entity */ + switch (get_kind(tore)) { + case k_entity: { + entity *ent = (entity *)tore; + if ((env) && is_class_type(get_entity_owner(ent))) { + /* The node */ + dump_entity_node(ent); + /* The edges */ + xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" " + TYPE_MEMBER_EDGE_ATTR "}\n", get_entity_owner(ent), ent); + for(i = 0; i < get_entity_n_overwrites(ent); i++) + xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" " + ENT_OVERWRITES_EDGE_ATTR "}\n", + ent, get_entity_overwrites(ent, i)); + } + } break; /* case k_entity */ + case k_type: + { + type *tp = (type *)tore; + switch (get_type_tpop_code(tp)) { + case tpo_class: { + print_type_node(tp); + /* and now the edges */ + for (i=0; i < get_class_n_supertypes(tp); i++) + xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" " + TYPE_SUPER_EDGE_ATTR "}\n", + tp, get_class_supertype(tp, i)); + } break; + default: break; + } /* switch type */ + } + break; /* case k_type */ + default: + { + printf(" *** irdump, %s(l.%i), faulty type.\n", __FUNCTION__, __LINE__); + } break; + } /* switch kind_or_entity */ +} + /************************************************************************/ /* open and close vcg file */ /************************************************************************/ @@ -1319,6 +1368,17 @@ dump_all_types (void) vcg_close(); } +void +dump_class_hierarchy (bool entities) +{ + vcg_open_name ("class_hierarchy"); + if (entities) + type_walk(dump_class_hierarchy_node, NULL, (void *)1); + else + type_walk(dump_class_hierarchy_node, NULL, NULL); + vcg_close(); +} + /***********************************************************************/ /* dumps a graph with type information */ /***********************************************************************/ diff --git a/ir/ir/irdump.h b/ir/ir/irdump.h index a0861da6b..b170f3281 100644 --- a/ir/ir/irdump.h +++ b/ir/ir/irdump.h @@ -142,6 +142,29 @@ void dump_type_graph (ir_graph *irg); */ void dump_all_types (void); +/****m* irdump/dump_class_hierarchy + * + * NAME + * dump_class_hierarchy -- Dumps the class hierarchy with or without entities. + * SYNOPSIS + * void dump_class_hierarchy (bool entities); + * FUNCTION + * Dumps a node for all classes and the sub/supertype relations. If + * entities is set to true also dumps the entities of classes, but without + * any additional information as the entities type. The overwrites relation + * is dumped along with the entities. + * Dumps to a file class_hierarchy.vcg + * INPUTS + * Flag whether to dump the entities. + * RESULT + * A file containing the class hierarchy tree for the program in standard + * vcg format. + * SEE ALSO + * + *** + */ +void dump_class_hierarchy (bool entities); + /****m* irdump/dump_ir_graph_w_types * * NAME -- 2.20.1