OSDN Git Service

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