From: Götz Lindenmaier Date: Wed, 4 Jul 2001 12:29:46 +0000 (+0000) Subject: added some routines to entity interface. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=5f893f437c8a7a7591a5b671a46121827f34d15a;p=libfirm added some routines to entity interface. [r217] --- diff --git a/Changes b/Changes index c8599645d..c1a1eb893 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,7 @@ + 4.7.2001 Goetz + Added a routine to set the mangled entity name. + Added two routines to copy entites. + 3.7.2001 Goetz Entities now have two more flags, for visibility and allocation mode. Types that have a layout have a flag indicating whether the layout is diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index eb230bbe0..24112f867 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -583,7 +583,7 @@ void vcg_open (ir_graph *irg, char *suffix) { char label[4]; /** open file for vcg graph */ - id = get_entity_ld_name (get_irg_ent(irg)); + id = get_entity_ld_ident (get_irg_ent(irg)); len = id_to_strlen (id); cp = id_to_str (id); diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 6c94473de..516f3668e 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -28,6 +28,25 @@ init_entity (void) /** ENTITY **/ /*******************************************************************/ +inline void insert_entity_in_owner (entity *ent) { + type *owner = ent->owner; + switch (get_type_tpop_code(owner)) { + case tpo_class: { + add_class_member (owner, ent); + } break; + case tpo_struct: { + add_struct_member (owner, ent); + } break; + case tpo_union: { + add_union_member (owner, ent); + } break; + case tpo_array: { + set_array_element_entity(owner, ent); + } break; + default: assert(0); + } +} + entity * new_entity (type *owner, ident *name, type *type) { @@ -45,25 +64,41 @@ new_entity (type *owner, ident *name, type *type) res->visit = 0; - switch (get_type_tpop_code(owner)) { - case tpo_class: { - add_class_member (owner, res); - } break; - case tpo_struct: { - add_struct_member (owner, res); - } break; - case tpo_union: { - add_union_member (owner, res); - } break; - case tpo_array: { - set_array_element_entity(owner, res); - } break; - default: assert(0); - } - + /* Remember entity in it's owner. */ + insert_entity_in_owner (res); return res; } +entity * +copy_entity_own (entity *old, type *new_owner) { + entity *new; + + assert_legal_owner_of_ent(new_owner); + if (old->owner == new_owner) return old; + new = (entity *) malloc (sizeof (entity)); + memcpy (new, old, sizeof (entity)); + new->owner = new_owner; + + insert_entity_in_owner (new); + + return new; +} + +entity * +copy_entity_name (entity *old, ident *new_name) { + entity *new; + + if (old->name == new_name) return old; + new = (entity *) malloc (sizeof (entity)); + memcpy (new, old, sizeof (entity)); + new->name = new_name; + new->ld_name = NULL; + + insert_entity_in_owner (new); + + return new; +} + inline const char * get_entity_name (entity *ent) { assert (ent); @@ -109,7 +144,7 @@ get_entity_ld_ident (entity *ent) return ent->ld_name; } -void set_entity_ld_ident (entity *, ident *ld_ident) { +void set_entity_ld_ident (entity *ent, ident *ld_ident) { ent->ld_name = ld_ident; } diff --git a/ir/tr/entity.h b/ir/tr/entity.h index ad18f75a7..c153a8178 100644 --- a/ir/tr/entity.h +++ b/ir/tr/entity.h @@ -75,7 +75,15 @@ typedef struct entity entity; /* Creates a new entity. Automatically inserts the entity as a member of owner. */ entity *new_entity (type *owner, ident *name, type *type); - +/* Copies the entity if the new_owner is different from the + owner of the old entity. Else returns the old entity. + Automatically inserts the new entity as a member of owner. */ +entity *copy_entity_own (entity *old, type *new_owner); +/* Copies the entity if the new_name is different from the + name of the old entity. Else returns the old entity. + Automatically inserts the new entity as a member of owner. + The mangled name ld_name is set to NULL. */ +entity *copy_entity_name (entity *old, ident *new_name); /* manipulate fields of entity */ const char *get_entity_name (entity *ent); ident *get_entity_ident (entity *ent);