* @param ent Any entity of compound type with at least pos initialization values.
* @param pos The position of the value for which the offset is requested.
*/
-int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos);
+unsigned get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos);
/** Return the overall offset of value at position pos in bytes.
*
* @param ent Any entity of compound type with at least pos initialization values.
* @param pos The position of the value for which the offset is requested.
*/
-int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos);
+unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos);
/* --- Fields of entities with a class type as owner --- */
/* Overwrites is a field that specifies that an access to the overwritten
*/
void set_type_mode(ir_type *tp, ir_mode* m);
-/** Returns the size of a type in bytes, returns -1 if the size is NOT
- * a byte size, i.e. not dividable by 8. */
-int get_type_size_bytes(const ir_type *tp);
-
-/** Returns the size of a type in bits. */
-int get_type_size_bits(const ir_type *tp);
+/** Returns the size of a type in bytes. */
+unsigned get_type_size_bytes(const ir_type *tp);
/** Sets the size of a type in bytes.
*
* For primitive, enumeration, pointer and method types the size
* is always fixed. This call is legal but has no effect.
*/
-void set_type_size_bytes(ir_type *tp, int size);
-
-/** Sets the size of a type in bits.
- *
- * For primitive, enumeration, pointer and method types the size
- * is always fixed. This call is legal but has no effect.
- */
-void set_type_size_bits(ir_type *tp, int size);
+void set_type_size_bytes(ir_type *tp, unsigned size);
/** Returns the alignment of a type in bytes.
*
* Returns -1 if the alignment is NOT
* a byte size, i.e. not dividable by 8. Calls get_type_alignment_bits(). */
-int get_type_alignment_bytes(ir_type *tp);
+unsigned get_type_alignment_bytes(ir_type *tp);
/** Returns the alignment of a type in bits.
*
* -#.) compound types have the alignment of there biggest member.
* -#.) array types have the alignment of there element type.
* -#.) method types return 0 here.
- * -#.) all other types return 8 here (i.e. aligned at byte).
- */
-int get_type_alignment_bits(ir_type *tp);
-
-/** Sets the alignment of a type in bytes. */
-void set_type_alignment_bytes(ir_type *tp, int size);
-
-/** Sets the alignment of a type in bits.
- *
- * For method types the alignment is always fixed.
- * This call is legal but has no effect.
+ * -#.) all other types return 1 here (i.e. aligned at byte).
*/
-void set_type_alignment_bits(ir_type *tp, int size);
+void set_type_alignment_bytes(ir_type *tp, unsigned align);
/** Returns the visited count of a type. */
unsigned long get_type_visited(const ir_type *tp);
*
* @return the entity representing the area
*/
-ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at_start);
+ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment, int at_start);
/*-----------------------------------------------------------------*/
/** Debug aides **/
ir_node *frame, *imem, *nmem, *store, *mem, *args, *args_bl;
const ir_edge_t *edge;
optimization_state_t state;
- int offset;
+ unsigned offset;
foreach_block_succ(start_bl, edge) {
ir_node *succ = get_edge_src_irn(edge);
frame_tp = get_irg_frame_type(irg);
offset = get_type_size_bytes(frame_tp);
for (ent = new_list; ent; ent = get_entity_link(ent)) {
- ir_type *tp = get_entity_type(ent);
- int align = get_type_alignment_bytes(tp);
+ ir_type *tp = get_entity_type(ent);
+ unsigned align = get_type_alignment_bytes(tp);
offset += align - 1;
- offset &= -align;
+ offset &= ~(align - 1);
set_entity_owner(ent, frame_tp);
add_class_member(frame_tp, ent);
/* must be automatic to set a fixed layout */
if(be_is_IncSP(irn)) {
if(ofs == BE_STACK_FRAME_SIZE_EXPAND) {
- ofs = get_type_size_bytes(get_irg_frame_type(env->birg->irg));
+ ofs = (int)get_type_size_bytes(get_irg_frame_type(env->birg->irg));
be_set_IncSP_offset(irn, ofs);
} else if(ofs == BE_STACK_FRAME_SIZE_SHRINK) {
- ofs = - get_type_size_bytes(get_irg_frame_type(env->birg->irg));
+ ofs = - (int)get_type_size_bytes(get_irg_frame_type(env->birg->irg));
be_set_IncSP_offset(irn, ofs);
}
}
break;
case symconst_type_size:
- obstack_printf(obst, "%d", get_type_size_bytes(get_SymConst_type(init)));
+ obstack_printf(obst, "%u", get_type_size_bytes(get_SymConst_type(init)));
break;
case symconst_type_align:
- obstack_printf(obst, "%d", get_type_alignment_bytes(get_SymConst_type(init)));
+ obstack_printf(obst, "%u", get_type_alignment_bytes(get_SymConst_type(init)));
break;
case symconst_enum_const:
{
normal_or_bitfield *vals;
int i, j, n = get_compound_ent_n_values(ent);
- int last_ofs;
+ unsigned k, last_ofs;
/* Find the initializer size. Sorrily gcc support a nasty feature:
The last field of a compound may be a flexible array. This allows
initializers bigger than the type size. */
last_ofs = get_type_size_bytes(get_entity_type(ent));
for (i = 0; i < n; ++i) {
- int offset = get_compound_ent_value_offset_bytes(ent, i);
- int bits_remainder = get_compound_ent_value_offset_bit_remainder(ent, i);
- ir_node *value = get_compound_ent_value(ent, i);
- int value_len = get_mode_size_bits(get_irn_mode(value));
+ unsigned offset = get_compound_ent_value_offset_bytes(ent, i);
+ unsigned bits_remainder = get_compound_ent_value_offset_bit_remainder(ent, i);
+ ir_node *value = get_compound_ent_value(ent, i);
+ unsigned value_len = get_mode_size_bits(get_irn_mode(value));
offset += (value_len + bits_remainder + 7) >> 3;
/* collect the values and store them at the offsets */
for (i = 0; i < n; ++i) {
- int offset = get_compound_ent_value_offset_bytes(ent, i);
- int offset_bits = get_compound_ent_value_offset_bit_remainder(ent, i);
- ir_node *value = get_compound_ent_value(ent, i);
- int value_len = get_mode_size_bits(get_irn_mode(value));
- assert(offset >= 0);
+ unsigned offset = get_compound_ent_value_offset_bytes(ent, i);
+ int offset_bits = get_compound_ent_value_offset_bit_remainder(ent, i);
+ ir_node *value = get_compound_ent_value(ent, i);
+ int value_len = get_mode_size_bits(get_irn_mode(value));
+
assert(offset_bits >= 0);
if (offset_bits != 0 ||
(value_len != 8 && value_len != 16 && value_len != 32 && value_len != 64)) {
tarval *tv = get_atomic_init_tv(value);
- unsigned char curr_bits, last_bits = 0;
+ unsigned char curr_bits, last_bits = 0;
if (tv == NULL) {
panic("Couldn't get numeric value for bitfield initializer '%s'\n",
get_entity_ld_name(ent));
}
- /* normalize offset */
- offset += offset_bits >> 3;
- offset_bits &= 7;
+ /* normalize offset */
+ offset += offset_bits >> 3;
+ offset_bits &= 7;
for (j = 0; value_len + offset_bits > 0; ++j) {
assert(offset + j < last_ofs);
assert(vals[offset + j].kind == BITFIELD || vals[offset + j].v.value == NULL);
vals[offset + j].kind = BITFIELD;
- curr_bits = get_tarval_sub_bits(tv, j);
+ curr_bits = get_tarval_sub_bits(tv, j);
vals[offset + j].v.bf_val |= (last_bits >> (8 - offset_bits)) | (curr_bits << offset_bits);
value_len -= 8;
- last_bits = curr_bits;
+ last_bits = curr_bits;
}
} else {
int i;
}
/* now write them sorted */
- for (i = 0; i < last_ofs; ) {
+ for (k = 0; k < last_ofs; ) {
int space = 0, skip = 0;
- if (vals[i].kind == NORMAL) {
- if(vals[i].v.value != NULL) {
- dump_atomic_init(env, obst, vals[i].v.value);
- skip = get_mode_size_bytes(get_irn_mode(vals[i].v.value)) - 1;
+ if (vals[k].kind == NORMAL) {
+ if(vals[k].v.value != NULL) {
+ dump_atomic_init(env, obst, vals[k].v.value);
+ skip = get_mode_size_bytes(get_irn_mode(vals[k].v.value)) - 1;
} else {
space = 1;
}
} else {
- assert(vals[i].kind == BITFIELD);
- obstack_printf(obst, "\t.byte\t%d\n", vals[i].v.bf_val);
+ assert(vals[k].kind == BITFIELD);
+ obstack_printf(obst, "\t.byte\t%d\n", vals[k].v.bf_val);
}
- ++i;
- while (i < last_ofs && vals[i].kind == NORMAL && vals[i].v.value == NULL) {
+ ++k;
+ while (k < last_ofs && vals[k].kind == NORMAL && vals[k].v.value == NULL) {
++space;
- ++i;
+ ++k;
}
space -= skip;
assert(space >= 0);
obstack_t *obst;
ir_type *type = get_entity_type(ent);
const char *ld_name = get_entity_ld_name(ent);
- int align = get_type_alignment_bytes(type);
+ unsigned align = get_type_alignment_bytes(type);
int emit_as_common = 0;
ir_variability variability;
ir_visibility visibility;
if (is_Method_type(type)) {
if (get_method_img_section(ent) == section_constructors) {
obst = env->ctor_obst;
- obstack_printf(obst, ".balign\t%d\n", align);
+ obstack_printf(obst, ".balign\t%u\n", align);
dump_size_type(obst, align);
obstack_printf(obst, "%s\n", ld_name);
}
}
/* alignment */
if (align > 1 && !emit_as_common) {
- obstack_printf(obst, ".balign\t%d\n", align);
+ obstack_printf(obst, ".balign\t%u\n", align);
}
if (!emit_as_common) {
if (variability == variability_uninitialized) {
if(emit_as_common) {
if (be_gas_flavour == GAS_FLAVOUR_NORMAL)
- obstack_printf(obst, "\t.comm %s,%d,%d\n",
+ obstack_printf(obst, "\t.comm %s,%u,%u\n",
ld_name, get_type_size_bytes(type), align);
else
- obstack_printf(obst, "\t.comm %s,%d # %d\n",
+ obstack_printf(obst, "\t.comm %s,%u # %u\n",
ld_name, get_type_size_bytes(type), align);
} else {
- obstack_printf(obst, "\t.zero %d\n", get_type_size_bytes(type));
+ obstack_printf(obst, "\t.zero %u\n", get_type_size_bytes(type));
}
} else {
if (is_atomic_entity(ent)) {
if(be_has_frame_entity(irn)) {
be_frame_attr_t *a = (be_frame_attr_t *) at;
if (a->ent) {
- int bits = get_type_size_bits(get_entity_type(a->ent));
- ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n",
- a->ent, a->offset, a->offset, bits, bits);
+ unsigned size = get_type_size_bytes(get_entity_type(a->ent));
+ ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n",
+ a->ent, a->offset, a->offset, size, size);
}
}
for (i = 0, n = get_compound_n_members(tp); i < n; ++i) {
ir_entity *ent = get_compound_member(tp, i);
ir_type *mtp = get_entity_type(ent);
- int ofs, size;
+ int ofs;
+ unsigned size;
if (! IS_TYPE_READY(mtp))
waitq_put(env->wq, mtp);
int bofs;
type_num = get_type_number(h, tp);
- size = get_type_size_bits(tp);
+ size = get_type_size_bytes(tp) * 8;
bofs = (ofs + get_entity_offset(ent)) * 8 + get_entity_offset_bits_remainder(ent);
/* name:type, bit offset from the start of the struct', number of bits in the element. */
- fprintf(h->f, "%s:%u,%d,%d;", get_entity_name(ent), type_num, bofs, size);
+ fprintf(h->f, "%s:%u,%d,%u;", get_entity_name(ent), type_num, bofs, size);
}
} else {
/* no bitfield */
/* name:type, bit offset from the start of the struct', number of bits in the element. */
fprintf(h->f, "%u", type_num);
}
- size = get_type_size_bits(mtp);
- fprintf(h->f, ",%d,%d;", ofs * 8, size);
+ size = get_type_size_bytes(mtp) * 8;
+ fprintf(h->f, ",%d,%u;", ofs * 8, size);
}
}
fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM);
arity = be_get_MemPerm_entity_arity(node);
pops = alloca(arity * sizeof(pops[0]));
- // create pushs
+ /* create Pushs */
for(i = 0; i < arity; ++i) {
ir_entity *inent = be_get_MemPerm_in_entity(node, i);
ir_entity *outent = be_get_MemPerm_out_entity(node, i);
ir_type *enttype = get_entity_type(inent);
- int entbits = get_type_size_bits(enttype);
- int entbits2 = get_type_size_bits(get_entity_type(outent));
+ unsigned entsize = get_type_size_bytes(enttype);
+ unsigned entsize2 = get_type_size_bytes(get_entity_type(outent));
ir_node *mem = get_irn_n(node, i + 1);
ir_node *push;
/* work around cases where entities have different sizes */
- if(entbits2 < entbits)
- entbits = entbits2;
- assert( (entbits == 32 || entbits == 64) && "spillslot on x86 should be 32 or 64 bit");
+ if(entsize2 < entsize)
+ entsize = entsize2;
+ assert( (entsize == 4 || entsize == 8) && "spillslot on x86 should be 32 or 64 bit");
push = create_push(cg, node, node, sp, mem, inent);
sp = create_spproj(cg, node, push, pn_ia32_Push_stack);
- if(entbits == 64) {
- // add another push after the first one
+ if(entsize == 8) {
+ /* add another push after the first one */
push = create_push(cg, node, node, sp, mem, inent);
add_ia32_am_offs_int(push, 4);
sp = create_spproj(cg, node, push, pn_ia32_Push_stack);
set_irn_n(node, i, new_Bad());
}
- // create pops
+ /* create pops */
for(i = arity - 1; i >= 0; --i) {
ir_entity *inent = be_get_MemPerm_in_entity(node, i);
ir_entity *outent = be_get_MemPerm_out_entity(node, i);
ir_type *enttype = get_entity_type(outent);
- int entbits = get_type_size_bits(enttype);
- int entbits2 = get_type_size_bits(get_entity_type(inent));
+ unsigned entsize = get_type_size_bytes(enttype);
+ unsigned entsize2 = get_type_size_bytes(get_entity_type(inent));
ir_node *pop;
/* work around cases where entities have different sizes */
- if(entbits2 < entbits)
- entbits = entbits2;
- assert( (entbits == 32 || entbits == 64) && "spillslot on x86 should be 32 or 64 bit");
+ if(entsize2 < entsize)
+ entsize = entsize2;
+ assert( (entsize == 4 || entsize == 8) && "spillslot on x86 should be 32 or 64 bit");
pop = create_pop(cg, node, node, sp, outent);
sp = create_spproj(cg, node, pop, pn_ia32_Pop_stack);
- if(entbits == 64) {
+ if(entsize == 8) {
add_ia32_am_offs_int(pop, 4);
- // add another pop after the first one
+ /* add another pop after the first one */
pop = create_pop(cg, node, node, sp, outent);
sp = create_spproj(cg, node, pop, pn_ia32_Pop_stack);
}
keep = be_new_Keep(&ia32_reg_classes[CLASS_ia32_gp], irg, block, 1, in);
sched_add_before(node, keep);
- // exchange memprojs
+ /* exchange memprojs */
foreach_out_edge_safe(node, edge, next) {
ir_node *proj = get_edge_src_irn(edge);
int p = get_Proj_proj(proj);
set_Proj_proj(proj, pn_ia32_Pop_M);
}
- // remove memperm
+ /* remove memperm */
arity = get_irn_arity(node);
for(i = 0; i < arity; ++i) {
set_irn_n(node, i, new_Bad());
for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
compound_graph_path *path = get_compound_ent_value_path(ent, i);
ir_entity *ent0 = get_compound_graph_path_node(path, 0);
- fprintf(F, "\n%s %3d:%d ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0));
+ fprintf(F, "\n%s %3d:%u ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0));
if (get_type_state(type) == layout_fixed)
- fprintf(F, "(%3d:%d) ", get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i));
+ fprintf(F, "(%3u:%u) ", get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i));
fprintf(F, "%s", get_entity_name(ent));
for (j = 0; j < get_compound_graph_path_length(path); ++j) {
ir_entity *node = get_compound_graph_path_node(path, j);
fprintf(F, " visibility: %s,\n", get_visibility_name(get_type_visibility(tp)));
fprintf(F, " state: %s,\n", get_type_state_name(get_type_state(tp)));
- fprintf(F, " size: %2d Bits,\n", get_type_size_bits(tp));
- fprintf(F, " alignment: %2d Bits,\n", get_type_alignment_bits(tp));
+ fprintf(F, " size: %2u Bytes,\n", get_type_size_bytes(tp));
+ fprintf(F, " alignment: %2u Bytes,\n", get_type_alignment_bytes(tp));
if (is_atomic_type(tp) || is_Method_type(tp))
fprintf(F, " mode: %s,\n", get_mode_name(get_type_mode(tp)));
tarval *tv;
int filename_len = strlen(filename)+1;
ident *cur_ident;
- int align_l, align_n, size;
+ unsigned align_l, align_n, size;
ir_graph *rem;
block_id_walker_data_t wd;
symconst_symbol sym;
if (tv != tarval_bad && tarval_is_long(tv) &&
get_type_state(atp) == layout_fixed &&
- get_tarval_long(tv) == get_type_size_bytes(atp)) {
+ (unsigned)get_tarval_long(tv) == get_type_size_bytes(atp)) {
/* a already lowered type size */
tp = atp;
}
} /* set_array_entity_values */
/* Return the overall offset of value at position pos in bytes. */
-int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) {
+unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) {
compound_graph_path *path;
int path_len, i;
- int offset = 0;
+ unsigned offset = 0;
ir_type *curr_tp;
assert(get_type_state(get_entity_type(ent)) == layout_fixed);
for (i = 0; i < path_len; ++i) {
if (is_Array_type(curr_tp)) {
ir_type *elem_type = get_array_element_type(curr_tp);
- int size = get_type_size_bits(elem_type);
- int align = get_type_alignment_bits(elem_type);
+ unsigned size = get_type_size_bytes(elem_type);
+ unsigned align = get_type_alignment_bytes(elem_type);
int idx;
assert(size > 0);
if(size % align > 0) {
size += align - (size % align);
}
- assert(size % 8 == 0);
- size /= 8;
idx = get_compound_graph_path_array_index(path, i);
assert(idx >= 0);
offset += size * idx;
} /* get_compound_ent_value_offset_bytes */
/* Return the offset in bits from the last byte address. */
-int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) {
+unsigned get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) {
compound_graph_path *path;
int path_len;
ir_entity *last_node;
free_class_entities,
NULL,
set_class_mode,
- set_class_size_bits,
+ set_class_size,
get_class_n_members,
get_class_member,
get_class_member_index
free_struct_entities,
NULL,
set_struct_mode,
- set_struct_size_bits,
+ set_struct_size,
get_struct_n_members,
get_struct_member,
get_struct_member_index
free_union_entities,
NULL,
NULL,
- set_union_size_bits,
+ set_union_size,
get_union_n_members,
get_union_member,
get_union_member_index
free_array_entities,
free_array_automatic_entities,
NULL,
- set_array_size_bits,
+ set_array_size,
NULL,
NULL,
NULL
NULL,
NULL,
NULL,
- set_default_size_bits,
+ set_default_size,
NULL,
NULL,
NULL
/** A function called to set the mode of a type. */
typedef void (*set_type_mode_func)(ir_type *tp, ir_mode *m);
-/** A function called to set the size of a type in bits */
-typedef void (*set_type_size_func)(ir_type *tp, int size);
+/** A function called to set the size of a type in bytes. */
+typedef void (*set_type_size_func)(ir_type *tp, unsigned size);
/** A function called to get the number of compound members */
typedef int (*get_n_members_func)(const ir_type *tp);
* tp_op operations.
*/
typedef struct _tp_op_ops {
- free_attrs_func free_attrs; /**< called to free the attributes of a type */
- free_entities_func free_entities; /**< called to free the owned entities of a type */
- free_auto_entities_func free_auto_entities; /**< called to free the automatic allocated entities of a type */
- set_type_mode_func set_type_mode; /**< called to set a ir_mode of a type */
- set_type_size_func set_type_size; /**< called to set the bit size of a type */
- get_n_members_func get_n_members; /**< called to return the number of compound members */
- get_member_func get_member; /**< called to get the pos'th compound member */
- get_member_index_func get_member_index; /**< called to get the index of a compound member */
+ free_attrs_func free_attrs; /**< Called to free the attributes of a type. */
+ free_entities_func free_entities; /**< Called to free the owned entities of a type. */
+ free_auto_entities_func free_auto_entities; /**< Called to free the automatic allocated entities of a type. */
+ set_type_mode_func set_type_mode; /**< Called to set a ir_mode of a type. */
+ set_type_size_func set_type_size; /**< Called to set the byte size of a type. */
+ get_n_members_func get_n_members; /**< Called to return the number of compound members. */
+ get_member_func get_member; /**< Called to get the pos'th compound member. */
+ get_member_index_func get_member_index; /**< Called to get the index of a compound member. */
} tp_op_ops;
/** possible flags for a type opcode */
TP_OP_FLAG_COMPOUND = 1 /**< is a compound type */
};
-/** The type opcode */
+/** The type opcode. */
struct tp_op {
- tp_opcode code; /**< the tpop code */
- ident *name; /**< the name of the type opcode */
- size_t attr_size; /**< the attribute size for a type of this opcode */
- unsigned flags; /**< flags for this opcode */
- tp_op_ops ops; /**< tp_op operations */
+ tp_opcode code; /**< The tpop code. */
+ ident *name; /**< The name of the type opcode. */
+ size_t attr_size; /**< The attribute size for a type of this opcode. */
+ unsigned flags; /**< Flags for this opcode. */
+ tp_op_ops ops; /**< tp_op operations. */
};
/**
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;
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;
}
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)
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;
}
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;
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++) {
}
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));
(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)) {
(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++) {
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;
}
/*----------------------------------------------------------------**/
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;
}
/*******************************************************************/
assert((get_mode_size_bytes(mode_P_code) != -1) && "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.value_params = NULL;
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;
}
/*-----------------------------------------------------------------*/
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;
}
/* 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;
}
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);
+ res->size = get_mode_size_bytes(res->mode);
res->flags |= tf_layout_fixed;
hook_new_type(res);
return res;
/* 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;
}
/* 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);
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;
}
}
/* 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;
}
* 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 *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];
- int frame_align, i, offset, frame_size;
+ unsigned frame_align;
+ int i, offset, frame_size;
static unsigned area_cnt = 0;
static ir_type *a_byte = NULL;
/* align the size */
frame_align = get_type_alignment_bytes(frame_type);
- size = (size + frame_align - 1) & -frame_align;
+ 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);
}
else {
/* calculate offset and new type size */
- offset = (frame_size + alignment - 1) & -alignment;
+ offset = (frame_size + alignment - 1) & ~(alignment - 1);
frame_size = offset + size;
}
ident *name; /**< The name of the type */
ir_visibility visibility;/**< Visibility of entities of this type. */
unsigned flags; /**< Type flags, a bitmask of enum type_flags. */
- int size; /**< Size of an ir_entity of this type. This is determined
+ unsigned size; /**< Size of an ir_entity of this type. This is determined
when fixing the layout of this class. Size must be
- given in bits. */
- int align; /**< Alignment of an ir_entity of this type. This should be
+ given in bytes. */
+ unsigned align; /**< Alignment of an ir_entity of this type. This should be
set according to the source language needs. If not set it's
calculated automatically by get_type_alignment().
- Alignment must be given in bits. */
+ Alignment must be given in bytes. */
ir_mode *mode; /**< The mode for atomic types */
unsigned long visit; /**< visited counter for walks of the type information */
void *link; /**< holds temporary data - like in irnode_t.h */
void set_primitive_mode(ir_type *tp, ir_mode *mode);
void set_enumeration_mode(ir_type *tp, ir_mode *mode);
-void set_class_size_bits(ir_type *tp, int bits);
-void set_struct_size_bits(ir_type *tp, int bits);
-void set_union_size_bits(ir_type *tp, int bits);
-void set_array_size_bits(ir_type *tp, int size);
-void set_default_size_bits(ir_type *tp, int size);
+void set_class_size(ir_type *tp, unsigned bytes);
+void set_struct_size(ir_type *tp, unsigned bytes);
+void set_union_size(ir_type *tp, unsigned bytes);
+void set_array_size(ir_type *tp, unsigned bytes);
+void set_default_size(ir_type *tp, unsigned bytes);
/**
* Initialize the type module.
tp->name = id;
}
-static INLINE int
-_get_type_size_bits(const ir_type *tp) {
+static INLINE unsigned
+_get_type_size_bytes(const ir_type *tp) {
assert(tp && tp->kind == k_type);
return tp->size;
}
-static INLINE int
-_get_type_size_bytes(const ir_type *tp) {
- int size = _get_type_size_bits(tp);
- if (size < 0)
- return -1;
- if ((size & 7) != 0) {
- assert(0 && "cannot take byte size of this type");
- return -1;
- }
- return size >> 3;
-}
-
static INLINE ir_type_state
_get_type_state(const ir_type *tp) {
assert(tp && tp->kind == k_type);
#define get_type_mode(tp) _get_type_mode(tp)
#define get_type_ident(tp) _get_type_ident(tp)
#define set_type_ident(tp, id) _set_type_ident(tp, id)
-#define get_type_size_bits(tp) _get_type_size_bits(tp)
#define get_type_size_bytes(tp) _get_type_size_bytes(tp)
#define get_type_state(tp) _get_type_state(tp)
#define get_type_visited(tp) _get_type_visited(tp)