OSDN Git Service

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