From 2da89aec2e7d54d70940cccfa82f74c83e5221eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Wed, 11 Jul 2001 13:28:09 +0000 Subject: [PATCH] Errors and Features of type_id stuff C [r225] --- ir/ir/irprog.c | 4 ++-- ir/ir/irprog.h | 14 ++++++++++++++ ir/tr/entity.c | 2 +- ir/tr/tpop.c | 1 + ir/tr/tpop.h | 4 ++-- ir/tr/type.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++- ir/tr/type_t.h | 11 +++++++++++ ir/tr/typegmod.c | 23 ++++++++++++++-------- ir/tr/typegmod.h | 5 +++-- 9 files changed, 98 insertions(+), 16 deletions(-) diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index 1858224f6..963ae93e0 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -108,8 +108,8 @@ int get_irp_n_types (void) { type *get_irp_type(int pos) { assert (irp && irp->types); /* Strangely the first element of the array is NULL. Why?? */ - /* Don't set the skip_id result so that no double entries are generated. */ - return skip_id(irp->types[pos+1]); + /* Don't set the skip_tid result so that no double entries are generated. */ + return skip_tid(irp->types[pos+1]); } void set_irp_type(int pos, type *typ) { diff --git a/ir/ir/irprog.h b/ir/ir/irprog.h index ab9f5a19a..e8b2296f0 100644 --- a/ir/ir/irprog.h +++ b/ir/ir/irprog.h @@ -29,6 +29,20 @@ * * SOURCE */ + +/***s* irprog/irprog + * + * NAME Datastructure that holds central information about a program + * + * NOTE Preliminary documentation ;-) + * + * FIELDS + * type A list containing all types known to the translated program. + * Some types can have several entries in this list (as a result of + * using exchange_types()). + * ... + * SOURCE + */ typedef struct ir_prog ir_prog; /* A variable from where everything in the ir can be accessed. */ diff --git a/ir/tr/entity.c b/ir/tr/entity.c index ec5c6d551..b9b50f18c 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -12,8 +12,8 @@ # include # include # include "entity_t.h" -# include "entity.h" # include "mangle.h" +# include "typegmod_t.h" /*******************************************************************/ /** general **/ diff --git a/ir/tr/tpop.c b/ir/tr/tpop.c index 217c2b32c..877420419 100644 --- a/ir/tr/tpop.c +++ b/ir/tr/tpop.c @@ -20,6 +20,7 @@ tp_op *type_array; tp_op *type_enumeration; tp_op *type_pointer; tp_op *type_primitive; +tp_op *type_id; tp_op * new_tpop (tp_opcode code, ident *name, size_t attr_size) diff --git a/ir/tr/tpop.h b/ir/tr/tpop.h index 13267d8ad..35413541e 100644 --- a/ir/tr/tpop.h +++ b/ir/tr/tpop.h @@ -232,7 +232,7 @@ extern tp_op *type_primitive; * PURPOSE * This type opcode is an auxiliary opcode dedicated to support transformations * of the type structure. If a type is changed to another type with another - * opcode the new type will be allocated with new memory. All nodes refereing + * opcode the new type will be allocated with new memory. All nodes refering * to the old type need to be changed to refer the new one. This is simplified * by turning the old type into an id type that merely forwards to the new type * that now replaces the old one. @@ -240,7 +240,7 @@ extern tp_op *type_primitive; * should automatically check for type_id and eventually follow the forward in * type_id. Two types are exchanged by a call to exchange_types. * If a type_id is visible externally report this as bug. If it is assured that - * this never happens this extern variable can be moved to type_t.h. + * this never happens this extern variable can be moved to tpop_t.h. * NOTES * This struct is dynamically allocated but constant for the lifetime * of the library. diff --git a/ir/tr/type.c b/ir/tr/type.c index 98b8c4805..a3b42b47b 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -63,6 +63,20 @@ new_type(tp_op *type_op, ir_mode *mode, ident* name) { return res; } +void free_type_attrs(type *tp) { + switch(get_type_tpop_code(tp)) { + case tpo_class: { free_class_attrs(tp); } break; + case tpo_struct: { free_struct_attrs(tp); } break; + case tpo_method: { free_method_attrs(tp); } break; + case tpo_union: { free_union_attrs(tp); } break; + case tpo_array: { free_array_attrs(tp); } break; + case tpo_enumeration: { free_enumeration_attrs(tp); } break; + case tpo_pointer: { free_pointer_attrs(tp); } break; + case tpo_primitive: { free_primitive_attrs(tp); } break; + default: break; + } +} + tp_op* get_type_tpop(type *tp) { assert(tp); return tp->type_op; @@ -170,6 +184,12 @@ type *new_type_class (ident *name) { return res; } +inline void free_class_attrs(type *clss) { + assert(clss && (clss->type_op == type_class)); + DEL_ARR_F(clss->attr.ca.members); + DEL_ARR_F(clss->attr.ca.subtypes); + DEL_ARR_F(clss->attr.ca.supertypes); +} /* manipulate private fields of class type */ void add_class_member (type *clss, entity *member) { assert(clss && (clss->type_op == type_class)); @@ -273,6 +293,10 @@ type *new_type_struct (ident *name) { res->attr.sa.members = NEW_ARR_F (entity *, 1); return res; } +inline void free_struct_attrs (type *strct) { + assert(strct && (strct->type_op == type_struct)); + DEL_ARR_F(strct->attr.sa.members); +} /* manipulate private fields of struct */ void add_struct_member (type *strct, entity *member) { assert(strct && (strct->type_op == type_struct)); @@ -322,7 +346,11 @@ type *new_type_method (ident *name, int n_param, int n_res) { res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res); return res; } - +inline void free_method_attrs(type *method) { + assert(method && (method->type_op == type_method)); + free(method->attr.ma.param_type); + free(method->attr.ma.res_type); +} /* manipulate private fields of method. */ int get_method_n_params (type *method) { assert(method && (method->type_op == type_method)); @@ -370,6 +398,10 @@ type *new_type_uni (ident *name) { res->attr.ua.members = NEW_ARR_F (entity *, 1); return res; } +inline void free_union_attrs (type *uni) { + assert(uni && (uni->type_op == type_union)); + DEL_ARR_F(uni->attr.ua.members); +} /* manipulate private fields of struct */ #if 0 int get_union_n_types (type *uni) { @@ -448,6 +480,11 @@ type *new_type_array (ident *name, int n_dimensions, new_entity(res, name, element_type); return res; } +inline void free_array_attrs (type *array) { + assert(array && (array->type_op == type_array)); + free(array->attr.aa.lower_bound); + free(array->attr.aa.upper_bound); +} /* manipulate private fields of array type */ int get_array_n_dimensions (type *array) { @@ -512,6 +549,11 @@ type *new_type_enumeration (ident *name, int n_enums) { res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums); return res; } +inline void free_enumeration_attrs(type *enumeration) { + assert(enumeration && (enumeration->type_op == type_enumeration)); + free(enumeration->attr.ea.enumer); + free(enumeration->attr.ea.enum_nameid); +} /* manipulate fields of enumeration type. */ int get_enumeration_n_enums (type *enumeration) { @@ -558,6 +600,9 @@ type *new_type_pointer (ident *name, type *points_to) { res->state = layout_fixed; return res; } +inline void free_pointer_attrs (type *pointer) { + assert(pointer && (pointer->type_op == type_pointer)); +} /* manipulate fields of type_pointer */ void set_pointer_points_to_type (type *pointer, type *type) { assert(pointer && (pointer->type_op == type_pointer)); @@ -587,6 +632,9 @@ type *new_type_primitive (ident *name, ir_mode *mode) { res->state = layout_fixed; return res; } +inline void free_primitive_attrs (type *primitive) { + assert(primitive && (primitive->type_op == type_primitive)); +} /* typecheck */ bool is_primitive_type (type *primitive) { diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h index 2d0737ffa..3229d2fbc 100644 --- a/ir/tr/type_t.h +++ b/ir/tr/type_t.h @@ -126,5 +126,16 @@ inline type * new_type(tp_op *type_op, ir_mode *mode, ident* name); +void free_type_attrs (type *tp); + +inline void free_class_attrs (type *clss); +inline void free_struct_attrs (type *strct); +inline void free_method_attrs (type *method); +inline void free_union_attrs (type *uni); +inline void free_array_attrs (type *array); +inline void free_enumeration_attrs(type *enumeration); +inline void free_pointer_attrs (type *pointer); +inline void free_primitive_attrs (type *primitive); + # endif /* _TYPE_T_H_ */ diff --git a/ir/tr/typegmod.c b/ir/tr/typegmod.c index d6138fc11..4a44ef97e 100644 --- a/ir/tr/typegmod.c +++ b/ir/tr/typegmod.c @@ -13,15 +13,22 @@ inline void exchange_types(type *old_type, type *new_type) { int i; /* Deallocate datastructures not directly contained in the - old type */ - /* @@@@ */ + old type. We must do this now as it is the latest point + where we know the original kind of type. + */ + free_type_attrs(old_type); - /* Remove old type from type list. Will this confuscate the - iterators? */ - /* @@@ */ - - /* Ev. add to a list of id types for later deallocation. */ - /* @@@ */ + /* @@@@ + Things to deal with: + * After exchange_types the type has two entries in the list of + all types in irp. So far this is fine for the walker. + Maybe it's better to remove the id entry and shrink the list. + Does this conflict with the walker? Might a type be left out + during the walk? + * Deallocation: if the Id is removed from the list it will eventualle + disappear in a memory leak. When is impossible to determine so we + need to hold it in a seperate list for deallocation. + */ /* Exchange the types */ old_type->type_op = type_id; diff --git a/ir/tr/typegmod.h b/ir/tr/typegmod.h index d6490b469..1077fe59a 100644 --- a/ir/tr/typegmod.h +++ b/ir/tr/typegmod.h @@ -28,8 +28,9 @@ * SIDE EFFECTS * Old type is replaced by new_type. All references to old_type * now point to new_type. The memory for the old type is destroyed, - * but still used. Therefore it is not freed. The memory will - * be lost after a certain while. + * but still used. Therefore it is not freed. + * All referenced to this memory will be lost after a certain while. + * An exception is the list of types in irp (irprog.h). * In the future there might be a routine to recover the memory, but * this will be at considerable runtime cost. *** -- 2.20.1