Fixed iterations broken with size_t refactoring.
[libfirm] / ir / tr / entity.c
index 0985436..f67d0e6 100644 (file)
@@ -64,7 +64,6 @@ ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
                         dbg_info *db)
 {
        ir_entity *res;
-       ir_graph *rem;
 
        assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
 
@@ -88,16 +87,14 @@ ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
        res->repr_class           = NULL;
 
        if (is_Method_type(type)) {
+               ir_graph *irg = get_const_code_irg();
                symconst_symbol sym;
                ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
                sym.entity_p            = res;
-               rem                     = current_ir_graph;
-               current_ir_graph        = get_const_code_irg();
-               set_atomic_ent_value(res, new_SymConst(mode, sym, symconst_addr_ent));
-               current_ir_graph        = rem;
+               set_atomic_ent_value(res, new_r_SymConst(irg, mode, sym, symconst_addr_ent));
                res->linkage            = IR_LINKAGE_CONSTANT;
                res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
-               res->attr.mtd_attr.vtable_number      = VTABLE_NUM_NOT_SET;
+               res->attr.mtd_attr.vtable_number      = IR_VTABLE_NUM_NOT_SET;
                res->attr.mtd_attr.param_access       = NULL;
                res->attr.mtd_attr.param_weight       = NULL;
                res->attr.mtd_attr.irg                = NULL;
@@ -239,7 +236,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);
@@ -304,6 +301,11 @@ const char *(get_entity_ld_name)(const ir_entity *ent)
        return _get_entity_ld_name(ent);
 }
 
+int entity_has_ld_ident(const ir_entity *entity)
+{
+       return entity->ld_name != NULL;
+}
+
 ir_type *(get_entity_type)(const ir_entity *ent)
 {
        return _get_entity_type(ent);
@@ -394,7 +396,7 @@ void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
 
 ir_visibility get_entity_visibility(const ir_entity *entity)
 {
-       return entity->visibility;
+       return (ir_visibility)entity->visibility;
 }
 
 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
@@ -457,7 +459,7 @@ ir_node *get_atomic_ent_value(ir_entity *entity)
                return new_r_Const(get_const_code_irg(), get_mode_null(mode));
        }
        case IR_INITIALIZER_TARVAL: {
-               tarval *tv = get_initializer_tarval_value(initializer);
+               ir_tarval *tv = get_initializer_tarval_value(initializer);
                return new_r_Const(get_const_code_irg(), tv);
        }
        case IR_INITIALIZER_CONST:
@@ -509,10 +511,11 @@ int is_irn_const_expression(ir_node *n)
 
 /*
  * Copies a firm subgraph that complies to the restrictions for
- * constant expressions to current_block in current_ir_graph.
+ * constant expressions to block.
  */
-ir_node *copy_const_value(dbg_info *dbg, ir_node *n)
+ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
 {
+       ir_graph *irg = get_irn_irg(block);
        ir_node *nn;
        ir_mode *m;
 
@@ -522,36 +525,52 @@ ir_node *copy_const_value(dbg_info *dbg, ir_node *n)
        m = get_irn_mode(n);
        switch (get_irn_opcode(n)) {
        case iro_Const:
-               nn = new_d_Const_type(dbg, get_Const_tarval(n), get_Const_type(n));
+               nn = new_rd_Const(dbg, irg, get_Const_tarval(n));
                break;
        case iro_SymConst:
-               nn = new_d_SymConst_type(dbg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n),
-                       get_SymConst_value_type(n));
+               nn = new_rd_SymConst(dbg, irg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n));
                break;
        case iro_Add:
-               nn = new_d_Add(dbg, copy_const_value(dbg, get_Add_left(n)),
-                       copy_const_value(dbg, get_Add_right(n)), m); break;
+               nn = new_rd_Add(dbg, block,
+                               copy_const_value(dbg, get_Add_left(n), block),
+                               copy_const_value(dbg, get_Add_right(n), block), m);
+               break;
        case iro_Sub:
-               nn = new_d_Sub(dbg, copy_const_value(dbg, get_Sub_left(n)),
-                       copy_const_value(dbg, get_Sub_right(n)), m); break;
+               nn = new_rd_Sub(dbg, block,
+                               copy_const_value(dbg, get_Sub_left(n), block),
+                               copy_const_value(dbg, get_Sub_right(n), block), m);
+               break;
        case iro_Mul:
-               nn = new_d_Mul(dbg, copy_const_value(dbg, get_Mul_left(n)),
-                       copy_const_value(dbg, get_Mul_right(n)), m); break;
+               nn = new_rd_Mul(dbg, block,
+                               copy_const_value(dbg, get_Mul_left(n), block),
+                               copy_const_value(dbg, get_Mul_right(n), block), m);
+               break;
        case iro_And:
