X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftr%2Ftype.c;h=de55dcfb8ed76802487ce6e5bd75a7f45292f1fd;hb=a523fd61fdc33d765729c82684bfaca9a5401ef0;hp=925dc68a0aa855c2225c5f260a8d55320f97a4df;hpb=a6e674f74ea93c3661f100088db520acb701571f;p=libfirm diff --git a/ir/tr/type.c b/ir/tr/type.c index 925dc68a0..de55dcfb8 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -1,5 +1,5 @@ /* - * 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. * @@ -85,17 +85,8 @@ ir_type *get_unknown_type(void) 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); @@ -115,6 +106,24 @@ void firm_init_type(unsigned def_cc_mask) 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; @@ -136,10 +145,10 @@ void (inc_master_type_visited)(void) 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; @@ -381,7 +390,7 @@ void set_type_state(ir_type *tp, ir_type_state state) 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 @@ -776,7 +785,7 @@ const char *get_class_name(const ir_type *clss) 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"); @@ -815,26 +824,7 @@ ir_entity *get_class_member_by_name(ir_type *clss, ident *name) 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)); @@ -898,7 +888,7 @@ void remove_class_subtype(ir_type *clss, ir_type *subtype) 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; } } @@ -954,7 +944,7 @@ void remove_class_supertype(ir_type *clss, ir_type *supertype) 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; } } @@ -1101,7 +1091,7 @@ int get_struct_n_members(const ir_type *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); @@ -1126,15 +1116,7 @@ int get_struct_member_index(const ir_type *strct, ir_entity *mem) 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)); @@ -1215,7 +1197,6 @@ ir_type *new_d_type_method(int n_param, int n_res, type_dbg_info *db) 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; } @@ -1470,20 +1451,20 @@ void set_method_first_variadic_param_index(ir_type *method, int index) 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) @@ -1566,7 +1547,7 @@ int get_union_n_members(const ir_type *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"); @@ -1591,14 +1572,7 @@ int get_union_member_index(const ir_type *uni, ir_entity *mem) 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)); @@ -1630,7 +1604,7 @@ ir_type *new_d_type_array(int n_dimensions, ir_type *element_type, 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)); @@ -1640,17 +1614,18 @@ ir_type *new_d_type_array(int n_dimensions, ir_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; } @@ -1701,12 +1676,10 @@ void set_array_bounds(ir_type *array, int dimension, ir_node *lower_bound, 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) @@ -1718,11 +1691,9 @@ 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) @@ -1734,11 +1705,9 @@ 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) @@ -1896,7 +1865,7 @@ int get_enumeration_n_enums(const ir_type *enumeration) } 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; @@ -1916,12 +1885,12 @@ ir_type *get_enumeration_owner(const ir_enum_const *enum_cnst) 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; } @@ -2142,6 +2111,30 @@ const char *get_compound_name(const ir_type *tp) 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);