OSDN Git Service

1341ed712ddadc264b1690a032acfb130e5f4b0c
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2out.c
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2    Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
3    Contributed by Gary Funck (gary@intrepid.com).  Derived from the
4    DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com).
5    Extensively modified by Jason Merrill (jason@cygnus.com).
6
7 This file is part of GNU CC.
8
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
22
23 #include "config.h"
24
25 #ifdef DWARF2_DEBUGGING_INFO
26 #include <stdio.h>
27 #include <setjmp.h>
28 #include "dwarf2.h"
29 #include "tree.h"
30 #include "flags.h"
31 #include "rtl.h"
32 #include "hard-reg-set.h"
33 #include "regs.h"
34 #include "insn-config.h"
35 #include "reload.h"
36 #include "output.h"
37 #include "defaults.h"
38 #include "expr.h"
39
40 /* #define NDEBUG 1 */
41 #include "assert.h"
42
43 extern char *getpwd ();
44
45 /* NOTE: In the comments in this file, many references are made to
46    "Debugging Information Entries".  This term is abbreviated as `DIE'
47    throughout the remainder of this file.  */
48
49 #ifndef __GNUC__
50 #define inline
51 #endif
52
53 /* An internal representation of the DWARF output is built, and then
54    walked to generate the DWARF debugging info.  The walk of the internal
55    representation is done after the entire program has been compiled.
56    The types below are used to describe the internal representation.  */
57
58 /* Each DIE may have a series of attribute/value pairs.  Values
59    can take on several forms.  The forms that are used in this
60    implementation are listed below.  */
61
62 typedef enum
63 {
64   dw_val_class_addr,
65   dw_val_class_loc,
66   dw_val_class_const,
67   dw_val_class_unsigned_const,
68   dw_val_class_long_long,
69   dw_val_class_float,
70   dw_val_class_flag,
71   dw_val_class_die_ref,
72   dw_val_class_fde_ref,
73   dw_val_class_lbl_id,
74   dw_val_class_section_offset,
75   dw_val_class_str
76 }
77 dw_val_class;
78
79 /* Various DIE's use offsets relative to the beginning of the
80    .debug_info section to refer to each other.  */
81
82 typedef long int dw_offset;
83
84 /* Define typedefs here to avoid circular dependencies.  */
85
86 typedef struct die_struct *dw_die_ref;
87 typedef struct dw_attr_struct *dw_attr_ref;
88 typedef struct dw_val_struct *dw_val_ref;
89 typedef struct dw_line_info_struct *dw_line_info_ref;
90 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
91 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
92 typedef struct dw_cfi_struct *dw_cfi_ref;
93 typedef struct dw_fde_struct *dw_fde_ref;
94 typedef union  dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
95 typedef struct pubname_struct *pubname_ref;
96 typedef dw_die_ref *arange_ref;
97
98 /* Describe a double word constant value.  */
99
100 typedef struct dw_long_long_struct
101 {
102   unsigned long hi;
103   unsigned long low;
104 }
105 dw_long_long_const;
106
107 /* Describe a floating point constant value.  */
108
109 typedef struct dw_fp_struct
110 {
111   long *array;
112   unsigned length;
113 }
114 dw_float_const;
115
116 /* Each entry in the line_info_table maintains the file and
117    line nuber associated with the label generated for that
118    entry.  The label gives the PC value associated with
119    the line number entry.  */
120
121 typedef struct dw_line_info_struct
122 {
123   unsigned long dw_file_num;
124   unsigned long dw_line_num;
125 }
126 dw_line_info_entry;
127
128 /* Line information for functions in separate sections; each one gets its
129    own sequence.  */
130 typedef struct dw_separate_line_info_struct
131 {
132   unsigned long dw_file_num;
133   unsigned long dw_line_num;
134   unsigned long function;
135 }
136 dw_separate_line_info_entry;
137
138 /* The dw_val_node describes an attibute's value, as it is
139    represented internally.  */
140
141 typedef struct dw_val_struct
142 {
143   dw_val_class val_class;
144   union
145     {
146       char *val_addr;
147       dw_loc_descr_ref val_loc;
148       long int val_int;
149       long unsigned val_unsigned;
150       dw_long_long_const val_long_long;
151       dw_float_const val_float;
152       dw_die_ref val_die_ref;
153       unsigned val_fde_index;
154       char *val_str;
155       char *val_lbl_id;
156       char *val_section;
157       unsigned char val_flag;
158     }
159   v;
160 }
161 dw_val_node;
162
163 /* Locations in memory are described using a sequence of stack machine
164    operations.  */
165
166 typedef struct dw_loc_descr_struct
167 {
168   dw_loc_descr_ref dw_loc_next;
169   enum dwarf_location_atom dw_loc_opc;
170   dw_val_node dw_loc_oprnd1;
171   dw_val_node dw_loc_oprnd2;
172 }
173 dw_loc_descr_node;
174
175 /* Each DIE attribute has a field specifying the attribute kind,
176    a link to the next attribute in the chain, and an attribute value.
177    Attributes are typically linked below the DIE they modify.  */
178
179 typedef struct dw_attr_struct
180 {
181   enum dwarf_attribute dw_attr;
182   dw_attr_ref dw_attr_next;
183   dw_val_node dw_attr_val;
184 }
185 dw_attr_node;
186
187 /* Call frames are described using a sequence of Call Frame
188    Information instructions.  The register number, offset
189    and address fields are provided as possible operands;
190    their use is selected by the opcode field.  */
191
192 typedef union dw_cfi_oprnd_struct
193 {
194   unsigned long dw_cfi_reg_num;
195   long int dw_cfi_offset;
196   char *dw_cfi_addr;
197 }
198 dw_cfi_oprnd;
199
200 typedef struct dw_cfi_struct
201 {
202   dw_cfi_ref dw_cfi_next;
203   enum dwarf_call_frame_info dw_cfi_opc;
204   dw_cfi_oprnd dw_cfi_oprnd1;
205   dw_cfi_oprnd dw_cfi_oprnd2;
206 }
207 dw_cfi_node;
208
209 /* All call frame descriptions (FDE's) in the GCC generated DWARF
210    refer to a single Common Information Entry (CIE), defined at
211    the beginning of the .debug_frame section.  This used of a single
212    CIE obviates the need to keep track of multiple CIE's
213    in the DWARF generation routines below.  */
214
215 typedef struct dw_fde_struct
216 {
217   unsigned long dw_fde_offset;
218   char *dw_fde_begin;
219   char *dw_fde_current_label;
220   char *dw_fde_end;
221   dw_cfi_ref dw_fde_cfi;
222 }
223 dw_fde_node;
224
225 /* The Debugging Information Entry (DIE) structure */
226
227 typedef struct die_struct
228 {
229   enum dwarf_tag die_tag;
230   dw_attr_ref die_attr;
231   dw_attr_ref die_attr_last;
232   dw_die_ref die_parent;
233   dw_die_ref die_child;
234   dw_die_ref die_child_last;
235   dw_die_ref die_sib;
236   dw_offset die_offset;
237   unsigned long die_abbrev;
238 }
239 die_node;
240
241 /* The pubname structure */
242
243 typedef struct pubname_struct
244 {
245   dw_die_ref die;
246   char * name;
247 }
248 pubname_entry;
249
250 /* How to start an assembler comment.  */
251 #ifndef ASM_COMMENT_START
252 #define ASM_COMMENT_START ";#"
253 #endif
254
255 /* Define a macro which returns non-zero for a TYPE_DECL which was
256    implicitly generated for a tagged type.
257
258    Note that unlike the gcc front end (which generates a NULL named
259    TYPE_DECL node for each complete tagged type, each array type, and
260    each function type node created) the g++ front end generates a
261    _named_ TYPE_DECL node for each tagged type node created.
262    These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
263    generate a DW_TAG_typedef DIE for them.  */
264
265 #define TYPE_DECL_IS_STUB(decl)                         \
266   (DECL_NAME (decl) == NULL_TREE                        \
267    || (DECL_ARTIFICIAL (decl)                           \
268        && is_tagged_type (TREE_TYPE (decl))             \
269        && decl == TYPE_STUB_DECL (TREE_TYPE (decl))))
270
271 /* Information concerning the compilation unit's programming
272    language, and compiler version.  */
273
274 extern int flag_traditional;
275 extern char *version_string;
276 extern char *language_string;
277
278 /* Maximum size (in bytes) of an artificially generated label.   */
279 #define MAX_ARTIFICIAL_LABEL_BYTES      30
280
281 /* Make sure we know the sizes of the various types dwarf can describe. These
282    are only defaults.  If the sizes are different for your target, you should
283    override these values by defining the appropriate symbols in your tm.h
284    file.  */
285
286 #ifndef CHAR_TYPE_SIZE
287 #define CHAR_TYPE_SIZE BITS_PER_UNIT
288 #endif
289 #ifndef PTR_SIZE
290 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
291 #endif
292
293 /* The size in bytes of a DWARF field indicating an offset or length
294    relative to a debug info section, specified to be 4 bytes in the DWARF-2
295    specification.  The SGI/MIPS ABI defines it to be the same as PTR_SIZE.  */
296
297 #ifndef DWARF_OFFSET_SIZE
298 #define DWARF_OFFSET_SIZE 4
299 #endif
300
301 #define DWARF_VERSION 2
302
303 /* Fixed size portion of the DWARF compilation unit header.  */
304 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
305
306 /* Fixed size portion of debugging line information prolog.  */
307 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
308
309 /* Fixed size portion of public names info.  */
310 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
311
312 /* Round SIZE up to the nearest BOUNDARY.  */
313 #define DWARF_ROUND(SIZE,BOUNDARY) \
314   (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
315
316 /* Fixed size portion of the address range info.  */
317 #define DWARF_ARANGES_HEADER_SIZE \
318   (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
319
320 /* Fixed size portion of the CIE (including the length field).  */
321 #define DWARF_CIE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 5)
322
323 /* The un-padded size of the CIE.  Initialized in calc_fde_sizes, used
324    in output_call_frame_info.  */
325 static unsigned cie_size;
326
327 /* Offsets recorded in opcodes are a multiple of this alignment factor.  */
328 #ifdef STACK_GROWS_DOWNWARD
329 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
330 #else
331 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
332 #endif
333
334 /* Fixed size portion of the FDE.  */
335 #define DWARF_FDE_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2 * PTR_SIZE)
336
337 /* Define the architecture-dependent minimum instruction length (in bytes).
338    In this implementation of DWARF, this field is used for information
339    purposes only.  Since GCC generates assembly language, we have
340    no a priori knowledge of how many instruction bytes are generated
341    for each source line, and therefore can use only the  DW_LNE_set_address
342    and DW_LNS_fixed_advance_pc line information commands.  */
343
344 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
345 #define DWARF_LINE_MIN_INSTR_LENGTH 4
346 #endif
347
348 /* Minimum line offset in a special line info. opcode.
349    This value was chosen to give a reasonable range of values.  */
350 #define DWARF_LINE_BASE  -10
351
352 /* First special line opcde - leave room for the standard opcodes.  */
353 #define DWARF_LINE_OPCODE_BASE  10
354
355 /* Range of line offsets in a special line info. opcode.  */
356 #define DWARF_LINE_RANGE  (254-DWARF_LINE_OPCODE_BASE+1)
357
358 /* Flag that indicates the initial value of the is_stmt_start flag.
359    In the present implementation, we do not mark any lines as
360    the beginning of a source statement, because that information
361    is not made available by the GCC front-end.  */
362 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
363
364 /* This location is used by calc_die_sizes() to keep track
365    the offset of each DIE within the .debug_info section.  */
366 static unsigned long next_die_offset;
367
368 /* This location is used by calc_fde_sizes() to keep track
369    the offset of each FDE within the .debug_frame section.  */
370 static unsigned long next_fde_offset;
371
372 /* Record the root of the DIE's built for the current compilation unit.  */
373 static dw_die_ref comp_unit_die;
374
375 /* The number of DIEs with a NULL parent waiting to be relocated.  */
376 static int limbo_die_count;
377
378 /* Pointer to an array of filenames referenced by this compilation unit.  */
379 static char **file_table;
380
381 /* Total number of entries in the table (i.e. array) pointed to by
382    `file_table'.  This is the *total* and includes both used and unused
383    slots.  */
384 static unsigned file_table_allocated;
385
386 /* Number of entries in the file_table which are actually in use.  */
387 static unsigned file_table_in_use;
388
389 /* Size (in elements) of increments by which we may expand the filename
390    table.  */
391 #define FILE_TABLE_INCREMENT 64
392
393 /* Local pointer to the name of the main input file.  Initialized in
394    dwarf2out_init.  */
395 static char *primary_filename;
396
397 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
398    which their beginnings are encountered. We output Dwarf debugging info
399    that refers to the beginnings and ends of the ranges of code for each
400    lexical block.  The labels themselves are generated in final.c, which
401    assigns numbers to the blocks in the same way.  */
402 static unsigned next_block_number = 2;
403
404 /* A pointer to the base of a table of references to DIE's that describe
405    declarations.  The table is indexed by DECL_UID() which is a unique
406    number, indentifying each decl.  */
407 static dw_die_ref *decl_die_table;
408
409 /* Number of elements currently allocated for the decl_die_table.  */
410 static unsigned decl_die_table_allocated;
411
412 /* Number of elements in decl_die_table currently in use.  */
413 static unsigned decl_die_table_in_use;
414
415 /* Size (in elements) of increments by which we may expand the
416    decl_die_table.  */
417 #define DECL_DIE_TABLE_INCREMENT 256
418
419 /* A pointer to the base of a table of references to declaration
420    scopes.  This table is a display which tracks the nesting
421    of declaration scopes at the current scope and containing
422    scopes.  This table is used to find the proper place to
423    define type declaration DIE's.  */
424 static tree *decl_scope_table;
425
426 /* Number of elements currently allocated for the decl_scope_table.  */
427 static unsigned decl_scope_table_allocated;
428
429 /* Current level of nesting of declataion scopes.  */
430 static unsigned decl_scope_depth;
431
432 /* Size (in elements) of increments by which we may expand the
433    decl_scope_table.  */
434 #define DECL_SCOPE_TABLE_INCREMENT 64
435
436 /* A pointer to the base of a list of references to DIE's that
437    are uniquely identified by their tag, presence/absence of
438    children DIE's, and list of attribute/value pairs.  */
439 static dw_die_ref *abbrev_die_table;
440
441 /* Number of elements currently allocated for abbrev_die_table.  */
442 static unsigned abbrev_die_table_allocated;
443
444 /* Number of elements in type_die_table currently in use.  */
445 static unsigned abbrev_die_table_in_use;
446
447 /* Size (in elements) of increments by which we may expand the
448    abbrev_die_table.  */
449 #define ABBREV_DIE_TABLE_INCREMENT 256
450
451 /* A pointer to the base of a table that contains line information
452    for each source code line in .text in the compilation unit.  */
453 static dw_line_info_ref line_info_table;
454
455 /* Number of elements currently allocated for line_info_table.  */
456 static unsigned line_info_table_allocated;
457
458 /* Number of elements in separate_line_info_table currently in use.  */
459 static unsigned separate_line_info_table_in_use;
460
461 /* A pointer to the base of a table that contains line information
462    for each source code line outside of .text in the compilation unit.  */
463 static dw_separate_line_info_ref separate_line_info_table;
464
465 /* Number of elements currently allocated for separate_line_info_table.  */
466 static unsigned separate_line_info_table_allocated;
467
468 /* Number of elements in line_info_table currently in use.  */
469 static unsigned line_info_table_in_use;
470
471 /* Size (in elements) of increments by which we may expand the
472    line_info_table.  */
473 #define LINE_INFO_TABLE_INCREMENT 1024
474
475 /* A pointer to the base of a table that contains frame description
476    information for each routine.  */
477 static dw_fde_ref fde_table;
478
479 /* Number of elements currently allocated for fde_table.  */
480 static unsigned fde_table_allocated;
481
482 /* Number of elements in fde_table currently in use.  */
483 static unsigned fde_table_in_use;
484
485 /* Size (in elements) of increments by which we may expand the
486    fde_table.  */
487 #define FDE_TABLE_INCREMENT 256
488
489 /* A list of call frame insns for the CIE.  */
490 static dw_cfi_ref cie_cfi_head;
491
492 /* A pointer to the base of a table that contains a list of publicly
493    accessible names.  */
494 static pubname_ref pubname_table;
495
496 /* Number of elements currently allocated for pubname_table.  */
497 static unsigned pubname_table_allocated;
498
499 /* Number of elements in pubname_table currently in use.  */
500 static unsigned pubname_table_in_use;
501
502 /* Size (in elements) of increments by which we may expand the
503    pubname_table.  */
504 #define PUBNAME_TABLE_INCREMENT 64
505
506 /* A pointer to the base of a table that contains a list of publicly
507    accessible names.  */
508 static arange_ref arange_table;
509
510 /* Number of elements currently allocated for arange_table.  */
511 static unsigned arange_table_allocated;
512
513 /* Number of elements in arange_table currently in use.  */
514 static unsigned arange_table_in_use;
515
516 /* Size (in elements) of increments by which we may expand the
517    arange_table.  */
518 #define ARANGE_TABLE_INCREMENT 64
519
520 /* A pointer to the base of a list of pending types which we haven't
521    generated DIEs for yet, but which we will have to come back to
522    later on.  */
523
524 static tree *pending_types_list;
525
526 /* Number of elements currently allocated for the pending_types_list.  */
527 static unsigned pending_types_allocated;
528
529 /* Number of elements of pending_types_list currently in use.  */
530 static unsigned pending_types;
531
532 /* Size (in elements) of increments by which we may expand the pending
533    types list.  Actually, a single hunk of space of this size should
534    be enough for most typical programs.  */
535 #define PENDING_TYPES_INCREMENT 64
536
537 /* The number of the current function definition for which debugging
538    information is being generated.  These numbers range from 1 up to the
539    maximum number of function definitions contained within the current
540    compilation unit.  These numbers are used to create unique label id's
541    unique to each function definition.  */
542 static unsigned current_funcdef_number = 1;
543
544 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
545    attribute that accelerates the lookup of the FDE associated
546    with the subprogram.  This variable holds the table index of the FDE 
547    associated with the current function (body) definition.  */
548 static unsigned current_funcdef_fde;
549
550 /* Record whether the function being analyzed contains inlined functions.  */
551 static int current_function_has_inlines;
552 static int comp_unit_has_inlines;
553
554 /* A pointer to the ..._DECL node which we have most recently been working
555    on.  We keep this around just in case something about it looks screwy and
556    we want to tell the user what the source coordinates for the actual
557    declaration are.  */
558 static tree dwarf_last_decl;
559
560 /* Forward declarations for functions defined in this file.  */
561
562 static char *stripattributes            PROTO((char *));
563 static void addr_const_to_string        PROTO((char *, rtx));
564 static char *addr_to_string             PROTO((rtx));
565 static int is_pseudo_reg                PROTO((rtx));
566 static tree type_main_variant           PROTO((tree));
567 static int is_tagged_type               PROTO((tree));
568 static char *dwarf_tag_name             PROTO((unsigned));
569 static char *dwarf_attr_name            PROTO((unsigned));
570 static char *dwarf_form_name            PROTO((unsigned));
571 static char *dwarf_stack_op_name        PROTO((unsigned));
572 static char *dwarf_type_encoding_name   PROTO((unsigned));
573 static char *dward_cfi_name             PROTO((unsigned));
574 static tree decl_ultimate_origin        PROTO((tree));
575 static tree block_ultimate_origin       PROTO((tree));
576 static tree decl_class_context          PROTO((tree));
577 static void add_dwarf_attr              PROTO((dw_die_ref, dw_attr_ref));
578 static void add_AT_flag                 PROTO((dw_die_ref,
579                                                enum dwarf_attribute,
580                                                unsigned));
581 static void add_AT_int                  PROTO((dw_die_ref,
582                                                enum dwarf_attribute, long));
583 static void add_AT_unsigned             PROTO((dw_die_ref,
584                                                enum dwarf_attribute,
585                                                unsigned long));
586 static void add_AT_long_long            PROTO((dw_die_ref,
587                                                enum dwarf_attribute,
588                                                unsigned long, unsigned long));
589 static void add_AT_float                PROTO((dw_die_ref,
590                                                enum dwarf_attribute,
591                                                unsigned, long *));
592 static void add_AT_string               PROTO((dw_die_ref,
593                                                enum dwarf_attribute, char *));
594 static void add_AT_die_ref              PROTO((dw_die_ref,
595                                                enum dwarf_attribute,
596                                                dw_die_ref));
597 static void add_AT_fde_ref              PROTO((dw_die_ref,
598                                                enum dwarf_attribute,
599                                                unsigned));
600 static void add_AT_loc                  PROTO((dw_die_ref,
601                                                enum dwarf_attribute,
602                                                dw_loc_descr_ref));
603 static void add_AT_addr                 PROTO((dw_die_ref,
604                                                enum dwarf_attribute, char *));
605 static void add_AT_lbl_id               PROTO((dw_die_ref,
606                                                enum dwarf_attribute, char *));
607 static void add_AT_setion_offset        PROTO((dw_die_ref,
608                                                enum dwarf_attribute, char *));
609 static int is_extern_subr_die           PROTO((dw_die_ref));
610 static dw_attr_ref get_AT               PROTO((dw_die_ref,
611                                                enum dwarf_attribute));
612 static char *get_AT_low_pc              PROTO((dw_die_ref));
613 static char *get_AT_hi_pc               PROTO((dw_die_ref));
614 static char *get_AT_string              PROTO((dw_die_ref,
615                                                enum dwarf_attribute));
616 static int get_AT_flag                  PROTO((dw_die_ref,
617                                                enum dwarf_attribute));
618 static unsigned get_AT_unsigned         PROTO((dw_die_ref,
619                                                enum dwarf_attribute));
620 static int is_c_family                  PROTO((void));
621 static int is_fortran                   PROTO((void));
622 static void remove_AT                   PROTO((dw_die_ref,
623                                                enum dwarf_attribute));
624 static void remove_children             PROTO((dw_die_ref));
625 static void add_child_die               PROTO((dw_die_ref, dw_die_ref));
626 static dw_die_ref new_die               PROTO((enum dwarf_tag, dw_die_ref));
627 static dw_die_ref lookup_type_die       PROTO((tree));
628 static void equate_type_number_to_die   PROTO((tree, dw_die_ref));
629 static dw_die_ref lookup_decl_die       PROTO((tree));
630 static void equate_decl_number_to_die   PROTO((tree, dw_die_ref));
631 static dw_loc_descr_ref new_loc_descr   PROTO((enum dwarf_location_atom,
632                                                unsigned long, unsigned long));
633 static void add_loc_descr               PROTO((dw_loc_descr_ref *,
634                                                dw_loc_descr_ref));
635 static dw_cfi_ref new_cfe               PROTO((void));
636 static void add_cfe                     PROTO((dw_cfi_ref *, dw_cfi_ref));
637 static void print_spaces                PROTO((FILE *));
638 static void print_die                   PROTO((dw_die_ref, FILE *));
639 static void print_dwarf_line_table      PROTO((FILE *));
640 static void add_sibling_atttributes     PROTO((dw_die_ref));
641 static void build_abbrev_table          PROTO((dw_die_ref));
642 static unsigned long size_of_uleb128    PROTO((unsigned long));
643 static unsigned long size_of_sleb128    PROTO((long));
644 static unsigned long size_of_string     PROTO((char *));
645 static unsigned long size_of_loc_descr  PROTO((dw_loc_descr_ref));
646 static unsigned long size_of_locs       PROTO((dw_loc_descr_ref));
647 static int constant_size                PROTO((long unsigned));
648 static unsigned long size_of_die        PROTO((dw_die_ref));
649 static void calc_die_sizes              PROTO((dw_die_ref));
650 static unsigned long size_of_prolog     PROTO((void));
651 static unsigned long size_of_line_info  PROTO((void));
652 static unsigned long size_of_pubnames   PROTO((void));
653 static unsigned long size_of_aranges    PROTO((void));
654 static void output_uleb128              PROTO((unsigned long));
655 static void output_sleb128              PROTO((long));
656 static enum dwarf_form value_format     PROTO((dw_val_ref));
657 static void output_value_format         PROTO((dw_val_ref));
658 static void output_abbrev_section       PROTO((void));
659 static void output_loc_operands         PROTO((dw_loc_descr_ref));
660 static unsigned long sibling_offset     PROTO((dw_die_ref));
661 static void output_die                  PROTO((dw_die_ref));
662 static void output_compilation_unit_header PROTO((void));
663 static char *dwarf2out_cfi_label        PROTO((void));
664 static void add_fde_cfi                 PROTO((char *, dw_cfi_ref));
665 static void lookup_cfa_1                PROTO((dw_cfi_ref, unsigned long *,
666                                                long *));
667 static void lookup_cfa                  PROTO((unsigned long *, long *));
668 static void reg_save                    PROTO((char *, unsigned, unsigned,
669                                                long));
670 static void initial_return_save         PROTO((rtx));
671 static unsigned long size_of_cfi        PROTO((dw_cfi_ref));
672 static unsigned long size_of_fde        PROTO((dw_fde_ref, unsigned long *));
673 static void calc_fde_sizes              PROTO((void));
674 static void output_cfi                  PROTO((dw_cfi_ref, dw_fde_ref));
675 static void output_call_frame_info      PROTO((void));
676 static char *dwarf2_name                PROTO((tree, int));
677 static void add_pubname                 PROTO((tree, dw_die_ref));
678 static void output_pubnames             PROTO((void));
679 static void add_arrange                 PROTO((tree, dw_die_ref));
680 static void output_arranges             PROTO((void));
681 static void output_line_info            PROTO((void));
682 static int is_body_block                PROTO((tree));
683 static dw_die_ref base_type_die         PROTO((tree));
684 static tree root_type                   PROTO((tree));
685 static int is_base_type                 PROTO((tree));
686 static dw_die_ref modified_type_die     PROTO((tree, int, int, dw_die_ref));
687 static int type_is_enum                 PROTO((tree));
688 static unsigned reg_number              PROTO((rtx));
689 static dw_loc_descr_ref reg_loc_descr_ref PROTO((rtx));
690 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
691 static int is_based_loc                 PROTO((rtx));
692 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx));
693 static dw_loc_descr_ref loc_descriptor  PROTO((rtx));
694 static unsigned ceiling                 PROTO((unsigned, unsigned));
695 static tree field_type                  PROTO((tree));
696 static unsigned simple_type_align_in_bits PROTO((tree));
697 static unsigned simple_type_size_in_bits PROTO((tree));
698 static unsigned field_byte_offset               PROTO((tree));
699 static void add_location_attribute      PROTO((dw_die_ref, rtx));
700 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
701 static void add_const_value_attribute   PROTO((dw_die_ref, rtx));
702 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
703 static void add_name_attribute          PROTO((dw_die_ref, char *));
704 static void add_bound_info              PROTO((dw_die_ref,
705                                                enum dwarf_attribute, tree));
706 static void add_subscript_info          PROTO((dw_die_ref, tree));
707 static void add_byte_size_attribute     PROTO((dw_die_ref, tree));
708 static void add_bit_offset_attribute    PROTO((dw_die_ref, tree));
709 static void add_bit_size_attribute      PROTO((dw_die_ref, tree));
710 static void add_prototyped_attribute    PROTO((dw_die_ref, tree));
711 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
712 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
713 static void add_src_coords_attributes   PROTO((dw_die_ref, tree));
714 static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
715 static void push_decl_scope             PROTO((tree));
716 static dw_die_ref scope_die_for         PROTO((tree, dw_die_ref));
717 static void pop_decl_scope              PROTO((void));
718 static void add_type_attribute          PROTO((dw_die_ref, tree, int, int,
719                                                dw_die_ref));
720 static char *type_tag                   PROTO((tree));
721 static tree member_declared_type        PROTO((tree));
722 static char *decl_start_label           PROTO((tree));
723 static void gen_arrqay_type_die         PROTO((tree, dw_die_ref));
724 static void gen_set_type_die            PROTO((tree, dw_die_ref));
725 static void gen_entry_point_die         PROTO((tree, dw_die_ref));
726 static void pend_type                   PROTO((tree));
727 static void output_pending_types_for_scope PROTO((dw_die_ref));
728 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
729 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
730 static void gen_inlined_union_type_die  PROTO((tree, dw_die_ref));
731 static void gen_enumeration_type_die    PROTO((tree, dw_die_ref));
732 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
733 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
734 static void gen_formal_types_die        PROTO((tree, dw_die_ref));
735 static void gen_subprogram_die          PROTO((tree, dw_die_ref));
736 static void gen_variable_die            PROTO((tree, dw_die_ref));
737 static void gen_labeld_die              PROTO((tree, dw_die_ref));
738 static void gen_lexical_block_die       PROTO((tree, dw_die_ref, int));
739 static void gen_inlined_subprogram_die  PROTO((tree, dw_die_ref, int));
740 static void gen_field_die               PROTO((tree, dw_die_ref));
741 static void gen_ptr_to_mbr_type_die     PROTO((tree, dw_die_ref));
742 static void gen_compile_unit_die        PROTO((char *));
743 static void gen_string_type_die         PROTO((tree, dw_die_ref));
744 static void gen_inheritance_die         PROTO((tree, dw_die_ref));
745 static void gen_member_die              PROTO((tree, dw_die_ref));
746 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
747 static void gen_subroutine_type_die     PROTO((tree, dw_die_ref));
748 static void gen_typedef_die             PROTO((tree, dw_die_ref));
749 static void gen_type_die                PROTO((tree, dw_die_ref));
750 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
751 static void gen_block_die               PROTO((tree, dw_die_ref, int));
752 static void decls_for_scope             PROTO((tree, dw_die_ref, int));
753 static int is_redundant_typedef         PROTO((tree));
754 static void gen_decl_die                PROTO((tree, dw_die_ref));
755 static unsigned lookup_filename         PROTO((char *));
756
757 /* Definitions of defaults for assembler-dependent names of various
758    pseudo-ops and section names.
759    Theses may be overridden in the tm.h file (if necessary) for a particular
760    assembler.  */
761
762 #ifndef UNALIGNED_SHORT_ASM_OP
763 #define UNALIGNED_SHORT_ASM_OP  ".2byte"
764 #endif
765 #ifndef UNALIGNED_INT_ASM_OP
766 #define UNALIGNED_INT_ASM_OP    ".4byte"
767 #endif
768 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
769 #define UNALIGNED_DOUBLE_INT_ASM_OP     ".8byte"
770 #endif
771 #ifndef ASM_BYTE_OP
772 #define ASM_BYTE_OP             ".byte"
773 #endif
774
775 #ifndef UNALIGNED_OFFSET_ASM_OP
776 #define UNALIGNED_OFFSET_ASM_OP \
777   (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
778 #endif
779
780 #ifndef UNALIGNED_WORD_ASM_OP
781 #define UNALIGNED_WORD_ASM_OP \
782   (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
783 #endif
784
785 /* Data and reference forms for relocatable data.  */
786 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
787 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
788
789 /* Pseudo-op for defining a new section.  */
790 #ifndef SECTION_ASM_OP
791 #define SECTION_ASM_OP  ".section"
792 #endif
793
794 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
795    print the SECTION_ASM_OP and the section name.  The default here works for
796    almost all svr4 assemblers, except for the sparc, where the section name
797    must be enclosed in double quotes.  (See sparcv4.h).  */
798 #ifndef SECTION_FORMAT
799 #define SECTION_FORMAT  "\t%s\t%s\n"
800 #endif
801
802 /* Section names used to hold DWARF debugging information.  */
803 #ifndef DEBUG_SECTION
804 #define DEBUG_SECTION           ".debug_info"
805 #endif
806 #ifndef ABBREV_SECTION
807 #define ABBREV_SECTION          ".debug_abbrev"
808 #endif
809 #ifndef ARANGES_SECTION
810 #define ARANGES_SECTION         ".debug_aranges"
811 #endif
812 #ifndef DW_MACINFO_SECTION
813 #define DW_MACINFO_SECTION      ".debug_macinfo"
814 #endif
815 #ifndef FRAME_SECTION
816 #define FRAME_SECTION           ".debug_frame"
817 #endif
818 #ifndef LINE_SECTION
819 #define LINE_SECTION            ".debug_line"
820 #endif
821 #ifndef LOC_SECTION
822 #define LOC_SECTION             ".debug_loc"
823 #endif
824 #ifndef PUBNAMES_SECTION
825 #define PUBNAMES_SECTION        ".debug_pubnames"
826 #endif
827 #ifndef STR_SECTION
828 #define STR_SECTION             ".debug_str"
829 #endif
830
831 /* Standerd ELF section names for compiled code and data.  */
832 #ifndef TEXT_SECTION
833 #define TEXT_SECTION            ".text"
834 #endif
835 #ifndef DATA_SECTION
836 #define DATA_SECTION            ".data"
837 #endif
838 #ifndef BSS_SECTION
839 #define BSS_SECTION             ".bss"
840 #endif
841
842
843 /* Definitions of defaults for formats and names of various special
844    (artificial) labels which may be generated within this file (when the -g
845    options is used and DWARF_DEBUGGING_INFO is in effect.
846    If necessary, these may be overridden from within the tm.h file, but
847    typically, overriding these defaults is unnecessary.  */
848
849 char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
850
851 #ifndef TEXT_END_LABEL
852 #define TEXT_END_LABEL          "Letext"
853 #endif
854 #ifndef DATA_END_LABEL
855 #define DATA_END_LABEL          "Ledata"
856 #endif
857 #ifndef BSS_END_LABEL
858 #define BSS_END_LABEL           "Lebss"
859 #endif
860 #ifndef INSN_LABEL_FMT
861 #define INSN_LABEL_FMT          "LI%u_"
862 #endif
863 #ifndef BLOCK_BEGIN_LABEL
864 #define BLOCK_BEGIN_LABEL       "LBB"
865 #endif
866 #ifndef BLOCK_END_LABEL
867 #define BLOCK_END_LABEL         "LBE"
868 #endif
869 #ifndef BODY_BEGIN_LABEL
870 #define BODY_BEGIN_LABEL        "Lbb"
871 #endif
872 #ifndef BODY_END_LABEL
873 #define BODY_END_LABEL          "Lbe"
874 #endif
875 #ifndef FUNC_BEGIN_LABEL
876 #define FUNC_BEGIN_LABEL        "LFB"
877 #endif
878 #ifndef FUNC_END_LABEL
879 #define FUNC_END_LABEL          "LFE"
880 #endif
881 #ifndef LINE_CODE_LABEL
882 #define LINE_CODE_LABEL         "LM"
883 #endif
884 #ifndef SEPARATE_LINE_CODE_LABEL
885 #define SEPARATE_LINE_CODE_LABEL        "LSM"
886 #endif
887
888 /* Definitions of defaults for various types of primitive assembly language
889    output operations.  These may be overridden from within the tm.h file,
890    but typically, that is unecessary.  */
891
892 #ifndef ASM_OUTPUT_SECTION
893 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
894   fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
895 #endif
896
897 #ifndef ASM_OUTPUT_DWARF_DELTA2
898 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2)                     \
899  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP);             \
900         assemble_name (FILE, LABEL1);                                   \
901         fprintf (FILE, "-");                                            \
902         assemble_name (FILE, LABEL2);                                   \
903   } while (0)
904 #endif
905
906 #ifndef ASM_OUTPUT_DWARF_DELTA4
907 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2)                     \
908  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP);               \
909         assemble_name (FILE, LABEL1);                                   \
910         fprintf (FILE, "-");                                            \
911         assemble_name (FILE, LABEL2);                                   \
912   } while (0)
913 #endif
914
915 #ifndef ASM_OUTPUT_DWARF_DELTA
916 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2)                      \
917  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP);            \
918         assemble_name (FILE, LABEL1);                                   \
919         fprintf (FILE, "-");                                            \
920         assemble_name (FILE, LABEL2);                                   \
921   } while (0)
922 #endif
923
924 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
925 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2)                 \
926  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP);              \
927         assemble_name (FILE, LABEL1);                                   \
928         fprintf (FILE, "-");                                            \
929         assemble_name (FILE, LABEL2);                                   \
930   } while (0)
931 #endif
932
933 #ifndef ASM_OUTPUT_DWARF_ADDR
934 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL)                               \
935  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP);              \
936         assemble_name (FILE, LABEL);                                    \
937   } while (0)
938 #endif
939
940 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
941 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR)                          \
942   fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
943 #endif
944
945 #ifndef ASM_OUTPUT_DWARF_OFFSET
946 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL)                             \
947  do {   fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP);            \
948         assemble_name (FILE, LABEL);                                    \
949   } while (0)
950 #endif
951
952 #ifndef ASM_OUTPUT_DWARF_DATA1
953 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
954   fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE)
955 #endif
956
957 #ifndef ASM_OUTPUT_DWARF_DATA2
958 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
959   fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE)
960 #endif
961
962 #ifndef ASM_OUTPUT_DWARF_DATA4
963 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
964   fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE)
965 #endif
966
967 #ifndef ASM_OUTPUT_DWARF_DATA
968 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
969   fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
970            (unsigned long) VALUE)
971 #endif
972
973 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
974 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
975   fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
976            (unsigned long) VALUE)
977 #endif
978
979 #ifndef ASM_OUTPUT_DWARF_DATA8
980 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE)               \
981   do {                                                                  \
982     if (WORDS_BIG_ENDIAN)                                               \
983       {                                                                 \
984         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
985         fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
986       }                                                                 \
987     else                                                                \
988       {                                                                 \
989         fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\
990         fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \
991       }                                                                 \
992   } while (0)
993 #endif
994
995 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
996    newline is produced.  When flag_verbose_asm is asserted, we add commnetary
997    at the end of the line, so we must avoid output of a newline here.  */
998 #ifndef ASM_OUTPUT_DWARF_STRING
999 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
1000   do {                                                                        \
1001     register int slen = strlen(P);                                            \
1002     register char *p = (P);                                                   \
1003     register int i;                                                           \
1004     fprintf (FILE, "\t.ascii \"");                                            \
1005     for (i = 0; i < slen; i++)                                                \
1006       {                                                                       \
1007           register int c = p[i];                                              \
1008           if (c == '\"' || c == '\\')                                         \
1009             putc ('\\', FILE);                                                \
1010           if (c >= ' ' && c < 0177)                                           \
1011             putc (c, FILE);                                                   \
1012           else                                                                \
1013             {                                                                 \
1014               fprintf (FILE, "\\%o", c);                                      \
1015             }                                                                 \
1016       }                                                                       \
1017     fprintf (FILE, "\\0\"");                                                  \
1018   }                                                                           \
1019   while (0)
1020 #endif
1021
1022 /* Convert a reference to the assembler name of a C-level name.  This
1023    macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
1024    a string rather than writing to a file.  */
1025 #ifndef ASM_NAME_TO_STRING
1026 #define ASM_NAME_TO_STRING(STR, NAME) \
1027   do {                                                                        \
1028       if ((NAME)[0] == '*')                                                   \
1029         strcpy (STR, NAME+1);                                                 \
1030       else                                                                    \
1031         strcpy (STR, NAME);                                                   \
1032   }                                                                           \
1033   while (0)
1034 #endif
1035
1036 /* The DWARF 2 CFA column which tracks the return address.  Normally this
1037    is the column for PC, or the first column after all of the hard
1038    registers.  */
1039 #ifndef DWARF_FRAME_RETURN_COLUMN
1040 #ifdef PC_REGNUM
1041 #define DWARF_FRAME_RETURN_COLUMN       DWARF_FRAME_REGNUM (PC_REGNUM)
1042 #else
1043 #define DWARF_FRAME_RETURN_COLUMN       FIRST_PSEUDO_REGISTER
1044 #endif
1045 #endif
1046
1047 /* The mapping from gcc register number to DWARF 2 CFA column number.  By
1048    default, we just provide columns for all registers.  */
1049 #ifndef DWARF_FRAME_REGNUM
1050 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
1051 #endif
1052 \f
1053 /* Return a pointer to a copy of the section string name S with all
1054    attributes stripped off.  */
1055
1056 static inline char *
1057 stripattributes (s)
1058      char *s;
1059 {
1060   char *stripped = xstrdup (s);
1061   char *p = stripped;
1062
1063   while (*p && *p != ',')
1064     p++;
1065
1066   *p = '\0';
1067   return stripped;
1068 }
1069
1070 /* Convert an integer constant expression into assembler syntax.  Addition
1071    and subtraction are the only arithmetic that may appear in these
1072    expressions.   This is an adaptation of output_addr_const in final.c.
1073    Here, the target of the conversion is a string buffer.  We can't use
1074    output_addr_const directly, because it writes to a file.  */
1075
1076 static void
1077 addr_const_to_string (str, x)
1078      char *str;
1079      rtx x;
1080 {
1081   char buf1[256];
1082   char buf2[256];
1083
1084 restart:
1085   str[0] = '\0';
1086   switch (GET_CODE (x))
1087     {
1088     case PC:
1089       if (flag_pic)
1090         strcat (str, ",");
1091       else
1092         abort ();
1093       break;
1094
1095     case SYMBOL_REF:
1096       ASM_NAME_TO_STRING (buf1, XSTR (x, 0));
1097       strcat (str, buf1);
1098       break;
1099
1100     case LABEL_REF:
1101       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
1102       ASM_NAME_TO_STRING (buf2, buf1);
1103       strcat (str, buf2);
1104       break;
1105
1106     case CODE_LABEL:
1107       ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
1108       ASM_NAME_TO_STRING (buf2, buf1);
1109       strcat (str, buf2);
1110       break;
1111
1112     case CONST_INT:
1113       sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
1114       strcat (str, buf1);
1115       break;
1116
1117     case CONST:
1118       /* This used to output parentheses around the expression, but that does 
1119          not work on the 386 (either ATT or BSD assembler).  */
1120       addr_const_to_string (buf1, XEXP (x, 0));
1121       strcat (str, buf1);
1122       break;
1123
1124     case CONST_DOUBLE:
1125       if (GET_MODE (x) == VOIDmode)
1126         {
1127           /* We can use %d if the number is one word and positive.  */
1128           if (CONST_DOUBLE_HIGH (x))
1129             sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1130                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
1131           else if (CONST_DOUBLE_LOW (x) < 0)
1132             sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
1133           else
1134             sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
1135                      CONST_DOUBLE_LOW (x));
1136           strcat (str, buf1);
1137         }
1138       else
1139         /* We can't handle floating point constants; PRINT_OPERAND must
1140            handle them.  */
1141         output_operand_lossage ("floating constant misused");
1142       break;
1143
1144     case PLUS:
1145       /* Some assemblers need integer constants to appear last (eg masm).  */
1146       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
1147         {
1148           addr_const_to_string (buf1, XEXP (x, 1));
1149           strcat (str, buf1);
1150           if (INTVAL (XEXP (x, 0)) >= 0)
1151             strcat (str, "+");
1152
1153           addr_const_to_string (buf1, XEXP (x, 0));
1154           strcat (str, buf1);
1155         }
1156       else
1157         {
1158           addr_const_to_string (buf1, XEXP (x, 0));
1159           strcat (str, buf1);
1160           if (INTVAL (XEXP (x, 1)) >= 0)
1161             strcat (str, "+");
1162
1163           addr_const_to_string (buf1, XEXP (x, 1));
1164           strcat (str, buf1);
1165         }
1166       break;
1167
1168     case MINUS:
1169       /* Avoid outputting things like x-x or x+5-x, since some assemblers
1170          can't handle that.  */
1171       x = simplify_subtraction (x);
1172       if (GET_CODE (x) != MINUS)
1173         goto restart;
1174
1175       addr_const_to_string (buf1, XEXP (x, 0));
1176       strcat (str, buf1);
1177       strcat (str, "-");
1178       if (GET_CODE (XEXP (x, 1)) == CONST_INT
1179           && INTVAL (XEXP (x, 1)) < 0)
1180         {
1181           strcat (str, ASM_OPEN_PAREN);
1182           addr_const_to_string (buf1, XEXP (x, 1));
1183           strcat (str, buf1);
1184           strcat (str, ASM_CLOSE_PAREN);
1185         }
1186       else
1187         {
1188           addr_const_to_string (buf1, XEXP (x, 1));
1189           strcat (str, buf1);
1190         }
1191       break;
1192
1193     case ZERO_EXTEND:
1194     case SIGN_EXTEND:
1195       addr_const_to_string (buf1, XEXP (x, 0));
1196       strcat (str, buf1);
1197       break;
1198
1199     default:
1200       output_operand_lossage ("invalid expression as operand");
1201     }
1202 }
1203
1204 /* Convert an address constant to a string, and return a pointer to
1205    a copy of the result, located on the heap.  */
1206
1207 static char *
1208 addr_to_string (x)
1209      rtx x;
1210 {
1211   char buf[1024];
1212   addr_const_to_string (buf, x);
1213   return xstrdup (buf);
1214 }
1215
1216 /* Test if rtl node points to a psuedo register.  */
1217
1218 static inline int
1219 is_pseudo_reg (rtl)
1220      register rtx rtl;
1221 {
1222   return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
1223           || ((GET_CODE (rtl) == SUBREG)
1224               && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
1225 }
1226
1227 /* Return a reference to a type, with its const and volatile qualifiers
1228    removed.  */
1229
1230 static inline tree
1231 type_main_variant (type)
1232      register tree type;
1233 {
1234   type = TYPE_MAIN_VARIANT (type);
1235
1236   /* There really should be only one main variant among any group of variants 
1237      of a given type (and all of the MAIN_VARIANT values for all members of
1238      the group should point to that one type) but sometimes the C front-end
1239      messes this up for array types, so we work around that bug here.  */
1240
1241   if (TREE_CODE (type) == ARRAY_TYPE)
1242     while (type != TYPE_MAIN_VARIANT (type))
1243       type = TYPE_MAIN_VARIANT (type);
1244
1245   return type;
1246 }
1247
1248 /* Return non-zero if the given type node represents a tagged type.  */
1249
1250 static inline int
1251 is_tagged_type (type)
1252      register tree type;
1253 {
1254   register enum tree_code code = TREE_CODE (type);
1255
1256   return (code == RECORD_TYPE || code == UNION_TYPE
1257           || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
1258 }
1259
1260 /* Convert a DIE tag into its string name.  */
1261
1262 static char *
1263 dwarf_tag_name (tag)
1264      register unsigned tag;
1265 {
1266   switch (tag)
1267     {
1268     case DW_TAG_padding:
1269       return "DW_TAG_padding";
1270     case DW_TAG_array_type:
1271       return "DW_TAG_array_type";
1272     case DW_TAG_class_type:
1273       return "DW_TAG_class_type";
1274     case DW_TAG_entry_point:
1275       return "DW_TAG_entry_point";
1276     case DW_TAG_enumeration_type:
1277       return "DW_TAG_enumeration_type";
1278     case DW_TAG_formal_parameter:
1279       return "DW_TAG_formal_parameter";
1280     case DW_TAG_imported_declaration:
1281       return "DW_TAG_imported_declaration";
1282     case DW_TAG_label:
1283       return "DW_TAG_label";
1284     case DW_TAG_lexical_block:
1285       return "DW_TAG_lexical_block";
1286     case DW_TAG_member:
1287       return "DW_TAG_member";
1288     case DW_TAG_pointer_type:
1289       return "DW_TAG_pointer_type";
1290     case DW_TAG_reference_type:
1291       return "DW_TAG_reference_type";
1292     case DW_TAG_compile_unit:
1293       return "DW_TAG_compile_unit";
1294     case DW_TAG_string_type:
1295       return "DW_TAG_string_type";
1296     case DW_TAG_structure_type:
1297       return "DW_TAG_structure_type";
1298     case DW_TAG_subroutine_type:
1299       return "DW_TAG_subroutine_type";
1300     case DW_TAG_typedef:
1301       return "DW_TAG_typedef";
1302     case DW_TAG_union_type:
1303       return "DW_TAG_union_type";
1304     case DW_TAG_unspecified_parameters:
1305       return "DW_TAG_unspecified_parameters";
1306     case DW_TAG_variant:
1307       return "DW_TAG_variant";
1308     case DW_TAG_common_block:
1309       return "DW_TAG_common_block";
1310     case DW_TAG_common_inclusion:
1311       return "DW_TAG_common_inclusion";
1312     case DW_TAG_inheritance:
1313       return "DW_TAG_inheritance";
1314     case DW_TAG_inlined_subroutine:
1315       return "DW_TAG_inlined_subroutine";
1316     case DW_TAG_module:
1317       return "DW_TAG_module";
1318     case DW_TAG_ptr_to_member_type:
1319       return "DW_TAG_ptr_to_member_type";
1320     case DW_TAG_set_type:
1321       return "DW_TAG_set_type";
1322     case DW_TAG_subrange_type:
1323       return "DW_TAG_subrange_type";
1324     case DW_TAG_with_stmt:
1325       return "DW_TAG_with_stmt";
1326     case DW_TAG_access_declaration:
1327       return "DW_TAG_access_declaration";
1328     case DW_TAG_base_type:
1329       return "DW_TAG_base_type";
1330     case DW_TAG_catch_block:
1331       return "DW_TAG_catch_block";
1332     case DW_TAG_const_type:
1333       return "DW_TAG_const_type";
1334     case DW_TAG_constant:
1335       return "DW_TAG_constant";
1336     case DW_TAG_enumerator:
1337       return "DW_TAG_enumerator";
1338     case DW_TAG_file_type:
1339       return "DW_TAG_file_type";
1340     case DW_TAG_friend:
1341       return "DW_TAG_friend";
1342     case DW_TAG_namelist:
1343       return "DW_TAG_namelist";
1344     case DW_TAG_namelist_item:
1345       return "DW_TAG_namelist_item";
1346     case DW_TAG_packed_type:
1347       return "DW_TAG_packed_type";
1348     case DW_TAG_subprogram:
1349       return "DW_TAG_subprogram";
1350     case DW_TAG_template_type_param:
1351       return "DW_TAG_template_type_param";
1352     case DW_TAG_template_value_param:
1353       return "DW_TAG_template_value_param";
1354     case DW_TAG_thrown_type:
1355       return "DW_TAG_thrown_type";
1356     case DW_TAG_try_block:
1357       return "DW_TAG_try_block";
1358     case DW_TAG_variant_part:
1359       return "DW_TAG_variant_part";
1360     case DW_TAG_variable:
1361       return "DW_TAG_variable";
1362     case DW_TAG_volatile_type:
1363       return "DW_TAG_volatile_type";
1364     case DW_TAG_MIPS_loop:
1365       return "DW_TAG_MIPS_loop";
1366     case DW_TAG_format_label:
1367       return "DW_TAG_format_label";
1368     case DW_TAG_function_template:
1369       return "DW_TAG_function_template";
1370     case DW_TAG_class_template:
1371       return "DW_TAG_class_template";
1372     default:
1373       return "DW_TAG_<unknown>";
1374     }
1375 }
1376
1377 /* Convert a DWARF attribute code into its string name.  */
1378
1379 static char *
1380 dwarf_attr_name (attr)
1381      register unsigned attr;
1382 {
1383   switch (attr)
1384     {
1385     case DW_AT_sibling:
1386       return "DW_AT_sibling";
1387     case DW_AT_location:
1388       return "DW_AT_location";
1389     case DW_AT_name:
1390       return "DW_AT_name";
1391     case DW_AT_ordering:
1392       return "DW_AT_ordering";
1393     case DW_AT_subscr_data:
1394       return "DW_AT_subscr_data";
1395     case DW_AT_byte_size:
1396       return "DW_AT_byte_size";
1397     case DW_AT_bit_offset:
1398       return "DW_AT_bit_offset";
1399     case DW_AT_bit_size:
1400       return "DW_AT_bit_size";
1401     case DW_AT_element_list:
1402       return "DW_AT_element_list";
1403     case DW_AT_stmt_list:
1404       return "DW_AT_stmt_list";
1405     case DW_AT_low_pc:
1406       return "DW_AT_low_pc";
1407     case DW_AT_high_pc:
1408       return "DW_AT_high_pc";
1409     case DW_AT_language:
1410       return "DW_AT_language";
1411     case DW_AT_member:
1412       return "DW_AT_member";
1413     case DW_AT_discr:
1414       return "DW_AT_discr";
1415     case DW_AT_discr_value:
1416       return "DW_AT_discr_value";
1417     case DW_AT_visibility:
1418       return "DW_AT_visibility";
1419     case DW_AT_import:
1420       return "DW_AT_import";
1421     case DW_AT_string_length:
1422       return "DW_AT_string_length";
1423     case DW_AT_common_reference:
1424       return "DW_AT_common_reference";
1425     case DW_AT_comp_dir:
1426       return "DW_AT_comp_dir";
1427     case DW_AT_const_value:
1428       return "DW_AT_const_value";
1429     case DW_AT_containing_type:
1430       return "DW_AT_containing_type";
1431     case DW_AT_default_value:
1432       return "DW_AT_default_value";
1433     case DW_AT_inline:
1434       return "DW_AT_inline";
1435     case DW_AT_is_optional:
1436       return "DW_AT_is_optional";
1437     case DW_AT_lower_bound:
1438       return "DW_AT_lower_bound";
1439     case DW_AT_producer:
1440       return "DW_AT_producer";
1441     case DW_AT_prototyped:
1442       return "DW_AT_prototyped";
1443     case DW_AT_return_addr:
1444       return "DW_AT_return_addr";
1445     case DW_AT_start_scope:
1446       return "DW_AT_start_scope";
1447     case DW_AT_stride_size:
1448       return "DW_AT_stride_size";
1449     case DW_AT_upper_bound:
1450       return "DW_AT_upper_bound";
1451     case DW_AT_abstract_origin:
1452       return "DW_AT_abstract_origin";
1453     case DW_AT_accessibility:
1454       return "DW_AT_accessibility";
1455     case DW_AT_address_class:
1456       return "DW_AT_address_class";
1457     case DW_AT_artificial:
1458       return "DW_AT_artificial";
1459     case DW_AT_base_types:
1460       return "DW_AT_base_types";
1461     case DW_AT_calling_convention:
1462       return "DW_AT_calling_convention";
1463     case DW_AT_count:
1464       return "DW_AT_count";
1465     case DW_AT_data_member_location:
1466       return "DW_AT_data_member_location";
1467     case DW_AT_decl_column:
1468       return "DW_AT_decl_column";
1469     case DW_AT_decl_file:
1470       return "DW_AT_decl_file";
1471     case DW_AT_decl_line:
1472       return "DW_AT_decl_line";
1473     case DW_AT_declaration:
1474       return "DW_AT_declaration";
1475     case DW_AT_discr_list:
1476       return "DW_AT_discr_list";
1477     case DW_AT_encoding:
1478       return "DW_AT_encoding";
1479     case DW_AT_external:
1480       return "DW_AT_external";
1481     case DW_AT_frame_base:
1482       return "DW_AT_frame_base";
1483     case DW_AT_friend:
1484       return "DW_AT_friend";
1485     case DW_AT_identifier_case:
1486       return "DW_AT_identifier_case";
1487     case DW_AT_macro_info:
1488       return "DW_AT_macro_info";
1489     case DW_AT_namelist_items:
1490       return "DW_AT_namelist_items";
1491     case DW_AT_priority:
1492       return "DW_AT_priority";
1493     case DW_AT_segment:
1494       return "DW_AT_segment";
1495     case DW_AT_specification:
1496       return "DW_AT_specification";
1497     case DW_AT_static_link:
1498       return "DW_AT_static_link";
1499     case DW_AT_type:
1500       return "DW_AT_type";
1501     case DW_AT_use_location:
1502       return "DW_AT_use_location";
1503     case DW_AT_variable_parameter:
1504       return "DW_AT_variable_parameter";
1505     case DW_AT_virtuality:
1506       return "DW_AT_virtuality";
1507     case DW_AT_vtable_elem_location:
1508       return "DW_AT_vtable_elem_location";
1509
1510     case DW_AT_MIPS_fde:
1511       return "DW_AT_MIPS_fde";
1512     case DW_AT_MIPS_loop_begin:
1513       return "DW_AT_MIPS_loop_begin";
1514     case DW_AT_MIPS_tail_loop_begin:
1515       return "DW_AT_MIPS_tail_loop_begin";
1516     case DW_AT_MIPS_epilog_begin:
1517       return "DW_AT_MIPS_epilog_begin";
1518     case DW_AT_MIPS_loop_unroll_factor:
1519       return "DW_AT_MIPS_loop_unroll_factor";
1520     case DW_AT_MIPS_software_pipeline_depth:
1521       return "DW_AT_MIPS_software_pipeline_depth";
1522     case DW_AT_MIPS_linkage_name:
1523       return "DW_AT_MIPS_linkage_name";
1524     case DW_AT_MIPS_stride:
1525       return "DW_AT_MIPS_stride";
1526     case DW_AT_MIPS_abstract_name:
1527       return "DW_AT_MIPS_abstract_name";
1528     case DW_AT_MIPS_clone_origin:
1529       return "DW_AT_MIPS_clone_origin";
1530     case DW_AT_MIPS_has_inlines:
1531       return "DW_AT_MIPS_has_inlines";
1532
1533     case DW_AT_sf_names:
1534       return "DW_AT_sf_names";
1535     case DW_AT_src_info:
1536       return "DW_AT_src_info";
1537     case DW_AT_mac_info:
1538       return "DW_AT_mac_info";
1539     case DW_AT_src_coords:
1540       return "DW_AT_src_coords";
1541     case DW_AT_body_begin:
1542       return "DW_AT_body_begin";
1543     case DW_AT_body_end:
1544       return "DW_AT_body_end";
1545     default:
1546       return "DW_AT_<unknown>";
1547     }
1548 }
1549
1550 /* Convert a DWARF value form code into its string name.  */
1551
1552 static char *
1553 dwarf_form_name (form)
1554      register unsigned form;
1555 {
1556   switch (form)
1557     {
1558     case DW_FORM_addr:
1559       return "DW_FORM_addr";
1560     case DW_FORM_block2:
1561       return "DW_FORM_block2";
1562     case DW_FORM_block4:
1563       return "DW_FORM_block4";
1564     case DW_FORM_data2:
1565       return "DW_FORM_data2";
1566     case DW_FORM_data4:
1567       return "DW_FORM_data4";
1568     case DW_FORM_data8:
1569       return "DW_FORM_data8";
1570     case DW_FORM_string:
1571       return "DW_FORM_string";
1572     case DW_FORM_block:
1573       return "DW_FORM_block";
1574     case DW_FORM_block1:
1575       return "DW_FORM_block1";
1576     case DW_FORM_data1:
1577       return "DW_FORM_data1";
1578     case DW_FORM_flag:
1579       return "DW_FORM_flag";
1580     case DW_FORM_sdata:
1581       return "DW_FORM_sdata";
1582     case DW_FORM_strp:
1583       return "DW_FORM_strp";
1584     case DW_FORM_udata:
1585       return "DW_FORM_udata";
1586     case DW_FORM_ref_addr:
1587       return "DW_FORM_ref_addr";
1588     case DW_FORM_ref1:
1589       return "DW_FORM_ref1";
1590     case DW_FORM_ref2:
1591       return "DW_FORM_ref2";
1592     case DW_FORM_ref4:
1593       return "DW_FORM_ref4";
1594     case DW_FORM_ref8:
1595       return "DW_FORM_ref8";
1596     case DW_FORM_ref_udata:
1597       return "DW_FORM_ref_udata";
1598     case DW_FORM_indirect:
1599       return "DW_FORM_indirect";
1600     default:
1601       return "DW_FORM_<unknown>";
1602     }
1603 }
1604
1605 /* Convert a DWARF stack opcode into its string name.  */
1606
1607 static char *
1608 dwarf_stack_op_name (op)
1609      register unsigned op;
1610 {
1611   switch (op)
1612     {
1613     case DW_OP_addr:
1614       return "DW_OP_addr";
1615     case DW_OP_deref:
1616       return "DW_OP_deref";
1617     case DW_OP_const1u:
1618       return "DW_OP_const1u";
1619     case DW_OP_const1s:
1620       return "DW_OP_const1s";
1621     case DW_OP_const2u:
1622       return "DW_OP_const2u";
1623     case DW_OP_const2s:
1624       return "DW_OP_const2s";
1625     case DW_OP_const4u:
1626       return "DW_OP_const4u";
1627     case DW_OP_const4s:
1628       return "DW_OP_const4s";
1629     case DW_OP_const8u:
1630       return "DW_OP_const8u";
1631     case DW_OP_const8s:
1632       return "DW_OP_const8s";
1633     case DW_OP_constu:
1634       return "DW_OP_constu";
1635     case DW_OP_consts:
1636       return "DW_OP_consts";
1637     case DW_OP_dup:
1638       return "DW_OP_dup";
1639     case DW_OP_drop:
1640       return "DW_OP_drop";
1641     case DW_OP_over:
1642       return "DW_OP_over";
1643     case DW_OP_pick:
1644       return "DW_OP_pick";
1645     case DW_OP_swap:
1646       return "DW_OP_swap";
1647     case DW_OP_rot:
1648       return "DW_OP_rot";
1649     case DW_OP_xderef:
1650       return "DW_OP_xderef";
1651     case DW_OP_abs:
1652       return "DW_OP_abs";
1653     case DW_OP_and:
1654       return "DW_OP_and";
1655     case DW_OP_div:
1656       return "DW_OP_div";
1657     case DW_OP_minus:
1658       return "DW_OP_minus";
1659     case DW_OP_mod:
1660       return "DW_OP_mod";
1661     case DW_OP_mul:
1662       return "DW_OP_mul";
1663     case DW_OP_neg:
1664       return "DW_OP_neg";
1665     case DW_OP_not:
1666       return "DW_OP_not";
1667     case DW_OP_or:
1668       return "DW_OP_or";
1669     case DW_OP_plus:
1670       return "DW_OP_plus";
1671     case DW_OP_plus_uconst:
1672       return "DW_OP_plus_uconst";
1673     case DW_OP_shl:
1674       return "DW_OP_shl";
1675     case DW_OP_shr:
1676       return "DW_OP_shr";
1677     case DW_OP_shra:
1678       return "DW_OP_shra";
1679     case DW_OP_xor:
1680       return "DW_OP_xor";
1681     case DW_OP_bra:
1682       return "DW_OP_bra";
1683     case DW_OP_eq:
1684       return "DW_OP_eq";
1685     case DW_OP_ge:
1686       return "DW_OP_ge";
1687     case DW_OP_gt:
1688       return "DW_OP_gt";
1689     case DW_OP_le:
1690       return "DW_OP_le";
1691     case DW_OP_lt:
1692       return "DW_OP_lt";
1693     case DW_OP_ne:
1694       return "DW_OP_ne";
1695     case DW_OP_skip:
1696       return "DW_OP_skip";
1697     case DW_OP_lit0:
1698       return "DW_OP_lit0";
1699     case DW_OP_lit1:
1700       return "DW_OP_lit1";
1701     case DW_OP_lit2:
1702       return "DW_OP_lit2";
1703     case DW_OP_lit3:
1704       return "DW_OP_lit3";
1705     case DW_OP_lit4:
1706       return "DW_OP_lit4";
1707     case DW_OP_lit5:
1708       return "DW_OP_lit5";
1709     case DW_OP_lit6:
1710       return "DW_OP_lit6";
1711     case DW_OP_lit7:
1712       return "DW_OP_lit7";
1713     case DW_OP_lit8:
1714       return "DW_OP_lit8";
1715     case DW_OP_lit9:
1716       return "DW_OP_lit9";
1717     case DW_OP_lit10:
1718       return "DW_OP_lit10";
1719     case DW_OP_lit11:
1720       return "DW_OP_lit11";
1721     case DW_OP_lit12:
1722       return "DW_OP_lit12";
1723     case DW_OP_lit13:
1724       return "DW_OP_lit13";
1725     case DW_OP_lit14:
1726       return "DW_OP_lit14";
1727     case DW_OP_lit15:
1728       return "DW_OP_lit15";
1729     case DW_OP_lit16:
1730       return "DW_OP_lit16";
1731     case DW_OP_lit17:
1732       return "DW_OP_lit17";
1733     case DW_OP_lit18:
1734       return "DW_OP_lit18";
1735     case DW_OP_lit19:
1736       return "DW_OP_lit19";
1737     case DW_OP_lit20:
1738       return "DW_OP_lit20";
1739     case DW_OP_lit21:
1740       return "DW_OP_lit21";
1741     case DW_OP_lit22:
1742       return "DW_OP_lit22";
1743     case DW_OP_lit23:
1744       return "DW_OP_lit23";
1745     case DW_OP_lit24:
1746       return "DW_OP_lit24";
1747     case DW_OP_lit25:
1748       return "DW_OP_lit25";
1749     case DW_OP_lit26:
1750       return "DW_OP_lit26";
1751     case DW_OP_lit27:
1752       return "DW_OP_lit27";
1753     case DW_OP_lit28:
1754       return "DW_OP_lit28";
1755     case DW_OP_lit29:
1756       return "DW_OP_lit29";
1757     case DW_OP_lit30:
1758       return "DW_OP_lit30";
1759     case DW_OP_lit31:
1760       return "DW_OP_lit31";
1761     case DW_OP_reg0:
1762       return "DW_OP_reg0";
1763     case DW_OP_reg1:
1764       return "DW_OP_reg1";
1765     case DW_OP_reg2:
1766       return "DW_OP_reg2";
1767     case DW_OP_reg3:
1768       return "DW_OP_reg3";
1769     case DW_OP_reg4:
1770       return "DW_OP_reg4";
1771     case DW_OP_reg5:
1772       return "DW_OP_reg5";
1773     case DW_OP_reg6:
1774       return "DW_OP_reg6";
1775     case DW_OP_reg7:
1776       return "DW_OP_reg7";
1777     case DW_OP_reg8:
1778       return "DW_OP_reg8";
1779     case DW_OP_reg9:
1780       return "DW_OP_reg9";
1781     case DW_OP_reg10:
1782       return "DW_OP_reg10";
1783     case DW_OP_reg11:
1784       return "DW_OP_reg11";
1785     case DW_OP_reg12:
1786       return "DW_OP_reg12";
1787     case DW_OP_reg13:
1788       return "DW_OP_reg13";
1789     case DW_OP_reg14:
1790       return "DW_OP_reg14";
1791     case DW_OP_reg15:
1792       return "DW_OP_reg15";
1793     case DW_OP_reg16:
1794       return "DW_OP_reg16";
1795     case DW_OP_reg17:
1796       return "DW_OP_reg17";
1797     case DW_OP_reg18:
1798       return "DW_OP_reg18";
1799     case DW_OP_reg19:
1800       return "DW_OP_reg19";
1801     case DW_OP_reg20:
1802       return "DW_OP_reg20";
1803     case DW_OP_reg21:
1804       return "DW_OP_reg21";
1805     case DW_OP_reg22:
1806       return "DW_OP_reg22";
1807     case DW_OP_reg23:
1808       return "DW_OP_reg23";
1809     case DW_OP_reg24:
1810       return "DW_OP_reg24";
1811     case DW_OP_reg25:
1812       return "DW_OP_reg25";
1813     case DW_OP_reg26:
1814       return "DW_OP_reg26";
1815     case DW_OP_reg27:
1816       return "DW_OP_reg27";
1817     case DW_OP_reg28:
1818       return "DW_OP_reg28";
1819     case DW_OP_reg29:
1820       return "DW_OP_reg29";
1821     case DW_OP_reg30:
1822       return "DW_OP_reg30";
1823     case DW_OP_reg31:
1824       return "DW_OP_reg31";
1825     case DW_OP_breg0:
1826       return "DW_OP_breg0";
1827     case DW_OP_breg1:
1828       return "DW_OP_breg1";
1829     case DW_OP_breg2:
1830       return "DW_OP_breg2";
1831     case DW_OP_breg3:
1832       return "DW_OP_breg3";
1833     case DW_OP_breg4:
1834       return "DW_OP_breg4";
1835     case DW_OP_breg5:
1836       return "DW_OP_breg5";
1837     case DW_OP_breg6:
1838       return "DW_OP_breg6";
1839     case DW_OP_breg7:
1840       return "DW_OP_breg7";
1841     case DW_OP_breg8:
1842       return "DW_OP_breg8";
1843     case DW_OP_breg9:
1844       return "DW_OP_breg9";
1845     case DW_OP_breg10:
1846       return "DW_OP_breg10";
1847     case DW_OP_breg11:
1848       return "DW_OP_breg11";
1849     case DW_OP_breg12:
1850       return "DW_OP_breg12";
1851     case DW_OP_breg13:
1852       return "DW_OP_breg13";
1853     case DW_OP_breg14:
1854       return "DW_OP_breg14";
1855     case DW_OP_breg15:
1856       return "DW_OP_breg15";
1857     case DW_OP_breg16:
1858       return "DW_OP_breg16";
1859     case DW_OP_breg17:
1860       return "DW_OP_breg17";
1861     case DW_OP_breg18:
1862       return "DW_OP_breg18";
1863     case DW_OP_breg19:
1864       return "DW_OP_breg19";
1865     case DW_OP_breg20:
1866       return "DW_OP_breg20";
1867     case DW_OP_breg21:
1868       return "DW_OP_breg21";
1869     case DW_OP_breg22:
1870       return "DW_OP_breg22";
1871     case DW_OP_breg23:
1872       return "DW_OP_breg23";
1873     case DW_OP_breg24:
1874       return "DW_OP_breg24";
1875     case DW_OP_breg25:
1876       return "DW_OP_breg25";
1877     case DW_OP_breg26:
1878       return "DW_OP_breg26";
1879     case DW_OP_breg27:
1880       return "DW_OP_breg27";
1881     case DW_OP_breg28:
1882       return "DW_OP_breg28";
1883     case DW_OP_breg29:
1884       return "DW_OP_breg29";
1885     case DW_OP_breg30:
1886       return "DW_OP_breg30";
1887     case DW_OP_breg31:
1888       return "DW_OP_breg31";
1889     case DW_OP_regx:
1890       return "DW_OP_regx";
1891     case DW_OP_fbreg:
1892       return "DW_OP_fbreg";
1893     case DW_OP_bregx:
1894       return "DW_OP_bregx";
1895     case DW_OP_piece:
1896       return "DW_OP_piece";
1897     case DW_OP_deref_size:
1898       return "DW_OP_deref_size";
1899     case DW_OP_xderef_size:
1900       return "DW_OP_xderef_size";
1901     case DW_OP_nop:
1902       return "DW_OP_nop";
1903     default:
1904       return "OP_<unknown>";
1905     }
1906 }
1907
1908 /* Convert a DWARF type code into its string name.  */
1909
1910 static char *
1911 dwarf_type_encoding_name (enc)
1912      register unsigned enc;
1913 {
1914   switch (enc)
1915     {
1916     case DW_ATE_address:
1917       return "DW_ATE_address";
1918     case DW_ATE_boolean:
1919       return "DW_ATE_boolean";
1920     case DW_ATE_complex_float:
1921       return "DW_ATE_complex_float";
1922     case DW_ATE_float:
1923       return "DW_ATE_float";
1924     case DW_ATE_signed:
1925       return "DW_ATE_signed";
1926     case DW_ATE_signed_char:
1927       return "DW_ATE_signed_char";
1928     case DW_ATE_unsigned:
1929       return "DW_ATE_unsigned";
1930     case DW_ATE_unsigned_char:
1931       return "DW_ATE_unsigned_char";
1932     default:
1933       return "DW_ATE_<unknown>";
1934     }
1935 }
1936
1937 /* Convert a DWARF call frame info. operation to its string name */
1938
1939 static char *
1940 dwarf_cfi_name (cfi_opc)
1941      register unsigned cfi_opc;
1942 {
1943   switch (cfi_opc)
1944     {
1945     case DW_CFA_advance_loc:
1946       return "DW_CFA_advance_loc";
1947     case DW_CFA_offset:
1948       return "DW_CFA_offset";
1949     case DW_CFA_restore:
1950       return "DW_CFA_restore";
1951     case DW_CFA_nop:
1952       return "DW_CFA_nop";
1953     case DW_CFA_set_loc:
1954       return "DW_CFA_set_loc";
1955     case DW_CFA_advance_loc1:
1956       return "DW_CFA_advance_loc1";
1957     case DW_CFA_advance_loc2:
1958       return "DW_CFA_advance_loc2";
1959     case DW_CFA_advance_loc4:
1960       return "DW_CFA_advance_loc4";
1961     case DW_CFA_offset_extended:
1962       return "DW_CFA_offset_extended";
1963     case DW_CFA_restore_extended:
1964       return "DW_CFA_restore_extended";
1965     case DW_CFA_undefined:
1966       return "DW_CFA_undefined";
1967     case DW_CFA_same_value:
1968       return "DW_CFA_same_value";
1969     case DW_CFA_register:
1970       return "DW_CFA_register";
1971     case DW_CFA_remember_state:
1972       return "DW_CFA_remember_state";
1973     case DW_CFA_restore_state:
1974       return "DW_CFA_restore_state";
1975     case DW_CFA_def_cfa:
1976       return "DW_CFA_def_cfa";
1977     case DW_CFA_def_cfa_register:
1978       return "DW_CFA_def_cfa_register";
1979     case DW_CFA_def_cfa_offset:
1980       return "DW_CFA_def_cfa_offset";
1981     /* SGI/MIPS specific */
1982     case DW_CFA_MIPS_advance_loc8:
1983       return "DW_CFA_MIPS_advance_loc8";
1984     default:
1985       return "DW_CFA_<unknown>";
1986     }
1987 }
1988 \f
1989 /* Determine the "ultimate origin" of a decl.  The decl may be an inlined
1990    instance of an inlined instance of a decl which is local to an inline
1991    function, so we have to trace all of the way back through the origin chain
1992    to find out what sort of node actually served as the original seed for the
1993    given block.  */
1994
1995 static tree
1996 decl_ultimate_origin (decl)
1997      register tree decl;
1998 {
1999   register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl);
2000
2001   if (immediate_origin == NULL_TREE || immediate_origin == decl)
2002     return NULL_TREE;
2003   else
2004     {
2005       register tree ret_val;
2006       register tree lookahead = immediate_origin;
2007
2008       do
2009         {
2010           ret_val = lookahead;
2011           lookahead = DECL_ABSTRACT_ORIGIN (ret_val);
2012         }
2013       while (lookahead != NULL && lookahead != ret_val);
2014
2015       return ret_val;
2016     }
2017 }
2018
2019 /* Determine the "ultimate origin" of a block.  The block may be an inlined
2020    instance of an inlined instance of a block which is local to an inline
2021    function, so we have to trace all of the way back through the origin chain
2022    to find out what sort of node actually served as the original seed for the
2023    given block.  */
2024
2025 static tree
2026 block_ultimate_origin (block)
2027      register tree block;
2028 {
2029   register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
2030
2031   if (immediate_origin == NULL_TREE)
2032     return NULL_TREE;
2033   else
2034     {
2035       register tree ret_val;
2036       register tree lookahead = immediate_origin;
2037
2038       do
2039         {
2040           ret_val = lookahead;
2041           lookahead = (TREE_CODE (ret_val) == BLOCK)
2042             ? BLOCK_ABSTRACT_ORIGIN (ret_val)
2043             : NULL;
2044         }
2045       while (lookahead != NULL && lookahead != ret_val);
2046
2047       return ret_val;
2048     }
2049 }
2050
2051 /* Get the class to which DECL belongs, if any.  In g++, the DECL_CONTEXT
2052    of a virtual function may refer to a base class, so we check the 'this'
2053    parameter.  */
2054
2055 static tree
2056 decl_class_context (decl)
2057      tree decl;
2058 {
2059   tree context = NULL_TREE;
2060
2061   if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
2062     context = DECL_CONTEXT (decl);
2063   else
2064     context = TYPE_MAIN_VARIANT
2065       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
2066
2067   if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
2068     context = NULL_TREE;
2069
2070   return context;
2071 }
2072 \f
2073 /* Add an attribute/value pair to a DIE */
2074
2075 static inline void
2076 add_dwarf_attr (die, attr)
2077      register dw_die_ref die;
2078      register dw_attr_ref attr;
2079 {
2080   if (die != NULL && attr != NULL)
2081     {
2082       if (die->die_attr == NULL)
2083         {
2084           die->die_attr = attr;
2085           die->die_attr_last = attr;
2086         }
2087       else
2088         {
2089           die->die_attr_last->dw_attr_next = attr;
2090           die->die_attr_last = attr;
2091         }
2092     }
2093 }
2094
2095 /* Add a flag value attribute to a DIE.  */
2096
2097 static inline void
2098 add_AT_flag (die, attr_kind, flag)
2099      register dw_die_ref die;
2100      register enum dwarf_attribute attr_kind;
2101      register unsigned flag;
2102 {
2103   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2104
2105   attr->dw_attr_next = NULL;
2106   attr->dw_attr = attr_kind;
2107   attr->dw_attr_val.val_class = dw_val_class_flag;
2108   attr->dw_attr_val.v.val_flag = flag;
2109   add_dwarf_attr (die, attr);
2110 }
2111
2112 /* Add a signed integer attribute value to a DIE.  */
2113
2114 static inline void
2115 add_AT_int (die, attr_kind, int_val)
2116      register dw_die_ref die;
2117      register enum dwarf_attribute attr_kind;
2118      register long int int_val;
2119 {
2120   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2121
2122   attr->dw_attr_next = NULL;
2123   attr->dw_attr = attr_kind;
2124   attr->dw_attr_val.val_class = dw_val_class_const;
2125   attr->dw_attr_val.v.val_int = int_val;
2126   add_dwarf_attr (die, attr);
2127 }
2128
2129 /* Add an unsigned integer attribute value to a DIE.  */
2130
2131 static inline void
2132 add_AT_unsigned (die, attr_kind, unsigned_val)
2133      register dw_die_ref die;
2134      register enum dwarf_attribute attr_kind;
2135      register unsigned long unsigned_val;
2136 {
2137   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2138
2139   attr->dw_attr_next = NULL;
2140   attr->dw_attr = attr_kind;
2141   attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
2142   attr->dw_attr_val.v.val_unsigned = unsigned_val;
2143   add_dwarf_attr (die, attr);
2144 }
2145
2146 /* Add an unsigned double integer attribute value to a DIE.  */
2147
2148 static inline void
2149 add_AT_long_long (die, attr_kind, val_hi, val_low)
2150      register dw_die_ref die;
2151      register enum dwarf_attribute attr_kind;
2152      register unsigned long val_hi;
2153      register unsigned long val_low;
2154 {
2155   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2156
2157   attr->dw_attr_next = NULL;
2158   attr->dw_attr = attr_kind;
2159   attr->dw_attr_val.val_class = dw_val_class_long_long;
2160   attr->dw_attr_val.v.val_long_long.hi = val_hi;
2161   attr->dw_attr_val.v.val_long_long.low = val_low;
2162   add_dwarf_attr (die, attr);
2163 }
2164
2165 /* Add a floating point attribute value to a DIE and return it.  */
2166
2167 static inline void
2168 add_AT_float (die, attr_kind, length, array)
2169      register dw_die_ref die;
2170      register enum dwarf_attribute attr_kind;
2171      register unsigned length;
2172      register long *array;
2173 {
2174   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2175
2176   attr->dw_attr_next = NULL;
2177   attr->dw_attr = attr_kind;
2178   attr->dw_attr_val.val_class = dw_val_class_float;
2179   attr->dw_attr_val.v.val_float.length = length;
2180   attr->dw_attr_val.v.val_float.array = array;
2181   add_dwarf_attr (die, attr);
2182 }
2183
2184 /* Add a string attribute value to a DIE.  */
2185
2186 static inline void
2187 add_AT_string (die, attr_kind, str)
2188      register dw_die_ref die;
2189      register enum dwarf_attribute attr_kind;
2190      register char *str;
2191 {
2192   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2193
2194   attr->dw_attr_next = NULL;
2195   attr->dw_attr = attr_kind;
2196   attr->dw_attr_val.val_class = dw_val_class_str;
2197   attr->dw_attr_val.v.val_str = xstrdup (str);
2198   add_dwarf_attr (die, attr);
2199 }
2200
2201 /* Add a DIE reference attribute value to a DIE.  */
2202
2203 static inline void
2204 add_AT_die_ref (die, attr_kind, targ_die)
2205      register dw_die_ref die;
2206      register enum dwarf_attribute attr_kind;
2207      register dw_die_ref targ_die;
2208 {
2209   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2210
2211   attr->dw_attr_next = NULL;
2212   attr->dw_attr = attr_kind;
2213   attr->dw_attr_val.val_class = dw_val_class_die_ref;
2214   attr->dw_attr_val.v.val_die_ref = targ_die;
2215   add_dwarf_attr (die, attr);
2216 }
2217
2218 /* Add an FDE reference attribute value to a DIE.  */
2219
2220 static inline void
2221 add_AT_fde_ref (die, attr_kind, targ_fde)
2222      register dw_die_ref die;
2223      register enum dwarf_attribute attr_kind;
2224      register unsigned targ_fde;
2225 {
2226   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2227
2228   attr->dw_attr_next = NULL;
2229   attr->dw_attr = attr_kind;
2230   attr->dw_attr_val.val_class = dw_val_class_fde_ref;
2231   attr->dw_attr_val.v.val_fde_index = targ_fde;
2232   add_dwarf_attr (die, attr);
2233 }
2234
2235 /* Add a location description attribute value to a DIE.  */
2236
2237 static inline void
2238 add_AT_loc (die, attr_kind, loc)
2239      register dw_die_ref die;
2240      register enum dwarf_attribute attr_kind;
2241      register dw_loc_descr_ref loc;
2242 {
2243   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2244
2245   attr->dw_attr_next = NULL;
2246   attr->dw_attr = attr_kind;
2247   attr->dw_attr_val.val_class = dw_val_class_loc;
2248   attr->dw_attr_val.v.val_loc = loc;
2249   add_dwarf_attr (die, attr);
2250 }
2251
2252 /* Add an address constant attribute value to a DIE.  */
2253
2254 static inline void
2255 add_AT_addr (die, attr_kind, addr)
2256      register dw_die_ref die;
2257      register enum dwarf_attribute attr_kind;
2258      char *addr;
2259 {
2260   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2261
2262   attr->dw_attr_next = NULL;
2263   attr->dw_attr = attr_kind;
2264   attr->dw_attr_val.val_class = dw_val_class_addr;
2265   attr->dw_attr_val.v.val_addr = addr;
2266   add_dwarf_attr (die, attr);
2267 }
2268
2269 /* Add a label identifier attribute value to a DIE.  */
2270
2271 static inline void
2272 add_AT_lbl_id (die, attr_kind, lbl_id)
2273      register dw_die_ref die;
2274      register enum dwarf_attribute attr_kind;
2275      register char *lbl_id;
2276 {
2277   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2278
2279   attr->dw_attr_next = NULL;
2280   attr->dw_attr = attr_kind;
2281   attr->dw_attr_val.val_class = dw_val_class_lbl_id;
2282   attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
2283   add_dwarf_attr (die, attr);
2284 }
2285
2286 /* Add a section offset attribute value to a DIE.  */
2287
2288 static inline void
2289 add_AT_section_offset (die, attr_kind, section)
2290      register dw_die_ref die;
2291      register enum dwarf_attribute attr_kind;
2292      register char *section;
2293 {
2294   register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2295
2296   attr->dw_attr_next = NULL;
2297   attr->dw_attr = attr_kind;
2298   attr->dw_attr_val.val_class = dw_val_class_section_offset;
2299   attr->dw_attr_val.v.val_section = section;
2300   add_dwarf_attr (die, attr);
2301   
2302 }
2303
2304 /* Test if die refers to an external subroutine.  */
2305
2306 static inline int
2307 is_extern_subr_die (die)
2308      register dw_die_ref die;
2309 {
2310   register dw_attr_ref a;
2311   register int is_subr = FALSE;
2312   register int is_extern = FALSE;
2313
2314   if (die != NULL && die->die_tag == DW_TAG_subprogram)
2315     {
2316       is_subr = TRUE;
2317       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2318         {
2319           if (a->dw_attr == DW_AT_external
2320               && a->dw_attr_val.val_class == dw_val_class_flag
2321               && a->dw_attr_val.v.val_flag != 0)
2322             {
2323               is_extern = TRUE;
2324               break;
2325             }
2326         }
2327     }
2328
2329   return is_subr && is_extern;
2330 }
2331
2332 /* Get the attribute of type attr_kind.  */
2333
2334 static inline dw_attr_ref
2335 get_AT (die, attr_kind)
2336      register dw_die_ref die;
2337      register enum dwarf_attribute attr_kind;
2338 {
2339   register dw_attr_ref a;
2340   register dw_die_ref spec = NULL;
2341   
2342   if (die != NULL)
2343     {
2344       for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2345         {
2346           if (a->dw_attr == attr_kind)
2347             return a;
2348
2349           if (a->dw_attr == DW_AT_specification
2350               || a->dw_attr == DW_AT_abstract_origin)
2351             spec = a->dw_attr_val.v.val_die_ref;
2352         }
2353
2354       if (spec)
2355         return get_AT (spec, attr_kind);
2356     }
2357
2358   return NULL;
2359 }
2360
2361 /* Return the "low pc" attribute value, typically associated with
2362    a subprogram DIE.  Return null if the "low pc" attribute is
2363    either not prsent, or if it cannot be represented as an
2364    assembler label identifier.  */
2365
2366 static inline char *
2367 get_AT_low_pc (die)
2368      register dw_die_ref die;
2369 {
2370   register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
2371
2372   if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2373     return a->dw_attr_val.v.val_lbl_id;
2374
2375   return NULL;
2376 }
2377
2378 /* Return the "high pc" attribute value, typically associated with
2379    a subprogram DIE.  Return null if the "high pc" attribute is
2380    either not prsent, or if it cannot be represented as an
2381    assembler label identifier.  */
2382
2383 static inline char *
2384 get_AT_hi_pc (die)
2385      register dw_die_ref die;
2386 {
2387   register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
2388
2389   if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
2390     return a->dw_attr_val.v.val_lbl_id;
2391
2392   return NULL;
2393 }
2394
2395 /* Return the value of the string attribute designated by ATTR_KIND, or
2396    NULL if it is not present.  */
2397
2398 static inline char *
2399 get_AT_string (die, attr_kind)
2400      register dw_die_ref die;
2401      register enum dwarf_attribute attr_kind;
2402 {
2403   register dw_attr_ref a = get_AT (die, attr_kind);
2404
2405   if (a && a->dw_attr_val.val_class == dw_val_class_str)
2406     return a->dw_attr_val.v.val_str;
2407
2408   return NULL;
2409 }
2410
2411 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
2412    if it is not present.  */
2413
2414 static inline int
2415 get_AT_flag (die, attr_kind)
2416      register dw_die_ref die;
2417      register enum dwarf_attribute attr_kind;
2418 {
2419   register dw_attr_ref a = get_AT (die, attr_kind);
2420
2421   if (a && a->dw_attr_val.val_class == dw_val_class_flag)
2422     return a->dw_attr_val.v.val_flag;
2423
2424   return -1;
2425 }
2426
2427 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
2428    if it is not present.  */
2429
2430 static inline unsigned
2431 get_AT_unsigned (die, attr_kind)
2432      register dw_die_ref die;
2433      register enum dwarf_attribute attr_kind;
2434 {
2435   register dw_attr_ref a = get_AT (die, attr_kind);
2436
2437   if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
2438     return a->dw_attr_val.v.val_unsigned;
2439
2440   return 0;
2441 }
2442
2443 static inline int
2444 is_c_family ()
2445 {
2446   register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2447
2448   return (lang == DW_LANG_C || lang == DW_LANG_C89
2449           || lang == DW_LANG_C_plus_plus);
2450
2451
2452 static inline int
2453 is_fortran ()
2454 {
2455   register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
2456
2457   return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
2458
2459
2460 /* Remove the specified attribute if present.  */
2461
2462 static inline void
2463 remove_AT (die, attr_kind)
2464      register dw_die_ref die;
2465      register enum dwarf_attribute attr_kind;
2466 {
2467   register dw_attr_ref a;
2468   register dw_attr_ref removed = NULL;;
2469
2470   if (die != NULL)
2471     {
2472       if (die->die_attr->dw_attr == attr_kind)
2473         {
2474           removed = die->die_attr;
2475           if (die->die_attr_last == die->die_attr)
2476             die->die_attr_last = NULL;
2477
2478           die->die_attr = die->die_attr->dw_attr_next;
2479         }
2480
2481       else
2482         for (a = die->die_attr; a->dw_attr_next != NULL;
2483              a = a->dw_attr_next)
2484           if (a->dw_attr_next->dw_attr == attr_kind)
2485             {
2486               removed = a->dw_attr_next;
2487               if (die->die_attr_last == a->dw_attr_next)
2488                 die->die_attr_last = a;
2489
2490               a->dw_attr_next = a->dw_attr_next->dw_attr_next;
2491               break;
2492             }
2493
2494       if (removed != 0)
2495         free (removed);
2496     }
2497 }
2498
2499 /* Discard the children of this DIE.  */
2500
2501 static inline void
2502 remove_children (die)
2503      register dw_die_ref die;
2504 {
2505   register dw_die_ref child_die = die->die_child;
2506
2507   die->die_child = NULL;
2508   die->die_child_last = NULL;
2509
2510   while (child_die != NULL)
2511     {
2512       register dw_die_ref tmp_die = child_die;
2513       register dw_attr_ref a;
2514
2515       child_die = child_die->die_sib;
2516       
2517       for (a = tmp_die->die_attr; a != NULL; )
2518         {
2519           register dw_attr_ref tmp_a = a;
2520
2521           a = a->dw_attr_next;
2522           free (tmp_a);
2523         }
2524
2525       free (tmp_die);
2526     }
2527 }
2528
2529 /* Add a child DIE below its parent.  */
2530
2531 static inline void
2532 add_child_die (die, child_die)
2533      register dw_die_ref die;
2534      register dw_die_ref child_die;
2535 {
2536   if (die != NULL && child_die != NULL)
2537     {
2538       assert (die != child_die);
2539       child_die->die_parent = die;
2540       child_die->die_sib = NULL;
2541
2542       if (die->die_child == NULL)
2543         {
2544           die->die_child = child_die;
2545           die->die_child_last = child_die;
2546         }
2547       else
2548         {
2549           die->die_child_last->die_sib = child_die;
2550           die->die_child_last = child_die;
2551         }
2552     }
2553 }
2554
2555 /* Return a pointer to a newly created DIE node.  */
2556
2557 static inline dw_die_ref
2558 new_die (tag_value, parent_die)
2559      register enum dwarf_tag tag_value;
2560      register dw_die_ref parent_die;
2561 {
2562   register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
2563
2564   die->die_tag = tag_value;
2565   die->die_abbrev = 0;
2566   die->die_offset = 0;
2567   die->die_child = NULL;
2568   die->die_parent = NULL;
2569   die->die_sib = NULL;
2570   die->die_child_last = NULL;
2571   die->die_attr = NULL;
2572   die->die_attr_last = NULL;
2573
2574   if (parent_die != NULL)
2575     add_child_die (parent_die, die);
2576   else
2577     ++limbo_die_count;
2578
2579   return die;
2580 }
2581
2582 /* Return the DIE associated with the given type specifier.  */
2583
2584 static inline dw_die_ref
2585 lookup_type_die (type)
2586      register tree type;
2587 {
2588   return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
2589 }
2590
2591 /* Equate a DIE to a given type specifier.  */
2592
2593 static void
2594 equate_type_number_to_die (type, type_die)
2595      register tree type;
2596      register dw_die_ref type_die;
2597 {
2598   TYPE_SYMTAB_POINTER (type) = (char *) type_die;
2599 }
2600
2601 /* Return the DIE associated with a given declaration.  */
2602
2603 static inline dw_die_ref
2604 lookup_decl_die (decl)
2605      register tree decl;
2606 {
2607   register unsigned decl_id = DECL_UID (decl);
2608
2609   return (decl_id < decl_die_table_in_use
2610           ? decl_die_table[decl_id] : NULL);
2611 }
2612
2613 /* Equate a DIE to a particular declaration.  */
2614
2615 static void
2616 equate_decl_number_to_die (decl, decl_die)
2617      register tree decl;
2618      register dw_die_ref decl_die;
2619 {
2620   register unsigned decl_id = DECL_UID (decl);
2621   register unsigned i;
2622   register unsigned num_allocated;
2623
2624   if (decl_id >= decl_die_table_allocated)
2625     {
2626       num_allocated
2627         = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
2628            / DECL_DIE_TABLE_INCREMENT)
2629           * DECL_DIE_TABLE_INCREMENT;
2630
2631       decl_die_table
2632         = (dw_die_ref *) xrealloc (decl_die_table,
2633                                    sizeof (dw_die_ref) * num_allocated);
2634
2635       bzero ((char *) &decl_die_table[decl_die_table_allocated],
2636              (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
2637       decl_die_table_allocated = num_allocated;
2638     }
2639
2640   if (decl_id >= decl_die_table_in_use)
2641     decl_die_table_in_use = (decl_id + 1);
2642
2643   decl_die_table[decl_id] = decl_die;
2644 }
2645
2646 /* Return a pointer to a newly allocated location description.  Location
2647    descriptions are simple expression terms that can be strung
2648    together to form more complicated location (address) descriptions.  */
2649
2650 static inline dw_loc_descr_ref
2651 new_loc_descr (op, oprnd1, oprnd2)
2652      register enum dwarf_location_atom op;
2653      register unsigned long oprnd1;
2654      register unsigned long oprnd2;
2655 {
2656   register dw_loc_descr_ref descr
2657     = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
2658
2659   descr->dw_loc_next = NULL;
2660   descr->dw_loc_opc = op;
2661   descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2662   descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2663   descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2664   descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2665
2666   return descr;
2667 }
2668
2669 /* Add a location description term to a location description expression.  */
2670
2671 static inline void
2672 add_loc_descr (list_head, descr)
2673      register dw_loc_descr_ref *list_head;
2674      register dw_loc_descr_ref descr;
2675 {
2676   register dw_loc_descr_ref *d;
2677
2678   /* Find the end of the chain.  */
2679   for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2680     ;
2681
2682   *d = descr;
2683 }
2684
2685 /* Return a pointer to a newly allocated Call Frame Instruction.  */
2686
2687 static inline dw_cfi_ref
2688 new_cfi ()
2689 {
2690   register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
2691
2692   cfi->dw_cfi_next = NULL;
2693   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
2694   cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
2695
2696   return cfi;
2697 }
2698
2699 /* Add a Call Frame Instruction to list of instructions.  */
2700
2701 static inline void
2702 add_cfi (list_head, cfi)
2703      register dw_cfi_ref *list_head;
2704      register dw_cfi_ref cfi;
2705 {
2706   register dw_cfi_ref *p;
2707
2708   /* Find the end of the chain.  */
2709   for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
2710     ;
2711
2712   *p = cfi;
2713 }
2714 \f
2715 /* Keep track of the number of spaces used to indent the
2716    output of the debugging routines that print the structure of
2717    the DIE internal representation.  */
2718 static int print_indent;
2719
2720 /* Indent the line the number of spaces given by print_indent.  */
2721
2722 static inline void
2723 print_spaces (outfile)
2724      FILE *outfile;
2725 {
2726   fprintf (outfile, "%*s", print_indent, "");
2727 }
2728
2729 /* Print the information assoaciated with a given DIE, and its children.
2730    This routine is a debugging aid only.  */
2731
2732 static void
2733 print_die (die, outfile)
2734      dw_die_ref die;
2735      FILE *outfile;
2736 {
2737   register dw_attr_ref a;
2738   register dw_die_ref c;
2739
2740   print_spaces (outfile);
2741   fprintf (outfile, "DIE %4u: %s\n",
2742            die->die_offset, dwarf_tag_name (die->die_tag));
2743   print_spaces (outfile);
2744   fprintf (outfile, "  abbrev id: %u", die->die_abbrev);
2745   fprintf (outfile, " offset: %u\n", die->die_offset);
2746
2747   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
2748     {
2749       print_spaces (outfile);
2750       fprintf (outfile, "  %s: ", dwarf_attr_name (a->dw_attr));
2751
2752       switch (a->dw_attr_val.val_class)
2753         {
2754         case dw_val_class_addr:
2755           fprintf (outfile, "address");
2756           break;
2757         case dw_val_class_loc:
2758           fprintf (outfile, "location descriptor");
2759           break;
2760         case dw_val_class_const:
2761           fprintf (outfile, "%d", a->dw_attr_val.v.val_int);
2762           break;
2763         case dw_val_class_unsigned_const:
2764           fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned);
2765           break;
2766         case dw_val_class_long_long:
2767           fprintf (outfile, "constant (%u,%u)",
2768                   a->dw_attr_val.v.val_long_long.hi,
2769                   a->dw_attr_val.v.val_long_long.low);
2770           break;
2771         case dw_val_class_float:
2772           fprintf (outfile, "floating-point constant");
2773           break;
2774         case dw_val_class_flag:
2775           fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
2776           break;
2777         case dw_val_class_die_ref:
2778           if (a->dw_attr_val.v.val_die_ref != NULL)
2779             fprintf (outfile, "die -> %u",
2780                      a->dw_attr_val.v.val_die_ref->die_offset);
2781           else
2782             fprintf (outfile, "die -> <null>");
2783           break;
2784         case dw_val_class_lbl_id:
2785           fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
2786           break;
2787         case dw_val_class_section_offset:
2788           fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section);
2789           break;
2790         case dw_val_class_str:
2791           if (a->dw_attr_val.v.val_str != NULL)
2792             fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
2793           else
2794             fprintf (outfile, "<null>");
2795           break;
2796         }
2797
2798       fprintf (outfile, "\n");
2799     }
2800
2801   if (die->die_child != NULL)
2802     {
2803       print_indent += 4;
2804       for (c = die->die_child; c != NULL; c = c->die_sib)
2805         print_die (c, outfile);
2806
2807       print_indent -= 4;
2808     }
2809 }
2810
2811 /* Print the contents of the source code line number correspondence table.
2812    This routine is a debugging aid only.  */
2813
2814 static void
2815 print_dwarf_line_table (outfile)
2816      FILE *outfile;
2817 {
2818   register unsigned i;
2819   register dw_line_info_ref line_info;
2820
2821   fprintf (outfile, "\n\nDWARF source line information\n");
2822   for (i = 1; i < line_info_table_in_use; ++i)
2823     {
2824       line_info = &line_info_table[i];
2825       fprintf (outfile, "%5d: ", i);
2826       fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
2827       fprintf (outfile, "%6d", line_info->dw_line_num);
2828       fprintf (outfile, "\n");
2829     }
2830
2831   fprintf (outfile, "\n\n");
2832 }
2833
2834 /* Print the information collected for a given DIE.  */
2835
2836 void
2837 debug_dwarf_die (die)
2838      dw_die_ref die;
2839 {
2840   print_die (die, stderr);
2841 }
2842
2843 /* Print all DWARF information collected for the compilation unit.
2844    This routine is a debugging aid only.  */
2845
2846 void
2847 debug_dwarf ()
2848 {
2849   print_indent = 0;
2850   print_die (comp_unit_die, stderr);
2851   print_dwarf_line_table (stderr);
2852 }
2853 \f
2854 /* Traverse the DIE, and add a sibling attribute if it may have the
2855    effect of speeding up access to siblings.  To save some space,
2856    avoid generating sibling attributes for DIE's without children.  */
2857
2858 static void
2859 add_sibling_attributes(die)
2860      register dw_die_ref die;
2861 {
2862   register dw_die_ref c;
2863   register dw_attr_ref attr;
2864   if (die != comp_unit_die && die->die_child != NULL)
2865     {
2866       attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
2867       attr->dw_attr_next = NULL;
2868       attr->dw_attr = DW_AT_sibling;
2869       attr->dw_attr_val.val_class = dw_val_class_die_ref;
2870       attr->dw_attr_val.v.val_die_ref = die->die_sib;
2871
2872       /* Add the sibling link to the front of the attribute list.  */
2873       attr->dw_attr_next = die->die_attr;
2874       if (die->die_attr == NULL)
2875         die->die_attr_last = attr;
2876
2877       die->die_attr = attr;
2878     }
2879
2880   for (c = die->die_child; c != NULL; c = c->die_sib)
2881     add_sibling_attributes (c);
2882 }
2883
2884 /* The format of each DIE (and its attribute value pairs)
2885    is encoded in an abbreviation table.  This routine builds the
2886    abbreviation table and assigns a unique abbreviation id for
2887    each abbreviation entry.  The children of each die are visited
2888    recursively.  */
2889
2890 static void
2891 build_abbrev_table (die)
2892      register dw_die_ref die;
2893 {
2894   register unsigned long abbrev_id;
2895   register unsigned long n_alloc;
2896   register dw_die_ref c;
2897   register dw_attr_ref d_attr, a_attr;
2898   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
2899     {
2900       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
2901
2902       if (abbrev->die_tag == die->die_tag)
2903         {
2904           if ((abbrev->die_child != NULL) == (die->die_child != NULL))
2905             {
2906               a_attr = abbrev->die_attr;
2907               d_attr = die->die_attr;
2908
2909               while (a_attr != NULL && d_attr != NULL)
2910                 {
2911                   if ((a_attr->dw_attr != d_attr->dw_attr)
2912                       || (value_format (&a_attr->dw_attr_val)
2913                           != value_format (&d_attr->dw_attr_val)))
2914                     break;
2915
2916                   a_attr = a_attr->dw_attr_next;
2917                   d_attr = d_attr->dw_attr_next;
2918                 }
2919
2920               if (a_attr == NULL && d_attr == NULL)
2921                 break;
2922             }
2923         }
2924     }
2925
2926   if (abbrev_id >= abbrev_die_table_in_use)
2927     {
2928       if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
2929         {
2930           n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
2931           abbrev_die_table 
2932             = (dw_die_ref *) xmalloc (abbrev_die_table,
2933                                       sizeof (dw_die_ref) * n_alloc);
2934
2935           bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
2936                  (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
2937           abbrev_die_table_allocated = n_alloc;
2938         }
2939
2940       ++abbrev_die_table_in_use;
2941       abbrev_die_table[abbrev_id] = die;
2942     }
2943
2944   die->die_abbrev = abbrev_id;
2945   for (c = die->die_child; c != NULL; c = c->die_sib)
2946     build_abbrev_table (c);
2947 }
2948 \f
2949 /* Return the size of an unsigned LEB128 quantity.  */
2950
2951 static inline unsigned long
2952 size_of_uleb128 (value)
2953      register unsigned long value;
2954 {
2955   register unsigned long size = 0;
2956   register unsigned byte;
2957
2958   do
2959     {
2960       byte = (value & 0x7f);
2961       value >>= 7;
2962       size += 1;
2963     }
2964   while (value != 0);
2965
2966   return size;
2967 }
2968
2969 /* Return the size of a signed LEB128 quantity.  */
2970
2971 static inline unsigned long
2972 size_of_sleb128 (value)
2973      register long value;
2974 {
2975   register unsigned long size = 0;
2976   register unsigned byte;
2977
2978   do
2979     {
2980       byte = (value & 0x7f);
2981       value >>= 7;
2982       size += 1;
2983     }
2984   while (!(((value == 0) && ((byte & 0x40) == 0))
2985            || ((value == -1) && ((byte & 0x40) != 0))));
2986
2987   return size;
2988 }
2989
2990 /* Return the size of a string, including the null byte.  */
2991
2992 static unsigned long
2993 size_of_string (str)
2994      register char *str;
2995 {
2996   register unsigned long size = 0;
2997   register unsigned long slen = strlen (str);
2998   register unsigned long i;
2999   register unsigned c;
3000
3001   for (i = 0; i < slen; ++i)
3002     {
3003       c = str[i];
3004       if (c == '\\')
3005         ++i;
3006
3007       size += 1;
3008     }
3009
3010   /* Null terminator.  */
3011   size += 1;
3012   return size;
3013 }
3014
3015 /* Return the size of a location descriptor.  */
3016
3017 static unsigned long
3018 size_of_loc_descr (loc)
3019      register dw_loc_descr_ref loc;
3020 {
3021   register unsigned long size = 1;
3022
3023   switch (loc->dw_loc_opc)
3024     {
3025     case DW_OP_addr:
3026       size += PTR_SIZE;
3027       break;
3028     case DW_OP_const1u:
3029     case DW_OP_const1s:
3030       size += 1;
3031       break;
3032     case DW_OP_const2u:
3033     case DW_OP_const2s:
3034       size += 2;
3035       break;
3036     case DW_OP_const4u:
3037     case DW_OP_const4s:
3038       size += 4;
3039       break;
3040     case DW_OP_const8u:
3041     case DW_OP_const8s:
3042       size += 8;
3043       break;
3044     case DW_OP_constu:
3045       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3046       break;
3047     case DW_OP_consts:
3048       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3049       break;
3050     case DW_OP_pick:
3051       size += 1;
3052       break;
3053     case DW_OP_plus_uconst:
3054       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3055       break;
3056     case DW_OP_skip:
3057     case DW_OP_bra:
3058       size += 2;
3059       break;
3060     case DW_OP_breg0:
3061     case DW_OP_breg1:
3062     case DW_OP_breg2:
3063     case DW_OP_breg3:
3064     case DW_OP_breg4:
3065     case DW_OP_breg5:
3066     case DW_OP_breg6:
3067     case DW_OP_breg7:
3068     case DW_OP_breg8:
3069     case DW_OP_breg9:
3070     case DW_OP_breg10:
3071     case DW_OP_breg11:
3072     case DW_OP_breg12:
3073     case DW_OP_breg13:
3074     case DW_OP_breg14:
3075     case DW_OP_breg15:
3076     case DW_OP_breg16:
3077     case DW_OP_breg17:
3078     case DW_OP_breg18:
3079     case DW_OP_breg19:
3080     case DW_OP_breg20:
3081     case DW_OP_breg21:
3082     case DW_OP_breg22:
3083     case DW_OP_breg23:
3084     case DW_OP_breg24:
3085     case DW_OP_breg25:
3086     case DW_OP_breg26:
3087     case DW_OP_breg27:
3088     case DW_OP_breg28:
3089     case DW_OP_breg29:
3090     case DW_OP_breg30:
3091     case DW_OP_breg31:
3092       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3093       break;
3094     case DW_OP_regx:
3095       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3096       break;
3097     case DW_OP_fbreg:
3098       size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3099       break;
3100     case DW_OP_bregx:
3101       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3102       size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3103       break;
3104     case DW_OP_piece:
3105       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3106       break;
3107     case DW_OP_deref_size:
3108     case DW_OP_xderef_size:
3109       size += 1;
3110       break;
3111     default:
3112       break;
3113     }
3114
3115   return size;
3116 }
3117
3118 /* Return the size of a series of location descriptors.  */
3119
3120 static unsigned long
3121 size_of_locs (loc)
3122      register dw_loc_descr_ref loc;
3123 {
3124   register unsigned long size = 0;
3125
3126   for (; loc != NULL; loc = loc->dw_loc_next)
3127     size += size_of_loc_descr (loc);
3128
3129   return size;
3130 }
3131
3132 /* Return the power-of-two number of bytes necessary to represent VALUE.  */
3133
3134 static int
3135 constant_size (value)
3136      long unsigned value;
3137 {
3138   int log;
3139
3140   if (value == 0)
3141     log = 0;
3142   else
3143     log = floor_log2 (value);
3144
3145   log = log / 8;
3146   log = 1 << (floor_log2 (log) + 1);
3147
3148   return MIN (log, 4);
3149 }
3150
3151 /* Return the size of a DIE, as it is represented in the
3152    .debug_info section.  */
3153
3154 static unsigned long
3155 size_of_die (die)
3156      register dw_die_ref die;
3157 {
3158   register unsigned long size = 0;
3159   register dw_attr_ref a;
3160
3161   size += size_of_uleb128 (die->die_abbrev);
3162   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3163     {
3164       switch (a->dw_attr_val.val_class)
3165         {
3166         case dw_val_class_addr:
3167           size += PTR_SIZE;
3168           break;
3169         case dw_val_class_loc:
3170           {
3171             register unsigned long lsize
3172               = size_of_locs (a->dw_attr_val.v.val_loc);
3173
3174             /* Block length.  */
3175             size += constant_size (lsize);
3176             size += lsize;
3177           }
3178           break;
3179         case dw_val_class_const:
3180           size += 4;
3181           break;
3182         case dw_val_class_unsigned_const:
3183           size += constant_size (a->dw_attr_val.v.val_unsigned);
3184           break;
3185         case dw_val_class_long_long:
3186           size += 1 + 8; /* block */
3187           break;
3188         case dw_val_class_float:
3189           size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
3190           break;
3191         case dw_val_class_flag:
3192           size += 1;
3193           break;
3194         case dw_val_class_die_ref:
3195           size += DWARF_OFFSET_SIZE;
3196           break;
3197         case dw_val_class_fde_ref:
3198           size += DWARF_OFFSET_SIZE;
3199           break;
3200         case dw_val_class_lbl_id:
3201           size += PTR_SIZE;
3202           break;
3203         case dw_val_class_section_offset:
3204           size += DWARF_OFFSET_SIZE;
3205           break;
3206         case dw_val_class_str:
3207           size += size_of_string (a->dw_attr_val.v.val_str);
3208           break;
3209         default:
3210           abort ();
3211         }
3212     }
3213
3214   return size;
3215 }
3216
3217 /* Size the debgging information associted with a given DIE.
3218    Visits the DIE's children recursively.  Updates the global
3219    variable next_die_offset, on each time through.  Uses the
3220    current value of next_die_offset to updete the die_offset
3221    field in each DIE.  */
3222
3223 static void
3224 calc_die_sizes (die)
3225      dw_die_ref die;
3226 {
3227   register dw_die_ref c;
3228   die->die_offset = next_die_offset;
3229   next_die_offset += size_of_die (die);
3230
3231   for (c = die->die_child; c != NULL; c = c->die_sib)
3232     calc_die_sizes (c);
3233
3234   if (die->die_child != NULL)
3235     /* Count the null byte used to terminate sibling lists.  */
3236     next_die_offset += 1;
3237 }
3238
3239 /* Return the size of the line information prolog generated for the
3240    compilation unit.  */
3241
3242 static unsigned long
3243 size_of_line_prolog ()
3244 {
3245   register unsigned long size;
3246   register unsigned long ft_index;
3247
3248   size = DWARF_LINE_PROLOG_HEADER_SIZE;
3249
3250   /* Count the size of the table giving number of args for each
3251      standard opcode.  */
3252   size += DWARF_LINE_OPCODE_BASE - 1;
3253
3254   /* Include directory table is empty (at present).  Count only the
3255      the null byte used to terminate the table.  */
3256   size += 1;
3257
3258   for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
3259     {
3260       /* File name entry.  */
3261       size += size_of_string (file_table[ft_index]);
3262
3263       /* Include directory index.  */
3264       size += size_of_uleb128 (0);
3265
3266       /* Modification time.  */
3267       size += size_of_uleb128 (0);
3268
3269       /* File length in bytes.  */
3270       size += size_of_uleb128 (0);
3271     }
3272
3273   /* Count the file table terminator.  */
3274   size += 1;
3275   return size;
3276 }
3277
3278 /* Return the size of the line information generated for this
3279    compilation unit.  */
3280
3281 static unsigned long
3282 size_of_line_info ()
3283 {
3284   register unsigned long size;
3285   register unsigned long lt_index;
3286   register unsigned long current_line;
3287   register long line_offset;
3288   register long line_delta;
3289   register unsigned long current_file;
3290   register unsigned long function;
3291
3292   /* Version number.  */
3293   size = 2;
3294
3295   /* Prolog length specifier.  */
3296   size += DWARF_OFFSET_SIZE;
3297
3298   /* Prolog.  */
3299   size += size_of_line_prolog ();
3300
3301   /* Set address register instruction.  */
3302   size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
3303
3304   current_file = 1;
3305   current_line = 1;
3306   for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
3307     {
3308       register dw_line_info_ref line_info;
3309
3310       /* Advance pc instruction.  */
3311       size += 1 + 2;
3312       line_info = &line_info_table[lt_index];
3313       if (line_info->dw_file_num != current_file)
3314         {
3315           /* Set file number instruction.  */
3316           size += 1;
3317           current_file = line_info->dw_file_num;
3318           size += size_of_uleb128 (current_file);
3319         }
3320
3321       if (line_info->dw_line_num != current_line)
3322         {
3323           line_offset = line_info->dw_line_num - current_line;
3324           line_delta = line_offset - DWARF_LINE_BASE;
3325           current_line = line_info->dw_line_num;
3326           if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3327             /* 1-byte special line number instruction.  */
3328             size += 1;
3329           else
3330             {
3331               /* Advance line instruction.  */
3332               size += 1;
3333               size += size_of_sleb128 (line_offset);
3334               /* Generate line entry instruction.  */
3335               size += 1;
3336             }
3337         }
3338     }
3339
3340   /* Advance pc instruction.  */
3341   size += 1 + 2;
3342
3343   /* End of line number info. marker.  */
3344   size += 1 + size_of_uleb128 (1) + 1;
3345
3346   function = 0;
3347   current_file = 1;
3348   current_line = 1;
3349   for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
3350     {
3351       register dw_separate_line_info_ref line_info
3352         = &separate_line_info_table[lt_index];
3353       if (function != line_info->function)
3354         {
3355           function = line_info->function;
3356           /* Set address register instruction.  */
3357           size += 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE;
3358         }
3359       else
3360         /* Advance pc instruction.  */
3361         size += 1 + 2;
3362
3363       if (line_info->dw_file_num != current_file)
3364         {
3365           /* Set file number instruction.  */
3366           size += 1;
3367           current_file = line_info->dw_file_num;
3368           size += size_of_uleb128 (current_file);
3369         }
3370
3371       if (line_info->dw_line_num != current_line)
3372         {
3373           line_offset = line_info->dw_line_num - current_line;
3374           line_delta = line_offset - DWARF_LINE_BASE;
3375           current_line = line_info->dw_line_num;
3376           if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
3377             /* 1-byte special line number instruction.  */
3378             size += 1;
3379           else
3380             {
3381               /* Advance line instruction.  */
3382               size += 1;
3383               size += size_of_sleb128 (line_offset);
3384
3385               /* Generate line entry instruction.  */
3386               size += 1;
3387             }
3388         }
3389
3390       ++lt_index;
3391
3392       /* If we're done with a function, end its sequence.  */
3393       if (lt_index == separate_line_info_table_in_use
3394           || separate_line_info_table[lt_index].function != function)
3395         {
3396           current_file = 1;
3397           current_line = 1;
3398
3399           /* Advance pc instruction.  */
3400           size += 1 + 2;
3401
3402           /* End of line number info. marker.  */
3403           size += 1 + size_of_uleb128 (1) + 1;
3404         }
3405     }
3406
3407   return size;
3408 }
3409
3410 /* Return the size of the .debug_pubnames table  generated for the
3411    compilation unit.  */
3412
3413 static unsigned long
3414 size_of_pubnames ()
3415 {
3416   register unsigned long size;
3417   register unsigned i;
3418
3419   size = DWARF_PUBNAMES_HEADER_SIZE;
3420   for (i = 0; i < pubname_table_in_use; ++i)
3421     {
3422       register pubname_ref p = &pubname_table[i];
3423       size += DWARF_OFFSET_SIZE + size_of_string (p->name);
3424     }
3425
3426   size += DWARF_OFFSET_SIZE;
3427   return size;
3428 }
3429
3430 /* Return the size of the information in the .debug_aranges seciton.  */
3431
3432 static unsigned long
3433 size_of_aranges ()
3434 {
3435   register unsigned long size;
3436
3437   size = DWARF_ARANGES_HEADER_SIZE;
3438
3439   /* Count the address/length pair for this compilation unit.  */
3440   size += 2 * PTR_SIZE;
3441   size += 2 * PTR_SIZE * arange_table_in_use;
3442
3443   /* Count the two zero words used to terminated the address range table.  */
3444   size += 2 * PTR_SIZE;
3445   return size;
3446 }
3447 \f
3448 /* Output an unsigned LEB128 quantity.  */
3449
3450 static void
3451 output_uleb128 (value)
3452      register unsigned long value;
3453 {
3454   unsigned long save_value = value;
3455
3456   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3457   do
3458     {
3459       register unsigned byte = (value & 0x7f);
3460       value >>= 7;
3461       if (value != 0)
3462         /* More bytes to follow.  */
3463         byte |= 0x80;
3464
3465       fprintf (asm_out_file, "0x%x", byte);
3466       if (value != 0)
3467         fprintf (asm_out_file, ",");
3468     }
3469   while (value != 0);
3470
3471   if (flag_verbose_asm)
3472     fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value);
3473 }
3474
3475 /* Output an signed LEB128 quantity.  */
3476
3477 static void
3478 output_sleb128 (value)
3479      register long value;
3480 {
3481   register int more;
3482   register unsigned byte;
3483   long save_value = value;
3484
3485   fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
3486   do
3487     {
3488       byte = (value & 0x7f);
3489       /* arithmetic shift */
3490       value >>= 7;
3491       more = !((((value == 0) && ((byte & 0x40) == 0))
3492                 || ((value == -1) && ((byte & 0x40) != 0))));
3493       if (more)
3494         byte |= 0x80;
3495
3496       fprintf (asm_out_file, "0x%x", byte);
3497       if (more)
3498         fprintf (asm_out_file, ",");
3499     }
3500
3501   while (more);
3502   if (flag_verbose_asm)
3503     fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value);
3504 }
3505
3506 /* Select the encoding of an attribute value.  */
3507
3508 static enum dwarf_form
3509 value_format (v)
3510      dw_val_ref v;
3511 {
3512   switch (v->val_class)
3513     {
3514     case dw_val_class_addr:
3515       return DW_FORM_addr;
3516     case dw_val_class_loc:
3517       switch (constant_size (size_of_locs (v->v.val_loc)))
3518         {
3519         case 1:
3520           return DW_FORM_block1;
3521         case 2:
3522           return DW_FORM_block2;
3523         default:
3524           abort ();
3525         }
3526     case dw_val_class_const:
3527       return DW_FORM_data4;
3528     case dw_val_class_unsigned_const:
3529       switch (constant_size (v->v.val_unsigned))
3530         {
3531         case 1:
3532           return DW_FORM_data1;
3533         case 2:
3534           return DW_FORM_data2;
3535         case 4:
3536           return DW_FORM_data4;
3537         case 8:
3538           return DW_FORM_data8;
3539         default:
3540           abort ();
3541         }
3542     case dw_val_class_long_long:
3543       return DW_FORM_block1;
3544     case dw_val_class_float:
3545       return DW_FORM_block1;
3546     case dw_val_class_flag:
3547       return DW_FORM_flag;
3548     case dw_val_class_die_ref:
3549       return DW_FORM_ref;
3550     case dw_val_class_fde_ref:
3551       return DW_FORM_data;
3552     case dw_val_class_lbl_id:
3553       return DW_FORM_addr;
3554     case dw_val_class_section_offset:
3555       return DW_FORM_data;
3556     case dw_val_class_str:
3557       return DW_FORM_string;
3558     default:
3559       abort ();
3560     }
3561 }
3562
3563 /* Output the encoding of an attribute value.  */
3564
3565 static void
3566 output_value_format (v)
3567      dw_val_ref v;
3568 {
3569   enum dwarf_form form = value_format (v);
3570
3571   output_uleb128 (form);
3572   if (flag_verbose_asm)
3573     fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
3574
3575   fputc ('\n', asm_out_file);
3576 }
3577
3578 /* Output the .debug_abbrev section which defines the DIE abbreviation
3579    table.  */
3580
3581 static void
3582 output_abbrev_section ()
3583 {
3584   unsigned long abbrev_id;
3585
3586   dw_attr_ref a_attr;
3587   for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
3588     {
3589       register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
3590
3591       output_uleb128 (abbrev_id);
3592       if (flag_verbose_asm)
3593         fprintf (asm_out_file, " (abbrev code)");
3594
3595       fputc ('\n', asm_out_file);
3596       output_uleb128 (abbrev->die_tag);
3597       if (flag_verbose_asm)
3598         fprintf (asm_out_file, " (TAG: %s)",
3599                  dwarf_tag_name (abbrev->die_tag));
3600
3601       fputc ('\n', asm_out_file);
3602       fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
3603                abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
3604
3605       if (flag_verbose_asm)
3606         fprintf (asm_out_file, "\t%s %s",
3607                  ASM_COMMENT_START,
3608                  (abbrev->die_child != NULL
3609                   ? "DW_children_yes" : "DW_children_no"));
3610
3611       fputc ('\n', asm_out_file);
3612
3613       for (a_attr = abbrev->die_attr; a_attr != NULL;
3614            a_attr = a_attr->dw_attr_next)
3615         {
3616           output_uleb128 (a_attr->dw_attr);
3617           if (flag_verbose_asm)
3618             fprintf (asm_out_file, " (%s)",
3619                      dwarf_attr_name (a_attr->dw_attr));
3620
3621           fputc ('\n', asm_out_file);
3622           output_value_format (&a_attr->dw_attr_val);
3623         }
3624
3625       fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
3626     }
3627 }
3628
3629 /* Output location description stack opcode's operands (if any).  */
3630
3631 static void
3632 output_loc_operands (loc)
3633      register dw_loc_descr_ref loc;
3634 {
3635   register dw_val_ref val1 = &loc->dw_loc_oprnd1;
3636   register dw_val_ref val2 = &loc->dw_loc_oprnd2;
3637
3638   switch (loc->dw_loc_opc)
3639     {
3640     case DW_OP_addr:
3641       ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
3642       fputc ('\n', asm_out_file);
3643       break;
3644     case DW_OP_const1u:
3645     case DW_OP_const1s:
3646       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3647       fputc ('\n', asm_out_file);
3648       break;
3649     case DW_OP_const2u:
3650     case DW_OP_const2s:
3651       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3652       fputc ('\n', asm_out_file);
3653       break;
3654     case DW_OP_const4u:
3655     case DW_OP_const4s:
3656       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
3657       fputc ('\n', asm_out_file);
3658       break;
3659     case DW_OP_const8u:
3660     case DW_OP_const8s:
3661       abort ();
3662       fputc ('\n', asm_out_file);
3663       break;
3664     case DW_OP_constu:
3665       output_uleb128 (val1->v.val_unsigned);
3666       fputc ('\n', asm_out_file);
3667       break;
3668     case DW_OP_consts:
3669       output_sleb128 (val1->v.val_int);
3670       fputc ('\n', asm_out_file);
3671       break;
3672     case DW_OP_pick:
3673       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
3674       fputc ('\n', asm_out_file);
3675       break;
3676     case DW_OP_plus_uconst:
3677       output_uleb128 (val1->v.val_unsigned);
3678       fputc ('\n', asm_out_file);
3679       break;
3680     case DW_OP_skip:
3681     case DW_OP_bra:
3682       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
3683       fputc ('\n', asm_out_file);
3684       break;
3685     case DW_OP_breg0:
3686     case DW_OP_breg1:
3687     case DW_OP_breg2:
3688     case DW_OP_breg3:
3689     case DW_OP_breg4:
3690     case DW_OP_breg5:
3691     case DW_OP_breg6:
3692     case DW_OP_breg7:
3693     case DW_OP_breg8:
3694     case DW_OP_breg9:
3695     case DW_OP_breg10:
3696     case DW_OP_breg11:
3697     case DW_OP_breg12:
3698     case DW_OP_breg13:
3699     case DW_OP_breg14:
3700     case DW_OP_breg15:
3701     case DW_OP_breg16:
3702     case DW_OP_breg17:
3703     case DW_OP_breg18:
3704     case DW_OP_breg19:
3705     case DW_OP_breg20:
3706     case DW_OP_breg21:
3707     case DW_OP_breg22:
3708     case DW_OP_breg23:
3709     case DW_OP_breg24:
3710     case DW_OP_breg25:
3711     case DW_OP_breg26:
3712     case DW_OP_breg27:
3713     case DW_OP_breg28:
3714     case DW_OP_breg29:
3715     case DW_OP_breg30:
3716     case DW_OP_breg31:
3717       output_sleb128 (val1->v.val_int);
3718       fputc ('\n', asm_out_file);
3719       break;
3720     case DW_OP_regx:
3721       output_uleb128 (val1->v.val_unsigned);
3722       fputc ('\n', asm_out_file);
3723       break;
3724     case DW_OP_fbreg:
3725       output_sleb128 (val1->v.val_int);
3726       fputc ('\n', asm_out_file);
3727       break;
3728     case DW_OP_bregx:
3729       output_uleb128 (val1->v.val_unsigned);
3730       fputc ('\n', asm_out_file);
3731       output_sleb128 (val2->v.val_int);
3732       fputc ('\n', asm_out_file);
3733       break;
3734     case DW_OP_piece:
3735       output_uleb128 (val1->v.val_unsigned);
3736       fputc ('\n', asm_out_file);
3737       break;
3738     case DW_OP_deref_size:
3739     case DW_OP_xderef_size:
3740       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3741       fputc ('\n', asm_out_file);
3742       break;
3743     default:
3744       break;
3745     }
3746 }
3747
3748 /* Compute the offset of a sibling.  */
3749
3750 static unsigned long
3751 sibling_offset (die)
3752      dw_die_ref die;
3753 {
3754   unsigned long offset;
3755
3756   if (die->die_child_last == NULL)
3757     offset = die->die_offset + size_of_die (die);
3758   else
3759     offset = sibling_offset (die->die_child_last) + 1;
3760
3761   return offset;
3762 }
3763
3764 /* Output the DIE and its attributes.  Called recursively to generate
3765    the definitions of each child DIE.  */
3766
3767 static void
3768 output_die (die)
3769      register dw_die_ref die;
3770 {
3771   register dw_attr_ref a;
3772   register dw_die_ref c;
3773   register unsigned long ref_offset;
3774   register unsigned long size;
3775   register dw_loc_descr_ref loc;
3776   register int i;
3777
3778   output_uleb128 (die->die_abbrev);
3779   if (flag_verbose_asm)
3780     fprintf (asm_out_file, " (DIE (0x%x) %s)",
3781              die->die_offset, dwarf_tag_name (die->die_tag));
3782
3783   fputc ('\n', asm_out_file);
3784
3785   for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3786     {
3787       switch (a->dw_attr_val.val_class)
3788         {
3789         case dw_val_class_addr:
3790           ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
3791                                        a->dw_attr_val.v.val_addr);
3792           break;
3793
3794         case dw_val_class_loc:
3795           size = size_of_locs (a->dw_attr_val.v.val_loc);
3796
3797           /* Output the block length for this list of location operations.  */
3798           switch (constant_size (size))
3799             {
3800             case 1:
3801               ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
3802               break;
3803             case 2:
3804               ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
3805               break;
3806             default:
3807               abort ();
3808             }
3809
3810           if (flag_verbose_asm)
3811             fprintf (asm_out_file, "\t%s %s",
3812                      ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3813
3814           fputc ('\n', asm_out_file);
3815           for (loc = a->dw_attr_val.v.val_loc; loc != NULL;
3816                loc = loc->dw_loc_next)
3817             {
3818               /* Output the opcode.  */
3819               ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3820               if (flag_verbose_asm)
3821                 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
3822                          dwarf_stack_op_name (loc->dw_loc_opc));
3823
3824               fputc ('\n', asm_out_file);
3825
3826               /* Output the operand(s) (if any).  */
3827               output_loc_operands (loc);
3828             }
3829           break;
3830
3831         case dw_val_class_const:
3832           ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
3833           break;
3834
3835         case dw_val_class_unsigned_const:
3836           switch (constant_size (a->dw_attr_val.v.val_unsigned))
3837             {
3838             case 1:
3839               ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3840                                       a->dw_attr_val.v.val_unsigned);
3841               break;
3842             case 2:
3843               ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
3844                                       a->dw_attr_val.v.val_unsigned);
3845               break;
3846             case 4:
3847               ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3848                                       a->dw_attr_val.v.val_unsigned);
3849               break;
3850             default:
3851               abort ();
3852             }
3853           break;
3854
3855         case dw_val_class_long_long:
3856           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
3857           if (flag_verbose_asm)
3858             fprintf (asm_out_file, "\t%s %s",
3859                    ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3860
3861           fputc ('\n', asm_out_file);
3862           ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
3863                                   a->dw_attr_val.v.val_long_long.hi,
3864                                   a->dw_attr_val.v.val_long_long.low);
3865
3866           if (flag_verbose_asm)
3867             fprintf (asm_out_file,
3868                      "\t%s long long constant", ASM_COMMENT_START);
3869           
3870           fputc ('\n', asm_out_file);
3871           break;
3872
3873         case dw_val_class_float:
3874           ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
3875                                   a->dw_attr_val.v.val_float.length * 4);
3876           if (flag_verbose_asm)
3877             fprintf (asm_out_file, "\t%s %s",
3878                      ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3879
3880           fputc ('\n', asm_out_file);
3881           for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
3882             {
3883               ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
3884                                       a->dw_attr_val.v.val_float.array[i]);
3885               if (flag_verbose_asm)
3886                 fprintf (asm_out_file, "\t%s fp constant word %d",
3887                          ASM_COMMENT_START, i);
3888
3889               fputc ('\n', asm_out_file);
3890             }
3891           break;
3892
3893         case dw_val_class_flag:
3894           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
3895           break;
3896
3897         case dw_val_class_die_ref:
3898           if (a->dw_attr_val.v.val_die_ref != NULL)
3899             ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
3900           else if (a->dw_attr == DW_AT_sibling)
3901             ref_offset = sibling_offset(die);
3902           else
3903             abort ();
3904
3905           ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
3906           break;
3907
3908         case dw_val_class_fde_ref:
3909           ref_offset = fde_table[a->dw_attr_val.v.val_fde_index].dw_fde_offset;
3910           fprintf (asm_out_file, "\t%s\t%s+0x%x", UNALIGNED_OFFSET_ASM_OP,
3911                    stripattributes (FRAME_SECTION), ref_offset);
3912           break;
3913
3914         case dw_val_class_lbl_id:
3915           ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
3916           break;
3917
3918         case dw_val_class_section_offset:
3919           ASM_OUTPUT_DWARF_OFFSET (asm_out_file,
3920                                    stripattributes
3921                                    (a->dw_attr_val.v.val_section));
3922           break;
3923
3924         case dw_val_class_str:
3925           ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
3926           break;
3927
3928         default:
3929           abort ();
3930         }
3931
3932       if (a->dw_attr_val.val_class != dw_val_class_loc
3933           && a->dw_attr_val.val_class != dw_val_class_long_long
3934           && a->dw_attr_val.val_class != dw_val_class_float)
3935         {
3936           if (flag_verbose_asm)
3937             fprintf (asm_out_file, "\t%s %s",
3938                      ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
3939
3940           fputc ('\n', asm_out_file);
3941         }
3942     }
3943
3944   for (c = die->die_child; c != NULL; c = c->die_sib)
3945     output_die (c);
3946
3947   if (die->die_child != NULL)
3948     {
3949       /* Add null byte to terminate sibling list. */
3950       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
3951       if (flag_verbose_asm)
3952         fprintf (asm_out_file, "\t%s end of children of DIE 0x%x",
3953                  ASM_COMMENT_START, die->die_offset);
3954
3955       fputc ('\n', asm_out_file);
3956     }
3957 }
3958
3959 /* Output the compilation unit that appears at the beginning of the
3960    .debug_info section, and precedes the DIE descriptions.  */
3961
3962 static void
3963 output_compilation_unit_header ()
3964 {
3965   ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
3966   if (flag_verbose_asm)
3967     fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
3968              ASM_COMMENT_START);
3969
3970   fputc ('\n', asm_out_file);
3971   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
3972   if (flag_verbose_asm)
3973     fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
3974
3975   fputc ('\n', asm_out_file);
3976   ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION));
3977   if (flag_verbose_asm)
3978     fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
3979              ASM_COMMENT_START);
3980
3981   fputc ('\n', asm_out_file);
3982   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
3983   if (flag_verbose_asm)
3984     fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
3985
3986   fputc ('\n', asm_out_file);
3987 }
3988
3989 /* Generate a new label for the CFI info to refer to.  */
3990
3991 static char *
3992 dwarf2out_cfi_label ()
3993 {
3994   static char label[20];
3995   static unsigned long label_num = 0;
3996   
3997   ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
3998   ASM_OUTPUT_LABEL (asm_out_file, label);
3999
4000   return label;
4001 }
4002
4003 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
4004    or to the CIE if LABEL is NULL.  */
4005
4006 static void
4007 add_fde_cfi (label, cfi)
4008      register char *label;
4009      register dw_cfi_ref cfi;
4010 {
4011   if (label)
4012     {
4013       register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
4014
4015       if (*label == 0)
4016         label = dwarf2out_cfi_label ();
4017
4018       if (fde->dw_fde_current_label == NULL
4019           || strcmp (label, fde->dw_fde_current_label) != 0)
4020         {
4021           register dw_cfi_ref xcfi;
4022
4023           fde->dw_fde_current_label = label = xstrdup (label);
4024
4025           /* Set the location counter to the new label.  */
4026           xcfi = new_cfi ();
4027           xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
4028           xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
4029           add_cfi (&fde->dw_fde_cfi, xcfi);
4030         }
4031
4032       add_cfi (&fde->dw_fde_cfi, cfi);
4033     }
4034
4035   else
4036     add_cfi (&cie_cfi_head, cfi);
4037 }
4038
4039 /* Subroutine of lookup_cfa.  */
4040
4041 static inline void
4042 lookup_cfa_1 (cfi, regp, offsetp)
4043      register dw_cfi_ref cfi;
4044      register unsigned long *regp;
4045      register long *offsetp;
4046 {
4047   switch (cfi->dw_cfi_opc)
4048     {
4049     case DW_CFA_def_cfa_offset:
4050       *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
4051       break;
4052     case DW_CFA_def_cfa_register:
4053       *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
4054       break;
4055     case DW_CFA_def_cfa:
4056       *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
4057       *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
4058       break;
4059     }
4060 }
4061
4062 /* Find the previous value for the CFA.  */
4063
4064 static void
4065 lookup_cfa (regp, offsetp)
4066      register unsigned long *regp;
4067      register long *offsetp;
4068 {
4069   register dw_cfi_ref cfi;
4070
4071   *regp = (unsigned long) -1;
4072   *offsetp = 0;
4073
4074   for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
4075     lookup_cfa_1 (cfi, regp, offsetp);
4076
4077   if (fde_table_in_use)
4078     {
4079       register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
4080       for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
4081         lookup_cfa_1 (cfi, regp, offsetp);
4082     }
4083 }
4084
4085 /* Entry point to update the canonical frame address (CFA).
4086    LABEL is passed to add_fde_cfi.  The value of CFA is now to be
4087    calculated from REG+OFFSET.  */
4088
4089 void
4090 dwarf2out_def_cfa (label, reg, offset)
4091      register char *label;
4092      register unsigned reg;
4093      register long offset;
4094 {
4095   register dw_cfi_ref cfi;
4096   unsigned long old_reg;
4097   long old_offset;
4098
4099   reg = DWARF_FRAME_REGNUM (reg);
4100   lookup_cfa (&old_reg, &old_offset);
4101
4102   if (reg == old_reg && offset == old_offset)
4103     return;
4104
4105   cfi = new_cfi ();
4106
4107   if (reg == old_reg)
4108     {
4109       cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
4110       cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
4111     }
4112
4113 #ifndef MIPS_DEBUGGING_INFO  /* SGI dbx thinks this means no offset.  */
4114   else if (offset == old_offset && old_reg != (unsigned long) -1)
4115     {
4116       cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
4117       cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
4118     }
4119 #endif
4120
4121   else
4122     {
4123       cfi->dw_cfi_opc = DW_CFA_def_cfa;
4124       cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
4125       cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
4126     }
4127
4128   add_fde_cfi (label, cfi);
4129 }
4130
4131 /* Add the CFI for saving a register.  REG is the CFA column number.
4132    LABEL is passed to add_fde_cfi.
4133    If SREG is -1, the register is saved at OFFSET from the CFA;
4134    otherwise it is saved in SREG.  */
4135
4136 static void
4137 reg_save (label, reg, sreg, offset)
4138      register char * label;
4139      register unsigned reg;
4140      register unsigned sreg;
4141      register long offset;
4142 {
4143   register dw_cfi_ref cfi = new_cfi ();
4144
4145   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
4146
4147   if (sreg == -1)
4148     {
4149       if (reg & ~0x3f)
4150         /* The register number won't fit in 6 bits, so we have to use
4151            the long form.  */
4152         cfi->dw_cfi_opc = DW_CFA_offset_extended;
4153       else
4154         cfi->dw_cfi_opc = DW_CFA_offset;
4155
4156       offset /= DWARF_CIE_DATA_ALIGNMENT;
4157       assert (offset >= 0);
4158       cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
4159     }
4160   else
4161     {
4162       cfi->dw_cfi_opc = DW_CFA_register;
4163       cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
4164     }
4165
4166   add_fde_cfi (label, cfi);
4167 }
4168
4169 /* Entry point for saving a register.  REG is the GCC register number.
4170    LABEL and OFFSET are passed to reg_save.  */
4171
4172 void
4173 dwarf2out_reg_save (label, reg, offset)
4174      register char * label;
4175      register unsigned reg;
4176      register long offset;
4177 {
4178   reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
4179 }
4180
4181 /* Record the initial position of the return address.  RTL is
4182    INCOMING_RETURN_ADDR_RTX.  */
4183
4184 static void
4185 initial_return_save (rtl)
4186      register rtx rtl;
4187 {
4188   unsigned reg = -1;
4189   long offset = 0;
4190
4191   switch (GET_CODE (rtl))
4192     {
4193     case REG:
4194       /* RA is in a register.  */
4195       reg = reg_number (rtl);
4196       break;
4197     case MEM:
4198       /* RA is on the stack.  */
4199       rtl = XEXP (rtl, 0);
4200       switch (GET_CODE (rtl))
4201         {
4202         case REG:
4203           assert (REGNO (rtl) == STACK_POINTER_REGNUM);
4204           offset = 0;
4205           break;
4206         case PLUS:
4207           assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
4208           offset = INTVAL (XEXP (rtl, 1));
4209           break;
4210         case MINUS:
4211           assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
4212           offset = -INTVAL (XEXP (rtl, 1));
4213           break;
4214         default:
4215           abort ();
4216         }
4217       break;
4218     default:
4219       abort ();
4220     }
4221
4222   reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset);
4223 }
4224
4225 /* Record call frame debugging information for INSN, which either
4226    sets SP or FP (adjusting how we calculate the frame address) or saves a
4227    register to the stack.  If INSN is NULL_RTX, initialize our state.  */
4228
4229 void
4230 dwarf2out_frame_debug (insn)
4231      rtx insn;
4232 {
4233   char *label;
4234   rtx src, dest;
4235   long offset;
4236
4237   /* The current rule for calculating the DWARF2 canonical frame address.  */
4238   static unsigned cfa_reg;
4239   static long cfa_offset;
4240
4241   /* The register used for saving registers to the stack, and its offset
4242      from the CFA.  */
4243   static unsigned cfa_store_reg;
4244   static long cfa_store_offset;
4245
4246   /* A temporary register used in adjusting SP or setting up the store_reg.  */
4247   static unsigned cfa_temp_reg;
4248   static long cfa_temp_value;
4249
4250   if (insn == NULL_RTX)
4251     {
4252       /* Set up state for generating call frame debug info.  */
4253       cfa_reg = STACK_POINTER_REGNUM;
4254       cfa_offset = 0;
4255       cfa_store_reg = STACK_POINTER_REGNUM;
4256       cfa_store_offset = 0;
4257       cfa_temp_reg = -1;
4258       cfa_temp_value = 0;
4259       return;
4260     }
4261
4262   label = dwarf2out_cfi_label ();
4263     
4264   insn = PATTERN (insn);
4265   assert (GET_CODE (insn) == SET);
4266
4267   src = SET_SRC (insn);
4268   dest = SET_DEST (insn);
4269
4270   switch (GET_CODE (dest))
4271     {
4272     case REG:
4273       /* Update the CFA rule wrt SP or FP.  Make sure src is
4274          relative to the current CFA register.  */
4275       switch (GET_CODE (src))
4276         {
4277           /* Setting FP from SP.  */
4278         case REG:
4279           assert (cfa_reg == REGNO (src));
4280           assert (REGNO (dest) == STACK_POINTER_REGNUM
4281                   || (frame_pointer_needed
4282                       && REGNO (dest) == HARD_FRAME_POINTER_REGNUM));
4283           cfa_reg = REGNO (dest);
4284           break;
4285
4286         case PLUS:
4287         case MINUS:
4288           if (dest == stack_pointer_rtx)
4289             {
4290               /* Adjusting SP.  */
4291               switch (GET_CODE (XEXP (src, 1)))
4292                 {
4293                 case CONST_INT:
4294                   offset = INTVAL (XEXP (src, 1));
4295                   break;
4296                 case REG:
4297                   assert (REGNO (XEXP (src, 1)) == cfa_temp_reg);
4298                   offset = cfa_temp_value;
4299                   break;
4300                 default:
4301                   abort ();
4302                 }
4303
4304               if (GET_CODE (src) == PLUS)
4305                 offset = -offset;
4306               if (cfa_reg == STACK_POINTER_REGNUM)
4307                 cfa_offset += offset;
4308               if (cfa_store_reg == STACK_POINTER_REGNUM)
4309                 cfa_store_offset += offset;
4310               assert (XEXP (src, 0) == stack_pointer_rtx);
4311             }
4312           else
4313             {
4314               /* Initializing the store base register.  */
4315               assert (GET_CODE (src) == PLUS);
4316               assert (XEXP (src, 1) == stack_pointer_rtx);
4317               assert (GET_CODE (XEXP (src, 0)) == REG
4318                       && REGNO (XEXP (src, 0)) == cfa_temp_reg);
4319               assert (cfa_store_reg == STACK_POINTER_REGNUM);
4320               cfa_store_reg = REGNO (dest);
4321               cfa_store_offset -= cfa_temp_value;
4322             }
4323           break;
4324
4325         case CONST_INT:
4326           cfa_temp_reg = REGNO (dest);
4327           cfa_temp_value = INTVAL (src);
4328           break;
4329
4330         default:
4331           abort ();
4332         }
4333       dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
4334       break;
4335
4336     case MEM:
4337       /* Saving a register to the stack.  Make sure dest is relative to the
4338          CFA register.  */
4339       assert (GET_CODE (src) == REG);
4340       switch (GET_CODE (XEXP (dest, 0)))
4341         {
4342           /* With a push.  */
4343         case PRE_INC:
4344         case PRE_DEC:
4345           offset = GET_MODE_SIZE (GET_MODE (dest));
4346           if (GET_CODE (src) == PRE_INC)
4347             offset = -offset;
4348
4349           assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM);
4350           assert (cfa_store_reg == STACK_POINTER_REGNUM);
4351           cfa_store_offset += offset;
4352           if (cfa_reg == STACK_POINTER_REGNUM)
4353             cfa_offset = cfa_store_offset;
4354
4355           offset = -cfa_store_offset;
4356           break;
4357
4358           /* With an offset.  */
4359         case PLUS:
4360         case MINUS:
4361           offset = INTVAL (XEXP (XEXP (dest, 0), 1));
4362           if (GET_CODE (src) == MINUS)
4363             offset = -offset;
4364
4365           assert (cfa_store_reg == REGNO (XEXP (XEXP (dest, 0), 0)));
4366           offset -= cfa_store_offset;
4367           break;
4368
4369         default:
4370           abort ();
4371         }
4372       dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
4373       dwarf2out_reg_save (label, REGNO (src), offset);
4374       break;
4375
4376     default:
4377       abort ();
4378     }
4379 }
4380
4381 /* Return the size of a Call Frame Instruction.  */
4382
4383 static unsigned long
4384 size_of_cfi (cfi)
4385      dw_cfi_ref cfi;
4386 {
4387   register unsigned long size;
4388
4389   /* Count the 1-byte opcode */
4390   size = 1;
4391   switch (cfi->dw_cfi_opc)
4392     {
4393     case DW_CFA_offset:
4394       size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
4395       break;
4396     case DW_CFA_set_loc:
4397       size += PTR_SIZE;
4398       break;
4399     case DW_CFA_advance_loc1:
4400       size += 1;
4401       break;
4402     case DW_CFA_advance_loc2:
4403       size += 2;
4404       break;
4405     case DW_CFA_advance_loc4:
4406       size += 4;
4407       break;
4408 #ifdef MIPS_DEBUGGING_INFO
4409     case DW_CFA_MIPS_advance_loc8:
4410       size += 8;
4411       break;
4412 #endif
4413     case DW_CFA_offset_extended:
4414     case DW_CFA_def_cfa:
4415       size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4416       size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
4417       break;
4418     case DW_CFA_restore_extended:
4419     case DW_CFA_undefined:
4420       size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4421       break;
4422     case DW_CFA_same_value:
4423     case DW_CFA_def_cfa_register:
4424       size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4425       break;
4426     case DW_CFA_register:
4427       size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4428       size += size_of_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4429       break;
4430     case DW_CFA_def_cfa_offset:
4431       size += size_of_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
4432       break;
4433     default:
4434       break;
4435     }
4436
4437     return size;
4438 }
4439
4440 /* Return the size of an FDE sans the length word.  */
4441
4442 static inline unsigned long
4443 size_of_fde (fde, npad)
4444     dw_fde_ref fde;
4445     unsigned long *npad;
4446 {
4447   register dw_cfi_ref cfi;
4448   register unsigned long aligned_size;
4449   register unsigned long size;
4450
4451   size = DWARF_FDE_HEADER_SIZE;
4452   for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
4453     size += size_of_cfi(cfi);
4454
4455   /* Round the size up to a word boundary.  */
4456   aligned_size = DWARF_ROUND (size, PTR_SIZE);
4457   *npad = aligned_size - size;
4458   return aligned_size;
4459 }
4460
4461 /* Calculate the size of the FDE table, and establish the offset
4462    of each FDE in the .debug_frame section.  */
4463
4464 static void
4465 calc_fde_sizes ()
4466 {
4467   register unsigned long i;
4468   register dw_fde_ref fde;
4469   register unsigned long fde_size;
4470   register dw_cfi_ref cfi;
4471   unsigned long fde_pad;
4472
4473   cie_size = DWARF_CIE_HEADER_SIZE;
4474   for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
4475     cie_size += size_of_cfi (cfi);
4476
4477   /* Initialize the beginning FDE offset.  */
4478   next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
4479
4480   for (i = 0; i < fde_table_in_use; ++i)
4481     {
4482       fde = &fde_table[i];
4483       fde->dw_fde_offset = next_fde_offset;
4484       fde_size = size_of_fde (fde, &fde_pad);
4485       next_fde_offset += fde_size;
4486     }
4487 }
4488
4489 /* Output a Call Frame Information opcode and its operand(s).  */
4490
4491 static void
4492 output_cfi (cfi, fde)
4493      register dw_cfi_ref cfi;
4494      register dw_fde_ref fde;
4495 {
4496   if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
4497     {
4498       ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4499                               cfi->dw_cfi_opc
4500                               | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
4501       if (flag_verbose_asm)
4502         fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x",
4503                  ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
4504       fputc ('\n', asm_out_file);
4505     }
4506
4507   else if (cfi->dw_cfi_opc == DW_CFA_offset)
4508     {
4509       ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4510                               cfi->dw_cfi_opc
4511                               | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
4512       if (flag_verbose_asm)
4513         fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x",
4514                  ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4515
4516       fputc ('\n', asm_out_file);
4517       output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
4518       fputc ('\n', asm_out_file);
4519     }
4520   else if (cfi->dw_cfi_opc == DW_CFA_restore)
4521     {
4522       ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
4523                               cfi->dw_cfi_opc
4524                               | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
4525       if (flag_verbose_asm)
4526         fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x",
4527                  ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4528
4529       fputc ('\n', asm_out_file);
4530     }
4531   else
4532     {
4533       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
4534       if (flag_verbose_asm)
4535         fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
4536                  dwarf_cfi_name (cfi->dw_cfi_opc));
4537
4538       fputc ('\n', asm_out_file);
4539       switch (cfi->dw_cfi_opc)
4540         {
4541         case DW_CFA_set_loc:
4542           ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
4543           fputc ('\n', asm_out_file);
4544           break;
4545         case DW_CFA_advance_loc1:
4546           /* TODO: not currently implemented.  */
4547           abort ();
4548           break;
4549         case DW_CFA_advance_loc2:
4550           ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
4551                                    cfi->dw_cfi_oprnd1.dw_cfi_addr,
4552                                    fde->dw_fde_current_label);
4553           fputc ('\n', asm_out_file);
4554           fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
4555           break;
4556         case DW_CFA_advance_loc4:
4557           ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
4558                                    cfi->dw_cfi_oprnd1.dw_cfi_addr,
4559                                    fde->dw_fde_current_label);
4560           fputc ('\n', asm_out_file);
4561           fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
4562           break;
4563 #ifdef MIPS_DEBUGGING_INFO
4564         case DW_CFA_MIPS_advance_loc8:
4565           /* TODO: not currently implemented.  */
4566           abort ();
4567           break;
4568 #endif
4569         case DW_CFA_offset_extended:
4570         case DW_CFA_def_cfa:
4571           output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4572           fputc ('\n', asm_out_file);
4573           output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
4574           fputc ('\n', asm_out_file);
4575           break;
4576         case DW_CFA_restore_extended:
4577         case DW_CFA_undefined:
4578           output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4579           fputc ('\n', asm_out_file);
4580           break;
4581         case DW_CFA_same_value:
4582         case DW_CFA_def_cfa_register:
4583           output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4584           fputc ('\n', asm_out_file);
4585           break;
4586         case DW_CFA_register:
4587           output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
4588           fputc ('\n', asm_out_file);
4589           output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
4590           fputc ('\n', asm_out_file);
4591           break;
4592         case DW_CFA_def_cfa_offset:
4593           output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
4594           fputc ('\n', asm_out_file);
4595           break;
4596         default:
4597           break;
4598         }
4599      }
4600 }
4601
4602 /* Output the call frame information used to used to record information
4603    that relates to calculating the frame pointer, and records the
4604    location of saved registers.  */
4605
4606 static void
4607 output_call_frame_info ()
4608 {
4609   register unsigned long i, j;
4610   register dw_fde_ref fde;
4611   register unsigned long fde_size;
4612   register dw_cfi_ref cfi;
4613   unsigned long fde_pad;
4614
4615   /* Only output the info if it will be interesting.  */
4616   for (i = 0; i < fde_table_in_use; ++i)
4617     if (fde_table[i].dw_fde_cfi != NULL)
4618       break;
4619   if (i == fde_table_in_use)
4620     return;
4621
4622   /* (re-)initialize the beginning FDE offset.  */
4623   next_fde_offset = DWARF_ROUND (cie_size, PTR_SIZE);
4624
4625   fputc ('\n', asm_out_file);
4626   ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
4627
4628   /* Output the CIE. */
4629   ASM_OUTPUT_DWARF_DATA (asm_out_file, next_fde_offset - DWARF_OFFSET_SIZE);
4630   if (flag_verbose_asm)
4631     fprintf (asm_out_file, "\t%s Length of Common Information Entry",
4632              ASM_COMMENT_START);
4633
4634   fputc ('\n', asm_out_file);
4635   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
4636   if (flag_verbose_asm)
4637     fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
4638
4639   fputc ('\n', asm_out_file);
4640   if (DWARF_OFFSET_SIZE == 8)
4641     {
4642       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
4643       fputc ('\n', asm_out_file);
4644     }
4645
4646   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
4647   if (flag_verbose_asm)
4648     fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
4649
4650   fputc ('\n', asm_out_file);
4651   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4652   if (flag_verbose_asm)
4653     fprintf (asm_out_file, "\t%s CIE Augmentation (none)", ASM_COMMENT_START);
4654
4655   fputc ('\n', asm_out_file);
4656   output_uleb128 (1);
4657   if (flag_verbose_asm)
4658     fprintf (asm_out_file, " (CIE Code Alignment Factor)");
4659
4660   fputc ('\n', asm_out_file);
4661   output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
4662   if (flag_verbose_asm)
4663     fprintf (asm_out_file, " (CIE Data Alignment Factor)");
4664
4665   fputc ('\n', asm_out_file);
4666   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
4667   if (flag_verbose_asm)
4668     fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
4669
4670   fputc ('\n', asm_out_file);
4671
4672   for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
4673     output_cfi (cfi, NULL);
4674
4675   /* Pad the CIE out to an address sized boundary.  */
4676   for (i = next_fde_offset - cie_size; i; --i)
4677     {
4678       /* Pad out to a pointer size boundary */
4679       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4680       if (flag_verbose_asm)
4681         fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)", ASM_COMMENT_START);
4682
4683       fputc ('\n', asm_out_file);
4684     }
4685
4686   /* Loop through all of the FDE's.  */
4687   for (i = 0; i < fde_table_in_use; ++i)
4688     {
4689       fde = &fde_table[i];
4690       if (fde->dw_fde_cfi == NULL)
4691         continue;
4692
4693       fde_size = size_of_fde (fde, &fde_pad);
4694       ASM_OUTPUT_DWARF_DATA (asm_out_file, fde_size - DWARF_OFFSET_SIZE);
4695       if (flag_verbose_asm)
4696         fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
4697
4698       fputc ('\n', asm_out_file);
4699       ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
4700       if (flag_verbose_asm)
4701         fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
4702
4703       fputc ('\n', asm_out_file);
4704       ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
4705       if (flag_verbose_asm)
4706         fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
4707
4708       fputc ('\n', asm_out_file);
4709       ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
4710                                    fde->dw_fde_end, fde->dw_fde_begin);
4711       if (flag_verbose_asm)
4712         fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
4713
4714       fputc ('\n', asm_out_file);
4715
4716       /* Loop through the Call Frame Instructions associated with
4717          this FDE.  */
4718       fde->dw_fde_current_label = fde->dw_fde_begin;
4719       for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
4720         output_cfi (cfi, fde);
4721
4722       /* Pad to a double word boundary.  */
4723       for (j = 0; j < fde_pad; ++j)
4724         {
4725           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CFA_nop);
4726           if (flag_verbose_asm)
4727             fprintf (asm_out_file, "\t%s CIE DW_CFA_nop (pad)",
4728                      ASM_COMMENT_START);
4729
4730           fputc ('\n', asm_out_file);
4731         }
4732     }
4733 }
4734
4735 /* The DWARF2 pubname for a nested thingy looks like "A::f".  The output
4736    of decl_printable_name for C++ looks like "A::f(int)".  Let's drop the
4737    argument list, and maybe the scope.  */
4738
4739 static char *
4740 dwarf2_name (decl, scope)
4741      tree decl;
4742      int scope;
4743 {
4744   return (*decl_printable_name) (decl, scope ? 1 : 0);
4745 }
4746
4747 /* Add a new entry to .debug_pubnames if appropriate.  */
4748
4749 static void
4750 add_pubname (decl, die)
4751      tree decl;
4752      dw_die_ref die;
4753 {
4754   pubname_ref p;
4755
4756   if (! TREE_PUBLIC (decl))
4757     return;
4758
4759   if (pubname_table_in_use == pubname_table_allocated)
4760     {
4761       pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
4762       pubname_table = (pubname_ref) xrealloc
4763         (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
4764     }
4765
4766   p = &pubname_table[pubname_table_in_use++];
4767   p->die = die;
4768
4769   p->name = xstrdup (dwarf2_name (decl, 1));
4770 }
4771
4772 /* Output the public names table used to speed up access to externally
4773    visible names.  For now, only generate entries for externally
4774    visible procedures.  */
4775
4776 static void
4777 output_pubnames ()
4778 {
4779   register unsigned i;
4780   register unsigned long pubnames_length = size_of_pubnames ();
4781
4782   ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
4783
4784   if (flag_verbose_asm)
4785     fprintf (asm_out_file, "\t%s Length of Public Names Info.",
4786              ASM_COMMENT_START);
4787
4788   fputc ('\n', asm_out_file);
4789   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4790
4791   if (flag_verbose_asm)
4792     fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
4793
4794   fputc ('\n', asm_out_file);
4795   ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4796   if (flag_verbose_asm)
4797     fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4798              ASM_COMMENT_START);
4799
4800   fputc ('\n', asm_out_file);
4801   ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
4802   if (flag_verbose_asm)
4803     fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
4804
4805   fputc ('\n', asm_out_file);
4806   for (i = 0; i < pubname_table_in_use; ++i)
4807     {
4808       register pubname_ref pub = &pubname_table[i];
4809
4810       ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
4811       if (flag_verbose_asm)
4812         fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
4813
4814       fputc ('\n', asm_out_file);
4815
4816       ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
4817       if (flag_verbose_asm)
4818         fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
4819
4820       fputc ('\n', asm_out_file);
4821     }
4822
4823   ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
4824   fputc ('\n', asm_out_file);
4825 }
4826
4827 /* Add a new entry to .debug_aranges if appropriate.  */
4828
4829 static void
4830 add_arange (decl, die)
4831      tree decl;
4832      dw_die_ref die;
4833 {
4834   if (! DECL_SECTION_NAME (decl))
4835     return;
4836
4837   if (arange_table_in_use == arange_table_allocated)
4838     {
4839       arange_table_allocated += ARANGE_TABLE_INCREMENT;
4840       arange_table
4841         = (arange_ref) xrealloc (arange_table,
4842                                  arange_table_allocated * sizeof (dw_die_ref));
4843     }
4844
4845   arange_table[arange_table_in_use++] = die;
4846 }
4847
4848 /* Output the information that goes into the .debug_aranges table.
4849    Namely, define the beginning and ending address range of the
4850    text section generated for this compilation unit.  */
4851
4852 static void
4853 output_aranges ()
4854 {
4855   register unsigned i;
4856   register unsigned long aranges_length = size_of_aranges ();
4857
4858   ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
4859   if (flag_verbose_asm)
4860     fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
4861              ASM_COMMENT_START);
4862
4863   fputc ('\n', asm_out_file);
4864   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4865   if (flag_verbose_asm)
4866     fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
4867
4868   fputc ('\n', asm_out_file);
4869   ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_SECTION));
4870   if (flag_verbose_asm)
4871     fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
4872              ASM_COMMENT_START);
4873
4874   fputc ('\n', asm_out_file);
4875   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
4876   if (flag_verbose_asm)
4877     fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
4878
4879   fputc ('\n', asm_out_file);
4880   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
4881   if (flag_verbose_asm)
4882     fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
4883              ASM_COMMENT_START);
4884
4885   fputc ('\n', asm_out_file);
4886   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
4887   if (PTR_SIZE == 8)
4888     fprintf (asm_out_file, ",0,0");
4889
4890   if (flag_verbose_asm)
4891     fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
4892              ASM_COMMENT_START, 2 * PTR_SIZE);
4893
4894   fputc ('\n', asm_out_file);
4895   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
4896   if (flag_verbose_asm)
4897     fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4898
4899   fputc ('\n', asm_out_file);
4900   ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION);
4901   if (flag_verbose_asm)
4902     fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4903
4904   fputc ('\n', asm_out_file);
4905   for (i = 0; i < arange_table_in_use; ++i)
4906     {
4907       dw_die_ref a = arange_table[i];
4908
4909       if (a->die_tag == DW_TAG_subprogram)
4910         ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a));
4911       else
4912         {
4913           char *name = get_AT_string (a, DW_AT_MIPS_linkage_name);
4914           if (! name)
4915             name = get_AT_string (a, DW_AT_name);
4916
4917           ASM_OUTPUT_DWARF_ADDR (asm_out_file, name);
4918         }
4919
4920       if (flag_verbose_asm)
4921         fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
4922
4923       fputc ('\n', asm_out_file);
4924       if (a->die_tag == DW_TAG_subprogram)
4925         ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a),
4926                                      get_AT_low_pc (a));
4927       else
4928         ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
4929                                     get_AT_unsigned (a, DW_AT_byte_size));
4930
4931       if (flag_verbose_asm)
4932         fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
4933
4934       fputc ('\n', asm_out_file);
4935     }
4936
4937   /* Output the terminator words.  */
4938   ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4939   fputc ('\n', asm_out_file);
4940   ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
4941   fputc ('\n', asm_out_file);
4942 }
4943
4944 /* Output the source line number correspondence information.  This
4945    information goes into the .debug_line section.  */
4946
4947 static void
4948 output_line_info ()
4949 {
4950   char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4951   char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
4952   register unsigned opc;
4953   register unsigned n_op_args;
4954   register unsigned long ft_index;
4955   register unsigned long lt_index;
4956   register unsigned long current_line;
4957   register long line_offset;
4958   register long line_delta;
4959   register unsigned long current_file;
4960   register unsigned long function;
4961
4962   ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ());
4963   if (flag_verbose_asm)
4964     fprintf (asm_out_file, "\t%s Length of Source Line Info.",
4965              ASM_COMMENT_START);
4966
4967   fputc ('\n', asm_out_file);
4968   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
4969   if (flag_verbose_asm)
4970     fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
4971
4972   fputc ('\n', asm_out_file);
4973   ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
4974   if (flag_verbose_asm)
4975     fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
4976
4977   fputc ('\n', asm_out_file);
4978   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
4979   if (flag_verbose_asm)
4980     fprintf (asm_out_file, "\t%s Minimum Instruction Length",
4981              ASM_COMMENT_START);
4982
4983   fputc ('\n', asm_out_file);
4984   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
4985   if (flag_verbose_asm)
4986     fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
4987              ASM_COMMENT_START);
4988
4989   fputc ('\n', asm_out_file);
4990   fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
4991   if (flag_verbose_asm)
4992     fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
4993              ASM_COMMENT_START);
4994
4995   fputc ('\n', asm_out_file);
4996   fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
4997   if (flag_verbose_asm)
4998     fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
4999              ASM_COMMENT_START);
5000
5001   fputc ('\n', asm_out_file);
5002   fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5003   if (flag_verbose_asm)
5004     fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5005
5006   fputc ('\n', asm_out_file);
5007   for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5008     {
5009       switch (opc)
5010         {
5011         case DW_LNS_advance_pc:
5012         case DW_LNS_advance_line:
5013         case DW_LNS_set_file:
5014         case DW_LNS_set_column:
5015         case DW_LNS_fixed_advance_pc:
5016           n_op_args = 1;
5017           break;
5018         default:
5019           n_op_args = 0;
5020           break;
5021         }
5022       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5023       if (flag_verbose_asm)
5024         fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5025                  ASM_COMMENT_START, opc, n_op_args);
5026       fputc ('\n', asm_out_file);
5027     }
5028
5029   if (flag_verbose_asm)
5030     fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5031
5032   /* Include directory table is empty, at present */
5033   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5034   fputc ('\n', asm_out_file);
5035   if (flag_verbose_asm)
5036     fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5037
5038   for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5039     {
5040       ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5041       if (flag_verbose_asm)
5042         fprintf (asm_out_file, "%s File Entry: 0x%x",
5043                  ASM_COMMENT_START, ft_index);
5044
5045       fputc ('\n', asm_out_file);
5046
5047       /* Include directory index */
5048       output_uleb128 (0);
5049       fputc ('\n', asm_out_file);
5050
5051       /* Modification time */
5052       output_uleb128 (0);
5053       fputc ('\n', asm_out_file);
5054
5055       /* File length in bytes */
5056       output_uleb128 (0);
5057       fputc ('\n', asm_out_file);
5058     }
5059
5060   /* Terminate the file name table */
5061   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5062   fputc ('\n', asm_out_file);
5063
5064   /* Set the address register to the first location in the text section */
5065   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5066   if (flag_verbose_asm)
5067     fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5068
5069   fputc ('\n', asm_out_file);
5070   output_uleb128 (1 + PTR_SIZE);
5071   fputc ('\n', asm_out_file);
5072   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5073   fputc ('\n', asm_out_file);
5074   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION);
5075   fputc ('\n', asm_out_file);
5076
5077   /* Generate the line number to PC correspondence table, encoded as
5078      a series of state machine operations.  */
5079   current_file = 1;
5080   current_line = 1;
5081   strcpy (prev_line_label, TEXT_SECTION);
5082   for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5083     {
5084       register dw_line_info_ref line_info;
5085
5086       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5087       if (flag_verbose_asm)
5088         fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5089                  ASM_COMMENT_START);
5090
5091       fputc ('\n', asm_out_file);
5092       ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5093       ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5094       fputc ('\n', asm_out_file);
5095       line_info = &line_info_table[lt_index];
5096       if (line_info->dw_file_num != current_file)
5097         {
5098           current_file = line_info->dw_file_num;
5099           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5100           if (flag_verbose_asm)
5101             fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5102
5103           fputc ('\n', asm_out_file);
5104           output_uleb128 (current_file);
5105           if (flag_verbose_asm)
5106             fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5107
5108           fputc ('\n', asm_out_file);
5109         }
5110
5111       line_offset = line_info->dw_line_num - current_line;
5112       line_delta = line_offset - DWARF_LINE_BASE;
5113       current_line = line_info->dw_line_num;
5114       if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5115         {
5116           ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5117                                   DWARF_LINE_OPCODE_BASE + line_delta);
5118           if (flag_verbose_asm)
5119               fprintf (asm_out_file,
5120                        "\t%s line %d", ASM_COMMENT_START, current_line);
5121
5122           fputc ('\n', asm_out_file);
5123         }
5124       else
5125         {
5126           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5127           if (flag_verbose_asm)
5128             fprintf (asm_out_file, "\t%s advance to line %d",
5129                      ASM_COMMENT_START, current_line);
5130
5131           fputc ('\n', asm_out_file);
5132           output_sleb128 (line_offset);
5133           fputc ('\n', asm_out_file);
5134           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5135           fputc ('\n', asm_out_file);
5136         }
5137
5138       strcpy (prev_line_label, line_label);
5139     }
5140
5141   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5142   if (flag_verbose_asm)
5143     fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", ASM_COMMENT_START);
5144
5145   fputc ('\n', asm_out_file);
5146   ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5147   fputc ('\n', asm_out_file);
5148
5149   /* Output the marker for the end of the line number info.  */
5150   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5151   if (flag_verbose_asm)
5152     fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5153
5154   fputc ('\n', asm_out_file);
5155   output_uleb128 (1);
5156   fputc ('\n', asm_out_file);
5157   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5158   fputc ('\n', asm_out_file);
5159
5160   function = 0;
5161   current_file = 1;
5162   current_line = 1;
5163   for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5164     {
5165       register dw_separate_line_info_ref line_info
5166         = &separate_line_info_table[lt_index];
5167
5168       ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5169                                    lt_index);
5170       if (function != line_info->function)
5171         {
5172           function = line_info->function;
5173
5174           /* Set the address register to the first line in the function */
5175           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5176           if (flag_verbose_asm)
5177             fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5178                      ASM_COMMENT_START);
5179
5180           fputc ('\n', asm_out_file);
5181           output_uleb128 (1 + PTR_SIZE);
5182           fputc ('\n', asm_out_file);
5183           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5184           fputc ('\n', asm_out_file);
5185           ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5186           fputc ('\n', asm_out_file);
5187         }
5188       else
5189         {
5190           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5191           if (flag_verbose_asm)
5192             fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5193                      ASM_COMMENT_START);
5194
5195           fputc ('\n', asm_out_file);
5196           ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5197           fputc ('\n', asm_out_file);
5198         }
5199
5200       if (line_info->dw_file_num != current_file)
5201         {
5202           current_file = line_info->dw_file_num;
5203           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5204           if (flag_verbose_asm)
5205             fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5206
5207           fputc ('\n', asm_out_file);
5208           output_uleb128 (current_file);
5209           if (flag_verbose_asm)
5210             fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5211
5212           fputc ('\n', asm_out_file);
5213         }
5214
5215       if (line_info->dw_line_num != current_line)
5216         {
5217           line_offset = line_info->dw_line_num - current_line;
5218           line_delta = line_offset - DWARF_LINE_BASE;
5219           current_line = line_info->dw_line_num;
5220           if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5221             {
5222               ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5223                                       DWARF_LINE_OPCODE_BASE + line_delta);
5224               if (flag_verbose_asm)
5225                 fprintf (asm_out_file,
5226                          "\t%s line %d", ASM_COMMENT_START, current_line);
5227
5228               fputc ('\n', asm_out_file);
5229             }
5230           else
5231             {
5232               ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5233               if (flag_verbose_asm)
5234                 fprintf (asm_out_file, "\t%s advance to line %d",
5235                          ASM_COMMENT_START, current_line);
5236
5237               fputc ('\n', asm_out_file);
5238               output_sleb128 (line_offset);
5239               fputc ('\n', asm_out_file);
5240               ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5241               fputc ('\n', asm_out_file);
5242             }
5243         }
5244
5245       ++lt_index;
5246       strcpy (prev_line_label, line_label);
5247
5248       /* If we're done with a function, end its sequence.  */
5249       if (lt_index == separate_line_info_table_in_use
5250           || separate_line_info_table[lt_index].function != function)
5251         {
5252           current_file = 1;
5253           current_line = 1;
5254           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5255           if (flag_verbose_asm)
5256             fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5257                      ASM_COMMENT_START);
5258
5259           fputc ('\n', asm_out_file);
5260           ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5261           ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5262           fputc ('\n', asm_out_file);
5263
5264           /* Output the marker for the end of this sequence.  */
5265           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5266           if (flag_verbose_asm)
5267             fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5268                      ASM_COMMENT_START);
5269
5270           fputc ('\n', asm_out_file);
5271           output_uleb128 (1);
5272           fputc ('\n', asm_out_file);
5273           ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5274           fputc ('\n', asm_out_file);
5275         }
5276     }
5277 }
5278 \f
5279 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5280    in question represents the outermost pair of curly braces (i.e. the "body
5281    block") of a function or method.
5282
5283    For any BLOCK node representing a "body block" of a function or method, the
5284    BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5285    represents the outermost (function) scope for the function or method (i.e.
5286    the one which includes the formal parameters).  The BLOCK_SUPERCONTEXT of
5287    *that* node in turn will point to the relevant FUNCTION_DECL node. */
5288
5289 static inline int
5290 is_body_block (stmt)
5291      register tree stmt;
5292 {
5293   if (TREE_CODE (stmt) == BLOCK)
5294     {
5295       register tree parent = BLOCK_SUPERCONTEXT (stmt);
5296
5297       if (TREE_CODE (parent) == BLOCK)
5298         {
5299           register tree grandparent = BLOCK_SUPERCONTEXT (parent);
5300
5301           if (TREE_CODE (grandparent) == FUNCTION_DECL)
5302             return 1;
5303         }
5304     }
5305
5306   return 0;
5307 }
5308
5309 /* Given a pointer to a tree node for some base type, return a pointer to
5310    a DIE that describes the given type.
5311
5312    This routine must only be called for GCC type nodes that correspond to
5313    Dwarf base (fundamental) types.  */
5314
5315 static dw_die_ref
5316 base_type_die (type)
5317      register tree type;
5318 {
5319   register dw_die_ref base_type_result;
5320   register char *type_name;
5321   register enum dwarf_type encoding;
5322   register tree name = TYPE_NAME (type);
5323
5324   if (TREE_CODE (type) == ERROR_MARK
5325       || TREE_CODE (type) == VOID_TYPE)
5326     return 0;
5327
5328   if (TREE_CODE (name) == TYPE_DECL)
5329     name = DECL_NAME (name);
5330   type_name = IDENTIFIER_POINTER (name);
5331
5332   switch (TREE_CODE (type))
5333     {
5334     case INTEGER_TYPE:
5335       /* Carefully distinguish the C character types, without messing
5336          up if the language is not C. Note that we check only for the names
5337          that contain spaces; other names might occur by coincidence in other 
5338          languages.  */
5339       if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5340              && (type == char_type_node
5341                  || ! strcmp (type_name, "signed char")
5342                  || ! strcmp (type_name, "unsigned char"))))
5343         {
5344           if (TREE_UNSIGNED (type))
5345             encoding = DW_ATE_unsigned;
5346           else
5347             encoding = DW_ATE_signed;
5348           break;
5349         }
5350       /* else fall through */
5351
5352     case CHAR_TYPE:
5353       /* GNU Pascal/Ada CHAR type.  Not used in C.  */
5354       if (TREE_UNSIGNED (type))
5355         encoding = DW_ATE_unsigned_char;
5356       else
5357         encoding = DW_ATE_signed_char;
5358       break;
5359
5360     case REAL_TYPE:
5361       encoding = DW_ATE_float;
5362       break;
5363
5364     case COMPLEX_TYPE:
5365       encoding = DW_ATE_complex_float;
5366       break;
5367
5368     case BOOLEAN_TYPE:
5369       /* GNU FORTRAN/Ada/C++ BOOLEAN type.  */
5370       encoding = DW_ATE_boolean;
5371       break;
5372
5373     default:
5374       abort (); /* No other TREE_CODEs are Dwarf fundamental types.  */
5375     }
5376
5377   base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
5378   add_AT_string (base_type_result, DW_AT_name, type_name);
5379   add_AT_unsigned (base_type_result, DW_AT_byte_size,
5380                    TYPE_PRECISION (type) / BITS_PER_UNIT);
5381   add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
5382
5383   return base_type_result;
5384 }
5385
5386 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
5387    the Dwarf "root" type for the given input type.  The Dwarf "root" type of
5388    a given type is generally the same as the given type, except that if the
5389    given type is a pointer or reference type, then the root type of the given
5390    type is the root type of the "basis" type for the pointer or reference
5391    type.  (This definition of the "root" type is recursive.) Also, the root
5392    type of a `const' qualified type or a `volatile' qualified type is the
5393    root type of the given type without the qualifiers.  */
5394
5395 static tree
5396 root_type (type)
5397      register tree type;
5398 {
5399   if (TREE_CODE (type) == ERROR_MARK)
5400     return error_mark_node;
5401
5402   switch (TREE_CODE (type))
5403     {
5404     case ERROR_MARK:
5405       return error_mark_node;
5406
5407     case POINTER_TYPE:
5408     case REFERENCE_TYPE:
5409       return type_main_variant (root_type (TREE_TYPE (type)));
5410
5411     default:
5412       return type_main_variant (type);
5413     }
5414 }
5415
5416 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
5417    given input type is a Dwarf "fundamental" type.  Otherwise return null.  */
5418
5419 static inline int
5420 is_base_type (type)
5421      register tree type;
5422 {
5423   switch (TREE_CODE (type))
5424     {
5425     case ERROR_MARK:
5426     case VOID_TYPE:
5427     case INTEGER_TYPE:
5428     case REAL_TYPE:
5429     case COMPLEX_TYPE:
5430     case BOOLEAN_TYPE:
5431     case CHAR_TYPE:
5432       return 1;
5433
5434     case SET_TYPE:
5435     case ARRAY_TYPE:
5436     case RECORD_TYPE:
5437     case UNION_TYPE:
5438     case QUAL_UNION_TYPE:
5439     case ENUMERAL_TYPE:
5440     case FUNCTION_TYPE:
5441     case METHOD_TYPE:
5442     case POINTER_TYPE:
5443     case REFERENCE_TYPE:
5444     case FILE_TYPE:
5445     case OFFSET_TYPE:
5446     case LANG_TYPE:
5447       return 0;
5448
5449     default:
5450       abort ();
5451     }
5452
5453   return 0;
5454 }
5455
5456 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
5457    entry that chains various modifiers in front of the given type.  */
5458
5459 static dw_die_ref
5460 modified_type_die (type, is_const_type, is_volatile_type, context_die)
5461      register tree type;
5462      register int is_const_type;
5463      register int is_volatile_type;
5464      register dw_die_ref context_die;
5465 {
5466   register enum tree_code code = TREE_CODE (type);
5467   register dw_die_ref mod_type_die = NULL;
5468   register dw_die_ref sub_die = NULL;
5469   register tree item_type = NULL;
5470
5471   if (code != ERROR_MARK)
5472     {
5473       type = build_type_variant (type, is_const_type, is_volatile_type);
5474
5475       mod_type_die = lookup_type_die (type);
5476       if (mod_type_die)
5477         return mod_type_die;
5478
5479       /* Handle C typedef types. */
5480       if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
5481           && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
5482         {
5483           tree dtype = TREE_TYPE (TYPE_NAME (type));
5484           if (type == dtype)
5485             {
5486               /* For a named type, use the typedef.  */
5487               gen_type_die (type, context_die);
5488               mod_type_die = lookup_type_die (type);
5489             }
5490
5491           else if (is_const_type < TYPE_READONLY (dtype)
5492                    || is_volatile_type < TYPE_VOLATILE (dtype))
5493             /* cv-unqualified version of named type.  Just use the unnamed
5494                type to which it refers.  */
5495             mod_type_die
5496               = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
5497                                    is_const_type, is_volatile_type,
5498                                    context_die);
5499           /* Else cv-qualified version of named type; fall through.  */
5500         }
5501
5502       if (mod_type_die)
5503         /* OK */;
5504       else if (is_const_type)
5505         {
5506           mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
5507           sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
5508         }
5509       else if (is_volatile_type)
5510         {
5511           mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
5512           sub_die = modified_type_die (type, 0, 0, context_die);
5513         }
5514       else if (code == POINTER_TYPE)
5515         {
5516           mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
5517           add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5518 #if 0
5519           add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5520 #endif
5521           item_type = TREE_TYPE (type);
5522         }
5523       else if (code == REFERENCE_TYPE)
5524         {
5525           mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
5526           add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
5527 #if 0
5528           add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
5529 #endif 
5530           item_type = TREE_TYPE (type);
5531         }
5532       else if (is_base_type (type))
5533         mod_type_die = base_type_die (type);
5534       else
5535         {
5536           gen_type_die (type, context_die);
5537
5538           /* We have to get the type_main_variant here (and pass that to the
5539              `lookup_type_die' routine) because the ..._TYPE node we have
5540              might simply be a *copy* of some original type node (where the
5541              copy was created to help us keep track of typedef names) and
5542              that copy might have a different TYPE_UID from the original
5543              ..._TYPE node.  */
5544           mod_type_die = lookup_type_die (type_main_variant (type));
5545           assert (mod_type_die != NULL);
5546         }
5547     }
5548
5549   equate_type_number_to_die (type, mod_type_die);
5550   if (item_type)
5551     /* We must do this after the equate_type_number_to_die call, in case
5552        this is a recursive type.  This ensures that the modified_type_die
5553        recursion will terminate even if the type is recursive.  Recursive
5554        types are possible in Ada.  */
5555     sub_die = modified_type_die (item_type,
5556                                  TYPE_READONLY (item_type),
5557                                  TYPE_VOLATILE (item_type),
5558                                  context_die);
5559
5560   if (sub_die != NULL)
5561     add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
5562
5563   return mod_type_die;
5564 }
5565
5566 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
5567    an enumerated type.   */
5568
5569 static inline int
5570 type_is_enum (type)
5571      register tree type;
5572 {
5573   return TREE_CODE (type) == ENUMERAL_TYPE;
5574 }
5575
5576 /* Return the register number described by a given RTL node.  */
5577
5578 static unsigned
5579 reg_number (rtl)
5580      register rtx rtl;
5581 {
5582   register unsigned regno = REGNO (rtl);
5583
5584   if (regno >= FIRST_PSEUDO_REGISTER)
5585     {
5586       warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n",
5587                          regno);
5588       regno = 0;
5589     }
5590
5591   regno = DBX_REGISTER_NUMBER (regno);
5592   return regno;
5593 }
5594
5595 /* Return a location descriptor that designates a machine register.  */
5596
5597 static dw_loc_descr_ref
5598 reg_loc_descriptor (rtl)
5599      register rtx rtl;
5600 {
5601   register dw_loc_descr_ref loc_result = NULL;
5602   register unsigned reg = reg_number (rtl);
5603
5604   if (reg >= 0 && reg <= 31)
5605     loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
5606   else
5607     loc_result = new_loc_descr (DW_OP_regx, reg, 0);
5608
5609   return loc_result;
5610 }
5611
5612 /* Return a location descriptor that designates a base+offset location.  */
5613
5614 static dw_loc_descr_ref
5615 based_loc_descr (reg, offset)
5616      unsigned reg;
5617      long int offset;
5618 {
5619   register dw_loc_descr_ref loc_result;
5620   /* For the "frame base", we use the frame pointer or stack pointer
5621      registers, since the RTL for local variables is relative to one of
5622      them.  */
5623   register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
5624                                                   ? HARD_FRAME_POINTER_REGNUM
5625                                                   : STACK_POINTER_REGNUM);
5626
5627   if (reg == fp_reg)
5628     loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
5629   else if (reg >= 0 && reg <= 31)
5630     loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
5631   else
5632     loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
5633
5634   return loc_result;
5635 }
5636
5637 /* Return true if this RTL expression describes a base+offset calculation.  */
5638
5639 static inline int
5640 is_based_loc (rtl)
5641      register rtx rtl;
5642 {
5643     return (GET_CODE (rtl) == PLUS
5644             && ((GET_CODE (XEXP (rtl, 0)) == REG
5645                  && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
5646 }
5647
5648 /* The following routine converts the RTL for a variable or parameter
5649    (resident in memory) into an equivalent Dwarf representation of a
5650    mechanism for getting the address of that same variable onto the top of a
5651    hypothetical "address evaluation" stack.
5652
5653    When creating memory location descriptors, we are effectively transforming
5654    the RTL for a memory-resident object into its Dwarf postfix expression
5655    equivalent.  This routine recursively descends an RTL tree, turning
5656    it into Dwarf postfix code as it goes.  */
5657
5658 static dw_loc_descr_ref
5659 mem_loc_descriptor (rtl)
5660      register rtx rtl;
5661 {
5662   dw_loc_descr_ref mem_loc_result = NULL;
5663   /* Note that for a dynamically sized array, the location we will generate a 
5664      description of here will be the lowest numbered location which is
5665      actually within the array.  That's *not* necessarily the same as the
5666      zeroth element of the array.  */
5667
5668   switch (GET_CODE (rtl))
5669     {
5670     case SUBREG:
5671       /* The case of a subreg may arise when we have a local (register)
5672          variable or a formal (register) parameter which doesn't quite fill
5673          up an entire register.  For now, just assume that it is
5674          legitimate to make the Dwarf info refer to the whole register which
5675          contains the given subreg.  */
5676       rtl = XEXP (rtl, 0);
5677
5678       /* ... fall through ... */
5679
5680     case REG:
5681       /* Whenever a register number forms a part of the description of the
5682          method for calculating the (dynamic) address of a memory resident
5683          object, DWARF rules require the register number be referred to as 
5684          a "base register".  This distinction is not based in any way upon
5685          what category of register the hardware believes the given register
5686          belongs to.  This is strictly DWARF terminology we're dealing with
5687          here. Note that in cases where the location of a memory-resident
5688          data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
5689          OP_CONST (0)) the actual DWARF location descriptor that we generate
5690          may just be OP_BASEREG (basereg).  This may look deceptively like
5691          the object in question was allocated to a register (rather than in
5692          memory) so DWARF consumers need to be aware of the subtle
5693          distinction between OP_REG and OP_BASEREG.  */
5694       mem_loc_result = based_loc_descr (reg_number (rtl), 0);
5695       break;
5696
5697     case MEM:
5698       mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5699       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
5700       break;
5701
5702     case CONST:
5703     case SYMBOL_REF:
5704       mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
5705       mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
5706       mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
5707       break;
5708
5709     case PLUS:
5710       if (is_based_loc (rtl))
5711         mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
5712                                           INTVAL (XEXP (rtl, 1)));
5713       else
5714         {
5715           add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5716           add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5717           add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
5718         }
5719       break;
5720
5721     case MULT:
5722       /* If a pseudo-reg is optimized away, it is possible for it to
5723          be replaced with a MEM containing a multiply.  */
5724       add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0)));
5725       add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1)));
5726       add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
5727       break;
5728
5729     case CONST_INT:
5730       mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
5731       break;
5732
5733     default:
5734       abort ();
5735     }
5736
5737   return mem_loc_result;
5738 }
5739
5740 /* Output a proper Dwarf location descriptor for a variable or parameter
5741    which is either allocated in a register or in a memory location.  For a
5742    register, we just generate an OP_REG and the register number.  For a
5743    memory location we provide a Dwarf postfix expression describing how to
5744    generate the (dynamic) address of the object onto the address stack.  */
5745
5746 static dw_loc_descr_ref
5747 loc_descriptor (rtl)
5748      register rtx rtl;
5749 {
5750   dw_loc_descr_ref loc_result = NULL;
5751   switch (GET_CODE (rtl))
5752     {
5753     case SUBREG:
5754       /* The case of a subreg may arise when we have a local (register)
5755          variable or a formal (register) parameter which doesn't quite fill
5756          up an entire register.  For now, just assume that it is
5757          legitimate to make the Dwarf info refer to the whole register which
5758          contains the given subreg.  */
5759       rtl = XEXP (rtl, 0);
5760
5761       /* ... fall through ... */
5762
5763     case REG:
5764       loc_result = reg_loc_descriptor (rtl);
5765       break;
5766
5767     case MEM:
5768       loc_result = mem_loc_descriptor (XEXP (rtl, 0));
5769       break;
5770
5771     default:
5772       abort ();
5773     }
5774
5775   return loc_result;
5776 }
5777
5778 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
5779    which is not less than the value itself.  */
5780
5781 static inline unsigned
5782 ceiling (value, boundary)
5783      register unsigned value;
5784      register unsigned boundary;
5785 {
5786   return (((value + boundary - 1) / boundary) * boundary);
5787 }
5788
5789 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
5790    pointer to the declared type for the relevant field variable, or return
5791    `integer_type_node' if the given node turns out to be an
5792    ERROR_MARK node.  */
5793
5794 static inline tree
5795 field_type (decl)
5796      register tree decl;
5797 {
5798   register tree type;
5799
5800   if (TREE_CODE (decl) == ERROR_MARK)
5801     return integer_type_node;
5802
5803   type = DECL_BIT_FIELD_TYPE (decl);
5804   if (type == NULL_TREE)
5805     type = TREE_TYPE (decl);
5806
5807   return type;
5808 }
5809
5810 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5811    node, return the alignment in bits for the type, or else return
5812    BITS_PER_WORD if the node actually turns out to be an
5813    ERROR_MARK node.  */
5814
5815 static inline unsigned
5816 simple_type_align_in_bits (type)
5817      register tree type;
5818 {
5819   return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
5820 }
5821
5822 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
5823    node, return the size in bits for the type if it is a constant, or else
5824    return the alignment for the type if the type's size is not constant, or
5825    else return BITS_PER_WORD if the type actually turns out to be an
5826    ERROR_MARK node.  */
5827
5828 static inline unsigned
5829 simple_type_size_in_bits (type)
5830      register tree type;
5831 {
5832   if (TREE_CODE (type) == ERROR_MARK)
5833     return BITS_PER_WORD;
5834   else
5835     {
5836       register tree type_size_tree = TYPE_SIZE (type);
5837
5838       if (TREE_CODE (type_size_tree) != INTEGER_CST)
5839         return TYPE_ALIGN (type);
5840
5841       return (unsigned) TREE_INT_CST_LOW (type_size_tree);
5842     }
5843 }
5844
5845 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
5846    return the byte offset of the lowest addressed byte of the "containing
5847    object" for the given FIELD_DECL, or return 0 if we are unable to
5848    determine what that offset is, either because the argument turns out to
5849    be a pointer to an ERROR_MARK node, or because the offset is actually
5850    variable.  (We can't handle the latter case just yet).  */
5851
5852 static unsigned
5853 field_byte_offset (decl)
5854      register tree decl;
5855 {
5856   register unsigned type_align_in_bytes;
5857   register unsigned type_align_in_bits;
5858   register unsigned type_size_in_bits;
5859   register unsigned object_offset_in_align_units;
5860   register unsigned object_offset_in_bits;
5861   register unsigned object_offset_in_bytes;
5862   register tree type;
5863   register tree bitpos_tree;
5864   register tree field_size_tree;
5865   register unsigned bitpos_int;
5866   register unsigned deepest_bitpos;
5867   register unsigned field_size_in_bits;
5868
5869   if (TREE_CODE (decl) == ERROR_MARK)
5870     return 0;
5871
5872   if (TREE_CODE (decl) != FIELD_DECL)
5873     abort ();
5874
5875   type = field_type (decl);
5876
5877   bitpos_tree = DECL_FIELD_BITPOS (decl);
5878   field_size_tree = DECL_SIZE (decl);
5879
5880   /* We cannot yet cope with fields whose positions or sizes are variable, so 
5881      for now, when we see such things, we simply return 0.  Someday, we may
5882      be able to handle such cases, but it will be damn difficult.  */
5883   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
5884     return 0;
5885   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
5886
5887   if (TREE_CODE (field_size_tree) != INTEGER_CST)
5888     return 0;
5889
5890   field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
5891   type_size_in_bits = simple_type_size_in_bits (type);
5892   type_align_in_bits = simple_type_align_in_bits (type);
5893   type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
5894
5895   /* Note that the GCC front-end doesn't make any attempt to keep track of
5896      the starting bit offset (relative to the start of the containing
5897      structure type) of the hypothetical "containing object" for a bit-
5898      field.  Thus, when computing the byte offset value for the start of the
5899      "containing object" of a bit-field, we must deduce this information on 
5900      our own. This can be rather tricky to do in some cases.  For example,
5901      handling the following structure type definition when compiling for an
5902      i386/i486 target (which only aligns long long's to 32-bit boundaries)
5903      can be very tricky:
5904
5905          struct S { int field1; long long field2:31; };
5906
5907      Fortunately, there is a simple rule-of-thumb which can be
5908      used in such cases.  When compiling for an i386/i486, GCC will allocate
5909      8 bytes for the structure shown above.  It decides to do this based upon 
5910      one simple rule for bit-field allocation.  Quite simply, GCC allocates
5911      each "containing object" for each bit-field at the first (i.e. lowest
5912      addressed) legitimate alignment boundary (based upon the required
5913      minimum alignment for the declared type of the field) which it can
5914      possibly use, subject to the condition that there is still enough
5915      available space remaining in the containing object (when allocated at
5916      the selected point) to fully accommodate all of the bits of the
5917      bit-field itself.  This simple rule makes it obvious why GCC allocates
5918      8 bytes for each object of the structure type shown above.  When looking
5919      for a place to allocate the "containing object" for `field2', the
5920      compiler simply tries to allocate a 64-bit "containing object" at each
5921      successive 32-bit boundary (starting at zero) until it finds a place to
5922      allocate that 64- bit field such that at least 31 contiguous (and
5923      previously unallocated) bits remain within that selected 64 bit field.
5924      (As it turns out, for the example above, the compiler finds that it is
5925      OK to allocate the "containing object" 64-bit field at bit-offset zero
5926      within the structure type.) Here we attempt to work backwards from the
5927      limited set of facts we're given, and we try to deduce from those facts, 
5928      where GCC must have believed that the containing object started (within
5929      the structure type). The value we deduce is then used (by the callers of 
5930      this routine) to generate DW_AT_location and DW_AT_bit_offset attributes 
5931      for fields (both bit-fields and, in the case of DW_AT_location, regular
5932      fields as well).  */
5933
5934   /* Figure out the bit-distance from the start of the structure to the
5935      "deepest" bit of the bit-field.  */
5936   deepest_bitpos = bitpos_int + field_size_in_bits;
5937
5938   /* This is the tricky part.  Use some fancy footwork to deduce where the
5939      lowest addressed bit of the containing object must be.  */
5940   object_offset_in_bits
5941     = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
5942
5943   /* Compute the offset of the containing object in "alignment units".  */
5944   object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
5945
5946   /* Compute the offset of the containing object in bytes.  */
5947   object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
5948
5949   return object_offset_in_bytes;
5950 }
5951 \f
5952 /* The following routines define various Dwarf attributes and any data
5953    associated with them.  */
5954
5955
5956 /* Output the form of location attributes suitable for whole variables and
5957    whole parameters.  Note that the location attributes for struct fields are
5958    generated by the routine `data_member_location_attribute' below.  */
5959
5960 static void
5961 add_location_attribute (die, rtl)
5962      dw_die_ref die;
5963      register rtx rtl;
5964 {
5965   dw_loc_descr_ref loc_descr = NULL;
5966
5967   /* Handle a special case.  If we are about to output a location descriptor
5968      for a variable or parameter which has been optimized out of existence,
5969      don't do that.  Instead we output a null location descriptor value as
5970      part of the location attribute. A variable which has been optimized out
5971      of existence will have a DECL_RTL value which denotes a pseudo-reg.
5972      Currently, in some rare cases, variables can have DECL_RTL values which
5973      look like (MEM (REG pseudo-reg#)).  These cases are due to bugs
5974      elsewhere in the compiler.  We treat such cases as if the variable(s) in 
5975      question had been optimized out of existence. Note that in all cases
5976      where we wish to express the fact that a variable has been optimized out 
5977      of existence, we do not simply suppress the generation of the entire
5978      location attribute because the absence of a location attribute in
5979      certain kinds of DIEs is used to indicate something else entirely...
5980      i.e. that the DIE represents an object declaration, but not a
5981      definition.  So sayeth the PLSIG.  */
5982
5983   if (!is_pseudo_reg (rtl)
5984       && (GET_CODE (rtl) != MEM
5985           || !is_pseudo_reg (XEXP (rtl, 0))))
5986     loc_descr = loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX, 0));
5987
5988 #ifdef MIPS_DEBUGGING_INFO
5989   /* ??? SGI's dwarf reader is buggy, and will not accept a zero size
5990      location descriptor.  Lets just use r0 for now to represent a
5991      variable that has been optimized away.  */
5992   if (loc_descr == NULL)
5993     loc_descr = loc_descriptor (gen_rtx (REG, word_mode, 0));
5994 #endif
5995
5996   add_AT_loc (die, DW_AT_location, loc_descr);
5997 }
5998
5999 /* Attach the specialized form of location attribute used for data
6000    members of struct and union types.  In the special case of a
6001    FIELD_DECL node which represents a bit-field, the "offset" part
6002    of this special location descriptor must indicate the distance
6003    in bytes from the lowest-addressed byte of the containing struct
6004    or union type to the lowest-addressed byte of the "containing
6005    object" for the bit-field.  (See the `field_byte_offset' function
6006    above).. For any given bit-field, the "containing object" is a
6007    hypothetical object (of some integral or enum type) within which
6008    the given bit-field lives.  The type of this hypothetical
6009    "containing object" is always the same as the declared type of
6010    the individual bit-field itself (for GCC anyway... the DWARF
6011    spec doesn't actually mandate this).  Note that it is the size
6012    (in bytes) of the hypothetical "containing object" which will
6013    be given in the DW_AT_byte_size attribute for this bit-field.
6014    (See the `byte_size_attribute' function below.)  It is also used
6015    when calculating the value of the DW_AT_bit_offset attribute.
6016    (See the `bit_offset_attribute' function below).  */
6017
6018 static void
6019 add_data_member_location_attribute (die, decl)
6020      register dw_die_ref die;
6021      register tree decl;
6022 {
6023   register unsigned long offset;
6024   register dw_loc_descr_ref loc_descr;
6025   register enum dwarf_location_atom op;
6026
6027   if (TREE_CODE (decl) == TREE_VEC)
6028     offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6029   else
6030     offset = field_byte_offset (decl);
6031
6032   /* The DWARF2 standard says that we should assume that the structure address
6033      is already on the stack, so we can specify a structure field address
6034      by using DW_OP_plus_uconst.  */
6035
6036 #ifdef MIPS_DEBUGGING_INFO
6037   /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6038      correctly.  It works only if we leave the offset on the stack.  */
6039   op = DW_OP_constu;
6040 #else
6041   op = DW_OP_plus_uconst;
6042 #endif
6043
6044   loc_descr = new_loc_descr (op, offset, 0);
6045   add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6046 }
6047
6048 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6049    does not have a "location" either in memory or in a register.  These
6050    things can arise in GNU C when a constant is passed as an actual parameter
6051    to an inlined function.  They can also arise in C++ where declared
6052    constants do not necessarily get memory "homes".  */
6053
6054 static void
6055 add_const_value_attribute (die, rtl)
6056      register dw_die_ref die;
6057      register rtx rtl;
6058 {
6059   switch (GET_CODE (rtl))
6060     {
6061     case CONST_INT:
6062       /* Note that a CONST_INT rtx could represent either an integer or a
6063          floating-point constant.  A CONST_INT is used whenever the constant
6064          will fit into a single word.  In all such cases, the original mode
6065          of the constant value is wiped out, and the CONST_INT rtx is
6066          assigned VOIDmode.  */
6067       add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6068       break;
6069
6070     case CONST_DOUBLE:
6071       /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6072          floating-point constant.  A CONST_DOUBLE is used whenever the
6073          constant requires more than one word in order to be adequately
6074          represented.  We output CONST_DOUBLEs as blocks.  */
6075       {
6076         register enum machine_mode mode = GET_MODE (rtl);
6077
6078         if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6079           {
6080             register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6081             long array[4];
6082             REAL_VALUE_TYPE rv;
6083
6084             REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6085             switch (mode)
6086               {
6087               case SFmode:
6088                 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6089                 break;
6090
6091               case DFmode:
6092                 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6093                 break;
6094
6095               case XFmode:
6096               case TFmode:
6097                 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6098                 break;
6099
6100               default:
6101                 abort ();
6102               }
6103
6104             add_AT_float (die, DW_AT_const_value, length, array);
6105           }
6106         else
6107           add_AT_long_long (die, DW_AT_const_value,
6108                             CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6109       }
6110       break;
6111
6112     case CONST_STRING:
6113       add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6114       break;
6115
6116     case SYMBOL_REF:
6117     case LABEL_REF:
6118     case CONST:
6119       add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6120       break;
6121
6122     case PLUS:
6123       /* In cases where an inlined instance of an inline function is passed
6124          the address of an `auto' variable (which is local to the caller) we
6125          can get a situation where the DECL_RTL of the artificial local
6126          variable (for the inlining) which acts as a stand-in for the
6127          corresponding formal parameter (of the inline function) will look
6128          like (plus:SI (reg:SI FRAME_PTR) (const_int ...)).  This is not
6129          exactly a compile-time constant expression, but it isn't the address 
6130          of the (artificial) local variable either.  Rather, it represents the 
6131          *value* which the artificial local variable always has during its
6132          lifetime.  We currently have no way to represent such quasi-constant 
6133          values in Dwarf, so for now we just punt and generate an
6134          DW_AT_const_value attribute with null address.  */
6135       add_AT_addr (die, DW_AT_const_value, addr_to_string (const0_rtx));
6136       break;
6137
6138     default:
6139       /* No other kinds of rtx should be possible here.  */
6140       abort ();
6141     }
6142
6143 }
6144
6145 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6146    data attribute for a variable or a parameter.  We generate the
6147    DW_AT_const_value attribute only in those cases where the given variable
6148    or parameter does not have a true "location" either in memory or in a
6149    register.  This can happen (for example) when a constant is passed as an
6150    actual argument in a call to an inline function.  (It's possible that
6151    these things can crop up in other ways also.)  Note that one type of
6152    constant value which can be passed into an inlined function is a constant
6153    pointer.  This can happen for example if an actual argument in an inlined
6154    function call evaluates to a compile-time constant address.  */
6155
6156 static void
6157 add_location_or_const_value_attribute (die, decl)
6158      register dw_die_ref die;
6159      register tree decl;
6160 {
6161   register rtx rtl;
6162   register tree declared_type;
6163   register tree passed_type;
6164
6165   if (TREE_CODE (decl) == ERROR_MARK)
6166     return;
6167
6168   if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6169     abort ();
6170
6171   /* Here we have to decide where we are going to say the parameter "lives"
6172      (as far as the debugger is concerned).  We only have a couple of
6173      choices.  GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6174
6175      DECL_RTL normally indicates where the parameter lives during most of the 
6176      activation of the function.  If optimization is enabled however, this
6177      could be either NULL or else a pseudo-reg.  Both of those cases indicate 
6178      that the parameter doesn't really live anywhere (as far as the code
6179      generation parts of GCC are concerned) during most of the function's
6180      activation.  That will happen (for example) if the parameter is never
6181      referenced within the function.
6182
6183      We could just generate a location descriptor here for all non-NULL
6184      non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6185      a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6186      where DECL_RTL is NULL or is a pseudo-reg.
6187
6188      Note however that we can only get away with using DECL_INCOMING_RTL as
6189      a backup substitute for DECL_RTL in certain limited cases.  In cases
6190      where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6191      we can be sure that the parameter was passed using the same type as it is
6192      declared to have within the function, and that its DECL_INCOMING_RTL
6193      points us to a place where a value of that type is passed.
6194
6195      In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6196      we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6197      because in these cases DECL_INCOMING_RTL points us to a value of some
6198      type which is *different* from the type of the parameter itself.  Thus,
6199      if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6200      such cases, the debugger would end up (for example) trying to fetch a
6201      `float' from a place which actually contains the first part of a
6202      `double'.  That would lead to really incorrect and confusing
6203      output at debug-time.
6204
6205      So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6206      in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl).  There
6207      are a couple of exceptions however.  On little-endian machines we can
6208      get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6209      not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6210      an integral type that is smaller than TREE_TYPE (decl). These cases arise
6211      when (on a little-endian machine) a non-prototyped function has a
6212      parameter declared to be of type `short' or `char'.  In such cases,
6213      TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6214      be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6215      passed `int' value.  If the debugger then uses that address to fetch
6216      a `short' or a `char' (on a little-endian machine) the result will be
6217      the correct data, so we allow for such exceptional cases below.
6218
6219      Note that our goal here is to describe the place where the given formal
6220      parameter lives during most of the function's activation (i.e. between
6221      the end of the prologue and the start of the epilogue).  We'll do that
6222      as best as we can. Note however that if the given formal parameter is
6223      modified sometime during the execution of the function, then a stack
6224      backtrace (at debug-time) will show the function as having been
6225      called with the *new* value rather than the value which was
6226      originally passed in.  This happens rarely enough that it is not
6227      a major problem, but it *is* a problem, and I'd like to fix it.
6228
6229      A future version of dwarf2out.c may generate two additional
6230      attributes for any given DW_TAG_formal_parameter DIE which will
6231      describe the "passed type" and the "passed location" for the
6232      given formal parameter in addition to the attributes we now
6233      generate to indicate the "declared type" and the "active
6234      location" for each parameter.  This additional set of attributes
6235      could be used by debuggers for stack backtraces. Separately, note
6236      that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6237      NULL also.  This happens (for example) for inlined-instances of
6238      inline function formal parameters which are never referenced.
6239      This really shouldn't be happening.  All PARM_DECL nodes should
6240      get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6241      doesn't currently generate these values for inlined instances of
6242      inline function parameters, so when we see such cases, we are
6243      just SOL (shit-out-of-luck) for the time being (until integrate.c
6244      gets fixed).  */
6245
6246   /* Use DECL_RTL as the "location" unless we find something better.  */
6247   rtl = DECL_RTL (decl);
6248
6249   if (TREE_CODE (decl) == PARM_DECL)
6250     {
6251       if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6252         {
6253           declared_type = type_main_variant (TREE_TYPE (decl));
6254           passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6255
6256           /* This decl represents a formal parameter which was optimized out.
6257              Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6258              all* cases where (rtl == NULL_RTX) just below.  */
6259           if (declared_type == passed_type)
6260             rtl = DECL_INCOMING_RTL (decl);
6261           else if (! BYTES_BIG_ENDIAN
6262                    && TREE_CODE (declared_type) == INTEGER_TYPE
6263                    && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type))
6264                 rtl = DECL_INCOMING_RTL (decl);
6265         }
6266     }
6267
6268   if (rtl == NULL_RTX)
6269     return;
6270
6271   switch (GET_CODE (rtl))
6272     {
6273     case CONST_INT:
6274     case CONST_DOUBLE:
6275     case CONST_STRING:
6276     case SYMBOL_REF:
6277     case LABEL_REF:
6278     case CONST:
6279     case PLUS:
6280       /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
6281       add_const_value_attribute (die, rtl);
6282       break;
6283
6284     case MEM:
6285     case REG:
6286     case SUBREG:
6287       add_location_attribute (die, rtl);
6288       break;
6289
6290     default:
6291       abort ();
6292     }
6293 }
6294
6295 /* Generate an DW_AT_name attribute given some string value to be included as
6296    the value of the attribute.  */
6297
6298 static inline void
6299 add_name_attribute (die, name_string)
6300      register dw_die_ref die;
6301      register char *name_string;
6302 {
6303   if (name_string != NULL && *name_string != 0)
6304     add_AT_string (die, DW_AT_name, name_string);
6305 }
6306
6307 /* Given a tree node describing an array bound (either lower or upper) output
6308    a representation for that bound.  */
6309
6310 static void
6311 add_bound_info (subrange_die, bound_attr, bound)
6312      register dw_die_ref subrange_die;
6313      register enum dwarf_attribute bound_attr;
6314      register tree bound;
6315 {
6316   register unsigned bound_value = 0;
6317   switch (TREE_CODE (bound))
6318     {
6319     case ERROR_MARK:
6320       return;
6321
6322     /* All fixed-bounds are represented by INTEGER_CST nodes.        */
6323     case INTEGER_CST:
6324       bound_value = TREE_INT_CST_LOW (bound);
6325       if (bound_attr == DW_AT_lower_bound
6326           && ((is_c_family () && bound_value == 0)
6327               || (is_fortran () && bound_value == 1)))
6328         /* use the default */;
6329       else
6330         add_AT_unsigned (subrange_die, bound_attr, bound_value);
6331       break;
6332
6333     case CONVERT_EXPR:
6334     case NOP_EXPR:
6335     case NON_LVALUE_EXPR:
6336       add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
6337       break;
6338       
6339     case SAVE_EXPR:
6340       /* If optimization is turned on, the SAVE_EXPRs that describe how to
6341          access the upper bound values may be bogus.  If they refer to a
6342          register, they may only describe how to get at these values at the
6343          points in the generated code right after they have just been
6344          computed.  Worse yet, in the typical case, the upper bound values
6345          will not even *be* computed in the optimized code (though the
6346          number of elements will), so these SAVE_EXPRs are entirely
6347          bogus. In order to compensate for this fact, we check here to see
6348          if optimization is enabled, and if so, we don't add an attribute
6349          for the (unknown and unknowable) upper bound.  This should not
6350          cause too much trouble for existing (stupid?)  debuggers because
6351          they have to deal with empty upper bounds location descriptions
6352          anyway in order to be able to deal with incomplete array types.
6353          Of course an intelligent debugger (GDB?)  should be able to
6354          comprehend that a missing upper bound specification in a array
6355          type used for a storage class `auto' local array variable
6356          indicates that the upper bound is both unknown (at compile- time)
6357          and unknowable (at run-time) due to optimization.
6358
6359          We assume that a MEM rtx is safe because gcc wouldn't put the
6360          value there unless it was going to be used repeatedly in the
6361          function, i.e. for cleanups.  */
6362       if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
6363         {
6364           register dw_die_ref ctx = lookup_decl_die (current_function_decl);
6365           register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
6366           add_AT_flag (decl_die, DW_AT_artificial, 1);
6367           add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
6368           add_location_attribute (decl_die, SAVE_EXPR_RTL (bound));
6369           add_AT_die_ref (subrange_die, bound_attr, decl_die);
6370         }
6371
6372       /* Else leave out the attribute.  */
6373       break;
6374     }
6375 }
6376
6377 /* Note that the block of subscript information for an array type also
6378    includes information about the element type of type given array type.  */
6379
6380 static void
6381 add_subscript_info (type_die, type)
6382      register dw_die_ref type_die;
6383      register tree type;
6384 {
6385   register unsigned dimension_number;
6386   register tree lower, upper;
6387   register dw_die_ref subrange_die;
6388
6389   /* The GNU compilers represent multidimensional array types as sequences of 
6390      one dimensional array types whose element types are themselves array
6391      types.  Here we squish that down, so that each multidimensional array
6392      type gets only one array_type DIE in the Dwarf debugging info. The draft 
6393      Dwarf specification say that we are allowed to do this kind of
6394      compression in C (because there is no difference between an array or
6395      arrays and a multidimensional array in C) but for other source languages 
6396      (e.g. Ada) we probably shouldn't do this.  */
6397
6398   /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6399      const enum type.  E.g. const enum machine_mode insn_operand_mode[2][10].
6400      We work around this by disabling this feature.  See also
6401      gen_array_type_die.  */
6402 #ifndef MIPS_DEBUGGING_INFO
6403   for (dimension_number = 0;
6404        TREE_CODE (type) == ARRAY_TYPE;
6405        type = TREE_TYPE (type), dimension_number++)
6406     {
6407 #endif
6408       register tree domain = TYPE_DOMAIN (type);
6409
6410       /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
6411          and (in GNU C only) variable bounds.  Handle all three forms 
6412          here.  */
6413       subrange_die = new_die (DW_TAG_subrange_type, type_die);
6414       if (domain)
6415         {
6416           /* We have an array type with specified bounds.  */
6417           lower = TYPE_MIN_VALUE (domain);
6418           upper = TYPE_MAX_VALUE (domain);
6419
6420           /* define the index type.  */
6421           if (TREE_TYPE (domain))
6422             add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
6423                                 type_die);
6424
6425           add_bound_info (subrange_die, DW_AT_lower_bound, lower);
6426           add_bound_info (subrange_die, DW_AT_upper_bound, upper);
6427         }
6428       else
6429         /* We have an array type with an unspecified length.  The DWARF-2
6430              spec does not say how to handle this; let's just leave out the
6431              bounds.  */
6432         ;
6433
6434 #ifndef MIPS_DEBUGGING_INFO
6435     }
6436 #endif
6437 }
6438
6439 static void
6440 add_byte_size_attribute (die, tree_node)
6441      dw_die_ref die;
6442      register tree tree_node;
6443 {
6444   register unsigned size;
6445
6446   switch (TREE_CODE (tree_node))
6447     {
6448     case ERROR_MARK:
6449       size = 0;
6450       break;
6451     case ENUMERAL_TYPE:
6452     case RECORD_TYPE:
6453     case UNION_TYPE:
6454     case QUAL_UNION_TYPE:
6455       size = int_size_in_bytes (tree_node);
6456       break;
6457     case FIELD_DECL:
6458       /* For a data member of a struct or union, the DW_AT_byte_size is
6459          generally given as the number of bytes normally allocated for an
6460          object of the *declared* type of the member itself.  This is true
6461          even for bit-fields.  */
6462       size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
6463       break;
6464     default:
6465       abort ();
6466     }
6467
6468   /* Note that `size' might be -1 when we get to this point.  If it is, that
6469      indicates that the byte size of the entity in question is variable.  We
6470      have no good way of expressing this fact in Dwarf at the present time,
6471      so just let the -1 pass on through.  */
6472
6473   add_AT_unsigned (die, DW_AT_byte_size, size);
6474 }
6475
6476 /* For a FIELD_DECL node which represents a bit-field, output an attribute
6477    which specifies the distance in bits from the highest order bit of the
6478    "containing object" for the bit-field to the highest order bit of the
6479    bit-field itself.
6480
6481    For any given bit-field, the "containing object" is a hypothetical
6482    object (of some integral or enum type) within which the given bit-field
6483    lives.  The type of this hypothetical "containing object" is always the
6484    same as the declared type of the individual bit-field itself.  The
6485    determination of the exact location of the "containing object" for a
6486    bit-field is rather complicated.  It's handled by the
6487    `field_byte_offset' function (above).
6488
6489    Note that it is the size (in bytes) of the hypothetical "containing object"
6490    which will be given in the DW_AT_byte_size attribute for this bit-field.
6491    (See `byte_size_attribute' above).  */
6492
6493 static inline void
6494 add_bit_offset_attribute (die, decl)
6495      register dw_die_ref die;
6496      register tree decl;
6497 {
6498   register unsigned object_offset_in_bytes = field_byte_offset (decl);
6499   register tree type = DECL_BIT_FIELD_TYPE (decl);
6500   register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
6501   register unsigned bitpos_int;
6502   register unsigned highest_order_object_bit_offset;
6503   register unsigned highest_order_field_bit_offset;
6504   register unsigned bit_offset;
6505
6506   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
6507   assert (type);                                /* Must be a bit field.  */
6508
6509   /* We can't yet handle bit-fields whose offsets are variable, so if we
6510      encounter such things, just return without generating any attribute
6511      whatsoever.  */
6512   if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6513     return;
6514
6515   bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6516
6517   /* Note that the bit offset is always the distance (in bits) from the
6518      highest-order bit of the "containing object" to the highest-order bit of 
6519      the bit-field itself.  Since the "high-order end" of any object or field 
6520      is different on big-endian and little-endian machines, the computation
6521      below must take account of these differences.  */
6522   highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
6523   highest_order_field_bit_offset = bitpos_int;
6524
6525   if (! BYTES_BIG_ENDIAN)
6526     {
6527       highest_order_field_bit_offset
6528         += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
6529
6530       highest_order_object_bit_offset += simple_type_size_in_bits (type);
6531     }
6532
6533   bit_offset
6534     = (! BYTES_BIG_ENDIAN
6535        ? highest_order_object_bit_offset - highest_order_field_bit_offset
6536        : highest_order_field_bit_offset - highest_order_object_bit_offset);
6537
6538   add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
6539 }
6540
6541 /* For a FIELD_DECL node which represents a bit field, output an attribute
6542    which specifies the length in bits of the given field.  */
6543
6544 static inline void
6545 add_bit_size_attribute (die, decl)
6546      register dw_die_ref die;
6547      register tree decl;
6548 {
6549   assert (TREE_CODE (decl) == FIELD_DECL);      /* Must be a field.  */
6550   assert (DECL_BIT_FIELD_TYPE (decl));          /* Must be a bit field.  */
6551   add_AT_unsigned (die, DW_AT_bit_size,
6552                    (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
6553 }
6554
6555 /* If the compiled language is ANSI C, then add a 'prototyped'
6556    attribute, if arg types are given for the parameters of a function.  */
6557
6558 static inline void
6559 add_prototyped_attribute (die, func_type)
6560      register dw_die_ref die;
6561      register tree func_type;
6562 {
6563   if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
6564       && TYPE_ARG_TYPES (func_type) != NULL)
6565     add_AT_flag (die, DW_AT_prototyped, 1);
6566 }
6567
6568
6569 /* Add an 'abstract_origin' attribute below a given DIE.  The DIE is found
6570    by looking in either the type declaration or object declaration
6571    equate table.  */
6572
6573 static inline void
6574 add_abstract_origin_attribute (die, origin)
6575      register dw_die_ref die;
6576      register tree origin;
6577 {
6578   dw_die_ref origin_die = NULL;
6579   if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
6580     origin_die = lookup_decl_die (origin);
6581   else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
6582     origin_die = lookup_type_die (origin);
6583
6584   add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
6585 }
6586
6587 /* We do not currently support the pure_virtual attribute.  */
6588
6589 static inline void
6590 add_pure_or_virtual_attribute (die, func_decl)
6591      register dw_die_ref die;
6592      register tree func_decl;
6593 {
6594   if (DECL_VINDEX (func_decl))
6595     {
6596       add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
6597       add_AT_loc (die, DW_AT_vtable_elem_location,
6598                   new_loc_descr (DW_OP_constu,
6599                                  TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
6600                                  0));
6601
6602       /* GNU extension: Record what type this method came from originally.  */
6603       if (debug_info_level > DINFO_LEVEL_TERSE)
6604         add_AT_die_ref (die, DW_AT_containing_type,
6605                         lookup_type_die (DECL_CONTEXT (func_decl)));
6606     }
6607 }
6608 \f
6609 /* Add source coordinate attributes for the given decl.  */
6610
6611 static void
6612 add_src_coords_attributes (die, decl)
6613      register dw_die_ref die;
6614      register tree decl;
6615 {
6616   register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
6617
6618   add_AT_unsigned (die, DW_AT_decl_file, file_index);
6619   add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
6620 }
6621
6622 /* Add an DW_AT_name attribute and source coordinate attribute for the
6623    given decl, but only if it actually has a name.  */
6624
6625 static void
6626 add_name_and_src_coords_attributes (die, decl)
6627      register dw_die_ref die;
6628      register tree decl;
6629 {
6630   register tree decl_name;
6631
6632   decl_name = DECL_NAME (decl); 
6633   if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
6634     {
6635       add_name_attribute (die, dwarf2_name (decl, 0));
6636       add_src_coords_attributes (die, decl);
6637       if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
6638           && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
6639         add_AT_string (die, DW_AT_MIPS_linkage_name,
6640                        IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
6641     }
6642 }
6643
6644 /* Push a new declaration scope. */
6645
6646 static void
6647 push_decl_scope (scope)
6648      tree scope;
6649 {
6650   /* Make room in the decl_scope_table, if necessary.  */
6651   if (decl_scope_table_allocated == decl_scope_depth)
6652     {
6653       decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
6654       decl_scope_table
6655         = (tree *) xrealloc (decl_scope_table,
6656                              decl_scope_table_allocated * sizeof (tree));
6657     }
6658
6659   decl_scope_table[decl_scope_depth++] = scope;
6660 }
6661
6662 /* Return the DIE for the scope the immediately contains this declaration.  */
6663
6664 static dw_die_ref
6665 scope_die_for (t, context_die)
6666     register tree t; 
6667     register dw_die_ref context_die;
6668 {
6669   register dw_die_ref scope_die = NULL;
6670   register tree containing_scope;
6671   register unsigned long i;
6672
6673   /* Function-local tags and functions get stuck in limbo until they are
6674      fixed up by decls_for_scope.  */
6675   if (context_die == NULL
6676       && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
6677     return NULL;
6678
6679   /* Walk back up the declaration tree looking for a place to define
6680      this type.  */
6681   if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
6682     containing_scope = TYPE_CONTEXT (t);
6683   else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
6684     containing_scope = decl_class_context (t);
6685   else
6686     containing_scope = DECL_CONTEXT (t);
6687
6688   if (containing_scope == NULL_TREE)
6689     scope_die = comp_unit_die;
6690   else
6691     {
6692       for (i = decl_scope_depth, scope_die = context_die;
6693            i > 0 && decl_scope_table[i - 1] != containing_scope;
6694            scope_die = scope_die->die_parent, --i)
6695         ;
6696
6697       if (i == 0)
6698         {
6699           assert (scope_die == comp_unit_die);
6700           assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't');
6701           if (debug_info_level > DINFO_LEVEL_TERSE)
6702             assert (TREE_ASM_WRITTEN (containing_scope));
6703         }
6704     }
6705
6706   return scope_die;
6707 }
6708
6709 /* Pop a declaration scope.  */
6710 static inline void
6711 pop_decl_scope ()
6712 {
6713   assert (decl_scope_depth > 0);
6714   --decl_scope_depth;
6715 }
6716
6717 /* Many forms of DIEs require a "type description" attribute.  This
6718    routine locates the proper "type descriptor" die for the type given
6719    by 'type', and adds an DW_AT_type attribute below the given die.  */
6720
6721 static void
6722 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
6723      register dw_die_ref object_die;
6724      register tree type;
6725      register int decl_const;
6726      register int decl_volatile;
6727      register dw_die_ref context_die;
6728 {
6729   register enum tree_code code  = TREE_CODE (type);
6730   register dw_die_ref type_die  = NULL;
6731
6732   /* If this type is an unnamed subtype of an integral or floating-point
6733      type, use the inner type.  */
6734   if ((code == INTEGER_TYPE || code == REAL_TYPE)
6735       && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
6736     type = TREE_TYPE (type), code = TREE_CODE (type);
6737
6738   if (code == ERROR_MARK)
6739     return;
6740
6741   /* Handle a special case.  For functions whose return type is void, we
6742      generate *no* type attribute.  (Note that no object may have type
6743      `void', so this only applies to function return types).  */
6744   if (code == VOID_TYPE)
6745     return;
6746
6747   type_die = modified_type_die (type,
6748                                 decl_const || TYPE_READONLY (type),
6749                                 decl_volatile || TYPE_VOLATILE (type),
6750                                 context_die);
6751   if (type_die != NULL)
6752     add_AT_die_ref (object_die, DW_AT_type, type_die);
6753 }
6754
6755 /* Given a tree pointer to a struct, class, union, or enum type node, return
6756    a pointer to the (string) tag name for the given type, or zero if the type
6757    was declared without a tag.  */
6758
6759 static char *
6760 type_tag (type)
6761      register tree type;
6762 {
6763   register char *name = 0;
6764
6765   if (TYPE_NAME (type) != 0)
6766     {
6767       register tree t = 0;
6768
6769       /* Find the IDENTIFIER_NODE for the type name.  */
6770       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
6771         t = TYPE_NAME (type);
6772
6773       /* The g++ front end makes the TYPE_NAME of *each* tagged type point to 
6774          a TYPE_DECL node, regardless of whether or not a `typedef' was
6775          involved.  */
6776       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6777                && ! DECL_IGNORED_P (TYPE_NAME (type)))
6778         t = DECL_NAME (TYPE_NAME (type));
6779
6780       /* Now get the name as a string, or invent one.  */
6781       if (t != 0)
6782         name = IDENTIFIER_POINTER (t);
6783     }
6784
6785   return (name == 0 || *name == '\0') ? 0 : name;
6786 }
6787
6788 /* Return the type associated with a data member, make a special check
6789    for bit field types.  */
6790
6791 static inline tree
6792 member_declared_type (member)
6793      register tree member;
6794 {
6795   return (DECL_BIT_FIELD_TYPE (member)
6796           ? DECL_BIT_FIELD_TYPE (member)
6797           : TREE_TYPE (member));
6798 }
6799
6800 /* Get the decl's label, as described by its RTL. This may be different
6801    from the DECL_NAME name used in the source file.  */
6802
6803 static char *
6804 decl_start_label (decl)
6805      register tree decl;
6806 {
6807   rtx x;
6808   char *fnname;
6809   x = DECL_RTL (decl);
6810   if (GET_CODE (x) != MEM)
6811     abort ();
6812
6813   x = XEXP (x, 0);
6814   if (GET_CODE (x) != SYMBOL_REF)
6815     abort ();
6816
6817   fnname = XSTR (x, 0);
6818   return fnname;
6819 }
6820 \f
6821 /* These routines generate the internnal representation of the DIE's for
6822    the compilation unit.  Debugging information is collected by walking
6823    the declaration trees passed in from dwarf2out_decl().  */
6824
6825 static void
6826 gen_array_type_die (type, context_die)
6827      register tree type;
6828      register dw_die_ref context_die;
6829 {
6830   register dw_die_ref scope_die = scope_die_for (type, context_die);
6831   register dw_die_ref array_die;
6832   register tree element_type;
6833
6834   /* ??? The SGI dwarf reader fails for array of array of enum types unless
6835      the inner array type comes before the outer array type.  Thus we must
6836      call gen_type_die before we call new_die.  See below also.  */
6837 #ifdef MIPS_DEBUGGING_INFO
6838   gen_type_die (TREE_TYPE (type), context_die);
6839 #endif
6840
6841   array_die = new_die (DW_TAG_array_type, scope_die);
6842
6843 #if 0
6844   /* We default the array ordering.  SDB will probably do
6845      the right things even if DW_AT_ordering is not present.  It's not even
6846      an issue until we start to get into multidimensional arrays anyway.  If
6847      SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
6848      then we'll have to put the DW_AT_ordering attribute back in.  (But if
6849      and when we find out that we need to put these in, we will only do so
6850      for multidimensional arrays.  */
6851   add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
6852 #endif
6853
6854 #ifdef MIPS_DEBUGGING_INFO
6855   /* The SGI compilers handle arrays of unknown bound by setting
6856      AT_declaration and not emitting any subrange DIEs.  */
6857   if (! TYPE_DOMAIN (type))
6858     add_AT_unsigned (array_die, DW_AT_declaration, 1);
6859   else
6860 #endif
6861     add_subscript_info (array_die, type);
6862
6863   equate_type_number_to_die (type, array_die);
6864
6865   /* Add representation of the type of the elements of this array type.  */
6866   element_type = TREE_TYPE (type);
6867
6868   /* ??? The SGI dwarf reader fails for multidimensional arrays with a
6869      const enum type.  E.g. const enum machine_mode insn_operand_mode[2][10].
6870      We work around this by disabling this feature.  See also
6871      add_subscript_info.  */
6872 #ifndef MIPS_DEBUGGING_INFO
6873   while (TREE_CODE (element_type) == ARRAY_TYPE)
6874     element_type = TREE_TYPE (element_type);
6875
6876   gen_type_die (element_type, context_die);
6877 #endif
6878
6879   add_type_attribute (array_die, element_type, 0, 0, context_die);
6880 }
6881
6882 static void
6883 gen_set_type_die (type, context_die)
6884      register tree type;
6885      register dw_die_ref context_die;
6886 {
6887   register dw_die_ref type_die
6888     = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
6889
6890   equate_type_number_to_die (type, type_die);
6891   add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
6892 }
6893
6894 static void
6895 gen_entry_point_die (decl, context_die)
6896      register tree decl;
6897      register dw_die_ref context_die;
6898 {
6899   register tree origin = decl_ultimate_origin (decl);
6900   register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
6901   if (origin != NULL)
6902     add_abstract_origin_attribute (decl_die, origin);
6903   else
6904     {
6905       add_name_and_src_coords_attributes (decl_die, decl);
6906       add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
6907                           0, 0, context_die);
6908     }
6909
6910   if (DECL_ABSTRACT (decl))
6911     equate_decl_number_to_die (decl, decl_die);
6912   else
6913     add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
6914 }
6915
6916 /* Remember a type in the pending_types_list.  */
6917
6918 static void
6919 pend_type (type)
6920      register tree type;
6921 {
6922   if (pending_types == pending_types_allocated)
6923     {
6924       pending_types_allocated += PENDING_TYPES_INCREMENT;
6925       pending_types_list
6926         = (tree *) xrealloc (pending_types_list,
6927                              sizeof (tree) * pending_types_allocated);
6928     }
6929
6930   pending_types_list[pending_types++] = type;
6931 }
6932
6933 /* Output any pending types (from the pending_types list) which we can output
6934    now (taking into account the scope that we are working on now).
6935
6936    For each type output, remove the given type from the pending_types_list
6937    *before* we try to output it.  */
6938
6939 static void
6940 output_pending_types_for_scope (context_die)
6941      register dw_die_ref context_die;
6942 {
6943   register tree type;
6944
6945   while (pending_types)
6946     {
6947       --pending_types;
6948       type = pending_types_list[pending_types];
6949       gen_type_die (type, context_die);
6950       assert (TREE_ASM_WRITTEN (type));
6951     }
6952 }
6953
6954 /* Generate a DIE to represent an inlined instance of an enumeration type.  */
6955
6956 static void
6957 gen_inlined_enumeration_type_die (type, context_die)
6958      register tree type;
6959      register dw_die_ref context_die;
6960 {
6961   register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
6962                                           scope_die_for (type, context_die));
6963
6964   assert (TREE_ASM_WRITTEN (type));
6965   add_abstract_origin_attribute (type_die, type);
6966 }
6967
6968 /* Generate a DIE to represent an inlined instance of a structure type.  */
6969
6970 static void
6971 gen_inlined_structure_type_die (type, context_die)
6972      register tree type;
6973      register dw_die_ref context_die;
6974 {
6975   register dw_die_ref type_die = new_die (DW_TAG_structure_type,
6976                                           scope_die_for (type, context_die));
6977
6978   assert (TREE_ASM_WRITTEN (type));
6979   add_abstract_origin_attribute (type_die, type);
6980 }
6981
6982 /* Generate a DIE to represent an inlined instance of a union type.  */
6983
6984 static void
6985 gen_inlined_union_type_die (type, context_die)
6986      register tree type;
6987      register dw_die_ref context_die;
6988 {
6989   register dw_die_ref type_die = new_die (DW_TAG_union_type,
6990                                           scope_die_for (type, context_die));
6991
6992   assert (TREE_ASM_WRITTEN (type));
6993   add_abstract_origin_attribute (type_die, type);
6994 }
6995
6996 /* Generate a DIE to represent an enumeration type.  Note that these DIEs
6997    include all of the information about the enumeration values also. Each
6998    enumerated type name/value is listed as a child of the enumerated type
6999    DIE.  */
7000
7001 static void
7002 gen_enumeration_type_die (type, context_die)
7003      register tree type;
7004      register dw_die_ref context_die;
7005 {
7006   register dw_die_ref type_die = lookup_type_die (type);
7007
7008   if (type_die == NULL)
7009     {
7010       type_die = new_die (DW_TAG_enumeration_type,
7011                           scope_die_for (type, context_die));
7012       equate_type_number_to_die (type, type_die);
7013       add_name_attribute (type_die, type_tag (type));
7014     }
7015   else if (! TYPE_SIZE (type))
7016     return;
7017   else
7018     remove_AT (type_die, DW_AT_declaration);
7019
7020   /* Handle a GNU C/C++ extension, i.e. incomplete enum types.  If the
7021      given enum type is incomplete, do not generate the DW_AT_byte_size
7022      attribute or the DW_AT_element_list attribute.  */
7023   if (TYPE_SIZE (type))
7024     {
7025       register tree link;
7026
7027       TREE_ASM_WRITTEN (type) = 1;
7028       add_byte_size_attribute (type_die, type);
7029       if (type_tag (type))
7030         add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7031
7032       for (link = TYPE_FIELDS (type);
7033            link != NULL; link = TREE_CHAIN (link))
7034         {
7035           register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7036
7037           add_name_attribute (enum_die,
7038                               IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7039           add_AT_unsigned (enum_die, DW_AT_const_value,
7040                            (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7041         }
7042     }
7043   else
7044     add_AT_flag (type_die, DW_AT_declaration, 1);
7045 }
7046
7047
7048 /* Generate a DIE to represent either a real live formal parameter decl or to
7049    represent just the type of some formal parameter position in some function
7050    type.
7051
7052    Note that this routine is a bit unusual because its argument may be a
7053    ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7054    represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7055    node.  If it's the former then this function is being called to output a
7056    DIE to represent a formal parameter object (or some inlining thereof).  If
7057    it's the latter, then this function is only being called to output a
7058    DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7059    argument type of some subprogram type.  */
7060
7061 static dw_die_ref
7062 gen_formal_parameter_die (node, context_die)
7063      register tree node;
7064      register dw_die_ref context_die;
7065 {
7066   register dw_die_ref parm_die
7067     = new_die (DW_TAG_formal_parameter, context_die);
7068   register tree origin;
7069
7070   switch (TREE_CODE_CLASS (TREE_CODE (node)))
7071     {
7072     case 'd':
7073       origin = decl_ultimate_origin (node);
7074       if (origin != NULL)
7075         add_abstract_origin_attribute (parm_die, origin);
7076       else
7077         {
7078           add_name_and_src_coords_attributes (parm_die, node);
7079           add_type_attribute (parm_die, TREE_TYPE (node),
7080                               TREE_READONLY (node),
7081                               TREE_THIS_VOLATILE (node),
7082                               context_die);
7083           if (DECL_ARTIFICIAL (node))
7084             add_AT_flag (parm_die, DW_AT_artificial, 1);
7085         }
7086
7087       equate_decl_number_to_die (node, parm_die);
7088       if (! DECL_ABSTRACT (node))
7089         add_location_or_const_value_attribute (parm_die, node);
7090
7091       break;
7092
7093     case 't':
7094       /* We were called with some kind of a ..._TYPE node.  */
7095       add_type_attribute (parm_die, node, 0, 0, context_die);
7096       break;
7097
7098     default:
7099       abort ();
7100     }
7101
7102   return parm_die;
7103 }
7104
7105 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7106    at the end of an (ANSI prototyped) formal parameters list.  */
7107
7108 static void
7109 gen_unspecified_parameters_die (decl_or_type, context_die)
7110      register tree decl_or_type;
7111      register dw_die_ref context_die;
7112 {
7113   register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters,
7114                                           context_die);
7115 }
7116
7117 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7118    DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7119    parameters as specified in some function type specification (except for
7120    those which appear as part of a function *definition*).
7121
7122    Note we must be careful here to output all of the parameter DIEs before*
7123    we output any DIEs needed to represent the types of the formal parameters.
7124    This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7125    non-parameter DIE it sees ends the formal parameter list.  */
7126
7127 static void
7128 gen_formal_types_die (function_or_method_type, context_die)
7129      register tree function_or_method_type;
7130      register dw_die_ref context_die;
7131 {
7132   register tree link;
7133   register tree formal_type = NULL;
7134   register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7135
7136 #if 0
7137   /* In the case where we are generating a formal types list for a C++
7138      non-static member function type, skip over the first thing on the
7139      TYPE_ARG_TYPES list because it only represents the type of the hidden
7140      `this pointer'.  The debugger should be able to figure out (without
7141      being explicitly told) that this non-static member function type takes a 
7142      `this pointer' and should be able to figure what the type of that hidden 
7143      parameter is from the DW_AT_member attribute of the parent
7144      DW_TAG_subroutine_type DIE.  */
7145   if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
7146     first_parm_type = TREE_CHAIN (first_parm_type);
7147 #endif
7148
7149   /* Make our first pass over the list of formal parameter types and output a 
7150      DW_TAG_formal_parameter DIE for each one.  */
7151   for (link = first_parm_type; link; link = TREE_CHAIN (link))
7152     {
7153       register dw_die_ref parm_die;
7154       
7155       formal_type = TREE_VALUE (link);
7156       if (formal_type == void_type_node)
7157         break;
7158
7159       /* Output a (nameless) DIE to represent the formal parameter itself.  */
7160       parm_die = gen_formal_parameter_die (formal_type, context_die);
7161       if (TREE_CODE (function_or_method_type) == METHOD_TYPE
7162           && link == first_parm_type)
7163         add_AT_flag (parm_die, DW_AT_artificial, 1);
7164     }
7165
7166   /* If this function type has an ellipsis, add a
7167      DW_TAG_unspecified_parameters DIE to the end of the parameter list.  */
7168   if (formal_type != void_type_node)
7169     gen_unspecified_parameters_die (function_or_method_type, context_die);
7170
7171   /* Make our second (and final) pass over the list of formal parameter types 
7172      and output DIEs to represent those types (as necessary).  */
7173   for (link = TYPE_ARG_TYPES (function_or_method_type);
7174        link;
7175        link = TREE_CHAIN (link))
7176     {
7177       formal_type = TREE_VALUE (link);
7178       if (formal_type == void_type_node)
7179         break;
7180
7181       gen_type_die (formal_type, context_die);
7182     }
7183 }
7184
7185 /* Generate a DIE to represent a declared function (either file-scope or
7186    block-local).  */
7187
7188 static void
7189 gen_subprogram_die (decl, context_die)
7190      register tree decl;
7191      register dw_die_ref context_die;
7192 {
7193   char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
7194   register tree origin = decl_ultimate_origin (decl);
7195   register dw_die_ref subr_die;
7196   register dw_loc_descr_ref fp_loc = NULL;
7197   register rtx fp_reg;
7198   register tree fn_arg_types;
7199   register tree outer_scope;
7200   register dw_die_ref old_die = lookup_decl_die (decl);
7201   register int declaration = (current_function_decl != decl
7202                               || context_die->die_tag == DW_TAG_structure_type
7203                               || context_die->die_tag == DW_TAG_union_type);
7204
7205   if (origin != NULL)
7206     {
7207       subr_die = new_die (DW_TAG_subprogram, context_die);
7208       add_abstract_origin_attribute (subr_die, origin);
7209     }
7210   else if (old_die)
7211     {
7212       register unsigned file_index
7213         = lookup_filename (DECL_SOURCE_FILE (decl));
7214
7215       assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
7216
7217       /* If the definition comes from the same place as the declaration,
7218          maybe use the old DIE.  We always want the DIE for this function
7219          that has the *_pc attributes to be under comp_unit_die so the
7220          debugger can find it.  For inlines, that is the concrete instance,
7221          so we can use the old DIE here.  For non-inline methods, we want a
7222          specification DIE at toplevel, so we need a new DIE.  For local
7223          class methods, this does not apply.  */
7224       if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
7225            || context_die == NULL)
7226           && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
7227           && (get_AT_unsigned (old_die, DW_AT_decl_line)
7228               == DECL_SOURCE_LINE (decl)))
7229         {
7230           subr_die = old_die;
7231
7232           /* Clear out the declaration attribute and the parm types.  */
7233           remove_AT (subr_die, DW_AT_declaration);
7234           remove_children (subr_die);
7235         }
7236       else
7237         {
7238           subr_die = new_die (DW_TAG_subprogram, context_die);
7239           add_AT_die_ref (subr_die, DW_AT_specification, old_die);
7240           if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7241             add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
7242           if (get_AT_unsigned (old_die, DW_AT_decl_line)
7243               != DECL_SOURCE_LINE (decl))
7244             add_AT_unsigned
7245               (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7246         }
7247     }
7248   else
7249     {
7250       register dw_die_ref scope_die;
7251
7252       if (DECL_CONTEXT (decl))
7253         scope_die = scope_die_for (decl, context_die);
7254       else
7255         /* Don't put block extern declarations under comp_unit_die.  */
7256         scope_die = context_die;
7257
7258       subr_die = new_die (DW_TAG_subprogram, scope_die);
7259                          
7260       if (TREE_PUBLIC (decl))
7261         add_AT_flag (subr_die, DW_AT_external, 1);
7262
7263       add_name_and_src_coords_attributes (subr_die, decl);
7264       if (debug_info_level > DINFO_LEVEL_TERSE)
7265         {
7266           register tree type = TREE_TYPE (decl);
7267
7268           add_prototyped_attribute (subr_die, type);
7269           add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
7270         }
7271
7272       add_pure_or_virtual_attribute (subr_die, decl);
7273       if (DECL_ARTIFICIAL (decl))
7274         add_AT_flag (subr_die, DW_AT_artificial, 1);
7275       if (TREE_PROTECTED (decl))
7276         add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
7277       else if (TREE_PRIVATE (decl))
7278         add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
7279     }
7280
7281   if (declaration)
7282     {
7283       add_AT_flag (subr_die, DW_AT_declaration, 1);
7284
7285       /* The first time we see a member function, it is in the context of
7286          the class to which it belongs.  We make sure of this by emitting
7287          the class first.  The next time is the definition, which is
7288          handled above.  The two may come from the same source text.  */
7289       if (decl_class_context (decl))
7290         equate_decl_number_to_die (decl, subr_die);
7291     }
7292   else if (DECL_ABSTRACT (decl))
7293     {
7294       if (DECL_DEFER_OUTPUT (decl))
7295         {
7296           if (DECL_INLINE (decl))
7297             add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
7298           else
7299             add_AT_unsigned (subr_die, DW_AT_inline,
7300                              DW_INL_declared_not_inlined);
7301         }
7302       else if (DECL_INLINE (decl))
7303         add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
7304       else if (declaration)
7305         /* Block extern declaration in an inline function.  */
7306         add_AT_flag (subr_die, DW_AT_declaration, 1);
7307       else
7308         abort ();
7309
7310       equate_decl_number_to_die (decl, subr_die);
7311     }
7312   else if (!DECL_EXTERNAL (decl))
7313     {
7314       if (origin == NULL_TREE)
7315         equate_decl_number_to_die (decl, subr_die);
7316
7317       ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
7318                                    current_funcdef_number);
7319       add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
7320       ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
7321                                    current_funcdef_number);
7322       add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
7323
7324       add_pubname (decl, subr_die);
7325       add_arange (decl, subr_die);
7326
7327 #ifdef MIPS_DEBUGGING_INFO
7328       /* Add a reference to the FDE for this routine.  */
7329       add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
7330 #endif
7331
7332       /* Define the "frame base" location for this routine.  We use the
7333          frame pointer or stack pointer registers, since the RTL for local
7334          variables is relative to one of them.  */
7335       fp_reg
7336         = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
7337       add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
7338
7339       if (current_function_needs_context)
7340         add_AT_loc (subr_die, DW_AT_static_link,
7341                     loc_descriptor (lookup_static_chain (decl)));
7342     }
7343
7344   /* Now output descriptions of the arguments for this function. This gets
7345      (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list 
7346      for a FUNCTION_DECL doesn't indicate cases where there was a trailing
7347      `...' at the end of the formal parameter list.  In order to find out if
7348      there was a trailing ellipsis or not, we must instead look at the type
7349      associated with the FUNCTION_DECL.  This will be a node of type
7350      FUNCTION_TYPE. If the chain of type nodes hanging off of this
7351      FUNCTION_TYPE node ends with a void_type_node then there should *not* be 
7352      an ellipsis at the end.  */
7353   push_decl_scope (decl);
7354
7355   /* In the case where we are describing a mere function declaration, all we
7356      need to do here (and all we *can* do here) is to describe the *types* of 
7357      its formal parameters.  */
7358   if (debug_info_level <= DINFO_LEVEL_TERSE)
7359     ;
7360   else if (declaration)
7361     gen_formal_types_die (TREE_TYPE (decl), subr_die);
7362   else
7363     {
7364       /* Generate DIEs to represent all known formal parameters */
7365       register tree arg_decls = DECL_ARGUMENTS (decl);
7366       register tree parm;
7367
7368       /* When generating DIEs, generate the unspecified_parameters DIE
7369          instead if we come across the arg "__builtin_va_alist" */
7370       for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
7371         if (TREE_CODE (parm) == PARM_DECL)
7372           {
7373             if (DECL_NAME (parm) &&
7374                 !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
7375                          "__builtin_va_alist"))
7376               gen_unspecified_parameters_die (parm, subr_die);
7377             else
7378               gen_decl_die (parm, subr_die);
7379           }
7380
7381       /* Decide whether we need a unspecified_parameters DIE at the end.
7382          There are 2 more cases to do this for: 1) the ansi ... declaration - 
7383          this is detectable when the end of the arg list is not a
7384          void_type_node 2) an unprototyped function declaration (not a
7385          definition).  This just means that we have no info about the
7386          parameters at all.  */
7387       fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
7388       if (fn_arg_types != NULL)
7389         {
7390           /* this is the prototyped case, check for ...  */
7391           if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
7392             gen_unspecified_parameters_die (decl, subr_die);
7393         }
7394       else if (DECL_INITIAL (decl) == NULL_TREE)
7395         gen_unspecified_parameters_die (decl, subr_die);
7396     }
7397
7398   /* Output Dwarf info for all of the stuff within the body of the function
7399      (if it has one - it may be just a declaration).  */
7400   outer_scope = DECL_INITIAL (decl);
7401
7402   /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
7403      node created to represent a function. This outermost BLOCK actually
7404      represents the outermost binding contour for the function, i.e. the
7405      contour in which the function's formal parameters and labels get
7406      declared. Curiously, it appears that the front end doesn't actually
7407      put the PARM_DECL nodes for the current function onto the BLOCK_VARS
7408      list for this outer scope.  (They are strung off of the DECL_ARGUMENTS
7409      list for the function instead.) The BLOCK_VARS list for the
7410      `outer_scope' does provide us with a list of the LABEL_DECL nodes for
7411      the function however, and we output DWARF info for those in
7412      decls_for_scope.  Just within the `outer_scope' there will be a BLOCK
7413      node representing the function's outermost pair of curly braces, and
7414      any blocks used for the base and member initializers of a C++
7415      constructor function.  */
7416   if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
7417     {
7418       current_function_has_inlines = 0;
7419       decls_for_scope (outer_scope, subr_die, 0);
7420
7421 #if 0 && defined (MIPS_DEBUGGING_INFO)
7422       if (current_function_has_inlines)
7423         {
7424           add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
7425           if (! comp_unit_has_inlines)
7426             {
7427               add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
7428               comp_unit_has_inlines = 1;
7429             }
7430         }
7431 #endif
7432     }
7433
7434   pop_decl_scope ();
7435 }
7436
7437 /* Generate a DIE to represent a declared data object.  */
7438
7439 static void
7440 gen_variable_die (decl, context_die)
7441      register tree decl;
7442      register dw_die_ref context_die;
7443 {
7444   register tree origin = decl_ultimate_origin (decl);
7445   register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
7446
7447   dw_die_ref old_die = lookup_decl_die (decl);
7448   int declaration
7449     = (DECL_EXTERNAL (decl)
7450        || current_function_decl != decl_function_context (decl)
7451        || context_die->die_tag == DW_TAG_structure_type
7452        || context_die->die_tag == DW_TAG_union_type);
7453
7454   if (origin != NULL)
7455     add_abstract_origin_attribute (var_die, origin);
7456   else if (old_die && TREE_STATIC (decl))
7457     {
7458       assert (get_AT_flag (old_die, DW_AT_declaration) == 1);
7459       add_AT_die_ref (var_die, DW_AT_specification, old_die);
7460       if (DECL_NAME (decl))
7461         {
7462           register unsigned file_index
7463             = lookup_filename (DECL_SOURCE_FILE (decl));
7464
7465           if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
7466             add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
7467
7468           if (get_AT_unsigned (old_die, DW_AT_decl_line)
7469               != DECL_SOURCE_LINE (decl))
7470
7471             add_AT_unsigned (var_die, DW_AT_decl_line,
7472                              DECL_SOURCE_LINE (decl));
7473         }
7474     }
7475   else
7476     {
7477       add_name_and_src_coords_attributes (var_die, decl);
7478       add_type_attribute (var_die, TREE_TYPE (decl),
7479                           TREE_READONLY (decl),
7480                           TREE_THIS_VOLATILE (decl), context_die);
7481
7482       if (TREE_PUBLIC (decl))
7483         add_AT_flag (var_die, DW_AT_external, 1);
7484
7485       if (DECL_ARTIFICIAL (decl))
7486         add_AT_flag (var_die, DW_AT_artificial, 1);
7487
7488       if (TREE_PROTECTED (decl))
7489         add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
7490
7491       else if (TREE_PRIVATE (decl))
7492         add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
7493     }
7494
7495   if (declaration)
7496     add_AT_flag (var_die, DW_AT_declaration, 1);
7497   
7498   if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
7499     equate_decl_number_to_die (decl, var_die);
7500
7501   if (! declaration && ! DECL_ABSTRACT (decl))
7502     {
7503       equate_decl_number_to_die (decl, var_die);
7504       add_location_or_const_value_attribute (var_die, decl);
7505       add_pubname (decl, var_die);
7506     }
7507 }
7508
7509 /* Generate a DIE to represent a label identifier.  */
7510
7511 static void
7512 gen_label_die (decl, context_die)
7513      register tree decl;
7514      register dw_die_ref context_die;
7515 {
7516   register tree origin = decl_ultimate_origin (decl);
7517   register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
7518   register rtx insn;
7519   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7520   char label2[MAX_ARTIFICIAL_LABEL_BYTES];
7521
7522   if (origin != NULL)
7523     add_abstract_origin_attribute (lbl_die, origin);
7524   else
7525     add_name_and_src_coords_attributes (lbl_die, decl);
7526
7527   if (DECL_ABSTRACT (decl))
7528     equate_decl_number_to_die (decl, lbl_die);
7529   else
7530     {
7531       insn = DECL_RTL (decl);
7532       if (GET_CODE (insn) == CODE_LABEL)
7533         {
7534           /* When optimization is enabled (via -O) some parts of the compiler 
7535              (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which 
7536              represent source-level labels which were explicitly declared by
7537              the user.  This really shouldn't be happening though, so catch
7538              it if it ever does happen.  */
7539           if (INSN_DELETED_P (insn))
7540             abort ();
7541
7542           sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
7543           ASM_GENERATE_INTERNAL_LABEL (label, label2,
7544                                        (unsigned) INSN_UID (insn));
7545           add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
7546         }
7547     }
7548 }
7549
7550 /* Generate a DIE for a lexical block.  */
7551
7552 static void
7553 gen_lexical_block_die (stmt, context_die, depth)
7554      register tree stmt;
7555      register dw_die_ref context_die;
7556      int depth;
7557 {
7558   register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
7559   char label[MAX_ARTIFICIAL_LABEL_BYTES];
7560
7561   if (! BLOCK_ABSTRACT (stmt))
7562     {
7563       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7564                                    next_block_number);
7565       add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
7566       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7567       add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
7568     }
7569
7570   push_decl_scope (stmt);
7571   decls_for_scope (stmt, stmt_die, depth);
7572   pop_decl_scope ();
7573 }
7574
7575 /* Generate a DIE for an inlined subprogram.  */
7576
7577 static void
7578 gen_inlined_subroutine_die (stmt, context_die, depth)
7579      register tree stmt;
7580      register dw_die_ref context_die;
7581      int depth;
7582 {
7583   if (! BLOCK_ABSTRACT (stmt))
7584     {
7585       register dw_die_ref subr_die
7586         = new_die (DW_TAG_inlined_subroutine, context_die);
7587       register tree decl = block_ultimate_origin (stmt);
7588       char label[MAX_ARTIFICIAL_LABEL_BYTES];
7589
7590       add_abstract_origin_attribute (subr_die, decl);
7591       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
7592                                    next_block_number);
7593       add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
7594       ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
7595       add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
7596       push_decl_scope (decl);
7597       decls_for_scope (stmt, subr_die, depth);
7598       pop_decl_scope ();
7599       current_function_has_inlines = 1;
7600     }
7601 }
7602
7603 /* Generate a DIE for a field in a record, or structure.  */
7604
7605 static void
7606 gen_field_die (decl, context_die)
7607      register tree decl;
7608      register dw_die_ref context_die;
7609 {
7610   register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
7611
7612   add_name_and_src_coords_attributes (decl_die, decl);
7613   add_type_attribute (decl_die, member_declared_type (decl),
7614                       TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
7615                       context_die);
7616
7617   /* If this is a bit field...  */
7618   if (DECL_BIT_FIELD_TYPE (decl))
7619     {
7620       add_byte_size_attribute (decl_die, decl);
7621       add_bit_size_attribute (decl_die, decl);
7622       add_bit_offset_attribute (decl_die, decl);
7623     }
7624
7625   if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
7626     add_data_member_location_attribute (decl_die, decl);
7627
7628   if (DECL_ARTIFICIAL (decl))
7629     add_AT_flag (decl_die, DW_AT_artificial, 1);
7630
7631   if (TREE_PROTECTED (decl))
7632     add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
7633
7634   else if (TREE_PRIVATE (decl))
7635     add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
7636 }
7637
7638 #if 0
7639 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7640    Use modified_type_die instead.
7641    We keep this code here just in case these types of DIEs may be needed to
7642    represent certain things in other languages (e.g. Pascal) someday.  */
7643 static void
7644 gen_pointer_type_die (type, context_die)
7645      register tree type;
7646      register dw_die_ref context_die;
7647 {
7648   register dw_die_ref ptr_die
7649     = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
7650
7651   equate_type_number_to_die (type, ptr_die);
7652   add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7653   add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7654 }
7655
7656 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
7657    Use modified_type_die instead.
7658    We keep this code here just in case these types of DIEs may be needed to
7659    represent certain things in other languages (e.g. Pascal) someday.  */
7660 static void
7661 gen_reference_type_die (type, context_die)
7662      register tree type;
7663      register dw_die_ref context_die;
7664 {
7665   register dw_die_ref ref_die
7666     = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
7667
7668   equate_type_number_to_die (type, ref_die);
7669   add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
7670   add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7671 }
7672 #endif
7673
7674 /* Generate a DIE for a pointer to a member type.  */
7675 static void
7676 gen_ptr_to_mbr_type_die (type, context_die)
7677      register tree type;
7678      register dw_die_ref context_die;
7679 {
7680   register dw_die_ref ptr_die
7681     = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
7682
7683   equate_type_number_to_die (type, ptr_die);
7684   add_AT_die_ref (ptr_die, DW_AT_containing_type,
7685                   lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
7686   add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
7687 }
7688
7689 /* Generate the DIE for the compilation unit.  */
7690
7691 static void
7692 gen_compile_unit_die (main_input_filename)
7693      register char *main_input_filename;
7694 {
7695   char producer[250];
7696   char *wd = getpwd ();
7697
7698   comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
7699   add_name_attribute (comp_unit_die, main_input_filename);
7700
7701   if (wd != NULL)
7702     add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
7703
7704   sprintf (producer, "%s %s", language_string, version_string);
7705
7706 #ifdef MIPS_DEBUGGING_INFO
7707   /* The MIPS/SGI compilers place the 'cc' command line options in the producer
7708      string.  The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
7709      not appear in the producer string, the debugger reaches the conclusion
7710      that the object file is stripped and has no debugging information.
7711      To get the MIPS/SGI debugger to believe that there is debugging
7712      information in the object file, we add a -g to the producer string.  */
7713   if (debug_info_level > DINFO_LEVEL_TERSE)
7714     strcat (producer, " -g");
7715 #endif
7716
7717   add_AT_string (comp_unit_die, DW_AT_producer, producer);
7718
7719   if (strcmp (language_string, "GNU C++") == 0)
7720     add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
7721
7722   else if (strcmp (language_string, "GNU Ada") == 0)
7723     add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
7724
7725   else if (strcmp (language_string, "GNU F77") == 0)
7726     add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
7727
7728   else if (flag_traditional)
7729     add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
7730
7731   else
7732     add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
7733
7734 #if 0 /* unimplemented */
7735   if (debug_info_level >= DINFO_LEVEL_VERBOSE)
7736     add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
7737 #endif
7738 }
7739
7740 /* Generate a DIE for a string type.  */
7741
7742 static void
7743 gen_string_type_die (type, context_die)
7744      register tree type;
7745      register dw_die_ref context_die;
7746 {
7747   register dw_die_ref type_die
7748     = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
7749
7750   equate_type_number_to_die (type, type_die);
7751
7752   /* Fudge the string length attribute for now.  */
7753   
7754   /* TODO: add string length info.
7755    string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
7756                               bound_representation (upper_bound, 0, 'u'); */
7757 }
7758
7759 /* Generate the DIE for a base class.  */
7760
7761 static void
7762 gen_inheritance_die (binfo, context_die)
7763      register tree binfo;
7764      register dw_die_ref context_die;
7765 {
7766   dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
7767
7768   add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
7769   add_data_member_location_attribute (die, binfo);
7770
7771   if (TREE_VIA_VIRTUAL (binfo))
7772     add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7773   if (TREE_VIA_PUBLIC (binfo))
7774     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
7775   else if (TREE_VIA_PROTECTED (binfo))
7776     add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
7777 }
7778
7779 /* Genearate a DIE for a class member.  */
7780
7781 static void
7782 gen_member_die (type, context_die)
7783      register tree type;
7784      register dw_die_ref context_die;
7785 {
7786   register tree member;
7787
7788   /* If this is not an incomplete type, output descriptions of each of its
7789      members. Note that as we output the DIEs necessary to represent the
7790      members of this record or union type, we will also be trying to output
7791      DIEs to represent the *types* of those members. However the `type'
7792      function (above) will specifically avoid generating type DIEs for member 
7793      types *within* the list of member DIEs for this (containing) type execpt 
7794      for those types (of members) which are explicitly marked as also being
7795      members of this (containing) type themselves.  The g++ front- end can
7796      force any given type to be treated as a member of some other
7797      (containing) type by setting the TYPE_CONTEXT of the given (member) type 
7798      to point to the TREE node representing the appropriate (containing)
7799      type.  */
7800
7801   /* First output info about the base classes.  */
7802   if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
7803     {
7804       register tree bases = TYPE_BINFO_BASETYPES (type);
7805       register int n_bases = TREE_VEC_LENGTH (bases);
7806       register int i;
7807
7808       for (i = 0; i < n_bases; i++)
7809         gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
7810     }
7811
7812   /* Now output info about the data members and type members.  */
7813   for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
7814     gen_decl_die (member, context_die);
7815
7816   /* Now output info about the function members (if any).  */
7817   for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
7818     gen_decl_die (member, context_die);
7819 }
7820
7821 /* Generate a DIE for a structure or union type.  */
7822
7823 static void
7824 gen_struct_or_union_type_die (type, context_die)
7825      register tree type;
7826      register dw_die_ref context_die;
7827 {
7828   register dw_die_ref type_die = lookup_type_die (type);
7829   register dw_die_ref scope_die = 0;
7830   register int nested = 0;
7831
7832   if (type_die && ! TYPE_SIZE (type))
7833     return;
7834
7835   if (TYPE_CONTEXT (type) != NULL_TREE
7836       && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't')
7837     nested = 1;
7838
7839   scope_die = scope_die_for (type, context_die);
7840
7841   if (! type_die || (nested && scope_die == comp_unit_die))
7842     /* First occurrence of type or toplevel definition of nested class.  */
7843     {
7844       register dw_die_ref old_die = type_die;
7845
7846       type_die = new_die (TREE_CODE (type) == RECORD_TYPE
7847                           ? DW_TAG_structure_type : DW_TAG_union_type,
7848                           scope_die);
7849       equate_type_number_to_die (type, type_die);
7850       add_name_attribute (type_die, type_tag (type));
7851       if (old_die)
7852         add_AT_die_ref (type_die, DW_AT_specification, old_die);
7853     }
7854   else
7855     remove_AT (type_die, DW_AT_declaration);
7856
7857   /* If we're not in the right context to be defining this type, defer to
7858      avoid tricky recursion.  */
7859   if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
7860     {
7861       add_AT_flag (type_die, DW_AT_declaration, 1);
7862       pend_type (type);
7863     }
7864   /* If this type has been completed, then give it a byte_size attribute and
7865      then give a list of members.  */
7866   else if (TYPE_SIZE (type))
7867     {
7868       /* Prevent infinite recursion in cases where the type of some member of 
7869          this type is expressed in terms of this type itself.  */
7870       TREE_ASM_WRITTEN (type) = 1;
7871       add_byte_size_attribute (type_die, type);
7872       if (type_tag (type))
7873         add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7874
7875       push_decl_scope (type);
7876       gen_member_die (type, type_die);
7877       pop_decl_scope ();
7878
7879       /* GNU extension: Record what type our vtable lives in.  */
7880       if (TYPE_VFIELD (type))
7881         {
7882           tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
7883
7884           gen_type_die (vtype, context_die);
7885           add_AT_die_ref (type_die, DW_AT_containing_type,
7886                           lookup_type_die (vtype));
7887         }
7888     }
7889   else
7890     add_AT_flag (type_die, DW_AT_declaration, 1);
7891 }
7892
7893 /* Generate a DIE for a subroutine _type_.  */
7894
7895 static void
7896 gen_subroutine_type_die (type, context_die)
7897      register tree type;
7898      register dw_die_ref context_die;
7899 {
7900   register tree return_type = TREE_TYPE (type);
7901   register dw_die_ref subr_die
7902     = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
7903
7904   equate_type_number_to_die (type, subr_die);
7905   add_prototyped_attribute (subr_die, type);
7906   add_type_attribute (subr_die, return_type, 0, 0, context_die);
7907   gen_formal_types_die (type, subr_die);
7908 }
7909
7910 /* Generate a DIE for a type definition */
7911
7912 static void
7913 gen_typedef_die (decl, context_die)
7914      register tree decl;
7915      register dw_die_ref context_die;
7916 {
7917   register dw_die_ref type_die;
7918   register tree origin;
7919
7920   if (TREE_ASM_WRITTEN (decl))
7921     return;
7922   TREE_ASM_WRITTEN (decl) = 1;
7923
7924   type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
7925   origin = decl_ultimate_origin (decl);
7926   if (origin != NULL)
7927     add_abstract_origin_attribute (type_die, origin);
7928   else
7929     {
7930       register tree type;
7931       add_name_and_src_coords_attributes (type_die, decl);
7932       if (DECL_ORIGINAL_TYPE (decl))
7933         {
7934           type = DECL_ORIGINAL_TYPE (decl);
7935           equate_type_number_to_die (TREE_TYPE (decl), type_die);
7936         }
7937       else
7938         type = TREE_TYPE (decl);
7939       add_type_attribute (type_die, type, TREE_READONLY (decl),
7940                           TREE_THIS_VOLATILE (decl), context_die);
7941     }
7942
7943   if (DECL_ABSTRACT (decl))
7944     equate_decl_number_to_die (decl, type_die);
7945 }
7946
7947 /* Generate a type description DIE.  */
7948
7949 static void
7950 gen_type_die (type, context_die)
7951      register tree type;
7952      register dw_die_ref context_die;
7953 {
7954   if (type == NULL_TREE || type == error_mark_node)
7955     return;
7956
7957   /* We are going to output a DIE to represent the unqualified version of of
7958      this type (i.e. without any const or volatile qualifiers) so get the
7959      main variant (i.e. the unqualified version) of this type now.  */
7960   type = type_main_variant (type);
7961
7962   if (TREE_ASM_WRITTEN (type))
7963     return;
7964
7965   if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7966       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7967     { 
7968       TREE_ASM_WRITTEN (type) = 1;
7969       gen_decl_die (TYPE_NAME (type), context_die);
7970       return;
7971     }
7972
7973   switch (TREE_CODE (type))
7974     {
7975     case ERROR_MARK:
7976       break;
7977
7978     case POINTER_TYPE:
7979     case REFERENCE_TYPE:
7980       /* For these types, all that is required is that we output a DIE (or a
7981          set of DIEs) to represent the "basis" type.  */
7982       gen_type_die (TREE_TYPE (type), context_die);
7983       break;
7984
7985     case OFFSET_TYPE:
7986       /* This code is used for C++ pointer-to-data-member types. 
7987          Output a description of the relevant class type.  */
7988       gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
7989
7990       /* Output a description of the type of the object pointed to.  */
7991       gen_type_die (TREE_TYPE (type), context_die);
7992
7993       /* Now output a DIE to represent this pointer-to-data-member type
7994          itself.  */
7995       gen_ptr_to_mbr_type_die (type, context_die);
7996       break;
7997
7998     case SET_TYPE:
7999       gen_type_die (TYPE_DOMAIN (type), context_die);
8000       gen_set_type_die (type, context_die);
8001       break;
8002
8003     case FILE_TYPE:
8004       gen_type_die (TREE_TYPE (type), context_die);
8005       abort ();                 /* No way to represent these in Dwarf yet!  */
8006       break;
8007
8008     case FUNCTION_TYPE:
8009       /* Force out return type (in case it wasn't forced out already).  */
8010       gen_type_die (TREE_TYPE (type), context_die);
8011       gen_subroutine_type_die (type, context_die);
8012       break;
8013
8014     case METHOD_TYPE:
8015       /* Force out return type (in case it wasn't forced out already).  */
8016       gen_type_die (TREE_TYPE (type), context_die);
8017       gen_subroutine_type_die (type, context_die);
8018       break;
8019
8020     case ARRAY_TYPE:
8021       if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8022         {
8023           gen_type_die (TREE_TYPE (type), context_die);
8024           gen_string_type_die (type, context_die);
8025         }
8026       else
8027         gen_array_type_die (type, context_die);
8028       break;
8029
8030     case ENUMERAL_TYPE:
8031     case RECORD_TYPE:
8032     case UNION_TYPE:
8033     case QUAL_UNION_TYPE:
8034       /* If this is a nested type whose containing class hasn't been
8035          written out yet, writing it out will cover this one, too.  */
8036       if (TYPE_CONTEXT (type)
8037           && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8038           && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8039         {
8040           gen_type_die (TYPE_CONTEXT (type), context_die);
8041
8042           if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8043             return;
8044
8045           /* If that failed, attach ourselves to the stub.  */
8046           push_decl_scope (TYPE_CONTEXT (type));
8047           context_die = lookup_type_die (TYPE_CONTEXT (type));
8048         }
8049
8050       if (TREE_CODE (type) == ENUMERAL_TYPE)
8051         gen_enumeration_type_die (type, context_die);
8052       else
8053         gen_struct_or_union_type_die (type, context_die);
8054
8055       if (TYPE_CONTEXT (type)
8056           && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't'
8057           && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
8058         pop_decl_scope ();
8059
8060       /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
8061          it up if it is ever completed.  gen_*_type_die will set it for us
8062          when appropriate.  */
8063       return;
8064
8065     case VOID_TYPE:
8066     case INTEGER_TYPE:
8067     case REAL_TYPE:
8068     case COMPLEX_TYPE:
8069     case BOOLEAN_TYPE:
8070     case CHAR_TYPE:
8071       /* No DIEs needed for fundamental types.  */
8072       break;
8073
8074     case LANG_TYPE:
8075       /* No Dwarf representation currently defined.  */
8076       break;
8077
8078     default:
8079       abort ();
8080     }
8081
8082   TREE_ASM_WRITTEN (type) = 1;
8083 }
8084
8085 /* Generate a DIE for a tagged type instantiation.  */
8086
8087 static void
8088 gen_tagged_type_instantiation_die (type, context_die)
8089      register tree type;
8090      register dw_die_ref context_die;
8091 {
8092   if (type == NULL_TREE || type == error_mark_node)
8093     return;
8094
8095   /* We are going to output a DIE to represent the unqualified version of of
8096      this type (i.e. without any const or volatile qualifiers) so make sure
8097      that we have the main variant (i.e. the unqualified version) of this
8098      type now.  */
8099   assert (type == type_main_variant (type));
8100   assert (TREE_ASM_WRITTEN (type));
8101
8102   switch (TREE_CODE (type))
8103     {
8104     case ERROR_MARK:
8105       break;
8106
8107     case ENUMERAL_TYPE:
8108       gen_inlined_enumeration_type_die (type, context_die);
8109       break;
8110
8111     case RECORD_TYPE:
8112       gen_inlined_structure_type_die (type, context_die);
8113       break;
8114
8115     case UNION_TYPE:
8116     case QUAL_UNION_TYPE:
8117       gen_inlined_union_type_die (type, context_die);
8118       break;
8119
8120     default:
8121       abort ();
8122     }
8123 }
8124
8125 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
8126    things which are local to the given block.  */
8127
8128 static void
8129 gen_block_die (stmt, context_die, depth)
8130      register tree stmt;
8131      register dw_die_ref context_die;
8132      int depth;
8133 {
8134   register int must_output_die = 0;
8135   register tree origin;
8136   register tree decl;
8137   register enum tree_code origin_code;
8138
8139   /* Ignore blocks never really used to make RTL.  */
8140
8141   if (stmt == NULL_TREE || !TREE_USED (stmt))
8142     return;
8143
8144   /* Determine the "ultimate origin" of this block.  This block may be an
8145      inlined instance of an inlined instance of inline function, so we have
8146      to trace all of the way back through the origin chain to find out what
8147      sort of node actually served as the original seed for the creation of
8148      the current block.  */
8149   origin = block_ultimate_origin (stmt);
8150   origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
8151
8152   /* Determine if we need to output any Dwarf DIEs at all to represent this
8153      block.  */
8154   if (origin_code == FUNCTION_DECL)
8155     /* The outer scopes for inlinings *must* always be represented.  We
8156        generate DW_TAG_inlined_subroutine DIEs for them.  (See below.) */
8157     must_output_die = 1;
8158   else
8159     {
8160       /* In the case where the current block represents an inlining of the
8161          "body block" of an inline function, we must *NOT* output any DIE for 
8162          this block because we have already output a DIE to represent the
8163          whole inlined function scope and the "body block" of any function
8164          doesn't really represent a different scope according to ANSI C
8165          rules.  So we check here to make sure that this block does not
8166          represent a "body block inlining" before trying to set the
8167          `must_output_die' flag.  */
8168       if (! is_body_block (origin ? origin : stmt))
8169         {
8170           /* Determine if this block directly contains any "significant"
8171              local declarations which we will need to output DIEs for.  */
8172           if (debug_info_level > DINFO_LEVEL_TERSE)
8173             /* We are not in terse mode so *any* local declaration counts
8174                as being a "significant" one.  */
8175             must_output_die = (BLOCK_VARS (stmt) != NULL);
8176           else
8177             /* We are in terse mode, so only local (nested) function
8178                definitions count as "significant" local declarations.  */
8179             for (decl = BLOCK_VARS (stmt);
8180                  decl != NULL; decl = TREE_CHAIN (decl))
8181               if (TREE_CODE (decl) == FUNCTION_DECL
8182                   && DECL_INITIAL (decl))
8183                 {
8184                   must_output_die = 1;
8185                   break;
8186                 }
8187         }
8188     }
8189
8190   /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
8191      DIE for any block which contains no significant local declarations at
8192      all.  Rather, in such cases we just call `decls_for_scope' so that any
8193      needed Dwarf info for any sub-blocks will get properly generated. Note
8194      that in terse mode, our definition of what constitutes a "significant"
8195      local declaration gets restricted to include only inlined function
8196      instances and local (nested) function definitions.  */
8197   if (must_output_die)
8198     {
8199       if (origin_code == FUNCTION_DECL)
8200         gen_inlined_subroutine_die (stmt, context_die, depth);
8201       else
8202         gen_lexical_block_die (stmt, context_die, depth);
8203     }
8204   else
8205     decls_for_scope (stmt, context_die, depth);
8206 }
8207
8208 /* Generate all of the decls declared within a given scope and (recursively)
8209    all of it's sub-blocks.  */
8210
8211 static void
8212 decls_for_scope (stmt, context_die, depth)
8213      register tree stmt;
8214      register dw_die_ref context_die;
8215      int depth;
8216 {
8217   register tree decl;
8218   register tree subblocks;
8219
8220   /* Ignore blocks never really used to make RTL.  */
8221   if (stmt == NULL_TREE || ! TREE_USED (stmt))
8222     return;
8223
8224   if (!BLOCK_ABSTRACT (stmt) && depth > 0)
8225     next_block_number++;
8226
8227   /* Output the DIEs to represent all of the data objects and typedefs
8228      declared directly within this block but not within any nested
8229      sub-blocks.  Also, nested function and tag DIEs have been
8230      generated with a parent of NULL; fix that up now.  */
8231   for (decl = BLOCK_VARS (stmt);
8232        decl != NULL; decl = TREE_CHAIN (decl))
8233     {
8234       register dw_die_ref die;
8235
8236       if (TREE_CODE (decl) == FUNCTION_DECL)
8237         die = lookup_decl_die (decl);
8238       else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
8239         die = lookup_type_die (TREE_TYPE (decl));
8240       else
8241         die = NULL;
8242
8243       if (die != NULL && die->die_parent == NULL)
8244         {
8245           add_child_die (context_die, die);
8246           --limbo_die_count;
8247         }
8248       else
8249         gen_decl_die (decl, context_die);
8250     }
8251
8252   /* Output the DIEs to represent all sub-blocks (and the items declared
8253      therein) of this block.  */
8254   for (subblocks = BLOCK_SUBBLOCKS (stmt);
8255        subblocks != NULL;
8256        subblocks = BLOCK_CHAIN (subblocks))
8257     gen_block_die (subblocks, context_die, depth + 1);
8258 }
8259
8260 /* Is this a typedef we can avoid emitting?  */
8261
8262 static inline int
8263 is_redundant_typedef (decl)
8264      register tree decl;
8265 {
8266   if (TYPE_DECL_IS_STUB (decl))
8267     return 1;
8268
8269   if (DECL_ARTIFICIAL (decl)
8270       && DECL_CONTEXT (decl)
8271       && is_tagged_type (DECL_CONTEXT (decl))
8272       && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
8273       && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
8274     /* Also ignore the artificial member typedef for the class name.  */
8275     return 1;
8276
8277   return 0;
8278 }
8279
8280 /* Generate Dwarf debug information for a decl described by DECL.  */
8281
8282 static void
8283 gen_decl_die (decl, context_die)
8284      register tree decl;
8285      register dw_die_ref context_die;
8286 {
8287   register tree origin;
8288
8289   /* Make a note of the decl node we are going to be working on.  We may need 
8290      to give the user the source coordinates of where it appeared in case we
8291      notice (later on) that something about it looks screwy.  */
8292   dwarf_last_decl = decl;
8293
8294   if (TREE_CODE (decl) == ERROR_MARK)
8295     return;
8296
8297   /* If this ..._DECL node is marked to be ignored, then ignore it. But don't 
8298      ignore a function definition, since that would screw up our count of
8299      blocks, and that it turn will completely screw up the the labels we will 
8300      reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8301      subsequent blocks).  */
8302   if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
8303     return;
8304
8305   switch (TREE_CODE (decl))
8306     {
8307     case CONST_DECL:
8308       /* The individual enumerators of an enum type get output when we output 
8309          the Dwarf representation of the relevant enum type itself.  */
8310       break;
8311
8312     case FUNCTION_DECL:
8313       /* Don't output any DIEs to represent mere function declarations,
8314          unless they are class members or explicit block externs.  */
8315       if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
8316           && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
8317         break;
8318
8319       if (debug_info_level > DINFO_LEVEL_TERSE)
8320         {
8321           /* Before we describe the FUNCTION_DECL itself, make sure that we
8322              have described its return type.  */
8323           gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
8324
8325           /* And its containing type.  */
8326           origin = decl_class_context (decl);
8327           if (origin != NULL_TREE)
8328             gen_type_die (origin, context_die);
8329
8330           /* And its virtual context.  */
8331           if (DECL_VINDEX (decl) != NULL_TREE)
8332             gen_type_die (DECL_CONTEXT (decl), context_die);
8333         }
8334
8335       /* Now output a DIE to represent the function itself.  */
8336       gen_subprogram_die (decl, context_die);
8337       break;
8338
8339     case TYPE_DECL:
8340       /* If we are in terse mode, don't generate any DIEs to represent any
8341          actual typedefs.  */
8342       if (debug_info_level <= DINFO_LEVEL_TERSE)
8343         break;
8344
8345       /* In the special case of a TYPE_DECL node representing the 
8346          declaration of some type tag, if the given TYPE_DECL is marked as
8347          having been instantiated from some other (original) TYPE_DECL node
8348          (e.g. one which was generated within the original definition of an
8349          inline function) we have to generate a special (abbreviated)
8350          DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration-type 
8351          DIE here.  */
8352       if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
8353         {
8354           gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
8355           break;
8356         }
8357
8358       if (is_redundant_typedef (decl))
8359         gen_type_die (TREE_TYPE (decl), context_die);
8360       else
8361         /* Output a DIE to represent the typedef itself.  */
8362         gen_typedef_die (decl, context_die);
8363       break;
8364
8365     case LABEL_DECL:
8366       if (debug_info_level >= DINFO_LEVEL_NORMAL)
8367         gen_label_die (decl, context_die);
8368       break;
8369
8370     case VAR_DECL:
8371       /* If we are in terse mode, don't generate any DIEs to represent any
8372          variable declarations or definitions.  */
8373       if (debug_info_level <= DINFO_LEVEL_TERSE)
8374         break;
8375
8376       /* Output any DIEs that are needed to specify the type of this data
8377          object.  */
8378       gen_type_die (TREE_TYPE (decl), context_die);
8379
8380       /* And its containing type.  */
8381       origin = decl_class_context (decl);
8382       if (origin != NULL_TREE)
8383         gen_type_die (origin, context_die);
8384
8385       /* Now output the DIE to represent the data object itself.  This gets
8386          complicated because of the possibility that the VAR_DECL really
8387          represents an inlined instance of a formal parameter for an inline
8388          function.  */
8389       origin = decl_ultimate_origin (decl);
8390       if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
8391         gen_formal_parameter_die (decl, context_die);
8392       else
8393         gen_variable_die (decl, context_die);
8394       break;
8395
8396     case FIELD_DECL:
8397       /* Ignore the nameless fields that are used to skip bits, but
8398          handle C++ anonymous unions.  */
8399       if (DECL_NAME (decl) != NULL_TREE
8400           || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
8401         {
8402           gen_type_die (member_declared_type (decl), context_die);
8403           gen_field_die (decl, context_die);
8404         }
8405       break;
8406
8407     case PARM_DECL:
8408       gen_type_die (TREE_TYPE (decl), context_die);
8409       gen_formal_parameter_die (decl, context_die);
8410       break;
8411
8412     default:
8413       abort ();
8414     }
8415 }
8416 \f
8417 /* Write the debugging output for DECL.  */
8418
8419 void
8420 dwarf2out_decl (decl)
8421      register tree decl;
8422 {
8423   register dw_die_ref context_die = comp_unit_die;
8424
8425   if (TREE_CODE (decl) == ERROR_MARK)
8426     return;
8427
8428   /* If this ..._DECL node is marked to be ignored, then ignore it.  We gotta 
8429      hope that the node in question doesn't represent a function definition.
8430      If it does, then totally ignoring it is bound to screw up our count of
8431      blocks, and that it turn will completely screw up the the labels we will 
8432      reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
8433      subsequent blocks).  (It's too bad that BLOCK nodes don't carry their
8434      own sequence numbers with them!) */
8435   if (DECL_IGNORED_P (decl))
8436     {
8437       if (TREE_CODE (decl) == FUNCTION_DECL
8438           && DECL_INITIAL (decl) != NULL)
8439         abort ();
8440
8441       return;
8442     }
8443
8444   switch (TREE_CODE (decl))
8445     {
8446     case FUNCTION_DECL:
8447       /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a 
8448          builtin function.  Explicit programmer-supplied declarations of
8449          these same functions should NOT be ignored however.  */
8450       if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
8451         return;
8452
8453       /* What we would really like to do here is to filter out all mere
8454          file-scope declarations of file-scope functions which are never
8455          referenced later within this translation unit (and keep all of ones
8456          that *are* referenced later on) but we aren't clarvoiant, so we have 
8457          no idea which functions will be referenced in the future (i.e. later 
8458          on within the current translation unit). So here we just ignore all
8459          file-scope function declarations which are not also definitions.  If 
8460          and when the debugger needs to know something about these funcstion, 
8461          it wil have to hunt around and find the DWARF information associated 
8462          with the definition of the function. Note that we can't just check
8463          `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
8464          definitions and which ones represent mere declarations.  We have to
8465          check `DECL_INITIAL' instead. That's because the C front-end
8466          supports some weird semantics for "extern inline" function
8467          definitions.  These can get inlined within the current translation
8468          unit (an thus, we need to generate DWARF info for their abstract
8469          instances so that the DWARF info for the concrete inlined instances
8470          can have something to refer to) but the compiler never generates any 
8471          out-of-lines instances of such things (despite the fact that they
8472          *are* definitions).  The important point is that the C front-end
8473          marks these "extern inline" functions as DECL_EXTERNAL, but we need
8474          to generate DWARF for them anyway. Note that the C++ front-end also
8475          plays some similar games for inline function definitions appearing
8476          within include files which also contain 
8477          `#pragma interface' pragmas.  */
8478       if (DECL_INITIAL (decl) == NULL_TREE)
8479         return;
8480
8481       /* Ignore nested functions, since they will be written in decl_for_scope.
8482          ??? There was an old comment here about methods, which now need to
8483          be handled.  */
8484       if (decl_function_context (decl))
8485         return;
8486
8487       break;
8488
8489     case VAR_DECL:
8490       /* Ignore this VAR_DECL if it refers to a file-scope extern data object 
8491          declaration and if the declaration was never even referenced from
8492          within this entire compilation unit.  We suppress these DIEs in
8493          order to save space in the .debug section (by eliminating entries
8494          which are probably useless).  Note that we must not suppress
8495          block-local extern declarations (whether used or not) because that
8496          would screw-up the debugger's name lookup mechanism and cause it to
8497          miss things which really ought to be in scope at a given point.  */
8498       if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
8499         return;
8500
8501       /* If we are in terse mode, don't generate any DIEs to represent any
8502          variable declarations or definitions.  */
8503       if (debug_info_level <= DINFO_LEVEL_TERSE)
8504         return;
8505       break;
8506
8507     case TYPE_DECL:
8508       /* Don't bother trying to generate any DIEs to represent any of the
8509          normal built-in types for the language we are compiling.  */
8510       if (DECL_SOURCE_LINE (decl) == 0)
8511         {
8512           /* OK, we need to generate one for `bool' so GDB knows what type
8513              comparisons have.  */
8514           if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
8515                == DW_LANG_C_plus_plus)
8516               && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
8517             modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
8518
8519           return;
8520         }
8521
8522       /* If we are in terse mode, don't generate any DIEs for types.  */
8523       if (debug_info_level <= DINFO_LEVEL_TERSE)
8524         return;
8525
8526       /* If we're a function-scope tag, initially use a parent of NULL;
8527          this will be fixed up in decls_for_scope.  */
8528       if (decl_function_context (decl))
8529         return;
8530
8531       break;
8532
8533     default:
8534       return;
8535     }
8536
8537   gen_decl_die (decl, context_die);
8538   output_pending_types_for_scope (comp_unit_die);
8539
8540   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL_TREE)
8541     current_funcdef_number++;
8542 }
8543
8544 /* Output a marker (i.e. a label) for the beginning of the generated code for
8545    a lexical block.  */
8546
8547 void
8548 dwarf2out_begin_block (blocknum)
8549      register unsigned blocknum;
8550 {
8551   function_section (current_function_decl);
8552   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
8553 }
8554
8555 /* Output a marker (i.e. a label) for the end of the generated code for a
8556    lexical block.  */
8557
8558 void
8559 dwarf2out_end_block (blocknum)
8560      register unsigned blocknum;
8561 {
8562   function_section (current_function_decl);
8563   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
8564 }
8565
8566 /* Output a marker (i.e. a label) at a point in the assembly code which
8567    corresponds to a given source level label.  */
8568
8569 void
8570 dwarf2out_label (insn)
8571      register rtx insn;
8572 {
8573   char label[MAX_ARTIFICIAL_LABEL_BYTES];
8574
8575   if (debug_info_level >= DINFO_LEVEL_NORMAL)
8576     {
8577       function_section (current_function_decl);
8578       sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
8579       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
8580                                  (unsigned) INSN_UID (insn));
8581     }
8582 }
8583
8584 /* Output a marker (i.e. a label) for the beginning of a function, before
8585    the prologue.  */
8586
8587 void
8588 dwarf2out_begin_prologue ()
8589 {
8590   char label[MAX_ARTIFICIAL_LABEL_BYTES];
8591   register dw_fde_ref fde;
8592
8593   function_section (current_function_decl);
8594   ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
8595                                current_funcdef_number);
8596   ASM_OUTPUT_LABEL (asm_out_file, label);
8597
8598   /* Expand the fde table if necessary.  */
8599   if (fde_table_in_use == fde_table_allocated)
8600     {
8601       fde_table_allocated += FDE_TABLE_INCREMENT;
8602       fde_table
8603         = (dw_fde_ref) xrealloc (fde_table,
8604                                  fde_table_allocated * sizeof (dw_fde_node));
8605     }
8606
8607   /* Record the FDE associated with this function.  */
8608   current_funcdef_fde = fde_table_in_use;
8609
8610   /* Add the new FDE at the end of the fde_table.  */
8611   fde = &fde_table[fde_table_in_use++];
8612   fde->dw_fde_begin = xstrdup (label);
8613   fde->dw_fde_current_label = NULL;
8614   fde->dw_fde_end = NULL;
8615   fde->dw_fde_cfi = NULL;
8616 }
8617
8618 /* Output a marker (i.e. a label) for the absolute end of the generated code
8619    for a function definition.  This gets called *after* the epilogue code has
8620    been generated.  */
8621
8622 void
8623 dwarf2out_end_epilogue ()
8624 {
8625   dw_fde_ref fde;
8626   char label[MAX_ARTIFICIAL_LABEL_BYTES];
8627
8628   /* Output a label to mark the endpoint of the code generated for this
8629      function.        */
8630   ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
8631   ASM_OUTPUT_LABEL (asm_out_file, label);
8632   fde = &fde_table[fde_table_in_use - 1];
8633   fde->dw_fde_end = xstrdup (label);
8634 }
8635
8636 /* Lookup a filename (in the list of filenames that we know about here in
8637    dwarf2out.c) and return its "index".  The index of each (known) filename is
8638    just a unique number which is associated with only that one filename.
8639    We need such numbers for the sake of generating labels
8640    (in the .debug_sfnames section) and references to those
8641    files  numbers (in the .debug_srcinfo and.debug_macinfo sections).
8642    If the filename given as an argument is not found in our current list,
8643    add it to the list and assign it the next available unique index number.
8644    In order to speed up searches, we remember the index of the filename
8645    was looked up last.  This handles the majority of all searches.  */
8646
8647 static unsigned
8648 lookup_filename (file_name)
8649      char *file_name;
8650 {
8651   static unsigned last_file_lookup_index = 0;
8652   register unsigned i;
8653
8654   /* Check to see if the file name that was searched on the previous call
8655      matches this file name. If so, return the index.  */
8656   if (last_file_lookup_index != 0)
8657     if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
8658       return last_file_lookup_index;
8659
8660   /* Didn't match the previous lookup, search the table */
8661   for (i = 1; i < file_table_in_use; ++i)
8662     if (strcmp (file_name, file_table[i]) == 0)
8663       {
8664         last_file_lookup_index = i;
8665         return i;
8666       }
8667
8668   /* Prepare to add a new table entry by making sure there is enough space in 
8669      the table to do so.  If not, expand the current table.  */
8670   if (file_table_in_use == file_table_allocated)
8671     {
8672       file_table_allocated += FILE_TABLE_INCREMENT;
8673       file_table
8674         = (char **) xrealloc (file_table,
8675                               file_table_allocated * sizeof (char *));
8676     }
8677
8678   /* Add the new entry to the end of the filename table.  */
8679   file_table[file_table_in_use] = xstrdup (file_name);
8680   last_file_lookup_index = file_table_in_use++;
8681
8682   return last_file_lookup_index;
8683 }
8684
8685 /* Output a label to mark the beginning of a source code line entry
8686    and record information relating to this source line, in
8687    'line_info_table' for later output of the .debug_line section.  */
8688
8689 void
8690 dwarf2out_line (filename, line)
8691      register char *filename;
8692      register unsigned line;
8693 {
8694   if (debug_info_level >= DINFO_LEVEL_NORMAL)
8695     {
8696       function_section (current_function_decl);
8697
8698       if (DECL_SECTION_NAME (current_function_decl))
8699         {
8700           register dw_separate_line_info_ref line_info;
8701           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
8702                                      separate_line_info_table_in_use);
8703           fputc ('\n', asm_out_file);
8704
8705           /* expand the line info table if necessary */
8706           if (separate_line_info_table_in_use
8707               == separate_line_info_table_allocated)
8708             {
8709               separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8710               separate_line_info_table
8711                 = (dw_separate_line_info_ref)
8712                   xrealloc (separate_line_info_table,
8713                             separate_line_info_table_allocated
8714                             * sizeof (dw_separate_line_info_entry));
8715             }
8716
8717           /* Add the new entry at the end of the line_info_table.  */
8718           line_info
8719             = &separate_line_info_table[separate_line_info_table_in_use++];
8720           line_info->dw_file_num = lookup_filename (filename);
8721           line_info->dw_line_num = line;
8722           line_info->function = current_funcdef_number;
8723         }
8724       else
8725         {
8726           register dw_line_info_ref line_info;
8727
8728           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
8729                                      line_info_table_in_use);
8730           fputc ('\n', asm_out_file);
8731
8732           /* Expand the line info table if necessary.  */
8733           if (line_info_table_in_use == line_info_table_allocated)
8734             {
8735               line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
8736               line_info_table
8737                 = (dw_line_info_ref)
8738                   xrealloc (line_info_table,
8739                             (line_info_table_allocated
8740                              * sizeof (dw_line_info_entry)));
8741             }
8742
8743           /* Add the new entry at the end of the line_info_table.  */
8744           line_info = &line_info_table[line_info_table_in_use++];
8745           line_info->dw_file_num = lookup_filename (filename);
8746           line_info->dw_line_num = line;
8747         }
8748     }
8749 }
8750
8751 /* Record the beginning of a new source file, for later output
8752    of the .debug_macinfo section.  At present, unimplemented.  */
8753
8754 void
8755 dwarf2out_start_source_file (filename)
8756      register char *filename;
8757 {
8758 }
8759
8760 /* Record the end of a source file, for later output
8761    of the .debug_macinfo section.  At present, unimplemented.  */
8762
8763 void
8764 dwarf2out_end_source_file ()
8765 {
8766 }
8767
8768 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
8769    the tail part of the directive line, i.e. the part which is past the
8770    initial whitespace, #, whitespace, directive-name, whitespace part.  */
8771
8772 void
8773 dwarf2out_define (lineno, buffer)
8774      register unsigned lineno;
8775      register char *buffer;
8776 {
8777   static int initialized = 0;
8778   if (!initialized)
8779     {
8780       dwarf2out_start_source_file (primary_filename);
8781       initialized = 1;
8782     }
8783 }
8784
8785 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
8786    the tail part of the directive line, i.e. the part which is past the
8787    initial whitespace, #, whitespace, directive-name, whitespace part.  */
8788
8789 void
8790 dwarf2out_undef (lineno, buffer)
8791      register unsigned lineno;
8792      register char *buffer;
8793 {
8794 }
8795
8796 /* Set up for Dwarf output at the start of compilation.  */
8797
8798 void
8799 dwarf2out_init (asm_out_file, main_input_filename)
8800      register FILE *asm_out_file;
8801      register char *main_input_filename;
8802 {
8803   /* Remember the name of the primary input file.  */
8804   primary_filename = main_input_filename;
8805
8806   /* Allocate the initial hunk of the file_table.  */
8807   file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *));
8808   bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *));
8809   file_table_allocated = FILE_TABLE_INCREMENT;
8810
8811   /* Skip the first entry - file numbers begin at 1.  */
8812   file_table_in_use = 1;
8813
8814   /* Allocate the initial hunk of the decl_die_table.  */
8815   decl_die_table
8816     = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8817   bzero ((char *) decl_die_table,
8818          DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8819   decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
8820   decl_die_table_in_use = 0;
8821
8822   /* Allocate the initial hunk of the decl_scope_table.  */
8823   decl_scope_table
8824     = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8825   bzero ((char *) decl_scope_table,
8826          DECL_SCOPE_TABLE_INCREMENT * sizeof (tree));
8827   decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
8828   decl_scope_depth = 0;
8829
8830   /* Allocate the initial hunk of the abbrev_die_table.  */
8831   abbrev_die_table
8832     = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT
8833                               * sizeof (dw_die_ref));
8834   bzero ((char *) abbrev_die_table,
8835          ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref));
8836   abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
8837   /* Zero-th entry is allocated, but unused */
8838   abbrev_die_table_in_use = 1;
8839
8840   /* Allocate the initial hunk of the line_info_table.  */
8841   line_info_table
8842     = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT
8843                                   * sizeof (dw_line_info_entry));
8844   bzero ((char *) line_info_table,
8845          LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
8846   line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
8847   /* Zero-th entry is allocated, but unused */
8848   line_info_table_in_use = 1;
8849
8850   /* Allocate the initial hunk of the fde_table.  */
8851   fde_table
8852     = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8853   bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
8854   fde_table_allocated = FDE_TABLE_INCREMENT;
8855   fde_table_in_use = 0;
8856
8857   /* Generate the initial DIE for the .debug section.  Note that the (string) 
8858      value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
8859      will (typically) be a relative pathname and that this pathname should be 
8860      taken as being relative to the directory from which the compiler was
8861      invoked when the given (base) source file was compiled.  */
8862   gen_compile_unit_die (main_input_filename);
8863
8864   ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
8865
8866   /* Generate the CFA instructions common to all FDE's.  Do it now for the
8867      sake of lookup_cfa.  */
8868
8869 #ifdef INCOMING_RETURN_ADDR_RTX
8870   /* On entry, the Canonical Frame Address is at SP+0.  */
8871   dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, 0);
8872   initial_return_save (INCOMING_RETURN_ADDR_RTX);
8873 #endif
8874 }
8875
8876 /* Output stuff that dwarf requires at the end of every file,
8877    and generate the DWARF-2 debugging info.  */
8878
8879 void
8880 dwarf2out_finish ()
8881 {
8882   /* Traverse the DIE tree and add sibling attributes to those DIE's
8883      that have children.  */
8884   add_sibling_attributes (comp_unit_die);
8885
8886   /* Output a terminator label for the .text section.  */
8887   fputc ('\n', asm_out_file);
8888   ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
8889   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
8890
8891 #if 0
8892   /* Output a terminator label for the .data section.  */
8893   fputc ('\n', asm_out_file);
8894   ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
8895   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
8896
8897   /* Output a terminator label for the .bss section.  */
8898   fputc ('\n', asm_out_file);
8899   ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
8900   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
8901 #endif
8902
8903   /* Output the source line correspondence table.  */
8904   if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
8905     {
8906       fputc ('\n', asm_out_file);
8907       ASM_OUTPUT_SECTION (asm_out_file, LINE_SECTION);
8908       output_line_info ();
8909
8910       /* We can only use the low/high_pc attributes if all of the code
8911          was in .text.  */
8912       if (separate_line_info_table_in_use == 0)
8913         {
8914           add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION);
8915           add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
8916         }
8917
8918       add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, LINE_SECTION);
8919     }
8920
8921   /* Output the abbreviation table.  */
8922   fputc ('\n', asm_out_file);
8923   ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
8924   build_abbrev_table (comp_unit_die);
8925   output_abbrev_section ();
8926
8927   /* Initialize the beginning DIE offset - and calculate sizes/offsets.   */
8928   next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
8929   calc_die_sizes (comp_unit_die);
8930
8931   /* calculate sizes/offsets for FDEs.  */
8932   calc_fde_sizes ();
8933
8934   /* Output debugging information.  */
8935   fputc ('\n', asm_out_file);
8936   ASM_OUTPUT_SECTION (asm_out_file, DEBUG_SECTION);
8937   output_compilation_unit_header ();
8938   output_die (comp_unit_die);
8939
8940   if (pubname_table_in_use)
8941     {
8942       /* Output public names table.  */
8943       fputc ('\n', asm_out_file);
8944       ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
8945       output_pubnames ();
8946     }
8947
8948   if (fde_table_in_use)
8949     {
8950       /* Output call frame information.  */
8951       output_call_frame_info ();
8952
8953       /* Output the address range information.  */
8954       fputc ('\n', asm_out_file);
8955       ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
8956       output_aranges ();
8957     }
8958
8959   /* The only DIE we should have with a parent of NULL is comp_unit_die.  */
8960   assert (limbo_die_count == 1);
8961 }
8962 #endif /* DWARF2_DEBUGGING_INFO */