support complex type (no arithmetic yet)
authorMatthias Braun <matze@braunis.de>
Thu, 29 Nov 2012 09:49:36 +0000 (10:49 +0100)
committerMatthias Braun <matze@braunis.de>
Mon, 3 Dec 2012 14:52:24 +0000 (15:52 +0100)
ast2firm.c
type.c
type.h

index 8e34489..7e605af 100644 (file)
@@ -209,8 +209,7 @@ static ir_mode *init_atomic_ir_mode(atomic_type_kind_t kind)
 {
        unsigned flags = get_atomic_type_flags(kind);
        unsigned size  = get_atomic_type_size(kind);
-       if ((flags & ATOMIC_TYPE_FLAG_FLOAT)
-           && !(flags & ATOMIC_TYPE_FLAG_COMPLEX)) {
+       if (flags & ATOMIC_TYPE_FLAG_FLOAT) {
                switch (size) {
                case 4:  return get_modeF();
                case 8:  return get_modeD();
@@ -271,35 +270,50 @@ static unsigned count_parameters(const function_type_t *function_type)
        return count;
 }
 
-/**
- * Creates a Firm type for an atomic type
- */
-static ir_type *create_atomic_type(atomic_type_kind_t akind, const type_t *type)
+static ir_type *create_primitive_irtype(atomic_type_kind_t akind,
+                                        type_dbg_info *dbgi)
 {
        ir_mode        *mode      = atomic_modes[akind];
-       type_dbg_info  *dbgi      = get_type_dbg_info_(type);
        ir_type        *irtype    = new_d_type_primitive(mode, dbgi);
-       il_alignment_t  alignment = get_atomic_type_alignment(akind);
+       unsigned        alignment = get_atomic_type_alignment(akind);
+       unsigned        size      = get_atomic_type_size(akind);
 
-       set_type_size_bytes(irtype, get_atomic_type_size(akind));
+       set_type_size_bytes(irtype, size);
        set_type_alignment_bytes(irtype, alignment);
 
        return irtype;
 }
 
+/**
+ * Creates a Firm type for an atomic type
+ */
+static ir_type *create_atomic_type(atomic_type_kind_t akind, const type_t *type)
+{
+       type_dbg_info *dbgi = get_type_dbg_info_(type);
+       return create_primitive_irtype(akind, dbgi);
+}
+
 /**
  * Creates a Firm type for a complex type
  */
-static ir_type *create_complex_type(const atomic_type_t *type)
+static ir_type *create_complex_type(atomic_type_kind_t akind,
+                                    const type_t *type)
 {
-       atomic_type_kind_t  kind = type->akind;
-       ir_mode            *mode = atomic_modes[kind];
-       ident              *id   = get_mode_ident(mode);
+       type_dbg_info *dbgi   = get_type_dbg_info_(type);
+       ir_type       *etype  = create_primitive_irtype(akind, NULL);
+       ir_type       *irtype = new_d_type_array(1, etype, dbgi);
 
-       (void) id;
+       int align = get_type_alignment_bytes(etype);
+       set_type_alignment_bytes(irtype, align);
+       unsigned n_elements = 2;
+       set_array_bounds_int(irtype, 0, 0, n_elements);
+       size_t elemsize = get_type_size_bytes(etype);
+       if (elemsize % align > 0) {
+               elemsize += align - (elemsize % align);
+       }
+       set_type_size_bytes(irtype, n_elements * elemsize);
 
-       /* FIXME: finish the array */
-       return NULL;
+       return irtype;
 }
 
 /**
@@ -682,7 +696,7 @@ ir_type *get_ir_type(type_t *type)
                firm_type = create_atomic_type(type->atomic.akind, type);
                break;
        case TYPE_COMPLEX:
-               firm_type = create_complex_type(&type->atomic);
+               firm_type = create_complex_type(type->atomic.akind, type);
                break;
        case TYPE_IMAGINARY:
                firm_type = create_imaginary_type(&type->atomic);
@@ -1830,7 +1844,7 @@ static ir_node *create_condition_evaluation(expression_t const *expression, jump
 static void assign_value(dbg_info *dbgi, ir_node *addr, type_t *type,
                          ir_node *value)
 {
-       if (!is_type_compound(type)) {
+       if (is_type_scalar(type)) {
                ir_mode *mode = get_ir_mode_storage(type);
                value         = create_conv(dbgi, value, mode);
        }
diff --git a/type.c b/type.c
index de6b570..9e7621e 100644 (file)
--- a/type.c
+++ b/type.c
@@ -53,6 +53,8 @@ static size_t get_type_struct_size(type_kind_t kind)
 {
        static const size_t sizes[] = {
                [TYPE_ATOMIC]          = sizeof(atomic_type_t),
+               [TYPE_IMAGINARY]       = sizeof(atomic_type_t),
+               [TYPE_COMPLEX]         = sizeof(atomic_type_t),
                [TYPE_COMPOUND_STRUCT] = sizeof(compound_type_t),
                [TYPE_COMPOUND_UNION]  = sizeof(compound_type_t),
                [TYPE_ENUM]            = sizeof(enum_type_t),
@@ -776,16 +778,6 @@ bool is_type_float(const type_t *type)
        return test_atomic_type_flag(type->atomic.akind, ATOMIC_TYPE_FLAG_FLOAT);
 }
 
-bool is_type_complex(const type_t *type)
-{
-       assert(!is_typeref(type));
-
-       if (type->kind != TYPE_ATOMIC)
-               return false;
-
-       return test_atomic_type_flag(type->atomic.akind, ATOMIC_TYPE_FLAG_COMPLEX);
-}
-
 bool is_type_signed(const type_t *type)
 {
        assert(!is_typeref(type));
@@ -825,10 +817,16 @@ bool is_type_scalar(const type_t *type)
 {
        assert(!is_typeref(type));
 
-       if (type->kind == TYPE_POINTER)
+       switch(type->kind) {
+       case TYPE_POINTER:
+       case TYPE_ENUM:
                return true;
-
-       return is_type_arithmetic(type);
+       case TYPE_ATOMIC:
+       case TYPE_IMAGINARY:
+               return test_atomic_type_flag(type->atomic.akind, ATOMIC_TYPE_FLAG_ARITHMETIC);
+       default:
+               return false;
+       }
 }
 
 bool is_type_incomplete(const type_t *type)
diff --git a/type.h b/type.h
index 728f458..c65448e 100644 (file)
--- a/type.h
+++ b/type.h
@@ -59,7 +59,6 @@ typedef enum atomic_type_flag_t {
        ATOMIC_TYPE_FLAG_INTEGER    = 1 << 1,
        ATOMIC_TYPE_FLAG_FLOAT      = 1 << 2,
        ATOMIC_TYPE_FLAG_ARITHMETIC = 1 << 3,
-       ATOMIC_TYPE_FLAG_COMPLEX    = 1 << 4,
 } atomic_type_flag_t;
 
 typedef enum type_qualifier_t {
@@ -78,8 +77,6 @@ typedef unsigned short type_qualifiers_t;
 
 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 reference_type_t      reference_type_t;
 typedef struct function_parameter_t  function_parameter_t;