Added has_entity_initializer() and get_initializer_kind_name()
[libfirm] / ir / tr / type.c
index 562cb66..0c3109f 100644 (file)
 
 #include "config.h"
 
-#ifdef HAVE_STRING_H
-# include <string.h>
-#endif
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-
+#include <string.h>
+#include <stdlib.h>
 #include <stddef.h>
 
 #include "type_t.h"
@@ -478,8 +473,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) {
                if (get_class_n_supertypes(typ1) != get_class_n_supertypes(typ2)) return 0;
                if (get_class_peculiarity(typ1) != get_class_peculiarity(typ2)) return 0;
                /** Compare the members **/
-               m = alloca(sizeof(ir_entity *) * get_class_n_members(typ1));
-               memset(m, 0, sizeof(ir_entity *) * get_class_n_members(typ1));
+               m = ALLOCANZ(ir_entity*, get_class_n_members(typ1));
                /* First sort the members of typ2 */
                for (i = 0; i < get_class_n_members(typ1); i++) {
                        ir_entity *e1 = get_class_member(typ1, i);
@@ -495,8 +489,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) {
                                return 0;
                }
                /** Compare the supertypes **/
-               t = alloca(sizeof(ir_entity *) * get_class_n_supertypes(typ1));
-               memset(t, 0, sizeof(ir_entity *) * get_class_n_supertypes(typ1));
+               t = ALLOCANZ(ir_type*, get_class_n_supertypes(typ1));
                /* First sort the supertypes of typ2 */
                for (i = 0; i < get_class_n_supertypes(typ1); i++) {
                        ir_type *t1 = get_class_supertype(typ1, i);
@@ -515,8 +508,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) {
 
        case tpo_struct:
                if (get_struct_n_members(typ1) != get_struct_n_members(typ2)) return 0;
-               m = alloca(sizeof(ir_entity *) * get_struct_n_members(typ1));
-               memset(m, 0, sizeof(ir_entity *) * get_struct_n_members(typ1));
+               m = ALLOCANZ(ir_entity*, get_struct_n_members(typ1));
                /* First sort the members of lt */
                for (i = 0; i < get_struct_n_members(typ1); i++) {
                        ir_entity *e1 = get_struct_member(typ1, i);
@@ -563,8 +555,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) {
 
        case tpo_union:
                if (get_union_n_members(typ1) != get_union_n_members(typ2)) return 0;
-               m = alloca(sizeof(ir_entity *) * get_union_n_members(typ1));
-               memset(m, 0, sizeof(ir_entity *) * get_union_n_members(typ1));
+               m = ALLOCANZ(ir_entity*, get_union_n_members(typ1));
                /* First sort the members of lt */
                for (i = 0; i < get_union_n_members(typ1); i++) {
                        ir_entity *e1 = get_union_member(typ1, i);
@@ -631,8 +622,7 @@ int smaller_type(ir_type *st, ir_type *lt) {
                if (n_st_members != get_struct_n_members(lt))
                        return 0;
 
-               m = alloca(sizeof(ir_entity *) * n_st_members);
-               memset(m, 0, sizeof(ir_entity *) * n_st_members);
+               m = ALLOCANZ(ir_entity*, n_st_members);
                /* First sort the members of lt */
                for (i = 0; i < n_st_members; ++i) {
                        ir_entity *se = get_struct_member(st, i);
@@ -682,8 +672,7 @@ int smaller_type(ir_type *st, ir_type *lt) {
        case tpo_union:
                n_st_members = get_union_n_members(st);
                if (n_st_members != get_union_n_members(lt)) return 0;
-               m = alloca(sizeof(ir_entity *) * n_st_members);
-               memset(m, 0, sizeof(ir_entity *) * n_st_members);
+               m = ALLOCANZ(ir_entity*, n_st_members);
                /* First sort the members of lt */
                for (i = 0; i < n_st_members; ++i) {
                        ir_entity *se = get_union_member(st, i);
@@ -1172,7 +1161,7 @@ build_value_type(ident *name, int len, tp_ent_pair *tps) {
 
                /* use the parameter name if specified */
                if (! id)
-                       id = mangle_u(name, get_type_ident(elt_type));
+                       id = id_mangle_u(name, get_type_ident(elt_type));
                tps[i].ent = new_entity(res, id, elt_type);
                set_entity_allocation(tps[i].ent, allocation_parameter);
        }
@@ -1218,7 +1207,7 @@ ir_type *clone_type_method(ir_type *tp, ident *prefix) {
 
        name = tp->name;
        if (prefix != NULL)
-               name = mangle(prefix, name);
+               name = id_mangle(prefix, name);
 
        mode     = tp->mode;
        n_params = tp->attr.ma.n_params;
@@ -1325,7 +1314,7 @@ ir_entity *get_method_value_param_ent(ir_type *method, int pos) {
        if (!method->attr.ma.value_params) {
                /* parameter value type not created yet, build */
                method->attr.ma.value_params
-                       = build_value_type(mangle_u(get_type_ident(method), value_params_suffix),
+                       = build_value_type(id_mangle_u(get_type_ident(method), value_params_suffix),
                        get_method_n_params(method), method->attr.ma.params);
        }
        /*
@@ -1379,7 +1368,7 @@ ir_entity *get_method_value_res_ent(ir_type *method, int pos) {
        if (!method->attr.ma.value_ress) {
                /* result value type not created yet, build */
                method->attr.ma.value_ress
-                       = build_value_type(mangle_u(get_type_ident(method), value_ress_suffix),
+                       = build_value_type(id_mangle_u(get_type_ident(method), value_ress_suffix),
                        get_method_n_ress(method), method->attr.ma.res_type);
        }
        /*
@@ -1401,7 +1390,7 @@ ir_type *get_method_value_res_type(const ir_type *method) {
 }
 
 /* Returns the null-terminated name of this variadicity. */
-const char *get_variadicity_name(variadicity vari) {
+const char *get_variadicity_name(ir_variadicity vari) {
 #define X(a)    case a: return #a
        switch (vari) {
        X(variadicity_non_variadic);
@@ -1412,12 +1401,12 @@ const char *get_variadicity_name(variadicity vari) {
 #undef X
 }
 
-variadicity get_method_variadicity(const ir_type *method) {
+ir_variadicity get_method_variadicity(const ir_type *method) {
        assert(method && (method->type_op == type_method));
        return method->attr.ma.variadicity;
 }
 
-void set_method_variadicity(ir_type *method, variadicity vari) {
+void set_method_variadicity(ir_type *method, ir_variadicity vari) {
        assert(method && (method->type_op == type_method));
        method->attr.ma.variadicity = vari;
 }
@@ -1609,7 +1598,7 @@ ir_type *new_d_type_array(ident *name, int n_dimensions, ir_type *element_type,
        current_ir_graph = rem;
 
        res->attr.aa.element_type = element_type;
-       new_entity(res, mangle_u(name, new_id_from_chars("elem_ent", 8)), element_type);
+       new_entity(res, id_mangle_u(name, new_id_from_chars("elem_ent", 8)), element_type);
        hook_new_type(res);
        return res;
 }
@@ -1656,8 +1645,8 @@ set_array_bounds_int(ir_type *array, int dimension, int lower_bound, int upper_b
        ir_graph *rem = current_ir_graph;
        current_ir_graph = get_const_code_irg();
        set_array_bounds(array, dimension,
-                 new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)),
-                 new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu )));
+                 new_Const_long(mode_Iu, lower_bound),
+                 new_Const_long(mode_Iu, upper_bound));
        current_ir_graph = rem;
 }
 
@@ -1672,7 +1661,7 @@ 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();
        set_array_lower_bound(array, dimension,
-            new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)));
+            new_Const_long(mode_Iu, lower_bound));
        current_ir_graph = rem;
 }
 void
@@ -1685,7 +1674,7 @@ 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();
        set_array_upper_bound(array, dimension,
-                   new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu)));
+                   new_Const_long(mode_Iu, upper_bound));
        current_ir_graph = rem;
 }
 
@@ -2073,6 +2062,8 @@ ir_type *clone_frame_type(ir_type *type) {
        int     i, n;
 
        assert(is_frame_type(type));
+       /* the entity link resource should be allocated if this function is called */
+       assert(irp_resources_reserved(irp) & IR_RESOURCE_ENTITY_LINK);
 
        res = new_type_frame(type->name);
        for (i = 0, n = get_class_n_members(type); i < n; ++i) {
@@ -2135,7 +2126,7 @@ ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment, i
        frame_align = get_type_alignment_bytes(frame_type);
        size = (size + frame_align - 1) & ~(frame_align - 1);
 
-       tp = new_type_array(mangle_u(get_type_ident(frame_type), name), 1, a_byte);
+       tp = new_type_array(id_mangle_u(get_type_ident(frame_type), name), 1, a_byte);
        set_array_bounds_int(tp, 0, 0, size);
        set_type_alignment_bytes(tp, alignment);