OSDN Git Service

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