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