Type cleanup

This commit is contained in:
Christoffer Lerno
2020-04-04 01:35:20 +02:00
parent bbef467317
commit 336e6cf47d

View File

@@ -21,11 +21,26 @@ Type *type_float = &t_f32;
Type *type_double = &t_f64;
Type *type_error = &t_err;
Type *type_typeid = &t_typeid;
Type *type_char, *type_short, *type_int, *type_long, *type_isize;
Type *type_byte, *type_ushort, *type_uint, *type_ulong, *type_usize;
Type *type_compint, *type_compfloat;
Type *type_c_short, *type_c_int, *type_c_long, *type_c_longlong;
Type *type_c_ushort, *type_c_uint, *type_c_ulong, *type_c_ulonglong;
Type *type_char = &t_i8;
Type *type_short = &t_i16;
Type *type_int = &t_i32;
Type *type_long = &t_i64;
Type *type_isize = &t_isz;
Type *type_byte = &t_u8;
Type *type_ushort = &t_u16;
Type *type_uint = &t_u32;
Type *type_ulong = &t_u64;
Type *type_usize = &t_usz;
Type *type_compint = &t_ixx;
Type *type_compfloat = &t_fxx;
Type *type_c_short = &t_cs;
Type *type_c_int = &t_ci;
Type *type_c_long = &t_cl;
Type *type_c_longlong = &t_cll;
Type *type_c_ushort = &t_cus;
Type *type_c_uint = &t_cui;
Type *type_c_ulong = &t_cul;
Type *type_c_ulonglong = &t_cull;
#define META_OFFSET 0
@@ -353,7 +368,7 @@ Type *type_get_array(Type *arr_type, uint64_t len)
return type_create_array(arr_type, len, false);
}
static void type_create(const char *name, Type *location, Type **ptr, TypeKind kind, unsigned bitsize,
static void type_create(const char *name, Type *location, TypeKind kind, unsigned bitsize,
unsigned align, unsigned pref_align)
{
*location = (Type) {
@@ -367,17 +382,15 @@ static void type_create(const char *name, Type *location, Type **ptr, TypeKind k
};
location->name = name;
location->canonical = location;
*ptr = location;
}
static void type_create_alias(const char *name, Type *location, Type **ptr, Type *canonical)
static void type_create_alias(const char *name, Type *location, Type *canonical)
{
*location = (Type) {
.type_kind = TYPE_TYPEDEF,
.name = name,
.canonical = canonical
};
*ptr = location;
}
@@ -390,7 +403,7 @@ void builtin_setup(Target *target)
type_string.type_kind = TYPE_STRING;
*/
#define DEF_TYPE(_name, _shortname, _type, _bits, _align) \
type_create(#_name, &_shortname, &type_ ## _name, _type, _bits, target->align_min_ ## _align, target->align_ ## _align)
type_create(#_name, &_shortname, _type, _bits, target->align_min_ ## _align, target->align_ ## _align)
DEF_TYPE(bool, t_u1, TYPE_BOOL, 1, byte);
DEF_TYPE(float, t_f32, TYPE_F32, 32, float);
@@ -411,29 +424,28 @@ type_create(#_name, &_shortname, &type_ ## _name, _type, _bits, target->align_mi
#undef DEF_TYPE
type_create("void*", &t_voidstar, &type_voidptr, TYPE_POINTER, target->width_pointer, target->align_min_pointer, target->align_pointer);
type_create("void*", &t_voidstar, TYPE_POINTER, target->width_pointer, target->align_min_pointer, target->align_pointer);
create_type_cache(type_void);
type_void->type_cache[0] = &t_voidstar;
t_voidstar.pointer = type_void;
type_create("compint", &t_ixx, &type_compint, TYPE_IXX, 32, 0, 0);
type_create("compfloat", &t_fxx, &type_compfloat, TYPE_FXX, 64, 0, 0);
type_create("compint", &t_ixx, TYPE_IXX, 32, 0, 0);
type_create("compfloat", &t_fxx, TYPE_FXX, 64, 0, 0);
type_create_alias("usize", &t_usz, &type_usize, type_unsigned_int_by_bitsize(target->width_pointer));
type_create_alias("isize", &t_isz, &type_isize, type_signed_int_by_bitsize(target->width_pointer));
type_create_alias("usize", &t_usz, type_unsigned_int_by_bitsize(target->width_pointer));
type_create_alias("isize", &t_isz, type_signed_int_by_bitsize(target->width_pointer));
type_create_alias("c_ushort", &t_cus, &type_c_ushort, type_unsigned_int_by_bitsize(target->width_c_short));
type_create_alias("c_uint", &t_cui, &type_c_uint, type_unsigned_int_by_bitsize(target->width_c_int));
type_create_alias("c_ulong", &t_cul, &type_c_ulong, type_unsigned_int_by_bitsize(target->width_c_long));
type_create_alias("c_ulonglong", &t_cull, &type_c_ulonglong, type_unsigned_int_by_bitsize(target->width_c_long_long));
type_create_alias("c_ushort", &t_cus, type_unsigned_int_by_bitsize(target->width_c_short));
type_create_alias("c_uint", &t_cui, type_unsigned_int_by_bitsize(target->width_c_int));
type_create_alias("c_ulong", &t_cul, type_unsigned_int_by_bitsize(target->width_c_long));
type_create_alias("c_ulonglong", &t_cull, type_unsigned_int_by_bitsize(target->width_c_long_long));
type_create_alias("c_short", &t_cs, &type_c_short, type_signed_int_by_bitsize(target->width_c_short));
type_create_alias("c_int", &t_ci, &type_c_int, type_signed_int_by_bitsize(target->width_c_int));
type_create_alias("c_short", &t_cs, type_signed_int_by_bitsize(target->width_c_short));
type_create_alias("c_int", &t_ci, type_signed_int_by_bitsize(target->width_c_int));
// TODO fix error size
type_create_alias("error", &t_err, &type_error, type_signed_int_by_bitsize(target->width_c_int));
type_create_alias("typeid", &t_typeid, &type_typeid, type_signed_int_by_bitsize(target->width_pointer));
type_create_alias("c_long", &t_cl, &type_c_long, type_signed_int_by_bitsize(target->width_c_long));
type_create_alias("c_longlong", &t_cll, &type_c_longlong, type_signed_int_by_bitsize(target->width_c_long_long));
type_create_alias("error", &t_err, type_signed_int_by_bitsize(target->width_c_int));
type_create_alias("typeid", &t_typeid, type_signed_int_by_bitsize(target->width_pointer));
type_create_alias("c_long", &t_cl, type_signed_int_by_bitsize(target->width_c_long));
type_create_alias("c_longlong", &t_cll, type_signed_int_by_bitsize(target->width_c_long_long));
}