From: Matthias Braun Date: Wed, 16 Jun 2010 14:42:05 +0000 (+0000) Subject: fix some bugs that prevented repeated calling of ir_init and ir_finish X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=9022c59ec32373291b4685c60ee4751b30c41594;p=libfirm fix some bugs that prevented repeated calling of ir_init and ir_finish [r27628] --- diff --git a/ir/be/becopystat.c b/ir/be/becopystat.c index 220a43ece..294c372cd 100644 --- a/ir/be/becopystat.c +++ b/ir/be/becopystat.c @@ -126,8 +126,14 @@ void be_init_copystat(void) BE_REGISTER_MODULE_DESTRUCTOR(be_quit_copystat); void be_quit_copystat(void) { - ir_nodeset_del(all_phi_nodes); - ir_nodeset_del(all_copy_nodes); + if (all_phi_nodes != NULL) { + ir_nodeset_del(all_phi_nodes); + all_phi_nodes = NULL; + } + if (all_copy_nodes != NULL) { + ir_nodeset_del(all_copy_nodes); + all_copy_nodes = NULL; + } } /** diff --git a/ir/common/firm.c b/ir/common/firm.c index e35f9cb9c..e62952acb 100644 --- a/ir/common/firm.c +++ b/ir/common/firm.c @@ -127,9 +127,9 @@ void ir_init(const firm_parameter_t *param) later. */ init_irprog_2(); /* Initialize the type module and construct some idents needed. */ - firm_init_type(); + ir_init_type(); /* initialize the entity module */ - firm_init_entity(); + ir_init_entity(); /* class cast optimization */ firm_init_class_casts_opt(); /* memory disambiguation */ @@ -166,6 +166,9 @@ void ir_finish(void) free_ir_prog(); + ir_finish_entity(); + ir_finish_type(); + finish_tarval(); finish_mode(); finish_tpop(); diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 098543672..575f679e5 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -239,7 +239,7 @@ ir_entity *copy_entity_name(ir_entity *old, ident *new_name) void free_entity(ir_entity *ent) { - if (! is_Array_type(ent->owner)) + if (ent->owner != NULL && !is_Array_type(ent->owner)) remove_compound_member(ent->owner, ent); assert(ent && ent->kind == k_entity); @@ -996,21 +996,23 @@ int entity_has_definition(const ir_entity *entity) || entity_has_compound_ent_values(entity); } -void firm_init_entity(void) +void ir_init_entity(void) { - symconst_symbol sym; - assert(firm_unknown_type && "Call init_type() before firm_init_entity()!"); assert(!unknown_entity && "Call firm_init_entity() only once!"); unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME), firm_unknown_type, NULL); set_entity_visibility(unknown_entity, ir_visibility_external); - set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity)); +} - current_ir_graph = get_const_code_irg(); - sym.entity_p = unknown_entity; +void ir_finish_entity(void) +{ + if (unknown_entity != NULL) { + free_entity(unknown_entity); + unknown_entity = NULL; + } } ir_allocation get_entity_allocation(const ir_entity *entity) diff --git a/ir/tr/entity_t.h b/ir/tr/entity_t.h index 190cfd4f0..12bf6452f 100644 --- a/ir/tr/entity_t.h +++ b/ir/tr/entity_t.h @@ -172,7 +172,9 @@ struct ir_entity { }; /** Initialize the entity module. */ -void firm_init_entity(void); +void ir_init_entity(void); +/** Cleanup entity module */ +void ir_finish_entity(void); /* ----------------------- inline functions ------------------------ */ static inline int _is_entity(const void *thing) diff --git a/ir/tr/type.c b/ir/tr/type.c index 30a9bf442..8f252f8c0 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -85,7 +85,7 @@ ir_type *get_unknown_type(void) static ident *value_params_suffix = NULL; static ident *value_ress_suffix = NULL; -void firm_init_type(void) +void ir_init_type(void) { value_params_suffix = new_id_from_str(VALUE_PARAMS_SUFFIX); value_ress_suffix = new_id_from_str(VALUE_RESS_SUFFIX); @@ -106,6 +106,24 @@ void firm_init_type(void) remove_irp_type(firm_unknown_type); } +void ir_finish_type(void) +{ + if (firm_none_type != NULL) { + free_type(firm_none_type); + firm_none_type = NULL; + } + if (firm_code_type != NULL) { + free_type(firm_code_type); + firm_code_type = NULL; + } + if (firm_unknown_type != NULL) { + free_type(firm_unknown_type); + firm_unknown_type = NULL; + } + value_params_suffix = NULL; + value_ress_suffix = NULL; +} + /** the global type visited flag */ ir_visited_t firm_type_visited; diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h index 1db06dd87..14f4d6f31 100644 --- a/ir/tr/type_t.h +++ b/ir/tr/type_t.h @@ -286,10 +286,11 @@ int get_class_dfn(const ir_type *clss); void add_compound_member(ir_type *compound, ir_entity *entity); void remove_compound_member(ir_type *compound, ir_entity *entity); -/** - * Initialize the type module. - */ -void firm_init_type(void); +/** Initialize the type module. */ +void ir_init_type(void); + +/** free internal datastructures of type module */ +void ir_finish_type(void); /** Clone an existing method type. *