fix fucompp emitter when no register is needed
[libfirm] / ir / be / ia32 / ia32_gen_decls.c
index 5646266..94722d2 100644 (file)
@@ -16,6 +16,7 @@
 #include "entity.h"
 #include "irprog.h"
 
+#include "ia32_emitter.h"
 #include "ia32_gen_decls.h"
 
 /************************************************************************/
@@ -53,6 +54,22 @@ static unsigned highest_bit(unsigned v)
        return res;
 }
 
+static void ia32_dump_comm(struct obstack *obst, const char *name, visibility vis, int size, int align) {
+       switch (asm_flavour) {
+       case ASM_LINUX_GAS:
+               if (vis == visibility_local)
+                       obstack_printf(obst, "\t.local\t%s\n", name);
+               obstack_printf(obst, "\t.comm\t%s,%d,%d\n", name, size, align);
+               break;
+       case ASM_MINGW_GAS:
+               if (vis == visibility_local)
+                       obstack_printf(obst, "\t.lcomm\t%s,%d\n", name, size);
+               else
+                       obstack_printf(obst, "\t.comm\t%s,%d\n", name, size);
+               break;
+       }
+}
+
 /*
  * output the alignment
  */
@@ -124,7 +141,7 @@ static void do_dump_atomic_init(struct obstack *obst, ir_node *init)
                tv = get_Const_tarval(init);
 
                /* beware of old stuff */
-               assert(! mode_is_reference(mode));
+               //assert(! mode_is_reference(mode));
 
                /* it's a arithmetic value */
                dump_arith_tarval(obst, tv, bytes);
@@ -140,10 +157,14 @@ static void do_dump_atomic_init(struct obstack *obst, ir_node *init)
                        obstack_printf(obst, "%s", get_entity_ld_name(get_SymConst_entity(init)));
                        break;
 
-               case symconst_size:
+               case symconst_type_size:
                        obstack_printf(obst, "%d", 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)));
+                       break;
+
                default:
                        assert(0 && "dump_atomic_init(): don't know how to init from this SymConst");
                }
@@ -291,6 +312,7 @@ static void dump_string_cst(struct obstack *obst, entity *ent)
                case '\n': obstack_printf(obst, "\\n"); break;
                case '\r': obstack_printf(obst, "\\r"); break;
                case '\t': obstack_printf(obst, "\\t"); break;
+               case '\\': obstack_printf(obst, "\\\\"); break;
                default  :
                        if (isprint(c))
                                obstack_printf(obst, "%c", c);
@@ -309,8 +331,12 @@ struct arr_info {
 };
 
 static void dump_object_size(struct obstack *obst, const char *name, int size) {
-       obstack_printf(obst, "\t.type\t%s,@object\n", name);
-       obstack_printf(obst, "\t.size\t%s,%d\n", name, size);
+       switch (asm_flavour) {
+       case ASM_LINUX_GAS:
+               obstack_printf(obst, "\t.type\t%s,@object\n", name);
+               obstack_printf(obst, "\t.size\t%s,%d\n", name, size);
+               break;
+       }
 }
 
 /*
@@ -443,7 +469,7 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
                                                                stepsize = (get_type_size_bits(step_type) + 7) >> 3;
 
                                                                /* Search the next free position in vals depending on the information from above (ai). */
-                                                               while (vals[offset]) {
+                                                               while (vals[offset] && aipos >= 0) {
                                                                        if (ai[aipos].visit_cnt < ai[aipos].n_elems) {
                                                                                offset += stepsize;
                                                                                ai[aipos].visit_cnt++;
@@ -484,10 +510,6 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
                        obstack_printf(obst, "\n");
                }
                else if (visibility != visibility_external_allocated) {
-                       if (visibility == visibility_local) {
-                               obstack_printf(comm_obstack, "\t.local\t%s\n", ld_name);
-                       }
-
                        /* calculate the alignment */
                        align = get_type_alignment_bytes(ty);
                        h = highest_bit(align);
@@ -499,7 +521,8 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
                        if (align < 1)
                                align = 1;
 
-                       obstack_printf(comm_obstack, "\t.comm\t%s,%d,%d\n", ld_name, (get_type_size_bits(ty) + 7) >> 3, align);
+                       ia32_dump_comm(comm_obstack, ld_name, visibility,
+                               (get_type_size_bits(ty) + 7) >> 3, align);
                }
        }
 }
@@ -532,7 +555,7 @@ void ia32_gen_decls(FILE *out) {
        size = obstack_object_size(&data);
        cp   = obstack_finish(&data);
        if (size > 0) {
-               fprintf(out, "\t.data\n");
+               ia32_switch_section(out, SECTION_DATA);
                fwrite(cp, 1, size, out);
        }
 
@@ -546,7 +569,7 @@ void ia32_gen_decls(FILE *out) {
        size = obstack_object_size(&comm);
        cp   = obstack_finish(&comm);
        if (size > 0) {
-               fprintf(out, "\t.text\n");
+               ia32_switch_section(out, SECTION_COMMON);
                fwrite(cp, 1, size, out);
        }