be: let begnuas call be_dbg_method_begin/end
[libfirm] / ir / be / bestabs.c
index ce6361f..05e8fd4 100644 (file)
@@ -37,7 +37,7 @@
 #include "xmalloc.h"
 #include "pmap.h"
 #include "pdeq.h"
-#include "irtools.h"
+#include "util.h"
 #include "obst.h"
 #include "array_t.h"
 #include "be_dbgout_t.h"
@@ -146,7 +146,7 @@ static unsigned get_type_number(stabs_handle *h, ir_type *tp)
                num = (unsigned)PTR_TO_INT(entry->value);
        }
        return num;
-}  /* get_type_number */
+}
 
 /**
  * Map a given Type to void by assigned the type number 0.
@@ -164,7 +164,7 @@ static void gen_void_type(stabs_handle *h)
        (void) h;
        be_emit_irprintf("\t.stabs\t\"void:t%u=%u\",%d,0,0,0\n", 0, 0, N_LSYM);
        be_emit_write_line();
-}  /* gen_void_type */
+}
 
 typedef struct walker_env {
        stabs_handle *h;
@@ -173,10 +173,10 @@ typedef struct walker_env {
 
 /* a type is not ready: put it on the wait queue */
 #define SET_TYPE_NOT_READY(wq, tp) \
-  do { \
-    set_type_link(tp, (void *)1);  \
-    waitq_put(wq, tp);             \
-  } while (0)
+       do { \
+               set_type_link(tp, (void *)1);  \
+               waitq_put(wq, tp);             \
+       } while (0)
 
 /* a the is ready */
 #define SET_TYPE_READY(tp)     set_type_link(tp, NULL)
@@ -242,12 +242,14 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp)
                Ignore it here as it's name is remapped to "void". */
                map_to_void(h, tp);
                return;
-       }  /* if */
+       }
 
-       if (0 && get_mode_size_bits(mode) & 7) {
+#if 0
+       if (get_mode_size_bits(mode) & 7) {
                /* this is a bitfield type, ignore it */
                return;
-       }  /* if */
+       }
+#endif
 
        type_num = get_type_number(h, tp);
 
@@ -267,7 +269,7 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp)
                be_emit_irprintf(":t%u=r1;%d;0;\",%d,0,0,0\n", type_num, size, N_LSYM);
                be_emit_write_line();
        }
-}  /* gen_primitive_type */
+}
 
 /**
  * Generates an enum type
@@ -293,7 +295,7 @@ static void gen_enum_type(stabs_handle *h, ir_type *tp)
        }
        be_emit_irprintf(";\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
-}  /* gen_enum_type */
+}
 
 /**
  * print a pointer type
@@ -328,7 +330,7 @@ static void gen_pointer_type(wenv_t *env, ir_type *tp)
        print_pointer_type(h, tp, 0);
        be_emit_irprintf("\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
-}  /* gen_pointer_type */
+}
 
 /**
  * print an array type
@@ -336,18 +338,18 @@ static void gen_pointer_type(wenv_t *env, ir_type *tp)
 static void print_array_type(stabs_handle *h, ir_type *tp, int local)
 {
        ir_type      *etp     = get_array_element_type(tp);
-       int          i, n     = get_array_n_dimensions(tp);
+       size_t       i, n     = get_array_n_dimensions(tp);
        unsigned     type_num = local ? h->next_type_nr++ : get_type_number(h, tp);
-       int          *perm;
+       size_t       *perm;
 
        be_emit_irprintf("%u=a", type_num);
-       NEW_ARR_A(int, perm, n);
+       perm = ALLOCAN(size_t, n);
        for (i = 0; i < n; ++i) {
                perm[i] = get_array_order(tp, i);
        }
 
        for (i = 0; i < n; ++i) {
-               int dim = perm[i];
+               size_t dim = perm[i];
 
                if (is_Const(get_array_lower_bound(tp, dim)) && is_Const(get_array_upper_bound(tp, dim))) {
                        long min = get_array_lower_bound_int(tp, dim);
@@ -385,7 +387,7 @@ static void gen_array_type(wenv_t *env, ir_type *tp)
 
        be_emit_irprintf("\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
-}  /* gen_array_type */
+}
 
 /**
  * Generates a struct/union type
@@ -426,19 +428,20 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp)
                ofs  = get_entity_offset(ent);
                if (is_Struct_type(mtp) && get_type_mode(mtp) != NULL) {
                        /* this structure is a bitfield, skip */
