Prefer tarval_is_negative(x) over tarval_cmp(x, get_mode_null(get_tarval_mode(x))).
[libfirm] / ir / be / begnuas.c
index 2e8e3b0..e3d78e5 100644 (file)
@@ -110,7 +110,7 @@ static void emit_section(be_gas_section_t section, const ir_entity *entity)
                "text", "data", "rodata", "bss", "ctors", "dtors"
        };
        static const char *const type[] = {
-               "", "progbits", "progbits", "nobits", "init_array", "fini_array"
+               "progbits", "progbits", "progbits", "nobits", "init_array", "fini_array"
        };
 
        if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O) {
@@ -161,7 +161,9 @@ static void emit_section(be_gas_section_t section, const ir_entity *entity)
        be_emit_cstring(",\"");
        if (be_gas_object_file_format != OBJECT_FILE_FORMAT_COFF)
                be_emit_char('a');
-       if (base != GAS_SECTION_RODATA)
+       if (base == GAS_SECTION_TEXT)
+               be_emit_char('x');
+       if (base != GAS_SECTION_RODATA && base != GAS_SECTION_TEXT)
                be_emit_char('w');
        if (flags & GAS_SECTION_FLAG_TLS)
                be_emit_char('T');
@@ -572,14 +574,6 @@ static void emit_arith_tarval(tarval *tv, int bytes)
        panic("Can't dump a tarval with %d bytes", bytes);
 }
 
-/**
- * Return the label prefix for labeled blocks.
- */
-const char *be_gas_block_label_prefix(void)
-{
-       return ".LG";
-}
-
 /**
  * Return the label prefix for labeled instructions.
  */
@@ -670,10 +664,6 @@ static void do_emit_atomic_init(be_gas_decl_env_t *env, ir_node *init)
 
        case iro_SymConst:
                switch (get_SymConst_kind(init)) {
-               case symconst_addr_name:
-                       be_emit_ident(get_SymConst_name(init));
-                       break;
-
                case symconst_addr_ent:
                        ent = get_SymConst_entity(init);
                        be_gas_emit_entity(ent);
@@ -846,7 +836,7 @@ static void emit_string_cst(const ir_entity *ent)
        remaining_space = type_size - len;
        assert(remaining_space >= 0);
        if (remaining_space > 0) {
-               be_emit_irprintf("\t.zero\t%d\n", remaining_space);
+               be_emit_irprintf("\t.space\t%d\n", remaining_space);
        }
 }
 
@@ -1311,7 +1301,7 @@ static void emit_common(const ir_entity *entity)
 
        switch (be_gas_object_file_format) {
        case OBJECT_FILE_FORMAT_MACH_O:
-               be_emit_cstring("\t.lcomm ");
+               be_emit_cstring("\t.comm ");
                be_gas_emit_entity(entity);
                be_emit_irprintf(",%u,%u\n", size, log2_floor(alignment));
                be_emit_write_line();
@@ -1373,7 +1363,7 @@ static void emit_indirect_symbol(const ir_entity *entity, be_gas_section_t secti
        /* we can only do PIC code on macho so far */
        assert(be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O);
 
-       be_emit_ident(get_entity_ld_ident(entity));
+       be_gas_emit_entity(entity);
        be_emit_cstring(":\n");
        be_emit_write_line();
        be_emit_cstring("\t.indirect_symbol ");
@@ -1390,21 +1380,37 @@ static void emit_indirect_symbol(const ir_entity *entity, be_gas_section_t secti
        }
 }
 
+char const *be_gas_get_private_prefix(void)
+{
+       return
+               be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O ? "L" :
+               ".L";
+}
+
 void be_gas_emit_entity(const ir_entity *entity)
 {
        if (entity->type == firm_code_type) {
                ir_label_t label = get_entity_label(entity);
-               be_emit_string(be_gas_block_label_prefix());
-               be_emit_irprintf("%lu", label);
+               be_emit_irprintf("%s_%lu", be_gas_get_private_prefix(), label);
                return;
        }
 
        if (get_entity_visibility(entity) == ir_visibility_private) {
-               be_emit_cstring(".L");
+               be_emit_string(be_gas_get_private_prefix());
        }
        be_emit_ident(get_entity_ld_ident(entity));
 }
 
+void be_gas_emit_block_name(const ir_node *block)
+{
+       if (has_Block_entity(block)) {
+               ir_entity *entity = get_Block_entity(block);
+               be_gas_emit_entity(entity);
+       } else {
+               be_emit_irprintf("%s%ld", be_gas_get_private_prefix(), get_irn_node_nr(block));
+       }
+}
+
 /**
  * Dump a global entity.
  *
@@ -1452,7 +1458,8 @@ static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
                        }
                        break;
                case ir_visibility_external:
-                       panic("merge link semantic not supported for extern entities");
+                       if (linkage & IR_LINKAGE_MERGE)
+                               panic("merge link semantic not supported for extern entities");
                        break;
                }
        }
@@ -1496,9 +1503,9 @@ static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
        }
 
        if (entity_is_null(entity)) {
-               be_emit_irprintf("\t.zero %u\n", get_type_size_bytes(type));
+               be_emit_irprintf("\t.space %u\n", get_type_size_bytes(type));
                be_emit_write_line();
-       } else if(entity_has_compound_ent_values(entity)) {
+       } else if (entity_has_compound_ent_values(entity)) {
                emit_compound_graph_init(env, entity);
        } else {
                assert(entity->initializer != NULL);