OSDN Git Service

Remove CYGNUS LOCAL tags.
[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           print_version (asm_out_file, ASM_COMMENT_START);
2203           print_switch_values (asm_out_file, 0, MAX_LINE,
2204                                ASM_COMMENT_START, " ", "\n");
2205           /* Add a blank line here so it appears in assembler output but not
2206              screen output.  */
2207           fprintf (asm_out_file, "\n");
2208         }
2209 #endif
2210     }
2211
2212   /* Output something to inform GDB that this compilation was by GCC.  Also
2213      serves to tell GDB file consists of bytecodes. */
2214   if (output_bytecode)
2215     fprintf (asm_out_file, "bc_gcc2_compiled.:\n");
2216   else
2217     {
2218 #ifndef ASM_IDENTIFY_GCC
2219       fprintf (asm_out_file, "gcc2_compiled.:\n");
2220 #else
2221       ASM_IDENTIFY_GCC (asm_out_file);
2222 #endif
2223     }
2224
2225   /* Output something to identify which front-end produced this file. */
2226 #ifdef ASM_IDENTIFY_LANGUAGE
2227   ASM_IDENTIFY_LANGUAGE (asm_out_file);
2228 #endif
2229
2230 #ifndef ASM_OUTPUT_SECTION_NAME
2231   if (flag_function_sections)
2232     {
2233       warning ("-ffunction-sections not supported for this target.");
2234       flag_function_sections = 0;
2235     }
2236 #endif
2237
2238   if (flag_function_sections
2239       && (profile_flag || profile_block_flag))
2240     {
2241       warning ("-ffunction-sections disabled; it makes profiling impossible.");
2242       flag_function_sections = 0;
2243     }
2244
2245   if (flag_function_sections && write_symbols != NO_DEBUG)
2246     warning ("-ffunction-sections may affect debugging on some targets.");
2247
2248   if (output_bytecode)
2249     {
2250       if (profile_flag || profile_block_flag)
2251         error ("profiling not supported in bytecode compilation");
2252     }
2253   else
2254     {
2255       /* ??? Note: There used to be a conditional here
2256          to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2257          This was to guarantee separation between gcc_compiled. and
2258          the first function, for the sake of dbx on Suns.
2259          However, having the extra zero here confused the Emacs
2260          code for unexec, and might confuse other programs too.
2261          Therefore, I took out that change.
2262          In future versions we should find another way to solve
2263          that dbx problem.  -- rms, 23 May 93.  */
2264       
2265       /* Don't let the first function fall at the same address
2266          as gcc_compiled., if profiling.  */
2267       if (profile_flag || profile_block_flag)
2268         assemble_zeros (UNITS_PER_WORD);
2269     }
2270
2271   /* If dbx symbol table desired, initialize writing it
2272      and output the predefined types.  */
2273 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2274   if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2275     TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2276                                        getdecls ()));
2277 #endif
2278 #ifdef SDB_DEBUGGING_INFO
2279   if (write_symbols == SDB_DEBUG)
2280     TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2281                                        getdecls ()));
2282 #endif
2283 #ifdef DWARF_DEBUGGING_INFO
2284   if (write_symbols == DWARF_DEBUG)
2285     TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2286 #endif
2287
2288   /* Initialize yet another pass.  */
2289
2290   if (!output_bytecode)
2291     init_final (main_input_filename);
2292
2293   start_time = get_run_time ();
2294
2295   /* Call the parser, which parses the entire file
2296      (calling rest_of_compilation for each function).  */
2297
2298   if (yyparse () != 0)
2299     {
2300       if (errorcount == 0)
2301         fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
2302
2303       /* In case there were missing closebraces,
2304          get us back to the global binding level.  */
2305       while (! global_bindings_p ())
2306         poplevel (0, 0, 0);
2307     }
2308
2309   /* Compilation is now finished except for writing
2310      what's left of the symbol table output.  */
2311
2312   parse_time += get_run_time () - start_time;
2313
2314   parse_time -= integration_time;
2315   parse_time -= varconst_time;
2316
2317   globals = getdecls ();
2318
2319   /* Really define vars that have had only a tentative definition.
2320      Really output inline functions that must actually be callable
2321      and have not been output so far.  */
2322
2323   {
2324     int len = list_length (globals);
2325     tree *vec = (tree *) alloca (sizeof (tree) * len);
2326     int i;
2327     tree decl;
2328     int reconsider = 1;
2329
2330     /* Process the decls in reverse order--earliest first.
2331        Put them into VEC from back to front, then take out from front.  */
2332
2333     for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2334       vec[len - i - 1] = decl;
2335
2336     for (i = 0; i < len; i++)
2337       {
2338         decl = vec[i];
2339
2340         /* We're not deferring this any longer.  */
2341         DECL_DEFER_OUTPUT (decl) = 0;
2342
2343         if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2344             && incomplete_decl_finalize_hook != 0)
2345           (*incomplete_decl_finalize_hook) (decl);
2346       }
2347
2348     /* Now emit any global variables or functions that we have been putting
2349        off.  We need to loop in case one of the things emitted here
2350        references another one which comes earlier in the list.  */
2351     while (reconsider)
2352       {
2353         reconsider = 0;
2354         for (i = 0; i < len; i++)
2355           {
2356             decl = vec[i];
2357
2358             if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2359               continue;
2360
2361             /* Don't write out static consts, unless we still need them.
2362
2363                We also keep static consts if not optimizing (for debugging).
2364                ??? They might be better written into the debug information.
2365                This is possible when using DWARF.
2366
2367                A language processor that wants static constants to be always
2368                written out (even if it is not used) is responsible for
2369                calling rest_of_decl_compilation itself.  E.g. the C front-end
2370                calls rest_of_decl_compilation from finish_decl.
2371                One motivation for this is that is conventional in some
2372                environments to write things like:
2373                    static const char rcsid[] = "... version string ...";
2374                intending to force the string to be in the executable.
2375
2376                A language processor that would prefer to have unneeded
2377                static constants "optimized away" would just defer writing
2378                them out until here.  E.g. C++ does this, because static
2379                constants are often defined in header files.
2380
2381                ??? A tempting alternative (for both C and C++) would be
2382                to force a constant to be written if and only if it is
2383                defined in a main file, as opposed to an include file. */
2384
2385             if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2386                 && (! TREE_READONLY (decl)
2387                     || TREE_PUBLIC (decl)
2388                     || !optimize
2389                     || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2390               {
2391                 reconsider = 1;
2392                 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2393               }
2394
2395             if (TREE_CODE (decl) == FUNCTION_DECL
2396                 && DECL_INITIAL (decl) != 0
2397                 && DECL_SAVED_INSNS (decl) != 0
2398                 && (flag_keep_inline_functions
2399                     || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2400               {
2401                 reconsider = 1;
2402                 temporary_allocation ();
2403                 output_inline_function (decl);
2404                 permanent_allocation (1);
2405               }
2406           }
2407       }
2408
2409     for (i = 0; i < len; i++)
2410       {
2411         decl = vec[i];
2412
2413         if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2414             && ! TREE_ASM_WRITTEN (decl))
2415           /* Cancel the RTL for this decl so that, if debugging info
2416              output for global variables is still to come,
2417              this one will be omitted.  */
2418           DECL_RTL (decl) = NULL;
2419
2420         /* Warn about any function
2421            declared static but not defined.
2422            We don't warn about variables,
2423            because many programs have static variables
2424            that exist only to get some text into the object file.  */
2425         if (TREE_CODE (decl) == FUNCTION_DECL
2426             && (warn_unused
2427                 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2428             && DECL_INITIAL (decl) == 0
2429             && DECL_EXTERNAL (decl)
2430             && ! DECL_ARTIFICIAL (decl)
2431             && ! TREE_PUBLIC (decl))
2432           {
2433             pedwarn_with_decl (decl, 
2434                                "`%s' declared `static' but never defined");
2435             /* This symbol is effectively an "extern" declaration now.  */
2436             TREE_PUBLIC (decl) = 1;
2437             assemble_external (decl);
2438           }
2439
2440         /* Warn about static fns or vars defined but not used,
2441            but not about inline functions or static consts
2442            since defining those in header files is normal practice.  */
2443         if (warn_unused
2444             && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2445                 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2446             && ! DECL_IN_SYSTEM_HEADER (decl)
2447             && ! DECL_EXTERNAL (decl)
2448             && ! TREE_PUBLIC (decl)
2449             && ! TREE_USED (decl)
2450             && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2451             /* The TREE_USED bit for file-scope decls
2452                is kept in the identifier, to handle multiple
2453                external decls in different scopes.  */
2454             && ! TREE_USED (DECL_NAME (decl)))
2455           warning_with_decl (decl, "`%s' defined but not used");
2456
2457 #ifdef SDB_DEBUGGING_INFO
2458         /* The COFF linker can move initialized global vars to the end.
2459            And that can screw up the symbol ordering.
2460            By putting the symbols in that order to begin with,
2461            we avoid a problem.  mcsun!unido!fauern!tumuc!pes@uunet.uu.net.  */
2462         if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2463             && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2464             && ! DECL_EXTERNAL (decl)
2465             && DECL_RTL (decl) != 0)
2466           TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2467
2468         /* Output COFF information for non-global
2469            file-scope initialized variables. */
2470         if (write_symbols == SDB_DEBUG
2471             && TREE_CODE (decl) == VAR_DECL
2472             && DECL_INITIAL (decl)
2473             && ! DECL_EXTERNAL (decl)
2474             && DECL_RTL (decl) != 0
2475             && GET_CODE (DECL_RTL (decl)) == MEM)
2476           TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2477 #endif /* SDB_DEBUGGING_INFO */
2478 #ifdef DWARF_DEBUGGING_INFO
2479         /* Output DWARF information for file-scope tentative data object
2480            declarations, file-scope (extern) function declarations (which
2481            had no corresponding body) and file-scope tagged type declarations
2482            and definitions which have not yet been forced out.  */
2483
2484         if (write_symbols == DWARF_DEBUG
2485             && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2486           TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2487 #endif
2488       }
2489   }
2490
2491   /* Write out any pending weak symbol declarations.  */
2492
2493   weak_finish ();
2494
2495   /* Do dbx symbols */
2496 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2497   if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2498     TIMEVAR (symout_time,
2499              {
2500                dbxout_finish (asm_out_file, main_input_filename);
2501              });
2502 #endif
2503
2504 #ifdef DWARF_DEBUGGING_INFO
2505   if (write_symbols == DWARF_DEBUG)
2506     TIMEVAR (symout_time,
2507              {
2508                dwarfout_finish ();
2509              });
2510 #endif
2511
2512   /* Output some stuff at end of file if nec.  */
2513
2514   if (!output_bytecode)
2515     {
2516       end_final (main_input_filename);
2517
2518 #ifdef ASM_FILE_END
2519       ASM_FILE_END (asm_out_file);
2520 #endif
2521     }
2522
2523   /* Language-specific end of compilation actions.  */
2524
2525   lang_finish ();
2526
2527   if (output_bytecode)
2528     bc_write_file (asm_out_file);
2529
2530   /* Close the dump files.  */
2531
2532   if (flag_gen_aux_info)
2533     {
2534       fclose (aux_info_file);
2535       if (errorcount)
2536         unlink (aux_info_file_name);
2537     }
2538
2539   if (rtl_dump)
2540     fclose (rtl_dump_file);
2541
2542   if (jump_opt_dump)
2543     fclose (jump_opt_dump_file);
2544
2545   if (cse_dump)
2546     fclose (cse_dump_file);
2547
2548   if (loop_dump)
2549     fclose (loop_dump_file);
2550
2551   if (cse2_dump)
2552     fclose (cse2_dump_file);
2553
2554   if (flow_dump)
2555     fclose (flow_dump_file);
2556
2557   if (combine_dump)
2558     {
2559       dump_combine_total_stats (combine_dump_file);
2560       fclose (combine_dump_file);
2561     }
2562
2563   if (sched_dump)
2564     fclose (sched_dump_file);
2565
2566   if (local_reg_dump)
2567     fclose (local_reg_dump_file);
2568
2569   if (global_reg_dump)
2570     fclose (global_reg_dump_file);
2571
2572   if (sched2_dump)
2573     fclose (sched2_dump_file);
2574
2575   if (jump2_opt_dump)
2576     fclose (jump2_opt_dump_file);
2577
2578   if (dbr_sched_dump)
2579     fclose (dbr_sched_dump_file);
2580
2581 #ifdef STACK_REGS
2582   if (stack_reg_dump)
2583     fclose (stack_reg_dump_file);
2584 #endif
2585
2586   /* Close non-debugging input and output files.  Take special care to note
2587      whether fclose returns an error, since the pages might still be on the
2588      buffer chain while the file is open.  */
2589
2590   fclose (finput);
2591   if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
2592     fatal_io_error (asm_file_name);
2593
2594   /* Print the times.  */
2595
2596   if (! quiet_flag)
2597     {
2598       fprintf (stderr,"\n");
2599       print_time ("parse", parse_time);
2600
2601       if (!output_bytecode)
2602         {
2603           print_time ("integration", integration_time);
2604           print_time ("jump", jump_time);
2605           print_time ("cse", cse_time);
2606           print_time ("loop", loop_time);
2607           print_time ("cse2", cse2_time);
2608           print_time ("flow", flow_time);
2609           print_time ("combine", combine_time);
2610           print_time ("sched", sched_time);
2611           print_time ("local-alloc", local_alloc_time);
2612           print_time ("global-alloc", global_alloc_time);
2613           print_time ("sched2", sched2_time);
2614           print_time ("dbranch", dbr_sched_time);
2615           print_time ("shorten-branch", shorten_branch_time);
2616           print_time ("stack-reg", stack_reg_time);
2617           print_time ("final", final_time);
2618           print_time ("varconst", varconst_time);
2619           print_time ("symout", symout_time);
2620           print_time ("dump", dump_time);
2621         }
2622     }
2623 }
2624 \f
2625 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2626    and TYPE_DECL nodes.
2627
2628    This does nothing for local (non-static) variables.
2629    Otherwise, it sets up the RTL and outputs any assembler code
2630    (label definition, storage allocation and initialization).
2631
2632    DECL is the declaration.  If ASMSPEC is nonzero, it specifies
2633    the assembler symbol name to be used.  TOP_LEVEL is nonzero
2634    if this declaration is not within a function.  */
2635
2636 void
2637 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2638      tree decl;
2639      char *asmspec;
2640      int top_level;
2641      int at_end;
2642 {
2643   /* Declarations of variables, and of functions defined elsewhere.  */
2644
2645 /* The most obvious approach, to put an #ifndef around where
2646    this macro is used, doesn't work since it's inside a macro call.  */
2647 #ifndef ASM_FINISH_DECLARE_OBJECT
2648 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2649 #endif
2650
2651   /* Forward declarations for nested functions are not "external",
2652      but we need to treat them as if they were.  */
2653   if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2654       || TREE_CODE (decl) == FUNCTION_DECL)
2655     TIMEVAR (varconst_time,
2656              {
2657                make_decl_rtl (decl, asmspec, top_level);
2658                /* Initialized extern variable exists to be replaced
2659                   with its value, or represents something that will be
2660                   output in another file.  */
2661                if (! (TREE_CODE (decl) == VAR_DECL
2662                       && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
2663                       && DECL_INITIAL (decl) != 0
2664                       && DECL_INITIAL (decl) != error_mark_node))
2665                  /* Don't output anything
2666                     when a tentative file-scope definition is seen.
2667                     But at end of compilation, do output code for them.  */
2668                  if (! (! at_end && top_level
2669                         && (DECL_INITIAL (decl) == 0
2670                             || DECL_INITIAL (decl) == error_mark_node)))
2671                    assemble_variable (decl, top_level, at_end, 0);
2672                if (!output_bytecode
2673                    && decl == last_assemble_variable_decl)
2674                  {
2675                    ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2676                                               top_level, at_end);
2677                  }
2678              });
2679   else if (DECL_REGISTER (decl) && asmspec != 0)
2680     {
2681       if (decode_reg_name (asmspec) >= 0)
2682         {
2683           DECL_RTL (decl) = 0;
2684           make_decl_rtl (decl, asmspec, top_level);
2685         }
2686       else
2687         error ("invalid register name `%s' for register variable", asmspec);
2688     }
2689 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2690   else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2691            && TREE_CODE (decl) == TYPE_DECL)
2692     TIMEVAR (symout_time, dbxout_symbol (decl, 0));
2693 #endif
2694 #ifdef SDB_DEBUGGING_INFO
2695   else if (write_symbols == SDB_DEBUG && top_level
2696            && TREE_CODE (decl) == TYPE_DECL)
2697     TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2698 #endif
2699 }
2700
2701 /* Called after finishing a record, union or enumeral type.  */
2702
2703 void
2704 rest_of_type_compilation (type, toplev)
2705      tree type;
2706      int toplev;
2707 {
2708 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2709   if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2710     TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
2711 #endif
2712 #ifdef SDB_DEBUGGING_INFO
2713   if (write_symbols == SDB_DEBUG)
2714     TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
2715 #endif
2716 }
2717
2718 /* This is called from finish_function (within yyparse)
2719    after each top-level definition is parsed.
2720    It is supposed to compile that function or variable
2721    and output the assembler code for it.
2722    After we return, the tree storage is freed.  */
2723
2724 void
2725 rest_of_compilation (decl)
2726      tree decl;
2727 {
2728   register rtx insns;
2729   int start_time = get_run_time ();
2730   int tem;
2731   /* Nonzero if we have saved the original DECL_INITIAL of the function,
2732      to be restored after we finish compiling the function
2733      (for use when compiling inline calls to this function).  */
2734   tree saved_block_tree = 0;
2735   /* Likewise, for DECL_ARGUMENTS.  */
2736   tree saved_arguments = 0;
2737   int failure = 0;
2738
2739   if (output_bytecode)
2740     return;
2741
2742   /* If we are reconsidering an inline function
2743      at the end of compilation, skip the stuff for making it inline.  */
2744
2745   if (DECL_SAVED_INSNS (decl) == 0)
2746     {
2747       int inlineable = 0;
2748       char *lose;
2749
2750       /* If requested, consider whether to make this function inline.  */
2751       if (DECL_INLINE (decl) || flag_inline_functions)
2752         TIMEVAR (integration_time,
2753                  {
2754                    lose = function_cannot_inline_p (decl);
2755                    if (lose || ! optimize)
2756                      {
2757                        if (warn_inline && DECL_INLINE (decl))
2758                          warning_with_decl (decl, lose);
2759                        DECL_ABSTRACT_ORIGIN (decl) = 0;
2760                        /* Don't really compile an extern inline function.
2761                           If we can't make it inline, pretend
2762                           it was only declared.  */
2763                        if (DECL_EXTERNAL (decl))
2764                          {
2765                            DECL_INITIAL (decl) = 0;
2766                            goto exit_rest_of_compilation;
2767                          }
2768                      }
2769                    else
2770                      /* ??? Note that this has the effect of making it look
2771                         like "inline" was specified for a function if we choose
2772                         to inline it.  This isn't quite right, but it's
2773                         probably not worth the trouble to fix.  */
2774                      inlineable = DECL_INLINE (decl) = 1;
2775                  });
2776
2777       insns = get_insns ();
2778
2779       /* Dump the rtl code if we are dumping rtl.  */
2780
2781       if (rtl_dump)
2782         TIMEVAR (dump_time,
2783                  {
2784                    fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2785                             IDENTIFIER_POINTER (DECL_NAME (decl)));
2786                    if (DECL_SAVED_INSNS (decl))
2787                      fprintf (rtl_dump_file, ";; (integrable)\n\n");
2788                    print_rtl (rtl_dump_file, insns);
2789                    fflush (rtl_dump_file);
2790                  });
2791
2792       /* If function is inline, and we don't yet know whether to
2793          compile it by itself, defer decision till end of compilation.
2794          finish_compilation will call rest_of_compilation again
2795          for those functions that need to be output.  Also defer those
2796          functions that we are supposed to defer.  We cannot defer
2797          functions containing nested functions since the nested function
2798          data is in our non-saved obstack.  */
2799
2800       if (! current_function_contains_functions
2801           && (DECL_DEFER_OUTPUT (decl)
2802               || (DECL_INLINE (decl)
2803                   && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2804                        && ! flag_keep_inline_functions)
2805                       || DECL_EXTERNAL (decl)))))
2806         {
2807           DECL_DEFER_OUTPUT (decl) = 1;
2808
2809           /* If -Wreturn-type, we have to do a bit of compilation.  */
2810           if (! warn_return_type)
2811             {
2812 #ifdef DWARF_DEBUGGING_INFO
2813               /* Generate the DWARF info for the "abstract" instance
2814                  of a function which we may later generate inlined and/or
2815                  out-of-line instances of.  */
2816               if (write_symbols == DWARF_DEBUG)
2817                 {
2818                   set_decl_abstract_flags (decl, 1);
2819                   TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2820                   set_decl_abstract_flags (decl, 0);
2821                 }
2822 #endif
2823               TIMEVAR (integration_time, save_for_inline_nocopy (decl));
2824               RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
2825               goto exit_rest_of_compilation;
2826             }
2827         }
2828
2829       /* If we have to compile the function now, save its rtl and subdecls
2830          so that its compilation will not affect what others get.  */
2831       if (inlineable || DECL_DEFER_OUTPUT (decl))
2832         {
2833 #ifdef DWARF_DEBUGGING_INFO
2834           /* Generate the DWARF info for the "abstract" instance of
2835              a function which we will generate an out-of-line instance
2836              of almost immediately (and which we may also later generate
2837              various inlined instances of).  */
2838           if (write_symbols == DWARF_DEBUG)
2839             {
2840               set_decl_abstract_flags (decl, 1);
2841               TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2842               set_decl_abstract_flags (decl, 0);
2843             }
2844 #endif
2845           saved_block_tree = DECL_INITIAL (decl);
2846           saved_arguments = DECL_ARGUMENTS (decl);
2847           TIMEVAR (integration_time, save_for_inline_copying (decl));
2848           RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
2849         }
2850
2851       /* If specified extern inline but we aren't inlining it, we are
2852          done.  */
2853       if (DECL_INLINE (decl) && DECL_EXTERNAL (decl))
2854         goto exit_rest_of_compilation;
2855     }
2856
2857   if (! DECL_DEFER_OUTPUT (decl))
2858     TREE_ASM_WRITTEN (decl) = 1;
2859
2860   /* Now that integrate will no longer see our rtl, we need not distinguish
2861      between the return value of this function and the return value of called
2862      functions.  */
2863   rtx_equal_function_value_matters = 0;
2864
2865   /* Don't return yet if -Wreturn-type; we need to do jump_optimize.  */
2866   if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
2867     {
2868       goto exit_rest_of_compilation;
2869     }
2870
2871   /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
2872      Note that that may have been done above, in save_for_inline_copying.
2873      The call to resume_temporary_allocation near the end of this function
2874      goes back to the usual state of affairs.  */
2875
2876   rtl_in_current_obstack ();
2877
2878 #ifdef FINALIZE_PIC
2879   /* If we are doing position-independent code generation, now
2880      is the time to output special prologues and epilogues.
2881      We do not want to do this earlier, because it just clutters
2882      up inline functions with meaningless insns.  */
2883   if (flag_pic)
2884     FINALIZE_PIC;
2885 #endif
2886
2887   insns = get_insns ();
2888
2889   /* Copy any shared structure that should not be shared.  */
2890
2891   unshare_all_rtl (insns);
2892
2893   /* Instantiate all virtual registers.  */
2894
2895   instantiate_virtual_regs (current_function_decl, get_insns ());
2896
2897   /* See if we have allocated stack slots that are not directly addressable.
2898      If so, scan all the insns and create explicit address computation
2899      for all references to such slots.  */
2900 /*   fixup_stack_slots (); */
2901
2902   /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
2903      are initialized and to compute whether control can drop off the end
2904      of the function.  */
2905   TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
2906   TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
2907
2908   /* Now is when we stop if -fsyntax-only and -Wreturn-type.  */
2909   if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
2910     goto exit_rest_of_compilation;
2911
2912   /* Dump rtl code after jump, if we are doing that.  */
2913
2914   if (jump_opt_dump)
2915     TIMEVAR (dump_time,
2916              {
2917                fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
2918                         IDENTIFIER_POINTER (DECL_NAME (decl)));
2919                print_rtl (jump_opt_dump_file, insns);
2920                fflush (jump_opt_dump_file);
2921              });
2922
2923   /* Perform common subexpression elimination.
2924      Nonzero value from `cse_main' means that jumps were simplified
2925      and some code may now be unreachable, so do
2926      jump optimization again.  */
2927
2928   if (cse_dump)
2929     TIMEVAR (dump_time,
2930              {
2931                fprintf (cse_dump_file, "\n;; Function %s\n\n",
2932                         IDENTIFIER_POINTER (DECL_NAME (decl)));
2933              });
2934
2935   if (optimize > 0)
2936     {
2937       TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
2938
2939       if (flag_thread_jumps)
2940         /* Hacks by tiemann & kenner.  */
2941         TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
2942
2943       TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
2944                                          0, cse_dump_file));
2945       TIMEVAR (cse_time, delete_dead_from_cse (insns, max_reg_num ()));
2946
2947       if (tem || optimize > 1)
2948         TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
2949     }
2950
2951   /* Dump rtl code after cse, if we are doing that.  */
2952
2953   if (cse_dump)
2954     TIMEVAR (dump_time,
2955              {
2956                print_rtl (cse_dump_file, insns);
2957                fflush (cse_dump_file);
2958              });
2959
2960   if (loop_dump)
2961     TIMEVAR (dump_time,
2962              {
2963                fprintf (loop_dump_file, "\n;; Function %s\n\n",
2964                         IDENTIFIER_POINTER (DECL_NAME (decl)));
2965              });
2966
2967   /* Move constant computations out of loops.  */
2968
2969   if (optimize > 0)
2970     {
2971       TIMEVAR (loop_time,
2972                {
2973                  loop_optimize (insns, loop_dump_file);
2974                });
2975     }
2976
2977   /* Dump rtl code after loop opt, if we are doing that.  */
2978
2979   if (loop_dump)
2980     TIMEVAR (dump_time,
2981              {
2982                print_rtl (loop_dump_file, insns);
2983                fflush (loop_dump_file);
2984              });
2985
2986   if (cse2_dump)
2987     TIMEVAR (dump_time,
2988              {
2989                fprintf (cse2_dump_file, "\n;; Function %s\n\n",
2990                         IDENTIFIER_POINTER (DECL_NAME (decl)));
2991              });
2992
2993   if (optimize > 0 && flag_rerun_cse_after_loop)
2994     {
2995       /* Running another jump optimization pass before the second
2996          cse pass sometimes simplifies the RTL enough to allow
2997          the second CSE pass to do a better job.  Jump_optimize can change
2998          max_reg_num so we must rerun reg_scan afterwards.
2999          ??? Rework to not call reg_scan so often.  */
3000       TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3001       TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
3002
3003       TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3004       TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3005                                           1, cse2_dump_file));
3006       if (tem)
3007         TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3008     }
3009
3010   if (optimize > 0 && flag_thread_jumps)
3011     /* This pass of jump threading straightens out code
3012        that was kinked by loop optimization.  */
3013     TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3014
3015   /* Dump rtl code after cse, if we are doing that.  */
3016
3017   if (cse2_dump)
3018     TIMEVAR (dump_time,
3019              {
3020                print_rtl (cse2_dump_file, insns);
3021                fflush (cse2_dump_file);
3022              });
3023
3024   /* We are no longer anticipating cse in this function, at least.  */
3025
3026   cse_not_expected = 1;
3027
3028   /* Now we choose between stupid (pcc-like) register allocation
3029      (if we got the -noreg switch and not -opt)
3030      and smart register allocation.  */
3031
3032   if (optimize > 0)                     /* Stupid allocation probably won't work */
3033     obey_regdecls = 0;          /* if optimizations being done.  */
3034
3035   regclass_init ();
3036
3037   /* Print function header into flow dump now
3038      because doing the flow analysis makes some of the dump.  */
3039
3040   if (flow_dump)
3041     TIMEVAR (dump_time,
3042              {
3043                fprintf (flow_dump_file, "\n;; Function %s\n\n",
3044                         IDENTIFIER_POINTER (DECL_NAME (decl)));
3045              });
3046
3047   if (obey_regdecls)
3048     {
3049       TIMEVAR (flow_time,
3050                {
3051                  regclass (insns, max_reg_num ());
3052                  stupid_life_analysis (insns, max_reg_num (),
3053                                        flow_dump_file);
3054                });
3055     }
3056   else
3057     {
3058       /* Do control and data flow analysis,
3059          and write some of the results to dump file.  */
3060
3061       TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
3062                                          flow_dump_file));
3063       if (warn_uninitialized)
3064         {
3065           uninitialized_vars_warning (DECL_INITIAL (decl));
3066           setjmp_args_warning ();
3067         }
3068     }
3069
3070   /* Dump rtl after flow analysis.  */
3071
3072   if (flow_dump)
3073     TIMEVAR (dump_time,
3074              {
3075                print_rtl (flow_dump_file, insns);
3076                fflush (flow_dump_file);
3077              });
3078
3079   /* If -opt, try combining insns through substitution.  */
3080
3081   if (optimize > 0)
3082     TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
3083
3084   /* Dump rtl code after insn combination.  */
3085
3086   if (combine_dump)
3087     TIMEVAR (dump_time,
3088              {
3089                fprintf (combine_dump_file, "\n;; Function %s\n\n",
3090                         IDENTIFIER_POINTER (DECL_NAME (decl)));
3091                dump_combine_stats (combine_dump_file);
3092                print_rtl (combine_dump_file, insns);
3093                fflush (combine_dump_file);
3094              });
3095
3096   /* Print function header into sched dump now
3097      because doing the sched analysis makes some of the dump.  */
3098
3099   if (sched_dump)
3100     TIMEVAR (dump_time,
3101              {
3102                fprintf (sched_dump_file, "\n;; Function %s\n\n",
3103                         IDENTIFIER_POINTER (DECL_NAME (decl)));
3104              });
3105
3106   if (optimize > 0 && flag_schedule_insns)
3107     {
3108       /* Do control and data sched analysis,
3109          and write some of the results to dump file.  */
3110
3111       TIMEVAR (sched_time, schedule_insns (sched_dump_file));
3112     }
3113
3114   /* Dump rtl after instruction scheduling.  */
3115
3116   if (sched_dump)
3117     TIMEVAR (dump_time,
3118              {
3119                print_rtl (sched_dump_file, insns);
3120                fflush (sched_dump_file);
3121              });
3122
3123   /* Unless we did stupid register allocation,
3124      allocate pseudo-regs that are used only within 1 basic block.  */
3125
3126   if (!obey_regdecls)
3127     TIMEVAR (local_alloc_time,
3128              {
3129                regclass (insns, max_reg_num ());
3130                local_alloc ();
3131              });
3132
3133   /* Dump rtl code after allocating regs within basic blocks.  */
3134
3135   if (local_reg_dump)
3136     TIMEVAR (dump_time,
3137              {
3138                fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
3139                         IDENTIFIER_POINTER (DECL_NAME (decl)));
3140                dump_flow_info (local_reg_dump_file);
3141                dump_local_alloc (local_reg_dump_file);
3142                print_rtl (local_reg_dump_file, insns);
3143                fflush (local_reg_dump_file);
3144              });
3145
3146   if (global_reg_dump)
3147     TIMEVAR (dump_time,
3148              fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
3149                       IDENTIFIER_POINTER (DECL_NAME (decl))));
3150
3151   /* Save the last label number used so far, so reorg can tell
3152      when it's safe to kill spill regs.  */
3153   max_label_num_after_reload = max_label_num ();
3154
3155   /* Unless we did stupid register allocation,
3156      allocate remaining pseudo-regs, then do the reload pass
3157      fixing up any insns that are invalid.  */
3158
3159   TIMEVAR (global_alloc_time,
3160            {
3161              if (!obey_regdecls)
3162                failure = global_alloc (global_reg_dump_file);
3163              else
3164                failure = reload (insns, 0, global_reg_dump_file);
3165            });
3166
3167   if (global_reg_dump)
3168     TIMEVAR (dump_time,
3169              {
3170                dump_global_regs (global_reg_dump_file);
3171                print_rtl (global_reg_dump_file, insns);
3172                fflush (global_reg_dump_file);
3173              });
3174
3175   if (failure)
3176     goto exit_rest_of_compilation;
3177
3178   reload_completed = 1;
3179
3180   /* On some machines, the prologue and epilogue code, or parts thereof,
3181      can be represented as RTL.  Doing so lets us schedule insns between
3182      it and the rest of the code and also allows delayed branch
3183      scheduling to operate in the epilogue.  */
3184
3185   thread_prologue_and_epilogue_insns (insns);
3186
3187   if (optimize > 0 && flag_schedule_insns_after_reload)
3188     {
3189       if (sched2_dump)
3190         TIMEVAR (dump_time,
3191                  {
3192                    fprintf (sched2_dump_file, "\n;; Function %s\n\n",
3193                             IDENTIFIER_POINTER (DECL_NAME (decl)));
3194                  });
3195
3196       /* Do control and data sched analysis again,
3197          and write some more of the results to dump file.  */
3198
3199       TIMEVAR (sched2_time, schedule_insns (sched2_dump_file));
3200
3201       /* Dump rtl after post-reorder instruction scheduling.  */
3202
3203       if (sched2_dump)
3204         TIMEVAR (dump_time,
3205                  {
3206                    print_rtl (sched2_dump_file, insns);
3207                    fflush (sched2_dump_file);
3208                  });
3209     }
3210
3211 #ifdef LEAF_REGISTERS
3212   leaf_function = 0;
3213   if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
3214     leaf_function = 1;
3215 #endif
3216
3217   /* One more attempt to remove jumps to .+1
3218      left by dead-store-elimination.
3219      Also do cross-jumping this time
3220      and delete no-op move insns.  */
3221
3222   if (optimize > 0)
3223     {
3224       TIMEVAR (jump_time, jump_optimize (insns, 1, 1, 0));
3225     }
3226
3227   /* Dump rtl code after jump, if we are doing that.  */
3228
3229   if (jump2_opt_dump)
3230     TIMEVAR (dump_time,
3231              {
3232                fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
3233                         IDENTIFIER_POINTER (DECL_NAME (decl)));
3234                print_rtl (jump2_opt_dump_file, insns);
3235                fflush (jump2_opt_dump_file);
3236              });
3237
3238   /* If a machine dependent reorganization is needed, call it.  */
3239 #ifdef MACHINE_DEPENDENT_REORG
3240    MACHINE_DEPENDENT_REORG (insns);
3241 #endif
3242
3243   /* If a scheduling pass for delayed branches is to be done,
3244      call the scheduling code. */
3245
3246 #ifdef DELAY_SLOTS
3247   if (optimize > 0 && flag_delayed_branch)
3248     {
3249       TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
3250       if (dbr_sched_dump)
3251         {
3252           TIMEVAR (dump_time,
3253                  {
3254                    fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
3255                             IDENTIFIER_POINTER (DECL_NAME (decl)));
3256                    print_rtl (dbr_sched_dump_file, insns);
3257                    fflush (dbr_sched_dump_file);
3258                  });
3259         }
3260     }
3261 #endif
3262
3263   /* Shorten branches.  */
3264   TIMEVAR (shorten_branch_time,
3265            {
3266              shorten_branches (get_insns ());
3267            });
3268
3269 #ifdef STACK_REGS
3270   TIMEVAR (stack_reg_time, reg_to_stack (insns, stack_reg_dump_file));
3271   if (stack_reg_dump)
3272     {
3273       TIMEVAR (dump_time,
3274                {
3275                  fprintf (stack_reg_dump_file, "\n;; Function %s\n\n",
3276                           IDENTIFIER_POINTER (DECL_NAME (decl)));
3277                  print_rtl (stack_reg_dump_file, insns);
3278                  fflush (stack_reg_dump_file);
3279                });
3280     }
3281 #endif
3282
3283   /* Now turn the rtl into assembler code.  */
3284
3285   TIMEVAR (final_time,
3286            {
3287              rtx x;
3288              char *fnname;
3289
3290              /* Get the function's name, as described by its RTL.
3291                 This may be different from the DECL_NAME name used
3292                 in the source file.  */
3293
3294              x = DECL_RTL (decl);
3295              if (GET_CODE (x) != MEM)
3296                abort ();
3297              x = XEXP (x, 0);
3298              if (GET_CODE (x) != SYMBOL_REF)
3299                abort ();
3300              fnname = XSTR (x, 0);
3301
3302              assemble_start_function (decl, fnname);
3303              final_start_function (insns, asm_out_file, optimize);
3304              final (insns, asm_out_file, optimize, 0);
3305              final_end_function (insns, asm_out_file, optimize);
3306              assemble_end_function (decl, fnname);
3307              fflush (asm_out_file);
3308            });
3309
3310   /* Write DBX symbols if requested */
3311
3312   /* Note that for those inline functions where we don't initially
3313      know for certain that we will be generating an out-of-line copy,
3314      the first invocation of this routine (rest_of_compilation) will
3315      skip over this code by doing a `goto exit_rest_of_compilation;'.
3316      Later on, finish_compilation will call rest_of_compilation again
3317      for those inline functions that need to have out-of-line copies
3318      generated.  During that call, we *will* be routed past here.  */
3319
3320 #ifdef DBX_DEBUGGING_INFO
3321   if (write_symbols == DBX_DEBUG)
3322     TIMEVAR (symout_time, dbxout_function (decl));
3323 #endif
3324
3325 #ifdef DWARF_DEBUGGING_INFO
3326   if (write_symbols == DWARF_DEBUG)
3327     TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3328 #endif
3329
3330  exit_rest_of_compilation:
3331
3332   /* In case the function was not output,
3333      don't leave any temporary anonymous types
3334      queued up for sdb output.  */
3335 #ifdef SDB_DEBUGGING_INFO
3336   if (write_symbols == SDB_DEBUG)
3337     sdbout_types (NULL_TREE);
3338 #endif
3339
3340   /* Put back the tree of subblocks and list of arguments
3341      from before we copied them.
3342      Code generation and the output of debugging info may have modified
3343      the copy, but the original is unchanged.  */
3344
3345   if (saved_block_tree != 0)
3346     DECL_INITIAL (decl) = saved_block_tree;
3347   if (saved_arguments != 0)
3348     DECL_ARGUMENTS (decl) = saved_arguments;
3349
3350   reload_completed = 0;
3351
3352   /* Clear out the insn_length contents now that they are no longer valid.  */
3353   init_insn_lengths ();
3354
3355   /* Clear out the real_constant_chain before some of the rtx's
3356      it runs through become garbage.  */
3357
3358   clear_const_double_mem ();
3359
3360   /* Cancel the effect of rtl_in_current_obstack.  */
3361
3362   resume_temporary_allocation ();
3363
3364   /* Show no temporary slots allocated.  */
3365
3366   init_temp_slots ();
3367
3368   /* The parsing time is all the time spent in yyparse
3369      *except* what is spent in this function.  */
3370
3371   parse_time -= get_run_time () - start_time;
3372 }
3373 \f
3374 /* Entry point of cc1/c++.  Decode command args, then call compile_file.
3375    Exit code is 35 if can't open files, 34 if fatal error,
3376    33 if had nonfatal errors, else success.  */
3377
3378 int
3379 main (argc, argv, envp)
3380      int argc;
3381      char **argv;
3382      char **envp;
3383 {
3384   register int i;
3385   char *filename = 0;
3386   int flag_print_mem = 0;
3387   int version_flag = 0;
3388   char *p;
3389
3390   /* save in case md file wants to emit args as a comment.  */
3391   save_argc = argc;
3392   save_argv = argv;
3393
3394   p = argv[0] + strlen (argv[0]);
3395   while (p != argv[0] && p[-1] != '/'
3396 #ifdef DIR_SEPARATOR
3397          && p[-1] != DIR_SEPARATOR
3398 #endif
3399          )
3400     --p;
3401   progname = p;
3402
3403 #ifdef RLIMIT_STACK
3404   /* Get rid of any avoidable limit on stack size.  */
3405   {
3406     struct rlimit rlim;
3407
3408     /* Set the stack limit huge so that alloca does not fail. */
3409     getrlimit (RLIMIT_STACK, &rlim);
3410     rlim.rlim_cur = rlim.rlim_max;
3411     setrlimit (RLIMIT_STACK, &rlim);
3412   }
3413 #endif /* RLIMIT_STACK */
3414
3415   signal (SIGFPE, float_signal);
3416
3417 #ifdef SIGPIPE
3418   signal (SIGPIPE, pipe_closed);
3419 #endif
3420
3421   decl_printable_name = decl_name;
3422   lang_expand_expr = (struct rtx_def *(*)()) do_abort;
3423   interim_eh_hook = interim_eh;
3424
3425   /* Initialize whether `char' is signed.  */
3426   flag_signed_char = DEFAULT_SIGNED_CHAR;
3427 #ifdef DEFAULT_SHORT_ENUMS
3428   /* Initialize how much space enums occupy, by default.  */
3429   flag_short_enums = DEFAULT_SHORT_ENUMS;
3430 #endif
3431
3432   /* Scan to see what optimization level has been specified.  That will
3433      determine the default value of many flags.  */
3434   for (i = 1; i < argc; i++)
3435     {
3436       if (!strcmp (argv[i], "-O"))
3437         {
3438           optimize = 1;
3439         }
3440       else if (argv[i][0] == '-' && argv[i][1] == 'O')
3441         {
3442           /* Handle -O2, -O3, -O69, ...  */
3443           char *p = &argv[i][2];
3444           int c;
3445
3446           while (c = *p++)
3447             if (! (c >= '0' && c <= '9'))
3448               break;
3449           if (c == 0)
3450             optimize = atoi (&argv[i][2]);
3451         }
3452     }
3453
3454   obey_regdecls = (optimize == 0);
3455   if (optimize == 0)
3456     {
3457       flag_no_inline = 1;
3458       warn_inline = 0;
3459     }
3460
3461   if (optimize >= 1)
3462     {
3463       flag_defer_pop = 1;
3464       flag_thread_jumps = 1;
3465 #ifdef DELAY_SLOTS
3466       flag_delayed_branch = 1;
3467 #endif
3468 #ifdef CAN_DEBUG_WITHOUT_FP
3469       flag_omit_frame_pointer = 1;
3470 #endif
3471     }
3472
3473   if (optimize >= 2)
3474     {
3475       flag_cse_follow_jumps = 1;
3476       flag_cse_skip_blocks = 1;
3477       flag_expensive_optimizations = 1;
3478       flag_strength_reduce = 1;
3479       flag_rerun_cse_after_loop = 1;
3480       flag_caller_saves = 1;
3481       flag_force_mem = 1;
3482 #ifdef INSN_SCHEDULING
3483       flag_schedule_insns = 1;
3484       flag_schedule_insns_after_reload = 1;
3485 #endif
3486     }
3487
3488   if (optimize >= 3)
3489     {
3490       flag_inline_functions = 1;
3491     }
3492
3493   /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
3494      modify it.  */
3495   target_flags = 0;
3496   set_target_switch ("");
3497
3498 #ifdef OPTIMIZATION_OPTIONS
3499   /* Allow default optimizations to be specified on a per-machine basis.  */
3500   OPTIMIZATION_OPTIONS (optimize);
3501 #endif
3502
3503   /* Initialize register usage now so switches may override.  */
3504   init_reg_sets ();
3505
3506   for (i = 1; i < argc; i++)
3507     {
3508       int j;
3509       /* If this is a language-specific option,
3510          decode it in a language-specific way.  */
3511       for (j = 0; lang_options[j] != 0; j++)
3512         if (!strncmp (argv[i], lang_options[j],
3513                       strlen (lang_options[j])))
3514           break;
3515       if (lang_options[j] != 0)
3516         /* If the option is valid for *some* language,
3517            treat it as valid even if this language doesn't understand it.  */
3518         lang_decode_option (argv[i]);
3519       else if (argv[i][0] == '-' && argv[i][1] != 0)
3520         {
3521           register char *str = argv[i] + 1;
3522           if (str[0] == 'Y')
3523             str++;
3524
3525           if (str[0] == 'm')
3526             set_target_switch (&str[1]);
3527           else if (!strcmp (str, "dumpbase"))
3528             {
3529               dump_base_name = argv[++i];
3530             }
3531           else if (str[0] == 'd')
3532             {
3533               register char *p = &str[1];
3534               while (*p)
3535                 switch (*p++)
3536                   {
3537                   case 'a':
3538                     combine_dump = 1;
3539                     dbr_sched_dump = 1;
3540                     flow_dump = 1;
3541                     global_reg_dump = 1;
3542                     jump_opt_dump = 1;
3543                     jump2_opt_dump = 1;
3544                     local_reg_dump = 1;
3545                     loop_dump = 1;
3546                     rtl_dump = 1;
3547                     cse_dump = 1, cse2_dump = 1;
3548                     sched_dump = 1;
3549                     sched2_dump = 1;
3550                     stack_reg_dump = 1;
3551                     break;
3552                   case 'k':
3553                     stack_reg_dump = 1;
3554                     break;
3555                   case 'c':
3556                     combine_dump = 1;
3557                     break;
3558                   case 'd':
3559                     dbr_sched_dump = 1;
3560                     break;
3561                   case 'f':
3562                     flow_dump = 1;
3563                     break;
3564                   case 'g':
3565                     global_reg_dump = 1;
3566                     break;
3567                   case 'j':
3568                     jump_opt_dump = 1;
3569                     break;
3570                   case 'J':
3571                     jump2_opt_dump = 1;
3572                     break;
3573                   case 'l':
3574                     local_reg_dump = 1;
3575                     break;
3576                   case 'L':
3577                     loop_dump = 1;
3578                     break;
3579                   case 'm':
3580                     flag_print_mem = 1;
3581                     break;
3582                   case 'p':
3583                     flag_print_asm_name = 1;
3584                     break;
3585                   case 'r':
3586                     rtl_dump = 1;
3587                     break;
3588                   case 's':
3589                     cse_dump = 1;
3590                     break;
3591                   case 't':
3592                     cse2_dump = 1;
3593                     break;
3594                   case 'S':
3595                     sched_dump = 1;
3596                     break;
3597                   case 'R':
3598                     sched2_dump = 1;
3599                     break;
3600                   case 'y':
3601                     set_yydebug (1);
3602                     break;
3603                   case 'x':
3604                     rtl_dump_and_exit = 1;
3605                     break;
3606                   case 'A':
3607                     flag_debug_asm = 1;
3608                     break;
3609                   }
3610             }
3611           else if (str[0] == 'f')
3612             {
3613               register char *p = &str[1];
3614               int found = 0;
3615
3616               /* Some kind of -f option.
3617                  P's value is the option sans `-f'.
3618                  Search for it in the table of options.  */
3619
3620               for (j = 0;
3621                    !found && j < sizeof (f_options) / sizeof (f_options[0]);
3622                    j++)
3623                 {
3624                   if (!strcmp (p, f_options[j].string))
3625                     {
3626                       *f_options[j].variable = f_options[j].on_value;
3627                       /* A goto here would be cleaner,
3628                          but breaks the vax pcc.  */
3629                       found = 1;
3630                     }
3631                   if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3632                       && ! strcmp (p+3, f_options[j].string))
3633                     {
3634                       *f_options[j].variable = ! f_options[j].on_value;
3635                       found = 1;
3636                     }
3637                 }
3638
3639               if (found)
3640                 ;
3641               else if (!strncmp (p, "fixed-", 6))
3642                 fix_register (&p[6], 1, 1);
3643               else if (!strncmp (p, "call-used-", 10))
3644                 fix_register (&p[10], 0, 1);
3645               else if (!strncmp (p, "call-saved-", 11))
3646                 fix_register (&p[11], 0, 0);
3647               else
3648                 error ("Invalid option `%s'", argv[i]);
3649             }
3650           else if (str[0] == 'O')
3651             {
3652               register char *p = str+1;
3653               while (*p && *p >= '0' && *p <= '9')
3654                 p++;
3655               if (*p == '\0')
3656                 ;
3657               else
3658                 error ("Invalid option `%s'", argv[i]);
3659             }
3660           else if (!strcmp (str, "pedantic"))
3661             pedantic = 1;
3662           else if (!strcmp (str, "pedantic-errors"))
3663             flag_pedantic_errors = pedantic = 1;
3664           else if (!strcmp (str, "quiet"))
3665             quiet_flag = 1;
3666           else if (!strcmp (str, "version"))
3667             version_flag = 1;
3668           else if (!strcmp (str, "w"))
3669             inhibit_warnings = 1;
3670           else if (!strcmp (str, "W"))
3671             {
3672               extra_warnings = 1;
3673               /* We save the value of warn_uninitialized, since if they put
3674                  -Wuninitialized on the command line, we need to generate a
3675                  warning about not using it without also specifying -O.  */
3676               if (warn_uninitialized != 1)
3677                 warn_uninitialized = 2;
3678             }
3679           else if (str[0] == 'W')
3680             {
3681               register char *p = &str[1];
3682               int found = 0;
3683
3684               /* Some kind of -W option.
3685                  P's value is the option sans `-W'.
3686                  Search for it in the table of options.  */
3687
3688               for (j = 0;
3689                    !found && j < sizeof (W_options) / sizeof (W_options[0]);
3690                    j++)
3691                 {
3692                   if (!strcmp (p, W_options[j].string))
3693                     {
3694                       *W_options[j].variable = W_options[j].on_value;
3695                       /* A goto here would be cleaner,
3696                          but breaks the vax pcc.  */
3697                       found = 1;
3698                     }
3699                   if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3700                       && ! strcmp (p+3, W_options[j].string))
3701                     {
3702                       *W_options[j].variable = ! W_options[j].on_value;
3703                       found = 1;
3704                     }
3705                 }
3706
3707               if (found)
3708                 ;
3709               else if (!strncmp (p, "id-clash-", 9))
3710                 {
3711                   char *endp = p + 9;
3712
3713                   while (*endp)
3714                     {
3715                       if (*endp >= '0' && *endp <= '9')
3716                         endp++;
3717                       else
3718                         {
3719                           error ("Invalid option `%s'", argv[i]);
3720                           goto id_clash_lose;
3721                         }
3722                     }
3723                   warn_id_clash = 1;
3724                   id_clash_len = atoi (str + 10);
3725                 id_clash_lose: ;
3726                 }
3727               else if (!strncmp (p, "larger-than-", 12))
3728                 {
3729                   char *endp = p + 12;
3730
3731                   while (*endp)
3732                     {
3733                       if (*endp >= '0' && *endp <= '9')
3734                         endp++;
3735                       else
3736                         {
3737                           error ("Invalid option `%s'", argv[i]);
3738                           goto larger_than_lose;
3739                         }
3740                     }
3741                   warn_larger_than = 1;
3742                   larger_than_size = atoi (str + 13);
3743                 larger_than_lose: ;
3744                 }
3745               else
3746                 error ("Invalid option `%s'", argv[i]);
3747             }
3748           else if (!strcmp (str, "p"))
3749             {
3750               profile_flag = 1;
3751             }
3752           else if (!strcmp (str, "a"))
3753             {
3754 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
3755               warning ("`-a' option (basic block profile) not supported");
3756 #else
3757               profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
3758 #endif
3759             }
3760           else if (!strcmp (str, "ax"))
3761             {
3762 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
3763               warning ("`-ax' option (jump profiling) not supported");
3764 #else
3765               profile_block_flag = (!profile_block_flag 
3766                                        || profile_block_flag == 2) ? 2 : 3;
3767 #endif
3768             }
3769           else if (str[0] == 'g')
3770             {
3771               char *p = str + 1;
3772               char *q;
3773               unsigned len;
3774               unsigned level;
3775
3776               while (*p && (*p < '0' || *p > '9'))
3777                 p++;
3778               len = p - str;
3779               q = p;
3780               while (*q && (*q >= '0' && *q <= '9'))
3781                 q++;
3782               if (*p)
3783                 level = atoi (p);
3784               else
3785                 level = 2;      /* default debugging info level */
3786               if (*q || level > 3)
3787                 {
3788                   warning ("invalid debug level specification in option: `-%s'",
3789                            str);
3790                   warning ("no debugging information will be generated");
3791                   level = 0;
3792                 }
3793
3794               /* If more than one debugging type is supported,
3795                  you must define PREFERRED_DEBUGGING_TYPE
3796                  to choose a format in a system-dependent way.  */
3797               /* This is one long line cause VAXC can't handle a \-newline.  */
3798 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
3799 #ifdef PREFERRED_DEBUGGING_TYPE
3800               if (!strncmp (str, "ggdb", len))
3801                 write_symbols = PREFERRED_DEBUGGING_TYPE;
3802 #else /* no PREFERRED_DEBUGGING_TYPE */
3803 You Lose!  You must define PREFERRED_DEBUGGING_TYPE!
3804 #endif /* no PREFERRED_DEBUGGING_TYPE */
3805 #endif /* More than one debugger format enabled.  */
3806 #ifdef DBX_DEBUGGING_INFO
3807               if (write_symbols != NO_DEBUG)
3808                 ;
3809               else if (!strncmp (str, "ggdb", len))
3810                 write_symbols = DBX_DEBUG;
3811               else if (!strncmp (str, "gstabs", len))
3812                 write_symbols = DBX_DEBUG;
3813               else if (!strncmp (str, "gstabs+", len))
3814                 write_symbols = DBX_DEBUG;
3815
3816               /* Always enable extensions for -ggdb or -gstabs+, 
3817                  always disable for -gstabs.
3818                  For plain -g, use system-specific default.  */
3819               if (write_symbols == DBX_DEBUG && !strncmp (str, "ggdb", len)
3820                   && len >= 2)
3821                 use_gnu_debug_info_extensions = 1;
3822               else if (write_symbols == DBX_DEBUG && !strncmp (str, "gstabs+", len)
3823                        && len >= 7)
3824                 use_gnu_debug_info_extensions = 1;
3825               else if (write_symbols == DBX_DEBUG
3826                        && !strncmp (str, "gstabs", len) && len >= 2)
3827                 use_gnu_debug_info_extensions = 0;
3828               else
3829                 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
3830 #endif /* DBX_DEBUGGING_INFO */
3831 #ifdef DWARF_DEBUGGING_INFO
3832               if (write_symbols != NO_DEBUG)
3833                 ;
3834               else if (!strncmp (str, "g", len))
3835                 write_symbols = DWARF_DEBUG;
3836               else if (!strncmp (str, "ggdb", len))
3837                 write_symbols = DWARF_DEBUG;
3838               else if (!strncmp (str, "gdwarf", len))
3839                 write_symbols = DWARF_DEBUG;
3840
3841               /* Always enable extensions for -ggdb or -gdwarf+, 
3842                  always disable for -gdwarf.
3843                  For plain -g, use system-specific default.  */
3844               if (write_symbols == DWARF_DEBUG && !strncmp (str, "ggdb", len)
3845                   && len >= 2)
3846                 use_gnu_debug_info_extensions = 1;
3847               else if (write_symbols == DWARF_DEBUG && !strcmp (str, "gdwarf+"))
3848                 use_gnu_debug_info_extensions = 1;
3849               else if (write_symbols == DWARF_DEBUG
3850                        && !strncmp (str, "gdwarf", len) && len >= 2)
3851                 use_gnu_debug_info_extensions = 0;
3852               else
3853                 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
3854 #endif
3855 #ifdef SDB_DEBUGGING_INFO
3856               if (write_symbols != NO_DEBUG)
3857                 ;
3858               else if (!strncmp (str, "g", len))
3859                 write_symbols = SDB_DEBUG;
3860               else if (!strncmp (str, "gdb", len))
3861                 write_symbols = SDB_DEBUG;
3862               else if (!strncmp (str, "gcoff", len))
3863                 write_symbols = SDB_DEBUG;
3864 #endif /* SDB_DEBUGGING_INFO */
3865 #ifdef XCOFF_DEBUGGING_INFO
3866               if (write_symbols != NO_DEBUG)
3867                 ;
3868               else if (!strncmp (str, "g", len))
3869                 write_symbols = XCOFF_DEBUG;
3870               else if (!strncmp (str, "ggdb", len))
3871                 write_symbols = XCOFF_DEBUG;
3872               else if (!strncmp (str, "gxcoff", len))
3873                 write_symbols = XCOFF_DEBUG;
3874
3875               /* Always enable extensions for -ggdb or -gxcoff+,
3876                  always disable for -gxcoff.
3877                  For plain -g, use system-specific default.  */
3878               if (write_symbols == XCOFF_DEBUG && !strncmp (str, "ggdb", len)
3879                   && len >= 2)
3880                 use_gnu_debug_info_extensions = 1;
3881               else if (write_symbols == XCOFF_DEBUG && !strcmp (str, "gxcoff+"))
3882                 use_gnu_debug_info_extensions = 1;
3883               else if (write_symbols == XCOFF_DEBUG
3884                        && !strncmp (str, "gxcoff", len) && len >= 2)
3885                 use_gnu_debug_info_extensions = 0;
3886               else
3887                 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
3888 #endif        
3889               if (write_symbols == NO_DEBUG)
3890                 warning ("`-%s' not supported by this configuration of GCC",
3891                          str);
3892               else if (level == 0)
3893                 write_symbols = NO_DEBUG;
3894               else
3895                 debug_info_level = (enum debug_info_level) level;
3896             }
3897           else if (!strcmp (str, "o"))
3898             {
3899               asm_file_name = argv[++i];
3900             }
3901           else if (str[0] == 'G')
3902             {
3903               g_switch_set = TRUE;
3904               g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
3905             }
3906           else if (!strncmp (str, "aux-info", 8))
3907             {
3908               flag_gen_aux_info = 1;
3909               aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
3910             }
3911           else
3912             error ("Invalid option `%s'", argv[i]);
3913         }
3914       else if (argv[i][0] == '+')
3915         error ("Invalid option `%s'", argv[i]);
3916       else
3917         filename = argv[i];
3918     }
3919
3920   /* Initialize for bytecode output.  A good idea to do this as soon as
3921      possible after the "-f" options have been parsed. */
3922   if (output_bytecode)
3923     {
3924 #ifndef TARGET_SUPPORTS_BYTECODE
3925       /* Just die with a fatal error if not supported */
3926       fatal ("-fbytecode not supporter for this target");
3927 #else
3928       bc_initialize ();
3929 #endif
3930     }
3931
3932   if (optimize == 0)
3933     {
3934       /* Inlining does not work if not optimizing,
3935          so force it not to be done.  */
3936       flag_no_inline = 1;
3937       warn_inline = 0;
3938
3939       /* The c_decode_option and lang_decode_option functions set
3940          this to `2' if -Wall is used, so we can avoid giving out
3941          lots of errors for people who don't realize what -Wall does.  */
3942       if (warn_uninitialized == 1)
3943         warning ("-Wuninitialized is not supported without -O");
3944     }
3945
3946 #if defined(DWARF_DEBUGGING_INFO)
3947   if (write_symbols == DWARF_DEBUG
3948       && strcmp (language_string, "GNU C++") == 0)
3949     {
3950       warning ("-g option not supported for C++ on systems using the DWARF debugging format");
3951       write_symbols = NO_DEBUG;
3952     }
3953 #endif /* defined(DWARF_DEBUGGING_INFO) */
3954
3955 #ifdef OVERRIDE_OPTIONS
3956   /* Some machines may reject certain combinations of options.  */
3957   OVERRIDE_OPTIONS;
3958 #endif
3959
3960   if (profile_block_flag == 3)
3961     {
3962       warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
3963       profile_block_flag = 2;
3964     }
3965
3966   /* Unrolling all loops implies that standard loop unrolling must also
3967      be done.  */
3968   if (flag_unroll_all_loops)
3969     flag_unroll_loops = 1;
3970   /* Loop unrolling requires that strength_reduction be on also.  Silently
3971      turn on strength reduction here if it isn't already on.  Also, the loop
3972      unrolling code assumes that cse will be run after loop, so that must
3973      be turned on also.  */
3974   if (flag_unroll_loops)
3975     {
3976       flag_strength_reduce = 1;
3977       flag_rerun_cse_after_loop = 1;
3978     }
3979
3980   /* Warn about options that are not supported on this machine.  */
3981 #ifndef INSN_SCHEDULING
3982   if (flag_schedule_insns || flag_schedule_insns_after_reload)
3983     warning ("instruction scheduling not supported on this target machine");
3984 #endif
3985 #ifndef DELAY_SLOTS
3986   if (flag_delayed_branch)
3987     warning ("this target machine does not have delayed branches");
3988 #endif
3989
3990   /* If we are in verbose mode, write out the version and maybe all the
3991      option flags in use.  */
3992   if (version_flag)
3993     {
3994       print_version (stderr, "");
3995       if (! quiet_flag)
3996         print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
3997     }
3998
3999   compile_file (filename);
4000
4001 #if !defined(OS2) && !defined(VMS) && !defined(_WIN32)
4002   if (flag_print_mem)
4003     {
4004       char *lim = (char *) sbrk (0);
4005
4006       fprintf (stderr, "Data size %d.\n",
4007                lim - (char *) &environ);
4008       fflush (stderr);
4009
4010 #ifdef USG
4011       system ("ps -l 1>&2");
4012 #else /* not USG */
4013       system ("ps v");
4014 #endif /* not USG */
4015     }
4016 #endif /* not OS2 and not VMS and not _WIN32 */
4017
4018   if (errorcount)
4019     exit (FATAL_EXIT_CODE);
4020   if (sorrycount)
4021     exit (FATAL_EXIT_CODE);
4022   exit (SUCCESS_EXIT_CODE);
4023   return 0;
4024 }
4025 \f
4026 /* Decode -m switches.  */
4027
4028 /* Here is a table, controlled by the tm.h file, listing each -m switch
4029    and which bits in `target_switches' it should set or clear.
4030    If VALUE is positive, it is bits to set.
4031    If VALUE is negative, -VALUE is bits to clear.
4032    (The sign bit is not used so there is no confusion.)  */
4033
4034 struct {char *name; int value;} target_switches []
4035   = TARGET_SWITCHES;
4036
4037 /* This table is similar, but allows the switch to have a value.  */
4038
4039 #ifdef TARGET_OPTIONS
4040 struct {char *prefix; char ** variable;} target_options []
4041   = TARGET_OPTIONS;
4042 #endif
4043
4044 /* Decode the switch -mNAME.  */
4045
4046 void
4047 set_target_switch (name)
4048      char *name;
4049 {
4050   register int j;
4051   int valid = 0;
4052
4053   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4054     if (!strcmp (target_switches[j].name, name))
4055       {
4056         if (target_switches[j].value < 0)
4057           target_flags &= ~-target_switches[j].value;
4058         else
4059           target_flags |= target_switches[j].value;
4060         valid = 1;
4061       }
4062
4063 #ifdef TARGET_OPTIONS
4064   if (!valid)
4065     for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4066       {
4067         int len = strlen (target_options[j].prefix);
4068         if (!strncmp (target_options[j].prefix, name, len))
4069           {
4070             *target_options[j].variable = name + len;
4071             valid = 1;
4072           }
4073       }
4074 #endif
4075
4076   if (!valid)
4077     error ("Invalid option `%s'", name);
4078 }
4079 \f
4080 /* Print version information to FILE.
4081    Each line begins with INDENT (for the case where FILE is the
4082    assembler output file).  */
4083
4084 void
4085 print_version (file, indent)
4086      FILE *file;
4087      char *indent;
4088 {
4089   fprintf (file, "%s%s%s version %s", indent, *indent != 0 ? " " : "",
4090            language_string, version_string);
4091   fprintf (file, " (%s)", TARGET_NAME);
4092 #ifdef __GNUC__
4093 #ifndef __VERSION__
4094 #define __VERSION__ "[unknown]"
4095 #endif
4096   fprintf (file, " compiled by GNU C version %s.\n", __VERSION__);
4097 #else
4098   fprintf (file, " compiled by CC.\n");
4099 #endif
4100 }
4101
4102 /* Print an option value and return the adjusted position in the line.
4103    ??? We don't handle error returns from fprintf (disk full).  */
4104
4105 int
4106 print_single_switch (file, pos, max, indent, sep, term, type, name)
4107      FILE *file;
4108      int pos, max;
4109      char *indent, *sep, *term, *type, *name;
4110 {
4111   if (pos != 0
4112       && pos + strlen (sep) + strlen (type) + strlen (name) > max)
4113     {
4114       fprintf (file, "%s", term);
4115       pos = 0;
4116     }
4117   if (pos == 0)
4118     {
4119       pos = fprintf (file, "%s", indent);
4120     }
4121   pos += fprintf (file, "%s%s%s", sep, type, name);
4122   return pos;
4123 }
4124      
4125 /* Print active target switches to FILE.
4126    POS is the current cursor position and MAX is the size of a "line".
4127    Each line begins with INDENT and ends with TERM.
4128    Each switch is separated from the next by SEP.  */
4129
4130 void
4131 print_switch_values (file, pos, max, indent, sep, term)
4132      FILE *file;
4133      int pos, max;
4134      char *indent, *sep, *term;
4135 {
4136   int j, flags;
4137   char **p;
4138
4139   /* Print the options as passed.  */
4140
4141   pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4142                              "options passed: ", "");
4143
4144   for (p = &save_argv[1]; *p != NULL; p++)
4145     if (**p == '-')
4146       {
4147         /* Ignore these.  */
4148         if (strcmp (*p, "-o") == 0)
4149           {
4150             if (p[1] != NULL)
4151               p++;
4152             continue;
4153           }
4154         if (strcmp (*p, "-quiet") == 0)
4155           continue;
4156         if (strcmp (*p, "-version") == 0)
4157           continue;
4158         if ((*p)[1] == 'd')
4159           continue;
4160
4161         pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4162       }
4163   if (pos > 0)
4164     fprintf (file, "%s", term);
4165
4166   /* Print the -f and -m options that have been enabled.
4167      We don't handle language specific options but printing argv
4168      should suffice.  */
4169
4170   pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4171                              "options enabled: ", "");
4172
4173   for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
4174     if (*f_options[j].variable == f_options[j].on_value)
4175       pos = print_single_switch (file, pos, max, indent, sep, term,
4176                                  "-f", f_options[j].string);
4177
4178   /* Print target specific options.  */
4179
4180   flags = target_flags;
4181   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4182     if (target_switches[j].name[0] != '\0'
4183         && target_switches[j].value > 0
4184         && ((target_switches[j].value & target_flags)
4185             == target_switches[j].value))
4186       {
4187         pos = print_single_switch (file, pos, max, indent, sep, term,
4188                                    "-m", target_switches[j].name);
4189         flags &= ~ target_switches[j].value;
4190       }
4191
4192 #ifdef TARGET_OPTIONS
4193   for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4194     if (*target_options[j].variable != NULL)
4195       {
4196         char prefix[256];
4197         sprintf (prefix, "-m%s", target_options[j].prefix);
4198         pos = print_single_switch (file, pos, max, indent, sep, term,
4199                                    prefix, *target_options[j].variable);
4200       }
4201 #endif
4202
4203   fprintf (file, "%s", term);
4204 }