remove #ifdef HAVE_CONFIG_Hs
[libfirm] / ir / tr / type.c
index 1a02978..562cb66 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -45,9 +45,7 @@
  * @see  type_t.h type tpop
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #ifdef HAVE_STRING_H
 # include <string.h>
@@ -110,11 +108,11 @@ void firm_init_type(dbg_info *builtin_db, unsigned def_cc_mask) {
 }
 
 /** the global type visited flag */
-unsigned long firm_type_visited;
+ir_visited_t firm_type_visited;
 
-void (set_master_type_visited)(unsigned long val) { _set_master_type_visited(val); }
-unsigned long (get_master_type_visited)(void)     { return _get_master_type_visited(); }
-void (inc_master_type_visited)(void)              { _inc_master_type_visited(); }
+void (set_master_type_visited)(ir_visited_t val) { _set_master_type_visited(val); }
+ir_visited_t (get_master_type_visited)(void)     { return _get_master_type_visited(); }
+void (inc_master_type_visited)(void)             { _inc_master_type_visited(); }
 
 /*
  * Creates a new type representation.
@@ -137,8 +135,8 @@ new_type(tp_op *type_op, ir_mode *mode, ident *name, dbg_info *db) {
        res->name       = name;
        res->visibility = visibility_external_allocated;
        res->flags      = tf_none;
-       res->size       = -1;
-       res->align      = -1;
+       res->size       = 0;
+       res->align      = 0;
        res->visit      = 0;
        res->link       = NULL;
        res->dbi        = db;
@@ -245,15 +243,10 @@ const char *get_type_name(const ir_type *tp) {
        return (get_id_str(tp->name));
 }
 
-int (get_type_size_bytes)(const ir_type *tp) {
+unsigned (get_type_size_bytes)(const ir_type *tp) {
        return _get_type_size_bytes(tp);
 }
 
-int (get_type_size_bits)(const ir_type *tp) {
-       return _get_type_size_bits(tp);
-}
-
-
 ir_visibility get_type_visibility(const ir_type *tp) {
 #if 0
        visibility res =  visibility_local;
@@ -305,7 +298,7 @@ void set_type_visibility(ir_type *tp, ir_visibility v) {
 }
 
 void
-set_type_size_bits(ir_type *tp, int size) {
+set_type_size_bytes(ir_type *tp, unsigned size) {
        const tp_op *tpop = get_type_tpop(tp);
 
        if (tpop->ops.set_type_size)
@@ -314,35 +307,24 @@ set_type_size_bits(ir_type *tp, int size) {
                assert(0 && "Cannot set size for this type");
 }
 
-void
-set_type_size_bytes(ir_type *tp, int size) {
-       set_type_size_bits(tp, 8*size);
-}
-
-int get_type_alignment_bytes(ir_type *tp) {
-       int align = get_type_alignment_bits(tp);
-
-       return align < 0 ? align : (align + 7) >> 3;
-}
-
-int get_type_alignment_bits(ir_type *tp) {
-       int align = 8;
+unsigned get_type_alignment_bytes(ir_type *tp) {
+       unsigned align = 1;
 
        if (tp->align > 0)
                return tp->align;
 
        /* alignment NOT set calculate it "on demand" */
        if (tp->mode)
-               align = get_mode_size_bits(tp->mode);
+               align = (get_mode_size_bits(tp->mode) + 7) >> 3;
        else if (is_Array_type(tp))
