From 95016d86cd1ad652b9bd5c6b652b4fe85ceef003 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Wed, 6 Sep 2000 11:37:16 +0000 Subject: [PATCH] *** empty log message *** [r65] --- Changes | 13 +++++++++++ ir/ir/irdump.c | 51 ++++++++++++++++++++++++++++++++++++++----- ir/ir/irdump.h | 3 +++ ir/ir/irgraph.c | 1 + ir/ir/irprog.c | 28 ++++++++++++++++++++++++ ir/ir/irprog.h | 9 +++++--- ir/tr/entity.h | 9 -------- ir/tr/type.c | 19 +++++----------- ir/tr/type.h | 34 ++++++++++++++++------------- ir/tr/typewalk.c | 27 ++++++++++++++++++----- ir/tr/typewalk.h | 18 +++++++++++---- testprograms/Makefile | 2 +- testprograms/empty.c | 2 ++ 13 files changed, 159 insertions(+), 57 deletions(-) diff --git a/Changes b/Changes index 91cc102ce..2befc9f9d 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,16 @@ + 6.9.00 Goetz + Added irdump routine dump_all_types. + Did changes to irprog, type, typewalk to achieve this. + typewalk needs to walk along members, sub and supertypes, this + is still missing! irdump then needs to output these edges. + +====================================================================== +==================== New version: 0.2.5 ============================== +====================================================================== + + 3.9.00 Goetz + Made new Version: 0.2.5 + 15.8.2000 Goetz until 3.9.00 Separated irnode.h and many others into two files: one public one private. diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index 1e0ee2526..8462cf2ab 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -497,15 +497,13 @@ void vcg_open (ir_graph *irg, char *suffix) { int len; /** open file for vcg graph */ - id = get_entity_ld_name (irg->ent); - + id = get_entity_ld_name (get_irg_ent(irg)); len = id_to_strlen (id); cp = id_to_str (id); fname = malloc (len + 5 + strlen(suffix)); strcpy (fname, cp); /* copy the filename */ strcat (fname, suffix); /* append file suffix */ strcat (fname, ".vcg"); /* append the .vcg suffix */ - F = fopen (fname, "w"); /* open file for writing */ if (!F) { panic ("cannot open %s for writing (%m)", fname); /* not reached */ @@ -525,6 +523,34 @@ void vcg_open (ir_graph *irg, char *suffix) { xfprintf (F, "\n"); /* a separator */ } +void vcg_open_name (const char *name) { + char *fname; /* filename to put the vcg information in */ + int len; + + /** open file for vcg graph */ + len = strlen(name); + fname = malloc (len + 5); + strcpy (fname, name); /* copy the filename */ + strcat (fname, ".vcg"); /* append the .vcg suffix */ + F = fopen (fname, "w"); /* open file for writing */ + if (!F) { + panic ("cannot open %s for writing (%m)", fname); /* not reached */ + } + + /* print header */ + xfprintf (F, + "graph: { title: \"ir graph of %s\"\n" + "display_edge_labels: yes\n" + "layoutalgorithm: mindepth\n" + "manhattan_edges: yes\n" + "port_sharing: no\n" + "orientation: bottom_to_top\n" + "classname 1: \"Data\"\n" + "classname 2: \"Block\"\n", name); + + xfprintf (F, "\n"); /* a separator */ +} + void vcg_close () { xfprintf (F, "}\n"); /* print footer */ @@ -651,7 +677,8 @@ dump_cfg (ir_graph *irg) /***********************************************************************/ -/* the following routine dumps all type information */ +/* the following routine dumps all type information reachable from an */ +/* irg */ /***********************************************************************/ @@ -665,12 +692,24 @@ dump_type_graph (ir_graph *irg) vcg_open (irg, "-type"); /* walk over the blocks in the graph */ - type_walk(irg, dump_type_info, NULL, NULL); + type_walk_irg(irg, dump_type_info, NULL, NULL); vcg_close(); current_ir_graph = rem; } +/***********************************************************************/ +/* the following routine dumps all type information */ +/***********************************************************************/ + + +void +dump_all_types (void) +{ + vcg_open_name ("All_types"); + type_walk(dump_type_info, NULL, NULL); + vcg_close(); +} /***********************************************************************/ /* dumps a graph with type information */ @@ -690,7 +729,7 @@ dump_ir_graph_w_types (ir_graph *irg) /* irg_block_walk(irg->end, dump_ir_block, NULL, irg); */ irg_walk(irg->end, dump_whole_node, NULL, NULL); /* dump type info */ - type_walk(irg, dump_type_info, NULL, NULL); + type_walk_irg(irg, dump_type_info, NULL, NULL); /* dump edges from graph to type info */ irg_walk(irg->end, dump_node2type_edges, NULL, NULL); diff --git a/ir/ir/irdump.h b/ir/ir/irdump.h index 4a89a6ceb..c7862387e 100644 --- a/ir/ir/irdump.h +++ b/ir/ir/irdump.h @@ -31,6 +31,9 @@ void dump_cfg (ir_graph *irg); /* dumps the type information reachable from an ir graph. */ void dump_type_graph (ir_graph *irg); +/* dumps all type information (reachable from ir prog). */ +void dump_all_types (void); + /* dumps a graph and the type inforamtion. */ void dump_ir_graph_w_types (ir_graph *irg); diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index a433ad0b8..e930f3a12 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -221,6 +221,7 @@ set_irg_current_block (ir_graph *irg, ir_node *node) entity * get_irg_ent (ir_graph *irg) { + assert(irg && irg->ent); return irg->ent; } diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index d1b3ff50a..18c55e144 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -72,6 +72,13 @@ ir_graph *get_irp_irg(int pos){ return irp->graphs[pos+1]; } +void set_irp_irg(int pos, ir_graph *irg) { + assert (irp && irg); + assert (pos < (ARR_LEN((irp)->graphs) - 1)); + /* Strangely the first element of the array is NULL. Why?? */ + irp->graphs[pos+1] = irg; +} + /* Adds type to the list of types in irp. */ void add_irp_type(type *typ) { assert (typ != NULL); @@ -79,6 +86,27 @@ void add_irp_type(type *typ) { ARR_APP1 (type *, irp->types, typ); } +int get_irp_n_types (void) { + assert (irp && irp->types); + /* Strangely the first element of the array is NULL. Why?? */ + return (ARR_LEN((irp)->types) - 1); +} + +type *get_irp_type(int pos) { + assert (irp && irp->types); + /* Strangely the first element of the array is NULL. Why?? */ + return irp->types[pos+1]; + +} + +void set_irp_type(int pos, type *typ) { + assert (irp && typ); + assert (pos < (ARR_LEN((irp)->types) - 1)); + /* Strangely the first element of the array is NULL. Why?? */ + irp->types[pos+1] = typ; + +} + int get_irp_new_node_nr() { assert(irp); irp->max_node_nr = irp->max_node_nr + 1; diff --git a/ir/ir/irprog.h b/ir/ir/irprog.h index 117abbdb7..166dfdbee 100644 --- a/ir/ir/irprog.h +++ b/ir/ir/irprog.h @@ -26,10 +26,10 @@ struct ir_prog { ir_graph *main_irg; /* entry point to the compiled program */ /* or a list, in case we compile a library or the like? */ ir_graph **graphs; /* all graphs in the ir */ - type **types; /* all types in the ir */ type_class *glob_type; /* global type. Class as it can have fields and procedures. Does this work? Better name??? @@@ */ + type **types; /* all types in the ir */ /*struct obstack *obst; * @@@ Should we place all types and entities on an obstack, too? */ #ifdef DEBUG_libfirm @@ -58,10 +58,13 @@ void set_irp_main_irg(ir_graph *main_irg); void add_irp_irg(ir_graph *irg); int get_irp_n_irgs(); ir_graph *get_irp_irg(int pos); - /* set_irp_irg() und das gleiche fuer type */ +void set_irp_irg(int pos, ir_graph *irg); /* Adds type to the list of types in irp. */ -void add_irp_type(type *typ); +void add_irp_type(type *typ); +int get_irp_n_types(); +type *get_irp_type(int pos); +void set_irp_type(int pos, type *typ); /** Functions to access the fields of ir_prog **/ type_class *get_glob_type(void); diff --git a/ir/tr/entity.h b/ir/tr/entity.h index 8ae0fccbc..a36b85c8c 100644 --- a/ir/tr/entity.h +++ b/ir/tr/entity.h @@ -55,15 +55,6 @@ typedef struct ir_graph ir_graph; typedef struct entity entity; #endif -/*CS*/ -//#ifndef _TYPE_TYPEDEF_ -//#define _TYPE_TYPEDEF_ -/* to resolve recursion between entity.h and irgraph.h */ -//typedef union type type; -//#endif - -//typedef struct entity entity; - /* create a new entity */ entity *new_entity (type *owner, ident *name, type *type); diff --git a/ir/tr/type.c b/ir/tr/type.c index 9e77730a5..93047c0d9 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -11,6 +11,7 @@ # include "irprog.h" /* So that constructors can add the type to global data structure. */ # include "array.h" +# include "ident_t.h" unsigned long type_visited = 0; @@ -36,9 +37,6 @@ new_type_class (ident *name)//, int members) res->members = NEW_ARR_F (entity *, 1); res->subtypes = NEW_ARR_F (type_class *, 1); res->supertypes = NEW_ARR_F (type_class *, 1); - // res->n_members = 0; - // res->max_members = members; - // res->member = (entity **) xmalloc (sizeof (entity*) * members); res->visit = 0; @@ -138,23 +136,20 @@ new_type_strct (ident *name)//, int members) res->kind = k_type_strct; res->name = name; - // res->n_members = 0; - // res->max_members = members; - // res->member = (entity **) xmalloc (sizeof (entity*) * members); - + res->members = NEW_ARR_F (entity *, 1); res->visit = 0; return res; } /* manipulate fields of type_strct */ -/* -char * + +const char * get_strct_name (type_strct *strct) { assert(strct); return ID_TO_STR(strct->name); } -*/ + ident * get_strct_ident (type_strct *strct) { @@ -193,13 +188,11 @@ new_type_method (ident *name, int arity, int n_res) } /* manipulate fields of type_method */ -/* -char * +const char * get_method_name (type_method *method) { assert(method); return ID_TO_STR(method->name); } -*/ ident * get_method_ident (type_method *method) { diff --git a/ir/tr/type.h b/ir/tr/type.h index cd748c56c..a0daa0c64 100644 --- a/ir/tr/type.h +++ b/ir/tr/type.h @@ -248,13 +248,19 @@ type_class *get_class_supertype (type_class *class, int pos); void set_class_supertype (type_class *class, type_class *supertype, int pos); -/* get_class_entity_arr +/* get_class_n_entities get_class_entity(class, pos) set_class_entity(class, pos, entity) - get_class_sub_arr + get_class_n_sub ... - get_class_super_arr + + + Bitte implementieren, und dann in walker (Suche nach !!!! ) + einfuegen. + Genauso Struct!! + + Dann ev. noch in irdump Ausgabe der Kanten eingeben. */ /*******************************************************************/ @@ -264,10 +270,7 @@ void set_class_supertype (type_class *class, type_class *supertype, int pos); typedef struct { firm_kind kind; ident *name; - /** needs list with it's entities -- does it really?? - Entities can be added during their creation. - int n_members; - entity **member; **/ + entity **members; unsigned long visit; /* visited counter for walks of the type information */ } type_strct; @@ -276,7 +279,7 @@ typedef struct { type_strct *new_type_strct (ident *name); /* manipulate fields of type_strct */ -char *get_strct_name (type_strct *strct); +const char *get_strct_name (type_strct *strct); ident *get_strct_ident (type_strct *strct); /* void set_strct_name (type_strct *strct, char *name); @@ -303,11 +306,12 @@ typedef struct { unsigned long visit; /* visited counter for walks of the type information */ } type_method; -/* create a new type_method */ +/* create a new type_method + arity is number of parameters. */ type_method *new_type_method (ident *name, int arity, int n_res); /* manipulate fields of type_method */ -char *get_method_name (type_method *method); +const char *get_method_name (type_method *method); ident *get_method_ident (type_method *method); /* void set_method_name (type_method *method, char *name); @@ -340,7 +344,7 @@ typedef struct { type_union *new_type_union (ident *name, int n_types); /* manipulate fields of type_union */ -char *get_union_name (type_union *uni); +const char *get_union_name (type_union *uni); ident *get_union_ident (type_union *uni); /* void set_union_name (type_union *union, char *name); @@ -372,7 +376,7 @@ typedef struct { type_array *new_type_array (ident *name, int n_dimensions); /* manipulate fields of type_array */ -char *get_array_name (type_array *array); +const char *get_array_name (type_array *array); ident *get_array_ident (type_array *array); /* void set_array_name (type_array *array, char *name); @@ -414,7 +418,7 @@ typedef struct { type_enumeration *new_type_enumeration (ident *name /* , int n_enums */); /* manipulate fields of type_enumeration */ -char *get_enumeration_name (type_enumeration *enumeration); +const char *get_enumeration_name (type_enumeration *enumeration); ident *get_enumeration_ident (type_enumeration *enumeration); /* void set_enumeration_name (type_enumeration *enumeration, char *name); @@ -447,7 +451,7 @@ typedef struct { type_pointer *new_type_pointer (ident *name, type *points_to); /* manipulate fields of type_pointer */ -char *get_pointer_name (type_pointer *pointer); +const char *get_pointer_name (type_pointer *pointer); ident *get_pointer_ident (type_pointer *pointer); /* void set_pointer_name (type_pointer *pointer, char *name); @@ -474,7 +478,7 @@ typedef struct { type_primitive *new_type_primitive (ident *name, ir_mode *mode); /* manipulate fields of type_primitive */ -char *get_primitive_name (type_primitive *primitive); +const char *get_primitive_name (type_primitive *primitive); ident *get_primitive_ident (type_primitive *primitive); /* void set_primitive_name (type_primitive *primitive, char *name); diff --git a/ir/tr/typewalk.c b/ir/tr/typewalk.c index 362ff9e72..88e5f080d 100644 --- a/ir/tr/typewalk.c +++ b/ir/tr/typewalk.c @@ -9,11 +9,12 @@ ** - execute the post function after recursion */ -#include #include +#include #include "irgwalk.h" #include "irgraph.h" #include "irnode.h" +#include "irprog.h" #include "type_or_entity.h" /* Make types visible to allow most efficient access */ @@ -27,8 +28,9 @@ typedef struct type_walk_env { void type_walk_2(type_or_ent *tore, - void (pre)(type_or_ent*, void*), void (post)(type_or_ent*, void*), - void *env) + void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env) { int i, visited = 0; @@ -92,6 +94,7 @@ void type_walk_2(type_or_ent *tore, break; case k_type_union: ((type_union *)tore)->visit = type_visited; + /* !!!!! */ break; case k_type_array: ((type_array *)tore)->visit = type_visited; @@ -155,9 +158,21 @@ void start_type_walk(ir_node *node, void *env) { } } -void type_walk(ir_graph *irg, - void (pre)(type_or_ent*, void*), void (post)(type_or_ent*, void*), - void *env) +void type_walk(void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env) { + int i; + ++type_visited; + type_walk_2((type_or_ent *)get_glob_type(), pre, post, env); + for (i = 0; i < get_irp_n_types(); i++) { + type_walk_2((type_or_ent *)get_irp_type(i), pre, post, env); + } +} + +void type_walk_irg (ir_graph *irg, + void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env) { /* this is needed to pass the parameters to the walker that actually walks the type information */ diff --git a/ir/tr/typewalk.h b/ir/tr/typewalk.h index 2fb7ad53c..6b023f640 100644 --- a/ir/tr/typewalk.h +++ b/ir/tr/typewalk.h @@ -13,12 +13,22 @@ /* walk over all type information reachable from the ir graph. */ - +#ifndef _TYPEWALK_H_ +#define _TYPEWALK_H_ # include "type_or_entity.h" +/** dumps all type information reachable from global roots **/ +void type_walk(void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env); + /** dumps all type information reachable from irg **/ -void type_walk(ir_graph *irg, - void (pre)(type_or_ent*, void*), void (post)(type_or_ent*, void*), - void *env); +void type_walk_irg(ir_graph *irg, + void (pre)(type_or_ent*, void*), + void (post)(type_or_ent*, void*), + void *env); + + +#endif /* _TYPEWALK_H_ */ diff --git a/testprograms/Makefile b/testprograms/Makefile index 588cfedb5..bbee5b445 100644 --- a/testprograms/Makefile +++ b/testprograms/Makefile @@ -2,7 +2,7 @@ DIRS = adt common debug ident ir tr tv INCDIRS = -I../include LIBDIRS=-L.. -L/usr/public/lib/gmp/ -LIBS=-lfirm -lgmp -lm +LIBS=-lfirm -lgmp %.o: %.c gcc -c $(INCDIRS) -g $< diff --git a/testprograms/empty.c b/testprograms/empty.c index f00430d63..238da87bd 100644 --- a/testprograms/empty.c +++ b/testprograms/empty.c @@ -92,6 +92,8 @@ int main(int argc, char **argv) printf("Done building the graph. Dumping it.\n"); dump_ir_block_graph (irg); + dump_all_types(); + printf("use xvcg to view this graph:\n"); printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n"); -- 2.20.1