panic("error type occured");
case TYPE_ATOMIC:
return get_atomic_type_size(type->atomic.akind);
+ case TYPE_COMPLEX:
+ return 2 * get_atomic_type_size(type->complex.akind);
+ case TYPE_IMAGINARY:
+ return get_atomic_type_size(type->imaginary.akind);
case TYPE_ENUM:
return get_mode_size_bytes(mode_int);
case TYPE_COMPOUND_UNION:
return count;
}
+/**
+ * Creates a Firm type for an atomic type
+ */
static ir_type *create_atomic_type(const atomic_type_t *type)
{
dbg_info *dbgi = get_dbg_info(&type->base.source_position);
atomic_type_kind_t kind = type->akind;
ir_mode *mode = _atomic_modes[kind];
- unsigned alignment = get_atomic_type_alignment(kind);
ident *id = get_mode_ident(mode);
ir_type *irtype = new_d_type_primitive(id, mode, dbgi);
- if(type->base.alignment > alignment)
- alignment = type->base.alignment;
+ set_type_alignment_bytes(irtype, type->base.alignment);
+
+ return irtype;
+}
+
+/**
+ * Creates a Firm type for a complex type
+ */
+static ir_type *create_complex_type(const complex_type_t *type)
+{
+ dbg_info *dbgi = get_dbg_info(&type->base.source_position);
+ atomic_type_kind_t kind = type->akind;
+ ir_mode *mode = _atomic_modes[kind];
+ ident *id = get_mode_ident(mode);
- set_type_alignment_bytes(irtype, alignment);
+ /* FIXME: finish the array */
+ return NULL;
+}
+
+/**
+ * Creates a Firm type for an imaginary type
+ */
+static ir_type *create_imaginary_type(const imaginary_type_t *type)
+{
+ dbg_info *dbgi = get_dbg_info(&type->base.source_position);
+ atomic_type_kind_t kind = type->akind;
+ ir_mode *mode = _atomic_modes[kind];
+ ident *id = get_mode_ident(mode);
+ ir_type *irtype = new_d_type_primitive(id, mode, dbgi);
+
+ set_type_alignment_bytes(irtype, type->base.alignment);
return irtype;
}
ir_type *firm_type = NULL;
switch(type->kind) {
case TYPE_ERROR:
- panic("error type occured");
+ panic("error type occurred");
case TYPE_ATOMIC:
firm_type = create_atomic_type(&type->atomic);
break;
+ case TYPE_COMPLEX:
+ firm_type = create_complex_type(&type->complex);
+ break;
+ case TYPE_IMAGINARY:
+ firm_type = create_imaginary_type(&type->imaginary);
+ break;
case TYPE_FUNCTION:
firm_type = create_method_type(&type->function);
break;
{
case TYPE_ATOMIC: {
const atomic_type_t *const atomic_type = &type->atomic;
- switch ((atomic_type_kind_t) atomic_type->akind) {
+ switch (atomic_type->akind) {
/* should not be reached */
case ATOMIC_TYPE_INVALID:
tc = no_type_class;
case ATOMIC_TYPE_LONG_DOUBLE:
tc = real_type_class;
goto make_const;
-
- case ATOMIC_TYPE_FLOAT_COMPLEX:
- case ATOMIC_TYPE_DOUBLE_COMPLEX:
- case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX:
- tc = complex_type_class;
- goto make_const;
- case ATOMIC_TYPE_FLOAT_IMAGINARY:
- case ATOMIC_TYPE_DOUBLE_IMAGINARY:
- case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY:
- tc = complex_type_class;
- goto make_const;
}
panic("Unexpected atomic type in classify_type_to_firm().");
}
+ case TYPE_COMPLEX: tc = complex_type_class; goto make_const;
+ case TYPE_IMAGINARY: tc = complex_type_class; goto make_const;
case TYPE_BITFIELD: tc = integer_type_class; goto make_const;
case TYPE_ARRAY: /* gcc handles this as pointer */
case TYPE_FUNCTION: /* gcc handles this as pointer */
{
static const size_t sizes[] = {
[TYPE_ATOMIC] = sizeof(atomic_type_t),
+ [TYPE_COMPLEX] = sizeof(complex_type_t),
+ [TYPE_IMAGINARY] = sizeof(imaginary_type_t),
[TYPE_BITFIELD] = sizeof(bitfield_type_t),
[TYPE_COMPOUND_STRUCT] = sizeof(compound_type_t),
[TYPE_COMPOUND_UNION] = sizeof(compound_type_t),
}
/**
- * skip any {...} blocks until a closing braket is reached.
+ * skip any {...} blocks until a closing bracket is reached.
*/
static void skip_initializers(void)
{
SPECIFIER_INT32 = 1 << 13,
SPECIFIER_INT64 = 1 << 14,
SPECIFIER_INT128 = 1 << 15,
-#ifdef PROVIDE_COMPLEX
SPECIFIER_COMPLEX = 1 << 16,
SPECIFIER_IMAGINARY = 1 << 17,
-#endif
} specifiers_t;
static type_t *create_builtin_type(symbol_t *const symbol,
type->builtin.real_type = real_type;
type_t *result = typehash_insert(type);
- if (type != result) {
+ if(type != result) {
free_type(type);
}
static type_t *get_typedef_type(symbol_t *symbol)
{
declaration_t *declaration = get_declaration(symbol, NAMESPACE_NORMAL);
- if(declaration == NULL
- || declaration->storage_class != STORAGE_CLASS_TYPEDEF)
+ if(declaration == NULL ||
+ declaration->storage_class != STORAGE_CLASS_TYPEDEF)
return NULL;
type_t *type = allocate_type_zero(TYPE_TYPEDEF, &declaration->source_position);
}
}
next_token();
- if(token.type == ',') {
+ if(token.type == ',') {
next_token();
continue;
}
MATCH_SPECIFIER(T__int32, SPECIFIER_INT32, "_int32")
MATCH_SPECIFIER(T__int64, SPECIFIER_INT64, "_int64")
MATCH_SPECIFIER(T__int128, SPECIFIER_INT128, "_int128")
-#ifdef PROVIDE_COMPLEX
MATCH_SPECIFIER(T__Complex, SPECIFIER_COMPLEX, "_Complex")
MATCH_SPECIFIER(T__Imaginary, SPECIFIER_IMAGINARY, "_Imaginary")
-#endif
+
case T__forceinline:
/* only in microsoft mode */
specifiers->decl_modifiers |= DM_FORCEINLINE;
case SPECIFIER_BOOL:
atomic_type = ATOMIC_TYPE_BOOL;
break;
-#ifdef PROVIDE_COMPLEX
case SPECIFIER_FLOAT | SPECIFIER_COMPLEX:
- atomic_type = ATOMIC_TYPE_FLOAT_COMPLEX;
- break;
- case SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
- atomic_type = ATOMIC_TYPE_DOUBLE_COMPLEX;
- break;
- case SPECIFIER_LONG | SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
- atomic_type = ATOMIC_TYPE_LONG_DOUBLE_COMPLEX;
- break;
case SPECIFIER_FLOAT | SPECIFIER_IMAGINARY:
- atomic_type = ATOMIC_TYPE_FLOAT_IMAGINARY;
+ atomic_type = ATOMIC_TYPE_FLOAT;
break;
+ case SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
case SPECIFIER_DOUBLE | SPECIFIER_IMAGINARY:
- atomic_type = ATOMIC_TYPE_DOUBLE_IMAGINARY;
+ atomic_type = ATOMIC_TYPE_DOUBLE;
break;
+ case SPECIFIER_LONG | SPECIFIER_DOUBLE | SPECIFIER_COMPLEX:
case SPECIFIER_LONG | SPECIFIER_DOUBLE | SPECIFIER_IMAGINARY:
- atomic_type = ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY;
+ atomic_type = ATOMIC_TYPE_LONG_DOUBLE;
break;
-#endif
default:
/* invalid specifier combination, give an error message */
if(type_specifiers == 0) {
atomic_type = ATOMIC_TYPE_INVALID;
}
- type = allocate_type_zero(TYPE_ATOMIC, &builtin_source_position);
- type->atomic.akind = atomic_type;
- newtype = 1;
+ if(type_specifiers & SPECIFIER_COMPLEX &&
+ atomic_type != ATOMIC_TYPE_INVALID) {
+ type = allocate_type_zero(TYPE_COMPLEX, &builtin_source_position);
+ type->complex.akind = atomic_type;
+ } else if(type_specifiers & SPECIFIER_IMAGINARY &&
+ atomic_type != ATOMIC_TYPE_INVALID) {
+ type = allocate_type_zero(TYPE_IMAGINARY, &builtin_source_position);
+ type->imaginary.akind = atomic_type;
+ } else {
+ type = allocate_type_zero(TYPE_ATOMIC, &builtin_source_position);
+ type->atomic.akind = atomic_type;
+ }
+ newtype = 1;
} else {
if(type_specifiers != 0) {
errorf(HERE, "multiple datatypes in declaration");
props[ATOMIC_TYPE_ULONGLONG].alignment = 4;
props[ATOMIC_TYPE_BOOL] = props[ATOMIC_TYPE_UINT];
-
- /* initialize complex/imaginary types */
- props[ATOMIC_TYPE_FLOAT_COMPLEX] = props[ATOMIC_TYPE_FLOAT];
- props[ATOMIC_TYPE_FLOAT_COMPLEX].flags |= ATOMIC_TYPE_FLAG_COMPLEX;
- props[ATOMIC_TYPE_FLOAT_COMPLEX].size *= 2;
- props[ATOMIC_TYPE_DOUBLE_COMPLEX] = props[ATOMIC_TYPE_DOUBLE];
- props[ATOMIC_TYPE_DOUBLE_COMPLEX].flags |= ATOMIC_TYPE_FLAG_COMPLEX;
- props[ATOMIC_TYPE_DOUBLE_COMPLEX].size *= 2;
- props[ATOMIC_TYPE_LONG_DOUBLE_COMPLEX]
- = props[ATOMIC_TYPE_LONG_DOUBLE];
- props[ATOMIC_TYPE_LONG_DOUBLE_COMPLEX].flags |= ATOMIC_TYPE_FLAG_COMPLEX;
- props[ATOMIC_TYPE_LONG_DOUBLE_COMPLEX].size *= 2;
-
- props[ATOMIC_TYPE_FLOAT_IMAGINARY] = props[ATOMIC_TYPE_FLOAT];
- props[ATOMIC_TYPE_DOUBLE_IMAGINARY] = props[ATOMIC_TYPE_DOUBLE];
- props[ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY] = props[ATOMIC_TYPE_LONG_DOUBLE];
}
void exit_types(void)
}
/**
- * Prints the name of a atomic type.
+ * Prints the name of an atomic type kinds.
+ *
+ * @param kind The type kind.
+ */
+static
+void print_atomic_kinds(atomic_type_kind_t kind)
+{
+ const char *s = "INVALIDATOMIC";
+ switch(kind) {
+ case ATOMIC_TYPE_INVALID: break;
+ case ATOMIC_TYPE_VOID: s = "void"; break;
+ case ATOMIC_TYPE_BOOL: s = "_Bool"; break;
+ case ATOMIC_TYPE_CHAR: s = "char"; break;
+ case ATOMIC_TYPE_SCHAR: s = "signed char"; break;
+ case ATOMIC_TYPE_UCHAR: s = "unsigned char"; break;
+ case ATOMIC_TYPE_INT: s = "int"; break;
+ case ATOMIC_TYPE_UINT: s = "unsigned int"; break;
+ case ATOMIC_TYPE_SHORT: s = "short"; break;
+ case ATOMIC_TYPE_USHORT: s = "unsigned short"; break;
+ case ATOMIC_TYPE_LONG: s = "long"; break;
+ case ATOMIC_TYPE_ULONG: s = "unsigned long"; break;
+ case ATOMIC_TYPE_LONGLONG: s = "long long"; break;
+ case ATOMIC_TYPE_ULONGLONG: s = "unsigned long long"; break;
+ case ATOMIC_TYPE_LONG_DOUBLE: s = "long double"; break;
+ case ATOMIC_TYPE_FLOAT: s = "float"; break;
+ case ATOMIC_TYPE_DOUBLE: s = "double"; break;
+ }
+ fputs(s, out);
+}
+
+/**
+ * Prints the name of an atomic type.
*
* @param type The type.
*/
void print_atomic_type(const atomic_type_t *type)
{
print_type_qualifiers(type->base.qualifiers);
+ print_atomic_kinds(type->akind);
+}
- const char *s = "INVALIDATOMIC";
- switch((atomic_type_kind_t) type->akind) {
- case ATOMIC_TYPE_INVALID: break;
- case ATOMIC_TYPE_VOID: s = "void"; break;
- case ATOMIC_TYPE_BOOL: s = "_Bool"; break;
- case ATOMIC_TYPE_CHAR: s = "char"; break;
- case ATOMIC_TYPE_SCHAR: s = "signed char"; break;
- case ATOMIC_TYPE_UCHAR: s = "unsigned char"; break;
- case ATOMIC_TYPE_INT: s = "int"; break;
- case ATOMIC_TYPE_UINT: s = "unsigned int"; break;
- case ATOMIC_TYPE_SHORT: s = "short"; break;
- case ATOMIC_TYPE_USHORT: s = "unsigned short"; break;
- case ATOMIC_TYPE_LONG: s = "long"; break;
- case ATOMIC_TYPE_ULONG: s = "unsigned long"; break;
- case ATOMIC_TYPE_LONGLONG: s = "long long"; break;
- case ATOMIC_TYPE_ULONGLONG: s = "unsigned long long"; break;
- case ATOMIC_TYPE_LONG_DOUBLE: s = "long double"; break;
- case ATOMIC_TYPE_FLOAT: s = "float"; break;
- case ATOMIC_TYPE_DOUBLE: s = "double"; break;
- case ATOMIC_TYPE_FLOAT_COMPLEX: s = "_Complex float"; break;
- case ATOMIC_TYPE_DOUBLE_COMPLEX: s = "_Complex float"; break;
- case ATOMIC_TYPE_LONG_DOUBLE_COMPLEX: s = "_Complex float"; break;
- case ATOMIC_TYPE_FLOAT_IMAGINARY: s = "_Imaginary float"; break;
- case ATOMIC_TYPE_DOUBLE_IMAGINARY: s = "_Imaginary float"; break;
- case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY: s = "_Imaginary float"; break;
- }
- fputs(s, out);
+/**
+ * Prints the name of a complex type.
+ *
+ * @param type The type.
+ */
+static
+void print_complex_type(const complex_type_t *type)
+{
+ print_type_qualifiers(type->base.qualifiers);
+ fputs("_Complex ", out);
+ print_atomic_kinds(type->akind);
+}
+
+/**
+ * Prints the name of an imaginary type.
+ *
+ * @param type The type.
+ */
+static
+void print_imaginary_type(const imaginary_type_t *type)
+{
+ print_type_qualifiers(type->base.qualifiers);
+ fputs("_Imaginary ", out);
+ print_atomic_kinds(type->akind);
}
/**
case TYPE_ATOMIC:
print_atomic_type(&type->atomic);
return;
+ case TYPE_COMPLEX:
+ print_complex_type(&type->complex);
+ return;
+ case TYPE_IMAGINARY:
+ print_imaginary_type(&type->imaginary);
+ return;
case TYPE_COMPOUND_STRUCT:
case TYPE_COMPOUND_UNION:
print_compound_type(&type->compound);
case TYPE_ERROR:
case TYPE_INVALID:
case TYPE_ATOMIC:
+ case TYPE_COMPLEX:
+ case TYPE_IMAGINARY:
case TYPE_ENUM:
case TYPE_COMPOUND_STRUCT:
case TYPE_COMPOUND_UNION:
{
switch(type->kind) {
case TYPE_ATOMIC: return sizeof(atomic_type_t);
+ case TYPE_COMPLEX: return sizeof(complex_type_t);
+ case TYPE_IMAGINARY: return sizeof(imaginary_type_t);
case TYPE_COMPOUND_STRUCT:
case TYPE_COMPOUND_UNION: return sizeof(compound_type_t);
case TYPE_ENUM: return sizeof(enum_type_t);
case TYPE_ATOMIC:
return type->atomic.akind == ATOMIC_TYPE_VOID;
+ case TYPE_COMPLEX:
+ return type->complex.akind == ATOMIC_TYPE_VOID;
+
+ case TYPE_IMAGINARY:
+ return type->imaginary.akind == ATOMIC_TYPE_VOID;
+
case TYPE_POINTER:
case TYPE_BUILTIN:
case TYPE_ERROR:
return function_types_compatible(&type1->function, &type2->function);
case TYPE_ATOMIC:
return type1->atomic.akind == type2->atomic.akind;
+ case TYPE_COMPLEX:
+ return type1->complex.akind == type2->complex.akind;
+ case TYPE_IMAGINARY:
+ return type1->imaginary.akind == type2->imaginary.akind;
case TYPE_ARRAY:
return array_types_compatible(&type1->array, &type2->array);
* @param akind The kind of the atomic type.
* @param qualifiers Type qualifiers for the new type.
*/
-type_t *make_atomic_type(atomic_type_kind_t atype, type_qualifiers_t qualifiers)
+type_t *make_atomic_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers)
{
type_t *type = obstack_alloc(type_obst, sizeof(atomic_type_t));
memset(type, 0, sizeof(atomic_type_t));
type->kind = TYPE_ATOMIC;
type->base.qualifiers = qualifiers;
- type->base.alignment = 0;
- type->atomic.akind = atype;
+ type->base.alignment = get_atomic_type_alignment(akind);
+ type->atomic.akind = akind;
- /* TODO: set the alignment depending on the atype here */
+ return identify_new_type(type);
+}
+
+/**
+ * Creates a new complex type.
+ *
+ * @param akind The kind of the atomic type.
+ * @param qualifiers Type qualifiers for the new type.
+ */
+type_t *make_complex_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers)
+{
+ type_t *type = obstack_alloc(type_obst, sizeof(complex_type_t));
+ memset(type, 0, sizeof(complex_type_t));
+
+ type->kind = TYPE_COMPLEX;
+ type->base.qualifiers = qualifiers;
+ type->base.alignment = get_atomic_type_alignment(akind);
+ type->complex.akind = akind;
+
+ return identify_new_type(type);
+}
+
+/**
+ * Creates a new imaginary type.
+ *
+ * @param akind The kind of the atomic type.
+ * @param qualifiers Type qualifiers for the new type.
+ */
+type_t *make_imaginary_type(atomic_type_kind_t akind, type_qualifiers_t qualifiers)
+{
+ type_t *type = obstack_alloc(type_obst, sizeof(imaginary_type_t));
+ memset(type, 0, sizeof(imaginary_type_t));
+
+ type->kind = TYPE_IMAGINARY;
+ type->base.qualifiers = qualifiers;
+ type->base.alignment = get_atomic_type_alignment(akind);
+ type->imaginary.akind = akind;
return identify_new_type(type);
}
ATOMIC_TYPE_LONG_DOUBLE,
ATOMIC_TYPE_BOOL,
- ATOMIC_TYPE_FLOAT_COMPLEX,
- ATOMIC_TYPE_DOUBLE_COMPLEX,
- ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
- ATOMIC_TYPE_FLOAT_IMAGINARY,
- ATOMIC_TYPE_DOUBLE_IMAGINARY,
- ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
-
- ATOMIC_TYPE_LAST = ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY
+ ATOMIC_TYPE_LAST = ATOMIC_TYPE_BOOL
} atomic_type_kind_t;
typedef enum {
typedef struct type_base_t type_base_t;
typedef struct atomic_type_t atomic_type_t;
+typedef struct complex_type_t complex_type_t;
+typedef struct imaginary_type_t imaginary_type_t;
typedef struct pointer_type_t pointer_type_t;
typedef struct function_parameter_t function_parameter_t;
typedef struct function_type_t function_type_t;
return result;
}
+static unsigned hash_complex_type(const complex_type_t *type)
+{
+ unsigned some_prime = 27644437;
+ unsigned result = type->akind * some_prime;
+
+ return result;
+}
+
+static unsigned hash_imaginary_type(const imaginary_type_t *type)
+{
+ unsigned some_prime = 27644437;
+ unsigned result = type->akind * some_prime;
+
+ return result;
+}
+
static unsigned hash_pointer_type(const pointer_type_t *type)
{
return hash_ptr(type->points_to);
case TYPE_ATOMIC:
hash = hash_atomic_type(&type->atomic);
break;
+ case TYPE_COMPLEX:
+ hash = hash_complex_type(&type->complex);
+ break;
+ case TYPE_IMAGINARY:
+ hash = hash_imaginary_type(&type->imaginary);
+ break;
case TYPE_ENUM:
hash = hash_enum_type(&type->enumt);
break;
}
static bool atomic_types_equal(const atomic_type_t *type1,
- const atomic_type_t *type2)
+ const atomic_type_t *type2)
+{
+ return type1->akind == type2->akind;
+}
+
+static bool complex_types_equal(const complex_type_t *type1,
+ const complex_type_t *type2)
+{
+ return type1->akind == type2->akind;
+}
+
+static bool imaginary_types_equal(const imaginary_type_t *type1,
+ const imaginary_type_t *type2)
{
return type1->akind == type2->akind;
}
return false;
case TYPE_ATOMIC:
return atomic_types_equal(&type1->atomic, &type2->atomic);
+ case TYPE_COMPLEX:
+ return complex_types_equal(&type1->complex, &type2->complex);
+ case TYPE_IMAGINARY:
+ return imaginary_types_equal(&type1->imaginary, &type2->imaginary);
case TYPE_ENUM:
return enum_types_equal(&type1->enumt, &type2->enumt);
case TYPE_COMPOUND_STRUCT:
TYPE_INVALID,
TYPE_ERROR,
TYPE_ATOMIC,
+ TYPE_COMPLEX,
+ TYPE_IMAGINARY,
TYPE_COMPOUND_STRUCT,
TYPE_COMPOUND_UNION,
TYPE_ENUM,
atomic_type_kind_t akind;
};
+struct complex_type_t {
+ type_base_t base;
+ atomic_type_kind_t akind;
+};
+
+struct imaginary_type_t {
+ type_base_t base;
+ atomic_type_kind_t akind;
+};
+
struct builtin_type_t {
type_base_t base;
symbol_t *symbol;
type_kind_t kind;
type_base_t base;
atomic_type_t atomic;
+ complex_type_t complex;
+ imaginary_type_t imaginary;
builtin_type_t builtin;
pointer_type_t pointer;
array_type_t array;
};
type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
+type_t *make_complex_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
+type_t *make_imaginary_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
type_t *make_array_type(type_t *element_type, size_t size,
type_qualifiers_t qualifiers);
case TYPE_INVALID:
panic("invalid type found");
break;
+ case TYPE_COMPLEX:
+ case TYPE_IMAGINARY:
default:
fprintf(out, "/* TODO type */");
break;