OSDN Git Service

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