/*
- * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
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;
ir_type *new_type(const tp_op *type_op, ir_mode *mode, type_dbg_info *db)
{
ir_type *res;
- int node_size;
+ size_t node_size;
node_size = offsetof(ir_type, attr) + type_op->attr_size;
- res = xmalloc(node_size);
+ res = (ir_type*)xmalloc(node_size);
memset(res, 0, node_size);
res->kind = k_type;
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);
+ ir_tarval *tv = get_enumeration_value(ec);
assert(tv != NULL && tv != tarval_bad);
}
#endif
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");
return NULL;
}
-void set_class_member(ir_type *clss, ir_entity *member, int pos)
-{
- assert(clss && (clss->type_op == type_class));
- assert(pos >= 0 && pos < get_class_n_members(clss));
- clss->attr.ca.members[pos] = member;
-}
-
-void set_class_members(ir_type *clss, ir_entity **members, int arity)
-{
- int i;
- assert(clss && (clss->type_op == type_class));
- DEL_ARR_F(clss->attr.ca.members);
- clss->attr.ca.members = NEW_ARR_F(ir_entity *, 0);
- for (i = 0; i < arity; ++i) {
- set_entity_owner(members[i], clss);
- ARR_APP1(ir_entity *, clss->attr.ca.members, members[i]);
- }
-}
-
-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));
if (clss->attr.ca.subtypes[i] == subtype) {
for (; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
- ARR_SETLEN(ir_entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
+ ARR_SETLEN(ir_type*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
break;
}
}
if (clss->attr.ca.supertypes[i] == supertype) {
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);
+ ARR_SETLEN(ir_type*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
break;
}
}
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);
return -1;
}
-void set_struct_member(ir_type *strct, int pos, ir_entity *member)
-{
- assert(strct && (strct->type_op == type_struct));
- assert(pos >= 0 && pos < get_struct_n_members(strct));
- assert(get_entity_type(member)->type_op != type_method);/* @@@ lowerfirm !!*/
- 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));
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;
}
method->attr.ma.first_variadic_param = index;
}
-unsigned (get_method_additional_properties)(const ir_type *method)
+mtp_additional_properties (get_method_additional_properties)(const ir_type *method)
{
return _get_method_additional_properties(method);
}
-void (set_method_additional_properties)(ir_type *method, unsigned mask)
+void (set_method_additional_properties)(ir_type *method, mtp_additional_properties mask)
{
_set_method_additional_properties(method, mask);
}
-void (set_method_additional_property)(ir_type *method,
- mtp_additional_property flag)
+void (add_method_additional_properties)(ir_type *method,
+ mtp_additional_properties flag)
{
- _set_method_additional_property(method, flag);
+ _add_method_additional_properties(method, flag);
}
unsigned (get_method_calling_convention)(const ir_type *method)
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");
return -1;
}
-void set_union_member(ir_type *uni, int pos, ir_entity *member)
-{
- assert(uni && (uni->type_op == type_union));
- assert(pos >= 0 && pos < get_union_n_members(uni));
- 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));
ir_type *res;
int i;
ir_node *unk;
- ir_graph *rem = current_ir_graph;
+ ir_graph *irg = get_const_code_irg();
assert(!is_Method_type(element_type));
res->attr.aa.upper_bound = XMALLOCNZ(ir_node*, n_dimensions);
res->attr.aa.order = XMALLOCNZ(int, n_dimensions);
- current_ir_graph = get_const_code_irg();
- unk = new_Unknown(mode_Iu);
+ unk = new_r_Unknown(irg, mode_Iu);
for (i = 0; i < n_dimensions; i++) {
res->attr.aa.lower_bound[i] =
res->attr.aa.upper_bound[i] = unk;
res->attr.aa.order[i] = i;
}
- 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;
}
void set_array_bounds_int(ir_type *array, int dimension, int lower_bound,
int upper_bound)
{
- ir_graph *rem = current_ir_graph;
- current_ir_graph = get_const_code_irg();
+ ir_graph *irg = get_const_code_irg();
set_array_bounds(array, dimension,
- new_Const_long(mode_Iu, lower_bound),
- new_Const_long(mode_Iu, upper_bound));
- current_ir_graph = rem;
+ new_r_Const_long(irg, mode_Iu, lower_bound),
+ new_r_Const_long(irg, mode_Iu, upper_bound));
}
void set_array_lower_bound(ir_type *array, int dimension, ir_node *lower_bound)
void set_array_lower_bound_int(ir_type *array, int dimension, int lower_bound)
{
- ir_graph *rem = current_ir_graph;
- current_ir_graph = get_const_code_irg();
+ ir_graph *irg = get_const_code_irg();
set_array_lower_bound(array, dimension,
- new_Const_long(mode_Iu, lower_bound));
- current_ir_graph = rem;
+ new_r_Const_long(irg, mode_Iu, lower_bound));
}
void set_array_upper_bound(ir_type *array, int dimension, ir_node *upper_bound)
void set_array_upper_bound_int(ir_type *array, int dimension, int upper_bound)
{
- ir_graph *rem = current_ir_graph;
- current_ir_graph = get_const_code_irg();
+ ir_graph *irg = get_const_code_irg();
set_array_upper_bound(array, dimension,
- new_Const_long(mode_Iu, upper_bound));
- current_ir_graph = rem;
+ new_r_Const_long(irg, mode_Iu, upper_bound));
}
int has_array_lower_bound(const ir_type *array, int dimension)
}
void set_enumeration_const(ir_type *enumeration, int pos, ident *nameid,
- tarval *con)
+ ir_tarval *con)
{
assert(0 <= pos && pos < ARR_LEN(enumeration->attr.ea.enumer));
enumeration->attr.ea.enumer[pos].nameid = nameid;
return enum_cnst->owner;
}
-void set_enumeration_value(ir_enum_const *enum_cnst, tarval *con)
+void set_enumeration_value(ir_enum_const *enum_cnst, ir_tarval *con)
{
enum_cnst->value = con;
}
-tarval *get_enumeration_value(const ir_enum_const *enum_cnst)
+ir_tarval *get_enumeration_value(const ir_enum_const *enum_cnst)
{
return enum_cnst->value;
}
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);