OSDN Git Service

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