-               nn = new_d_And(dbg, copy_const_value(dbg, get_And_left(n)),
-                       copy_const_value(dbg, get_And_right(n)), m); break;
+               nn = new_rd_And(dbg, block,
+                               copy_const_value(dbg, get_And_left(n), block),
+                               copy_const_value(dbg, get_And_right(n), block), m);
+               break;
        case iro_Or:
-               nn = new_d_Or(dbg, copy_const_value(dbg, get_Or_left(n)),
-                       copy_const_value(dbg, get_Or_right(n)), m); break;
+               nn = new_rd_Or(dbg, block,
+                              copy_const_value(dbg, get_Or_left(n), block),
+                              copy_const_value(dbg, get_Or_right(n), block), m);
+               break;
        case iro_Eor:
-               nn = new_d_Eor(dbg, copy_const_value(dbg, get_Eor_left(n)),
-                       copy_const_value(dbg, get_Eor_right(n)), m); break;
+               nn = new_rd_Eor(dbg, block,
+                               copy_const_value(dbg, get_Eor_left(n), block),
+                               copy_const_value(dbg, get_Eor_right(n), block), m);
+               break;
        case iro_Cast:
-               nn = new_d_Cast(dbg, copy_const_value(dbg, get_Cast_op(n)), get_Cast_type(n)); break;
+               nn = new_rd_Cast(dbg, block,
+                                copy_const_value(dbg, get_Cast_op(n), block),
+                                get_Cast_type(n));
+               break;
        case iro_Conv:
-               nn = new_d_Conv(dbg, copy_const_value(dbg, get_Conv_op(n)), m); break;
+               nn = new_rd_Conv(dbg, block,
+                                copy_const_value(dbg, get_Conv_op(n), block), m);
+               break;
        case iro_Unknown:
-               nn = new_Unknown(m); break;
+               nn = new_r_Unknown(irg, m); break;
        default:
                panic("opcode invalid or not implemented");
        }
@@ -584,19 +603,19 @@ ir_initializer_t *create_initializer_const(ir_node *value)
        struct obstack *obst = get_irg_obstack(get_const_code_irg());
 
        ir_initializer_t *initializer
-               = obstack_alloc(obst, sizeof(ir_initializer_const_t));
+               = (ir_initializer_t*)OALLOC(obst, ir_initializer_const_t);
        initializer->kind         = IR_INITIALIZER_CONST;
        initializer->consti.value = value;
 
        return initializer;
 }
 
-ir_initializer_t *create_initializer_tarval(tarval *tv)
+ir_initializer_t *create_initializer_tarval(ir_tarval *tv)
 {
        struct obstack *obst = get_irg_obstack(get_const_code_irg());
 
        ir_initializer_t *initializer
-               = obstack_alloc(obst, sizeof(ir_initializer_tarval_t));
+               = (ir_initializer_t*)OALLOC(obst, ir_initializer_tarval_t);
        initializer->kind         = IR_INITIALIZER_TARVAL;
        initializer->tarval.value = tv;
 
@@ -611,7 +630,8 @@ ir_initializer_t *create_initializer_compound(unsigned n_entries)
        size_t size  = sizeof(ir_initializer_compound_t)
                     + (n_entries-1) * sizeof(ir_initializer_t*);
 
-       ir_initializer_t *initializer = obstack_alloc(obst, size);
+       ir_initializer_t *initializer
+               = (ir_initializer_t*)obstack_alloc(obst, size);
        initializer->kind                    = IR_INITIALIZER_COMPOUND;
        initializer->compound.n_initializers = n_entries;
 
@@ -628,7 +648,7 @@ ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
        return skip_Id(initializer->consti.value);
 }
 
-tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
+ir_tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
 {
        assert(initializer->kind == IR_INITIALIZER_TARVAL);
        return initializer->tarval.value;
@@ -733,31 +753,31 @@ void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
        ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
 }
 
-int get_entity_n_overwrites(const ir_entity *ent)
+size_t get_entity_n_overwrites(const ir_entity *ent)
 {
        if (ent->overwrites == NULL)
                return 0;
        return ARR_LEN(ent->overwrites);
 }
 
-int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
+size_t get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
 {
-       int i, n;
-       n = get_entity_n_overwrites(ent);
+       size_t i;
+       size_t n = get_entity_n_overwrites(ent);
        for (i = 0; i < n; ++i) {
                if (get_entity_overwrites(ent, i) == overwritten)
                        return i;
        }
-       return -1;
+       return (size_t)-1;
 }
 
