fix another PIC problem
[libfirm] / ir / be / bestabs.c
index e522a55..a51fdfd 100644 (file)
@@ -24,9 +24,7 @@
  * @date    11.9.2006
  * @version $Id$
  */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -41,7 +39,7 @@
 #include "pdeq.h"
 #include "irtools.h"
 #include "obst.h"
-#include "array.h"
+#include "array_t.h"
 #include "be_dbgout_t.h"
 #include "beabi.h"
 #include "bemodule.h"
@@ -209,6 +207,13 @@ static void be_emit_tv_as_decimal(tarval *tv) {
        set_tarval_mode_output_option(mode, old);
 }
 
+static void emit_type_name(const ir_type *type)
+{
+       char buf[256];
+       ir_print_type(buf, sizeof(buf), type);
+       be_emit_string(buf);
+}
+
 /**
  * Generates a primitive type.
  *
@@ -235,7 +240,9 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp) {
        type_num = get_type_number(h, tp);
 
        if (mode_is_int(mode)) {
-               be_emit_irprintf("\t.stabs\t\"%s:t%u=r%u;", get_type_name(tp), type_num, type_num);
+               be_emit_cstring("\t.stabs\t\"");
+               emit_type_name(tp);
+               be_emit_irprintf(":t%u=r%u;", type_num, type_num);
                be_emit_tv_as_decimal(get_mode_min(mode));
                be_emit_char(';');
                be_emit_tv_as_decimal(get_mode_max(mode));
@@ -243,7 +250,9 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp) {
                be_emit_write_line();
        } else if (mode_is_float(mode)) {
                int size = get_type_size_bytes(tp);
-               be_emit_irprintf("\t.stabs\t\"%s:t%u=r1;%d;0;\",%d,0,0,0\n", get_type_name(tp), type_num, size, N_LSYM);
+               be_emit_cstring("\t.stabs\t\"");
+               emit_type_name(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 */
@@ -259,13 +268,15 @@ static void gen_enum_type(stabs_handle *h, ir_type *tp) {
        int i, n;
 
        SET_TYPE_READY(tp);
-       be_emit_irprintf("\t.stabs\t\"%s:T%u=e", get_type_name(tp), type_num);
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_irprintf(":T%u=e", type_num);
        for (i = 0, n = get_enumeration_n_enums(tp); i < n; ++i) {
                ir_enum_const *ec = get_enumeration_const(tp, i);
                char buf[64];
 
                tarval_snprintf(buf, sizeof(buf), get_enumeration_value(ec));
-               be_emit_irprintf("%s:%s,", get_enumeration_name(ec), buf);
+               be_emit_irprintf("%s:%s,", get_enumeration_const_name(ec), buf);
        }
        be_emit_irprintf(";\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
@@ -296,7 +307,9 @@ static void gen_pointer_type(wenv_t *env, ir_type *tp) {
        if (! IS_TYPE_READY(el_tp))
                waitq_put(env->wq, el_tp);
 
-       be_emit_irprintf("\t.stabs\t\"%s:t", get_type_name(tp));
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_cstring(":t");
        print_pointer_type(h, tp, 0);
        be_emit_irprintf("\",%d,0,0,0\n", N_LSYM);
        be_emit_write_line();
@@ -347,7 +360,9 @@ static void gen_array_type(wenv_t *env, ir_type *tp) {
        if (! IS_TYPE_READY(etp))
                waitq_put(env->wq, etp);
 
-       be_emit_irprintf("\t.stabs\t\"%s:t", get_type_name(tp));
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_cstring(":t");
 
        print_array_type(h, tp, 0);
 
@@ -378,8 +393,9 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) {
        else if (is_Union_type(tp))
                desc = 'u';
 
-       be_emit_irprintf("\t.stabs\t\"%s:Tt%u=%c%d",
-               get_type_name(tp), type_num, desc, get_type_size_bytes(tp));
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_irprintf(":Tt%u=%c%d", type_num, desc, get_type_size_bytes(tp));
 
        for (i = 0, n = get_compound_n_members(tp); i < n; ++i) {
                ir_entity *ent = get_compound_member(tp, i);
@@ -451,7 +467,9 @@ static void gen_method_type(wenv_t *env, ir_type *tp) {
        }
        res_type_num = get_type_number(h, rtp);
 
-       be_emit_irprintf("\t.stabs\t\"%s:t%u=f%u", get_type_name(tp), type_num, res_type_num);
+       be_emit_cstring("\t.stabs\t\"");
+       emit_type_name(tp);
+       be_emit_irprintf(":t%u=f%u", type_num, res_type_num);
 
        /* handle more than one return type */
        for (i = 1; i < n; ++i) {
@@ -469,13 +487,13 @@ static void gen_method_type(wenv_t *env, ir_type *tp) {
  * type-walker: generate declaration for simple types,
  * put all other types on a wait queue
  */
-static void walk_type(type_or_ent *tore, void *ctx)
+static void walk_type(type_or_ent tore, void *ctx)
 {
        wenv_t *env = ctx;
        ir_type  *tp;
 
-       if (get_kind(tore) == k_type) {
-               tp = (ir_type *)tore;
+       if (is_type(tore.typ)) {
+               tp = tore.typ;
 
                /* ignore the unknown type */
                if (tp == firm_unknown_type)
@@ -643,7 +661,8 @@ static void stabs_set_dbg_info(dbg_handle *h, dbg_info *dbgi)
 /**
  * dump the stabs for a method begin
  */
-static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stack_layout_t *layout) {
+static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stack_layout_t *layout)
+{
        stabs_handle *h = (stabs_handle *)handle;
        ir_type      *mtp, *rtp;
        unsigned     type_num;
@@ -663,7 +682,7 @@ static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stac
        type_num = get_type_number(h, rtp);
        be_emit_irprintf("\t.stabs\t\"%s:%c%u\",%u,0,0,%s\n",
                get_entity_name(ent),
-               get_entity_visibility(ent) == visibility_external_visible ? 'F' : 'f',
+               get_entity_visibility(ent) == ir_visibility_local ? 'f' : 'F',
                type_num,
                N_FUN,
                get_entity_ld_name(ent));
@@ -775,20 +794,19 @@ static void stabs_variable(dbg_handle *handle, ir_entity *ent) {
        unsigned tp_num = get_type_number(h, get_entity_type(ent));
        char buf[1024];
 
-       if (get_entity_visibility(ent) == visibility_external_visible) {
-               /* 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);
-       } else { /* some kind of local */
-               ir_variability variability = get_entity_variability(ent);
+       if (get_entity_visibility(ent) == ir_visibility_local) {
+               /* some kind of local */
+               ir_linkage linkage = get_entity_linkage(ent);
                int kind = N_STSYM;
 
-               if (variability == variability_uninitialized)
-                       kind = N_LCSYM;
-               else if (variability == variability_constant)
+               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));
+       } 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);
        }
        buf[sizeof(buf) - 1] = '\0';
 
@@ -818,15 +836,10 @@ static const debug_ops stabs_ops = {
 
 /* Opens a stabs handler */
 dbg_handle *be_stabs_open(void) {
-       stabs_handle *h = xmalloc(sizeof(*h));
+       stabs_handle *h = XMALLOCZ(stabs_handle);
 
        h->base.ops     = &stabs_ops;
-       h->cur_ent      = NULL;
-       h->layout       = NULL;
-       h->next_type_nr = 0;
        h->type_map     = pmap_create_ex(64);
-       h->main_file    = NULL;
-       h->curr_file    = NULL;
 
        return &h->base;
 }