query firm backend for machine_size and long double size
authorMatthias Braun <matze@braunis.de>
Wed, 15 Jun 2011 13:00:28 +0000 (15:00 +0200)
committerMatthias Braun <matze@braunis.de>
Fri, 17 Jun 2011 11:37:10 +0000 (13:37 +0200)
lang_features.h
main.c
type.c

index 4771433..95e8a3f 100644 (file)
@@ -52,9 +52,9 @@ extern bool strict_mode;
 /** atomic type of wchar_t */
 extern atomic_type_kind_t wchar_atomic_kind;
 
-/** size of long double (this is 16 on some x86 architectures even if only the
- * lowest 80bits are used */
-extern unsigned force_long_double_size;
+/** size of long double in bits (this is the size stored to memory, not
+ * necessary the precision of the arithmetic) */
+extern unsigned long_double_size;
 
 /** a hack that adds a call to __main into the main function, necessary on
  * mingw */
diff --git a/main.c b/main.c
index 190f932..b0a477d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -105,7 +105,7 @@ bool               char_is_signed            = true;
 bool               strict_mode               = false;
 bool               use_builtins              = false;
 atomic_type_kind_t wchar_atomic_kind         = ATOMIC_TYPE_INT;
-unsigned           force_long_double_size    = 0;
+unsigned           long_double_size          = 0;
 bool               enable_main_collect2_hack = false;
 bool               freestanding              = false;
 
@@ -808,7 +808,6 @@ static bool init_os_support(void)
 {
        const char *os = target_machine->operating_system;
        wchar_atomic_kind         = ATOMIC_TYPE_INT;
-       force_long_double_size    = 0;
        enable_main_collect2_hack = false;
        define_intmax_types       = false;
 
@@ -816,7 +815,7 @@ static bool init_os_support(void)
                        || streq(os, "solaris")) {
                set_create_ld_ident(create_name_linux_elf);
        } else if (streq(os, "darwin")) {
-               force_long_double_size = 16;
+               long_double_size = 16;
                set_create_ld_ident(create_name_macho);
                define_intmax_types = true;
        } else if (strstr(os, "mingw") != NULL || streq(os, "win32")) {
@@ -845,6 +844,17 @@ static void setup_target_machine(void)
 {
        if (!setup_firm_for_machine(target_machine))
                exit(1);
+
+       const backend_params *be_params = be_get_backend_param();
+       if (be_params->long_double_size % 8 != 0) {
+               fprintf(stderr, "firm-target long double size is not a multiple of 8, can't handle this\n");
+               exit(1);
+       }
+
+       byte_order_big_endian = be_params->byte_order_big_endian;
+       machine_size          = be_params->machine_size;
+       long_double_size      = be_params->long_double_size / 8;
+
        init_os_support();
 }
 
@@ -1236,10 +1246,10 @@ int main(int argc, char **argv)
                                                fprintf(stderr, "error: option -m supports only 16, 32 or 64\n");
                                                argument_errors = true;
                                        } else {
-                                               machine_size = (unsigned int)value;
                                                add_flag(&cppflags_obst, "-m%u", machine_size);
                                                add_flag(&asflags_obst, "-m%u", machine_size);
                                                add_flag(&ldflags_obst, "-m%u", machine_size);
+                                               /* TODO: choose/change backend based on this */
                                        }
                                }
                        } else if (streq(option, "pg")) {
@@ -1443,7 +1453,6 @@ int main(int argc, char **argv)
        }
 
        gen_firm_init();
-       byte_order_big_endian = be_get_backend_param()->byte_order_big_endian;
        init_symbol_table();
        init_types();
        init_typehash();
diff --git a/type.c b/type.c
index 1fd4b64..51bad27 100644 (file)
--- a/type.c
+++ b/type.c
@@ -183,7 +183,7 @@ static atomic_type_properties_t atomic_type_properties[ATOMIC_TYPE_LAST+1] = {
                              | ATOMIC_TYPE_FLAG_SIGNED,
        },
        [ATOMIC_TYPE_LONG_DOUBLE] = {
-               .size       = 12,
+               .size       = (unsigned) -1, /* will be filled in later */
                .alignment  = (unsigned) -1,
                .flags      = ATOMIC_TYPE_FLAG_FLOAT | ATOMIC_TYPE_FLAG_ARITHMETIC
                              | ATOMIC_TYPE_FLAG_SIGNED,
@@ -234,9 +234,12 @@ void init_types(void)
                props[ATOMIC_TYPE_LONGLONG].alignment    = 8;
                props[ATOMIC_TYPE_ULONGLONG].alignment   = 8;
        }
-       if (force_long_double_size > 0) {
-               props[ATOMIC_TYPE_LONG_DOUBLE].size      = force_long_double_size;
-               props[ATOMIC_TYPE_LONG_DOUBLE].alignment = force_long_double_size;
+
+       if (long_double_size > 0) {
+               props[ATOMIC_TYPE_LONG_DOUBLE].size      = long_double_size;
+               props[ATOMIC_TYPE_LONG_DOUBLE].alignment = long_double_size;
+       } else {
+               props[ATOMIC_TYPE_LONG_DOUBLE] = props[ATOMIC_TYPE_DOUBLE];
        }
 
        /* TODO: make this configurable for platforms which do not use byte sized