OSDN Git Service

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