BugFix: fixed list_for_each_safe() instance.
[libfirm] / ir / tr / type.c
index d84ef16..ab81082 100644 (file)
@@ -144,7 +144,7 @@ ir_type *new_type(const tp_op *type_op, ir_mode *mode, type_dbg_info *db)
        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;
@@ -365,7 +365,6 @@ void set_type_state(ir_type *tp, ir_type_state state)
                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:
@@ -971,18 +970,6 @@ void set_class_type_info(ir_type *clss, ir_entity *ent)
                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));
@@ -2239,6 +2226,43 @@ void set_default_size(ir_type *tp, unsigned size)
        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)
 {