OSDN Git Service

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