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