-ir_entity *get_entity_overwrites(const ir_entity *ent, int pos)
+ir_entity *get_entity_overwrites(const ir_entity *ent, size_t pos)
 {
        assert(pos < get_entity_n_overwrites(ent));
        return ent->overwrites[pos];
 }
 
-void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten)
+void set_entity_overwrites(ir_entity *ent, size_t pos, ir_entity *overwritten)
 {
        assert(pos < get_entity_n_overwrites(ent));
        ent->overwrites[pos] = overwritten;
@@ -765,8 +785,8 @@ void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten)
 
 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
 {
-       int i, n;
-       n = get_entity_n_overwrites(ent);
+       size_t i;
+       size_t n = get_entity_n_overwrites(ent);
        for (i = 0; i < n; ++i) {
                if (ent->overwrites[i] == overwritten) {
                        for (; i < n - 1; i++)
@@ -778,31 +798,32 @@ void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
 }
 
 
-int get_entity_n_overwrittenby(const ir_entity *ent)
+size_t get_entity_n_overwrittenby(const ir_entity *ent)
 {
        if (ent->overwrittenby == NULL)
                return 0;
        return ARR_LEN(ent->overwrittenby);
 }
 
-int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites)
+size_t get_entity_overwrittenby_index(const ir_entity *ent,
+                                      ir_entity *overwrites)
 {
-       int i, n;
-       n = get_entity_n_overwrittenby(ent);
+       size_t i;
+       size_t n = get_entity_n_overwrittenby(ent);
        for (i = 0; i < n; ++i) {
                if (get_entity_overwrittenby(ent, i) == overwrites)
                        return i;
        }
-       return -1;
+       return (size_t)-1;
 }
 
-ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos)
+ir_entity *get_entity_overwrittenby(const ir_entity *ent, size_t pos)
 {
        assert(pos < get_entity_n_overwrittenby(ent));
        return ent->overwrittenby[pos];
 }
 
-void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites)
+void set_entity_overwrittenby(ir_entity *ent, size_t pos, ir_entity *overwrites)
 {
        assert(pos < get_entity_n_overwrittenby(ent));
        ent->overwrittenby[pos] = overwrites;
@@ -810,9 +831,8 @@ void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites)
 
 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
 {
-       int i, n;
-
-       n = get_entity_n_overwrittenby(ent);
+       size_t i;
+       size_t n = get_entity_n_overwrittenby(ent);
        for (i = 0; i < n; ++i) {
                if (ent->overwrittenby[i] == overwrites) {
                        for (; i < n - 1; ++i)
@@ -909,7 +929,7 @@ int (entity_not_visited)(const ir_entity *ent)
        return _entity_not_visited(ent);
 }
 
-unsigned get_entity_additional_properties(const ir_entity *ent)
+mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
 {
        ir_graph *irg;
 
@@ -927,7 +947,7 @@ unsigned get_entity_additional_properties(const ir_entity *ent)
        return ent->attr.mtd_attr.irg_add_properties;
 }
 
-void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
+void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties property_mask)
 {
        ir_graph *irg;
 
@@ -938,13 +958,13 @@ void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
        if (irg)
                set_irg_additional_properties(irg, property_mask);
        else {
-    /* do not allow to set the mtp_property_inherited flag or
-               * the automatic inheritance of flags will not work */
+               /* do not allow to set the mtp_property_inherited flag or
+                * the automatic inheritance of flags will not work */
                ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
        }
 }
 
-void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag)
+void add_entity_additional_properties(ir_entity *ent, mtp_additional_properties properties)
 {
        ir_graph *irg;
 
@@ -953,16 +973,16 @@ void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag
        /* first check, if the graph exists */
        irg = get_entity_irg(ent);
        if (irg)
-               set_irg_additional_property(irg, flag);
+               add_irg_additional_properties(irg, properties);
        else {
-               unsigned mask = ent->attr.mtd_attr.irg_add_properties;
+               mtp_additional_properties mask = ent->attr.mtd_attr.irg_add_properties;
 
                if (mask & mtp_property_inherited)
                        mask = get_method_additional_properties(get_entity_type(ent));
 
                /* do not allow to set the mtp_property_inherited flag or
                 * the automatic inheritance of flags will not work */
-               ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited);
+               ent->attr.mtd_attr.irg_add_properties = mask | (properties & ~mtp_property_inherited);
        }
 }
 
@@ -996,26 +1016,28 @@ 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)
 {
-       return entity->allocation;
+       return (ir_allocation)entity->allocation;
 }
 
 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
@@ -1025,7 +1047,7 @@ void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
 
 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
 {
-       return entity->peculiarity;
+       return (ir_peculiarity)entity->peculiarity;
 }
 
 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)