OSDN Git Service

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