}
ir_type *firm_unknown_type;
-ir_type *get_unknown_type(void) {
+ir_type *get_unknown_type(void)
+{
return firm_unknown_type;
}
static ident *value_params_suffix = NULL;
static ident *value_ress_suffix = NULL;
-/** The default calling convention for method types. */
-static unsigned default_cc_mask;
-
-unsigned get_default_cc_mask(void)
-{
- return default_cc_mask;
-}
-
-void firm_init_type(unsigned def_cc_mask)
+void ir_init_type(void)
{
- default_cc_mask = def_cc_mask;
value_params_suffix = new_id_from_str(VALUE_PARAMS_SUFFIX);
value_ress_suffix = new_id_from_str(VALUE_RESS_SUFFIX);
remove_irp_type(firm_unknown_type);
}
+void ir_finish_type(void)
+{
+ if (firm_none_type != NULL) {
+ free_type(firm_none_type);
+ firm_none_type = NULL;
+ }
+ if (firm_code_type != NULL) {
+ free_type(firm_code_type);
+ firm_code_type = NULL;
+ }
+ if (firm_unknown_type != NULL) {
+ free_type(firm_unknown_type);
+ firm_unknown_type = NULL;
+ }
+ value_params_suffix = NULL;
+ value_ress_suffix = NULL;
+}
+
/** the global type visited flag */
ir_visited_t firm_type_visited;
res->kind = k_type;
res->type_op = type_op;
res->mode = mode;
- res->visibility = visibility_external_allocated;
+ res->visibility = ir_visibility_external;
res->flags = tf_none;
res->size = 0;
res->align = 0;
case tpo_struct:
for (i = 0; i < get_struct_n_members(tp); i++) {
assert(get_entity_offset(get_struct_member(tp, i)) > -1);
- assert((get_entity_allocation(get_struct_member(tp, i)) == allocation_automatic));
}
break;
case tpo_union:
break;
case tpo_enumeration:
#ifndef NDEBUG
- assert(get_type_mode != NULL);
+ assert(get_type_mode(tp) != NULL);
for (i = get_enumeration_n_enums(tp) - 1; i >= 0; --i) {
ir_enum_const *ec = get_enumeration_const(tp, i);
tarval *tv = get_enumeration_value(ec);
return 0;
if (!equal_type(get_array_element_type(typ1), get_array_element_type(typ2)))
return 0;
- for(i = 0; i < get_array_n_dimensions(typ1); i++) {
+ for (i = 0; i < get_array_n_dimensions(typ1); i++) {
if (get_array_lower_bound(typ1, i) != get_array_lower_bound(typ2, i) ||
get_array_upper_bound(typ1, i) != get_array_upper_bound(typ2, i))
return 0;
if (get_type_tpop_code(st) != get_type_tpop_code(lt))
return 0;
- switch(get_type_tpop_code(st)) {
+ switch (get_type_tpop_code(st)) {
case tpo_class:
return is_SubClass_of(st, lt);
get_type_size_bytes(set) != get_type_size_bytes(let))
return 0;
}
- for(i = 0; i < get_array_n_dimensions(st); i++) {
+ for (i = 0; i < get_array_n_dimensions(st); i++) {
if (get_array_lower_bound(lt, i))
- if(get_array_lower_bound(st, i) != get_array_lower_bound(lt, i))
+ if (get_array_lower_bound(st, i) != get_array_lower_bound(lt, i))
return 0;
if (get_array_upper_bound(lt, i))
- if(get_array_upper_bound(st, i) != get_array_upper_bound(lt, i))
+ if (get_array_upper_bound(st, i) != get_array_upper_bound(lt, i))
return 0;
}
} break;
const char *get_class_name(const ir_type *clss)
{
+ if (get_class_ident(clss) == NULL)
+ return NULL;
return get_id_str(get_class_ident(clss));
}
-void add_class_member(ir_type *clss, ir_entity *member)
+static void add_class_member(ir_type *clss, ir_entity *member)
{
assert(clss && (clss->type_op == type_class));
assert(clss != get_entity_type(member) && "recursive type");
- assert(get_type_state(clss) != layout_fixed);
ARR_APP1 (ir_entity *, clss->attr.ca.members, member);
}
}
}
-void remove_class_member(ir_type *clss, ir_entity *member)
+static void remove_class_member(ir_type *clss, ir_entity *member)
{
int i;
assert(clss && (clss->type_op == type_class));
assert(clss && (clss->type_op == type_class));
for (i = 0; i < (ARR_LEN(clss->attr.ca.supertypes)); i++)
if (clss->attr.ca.supertypes[i] == supertype) {
- for(; i < (ARR_LEN(clss->attr.ca.supertypes))-1; i++)
+ for (; i < (ARR_LEN(clss->attr.ca.supertypes))-1; i++)
clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
ARR_SETLEN(ir_entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
break;
ent->repr_class = clss;
}
-const char *get_peculiarity_name(ir_peculiarity p)
-{
-#define X(a) case a: return #a
- switch (p) {
- X(peculiarity_description);
- X(peculiarity_inherited);
- X(peculiarity_existent);
- }
-#undef X
- return "invalid peculiarity";
-}
-
ir_peculiarity get_class_peculiarity(const ir_type *clss)
{
assert(clss && (clss->type_op == type_class));
tp->mode = mode;
}
-void set_class_size(ir_type *tp, unsigned size) {
+void set_class_size(ir_type *tp, unsigned size)
+{
tp->size = size;
}
const char *get_struct_name(const ir_type *strct)
{
+ if (get_struct_ident(strct) == NULL)
+ return NULL;
return get_id_str(get_struct_ident(strct));
}
return ARR_LEN(strct->attr.sa.members);
}
-void add_struct_member(ir_type *strct, ir_entity *member)
+static void add_struct_member(ir_type *strct, ir_entity *member)
{
assert(strct && (strct->type_op == type_struct));
assert(get_type_tpop(get_entity_type(member)) != type_method);
assert(strct != get_entity_type(member) && "recursive type");
- assert(get_type_state(strct) != layout_fixed);
ARR_APP1 (ir_entity *, strct->attr.sa.members, member);
}
strct->attr.sa.members[pos] = member;
}
-void remove_struct_member(ir_type *strct, ir_entity *member)
+static void remove_struct_member(ir_type *strct, ir_entity *member)
{
int i;
assert(strct && (strct->type_op == type_struct));
for (i = 0; i < (ARR_LEN (strct->attr.sa.members)); i++)
if (strct->attr.sa.members[i] == member) {
- for(; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
+ for (; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
ARR_SETLEN(ir_entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
break;
* @param len number of fields
* @param tps array of field types with length len
*/
-static ir_type *build_value_type(int len, tp_ent_pair *tps)
+static ir_type *build_value_type(char const* name, int len, tp_ent_pair *tps)
{
int i;
- ir_type *res = new_type_struct(NULL);
+ ir_type *res = new_type_struct(new_id_from_str(name));
res->flags |= tf_value_param_type;
/* Remove type from type list. Must be treated differently than other types. */
remove_irp_type(res);
res->attr.ma.variadicity = variadicity_non_variadic;
res->attr.ma.first_variadic_param = -1;
res->attr.ma.additional_properties = mtp_no_property;
- res->attr.ma.irg_calling_conv = default_cc_mask;
hook_new_type(res);
return res;
}
if (!method->attr.ma.value_params) {
/* parameter value type not created yet, build */
- method->attr.ma.value_params
- = build_value_type(get_method_n_params(method),
- method->attr.ma.params);
+ method->attr.ma.value_params = build_value_type("<value param>",
+ get_method_n_params(method), method->attr.ma.params);
}
/*
* build_value_type() sets the method->attr.ma.value_params type as default if
if (!method->attr.ma.value_ress) {
/* result value type not created yet, build */
- method->attr.ma.value_ress
- = build_value_type(get_method_n_ress(method),
- method->attr.ma.res_type);
+ method->attr.ma.value_ress = build_value_type("<value result>",
+ get_method_n_ress(method), method->attr.ma.res_type);
}
/*
* build_value_type() sets the method->attr.ma.value_ress type as default if
const char *get_union_name(const ir_type *uni)
{
+ if (get_union_ident(uni) == NULL)
+ return NULL;
return get_id_str(get_union_ident(uni));
}
return ARR_LEN(uni->attr.ua.members);
}
-void add_union_member(ir_type *uni, ir_entity *member)
+static void add_union_member(ir_type *uni, ir_entity *member)
{
assert(uni && (uni->type_op == type_union));
assert(uni != get_entity_type(member) && "recursive type");
- assert(get_type_state(uni) != layout_fixed);
ARR_APP1(ir_entity *, uni->attr.ua.members, member);
}
uni->attr.ua.members[pos] = member;
}
-void remove_union_member(ir_type *uni, ir_entity *member)
+static void remove_union_member(ir_type *uni, ir_entity *member)
{
int i;
assert(uni && (uni->type_op == type_union));
for (i = 0; i < (ARR_LEN(uni->attr.ua.members)); i++) {
if (uni->attr.ua.members[i] == member) {
- for(; i < (ARR_LEN(uni->attr.ua.members))-1; i++)
+ for (; i < (ARR_LEN(uni->attr.ua.members))-1; i++)
uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
ARR_SETLEN(ir_entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
break;
current_ir_graph = rem;
res->attr.aa.element_type = element_type;
- new_entity(res, new_id_from_chars("elem_ent", 8), element_type);
+ res->attr.aa.element_ent
+ = new_entity(NULL, new_id_from_chars("elem_ent", 8), element_type);
+ res->attr.aa.element_ent->owner = res;
+
hook_new_type(res);
return res;
}
const char *get_enumeration_name(const ir_type *enumeration)
{
+ if (get_enumeration_ident(enumeration) == NULL)
+ return NULL;
return get_id_str(get_enumeration_ident(enumeration));
}
const char *get_compound_name(const ir_type *tp)
{
+ if (get_compound_ident(tp) == NULL)
+ return NULL;
return get_id_str(get_compound_ident(tp));
}
+void remove_compound_member(ir_type *compound, ir_entity *entity)
+{
+ switch (get_type_tpop_code(compound)) {
+ case tpo_class: remove_class_member(compound, entity); break;
+ case tpo_struct: remove_struct_member(compound, entity); break;
+ case tpo_union: remove_union_member(compound, entity); break;
+ default:
+ panic("argument for remove_compound_member not a compound type");
+ }
+}
+
+void add_compound_member(ir_type *compound, ir_entity *entity)
+{
+ switch (get_type_tpop_code(compound)) {
+ case tpo_class: add_class_member(compound, entity); break;
+ case tpo_struct: add_struct_member(compound, entity); break;
+ case tpo_union: add_union_member(compound, entity); break;
+ default:
+ panic("argument for add_compound_member not a compound type");
+ }
+}
+
+
+
int is_code_type(const ir_type *tp)
{
assert(tp && tp->kind == k_type);
tp->size = size;
}
+void default_layout_compound_type(ir_type *type)
+{
+ int i;
+ int n = get_compound_n_members(type);
+ int size = 0;
+ unsigned align_all = 1;
+
+ for (i = 0; i < n; ++i) {
+ ir_entity *entity = get_compound_member(type, i);
+ ir_type *entity_type = get_entity_type(entity);
+ unsigned align;
+ unsigned misalign;
+
+ if (is_Method_type(entity_type))
+ continue;
+
+ assert(get_type_state(entity_type) == layout_fixed);
+ align = get_type_alignment_bytes(entity_type);
+ align_all = align > align_all ? align : align_all;
+ misalign = (align ? size % align : 0);
+ size += (misalign ? align - misalign : 0);
+
+ set_entity_offset(entity, size);
+ if (!is_Union_type(type)) {
+ size += get_type_size_bytes(entity_type);
+ }
+ }
+ if (align_all > 0 && size % align_all) {
+ size += align_all - (size % align_all);
+ }
+ if (align_all > get_type_alignment_bytes(type)) {
+ set_type_alignment_bytes(type, align_all);
+ }
+ set_type_size_bytes(type, size);
+ set_type_state(type, layout_fixed);
+}
+
ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment,
int at_start)
{