OSDN Git Service

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