warning fixes
[libfirm] / ir / be / begnuas.c
index 5bb8185..7269b3f 100644 (file)
@@ -38,7 +38,6 @@
 #include "obst.h"
 #include "tv.h"
 #include "irnode.h"
-#include "entity.h"
 #include "irprog.h"
 #include "pdeq.h"
 #include "error.h"
@@ -80,8 +79,8 @@ static const char *get_section_name(be_gas_section_t section) {
                }
        };
 
-       assert(be_gas_flavour >= 0 && be_gas_flavour < GAS_FLAVOUR_MAX);
-       assert(section >= 0 && section < GAS_SECTION_MAX);
+       assert((int) be_gas_flavour >= 0 && be_gas_flavour < GAS_FLAVOUR_MAX);
+       assert((int) section >= 0 && section < GAS_SECTION_MAX);
        return text[be_gas_flavour][section];
 }
 
@@ -258,9 +257,9 @@ static void do_dump_atomic_init(be_gas_decl_env_t *env, obstack_t *obst,
 
                case symconst_addr_ent:
                        ent = get_SymConst_entity(init);
-                       if(!entity_visited(ent)) {
+                       if(!is_entity_backend_marked(ent)) {
                                waitq_put(env->worklist, ent);
-                               mark_entity_visited(ent);
+                               set_entity_backend_marked(ent, 1);
                        }
                        obstack_printf(obst, "%s", get_entity_ld_name(ent));
                        break;
@@ -268,9 +267,9 @@ static void do_dump_atomic_init(be_gas_decl_env_t *env, obstack_t *obst,
                case symconst_ofs_ent:
                        ent = get_SymConst_entity(init);
 #if 0       /* not needed, is it? */
-                       if(!entity_visited(ent)) {
+                       if(!is_entity_backend_marked(ent)) {
                                waitq_put(env->worklist, ent);
-                               mark_entity_visited(ent);
+                               set_entity_backend_marked(ent, 1);
                        }
 #endif
                        obstack_printf(obst, "%d", get_entity_offset(ent));
@@ -436,7 +435,10 @@ static int ent_is_string_const(ir_entity *ent)
  */
 static void dump_string_cst(obstack_t *obst, ir_entity *ent)
 {
-       int i, n;
+       int      i, n;
+       ir_type *type;
+       int      type_size;
+       int      remaining_space;
 
        obstack_printf(obst, "\t.string \"");
        n = get_compound_ent_n_values(ent);
@@ -463,37 +465,14 @@ static void dump_string_cst(obstack_t *obst, ir_entity *ent)
                }
        }
        obstack_printf(obst, "\"\n");
-}
 
-static void dump_array_init(be_gas_decl_env_t *env, obstack_t *obst,
-                            ir_entity *ent)
-{
-       const ir_type *ty = get_entity_type(ent);
-       int i;
-       int filler;
-       int size = 0;
-
-       /* potential spare values should be already included! */
-       for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
-               ir_entity *step = get_compound_ent_value_member(ent, i);
-               ir_type *stype = get_entity_type(step);
-
-               if (get_type_mode(stype)) {
-                       int align = (get_type_alignment_bits(stype) + 7) >> 3;
-                       int n     = size % align;
-
-                       if (n > 0) {
-                               obstack_printf(obst, "\t.zero\t%d\n", align - n);
-                               size += align - n;
-                       }
-               }
-               dump_atomic_init(env, obst, get_compound_ent_value(ent, i));
-               size += get_type_size_bytes(stype);
+       type            = get_entity_type(ent);
+       type_size       = get_type_size_bytes(type);
+       remaining_space = type_size - n;
+       assert(remaining_space >= 0);
+       if(remaining_space > 0) {
+               obstack_printf(obst, "\t.skip\t%d\n", remaining_space);
        }
-       filler = get_type_size_bytes(ty) - size;
-
-       if (filler > 0)
-               obstack_printf(obst, "\t.skip\t%d\n", filler);
 }
 
 enum normal_or_bitfield_kind {
@@ -631,10 +610,10 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons
        obstack_t *obst;
        ir_type *type = get_entity_type(ent);
        const char *ld_name = get_entity_ld_name(ent);
-       ir_variability variability = get_entity_variability(ent);
-       ir_visibility visibility = get_entity_visibility(ent);
        int align = get_type_alignment_bytes(type);
        int emit_as_common = 0;
+       ir_variability variability;
+       ir_visibility visibility;
 
        obst = env->data_obst;
        if (is_Method_type(type)) {
@@ -645,13 +624,17 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons
                        obstack_printf(obst, "%s\n", ld_name);
                }
                return;
-       } else if (variability == variability_constant) {
+       }
+
+       variability = get_entity_variability(ent);
+       visibility = get_entity_visibility(ent);
+       if (variability == variability_constant) {
                /* a constant entity, put it on the rdata */
                obst = env->rodata_obst;
        } else if (variability == variability_uninitialized) {
                /* uninitialized entity put it in bss segment */
                obst = env->bss_obst;
-               if(emit_commons && visibility != visibility_local)
+               if (emit_commons && visibility != visibility_local)
                        emit_as_common = 1;
        }
 
@@ -676,21 +659,36 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons
 
        if (variability == variability_uninitialized) {
                if(emit_as_common) {
-                       obstack_printf(obst, "\t.comm %s,%d,%d\n",
+                       if (be_gas_flavour == GAS_FLAVOUR_NORMAL)
+                               obstack_printf(obst, "\t.comm %s,%d,%d\n",
+                                       ld_name, get_type_size_bytes(type), align);
+                       else
+                               obstack_printf(obst, "\t.comm %s,%d # %d\n",
                                        ld_name, get_type_size_bytes(type), align);
                } else {
                        obstack_printf(obst, "\t.zero %d\n", get_type_size_bytes(type));
                }
-       } else if (is_atomic_type(type)) {
-               dump_atomic_init(env, obst, get_atomic_ent_value(ent));
-       } else if (ent_is_string_const(ent)) {
-               dump_string_cst(obst, ent);
-       } else if (is_Array_type(type)) {
-               dump_array_init(env, obst, ent);
-       } else if (is_compound_type(type)) {
-               dump_compound_init(env, obst, ent);
        } else {
-               assert(0 && "unsupported type");
+               if (is_atomic_entity(ent)) {
+                       dump_atomic_init(env, obst, get_atomic_ent_value(ent));
+               } else {
+                       /* sort_compound_ent_values(ent); */
+
+                       switch (get_type_tpop_code(get_entity_type(ent))) {
+                       case tpo_array:
+                               if (ent_is_string_const(ent))
+                                       dump_string_cst(obst, ent);
+                               else
+                                       dump_compound_init(env, obst, ent);
+                               break;
+                       case tpo_struct:
+                       case tpo_class:
+                               dump_compound_init(env, obst, ent);
+                               break;
+                       default:
+                               assert(0);
+                       }
+               }
        }
 }
 
@@ -709,27 +707,26 @@ static void be_gas_dump_globals(ir_type *gt, be_gas_decl_env_t *env,
        int i, n = get_compound_n_members(gt);
        waitq *worklist = new_waitq();
 
-       if(only_emit_marked) {
+       if (only_emit_marked) {
                for (i = 0; i < n; i++) {
                        ir_entity *ent = get_compound_member(gt, i);
-                       if(entity_visited(ent) ||
-                                       get_entity_visibility(ent) != visibility_external_allocated) {
+                       if (is_entity_backend_marked(ent) ||
+                           get_entity_visibility(ent) != visibility_external_allocated) {
                                waitq_put(worklist, ent);
-                               mark_entity_visited(ent);
+                               set_entity_backend_marked(ent, 1);
                        }
                }
        } else {
-               inc_master_type_visited();
                for (i = 0; i < n; i++) {
                        ir_entity *ent = get_compound_member(gt, i);
-                       mark_entity_visited(ent);
+                       set_entity_backend_marked(ent, 1);
                        waitq_put(worklist, ent);
                }
        }
 
        env->worklist = worklist;
 
-       while(!waitq_empty(worklist)) {
+       while (!waitq_empty(worklist)) {
                ir_entity *ent = waitq_get(worklist);
 
                dump_global(env, ent, emit_commons);