X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbestabs.c;h=a5918840f6482500ddf6739b19a462ef28017f18;hb=5bb8cd35a8074112fa2da8b8f68d7c77918119e5;hp=ad44e66f0afdf5c1576856647114ddccb32bf677;hpb=b6d8cb4ac5f28bd50cb804f02df94712321ba246;p=libfirm diff --git a/ir/be/bestabs.c b/ir/be/bestabs.c index ad44e66f0..a5918840f 100644 --- a/ir/be/bestabs.c +++ b/ir/be/bestabs.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -24,9 +24,7 @@ * @date 11.9.2006 * @version $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #include #include @@ -41,9 +39,13 @@ #include "pdeq.h" #include "irtools.h" #include "obst.h" -#include "array.h" -#include "be_dbgout.h" +#include "array_t.h" +#include "be_dbgout_t.h" #include "beabi.h" +#include "bemodule.h" +#include "beemitter.h" +#include "dbginfo.h" +#include "begnuas.h" /* Non-Stab Symbol and Stab Symbol Types */ enum stabs_types { @@ -114,19 +116,21 @@ enum stabs_types { */ typedef struct stabs_handle { dbg_handle base; /**< the base class */ - FILE *f; /**< the file write to */ - ir_entity *cur_ent; /**< current method entity */ + const ir_entity *cur_ent; /**< current method entity */ const be_stack_layout_t *layout; /**< current stack layout */ unsigned next_type_nr; /**< next type number */ pmap *type_map; /**< a map from type to type number */ const char *main_file; /**< name of the main source file */ const char *curr_file; /**< name of the current source file */ + unsigned label_num; + unsigned last_line; } stabs_handle; /** * Returns the stabs type number of a Firm type. */ -static unsigned get_type_number(stabs_handle *h, ir_type *tp) { +static unsigned get_type_number(stabs_handle *h, ir_type *tp) +{ pmap_entry *entry; unsigned num; @@ -147,15 +151,19 @@ static unsigned get_type_number(stabs_handle *h, ir_type *tp) { /** * Map a given Type to void by assigned the type number 0. */ -static void map_to_void(stabs_handle *h, ir_type *tp) { +static void map_to_void(stabs_handle *h, ir_type *tp) +{ pmap_insert(h->type_map, tp, INT_TO_PTR(0)); } /** * generate the void type. */ -static void gen_void_type(stabs_handle *h) { - fprintf(h->f, "\t.stabs\t\"void:t%u=%u\",%d,0,0,0\n", 0, 0, N_LSYM); +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 { @@ -168,7 +176,7 @@ typedef struct walker_env { do { \ set_type_link(tp, (void *)1); \ waitq_put(wq, tp); \ - } while(0) + } while (0) /* a the is ready */ #define SET_TYPE_READY(tp) set_type_link(tp, NULL) @@ -182,13 +190,43 @@ typedef struct walker_env { #define SKIP_PTR(tp) (is_Pointer_type(tp) ? get_pointer_points_to_type(tp) : tp) #endif +/** + * mode_info for output as decimal + */ +static const tarval_mode_info dec_output = { + TVO_DECIMAL, + NULL, + NULL, +}; + +/** + * emit a tarval as decimal + */ +static void be_emit_tv_as_decimal(tarval *tv) +{ + ir_mode *mode = get_tarval_mode(tv); + const tarval_mode_info *old = get_tarval_mode_output_option(mode); + + set_tarval_mode_output_option(mode, &dec_output); + be_emit_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. * * @param h the stabs handle * @param tp the type */ -static void gen_primitive_type(stabs_handle *h, ir_type *tp) { +static void gen_primitive_type(stabs_handle *h, ir_type *tp) +{ ir_mode *mode = get_type_mode(tp); unsigned type_num; @@ -207,16 +245,21 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp) { type_num = get_type_number(h, tp); - if (mode_is_int(mode) || mode_is_character(mode)) { - char buf[64]; - fprintf(h->f, "\t.stabs\t\"%s:t%u=r%u;", get_type_name(tp), type_num, type_num); - tarval_snprintf(buf, sizeof(buf), get_mode_min(mode)); - fprintf(h->f, "%s;", buf); - tarval_snprintf(buf, sizeof(buf), get_mode_max(mode)); - fprintf(h->f, "%s;\",%d,0,0,0\n", buf, N_LSYM); + if (mode_is_int(mode)) { + 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)); + be_emit_irprintf(";\",%d,0,0,0\n", N_LSYM); + be_emit_write_line(); } else if (mode_is_float(mode)) { int size = get_type_size_bytes(tp); - fprintf(h->f, "\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 */ @@ -226,32 +269,36 @@ static void gen_primitive_type(stabs_handle *h, ir_type *tp) { * @param h the stabs handle * @param tp the type */ -static void gen_enum_type(stabs_handle *h, ir_type *tp) { +static void gen_enum_type(stabs_handle *h, ir_type *tp) +{ unsigned type_num = get_type_number(h, tp); int i, n; SET_TYPE_READY(tp); - fprintf(h->f, "\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)); - fprintf(h->f, "%s:%s,", get_enumeration_name(ec), buf); + be_emit_irprintf("%s:%s,", get_enumeration_const_name(ec), buf); } - fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM); + be_emit_irprintf(";\",%d,0,0,0\n", N_LSYM); + be_emit_write_line(); } /* gen_enum_type */ /** * print a pointer type */ -void print_pointer_type(wenv_t *env, ir_type *tp, int local) { - stabs_handle *h = env->h; +static void print_pointer_type(stabs_handle *h, ir_type *tp, int local) +{ unsigned type_num = local ? h->next_type_nr++ : get_type_number(h, tp); ir_type *el_tp = get_pointer_points_to_type(tp); unsigned el_num = get_type_number(h, el_tp); - fprintf(h->f, "%u=*%u", type_num, el_num); + be_emit_irprintf("%u=*%u", type_num, el_num); } /** @@ -260,7 +307,8 @@ void print_pointer_type(wenv_t *env, ir_type *tp, int local) { * @param env the walker environment * @param tp the type */ -static void gen_pointer_type(wenv_t *env, ir_type *tp) { +static void gen_pointer_type(wenv_t *env, ir_type *tp) +{ stabs_handle *h = env->h; ir_type *el_tp = get_pointer_points_to_type(tp); @@ -268,22 +316,25 @@ static void gen_pointer_type(wenv_t *env, ir_type *tp) { if (! IS_TYPE_READY(el_tp)) waitq_put(env->wq, el_tp); - fprintf(h->f, "\t.stabs\t\"%s:t", get_type_name(tp)); - print_pointer_type(env, tp, 0); - fprintf(h->f, "\",%d,0,0,0\n", N_LSYM); + 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(); } /* gen_pointer_type */ /** * print an array type */ -static void print_array_type(wenv_t *env, ir_type *tp, int local) { - stabs_handle *h = env->h; +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); unsigned type_num = local ? h->next_type_nr++ : get_type_number(h, tp); int *perm; - fprintf(h->f, "%u=a", type_num); + be_emit_irprintf("%u=a", type_num); NEW_ARR_A(int, perm, n); for (i = 0; i < n; ++i) { perm[i] = get_array_order(tp, i); @@ -297,12 +348,12 @@ static void print_array_type(wenv_t *env, ir_type *tp, int local) { long max = get_array_upper_bound_int(tp, dim); /* FIXME r1 must be integer type, but seems to work for now */ - fprintf(h->f, "r1;%ld;%ld;", min, max-1); + be_emit_irprintf("r1;%ld;%ld;", min, max-1); } } type_num = get_type_number(h, etp); - fprintf(h->f, "%d", type_num); + be_emit_irprintf("%d", type_num); } /** @@ -311,19 +362,23 @@ static void print_array_type(wenv_t *env, ir_type *tp, int local) { * @param env the walker environment * @param tp the type */ -static void gen_array_type(wenv_t *env, ir_type *tp) { - stabs_handle *h = env->h; +static void gen_array_type(wenv_t *env, ir_type *tp) +{ + stabs_handle *h = env->h; ir_type *etp = get_array_element_type(tp); SET_TYPE_READY(tp); if (! IS_TYPE_READY(etp)) waitq_put(env->wq, etp); - fprintf(h->f, "\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(env, tp, 0); + print_array_type(h, tp, 0); - fprintf(h->f, "\",%d,0,0,0\n", N_LSYM); + be_emit_irprintf("\",%d,0,0,0\n", N_LSYM); + be_emit_write_line(); } /* gen_array_type */ /** @@ -332,7 +387,8 @@ static void gen_array_type(wenv_t *env, ir_type *tp) { * @param env the walker environment * @param tp the type */ -static void gen_struct_union_type(wenv_t *env, ir_type *tp) { +static void gen_struct_union_type(wenv_t *env, ir_type *tp) +{ stabs_handle *h = env->h; unsigned type_num = get_type_number(h, tp); int i, n; @@ -349,13 +405,15 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) { else if (is_Union_type(tp)) desc = 'u'; - fprintf(h->f, "\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); ir_type *mtp = get_entity_type(ent); - int ofs, size; + int ofs; + unsigned size; if (! IS_TYPE_READY(mtp)) waitq_put(env->wq, mtp); @@ -370,33 +428,34 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) { int bofs; type_num = get_type_number(h, tp); - size = get_type_size_bits(tp); + size = get_type_size_bytes(tp) * 8; bofs = (ofs + get_entity_offset(ent)) * 8 + get_entity_offset_bits_remainder(ent); /* name:type, bit offset from the start of the struct', number of bits in the element. */ - fprintf(h->f, "%s:%u,%d,%d;", get_entity_name(ent), type_num, bofs, size); + be_emit_irprintf("%s:%u,%d,%u;", get_entity_name(ent), type_num, bofs, size); } } else { /* no bitfield */ - fprintf(h->f, "%s:", get_entity_name(ent)); + be_emit_irprintf("%s:", get_entity_name(ent)); if (is_Array_type(mtp)) { /* use a local array definition */ - print_array_type(env, mtp, 1); + print_array_type(h, mtp, 1); } else if (is_Pointer_type(mtp)) { /* use local pointer definition */ - print_pointer_type(env, mtp, 1); + print_pointer_type(h, mtp, 1); } else { type_num = get_type_number(h, mtp); /* name:type, bit offset from the start of the struct', number of bits in the element. */ - fprintf(h->f, "%u", type_num); + be_emit_irprintf("%u", type_num); } - size = get_type_size_bits(mtp); - fprintf(h->f, ",%d,%d;", ofs * 8, size); + size = get_type_size_bytes(mtp) * 8; + be_emit_irprintf(",%d,%u;", ofs * 8, size); } } - fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM); + be_emit_irprintf(";\",%d,0,0,0\n", N_LSYM); + be_emit_write_line(); } /* gen_struct_type */ /** @@ -405,7 +464,8 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) { * @param env the walker environment * @param tp the type */ -static void gen_method_type(wenv_t *env, ir_type *tp) { +static void gen_method_type(wenv_t *env, ir_type *tp) +{ stabs_handle *h = env->h; unsigned type_num = get_type_number(h, tp); ir_type *rtp = NULL; @@ -420,7 +480,9 @@ static void gen_method_type(wenv_t *env, ir_type *tp) { } res_type_num = get_type_number(h, rtp); - fprintf(h->f, "\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) { @@ -428,22 +490,23 @@ static void gen_method_type(wenv_t *env, ir_type *tp) { if (! IS_TYPE_READY(rtp)) waitq_put(env->wq, rtp); res_type_num = get_type_number(h, rtp); - fprintf(h->f, ",%u", res_type_num); + be_emit_irprintf(",%u", res_type_num); } - fprintf(h->f, "\",%d,0,0,0\n", N_LSYM); + be_emit_irprintf("\",%d,0,0,0\n", N_LSYM); + be_emit_write_line(); } /* gen_method_type */ /** * 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) @@ -540,7 +603,8 @@ static void finish_types(wenv_t *env) /** * generate all types. */ -static void gen_types(stabs_handle *h) { +static void gen_types(stabs_handle *h) +{ wenv_t env; env.h = h; @@ -556,54 +620,65 @@ static void gen_types(stabs_handle *h) { /** * start a new source object (compilation unit) */ -static void stabs_so(dbg_handle *handle, const char *filename) { +static void stabs_so(dbg_handle *handle, const char *filename) +{ stabs_handle *h = (stabs_handle *)handle; h->main_file = h->curr_file = filename; - fprintf(h->f, "\t.stabs\t\"%s\",%d,0,0,.Ltext0\n", filename, N_SO); + be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,%stext0\n", filename, N_SO, be_gas_get_private_prefix()); + be_emit_write_line(); } /* stabs_so */ -/** - * end an include file - */ -static void stabs_include_end(dbg_handle *handle) { - stabs_handle *h = (stabs_handle *)handle; - h->curr_file = h->main_file; -} /* stabs_include_end */ - -/** - * start an include file - */ -static void stabs_include_begin(dbg_handle *handle, const char *filename) { - stabs_handle *h = (stabs_handle *)handle; - if (h->main_file != h->curr_file) - stabs_include_end(handle); - h->curr_file = filename; - fprintf(h->f, "\t.stabs\t\"%s\",%d,0,0,0\n", filename, N_SOL); -} /* stabs_include_begin */ - /** * Main Program */ -static void stabs_main_program(dbg_handle *handle) { - stabs_handle *h = (stabs_handle *)handle; +static void stabs_main_program(dbg_handle *handle) +{ ir_graph *irg = get_irp_main_irg(); + + (void) handle; if (irg) { - fprintf(h->f, "\t.stabs\t\"%s\",%d,0,0,0\n", get_entity_name(get_irg_entity(irg)), N_MAIN); + be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,0\n", get_entity_name(get_irg_entity(irg)), N_MAIN); + be_emit_write_line(); } } /* stabs_main_program */ -/** - * prints a line number - */ -static void stabs_line(dbg_handle *handle, unsigned lineno, const char *address) { - stabs_handle *h = (stabs_handle *)handle; - fprintf(h->f, "\t.stabn\t%d, 0, %u, %s-%s\n", N_SLINE, lineno, address, get_entity_ld_name(h->cur_ent)); -} /* stabs_line */ +static void stabs_set_dbg_info(dbg_handle *h, dbg_info *dbgi) +{ + stabs_handle *handle = (stabs_handle*) h; + unsigned lineno; + const char *fname = ir_retrieve_dbg_info(dbgi, &lineno); + + if (fname == NULL) + return; + + if (handle->curr_file != fname) { + if (fname != handle->main_file) { + be_emit_irprintf("\t.stabs\t\"%s\",%d,0,0,0\n", fname, N_SOL); + be_emit_write_line(); + } + handle->curr_file = fname; + } + if (handle->last_line != lineno) { + char label[64]; + + snprintf(label, sizeof(label), ".LM%u", ++handle->label_num); + handle->last_line = lineno; + + be_emit_irprintf("\t.stabn\t%d, 0, %u, %s-%s\n", N_SLINE, lineno, + label, get_entity_ld_name(handle->cur_ent)); + be_emit_write_line(); + + be_emit_string(label); + be_emit_cstring(":\n"); + be_emit_write_line(); + } +} /** * 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, const ir_entity *ent, const be_stack_layout_t *layout) +{ stabs_handle *h = (stabs_handle *)handle; ir_type *mtp, *rtp; unsigned type_num; @@ -621,12 +696,13 @@ static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stac else rtp = NULL; type_num = get_type_number(h, rtp); - fprintf(h->f, "\t.stabs\t\"%s:%c%u\",%u,0,0,%s\n", + 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)); + be_emit_write_line(); /* create parameter entries */ between_size = get_type_size_bytes(layout->between_type); @@ -648,16 +724,32 @@ static void stabs_method_begin(dbg_handle *handle, ir_entity *ent, const be_stac if (stack_ent) { ofs = get_entity_offset(stack_ent) + between_size; } - fprintf(h->f, "\t.stabs\t\"%s:p%u\",%d,0,0,%d\n", name, type_num, N_PSYM, ofs); + be_emit_irprintf("\t.stabs\t\"%s:p", name); + if (is_Array_type(ptp)) { + /* use a local array definition */ + print_array_type(h, ptp, 1); + } else if (is_Pointer_type(ptp)) { + /* use local pointer definition */ + print_pointer_type(h, ptp, 1); + } else { + type_num = get_type_number(h, ptp); + + /* name:type, bit offset from the start of the struct', number of bits in the element. */ + be_emit_irprintf("%u", type_num); + } + + 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 */ -static void stabs_method_end(dbg_handle *handle) { +static void stabs_method_end(dbg_handle *handle) +{ stabs_handle *h = (stabs_handle *)handle; - ir_entity *ent = h->cur_ent; + const ir_entity *ent = h->cur_ent; const be_stack_layout_t *layout = h->layout; const char *ld_name = get_entity_ld_name(ent); int i, n, frame_size; @@ -682,13 +774,17 @@ static void stabs_method_end(dbg_handle *handle) { type_num = get_type_number(h, tp); ofs = -frame_size + get_entity_offset(ent); - fprintf(h->f, "\t.stabs\t\"%s:%u\",%d,0,0,%d\n", + be_emit_irprintf("\t.stabs\t\"%s:%u\",%d,0,0,%d\n", get_entity_name(ent), type_num, N_LSYM, ofs); + be_emit_write_line(); } /* we need a lexical block here */ - fprintf(h->f, "\t.stabn\t%d,0,0,%s-%s\n", N_LBRAC, ld_name, ld_name); - fprintf(h->f, "\t.stabn\t%d,0,0,.Lscope%u-%s\n", N_RBRAC, scope_nr, ld_name); - fprintf(h->f, ".Lscope%u:\n", scope_nr); + be_emit_irprintf("\t.stabn\t%d,0,0,%s-%s\n", N_LBRAC, ld_name, ld_name); + be_emit_write_line(); + be_emit_irprintf("\t.stabn\t%d,0,0,.Lscope%u-%s\n", N_RBRAC, scope_nr, ld_name); + be_emit_write_line(); + be_emit_irprintf(".Lscope%u:\n", scope_nr); + be_emit_write_line(); ++scope_nr; h->cur_ent = NULL; @@ -698,7 +794,8 @@ static void stabs_method_end(dbg_handle *handle) { /** * dump types */ -static void stabs_types(dbg_handle *handle) { +static void stabs_types(dbg_handle *handle) +{ stabs_handle *h = (stabs_handle *)handle; /* allocate the zero for the void type */ @@ -710,38 +807,36 @@ static void stabs_types(dbg_handle *handle) { /** * dump a variable in the global type */ -static void stabs_variable(dbg_handle *handle, struct obstack *obst, ir_entity *ent) { +static void stabs_variable(dbg_handle *handle, const ir_entity *ent) +{ stabs_handle *h = (stabs_handle *)handle; 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'; - if (obst) - obstack_printf(obst, "%s", buf); - else - fprintf(h->f, "%s", buf); + be_emit_string(buf); } /* stabs_variable */ /** * Close the stabs handler. */ -static void stabs_close(dbg_handle *handle) { +static void stabs_close(dbg_handle *handle) +{ stabs_handle *h = (stabs_handle *)handle; pmap_destroy(h->type_map); free(h); @@ -751,101 +846,27 @@ static void stabs_close(dbg_handle *handle) { static const debug_ops stabs_ops = { stabs_close, stabs_so, - stabs_include_begin, - stabs_include_end, stabs_main_program, stabs_method_begin, stabs_method_end, - stabs_line, stabs_types, - stabs_variable + stabs_variable, + stabs_set_dbg_info }; -/* Opens the NULL handler */ -dbg_handle *be_nulldbg_open(void) { - return NULL; -} /* be_nulldbg_open */ - /* Opens a stabs handler */ -dbg_handle *be_stabs_open(FILE *out) { - stabs_handle *h = xmalloc(sizeof(*h)); +static dbg_handle *be_stabs_open(void) +{ + stabs_handle *h = XMALLOCZ(stabs_handle); h->base.ops = &stabs_ops; - h->f = out; - 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; -} /* stabs_open */ - -/** close a debug handler. */ -void be_dbg_close(dbg_handle *h) { - if (h && h->ops->close) - h->ops->close(h); -} /* be_dbg_close */ - -/** - * start a new source object (compilation unit) - */ -void be_dbg_so(dbg_handle *h, const char *filename) { - if (h && h->ops->so) - h->ops->so(h, filename); -} /* be_dbg_begin */ - -/** - * start an include file - */ -void be_dbg_include_begin(dbg_handle *h, const char *filename) { - if (h && h->ops->include_begin) - h->ops->include_begin(h, filename); -} /* stabs_include_begin */ - -/** - * end an include file - */ -void be_dbg_include_end(dbg_handle *h) { - if (h && h->ops->include_end) - h->ops->include_end(h); -} /* stabs_include_end */ +} -/** - * Main program - */ -void be_dbg_main_program(dbg_handle *h) { - if (h && h->ops->main_program) - h->ops->main_program(h); -} /* be_dbg_main_program */ - -/** debug for a method begin */ -void be_dbg_method_begin(dbg_handle *h, ir_entity *ent, const be_stack_layout_t *layout) { - if (h && h->ops->method_begin) - h->ops->method_begin(h, ent, layout); -} /* be_dbg_method_begin */ - -/** debug for a method end */ -void be_dbg_method_end(dbg_handle *h) { - if (h && h->ops->method_end) - h->ops->method_end(h); -} /* be_dbg_method_end */ - -/** debug for line number */ -void be_dbg_line(dbg_handle *h, unsigned lineno, const char *address) { - if (h && h->ops->line) - h->ops->line(h, lineno, address); -} /* be_dbg_line */ - -/** dump types */ -void be_dbg_types(dbg_handle *h) { - if (h && h->ops->types) - h->ops->types(h); -} /* be_dbg_types */ - -/** dump a global */ -void be_dbg_variable(dbg_handle *h, struct obstack *obst, ir_entity *ent) { - if (h && h->ops->variable) - h->ops->variable(h, obst, ent); -} /* be_dbg_variable */ +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_stabs); +void be_init_stabs(void) +{ + be_register_dbgout_module("stabs", be_stabs_open); +}