renamed some firm enum types to have the ir_ prefix
[libfirm] / ir / be / bestabs.c
1 /**
2  * Stabs support.
3  *
4  * @author Michael Beck
5  * @date   11.9.2006
6  * @cvsid  $Id$
7  */
8
9 #ifdef HAVE_CONFIG_H
10 # include "config.h"
11 #endif
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <assert.h>
16
17 #include "irprog.h"
18 #include "entity.h"
19 #include "irgraph.h"
20 #include "typewalk.h"
21 #include "tv.h"
22 #include "xmalloc.h"
23 #include "pmap.h"
24 #include "pdeq.h"
25 #include "irtools.h"
26 #include "obst.h"
27 #include "array.h"
28 #include "be_dbgout.h"
29 #include "beabi.h"
30
31 /* Non-Stab Symbol and Stab Symbol Types */
32 enum stabs_types {
33         N_UNDF    = 0x00,    /**< 0: Undefined symbol */
34         N_ABS     = 0x02,    /**< 2: File scope absolute symbol */
35         N_TEXT    = 0x04,    /**< 4: File scope text symbol */
36         N_DATA    = 0x06,    /**< 6: File scope data symbol */
37         N_BSS     = 0x08,    /**< 8: File scope BSS symbol */
38         N_INDR    = 0x0A,    /**< 10: Symbol is indirected to another symbol */
39         N_FN_SEQ  = 0x0C,    /**< 12: Same as N_FN, for Sequent compilers */
40         N_COMM    = 0x12,    /**< 18: Common--visible after shared library dynamic link */
41         N_SETA    = 0x14,    /**< 20: Absolute set element */
42         N_SETT    = 0x17,    /**< 23: Text segment set element */
43         N_SETD    = 0x18,    /**< 24: Data segment set element */
44         N_SETB    = 0x1A,    /**< 26: BSS segment set element */
45         N_SETV    = 0x1C,    /**< 28: Pointer to set vector */
46         N_WARNING = 0x1E,    /**< 30: Print a warning message during linking */
47         N_FN      = 0x1F,    /**< 31: File name of a `.o' file */
48         N_GSYM    = 0x20,    /**< 32: Global symbol */
49         N_FNAME   = 0x22,    /**< 34: Function name (for BSD Fortran) */
50         N_FUN     = 0x24,    /**< 36: Function name */
51         N_STSYM   = 0x26,    /**< 38: Data segment file-scope variable */
52         N_LCSYM   = 0x28,    /**< 40: BSS segment file-scope variable */
53         N_MAIN    = 0x2A,    /**< 42: Name of main routine */
54         N_ROSYM   = 0x2C,    /**< 44: Variable in .rodata section */
55         N_PC      = 0x30,    /**< 48: Global symbol (for Pascal) */
56         N_NSYMS   = 0x32,    /**< 50: Number of symbols (according to Ultrix V4.0) */
57         N_NOMAP   = 0x34,    /**< 52: No DST map */
58         N_OBJ     = 0x38,    /**< 56: Object file (Solaris2) */
59         N_OPT     = 0x3C,    /**< 60: Debugger options (Solaris2) */
60         N_RSYM    = 0x40,    /**< 64: Register variable */
61         N_M2C     = 0x42,    /**< 66: Modula-2 compilation unit */
62         N_SLINE   = 0x44,    /**< 68: Line number in text segment */
63         N_DSLINE  = 0x46,    /**< 70: Line number in data segment */
64         N_BSLINE  = 0x48,    /**< 72: Line number in bss segment */
65         N_BROWS   = 0x48,    /**< 72: Sun source code browser, path to `.cb' file */
66         N_DEFD    = 0x4A,    /**< 74: GNU Modula2 definition module dependency */
67         N_FLINE   = 0x4C,    /**< 76: Function start/body/end line numbers (Solaris2) */
68         N_EHDECL  = 0x50,    /**< 80: GNU C++ exception variable */
69         N_MOD2    = 0x50,    /**< 80: Modula2 info "for imc" (according to Ultrix V4.0) */
70         N_CATCH   = 0x54,    /**< 84: GNU C++ catch clause */
71         N_SSYM    = 0x60,    /**< 96: Structure of union element */
72         N_ENDM    = 0x62,    /**< 98: Last stab for module (Solaris2) */
73         N_SO      = 0x64,    /**< 100: Path and name of source file */
74         N_LSYM    = 0x80,    /**< 128: Stack variable */
75         N_BINCL   = 0x82,    /**< 130: Beginning of an include file (Sun only) */
76         N_SOL     = 0x84,    /**< 132: Name of include file */
77         N_PSYM    = 0xA0,    /**< 160: Parameter variable */
78         N_EINCL   = 0xA2,    /**< 162: End of an include file */
79         N_ENTRY   = 0xA4,    /**< 164: Alternate entry point */
80         N_LBRAC   = 0xC0,    /**< 192: Beginning of a lexical block */
81         N_EXCL    = 0xC2,    /**< 194: Place holder for a deleted include file */
82         N_SCOPE   = 0xC4,    /**< 196: Modula2 scope information (Sun linker) */
83         N_RBRAC   = 0xE0,    /**< 224: End of a lexical block */
84         N_BCOMM   = 0xE2,    /**< 226: Begin named common block */
85         N_ECOMM   = 0xE4,    /**< 228: End named common block */
86         N_ECOML   = 0xE8,    /**< 232: Member of a common block */
87         N_WITH    = 0xEA,    /**< 234: Pascal with statement: type,,0,0,offset (Solaris2) */
88         N_NBTEXT  = 0xF0,    /**< 240: Gould non-base registers */
89         N_NBDATA  = 0xF2,    /**< 242: Gould non-base registers */
90         N_NBBSS   = 0xF4,    /**< 244: Gould non-base registers */
91         N_NBSTS   = 0xF6,    /**< 246: Gould non-base registers */
92         N_NBLCS   = 0xF8,    /**< 248: Gould non-base registers */
93 };
94
95 /**
96  * The stabs handle.
97  */
98 typedef struct stabs_handle {
99         dbg_handle base;         /**< the base class */
100         FILE       *f;           /**< the file write to */
101         entity     *cur_ent;     /**< current method entity */
102         unsigned   next_type_nr; /**< next type number */
103         pmap       *type_map;    /**< a map from type to type number */
104 } stabs_handle;
105
106 /**
107  * Returns the stabs type number of a Firm type.
108  */
109 static unsigned get_type_number(stabs_handle *h, ir_type *tp) {
110         pmap_entry *entry;
111
112         if (tp == NULL) {
113                 /* map to the void type */
114                 return 0;
115         }
116         entry = pmap_find(h->type_map, tp);
117         return entry ? PTR_TO_INT(entry->value) : 0;
118 }  /* get_type_number */
119
120 /**
121  * Assign a stabs type number to a Firm type.
122  */
123 static unsigned assign_type_number(stabs_handle *h, ir_type *tp) {
124         unsigned num;
125         if (tp == NULL) {
126                 /* map to the void type */
127                 return 0;
128         }
129         num = h->next_type_nr++;
130         pmap_insert(h->type_map, tp, INT_TO_PTR(num));
131         return num;
132 }  /* assign_type_number */
133
134 /**
135  * generate the void type.
136  */
137 static void gen_void_type(stabs_handle *h) {
138         fprintf(h->f, "\t.stabs \"void:t%u=%u\",%d,0,0,0\n", 0, 0, N_LSYM);
139 }  /* gen_void_type */
140
141 typedef struct walker_env {
142         stabs_handle *h;
143         waitq        *wq;
144 } wenv_t;
145
146 /* a type is not ready: put it on the wait queue */
147 #define SET_TYPE_NOT_READY(wq, tp) \
148   do { \
149     set_type_link(tp, (void *)1);  \
150     waitq_put(wq, tp);              \
151   } while(0)
152
153 /* a the is ready */
154 #define SET_TYPE_READY(tp)     set_type_link(tp, NULL)
155
156 /* check whether a type is ready */
157 #define IS_TYPE_READY(tp)      (get_type_link(tp) == NULL)
158
159 #ifdef EXPLICITE_PTR_TYPES
160 #define SKIP_PTR(tp)  tp
161 #else
162 #define SKIP_PTR(tp)   (is_Pointer_type(tp) ? get_pointer_points_to_type(tp) : tp)
163 #endif
164
165 /**
166  * Generates a primitive type.
167  *
168  * @param h    the stabs handle
169  * @param tp   the type
170  */
171 static void gen_primitive_type(stabs_handle *h, ir_type *tp)
172 {
173         ir_mode *mode = get_type_mode(tp);
174         unsigned type_num;
175
176         if (mode == mode_T) {
177     /* jack and FirmJC compiler use mode_T for the void type.
178                 Ignore it here as it's name is remapped to "void". */
179                 return;
180         }  /* if */
181
182         if (0 && get_mode_size_bits(mode) & 7) {
183                 /* this is a bitfield type, ignore it */
184                 return;
185         }  /* if */
186
187         type_num = assign_type_number(h, tp);
188
189         if (mode_is_int(mode)) {
190                 char buf[64];
191                 fprintf(h->f, "\t.stabs \"%s:t%u=r%u;", get_type_name(tp), type_num, type_num);
192                 tarval_snprintf(buf, sizeof(buf), get_mode_min(mode));
193                 fprintf(h->f, "%s;", buf);
194                 tarval_snprintf(buf, sizeof(buf), get_mode_max(mode));
195                 fprintf(h->f, "%s;\",%d,0,0,0\n", buf, N_LSYM);
196         } else if (mode_is_float(mode)) {
197                 int size = get_type_size_bytes(tp);
198                 fprintf(h->f, "\t.stabs \"%s:t%u=r1;%d;0;\",%d,0,0,0\n", get_type_name(tp), type_num, size, N_LSYM);
199         }
200 }  /* gen_primitive_type */
201
202 /**
203  * Generates an enum type
204  *
205  * @param h    the stabs handle
206  * @param tp   the type
207  */
208 static void gen_enum_type(stabs_handle *h, ir_type *tp) {
209         unsigned type_num = assign_type_number(h, tp);
210         int i, n;
211
212         fprintf(h->f, "\t.stabs \"%s:T%u=e", get_type_name(tp), type_num);
213         for (i = 0, n = get_enumeration_n_enums(tp); i < n; ++i) {
214                 ir_enum_const *ec = get_enumeration_const(tp, i);
215                 char buf[64];
216
217                 tarval_snprintf(buf, sizeof(buf), get_enumeration_value(ec));
218                 fprintf(h->f, "%s:%s,", get_enumeration_name(ec), buf);
219         }
220         fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM);
221 }  /* gen_enum_type */
222
223 /**
224  * Generates a pointer type
225  *
226  * @param h    the stabs handle
227  * @param tp   the type
228  */
229 static void gen_pointer_type(stabs_handle *h, ir_type *tp) {
230         unsigned type_num = assign_type_number(h, tp);
231         unsigned el_num   = get_type_number(h, get_pointer_points_to_type(tp));
232
233         fprintf(h->f, "\t.stabs \"%s:t%u=*%u\",%d,0,0,0\n",
234                 get_type_name(tp), type_num, el_num, N_LSYM);
235 }  /* gen_pointer_type */
236
237 /**
238  * Generates a struct/union type
239  *
240  * @param h    the stabs handle
241  * @param tp   the type
242  */
243 static void gen_struct_union_type(stabs_handle *h, ir_type *tp) {
244         unsigned type_num = assign_type_number(h, tp);
245         int i, n;
246         char desc;
247
248         if (is_Struct_type(tp)) {
249                 desc = 's';
250                 if (get_type_mode(tp) != NULL) {
251                         /* this is a bitfield type, ignore it safely */
252                         return;
253                 }
254         }
255         else
256                 desc = 'u';
257
258         fprintf(h->f, "\t.stabs \"%s:T%u=%c%d",
259                 get_type_name(tp), type_num, desc, get_type_size_bytes(tp));
260
261         for (i = 0, n = get_compound_n_members(tp); i < n; ++i) {
262                 entity  *ent = get_compound_member(tp, i);
263                 ir_type *mtp = get_entity_type(ent);
264                 int ofs, size;
265
266                 ofs  = get_entity_offset_bits(ent);
267                 if (is_Struct_type(mtp) && get_type_mode(mtp) != NULL) {
268                         /* this structure is a bitfield, skip */
269                         int i, n;
270
271                         for (i = 0, n = get_struct_n_members(mtp); i < n; ++i) {
272                                 entity *ent = get_struct_member(mtp, i);
273                                 ir_type *tp = get_entity_type(ent);
274                                 int bofs;
275
276                                 type_num = get_type_number(h, tp);
277                                 size = get_type_size_bits(tp);
278                                 bofs = ofs + get_entity_offset_bits(ent);
279
280                                 /* name:type, bit offset from the start of the struct', number of bits in the element. */
281                                 fprintf(h->f, "%s:%u,%d,%d;", get_entity_name(ent), type_num, bofs, size);
282                         }
283                 } else {
284                         /* no bitfield */
285                         type_num = get_type_number(h, mtp);
286                         size = get_type_size_bits(mtp);
287
288                         /* name:type, bit offset from the start of the struct', number of bits in the element. */
289                         fprintf(h->f, "%s:%u,%d,%d;", get_entity_name(ent), type_num, ofs, size);
290                 }
291         }
292         fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM);
293 }  /* gen_struct_type */
294
295 /**
296  * Generates an array type
297  *
298  * @param h    the stabs handle
299  * @param tp   the type
300  */
301 static void gen_array_type(stabs_handle *h, ir_type *tp) {
302         unsigned type_num = assign_type_number(h, tp);
303         int i, n = get_array_n_dimensions(tp);
304         int *perm;
305         ir_type *etp;
306
307         NEW_ARR_A(int, perm, n);
308         for (i = 0; i < n; ++i) {
309                 perm[i] = get_array_order(tp, i);
310         }
311         fprintf(h->f, "\t.stabs \"%s:t%u=a", get_type_name(tp), type_num);
312
313         for (i = 0; i < n; ++i) {
314                 int dim = perm[i];
315                 long min = get_array_lower_bound_int(tp, dim);
316                 long max = get_array_upper_bound_int(tp, dim);
317
318                 /* FIXME r1 must be integer type, but seems to work for now */
319                 fprintf(h->f, "r1;%ld;%ld;", min, max-1);
320         }
321
322         etp = get_array_element_type(tp);
323         type_num = get_type_number(h, etp);
324         fprintf(h->f, "%d\",%d,0,0,0\n", type_num, N_LSYM);
325 }  /* gen_array_type */
326
327 /**
328  * Generates a method type
329  *
330  * @param h    the stabs handle
331  * @param tp   the type
332  */
333 static void gen_method_type(stabs_handle *h, ir_type *tp) {
334         unsigned type_num = assign_type_number(h, tp);
335         ir_type *rtp = NULL;
336         unsigned res_type_num;
337
338         if (get_method_n_ress(tp) > 0)
339                 rtp = get_method_res_type(tp, 0);
340         res_type_num = get_type_number(h, rtp);
341
342         fprintf(h->f, "\t.stabs \"%s:t%u=f%u\",%d,0,0,0\n",
343                 get_type_name(tp), type_num, res_type_num, N_LSYM);
344 }  /* gen_method_type */
345
346 /**
347  * type-walker: generate declaration for simple types,
348  * put all other types on a wait queue
349  */
350 static void walk_type(type_or_ent *tore, void *ctx)
351 {
352         wenv_t *env = ctx;
353         FILE *f = env->h->f;
354         entity   *ent;
355         ir_type  *tp;
356         ir_graph *irg;
357
358         if (get_kind(tore) == k_type) {
359                 tp = (ir_type *)tore;
360
361                 /* ignore the unknown type */
362                 if (tp == firm_unknown_type)
363                         return;
364         } else {
365                 return;
366         }  /* if */
367
368         switch (get_type_tpop_code(tp)) {
369         case tpo_class:
370                 if (tp == get_glob_type()) {
371                         SET_TYPE_READY(tp);
372                         break;
373                 }
374                 /* fall through */
375         case tpo_struct:
376         case tpo_union:
377                 SET_TYPE_NOT_READY(env->wq, tp);
378                 break;
379
380         case tpo_enumeration:
381                 gen_enum_type(env->h, tp);
382                 SET_TYPE_READY(tp);
383                 break;
384
385         case tpo_primitive:
386                 gen_primitive_type(env->h, tp);
387                 SET_TYPE_READY(tp);
388                 break;
389
390         case tpo_method:
391         case tpo_array:
392                 SET_TYPE_NOT_READY(env->wq, tp);
393                 break;
394
395         case tpo_pointer:
396                 /* must construct the pointer type */
397                 SET_TYPE_NOT_READY(env->wq, tp);
398                 break;
399
400         case tpo_unknown:
401                 /* the unknown type: ignore */
402                 break;
403         default:
404                 assert(! "Unknown tpop code");
405         }  /* switch */
406 }  /* walk_type */
407
408 /**
409  * check, if a method type can be generated
410  */
411 static int is_method_type_ready(ir_type *tp)
412 {
413   int i;
414   ir_type *etp;
415
416   for (i = get_method_n_ress(tp) - 1; i >= 0; --i) {
417     etp = SKIP_PTR(get_method_res_type(tp, i));
418
419     if (! IS_TYPE_READY(etp) && (! is_compound_type(etp) || is_Array_type(etp)))
420       return 0;
421   }  /* for */
422
423   for (i = get_method_n_params(tp) - 1; i >= 0; --i) {
424     etp = SKIP_PTR(get_method_param_type(tp, i));
425
426     if (! IS_TYPE_READY(etp) && (! is_compound_type(etp) || is_Array_type(etp)))
427       return 0;
428   }  /* for */
429   return 1;
430 }  /* is_method_type_ready */
431
432 /**
433  * check, whether a compound type can be generated
434  */
435 static int is_compound_type_ready(ir_type *tp)
436 {
437   int i;
438   ir_type *etp;
439
440   for (i = get_compound_n_members(tp) - 1; i >= 0; --i) {
441     etp = SKIP_PTR(get_entity_type(get_compound_member(tp, i)));
442
443     if (! IS_TYPE_READY(etp) && (! is_compound_type(etp) || is_Array_type(etp)))
444       return 0;
445   }  /* for */
446   return 1;
447 }  /* is_compound_type_ready */
448
449 /**
450  * generate declaration for all types
451  */
452 static void finish_types(stabs_handle *h, waitq *wq)
453 {
454   ir_type *tp;
455
456   while (! waitq_empty(wq)) {
457     tp = waitq_get(wq);
458
459     switch (get_type_tpop_code(tp)) {
460     case tpo_method:
461       if (is_method_type_ready(tp)) {
462         if (get_method_n_ress(tp) <= 1)
463           gen_method_type(h, tp);
464         else {
465           fprintf(stderr, "Warning: Cannot create stabs debug info for type %s\n", get_type_name(tp));
466         }  /* if */
467         SET_TYPE_READY(tp);
468         continue;
469       }  /* if */
470       break;
471     case tpo_class:
472     case tpo_union:
473     case tpo_struct:
474       if (is_compound_type_ready(tp)) {
475         gen_struct_union_type(h, tp);
476         SET_TYPE_READY(tp);
477         continue;
478       }  /* if */
479       break;
480     case tpo_array:
481       if (IS_TYPE_READY(get_array_element_type(tp))) {
482         gen_array_type(h, tp);
483         SET_TYPE_READY(tp);
484         continue;
485       }  /* if */
486       break;
487     case tpo_pointer:
488       if (IS_TYPE_READY(get_pointer_points_to_type(tp))) {
489         gen_pointer_type(h, tp);
490         SET_TYPE_READY(tp);
491         continue;
492       }  /* if */
493       break;
494     default:
495       assert(! "Unknown tpop code");
496     }  /* switch */
497
498     /* still not ready, defer type output */
499     pdeq_putr(wq, tp);
500   }  /* while */
501 }  /* finish_types */
502
503 /**
504  * generate all types.
505  */
506 static void gen_types(stabs_handle *h) {
507         wenv_t env;
508
509         env.h  = h;
510         env.wq = new_waitq();
511         type_walk(NULL, walk_type, &env);
512         finish_types(h, env.wq);
513         del_waitq(env.wq);
514 }  /* gen_types */
515
516
517 /* -------------------------- I/F ----------------------------- */
518
519 /**
520  * start a new source object (compilation unit)
521  */
522 static void stabs_so(dbg_handle *handle, const char *filename) {
523         stabs_handle *h = (stabs_handle *)handle;
524         fprintf(h->f, "\t.stabs \"%s\",%d,0,0,.Ltext0\n", filename, N_SO);
525 }  /* stabs_so */
526
527 /**
528  * Main Program
529  */
530 static void stabs_main_program(dbg_handle *handle) {
531         stabs_handle *h = (stabs_handle *)handle;
532         ir_graph *irg = get_irp_main_irg();
533         if (irg) {
534                 fprintf(h->f, "\t.stabs \"%s\",%d,0,0,0\n", get_entity_name(get_irg_entity(irg)), N_MAIN);
535         }
536 }  /* stabs_main_program */
537
538 /**
539  * prints a line number
540  */
541 static void stabs_line(dbg_handle *handle, unsigned lineno, const char *address) {
542         stabs_handle *h = (stabs_handle *)handle;
543         fprintf(h->f, ".stabn %d, 0, %u, %s-%s\n", N_SLINE, lineno, address, get_entity_ld_name(h->cur_ent));
544 }  /* stabs_line */
545
546 /**
547  * dump the stabs for a function
548  */
549 static void stabs_method(dbg_handle *handle, entity *ent, const be_stack_layout_t *layout) {
550         stabs_handle *h = (stabs_handle *)handle;
551         ir_type *mtp, *rtp;
552         unsigned type_num;
553         int i, n, between_size;
554
555         h->cur_ent = ent;
556
557         mtp = get_entity_type(ent);
558         if (is_lowered_type(mtp))
559                 mtp = get_associated_type(mtp);
560         if (get_method_n_ress(mtp) > 0)
561                 rtp = get_method_res_type(mtp, 0);
562         else
563                 rtp = NULL;
564         type_num = get_type_number(h, rtp);
565         fprintf(h->f, "\t.stabs \"%s:%c%u\",%u,0,0,%s\n",
566                 get_entity_name(ent),
567                 get_entity_visibility(ent) == visibility_external_visible ? 'F' : 'f',
568                 type_num,
569                 N_FUN,
570                 get_entity_ld_name(ent));
571
572         between_size = get_type_size_bytes(layout->between_type);
573         for (i = 0, n = get_method_n_params(mtp); i < n; ++i) {
574                 ir_type *ptp      = get_method_param_type(mtp, i);
575         const char *name  = get_method_param_name(mtp, i);
576                 unsigned type_num = get_type_number(h, ptp);
577         char buf[16];
578         int ofs = 0;
579                 entity *stack_ent;
580
581         if (! name) {
582           snprintf(buf, sizeof(buf), "arg%d", i);
583           name = buf;
584         }
585                 /* check if this parameter has a stack entity. If it has, it
586                    it transmitted on the stack, else in a register */
587                 stack_ent = layout->param_map[i];
588                 if (stack_ent) {
589                         ofs = get_entity_offset_bytes(stack_ent) + between_size;
590                 }
591                 fprintf(h->f, "\t.stabs \"%s:p%u\",%d,0,0,%d\n", name, type_num, N_PSYM, ofs);
592         }
593 }  /* stabs_method */
594
595 /**
596  * dump types
597  */
598 static void stabs_types(dbg_handle *handle) {
599         stabs_handle *h = (stabs_handle *)handle;
600
601         /* allocate the zero for the void type */
602         h->next_type_nr++;
603         gen_void_type(h);
604         gen_types(h);
605 }  /* stabs_types */
606
607 /**
608  * dump a global
609  */
610 static void stabs_global(dbg_handle *handle, struct obstack *obst, entity *ent) {
611         stabs_handle *h = (stabs_handle *)handle;
612         unsigned tp_num = get_type_number(h, get_entity_type(ent));
613
614         if (obst) {
615                 obstack_printf(obst, "\t.stabs \"%s:G%u\",%d,0,0,0\n",
616                         get_entity_name(ent), tp_num, N_GSYM);
617         } else {
618                 fprintf(h->f, "\t.stabs \"%s:G%u\",%d,0,0,0\n",
619                         get_entity_name(ent), tp_num, N_GSYM);
620         }
621 }  /* stabs_global */
622
623 /**
624  * Close the stabs handler.
625  */
626 static void stabs_close(dbg_handle *handle) {
627         stabs_handle *h = (stabs_handle *)handle;
628         pmap_destroy(h->type_map);
629         free(h);
630 }  /* stabs_close */
631
632 /** The stabs operations. */
633 static const debug_ops stabs_ops = {
634         stabs_close,
635         stabs_so,
636         stabs_main_program,
637         stabs_method,
638         stabs_line,
639         stabs_types,
640         stabs_global
641 };
642
643 /* Opens a stabs handler */
644 dbg_handle *be_stabs_open(FILE *out) {
645         stabs_handle *h = xmalloc(sizeof(*h));
646
647         h->base.ops     = &stabs_ops;
648         h->f            = out;
649         h->cur_ent      = NULL;
650         h->next_type_nr = 0;
651         h->type_map     = pmap_create_ex(64);
652         return &h->base;
653 }  /* stabs_open */
654
655 /** close a debug handler. */
656 void be_dbg_close(dbg_handle *h) {
657         if (h->ops->close)
658                 h->ops->close(h);
659 }  /* be_dbg_close */
660
661 /**
662  * start a new source object (compilation unit)
663  */
664 void be_dbg_so(dbg_handle *h, const char *filename) {
665         if (h->ops->so)
666                 h->ops->so(h, filename);
667 }  /* be_dbg_begin */
668
669 /**
670  * Main program
671  */
672 void be_dbg_main_program(dbg_handle *h) {
673         if (h->ops->main_program)
674                 h->ops->main_program(h);
675 }  /* be_dbg_main_program */
676
677 /** debug for a function */
678 void be_dbg_method(dbg_handle *h, entity *ent, const be_stack_layout_t *layout) {
679         if (h->ops->method)
680                 h->ops->method(h, ent, layout);
681 }  /* be_dbg_method */
682
683 /** debug for line number */
684 void be_dbg_line(dbg_handle *h, unsigned lineno, const char *address) {
685         if (h->ops->line)
686                 h->ops->line(h, lineno, address);
687 }  /* be_dbg_line */
688
689 /** dump types */
690 void be_dbg_types(dbg_handle *h) {
691         if (h->ops->types)
692                 h->ops->types(h);
693 }  /* be_dbg_types */
694
695 /** dump a global */
696 void be_dbg_global(dbg_handle *h, struct obstack *obst, entity *ent) {
697         if (h->ops->global)
698                 h->ops->global(h, obst, ent);
699 }  /* be_dbg_global */