Slightly reduce code duplication.
[libfirm] / ir / tr / entity.c
index 9fc54f4..da62e15 100644 (file)
@@ -170,7 +170,6 @@ new_rd_entity(dbg_info *db, ir_type *owner, ident *name, ir_type *type)
                res->attr.mtd_attr.param_access       = NULL;
                res->attr.mtd_attr.param_weight       = NULL;
                res->attr.mtd_attr.irg                = NULL;
-               res->attr.mtd_attr.section            = section_text;
        } else if (is_compound_type(type)) {
                res->variability = variability_uninitialized;
                res->value       = NULL;
@@ -255,11 +254,16 @@ static void free_entity_attrs(ir_entity *ent) {
        }
 }  /* free_entity_attrs */
 
+/*
+ * Copies the entity if the new_owner is different from the
+ * owner of the old entity,  else returns the old entity.
+ */
 ir_entity *
 copy_entity_own(ir_entity *old, ir_type *new_owner) {
        ir_entity *newe;
        assert(is_entity(old));
        assert(is_compound_type(new_owner));
+       assert(get_type_state(new_owner) != layout_fixed);
 
        if (old->owner == new_owner) return old;
        newe = xmalloc(sizeof(*newe));
@@ -723,8 +727,8 @@ ir_initializer_t *create_initializer_compound(unsigned n_entries)
        struct obstack *obst = get_irg_obstack(get_const_code_irg());
 
        size_t i;
-       size_t size  = sizeof(ir_initializer_compound_t);
-       size        += (n_entries-1) * sizeof(ir_initializer_t*);
+       size_t size  = sizeof(ir_initializer_compound_t)
+                    + (n_entries-1) * sizeof(ir_initializer_t*);
 
        ir_initializer_t *initializer = obstack_alloc(obst, size);
        initializer->kind                    = IR_INITIALIZER_COMPOUND;
@@ -905,6 +909,7 @@ set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path
 
 int
 get_compound_ent_n_values(ir_entity *ent) {
+       assert(!ent->has_initializer);
        assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
        return ARR_LEN(ent->attr.cmpd_attr.values);
 }  /* get_compound_ent_n_values */
@@ -912,6 +917,7 @@ get_compound_ent_n_values(ir_entity *ent) {
 ir_node *
 get_compound_ent_value(ir_entity *ent, int pos) {
        assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+       assert(!ent->has_initializer);
        assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.values));
        return ent->attr.cmpd_attr.values[pos];
 }  /* get_compound_ent_value */
@@ -919,6 +925,7 @@ get_compound_ent_value(ir_entity *ent, int pos) {
 compound_graph_path *
 get_compound_ent_value_path(ir_entity *ent, int pos) {
        assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
+       assert(!ent->has_initializer);
        assert(0 <= pos && pos < ARR_LEN(ent->attr.cmpd_attr.val_paths));
        return ent->attr.cmpd_attr.val_paths[pos];
 }  /* get_compound_ent_value_path */
@@ -1326,18 +1333,6 @@ void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number) {
        ent->attr.mtd_attr.vtable_number = vtable_number;
 }  /* set_entity_vtable_number */
 
-/* Returns the section of a method. */
-ir_img_section get_method_img_section(const ir_entity *ent) {
-       assert(is_method_entity((ir_entity *)ent));
-       return ent->attr.mtd_attr.section;
-}  /* get_method_img_section */
-
-/* Sets the section of a method. */
-void set_method_img_section(ir_entity *ent, ir_img_section section) {
-       assert(is_method_entity(ent));
-       ent->attr.mtd_attr.section = section;
-}  /* set_method_img_section */
-
 int
 (is_entity)(const void *thing) {
        return _is_entity(thing);