Initial revision
[official-gcc.git] / gcc / toplev.c
blob821dab62158bc08c82720314f395c3c6910a9bd2
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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.
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.
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. */
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. */
26 #include "config.h"
27 #ifdef __STDC__
28 #include <stdarg.h>
29 #else
30 #include <varargs.h>
31 #endif
32 #include <stdio.h>
33 #include <signal.h>
34 #include <setjmp.h>
35 #include <sys/types.h>
36 #include <ctype.h>
37 #include <sys/stat.h>
39 #ifndef _WIN32
40 #ifdef USG
41 #undef FLOAT
42 #include <sys/param.h>
43 /* This is for hpux. It is a real screw. They should change hpux. */
44 #undef FLOAT
45 #include <sys/times.h>
46 #include <time.h> /* Correct for hpux at least. Is it good on other USG? */
47 #undef FFS /* Some systems define this in param.h. */
48 #else
49 #ifndef VMS
50 #include <sys/time.h>
51 #include <sys/resource.h>
52 #endif
53 #endif
54 #endif
56 #include "input.h"
57 #include "tree.h"
58 #include "rtl.h"
59 #include "flags.h"
60 #include "insn-attr.h"
61 #include "defaults.h"
62 #include "output.h"
63 #include "bytecode.h"
64 #include "bc-emit.h"
65 #include "except.h"
67 #ifdef XCOFF_DEBUGGING_INFO
68 #include "xcoffout.h"
69 #endif
71 #ifdef VMS
72 /* The extra parameters substantially improve the I/O performance. */
73 static FILE *
74 vms_fopen (fname, type)
75 char * fname;
76 char * type;
78 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
79 fixed arguments, which matches ANSI's specification but not VAXCRTL's
80 pre-ANSI implementation. This hack circumvents the mismatch problem. */
81 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
83 if (*type == 'w')
84 return (*vmslib_fopen) (fname, type, "mbc=32",
85 "deq=64", "fop=tef", "shr=nil");
86 else
87 return (*vmslib_fopen) (fname, type, "mbc=32");
89 #define fopen vms_fopen
90 #endif /* VMS */
92 #ifndef DEFAULT_GDB_EXTENSIONS
93 #define DEFAULT_GDB_EXTENSIONS 1
94 #endif
96 /* If more than one debugging type is supported, you must define
97 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
99 This is one long line cause VAXC can't handle a \-newline. */
100 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
101 #ifndef PREFERRED_DEBUGGING_TYPE
102 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
103 #endif /* no PREFERRED_DEBUGGING_TYPE */
104 #else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
105 so the following code needn't care. */
106 #ifdef DBX_DEBUGGING_INFO
107 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
108 #endif
109 #ifdef SDB_DEBUGGING_INFO
110 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
111 #endif
112 #ifdef DWARF_DEBUGGING_INFO
113 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
114 #endif
115 #ifdef DWARF2_DEBUGGING_INFO
116 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
117 #endif
118 #ifdef XCOFF_DEBUGGING_INFO
119 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
120 #endif
121 #endif /* More than one debugger format enabled. */
123 /* If still not defined, must have been because no debugging formats
124 are supported. */
125 #ifndef PREFERRED_DEBUGGING_TYPE
126 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
127 #endif
129 extern int rtx_equal_function_value_matters;
131 #if ! (defined (VMS) || defined (OS2))
132 extern char **environ;
133 #endif
134 extern char *version_string, *language_string;
136 /* Carry information from ASM_DECLARE_OBJECT_NAME
137 to ASM_FINISH_DECLARE_OBJECT. */
139 extern int size_directive_output;
140 extern tree last_assemble_variable_decl;
142 extern void init_lex ();
143 extern void init_decl_processing ();
144 extern void init_obstacks ();
145 extern void init_tree_codes ();
146 extern void init_rtl ();
147 extern void init_regs ();
148 extern void init_optabs ();
149 extern void init_stmt ();
150 extern void init_reg_sets ();
151 extern void dump_flow_info ();
152 extern void dump_sched_info ();
153 extern void dump_local_alloc ();
154 extern void regset_release_memory ();
156 void rest_of_decl_compilation ();
157 void error_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
158 void error_with_decl PVPROTO((tree decl, char *s, ...));
159 void error_for_asm PVPROTO((rtx insn, char *s, ...));
160 void error PVPROTO((char *s, ...));
161 void fatal PVPROTO((char *s, ...));
162 void warning_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
163 void warning_with_decl PVPROTO((tree decl, char *s, ...));
164 void warning_for_asm PVPROTO((rtx insn, char *s, ...));
165 void warning PVPROTO((char *s, ...));
166 void pedwarn PVPROTO((char *s, ...));
167 void pedwarn_with_decl PVPROTO((tree decl, char *s, ...));
168 void pedwarn_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
169 void sorry PVPROTO((char *s, ...));
170 void really_sorry PVPROTO((char *s, ...));
171 void fancy_abort ();
172 #ifndef abort
173 void abort ();
174 #endif
175 void set_target_switch ();
176 static char *decl_name ();
178 void print_version ();
179 int print_single_switch ();
180 void print_switch_values ();
181 /* Length of line when printing switch values. */
182 #define MAX_LINE 75
184 #ifdef __alpha
185 extern char *sbrk ();
186 #endif
188 /* Name of program invoked, sans directories. */
190 char *progname;
192 /* Copy of arguments to main. */
193 int save_argc;
194 char **save_argv;
196 /* Name of current original source file (what was input to cpp).
197 This comes from each #-command in the actual input. */
199 char *input_filename;
201 /* Name of top-level original source file (what was input to cpp).
202 This comes from the #-command at the beginning of the actual input.
203 If there isn't any there, then this is the cc1 input file name. */
205 char *main_input_filename;
207 #if !USE_CPPLIB
208 /* Stream for reading from the input file. */
209 FILE *finput;
210 #endif
212 /* Current line number in real source file. */
214 int lineno;
216 /* Stack of currently pending input files. */
218 struct file_stack *input_file_stack;
220 /* Incremented on each change to input_file_stack. */
221 int input_file_stack_tick;
223 /* FUNCTION_DECL for function now being parsed or compiled. */
225 extern tree current_function_decl;
227 /* Name to use as base of names for dump output files. */
229 char *dump_base_name;
231 /* Bit flags that specify the machine subtype we are compiling for.
232 Bits are tested using macros TARGET_... defined in the tm.h file
233 and set by `-m...' switches. Must be defined in rtlanal.c. */
235 extern int target_flags;
237 /* Flags saying which kinds of debugging dump have been requested. */
239 int rtl_dump = 0;
240 int rtl_dump_and_exit = 0;
241 int jump_opt_dump = 0;
242 int cse_dump = 0;
243 int loop_dump = 0;
244 int cse2_dump = 0;
245 int branch_prob_dump = 0;
246 int flow_dump = 0;
247 int combine_dump = 0;
248 int regmove_dump = 0;
249 int sched_dump = 0;
250 int local_reg_dump = 0;
251 int global_reg_dump = 0;
252 int sched2_dump = 0;
253 int jump2_opt_dump = 0;
254 int dbr_sched_dump = 0;
255 int flag_print_asm_name = 0;
256 int stack_reg_dump = 0;
258 /* Name for output file of assembly code, specified with -o. */
260 char *asm_file_name;
262 /* Value of the -G xx switch, and whether it was passed or not. */
263 int g_switch_value;
264 int g_switch_set;
266 /* Type(s) of debugging information we are producing (if any).
267 See flags.h for the definitions of the different possible
268 types of debugging information. */
269 enum debug_info_type write_symbols = NO_DEBUG;
271 /* Level of debugging information we are producing. See flags.h
272 for the definitions of the different possible levels. */
273 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
275 /* Nonzero means use GNU-only extensions in the generated symbolic
276 debugging information. */
277 /* Currently, this only has an effect when write_symbols is set to
278 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
279 int use_gnu_debug_info_extensions = 0;
281 /* Nonzero means do optimizations. -O.
282 Particular numeric values stand for particular amounts of optimization;
283 thus, -O2 stores 2 here. However, the optimizations beyond the basic
284 ones are not controlled directly by this variable. Instead, they are
285 controlled by individual `flag_...' variables that are defaulted
286 based on this variable. */
288 int optimize = 0;
290 /* Number of error messages and warning messages so far. */
292 int errorcount = 0;
293 int warningcount = 0;
294 int sorrycount = 0;
296 /* Flag to output bytecode instead of native assembler */
297 int output_bytecode = 0;
299 /* Pointer to function to compute the name to use to print a declaration.
300 DECL is the declaration in question.
301 VERBOSITY determines what information will be printed:
302 0: DECL_NAME, demangled as necessary.
303 1: and scope information.
304 2: and any other information that might be interesting, such as function
305 parameter types in C++. */
307 char *(*decl_printable_name) (/* tree decl, int verbosity */);
309 /* Pointer to function to compute rtl for a language-specific tree code. */
311 struct rtx_def *(*lang_expand_expr) ();
313 /* Pointer to function to finish handling an incomplete decl at the
314 end of compilation. */
316 void (*incomplete_decl_finalize_hook) () = 0;
318 /* Highest label number used at the end of reload. */
320 int max_label_num_after_reload;
322 /* Nonzero if generating code to do profiling. */
324 int profile_flag = 0;
326 /* Nonzero if generating code to do profiling on a line-by-line basis. */
328 int profile_block_flag;
330 /* Nonzero if generating code to profile program flow graph arcs. */
332 int profile_arc_flag = 0;
334 /* Nonzero if generating info for gcov to calculate line test coverage. */
336 int flag_test_coverage = 0;
338 /* Nonzero indicates that branch taken probabilities should be calculated. */
340 int flag_branch_probabilities = 0;
342 /* Nonzero for -pedantic switch: warn about anything
343 that standard spec forbids. */
345 int pedantic = 0;
347 /* Temporarily suppress certain warnings.
348 This is set while reading code from a system header file. */
350 int in_system_header = 0;
352 /* Nonzero means do stupid register allocation.
353 Currently, this is 1 if `optimize' is 0. */
355 int obey_regdecls = 0;
357 /* Don't print functions as they are compiled and don't print
358 times taken by the various passes. -quiet. */
360 int quiet_flag = 0;
362 /* -f flags. */
364 /* Nonzero means `char' should be signed. */
366 int flag_signed_char;
368 /* Nonzero means give an enum type only as many bytes as it needs. */
370 int flag_short_enums;
372 /* Nonzero for -fcaller-saves: allocate values in regs that need to
373 be saved across function calls, if that produces overall better code.
374 Optional now, so people can test it. */
376 #ifdef DEFAULT_CALLER_SAVES
377 int flag_caller_saves = 1;
378 #else
379 int flag_caller_saves = 0;
380 #endif
382 /* Nonzero if structures and unions should be returned in memory.
384 This should only be defined if compatibility with another compiler or
385 with an ABI is needed, because it results in slower code. */
387 #ifndef DEFAULT_PCC_STRUCT_RETURN
388 #define DEFAULT_PCC_STRUCT_RETURN 1
389 #endif
391 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
393 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
395 /* Nonzero for -fforce-mem: load memory value into a register
396 before arithmetic on it. This makes better cse but slower compilation. */
398 int flag_force_mem = 0;
400 /* Nonzero for -fforce-addr: load memory address into a register before
401 reference to memory. This makes better cse but slower compilation. */
403 int flag_force_addr = 0;
405 /* Nonzero for -fdefer-pop: don't pop args after each function call;
406 instead save them up to pop many calls' args with one insns. */
408 int flag_defer_pop = 0;
410 /* Nonzero for -ffloat-store: don't allocate floats and doubles
411 in extended-precision registers. */
413 int flag_float_store = 0;
415 /* Nonzero for -fcse-follow-jumps:
416 have cse follow jumps to do a more extensive job. */
418 int flag_cse_follow_jumps;
420 /* Nonzero for -fcse-skip-blocks:
421 have cse follow a branch around a block. */
422 int flag_cse_skip_blocks;
424 /* Nonzero for -fexpensive-optimizations:
425 perform miscellaneous relatively-expensive optimizations. */
426 int flag_expensive_optimizations;
428 /* Nonzero for -fthread-jumps:
429 have jump optimize output of loop. */
431 int flag_thread_jumps;
433 /* Nonzero enables strength-reduction in loop.c. */
435 int flag_strength_reduce = 0;
437 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
438 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
439 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
440 unrolled. */
442 int flag_unroll_loops;
444 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
445 This is generally not a win. */
447 int flag_unroll_all_loops;
449 /* Nonzero for -fwritable-strings:
450 store string constants in data segment and don't uniquize them. */
452 int flag_writable_strings = 0;
454 /* Nonzero means don't put addresses of constant functions in registers.
455 Used for compiling the Unix kernel, where strange substitutions are
456 done on the assembly output. */
458 int flag_no_function_cse = 0;
460 /* Nonzero for -fomit-frame-pointer:
461 don't make a frame pointer in simple functions that don't require one. */
463 int flag_omit_frame_pointer = 0;
465 /* Nonzero means place each function into its own section on those platforms
466 which support arbitrary section names and unlimited numbers of sections. */
468 int flag_function_sections = 0;
470 /* Nonzero to inhibit use of define_optimization peephole opts. */
472 int flag_no_peephole = 0;
474 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
475 operations in the interest of optimization. For example it allows
476 GCC to assume arguments to sqrt are nonnegative numbers, allowing
477 faster code for sqrt to be generated. */
479 int flag_fast_math = 0;
481 /* Nonzero means all references through pointers are volatile. */
483 int flag_volatile;
485 /* Nonzero means treat all global and extern variables as global. */
487 int flag_volatile_global;
489 /* Nonzero means just do syntax checking; don't output anything. */
491 int flag_syntax_only = 0;
493 /* Nonzero means to rerun cse after loop optimization. This increases
494 compilation time about 20% and picks up a few more common expressions. */
496 static int flag_rerun_cse_after_loop;
498 /* Nonzero for -finline-functions: ok to inline functions that look like
499 good inline candidates. */
501 int flag_inline_functions;
503 /* Nonzero for -fkeep-inline-functions: even if we make a function
504 go inline everywhere, keep its definition around for debugging
505 purposes. */
507 int flag_keep_inline_functions;
509 /* Nonzero means that functions will not be inlined. */
511 int flag_no_inline;
513 /* Nonzero means that we should emit static const variables
514 regardless of whether or not optimization is turned on. */
516 int flag_keep_static_consts = 1;
518 /* Nonzero means we should be saving declaration info into a .X file. */
520 int flag_gen_aux_info = 0;
522 /* Specified name of aux-info file. */
524 static char *aux_info_file_name;
526 /* Nonzero means make the text shared if supported. */
528 int flag_shared_data;
530 /* Nonzero means schedule into delayed branch slots if supported. */
532 int flag_delayed_branch;
534 /* Nonzero if we are compiling pure (sharable) code.
535 Value is 1 if we are doing reasonable (i.e. simple
536 offset into offset table) pic. Value is 2 if we can
537 only perform register offsets. */
539 int flag_pic;
541 /* Nonzero means generate extra code for exception handling and enable
542 exception handling. */
544 int flag_exceptions = 1;
546 /* Nonzero means don't place uninitialized global data in common storage
547 by default. */
549 int flag_no_common;
551 /* Nonzero means pretend it is OK to examine bits of target floats,
552 even if that isn't true. The resulting code will have incorrect constants,
553 but the same series of instructions that the native compiler would make. */
555 int flag_pretend_float;
557 /* Nonzero means change certain warnings into errors.
558 Usually these are warnings about failure to conform to some standard. */
560 int flag_pedantic_errors = 0;
562 /* flag_schedule_insns means schedule insns within basic blocks (before
563 local_alloc).
564 flag_schedule_insns_after_reload means schedule insns after
565 global_alloc. */
567 int flag_schedule_insns = 0;
568 int flag_schedule_insns_after_reload = 0;
570 #ifdef HAIFA
571 /* The following flags have effect only for scheduling before register
572 allocation:
574 flag_schedule_interblock means schedule insns accross basic blocks.
575 flag_schedule_speculative means allow speculative motion of non-load insns.
576 flag_schedule_speculative_load means allow speculative motion of some
577 load insns.
578 flag_schedule_speculative_load_dangerous allows speculative motion of more
579 load insns.
580 flag_schedule_reverse_before_reload means try to reverse original order
581 of insns (S).
582 flag_schedule_reverse_after_reload means try to reverse original order
583 of insns (R). */
585 int flag_schedule_interblock = 1;
586 int flag_schedule_speculative = 1;
587 int flag_schedule_speculative_load = 0;
588 int flag_schedule_speculative_load_dangerous = 0;
589 int flag_schedule_reverse_before_reload = 0;
590 int flag_schedule_reverse_after_reload = 0;
593 /* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
594 by a cheaper branch, on a count register. */
595 int flag_branch_on_count_reg;
596 #endif /* HAIFA */
599 /* -finhibit-size-directive inhibits output of .size for ELF.
600 This is used only for compiling crtstuff.c,
601 and it may be extended to other effects
602 needed for crtstuff.c on other systems. */
603 int flag_inhibit_size_directive = 0;
605 /* -fverbose-asm causes extra commentary information to be produced in
606 the generated assembly code (to make it more readable). This option
607 is generally only of use to those who actually need to read the
608 generated assembly code (perhaps while debugging the compiler itself).
609 -fverbose-asm is the default. -fno-verbose-asm causes the extra information
610 to be omitted and is useful when comparing two assembler files. */
612 int flag_verbose_asm = 1;
614 /* -dA causes debug commentary information to be produced in
615 the generated assembly code (to make it more readable). This option
616 is generally only of use to those who actually need to read the
617 generated assembly code (perhaps while debugging the compiler itself).
618 Currently, this switch is only used by dwarfout.c; however, it is intended
619 to be a catchall for printing debug information in the assembler file. */
621 int flag_debug_asm = 0;
623 /* -fgnu-linker specifies use of the GNU linker for initializations.
624 (Or, more generally, a linker that handles initializations.)
625 -fno-gnu-linker says that collect2 will be used. */
626 #ifdef USE_COLLECT2
627 int flag_gnu_linker = 0;
628 #else
629 int flag_gnu_linker = 1;
630 #endif
632 /* Tag all structures with __attribute__(packed) */
633 int flag_pack_struct = 0;
635 /* Emit code to check for stack overflow; also may cause large objects
636 to be allocated dynamically. */
637 int flag_stack_check;
639 /* -fcheck-memory-usage causes extra code to be generated in order to check
640 memory accesses. This is used by a detector of bad memory accesses such
641 as Checker. */
642 int flag_check_memory_usage = 0;
644 /* -fprefix-function-name causes function name to be prefixed. This
645 can be used with -fcheck-memory-usage to isolate code compiled with
646 -fcheck-memory-usage. */
647 int flag_prefix_function_name = 0;
649 int flag_regmove = 0;
651 /* 1 if alias checking is on (by default, when -O). */
652 int flag_alias_check = 0;
654 /* 0 if pointer arguments may alias each other. True in C.
655 1 if pointer arguments may not alias each other but may alias
656 global variables.
657 2 if pointer arguments may not alias each other and may not
658 alias global variables. True in Fortran.
659 This defaults to 0 for C. */
660 int flag_argument_noalias = 0;
662 /* Table of language-independent -f options.
663 STRING is the option name. VARIABLE is the address of the variable.
664 ON_VALUE is the value to store in VARIABLE
665 if `-fSTRING' is seen as an option.
666 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
668 struct { char *string; int *variable; int on_value;} f_options[] =
670 {"float-store", &flag_float_store, 1},
671 {"volatile", &flag_volatile, 1},
672 {"volatile-global", &flag_volatile_global, 1},
673 {"defer-pop", &flag_defer_pop, 1},
674 {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
675 {"cse-follow-jumps", &flag_cse_follow_jumps, 1},
676 {"cse-skip-blocks", &flag_cse_skip_blocks, 1},
677 {"expensive-optimizations", &flag_expensive_optimizations, 1},
678 {"thread-jumps", &flag_thread_jumps, 1},
679 {"strength-reduce", &flag_strength_reduce, 1},
680 {"unroll-loops", &flag_unroll_loops, 1},
681 {"unroll-all-loops", &flag_unroll_all_loops, 1},
682 {"writable-strings", &flag_writable_strings, 1},
683 {"peephole", &flag_no_peephole, 0},
684 {"force-mem", &flag_force_mem, 1},
685 {"force-addr", &flag_force_addr, 1},
686 {"function-cse", &flag_no_function_cse, 0},
687 {"inline-functions", &flag_inline_functions, 1},
688 {"keep-inline-functions", &flag_keep_inline_functions, 1},
689 {"inline", &flag_no_inline, 0},
690 {"keep-static-consts", &flag_keep_static_consts, 1},
691 {"syntax-only", &flag_syntax_only, 1},
692 {"shared-data", &flag_shared_data, 1},
693 {"caller-saves", &flag_caller_saves, 1},
694 {"pcc-struct-return", &flag_pcc_struct_return, 1},
695 {"reg-struct-return", &flag_pcc_struct_return, 0},
696 {"delayed-branch", &flag_delayed_branch, 1},
697 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1},
698 {"pretend-float", &flag_pretend_float, 1},
699 {"schedule-insns", &flag_schedule_insns, 1},
700 {"schedule-insns2", &flag_schedule_insns_after_reload, 1},
701 #ifdef HAIFA
702 {"sched-interblock",&flag_schedule_interblock, 1},
703 {"sched-spec",&flag_schedule_speculative, 1},
704 {"sched-spec-load",&flag_schedule_speculative_load, 1},
705 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1},
706 {"sched-reverse-S",&flag_schedule_reverse_before_reload, 1},
707 {"sched-reverse-R",&flag_schedule_reverse_after_reload, 1},
708 {"branch-count-reg",&flag_branch_on_count_reg, 1},
709 #endif /* HAIFA */
710 {"pic", &flag_pic, 1},
711 {"PIC", &flag_pic, 2},
712 {"exceptions", &flag_exceptions, 1},
713 {"sjlj-exceptions", &exceptions_via_longjmp, 1},
714 {"asynchronous-exceptions", &asynchronous_exceptions, 1},
715 {"profile-arcs", &profile_arc_flag, 1},
716 {"test-coverage", &flag_test_coverage, 1},
717 {"branch-probabilities", &flag_branch_probabilities, 1},
718 {"fast-math", &flag_fast_math, 1},
719 {"common", &flag_no_common, 0},
720 {"inhibit-size-directive", &flag_inhibit_size_directive, 1},
721 {"function-sections", &flag_function_sections, 1},
722 {"verbose-asm", &flag_verbose_asm, 1},
723 {"gnu-linker", &flag_gnu_linker, 1},
724 {"regmove", &flag_regmove, 1},
725 {"pack-struct", &flag_pack_struct, 1},
726 {"stack-check", &flag_stack_check, 1},
727 {"bytecode", &output_bytecode, 1},
728 {"alias-check", &flag_alias_check, 1},
729 {"argument-alias", &flag_argument_noalias, 0},
730 {"argument-noalias", &flag_argument_noalias, 1},
731 {"argument-noalias-global", &flag_argument_noalias, 2},
732 {"check-memory-usage", &flag_check_memory_usage, 1},
733 {"prefix-function-name", &flag_prefix_function_name, 1}
736 /* Table of language-specific options. */
738 char *lang_options[] =
740 "-ansi",
741 "-fallow-single-precision",
743 "-fsigned-bitfields",
744 "-funsigned-bitfields",
745 "-fno-signed-bitfields",
746 "-fno-unsigned-bitfields",
747 "-fsigned-char",
748 "-funsigned-char",
749 "-fno-signed-char",
750 "-fno-unsigned-char",
752 "-ftraditional",
753 "-traditional",
754 "-fnotraditional",
755 "-fno-traditional",
757 "-fasm",
758 "-fno-asm",
759 "-fbuiltin",
760 "-fno-builtin",
761 "-fhosted",
762 "-fno-hosted",
763 "-ffreestanding",
764 "-fno-freestanding",
765 "-fcond-mismatch",
766 "-fno-cond-mismatch",
767 "-fdollars-in-identifiers",
768 "-fno-dollars-in-identifiers",
769 "-fident",
770 "-fno-ident",
771 "-fshort-double",
772 "-fno-short-double",
773 "-fshort-enums",
774 "-fno-short-enums",
776 "-Wall",
777 "-Wbad-function-cast",
778 "-Wno-bad-function-cast",
779 "-Wcast-qual",
780 "-Wno-cast-qual",
781 "-Wchar-subscripts",
782 "-Wno-char-subscripts",
783 "-Wcomment",
784 "-Wno-comment",
785 "-Wcomments",
786 "-Wno-comments",
787 "-Wconversion",
788 "-Wno-conversion",
789 "-Wformat",
790 "-Wno-format",
791 "-Wimport",
792 "-Wno-import",
793 "-Wimplicit",
794 "-Wno-implicit",
795 "-Wmain",
796 "-Wno-main",
797 "-Wmissing-braces",
798 "-Wno-missing-braces",
799 "-Wmissing-declarations",
800 "-Wno-missing-declarations",
801 "-Wmissing-prototypes",
802 "-Wno-missing-prototypes",
803 "-Wnested-externs",
804 "-Wno-nested-externs",
805 "-Wparentheses",
806 "-Wno-parentheses",
807 "-Wpointer-arith",
808 "-Wno-pointer-arith",
809 "-Wredundant-decls",
810 "-Wno-redundant-decls",
811 "-Wsign-compare",
812 "-Wno-sign-compare",
813 "-Wstrict-prototypes",
814 "-Wno-strict-prototypes",
815 "-Wtraditional",
816 "-Wno-traditional",
817 "-Wtrigraphs",
818 "-Wno-trigraphs",
819 "-Wundef",
820 "-Wno-undef",
821 "-Wwrite-strings",
822 "-Wno-write-strings",
824 /* these are for obj c */
825 "-lang-objc",
826 "-gen-decls",
827 "-fgnu-runtime",
828 "-fno-gnu-runtime",
829 "-fnext-runtime",
830 "-fno-next-runtime",
831 "-Wselector",
832 "-Wno-selector",
833 "-Wprotocol",
834 "-Wno-protocol",
836 #include "options.h"
840 /* Options controlling warnings */
842 /* Don't print warning messages. -w. */
844 int inhibit_warnings = 0;
846 /* Print various extra warnings. -W. */
848 int extra_warnings = 0;
850 /* Treat warnings as errors. -Werror. */
852 int warnings_are_errors = 0;
854 /* Nonzero to warn about unused local variables. */
856 int warn_unused;
858 /* Nonzero to warn about variables used before they are initialized. */
860 int warn_uninitialized;
862 /* Nonzero means warn about all declarations which shadow others. */
864 int warn_shadow;
866 /* Warn if a switch on an enum fails to have a case for every enum value. */
868 int warn_switch;
870 /* Nonzero means warn about function definitions that default the return type
871 or that use a null return and have a return-type other than void. */
873 int warn_return_type;
875 /* Nonzero means warn about pointer casts that increase the required
876 alignment of the target type (and might therefore lead to a crash
877 due to a misaligned access). */
879 int warn_cast_align;
881 /* Nonzero means warn about any identifiers that match in the first N
882 characters. The value N is in `id_clash_len'. */
884 int warn_id_clash;
885 unsigned id_clash_len;
887 /* Nonzero means warn about any objects definitions whose size is larger
888 than N bytes. Also want about function definitions whose returned
889 values are larger than N bytes. The value N is in `larger_than_size'. */
891 int warn_larger_than;
892 unsigned larger_than_size;
894 /* Nonzero means warn if inline function is too large. */
896 int warn_inline;
898 /* Warn if a function returns an aggregate,
899 since there are often incompatible calling conventions for doing this. */
901 int warn_aggregate_return;
903 /* Likewise for -W. */
905 struct { char *string; int *variable; int on_value;} W_options[] =
907 {"unused", &warn_unused, 1},
908 {"error", &warnings_are_errors, 1},
909 {"shadow", &warn_shadow, 1},
910 {"switch", &warn_switch, 1},
911 {"aggregate-return", &warn_aggregate_return, 1},
912 {"cast-align", &warn_cast_align, 1},
913 {"uninitialized", &warn_uninitialized, 1},
914 {"inline", &warn_inline, 1}
917 /* Output files for assembler code (real compiler output)
918 and debugging dumps. */
920 FILE *asm_out_file;
921 FILE *aux_info_file;
922 FILE *rtl_dump_file;
923 FILE *jump_opt_dump_file;
924 FILE *cse_dump_file;
925 FILE *loop_dump_file;
926 FILE *cse2_dump_file;
927 FILE *branch_prob_dump_file;
928 FILE *flow_dump_file;
929 FILE *combine_dump_file;
930 FILE *regmove_dump_file;
931 FILE *sched_dump_file;
932 FILE *local_reg_dump_file;
933 FILE *global_reg_dump_file;
934 FILE *sched2_dump_file;
935 FILE *jump2_opt_dump_file;
936 FILE *dbr_sched_dump_file;
937 FILE *stack_reg_dump_file;
939 /* Time accumulators, to count the total time spent in various passes. */
941 int parse_time;
942 int varconst_time;
943 int integration_time;
944 int jump_time;
945 int cse_time;
946 int loop_time;
947 int cse2_time;
948 int branch_prob_time;
949 int flow_time;
950 int combine_time;
951 int regmove_time;
952 int sched_time;
953 int local_alloc_time;
954 int global_alloc_time;
955 int sched2_time;
956 int dbr_sched_time;
957 int shorten_branch_time;
958 int stack_reg_time;
959 int final_time;
960 int symout_time;
961 int dump_time;
963 /* Return time used so far, in microseconds. */
966 get_run_time ()
968 #ifndef _WIN32
969 #ifdef USG
970 struct tms tms;
971 #else
972 #ifndef VMS
973 struct rusage rusage;
974 #else
975 struct
977 int proc_user_time;
978 int proc_system_time;
979 int child_user_time;
980 int child_system_time;
981 } vms_times;
982 #endif
983 #endif
984 #endif
986 if (quiet_flag)
987 return 0;
988 #ifdef _WIN32
989 if (clock() < 0)
990 return 0;
991 else
992 return (clock() * 1000);
993 #else /* not _WIN32 */
994 #ifdef USG
995 times (&tms);
996 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
997 #else
998 #ifndef VMS
999 getrusage (0, &rusage);
1000 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1001 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1002 #else /* VMS */
1003 times (&vms_times);
1004 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
1005 #endif
1006 #endif
1007 #endif
1010 #define TIMEVAR(VAR, BODY) \
1011 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1013 void
1014 print_time (str, total)
1015 char *str;
1016 int total;
1018 fprintf (stderr,
1019 "time in %s: %d.%06d\n",
1020 str, total / 1000000, total % 1000000);
1023 /* Count an error or warning. Return 1 if the message should be printed. */
1026 count_error (warningp)
1027 int warningp;
1029 if (warningp && inhibit_warnings)
1030 return 0;
1032 if (warningp && !warnings_are_errors)
1033 warningcount++;
1034 else
1036 static int warning_message = 0;
1038 if (warningp && !warning_message)
1040 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
1041 warning_message = 1;
1043 errorcount++;
1046 return 1;
1049 /* Print a fatal error message. NAME is the text.
1050 Also include a system error message based on `errno'. */
1052 void
1053 pfatal_with_name (name)
1054 char *name;
1056 fprintf (stderr, "%s: ", progname);
1057 perror (name);
1058 exit (FATAL_EXIT_CODE);
1061 void
1062 fatal_io_error (name)
1063 char *name;
1065 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
1066 exit (FATAL_EXIT_CODE);
1069 /* Called to give a better error message for a bad insn rather than
1070 just calling abort(). */
1072 void
1073 fatal_insn (message, insn)
1074 char *message;
1075 rtx insn;
1077 if (!output_bytecode)
1079 error (message);
1080 debug_rtx (insn);
1082 if (asm_out_file)
1083 fflush (asm_out_file);
1084 if (aux_info_file)
1085 fflush (aux_info_file);
1086 if (rtl_dump_file)
1087 fflush (rtl_dump_file);
1088 if (jump_opt_dump_file)
1089 fflush (jump_opt_dump_file);
1090 if (cse_dump_file)
1091 fflush (cse_dump_file);
1092 if (loop_dump_file)
1093 fflush (loop_dump_file);
1094 if (cse2_dump_file)
1095 fflush (cse2_dump_file);
1096 if (flow_dump_file)
1097 fflush (flow_dump_file);
1098 if (combine_dump_file)
1099 fflush (combine_dump_file);
1100 if (regmove_dump_file)
1101 fflush (regmove_dump_file);
1102 if (sched_dump_file)
1103 fflush (sched_dump_file);
1104 if (local_reg_dump_file)
1105 fflush (local_reg_dump_file);
1106 if (global_reg_dump_file)
1107 fflush (global_reg_dump_file);
1108 if (sched2_dump_file)
1109 fflush (sched2_dump_file);
1110 if (jump2_opt_dump_file)
1111 fflush (jump2_opt_dump_file);
1112 if (dbr_sched_dump_file)
1113 fflush (dbr_sched_dump_file);
1114 if (stack_reg_dump_file)
1115 fflush (stack_reg_dump_file);
1116 fflush (stdout);
1117 fflush (stderr);
1118 abort ();
1121 /* Called to give a better error message when we don't have an insn to match
1122 what we are looking for or if the insn's constraints aren't satisfied,
1123 rather than just calling abort(). */
1125 void
1126 fatal_insn_not_found (insn)
1127 rtx insn;
1129 if (INSN_CODE (insn) < 0)
1130 fatal_insn ("internal error--unrecognizable insn:", insn);
1131 else
1132 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1135 /* This is the default decl_printable_name function. */
1137 static char *
1138 decl_name (decl, verbosity)
1139 tree decl;
1140 int verbosity;
1142 return IDENTIFIER_POINTER (DECL_NAME (decl));
1145 static int need_error_newline;
1147 /* Function of last error message;
1148 more generally, function such that if next error message is in it
1149 then we don't have to mention the function name. */
1150 static tree last_error_function = NULL;
1152 /* Used to detect when input_file_stack has changed since last described. */
1153 static int last_error_tick;
1155 /* Called when the start of a function definition is parsed,
1156 this function prints on stderr the name of the function. */
1158 void
1159 announce_function (decl)
1160 tree decl;
1162 if (! quiet_flag)
1164 if (rtl_dump_and_exit)
1165 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1166 else
1167 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1168 fflush (stderr);
1169 need_error_newline = 1;
1170 last_error_function = current_function_decl;
1174 /* The default function to print out name of current function that caused
1175 an error. */
1177 void
1178 default_print_error_function (file)
1179 char *file;
1181 if (last_error_function != current_function_decl)
1183 char *kind = "function";
1184 if (current_function_decl != 0
1185 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1186 kind = "method";
1188 if (file)
1189 fprintf (stderr, "%s: ", file);
1191 if (current_function_decl == NULL)
1192 fprintf (stderr, "At top level:\n");
1193 else
1195 char *name = (*decl_printable_name) (current_function_decl, 2);
1196 fprintf (stderr, "In %s `%s':\n", kind, name);
1199 last_error_function = current_function_decl;
1203 /* Called by report_error_function to print out function name.
1204 * Default may be overridden by language front-ends. */
1206 void (*print_error_function) PROTO((char *)) = default_print_error_function;
1208 /* Prints out, if necessary, the name of the current function
1209 that caused an error. Called from all error and warning functions. */
1211 void
1212 report_error_function (file)
1213 char *file;
1215 struct file_stack *p;
1217 if (need_error_newline)
1219 fprintf (stderr, "\n");
1220 need_error_newline = 0;
1223 (*print_error_function) (file);
1225 if (input_file_stack && input_file_stack->next != 0
1226 && input_file_stack_tick != last_error_tick
1227 && file == input_filename)
1229 fprintf (stderr, "In file included");
1230 for (p = input_file_stack->next; p; p = p->next)
1232 fprintf (stderr, " from %s:%d", p->name, p->line);
1233 if (p->next)
1234 fprintf (stderr, ",\n ");
1236 fprintf (stderr, ":\n");
1237 last_error_tick = input_file_stack_tick;
1241 /* Print a message. */
1243 static void
1244 vmessage (prefix, s, ap)
1245 char *prefix;
1246 char *s;
1247 va_list ap;
1249 if (prefix)
1250 fprintf (stderr, "%s: ", prefix);
1252 #ifdef HAVE_VPRINTF
1253 vfprintf (stderr, s, ap);
1254 #else
1256 HOST_WIDE_INT v1 = va_arg(ap, HOST_WIDE_INT);
1257 HOST_WIDE_INT v2 = va_arg(ap, HOST_WIDE_INT);
1258 HOST_WIDE_INT v3 = va_arg(ap, HOST_WIDE_INT);
1259 HOST_WIDE_INT v4 = va_arg(ap, HOST_WIDE_INT);
1260 fprintf (stderr, s, v1, v2, v3, v4);
1262 #endif
1265 /* Print a message relevant to line LINE of file FILE. */
1267 static void
1268 v_message_with_file_and_line (file, line, prefix, s, ap)
1269 char *file;
1270 int line;
1271 char *prefix;
1272 char *s;
1273 va_list ap;
1275 if (file)
1276 fprintf (stderr, "%s:%d: ", file, line);
1277 else
1278 fprintf (stderr, "%s: ", progname);
1280 vmessage (prefix, s, ap);
1281 fputc ('\n', stderr);
1284 /* Print a message relevant to the given DECL. */
1286 static void
1287 v_message_with_decl (decl, prefix, s, ap)
1288 tree decl;
1289 char *prefix;
1290 char *s;
1291 va_list ap;
1293 char *n, *p;
1295 fprintf (stderr, "%s:%d: ",
1296 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1298 if (prefix)
1299 fprintf (stderr, "%s: ", prefix);
1301 /* Do magic to get around lack of varargs support for insertion
1302 of arguments into existing list. We know that the decl is first;
1303 we ass_u_me that it will be printed with "%s". */
1305 for (p = s; *p; ++p)
1307 if (*p == '%')
1309 if (*(p + 1) == '%')
1310 ++p;
1311 else
1312 break;
1316 if (p > s) /* Print the left-hand substring. */
1318 char fmt[sizeof "%.255s"];
1319 long width = p - s;
1321 if (width > 255L) width = 255L; /* arbitrary */
1322 sprintf (fmt, "%%.%lds", width);
1323 fprintf (stderr, fmt, s);
1326 if (*p == '%') /* Print the name. */
1328 char *n = (DECL_NAME (decl)
1329 ? (*decl_printable_name) (decl, 2)
1330 : "((anonymous))");
1331 fputs (n, stderr);
1332 while (*p)
1334 ++p;
1335 if (isalpha (*(p - 1) & 0xFF))
1336 break;
1340 if (*p) /* Print the rest of the message. */
1341 vmessage ((char *)NULL, p, ap);
1343 fputc ('\n', stderr);
1346 /* Figure file and line of the given INSN. */
1348 static void
1349 file_and_line_for_asm (insn, pfile, pline)
1350 rtx insn;
1351 char **pfile;
1352 int *pline;
1354 rtx body = PATTERN (insn);
1355 rtx asmop;
1357 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1358 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1359 asmop = SET_SRC (body);
1360 else if (GET_CODE (body) == ASM_OPERANDS)
1361 asmop = body;
1362 else if (GET_CODE (body) == PARALLEL
1363 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1364 asmop = SET_SRC (XVECEXP (body, 0, 0));
1365 else if (GET_CODE (body) == PARALLEL
1366 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1367 asmop = XVECEXP (body, 0, 0);
1368 else
1369 asmop = NULL;
1371 if (asmop)
1373 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1374 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1376 else
1378 *pfile = input_filename;
1379 *pline = lineno;
1383 /* Report an error at line LINE of file FILE. */
1385 static void
1386 v_error_with_file_and_line (file, line, s, ap)
1387 char *file;
1388 int line;
1389 char *s;
1390 va_list ap;
1392 count_error (0);
1393 report_error_function (file);
1394 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1397 void
1398 error_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1400 #ifndef __STDC__
1401 char *file;
1402 int line;
1403 char *s;
1404 #endif
1405 va_list ap;
1407 VA_START (ap, s);
1409 #ifndef __STDC__
1410 file = va_arg (ap, char *);
1411 line = va_arg (ap, int);
1412 s = va_arg (ap, char *);
1413 #endif
1415 v_error_with_file_and_line (file, line, s, ap);
1416 va_end (ap);
1419 /* Report an error at the declaration DECL.
1420 S is a format string which uses %s to substitute the declaration
1421 name; subsequent substitutions are a la printf. */
1423 static void
1424 v_error_with_decl (decl, s, ap)
1425 tree decl;
1426 char *s;
1427 va_list ap;
1429 count_error (0);
1430 report_error_function (DECL_SOURCE_FILE (decl));
1431 v_message_with_decl (decl, (char *)NULL, s, ap);
1434 void
1435 error_with_decl VPROTO((tree decl, char *s, ...))
1437 #ifndef __STDC__
1438 tree decl;
1439 char *s;
1440 #endif
1441 va_list ap;
1443 VA_START (ap, s);
1445 #ifndef __STDC__
1446 decl = va_arg (ap, tree);
1447 s = va_arg (ap, char *);
1448 #endif
1450 v_error_with_decl (decl, s, ap);
1451 va_end (ap);
1454 /* Report an error at the line number of the insn INSN.
1455 This is used only when INSN is an `asm' with operands,
1456 and each ASM_OPERANDS records its own source file and line. */
1458 static void
1459 v_error_for_asm (insn, s, ap)
1460 rtx insn;
1461 char *s;
1462 va_list ap;
1464 char *file;
1465 int line;
1467 count_error (0);
1468 file_and_line_for_asm (insn, &file, &line);
1469 report_error_function (file);
1470 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1473 void
1474 error_for_asm VPROTO((rtx insn, char *s, ...))
1476 #ifndef __STDC__
1477 rtx insn;
1478 char *s;
1479 #endif
1480 va_list ap;
1482 VA_START (ap, s);
1484 #ifndef __STDC__
1485 insn = va_arg (ap, rtx);
1486 s = va_arg (ap, char *);
1487 #endif
1489 v_error_for_asm (insn, s, ap);
1490 va_end (ap);
1493 /* Report an error at the current line number. */
1495 static void
1496 verror (s, ap)
1497 char *s;
1498 va_list ap;
1500 v_error_with_file_and_line (input_filename, lineno, s, ap);
1503 void
1504 error VPROTO((char *s, ...))
1506 #ifndef __STDC__
1507 char *s;
1508 #endif
1509 va_list ap;
1511 VA_START (ap, s);
1513 #ifndef __STDC__
1514 s = va_arg (ap, char *);
1515 #endif
1517 verror (s, ap);
1518 va_end (ap);
1521 /* Report a fatal error at the current line number. */
1523 static void
1524 vfatal (s, ap)
1525 char *s;
1526 va_list ap;
1528 verror (s, ap);
1529 exit (FATAL_EXIT_CODE);
1532 void
1533 fatal VPROTO((char *s, ...))
1535 #ifndef __STDC__
1536 char *s;
1537 #endif
1538 va_list ap;
1540 VA_START (ap, s);
1542 #ifndef __STDC__
1543 s = va_arg (ap, char *);
1544 #endif
1546 vfatal (s, ap);
1547 va_end (ap);
1550 /* Report a warning at line LINE of file FILE. */
1552 static void
1553 v_warning_with_file_and_line (file, line, s, ap)
1554 char *file;
1555 int line;
1556 char *s;
1557 va_list ap;
1559 if (count_error (1))
1561 report_error_function (file);
1562 v_message_with_file_and_line (file, line, "warning", s, ap);
1566 void
1567 warning_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1569 #ifndef __STDC__
1570 char *file;
1571 int line;
1572 char *s;
1573 #endif
1574 va_list ap;
1576 VA_START (ap, s);
1578 #ifndef __STDC__
1579 file = va_arg (ap, char *);
1580 line = va_arg (ap, int);
1581 s = va_arg (ap, char *);
1582 #endif
1584 v_warning_with_file_and_line (file, line, s, ap);
1585 va_end (ap);
1588 /* Report a warning at the declaration DECL.
1589 S is a format string which uses %s to substitute the declaration
1590 name; subsequent substitutions are a la printf. */
1592 static void
1593 v_warning_with_decl (decl, s, ap)
1594 tree decl;
1595 char *s;
1596 va_list ap;
1598 if (count_error (1))
1600 report_error_function (DECL_SOURCE_FILE (decl));
1601 v_message_with_decl (decl, "warning", s, ap);
1605 void
1606 warning_with_decl VPROTO((tree decl, char *s, ...))
1608 #ifndef __STDC__
1609 tree decl;
1610 char *s;
1611 #endif
1612 va_list ap;
1614 VA_START (ap, s);
1616 #ifndef __STDC__
1617 decl = va_arg (ap, tree);
1618 s = va_arg (ap, char *);
1619 #endif
1621 v_warning_with_decl (decl, s, ap);
1622 va_end (ap);
1625 /* Report a warning at the line number of the insn INSN.
1626 This is used only when INSN is an `asm' with operands,
1627 and each ASM_OPERANDS records its own source file and line. */
1629 static void
1630 v_warning_for_asm (insn, s, ap)
1631 rtx insn;
1632 char *s;
1633 va_list ap;
1635 if (count_error (1))
1637 char *file;
1638 int line;
1640 file_and_line_for_asm (insn, &file, &line);
1641 report_error_function (file);
1642 v_message_with_file_and_line (file, line, "warning", s, ap);
1646 void
1647 warning_for_asm VPROTO((rtx insn, char *s, ...))
1649 #ifndef __STDC__
1650 rtx insn;
1651 char *s;
1652 #endif
1653 va_list ap;
1655 VA_START (ap, s);
1657 #ifndef __STDC__
1658 insn = va_arg (ap, rtx);
1659 s = va_arg (ap, char *);
1660 #endif
1662 v_warning_for_asm (insn, s, ap);
1663 va_end (ap);
1666 /* Report a warning at the current line number. */
1668 static void
1669 vwarning (s, ap)
1670 char *s;
1671 va_list ap;
1673 v_warning_with_file_and_line (input_filename, lineno, s, ap);
1676 void
1677 warning VPROTO((char *s, ...))
1679 #ifndef __STDC__
1680 char *s;
1681 #endif
1682 va_list ap;
1684 VA_START (ap, s);
1686 #ifndef __STDC__
1687 s = va_arg (ap, char *);
1688 #endif
1690 vwarning (s, ap);
1691 va_end (ap);
1694 /* These functions issue either warnings or errors depending on
1695 -pedantic-errors. */
1697 static void
1698 vpedwarn (s, ap)
1699 char *s;
1700 va_list ap;
1702 if (flag_pedantic_errors)
1703 verror (s, ap);
1704 else
1705 vwarning (s, ap);
1708 void
1709 pedwarn VPROTO((char *s, ...))
1711 #ifndef __STDC__
1712 char *s;
1713 #endif
1714 va_list ap;
1716 VA_START (ap, s);
1718 #ifndef __STDC__
1719 s = va_arg (ap, char *);
1720 #endif
1722 vpedwarn (s, ap);
1723 va_end (ap);
1726 static void
1727 v_pedwarn_with_decl (decl, s, ap)
1728 tree decl;
1729 char *s;
1730 va_list ap;
1732 /* We don't want -pedantic-errors to cause the compilation to fail from
1733 "errors" in system header files. Sometimes fixincludes can't fix what's
1734 broken (eg: unsigned char bitfields - fixing it may change the alignment
1735 which will cause programs to mysteriously fail because the C library
1736 or kernel uses the original layout). There's no point in issuing a
1737 warning either, it's just unnecessary noise. */
1739 if (! DECL_IN_SYSTEM_HEADER (decl))
1741 if (flag_pedantic_errors)
1742 v_error_with_decl (decl, s, ap);
1743 else
1744 v_warning_with_decl (decl, s, ap);
1748 void
1749 pedwarn_with_decl VPROTO((tree decl, char *s, ...))
1751 #ifndef __STDC__
1752 tree decl;
1753 char *s;
1754 #endif
1755 va_list ap;
1757 VA_START (ap, s);
1759 #ifndef __STDC__
1760 decl = va_arg (ap, tree);
1761 s = va_arg (ap, char *);
1762 #endif
1764 v_pedwarn_with_decl (decl, s, ap);
1765 va_end (ap);
1768 static void
1769 v_pedwarn_with_file_and_line (file, line, s, ap)
1770 char *file;
1771 int line;
1772 char *s;
1773 va_list ap;
1775 if (flag_pedantic_errors)
1776 v_error_with_file_and_line (file, line, s, ap);
1777 else
1778 v_warning_with_file_and_line (file, line, s, ap);
1781 void
1782 pedwarn_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1784 #ifndef __STDC__
1785 char *file;
1786 int line;
1787 char *s;
1788 #endif
1789 va_list ap;
1791 VA_START (ap, s);
1793 #ifndef __STDC__
1794 file = va_arg (ap, char *);
1795 line = va_arg (ap, int);
1796 s = va_arg (ap, char *);
1797 #endif
1799 v_pedwarn_with_file_and_line (file, line, s, ap);
1800 va_end (ap);
1803 /* Apologize for not implementing some feature. */
1805 static void
1806 vsorry (s, ap)
1807 char *s;
1808 va_list ap;
1810 sorrycount++;
1811 if (input_filename)
1812 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1813 else
1814 fprintf (stderr, "%s: ", progname);
1815 vmessage ("sorry, not implemented", s, ap);
1816 fputc ('\n', stderr);
1819 void
1820 sorry VPROTO((char *s, ...))
1822 #ifndef __STDC__
1823 char *s;
1824 #endif
1825 va_list ap;
1827 VA_START (ap, s);
1829 #ifndef __STDC__
1830 s = va_arg (ap, char *);
1831 #endif
1833 vsorry (s, ap);
1834 va_end (ap);
1837 /* Apologize for not implementing some feature, then quit. */
1839 static void
1840 v_really_sorry (s, ap)
1841 char *s;
1842 va_list ap;
1844 sorrycount++;
1845 if (input_filename)
1846 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1847 else
1848 fprintf (stderr, "%s: ", progname);
1849 vmessage ("sorry, not implemented", s, ap);
1850 fatal (" (fatal)\n");
1853 void
1854 really_sorry VPROTO((char *s, ...))
1856 #ifndef __STDC__
1857 char *s;
1858 #endif
1859 va_list ap;
1861 VA_START (ap, s);
1863 #ifndef __STDC__
1864 s = va_arg (ap, char *);
1865 #endif
1867 v_really_sorry (s, ap);
1868 va_end (ap);
1871 /* More 'friendly' abort that prints the line and file.
1872 config.h can #define abort fancy_abort if you like that sort of thing.
1874 I don't think this is actually a good idea.
1875 Other sorts of crashes will look a certain way.
1876 It is a good thing if crashes from calling abort look the same way.
1877 -- RMS */
1879 void
1880 fancy_abort ()
1882 fatal ("internal gcc abort");
1885 /* This calls abort and is used to avoid problems when abort if a macro.
1886 It is used when we need to pass the address of abort. */
1888 void
1889 do_abort ()
1891 abort ();
1894 /* When `malloc.c' is compiled with `rcheck' defined,
1895 it calls this function to report clobberage. */
1897 void
1898 botch (s)
1900 abort ();
1903 /* Same as `malloc' but report error if no memory available. */
1905 char *
1906 xmalloc (size)
1907 unsigned size;
1909 register char *value = (char *) malloc (size);
1910 if (value == 0 && size != 0)
1911 fatal ("virtual memory exhausted");
1912 return value;
1915 /* Same as `realloc' but report error if no memory available. */
1917 char *
1918 xrealloc (ptr, size)
1919 char *ptr;
1920 int size;
1922 char *result = (char *) realloc (ptr, size);
1923 if (!result)
1924 fatal ("virtual memory exhausted");
1925 return result;
1928 /* Same as `strdup' but report error if no memory available. */
1930 char *
1931 xstrdup (s)
1932 register char *s;
1934 register char *result = (char *) malloc (strlen (s) + 1);
1936 if (! result)
1937 fatal ("virtual memory exhausted");
1938 strcpy (result, s);
1939 return result;
1942 /* Return the logarithm of X, base 2, considering X unsigned,
1943 if X is a power of 2. Otherwise, returns -1.
1945 This should be used via the `exact_log2' macro. */
1948 exact_log2_wide (x)
1949 register unsigned HOST_WIDE_INT x;
1951 register int log = 0;
1952 /* Test for 0 or a power of 2. */
1953 if (x == 0 || x != (x & -x))
1954 return -1;
1955 while ((x >>= 1) != 0)
1956 log++;
1957 return log;
1960 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1961 If X is 0, return -1.
1963 This should be used via the floor_log2 macro. */
1966 floor_log2_wide (x)
1967 register unsigned HOST_WIDE_INT x;
1969 register int log = -1;
1970 while (x != 0)
1971 log++,
1972 x >>= 1;
1973 return log;
1976 static int float_handler_set;
1977 int float_handled;
1978 jmp_buf float_handler;
1980 /* Signals actually come here. */
1982 static void
1983 float_signal (signo)
1984 /* If this is missing, some compilers complain. */
1985 int signo;
1987 if (float_handled == 0)
1988 abort ();
1989 #if defined (USG) || defined (hpux)
1990 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
1991 #endif
1992 float_handled = 0;
1993 signal (SIGFPE, float_signal);
1994 longjmp (float_handler, 1);
1997 /* Specify where to longjmp to when a floating arithmetic error happens.
1998 If HANDLER is 0, it means don't handle the errors any more. */
2000 void
2001 set_float_handler (handler)
2002 jmp_buf handler;
2004 float_handled = (handler != 0);
2005 if (handler)
2006 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2008 if (float_handled && ! float_handler_set)
2010 signal (SIGFPE, float_signal);
2011 float_handler_set = 1;
2015 /* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2016 error happens, pushing the previous specification into OLD_HANDLER.
2017 Return an indication of whether there was a previous handler in effect. */
2020 push_float_handler (handler, old_handler)
2021 jmp_buf handler, old_handler;
2023 int was_handled = float_handled;
2025 float_handled = 1;
2026 if (was_handled)
2027 bcopy ((char *) float_handler, (char *) old_handler,
2028 sizeof (float_handler));
2030 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2031 return was_handled;
2034 /* Restore the previous specification of whether and where to longjmp to
2035 when a floating arithmetic error happens. */
2037 void
2038 pop_float_handler (handled, handler)
2039 int handled;
2040 jmp_buf handler;
2042 float_handled = handled;
2043 if (handled)
2044 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2047 /* Handler for SIGPIPE. */
2049 static void
2050 pipe_closed (signo)
2051 /* If this is missing, some compilers complain. */
2052 int signo;
2054 fatal ("output pipe has been closed");
2057 /* Strip off a legitimate source ending from the input string NAME of
2058 length LEN. Rather than having to know the names used by all of
2059 our front ends, we strip off an ending of a period followed by one,
2060 two, or three characters. */
2062 void
2063 strip_off_ending (name, len)
2064 char *name;
2065 int len;
2067 if (len > 2 && name[len - 2] == '.')
2068 name[len - 2] = '\0';
2069 else if (len > 3 && name[len - 3] == '.')
2070 name[len - 3] = '\0';
2071 else if (len > 4 && name[len - 4] == '.')
2072 name[len - 4] = '\0';
2075 /* Output a quoted string. */
2077 void
2078 output_quoted_string (asm_file, string)
2079 FILE *asm_file;
2080 char *string;
2082 char c;
2084 putc ('\"', asm_file);
2085 while ((c = *string++) != 0)
2087 if (c == '\"' || c == '\\')
2088 putc ('\\', asm_file);
2089 putc (c, asm_file);
2091 putc ('\"', asm_file);
2094 /* Output a file name in the form wanted by System V. */
2096 void
2097 output_file_directive (asm_file, input_name)
2098 FILE *asm_file;
2099 char *input_name;
2101 int len = strlen (input_name);
2102 char *na = input_name + len;
2104 /* NA gets INPUT_NAME sans directory names. */
2105 while (na > input_name)
2107 if (na[-1] == '/')
2108 break;
2109 na--;
2112 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2113 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2114 #else
2115 #ifdef ASM_OUTPUT_SOURCE_FILENAME
2116 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2117 #else
2118 fprintf (asm_file, "\t.file\t");
2119 output_quoted_string (asm_file, na);
2120 fputc ('\n', asm_file);
2121 #endif
2122 #endif
2125 /* Routine to build language identifier for object file. */
2127 static void
2128 output_lang_identify (asm_out_file)
2129 FILE *asm_out_file;
2131 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2132 char *s = (char *) alloca (len);
2133 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2134 ASM_OUTPUT_LABEL (asm_out_file, s);
2137 /* Routine to open a dump file. */
2139 static FILE *
2140 open_dump_file (base_name, suffix)
2141 char *base_name;
2142 char *suffix;
2144 FILE *f;
2145 char *dumpname = (char *) alloca (strlen (base_name) + strlen (suffix) + 1);
2147 strcpy (dumpname, base_name);
2148 strcat (dumpname, suffix);
2149 f = fopen (dumpname, "w");
2150 if (f == 0)
2151 pfatal_with_name (dumpname);
2152 return f;
2155 /* Compile an entire file of output from cpp, named NAME.
2156 Write a file of assembly output and various debugging dumps. */
2158 static void
2159 compile_file (name)
2160 char *name;
2162 tree globals;
2163 int start_time;
2165 int name_specified = name != 0;
2167 if (dump_base_name == 0)
2168 dump_base_name = name ? name : "gccdump";
2170 parse_time = 0;
2171 varconst_time = 0;
2172 integration_time = 0;
2173 jump_time = 0;
2174 cse_time = 0;
2175 loop_time = 0;
2176 cse2_time = 0;
2177 branch_prob_time = 0;
2178 flow_time = 0;
2179 combine_time = 0;
2180 regmove_time = 0;
2181 sched_time = 0;
2182 local_alloc_time = 0;
2183 global_alloc_time = 0;
2184 sched2_time = 0;
2185 dbr_sched_time = 0;
2186 shorten_branch_time = 0;
2187 stack_reg_time = 0;
2188 final_time = 0;
2189 symout_time = 0;
2190 dump_time = 0;
2192 #if !USE_CPPLIB
2193 /* Open input file. */
2195 if (name == 0 || !strcmp (name, "-"))
2197 finput = stdin;
2198 name = "stdin";
2200 else
2201 finput = fopen (name, "r");
2202 if (finput == 0)
2203 pfatal_with_name (name);
2205 #ifdef IO_BUFFER_SIZE
2206 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
2207 #endif
2208 #endif /* !USE_CPPLIB */
2210 /* Initialize data in various passes. */
2212 init_obstacks ();
2213 init_tree_codes ();
2214 #if USE_CPPLIB
2215 init_parse (name);
2216 #else
2217 init_lex ();
2218 #endif
2219 /* Some of these really don't need to be called when generating bytecode,
2220 but the options would have to be parsed first to know that. -bson */
2221 init_rtl ();
2222 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2223 || debug_info_level == DINFO_LEVEL_VERBOSE
2224 || flag_test_coverage);
2225 init_regs ();
2226 init_decl_processing ();
2227 init_optabs ();
2228 init_stmt ();
2229 init_expmed ();
2230 init_expr_once ();
2231 init_loop ();
2232 init_reload ();
2234 if (flag_caller_saves)
2235 init_caller_save ();
2237 /* If auxiliary info generation is desired, open the output file.
2238 This goes in the same directory as the source file--unlike
2239 all the other output files. */
2240 if (flag_gen_aux_info)
2242 aux_info_file = fopen (aux_info_file_name, "w");
2243 if (aux_info_file == 0)
2244 pfatal_with_name (aux_info_file_name);
2247 /* If rtl dump desired, open the output file. */
2248 if (rtl_dump)
2249 rtl_dump_file = open_dump_file (dump_base_name, ".rtl");
2251 /* If jump_opt dump desired, open the output file. */
2252 if (jump_opt_dump)
2253 jump_opt_dump_file = open_dump_file (dump_base_name, ".jump");
2255 /* If cse dump desired, open the output file. */
2256 if (cse_dump)
2257 cse_dump_file = open_dump_file (dump_base_name, ".cse");
2259 /* If loop dump desired, open the output file. */
2260 if (loop_dump)
2261 loop_dump_file = open_dump_file (dump_base_name, ".loop");
2263 /* If cse2 dump desired, open the output file. */
2264 if (cse2_dump)
2265 cse2_dump_file = open_dump_file (dump_base_name, ".cse2");
2267 /* If branch_prob dump desired, open the output file. */
2268 if (branch_prob_dump)
2269 branch_prob_dump_file = open_dump_file (dump_base_name, ".bp");
2271 /* If flow dump desired, open the output file. */
2272 if (flow_dump)
2273 flow_dump_file = open_dump_file (dump_base_name, ".flow");
2275 /* If combine dump desired, open the output file. */
2276 if (combine_dump)
2277 combine_dump_file = open_dump_file (dump_base_name, ".combine");
2279 /* If regmove dump desired, open the output file. */
2280 if (regmove_dump)
2281 regmove_dump_file = open_dump_file (dump_base_name, ".regmove");
2283 /* If scheduling dump desired, open the output file. */
2284 if (sched_dump)
2285 sched_dump_file = open_dump_file (dump_base_name, ".sched");
2287 /* If local_reg dump desired, open the output file. */
2288 if (local_reg_dump)
2289 local_reg_dump_file = open_dump_file (dump_base_name, ".lreg");
2291 /* If global_reg dump desired, open the output file. */
2292 if (global_reg_dump)
2293 global_reg_dump_file = open_dump_file (dump_base_name, ".greg");
2295 /* If 2nd scheduling dump desired, open the output file. */
2296 if (sched2_dump)
2297 sched2_dump_file = open_dump_file (dump_base_name, ".sched2");
2299 /* If jump2_opt dump desired, open the output file. */
2300 if (jump2_opt_dump)
2301 jump2_opt_dump_file = open_dump_file (dump_base_name, ".jump2");
2303 /* If dbr_sched dump desired, open the output file. */
2304 if (dbr_sched_dump)
2305 dbr_sched_dump_file = open_dump_file (dump_base_name, ".dbr");
2307 #ifdef STACK_REGS
2309 /* If stack_reg dump desired, open the output file. */
2310 if (stack_reg_dump)
2311 stack_reg_dump_file = open_dump_file (dump_base_name, ".stack");
2313 #endif
2315 /* Open assembler code output file. */
2317 if (! name_specified && asm_file_name == 0)
2318 asm_out_file = stdout;
2319 else
2321 int len = strlen (dump_base_name);
2322 register char *dumpname = (char *) xmalloc (len + 6);
2323 strcpy (dumpname, dump_base_name);
2324 strip_off_ending (dumpname, len);
2325 strcat (dumpname, ".s");
2326 if (asm_file_name == 0)
2328 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
2329 strcpy (asm_file_name, dumpname);
2331 if (!strcmp (asm_file_name, "-"))
2332 asm_out_file = stdout;
2333 else
2334 asm_out_file = fopen (asm_file_name, "w");
2335 if (asm_out_file == 0)
2336 pfatal_with_name (asm_file_name);
2339 #ifdef IO_BUFFER_SIZE
2340 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2341 _IOFBF, IO_BUFFER_SIZE);
2342 #endif
2344 input_filename = name;
2346 /* Put an entry on the input file stack for the main input file. */
2347 input_file_stack
2348 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2349 input_file_stack->next = 0;
2350 input_file_stack->name = input_filename;
2352 /* Perform language-specific initialization.
2353 This may set main_input_filename. */
2354 lang_init ();
2356 /* If the input doesn't start with a #line, use the input name
2357 as the official input file name. */
2358 if (main_input_filename == 0)
2359 main_input_filename = name;
2361 if (!output_bytecode)
2363 ASM_FILE_START (asm_out_file);
2365 #ifdef ASM_COMMENT_START
2366 if (flag_verbose_asm)
2368 /* Print the list of options in effect. */
2369 print_version (asm_out_file, ASM_COMMENT_START);
2370 print_switch_values (asm_out_file, 0, MAX_LINE,
2371 ASM_COMMENT_START, " ", "\n");
2372 /* Add a blank line here so it appears in assembler output but not
2373 screen output. */
2374 fprintf (asm_out_file, "\n");
2376 #endif
2379 /* Output something to inform GDB that this compilation was by GCC. Also
2380 serves to tell GDB file consists of bytecodes. */
2381 if (output_bytecode)
2382 fprintf (asm_out_file, "bc_gcc2_compiled.:\n");
2383 else
2385 #ifndef ASM_IDENTIFY_GCC
2386 fprintf (asm_out_file, "gcc2_compiled.:\n");
2387 #else
2388 ASM_IDENTIFY_GCC (asm_out_file);
2389 #endif
2392 /* Output something to identify which front-end produced this file. */
2393 #ifdef ASM_IDENTIFY_LANGUAGE
2394 ASM_IDENTIFY_LANGUAGE (asm_out_file);
2395 #endif
2397 #ifndef ASM_OUTPUT_SECTION_NAME
2398 if (flag_function_sections)
2400 warning ("-ffunction-sections not supported for this target.");
2401 flag_function_sections = 0;
2403 #endif
2405 if (flag_function_sections
2406 && (profile_flag || profile_block_flag))
2408 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2409 flag_function_sections = 0;
2412 if (flag_function_sections && write_symbols != NO_DEBUG)
2413 warning ("-ffunction-sections may affect debugging on some targets.");
2415 if (output_bytecode)
2417 if (profile_flag || profile_block_flag)
2418 error ("profiling not supported in bytecode compilation");
2420 else
2422 /* ??? Note: There used to be a conditional here
2423 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2424 This was to guarantee separation between gcc_compiled. and
2425 the first function, for the sake of dbx on Suns.
2426 However, having the extra zero here confused the Emacs
2427 code for unexec, and might confuse other programs too.
2428 Therefore, I took out that change.
2429 In future versions we should find another way to solve
2430 that dbx problem. -- rms, 23 May 93. */
2432 /* Don't let the first function fall at the same address
2433 as gcc_compiled., if profiling. */
2434 if (profile_flag || profile_block_flag)
2435 assemble_zeros (UNITS_PER_WORD);
2438 /* If dbx symbol table desired, initialize writing it
2439 and output the predefined types. */
2440 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2441 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2442 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2443 getdecls ()));
2444 #endif
2445 #ifdef SDB_DEBUGGING_INFO
2446 if (write_symbols == SDB_DEBUG)
2447 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2448 getdecls ()));
2449 #endif
2450 #ifdef DWARF_DEBUGGING_INFO
2451 if (write_symbols == DWARF_DEBUG)
2452 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2453 #endif
2454 #ifdef DWARF2_DEBUGGING_INFO
2455 if (write_symbols == DWARF2_DEBUG)
2456 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
2457 #endif
2459 /* Initialize yet another pass. */
2461 if (!output_bytecode)
2462 init_final (main_input_filename);
2463 init_branch_prob (dump_base_name);
2465 start_time = get_run_time ();
2467 /* Call the parser, which parses the entire file
2468 (calling rest_of_compilation for each function). */
2470 if (yyparse () != 0)
2472 if (errorcount == 0)
2473 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
2475 /* In case there were missing closebraces,
2476 get us back to the global binding level. */
2477 while (! global_bindings_p ())
2478 poplevel (0, 0, 0);
2481 output_func_start_profiler ();
2483 /* Compilation is now finished except for writing
2484 what's left of the symbol table output. */
2486 parse_time += get_run_time () - start_time;
2488 parse_time -= integration_time;
2489 parse_time -= varconst_time;
2491 globals = getdecls ();
2493 /* Really define vars that have had only a tentative definition.
2494 Really output inline functions that must actually be callable
2495 and have not been output so far. */
2498 int len = list_length (globals);
2499 tree *vec = (tree *) alloca (sizeof (tree) * len);
2500 int i;
2501 tree decl;
2502 int reconsider = 1;
2504 /* Process the decls in reverse order--earliest first.
2505 Put them into VEC from back to front, then take out from front. */
2507 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2508 vec[len - i - 1] = decl;
2510 for (i = 0; i < len; i++)
2512 decl = vec[i];
2514 /* We're not deferring this any longer. */
2515 DECL_DEFER_OUTPUT (decl) = 0;
2517 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2518 && incomplete_decl_finalize_hook != 0)
2519 (*incomplete_decl_finalize_hook) (decl);
2522 /* Now emit any global variables or functions that we have been putting
2523 off. We need to loop in case one of the things emitted here
2524 references another one which comes earlier in the list. */
2525 while (reconsider)
2527 reconsider = 0;
2528 for (i = 0; i < len; i++)
2530 decl = vec[i];
2532 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2533 continue;
2535 /* Don't write out static consts, unless we still need them.
2537 We also keep static consts if not optimizing (for debugging),
2538 unless the user specified -fno-keep-static-consts.
2539 ??? They might be better written into the debug information.
2540 This is possible when using DWARF.
2542 A language processor that wants static constants to be always
2543 written out (even if it is not used) is responsible for
2544 calling rest_of_decl_compilation itself. E.g. the C front-end
2545 calls rest_of_decl_compilation from finish_decl.
2546 One motivation for this is that is conventional in some
2547 environments to write things like:
2548 static const char rcsid[] = "... version string ...";
2549 intending to force the string to be in the executable.
2551 A language processor that would prefer to have unneeded
2552 static constants "optimized away" would just defer writing
2553 them out until here. E.g. C++ does this, because static
2554 constants are often defined in header files.
2556 ??? A tempting alternative (for both C and C++) would be
2557 to force a constant to be written if and only if it is
2558 defined in a main file, as opposed to an include file. */
2560 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2561 && (! TREE_READONLY (decl)
2562 || TREE_PUBLIC (decl)
2563 || (!optimize && flag_keep_static_consts)
2564 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2566 reconsider = 1;
2567 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2570 if (TREE_CODE (decl) == FUNCTION_DECL
2571 && DECL_INITIAL (decl) != 0
2572 && DECL_SAVED_INSNS (decl) != 0
2573 && (flag_keep_inline_functions
2574 || TREE_PUBLIC (decl)
2575 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2577 reconsider = 1;
2578 temporary_allocation ();
2579 output_inline_function (decl);
2580 permanent_allocation (1);
2585 /* Now that all possible functions have been output, we can dump
2586 the exception table. */
2588 if (exception_table_p ())
2589 output_exception_table ();
2591 for (i = 0; i < len; i++)
2593 decl = vec[i];
2595 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2596 && ! TREE_ASM_WRITTEN (decl))
2597 /* Cancel the RTL for this decl so that, if debugging info
2598 output for global variables is still to come,
2599 this one will be omitted. */
2600 DECL_RTL (decl) = NULL;
2602 /* Warn about any function
2603 declared static but not defined.
2604 We don't warn about variables,
2605 because many programs have static variables
2606 that exist only to get some text into the object file. */
2607 if (TREE_CODE (decl) == FUNCTION_DECL
2608 && (warn_unused
2609 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2610 && DECL_INITIAL (decl) == 0
2611 && DECL_EXTERNAL (decl)
2612 && ! DECL_ARTIFICIAL (decl)
2613 && ! TREE_PUBLIC (decl))
2615 pedwarn_with_decl (decl,
2616 "`%s' declared `static' but never defined");
2617 /* This symbol is effectively an "extern" declaration now. */
2618 TREE_PUBLIC (decl) = 1;
2619 assemble_external (decl);
2622 /* Warn about static fns or vars defined but not used,
2623 but not about inline functions or static consts
2624 since defining those in header files is normal practice. */
2625 if (warn_unused
2626 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2627 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2628 && ! DECL_IN_SYSTEM_HEADER (decl)
2629 && ! DECL_EXTERNAL (decl)
2630 && ! TREE_PUBLIC (decl)
2631 && ! TREE_USED (decl)
2632 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2633 /* The TREE_USED bit for file-scope decls
2634 is kept in the identifier, to handle multiple
2635 external decls in different scopes. */
2636 && ! TREE_USED (DECL_NAME (decl)))
2637 warning_with_decl (decl, "`%s' defined but not used");
2639 #ifdef SDB_DEBUGGING_INFO
2640 /* The COFF linker can move initialized global vars to the end.
2641 And that can screw up the symbol ordering.
2642 By putting the symbols in that order to begin with,
2643 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2644 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2645 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2646 && ! DECL_EXTERNAL (decl)
2647 && DECL_RTL (decl) != 0)
2648 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2650 /* Output COFF information for non-global
2651 file-scope initialized variables. */
2652 if (write_symbols == SDB_DEBUG
2653 && TREE_CODE (decl) == VAR_DECL
2654 && DECL_INITIAL (decl)
2655 && ! DECL_EXTERNAL (decl)
2656 && DECL_RTL (decl) != 0
2657 && GET_CODE (DECL_RTL (decl)) == MEM)
2658 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2659 #endif /* SDB_DEBUGGING_INFO */
2660 #ifdef DWARF_DEBUGGING_INFO
2661 /* Output DWARF information for file-scope tentative data object
2662 declarations, file-scope (extern) function declarations (which
2663 had no corresponding body) and file-scope tagged type declarations
2664 and definitions which have not yet been forced out. */
2666 if (write_symbols == DWARF_DEBUG
2667 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2668 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2669 #endif
2670 #ifdef DWARF2_DEBUGGING_INFO
2671 /* Output DWARF2 information for file-scope tentative data object
2672 declarations, file-scope (extern) function declarations (which
2673 had no corresponding body) and file-scope tagged type declarations
2674 and definitions which have not yet been forced out. */
2676 if (write_symbols == DWARF2_DEBUG
2677 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2678 TIMEVAR (symout_time, dwarf2out_decl (decl));
2679 #endif
2683 /* Write out any pending weak symbol declarations. */
2685 weak_finish ();
2687 /* Do dbx symbols */
2688 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2689 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2690 TIMEVAR (symout_time,
2692 dbxout_finish (asm_out_file, main_input_filename);
2694 #endif
2696 #ifdef DWARF_DEBUGGING_INFO
2697 if (write_symbols == DWARF_DEBUG)
2698 TIMEVAR (symout_time,
2700 dwarfout_finish ();
2702 #endif
2704 #ifdef DWARF2_DEBUGGING_INFO
2705 if (write_symbols == DWARF2_DEBUG)
2706 TIMEVAR (symout_time,
2708 dwarf2out_finish ();
2710 #endif
2712 /* Output some stuff at end of file if nec. */
2714 if (!output_bytecode)
2716 end_final (dump_base_name);
2717 end_branch_prob (branch_prob_dump_file);
2719 #ifdef ASM_FILE_END
2720 ASM_FILE_END (asm_out_file);
2721 #endif
2724 /* Language-specific end of compilation actions. */
2726 lang_finish ();
2728 if (output_bytecode)
2729 bc_write_file (asm_out_file);
2731 /* Close the dump files. */
2733 if (flag_gen_aux_info)
2735 fclose (aux_info_file);
2736 if (errorcount)
2737 unlink (aux_info_file_name);
2740 if (rtl_dump)
2741 fclose (rtl_dump_file);
2743 if (jump_opt_dump)
2744 fclose (jump_opt_dump_file);
2746 if (cse_dump)
2747 fclose (cse_dump_file);
2749 if (loop_dump)
2750 fclose (loop_dump_file);
2752 if (cse2_dump)
2753 fclose (cse2_dump_file);
2755 if (branch_prob_dump)
2756 fclose (branch_prob_dump_file);
2758 if (flow_dump)
2759 fclose (flow_dump_file);
2761 if (combine_dump)
2763 dump_combine_total_stats (combine_dump_file);
2764 fclose (combine_dump_file);
2767 if (regmove_dump)
2768 fclose (regmove_dump_file);
2770 if (sched_dump)
2771 fclose (sched_dump_file);
2773 if (local_reg_dump)
2774 fclose (local_reg_dump_file);
2776 if (global_reg_dump)
2777 fclose (global_reg_dump_file);
2779 if (sched2_dump)
2780 fclose (sched2_dump_file);
2782 if (jump2_opt_dump)
2783 fclose (jump2_opt_dump_file);
2785 if (dbr_sched_dump)
2786 fclose (dbr_sched_dump_file);
2788 #ifdef STACK_REGS
2789 if (stack_reg_dump)
2790 fclose (stack_reg_dump_file);
2791 #endif
2793 /* Close non-debugging input and output files. Take special care to note
2794 whether fclose returns an error, since the pages might still be on the
2795 buffer chain while the file is open. */
2797 #if USE_CPPLIB
2798 finish_parse ();
2799 #else
2800 fclose (finput);
2801 #endif
2802 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
2803 fatal_io_error (asm_file_name);
2805 /* Print the times. */
2807 if (! quiet_flag)
2809 fprintf (stderr,"\n");
2810 print_time ("parse", parse_time);
2812 if (!output_bytecode)
2814 print_time ("integration", integration_time);
2815 print_time ("jump", jump_time);
2816 print_time ("cse", cse_time);
2817 print_time ("loop", loop_time);
2818 print_time ("cse2", cse2_time);
2819 print_time ("branch-prob", branch_prob_time);
2820 print_time ("flow", flow_time);
2821 print_time ("combine", combine_time);
2822 print_time ("regmove", regmove_time);
2823 print_time ("sched", sched_time);
2824 print_time ("local-alloc", local_alloc_time);
2825 print_time ("global-alloc", global_alloc_time);
2826 print_time ("sched2", sched2_time);
2827 print_time ("dbranch", dbr_sched_time);
2828 print_time ("shorten-branch", shorten_branch_time);
2829 print_time ("stack-reg", stack_reg_time);
2830 print_time ("final", final_time);
2831 print_time ("varconst", varconst_time);
2832 print_time ("symout", symout_time);
2833 print_time ("dump", dump_time);
2838 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2839 and TYPE_DECL nodes.
2841 This does nothing for local (non-static) variables.
2842 Otherwise, it sets up the RTL and outputs any assembler code
2843 (label definition, storage allocation and initialization).
2845 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2846 the assembler symbol name to be used. TOP_LEVEL is nonzero
2847 if this declaration is not within a function. */
2849 void
2850 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2851 tree decl;
2852 char *asmspec;
2853 int top_level;
2854 int at_end;
2856 /* Declarations of variables, and of functions defined elsewhere. */
2858 /* The most obvious approach, to put an #ifndef around where
2859 this macro is used, doesn't work since it's inside a macro call. */
2860 #ifndef ASM_FINISH_DECLARE_OBJECT
2861 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2862 #endif
2864 /* Forward declarations for nested functions are not "external",
2865 but we need to treat them as if they were. */
2866 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2867 || TREE_CODE (decl) == FUNCTION_DECL)
2868 TIMEVAR (varconst_time,
2870 make_decl_rtl (decl, asmspec, top_level);
2871 /* Initialized extern variable exists to be replaced
2872 with its value, or represents something that will be
2873 output in another file. */
2874 if (! (TREE_CODE (decl) == VAR_DECL
2875 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
2876 && DECL_INITIAL (decl) != 0
2877 && DECL_INITIAL (decl) != error_mark_node))
2878 /* Don't output anything
2879 when a tentative file-scope definition is seen.
2880 But at end of compilation, do output code for them. */
2881 if (! (! at_end && top_level
2882 && (DECL_INITIAL (decl) == 0
2883 || DECL_INITIAL (decl) == error_mark_node)))
2884 assemble_variable (decl, top_level, at_end, 0);
2885 if (!output_bytecode
2886 && decl == last_assemble_variable_decl)
2888 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2889 top_level, at_end);
2892 else if (DECL_REGISTER (decl) && asmspec != 0)
2894 if (decode_reg_name (asmspec) >= 0)
2896 DECL_RTL (decl) = 0;
2897 make_decl_rtl (decl, asmspec, top_level);
2899 else
2900 error ("invalid register name `%s' for register variable", asmspec);
2902 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2903 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2904 && TREE_CODE (decl) == TYPE_DECL)
2905 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
2906 #endif
2907 #ifdef SDB_DEBUGGING_INFO
2908 else if (write_symbols == SDB_DEBUG && top_level
2909 && TREE_CODE (decl) == TYPE_DECL)
2910 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2911 #endif
2914 /* Called after finishing a record, union or enumeral type. */
2916 void
2917 rest_of_type_compilation (type, toplev)
2918 tree type;
2919 int toplev;
2921 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2922 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2923 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
2924 #endif
2925 #ifdef SDB_DEBUGGING_INFO
2926 if (write_symbols == SDB_DEBUG)
2927 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
2928 #endif
2931 /* This is called from finish_function (within yyparse)
2932 after each top-level definition is parsed.
2933 It is supposed to compile that function or variable
2934 and output the assembler code for it.
2935 After we return, the tree storage is freed. */
2937 void
2938 rest_of_compilation (decl)
2939 tree decl;
2941 register rtx insns;
2942 int start_time = get_run_time ();
2943 int tem;
2944 /* Nonzero if we have saved the original DECL_INITIAL of the function,
2945 to be restored after we finish compiling the function
2946 (for use when compiling inline calls to this function). */
2947 tree saved_block_tree = 0;
2948 /* Likewise, for DECL_ARGUMENTS. */
2949 tree saved_arguments = 0;
2950 int failure = 0;
2952 if (output_bytecode)
2953 return;
2955 /* If we are reconsidering an inline function
2956 at the end of compilation, skip the stuff for making it inline. */
2958 if (DECL_SAVED_INSNS (decl) == 0)
2960 int inlineable = 0;
2961 char *lose;
2963 /* If requested, consider whether to make this function inline. */
2964 if (DECL_INLINE (decl) || flag_inline_functions)
2965 TIMEVAR (integration_time,
2967 lose = function_cannot_inline_p (decl);
2968 if (lose || ! optimize)
2970 if (warn_inline && DECL_INLINE (decl))
2971 warning_with_decl (decl, lose);
2972 DECL_ABSTRACT_ORIGIN (decl) = 0;
2973 /* Don't really compile an extern inline function.
2974 If we can't make it inline, pretend
2975 it was only declared. */
2976 if (DECL_EXTERNAL (decl))
2978 DECL_INITIAL (decl) = 0;
2979 goto exit_rest_of_compilation;
2982 else
2983 /* ??? Note that this has the effect of making it look
2984 like "inline" was specified for a function if we choose
2985 to inline it. This isn't quite right, but it's
2986 probably not worth the trouble to fix. */
2987 inlineable = DECL_INLINE (decl) = 1;
2990 insns = get_insns ();
2992 /* Dump the rtl code if we are dumping rtl. */
2994 if (rtl_dump)
2995 TIMEVAR (dump_time,
2997 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2998 (*decl_printable_name) (decl, 2));
2999 if (DECL_SAVED_INSNS (decl))
3000 fprintf (rtl_dump_file, ";; (integrable)\n\n");
3001 print_rtl (rtl_dump_file, insns);
3002 fflush (rtl_dump_file);
3005 /* If function is inline, and we don't yet know whether to
3006 compile it by itself, defer decision till end of compilation.
3007 finish_compilation will call rest_of_compilation again
3008 for those functions that need to be output. Also defer those
3009 functions that we are supposed to defer. We cannot defer
3010 functions containing nested functions since the nested function
3011 data is in our non-saved obstack. */
3013 if (! current_function_contains_functions
3014 && (DECL_DEFER_OUTPUT (decl)
3015 || (DECL_INLINE (decl)
3016 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3017 && ! flag_keep_inline_functions)
3018 || DECL_EXTERNAL (decl)))))
3020 DECL_DEFER_OUTPUT (decl) = 1;
3022 /* If -Wreturn-type, we have to do a bit of compilation. */
3023 if (! warn_return_type)
3025 #ifdef DWARF_DEBUGGING_INFO
3026 /* Generate the DWARF info for the "abstract" instance
3027 of a function which we may later generate inlined and/or
3028 out-of-line instances of. */
3029 if (write_symbols == DWARF_DEBUG)
3031 set_decl_abstract_flags (decl, 1);
3032 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3033 set_decl_abstract_flags (decl, 0);
3035 #endif
3036 #ifdef DWARF2_DEBUGGING_INFO
3037 /* Generate the DWARF2 info for the "abstract" instance
3038 of a function which we may later generate inlined and/or
3039 out-of-line instances of. */
3040 if (write_symbols == DWARF2_DEBUG)
3042 set_decl_abstract_flags (decl, 1);
3043 TIMEVAR (symout_time, dwarf2out_decl (decl));
3044 set_decl_abstract_flags (decl, 0);
3046 #endif
3047 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3048 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
3049 goto exit_rest_of_compilation;
3053 /* If we have to compile the function now, save its rtl and subdecls
3054 so that its compilation will not affect what others get. */
3055 if (inlineable || DECL_DEFER_OUTPUT (decl))
3057 #ifdef DWARF_DEBUGGING_INFO
3058 /* Generate the DWARF info for the "abstract" instance of
3059 a function which we will generate an out-of-line instance
3060 of almost immediately (and which we may also later generate
3061 various inlined instances of). */
3062 if (write_symbols == DWARF_DEBUG)
3064 set_decl_abstract_flags (decl, 1);
3065 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3066 set_decl_abstract_flags (decl, 0);
3068 #endif
3069 #ifdef DWARF2_DEBUGGING_INFO
3070 /* Generate the DWARF2 info for the "abstract" instance of
3071 a function which we will generate an out-of-line instance
3072 of almost immediately (and which we may also later generate
3073 various inlined instances of). */
3074 if (write_symbols == DWARF2_DEBUG)
3076 set_decl_abstract_flags (decl, 1);
3077 TIMEVAR (symout_time, dwarf2out_decl (decl));
3078 set_decl_abstract_flags (decl, 0);
3080 #endif
3081 saved_block_tree = DECL_INITIAL (decl);
3082 saved_arguments = DECL_ARGUMENTS (decl);
3083 TIMEVAR (integration_time, save_for_inline_copying (decl));
3084 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
3087 /* If specified extern inline but we aren't inlining it, we are
3088 done. */
3089 if (DECL_INLINE (decl) && DECL_EXTERNAL (decl))
3090 goto exit_rest_of_compilation;
3093 if (! DECL_DEFER_OUTPUT (decl))
3094 TREE_ASM_WRITTEN (decl) = 1;
3096 /* Now that integrate will no longer see our rtl, we need not distinguish
3097 between the return value of this function and the return value of called
3098 functions. */
3099 rtx_equal_function_value_matters = 0;
3101 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3102 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3104 goto exit_rest_of_compilation;
3107 /* Add an unwinder for exception handling, if needed.
3108 This must be done before we finalize PIC code. */
3109 emit_unwinder ();
3111 #ifdef FINALIZE_PIC
3112 /* If we are doing position-independent code generation, now
3113 is the time to output special prologues and epilogues.
3114 We do not want to do this earlier, because it just clutters
3115 up inline functions with meaningless insns. */
3116 if (flag_pic)
3117 FINALIZE_PIC;
3118 #endif
3120 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3121 Note that that may have been done above, in save_for_inline_copying.
3122 The call to resume_temporary_allocation near the end of this function
3123 goes back to the usual state of affairs. This must be done after
3124 we've built up any unwinders for exception handling, and done
3125 the FINALIZE_PIC work, if necessary. */
3127 rtl_in_current_obstack ();
3129 insns = get_insns ();
3131 /* Copy any shared structure that should not be shared. */
3133 unshare_all_rtl (insns);
3135 /* Instantiate all virtual registers. */
3137 instantiate_virtual_regs (current_function_decl, get_insns ());
3139 /* See if we have allocated stack slots that are not directly addressable.
3140 If so, scan all the insns and create explicit address computation
3141 for all references to such slots. */
3142 /* fixup_stack_slots (); */
3144 /* Find all the EH handlers. */
3145 find_exception_handler_labels ();
3147 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3148 are initialized and to compute whether control can drop off the end
3149 of the function. */
3150 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3151 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
3153 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3154 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3155 goto exit_rest_of_compilation;
3157 /* Dump rtl code after jump, if we are doing that. */
3159 if (jump_opt_dump)
3160 TIMEVAR (dump_time,
3162 fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
3163 (*decl_printable_name) (decl, 2));
3164 print_rtl (jump_opt_dump_file, insns);
3165 fflush (jump_opt_dump_file);
3168 /* Perform common subexpression elimination.
3169 Nonzero value from `cse_main' means that jumps were simplified
3170 and some code may now be unreachable, so do
3171 jump optimization again. */
3173 if (cse_dump)
3174 TIMEVAR (dump_time,
3176 fprintf (cse_dump_file, "\n;; Function %s\n\n",
3177 (*decl_printable_name) (decl, 2));
3180 if (optimize > 0)
3182 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3184 if (flag_thread_jumps)
3185 /* Hacks by tiemann & kenner. */
3186 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3188 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3189 0, cse_dump_file));
3190 TIMEVAR (cse_time, delete_dead_from_cse (insns, max_reg_num ()));
3192 if (tem || optimize > 1)
3193 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3196 /* Dump rtl code after cse, if we are doing that. */
3198 if (cse_dump)
3199 TIMEVAR (dump_time,
3201 print_rtl (cse_dump_file, insns);
3202 fflush (cse_dump_file);
3205 if (loop_dump)
3206 TIMEVAR (dump_time,
3208 fprintf (loop_dump_file, "\n;; Function %s\n\n",
3209 (*decl_printable_name) (decl, 2));
3212 /* Move constant computations out of loops. */
3214 if (optimize > 0)
3216 TIMEVAR (loop_time,
3218 loop_optimize (insns, loop_dump_file);
3222 /* Dump rtl code after loop opt, if we are doing that. */
3224 if (loop_dump)
3225 TIMEVAR (dump_time,
3227 print_rtl (loop_dump_file, insns);
3228 fflush (loop_dump_file);
3231 if (cse2_dump)
3232 TIMEVAR (dump_time,
3234 fprintf (cse2_dump_file, "\n;; Function %s\n\n",
3235 (*decl_printable_name) (decl, 2));
3238 if (optimize > 0 && flag_rerun_cse_after_loop)
3240 /* Running another jump optimization pass before the second
3241 cse pass sometimes simplifies the RTL enough to allow
3242 the second CSE pass to do a better job. Jump_optimize can change
3243 max_reg_num so we must rerun reg_scan afterwards.
3244 ??? Rework to not call reg_scan so often. */
3245 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3246 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
3248 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3249 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3250 1, cse2_dump_file));
3251 if (tem)
3252 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3255 if (optimize > 0 && flag_thread_jumps)
3257 /* This pass of jump threading straightens out code
3258 that was kinked by loop optimization. */
3259 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3260 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3262 /* Dump rtl code after cse, if we are doing that. */
3264 if (cse2_dump)
3265 TIMEVAR (dump_time,
3267 print_rtl (cse2_dump_file, insns);
3268 fflush (cse2_dump_file);
3271 if (branch_prob_dump)
3272 TIMEVAR (dump_time,
3274 fprintf (branch_prob_dump_file, "\n;; Function %s\n\n",
3275 (*decl_printable_name) (decl, 2));
3278 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3279 TIMEVAR (branch_prob_time,
3281 branch_prob (insns, branch_prob_dump_file);
3284 if (branch_prob_dump)
3285 TIMEVAR (dump_time,
3287 print_rtl (branch_prob_dump_file, insns);
3288 fflush (branch_prob_dump_file);
3290 /* We are no longer anticipating cse in this function, at least. */
3292 cse_not_expected = 1;
3294 /* Now we choose between stupid (pcc-like) register allocation
3295 (if we got the -noreg switch and not -opt)
3296 and smart register allocation. */
3298 if (optimize > 0) /* Stupid allocation probably won't work */
3299 obey_regdecls = 0; /* if optimizations being done. */
3301 regclass_init ();
3303 /* Print function header into flow dump now
3304 because doing the flow analysis makes some of the dump. */
3306 if (flow_dump)
3307 TIMEVAR (dump_time,
3309 fprintf (flow_dump_file, "\n;; Function %s\n\n",
3310 (*decl_printable_name) (decl, 2));
3313 if (obey_regdecls)
3315 TIMEVAR (flow_time,
3317 regclass (insns, max_reg_num ());
3318 stupid_life_analysis (insns, max_reg_num (),
3319 flow_dump_file);
3322 else
3324 /* Do control and data flow analysis,
3325 and write some of the results to dump file. */
3327 TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
3328 flow_dump_file));
3329 if (warn_uninitialized)
3331 uninitialized_vars_warning (DECL_INITIAL (decl));
3332 setjmp_args_warning ();
3336 /* Dump rtl after flow analysis. */
3338 if (flow_dump)
3339 TIMEVAR (dump_time,
3341 print_rtl (flow_dump_file, insns);
3342 fflush (flow_dump_file);
3345 /* If -opt, try combining insns through substitution. */
3347 if (optimize > 0)
3348 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
3350 /* Dump rtl code after insn combination. */
3352 if (combine_dump)
3353 TIMEVAR (dump_time,
3355 fprintf (combine_dump_file, "\n;; Function %s\n\n",
3356 (*decl_printable_name) (decl, 2));
3357 dump_combine_stats (combine_dump_file);
3358 print_rtl (combine_dump_file, insns);
3359 fflush (combine_dump_file);
3362 if (regmove_dump)
3363 TIMEVAR (dump_time,
3365 fprintf (regmove_dump_file, "\n;; Function %s\n\n",
3366 (*decl_printable_name) (decl, 2));
3369 /* Register allocation pre-pass, to reduce number of moves
3370 necessary for two-address machines. */
3371 if (optimize > 0 && flag_regmove)
3372 TIMEVAR (regmove_time, regmove_optimize (insns, max_reg_num (),
3373 regmove_dump_file));
3375 if (regmove_dump)
3376 TIMEVAR (dump_time,
3378 print_rtl (regmove_dump_file, insns);
3379 fflush (regmove_dump_file);
3382 /* Print function header into sched dump now
3383 because doing the sched analysis makes some of the dump. */
3385 if (sched_dump)
3386 TIMEVAR (dump_time,
3388 fprintf (sched_dump_file, "\n;; Function %s\n\n",
3389 (*decl_printable_name) (decl, 2));
3392 if (optimize > 0 && flag_schedule_insns)
3394 /* Do control and data sched analysis,
3395 and write some of the results to dump file. */
3397 TIMEVAR (sched_time, schedule_insns (sched_dump_file));
3400 /* Dump rtl after instruction scheduling. */
3402 if (sched_dump)
3403 TIMEVAR (dump_time,
3405 print_rtl (sched_dump_file, insns);
3406 fflush (sched_dump_file);
3409 /* Unless we did stupid register allocation,
3410 allocate pseudo-regs that are used only within 1 basic block. */
3412 if (!obey_regdecls)
3413 TIMEVAR (local_alloc_time,
3415 regclass (insns, max_reg_num ());
3416 local_alloc ();
3419 /* Dump rtl code after allocating regs within basic blocks. */
3421 if (local_reg_dump)
3422 TIMEVAR (dump_time,
3424 fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
3425 (*decl_printable_name) (decl, 2));
3426 dump_flow_info (local_reg_dump_file);
3427 dump_local_alloc (local_reg_dump_file);
3428 print_rtl (local_reg_dump_file, insns);
3429 fflush (local_reg_dump_file);
3432 if (global_reg_dump)
3433 TIMEVAR (dump_time,
3434 fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
3435 (*decl_printable_name) (decl, 2)));
3437 /* Save the last label number used so far, so reorg can tell
3438 when it's safe to kill spill regs. */
3439 max_label_num_after_reload = max_label_num ();
3441 /* Unless we did stupid register allocation,
3442 allocate remaining pseudo-regs, then do the reload pass
3443 fixing up any insns that are invalid. */
3445 TIMEVAR (global_alloc_time,
3447 if (!obey_regdecls)
3448 failure = global_alloc (global_reg_dump_file);
3449 else
3450 failure = reload (insns, 0, global_reg_dump_file);
3453 if (global_reg_dump)
3454 TIMEVAR (dump_time,
3456 dump_global_regs (global_reg_dump_file);
3457 print_rtl (global_reg_dump_file, insns);
3458 fflush (global_reg_dump_file);
3461 if (failure)
3462 goto exit_rest_of_compilation;
3464 reload_completed = 1;
3466 /* Do a very simple CSE pass over just the hard registers. */
3467 if (optimize > 0)
3468 reload_cse_regs (insns);
3470 /* On some machines, the prologue and epilogue code, or parts thereof,
3471 can be represented as RTL. Doing so lets us schedule insns between
3472 it and the rest of the code and also allows delayed branch
3473 scheduling to operate in the epilogue. */
3475 thread_prologue_and_epilogue_insns (insns);
3477 if (optimize > 0 && flag_schedule_insns_after_reload)
3479 if (sched2_dump)
3480 TIMEVAR (dump_time,
3482 fprintf (sched2_dump_file, "\n;; Function %s\n\n",
3483 (*decl_printable_name) (decl, 2));
3486 /* Do control and data sched analysis again,
3487 and write some more of the results to dump file. */
3489 TIMEVAR (sched2_time, schedule_insns (sched2_dump_file));
3491 /* Dump rtl after post-reorder instruction scheduling. */
3493 if (sched2_dump)
3494 TIMEVAR (dump_time,
3496 print_rtl (sched2_dump_file, insns);
3497 fflush (sched2_dump_file);
3501 #ifdef LEAF_REGISTERS
3502 leaf_function = 0;
3503 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
3504 leaf_function = 1;
3505 #endif
3507 /* One more attempt to remove jumps to .+1
3508 left by dead-store-elimination.
3509 Also do cross-jumping this time
3510 and delete no-op move insns. */
3512 if (optimize > 0)
3514 TIMEVAR (jump_time, jump_optimize (insns, 1, 1, 0));
3517 /* Dump rtl code after jump, if we are doing that. */
3519 if (jump2_opt_dump)
3520 TIMEVAR (dump_time,
3522 fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
3523 (*decl_printable_name) (decl, 2));
3524 print_rtl (jump2_opt_dump_file, insns);
3525 fflush (jump2_opt_dump_file);
3528 /* If a machine dependent reorganization is needed, call it. */
3529 #ifdef MACHINE_DEPENDENT_REORG
3530 MACHINE_DEPENDENT_REORG (insns);
3531 #endif
3533 /* If a scheduling pass for delayed branches is to be done,
3534 call the scheduling code. */
3536 #ifdef DELAY_SLOTS
3537 if (optimize > 0 && flag_delayed_branch)
3539 TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
3540 if (dbr_sched_dump)
3542 TIMEVAR (dump_time,
3544 fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
3545 (*decl_printable_name) (decl, 2));
3546 print_rtl (dbr_sched_dump_file, insns);
3547 fflush (dbr_sched_dump_file);
3551 #endif
3553 /* Shorten branches. */
3554 TIMEVAR (shorten_branch_time,
3556 shorten_branches (get_insns ());
3559 #ifdef STACK_REGS
3560 TIMEVAR (stack_reg_time, reg_to_stack (insns, stack_reg_dump_file));
3561 if (stack_reg_dump)
3563 TIMEVAR (dump_time,
3565 fprintf (stack_reg_dump_file, "\n;; Function %s\n\n",
3566 (*decl_printable_name) (decl, 2));
3567 print_rtl (stack_reg_dump_file, insns);
3568 fflush (stack_reg_dump_file);
3571 #endif
3573 /* Now turn the rtl into assembler code. */
3575 TIMEVAR (final_time,
3577 rtx x;
3578 char *fnname;
3580 /* Get the function's name, as described by its RTL.
3581 This may be different from the DECL_NAME name used
3582 in the source file. */
3584 x = DECL_RTL (decl);
3585 if (GET_CODE (x) != MEM)
3586 abort ();
3587 x = XEXP (x, 0);
3588 if (GET_CODE (x) != SYMBOL_REF)
3589 abort ();
3590 fnname = XSTR (x, 0);
3592 assemble_start_function (decl, fnname);
3593 final_start_function (insns, asm_out_file, optimize);
3594 final (insns, asm_out_file, optimize, 0);
3595 final_end_function (insns, asm_out_file, optimize);
3596 assemble_end_function (decl, fnname);
3597 fflush (asm_out_file);
3599 /* Release all memory held by regsets now */
3600 regset_release_memory ();
3603 /* Write DBX symbols if requested */
3605 /* Note that for those inline functions where we don't initially
3606 know for certain that we will be generating an out-of-line copy,
3607 the first invocation of this routine (rest_of_compilation) will
3608 skip over this code by doing a `goto exit_rest_of_compilation;'.
3609 Later on, finish_compilation will call rest_of_compilation again
3610 for those inline functions that need to have out-of-line copies
3611 generated. During that call, we *will* be routed past here. */
3613 #ifdef DBX_DEBUGGING_INFO
3614 if (write_symbols == DBX_DEBUG)
3615 TIMEVAR (symout_time, dbxout_function (decl));
3616 #endif
3618 #ifdef DWARF_DEBUGGING_INFO
3619 if (write_symbols == DWARF_DEBUG)
3620 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3621 #endif
3623 #ifdef DWARF2_DEBUGGING_INFO
3624 if (write_symbols == DWARF2_DEBUG)
3625 TIMEVAR (symout_time, dwarf2out_decl (decl));
3626 #endif
3628 exit_rest_of_compilation:
3630 /* In case the function was not output,
3631 don't leave any temporary anonymous types
3632 queued up for sdb output. */
3633 #ifdef SDB_DEBUGGING_INFO
3634 if (write_symbols == SDB_DEBUG)
3635 sdbout_types (NULL_TREE);
3636 #endif
3638 /* Put back the tree of subblocks and list of arguments
3639 from before we copied them.
3640 Code generation and the output of debugging info may have modified
3641 the copy, but the original is unchanged. */
3643 if (saved_block_tree != 0)
3645 DECL_INITIAL (decl) = saved_block_tree;
3646 DECL_ARGUMENTS (decl) = saved_arguments;
3647 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
3650 reload_completed = 0;
3652 /* Clear out the insn_length contents now that they are no longer valid. */
3653 init_insn_lengths ();
3655 /* Clear out the real_constant_chain before some of the rtx's
3656 it runs through become garbage. */
3658 clear_const_double_mem ();
3660 /* Cancel the effect of rtl_in_current_obstack. */
3662 resume_temporary_allocation ();
3664 /* Show no temporary slots allocated. */
3666 init_temp_slots ();
3668 /* The parsing time is all the time spent in yyparse
3669 *except* what is spent in this function. */
3671 parse_time -= get_run_time () - start_time;
3674 /* Entry point of cc1/c++. Decode command args, then call compile_file.
3675 Exit code is 35 if can't open files, 34 if fatal error,
3676 33 if had nonfatal errors, else success. */
3679 main (argc, argv, envp)
3680 int argc;
3681 char **argv;
3682 char **envp;
3684 register int i;
3685 char *filename = 0;
3686 int flag_print_mem = 0;
3687 int version_flag = 0;
3688 char *p;
3690 /* save in case md file wants to emit args as a comment. */
3691 save_argc = argc;
3692 save_argv = argv;
3694 p = argv[0] + strlen (argv[0]);
3695 while (p != argv[0] && p[-1] != '/'
3696 #ifdef DIR_SEPARATOR
3697 && p[-1] != DIR_SEPARATOR
3698 #endif
3700 --p;
3701 progname = p;
3703 #ifdef RLIMIT_STACK
3704 /* Get rid of any avoidable limit on stack size. */
3706 struct rlimit rlim;
3708 /* Set the stack limit huge so that alloca does not fail. */
3709 getrlimit (RLIMIT_STACK, &rlim);
3710 rlim.rlim_cur = rlim.rlim_max;
3711 setrlimit (RLIMIT_STACK, &rlim);
3713 #endif /* RLIMIT_STACK */
3715 signal (SIGFPE, float_signal);
3717 #ifdef SIGPIPE
3718 signal (SIGPIPE, pipe_closed);
3719 #endif
3721 decl_printable_name = decl_name;
3722 lang_expand_expr = (struct rtx_def *(*)()) do_abort;
3724 /* Initialize whether `char' is signed. */
3725 flag_signed_char = DEFAULT_SIGNED_CHAR;
3726 #ifdef DEFAULT_SHORT_ENUMS
3727 /* Initialize how much space enums occupy, by default. */
3728 flag_short_enums = DEFAULT_SHORT_ENUMS;
3729 #endif
3731 /* Scan to see what optimization level has been specified. That will
3732 determine the default value of many flags. */
3733 for (i = 1; i < argc; i++)
3735 if (!strcmp (argv[i], "-O"))
3737 optimize = 1;
3739 else if (argv[i][0] == '-' && argv[i][1] == 'O')
3741 /* Handle -O2, -O3, -O69, ... */
3742 char *p = &argv[i][2];
3743 int c;
3745 while (c = *p++)
3746 if (! (c >= '0' && c <= '9'))
3747 break;
3748 if (c == 0)
3749 optimize = atoi (&argv[i][2]);
3753 obey_regdecls = (optimize == 0);
3755 if (optimize >= 1)
3757 flag_defer_pop = 1;
3758 flag_thread_jumps = 1;
3759 #ifdef DELAY_SLOTS
3760 flag_delayed_branch = 1;
3761 #endif
3762 #ifdef CAN_DEBUG_WITHOUT_FP
3763 flag_omit_frame_pointer = 1;
3764 #endif
3765 flag_alias_check = 1;
3768 if (optimize >= 2)
3770 flag_cse_follow_jumps = 1;
3771 flag_cse_skip_blocks = 1;
3772 flag_expensive_optimizations = 1;
3773 flag_strength_reduce = 1;
3774 flag_rerun_cse_after_loop = 1;
3775 flag_caller_saves = 1;
3776 flag_force_mem = 1;
3777 #ifdef INSN_SCHEDULING
3778 flag_schedule_insns = 1;
3779 flag_schedule_insns_after_reload = 1;
3780 #endif
3781 flag_regmove = 1;
3784 if (optimize >= 3)
3786 flag_inline_functions = 1;
3789 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
3790 modify it. */
3791 target_flags = 0;
3792 set_target_switch ("");
3794 #ifdef OPTIMIZATION_OPTIONS
3795 /* Allow default optimizations to be specified on a per-machine basis. */
3796 OPTIMIZATION_OPTIONS (optimize);
3797 #endif
3799 /* Initialize register usage now so switches may override. */
3800 init_reg_sets ();
3802 for (i = 1; i < argc; i++)
3804 int j;
3805 /* If this is a language-specific option,
3806 decode it in a language-specific way. */
3807 for (j = 0; lang_options[j] != 0; j++)
3808 if (!strncmp (argv[i], lang_options[j],
3809 strlen (lang_options[j])))
3810 break;
3811 if (lang_options[j] != 0)
3812 /* If the option is valid for *some* language,
3813 treat it as valid even if this language doesn't understand it. */
3814 lang_decode_option (argv[i]);
3815 else if (argv[i][0] == '-' && argv[i][1] != 0)
3817 register char *str = argv[i] + 1;
3818 if (str[0] == 'Y')
3819 str++;
3821 if (str[0] == 'm')
3822 set_target_switch (&str[1]);
3823 else if (!strcmp (str, "dumpbase"))
3825 dump_base_name = argv[++i];
3827 else if (str[0] == 'd')
3829 register char *p = &str[1];
3830 while (*p)
3831 switch (*p++)
3833 case 'a':
3834 branch_prob_dump = 1;
3835 combine_dump = 1;
3836 dbr_sched_dump = 1;
3837 flow_dump = 1;
3838 global_reg_dump = 1;
3839 jump_opt_dump = 1;
3840 jump2_opt_dump = 1;
3841 local_reg_dump = 1;
3842 loop_dump = 1;
3843 regmove_dump = 1;
3844 rtl_dump = 1;
3845 cse_dump = 1, cse2_dump = 1;
3846 sched_dump = 1;
3847 sched2_dump = 1;
3848 stack_reg_dump = 1;
3849 break;
3850 case 'b':
3851 branch_prob_dump = 1;
3852 break;
3853 case 'k':
3854 stack_reg_dump = 1;
3855 break;
3856 case 'c':
3857 combine_dump = 1;
3858 break;
3859 case 'd':
3860 dbr_sched_dump = 1;
3861 break;
3862 case 'f':
3863 flow_dump = 1;
3864 break;
3865 case 'g':
3866 global_reg_dump = 1;
3867 break;
3868 case 'j':
3869 jump_opt_dump = 1;
3870 break;
3871 case 'J':
3872 jump2_opt_dump = 1;
3873 break;
3874 case 'l':
3875 local_reg_dump = 1;
3876 break;
3877 case 'L':
3878 loop_dump = 1;
3879 break;
3880 case 'm':
3881 flag_print_mem = 1;
3882 break;
3883 case 'p':
3884 flag_print_asm_name = 1;
3885 break;
3886 case 'r':
3887 rtl_dump = 1;
3888 break;
3889 case 's':
3890 cse_dump = 1;
3891 break;
3892 case 't':
3893 cse2_dump = 1;
3894 break;
3895 case 'N':
3896 regmove_dump = 1;
3897 break;
3898 case 'S':
3899 sched_dump = 1;
3900 break;
3901 case 'R':
3902 sched2_dump = 1;
3903 break;
3904 case 'y':
3905 set_yydebug (1);
3906 break;
3907 case 'x':
3908 rtl_dump_and_exit = 1;
3909 break;
3910 case 'A':
3911 flag_debug_asm = 1;
3912 break;
3915 else if (str[0] == 'f')
3917 register char *p = &str[1];
3918 int found = 0;
3920 /* Some kind of -f option.
3921 P's value is the option sans `-f'.
3922 Search for it in the table of options. */
3924 for (j = 0;
3925 !found && j < sizeof (f_options) / sizeof (f_options[0]);
3926 j++)
3928 if (!strcmp (p, f_options[j].string))
3930 *f_options[j].variable = f_options[j].on_value;
3931 /* A goto here would be cleaner,
3932 but breaks the vax pcc. */
3933 found = 1;
3935 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3936 && ! strcmp (p+3, f_options[j].string))
3938 *f_options[j].variable = ! f_options[j].on_value;
3939 found = 1;
3943 if (found)
3945 #ifdef HAIFA
3946 #ifdef INSN_SCHEDULING
3947 else if (!strncmp (p, "sched-verbose-",14))
3948 fix_sched_param("verbose",&p[14]);
3949 else if (!strncmp (p, "sched-max-",10))
3950 fix_sched_param("max",&p[10]);
3951 else if (!strncmp (p, "sched-inter-max-b-",18))
3952 fix_sched_param("interblock-max-blocks",&p[18]);
3953 else if (!strncmp (p, "sched-inter-max-i-",18))
3954 fix_sched_param("interblock-max-insns",&p[18]);
3955 #endif
3956 #endif /* HAIFA */
3957 else if (!strncmp (p, "fixed-", 6))
3958 fix_register (&p[6], 1, 1);
3959 else if (!strncmp (p, "call-used-", 10))
3960 fix_register (&p[10], 0, 1);
3961 else if (!strncmp (p, "call-saved-", 11))
3962 fix_register (&p[11], 0, 0);
3963 else
3964 error ("Invalid option `%s'", argv[i]);
3966 else if (str[0] == 'O')
3968 register char *p = str+1;
3969 while (*p && *p >= '0' && *p <= '9')
3970 p++;
3971 if (*p == '\0')
3973 else
3974 error ("Invalid option `%s'", argv[i]);
3976 else if (!strcmp (str, "pedantic"))
3977 pedantic = 1;
3978 else if (!strcmp (str, "pedantic-errors"))
3979 flag_pedantic_errors = pedantic = 1;
3980 else if (!strcmp (str, "quiet"))
3981 quiet_flag = 1;
3982 else if (!strcmp (str, "version"))
3983 version_flag = 1;
3984 else if (!strcmp (str, "w"))
3985 inhibit_warnings = 1;
3986 else if (!strcmp (str, "W"))
3988 extra_warnings = 1;
3989 /* We save the value of warn_uninitialized, since if they put
3990 -Wuninitialized on the command line, we need to generate a
3991 warning about not using it without also specifying -O. */
3992 if (warn_uninitialized != 1)
3993 warn_uninitialized = 2;
3995 else if (str[0] == 'W')
3997 register char *p = &str[1];
3998 int found = 0;
4000 /* Some kind of -W option.
4001 P's value is the option sans `-W'.
4002 Search for it in the table of options. */
4004 for (j = 0;
4005 !found && j < sizeof (W_options) / sizeof (W_options[0]);
4006 j++)
4008 if (!strcmp (p, W_options[j].string))
4010 *W_options[j].variable = W_options[j].on_value;
4011 /* A goto here would be cleaner,
4012 but breaks the vax pcc. */
4013 found = 1;
4015 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
4016 && ! strcmp (p+3, W_options[j].string))
4018 *W_options[j].variable = ! W_options[j].on_value;
4019 found = 1;
4023 if (found)
4025 else if (!strncmp (p, "id-clash-", 9))
4027 char *endp = p + 9;
4029 while (*endp)
4031 if (*endp >= '0' && *endp <= '9')
4032 endp++;
4033 else
4035 error ("Invalid option `%s'", argv[i]);
4036 goto id_clash_lose;
4039 warn_id_clash = 1;
4040 id_clash_len = atoi (str + 10);
4041 id_clash_lose: ;
4043 else if (!strncmp (p, "larger-than-", 12))
4045 char *endp = p + 12;
4047 while (*endp)
4049 if (*endp >= '0' && *endp <= '9')
4050 endp++;
4051 else
4053 error ("Invalid option `%s'", argv[i]);
4054 goto larger_than_lose;
4057 warn_larger_than = 1;
4058 larger_than_size = atoi (str + 13);
4059 larger_than_lose: ;
4061 else
4062 error ("Invalid option `%s'", argv[i]);
4064 else if (!strcmp (str, "p"))
4066 profile_flag = 1;
4068 else if (!strcmp (str, "a"))
4070 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4071 warning ("`-a' option (basic block profile) not supported");
4072 #else
4073 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
4074 #endif
4076 else if (!strcmp (str, "ax"))
4078 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4079 warning ("`-ax' option (jump profiling) not supported");
4080 #else
4081 profile_block_flag = (!profile_block_flag
4082 || profile_block_flag == 2) ? 2 : 3;
4083 #endif
4085 else if (str[0] == 'g')
4087 unsigned len;
4088 unsigned level;
4089 /* A lot of code assumes write_symbols == NO_DEBUG if the
4090 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4091 of what debugging type has been selected). This records the
4092 selected type. It is an error to specify more than one
4093 debugging type. */
4094 static enum debug_info_type selected_debug_type = NO_DEBUG;
4095 /* Non-zero if debugging format has been explicitly set.
4096 -g and -ggdb don't explicitly set the debugging format so
4097 -gdwarf -g3 is equivalent to -gdwarf3. */
4098 static int type_explicitly_set_p = 0;
4099 /* Table of supported debugging formats. */
4100 static struct {
4101 char *arg;
4102 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
4103 constant expression, we use NO_DEBUG in its place. */
4104 enum debug_info_type debug_type;
4105 int use_extensions_p;
4106 } *da, debug_args[] = {
4107 { "g", NO_DEBUG, DEFAULT_GDB_EXTENSIONS },
4108 { "ggdb", NO_DEBUG, 1 },
4109 #ifdef DBX_DEBUGGING_INFO
4110 { "gstabs", DBX_DEBUG, 0 },
4111 { "gstabs+", DBX_DEBUG, 1 },
4112 #endif
4113 #ifdef DWARF_DEBUGGING_INFO
4114 { "gdwarf", DWARF_DEBUG, 0 },
4115 { "gdwarf+", DWARF_DEBUG, 1 },
4116 #endif
4117 #ifdef DWARF2_DEBUGGING_INFO
4118 { "gdwarf-2", DWARF2_DEBUG, 0 },
4119 #endif
4120 #ifdef XCOFF_DEBUGGING_INFO
4121 { "gxcoff", XCOFF_DEBUG, 0 },
4122 { "gxcoff+", XCOFF_DEBUG, 1 },
4123 #endif
4124 #ifdef SDB_DEBUGGING_INFO
4125 { "gcoff", SDB_DEBUG, 0 },
4126 #endif
4127 { 0, 0, 0 }
4129 /* Indexed by enum debug_info_type. */
4130 static char *debug_type_names[] = {
4131 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
4134 /* Look up STR in the table. */
4135 for (da = debug_args; da->arg; da++)
4137 if (! strncmp (str, da->arg, strlen (da->arg)))
4139 enum debug_info_type type = da->debug_type;
4140 char *p, *q;
4142 p = str + strlen (da->arg);
4143 if (*p && (*p < '0' || *p > '9'))
4144 continue;
4145 q = p;
4146 len = p - str;
4147 while (*q && (*q >= '0' && *q <= '9'))
4148 q++;
4149 if (*p)
4150 level = atoi (p);
4151 else
4152 level = 2; /* default debugging info level */
4153 if (*q || level > 3)
4155 warning ("invalid debug level specification in option: `-%s'",
4156 str);
4157 /* ??? This error message is incorrect in the case of
4158 -g4 -g. */
4159 warning ("no debugging information will be generated");
4160 level = 0;
4163 if (type == NO_DEBUG)
4165 type = PREFERRED_DEBUGGING_TYPE;
4166 if (len > 1 && strncmp (str, "ggdb", len) == 0)
4168 #ifdef DWARF2_DEBUGGING_INFO
4169 type = DWARF2_DEBUG;
4170 #elif defined DBX_DEBUGGING_INFO
4171 type = DBX_DEBUG;
4172 #endif
4176 if (type == NO_DEBUG)
4177 warning ("`-%s' not supported by this configuration of GCC",
4178 str);
4180 /* Does it conflict with an already selected type? */
4181 if (type_explicitly_set_p
4182 /* -g/-ggdb don't conflict with anything */
4183 && da->debug_type != NO_DEBUG
4184 && type != selected_debug_type)
4185 warning ("`-%s' ignored, conflicts with `-g%s'",
4186 str, debug_type_names[(int) selected_debug_type]);
4187 else
4189 /* If the format has already been set, -g/-ggdb
4190 only change the debug level. */
4191 if (type_explicitly_set_p
4192 && da->debug_type == NO_DEBUG)
4193 ; /* don't change debugging type */
4194 else
4196 selected_debug_type = type;
4197 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4199 write_symbols = (level == 0
4200 ? NO_DEBUG
4201 : selected_debug_type);
4202 use_gnu_debug_info_extensions = da->use_extensions_p;
4203 debug_info_level = (enum debug_info_level) level;
4205 break;
4208 if (! da->arg)
4209 warning ("`-%s' not supported by this configuration of GCC",
4210 str);
4212 else if (!strcmp (str, "o"))
4214 asm_file_name = argv[++i];
4216 else if (str[0] == 'G')
4218 g_switch_set = TRUE;
4219 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
4221 else if (!strncmp (str, "aux-info", 8))
4223 flag_gen_aux_info = 1;
4224 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
4226 else
4227 error ("Invalid option `%s'", argv[i]);
4229 else if (argv[i][0] == '+')
4230 error ("Invalid option `%s'", argv[i]);
4231 else
4232 filename = argv[i];
4235 /* Checker uses the frame pointer. */
4236 if (flag_check_memory_usage)
4237 flag_omit_frame_pointer = 0;
4239 /* Initialize for bytecode output. A good idea to do this as soon as
4240 possible after the "-f" options have been parsed. */
4241 if (output_bytecode)
4243 #ifndef TARGET_SUPPORTS_BYTECODE
4244 /* Just die with a fatal error if not supported */
4245 fatal ("-fbytecode not supported for this target");
4246 #else
4247 bc_initialize ();
4248 #endif
4251 if (optimize == 0)
4253 /* Inlining does not work if not optimizing,
4254 so force it not to be done. */
4255 flag_no_inline = 1;
4256 warn_inline = 0;
4258 /* The c_decode_option and lang_decode_option functions set
4259 this to `2' if -Wall is used, so we can avoid giving out
4260 lots of errors for people who don't realize what -Wall does. */
4261 if (warn_uninitialized == 1)
4262 warning ("-Wuninitialized is not supported without -O");
4265 #ifdef OVERRIDE_OPTIONS
4266 /* Some machines may reject certain combinations of options. */
4267 OVERRIDE_OPTIONS;
4268 #endif
4270 if (profile_block_flag == 3)
4272 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
4273 profile_block_flag = 2;
4276 /* Unrolling all loops implies that standard loop unrolling must also
4277 be done. */
4278 if (flag_unroll_all_loops)
4279 flag_unroll_loops = 1;
4280 /* Loop unrolling requires that strength_reduction be on also. Silently
4281 turn on strength reduction here if it isn't already on. Also, the loop
4282 unrolling code assumes that cse will be run after loop, so that must
4283 be turned on also. */
4284 if (flag_unroll_loops)
4286 flag_strength_reduce = 1;
4287 flag_rerun_cse_after_loop = 1;
4290 /* Warn about options that are not supported on this machine. */
4291 #ifndef INSN_SCHEDULING
4292 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4293 warning ("instruction scheduling not supported on this target machine");
4294 #endif
4295 #ifndef DELAY_SLOTS
4296 if (flag_delayed_branch)
4297 warning ("this target machine does not have delayed branches");
4298 #endif
4300 /* If we are in verbose mode, write out the version and maybe all the
4301 option flags in use. */
4302 if (version_flag)
4304 print_version (stderr, "");
4305 if (! quiet_flag)
4306 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4309 compile_file (filename);
4311 #if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN32__))
4312 if (flag_print_mem)
4314 char *lim = (char *) sbrk (0);
4316 fprintf (stderr, "Data size %d.\n",
4317 lim - (char *) &environ);
4318 fflush (stderr);
4320 #ifdef USG
4321 system ("ps -l 1>&2");
4322 #else /* not USG */
4323 system ("ps v");
4324 #endif /* not USG */
4326 #endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN32) */
4328 if (errorcount)
4329 exit (FATAL_EXIT_CODE);
4330 if (sorrycount)
4331 exit (FATAL_EXIT_CODE);
4332 exit (SUCCESS_EXIT_CODE);
4333 return 0;
4336 /* Decode -m switches. */
4338 /* Here is a table, controlled by the tm.h file, listing each -m switch
4339 and which bits in `target_switches' it should set or clear.
4340 If VALUE is positive, it is bits to set.
4341 If VALUE is negative, -VALUE is bits to clear.
4342 (The sign bit is not used so there is no confusion.) */
4344 struct {char *name; int value;} target_switches []
4345 = TARGET_SWITCHES;
4347 /* This table is similar, but allows the switch to have a value. */
4349 #ifdef TARGET_OPTIONS
4350 struct {char *prefix; char ** variable;} target_options []
4351 = TARGET_OPTIONS;
4352 #endif
4354 /* Decode the switch -mNAME. */
4356 void
4357 set_target_switch (name)
4358 char *name;
4360 register int j;
4361 int valid = 0;
4363 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4364 if (!strcmp (target_switches[j].name, name))
4366 if (target_switches[j].value < 0)
4367 target_flags &= ~-target_switches[j].value;
4368 else
4369 target_flags |= target_switches[j].value;
4370 valid = 1;
4373 #ifdef TARGET_OPTIONS
4374 if (!valid)
4375 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4377 int len = strlen (target_options[j].prefix);
4378 if (!strncmp (target_options[j].prefix, name, len))
4380 *target_options[j].variable = name + len;
4381 valid = 1;
4384 #endif
4386 if (!valid)
4387 error ("Invalid option `%s'", name);
4390 /* Print version information to FILE.
4391 Each line begins with INDENT (for the case where FILE is the
4392 assembler output file). */
4394 void
4395 print_version (file, indent)
4396 FILE *file;
4397 char *indent;
4399 fprintf (file, "%s%s%s version %s", indent, *indent != 0 ? " " : "",
4400 language_string, version_string);
4401 fprintf (file, " (%s)", TARGET_NAME);
4402 #ifdef __GNUC__
4403 #ifndef __VERSION__
4404 #define __VERSION__ "[unknown]"
4405 #endif
4406 fprintf (file, " compiled by GNU C version %s.\n", __VERSION__);
4407 #else
4408 fprintf (file, " compiled by CC.\n");
4409 #endif
4412 /* Print an option value and return the adjusted position in the line.
4413 ??? We don't handle error returns from fprintf (disk full); presumably
4414 other code will catch a disk full though. */
4417 print_single_switch (file, pos, max, indent, sep, term, type, name)
4418 FILE *file;
4419 int pos, max;
4420 char *indent, *sep, *term, *type, *name;
4422 /* The ultrix fprintf returns 0 on success, so compute the result we want
4423 here since we need it for the following test. */
4424 int len = strlen (sep) + strlen (type) + strlen (name);
4426 if (pos != 0
4427 && pos + len > max)
4429 fprintf (file, "%s", term);
4430 pos = 0;
4432 if (pos == 0)
4434 fprintf (file, "%s", indent);
4435 pos = strlen (indent);
4437 fprintf (file, "%s%s%s", sep, type, name);
4438 pos += len;
4439 return pos;
4442 /* Print active target switches to FILE.
4443 POS is the current cursor position and MAX is the size of a "line".
4444 Each line begins with INDENT and ends with TERM.
4445 Each switch is separated from the next by SEP. */
4447 void
4448 print_switch_values (file, pos, max, indent, sep, term)
4449 FILE *file;
4450 int pos, max;
4451 char *indent, *sep, *term;
4453 int j, flags;
4454 char **p;
4456 /* Print the options as passed. */
4458 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4459 "options passed: ", "");
4461 for (p = &save_argv[1]; *p != NULL; p++)
4462 if (**p == '-')
4464 /* Ignore these. */
4465 if (strcmp (*p, "-o") == 0)
4467 if (p[1] != NULL)
4468 p++;
4469 continue;
4471 if (strcmp (*p, "-quiet") == 0)
4472 continue;
4473 if (strcmp (*p, "-version") == 0)
4474 continue;
4475 if ((*p)[1] == 'd')
4476 continue;
4478 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4480 if (pos > 0)
4481 fprintf (file, "%s", term);
4483 /* Print the -f and -m options that have been enabled.
4484 We don't handle language specific options but printing argv
4485 should suffice. */
4487 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4488 "options enabled: ", "");
4490 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
4491 if (*f_options[j].variable == f_options[j].on_value)
4492 pos = print_single_switch (file, pos, max, indent, sep, term,
4493 "-f", f_options[j].string);
4495 /* Print target specific options. */
4497 flags = target_flags;
4498 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4499 if (target_switches[j].name[0] != '\0'
4500 && target_switches[j].value > 0
4501 && ((target_switches[j].value & target_flags)
4502 == target_switches[j].value))
4504 pos = print_single_switch (file, pos, max, indent, sep, term,
4505 "-m", target_switches[j].name);
4506 flags &= ~ target_switches[j].value;
4509 #ifdef TARGET_OPTIONS
4510 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4511 if (*target_options[j].variable != NULL)
4513 char prefix[256];
4514 sprintf (prefix, "-m%s", target_options[j].prefix);
4515 pos = print_single_switch (file, pos, max, indent, sep, term,
4516 prefix, *target_options[j].variable);
4518 #endif
4520 fprintf (file, "%s", term);
4523 /* Record the beginning of a new source file, named FILENAME. */
4525 void
4526 debug_start_source_file (filename)
4527 register char *filename;
4529 #ifdef DBX_DEBUGGING_INFO
4530 if (write_symbols == DBX_DEBUG)
4531 dbxout_start_new_source_file (filename);
4532 #endif
4533 #ifdef DWARF_DEBUGGING_INFO
4534 if (debug_info_level == DINFO_LEVEL_VERBOSE
4535 && write_symbols == DWARF_DEBUG)
4536 dwarfout_start_new_source_file (filename);
4537 #endif /* DWARF_DEBUGGING_INFO */
4538 #ifdef DWARF2_DEBUGGING_INFO
4539 if (debug_info_level == DINFO_LEVEL_VERBOSE
4540 && write_symbols == DWARF2_DEBUG)
4541 dwarf2out_start_source_file (filename);
4542 #endif /* DWARF2_DEBUGGING_INFO */
4543 #ifdef SDB_DEBUGGING_INFO
4544 if (write_symbols == SDB_DEBUG)
4545 sdbout_start_new_source_file (filename);
4546 #endif
4549 /* Record the resumption of a source file. LINENO is the line number in
4550 the source file we are returning to. */
4552 void
4553 debug_end_source_file (lineno)
4554 register unsigned lineno;
4556 #ifdef DBX_DEBUGGING_INFO
4557 if (write_symbols == DBX_DEBUG)
4558 dbxout_resume_previous_source_file ();
4559 #endif
4560 #ifdef DWARF_DEBUGGING_INFO
4561 if (debug_info_level == DINFO_LEVEL_VERBOSE
4562 && write_symbols == DWARF_DEBUG)
4563 dwarfout_resume_previous_source_file (lineno);
4564 #endif /* DWARF_DEBUGGING_INFO */
4565 #ifdef DWARF2_DEBUGGING_INFO
4566 if (debug_info_level == DINFO_LEVEL_VERBOSE
4567 && write_symbols == DWARF2_DEBUG)
4568 dwarf2out_end_source_file ();
4569 #endif /* DWARF2_DEBUGGING_INFO */
4570 #ifdef SDB_DEBUGGING_INFO
4571 if (write_symbols == SDB_DEBUG)
4572 sdbout_resume_previous_source_file ();
4573 #endif
4576 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
4577 the tail part of the directive line, i.e. the part which is past the
4578 initial whitespace, #, whitespace, directive-name, whitespace part. */
4580 void
4581 debug_define (lineno, buffer)
4582 register unsigned lineno;
4583 register char *buffer;
4585 #ifdef DWARF_DEBUGGING_INFO
4586 if (debug_info_level == DINFO_LEVEL_VERBOSE
4587 && write_symbols == DWARF_DEBUG)
4588 dwarfout_define (lineno, buffer);
4589 #endif /* DWARF_DEBUGGING_INFO */
4590 #ifdef DWARF2_DEBUGGING_INFO
4591 if (debug_info_level == DINFO_LEVEL_VERBOSE
4592 && write_symbols == DWARF2_DEBUG)
4593 dwarf2out_define (lineno, buffer);
4594 #endif /* DWARF2_DEBUGGING_INFO */
4597 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
4598 the tail part of the directive line, i.e. the part which is past the
4599 initial whitespace, #, whitespace, directive-name, whitespace part. */
4601 void
4602 debug_undef (lineno, buffer)
4603 register unsigned lineno;
4604 register char *buffer;
4606 #ifdef DWARF_DEBUGGING_INFO
4607 if (debug_info_level == DINFO_LEVEL_VERBOSE
4608 && write_symbols == DWARF_DEBUG)
4609 dwarfout_undef (lineno, buffer);
4610 #endif /* DWARF_DEBUGGING_INFO */
4611 #ifdef DWARF2_DEBUGGING_INFO
4612 if (debug_info_level == DINFO_LEVEL_VERBOSE
4613 && write_symbols == DWARF2_DEBUG)
4614 dwarf2out_undef (lineno, buffer);
4615 #endif /* DWARF2_DEBUGGING_INFO */