OSDN Git Service

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