-               align = get_type_alignment_bits(get_array_element_type(tp));
+               align = get_type_alignment_bytes(get_array_element_type(tp));
        else if (is_compound_type(tp)) {
                int i, n = get_compound_n_members(tp);
 
                align = 0;
                for (i = 0; i < n; ++i) {
-                       ir_type *t = get_entity_type(get_compound_member(tp, i));
-                       int   a = get_type_alignment_bits(t);
+                       ir_type  *t = get_entity_type(get_compound_member(tp, i));
+                       unsigned a  = get_type_alignment_bytes(t);
 
                        if (a > align)
                                align = a;
@@ -358,24 +340,14 @@ int get_type_alignment_bits(ir_type *tp) {
 }
 
 void
-set_type_alignment_bits(ir_type *tp, int align) {
+set_type_alignment_bytes(ir_type *tp, unsigned align) {
        assert(tp && tp->kind == k_type);
-       assert((align == -1 || (align & (align - 1)) == 0) && "type alignment not power of two");
        /* Methods don't have an alignment. */
        if (tp->type_op != type_method) {
                tp->align = align;
        }
 }
 
-void
-set_type_alignment_bytes(ir_type *tp, int align) {
-       if (align == -1) {
-               set_type_alignment_bits(tp, -1);
-       } else {
-               set_type_alignment_bits(tp, 8*align);
-       }
-}
-
 /* Returns a human readable string for the enum entry. */
 const char *get_type_state_name(ir_type_state s) {
 #define X(a)    case a: return #a;
@@ -405,7 +377,6 @@ set_type_state(ir_type *tp, ir_type_state state) {
                int i;
                switch (get_type_tpop_code(tp)) {
                case tpo_class:
-                       assert(get_type_size_bits(tp) > -1);
                        if (tp != get_glob_type()) {
                                int n_mem = get_class_n_members(tp);
                                for (i = 0; i < n_mem; i++) {
@@ -418,7 +389,6 @@ set_type_state(ir_type *tp, ir_type_state state) {
                        }
                        break;
                case tpo_struct:
-                       assert(get_type_size_bits(tp) > -1);
                        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));
@@ -451,11 +421,11 @@ set_type_state(ir_type *tp, ir_type_state state) {
                tp->flags &= ~tf_layout_fixed;
 }
 
-unsigned long (get_type_visited)(const ir_type *tp) {
+ir_visited_t (get_type_visited)(const ir_type *tp) {
        return _get_type_visited(tp);
 }
 
-void (set_type_visited)(ir_type *tp, unsigned long num) {
+void (set_type_visited)(ir_type *tp, ir_visited_t num) {
        _set_type_visited(tp, num);
 }
 
@@ -498,7 +468,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) {
            (get_type_state(typ1) != get_type_state(typ2)))
                return 0;
        if ((get_type_state(typ1) == layout_fixed) &&
-               (get_type_size_bits(typ1) != get_type_size_bits(typ2)))
+               (get_type_size_bytes(typ1) != get_type_size_bytes(typ2)))
                return 0;
 
        switch (get_type_tpop_code(typ1)) {
@@ -746,7 +716,7 @@ int smaller_type(ir_type *st, ir_type *lt) {
                            (get_type_state(let) != layout_fixed))
                                return 0;
                        if (!smaller_type(set, let) ||
-                           get_type_size_bits(set) != get_type_size_bits(let))
+                           get_type_size_bytes(set) != get_type_size_bytes(let))
                                return 0;
                }
                for(i = 0; i < get_array_n_dimensions(st); i++) {
@@ -824,6 +794,7 @@ void free_class_attrs(ir_type *clss) {
 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");
+       assert(get_type_state(clss) != layout_fixed);
        ARR_APP1 (ir_entity *, clss->attr.ca.members, member);
 }
 
@@ -1072,14 +1043,12 @@ int (is_Class_type)(const ir_type *clss) {
 void set_class_mode(ir_type *tp, ir_mode *mode) {
        /* for classes and structs we allow to set a mode if the layout is fixed AND the size matches */
        assert(get_type_state(tp) == layout_fixed &&
-              tp->size == get_mode_size_bits(mode) && "mode don't match class layout");
+              tp->size == get_mode_size_bytes(mode) && "mode don't match class layout");
        tp->mode = mode;
 }
 
-void set_class_size_bits(ir_type *tp, int size) {
-       /* argh: we must allow to set negative values as "invalid size" */
-       tp->size = (size >= 0) ? (size + 7) & ~7 : size;
-       assert(tp->size == size && "setting a bit size is NOT allowed for this type");
+void set_class_size(ir_type *tp, unsigned size) {
+       tp->size = size;
 }
 
 /*----------------------------------------------------------------**/
@@ -1121,6 +1090,7 @@ 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);
        assert(strct != get_entity_type(member) && "recursive type");
+       assert(get_type_state(strct) != layout_fixed);
        ARR_APP1 (ir_entity *, strct->attr.sa.members, member);
 }
 
@@ -1166,14 +1136,12 @@ int (is_Struct_type)(const ir_type *strct) {
 void set_struct_mode(ir_type *tp, ir_mode *mode) {
        /* for classes and structs we allow to set a mode if the layout is fixed AND the size matches */
        assert(get_type_state(tp) == layout_fixed &&
-              tp->size == get_mode_size_bits(mode) && "mode don't match struct layout");
+              tp->size == get_mode_size_bytes(mode) && "mode don't match struct layout");
        tp->mode = mode;
 }
 
-void set_struct_size_bits(ir_type *tp, int size) {
-       /* argh: we must allow to set negative values as "invalid size" */
-       tp->size = (size >= 0) ? (size + 7) & ~7 : size;
-       assert(tp->size == size && "setting a bit size is NOT allowed for this type");
+void set_struct_size(ir_type *tp, unsigned size) {
+       tp->size = size;
 }
 
 /*******************************************************************/
@@ -1216,15 +1184,15 @@ build_value_type(ident *name, int len, tp_ent_pair *tps) {
 ir_type *new_d_type_method(ident *name, int n_param, int n_res, dbg_info *db) {
        ir_type *res;
 
-       assert((get_mode_size_bytes(mode_P_code) != -1) && "unorthodox modes not implemented");
+       assert((get_mode_size_bits(mode_P_code) % 8 == 0) && "unorthodox modes not implemented");
        res = new_type(type_method, mode_P_code, name, db);
        res->flags                       |= tf_layout_fixed;
-       res->size                         = get_mode_size_bits(mode_P_code);
+       res->size                         = get_mode_size_bytes(mode_P_code);
        res->attr.ma.n_params             = n_param;
-       res->attr.ma.params               = xcalloc(n_param, sizeof(res->attr.ma.params[0]));
+       res->attr.ma.params               = XMALLOCNZ(tp_ent_pair, n_param);
        res->attr.ma.value_params         = NULL;
        res->attr.ma.n_res                = n_res;
-       res->attr.ma.res_type             = xcalloc(n_res, sizeof(res->attr.ma.res_type[0]));
+       res->attr.ma.res_type             = XMALLOCNZ(tp_ent_pair, n_res);
        res->attr.ma.value_ress           = NULL;
        res->attr.ma.variadicity          = variadicity_non_variadic;
        res->attr.ma.first_variadic_param = -1;
@@ -1238,6 +1206,46 @@ ir_type *new_type_method(ident *name, int n_param, int n_res) {
        return new_d_type_method(name, n_param, n_res, NULL);
 }
 
+/* clone an existing method type */
+ir_type *clone_type_method(ir_type *tp, ident *prefix) {
+       ir_type  *res;
+       ident    *name;
+       ir_mode  *mode;
+       int      n_params, n_res;
+       dbg_info *db;
+
+       assert(is_Method_type(tp));
+
+       name = tp->name;
+       if (prefix != NULL)
+               name = mangle(prefix, name);
+
+       mode     = tp->mode;
+       n_params = tp->attr.ma.n_params;
+       n_res    = tp->attr.ma.n_res;
+       db       = tp->dbi;
+
+       res = new_type(type_method, mode, name, db);
+
+       res->flags                         = tp->flags;
+       res->assoc_type                    = tp->assoc_type;
+       res->size                          = tp->size;
+       res->attr.ma.n_params              = n_params;
+       res->attr.ma.params                = XMALLOCN(tp_ent_pair, n_params);
+       memcpy(res->attr.ma.params, tp->attr.ma.params, n_params * sizeof(res->attr.ma.params[0]));
+       res->attr.ma.value_params          = tp->attr.ma.value_params;
+       res->attr.ma.n_res                 = n_res;
+       res->attr.ma.res_type              = XMALLOCN(tp_ent_pair, n_res);
+       memcpy(res->attr.ma.res_type, tp->attr.ma.res_type, n_res * sizeof(res->attr.ma.res_type[0]));
+       res->attr.ma.value_ress            = tp->attr.ma.value_ress;
+       res->attr.ma.variadicity           = tp->attr.ma.variadicity;
+       res->attr.ma.first_variadic_param  = tp->attr.ma.first_variadic_param;
+       res->attr.ma.additional_properties = tp->attr.ma.additional_properties;
+       res->attr.ma.irg_calling_conv      = tp->attr.ma.irg_calling_conv;
+       hook_new_type(res);
+       return res;
+}
+
 void free_method_entities(ir_type *method) {
   (void) method;
        assert(method && (method->type_op == type_method));
@@ -1248,10 +1256,12 @@ void free_method_attrs(ir_type *method) {
        assert(method && (method->type_op == type_method));
        free(method->attr.ma.params);
        free(method->attr.ma.res_type);
+       /* cannot free it yet, type could be cloned ...
        if (method->attr.ma.value_params) {
                free_type_entities(method->attr.ma.value_params);
                free_type(method->attr.ma.value_params);
        }
+       */
        if (method->attr.ma.value_ress) {
                free_type_entities(method->attr.ma.value_ress);
                free_type(method->attr.ma.value_ress);
@@ -1523,6 +1533,7 @@ int get_union_n_members(const ir_type *uni) {
 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");
+       assert(get_type_state(uni) != layout_fixed);
        ARR_APP1(ir_entity *, uni->attr.ua.members, member);
 }
 
@@ -1564,10 +1575,8 @@ int (is_Union_type)(const ir_type *uni) {
        return _is_union_type(uni);
 }
 
-void set_union_size_bits(ir_type *tp, int size) {
-       /* argh: we must allow to set negative values as "invalid size" */
-       tp->size = (size >= 0) ? (size + 7) & ~7 : size;
-       assert(tp->size == size && "setting a bit size is NOT allowed for this type");
+void set_union_size(ir_type *tp, unsigned size) {
+       tp->size = size;
 }
 
 /*-----------------------------------------------------------------*/
@@ -1586,9 +1595,9 @@ ir_type *new_d_type_array(ident *name, int n_dimensions, ir_type *element_type,
 
        res = new_type(type_array, NULL, name, db);
        res->attr.aa.n_dimensions = n_dimensions;
-       res->attr.aa.lower_bound  = xcalloc(n_dimensions, sizeof(*res->attr.aa.lower_bound));
-       res->attr.aa.upper_bound  = xcalloc(n_dimensions, sizeof(*res->attr.aa.upper_bound));
-       res->attr.aa.order        = xcalloc(n_dimensions, sizeof(*res->attr.aa.order));
+       res->attr.aa.lower_bound  = XMALLOCNZ(ir_node*, n_dimensions);
+       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);
@@ -1682,7 +1691,7 @@ void set_array_upper_bound_int(ir_type *array, int dimension, int upper_bound) {
 
 int has_array_lower_bound(const ir_type *array, int dimension) {
        assert(array && (array->type_op == type_array));
-       return (get_irn_op(array->attr.aa.lower_bound[dimension]) != op_Unknown);
+       return !is_Unknown(array->attr.aa.lower_bound[dimension]);
 }
 
 ir_node *get_array_lower_bound(const ir_type *array, int dimension) {
@@ -1694,13 +1703,13 @@ long get_array_lower_bound_int(const ir_type *array, int dimension) {
        ir_node *node;
        assert(array && (array->type_op == type_array));
        node = array->attr.aa.lower_bound[dimension];
-       assert(get_irn_op(node) == op_Const);
+       assert(is_Const(node));
        return get_tarval_long(get_Const_tarval(node));
 }
 
 int has_array_upper_bound(const ir_type *array, int dimension) {
        assert(array && (array->type_op == type_array));
-       return get_irn_op(array->attr.aa.upper_bound[dimension]) != op_Unknown;
+       return !is_Unknown(array->attr.aa.upper_bound[dimension]);
 }
 
 ir_node *get_array_upper_bound(const ir_type *array, int dimension) {
@@ -1712,7 +1721,7 @@ long get_array_upper_bound_int(const ir_type *array, int dimension) {
        ir_node *node;
        assert(array && (array->type_op == type_array));
        node = array->attr.aa.upper_bound[dimension];
-       assert(get_irn_op(node) == op_Const);
+       assert(is_Const(node));
        return get_tarval_long(get_Const_tarval(node));
 }
 
@@ -1766,7 +1775,7 @@ int (is_Array_type)(const ir_type *array) {
        return _is_array_type(array);
 }
 
-void set_array_size_bits(ir_type *tp, int size) {
+void set_array_size(ir_type *tp, unsigned size) {
        /* FIXME: Here we should make some checks with the element type size */
        tp->size = size;
 }
@@ -1850,9 +1859,9 @@ int (is_Enumeration_type)(const ir_type *enumeration) {
 void set_enumeration_mode(ir_type *tp, ir_mode *mode) {
        assert(mode_is_int(mode) && "Modes of enumerations must be integers");
        /* For pointer and enumeration size depends on the mode, but only byte size allowed. */
-       assert((get_mode_size_bits(mode) & 7) == 0 && "unorthodox modes not implemented");
+       assert((get_mode_size_bits(mode) % 8) == 0 && "unorthodox modes not implemented");
 
-       tp->size = get_mode_size_bits(mode);
+       tp->size = get_mode_size_bytes(mode);
        tp->mode = mode;
 }
 
@@ -1867,8 +1876,8 @@ ir_type *new_d_type_pointer(ident *name, ir_type *points_to, ir_mode *ptr_mode,
        assert(mode_is_reference(ptr_mode));
        res = new_type(type_pointer, ptr_mode, name, db);
        res->attr.pa.points_to = points_to;
-       assert((get_mode_size_bytes(res->mode) != -1) && "unorthodox modes not implemented");
-       res->size = get_mode_size_bits(res->mode);
+       assert((get_mode_size_bits(res->mode) % 8 == 0) && "unorthodox modes not implemented");
+       res->size = get_mode_size_bytes(res->mode);
        res->flags |= tf_layout_fixed;
        hook_new_type(res);
        return res;
@@ -1909,7 +1918,7 @@ void set_pointer_mode(ir_type *tp, ir_mode *mode) {
        /* For pointer and enumeration size depends on the mode, but only byte size allowed. */
        assert((get_mode_size_bits(mode) & 7) == 0 && "unorthodox modes not implemented");
 
-       tp->size = get_mode_size_bits(mode);
+       tp->size = get_mode_size_bytes(mode);
        tp->mode = mode;
 }
 
@@ -1934,7 +1943,7 @@ ir_type *find_pointer_type_to_type (ir_type *tp) {
 /* create a new type primitive */
 ir_type *new_d_type_primitive(ident *name, ir_mode *mode, dbg_info *db) {
        ir_type *res = new_type(type_primitive, mode, name, db);
-       res->size  = get_mode_size_bits(mode);
+       res->size  = get_mode_size_bytes(mode);
        res->flags |= tf_layout_fixed;
        res->attr.ba.base_type = NULL;
        hook_new_type(res);
@@ -1955,7 +1964,7 @@ void set_primitive_mode(ir_type *tp, ir_mode *mode) {
        assert(mode_is_data(mode));
 
        /* For primitive size depends on the mode. */
-       tp->size = get_mode_size_bits(mode);
+       tp->size = get_mode_size_bytes(mode);
        tp->mode = mode;
 }
 
@@ -2058,6 +2067,23 @@ ir_type *new_type_frame(ident *name) {
        return res;
 }
 
+/* Makes a clone of a frame type. */
+ir_type *clone_frame_type(ir_type *type) {
+       ir_type *res;
+       int     i, n;
+
+       assert(is_frame_type(type));
+
+       res = new_type_frame(type->name);
+       for (i = 0, n = get_class_n_members(type); i < n; ++i) {
+               ir_entity *ent  = get_class_member(type, i);
+               ir_entity *nent = copy_entity_own(ent, res);
+               set_entity_link(ent, nent);
+               set_entity_link(nent, ent);
+       }
+       return res;
+}
+
 /* Sets a lowered type for a type. This sets both associations. */
 void set_lowered_type(ir_type *tp, ir_type *lowered_type) {
        assert(is_type(tp) && is_type(lowered_type));
@@ -2075,7 +2101,7 @@ ir_type *get_associated_type(const ir_type *tp) {
 }
 
 /* set the type size for the unknown and none ir_type */
-void set_default_size_bits(ir_type *tp, int size) {
+void set_default_size(ir_type *tp, unsigned size) {
        tp->size = size;
 }
 
@@ -2084,56 +2110,66 @@ void set_default_size_bits(ir_type *tp, int size) {
  * at the start or the end of a frame type.
  * The frame type must have already an fixed layout.
  */
-ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at_start) {
-  ir_entity *area;
-  ir_type *tp;
-  ident *name;
-  char buf[32];
-  int frame_align, i, offset, frame_size;
-  static unsigned area_cnt = 0;
-  static ir_type *a_byte = NULL;
-
-  assert(is_frame_type(frame_type));
-  assert(get_type_state(frame_type) == layout_fixed);
-  assert(get_type_alignment_bytes(frame_type) > 0);
-
-  if (! a_byte)
-    a_byte = new_type_primitive(new_id_from_chars("byte", 4), mode_Bu);
-
-  snprintf(buf, sizeof(buf), "area%u", area_cnt++);
-  name = new_id_from_str(buf);
-
-  /* align the size */
-  frame_align = get_type_alignment_bytes(frame_type);
-  size = (size + frame_align - 1) & -frame_align;
-
-  tp = new_type_array(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);
-
-  frame_size = get_type_size_bytes(frame_type);
-  if (at_start) {
-    /* fix all offsets so far */
-    for (i = get_class_n_members(frame_type) - 1; i >= 0; --i) {
-      ir_entity *ent = get_class_member(frame_type, i);
-
-      set_entity_offset(ent, get_entity_offset(ent) + size);
-    }
-    /* calculate offset and new type size */
-    offset = 0;
-    frame_size += size;
-  }
-  else {
-    /* calculate offset and new type size */
-    offset = (frame_size + alignment - 1) & -alignment;
-    frame_size = offset + size;
-  }
-
-  area = new_entity(frame_type, name, tp);
-  set_entity_offset(area, offset);
-  set_type_size_bytes(frame_type, frame_size);
-
-  /* mark this entity as compiler generated */
-  set_entity_compiler_generated(area, 1);
-  return area;
+ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment, int at_start) {
+       ir_entity *area;
+       ir_type *tp;
+       ident *name;
+       char buf[32];
+       unsigned frame_align;
+       int i, offset, frame_size;
+       static unsigned area_cnt = 0;
+       static ir_type *a_byte = NULL;
+
+       assert(is_frame_type(frame_type));
+       assert(get_type_state(frame_type) == layout_fixed);
+       assert(get_type_alignment_bytes(frame_type) > 0);
+       set_type_state(frame_type, layout_undefined);
+
+       if (! a_byte)
+               a_byte = new_type_primitive(new_id_from_chars("byte", 4), mode_Bu);
+
+       snprintf(buf, sizeof(buf), "area%u", area_cnt++);
+       name = new_id_from_str(buf);
+
+       /* align the size */
+       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);
+       set_array_bounds_int(tp, 0, 0, size);
+       set_type_alignment_bytes(tp, alignment);
+
+       frame_size = get_type_size_bytes(frame_type);
+       if (at_start) {
+               /* fix all offsets so far */
+               for (i = get_class_n_members(frame_type) - 1; i >= 0; --i) {
+                       ir_entity *ent = get_class_member(frame_type, i);
+
+                       set_entity_offset(ent, get_entity_offset(ent) + size);
+               }
+               /* calculate offset and new type size */
+               offset = 0;
+               frame_size += size;
+
+               /* increase size to match alignment... */
+               if (alignment > frame_align) {
+                       frame_align = alignment;
+                       set_type_alignment_bytes(frame_type, frame_align);
+                       frame_size  = (frame_size + frame_align - 1) & ~(frame_align - 1);
+               }
+       } else {
+               /* calculate offset and new type size */
+               offset = (frame_size + alignment - 1) & ~(alignment - 1);
+               frame_size = offset + size;
+       }
+
+       area = new_entity(frame_type, name, tp);
+       set_entity_offset(area, offset);
+       set_type_size_bytes(frame_type, frame_size);
+
+       /* mark this entity as compiler generated */
+       set_entity_compiler_generated(area, 1);
+
+       set_type_state(frame_type, layout_fixed);
+       return area;
 }