OSDN Git Service

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