X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Fentity.c;h=380ee1ef0ea3e0a51f17ec4ec9b4c1e461b5c2da;hb=d6a4592afc658544100e136acaf09902b710b7e7;hp=a02b8e1071c923e66029969948a4cbfc94cad62d;hpb=bb9f2e36362333c6635b89f5258171b06c786608;p=libfirm diff --git a/ir/tr/entity.c b/ir/tr/entity.c index a02b8e107..380ee1ef0 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -46,34 +46,6 @@ #include "callgraph.h" #include "error.h" -/** - * An interval initializer. - */ -typedef struct interval_initializer interval_initializer; - -/** - * A value initializer. - */ -typedef struct value_initializer value_initializer; - -struct interval_initializer { - int first_index; /**< The first index of the initialized interval. */ - int last_index; /**< The last index of the initialized interval. */ - interval_initializer *next; /**< Points to the next interval initializer. */ -}; - -struct value_initializer { - ir_entity *ent; /**< The initialized entity. */ - value_initializer *next; /**< Points to the next value initializer. */ -}; - -typedef union initializer { - ir_node *value; /**< The value of the initializer. */ - ir_node **values; /**< The values of an interval. */ - value_initializer *val_init; /**< Points the the head of the next value initializers. */ - interval_initializer *int_init; /**< Points to the head of the next value initializers. */ -} initializer; - /*-----------------------------------------------------------------*/ /** general **/ /*-----------------------------------------------------------------*/ @@ -229,17 +201,23 @@ static void free_entity_attrs(ir_entity *ent) { assert(ent->overwrittenby == NULL); } if (is_compound_entity(ent)) { - if (ent->attr.cmpd_attr.val_paths) { - for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i) - if (ent->attr.cmpd_attr.val_paths[i]) { - /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ; * @@@ warum nich? */ - /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */ - /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */ - } - ent->attr.cmpd_attr.val_paths = NULL; + if (ent->has_initializer) { + /* TODO: free initializers */ + } else { + if (ent->attr.cmpd_attr.val_paths) { + for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i) + if (ent->attr.cmpd_attr.val_paths[i]) { + /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ; * @@@ warum nich? */ + /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */ + /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */ + } + ent->attr.cmpd_attr.val_paths = NULL; + } + if (ent->attr.cmpd_attr.values) { + /*DEL_ARR_F(ent->attr.cmpd_attr.values)*/; + } + ent->attr.cmpd_attr.values = NULL; } - /* if (ent->attr.cmpd_attr.values) DEL_ARR_F(ent->attr.cmpd_attr.values); *//* @@@ warum nich? */ - ent->attr.cmpd_attr.values = NULL; } else if (is_method_entity(ent)) { if (ent->attr.mtd_attr.param_access) { DEL_ARR_F(ent->attr.mtd_attr.param_access); @@ -252,6 +230,38 @@ static void free_entity_attrs(ir_entity *ent) { } } /* free_entity_attrs */ +/** + * Creates a deep copy of an entity. + */ +static ir_entity *deep_entity_copy(ir_entity *old) +{ + ir_entity *newe = XMALLOC(ir_entity); + + *newe = *old; + if (is_compound_entity(old)) { + if (old->has_initializer) { + /* FIXME: the initializers are NOT copied */ + } else { + newe->attr.cmpd_attr.values = NULL; + newe->attr.cmpd_attr.val_paths = NULL; + if (old->attr.cmpd_attr.values) + newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values); + + /* FIXME: the compound graph paths are NOT copied */ + if (old->attr.cmpd_attr.val_paths) + newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths); + } + } else if (is_method_entity(old)) { + /* do NOT copy them, reanalyze. This might be the best solution */ + newe->attr.mtd_attr.param_access = NULL; + newe->attr.mtd_attr.param_weight = NULL; + } + +#ifdef DEBUG_libfirm + newe->nr = get_irp_new_node_nr(); +#endif + return newe; +} /* * Copies the entity if the new_owner is different from the * owner of the old entity, else returns the old entity. @@ -263,20 +273,19 @@ copy_entity_own(ir_entity *old, ir_type *new_owner) { assert(is_compound_type(new_owner)); assert(get_type_state(new_owner) != layout_fixed); - if (old->owner == new_owner) return old; - newe = XMALLOC(ir_entity); - memcpy(newe, old, sizeof(*newe)); + if (old->owner == new_owner) + return old; + + /* create a deep copy so we are safe of aliasing and double-freeing. */ + newe = deep_entity_copy(old); newe->owner = new_owner; + if (is_Class_type(new_owner)) { newe->overwrites = NEW_ARR_F(ir_entity *, 0); newe->overwrittenby = NEW_ARR_F(ir_entity *, 0); } -#ifdef DEBUG_libfirm - newe->nr = get_irp_new_node_nr(); -#endif insert_entity_in_owner(newe); - return newe; } /* copy_entity_own */ @@ -286,24 +295,19 @@ copy_entity_name(ir_entity *old, ident *new_name) { assert(old && old->kind == k_entity); if (old->name == new_name) return old; - newe = XMALLOC(ir_entity); - memcpy(newe, old, sizeof(*newe)); + newe = deep_entity_copy(old); newe->name = new_name; newe->ld_name = NULL; + if (is_Class_type(newe->owner)) { newe->overwrites = DUP_ARR_F(ir_entity *, old->overwrites); newe->overwrittenby = DUP_ARR_F(ir_entity *, old->overwrittenby); } -#ifdef DEBUG_libfirm - newe->nr = get_irp_new_node_nr(); -#endif - insert_entity_in_owner(newe); return newe; } /* copy_entity_name */ - void free_entity(ir_entity *ent) { assert(ent && ent->kind == k_entity); @@ -637,7 +641,7 @@ ir_node *copy_const_value(dbg_info *dbg, ir_node *n) { m = get_irn_mode(n); switch (get_irn_opcode(n)) { case iro_Const: - nn = new_d_Const_type(dbg, m, get_Const_tarval(n), get_Const_type(n)); + nn = new_d_Const_type(dbg, get_Const_tarval(n), get_Const_type(n)); break; case iro_SymConst: nn = new_d_SymConst_type(dbg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n), @@ -728,7 +732,7 @@ ir_initializer_t *create_initializer_compound(unsigned n_entries) ir_node *get_initializer_const_value(const ir_initializer_t *initializer) { assert(initializer->kind == IR_INITIALIZER_CONST); - return initializer->consti.value; + return skip_Id(initializer->consti.value); } tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)