added some routines to entity interface.
authorGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Wed, 4 Jul 2001 12:29:46 +0000 (12:29 +0000)
committerGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Wed, 4 Jul 2001 12:29:46 +0000 (12:29 +0000)
[r217]

Changes
ir/ir/irdump.c
ir/tr/entity.c
ir/tr/entity.h

diff --git a/Changes b/Changes
index c859964..c1a1eb8 100644 (file)
--- 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
index eb230bb..24112f8 100644 (file)
@@ -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);
 
index 6c94473..516f366 100644 (file)
@@ -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;
 }
 
index ad18f75..c153a81 100644 (file)
@@ -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);