Added iro_InstOf operator --flo
[libfirm] / ir / tr / entity.c
index 8eba693..b2c482e 100644 (file)
@@ -110,7 +110,7 @@ copy_entity_own (entity *old, type *new_owner) {
   memcpy (new, old, sizeof (entity));
   new->owner = new_owner;
   new->overwrites = DUP_ARR_F(entity *, old->overwrites);
-  new->overwrittenby = DUP_ARR_F(entity *, old->overwrites);
+  new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
 
   insert_entity_in_owner (new);
 
@@ -127,7 +127,7 @@ copy_entity_name (entity *old, ident *new_name) {
   new->name = new_name;
   new->ld_name = NULL;
   new->overwrites = DUP_ARR_F(entity *, old->overwrites);
-  new->overwrittenby = DUP_ARR_F(entity *, old->overwrites);
+  new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
 
   insert_entity_in_owner (new);
 
@@ -265,7 +265,7 @@ set_entity_volatility (entity *ent, ent_volatility vol) {
 inline peculiarity
 get_entity_peculiarity (entity *ent) {
   assert (ent);
-  assert (is_method_type(ent->type));
+  //assert (is_method_type(ent->type));
   return ent->peculiarity;
 }
 
@@ -279,7 +279,8 @@ set_entity_peculiarity (entity *ent, peculiarity pec) {
 /* Set has no effect for entities of type method. */
 inline ir_node *
 get_atomic_ent_value(entity *ent) {
-  assert(ent); assert(is_atomic_entity(ent)); assert((ent->variability != uninitialized));
+  assert(ent); assert(is_atomic_entity(ent));
+  assert((ent->variability != uninitialized));
   return ent->value;
 }
 
@@ -290,7 +291,8 @@ set_atomic_ent_value(entity *ent, ir_node *val) {
   ent->value = val;
 }
 
-ir_node *copy_value(ir_node *n) {
+
+ir_node *copy_const_value(ir_node *n) {
   ir_node *nn;
   ir_mode *m;
 
@@ -301,7 +303,7 @@ ir_node *copy_value(ir_node *n) {
   case iro_SymConst:
     nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n)); break;
   case iro_Add:
-    nn = new_Add(copy_value(get_Add_left(n)), copy_value(get_Add_right(n)), m); break;
+    nn = new_Add(copy_const_value(get_Add_left(n)), copy_const_value(get_Add_right(n)), m); break;
   default:
     assert(0 && "opdope invalid or not implemented"); break;
   }
@@ -312,7 +314,7 @@ ir_node *copy_value(ir_node *n) {
    in current_ir_graph. */
 ir_node *copy_atomic_ent_value(entity *ent) {
   assert(ent && is_atomic_entity(ent) && (ent->variability != uninitialized));
-  return copy_value(ent->value);
+  return copy_const_value(ent->value);
 }
 
 /* A value of a compound entity is a pair of value and the corresponding member of
@@ -324,6 +326,21 @@ add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
   ARR_APP1 (entity *, ent->val_ents, member);
 }
 
+/* Copies the firm subgraph referenced by val to const_code_irg and adds
+   the node as constant initialization to ent.
+   The subgraph may not contain control flow operations. */
+inline void
+copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
+  ir_graph *rem = current_ir_graph;
+
+  assert(get_entity_variability(ent) != uninitialized);
+  current_ir_graph = get_const_code_irg();
+
+  val = copy_const_value(val);
+  add_compound_ent_value(ent, val, member);
+  current_ir_graph = rem;
+}
+
 inline int
 get_compound_ent_n_values(entity *ent) {
   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
@@ -337,9 +354,10 @@ get_compound_ent_value(entity *ent, int pos) {
 }
 
 /* Copies the value i of the entity to current_block in current_ir_graph. */
-ir_node *copy_compound_ent_value(entity *ent, int pos) {
+ir_node *
+copy_compound_ent_value(entity *ent, int pos) {
   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
-  return copy_value(ent->values[pos+1]);
+  return copy_const_value(ent->values[pos+1]);
 }
 
 inline entity   *
@@ -355,6 +373,28 @@ set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
   ent->val_ents[pos+1] = member;
 }
 
+void
+set_array_entity_values(entity *ent, tarval **values, int num_vals) {
+  int i;
+  ir_graph *rem = current_ir_graph;
+  type *arrtp = get_entity_type(ent);
+  ir_node *val;
+
+  assert(is_array_type(arrtp));
+  assert(get_array_n_dimensions(arrtp) == 1);
+  /* One bound is sufficient, the nunmber of constant fields makes the
+     size. */
+  assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
+  assert(get_entity_variability(ent) != uninitialized);
+  current_ir_graph = get_const_code_irg();
+
+  for (i = 0; i < num_vals; i++) {
+    val = new_Const(get_tv_mode (values[i]), values[i]);
+    add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
+  }
+  current_ir_graph = rem;
+}
+
 inline int
 get_entity_offset (entity *ent) {
   return ent->offset;
@@ -449,7 +489,10 @@ get_entity_irg(entity *ent) {
 inline void
 set_entity_irg(entity *ent, ir_graph *irg) {
   assert (ent && ent->type);
-  assert (irg);
+  /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
+   * Methode selbst nicht mehr aufgerufen werden kann, die Entität
+   * aber erhalten bleiben soll. */
+  /* assert (irg); */
   assert (is_method_type(ent->type));
   assert (ent->peculiarity == existent);
   ent->irg = irg;