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