OSDN Git Service

* toplev.c (dbr_sched_time): Unconditional.
[pf3gnuchains/gcc-fork.git] / gcc / toplev.c
1 /* Top level of GNU C compiler
2    Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 /* This is the top level of cc1/c++.
22    It parses command args, opens files, invokes the various passes
23    in the proper order, and counts the time used by each.
24    Error messages and low-level interface to malloc also handled here.  */
25
26 #include "config.h"
27 #undef FLOAT /* This is for hpux. They should change hpux.  */
28 #undef FFS  /* Some systems define this in param.h.  */
29 #include "system.h"
30 #include <signal.h>
31 #include <setjmp.h>
32
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
35 #endif
36
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
39 #endif
40
41 #include "input.h"
42 #include "tree.h"
43 #include "rtl.h"
44 #include "tm_p.h"
45 #include "flags.h"
46 #include "insn-attr.h"
47 #include "insn-codes.h"
48 #include "insn-config.h"
49 #include "recog.h"
50 #include "defaults.h"
51 #include "output.h"
52 #include "except.h"
53 #include "function.h"
54 #include "toplev.h"
55 #include "expr.h"
56 #include "basic-block.h"
57 #include "intl.h"
58 #include "ggc.h"
59 #include "graph.h"
60
61 #ifdef DWARF_DEBUGGING_INFO
62 #include "dwarfout.h"
63 #endif
64
65 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
66 #include "dwarf2out.h"
67 #endif
68
69 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
70 #include "dbxout.h"
71 #endif
72
73 #ifdef SDB_DEBUGGING_INFO
74 #include "sdbout.h"
75 #endif
76
77 #ifdef XCOFF_DEBUGGING_INFO
78 #include "xcoffout.h"
79 #endif
80 \f
81 #ifdef VMS
82 /* The extra parameters substantially improve the I/O performance.  */
83 static FILE *
84 vms_fopen (fname, type)
85      char * fname;
86      char * type;
87 {
88   /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
89      fixed arguments, which matches ANSI's specification but not VAXCRTL's
90      pre-ANSI implementation.  This hack circumvents the mismatch problem.  */
91   FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
92
93   if (*type == 'w')
94     return (*vmslib_fopen) (fname, type, "mbc=32",
95                             "deq=64", "fop=tef", "shr=nil");
96   else
97     return (*vmslib_fopen) (fname, type, "mbc=32");
98 }
99 #define fopen vms_fopen
100 #endif  /* VMS */
101
102 #ifndef DEFAULT_GDB_EXTENSIONS
103 #define DEFAULT_GDB_EXTENSIONS 1
104 #endif
105
106 /* If more than one debugging type is supported, you must define
107    PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way. 
108
109    This is one long line cause VAXC can't handle a \-newline.  */
110 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
111 #ifndef PREFERRED_DEBUGGING_TYPE
112 You Lose!  You must define PREFERRED_DEBUGGING_TYPE!
113 #endif /* no PREFERRED_DEBUGGING_TYPE */
114 #else /* Only one debugging format supported.  Define PREFERRED_DEBUGGING_TYPE
115          so the following code needn't care.  */
116 #ifdef DBX_DEBUGGING_INFO
117 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
118 #endif
119 #ifdef SDB_DEBUGGING_INFO
120 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
121 #endif
122 #ifdef DWARF_DEBUGGING_INFO
123 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
124 #endif
125 #ifdef DWARF2_DEBUGGING_INFO
126 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
127 #endif
128 #ifdef XCOFF_DEBUGGING_INFO
129 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
130 #endif
131 #endif /* More than one debugger format enabled.  */
132
133 /* If still not defined, must have been because no debugging formats
134    are supported.  */
135 #ifndef PREFERRED_DEBUGGING_TYPE
136 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
137 #endif
138
139 #ifndef DIR_SEPARATOR
140 #define DIR_SEPARATOR '/'
141 #endif
142
143 #if ! (defined (VMS) || defined (OS2))
144 extern char **environ;
145 #endif
146 extern char *version_string;
147
148 /* Carry information from ASM_DECLARE_OBJECT_NAME
149    to ASM_FINISH_DECLARE_OBJECT.  */
150
151 extern int size_directive_output;
152 extern tree last_assemble_variable_decl;
153
154 static void notice PVPROTO((const char *s, ...)) ATTRIBUTE_PRINTF_1;
155 static void set_target_switch PROTO((const char *));
156 static const char *decl_name PROTO((tree, int));
157 static void vmessage PROTO((const char *, const char *, va_list));
158 static void v_message_with_file_and_line PROTO((const char *, int, int,
159                                                 const char *, va_list));
160 static void v_message_with_decl PROTO((tree, int, const char *, va_list));
161 static void file_and_line_for_asm PROTO((rtx, char **, int *));
162 static void v_error_with_file_and_line PROTO((const char *, int,
163                                               const char *, va_list));
164 static void v_error_with_decl PROTO((tree, const char *, va_list));
165 static void v_error_for_asm PROTO((rtx, const char *, va_list));
166 static void verror PROTO((const char *, va_list));
167 static void vfatal PROTO((const char *, va_list)) ATTRIBUTE_NORETURN;
168 static void v_warning_with_file_and_line PROTO ((const char *, int,
169                                                  const char *, va_list));
170 static void v_warning_with_decl PROTO((tree, const char *, va_list));
171 static void v_warning_for_asm PROTO((rtx, const char *, va_list));
172 static void vwarning PROTO((const char *, va_list));
173 static void vpedwarn PROTO((const char *, va_list));
174 static void v_pedwarn_with_decl PROTO((tree, const char *, va_list));
175 static void v_pedwarn_with_file_and_line PROTO((const char *, int,
176                                                 const char *, va_list));
177 static void vsorry PROTO((const char *, va_list));
178 extern void set_fatal_function PROTO((void (*)(const char *, va_list)));
179 static void float_signal PROTO((int)) ATTRIBUTE_NORETURN;
180 static void pipe_closed PROTO((int)) ATTRIBUTE_NORETURN;
181 #ifdef ASM_IDENTIFY_LANGUAGE
182 /* This might or might not be used in ASM_IDENTIFY_LANGUAGE. */
183 static void output_lang_identify PROTO((FILE *)) ATTRIBUTE_UNUSED;
184 #endif
185 static void open_dump_file PROTO((const char *, const char *));
186 static void close_dump_file PROTO((void (*) (FILE *, rtx), rtx));
187 static void dump_rtl PROTO((const char *, tree, void (*) (FILE *, rtx), rtx));
188 static void clean_dump_file PROTO((const char *));
189 static void compile_file PROTO((char *));
190 static void display_help PROTO ((void));
191 static void report_file_and_line PROTO ((const char *, int, int));
192 static void vnotice PROTO ((FILE *, const char *, va_list));
193 static void mark_file_stack PROTO ((void *));
194
195 static void decode_d_option PROTO ((const char *));
196 static int  decode_f_option PROTO ((const char *));
197 static int  decode_W_option PROTO ((const char *));
198 static int  decode_g_option PROTO ((const char *));
199 static unsigned independent_decode_option PROTO ((int, char **, unsigned));
200
201 static void print_version PROTO((FILE *, const char *));
202 static int print_single_switch PROTO((FILE *, int, int, const char *,
203                                       const char *, const char *,
204                                       const char *, const char *));
205 static void print_switch_values PROTO((FILE *, int, int, const char *,
206                                        const char *, const char *));
207
208 /* Length of line when printing switch values.  */
209 #define MAX_LINE 75
210
211 /* Name of program invoked, sans directories.  */
212
213 const char *progname;
214
215 /* Copy of arguments to main.  */
216 int save_argc;
217 char **save_argv;
218 \f
219 /* Name of current original source file (what was input to cpp).
220    This comes from each #-command in the actual input.  */
221
222 char *input_filename;
223
224 /* Name of top-level original source file (what was input to cpp).
225    This comes from the #-command at the beginning of the actual input.
226    If there isn't any there, then this is the cc1 input file name.  */
227
228 char *main_input_filename;
229
230 /* Current line number in real source file.  */
231
232 int lineno;
233
234 /* Nonzero if it is unsafe to create any new pseudo registers.  */
235 int no_new_pseudos;
236
237 /* Stack of currently pending input files.  */
238
239 struct file_stack *input_file_stack;
240
241 /* Incremented on each change to input_file_stack.  */
242 int input_file_stack_tick;
243
244 /* Name to use as base of names for dump output files.  */
245
246 const char *dump_base_name;
247
248 /* Bit flags that specify the machine subtype we are compiling for.
249    Bits are tested using macros TARGET_... defined in the tm.h file
250    and set by `-m...' switches.  Must be defined in rtlanal.c.  */
251
252 extern int target_flags;
253
254 /* Flags saying which kinds of debugging dump have been requested.  */
255
256 int rtl_dump = 0;
257 int rtl_dump_and_exit = 0;
258 int jump_opt_dump = 0;
259 int addressof_dump = 0;
260 int cse_dump = 0;
261 int gcse_dump = 0;
262 int loop_dump = 0;
263 int cse2_dump = 0;
264 int branch_prob_dump = 0;
265 int flow_dump = 0;
266 int combine_dump = 0;
267 int regmove_dump = 0;
268 int sched_dump = 0;
269 int local_reg_dump = 0;
270 int global_reg_dump = 0;
271 int flow2_dump = 0;
272 int peephole2_dump = 0;
273 int sched2_dump = 0;
274 int jump2_opt_dump = 0;
275 #ifdef DELAY_SLOTS
276 int dbr_sched_dump = 0;
277 #endif
278 int flag_print_asm_name = 0;
279 #ifdef STACK_REGS
280 int stack_reg_dump = 0;
281 #endif
282 #ifdef MACHINE_DEPENDENT_REORG
283 int mach_dep_reorg_dump = 0;
284 #endif
285 static int flag_print_mem = 0;
286 static int version_flag = 0;
287 static char * filename = 0;
288 enum graph_dump_types graph_dump_format;
289
290 /* Name for output file of assembly code, specified with -o.  */
291
292 char *asm_file_name;
293
294 /* Value of the -G xx switch, and whether it was passed or not.  */
295 int g_switch_value;
296 int g_switch_set;
297
298 /* Type(s) of debugging information we are producing (if any).
299    See flags.h for the definitions of the different possible
300    types of debugging information.  */
301 enum debug_info_type write_symbols = NO_DEBUG;
302
303 /* Level of debugging information we are producing.  See flags.h
304    for the definitions of the different possible levels.  */
305 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
306
307 /* Nonzero means use GNU-only extensions in the generated symbolic
308    debugging information.  */
309 /* Currently, this only has an effect when write_symbols is set to
310    DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG.  */
311 int use_gnu_debug_info_extensions = 0;
312
313 /* Nonzero means do optimizations.  -O.
314    Particular numeric values stand for particular amounts of optimization;
315    thus, -O2 stores 2 here.  However, the optimizations beyond the basic
316    ones are not controlled directly by this variable.  Instead, they are
317    controlled by individual `flag_...' variables that are defaulted
318    based on this variable.  */
319
320 int optimize = 0;
321
322 /* Nonzero means optimize for size.  -Os.
323    The only valid values are zero and non-zero. When optimize_size is
324    non-zero, optimize defaults to 2, but certain individual code
325    bloating optimizations are disabled.  */
326
327 int optimize_size = 0;
328
329 /* Number of error messages and warning messages so far.  */
330
331 int errorcount = 0;
332 int warningcount = 0;
333 int sorrycount = 0;
334
335 /* Pointer to function to compute the name to use to print a declaration.
336    DECL is the declaration in question.
337    VERBOSITY determines what information will be printed:
338      0: DECL_NAME, demangled as necessary.
339      1: and scope information.
340      2: and any other information that might be interesting, such as function
341         parameter types in C++.  */
342
343 const char *(*decl_printable_name)      PROTO ((tree, int));
344
345 /* Pointer to function to compute rtl for a language-specific tree code.  */
346
347 typedef rtx (*lang_expand_expr_t)
348   PROTO ((union tree_node *, rtx, enum machine_mode,
349           enum expand_modifier modifier));
350
351 lang_expand_expr_t lang_expand_expr = 0;
352
353 tree (*lang_expand_constant) PROTO((tree)) = 0;
354
355 /* Pointer to function to finish handling an incomplete decl at the
356    end of compilation.  */
357
358 void (*incomplete_decl_finalize_hook) PROTO((tree)) = 0;
359
360 /* Nonzero if generating code to do profiling.  */
361
362 int profile_flag = 0;
363
364 /* Nonzero if generating code to do profiling on a line-by-line basis.  */
365
366 int profile_block_flag;
367
368 /* Nonzero if generating code to profile program flow graph arcs.  */
369
370 int profile_arc_flag = 0;
371
372 /* Nonzero if generating info for gcov to calculate line test coverage.  */
373
374 int flag_test_coverage = 0;
375
376 /* Nonzero indicates that branch taken probabilities should be calculated.  */
377
378 int flag_branch_probabilities = 0;
379
380 /* Nonzero for -pedantic switch: warn about anything
381    that standard spec forbids.  */
382
383 int pedantic = 0;
384
385 /* Temporarily suppress certain warnings.
386    This is set while reading code from a system header file.  */
387
388 int in_system_header = 0;
389
390 /* Nonzero means do stupid register allocation.
391    Currently, this is 1 if `optimize' is 0.  */
392
393 int obey_regdecls = 0;
394
395 /* Don't print functions as they are compiled and don't print
396    times taken by the various passes.  -quiet.  */
397
398 int quiet_flag = 0;
399 \f
400 /* -f flags.  */
401
402 /* Nonzero means `char' should be signed.  */
403
404 int flag_signed_char;
405
406 /* Nonzero means give an enum type only as many bytes as it needs.  */
407
408 int flag_short_enums;
409
410 /* Nonzero for -fcaller-saves: allocate values in regs that need to
411    be saved across function calls, if that produces overall better code.
412    Optional now, so people can test it.  */
413
414 #ifdef DEFAULT_CALLER_SAVES
415 int flag_caller_saves = 1;
416 #else
417 int flag_caller_saves = 0;
418 #endif
419
420 /* Nonzero if structures and unions should be returned in memory.
421
422    This should only be defined if compatibility with another compiler or
423    with an ABI is needed, because it results in slower code.  */
424
425 #ifndef DEFAULT_PCC_STRUCT_RETURN
426 #define DEFAULT_PCC_STRUCT_RETURN 1
427 #endif
428
429 /* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */
430
431 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
432
433 /* Nonzero for -fforce-mem: load memory value into a register
434    before arithmetic on it.  This makes better cse but slower compilation.  */
435
436 int flag_force_mem = 0;
437
438 /* Nonzero for -fforce-addr: load memory address into a register before
439    reference to memory.  This makes better cse but slower compilation.  */
440
441 int flag_force_addr = 0;
442
443 /* Nonzero for -fdefer-pop: don't pop args after each function call;
444    instead save them up to pop many calls' args with one insns.  */
445
446 int flag_defer_pop = 0;
447
448 /* Nonzero for -ffloat-store: don't allocate floats and doubles
449    in extended-precision registers.  */
450
451 int flag_float_store = 0;
452
453 /* Nonzero for -fcse-follow-jumps:
454    have cse follow jumps to do a more extensive job.  */
455
456 int flag_cse_follow_jumps;
457
458 /* Nonzero for -fcse-skip-blocks:
459    have cse follow a branch around a block.  */
460 int flag_cse_skip_blocks;
461
462 /* Nonzero for -fexpensive-optimizations:
463    perform miscellaneous relatively-expensive optimizations.  */
464 int flag_expensive_optimizations;
465
466 /* Nonzero for -fthread-jumps:
467    have jump optimize output of loop.  */
468
469 int flag_thread_jumps;
470
471 /* Nonzero enables strength-reduction in loop.c.  */
472
473 int flag_strength_reduce = 0;
474
475 /* Nonzero enables loop unrolling in unroll.c.  Only loops for which the
476    number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
477    UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
478    unrolled.  */
479
480 int flag_unroll_loops;
481
482 /* Nonzero enables loop unrolling in unroll.c.  All loops are unrolled.
483    This is generally not a win.  */
484
485 int flag_unroll_all_loops;
486
487 /* Nonzero forces all invariant computations in loops to be moved
488    outside the loop. */
489
490 int flag_move_all_movables = 0;
491
492 /* Nonzero forces all general induction variables in loops to be
493    strength reduced. */
494
495 int flag_reduce_all_givs = 0;
496
497 /* Nonzero to perform full register move optimization passes.  This is the
498    default for -O2.  */
499
500 int flag_regmove = 0;
501
502 /* Nonzero for -fwritable-strings:
503    store string constants in data segment and don't uniquize them.  */
504
505 int flag_writable_strings = 0;
506
507 /* Nonzero means don't put addresses of constant functions in registers.
508    Used for compiling the Unix kernel, where strange substitutions are
509    done on the assembly output.  */
510
511 int flag_no_function_cse = 0;
512
513 /* Nonzero for -fomit-frame-pointer:
514    don't make a frame pointer in simple functions that don't require one.  */
515
516 int flag_omit_frame_pointer = 0;
517
518 /* Nonzero means place each function into its own section on those platforms
519    which support arbitrary section names and unlimited numbers of sections.  */
520
521 int flag_function_sections = 0;
522
523 /* ... and similar for data.  */
524  
525 int flag_data_sections = 0;
526
527 /* Nonzero to inhibit use of define_optimization peephole opts.  */
528
529 int flag_no_peephole = 0;
530
531 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
532    operations in the interest of optimization.  For example it allows
533    GCC to assume arguments to sqrt are nonnegative numbers, allowing
534    faster code for sqrt to be generated.  */
535
536 int flag_fast_math = 0;
537
538 /* Nonzero means the front end generally wants `errno' maintained by math
539    operations, like built-in SQRT, unless overridden by flag_fast_math.  */
540
541 int flag_errno_math = 1;
542
543 /* 0 means straightforward implementation of complex divide acceptable.
544    1 means wide ranges of inputs must work for complex divide.
545    2 means C9X-like requirements for complex divide (not yet implemented).  */
546
547 int flag_complex_divide_method = 0;
548
549 /* Nonzero means all references through pointers are volatile.  */
550
551 int flag_volatile;
552
553 /* Nonzero means treat all global and extern variables as volatile.  */
554
555 int flag_volatile_global;
556
557 /* Nonzero means treat all static variables as volatile.  */
558
559 int flag_volatile_static;
560
561 /* Nonzero means just do syntax checking; don't output anything.  */
562
563 int flag_syntax_only = 0;
564
565 /* Nonzero means perform global cse.  */
566
567 static int flag_gcse;
568
569 /* Nonzero means to use global dataflow analysis to eliminate
570    useless null pointer tests.  */
571
572 static int flag_delete_null_pointer_checks;
573
574 /* Nonzero means to rerun cse after loop optimization.  This increases
575    compilation time about 20% and picks up a few more common expressions.  */
576
577 static int flag_rerun_cse_after_loop;
578
579 /* Nonzero means to run loop optimizations twice.  */
580
581 int flag_rerun_loop_opt;
582
583 /* Nonzero for -finline-functions: ok to inline functions that look like
584    good inline candidates.  */
585
586 int flag_inline_functions;
587
588 /* Nonzero for -fkeep-inline-functions: even if we make a function
589    go inline everywhere, keep its definition around for debugging
590    purposes.  */
591
592 int flag_keep_inline_functions;
593
594 /* Nonzero means that functions will not be inlined.  */
595
596 int flag_no_inline;
597
598 /* Nonzero means that we should emit static const variables
599    regardless of whether or not optimization is turned on.  */
600
601 int flag_keep_static_consts = 1;
602
603 /* Nonzero means we should be saving declaration info into a .X file.  */
604
605 int flag_gen_aux_info = 0;
606
607 /* Specified name of aux-info file.  */
608
609 static char *aux_info_file_name;
610
611 /* Nonzero means make the text shared if supported.  */
612
613 int flag_shared_data;
614
615 /* Nonzero means schedule into delayed branch slots if supported.  */
616
617 int flag_delayed_branch;
618
619 /* Nonzero if we are compiling pure (sharable) code.
620    Value is 1 if we are doing reasonable (i.e. simple
621    offset into offset table) pic.  Value is 2 if we can
622    only perform register offsets.  */
623
624 int flag_pic;
625
626 /* Nonzero means generate extra code for exception handling and enable
627    exception handling.  */
628
629 int flag_exceptions;
630
631 /* Nonzero means use the new model for exception handling. Replaces 
632    -DNEW_EH_MODEL as a compile option. */
633
634 int flag_new_exceptions = 1;
635
636 /* Nonzero means don't place uninitialized global data in common storage
637    by default.  */
638
639 int flag_no_common;
640
641 /* Nonzero means pretend it is OK to examine bits of target floats,
642    even if that isn't true.  The resulting code will have incorrect constants,
643    but the same series of instructions that the native compiler would make.  */
644
645 int flag_pretend_float;
646
647 /* Nonzero means change certain warnings into errors.
648    Usually these are warnings about failure to conform to some standard.  */
649
650 int flag_pedantic_errors = 0;
651
652 /* flag_schedule_insns means schedule insns within basic blocks (before
653    local_alloc).
654    flag_schedule_insns_after_reload means schedule insns after
655    global_alloc.  */
656
657 int flag_schedule_insns = 0;
658 int flag_schedule_insns_after_reload = 0;
659
660 /* The following flags have effect only for scheduling before register
661    allocation:
662
663    flag_schedule_interblock means schedule insns accross basic blocks.
664    flag_schedule_speculative means allow speculative motion of non-load insns.
665    flag_schedule_speculative_load means allow speculative motion of some
666    load insns.
667    flag_schedule_speculative_load_dangerous allows speculative motion of more
668    load insns.  */
669
670 int flag_schedule_interblock = 1;
671 int flag_schedule_speculative = 1;
672 int flag_schedule_speculative_load = 0;
673 int flag_schedule_speculative_load_dangerous = 0;
674
675 /* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
676    by a cheaper branch, on a count register. */
677 int flag_branch_on_count_reg;
678
679 /* -finhibit-size-directive inhibits output of .size for ELF.
680    This is used only for compiling crtstuff.c, 
681    and it may be extended to other effects
682    needed for crtstuff.c on other systems.  */
683 int flag_inhibit_size_directive = 0;
684
685 /* -fverbose-asm causes extra commentary information to be produced in
686    the generated assembly code (to make it more readable).  This option
687    is generally only of use to those who actually need to read the
688    generated assembly code (perhaps while debugging the compiler itself).
689    -fno-verbose-asm, the default, causes the extra information
690    to be omitted and is useful when comparing two assembler files.  */
691
692 int flag_verbose_asm = 0;
693
694 /* -dA causes debug commentary information to be produced in
695    the generated assembly code (to make it more readable).  This option
696    is generally only of use to those who actually need to read the
697    generated assembly code (perhaps while debugging the compiler itself).
698    Currently, this switch is only used by dwarfout.c; however, it is intended
699    to be a catchall for printing debug information in the assembler file.  */
700
701 int flag_debug_asm = 0;
702
703 /* -fgnu-linker specifies use of the GNU linker for initializations.
704    (Or, more generally, a linker that handles initializations.)
705    -fno-gnu-linker says that collect2 will be used.  */
706 #ifdef USE_COLLECT2
707 int flag_gnu_linker = 0;
708 #else
709 int flag_gnu_linker = 1;
710 #endif
711
712 /* Tag all structures with __attribute__(packed) */
713 int flag_pack_struct = 0;
714
715 /* Emit code to check for stack overflow; also may cause large objects
716    to be allocated dynamically.  */
717 int flag_stack_check;
718
719 /* -fcheck-memory-usage causes extra code to be generated in order to check
720    memory accesses.  This is used by a detector of bad memory accesses such
721    as Checker.  */
722 int flag_check_memory_usage = 0;
723
724 /* -fprefix-function-name causes function name to be prefixed.  This
725    can be used with -fcheck-memory-usage to isolate code compiled with
726    -fcheck-memory-usage.  */
727 int flag_prefix_function_name = 0;
728
729 /* 0 if pointer arguments may alias each other.  True in C.
730    1 if pointer arguments may not alias each other but may alias
731    global variables.
732    2 if pointer arguments may not alias each other and may not
733    alias global variables.  True in Fortran.
734    This defaults to 0 for C.  */
735 int flag_argument_noalias = 0;
736
737 /* Nonzero if we should do (language-dependent) alias analysis.
738    Typically, this analysis will assume that expressions of certain
739    types do not alias expressions of certain other types.  Only used
740    if alias analysis (in general) is enabled.  */
741 int flag_strict_aliasing = 0;
742
743 /* Instrument functions with calls at entry and exit, for profiling.  */
744 int flag_instrument_function_entry_exit = 0;
745
746 /* Nonzero means ignore `#ident' directives.  0 means handle them.
747    On SVR4 targets, it also controls whether or not to emit a
748    string identifying the compiler.  */
749
750 int flag_no_ident = 0;
751
752 /* This will perform a peephole pass before sched2. */
753 int flag_peephole2 = 0;
754
755 /* Values of the -falign-* flags: how much to align labels in code. 
756    0 means `use default', 1 means `don't align'.  
757    For each variable, there is an _log variant which is the power
758    of two not less than the variable, for .align output.  */
759
760 int align_loops;
761 int align_loops_log;
762 int align_jumps;
763 int align_jumps_log;
764 int align_labels;
765 int align_labels_log;
766 int align_functions;
767 int align_functions_log;
768
769 /* Table of supported debugging formats.  */
770 static struct
771 {
772   const char * arg;
773   /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
774      constant expression, we use NO_DEBUG in its place.  */
775   enum debug_info_type debug_type;
776   int use_extensions_p;
777   const char * description;
778 } *da,
779 debug_args[] =
780 {
781   { "",       NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
782     "Generate default debug format output" },
783   { "gdb",    NO_DEBUG, 1, "Generate default extended debug format output" },
784 #ifdef DBX_DEBUGGING_INFO
785   { "stabs",  DBX_DEBUG, 0, "Generate STABS format debug output" },
786   { "stabs+", DBX_DEBUG, 1, "Generate extended STABS format debug output" },
787 #endif
788 #ifdef DWARF_DEBUGGING_INFO
789   { "dwarf",  DWARF_DEBUG, 0, "Generate DWARF-1 format debug output"},
790   { "dwarf+", DWARF_DEBUG, 1,
791     "Generated extended DWARF-1 format debug output" },
792 #endif
793 #ifdef DWARF2_DEBUGGING_INFO
794   { "dwarf-2", DWARF2_DEBUG, 0, "Enable DWARF-2 debug output" },
795 #endif
796 #ifdef XCOFF_DEBUGGING_INFO
797   { "xcoff",  XCOFF_DEBUG, 0, "Generate XCOFF format debug output" },
798   { "xcoff+", XCOFF_DEBUG, 1, "Generate extended XCOFF format debug output" },
799 #endif
800 #ifdef SDB_DEBUGGING_INFO
801   { "coff", SDB_DEBUG, 0, "Generate COFF format debug output" },
802 #endif
803   { 0, 0, 0, 0 }
804 };
805
806 typedef struct
807 {
808   const char * string;
809   int *  variable;
810   int    on_value;
811   const char * description;
812 }
813 lang_independent_options;
814
815 /* Add or remove a leading underscore from user symbols.  */
816 int flag_leading_underscore = -1;
817
818 /* The user symbol prefix after having resolved same.  */
819 const char *user_label_prefix;
820
821 /* A default for same.  */
822 #ifndef USER_LABEL_PREFIX
823 #define USER_LABEL_PREFIX ""
824 #endif
825
826 /* Table of language-independent -f options.
827    STRING is the option name.  VARIABLE is the address of the variable.
828    ON_VALUE is the value to store in VARIABLE
829     if `-fSTRING' is seen as an option.
830    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
831
832 lang_independent_options f_options[] =
833 {
834   {"float-store", &flag_float_store, 1,
835    "Do not store floats in registers" },
836   {"volatile", &flag_volatile, 1,
837    "Consider all mem refs through pointers as volatile"},
838   {"volatile-global", &flag_volatile_global, 1,
839    "Consider all mem refs to global data to be volatile" },
840   {"volatile-static", &flag_volatile_static, 1,
841    "Consider all mem refs to static data to be volatile" },
842   {"defer-pop", &flag_defer_pop, 1,
843    "Defer popping functions args from stack until later" },
844   {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
845    "When possible do not generate stack frames"},
846   {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
847    "When running CSE, follow jumps to their targets" },
848   {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
849    "When running CSE, follow conditional jumps" },
850   {"expensive-optimizations", &flag_expensive_optimizations, 1,
851    "Perform a number of minor, expensive optimisations" },
852   {"thread-jumps", &flag_thread_jumps, 1,
853    "Perform jump threading optimisations"},
854   {"strength-reduce", &flag_strength_reduce, 1,
855    "Perform strength reduction optimisations" },
856   {"unroll-loops", &flag_unroll_loops, 1,
857    "Perform loop unrolling when iteration count is known" },
858   {"unroll-all-loops", &flag_unroll_all_loops, 1,
859    "Perform loop unrolling for all loops" },
860   {"move-all-movables", &flag_move_all_movables, 1,
861    "Force all loop invariant computations out of loops" },
862   {"reduce-all-givs", &flag_reduce_all_givs, 1,
863    "Strength reduce all loop general induction variables" },
864   {"writable-strings", &flag_writable_strings, 1,
865    "Store strings in writable data section" },
866   {"peephole", &flag_no_peephole, 0,
867    "Enable machine specific peephole optimisations" },
868   {"force-mem", &flag_force_mem, 1,
869    "Copy memory operands into registers before using" },
870   {"force-addr", &flag_force_addr, 1,
871    "Copy memory address constants into regs before using" },
872   {"function-cse", &flag_no_function_cse, 0,
873    "Allow function addresses to be held in registers" },
874   {"inline-functions", &flag_inline_functions, 1,
875    "Integrate simple functions into their callers" },
876   {"keep-inline-functions", &flag_keep_inline_functions, 1,
877    "Generate code for funcs even if they are fully inlined" },
878   {"inline", &flag_no_inline, 0,
879    "Pay attention to the 'inline' keyword"},
880   {"keep-static-consts", &flag_keep_static_consts, 1,
881    "Emit static const variables even if they are not used" },
882   {"syntax-only", &flag_syntax_only, 1,
883    "Check for syntax errors, then stop" },
884   {"shared-data", &flag_shared_data, 1,
885    "Mark data as shared rather than private" },
886   {"caller-saves", &flag_caller_saves, 1,
887    "Enable saving registers around function calls" },
888   {"pcc-struct-return", &flag_pcc_struct_return, 1,
889    "Return 'short' aggregates in memory, not registers" },
890   {"reg-struct-return", &flag_pcc_struct_return, 0,
891    "Return 'short' aggregates in registers" },
892   {"delayed-branch", &flag_delayed_branch, 1,
893    "Attempt to fill delay slots of branch instructions" },
894   {"gcse", &flag_gcse, 1,
895    "Perform the global common subexpression elimination" },
896   {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
897    "Run CSE pass after loop optimisations"},
898   {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
899    "Run the loop optimiser twice"},
900   {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
901    "Delete useless null pointer checks" },
902   {"pretend-float", &flag_pretend_float, 1,
903    "Pretend that host and target use the same FP format"},
904   {"schedule-insns", &flag_schedule_insns, 1,
905    "Reschedule instructions to avoid pipeline stalls"},
906   {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
907   "Run two passes of the instruction scheduler"},
908   {"sched-interblock",&flag_schedule_interblock, 1,
909    "Enable scheduling across basic blocks" },
910   {"sched-spec",&flag_schedule_speculative, 1,
911    "Allow speculative motion of non-loads" },
912   {"sched-spec-load",&flag_schedule_speculative_load, 1,
913    "Allow speculative motion of some loads" },
914   {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
915    "Allow speculative motion of more loads" },
916   {"branch-count-reg",&flag_branch_on_count_reg, 1,
917    "Replace add,compare,branch with branch on count reg"},
918   {"pic", &flag_pic, 1,
919    "Generate position independent code, if possible"},
920   {"PIC", &flag_pic, 2, ""},
921   {"exceptions", &flag_exceptions, 1,
922    "Enable exception handling" },
923   {"new-exceptions", &flag_new_exceptions, 1,
924    "Use the new model for exception handling" },
925   {"sjlj-exceptions", &exceptions_via_longjmp, 1,
926    "Use setjmp/longjmp to handle exceptions" },
927   {"asynchronous-exceptions", &asynchronous_exceptions, 1,
928    "Support asynchronous exceptions" },
929   {"profile-arcs", &profile_arc_flag, 1,
930    "Insert arc based program profiling code" },
931   {"test-coverage", &flag_test_coverage, 1,
932    "Create data files needed by gcov" },
933   {"branch-probabilities", &flag_branch_probabilities, 1,
934    "Use profiling information for branch probabilities" },
935   {"fast-math", &flag_fast_math, 1,
936    "Improve FP speed by violating ANSI & IEEE rules" },
937   {"common", &flag_no_common, 0,
938    "Do not put unitialised globals in the common section" },
939   {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
940    "Do not generate .size directives" },
941   {"function-sections", &flag_function_sections, 1,
942    "place each function into its own section" },
943   {"data-sections", &flag_data_sections, 1,
944    "place data items into their own section" },
945   {"verbose-asm", &flag_verbose_asm, 1,
946    "Add extra commentry to assembler output"},
947   {"gnu-linker", &flag_gnu_linker, 1,
948    "Output GNU ld formatted global initialisers"},
949   {"regmove", &flag_regmove, 1,
950    "Enables a register move optimisation"},
951   {"optimize-register-move", &flag_regmove, 1,
952    "Do the full regmove optimization pass"},
953   {"pack-struct", &flag_pack_struct, 1,
954    "Pack structure members together without holes" },
955   {"stack-check", &flag_stack_check, 1,
956    "Insert stack checking code into the program" },
957   {"argument-alias", &flag_argument_noalias, 0,
958    "Specify that arguments may alias each other & globals"},
959   {"argument-noalias", &flag_argument_noalias, 1,
960    "Assume arguments may alias globals but not each other"},
961   {"argument-noalias-global", &flag_argument_noalias, 2,
962    "Assume arguments do not alias each other or globals" },
963   {"strict-aliasing", &flag_strict_aliasing, 1,
964    "Assume strict aliasing rules apply" },
965   {"align-loops", &align_loops, 0, 
966    "Align the start of loops" },
967   {"align-jumps", &align_jumps, 0, 
968    "Align labels which are only reached by jumping" },
969   {"align-labels", &align_labels, 0,
970    "Align all labels" },
971   {"align-functions", &align_functions, 0,
972    "Align the start of functions" },
973   {"check-memory-usage", &flag_check_memory_usage, 1,
974    "Generate code to check every memory access" },
975   {"prefix-function-name", &flag_prefix_function_name, 1,
976    "Add a prefix to all function names" },
977   {"dump-unnumbered", &flag_dump_unnumbered, 1,
978    "Suppress output of instruction numbers and line number notes in debugging dumps"},
979   {"instrument-functions", &flag_instrument_function_entry_exit, 1,
980    "Instrument function entry/exit with profiling calls"},
981   {"leading-underscore", &flag_leading_underscore, 1,
982    "External symbols have a leading underscore" },
983   {"ident", &flag_no_ident, 0,
984    "Process #ident directives"},
985   { "peephole2", &flag_peephole2, 1,
986     "Enables an rtl peephole pass run before sched2" },
987   {"math-errno", &flag_errno_math, 1,
988    "Set errno after built-in math functions"}
989 };
990
991 #define NUM_ELEM(a)  (sizeof (a) / sizeof ((a)[0]))
992
993 /* Table of language-specific options.  */
994
995 static struct lang_opt
996 {
997   const char * option;
998   const char * description;
999 }
1000 documented_lang_options[] =
1001 {
1002   /* In order not to overload the --help output, the convention
1003      used here is to only describe those options which are not
1004      enabled by default.  */
1005
1006   { "-ansi", "Compile just for ANSI C" },
1007   { "-fallow-single-precision",
1008     "Do not promote floats to double if using -traditional" },
1009   { "-std= ", "Determine language standard"},
1010
1011   { "-fsigned-bitfields", "" },
1012   { "-funsigned-bitfields","Make bitfields by unsigned by default" },
1013   { "-fno-signed-bitfields", "" },
1014   { "-fno-unsigned-bitfields","" },
1015   { "-fsigned-char", "Make 'char' be signed by default"},
1016   { "-funsigned-char", "Make 'char' be unsigned by default"},
1017   { "-fno-signed-char", "" },
1018   { "-fno-unsigned-char", "" },
1019
1020   { "-ftraditional", "" },
1021   { "-traditional", "Attempt to support traditional K&R style C"},
1022   { "-fnotraditional", "" },
1023   { "-fno-traditional", "" },
1024
1025   { "-fasm", "" },
1026   { "-fno-asm", "Do not recognise the 'asm' keyword" },
1027   { "-fbuiltin", "" },
1028   { "-fno-builtin", "Do not recognise any built in functions" },
1029   { "-fhosted", "Assume normal C execution environment" },
1030   { "-fno-hosted", "" },
1031   { "-ffreestanding",
1032     "Assume that standard libraries & main might not exist" },
1033   { "-fno-freestanding", "" },
1034   { "-fcond-mismatch", "Allow different types as args of ? operator"},
1035   { "-fno-cond-mismatch", "" },
1036   { "-fdollars-in-identifiers", "Allow the use of $ inside identifiers" },
1037   { "-fno-dollars-in-identifiers", "" },
1038   { "-fpreprocessed", "" },
1039   { "-fno-preprocessed", "" },
1040   { "-fshort-double", "Use the same size for double as for float" },
1041   { "-fno-short-double", "" },
1042   { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
1043   { "-fno-short-enums", "" },
1044   { "-fshort-wchar", "Override the underlying type for wchar_t to `unsigned short'" },
1045   { "-fno-short-wchar", "" },
1046
1047   { "-Wall", "Enable most warning messages" },
1048   { "-Wbad-function-cast",
1049     "Warn about casting functions to incompatible types" },
1050   { "-Wno-bad-function-cast", "" },
1051   { "-Wmissing-noreturn",
1052     "Warn about functions which might be candidates for attribute noreturn" },
1053   { "-Wno-missing-noreturn", "" },
1054   { "-Wcast-qual", "Warn about casts which discard qualifiers"},
1055   { "-Wno-cast-qual", "" },
1056   { "-Wchar-subscripts", "Warn about subscripts whose type is 'char'"},
1057   { "-Wno-char-subscripts", "" },
1058   { "-Wcomment", "Warn if nested comments are detected" },
1059   { "-Wno-comment", "" },
1060   { "-Wcomments", "Warn if nested comments are detected" },
1061   { "-Wno-comments", "" },
1062   { "-Wconversion", "Warn about possibly confusing type conversions" },
1063   { "-Wno-conversion", "" },
1064   { "-Wformat", "Warn about printf format anomalies" },
1065   { "-Wno-format", "" },
1066   { "-Wimplicit-function-declaration",
1067     "Warn about implicit function declarations" },
1068   { "-Wno-implicit-function-declaration", "" },
1069   { "-Werror-implicit-function-declaration", "" },
1070   { "-Wimplicit-int", "Warn when a declaration does not specify a type" },
1071   { "-Wno-implicit-int", "" },
1072   { "-Wimplicit", "" },
1073   { "-Wno-implicit", "" },
1074   { "-Wimport", "Warn about the use of the #import directive" },
1075   { "-Wno-import", "" },
1076   { "-Wlong-long","" },
1077   { "-Wno-long-long", "Do not warn about using 'long long' when -pedantic" },
1078   { "-Wmain", "Warn about suspicious declarations of main" },
1079   { "-Wno-main", "" },
1080   { "-Wmissing-braces",
1081     "Warn about possibly missing braces around initialisers" },
1082   { "-Wno-missing-braces", "" },
1083   { "-Wmissing-declarations",
1084     "Warn about global funcs without previous declarations"},
1085   { "-Wno-missing-declarations", "" },
1086   { "-Wmissing-prototypes", "Warn about global funcs without prototypes" },
1087   { "-Wno-missing-prototypes", "" },
1088   { "-Wmultichar", "Warn about use of multicharacter literals"},
1089   { "-Wno-multichar", "" },
1090   { "-Wnested-externs", "Warn about externs not at file scope level" },
1091   { "-Wno-nested-externs", "" },
1092   { "-Wparentheses", "Warn about possible missing parentheses" },
1093   { "-Wno-parentheses", "" },
1094   { "-Wpointer-arith", "Warn about function pointer arithmetic" },
1095   { "-Wno-pointer-arith", "" },
1096   { "-Wredundant-decls",
1097     "Warn about multiple declarations of the same object" },
1098   { "-Wno-redundant-decls", "" },
1099   { "-Wsign-compare", "Warn about signed/unsigned comparisons" },
1100   { "-Wno-sign-compare", "" },
1101   { "-Wfloat-equal", "Warn about testing equality of floating point numbers" },
1102   { "-Wno-float-equal", "" },
1103   { "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
1104   { "-Wno-unknown-pragmas", "" },
1105   { "-Wstrict-prototypes", "Warn about non-prototyped function decls" },
1106   { "-Wno-strict-prototypes", "" },
1107   { "-Wtraditional", "Warn about constructs whose meaning change in ANSI C"},
1108   { "-Wno-traditional", "" },
1109   { "-Wtrigraphs", "Warn when trigraphs are encountered" },
1110   { "-Wno-trigraphs", "" },
1111   { "-Wundef", "" },
1112   { "-Wno-undef", "" },
1113   { "-Wwrite-strings", "Mark strings as 'const char *'"},
1114   { "-Wno-write-strings", "" },
1115   
1116 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1117   
1118   /* These are for Objective C.  */
1119   DEFINE_LANG_NAME ("Objective C")
1120   
1121   { "-lang-objc", "" },
1122   { "-gen-decls", "Dump decls to a .decl file" },
1123   { "-fgnu-runtime", "Generate code for GNU runtime environment" },
1124   { "-fno-gnu-runtime", "" },
1125   { "-fnext-runtime", "Generate code for NeXT runtime environment" },
1126   { "-fno-next-runtime", "" },
1127   { "-Wselector", "Warn if a selector has multiple methods" },
1128   { "-Wno-selector", "" },
1129   { "-Wprotocol", "" },
1130   { "-Wno-protocol", "Do not warn if inherited methods are unimplemented"},
1131   { "-print-objc-runtime-info",
1132     "Generate C header of platform specific features" },
1133
1134 #include "options.h"
1135   
1136 };
1137
1138 /* Here is a table, controlled by the tm.h file, listing each -m switch
1139    and which bits in `target_switches' it should set or clear.
1140    If VALUE is positive, it is bits to set.
1141    If VALUE is negative, -VALUE is bits to clear.
1142    (The sign bit is not used so there is no confusion.)  */
1143
1144 struct
1145 {
1146   const char * name;
1147   int    value;
1148   const char * description;
1149 }
1150 target_switches [] = TARGET_SWITCHES;
1151
1152 /* This table is similar, but allows the switch to have a value.  */
1153
1154 #ifdef TARGET_OPTIONS
1155 struct
1156 {
1157   const char *  prefix;
1158   const char ** variable;
1159   const char *  description;
1160 }
1161 target_options [] = TARGET_OPTIONS;
1162 #endif
1163 \f
1164 /* Options controlling warnings */
1165
1166 /* Don't print warning messages.  -w.  */
1167
1168 int inhibit_warnings = 0;
1169
1170 /* Print various extra warnings.  -W.  */
1171
1172 int extra_warnings = 0;
1173
1174 /* Treat warnings as errors.  -Werror.  */
1175
1176 int warnings_are_errors = 0;
1177
1178 /* Nonzero to warn about unused local variables.  */
1179
1180 int warn_unused;
1181
1182 /* Nonzero to warn about code which is never reached.  */
1183
1184 int warn_notreached;
1185
1186 /* Nonzero to warn about variables used before they are initialized.  */
1187
1188 int warn_uninitialized;
1189
1190 /* Nonzero means warn about all declarations which shadow others.   */
1191
1192 int warn_shadow;
1193
1194 /* Warn if a switch on an enum fails to have a case for every enum value.  */
1195
1196 int warn_switch;
1197
1198 /* Nonzero means warn about function definitions that default the return type
1199    or that use a null return and have a return-type other than void.  */
1200
1201 int warn_return_type;
1202
1203 /* Nonzero means warn about pointer casts that increase the required
1204    alignment of the target type (and might therefore lead to a crash
1205    due to a misaligned access).  */
1206
1207 int warn_cast_align;
1208
1209 /* Nonzero means warn about any identifiers that match in the first N
1210    characters.  The value N is in `id_clash_len'.  */
1211
1212 int warn_id_clash;
1213 unsigned id_clash_len;
1214
1215 /* Nonzero means warn about any objects definitions whose size is larger
1216    than N bytes.  Also want about function definitions whose returned
1217    values are larger than N bytes. The value N is in `larger_than_size'.  */
1218  
1219 int warn_larger_than;
1220 unsigned larger_than_size;
1221
1222 /* Nonzero means warn if inline function is too large.  */
1223
1224 int warn_inline;
1225
1226 /* Warn if a function returns an aggregate,
1227    since there are often incompatible calling conventions for doing this.  */
1228
1229 int warn_aggregate_return;
1230
1231 /* Likewise for -W.  */
1232
1233 lang_independent_options W_options[] =
1234 {
1235   {"unused", &warn_unused, 1, "Warn when a variable is unused" },
1236   {"error", &warnings_are_errors, 1, ""},
1237   {"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
1238   {"switch", &warn_switch, 1,
1239    "Warn about enumerated switches missing a specific case" },
1240   {"aggregate-return", &warn_aggregate_return, 1,
1241    "Warn about returning structures, unions or arrays" },
1242   {"cast-align", &warn_cast_align, 1,
1243    "Warn about pointer casts which increase alignment" },
1244   {"unreachable-code", &warn_notreached, 1, 
1245    "Warn about code that will never be executed" },
1246   {"uninitialized", &warn_uninitialized, 1,
1247    "Warn about unitialized automatic variables"},
1248   {"inline", &warn_inline, 1,
1249    "Warn when an inlined function cannot be inlined"}
1250 };
1251 \f
1252 /* Output files for assembler code (real compiler output)
1253    and debugging dumps.  */
1254
1255 FILE *asm_out_file;
1256 FILE *aux_info_file;
1257 FILE *rtl_dump_file = NULL;
1258
1259 /* Decode the string P as an integral parameter.
1260    If the string is indeed an integer return its numeric value else
1261    issue an Invalid Option error for the option PNAME and return DEFVAL.
1262    If PNAME is zero just return DEFVAL, do not call error.               */
1263    
1264 int
1265 read_integral_parameter (p, pname, defval)
1266      const char *p;
1267      const char *pname;
1268      const int  defval;
1269 {
1270   const char *endp = p;
1271
1272   while (*endp)
1273     {
1274       if (*endp >= '0' && *endp <= '9')
1275         endp++;
1276       else
1277         break;
1278     }
1279
1280   if (*endp != 0)
1281     {
1282       if (pname != 0)
1283         error ("Invalid option `%s'", pname);
1284       return defval;
1285     }
1286
1287   return atoi (p);
1288 }
1289
1290
1291 /* Time accumulators, to count the total time spent in various passes.  */
1292
1293 int parse_time;
1294 int varconst_time;
1295 int integration_time;
1296 int jump_time;
1297 int cse_time;
1298 int gcse_time;
1299 int loop_time;
1300 int cse2_time;
1301 int branch_prob_time;
1302 int flow_time;
1303 int combine_time;
1304 int regmove_time;
1305 int sched_time;
1306 int local_alloc_time;
1307 int global_alloc_time;
1308 int flow2_time;
1309 int peephole2_time;
1310 int sched2_time;
1311 int dbr_sched_time;
1312 int shorten_branch_time;
1313 int stack_reg_time;
1314 int final_time;
1315 int symout_time;
1316 int dump_time;
1317 int gc_time;
1318 int all_time;
1319 \f
1320 /* Return time used so far, in microseconds.  */
1321
1322 long
1323 get_run_time ()
1324 {
1325   if (quiet_flag)
1326     return 0;
1327
1328 #ifdef __BEOS__
1329   return 0;
1330 #else /* not BeOS */
1331 #if defined (_WIN32) && !defined (__CYGWIN__)
1332   if (clock() < 0)
1333     return 0;
1334   else
1335     return (clock() * 1000);
1336 #else /* not _WIN32 */
1337 #ifdef _SC_CLK_TCK
1338   {
1339     static int tick;
1340     struct tms tms;
1341     if (tick == 0)
1342       tick = 1000000 / sysconf(_SC_CLK_TCK);
1343     times (&tms);
1344     return (tms.tms_utime + tms.tms_stime) * tick;
1345   }
1346 #else
1347 #ifdef USG
1348   {
1349     struct tms tms;
1350 #   if HAVE_SYSCONF && defined _SC_CLK_TCK
1351 #    define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
1352 #   else
1353 #    ifdef CLK_TCK
1354 #     define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
1355 #    else
1356 #     define TICKS_PER_SECOND HZ /* traditional UNIX */
1357 #    endif
1358 #   endif
1359     times (&tms);
1360     return (tms.tms_utime + tms.tms_stime) * (1000000 / TICKS_PER_SECOND);
1361   }
1362 #else
1363 #ifndef VMS
1364   {
1365     struct rusage rusage;
1366     getrusage (0, &rusage);
1367     return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1368             + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1369   }
1370 #else /* VMS */
1371   {
1372     struct
1373       {
1374         int proc_user_time;
1375         int proc_system_time;
1376         int child_user_time;
1377         int child_system_time;
1378       } vms_times;
1379     times ((void *) &vms_times);
1380     return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
1381   }
1382 #endif  /* VMS */
1383 #endif  /* USG */
1384 #endif  /* _SC_CLK_TCK */
1385 #endif  /* _WIN32 */
1386 #endif  /* __BEOS__ */
1387 }
1388
1389 #define TIMEVAR(VAR, BODY)    \
1390 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1391
1392 void
1393 print_time (str, total)
1394      const char *str;
1395      int total;
1396 {
1397   fprintf (stderr,
1398            "time in %s: %d.%06d (%.0f%%)\n",
1399            str, total / 1000000, total % 1000000,
1400            (double)total / (double)all_time * 100.0);
1401 }
1402
1403 /* Count an error or warning.  Return 1 if the message should be printed.  */
1404
1405 int
1406 count_error (warningp)
1407      int warningp;
1408 {
1409   if (warningp && inhibit_warnings)
1410     return 0;
1411
1412   if (warningp && !warnings_are_errors)
1413     warningcount++;
1414   else
1415     {
1416       static int warning_message = 0;
1417
1418       if (warningp && !warning_message)
1419         {
1420           notice ("%s: warnings being treated as errors\n", progname);
1421           warning_message = 1;
1422         }
1423       errorcount++;
1424     }
1425
1426   return 1;
1427 }
1428
1429 /* Print a fatal error message.  NAME is the text.
1430    Also include a system error message based on `errno'.  */
1431
1432 void
1433 pfatal_with_name (name)
1434   const char *name;
1435 {
1436   fprintf (stderr, "%s: ", progname);
1437   perror (name);
1438   exit (FATAL_EXIT_CODE);
1439 }
1440
1441 void
1442 fatal_io_error (name)
1443   const char *name;
1444 {
1445   notice ("%s: %s: I/O error\n", progname, name);
1446   exit (FATAL_EXIT_CODE);
1447 }
1448
1449 /* This is the default decl_printable_name function.  */
1450
1451 static const char *
1452 decl_name (decl, verbosity)
1453      tree decl;
1454      int verbosity ATTRIBUTE_UNUSED;
1455 {
1456   return IDENTIFIER_POINTER (DECL_NAME (decl));
1457 }
1458 \f
1459 /* Mark P for GC.  Also mark main_input_filename and input_filename.  */
1460 static void
1461 mark_file_stack (p)
1462      void *p;
1463 {
1464   struct file_stack *stack = *(struct file_stack **)p;
1465
1466   /* We're only called for input_file_stack, so we can mark the current
1467      input_filename here as well.  */
1468   ggc_mark_string (main_input_filename);
1469   ggc_mark_string (input_filename);
1470
1471   while (stack)
1472     {
1473       ggc_mark_string (stack->name);
1474       stack = stack->next;
1475     }
1476 }
1477
1478 static int need_error_newline;
1479
1480 /* Function of last error message;
1481    more generally, function such that if next error message is in it
1482    then we don't have to mention the function name.  */
1483 static tree last_error_function = NULL;
1484
1485 /* Used to detect when input_file_stack has changed since last described.  */
1486 static int last_error_tick;
1487
1488 /* Called when the start of a function definition is parsed,
1489    this function prints on stderr the name of the function.  */
1490
1491 void
1492 announce_function (decl)
1493      tree decl;
1494 {
1495   if (! quiet_flag)
1496     {
1497       if (rtl_dump_and_exit)
1498         fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1499       else
1500         fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1501       fflush (stderr);
1502       need_error_newline = 1;
1503       last_error_function = current_function_decl;
1504     }
1505 }
1506
1507 /* The default function to print out name of current function that caused
1508    an error.  */
1509
1510 void
1511 default_print_error_function (file)
1512   const char *file;
1513 {
1514   if (last_error_function != current_function_decl)
1515     {
1516       if (file)
1517         fprintf (stderr, "%s: ", file);
1518
1519       if (current_function_decl == NULL)
1520         notice ("At top level:\n");
1521       else
1522         notice ((TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE
1523                  ? "In method `%s':\n"
1524                  : "In function `%s':\n"),
1525                 (*decl_printable_name) (current_function_decl, 2));
1526
1527       last_error_function = current_function_decl;
1528     }
1529 }
1530
1531 /* Called by report_error_function to print out function name.
1532  * Default may be overridden by language front-ends.  */
1533
1534 void (*print_error_function) PROTO((const char *)) =
1535   default_print_error_function;
1536
1537 /* Prints out, if necessary, the name of the current function
1538   that caused an error.  Called from all error and warning functions.
1539   We ignore the FILE parameter, as it cannot be relied upon.  */
1540
1541 void
1542 report_error_function (file)
1543   const char *file ATTRIBUTE_UNUSED;
1544 {
1545   struct file_stack *p;
1546
1547   if (need_error_newline)
1548     {
1549       fprintf (stderr, "\n");
1550       need_error_newline = 0;
1551     }
1552
1553   if (input_file_stack && input_file_stack->next != 0
1554       && input_file_stack_tick != last_error_tick)
1555     {
1556       for (p = input_file_stack->next; p; p = p->next)
1557         notice ((p == input_file_stack->next
1558                  ?    "In file included from %s:%d"
1559                  : ",\n                 from %s:%d"),
1560                 p->name, p->line);
1561       fprintf (stderr, ":\n");
1562       last_error_tick = input_file_stack_tick;
1563     }
1564
1565   (*print_error_function) (input_filename);
1566 }
1567 \f
1568 /* Print a message.  */
1569
1570 static void
1571 vnotice (file, msgid, ap)
1572      FILE *file;
1573      const char *msgid;
1574      va_list ap;
1575 {
1576   vfprintf (file, _(msgid), ap);
1577 }
1578
1579 static void
1580 notice VPROTO((const char *msgid, ...))
1581 {
1582 #ifndef ANSI_PROTOTYPES
1583   char *msgid;
1584 #endif
1585   va_list ap;
1586
1587   VA_START (ap, msgid);
1588
1589 #ifndef ANSI_PROTOTYPES
1590   msgid = va_arg (ap, char *);
1591 #endif
1592
1593   vnotice (stderr, msgid, ap);
1594   va_end (ap);
1595 }
1596
1597 void
1598 fnotice VPROTO((FILE *file, const char *msgid, ...))
1599 {
1600 #ifndef ANSI_PROTOTYPES
1601   FILE *file;
1602   const char *msgid;
1603 #endif
1604   va_list ap;
1605
1606   VA_START (ap, msgid);
1607
1608 #ifndef ANSI_PROTOTYPES
1609   file = va_arg (ap, FILE *);
1610   msgid = va_arg (ap, const char *);
1611 #endif
1612
1613   vnotice (file, msgid, ap);
1614   va_end (ap);
1615 }
1616
1617 /* Report FILE and LINE (or program name), and optionally just WARN.  */
1618
1619 static void
1620 report_file_and_line (file, line, warn)
1621      const char *file;
1622      int line;
1623      int warn;
1624 {
1625   if (file)
1626     fprintf (stderr, "%s:%d: ", file, line);
1627   else
1628     fprintf (stderr, "%s: ", progname);
1629
1630   if (warn)
1631     notice ("warning: ");
1632 }
1633
1634 /* Print a message.  */
1635
1636 static void
1637 vmessage (prefix, msgid, ap)
1638      const char *prefix;
1639      const char *msgid;
1640      va_list ap;
1641 {
1642   if (prefix)
1643     fprintf (stderr, "%s: ", prefix);
1644
1645   vfprintf (stderr, msgid, ap);
1646 }
1647
1648 /* Print a message relevant to line LINE of file FILE.  */
1649
1650 static void
1651 v_message_with_file_and_line (file, line, warn, msgid, ap)
1652      const char *file;
1653      int line;
1654      int warn;
1655      const char *msgid;
1656      va_list ap;
1657 {
1658   report_file_and_line (file, line, warn);
1659   vnotice (stderr, msgid, ap);
1660   fputc ('\n', stderr);
1661 }
1662
1663 /* Print a message relevant to the given DECL.  */
1664
1665 static void
1666 v_message_with_decl (decl, warn, msgid, ap)
1667      tree decl;
1668      int warn;
1669      const char *msgid;
1670      va_list ap;
1671 {
1672   const char *p;
1673
1674   report_file_and_line (DECL_SOURCE_FILE (decl),
1675                         DECL_SOURCE_LINE (decl), warn);
1676
1677   /* Do magic to get around lack of varargs support for insertion
1678      of arguments into existing list.  We know that the decl is first;
1679      we ass_u_me that it will be printed with "%s".  */
1680
1681   for (p = _(msgid); *p; ++p)
1682     {
1683       if (*p == '%')
1684         {
1685           if (*(p + 1) == '%')
1686             ++p;
1687           else if (*(p + 1) != 's')
1688             abort ();
1689           else
1690             break;
1691         }
1692     }
1693
1694   if (p > _(msgid))                     /* Print the left-hand substring.  */
1695     {
1696       char fmt[sizeof "%.255s"];
1697       long width = p - _(msgid);
1698              
1699       if (width > 255L) width = 255L;   /* arbitrary */
1700       sprintf (fmt, "%%.%lds", width);
1701       fprintf (stderr, fmt, _(msgid));
1702     }
1703
1704   if (*p == '%')                /* Print the name.  */
1705     {
1706       const char *n = (DECL_NAME (decl)
1707                  ? (*decl_printable_name) (decl, 2)
1708                  : "((anonymous))");
1709       fputs (n, stderr);
1710       while (*p)
1711         {
1712           ++p;
1713           if (ISALPHA (*(p - 1) & 0xFF))
1714             break;
1715         }
1716     }
1717
1718   if (*p)                       /* Print the rest of the message.  */
1719     vmessage ((char *)NULL, p, ap);
1720
1721   fputc ('\n', stderr);
1722 }
1723
1724 /* Figure file and line of the given INSN.  */
1725
1726 static void
1727 file_and_line_for_asm (insn, pfile, pline)
1728      rtx insn;
1729      char **pfile;
1730      int *pline;
1731 {
1732   rtx body = PATTERN (insn);
1733   rtx asmop;
1734
1735   /* Find the (or one of the) ASM_OPERANDS in the insn.  */
1736   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1737     asmop = SET_SRC (body);
1738   else if (GET_CODE (body) == ASM_OPERANDS)
1739     asmop = body;
1740   else if (GET_CODE (body) == PARALLEL
1741            && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1742     asmop = SET_SRC (XVECEXP (body, 0, 0));
1743   else if (GET_CODE (body) == PARALLEL
1744            && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1745     asmop = XVECEXP (body, 0, 0);
1746   else
1747     asmop = NULL;
1748
1749   if (asmop)
1750     {
1751       *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1752       *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1753     }
1754   else
1755     {
1756       *pfile = input_filename;
1757       *pline = lineno;
1758     }
1759 }
1760
1761 /* Report an error at line LINE of file FILE.  */
1762
1763 static void
1764 v_error_with_file_and_line (file, line, msgid, ap)
1765      const char *file;
1766      int line;
1767      const char *msgid;
1768      va_list ap;
1769 {
1770   count_error (0);
1771   report_error_function (file);
1772   v_message_with_file_and_line (file, line, 0, msgid, ap);
1773 }
1774
1775 void
1776 error_with_file_and_line VPROTO((const char *file, int line,
1777                                  const char *msgid, ...))
1778 {
1779 #ifndef ANSI_PROTOTYPES
1780   const char *file;
1781   int line;
1782   const char *msgid;
1783 #endif
1784   va_list ap;
1785
1786   VA_START (ap, msgid);
1787
1788 #ifndef ANSI_PROTOTYPES
1789   file = va_arg (ap, const char *);
1790   line = va_arg (ap, int);
1791   msgid = va_arg (ap, const char *);
1792 #endif
1793
1794   v_error_with_file_and_line (file, line, msgid, ap);
1795   va_end (ap);
1796 }
1797
1798 /* Report an error at the declaration DECL.
1799    MSGID is a format string which uses %s to substitute the declaration
1800    name; subsequent substitutions are a la printf.  */
1801
1802 static void
1803 v_error_with_decl (decl, msgid, ap)
1804      tree decl;
1805      const char *msgid;
1806      va_list ap;
1807 {
1808   count_error (0);
1809   report_error_function (DECL_SOURCE_FILE (decl));
1810   v_message_with_decl (decl, 0, msgid, ap);
1811 }
1812
1813 void
1814 error_with_decl VPROTO((tree decl, const char *msgid, ...))
1815 {
1816 #ifndef ANSI_PROTOTYPES
1817   tree decl;
1818   const char *msgid;
1819 #endif
1820   va_list ap;
1821
1822   VA_START (ap, msgid);
1823
1824 #ifndef ANSI_PROTOTYPES
1825   decl = va_arg (ap, tree);
1826   msgid = va_arg (ap, const char *);
1827 #endif
1828
1829   v_error_with_decl (decl, msgid, ap);
1830   va_end (ap);
1831 }
1832
1833 /* Report an error at the line number of the insn INSN.
1834    This is used only when INSN is an `asm' with operands,
1835    and each ASM_OPERANDS records its own source file and line.  */
1836
1837 static void
1838 v_error_for_asm (insn, msgid, ap)
1839      rtx insn;
1840      const char *msgid;
1841      va_list ap;
1842 {
1843   char *file;
1844   int line;
1845
1846   count_error (0);
1847   file_and_line_for_asm (insn, &file, &line);
1848   report_error_function (file);
1849   v_message_with_file_and_line (file, line, 0, msgid, ap);
1850 }
1851
1852 void
1853 error_for_asm VPROTO((rtx insn, const char *msgid, ...))
1854 {
1855 #ifndef ANSI_PROTOTYPES
1856   rtx insn;
1857   const char *msgid;
1858 #endif
1859   va_list ap;
1860
1861   VA_START (ap, msgid);
1862
1863 #ifndef ANSI_PROTOTYPES
1864   insn = va_arg (ap, rtx);
1865   msgid = va_arg (ap, const char *);
1866 #endif
1867
1868   v_error_for_asm (insn, msgid, ap);
1869   va_end (ap);
1870 }
1871
1872 /* Report an error at the current line number.  */
1873
1874 static void
1875 verror (msgid, ap)
1876      const char *msgid;
1877      va_list ap;
1878 {
1879   v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1880 }
1881
1882 void
1883 error VPROTO((const char *msgid, ...))
1884 {
1885 #ifndef ANSI_PROTOTYPES
1886   const char *msgid;
1887 #endif
1888   va_list ap;
1889
1890   VA_START (ap, msgid);
1891
1892 #ifndef ANSI_PROTOTYPES
1893   msgid = va_arg (ap, const char *);
1894 #endif
1895
1896   verror (msgid, ap);
1897   va_end (ap);
1898 }
1899
1900 /* Report a fatal error at the current line number.  Allow a front end to
1901    intercept the message.  */
1902
1903 static void (*fatal_function) PROTO ((const char *, va_list));
1904
1905 /* Set the function to call when a fatal error occurs.  */
1906
1907 void
1908 set_fatal_function (f)
1909      void (*f) PROTO ((const char *, va_list));
1910 {
1911   fatal_function = f;
1912 }
1913
1914 static void
1915 vfatal (msgid, ap)
1916      const char *msgid;
1917      va_list ap;
1918 {
1919    if (fatal_function != 0)
1920      (*fatal_function) (_(msgid), ap);
1921
1922   verror (msgid, ap);
1923   exit (FATAL_EXIT_CODE);
1924 }
1925
1926 void
1927 fatal VPROTO((const char *msgid, ...))
1928 {
1929 #ifndef ANSI_PROTOTYPES
1930   const char *msgid;
1931 #endif
1932   va_list ap;
1933
1934   VA_START (ap, msgid);
1935
1936 #ifndef ANSI_PROTOTYPES
1937   msgid = va_arg (ap, const char *);
1938 #endif
1939
1940   vfatal (msgid, ap);
1941   va_end (ap);
1942 }
1943
1944 void
1945 _fatal_insn (msgid, insn, file, line, function)
1946      const char *msgid;
1947      rtx insn;
1948      const char *file;
1949      int line;
1950      const char *function;
1951 {
1952   error (msgid);
1953   debug_rtx (insn);
1954   fancy_abort (file, line, function);
1955 }
1956
1957 void
1958 _fatal_insn_not_found (insn, file, line, function)
1959      rtx insn;
1960      const char *file;
1961      int line;
1962      const char *function;
1963 {
1964   if (INSN_CODE (insn) < 0)
1965     _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1966   else
1967     _fatal_insn ("Insn does not satisfy its constraints:",
1968                 insn, file, line, function);
1969 }
1970
1971 /* Report a warning at line LINE of file FILE.  */
1972
1973 static void
1974 v_warning_with_file_and_line (file, line, msgid, ap)
1975      const char *file;
1976      int line;
1977      const char *msgid;
1978      va_list ap;
1979 {
1980   if (count_error (1))
1981     {
1982       report_error_function (file);
1983       v_message_with_file_and_line (file, line, 1, msgid, ap);
1984     }
1985 }
1986
1987 void
1988 warning_with_file_and_line VPROTO((const char *file, int line,
1989                                    const char *msgid, ...))
1990 {
1991 #ifndef ANSI_PROTOTYPES
1992   const char *file;
1993   int line;
1994   const char *msgid;
1995 #endif
1996   va_list ap;
1997
1998   VA_START (ap, msgid);
1999
2000 #ifndef ANSI_PROTOTYPES
2001   file = va_arg (ap, const char *);
2002   line = va_arg (ap, int);
2003   msgid = va_arg (ap, const char *);
2004 #endif
2005
2006   v_warning_with_file_and_line (file, line, msgid, ap);
2007   va_end (ap);
2008 }
2009
2010 /* Report a warning at the declaration DECL.
2011    MSGID is a format string which uses %s to substitute the declaration
2012    name; subsequent substitutions are a la printf.  */
2013
2014 static void
2015 v_warning_with_decl (decl, msgid, ap)
2016      tree decl;
2017      const char *msgid;
2018      va_list ap;
2019 {
2020   if (count_error (1))
2021     {
2022       report_error_function (DECL_SOURCE_FILE (decl));
2023       v_message_with_decl (decl, 1, msgid, ap);
2024     }
2025 }
2026
2027 void
2028 warning_with_decl VPROTO((tree decl, const char *msgid, ...))
2029 {
2030 #ifndef ANSI_PROTOTYPES
2031   tree decl;
2032   const char *msgid;
2033 #endif
2034   va_list ap;
2035
2036   VA_START (ap, msgid);
2037
2038 #ifndef ANSI_PROTOTYPES
2039   decl = va_arg (ap, tree);
2040   msgid = va_arg (ap, const char *);
2041 #endif
2042
2043   v_warning_with_decl (decl, msgid, ap);
2044   va_end (ap);
2045 }
2046
2047 /* Report a warning at the line number of the insn INSN.
2048    This is used only when INSN is an `asm' with operands,
2049    and each ASM_OPERANDS records its own source file and line.  */
2050
2051 static void
2052 v_warning_for_asm (insn, msgid, ap)
2053      rtx insn;
2054      const char *msgid;
2055      va_list ap;
2056 {
2057   if (count_error (1))
2058     {
2059       char *file;
2060       int line;
2061
2062       file_and_line_for_asm (insn, &file, &line);
2063       report_error_function (file);
2064       v_message_with_file_and_line (file, line, 1, msgid, ap);
2065     }
2066 }
2067
2068 void
2069 warning_for_asm VPROTO((rtx insn, const char *msgid, ...))
2070 {
2071 #ifndef ANSI_PROTOTYPES
2072   rtx insn;
2073   const char *msgid;
2074 #endif
2075   va_list ap;
2076
2077   VA_START (ap, msgid);
2078
2079 #ifndef ANSI_PROTOTYPES
2080   insn = va_arg (ap, rtx);
2081   msgid = va_arg (ap, const char *);
2082 #endif
2083
2084   v_warning_for_asm (insn, msgid, ap);
2085   va_end (ap);
2086 }
2087
2088 /* Report a warning at the current line number.  */
2089
2090 static void
2091 vwarning (msgid, ap)
2092      const char *msgid;
2093      va_list ap;
2094 {
2095   v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
2096 }
2097
2098 void
2099 warning VPROTO((const char *msgid, ...))
2100 {
2101 #ifndef ANSI_PROTOTYPES
2102   const char *msgid;
2103 #endif
2104   va_list ap;
2105
2106   VA_START (ap, msgid);
2107
2108 #ifndef ANSI_PROTOTYPES
2109   msgid = va_arg (ap, const char *);
2110 #endif
2111
2112   vwarning (msgid, ap);
2113   va_end (ap);
2114 }
2115
2116 /* These functions issue either warnings or errors depending on
2117    -pedantic-errors.  */
2118
2119 static void
2120 vpedwarn (msgid, ap)
2121      const char *msgid;
2122      va_list ap;
2123 {
2124   if (flag_pedantic_errors)
2125     verror (msgid, ap);
2126   else
2127     vwarning (msgid, ap);
2128 }
2129
2130 void
2131 pedwarn VPROTO((const char *msgid, ...))
2132 {
2133 #ifndef ANSI_PROTOTYPES
2134   const char *msgid;
2135 #endif
2136   va_list ap;
2137
2138   VA_START (ap, msgid);
2139
2140 #ifndef ANSI_PROTOTYPES
2141   msgid = va_arg (ap, const char *);
2142 #endif
2143
2144   vpedwarn (msgid, ap);
2145   va_end (ap);
2146 }
2147
2148 static void
2149 v_pedwarn_with_decl (decl, msgid, ap)
2150      tree decl;
2151      const char *msgid;
2152      va_list ap;
2153 {
2154   /* We don't want -pedantic-errors to cause the compilation to fail from
2155      "errors" in system header files.  Sometimes fixincludes can't fix what's
2156      broken (eg: unsigned char bitfields - fixing it may change the alignment
2157      which will cause programs to mysteriously fail because the C library
2158      or kernel uses the original layout).  There's no point in issuing a
2159      warning either, it's just unnecessary noise.  */
2160
2161   if (! DECL_IN_SYSTEM_HEADER (decl))
2162     {
2163       if (flag_pedantic_errors)
2164         v_error_with_decl (decl, msgid, ap);
2165       else
2166         v_warning_with_decl (decl, msgid, ap);
2167     }
2168 }
2169
2170 void
2171 pedwarn_with_decl VPROTO((tree decl, const char *msgid, ...))
2172 {
2173 #ifndef ANSI_PROTOTYPES
2174   tree decl;
2175   const char *msgid;
2176 #endif
2177   va_list ap;
2178
2179   VA_START (ap, msgid);
2180
2181 #ifndef ANSI_PROTOTYPES
2182   decl = va_arg (ap, tree);
2183   msgid = va_arg (ap, const char *);
2184 #endif
2185
2186   v_pedwarn_with_decl (decl, msgid, ap);
2187   va_end (ap);
2188 }
2189
2190 static void
2191 v_pedwarn_with_file_and_line (file, line, msgid, ap)
2192      const char *file;
2193      int line;
2194      const char *msgid;
2195      va_list ap;
2196 {
2197   if (flag_pedantic_errors)
2198     v_error_with_file_and_line (file, line, msgid, ap);
2199   else
2200     v_warning_with_file_and_line (file, line, msgid, ap);
2201 }
2202
2203 void
2204 pedwarn_with_file_and_line VPROTO((const char *file, int line,
2205                                    const char *msgid, ...))
2206 {
2207 #ifndef ANSI_PROTOTYPES
2208   const char *file;
2209   int line;
2210   const char *msgid;
2211 #endif
2212   va_list ap;
2213
2214   VA_START (ap, msgid);
2215
2216 #ifndef ANSI_PROTOTYPES
2217   file = va_arg (ap, const char *);
2218   line = va_arg (ap, int);
2219   msgid = va_arg (ap, const char *);
2220 #endif
2221
2222   v_pedwarn_with_file_and_line (file, line, msgid, ap);
2223   va_end (ap);
2224 }
2225
2226 /* Apologize for not implementing some feature.  */
2227
2228 static void
2229 vsorry (msgid, ap)
2230      const char *msgid;
2231      va_list ap;
2232 {
2233   sorrycount++;
2234   if (input_filename)
2235     fprintf (stderr, "%s:%d: ", input_filename, lineno);
2236   else
2237     fprintf (stderr, "%s: ", progname);
2238   notice ("sorry, not implemented: ");
2239   vnotice (stderr, msgid, ap);
2240   fputc ('\n', stderr);
2241 }
2242
2243 void
2244 sorry VPROTO((const char *msgid, ...))
2245 {
2246 #ifndef ANSI_PROTOTYPES
2247   const char *msgid;
2248 #endif
2249   va_list ap;
2250
2251   VA_START (ap, msgid);
2252
2253 #ifndef ANSI_PROTOTYPES
2254   msgid = va_arg (ap, const char *);
2255 #endif
2256
2257   vsorry (msgid, ap);
2258   va_end (ap);
2259 }
2260 \f
2261
2262 /* This calls abort and is used to avoid problems when abort if a macro.
2263    It is used when we need to pass the address of abort.  */
2264
2265 void
2266 do_abort ()
2267 {
2268   abort ();
2269 }
2270
2271 /* When `malloc.c' is compiled with `rcheck' defined,
2272    it calls this function to report clobberage.  */
2273
2274 void
2275 botch (s)
2276   const char * s ATTRIBUTE_UNUSED;
2277 {
2278   abort ();
2279 }
2280 \f
2281 /* Return the logarithm of X, base 2, considering X unsigned,
2282    if X is a power of 2.  Otherwise, returns -1.
2283
2284    This should be used via the `exact_log2' macro.  */
2285
2286 int
2287 exact_log2_wide (x)
2288      register unsigned HOST_WIDE_INT x;
2289 {
2290   register int log = 0;
2291   /* Test for 0 or a power of 2.  */
2292   if (x == 0 || x != (x & -x))
2293     return -1;
2294   while ((x >>= 1) != 0)
2295     log++;
2296   return log;
2297 }
2298
2299 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
2300    If X is 0, return -1.
2301
2302    This should be used via the floor_log2 macro.  */
2303
2304 int
2305 floor_log2_wide (x)
2306      register unsigned HOST_WIDE_INT x;
2307 {
2308   register int log = -1;
2309   while (x != 0)
2310     log++,
2311     x >>= 1;
2312   return log;
2313 }
2314
2315 static int float_handler_set;
2316 int float_handled;
2317 jmp_buf float_handler;
2318
2319 /* Signals actually come here.  */
2320
2321 static void
2322 float_signal (signo)
2323      /* If this is missing, some compilers complain.  */
2324      int signo ATTRIBUTE_UNUSED;
2325 {
2326   if (float_handled == 0)
2327     abort ();
2328 #if defined (USG) || defined (hpux)
2329   signal (SIGFPE, float_signal);  /* re-enable the signal catcher */
2330 #endif
2331   float_handled = 0;
2332   signal (SIGFPE, float_signal);
2333   longjmp (float_handler, 1);
2334 }
2335
2336 /* Specify where to longjmp to when a floating arithmetic error happens.
2337    If HANDLER is 0, it means don't handle the errors any more.  */
2338
2339 void
2340 set_float_handler (handler)
2341      jmp_buf handler;
2342 {
2343   float_handled = (handler != 0);
2344   if (handler)
2345     bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2346
2347   if (float_handled && ! float_handler_set)
2348     {
2349       signal (SIGFPE, float_signal);
2350       float_handler_set = 1;
2351     }
2352 }
2353
2354 /* This is a wrapper function for code which might elicit an
2355    arithmetic exception.  That code should be passed in as a function
2356    pointer FN, and one argument DATA.  DATA is usually a struct which
2357    contains the real input and output for function FN.  This function
2358    returns 0 (failure) if longjmp was called (i.e. an exception
2359    occured.)  It returns 1 (success) otherwise. */
2360
2361 int
2362 do_float_handler (fn, data)
2363   void (*fn) PROTO ((PTR));
2364   PTR data;
2365 {
2366   jmp_buf buf;
2367
2368   if (setjmp (buf))
2369     {
2370       /* We got here via longjmp() caused by an exception in function fn() */
2371       set_float_handler (NULL);
2372       return 0;
2373     }
2374
2375   set_float_handler (buf);
2376   (*fn)(data);
2377   set_float_handler (NULL);
2378   return 1;
2379 }
2380
2381 /* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2382    error happens, pushing the previous specification into OLD_HANDLER.
2383    Return an indication of whether there was a previous handler in effect.  */
2384
2385 int
2386 push_float_handler (handler, old_handler)
2387      jmp_buf handler, old_handler;
2388 {
2389   int was_handled = float_handled;
2390
2391   float_handled = 1;
2392   if (was_handled)
2393     memcpy ((char *) old_handler, (char *) float_handler,
2394            sizeof (float_handler));
2395
2396   memcpy ((char *) float_handler, (char *) handler, sizeof (float_handler));
2397   return was_handled;
2398 }
2399
2400 /* Restore the previous specification of whether and where to longjmp to
2401    when a floating arithmetic error happens.  */
2402
2403 void
2404 pop_float_handler (handled, handler)
2405      int handled;
2406      jmp_buf handler;
2407 {
2408   float_handled = handled;
2409   if (handled)
2410     bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2411 }
2412
2413 /* Handler for SIGPIPE.  */
2414
2415 static void
2416 pipe_closed (signo)
2417      /* If this is missing, some compilers complain.  */
2418      int signo ATTRIBUTE_UNUSED;
2419 {
2420   fatal ("output pipe has been closed");
2421 }
2422
2423 /* Strip off a legitimate source ending from the input string NAME of
2424    length LEN.  Rather than having to know the names used by all of
2425    our front ends, we strip off an ending of a period followed by
2426    up to five characters.  (Java uses ".class".) */
2427
2428 void
2429 strip_off_ending (name, len)
2430      char *name;
2431      int len;
2432 {
2433   int i;
2434   for (i = 2;  i < 6 && len > i;  i++)
2435     {
2436       if (name[len - i] == '.')
2437         {
2438           name[len - i] = '\0';
2439           break;
2440         }
2441     }
2442 }
2443
2444 /* Output a quoted string.  */
2445
2446 void
2447 output_quoted_string (asm_file, string)
2448      FILE *asm_file;
2449      const char *string;
2450 {
2451 #ifdef OUTPUT_QUOTED_STRING
2452   OUTPUT_QUOTED_STRING (asm_file, string);
2453 #else
2454   char c;
2455
2456   putc ('\"', asm_file);
2457   while ((c = *string++) != 0)
2458     {
2459       if (c == '\"' || c == '\\')
2460         putc ('\\', asm_file);
2461       putc (c, asm_file);
2462     }
2463   putc ('\"', asm_file);
2464 #endif
2465 }
2466
2467 /* Output a file name in the form wanted by System V.  */
2468
2469 void
2470 output_file_directive (asm_file, input_name)
2471      FILE *asm_file;
2472      const char *input_name;
2473 {
2474   int len = strlen (input_name);
2475   const char *na = input_name + len;
2476
2477   /* NA gets INPUT_NAME sans directory names.  */
2478   while (na > input_name)
2479     {
2480       if (na[-1] == '/')
2481         break;
2482 #ifdef DIR_SEPARATOR
2483       if (na[-1] == DIR_SEPARATOR)
2484         break;
2485 #endif
2486       na--;
2487     }
2488
2489 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2490   ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2491 #else
2492 #ifdef ASM_OUTPUT_SOURCE_FILENAME
2493   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2494 #else
2495   fprintf (asm_file, "\t.file\t");
2496   output_quoted_string (asm_file, na);
2497   fputc ('\n', asm_file);
2498 #endif
2499 #endif
2500 }
2501 \f
2502 #ifdef ASM_IDENTIFY_LANGUAGE
2503 /* Routine to build language identifier for object file.  */
2504 static void
2505 output_lang_identify (asm_out_file)
2506      FILE *asm_out_file;
2507 {
2508   int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2509   char *s = (char *) alloca (len);
2510   sprintf (s, "__gnu_compiled_%s", lang_identify ());
2511   ASM_OUTPUT_LABEL (asm_out_file, s);
2512 }
2513 #endif
2514
2515 /* Routine to open a dump file.  */
2516 static void
2517 open_dump_file (suffix, function_name)
2518      const char *suffix;
2519      const char *function_name;
2520 {
2521   char *dumpname;
2522
2523   TIMEVAR
2524     (dump_time,
2525      {
2526        dumpname = concat (dump_base_name, suffix, NULL);
2527
2528        if (rtl_dump_file != NULL)
2529          fclose (rtl_dump_file);
2530   
2531        rtl_dump_file = fopen (dumpname, "a");
2532        
2533        if (rtl_dump_file == NULL)
2534          pfatal_with_name (dumpname);
2535        
2536        free (dumpname);
2537
2538        if (function_name)
2539          fprintf (rtl_dump_file, "\n;; Function %s\n\n", function_name);
2540      });
2541   
2542   return;
2543 }
2544
2545 /* Routine to close a dump file.  */
2546 static void
2547 close_dump_file (func, insns)
2548      void (*func) PROTO ((FILE *, rtx));
2549      rtx    insns;
2550 {
2551   TIMEVAR
2552     (dump_time,
2553      {
2554        if (func)
2555          func (rtl_dump_file, insns);
2556        
2557        fflush (rtl_dump_file);
2558        fclose (rtl_dump_file);
2559        
2560        rtl_dump_file = NULL;
2561      });
2562
2563   return;
2564 }
2565
2566 /* Routine to dump rtl into a file.  */
2567 static void
2568 dump_rtl (suffix, decl, func, insns)
2569      const char *suffix;
2570      tree   decl;
2571      void (*func) PROTO ((FILE *, rtx));
2572      rtx    insns;
2573 {
2574   open_dump_file (suffix, decl_printable_name (decl, 2));
2575   close_dump_file (func, insns);
2576 }
2577
2578 /* Routine to empty a dump file.  */
2579 static void
2580 clean_dump_file (suffix)
2581   const char *suffix;
2582 {
2583   char * const dumpname = concat (dump_base_name, suffix, NULL);
2584
2585   rtl_dump_file = fopen (dumpname, "w");
2586
2587   if (rtl_dump_file == NULL)
2588     pfatal_with_name (dumpname);       
2589
2590   free (dumpname);
2591
2592   fclose (rtl_dump_file);
2593   rtl_dump_file = NULL;
2594   
2595   return;
2596 }
2597
2598 /* Do any final processing required for the declarations in VEC, of
2599    which there are LEN.  We write out inline functions and variables
2600    that have been deferred until this point, but which are required.
2601    Returns non-zero if anything was put out.  */ 
2602 int
2603 wrapup_global_declarations (vec, len)
2604      tree *vec;
2605      int len;
2606 {
2607   tree decl;
2608   int i;
2609   int reconsider;
2610   int output_something = 0;
2611
2612   for (i = 0; i < len; i++)
2613     {
2614       decl = vec[i];
2615       
2616       /* We're not deferring this any longer.  */
2617       DECL_DEFER_OUTPUT (decl) = 0;
2618       
2619       if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2620           && incomplete_decl_finalize_hook != 0)
2621         (*incomplete_decl_finalize_hook) (decl);
2622     }
2623
2624   /* Now emit any global variables or functions that we have been
2625      putting off.  We need to loop in case one of the things emitted
2626      here references another one which comes earlier in the list.  */
2627   do
2628     {
2629       reconsider = 0;
2630       for (i = 0; i < len; i++)
2631         {
2632           decl = vec[i];
2633
2634           if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2635             continue;
2636
2637           /* Don't write out static consts, unless we still need them.
2638
2639              We also keep static consts if not optimizing (for debugging),
2640              unless the user specified -fno-keep-static-consts.
2641              ??? They might be better written into the debug information.
2642              This is possible when using DWARF.
2643
2644              A language processor that wants static constants to be always
2645              written out (even if it is not used) is responsible for
2646              calling rest_of_decl_compilation itself.  E.g. the C front-end
2647              calls rest_of_decl_compilation from finish_decl.
2648              One motivation for this is that is conventional in some
2649              environments to write things like:
2650              static const char rcsid[] = "... version string ...";
2651              intending to force the string to be in the executable.
2652
2653              A language processor that would prefer to have unneeded
2654              static constants "optimized away" would just defer writing
2655              them out until here.  E.g. C++ does this, because static
2656              constants are often defined in header files.
2657
2658              ??? A tempting alternative (for both C and C++) would be
2659              to force a constant to be written if and only if it is
2660              defined in a main file, as opposed to an include file.  */
2661
2662           if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2663               && (! TREE_READONLY (decl)
2664                   || TREE_PUBLIC (decl)
2665                   || (!optimize && flag_keep_static_consts)
2666                   || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2667             {
2668               reconsider = 1;
2669               rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2670             }
2671
2672           if (TREE_CODE (decl) == FUNCTION_DECL
2673               && DECL_INITIAL (decl) != 0
2674               && DECL_SAVED_INSNS (decl) != 0
2675               && (flag_keep_inline_functions
2676                   || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
2677                   || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2678             {
2679               reconsider = 1;
2680               temporary_allocation ();
2681               output_inline_function (decl);
2682               permanent_allocation (1);
2683             }
2684         }
2685
2686       if (reconsider)
2687         output_something = 1;
2688     }
2689   while (reconsider);
2690
2691   return output_something;
2692 }
2693
2694 /* Issue appropriate warnings for the global declarations in VEC (of
2695    which there are LEN).  Output debugging information for them.  */
2696 void
2697 check_global_declarations (vec, len)
2698      tree *vec;
2699      int len;
2700 {
2701   tree decl;
2702   int i;
2703
2704   for (i = 0; i < len; i++)
2705     {
2706       decl = vec[i];
2707
2708       if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2709           && ! TREE_ASM_WRITTEN (decl))
2710         /* Cancel the RTL for this decl so that, if debugging info
2711            output for global variables is still to come,
2712            this one will be omitted.  */
2713         DECL_RTL (decl) = NULL;
2714
2715       /* Warn about any function
2716          declared static but not defined.
2717          We don't warn about variables,
2718          because many programs have static variables
2719          that exist only to get some text into the object file.  */
2720       if (TREE_CODE (decl) == FUNCTION_DECL
2721           && (warn_unused
2722               || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2723           && DECL_INITIAL (decl) == 0
2724           && DECL_EXTERNAL (decl)
2725           && ! DECL_ARTIFICIAL (decl)
2726           && ! TREE_PUBLIC (decl))
2727         {
2728           if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2729             pedwarn_with_decl (decl,
2730                                "`%s' used but never defined");
2731           else
2732             warning_with_decl (decl,
2733                                "`%s' declared `static' but never defined");
2734           /* This symbol is effectively an "extern" declaration now.  */
2735           TREE_PUBLIC (decl) = 1;
2736           assemble_external (decl);
2737         }
2738
2739       /* Warn about static fns or vars defined but not used,
2740          but not about inline functions or static consts
2741          since defining those in header files is normal practice.  */
2742       if (warn_unused
2743           && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2744               || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2745           && ! DECL_IN_SYSTEM_HEADER (decl)
2746           && ! DECL_EXTERNAL (decl)
2747           && ! TREE_PUBLIC (decl)
2748           && ! TREE_USED (decl)
2749           && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2750           /* The TREE_USED bit for file-scope decls
2751              is kept in the identifier, to handle multiple
2752              external decls in different scopes.  */
2753           && ! TREE_USED (DECL_NAME (decl)))
2754         warning_with_decl (decl, "`%s' defined but not used");
2755
2756 #ifdef SDB_DEBUGGING_INFO
2757       /* The COFF linker can move initialized global vars to the end.
2758          And that can screw up the symbol ordering.
2759          By putting the symbols in that order to begin with,
2760          we avoid a problem.  mcsun!unido!fauern!tumuc!pes@uunet.uu.net.  */
2761       if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2762           && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2763           && ! DECL_EXTERNAL (decl)
2764           && DECL_RTL (decl) != 0)
2765         TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2766
2767       /* Output COFF information for non-global
2768          file-scope initialized variables.  */
2769       if (write_symbols == SDB_DEBUG
2770           && TREE_CODE (decl) == VAR_DECL
2771           && DECL_INITIAL (decl)
2772           && ! DECL_EXTERNAL (decl)
2773           && DECL_RTL (decl) != 0
2774           && GET_CODE (DECL_RTL (decl)) == MEM)
2775         TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2776 #endif /* SDB_DEBUGGING_INFO */
2777 #ifdef DWARF_DEBUGGING_INFO
2778       /* Output DWARF information for file-scope tentative data object
2779          declarations, file-scope (extern) function declarations (which
2780          had no corresponding body) and file-scope tagged type declarations
2781          and definitions which have not yet been forced out.  */
2782
2783       if (write_symbols == DWARF_DEBUG
2784           && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2785         TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2786 #endif
2787 #ifdef DWARF2_DEBUGGING_INFO
2788       /* Output DWARF2 information for file-scope tentative data object
2789          declarations, file-scope (extern) function declarations (which
2790          had no corresponding body) and file-scope tagged type declarations
2791          and definitions which have not yet been forced out.  */
2792
2793       if (write_symbols == DWARF2_DEBUG
2794           && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2795         TIMEVAR (symout_time, dwarf2out_decl (decl));
2796 #endif
2797     }
2798 }
2799
2800 /* Compile an entire file of output from cpp, named NAME.
2801    Write a file of assembly output and various debugging dumps.  */
2802
2803 static void
2804 compile_file (name)
2805      char *name;
2806 {
2807   tree globals;
2808   int start_time;
2809
2810   int name_specified = name != 0;
2811
2812   if (dump_base_name == 0)
2813     dump_base_name = name ? name : "gccdump";
2814
2815   parse_time = 0;
2816   varconst_time = 0;
2817   integration_time = 0;
2818   jump_time = 0;
2819   cse_time = 0;
2820   gcse_time = 0;
2821   loop_time = 0;
2822   cse2_time = 0;
2823   branch_prob_time = 0;
2824   flow_time = 0;
2825   combine_time = 0;
2826   regmove_time = 0;
2827   sched_time = 0;
2828   local_alloc_time = 0;
2829   global_alloc_time = 0;
2830   flow2_time = 0;
2831   peephole2_time = 0;
2832   sched2_time = 0;
2833   dbr_sched_time = 0;
2834   shorten_branch_time = 0;
2835   stack_reg_time = 0;
2836   final_time = 0;
2837   symout_time = 0;
2838   dump_time = 0;
2839
2840   /* Initialize data in various passes.  */
2841
2842   init_obstacks ();
2843   init_tree_codes ();
2844   name = init_parse (name);
2845   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2846                   || debug_info_level == DINFO_LEVEL_VERBOSE
2847                   || flag_test_coverage
2848                   || warn_notreached);
2849   init_regs ();
2850   init_decl_processing ();
2851   init_optabs ();
2852   init_stmt ();
2853   init_eh ();
2854   init_loop ();
2855   init_reload ();
2856   init_alias_once ();
2857   init_function_once ();
2858   init_stor_layout_once ();
2859   init_varasm_once ();
2860
2861   /* The following initialization functions need to generate rtl, so
2862      provide a dummy function context for them.  */
2863   init_dummy_function_start ();
2864   init_expmed ();
2865   init_expr_once ();
2866   if (flag_caller_saves)
2867     init_caller_save ();
2868   expand_dummy_function_end ();
2869
2870   /* If auxiliary info generation is desired, open the output file.
2871      This goes in the same directory as the source file--unlike
2872      all the other output files.  */
2873   if (flag_gen_aux_info)
2874     {
2875       aux_info_file = fopen (aux_info_file_name, "w");
2876       if (aux_info_file == 0)
2877         pfatal_with_name (aux_info_file_name);
2878     }
2879
2880   /* Clear the dump files.  */
2881   if (rtl_dump)
2882     clean_dump_file (".00.rtl");
2883   if (jump_opt_dump)
2884     {
2885       clean_dump_file (".01.jump");
2886       if (graph_dump_format != no_graph)
2887         clean_graph_dump_file (dump_base_name, ".01.jump");
2888     }
2889   if (cse_dump)
2890     {
2891       clean_dump_file (".02.cse");
2892       if (graph_dump_format != no_graph)
2893         clean_graph_dump_file (dump_base_name, ".02.cse");
2894     }
2895   if (addressof_dump)
2896     {
2897       clean_dump_file (".03.addressof");
2898       if (graph_dump_format != no_graph)
2899         clean_graph_dump_file (dump_base_name, ".03.addressof");
2900     }
2901   if (gcse_dump)
2902     {
2903       clean_dump_file (".04.gcse");
2904       if (graph_dump_format != no_graph)
2905         clean_graph_dump_file (dump_base_name, ".04.gcse");
2906     }
2907   if (loop_dump)
2908     {
2909       clean_dump_file (".05.loop");
2910       if (graph_dump_format != no_graph)
2911         clean_graph_dump_file (dump_base_name, ".05.loop");
2912     }
2913   if (cse2_dump)
2914     {
2915       clean_dump_file (".06.cse2");
2916       if (graph_dump_format != no_graph)
2917         clean_graph_dump_file (dump_base_name, ".06.cse2");
2918     }
2919   if (branch_prob_dump)
2920     {
2921       clean_dump_file (".07.bp");
2922       if (graph_dump_format != no_graph)
2923         clean_graph_dump_file (dump_base_name, ".07.bp");
2924     }
2925   if (flow_dump)
2926     {
2927       clean_dump_file (".08.flow");
2928       if (graph_dump_format != no_graph)
2929         clean_graph_dump_file (dump_base_name, ".08.flow");
2930     }
2931   if (combine_dump)
2932     {
2933       clean_dump_file (".09.combine");
2934       if (graph_dump_format != no_graph)
2935         clean_graph_dump_file (dump_base_name, ".09.combine");
2936     }
2937   if (regmove_dump)
2938     {
2939       clean_dump_file (".10.regmove");
2940       if (graph_dump_format != no_graph)
2941         clean_graph_dump_file (dump_base_name, ".10.regmove");
2942     }
2943 #ifdef INSN_SCHEDULING
2944   if (sched_dump)
2945     {
2946       clean_dump_file (".11.sched");
2947       if (graph_dump_format != no_graph)
2948         clean_graph_dump_file (dump_base_name, ".11.sched");
2949     }
2950 #endif
2951   if (local_reg_dump)
2952     {
2953       clean_dump_file (".12.lreg");
2954       if (graph_dump_format != no_graph)
2955         clean_graph_dump_file (dump_base_name, ".12.lreg");
2956     }
2957   if (global_reg_dump)
2958     {
2959       clean_dump_file (".13.greg");
2960       if (graph_dump_format != no_graph)
2961         clean_graph_dump_file (dump_base_name, ".13.greg");
2962     }
2963   if (flow2_dump)
2964     {
2965       clean_dump_file (".14.flow2");
2966       if (graph_dump_format != no_graph)
2967         clean_graph_dump_file (dump_base_name, ".14.flow2");
2968     }
2969 #ifdef HAVE_peephole2
2970   if (peephole2_dump)
2971     {
2972       clean_dump_file (".15.peephole2");
2973       if (graph_dump_format != no_graph)
2974         clean_graph_dump_file (dump_base_name, ".15.peephole2");
2975     }
2976 #endif
2977 #ifdef INSN_SCHEDULING
2978   if (sched2_dump)
2979     {
2980       clean_dump_file (".16.sched2");
2981       if (graph_dump_format != no_graph)
2982         clean_graph_dump_file (dump_base_name, ".16.sched2");
2983     }
2984 #endif
2985   if (jump2_opt_dump)
2986     {
2987       clean_dump_file (".17.jump2");
2988       if (graph_dump_format != no_graph)
2989         clean_graph_dump_file (dump_base_name, ".17.jump2");
2990     }
2991 #ifdef MACHINE_DEPENDENT_REORG
2992   if (mach_dep_reorg_dump)
2993     {
2994       clean_dump_file (".18.mach");
2995       if (graph_dump_format != no_graph)
2996         clean_graph_dump_file (dump_base_name, ".18.mach");
2997     }
2998 #endif
2999 #ifdef DELAY_SLOTS
3000   if (dbr_sched_dump)
3001     {
3002       clean_dump_file (".19.dbr");
3003       if (graph_dump_format != no_graph)
3004         clean_graph_dump_file (dump_base_name, ".19.dbr");
3005     }
3006 #endif
3007 #ifdef STACK_REGS
3008   if (stack_reg_dump)
3009     {
3010       clean_dump_file (".20.stack");
3011       if (graph_dump_format != no_graph)
3012         clean_graph_dump_file (dump_base_name, ".20.stack");
3013     }
3014 #endif
3015
3016   /* Open assembler code output file.  */
3017
3018   if (flag_syntax_only)
3019     asm_out_file = NULL;
3020   else
3021     {
3022       if (! name_specified && asm_file_name == 0)
3023         asm_out_file = stdout;
3024       else
3025         {
3026           int len = strlen (dump_base_name);
3027           register char *dumpname = (char *) xmalloc (len + 6);
3028           strcpy (dumpname, dump_base_name);
3029           strip_off_ending (dumpname, len);
3030           strcat (dumpname, ".s");
3031           if (asm_file_name == 0)
3032             asm_file_name = xstrdup (dumpname);
3033           if (!strcmp (asm_file_name, "-"))
3034             asm_out_file = stdout;
3035           else
3036             asm_out_file = fopen (asm_file_name, "w");
3037           if (asm_out_file == 0)
3038             pfatal_with_name (asm_file_name);
3039         }
3040
3041 #ifdef IO_BUFFER_SIZE
3042       setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
3043                _IOFBF, IO_BUFFER_SIZE);
3044 #endif
3045     }
3046
3047   if (ggc_p)
3048     name = ggc_alloc_string (name, strlen (name));
3049   input_filename = name;
3050
3051   /* Put an entry on the input file stack for the main input file.  */
3052   input_file_stack
3053     = (struct file_stack *) xmalloc (sizeof (struct file_stack));
3054   input_file_stack->next = 0;
3055   input_file_stack->name = input_filename;
3056
3057   /* Perform language-specific initialization.
3058      This may set main_input_filename.  */
3059   lang_init ();
3060
3061   /* If the input doesn't start with a #line, use the input name
3062      as the official input file name.  */
3063   if (main_input_filename == 0)
3064     main_input_filename = name;
3065
3066   if (flag_syntax_only)
3067     {
3068       write_symbols = NO_DEBUG;
3069       profile_flag = 0;
3070       profile_block_flag = 0;
3071     }
3072   else
3073     {
3074       ASM_FILE_START (asm_out_file);
3075
3076 #ifdef ASM_COMMENT_START
3077       if (flag_verbose_asm)
3078         {
3079           /* Print the list of options in effect.  */
3080           print_version (asm_out_file, ASM_COMMENT_START);
3081           print_switch_values (asm_out_file, 0, MAX_LINE,
3082                                ASM_COMMENT_START, " ", "\n");
3083           /* Add a blank line here so it appears in assembler output but not
3084              screen output.  */
3085           fprintf (asm_out_file, "\n");
3086         }
3087 #endif
3088
3089       /* Output something to inform GDB that this compilation was by GCC.  */
3090 #ifndef ASM_IDENTIFY_GCC
3091       fprintf (asm_out_file, "gcc2_compiled.:\n");
3092 #else
3093       ASM_IDENTIFY_GCC (asm_out_file);
3094 #endif
3095
3096   /* Output something to identify which front-end produced this file.  */
3097 #ifdef ASM_IDENTIFY_LANGUAGE
3098       ASM_IDENTIFY_LANGUAGE (asm_out_file);
3099 #endif
3100     } /* ! flag_syntax_only */
3101
3102 #ifndef ASM_OUTPUT_SECTION_NAME
3103   if (flag_function_sections)
3104     {
3105       warning ("-ffunction-sections not supported for this target.");
3106       flag_function_sections = 0;
3107     }
3108   if (flag_data_sections)
3109     {
3110       warning ("-fdata-sections not supported for this target.");
3111       flag_data_sections = 0;
3112     }
3113 #endif
3114
3115   if (flag_function_sections
3116       && (profile_flag || profile_block_flag))
3117     {
3118       warning ("-ffunction-sections disabled; it makes profiling impossible.");
3119       flag_function_sections = 0;
3120     }
3121
3122 #ifndef OBJECT_FORMAT_ELF
3123   if (flag_function_sections && write_symbols != NO_DEBUG)
3124     warning ("-ffunction-sections may affect debugging on some targets.");
3125 #endif
3126
3127   /* ??? Note: There used to be a conditional here
3128       to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
3129       This was to guarantee separation between gcc_compiled. and
3130       the first function, for the sake of dbx on Suns.
3131       However, having the extra zero here confused the Emacs
3132       code for unexec, and might confuse other programs too.
3133       Therefore, I took out that change.
3134       In future versions we should find another way to solve
3135       that dbx problem.  -- rms, 23 May 93.  */
3136       
3137   /* Don't let the first function fall at the same address
3138      as gcc_compiled., if profiling.  */
3139   if (profile_flag || profile_block_flag)
3140     {
3141       /* It's best if we can write a nop here since some
3142          assemblers don't tolerate zeros in the text section.  */
3143       output_asm_insn (get_insn_template (CODE_FOR_nop, NULL), NULL_PTR);
3144     }
3145
3146   /* If dbx symbol table desired, initialize writing it
3147      and output the predefined types.  */
3148 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3149   if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3150     TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
3151                                        getdecls ()));
3152 #endif
3153 #ifdef SDB_DEBUGGING_INFO
3154   if (write_symbols == SDB_DEBUG)
3155     TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
3156                                        getdecls ()));
3157 #endif
3158 #ifdef DWARF_DEBUGGING_INFO
3159   if (write_symbols == DWARF_DEBUG)
3160     TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
3161 #endif
3162 #ifdef DWARF2_UNWIND_INFO
3163   if (dwarf2out_do_frame ())
3164     dwarf2out_frame_init ();
3165 #endif
3166 #ifdef DWARF2_DEBUGGING_INFO
3167   if (write_symbols == DWARF2_DEBUG)
3168     TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
3169 #endif
3170
3171   /* Initialize yet another pass.  */
3172
3173   init_final (main_input_filename);
3174   init_branch_prob (dump_base_name);
3175
3176   start_time = get_run_time ();
3177
3178   /* Call the parser, which parses the entire file
3179      (calling rest_of_compilation for each function).  */
3180
3181   if (yyparse () != 0)
3182     {
3183       if (errorcount == 0)
3184         notice ("Errors detected in input file (your bison.simple is out of date)\n");
3185
3186       /* In case there were missing closebraces,
3187          get us back to the global binding level.  */
3188       while (! global_bindings_p ())
3189         poplevel (0, 0, 0);
3190     }
3191
3192   /* Compilation is now finished except for writing
3193      what's left of the symbol table output.  */
3194
3195   parse_time += get_run_time () - start_time;
3196
3197   parse_time -= integration_time;
3198   parse_time -= varconst_time;
3199
3200   if (flag_syntax_only)
3201     goto finish_syntax;
3202
3203   globals = getdecls ();
3204
3205   /* Really define vars that have had only a tentative definition.
3206      Really output inline functions that must actually be callable
3207      and have not been output so far.  */
3208
3209   {
3210     int len = list_length (globals);
3211     tree *vec = (tree *) alloca (sizeof (tree) * len);
3212     int i;
3213     tree decl;
3214
3215     /* Process the decls in reverse order--earliest first.
3216        Put them into VEC from back to front, then take out from front.  */
3217
3218     for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
3219       vec[len - i - 1] = decl;
3220
3221     wrapup_global_declarations (vec, len);
3222
3223     /* This must occur after the loop to output deferred functions.  Else
3224        the profiler initializer would not be emitted if all the functions
3225        in this compilation unit were deferred.
3226
3227        output_func_start_profiler can not cause any additional functions or
3228        data to need to be output, so it need not be in the deferred function
3229        loop above.  */
3230     output_func_start_profiler ();
3231
3232     /* Now that all possible functions have been output, we can dump
3233        the exception table.  */
3234
3235     output_exception_table ();
3236
3237     check_global_declarations (vec, len);
3238   }
3239
3240   /* Write out any pending weak symbol declarations.  */
3241
3242   weak_finish ();
3243
3244   /* Do dbx symbols */
3245 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3246   if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3247     TIMEVAR (symout_time,
3248              {
3249                dbxout_finish (asm_out_file, main_input_filename);
3250              });
3251 #endif
3252
3253 #ifdef DWARF_DEBUGGING_INFO
3254   if (write_symbols == DWARF_DEBUG)
3255     TIMEVAR (symout_time,
3256              {
3257                dwarfout_finish ();
3258              });
3259 #endif
3260
3261 #ifdef DWARF2_UNWIND_INFO
3262   if (dwarf2out_do_frame ())
3263     dwarf2out_frame_finish ();
3264 #endif
3265
3266 #ifdef DWARF2_DEBUGGING_INFO
3267   if (write_symbols == DWARF2_DEBUG)
3268     TIMEVAR (symout_time,
3269              {
3270                dwarf2out_finish ();
3271              });
3272 #endif
3273
3274   /* Output some stuff at end of file if nec.  */
3275
3276   end_final (dump_base_name);
3277    
3278   if (branch_prob_dump)
3279     open_dump_file (".07.bp", NULL);
3280    
3281   TIMEVAR (dump_time, end_branch_prob (rtl_dump_file));
3282    
3283   if (branch_prob_dump)
3284     close_dump_file (NULL, NULL_RTX);
3285    
3286 #ifdef ASM_FILE_END
3287   ASM_FILE_END (asm_out_file);
3288 #endif
3289
3290
3291   /* Language-specific end of compilation actions.  */
3292  finish_syntax:
3293   lang_finish ();
3294
3295   /* Close the dump files.  */
3296
3297   if (flag_gen_aux_info)
3298     {
3299       fclose (aux_info_file);
3300       if (errorcount)
3301         unlink (aux_info_file_name);
3302     }
3303
3304   if (combine_dump)
3305     {
3306       open_dump_file (".09.combine", NULL);
3307       TIMEVAR (dump_time, dump_combine_total_stats (rtl_dump_file));
3308       close_dump_file (NULL, NULL_RTX);
3309     }
3310
3311   /* Close non-debugging input and output files.  Take special care to note
3312      whether fclose returns an error, since the pages might still be on the
3313      buffer chain while the file is open.  */
3314
3315   finish_parse ();
3316
3317   if (! flag_syntax_only
3318       && (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0))
3319     fatal_io_error (asm_file_name);
3320
3321   /* Do whatever is necessary to finish printing the graphs.  */
3322   if (graph_dump_format != no_graph)
3323     {
3324       if (jump_opt_dump)
3325         finish_graph_dump_file (dump_base_name, ".01.jump");
3326       if (cse_dump)
3327         finish_graph_dump_file (dump_base_name, ".02.cse");
3328       if (addressof_dump)
3329         finish_graph_dump_file (dump_base_name, ".03.addressof");
3330       if (gcse_dump)
3331         finish_graph_dump_file (dump_base_name, ".04.gcse");
3332       if (loop_dump)
3333         finish_graph_dump_file (dump_base_name, ".05.loop");
3334       if (cse2_dump)
3335         finish_graph_dump_file (dump_base_name, ".06.cse2");
3336       if (branch_prob_dump)
3337         finish_graph_dump_file (dump_base_name, ".07.bp");
3338       if (flow_dump)
3339         finish_graph_dump_file (dump_base_name, ".08.flow");
3340       if (combine_dump)
3341         finish_graph_dump_file (dump_base_name, ".09.combine");
3342       if (regmove_dump)
3343         finish_graph_dump_file (dump_base_name, ".10.regmove");
3344 #ifdef INSN_SCHEDULING
3345       if (sched_dump)
3346         finish_graph_dump_file (dump_base_name, ".11.sched");
3347 #endif
3348       if (local_reg_dump)
3349         finish_graph_dump_file (dump_base_name, ".12.lreg");
3350       if (global_reg_dump)
3351         finish_graph_dump_file (dump_base_name, ".13.greg");
3352       if (flow2_dump)
3353         finish_graph_dump_file (dump_base_name, ".14.flow2");
3354 #ifdef HAVE_peephole2
3355       if (flow2_dump)
3356         finish_graph_dump_file (dump_base_name, ".15.peephole2");
3357 #endif
3358 #ifdef INSN_SCHEDULING
3359       if (sched2_dump)
3360         finish_graph_dump_file (dump_base_name, ".16.sched2");
3361 #endif
3362       if (jump2_opt_dump)
3363         finish_graph_dump_file (dump_base_name, ".17.jump2");
3364 #ifdef MACHINE_DEPENDENT_REORG
3365       if (mach_dep_reorg_dump)
3366         finish_graph_dump_file (dump_base_name, ".18.mach");
3367 #endif
3368 #ifdef DELAY_SLOTS
3369       if (dbr_sched_dump)
3370         finish_graph_dump_file (dump_base_name, ".19.dbr");
3371 #endif
3372 #ifdef STACK_REGS
3373       if (stack_reg_dump)
3374         finish_graph_dump_file (dump_base_name, ".20.stack");
3375 #endif
3376     }
3377
3378   /* Free up memory for the benefit of leak detectors.  */
3379   free_reg_info ();
3380
3381   /* Print the times.  */
3382
3383   if (! quiet_flag)
3384     {
3385       all_time = get_run_time ();
3386
3387       fprintf (stderr,"\n");
3388
3389       print_time ("parse", parse_time);
3390       print_time ("integration", integration_time);
3391       print_time ("jump", jump_time);
3392       print_time ("cse", cse_time);
3393       print_time ("gcse", gcse_time);
3394       print_time ("loop", loop_time);
3395       print_time ("cse2", cse2_time);
3396       print_time ("branch-prob", branch_prob_time);
3397       print_time ("flow", flow_time);
3398       print_time ("combine", combine_time);
3399       print_time ("regmove", regmove_time);
3400 #ifdef INSN_SCHEDULING
3401       print_time ("sched", sched_time);
3402 #endif
3403       print_time ("local-alloc", local_alloc_time);
3404       print_time ("global-alloc", global_alloc_time);
3405       print_time ("flow2", flow2_time);
3406 #ifdef HAVE_peephole2
3407       print_time ("peephole2", peephole2_time);
3408 #endif
3409 #ifdef INSN_SCHEDULING
3410       print_time ("sched2", sched2_time);
3411 #endif
3412 #ifdef DELAY_SLOTS
3413       print_time ("dbranch", dbr_sched_time);
3414 #endif
3415       print_time ("shorten-branch", shorten_branch_time);
3416 #ifdef STACK_REGS
3417       print_time ("stack-reg", stack_reg_time);
3418 #endif
3419       print_time ("final", final_time);
3420       print_time ("varconst", varconst_time);
3421       print_time ("symout", symout_time);
3422       print_time ("dump", dump_time);
3423       if (ggc_p)
3424         print_time ("gc", gc_time);
3425     }
3426 }
3427 \f
3428 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
3429    and TYPE_DECL nodes.
3430
3431    This does nothing for local (non-static) variables, unless the
3432    variable is a register variable with an ASMSPEC.  In that case, or
3433    if the variable is not an automatice, it sets up the RTL and
3434    outputs any assembler code (label definition, storage allocation
3435    and initialization).
3436
3437    DECL is the declaration.  If ASMSPEC is nonzero, it specifies
3438    the assembler symbol name to be used.  TOP_LEVEL is nonzero
3439    if this declaration is not within a function.  */
3440
3441 void
3442 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
3443      tree decl;
3444      const char *asmspec;
3445      int top_level;
3446      int at_end;
3447 {
3448   /* Declarations of variables, and of functions defined elsewhere.  */
3449
3450 /* The most obvious approach, to put an #ifndef around where
3451    this macro is used, doesn't work since it's inside a macro call.  */
3452 #ifndef ASM_FINISH_DECLARE_OBJECT
3453 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
3454 #endif
3455
3456   /* Forward declarations for nested functions are not "external",
3457      but we need to treat them as if they were.  */
3458   if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
3459       || TREE_CODE (decl) == FUNCTION_DECL)
3460     TIMEVAR (varconst_time,
3461              {
3462                make_decl_rtl (decl, asmspec, top_level);
3463                /* Initialized extern variable exists to be replaced
3464                   with its value, or represents something that will be
3465                   output in another file.  */
3466                if (! (TREE_CODE (decl) == VAR_DECL
3467                       && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
3468                       && DECL_INITIAL (decl) != 0
3469                       && DECL_INITIAL (decl) != error_mark_node))
3470                  /* Don't output anything
3471                     when a tentative file-scope definition is seen.
3472                     But at end of compilation, do output code for them.  */
3473                  if (! (! at_end && top_level
3474                         && (DECL_INITIAL (decl) == 0
3475                             || DECL_INITIAL (decl) == error_mark_node)))
3476                    assemble_variable (decl, top_level, at_end, 0);
3477                if (decl == last_assemble_variable_decl)
3478                  {
3479                    ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
3480                                               top_level, at_end);
3481                  }
3482              });
3483   else if (DECL_REGISTER (decl) && asmspec != 0)
3484     {
3485       if (decode_reg_name (asmspec) >= 0)
3486         {
3487           DECL_RTL (decl) = 0;
3488           make_decl_rtl (decl, asmspec, top_level);
3489         }
3490       else
3491         error ("invalid register name `%s' for register variable", asmspec);
3492     }
3493 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3494   else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3495            && TREE_CODE (decl) == TYPE_DECL)
3496     TIMEVAR (symout_time, dbxout_symbol (decl, 0));
3497 #endif
3498 #ifdef SDB_DEBUGGING_INFO
3499   else if (write_symbols == SDB_DEBUG && top_level
3500            && TREE_CODE (decl) == TYPE_DECL)
3501     TIMEVAR (symout_time, sdbout_symbol (decl, 0));
3502 #endif
3503 }
3504
3505 /* Called after finishing a record, union or enumeral type.  */
3506
3507 void
3508 rest_of_type_compilation (type, toplev)
3509 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
3510      tree type;
3511      int toplev;
3512 #else
3513      tree type ATTRIBUTE_UNUSED;
3514      int toplev ATTRIBUTE_UNUSED;
3515 #endif
3516 {
3517 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3518   if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3519     TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
3520 #endif
3521 #ifdef SDB_DEBUGGING_INFO
3522   if (write_symbols == SDB_DEBUG)
3523     TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
3524 #endif
3525 }
3526
3527 /* This is called from finish_function (within yyparse)
3528    after each top-level definition is parsed.
3529    It is supposed to compile that function or variable
3530    and output the assembler code for it.
3531    After we return, the tree storage is freed.  */
3532
3533 void
3534 rest_of_compilation (decl)
3535      tree decl;
3536 {
3537   register rtx insns;
3538   int start_time = get_run_time ();
3539   int tem;
3540   /* Nonzero if we have saved the original DECL_INITIAL of the function,
3541      to be restored after we finish compiling the function
3542      (for use when compiling inline calls to this function).  */
3543   tree saved_block_tree = 0;
3544   /* Likewise, for DECL_ARGUMENTS.  */
3545   tree saved_arguments = 0;
3546   int failure = 0;
3547   int rebuild_label_notes_after_reload;
3548
3549   /* If we are reconsidering an inline function
3550      at the end of compilation, skip the stuff for making it inline.  */
3551
3552   if (DECL_SAVED_INSNS (decl) == 0)
3553     {
3554       int inlinable = 0;
3555       const char *lose;
3556
3557       /* If requested, consider whether to make this function inline.  */
3558       if (DECL_INLINE (decl) || flag_inline_functions)
3559         TIMEVAR (integration_time,
3560                  {
3561                    lose = function_cannot_inline_p (decl);
3562                    if (lose || ! optimize)
3563                      {
3564                        if (warn_inline && DECL_INLINE (decl))
3565                          warning_with_decl (decl, lose);
3566                        DECL_ABSTRACT_ORIGIN (decl) = 0;
3567                        /* Don't really compile an extern inline function.
3568                           If we can't make it inline, pretend
3569                           it was only declared.  */
3570                        if (DECL_EXTERNAL (decl))
3571                          {
3572                            DECL_INITIAL (decl) = 0;
3573                            goto exit_rest_of_compilation;
3574                          }
3575                      }
3576                    else
3577                      /* ??? Note that this has the effect of making it look
3578                         like "inline" was specified for a function if we choose
3579                         to inline it.  This isn't quite right, but it's
3580                         probably not worth the trouble to fix.  */
3581                      inlinable = DECL_INLINE (decl) = 1;
3582                  });
3583
3584       insns = get_insns ();
3585
3586       /* Dump the rtl code if we are dumping rtl.  */
3587
3588       if (rtl_dump)
3589         {
3590           open_dump_file (".00.rtl", decl_printable_name (decl, 2));
3591           
3592           if (DECL_SAVED_INSNS (decl))
3593             fprintf (rtl_dump_file, ";; (integrable)\n\n");
3594           
3595           close_dump_file (print_rtl, insns);
3596         }
3597
3598       /* If function is inline, and we don't yet know whether to
3599          compile it by itself, defer decision till end of compilation.
3600          finish_compilation will call rest_of_compilation again
3601          for those functions that need to be output.  Also defer those
3602          functions that we are supposed to defer.  */
3603
3604       if (inlinable)
3605         DECL_DEFER_OUTPUT (decl) = 1;
3606
3607       if (DECL_DEFER_OUTPUT (decl)
3608           || (DECL_INLINE (decl)
3609               && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3610                    && ! flag_keep_inline_functions)
3611                   || DECL_EXTERNAL (decl))))
3612         {
3613           DECL_DEFER_OUTPUT (decl) = 1;
3614
3615           /* If -Wreturn-type, we have to do a bit of compilation.
3616              However, if we just fall through we will call
3617              save_for_inline_copying() which results in excessive
3618              memory use.  Instead, we just want to call
3619              jump_optimize() to figure out whether or not we can fall
3620              off the end of the function; we do the minimum amount of
3621              work necessary to make that safe.  And, we set optimize
3622              to zero to keep jump_optimize from working too hard.  */
3623           if (warn_return_type)
3624             {
3625               int saved_optimize = optimize;
3626               optimize = 0;
3627               find_exception_handler_labels ();
3628               jump_optimize (get_insns(), !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3629                              !JUMP_AFTER_REGSCAN);
3630               optimize = saved_optimize;
3631             }
3632
3633 #ifdef DWARF_DEBUGGING_INFO
3634           /* Generate the DWARF info for the "abstract" instance
3635              of a function which we may later generate inlined and/or
3636              out-of-line instances of.  */
3637           if (write_symbols == DWARF_DEBUG)
3638             {
3639               set_decl_abstract_flags (decl, 1);
3640               TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3641               set_decl_abstract_flags (decl, 0);
3642             }
3643 #endif
3644 #ifdef DWARF2_DEBUGGING_INFO
3645           /* Generate the DWARF2 info for the "abstract" instance
3646              of a function which we may later generate inlined and/or
3647              out-of-line instances of.  */
3648           if (write_symbols == DWARF2_DEBUG)
3649             {
3650               set_decl_abstract_flags (decl, 1);
3651               TIMEVAR (symout_time, dwarf2out_decl (decl));
3652               set_decl_abstract_flags (decl, 0);
3653             }
3654 #endif
3655           TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3656           DECL_SAVED_INSNS (decl)->inlinable = inlinable;
3657           goto exit_rest_of_compilation;
3658         }
3659
3660       /* If specified extern inline but we aren't inlining it, we are
3661          done.  This goes for anything that gets here with DECL_EXTERNAL
3662          set, not just things with DECL_INLINE.  */
3663       if (DECL_EXTERNAL (decl))
3664         goto exit_rest_of_compilation;
3665     }
3666
3667   /* Initialize some variables used by the optimizers.  */
3668   init_function_for_compilation ();
3669
3670   if (! DECL_DEFER_OUTPUT (decl))
3671     TREE_ASM_WRITTEN (decl) = 1;
3672
3673   /* Now that integrate will no longer see our rtl, we need not distinguish
3674      between the return value of this function and the return value of called
3675      functions.  */
3676   rtx_equal_function_value_matters = 0;
3677
3678   /* Don't return yet if -Wreturn-type; we need to do jump_optimize.  */
3679   if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3680     {
3681       goto exit_rest_of_compilation;
3682     }
3683
3684   /* Emit code to get eh context, if needed. */
3685   emit_eh_context ();
3686
3687 #ifdef FINALIZE_PIC
3688   /* If we are doing position-independent code generation, now
3689      is the time to output special prologues and epilogues.
3690      We do not want to do this earlier, because it just clutters
3691      up inline functions with meaningless insns.  */
3692   if (flag_pic)
3693     FINALIZE_PIC;
3694 #endif
3695
3696   /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3697      Note that that may have been done above, in save_for_inline_copying.
3698      The call to resume_temporary_allocation near the end of this function
3699      goes back to the usual state of affairs.  This must be done after
3700      we've built up any unwinders for exception handling, and done
3701      the FINALIZE_PIC work, if necessary.  */
3702
3703   rtl_in_current_obstack ();
3704
3705   insns = get_insns ();
3706
3707   /* Copy any shared structure that should not be shared.  */
3708
3709   unshare_all_rtl (insns);
3710
3711   init_EXPR_INSN_LIST_cache ();
3712
3713 #ifdef SETJMP_VIA_SAVE_AREA
3714   /* This must be performed before virutal register instantiation.  */
3715   if (current_function_calls_alloca)
3716     optimize_save_area_alloca (insns);
3717 #endif
3718
3719   /* Instantiate all virtual registers.  */
3720
3721   instantiate_virtual_regs (current_function_decl, get_insns ());
3722
3723   /* See if we have allocated stack slots that are not directly addressable.
3724      If so, scan all the insns and create explicit address computation
3725      for all references to such slots.  */
3726   /* fixup_stack_slots (); */
3727
3728   /* Find all the EH handlers.  */
3729   find_exception_handler_labels ();
3730
3731   /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3732      are initialized and to compute whether control can drop off the end
3733      of the function.  */
3734   TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3735   TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3736                                      JUMP_AFTER_REGSCAN));
3737
3738   /* Now is when we stop if -fsyntax-only and -Wreturn-type.  */
3739   if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3740     goto exit_rest_of_compilation;
3741
3742   /* Try to identify useless null pointer tests and delete them.  */
3743   if (flag_delete_null_pointer_checks)
3744     TIMEVAR (jump_time, delete_null_pointer_checks (get_insns ()));
3745
3746   /* Dump rtl code after jump, if we are doing that.  */
3747   if (jump_opt_dump)
3748     dump_rtl (".01.jump", decl, print_rtl, insns);
3749
3750   if (ggc_p)
3751     ggc_collect ();
3752
3753   /* Perform common subexpression elimination.
3754      Nonzero value from `cse_main' means that jumps were simplified
3755      and some code may now be unreachable, so do
3756      jump optimization again.  */
3757
3758   if (optimize > 0)
3759     {
3760       if (cse_dump)
3761         open_dump_file (".02.cse", decl_printable_name (decl, 2));
3762
3763       TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3764
3765       if (flag_thread_jumps)
3766         TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3767
3768       TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3769                                          0, rtl_dump_file));
3770       /* If we are not running the second CSE pass, then we are no longer
3771          expecting CSE to be run.  */
3772       cse_not_expected = !flag_rerun_cse_after_loop;
3773
3774       if (tem || optimize > 1)
3775         TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3776                                            !JUMP_NOOP_MOVES,
3777                                            !JUMP_AFTER_REGSCAN));
3778  
3779       /* Run this after jump optmizations remove all the unreachable code
3780          so that unreachable code will not keep values live.  */
3781       TIMEVAR (cse_time, delete_trivially_dead_insns (insns, max_reg_num ()));
3782
3783       /* Try to identify useless null pointer tests and delete them.  */
3784       if (flag_delete_null_pointer_checks)
3785         TIMEVAR (jump_time, delete_null_pointer_checks (get_insns ()));
3786
3787       /* Dump rtl code after cse, if we are doing that.  */
3788
3789       if (cse_dump)
3790         {
3791           close_dump_file (print_rtl, insns);
3792           if (graph_dump_format != no_graph)
3793             print_rtl_graph_with_bb (dump_base_name, ".02.cse", insns);
3794         }
3795     }
3796
3797   purge_addressof (insns);
3798   reg_scan (insns, max_reg_num (), 1);
3799
3800   if (addressof_dump)
3801     {
3802       dump_rtl (".03.addressof", decl, print_rtl, insns);
3803       if (graph_dump_format != no_graph)
3804         print_rtl_graph_with_bb (dump_base_name, ".03.addressof", insns);
3805     }
3806
3807   if (ggc_p)
3808     ggc_collect ();
3809
3810   /* Perform global cse.  */
3811
3812   if (optimize > 0 && flag_gcse)
3813     {
3814       if (gcse_dump)
3815         open_dump_file (".04.gcse", decl_printable_name (decl, 2));
3816
3817       TIMEVAR (gcse_time, tem = gcse_main (insns, rtl_dump_file));
3818
3819       /* If gcse altered any jumps, rerun jump optimizations to clean
3820          things up.  */
3821       if (tem)
3822         {
3823           TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3824                                              !JUMP_NOOP_MOVES,
3825                                              !JUMP_AFTER_REGSCAN));
3826         }
3827
3828       if (gcse_dump)
3829         {
3830           close_dump_file (print_rtl, insns);
3831           if (graph_dump_format != no_graph)
3832             print_rtl_graph_with_bb (dump_base_name, ".04.gcse", insns);
3833         }
3834
3835       if (ggc_p)
3836         ggc_collect ();
3837     }
3838   /* Move constant computations out of loops.  */
3839
3840   if (optimize > 0)
3841     {
3842       if (loop_dump)
3843         open_dump_file (".05.loop", decl_printable_name (decl, 2));
3844         
3845       TIMEVAR
3846         (loop_time,
3847          {
3848            if (flag_rerun_loop_opt)
3849              {
3850                /* We only want to perform unrolling once.  */
3851                
3852                loop_optimize (insns, rtl_dump_file, 0, 0);
3853                
3854         
3855                /* The first call to loop_optimize makes some instructions
3856                   trivially dead.  We delete those instructions now in the
3857                   hope that doing so will make the heuristics in loop work
3858                   better and possibly speed up compilation.  */
3859                delete_trivially_dead_insns (insns, max_reg_num ());
3860
3861                /* The regscan pass is currently necessary as the alias
3862                   analysis code depends on this information.  */
3863                reg_scan (insns, max_reg_num (), 1);
3864              }
3865            loop_optimize (insns, rtl_dump_file, flag_unroll_loops, 1);
3866          });
3867
3868       /* Dump rtl code after loop opt, if we are doing that.  */
3869
3870       if (loop_dump)
3871         {
3872           close_dump_file (print_rtl, insns);
3873           if (graph_dump_format != no_graph)
3874             print_rtl_graph_with_bb (dump_base_name, ".05.loop", insns);
3875         }
3876
3877       if (ggc_p)
3878         ggc_collect ();
3879     }
3880
3881   /* ??? Well, nearly.  If HAVE_conditional_arithmetic, jump_optimize
3882      has put off all if-conversion until "after CSE".  If we put this
3883      off any longer we may miss out doing if-conversion entirely.  */
3884   cse_not_expected = 1;
3885
3886   if (optimize > 0)
3887     {
3888       if (cse2_dump)
3889         open_dump_file (".06.cse2", decl_printable_name (decl, 2));
3890
3891       if (flag_rerun_cse_after_loop)
3892         {
3893           /* Running another jump optimization pass before the second
3894              cse pass sometimes simplifies the RTL enough to allow
3895              the second CSE pass to do a better job.  Jump_optimize can change
3896              max_reg_num so we must rerun reg_scan afterwards.
3897              ??? Rework to not call reg_scan so often.  */
3898           TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3899           TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3900                                              !JUMP_NOOP_MOVES,
3901                                              JUMP_AFTER_REGSCAN));
3902           
3903           TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3904           TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3905                                               1, rtl_dump_file));
3906           if (tem)
3907             TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3908                                                !JUMP_NOOP_MOVES,
3909                                                !JUMP_AFTER_REGSCAN));
3910         }
3911
3912       if (flag_thread_jumps)
3913         {
3914           /* This pass of jump threading straightens out code
3915              that was kinked by loop optimization.  */
3916           TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3917           TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3918         }
3919
3920       /* Dump rtl code after cse, if we are doing that.  */
3921
3922       if (cse2_dump)
3923         {
3924           close_dump_file (print_rtl, insns);
3925           if (graph_dump_format != no_graph)
3926             print_rtl_graph_with_bb (dump_base_name, ".06.cse2", insns);
3927         }
3928
3929       if (ggc_p)
3930         ggc_collect ();
3931     }
3932
3933   if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3934     {
3935       if (branch_prob_dump)
3936         open_dump_file (".07.bp", decl_printable_name (decl, 2));
3937
3938       TIMEVAR
3939         (branch_prob_time,
3940          {
3941            branch_prob (insns, rtl_dump_file);
3942          });
3943
3944       if (branch_prob_dump)
3945         {
3946           close_dump_file (print_rtl, insns);
3947           if (graph_dump_format != no_graph)
3948             print_rtl_graph_with_bb (dump_base_name, ".07.bp", insns);
3949         }
3950
3951       if (ggc_p)
3952         ggc_collect ();
3953     }
3954
3955   /* Now we choose between stupid (pcc-like) register allocation
3956      (if we got the -noreg switch and not -opt)
3957      and smart register allocation.  */
3958
3959   if (optimize > 0)             /* Stupid allocation probably won't work */
3960     obey_regdecls = 0;          /* if optimizations being done.  */
3961
3962   regclass_init ();
3963
3964   /* Print function header into flow dump now
3965      because doing the flow analysis makes some of the dump.  */
3966
3967   if (flow_dump)
3968     open_dump_file (".08.flow", decl_printable_name (decl, 2));
3969   
3970   if (obey_regdecls)
3971     {
3972       TIMEVAR (flow_time,
3973                {
3974                  regclass (insns, max_reg_num ());
3975                  stupid_life_analysis (insns, max_reg_num (),
3976                                        rtl_dump_file);
3977                });
3978     }
3979   else
3980     {
3981       /* Do control and data flow analysis,
3982          and write some of the results to dump file.  */
3983
3984       TIMEVAR
3985         (flow_time,
3986          {
3987            find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
3988            life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
3989          });
3990
3991       if (warn_uninitialized)
3992         {
3993           uninitialized_vars_warning (DECL_INITIAL (decl));
3994           setjmp_args_warning ();
3995         }
3996     }
3997
3998   /* Dump rtl after flow analysis.  */
3999
4000   if (flow_dump)
4001     {
4002       close_dump_file (print_rtl_with_bb, insns);
4003       if (graph_dump_format != no_graph)
4004         print_rtl_graph_with_bb (dump_base_name, ".08.flow", insns);
4005     }
4006
4007   if (ggc_p)
4008     ggc_collect ();
4009
4010   /* The first life analysis pass has finished.  From now on we can not
4011      generate any new pseudos.  */
4012   no_new_pseudos = 1;
4013
4014   /* If -opt, try combining insns through substitution.  */
4015
4016   if (optimize > 0)
4017     {
4018       TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
4019
4020       /* Dump rtl code after insn combination.  */
4021
4022       if (combine_dump)
4023         {
4024           dump_rtl (".09.combine", decl, print_rtl_with_bb, insns);
4025           if (graph_dump_format != no_graph)
4026             print_rtl_graph_with_bb (dump_base_name, ".09.combine", insns);
4027         }
4028
4029       if (ggc_p)
4030         ggc_collect ();
4031     }
4032
4033   /* Register allocation pre-pass, to reduce number of moves
4034      necessary for two-address machines.  */
4035   if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
4036     {
4037       if (regmove_dump)
4038         open_dump_file (".10.regmove", decl_printable_name (decl, 2));
4039
4040       TIMEVAR (regmove_time, regmove_optimize (insns, max_reg_num (),
4041                                                rtl_dump_file));
4042
4043       if (regmove_dump)
4044         {
4045           close_dump_file (print_rtl_with_bb, insns);
4046           if (graph_dump_format != no_graph)
4047             print_rtl_graph_with_bb (dump_base_name, ".10.regmove", insns);
4048         }
4049
4050       if (ggc_p)
4051         ggc_collect ();
4052     }
4053
4054   /* Print function header into sched dump now
4055      because doing the sched analysis makes some of the dump.  */
4056
4057 #ifdef INSN_SCHEDULING
4058   if (optimize > 0 && flag_schedule_insns)
4059     {
4060       if (sched_dump)
4061         open_dump_file (".11.sched", decl_printable_name (decl, 2));
4062
4063       /* Do control and data sched analysis,
4064          and write some of the results to dump file.  */
4065
4066       TIMEVAR (sched_time, schedule_insns (rtl_dump_file));
4067
4068       /* Dump rtl after instruction scheduling.  */
4069
4070       if (sched_dump)
4071         {
4072           close_dump_file (print_rtl_with_bb, insns);
4073           if (graph_dump_format != no_graph)
4074             print_rtl_graph_with_bb (dump_base_name, ".11.sched", insns);
4075         }
4076
4077       if (ggc_p)
4078         ggc_collect ();
4079     }
4080 #endif
4081
4082   /* Determine if the current function is a leaf before running reload
4083      since this can impact optimizations done by the prologue and
4084      epilogue thus changing register elimination offsets.  */
4085   current_function_is_leaf = leaf_function_p ();
4086
4087   /* Unless we did stupid register allocation,
4088      allocate pseudo-regs that are used only within 1 basic block. 
4089
4090      RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
4091      jump optimizer after register allocation and reloading are finished.  */
4092
4093   if (!obey_regdecls)
4094     TIMEVAR (local_alloc_time,
4095              {
4096                recompute_reg_usage (insns, ! optimize_size);
4097                regclass (insns, max_reg_num ());
4098                rebuild_label_notes_after_reload = local_alloc ();
4099              });
4100   else
4101     rebuild_label_notes_after_reload = 0;
4102
4103   /* Dump rtl code after allocating regs within basic blocks.  */
4104
4105   if (local_reg_dump)
4106     {
4107       open_dump_file (".12.lreg", decl_printable_name (decl, 2));
4108
4109       TIMEVAR (dump_time, dump_flow_info (rtl_dump_file));
4110       TIMEVAR (dump_time, dump_local_alloc (rtl_dump_file));
4111
4112       close_dump_file (print_rtl_with_bb, insns);
4113       if (graph_dump_format != no_graph)
4114         print_rtl_graph_with_bb (dump_base_name, ".12.lreg", insns);
4115     }
4116
4117   if (ggc_p)
4118     ggc_collect ();
4119
4120   if (global_reg_dump)
4121     open_dump_file (".13.greg", decl_printable_name (decl, 2));
4122
4123   /* Unless we did stupid register allocation,
4124      allocate remaining pseudo-regs, then do the reload pass
4125      fixing up any insns that are invalid.  */
4126
4127   TIMEVAR (global_alloc_time,
4128            {
4129              if (!obey_regdecls)
4130                failure = global_alloc (rtl_dump_file);
4131              else
4132                failure = reload (insns, 0, rtl_dump_file);
4133            });
4134
4135
4136   if (failure)
4137     goto exit_rest_of_compilation;
4138
4139   if (ggc_p)
4140     ggc_collect ();
4141
4142   /* Do a very simple CSE pass over just the hard registers.  */
4143   if (optimize > 0)
4144     reload_cse_regs (insns);
4145
4146   /* Register allocation and reloading may have turned an indirect jump into
4147      a direct jump.  If so, we must rebuild the JUMP_LABEL fields of
4148      jumping instructions.  */
4149   if (rebuild_label_notes_after_reload)
4150     TIMEVAR (jump_time, rebuild_jump_labels (insns));
4151
4152   /* If optimizing and we are performing instruction scheduling after
4153      reload, then go ahead and split insns now since we are about to
4154      recompute flow information anyway.
4155
4156      reload_cse_regs may expose more splitting opportunities, expecially
4157      for double-word operations.  */
4158   if (optimize > 0 && flag_schedule_insns_after_reload)
4159     {
4160       rtx insn;
4161
4162       for (insn = insns; insn; insn = NEXT_INSN (insn))
4163         {
4164           rtx last;
4165
4166           if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
4167             continue;
4168
4169           last = try_split (PATTERN (insn), insn, 1);
4170
4171           if (last != insn)
4172             {
4173               PUT_CODE (insn, NOTE);
4174               NOTE_SOURCE_FILE (insn) = 0;
4175               NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
4176             }
4177         }
4178     }
4179
4180   if (global_reg_dump)
4181     {
4182       TIMEVAR (dump_time, dump_global_regs (rtl_dump_file));
4183       close_dump_file (print_rtl_with_bb, insns);
4184       if (graph_dump_format != no_graph)
4185         print_rtl_graph_with_bb (dump_base_name, ".13.greg", insns);
4186     }
4187
4188   /* Re-create the death notes which were deleted during reload.  */
4189   if (flow2_dump)
4190     open_dump_file (".14.flow2", decl_printable_name (decl, 2));
4191   
4192   if (optimize)
4193     {
4194       TIMEVAR
4195         (flow2_time,
4196          {
4197            find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
4198            life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
4199          });
4200
4201       if (ggc_p)
4202         ggc_collect ();
4203     }
4204
4205   flow2_completed = 1;
4206
4207   /* On some machines, the prologue and epilogue code, or parts thereof,
4208      can be represented as RTL.  Doing so lets us schedule insns between
4209      it and the rest of the code and also allows delayed branch
4210      scheduling to operate in the epilogue.  */
4211
4212   thread_prologue_and_epilogue_insns (insns);
4213
4214   if (flow2_dump)
4215     {
4216       close_dump_file (print_rtl_with_bb, insns);
4217       if (graph_dump_format != no_graph)
4218         print_rtl_graph_with_bb (dump_base_name, ".14.flow2", insns);
4219     }
4220
4221 #ifdef HAVE_peephole2
4222   if (optimize > 0 && flag_peephole2)
4223     {
4224       if (peephole2_dump)
4225         open_dump_file (".15.peephole2", decl_printable_name (decl, 2));
4226
4227       TIMEVAR (peephole2_time, peephole2_optimize (rtl_dump_file));
4228
4229       if (peephole2_dump)
4230         {
4231           close_dump_file (print_rtl_with_bb, insns);
4232           if (graph_dump_format != no_graph)
4233             print_rtl_graph_with_bb (dump_base_name, ".15.peephole2", insns);
4234         }
4235     }
4236 #endif
4237
4238 #ifdef INSN_SCHEDULING
4239   if (optimize > 0 && flag_schedule_insns_after_reload)
4240     {
4241       if (sched2_dump)
4242         open_dump_file (".16.sched2", decl_printable_name (decl, 2));
4243
4244       /* Do control and data sched analysis again,
4245          and write some more of the results to dump file.  */
4246
4247       TIMEVAR (sched2_time, schedule_insns (rtl_dump_file));
4248
4249       /* Dump rtl after post-reorder instruction scheduling.  */
4250
4251       if (sched2_dump)
4252         {
4253           close_dump_file (print_rtl_with_bb, insns);
4254           if (graph_dump_format != no_graph)
4255             print_rtl_graph_with_bb (dump_base_name, ".16.sched2", insns);
4256         }
4257
4258       if (ggc_p)
4259         ggc_collect ();
4260     }
4261 #endif
4262
4263 #ifdef LEAF_REGISTERS
4264   current_function_uses_only_leaf_regs
4265     = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
4266 #endif
4267
4268   /* One more attempt to remove jumps to .+1
4269      left by dead-store-elimination.
4270      Also do cross-jumping this time
4271      and delete no-op move insns.  */
4272
4273   if (optimize > 0)
4274     {
4275       TIMEVAR (jump_time, jump_optimize (insns, JUMP_CROSS_JUMP,
4276                                          JUMP_NOOP_MOVES,
4277                                          !JUMP_AFTER_REGSCAN));
4278
4279       /* Dump rtl code after jump, if we are doing that.  */
4280
4281       if (jump2_opt_dump)
4282         {
4283           dump_rtl (".17.jump2", decl, print_rtl_with_bb, insns);
4284           if (graph_dump_format != no_graph)
4285             print_rtl_graph_with_bb (dump_base_name, ".17.jump2", insns);
4286         }
4287     }
4288
4289   /* If a machine dependent reorganization is needed, call it.  */
4290 #ifdef MACHINE_DEPENDENT_REORG
4291   if (mach_dep_reorg_dump)
4292     open_dump_file (".18.mach", decl_printable_name (decl, 2));
4293
4294    MACHINE_DEPENDENT_REORG (insns);
4295
4296    if (mach_dep_reorg_dump)
4297      {
4298        close_dump_file (print_rtl_with_bb, insns);
4299        if (graph_dump_format != no_graph)
4300          print_rtl_graph_with_bb (dump_base_name, ".18.mach", insns);
4301      }
4302
4303    if (ggc_p)
4304      ggc_collect ();
4305 #endif
4306
4307   /* If a scheduling pass for delayed branches is to be done,
4308      call the scheduling code.  */
4309
4310 #ifdef DELAY_SLOTS
4311   if (optimize > 0 && flag_delayed_branch)
4312     {
4313       if (dbr_sched_dump)
4314         open_dump_file (".19.dbr", decl_printable_name (decl, 2));
4315
4316       TIMEVAR (dbr_sched_time, dbr_schedule (insns, rtl_dump_file));
4317
4318       if (dbr_sched_dump)
4319         {
4320           close_dump_file (print_rtl_with_bb, insns);
4321           if (graph_dump_format != no_graph)
4322             print_rtl_graph_with_bb (dump_base_name, ".19.dbr", insns);
4323         }
4324     }
4325
4326    if (ggc_p)
4327      ggc_collect ();
4328 #endif
4329
4330   /* Shorten branches.  */
4331   TIMEVAR (shorten_branch_time,
4332            {
4333              shorten_branches (get_insns ());
4334            });
4335
4336 #ifdef STACK_REGS
4337   if (stack_reg_dump)
4338     open_dump_file (".20.stack", decl_printable_name (decl, 2));
4339
4340   TIMEVAR (stack_reg_time, reg_to_stack (insns, rtl_dump_file));
4341
4342   if (stack_reg_dump)
4343     {
4344       close_dump_file (print_rtl_with_bb, insns);
4345       if (graph_dump_format != no_graph)
4346         print_rtl_graph_with_bb (dump_base_name, ".20.stack", insns);
4347     }
4348
4349    if (ggc_p)
4350      ggc_collect ();
4351 #endif
4352
4353   /* Now turn the rtl into assembler code.  */
4354
4355   TIMEVAR (final_time,
4356            {
4357              rtx x;
4358              char *fnname;
4359
4360              /* Get the function's name, as described by its RTL.
4361                 This may be different from the DECL_NAME name used
4362                 in the source file.  */
4363
4364              x = DECL_RTL (decl);
4365              if (GET_CODE (x) != MEM)
4366                abort ();
4367              x = XEXP (x, 0);
4368              if (GET_CODE (x) != SYMBOL_REF)
4369                abort ();
4370              fnname = XSTR (x, 0);
4371
4372              assemble_start_function (decl, fnname);
4373              final_start_function (insns, asm_out_file, optimize);
4374              final (insns, asm_out_file, optimize, 0);
4375              final_end_function (insns, asm_out_file, optimize);
4376              assemble_end_function (decl, fnname);
4377              if (! quiet_flag)
4378                fflush (asm_out_file);
4379
4380              /* Release all memory allocated by flow.  */
4381              free_basic_block_vars (0);
4382
4383              /* Release all memory held by regsets now */
4384              regset_release_memory ();
4385            });
4386
4387    if (ggc_p)
4388      ggc_collect ();
4389
4390   /* Write DBX symbols if requested */
4391
4392   /* Note that for those inline functions where we don't initially
4393      know for certain that we will be generating an out-of-line copy,
4394      the first invocation of this routine (rest_of_compilation) will
4395      skip over this code by doing a `goto exit_rest_of_compilation;'.
4396      Later on, finish_compilation will call rest_of_compilation again
4397      for those inline functions that need to have out-of-line copies
4398      generated.  During that call, we *will* be routed past here.  */
4399
4400 #ifdef DBX_DEBUGGING_INFO
4401   if (write_symbols == DBX_DEBUG)
4402     TIMEVAR (symout_time, dbxout_function (decl));
4403 #endif
4404
4405 #ifdef DWARF_DEBUGGING_INFO
4406   if (write_symbols == DWARF_DEBUG)
4407     TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
4408 #endif
4409
4410 #ifdef DWARF2_DEBUGGING_INFO
4411   if (write_symbols == DWARF2_DEBUG)
4412     TIMEVAR (symout_time, dwarf2out_decl (decl));
4413 #endif
4414
4415  exit_rest_of_compilation:
4416
4417   free_bb_mem ();
4418
4419   /* In case the function was not output,
4420      don't leave any temporary anonymous types
4421      queued up for sdb output.  */
4422 #ifdef SDB_DEBUGGING_INFO
4423   if (write_symbols == SDB_DEBUG)
4424     sdbout_types (NULL_TREE);
4425 #endif
4426
4427   /* Put back the tree of subblocks and list of arguments
4428      from before we copied them.
4429      Code generation and the output of debugging info may have modified
4430      the copy, but the original is unchanged.  */
4431
4432   if (saved_block_tree != 0)
4433     {
4434       DECL_INITIAL (decl) = saved_block_tree;
4435       DECL_ARGUMENTS (decl) = saved_arguments;
4436       DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
4437     }
4438
4439   reload_completed = 0;
4440   flow2_completed = 0;
4441   no_new_pseudos = 0;
4442
4443   TIMEVAR (final_time,
4444            {
4445               /* Clear out the insn_length contents now that they are no
4446                  longer valid.  */
4447               init_insn_lengths ();
4448
4449               /* Clear out the real_constant_chain before some of the rtx's
4450                  it runs through become garbage.  */
4451               clear_const_double_mem ();
4452
4453               /* Cancel the effect of rtl_in_current_obstack.  */
4454               resume_temporary_allocation ();
4455
4456               /* Show no temporary slots allocated.  */
4457               init_temp_slots ();
4458
4459               free_basic_block_vars (0);
4460            });
4461
4462   /* Make sure volatile mem refs aren't considered valid operands for
4463      arithmetic insns.  We must call this here if this is a nested inline
4464      function, since the above code leaves us in the init_recog state
4465      (from final.c), and the function context push/pop code does not
4466      save/restore volatile_ok.
4467
4468      ??? Maybe it isn't necessary for expand_start_function to call this
4469      anymore if we do it here?  */
4470
4471   init_recog_no_volatile ();
4472
4473   /* We're done with this function.  Free up memory if we can.  */
4474   free_after_parsing (current_function);
4475   if (! DECL_DEFER_OUTPUT (decl))
4476     free_after_compilation (current_function);
4477   current_function = 0;
4478
4479   if (ggc_p)
4480     ggc_collect ();
4481
4482   /* The parsing time is all the time spent in yyparse
4483      *except* what is spent in this function.  */
4484
4485   parse_time -= get_run_time () - start_time;
4486 }
4487 \f
4488 static void
4489 display_help ()
4490 {
4491   int    undoc;
4492   unsigned long  i;
4493   const char * lang;
4494   
4495 #ifndef USE_CPPLIB  
4496   printf ("Usage: %s input [switches]\n", progname);
4497   printf ("Switches:\n");
4498 #endif
4499   printf ("  -ffixed-<register>      Mark <register> as being unavailable to the compiler\n");
4500   printf ("  -fcall-used-<register>  Mark <register> as being corrupted by function calls\n");
4501   printf ("  -fcall-saved-<register> Mark <register> as being preserved across functions\n");
4502   printf ("  -finline-limit=<number> Limits the size of inlined functions to <number>\n");
4503
4504   for (i = NUM_ELEM (f_options); i--;)
4505     {
4506       const char * description = f_options[i].description;
4507       
4508       if (description != NULL && * description != 0)
4509         printf ("  -f%-21s %s\n",
4510                 f_options[i].string, description);
4511     }
4512   
4513   printf ("  -O[number]              Set optimisation level to [number]\n");
4514   printf ("  -Os                     Optimise for space rather than speed\n");
4515   printf ("  -pedantic               Issue warnings needed by strict compliance to ANSI C\n");
4516   printf ("  -pedantic-errors        Like -pedantic except that errors are produced\n");
4517   printf ("  -w                      Suppress warnings\n");
4518   printf ("  -W                      Enable extra warnings\n");
4519   
4520   for (i = NUM_ELEM (W_options); i--;)
4521     {
4522       const char * description = W_options[i].description;
4523       
4524       if (description != NULL && * description != 0)
4525         printf ("  -W%-21s %s\n",
4526                 W_options[i].string, description);
4527     }
4528   
4529   printf ("  -Wid-clash-<num>        Warn if 2 identifiers have the same first <num> chars\n");
4530   printf ("  -Wlarger-than-<number>  Warn if an object is larger than <number> bytes\n");
4531   printf ("  -p                      Enable function profiling\n");
4532 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER)
4533   printf ("  -a                      Enable block profiling \n");
4534 #endif  
4535 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER) || defined FUNCTION_BLOCK_PROFILER_EXIT
4536   printf ("  -ax                     Enable jump profiling \n");
4537 #endif  
4538   printf ("  -o <file>               Place output into <file> \n");
4539   printf ("  -G <number>             Put global and static data smaller than <number>\n");
4540   printf ("                           bytes into a special section (on some targets)\n");
4541   
4542   for (i = NUM_ELEM (debug_args); i--;)
4543     {
4544       if (debug_args[i].description != NULL)
4545         printf ("  -g%-21s %s\n", debug_args[i].arg, debug_args[i].description);
4546     }
4547   
4548   printf ("  -aux-info <file>        Emit declaration info into <file>.X\n");
4549   printf ("  -quiet                  Do not display functions compiled or elapsed time\n");
4550   printf ("  -version                Display the compiler's version\n");
4551   printf ("  -d[letters]             Enable dumps from specific passes of the compiler\n");
4552   printf ("  -dumpbase <file>        Base name to be used for dumps from specific passes\n");
4553 #if defined INSN_SCHEDULING
4554   printf ("  -sched-verbose=<number> Set the verbosity level of the scheduler\n");
4555 #endif
4556   printf ("  --help                  Display this information\n");
4557
4558   undoc = 0;
4559   lang  = "language";
4560   
4561   /* Display descriptions of language specific options.
4562      If there is no description, note that there is an undocumented option.
4563      If the description is empty, do not display anything.  (This allows
4564      options to be deliberately undocumented, for whatever reason).
4565      If the option string is missing, then this is a marker, indicating
4566      that the description string is in fact the name of a language, whose
4567      language specific options are to follow.  */
4568   
4569   if (NUM_ELEM (documented_lang_options) > 1)
4570     {
4571       printf ("\nLanguage specific options:\n");
4572
4573       for (i = 0; i < NUM_ELEM (documented_lang_options); i++)
4574         {
4575           const char * description = documented_lang_options[i].description;
4576           const char * option      = documented_lang_options[i].option;
4577
4578           if (description == NULL)
4579             {
4580               undoc = 1;
4581
4582               if (extra_warnings)
4583                 printf ("  %-23.23s [undocumented]\n", option);
4584             }
4585           else if (* description == 0)
4586             continue;
4587           else if (option == NULL)
4588             {
4589               if (undoc)
4590                 printf
4591                   ("\nThere are undocumented %s specific options as well.\n",
4592                         lang);
4593               undoc = 0;
4594               
4595               printf ("\n Options for %s:\n", description);
4596
4597               lang = description;
4598             }
4599           else
4600             printf ("  %-23.23s %s\n", option, description);
4601         }
4602     }
4603
4604   if (undoc)
4605     printf ("\nThere are undocumented %s specific options as well.\n", lang);
4606
4607   if (NUM_ELEM (target_switches) > 1
4608 #ifdef TARGET_OPTIONS
4609       || NUM_ELEM (target_options) > 1
4610 #endif
4611       )
4612     {
4613       int doc = 0;
4614       
4615       undoc = 0;
4616   
4617       printf ("\nTarget specific options:\n");
4618
4619       for (i = NUM_ELEM (target_switches); i--;)
4620         {
4621           const char * option      = target_switches[i].name;
4622           const char * description = target_switches[i].description;
4623
4624           if (option == NULL || * option == 0)
4625             continue;
4626           else if (description == NULL)
4627             {
4628               undoc = 1;
4629               
4630               if (extra_warnings)
4631                 printf ("  -m%-21.21s [undocumented]\n", option);
4632             }
4633           else if (* description != 0)
4634             doc += printf ("  -m%-21.21s %s\n", option, description);
4635         }
4636       
4637 #ifdef TARGET_OPTIONS      
4638       for (i = NUM_ELEM (target_options); i--;)
4639         {
4640           const char * option      = target_options[i].prefix;
4641           const char * description = target_options[i].description;
4642
4643           if (option == NULL || * option == 0)
4644             continue;
4645           else if (description == NULL)
4646             {
4647               undoc = 1;
4648               
4649               if (extra_warnings)
4650                 printf ("  -m%-21.21s [undocumented]\n", option);
4651             }
4652           else if (* description != 0)
4653             doc += printf ("  -m%-21.21s %s\n", option, description);
4654         }
4655 #endif
4656       if (undoc)
4657         {
4658           if (doc)
4659             printf ("\nThere are undocumented target specific options as well.\n");
4660           else
4661             printf ("  They exist, but they are not documented.\n");
4662         }
4663     }
4664 }
4665 \f
4666 /* Parse a -d... comand line switch.  */
4667
4668 static void
4669 decode_d_option (arg)
4670      const char * arg;
4671 {
4672   while (* arg)
4673     switch (* arg ++)
4674       {
4675       case 'a':
4676         branch_prob_dump = 1;
4677         combine_dump = 1;
4678 #ifdef DELAY_SLOTS
4679         dbr_sched_dump = 1;
4680 #endif
4681         flow_dump = 1;
4682         flow2_dump = 1;
4683         global_reg_dump = 1;
4684         jump_opt_dump = 1;
4685         addressof_dump = 1;
4686         jump2_opt_dump = 1;
4687         local_reg_dump = 1;
4688         loop_dump = 1;
4689         regmove_dump = 1;
4690         rtl_dump = 1;
4691         cse_dump = 1;
4692         cse2_dump = 1;
4693         gcse_dump = 1;
4694         sched_dump = 1;
4695         sched2_dump = 1;
4696 #ifdef STACK_REGS
4697         stack_reg_dump = 1;
4698 #endif
4699 #ifdef MACHINE_DEPENDENT_REORG
4700         mach_dep_reorg_dump = 1;
4701 #endif
4702         peephole2_dump = 1;
4703         break;
4704       case 'A':
4705         flag_debug_asm = 1;
4706         break;
4707       case 'b':
4708         branch_prob_dump = 1;
4709         break;
4710       case 'c':
4711         combine_dump = 1;
4712         break;
4713 #ifdef DELAY_SLOTS
4714       case 'd':
4715         dbr_sched_dump = 1;
4716         break;
4717 #endif
4718       case 'f':
4719         flow_dump = 1;
4720         break;
4721       case 'F':
4722         addressof_dump = 1;
4723         break;
4724       case 'g':
4725         global_reg_dump = 1;
4726         break;
4727       case 'G':
4728         gcse_dump = 1;
4729         break;
4730       case 'j':
4731         jump_opt_dump = 1;
4732         break;
4733       case 'J':
4734         jump2_opt_dump = 1;
4735         break;
4736 #ifdef STACK_REGS                   
4737       case 'k':
4738         stack_reg_dump = 1;
4739         break;
4740 #endif
4741       case 'l':
4742         local_reg_dump = 1;
4743         break;
4744       case 'L':
4745         loop_dump = 1;
4746         break;
4747       case 'm':
4748         flag_print_mem = 1;
4749         break;
4750 #ifdef MACHINE_DEPENDENT_REORG
4751       case 'M':
4752         mach_dep_reorg_dump = 1;
4753         break;
4754 #endif
4755       case 'p':
4756         flag_print_asm_name = 1;
4757         break;
4758       case 'r':
4759         rtl_dump = 1;
4760         break;
4761       case 'R':
4762         sched2_dump = 1;
4763         break;
4764       case 's':
4765         cse_dump = 1;
4766         break;
4767       case 'S':
4768         sched_dump = 1;
4769         break;
4770       case 't':
4771         cse2_dump = 1;
4772         break;
4773       case 'N':
4774         regmove_dump = 1;
4775         break;
4776       case 'v':
4777         graph_dump_format = vcg;
4778         break;
4779       case 'w':
4780         flow2_dump = 1;
4781         break;
4782       case 'x':
4783         rtl_dump_and_exit = 1;
4784         break;
4785       case 'y':
4786         set_yydebug (1);
4787         break;
4788       case 'z':
4789         peephole2_dump = 1;
4790         break;
4791       case 'D': /* These are handled by the preprocessor.  */
4792       case 'I':
4793         break;
4794       default:
4795         warning ("unrecognised gcc debugging option: %c", arg[-1]);
4796         break;
4797       }
4798 }
4799
4800 /* Parse a -f... comand line switch.  ARG is the value after the -f.
4801    It is safe to access 'ARG - 2' to generate the full switch name.
4802    Return the number of strings consumed.  */
4803
4804 static int
4805 decode_f_option (arg)
4806      const char * arg;
4807 {
4808   int j;
4809
4810   /* Search for the option in the table of binary f options.  */
4811   for (j = sizeof (f_options) / sizeof (f_options[0]); j--;)
4812     {
4813       if (!strcmp (arg, f_options[j].string))
4814         {
4815           *f_options[j].variable = f_options[j].on_value;
4816           return 1;
4817         }
4818     
4819       if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4820           && ! strcmp (arg + 3, f_options[j].string))
4821         {
4822           *f_options[j].variable = ! f_options[j].on_value;
4823           return 1;
4824         }
4825     }
4826
4827   if (!strncmp (arg, "inline-limit-", 13)
4828       || !strncmp (arg, "inline-limit=", 13))
4829     inline_max_insns =
4830       read_integral_parameter (arg + 13, arg - 2, inline_max_insns);
4831 #ifdef INSN_SCHEDULING
4832   else if (!strncmp (arg, "sched-verbose=", 14))
4833     fix_sched_param ("verbose", (char *)(arg + 14));
4834 #endif
4835   else if (!strncmp (arg, "fixed-", 6))
4836     fix_register ((char *)(arg + 6), 1, 1);
4837   else if (!strncmp (arg, "call-used-", 10))
4838     fix_register ((char *)(arg + 10), 0, 1);
4839   else if (!strncmp (arg, "call-saved-", 11))
4840     fix_register ((char *)(arg + 11), 0, 0);
4841   else if (!strncmp (arg, "align-loops=", 12))
4842     align_loops = read_integral_parameter (arg + 12, arg - 2, align_loops);
4843   else if (!strncmp (arg, "align-functions=", 16))
4844     align_functions =
4845       read_integral_parameter (arg + 16, arg - 2, align_functions);
4846   else if (!strncmp (arg, "align-jumps=", 12))
4847     align_jumps = read_integral_parameter (arg + 12, arg - 2, align_jumps);
4848   else if (!strncmp (arg, "align-labels=", 13))
4849     align_labels = read_integral_parameter (arg + 13, arg - 2, align_labels);
4850   else if (!strcmp (arg, "preprocessed"))
4851     /* Recognise this switch but do nothing.  This prevents warnings
4852        about an unrecognised switch if cpplib has not been linked in.  */
4853     ;
4854   else
4855     return 0;
4856
4857   return 1;
4858 }
4859
4860 /* Parse a -W... comand line switch.  ARG is the value after the -W.
4861    It is safe to access 'ARG - 2' to generate the full switch name.
4862    Return the number of strings consumed.  */
4863 static int
4864 decode_W_option (arg)
4865      const char * arg;
4866 {
4867   int j;
4868   
4869   /* Search for the option in the table of binary W options.  */
4870
4871   for (j = sizeof (W_options) / sizeof (W_options[0]); j--;)
4872     {
4873       if (!strcmp (arg, W_options[j].string))
4874         {
4875           *W_options[j].variable = W_options[j].on_value;
4876           return 1;
4877         }
4878
4879       if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4880           && ! strcmp (arg + 3, W_options[j].string))
4881         {
4882           *W_options[j].variable = ! W_options[j].on_value;
4883           return 1;
4884         }
4885     }
4886
4887   if (!strncmp (arg, "id-clash-", 9))
4888     {
4889       const int id_clash_val = read_integral_parameter (arg + 9, arg - 2, -1);
4890       
4891       if (id_clash_val != -1)
4892         {
4893           id_clash_len = id_clash_val;
4894           warn_id_clash = 1;
4895         }
4896     }
4897   else if (!strncmp (arg, "larger-than-", 12))
4898     {
4899       const int larger_than_val =
4900         read_integral_parameter (arg + 12, arg - 2, -1);
4901       if (larger_than_val != -1)
4902         {
4903           larger_than_size = larger_than_val;
4904           warn_larger_than = 1;
4905         }
4906     }
4907   else
4908     return 0;
4909
4910   return 1;
4911 }
4912
4913 /* Parse a -g... comand line switch.  ARG is the value after the -g.
4914    It is safe to access 'ARG - 2' to generate the full switch name.
4915    Return the number of strings consumed.  */
4916 static int
4917 decode_g_option (arg)
4918      const char * arg;
4919 {
4920   unsigned level;
4921   /* A lot of code assumes write_symbols == NO_DEBUG if the
4922      debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4923      of what debugging type has been selected).  This records the
4924      selected type.  It is an error to specify more than one
4925      debugging type.  */
4926   static enum debug_info_type selected_debug_type = NO_DEBUG;
4927   /* Non-zero if debugging format has been explicitly set.
4928      -g and -ggdb don't explicitly set the debugging format so
4929      -gdwarf -g3 is equivalent to -gdwarf3.  */
4930   static int type_explicitly_set_p = 0;
4931   /* Indexed by enum debug_info_type.  */
4932   static const char * debug_type_names[] =
4933   {
4934     "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
4935   };
4936   
4937   /* The maximum admissible debug level value.  */
4938   static const unsigned max_debug_level = 3;
4939   
4940   /* Look up ARG in the table.  */
4941   for (da = debug_args; da->arg; da++)
4942     {
4943       const int da_len = strlen (da->arg);
4944
4945       if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4946         {
4947           enum debug_info_type type = da->debug_type;
4948           const char * p = arg + da_len;
4949           
4950           if (*p && (*p < '0' || *p > '9'))
4951             continue;
4952           
4953           /* A debug flag without a level defaults to level 2.
4954              Note we do not want to call read_integral_parameter
4955              for that case since it will call atoi which 
4956              will return zero.
4957              
4958              ??? We may want to generalize the interface to 
4959              read_integral_parameter to better handle this case
4960              if this case shows up often.  */
4961           if (*p)
4962             level = read_integral_parameter (p, 0, max_debug_level + 1);
4963           else
4964             level = 2;
4965           
4966           if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4967             {
4968               error ("use -gdwarf -g%d for DWARF v1, level %d",
4969                      level, level);
4970               if (level == 2)
4971                 error ("use -gdwarf-2   for DWARF v2");
4972             }
4973           
4974           if (level > max_debug_level)
4975             {
4976               warning ("\
4977 ignoring option `%s' due to invalid debug level specification",
4978                        arg - 2);
4979               level = debug_info_level;
4980             }
4981
4982           if (type == NO_DEBUG)
4983             {
4984               type = PREFERRED_DEBUGGING_TYPE;
4985               
4986               if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4987                 {
4988 #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
4989                   type = DWARF2_DEBUG;
4990 #else
4991 #ifdef DBX_DEBUGGING_INFO
4992                   type = DBX_DEBUG;
4993 #endif
4994 #endif
4995                 }
4996             }
4997           
4998           if (type == NO_DEBUG)
4999             warning ("`%s' not supported by this configuration of GCC",
5000                      arg - 2);
5001
5002           /* Does it conflict with an already selected type?  */
5003           if (type_explicitly_set_p
5004               /* -g/-ggdb don't conflict with anything */
5005               && da->debug_type != NO_DEBUG
5006               && type != selected_debug_type)
5007             warning ("`%s' ignored, conflicts with `-g%s'",
5008                      arg - 2, debug_type_names[(int) selected_debug_type]);
5009           else
5010             {
5011               /* If the format has already been set, -g/-ggdb
5012                  only change the debug level.  */
5013               if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
5014                 ; /* don't change debugging type */
5015               else
5016                 {
5017                   selected_debug_type = type;
5018                   type_explicitly_set_p = da->debug_type != NO_DEBUG;
5019                 }
5020               
5021               write_symbols = (level == 0
5022                                ? NO_DEBUG
5023                                : selected_debug_type);
5024               use_gnu_debug_info_extensions = da->use_extensions_p;
5025               debug_info_level = (enum debug_info_level) level;
5026             }
5027           
5028           break;
5029         }
5030     }
5031   
5032   if (! da->arg)
5033     warning ("`%s' not supported by this configuration of GCC", arg - 2);
5034
5035   return 1;
5036 }
5037
5038 /* Decode the first argument in the argv as a language-independent option.
5039    Return the number of strings consumed.  'strings_processed' is the
5040    number of strings that have already been decoded in a language
5041    specific fashion before this function was invoked.  */
5042    
5043 static unsigned
5044 independent_decode_option (argc, argv, strings_processed)
5045      int argc;
5046      char ** argv;
5047      unsigned strings_processed ATTRIBUTE_UNUSED;
5048 {
5049   char * arg = argv[0];
5050   
5051   if (arg[0] != '-' || arg[1] == 0)
5052     {
5053       if (arg[0] == '+')
5054         return 0;
5055       
5056       filename = arg;
5057
5058       return 1;
5059     }
5060
5061   arg ++;
5062   
5063   if (!strcmp (arg, "-help"))
5064     {
5065       display_help ();
5066       exit (0);
5067     }
5068
5069   if (* arg == 'Y')
5070     arg ++;
5071   
5072   switch (* arg)
5073     {
5074     default:
5075       return 0;
5076       
5077     case 'O':
5078       /* Already been treated in main (). Do nothing.  */
5079       break;
5080           
5081     case 'm':
5082       set_target_switch (arg + 1);
5083       break;
5084
5085     case 'f':
5086       return decode_f_option (arg + 1);
5087             
5088     case 'g':
5089       return decode_g_option (arg + 1);
5090
5091     case 'd':
5092       if (!strcmp (arg, "dumpbase"))
5093         {
5094           if (argc == 1)
5095             return 0;
5096           
5097           dump_base_name = argv[1];
5098           return 2;
5099         }
5100       else
5101         decode_d_option (arg + 1);
5102       break;
5103
5104     case 'p':
5105       if (!strcmp (arg, "pedantic"))
5106         pedantic = 1;
5107       else if (!strcmp (arg, "pedantic-errors"))
5108         flag_pedantic_errors = pedantic = 1;
5109       else if (arg[1] == 0)
5110         profile_flag = 1;
5111       else
5112         return 0;
5113       break;
5114
5115     case 'q':
5116       if (!strcmp (arg, "quiet"))
5117         quiet_flag = 1;
5118       else
5119         return 0;
5120       break;
5121
5122     case 'v':
5123       if (!strcmp (arg, "version"))
5124         version_flag = 1;
5125       else
5126         return 0;
5127       break;
5128
5129     case 'w':
5130       if (arg[1] == 0)
5131         inhibit_warnings = 1;
5132       else
5133         return 0;
5134       break;
5135
5136     case 'W':
5137       if (arg[1] == 0)
5138         {
5139           extra_warnings = 1;
5140           /* We save the value of warn_uninitialized, since if they put
5141              -Wuninitialized on the command line, we need to generate a
5142              warning about not using it without also specifying -O.  */
5143           if (warn_uninitialized != 1)
5144             warn_uninitialized = 2;
5145         }
5146       else
5147         return decode_W_option (arg + 1);
5148       break;
5149           
5150     case 'a':
5151       if (arg[1] == 0)
5152         {
5153 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5154           warning ("`-a' option (basic block profile) not supported");
5155 #else
5156           profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
5157 #endif
5158         }
5159       else if (!strcmp (arg, "ax"))
5160         {
5161 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5162           warning ("`-ax' option (jump profiling) not supported");
5163 #else
5164           profile_block_flag = (!profile_block_flag 
5165                                 || profile_block_flag == 2) ? 2 : 3;
5166 #endif
5167         }
5168       else if (!strncmp (arg, "aux-info", 8))
5169         {
5170           flag_gen_aux_info = 1;
5171           if (arg[8] == '\0')
5172             {
5173               if (argc == 1)
5174                 return 0;
5175               
5176               aux_info_file_name = argv[1];
5177               return 2;
5178             }
5179           else
5180             aux_info_file_name = arg + 8;
5181         }
5182       else
5183         return 0;
5184       break;
5185
5186     case 'o':
5187       if (arg[1] == 0)
5188         {
5189           if (argc == 1)
5190             return 0;
5191           
5192           asm_file_name = argv[1];
5193           return 2;
5194         }
5195       return 0;
5196
5197     case 'G':
5198       {
5199         int g_switch_val;
5200         int return_val;
5201             
5202         if (arg[1] == 0)
5203           {
5204             if (argc == 1)
5205               return 0;
5206             
5207             g_switch_val = read_integral_parameter (argv[1], 0, -1);
5208             return_val = 2;
5209           }
5210         else
5211           {
5212             g_switch_val = read_integral_parameter (arg + 1, 0, -1);
5213             return_val = 1;
5214           }
5215             
5216         if (g_switch_val == -1)
5217           return_val = 0;
5218         else
5219           {
5220             g_switch_set = TRUE;
5221             g_switch_value = g_switch_val;
5222           }
5223             
5224         return return_val;
5225       }
5226     }
5227   
5228   return 1;
5229 }
5230 \f
5231 /* Entry point of cc1/c++.  Decode command args, then call compile_file.
5232    Exit code is 35 if can't open files, 34 if fatal error,
5233    33 if had nonfatal errors, else success.  */
5234
5235 extern int main PROTO ((int, char **));
5236
5237 int
5238 main (argc, argv)
5239      int argc;
5240      char **argv;
5241 {
5242   register int i;
5243   char *p;
5244
5245   /* save in case md file wants to emit args as a comment.  */
5246   save_argc = argc;
5247   save_argv = argv;
5248
5249   p = argv[0] + strlen (argv[0]);
5250   while (p != argv[0] && p[-1] != '/'
5251 #ifdef DIR_SEPARATOR
5252          && p[-1] != DIR_SEPARATOR
5253 #endif
5254          )
5255     --p;
5256   progname = p;
5257
5258 #if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
5259   /* Get rid of any avoidable limit on stack size.  */
5260   {
5261     struct rlimit rlim;
5262
5263     /* Set the stack limit huge so that alloca does not fail.  */
5264     getrlimit (RLIMIT_STACK, &rlim);
5265     rlim.rlim_cur = rlim.rlim_max;
5266     setrlimit (RLIMIT_STACK, &rlim);
5267   }
5268 #endif
5269
5270 #ifdef HAVE_LC_MESSAGES
5271   setlocale (LC_MESSAGES, "");
5272 #endif
5273   (void) bindtextdomain (PACKAGE, localedir);
5274   (void) textdomain (PACKAGE);
5275
5276   signal (SIGFPE, float_signal);
5277
5278 #ifdef SIGPIPE
5279   signal (SIGPIPE, pipe_closed);
5280 #endif
5281
5282   decl_printable_name = decl_name;
5283   lang_expand_expr = (lang_expand_expr_t) do_abort;
5284
5285   /* Initialize whether `char' is signed.  */
5286   flag_signed_char = DEFAULT_SIGNED_CHAR;
5287 #ifdef DEFAULT_SHORT_ENUMS
5288   /* Initialize how much space enums occupy, by default.  */
5289   flag_short_enums = DEFAULT_SHORT_ENUMS;
5290 #endif
5291
5292   /* Initialize the garbage-collector.  */
5293   init_ggc ();
5294   ggc_add_root (&input_file_stack, 1, sizeof input_file_stack,
5295                 &mark_file_stack);
5296
5297   /* Perform language-specific options intialization.  */
5298   lang_init_options ();
5299
5300   /* Scan to see what optimization level has been specified.  That will
5301      determine the default value of many flags.  */
5302   for (i = 1; i < argc; i++)
5303     {
5304       if (!strcmp (argv[i], "-O"))
5305         {
5306           optimize = 1;
5307           optimize_size = 0;
5308         }
5309       else if (argv[i][0] == '-' && argv[i][1] == 'O')
5310         {
5311           /* Handle -Os, -O2, -O3, -O69, ...  */
5312           char *p = &argv[i][2];
5313           
5314           if ((p[0] == 's') && (p[1] == 0))
5315             {
5316               optimize_size = 1;
5317               
5318               /* Optimizing for size forces optimize to be 2. */
5319               optimize = 2;
5320             }
5321           else
5322             {       
5323               const int optimize_val = read_integral_parameter (p, p - 2, -1);
5324               if (optimize_val != -1)
5325                 {
5326                   optimize = optimize_val;
5327                   optimize_size = 0;
5328                 }
5329             }
5330         }
5331     }
5332
5333   obey_regdecls = (optimize == 0);
5334
5335   if (optimize >= 1)
5336     {
5337       flag_defer_pop = 1;
5338       flag_thread_jumps = 1;
5339 #ifdef DELAY_SLOTS
5340       flag_delayed_branch = 1;
5341 #endif
5342 #ifdef CAN_DEBUG_WITHOUT_FP
5343       flag_omit_frame_pointer = 1;
5344 #endif
5345     }
5346
5347   if (optimize >= 2)
5348     {
5349       flag_cse_follow_jumps = 1;
5350       flag_cse_skip_blocks = 1;
5351       flag_gcse = 1;
5352       flag_expensive_optimizations = 1;
5353       flag_strength_reduce = 1;
5354       flag_rerun_cse_after_loop = 1;
5355       flag_rerun_loop_opt = 1;
5356       flag_caller_saves = 1;
5357       flag_force_mem = 1;
5358       flag_peephole2 = 1;
5359 #ifdef INSN_SCHEDULING
5360       flag_schedule_insns = 1;
5361       flag_schedule_insns_after_reload = 1;
5362 #endif
5363       flag_regmove = 1;
5364       flag_strict_aliasing = 1;
5365       flag_delete_null_pointer_checks = 1;
5366     }
5367
5368   if (optimize >= 3)
5369     {
5370       flag_inline_functions = 1;
5371     }
5372
5373   if (optimize < 2 || optimize_size)
5374     {
5375       align_loops = 1;
5376       align_jumps = 1;
5377       align_labels = 1;
5378       align_functions = 1;
5379     }
5380
5381   /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
5382      modify it.  */
5383   target_flags = 0;
5384   set_target_switch ("");
5385
5386 #ifdef OPTIMIZATION_OPTIONS
5387   /* Allow default optimizations to be specified on a per-machine basis.  */
5388   OPTIMIZATION_OPTIONS (optimize, optimize_size);
5389 #endif
5390
5391   /* Initialize register usage now so switches may override.  */
5392   init_reg_sets ();
5393
5394   /* Perform normal command line switch decoding.  */
5395   for (i = 1; i < argc;)
5396     {
5397       unsigned lang_processed;
5398       unsigned indep_processed;
5399       
5400       /* Give the language a chance to decode the option for itself.  */
5401       lang_processed = lang_decode_option (argc - i, argv + i);
5402  
5403       /* Now see if the option also has a language independent meaning.
5404          Some options are both language specific and language independent,
5405          eg --help.  It is possible that there might be options that should
5406          only be decoded in a language independent way if the were not
5407          decoded in a langauge specific way, which is why 'lang_processed'
5408          is passed in.  */
5409       indep_processed = independent_decode_option (argc - i, argv + i, lang_processed);
5410
5411       if (lang_processed || indep_processed)
5412         i += lang_processed > indep_processed ? lang_processed : indep_processed;
5413       else
5414         {
5415           error ("Invalid option `%s'", argv[i]);
5416           i++;
5417         }
5418     }
5419
5420   /* Checker uses the frame pointer.  */
5421   if (flag_check_memory_usage)
5422     flag_omit_frame_pointer = 0;
5423
5424   if (optimize == 0)
5425     {
5426       /* Inlining does not work if not optimizing,
5427          so force it not to be done.  */
5428       flag_no_inline = 1;
5429       warn_inline = 0;
5430
5431       /* The c_decode_option and lang_decode_option functions set
5432          this to `2' if -Wall is used, so we can avoid giving out
5433          lots of errors for people who don't realize what -Wall does.  */
5434       if (warn_uninitialized == 1)
5435         warning ("-Wuninitialized is not supported without -O");
5436     }
5437
5438 #ifdef OVERRIDE_OPTIONS
5439   /* Some machines may reject certain combinations of options.  */
5440   OVERRIDE_OPTIONS;
5441 #endif
5442
5443   if (exceptions_via_longjmp == 2)
5444     {
5445 #ifdef DWARF2_UNWIND_INFO
5446       exceptions_via_longjmp = ! DWARF2_UNWIND_INFO;
5447 #else
5448       exceptions_via_longjmp = 1;
5449 #endif
5450     }
5451
5452   /* Set up the align_*_log variables, defaulting them to 1 if they
5453      were still unset.  */
5454   if (align_loops <= 0) align_loops = 1;
5455   align_loops_log = floor_log2 (align_loops*2-1);
5456   if (align_jumps <= 0) align_jumps = 1;
5457   align_jumps_log = floor_log2 (align_jumps*2-1);
5458   if (align_labels <= 0) align_labels = 1;
5459   align_labels_log = floor_log2 (align_labels*2-1);
5460   if (align_functions <= 0) align_functions = 1;
5461   align_functions_log = floor_log2 (align_functions*2-1);
5462   
5463   if (profile_block_flag == 3)
5464     {
5465       warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
5466       profile_block_flag = 2;
5467     }
5468
5469   /* Unrolling all loops implies that standard loop unrolling must also
5470      be done.  */
5471   if (flag_unroll_all_loops)
5472     flag_unroll_loops = 1;
5473   /* Loop unrolling requires that strength_reduction be on also.  Silently
5474      turn on strength reduction here if it isn't already on.  Also, the loop
5475      unrolling code assumes that cse will be run after loop, so that must
5476      be turned on also.  */
5477   if (flag_unroll_loops)
5478     {
5479       flag_strength_reduce = 1;
5480       flag_rerun_cse_after_loop = 1;
5481     }
5482
5483   /* Warn about options that are not supported on this machine.  */
5484 #ifndef INSN_SCHEDULING
5485   if (flag_schedule_insns || flag_schedule_insns_after_reload)
5486     warning ("instruction scheduling not supported on this target machine");
5487 #endif
5488 #ifndef DELAY_SLOTS
5489   if (flag_delayed_branch)
5490     warning ("this target machine does not have delayed branches");
5491 #endif
5492
5493   user_label_prefix = USER_LABEL_PREFIX;
5494   if (flag_leading_underscore != -1)
5495     {
5496       /* If the default prefix is more complicated than "" or "_", 
5497          issue a warning and ignore this option.  */
5498       if (user_label_prefix[0] == 0 ||
5499           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
5500         {
5501           user_label_prefix = flag_leading_underscore ? "_" : "";
5502         }
5503       else
5504         warning ("-f%sleading-underscore not supported on this target machine",
5505                  flag_leading_underscore ? "" : "no-");
5506     }
5507
5508   /* If we are in verbose mode, write out the version and maybe all the
5509      option flags in use.  */
5510   if (version_flag)
5511     {
5512       print_version (stderr, "");
5513       if (! quiet_flag)
5514         print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
5515     }
5516
5517   compile_file (filename);
5518
5519 #if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN__)) && !defined(__INTERIX)
5520   if (flag_print_mem)
5521     {
5522       char *lim = (char *) sbrk (0);
5523
5524       notice ("Data size %ld.\n", (long) (lim - (char *) &environ));
5525       fflush (stderr);
5526
5527 #ifndef __MSDOS__
5528 #ifdef USG
5529       system ("ps -l 1>&2");
5530 #else /* not USG */
5531       system ("ps v");
5532 #endif /* not USG */
5533 #endif
5534     }
5535 #endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN) && ! __INTERIX */
5536
5537   if (errorcount)
5538     return (FATAL_EXIT_CODE);
5539   if (sorrycount)
5540     return (FATAL_EXIT_CODE);
5541   return (SUCCESS_EXIT_CODE);
5542 }
5543 \f
5544 /* Decode -m switches.  */
5545 /* Decode the switch -mNAME.  */
5546
5547 static void
5548 set_target_switch (name)
5549   const char *name;
5550 {
5551   register size_t j;
5552   int valid_target_option = 0;
5553
5554   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5555     if (!strcmp (target_switches[j].name, name))
5556       {
5557         if (target_switches[j].value < 0)
5558           target_flags &= ~-target_switches[j].value;
5559         else
5560           target_flags |= target_switches[j].value;
5561         valid_target_option = 1;
5562       }
5563
5564 #ifdef TARGET_OPTIONS
5565   if (!valid_target_option)
5566     for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5567       {
5568         int len = strlen (target_options[j].prefix);
5569         if (!strncmp (target_options[j].prefix, name, len))
5570           {
5571             *target_options[j].variable = name + len;
5572             valid_target_option = 1;
5573           }
5574       }
5575 #endif
5576
5577   if (!valid_target_option)
5578     error ("Invalid option `%s'", name);
5579 }
5580 \f
5581 /* Print version information to FILE.
5582    Each line begins with INDENT (for the case where FILE is the
5583    assembler output file).  */
5584
5585 static void
5586 print_version (file, indent)
5587      FILE *file;
5588      const char *indent;
5589 {
5590 #ifndef __VERSION__
5591 #define __VERSION__ "[?]"
5592 #endif
5593   fnotice (file,
5594 #ifdef __GNUC__
5595            "%s%s%s version %s (%s) compiled by GNU C version %s.\n"
5596 #else
5597            "%s%s%s version %s (%s) compiled by CC.\n"
5598 #endif
5599            , indent, *indent != 0 ? " " : "",
5600            language_string, version_string, TARGET_NAME, __VERSION__);
5601 }
5602
5603 /* Print an option value and return the adjusted position in the line.
5604    ??? We don't handle error returns from fprintf (disk full); presumably
5605    other code will catch a disk full though.  */
5606
5607 static int
5608 print_single_switch (file, pos, max, indent, sep, term, type, name)
5609      FILE *file;
5610      int pos, max;
5611      const char *indent, *sep, *term, *type, *name;
5612 {
5613   /* The ultrix fprintf returns 0 on success, so compute the result we want
5614      here since we need it for the following test.  */
5615   int len = strlen (sep) + strlen (type) + strlen (name);
5616
5617   if (pos != 0
5618       && pos + len > max)
5619     {
5620       fprintf (file, "%s", term);
5621       pos = 0;
5622     }
5623   if (pos == 0)
5624     {
5625       fprintf (file, "%s", indent);
5626       pos = strlen (indent);
5627     }
5628   fprintf (file, "%s%s%s", sep, type, name);
5629   pos += len;
5630   return pos;
5631 }
5632      
5633 /* Print active target switches to FILE.
5634    POS is the current cursor position and MAX is the size of a "line".
5635    Each line begins with INDENT and ends with TERM.
5636    Each switch is separated from the next by SEP.  */
5637
5638 static void
5639 print_switch_values (file, pos, max, indent, sep, term)
5640      FILE *file;
5641      int pos, max;
5642      const char *indent, *sep, *term;
5643 {
5644   size_t j;
5645   char **p;
5646
5647   /* Print the options as passed.  */
5648
5649   pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
5650                              _("options passed: "), "");
5651
5652   for (p = &save_argv[1]; *p != NULL; p++)
5653     if (**p == '-')
5654       {
5655         /* Ignore these.  */
5656         if (strcmp (*p, "-o") == 0)
5657           {
5658             if (p[1] != NULL)
5659               p++;
5660             continue;
5661           }
5662         if (strcmp (*p, "-quiet") == 0)
5663           continue;
5664         if (strcmp (*p, "-version") == 0)
5665           continue;
5666         if ((*p)[1] == 'd')
5667           continue;
5668
5669         pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
5670       }
5671   if (pos > 0)
5672     fprintf (file, "%s", term);
5673
5674   /* Print the -f and -m options that have been enabled.
5675      We don't handle language specific options but printing argv
5676      should suffice.  */
5677
5678   pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
5679                              _("options enabled: "), "");
5680
5681   for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
5682     if (*f_options[j].variable == f_options[j].on_value)
5683       pos = print_single_switch (file, pos, max, indent, sep, term,
5684                                  "-f", f_options[j].string);
5685
5686   /* Print target specific options.  */
5687
5688   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5689     if (target_switches[j].name[0] != '\0'
5690         && target_switches[j].value > 0
5691         && ((target_switches[j].value & target_flags)
5692             == target_switches[j].value))
5693       {
5694         pos = print_single_switch (file, pos, max, indent, sep, term,
5695                                    "-m", target_switches[j].name);
5696       }
5697
5698 #ifdef TARGET_OPTIONS
5699   for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5700     if (*target_options[j].variable != NULL)
5701       {
5702         char prefix[256];
5703         sprintf (prefix, "-m%s", target_options[j].prefix);
5704         pos = print_single_switch (file, pos, max, indent, sep, term,
5705                                    prefix, *target_options[j].variable);
5706       }
5707 #endif
5708
5709   fprintf (file, "%s", term);
5710 }
5711
5712 /* Record the beginning of a new source file, named FILENAME.  */
5713
5714 void
5715 debug_start_source_file (filename)
5716      register char *filename ATTRIBUTE_UNUSED;
5717 {
5718 #ifdef DBX_DEBUGGING_INFO
5719   if (write_symbols == DBX_DEBUG)
5720     dbxout_start_new_source_file (filename);
5721 #endif
5722 #ifdef DWARF_DEBUGGING_INFO
5723   if (debug_info_level == DINFO_LEVEL_VERBOSE
5724       && write_symbols == DWARF_DEBUG)
5725     dwarfout_start_new_source_file (filename);
5726 #endif /* DWARF_DEBUGGING_INFO */
5727 #ifdef DWARF2_DEBUGGING_INFO
5728   if (debug_info_level == DINFO_LEVEL_VERBOSE
5729       && write_symbols == DWARF2_DEBUG)
5730     dwarf2out_start_source_file (filename);
5731 #endif /* DWARF2_DEBUGGING_INFO */  
5732 #ifdef SDB_DEBUGGING_INFO
5733   if (write_symbols == SDB_DEBUG)
5734     sdbout_start_new_source_file (filename);
5735 #endif
5736 }
5737
5738 /* Record the resumption of a source file.  LINENO is the line number in
5739    the source file we are returning to.  */
5740
5741 void
5742 debug_end_source_file (lineno)
5743      register unsigned lineno ATTRIBUTE_UNUSED;
5744 {
5745 #ifdef DBX_DEBUGGING_INFO
5746   if (write_symbols == DBX_DEBUG)
5747     dbxout_resume_previous_source_file ();
5748 #endif
5749 #ifdef DWARF_DEBUGGING_INFO
5750   if (debug_info_level == DINFO_LEVEL_VERBOSE
5751       && write_symbols == DWARF_DEBUG)
5752     dwarfout_resume_previous_source_file (lineno);
5753 #endif /* DWARF_DEBUGGING_INFO */
5754 #ifdef DWARF2_DEBUGGING_INFO
5755   if (debug_info_level == DINFO_LEVEL_VERBOSE
5756       && write_symbols == DWARF2_DEBUG)
5757     dwarf2out_end_source_file ();
5758 #endif /* DWARF2_DEBUGGING_INFO */
5759 #ifdef SDB_DEBUGGING_INFO
5760   if (write_symbols == SDB_DEBUG)
5761     sdbout_resume_previous_source_file ();
5762 #endif
5763 }
5764
5765 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
5766    the tail part of the directive line, i.e. the part which is past the
5767    initial whitespace, #, whitespace, directive-name, whitespace part.  */
5768
5769 void
5770 debug_define (lineno, buffer)
5771      register unsigned lineno ATTRIBUTE_UNUSED;
5772      register char *buffer ATTRIBUTE_UNUSED;
5773 {
5774 #ifdef DWARF_DEBUGGING_INFO
5775   if (debug_info_level == DINFO_LEVEL_VERBOSE
5776       && write_symbols == DWARF_DEBUG)
5777     dwarfout_define (lineno, buffer);
5778 #endif /* DWARF_DEBUGGING_INFO */
5779 #ifdef DWARF2_DEBUGGING_INFO
5780   if (debug_info_level == DINFO_LEVEL_VERBOSE
5781       && write_symbols == DWARF2_DEBUG)
5782     dwarf2out_define (lineno, buffer);
5783 #endif /* DWARF2_DEBUGGING_INFO */
5784 }
5785
5786 /* Called from check_newline in c-parse.y.  The `buffer' parameter contains
5787    the tail part of the directive line, i.e. the part which is past the
5788    initial whitespace, #, whitespace, directive-name, whitespace part.  */
5789
5790 void
5791 debug_undef (lineno, buffer)
5792      register unsigned lineno ATTRIBUTE_UNUSED;
5793      register char *buffer ATTRIBUTE_UNUSED;
5794 {
5795 #ifdef DWARF_DEBUGGING_INFO
5796   if (debug_info_level == DINFO_LEVEL_VERBOSE
5797       && write_symbols == DWARF_DEBUG)
5798     dwarfout_undef (lineno, buffer);
5799 #endif /* DWARF_DEBUGGING_INFO */
5800 #ifdef DWARF2_DEBUGGING_INFO
5801   if (debug_info_level == DINFO_LEVEL_VERBOSE
5802       && write_symbols == DWARF2_DEBUG)
5803     dwarf2out_undef (lineno, buffer);
5804 #endif /* DWARF2_DEBUGGING_INFO */
5805 }