OSDN Git Service

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