Commit d4d28e60 authored by Matthias Braun's avatar Matthias Braun
Browse files

some cleanups

parent 31025513
......@@ -32,28 +32,23 @@ ir_entity *get_unknown_entity(void)
return irp->unknown_entity;
}
/*-----------------------------------------------------------------*/
/* ENTITY */
/*-----------------------------------------------------------------*/
static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
ident *name, ir_type *type)
{
assert(owner != NULL);
ir_entity *res = XMALLOCZ(ir_entity);
res->kind = k_entity;
res->name = name;
res->type = type;
res->owner = owner;
res->entity_kind = kind;
res->volatility = volatility_non_volatile;
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
res->visibility = ir_visibility_external;
res->kind = k_entity;
res->name = name;
res->type = type;
res->owner = owner;
res->entity_kind = kind;
res->volatility = volatility_non_volatile;
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
res->visibility = ir_visibility_external;
#ifdef DEBUG_libfirm
res->nr = get_irp_new_node_nr();
res->nr = get_irp_new_node_nr();
#endif
/* Remember entity in its owner. */
......@@ -70,11 +65,13 @@ ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
if (is_Method_type(type)) {
ir_graph *irg = get_const_code_irg();
symconst_symbol sym;
res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type);
sym.entity_p = res;
set_atomic_ent_value(res, new_r_SymConst(irg, mode_P_code, sym, symconst_addr_ent));
res->linkage = IR_LINKAGE_CONSTANT;
res->attr.mtd_attr.properties = get_method_additional_properties(type);
res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type);
sym.entity_p = res;
ir_node *symconst
= new_r_SymConst(irg, mode_P_code, sym, symconst_addr_ent);
set_atomic_ent_value(res, symconst);
res->linkage = IR_LINKAGE_CONSTANT;
res->attr.mtd_attr.properties = get_method_additional_properties(type);
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;
......@@ -120,8 +117,6 @@ ir_entity *new_label_entity(ir_label_t label)
/**
* Free entity attributes.
*
* @param ent the entity
*/
static void free_entity_attrs(ir_entity *ent)
{
......@@ -416,9 +411,9 @@ void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
ir_node *get_atomic_ent_value(const ir_entity *entity)
{
ir_initializer_t *initializer = get_entity_initializer(entity);
assert(is_atomic_entity(entity));
ir_initializer_t *initializer = get_entity_initializer(entity);
if (initializer == NULL) {
ir_type *type = get_entity_type(entity);
return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
......@@ -833,7 +828,8 @@ mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
return ent->attr.mtd_attr.properties;
}
void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties property_mask)
void set_entity_additional_properties(ir_entity *ent,
mtp_additional_properties property_mask)
{
assert(is_method_entity(ent));
/* you mustn't set less properties than the entities type */
......@@ -844,7 +840,8 @@ void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties
ent->attr.mtd_attr.properties = property_mask;
}
void add_entity_additional_properties(ir_entity *ent, mtp_additional_properties properties)
void add_entity_additional_properties(ir_entity *ent,
mtp_additional_properties properties)
{
assert(is_method_entity(ent));
......
......@@ -241,11 +241,11 @@ void set_type_size_bytes(ir_type *tp, unsigned size)
unsigned get_type_alignment_bytes(ir_type *tp)
{
unsigned align = 1;
if (tp->align > 0)
return tp->align;
/* alignment NOT set calculate it "on demand" */
unsigned align;
if (tp->mode)
align = (get_mode_size_bits(tp->mode) + 7) >> 3;
else if (is_Array_type(tp))
......@@ -261,11 +261,12 @@ unsigned get_type_alignment_bytes(ir_type *tp)
}
} else if (is_Method_type(tp)) {
align = 0;
} else {
align = 1;
}
/* write back */
tp->align = align;
return align;
}
......@@ -657,9 +658,10 @@ int (is_Class_type)(const ir_type *clss)
void set_class_mode(ir_type *tp, ir_mode *mode)
{
/* for classes and structs we allow to set a mode if the layout is fixed AND the size matches */
/* for classes and structs we allow to set a mode if the layout is fixed
* AND the size matches */
assert(get_type_state(tp) == layout_fixed &&
tp->size == get_mode_size_bytes(mode) && "mode don't match class layout");
tp->size == get_mode_size_bytes(mode));
tp->mode = mode;
}
......@@ -758,9 +760,10 @@ int (is_Struct_type)(const ir_type *strct)
void set_struct_mode(ir_type *tp, ir_mode *mode)
{
/* for classes and structs we allow to set a mode if the layout is fixed AND the size matches */
/* for classes and structs we allow to set a mode if the layout is fixed
* AND the size matches */
assert(get_type_state(tp) == layout_fixed &&
tp->size == get_mode_size_bytes(mode) && "mode don't match struct layout");
tp->size == get_mode_size_bytes(mode));
tp->mode = mode;
}
......@@ -771,7 +774,6 @@ void set_struct_size(ir_type *tp, unsigned size)
ir_type *new_type_method(size_t n_param, size_t n_res)
{
assert((get_mode_size_bits(mode_P_code) % 8 == 0) && "unorthodox modes not implemented");
ir_type *res = new_type(type_method, mode_P_code);
res->flags |= tf_layout_fixed;
res->size = get_mode_size_bytes(mode_P_code);
......@@ -1027,7 +1029,6 @@ void set_union_size(ir_type *tp, unsigned size)
tp->size = size;
}
ir_type *new_type_segment(ident *const name, type_flags const flags)
{
ir_type *const seg = new_type_class(name);
......@@ -1036,7 +1037,6 @@ ir_type *new_type_segment(ident *const name, type_flags const flags)
return seg;
}
ir_type *new_type_array(size_t n_dimensions, ir_type *element_type)
{
assert(!is_Method_type(element_type));
......@@ -1093,8 +1093,8 @@ void set_array_bounds(ir_type *array, size_t dimension, ir_node *lower_bound,
ir_node *upper_bound)
{
assert(array->type_op == type_array);
assert(lower_bound && "lower_bound node may not be NULL.");
assert(upper_bound && "upper_bound node may not be NULL.");
assert(lower_bound != NULL);
assert(upper_bound != NULL);
assert(dimension < array->attr.aa.n_dimensions);
array->attr.aa.lower_bound[dimension] = lower_bound;
array->attr.aa.upper_bound[dimension] = upper_bound;
......@@ -1263,7 +1263,6 @@ ir_type *new_type_pointer(ir_type *points_to)
ir_type *res = new_type(type_pointer, mode);
res->attr.pa.points_to = points_to;
assert((get_mode_size_bits(res->mode) % 8 == 0) && "unorthodox modes not implemented");
res->size = get_mode_size_bytes(res->mode);
res->flags |= tf_layout_fixed;
hook_new_type(res);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment