Do not mark the transformed as visited. It makes no sense at all.
[libfirm] / ir / be / begnuas.c
index 531e868..7ca9fcf 100644 (file)
@@ -249,31 +249,37 @@ static void dump_arith_tarval(tarval *tv, int bytes)
                return;
 
        case 12:
-               be_emit_irprintf("0x%02x%02x%02x%02x%02x%02x%02x%02x"
-                                  "%02x%02x%02x%02x", get_tarval_sub_bits(tv, 11),
-                               get_tarval_sub_bits(tv, 10), get_tarval_sub_bits(tv, 9),
-                               get_tarval_sub_bits(tv, 8), get_tarval_sub_bits(tv, 7),
-                               get_tarval_sub_bits(tv, 6), get_tarval_sub_bits(tv, 5),
-                               get_tarval_sub_bits(tv, 4), get_tarval_sub_bits(tv, 3),
-                               get_tarval_sub_bits(tv, 2), get_tarval_sub_bits(tv, 1),
-                               get_tarval_sub_bits(tv, 0));
+               /* Beware: Mixed endian output!  One little endian number emitted as
+                * three longs.  Each long initializer is written in big endian. */
+               be_emit_irprintf(
+                       "\t.long\t0x%02x%02x%02x%02x\n"
+                       "\t.long\t0x%02x%02x%02x%02x\n"
+                       "\t.long\t0x%02x%02x%02x%02x",
+                       get_tarval_sub_bits(tv,  3), get_tarval_sub_bits(tv,  2),
+                       get_tarval_sub_bits(tv,  1), get_tarval_sub_bits(tv,  0),
+                       get_tarval_sub_bits(tv,  7), get_tarval_sub_bits(tv,  6),
+                       get_tarval_sub_bits(tv,  5), get_tarval_sub_bits(tv,  4),
+                       get_tarval_sub_bits(tv, 11), get_tarval_sub_bits(tv, 10),
+                       get_tarval_sub_bits(tv,  9), get_tarval_sub_bits(tv,  8)
+               );
                return;
 
        case 16:
-               be_emit_irprintf("0x%02x%02x%02x%02x%02x%02x%02x%02x"
-                                              "%02x%02x%02x%02x%02x%02x%02x%02x",
+               be_emit_irprintf(
+                       "\t.long\t0x%02x%02x%02x%02x0x%02x%02x%02x%02x0x%02x%02x%02x%02x0x%02x%02x%02x%02x",
                        get_tarval_sub_bits(tv, 15), get_tarval_sub_bits(tv, 16),
                        get_tarval_sub_bits(tv, 13), get_tarval_sub_bits(tv, 12),
                        get_tarval_sub_bits(tv, 11), get_tarval_sub_bits(tv, 10),
-                       get_tarval_sub_bits(tv, 9), get_tarval_sub_bits(tv, 8),
-                       get_tarval_sub_bits(tv, 7), get_tarval_sub_bits(tv, 6),
-                       get_tarval_sub_bits(tv, 5), get_tarval_sub_bits(tv, 4),
-                       get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2),
-                       get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
+                       get_tarval_sub_bits(tv,  9), get_tarval_sub_bits(tv,  8),
+                       get_tarval_sub_bits(tv,  7), get_tarval_sub_bits(tv,  6),
+                       get_tarval_sub_bits(tv,  5), get_tarval_sub_bits(tv,  4),
+                       get_tarval_sub_bits(tv,  3), get_tarval_sub_bits(tv,  2),
+                       get_tarval_sub_bits(tv,  1), get_tarval_sub_bits(tv,  0)
+               );
                return;
        }
 
-       panic("Can't dump a tarval with %d bytes\n", bytes);
+       panic("Can't dump a tarval with %d bytes", bytes);
 }
 
 /**
@@ -430,35 +436,35 @@ static void do_dump_atomic_init(be_gas_decl_env_t *env, ir_node *init)
                }
                return;
 
-               case iro_Add:
-                       if (!mode_is_int(mode) && !mode_is_reference(mode)) {
-                               panic("Constant must be int or pointer for '+' to work");
-                       }
-                       do_dump_atomic_init(env, get_Add_left(init));
-                       be_emit_cstring(" + ");
-                       do_dump_atomic_init(env, get_Add_right(init));
-                       return;
-
-               case iro_Sub:
-                       if (!mode_is_int(mode) && !mode_is_reference(mode)) {
-                               panic("Constant must be int or pointer for '-' to work");
-                       }
-                       do_dump_atomic_init(env, get_Sub_left(init));
-                       be_emit_cstring(" - ");
-                       do_dump_atomic_init(env, get_Sub_right(init));
-                       return;
-
-               case iro_Mul:
-                       if (!mode_is_int(mode) && !mode_is_reference(mode)) {
-                               panic("Constant must be int or pointer for '*' to work");
-                       }
-                       do_dump_atomic_init(env, get_Mul_left(init));
-                       be_emit_cstring(" * ");
-                       do_dump_atomic_init(env, get_Mul_right(init));
-                       return;
+       case iro_Add:
+               if (!mode_is_int(mode) && !mode_is_reference(mode)) {
+                       panic("Constant must be int or pointer for '+' to work");
+               }
+               do_dump_atomic_init(env, get_Add_left(init));
+               be_emit_cstring(" + ");
+               do_dump_atomic_init(env, get_Add_right(init));
+               return;
 
-               default:
-                       assert(0 && "dump_atomic_init(): unknown IR-node");
+       case iro_Sub:
+               if (!mode_is_int(mode) && !mode_is_reference(mode)) {
+                       panic("Constant must be int or pointer for '-' to work");
+               }
+               do_dump_atomic_init(env, get_Sub_left(init));
+               be_emit_cstring(" - ");
+               do_dump_atomic_init(env, get_Sub_right(init));
+               return;
+
+       case iro_Mul:
+               if (!mode_is_int(mode) && !mode_is_reference(mode)) {
+                       panic("Constant must be int or pointer for '*' to work");
+               }
+               do_dump_atomic_init(env, get_Mul_left(init));
+               be_emit_cstring(" * ");
+               do_dump_atomic_init(env, get_Mul_right(init));
+               return;
+
+       default:
+               panic("dump_atomic_init(): unsupported IR-node %+F", init);
        }
 }
 
@@ -495,7 +501,7 @@ static void dump_size_type(size_t size) {
                break;
 
        default:
-               panic("Try to dump a type with %u bytes\n", (unsigned) size);
+               panic("Try to dump a type with %u bytes", (unsigned)size);
        }
 }
 
@@ -628,19 +634,21 @@ static int ent_is_string_const(ir_entity *ent)
 static void dump_string_cst(ir_entity *ent)
 {
        int      i, len;
+       int      output_len;
        ir_type *type;
        int      type_size;
        int      remaining_space;
 
-       len = get_compound_ent_n_values(ent);
+       len        = get_compound_ent_n_values(ent);
+       output_len = len;
        if (be_gas_flavour == GAS_FLAVOUR_MACH_O) {
                be_emit_cstring("\t.ascii \"");
        } else {
                be_emit_cstring("\t.string \"");
-               len -= 1;
+               output_len -= 1;
        }
 
-       for (i = 0; i < len; ++i) {
+       for (i = 0; i < output_len; ++i) {
                ir_node *irn;
                int c;
 
@@ -669,7 +677,7 @@ static void dump_string_cst(ir_entity *ent)
        remaining_space = type_size - len;
        assert(remaining_space >= 0);
        if(remaining_space > 0) {
-               be_emit_irprintf("\t.skip\t%d\n", remaining_space);
+               be_emit_irprintf("\t.space\t%d\n", remaining_space);
        }
 }
 
@@ -806,8 +814,9 @@ static void dump_bitfield(normal_or_bitfield *vals, size_t offset_bits,
                panic("bitfield initializer is compound");
        }
        if (tv == NULL) {
-               panic("Couldn't get numeric value for bitfield initializer\n");
+               panic("Couldn't get numeric value for bitfield initializer");
        }
+       tv = tarval_convert_to(tv, get_type_mode(type));
 
        /* normalize offset */
        vals        += offset_bits >> 3;
@@ -945,7 +954,7 @@ static void dump_initializer(be_gas_decl_env_t *env, ir_entity *entity)
         * In the worst case, every initializer allocates one byte.
         * Moreover, initializer might be big, do not allocate on stack.
         */
-       vals = xcalloc(size, sizeof(vals[0]));
+       vals = XMALLOCNZ(normal_or_bitfield, size);
 
 #ifndef NDEBUG
        glob_vals = vals;
@@ -990,7 +999,7 @@ static void dump_initializer(be_gas_decl_env_t *env, ir_entity *entity)
 
                /* a gap */
                if (space > 0) {
-                       be_emit_irprintf("\t.skip\t%d\n", space);
+                       be_emit_irprintf("\t.space\t%d\n", space);
                        be_emit_write_line();
                }
        }
@@ -1034,7 +1043,7 @@ static void dump_compound_init(be_gas_decl_env_t *env, ir_entity *ent)
         * In the worst case, every initializer allocates one byte.
         * Moreover, initializer might be big, do not allocate on stack.
         */
-       vals = xcalloc(last_ofs, sizeof(vals[0]));
+       vals = XMALLOCNZ(normal_or_bitfield, last_ofs);
 
        /* collect the values and store them at the offsets */
        for (i = 0; i < n; ++i) {
@@ -1050,7 +1059,7 @@ static void dump_compound_init(be_gas_decl_env_t *env, ir_entity *ent)
                        tarval *tv = get_atomic_init_tv(value);
                        unsigned char curr_bits, last_bits = 0;
                        if (tv == NULL) {
-                               panic("Couldn't get numeric value for bitfield initializer '%s'\n",
+                               panic("Couldn't get numeric value for bitfield initializer '%s'",
                                      get_entity_ld_name(ent));
                        }
                        /* normalize offset */
@@ -1103,7 +1112,7 @@ static void dump_compound_init(be_gas_decl_env_t *env, ir_entity *ent)
 
                /* a gap */
                if (space > 0) {
-                       be_emit_irprintf("\t.skip\t%d\n", space);
+                       be_emit_irprintf("\t.space\t%d\n", space);
                        be_emit_write_line();
                }
        }
@@ -1214,14 +1223,21 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent)
                                be_emit_write_line();
                                break;
                        }
-               } else if (section == GAS_SECTION_PIC_TRAMPOLINES) {
+               } else if (section == GAS_SECTION_PIC_TRAMPOLINES
+                               || section == GAS_SECTION_PIC_SYMBOLS) {
                        if (be_gas_flavour == GAS_FLAVOUR_MACH_O) {
                                be_emit_cstring("\t.indirect_symbol ");
                                be_emit_ident(get_entity_ident(ent));
                                be_emit_char('\n');
                                be_emit_write_line();
-                               be_emit_cstring("\thlt ; hlt ; hlt ; hlt ; hlt\n");
-                               be_emit_write_line();
+                               if (section == GAS_SECTION_PIC_TRAMPOLINES) {
+                                       be_emit_cstring("\thlt ; hlt ; hlt ; hlt ; hlt\n");
+                                       be_emit_write_line();
+                               } else {
+                                       assert(section == GAS_SECTION_PIC_SYMBOLS);
+                                       be_emit_cstring("\t.long 0\n");
+                                       be_emit_write_line();
+                               }
                        } else {
                                panic("PIC trampolines not yet supported in this gas mode");
                        }
@@ -1248,7 +1264,7 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent)
                                dump_compound_init(env, ent);
                                break;
                        default:
-                               assert(0);
+                               panic("Unimplemented type kind in dump_global()");
                        }
                }
        }