OSDN Git Service

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