OSDN Git Service

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