-                       int i, n;
+                       int m;
+                       int n_members = get_struct_n_members(mtp);
 
-                       for (i = 0, n = get_struct_n_members(mtp); i < n; ++i) {
-                               ir_entity *ent = get_struct_member(mtp, i);
-                               ir_type *tp = get_entity_type(ent);
+                       for (m = 0; m < n_members; ++m) {
+                               ir_entity *member    = get_struct_member(mtp, m);
+                               ir_type   *member_tp = get_entity_type(member);
                                int bofs;
 
-                               type_num = get_type_number(h, tp);
-                               size = get_type_size_bytes(tp) * 8;
-                               bofs = (ofs + get_entity_offset(ent)) * 8 + get_entity_offset_bits_remainder(ent);
+                               type_num = get_type_number(h, member_tp);
+                               size = get_type_size_bytes(member_tp) * 8;
+                               bofs = (ofs + get_entity_offset(member)) * 8 + get_entity_offset_bits_remainder(member);
 
                                /* name:type, bit offset from the start of the struct', number of bits in the element. */
-                               be_emit_irprintf("%s:%u,%d,%u;", get_entity_name(ent), type_num, bofs, size);
+                               be_emit_irprintf("%s:%u,%d,%u;", get_entity_name(member), type_num, bofs, size);
                        }
                } else {
                        /* no bitfield */
@@ -462,7 +465,7 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp)
        }
        be_emit_irprintf(";\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
-}  /* gen_struct_type */
+}
 
 /**
  * Generates a method type
@@ -500,7 +503,7 @@ static void gen_method_type(wenv_t *env, ir_type *tp)
        }
        be_emit_irprintf("\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
-}  /* gen_method_type */
+}
 
 /**
  * type-walker: generate declaration for simple types,
@@ -519,7 +522,7 @@ static void walk_type(type_or_ent tore, void *ctx)
                        return;
        } else {
                return;
-       }  /* if */
+       }
 
        switch (get_type_tpop_code(tp)) {
        case tpo_class:
@@ -559,8 +562,8 @@ static void walk_type(type_or_ent tore, void *ctx)
                break;
        default:
                assert(! "Unknown tpop code");
-       }  /* switch */
-}  /* walk_type */
+       }
+}
 
 /**
  * generate declaration for all types
@@ -601,9 +604,9 @@ static void finish_types(wenv_t *env)
                        break;
                default:
                        assert(! "Unknown tpop code");
-               }  /* switch */
-       }  /* while */
-}  /* finish_types */
+               }
+       }
+}
 
 /**
  * generate all types.
@@ -614,10 +617,15 @@ static void gen_types(stabs_handle *h)
 
        env.h  = h;
        env.wq = new_waitq();
+
+       irp_reserve_resources(irp, IRP_RESOURCE_TYPE_LINK);
        type_walk(NULL, walk_type, &env);
+       irp_free_resources(irp, IRP_RESOURCE_TYPE_LINK);
+
        finish_types(&env);
        del_waitq(env.wq);
-}  /* gen_types */
+
+}
 
 
 /* -------------------------- I/F ----------------------------- */
@@ -699,8 +707,8 @@ static void stabs_method_begin(dbg_handle *handle, const ir_entity *ent)
 
        /* create the method entry */
        mtp = get_entity_type(ent);
-       if (is_lowered_type(mtp))
-               mtp = get_associated_type(mtp);
+       while (is_lowered_type(mtp))
+               mtp = get_higher_type(mtp);
        if (get_method_n_ress(mtp) > 0)
                rtp = get_method_res_type(mtp, 0);
        else
