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