Improved native detection further.
[libfirm] / ir / tr / type.c
index 30a9bf4..3f909d3 100644 (file)
@@ -85,7 +85,7 @@ ir_type *get_unknown_type(void)
 static ident *value_params_suffix = NULL;
 static ident *value_ress_suffix = NULL;
 
-void firm_init_type(void)
+void ir_init_type(void)
 {
        value_params_suffix = new_id_from_str(VALUE_PARAMS_SUFFIX);
        value_ress_suffix   = new_id_from_str(VALUE_RESS_SUFFIX);
@@ -106,6 +106,24 @@ void firm_init_type(void)
        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;
 
@@ -130,7 +148,7 @@ ir_type *new_type(const tp_op *type_op, ir_mode *mode, type_dbg_info *db)
        int 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;
@@ -372,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
@@ -806,25 +824,6 @@ 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]);
-       }
-}
-
 static void remove_class_member(ir_type *clss, ir_entity *member)
 {
        int i;
@@ -889,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;
                }
 }
@@ -945,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;
                }
 }
@@ -1117,14 +1116,6 @@ 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;
-}
-
 static void remove_struct_member(ir_type *strct, ir_entity *member)
 {
        int i;
@@ -1460,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)
@@ -1581,13 +1572,6 @@ 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;
-}
-
 static void remove_union_member(ir_type *uni, ir_entity *member)
 {
        int i;
@@ -1620,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));
 
@@ -1630,14 +1614,12 @@ 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;
        res->attr.aa.element_ent
@@ -1694,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)
@@ -1711,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)
@@ -1727,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)
@@ -1889,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;
@@ -1909,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;
 }