@@ -717,19 +725,18 @@ static void stabs_method_begin(dbg_handle *handle, const ir_entity *ent)
        /* create parameter entries */
        between_size = get_type_size_bytes(layout->between_type);
        for (i = 0, n = get_method_n_params(mtp); i < n; ++i) {
-               ir_type *ptp      = get_method_param_type(mtp, i);
-        const char *name  = NULL;
-               unsigned type_num = get_type_number(h, ptp);
-        char buf[16];
-        int ofs = 0;
-               ir_entity *stack_ent;
-
-        if (! name) {
-          snprintf(buf, sizeof(buf), "arg%d", i);
-          name = buf;
-        }
+               ir_type    *ptp  = get_method_param_type(mtp, i);
+               const char *name = NULL;
+               char        buf[16];
+               int         ofs  = 0;
+               ir_entity  *stack_ent;
+
+               if (! name) {
+                       snprintf(buf, sizeof(buf), "arg%d", i);
+                       name = buf;
+               }
                /* check if this parameter has a stack entity. If it has, it
-                  it transmitted on the stack, else in a register */
+                * it transmitted on the stack, else in a register */
                stack_ent = layout->param_map[i];
                if (stack_ent) {
                        ofs = get_entity_offset(stack_ent) + between_size;
@@ -751,7 +758,7 @@ static void stabs_method_begin(dbg_handle *handle, const ir_entity *ent)
                be_emit_irprintf("\",%d,0,0,%d\n", N_PSYM, ofs);
                be_emit_write_line();
        }
-}  /* stabs_method_begin */
+}
 
 /**
  * dump the stabs for a method end
@@ -768,24 +775,24 @@ static void stabs_method_end(dbg_handle *handle)
        /* create entries for automatic variables on the stack */
        frame_size = get_type_size_bytes(layout->frame_type);
        for (i = 0, n = get_compound_n_members(layout->frame_type); i < n; ++i) {
-               ir_entity *ent = get_compound_member(layout->frame_type, i);
+               ir_entity *member = get_compound_member(layout->frame_type, i);
                ir_type *tp;
                int ofs;
                unsigned type_num;
 
                /* ignore spill slots and other helper objects */
-               if (is_entity_compiler_generated(ent))
+               if (is_entity_compiler_generated(member))
                        continue;
 
-               tp = get_entity_type(ent);
+               tp = get_entity_type(member);
                /* should not happen in backend but ... */
                if (is_Method_type(tp))
                        continue;
                type_num = get_type_number(h, tp);
-               ofs      = -frame_size + get_entity_offset(ent);
+               ofs      = -frame_size + get_entity_offset(member);
 
                be_emit_irprintf("\t.stabs\t\"%s:%u\",%d,0,0,%d\n",
-                       get_entity_name(ent), type_num, N_LSYM, ofs);
+                                get_entity_name(member), type_num, N_LSYM, ofs);
                be_emit_write_line();
        }
        /* we need a lexical block here */
@@ -799,7 +806,7 @@ static void stabs_method_end(dbg_handle *handle)
 
        h->cur_ent = NULL;
        h->layout  = NULL;
-}  /* stabs_method_end */
+}
 
 /**
  * dump types
@@ -812,7 +819,7 @@ static void stabs_types(dbg_handle *handle)
        h->next_type_nr++;
        gen_void_type(h);
        gen_types(h);
-}  /* stabs_types */
+}
 
 /**
  * dump a variable in the global type
@@ -831,16 +838,16 @@ static void stabs_variable(dbg_handle *handle, const ir_entity *ent)
                if (linkage & IR_LINKAGE_CONSTANT)
                        kind = N_ROSYM;
                snprintf(buf, sizeof(buf), "\t.stabs\t\"%s:S%u\",%d,0,0,%s\n",
-                       get_entity_name(ent), tp_num, kind, get_entity_ld_name(ent));
+                        get_entity_name(ent), tp_num, kind, get_entity_ld_name(ent));
        } else {
                /* a global variable */
                snprintf(buf, sizeof(buf), "\t.stabs\t\"%s:G%u\",%d,0,0,0\n",
-                       get_entity_name(ent), tp_num, N_GSYM);
+                        get_entity_name(ent), tp_num, (int)N_GSYM);
        }
        buf[sizeof(buf) - 1] = '\0';
 
        be_emit_string(buf);
-}  /* stabs_variable */
+}
 
 /**
  * Close the stabs handler.
@@ -850,7 +857,7 @@ static void stabs_close(dbg_handle *handle)
        stabs_handle *h = (stabs_handle *)handle;
        pmap_destroy(h->type_map);
        free(h);
-}  /* stabs_close */
+}
 
 /** The stabs operations. */
 static const debug_ops stabs_ops = {
@@ -875,7 +882,7 @@ static dbg_handle *be_stabs_open(void)
        return &h->base;
 }
 
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_stabs);
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_stabs)
 void be_init_stabs(void)
 {
        be_register_dbgout_module("stabs", be_stabs_open);