* mips.md: Define conditional move patterns for floating point
[official-gcc.git] / gcc / toplev.c
blob662ab4095f4d48aae982e6500a3d64f254c1d9a8
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 88, 89, 92-98, 1999 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 #undef FLOAT /* This is for hpux. They should change hpux. */
28 #undef FFS /* Some systems define this in param.h. */
29 #include "system.h"
30 #include <signal.h>
31 #include <setjmp.h>
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
35 #endif
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
39 #endif
41 #include "input.h"
42 #include "tree.h"
43 #include "rtl.h"
44 #include "tm_p.h"
45 #include "flags.h"
46 #include "insn-attr.h"
47 #include "insn-codes.h"
48 #include "insn-config.h"
49 #include "recog.h"
50 #include "defaults.h"
51 #include "output.h"
52 #include "except.h"
53 #include "function.h"
54 #include "toplev.h"
55 #include "expr.h"
56 #include "basic-block.h"
57 #include "intl.h"
58 #include "ggc.h"
59 #include "graph.h"
61 #ifdef DWARF_DEBUGGING_INFO
62 #include "dwarfout.h"
63 #endif
65 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
66 #include "dwarf2out.h"
67 #endif
69 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
70 #include "dbxout.h"
71 #endif
73 #ifdef SDB_DEBUGGING_INFO
74 #include "sdbout.h"
75 #endif
77 #ifdef XCOFF_DEBUGGING_INFO
78 #include "xcoffout.h"
79 #endif
81 #ifdef VMS
82 /* The extra parameters substantially improve the I/O performance. */
83 static FILE *
84 vms_fopen (fname, type)
85 char * fname;
86 char * type;
88 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
89 fixed arguments, which matches ANSI's specification but not VAXCRTL's
90 pre-ANSI implementation. This hack circumvents the mismatch problem. */
91 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
93 if (*type == 'w')
94 return (*vmslib_fopen) (fname, type, "mbc=32",
95 "deq=64", "fop=tef", "shr=nil");
96 else
97 return (*vmslib_fopen) (fname, type, "mbc=32");
99 #define fopen vms_fopen
100 #endif /* VMS */
102 #ifndef DEFAULT_GDB_EXTENSIONS
103 #define DEFAULT_GDB_EXTENSIONS 1
104 #endif
106 /* If more than one debugging type is supported, you must define
107 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
109 This is one long line cause VAXC can't handle a \-newline. */
110 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
111 #ifndef PREFERRED_DEBUGGING_TYPE
112 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
113 #endif /* no PREFERRED_DEBUGGING_TYPE */
114 #else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
115 so the following code needn't care. */
116 #ifdef DBX_DEBUGGING_INFO
117 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
118 #endif
119 #ifdef SDB_DEBUGGING_INFO
120 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
121 #endif
122 #ifdef DWARF_DEBUGGING_INFO
123 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
124 #endif
125 #ifdef DWARF2_DEBUGGING_INFO
126 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
127 #endif
128 #ifdef XCOFF_DEBUGGING_INFO
129 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
130 #endif
131 #endif /* More than one debugger format enabled. */
133 /* If still not defined, must have been because no debugging formats
134 are supported. */
135 #ifndef PREFERRED_DEBUGGING_TYPE
136 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
137 #endif
139 #ifndef DIR_SEPARATOR
140 #define DIR_SEPARATOR '/'
141 #endif
143 #if ! (defined (VMS) || defined (OS2))
144 extern char **environ;
145 #endif
146 extern char *version_string;
148 /* Carry information from ASM_DECLARE_OBJECT_NAME
149 to ASM_FINISH_DECLARE_OBJECT. */
151 extern int size_directive_output;
152 extern tree last_assemble_variable_decl;
154 static void notice PVPROTO((const char *s, ...)) ATTRIBUTE_PRINTF_1;
155 static void set_target_switch PROTO((const char *));
156 static const char *decl_name PROTO((tree, int));
157 static void vmessage PROTO((const char *, const char *, va_list));
158 static void v_message_with_file_and_line PROTO((const char *, int, int,
159 const char *, va_list));
160 static void v_message_with_decl PROTO((tree, int, const char *, va_list));
161 static void file_and_line_for_asm PROTO((rtx, char **, int *));
162 static void v_error_with_file_and_line PROTO((const char *, int,
163 const char *, va_list));
164 static void v_error_with_decl PROTO((tree, const char *, va_list));
165 static void v_error_for_asm PROTO((rtx, const char *, va_list));
166 static void verror PROTO((const char *, va_list));
167 static void vfatal PROTO((const char *, va_list)) ATTRIBUTE_NORETURN;
168 static void v_warning_with_file_and_line PROTO ((const char *, int,
169 const char *, va_list));
170 static void v_warning_with_decl PROTO((tree, const char *, va_list));
171 static void v_warning_for_asm PROTO((rtx, const char *, va_list));
172 static void vwarning PROTO((const char *, va_list));
173 static void vpedwarn PROTO((const char *, va_list));
174 static void v_pedwarn_with_decl PROTO((tree, const char *, va_list));
175 static void v_pedwarn_with_file_and_line PROTO((const char *, int,
176 const char *, va_list));
177 static void vsorry PROTO((const char *, va_list));
178 extern void set_fatal_function PROTO((void (*)(const char *, va_list)));
179 static void float_signal PROTO((int)) ATTRIBUTE_NORETURN;
180 static void pipe_closed PROTO((int)) ATTRIBUTE_NORETURN;
181 #ifdef ASM_IDENTIFY_LANGUAGE
182 /* This might or might not be used in ASM_IDENTIFY_LANGUAGE. */
183 static void output_lang_identify PROTO((FILE *)) ATTRIBUTE_UNUSED;
184 #endif
185 static void open_dump_file PROTO((const char *, const char *));
186 static void close_dump_file PROTO((void (*) (FILE *, rtx), rtx));
187 static void dump_rtl PROTO((const char *, tree, void (*) (FILE *, rtx), rtx));
188 static void clean_dump_file PROTO((const char *));
189 static void compile_file PROTO((char *));
190 static void display_help PROTO ((void));
191 static void report_file_and_line PROTO ((const char *, int, int));
192 static void vnotice PROTO ((FILE *, const char *, va_list));
193 static void mark_file_stack PROTO ((void *));
195 static void decode_d_option PROTO ((const char *));
196 static int decode_f_option PROTO ((const char *));
197 static int decode_W_option PROTO ((const char *));
198 static int decode_g_option PROTO ((const char *));
199 static unsigned independent_decode_option PROTO ((int, char **, unsigned));
201 static void print_version PROTO((FILE *, const char *));
202 static int print_single_switch PROTO((FILE *, int, int, const char *,
203 const char *, const char *,
204 const char *, const char *));
205 static void print_switch_values PROTO((FILE *, int, int, const char *,
206 const char *, const char *));
208 /* Length of line when printing switch values. */
209 #define MAX_LINE 75
211 /* Name of program invoked, sans directories. */
213 const char *progname;
215 /* Copy of arguments to main. */
216 int save_argc;
217 char **save_argv;
219 /* Name of current original source file (what was input to cpp).
220 This comes from each #-command in the actual input. */
222 char *input_filename;
224 /* Name of top-level original source file (what was input to cpp).
225 This comes from the #-command at the beginning of the actual input.
226 If there isn't any there, then this is the cc1 input file name. */
228 char *main_input_filename;
230 /* Current line number in real source file. */
232 int lineno;
234 /* Nonzero if it is unsafe to create any new pseudo registers. */
235 int no_new_pseudos;
237 /* Stack of currently pending input files. */
239 struct file_stack *input_file_stack;
241 /* Incremented on each change to input_file_stack. */
242 int input_file_stack_tick;
244 /* Name to use as base of names for dump output files. */
246 const char *dump_base_name;
248 /* Bit flags that specify the machine subtype we are compiling for.
249 Bits are tested using macros TARGET_... defined in the tm.h file
250 and set by `-m...' switches. Must be defined in rtlanal.c. */
252 extern int target_flags;
254 /* Flags saying which kinds of debugging dump have been requested. */
256 int rtl_dump = 0;
257 int rtl_dump_and_exit = 0;
258 int jump_opt_dump = 0;
259 int addressof_dump = 0;
260 int cse_dump = 0;
261 int gcse_dump = 0;
262 int loop_dump = 0;
263 int cse2_dump = 0;
264 int branch_prob_dump = 0;
265 int flow_dump = 0;
266 int combine_dump = 0;
267 int regmove_dump = 0;
268 int sched_dump = 0;
269 int local_reg_dump = 0;
270 int global_reg_dump = 0;
271 int flow2_dump = 0;
272 int peephole2_dump = 0;
273 int sched2_dump = 0;
274 int jump2_opt_dump = 0;
275 #ifdef DELAY_SLOTS
276 int dbr_sched_dump = 0;
277 #endif
278 int flag_print_asm_name = 0;
279 #ifdef STACK_REGS
280 int stack_reg_dump = 0;
281 #endif
282 #ifdef MACHINE_DEPENDENT_REORG
283 int mach_dep_reorg_dump = 0;
284 #endif
285 static int flag_print_mem = 0;
286 static int version_flag = 0;
287 static char * filename = 0;
288 enum graph_dump_types graph_dump_format;
290 /* Name for output file of assembly code, specified with -o. */
292 char *asm_file_name;
294 /* Value of the -G xx switch, and whether it was passed or not. */
295 int g_switch_value;
296 int g_switch_set;
298 /* Type(s) of debugging information we are producing (if any).
299 See flags.h for the definitions of the different possible
300 types of debugging information. */
301 enum debug_info_type write_symbols = NO_DEBUG;
303 /* Level of debugging information we are producing. See flags.h
304 for the definitions of the different possible levels. */
305 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
307 /* Nonzero means use GNU-only extensions in the generated symbolic
308 debugging information. */
309 /* Currently, this only has an effect when write_symbols is set to
310 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
311 int use_gnu_debug_info_extensions = 0;
313 /* Nonzero means do optimizations. -O.
314 Particular numeric values stand for particular amounts of optimization;
315 thus, -O2 stores 2 here. However, the optimizations beyond the basic
316 ones are not controlled directly by this variable. Instead, they are
317 controlled by individual `flag_...' variables that are defaulted
318 based on this variable. */
320 int optimize = 0;
322 /* Nonzero means optimize for size. -Os.
323 The only valid values are zero and non-zero. When optimize_size is
324 non-zero, optimize defaults to 2, but certain individual code
325 bloating optimizations are disabled. */
327 int optimize_size = 0;
329 /* Number of error messages and warning messages so far. */
331 int errorcount = 0;
332 int warningcount = 0;
333 int sorrycount = 0;
335 /* Pointer to function to compute the name to use to print a declaration.
336 DECL is the declaration in question.
337 VERBOSITY determines what information will be printed:
338 0: DECL_NAME, demangled as necessary.
339 1: and scope information.
340 2: and any other information that might be interesting, such as function
341 parameter types in C++. */
343 const char *(*decl_printable_name) PROTO ((tree, int));
345 /* Pointer to function to compute rtl for a language-specific tree code. */
347 typedef rtx (*lang_expand_expr_t)
348 PROTO ((union tree_node *, rtx, enum machine_mode,
349 enum expand_modifier modifier));
351 lang_expand_expr_t lang_expand_expr = 0;
353 tree (*lang_expand_constant) PROTO((tree)) = 0;
355 /* Pointer to function to finish handling an incomplete decl at the
356 end of compilation. */
358 void (*incomplete_decl_finalize_hook) PROTO((tree)) = 0;
360 /* Nonzero if generating code to do profiling. */
362 int profile_flag = 0;
364 /* Nonzero if generating code to do profiling on a line-by-line basis. */
366 int profile_block_flag;
368 /* Nonzero if generating code to profile program flow graph arcs. */
370 int profile_arc_flag = 0;
372 /* Nonzero if generating info for gcov to calculate line test coverage. */
374 int flag_test_coverage = 0;
376 /* Nonzero indicates that branch taken probabilities should be calculated. */
378 int flag_branch_probabilities = 0;
380 /* Nonzero for -pedantic switch: warn about anything
381 that standard spec forbids. */
383 int pedantic = 0;
385 /* Temporarily suppress certain warnings.
386 This is set while reading code from a system header file. */
388 int in_system_header = 0;
390 /* Nonzero means do stupid register allocation.
391 Currently, this is 1 if `optimize' is 0. */
393 int obey_regdecls = 0;
395 /* Don't print functions as they are compiled and don't print
396 times taken by the various passes. -quiet. */
398 int quiet_flag = 0;
400 /* -f flags. */
402 /* Nonzero means `char' should be signed. */
404 int flag_signed_char;
406 /* Nonzero means give an enum type only as many bytes as it needs. */
408 int flag_short_enums;
410 /* Nonzero for -fcaller-saves: allocate values in regs that need to
411 be saved across function calls, if that produces overall better code.
412 Optional now, so people can test it. */
414 #ifdef DEFAULT_CALLER_SAVES
415 int flag_caller_saves = 1;
416 #else
417 int flag_caller_saves = 0;
418 #endif
420 /* Nonzero if structures and unions should be returned in memory.
422 This should only be defined if compatibility with another compiler or
423 with an ABI is needed, because it results in slower code. */
425 #ifndef DEFAULT_PCC_STRUCT_RETURN
426 #define DEFAULT_PCC_STRUCT_RETURN 1
427 #endif
429 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
431 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
433 /* Nonzero for -fforce-mem: load memory value into a register
434 before arithmetic on it. This makes better cse but slower compilation. */
436 int flag_force_mem = 0;
438 /* Nonzero for -fforce-addr: load memory address into a register before
439 reference to memory. This makes better cse but slower compilation. */
441 int flag_force_addr = 0;
443 /* Nonzero for -fdefer-pop: don't pop args after each function call;
444 instead save them up to pop many calls' args with one insns. */
446 int flag_defer_pop = 0;
448 /* Nonzero for -ffloat-store: don't allocate floats and doubles
449 in extended-precision registers. */
451 int flag_float_store = 0;
453 /* Nonzero for -fcse-follow-jumps:
454 have cse follow jumps to do a more extensive job. */
456 int flag_cse_follow_jumps;
458 /* Nonzero for -fcse-skip-blocks:
459 have cse follow a branch around a block. */
460 int flag_cse_skip_blocks;
462 /* Nonzero for -fexpensive-optimizations:
463 perform miscellaneous relatively-expensive optimizations. */
464 int flag_expensive_optimizations;
466 /* Nonzero for -fthread-jumps:
467 have jump optimize output of loop. */
469 int flag_thread_jumps;
471 /* Nonzero enables strength-reduction in loop.c. */
473 int flag_strength_reduce = 0;
475 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
476 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
477 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
478 unrolled. */
480 int flag_unroll_loops;
482 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
483 This is generally not a win. */
485 int flag_unroll_all_loops;
487 /* Nonzero forces all invariant computations in loops to be moved
488 outside the loop. */
490 int flag_move_all_movables = 0;
492 /* Nonzero forces all general induction variables in loops to be
493 strength reduced. */
495 int flag_reduce_all_givs = 0;
497 /* Nonzero to perform full register move optimization passes. This is the
498 default for -O2. */
500 int flag_regmove = 0;
502 /* Nonzero for -fwritable-strings:
503 store string constants in data segment and don't uniquize them. */
505 int flag_writable_strings = 0;
507 /* Nonzero means don't put addresses of constant functions in registers.
508 Used for compiling the Unix kernel, where strange substitutions are
509 done on the assembly output. */
511 int flag_no_function_cse = 0;
513 /* Nonzero for -fomit-frame-pointer:
514 don't make a frame pointer in simple functions that don't require one. */
516 int flag_omit_frame_pointer = 0;
518 /* Nonzero means place each function into its own section on those platforms
519 which support arbitrary section names and unlimited numbers of sections. */
521 int flag_function_sections = 0;
523 /* ... and similar for data. */
525 int flag_data_sections = 0;
527 /* Nonzero to inhibit use of define_optimization peephole opts. */
529 int flag_no_peephole = 0;
531 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
532 operations in the interest of optimization. For example it allows
533 GCC to assume arguments to sqrt are nonnegative numbers, allowing
534 faster code for sqrt to be generated. */
536 int flag_fast_math = 0;
538 /* Nonzero means the front end generally wants `errno' maintained by math
539 operations, like built-in SQRT, unless overridden by flag_fast_math. */
541 int flag_errno_math = 1;
543 /* 0 means straightforward implementation of complex divide acceptable.
544 1 means wide ranges of inputs must work for complex divide.
545 2 means C9X-like requirements for complex divide (not yet implemented). */
547 int flag_complex_divide_method = 0;
549 /* Nonzero means all references through pointers are volatile. */
551 int flag_volatile;
553 /* Nonzero means treat all global and extern variables as volatile. */
555 int flag_volatile_global;
557 /* Nonzero means treat all static variables as volatile. */
559 int flag_volatile_static;
561 /* Nonzero means just do syntax checking; don't output anything. */
563 int flag_syntax_only = 0;
565 /* Nonzero means perform global cse. */
567 static int flag_gcse;
569 /* Nonzero means to use global dataflow analysis to eliminate
570 useless null pointer tests. */
572 static int flag_delete_null_pointer_checks;
574 /* Nonzero means to rerun cse after loop optimization. This increases
575 compilation time about 20% and picks up a few more common expressions. */
577 static int flag_rerun_cse_after_loop;
579 /* Nonzero means to run loop optimizations twice. */
581 int flag_rerun_loop_opt;
583 /* Nonzero for -finline-functions: ok to inline functions that look like
584 good inline candidates. */
586 int flag_inline_functions;
588 /* Nonzero for -fkeep-inline-functions: even if we make a function
589 go inline everywhere, keep its definition around for debugging
590 purposes. */
592 int flag_keep_inline_functions;
594 /* Nonzero means that functions will not be inlined. */
596 int flag_no_inline;
598 /* Nonzero means that we should emit static const variables
599 regardless of whether or not optimization is turned on. */
601 int flag_keep_static_consts = 1;
603 /* Nonzero means we should be saving declaration info into a .X file. */
605 int flag_gen_aux_info = 0;
607 /* Specified name of aux-info file. */
609 static char *aux_info_file_name;
611 /* Nonzero means make the text shared if supported. */
613 int flag_shared_data;
615 /* Nonzero means schedule into delayed branch slots if supported. */
617 int flag_delayed_branch;
619 /* Nonzero if we are compiling pure (sharable) code.
620 Value is 1 if we are doing reasonable (i.e. simple
621 offset into offset table) pic. Value is 2 if we can
622 only perform register offsets. */
624 int flag_pic;
626 /* Nonzero means generate extra code for exception handling and enable
627 exception handling. */
629 int flag_exceptions;
631 /* Nonzero means use the new model for exception handling. Replaces
632 -DNEW_EH_MODEL as a compile option. */
634 int flag_new_exceptions = 1;
636 /* Nonzero means don't place uninitialized global data in common storage
637 by default. */
639 int flag_no_common;
641 /* Nonzero means pretend it is OK to examine bits of target floats,
642 even if that isn't true. The resulting code will have incorrect constants,
643 but the same series of instructions that the native compiler would make. */
645 int flag_pretend_float;
647 /* Nonzero means change certain warnings into errors.
648 Usually these are warnings about failure to conform to some standard. */
650 int flag_pedantic_errors = 0;
652 /* flag_schedule_insns means schedule insns within basic blocks (before
653 local_alloc).
654 flag_schedule_insns_after_reload means schedule insns after
655 global_alloc. */
657 int flag_schedule_insns = 0;
658 int flag_schedule_insns_after_reload = 0;
660 /* The following flags have effect only for scheduling before register
661 allocation:
663 flag_schedule_interblock means schedule insns accross basic blocks.
664 flag_schedule_speculative means allow speculative motion of non-load insns.
665 flag_schedule_speculative_load means allow speculative motion of some
666 load insns.
667 flag_schedule_speculative_load_dangerous allows speculative motion of more
668 load insns. */
670 int flag_schedule_interblock = 1;
671 int flag_schedule_speculative = 1;
672 int flag_schedule_speculative_load = 0;
673 int flag_schedule_speculative_load_dangerous = 0;
675 /* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
676 by a cheaper branch, on a count register. */
677 int flag_branch_on_count_reg;
679 /* -finhibit-size-directive inhibits output of .size for ELF.
680 This is used only for compiling crtstuff.c,
681 and it may be extended to other effects
682 needed for crtstuff.c on other systems. */
683 int flag_inhibit_size_directive = 0;
685 /* -fverbose-asm causes extra commentary information to be produced in
686 the generated assembly code (to make it more readable). This option
687 is generally only of use to those who actually need to read the
688 generated assembly code (perhaps while debugging the compiler itself).
689 -fno-verbose-asm, the default, causes the extra information
690 to be omitted and is useful when comparing two assembler files. */
692 int flag_verbose_asm = 0;
694 /* -dA causes debug commentary information to be produced in
695 the generated assembly code (to make it more readable). This option
696 is generally only of use to those who actually need to read the
697 generated assembly code (perhaps while debugging the compiler itself).
698 Currently, this switch is only used by dwarfout.c; however, it is intended
699 to be a catchall for printing debug information in the assembler file. */
701 int flag_debug_asm = 0;
703 /* -fgnu-linker specifies use of the GNU linker for initializations.
704 (Or, more generally, a linker that handles initializations.)
705 -fno-gnu-linker says that collect2 will be used. */
706 #ifdef USE_COLLECT2
707 int flag_gnu_linker = 0;
708 #else
709 int flag_gnu_linker = 1;
710 #endif
712 /* Tag all structures with __attribute__(packed) */
713 int flag_pack_struct = 0;
715 /* Emit code to check for stack overflow; also may cause large objects
716 to be allocated dynamically. */
717 int flag_stack_check;
719 /* -fcheck-memory-usage causes extra code to be generated in order to check
720 memory accesses. This is used by a detector of bad memory accesses such
721 as Checker. */
722 int flag_check_memory_usage = 0;
724 /* -fprefix-function-name causes function name to be prefixed. This
725 can be used with -fcheck-memory-usage to isolate code compiled with
726 -fcheck-memory-usage. */
727 int flag_prefix_function_name = 0;
729 /* 0 if pointer arguments may alias each other. True in C.
730 1 if pointer arguments may not alias each other but may alias
731 global variables.
732 2 if pointer arguments may not alias each other and may not
733 alias global variables. True in Fortran.
734 This defaults to 0 for C. */
735 int flag_argument_noalias = 0;
737 /* Nonzero if we should do (language-dependent) alias analysis.
738 Typically, this analysis will assume that expressions of certain
739 types do not alias expressions of certain other types. Only used
740 if alias analysis (in general) is enabled. */
741 int flag_strict_aliasing = 0;
743 /* Instrument functions with calls at entry and exit, for profiling. */
744 int flag_instrument_function_entry_exit = 0;
746 /* Nonzero means ignore `#ident' directives. 0 means handle them.
747 On SVR4 targets, it also controls whether or not to emit a
748 string identifying the compiler. */
750 int flag_no_ident = 0;
752 /* This will perform a peephole pass before sched2. */
753 int flag_peephole2 = 0;
755 /* Values of the -falign-* flags: how much to align labels in code.
756 0 means `use default', 1 means `don't align'.
757 For each variable, there is an _log variant which is the power
758 of two not less than the variable, for .align output. */
760 int align_loops;
761 int align_loops_log;
762 int align_jumps;
763 int align_jumps_log;
764 int align_labels;
765 int align_labels_log;
766 int align_functions;
767 int align_functions_log;
769 /* Table of supported debugging formats. */
770 static struct
772 const char * arg;
773 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
774 constant expression, we use NO_DEBUG in its place. */
775 enum debug_info_type debug_type;
776 int use_extensions_p;
777 const char * description;
778 } *da,
779 debug_args[] =
781 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
782 "Generate default debug format output" },
783 { "gdb", NO_DEBUG, 1, "Generate default extended debug format output" },
784 #ifdef DBX_DEBUGGING_INFO
785 { "stabs", DBX_DEBUG, 0, "Generate STABS format debug output" },
786 { "stabs+", DBX_DEBUG, 1, "Generate extended STABS format debug output" },
787 #endif
788 #ifdef DWARF_DEBUGGING_INFO
789 { "dwarf", DWARF_DEBUG, 0, "Generate DWARF-1 format debug output"},
790 { "dwarf+", DWARF_DEBUG, 1,
791 "Generated extended DWARF-1 format debug output" },
792 #endif
793 #ifdef DWARF2_DEBUGGING_INFO
794 { "dwarf-2", DWARF2_DEBUG, 0, "Enable DWARF-2 debug output" },
795 #endif
796 #ifdef XCOFF_DEBUGGING_INFO
797 { "xcoff", XCOFF_DEBUG, 0, "Generate XCOFF format debug output" },
798 { "xcoff+", XCOFF_DEBUG, 1, "Generate extended XCOFF format debug output" },
799 #endif
800 #ifdef SDB_DEBUGGING_INFO
801 { "coff", SDB_DEBUG, 0, "Generate COFF format debug output" },
802 #endif
803 { 0, 0, 0, 0 }
806 typedef struct
808 const char * string;
809 int * variable;
810 int on_value;
811 const char * description;
813 lang_independent_options;
815 /* Add or remove a leading underscore from user symbols. */
816 int flag_leading_underscore = -1;
818 /* The user symbol prefix after having resolved same. */
819 const char *user_label_prefix;
821 /* A default for same. */
822 #ifndef USER_LABEL_PREFIX
823 #define USER_LABEL_PREFIX ""
824 #endif
826 /* Table of language-independent -f options.
827 STRING is the option name. VARIABLE is the address of the variable.
828 ON_VALUE is the value to store in VARIABLE
829 if `-fSTRING' is seen as an option.
830 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
832 lang_independent_options f_options[] =
834 {"float-store", &flag_float_store, 1,
835 "Do not store floats in registers" },
836 {"volatile", &flag_volatile, 1,
837 "Consider all mem refs through pointers as volatile"},
838 {"volatile-global", &flag_volatile_global, 1,
839 "Consider all mem refs to global data to be volatile" },
840 {"volatile-static", &flag_volatile_static, 1,
841 "Consider all mem refs to static data to be volatile" },
842 {"defer-pop", &flag_defer_pop, 1,
843 "Defer popping functions args from stack until later" },
844 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
845 "When possible do not generate stack frames"},
846 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
847 "When running CSE, follow jumps to their targets" },
848 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
849 "When running CSE, follow conditional jumps" },
850 {"expensive-optimizations", &flag_expensive_optimizations, 1,
851 "Perform a number of minor, expensive optimisations" },
852 {"thread-jumps", &flag_thread_jumps, 1,
853 "Perform jump threading optimisations"},
854 {"strength-reduce", &flag_strength_reduce, 1,
855 "Perform strength reduction optimisations" },
856 {"unroll-loops", &flag_unroll_loops, 1,
857 "Perform loop unrolling when iteration count is known" },
858 {"unroll-all-loops", &flag_unroll_all_loops, 1,
859 "Perform loop unrolling for all loops" },
860 {"move-all-movables", &flag_move_all_movables, 1,
861 "Force all loop invariant computations out of loops" },
862 {"reduce-all-givs", &flag_reduce_all_givs, 1,
863 "Strength reduce all loop general induction variables" },
864 {"writable-strings", &flag_writable_strings, 1,
865 "Store strings in writable data section" },
866 {"peephole", &flag_no_peephole, 0,
867 "Enable machine specific peephole optimisations" },
868 {"force-mem", &flag_force_mem, 1,
869 "Copy memory operands into registers before using" },
870 {"force-addr", &flag_force_addr, 1,
871 "Copy memory address constants into regs before using" },
872 {"function-cse", &flag_no_function_cse, 0,
873 "Allow function addresses to be held in registers" },
874 {"inline-functions", &flag_inline_functions, 1,
875 "Integrate simple functions into their callers" },
876 {"keep-inline-functions", &flag_keep_inline_functions, 1,
877 "Generate code for funcs even if they are fully inlined" },
878 {"inline", &flag_no_inline, 0,
879 "Pay attention to the 'inline' keyword"},
880 {"keep-static-consts", &flag_keep_static_consts, 1,
881 "Emit static const variables even if they are not used" },
882 {"syntax-only", &flag_syntax_only, 1,
883 "Check for syntax errors, then stop" },
884 {"shared-data", &flag_shared_data, 1,
885 "Mark data as shared rather than private" },
886 {"caller-saves", &flag_caller_saves, 1,
887 "Enable saving registers around function calls" },
888 {"pcc-struct-return", &flag_pcc_struct_return, 1,
889 "Return 'short' aggregates in memory, not registers" },
890 {"reg-struct-return", &flag_pcc_struct_return, 0,
891 "Return 'short' aggregates in registers" },
892 {"delayed-branch", &flag_delayed_branch, 1,
893 "Attempt to fill delay slots of branch instructions" },
894 {"gcse", &flag_gcse, 1,
895 "Perform the global common subexpression elimination" },
896 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
897 "Run CSE pass after loop optimisations"},
898 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
899 "Run the loop optimiser twice"},
900 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1,
901 "Delete useless null pointer checks" },
902 {"pretend-float", &flag_pretend_float, 1,
903 "Pretend that host and target use the same FP format"},
904 {"schedule-insns", &flag_schedule_insns, 1,
905 "Reschedule instructions to avoid pipeline stalls"},
906 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
907 "Run two passes of the instruction scheduler"},
908 {"sched-interblock",&flag_schedule_interblock, 1,
909 "Enable scheduling across basic blocks" },
910 {"sched-spec",&flag_schedule_speculative, 1,
911 "Allow speculative motion of non-loads" },
912 {"sched-spec-load",&flag_schedule_speculative_load, 1,
913 "Allow speculative motion of some loads" },
914 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
915 "Allow speculative motion of more loads" },
916 {"branch-count-reg",&flag_branch_on_count_reg, 1,
917 "Replace add,compare,branch with branch on count reg"},
918 {"pic", &flag_pic, 1,
919 "Generate position independent code, if possible"},
920 {"PIC", &flag_pic, 2, ""},
921 {"exceptions", &flag_exceptions, 1,
922 "Enable exception handling" },
923 {"new-exceptions", &flag_new_exceptions, 1,
924 "Use the new model for exception handling" },
925 {"sjlj-exceptions", &exceptions_via_longjmp, 1,
926 "Use setjmp/longjmp to handle exceptions" },
927 {"asynchronous-exceptions", &asynchronous_exceptions, 1,
928 "Support asynchronous exceptions" },
929 {"profile-arcs", &profile_arc_flag, 1,
930 "Insert arc based program profiling code" },
931 {"test-coverage", &flag_test_coverage, 1,
932 "Create data files needed by gcov" },
933 {"branch-probabilities", &flag_branch_probabilities, 1,
934 "Use profiling information for branch probabilities" },
935 {"fast-math", &flag_fast_math, 1,
936 "Improve FP speed by violating ANSI & IEEE rules" },
937 {"common", &flag_no_common, 0,
938 "Do not put unitialised globals in the common section" },
939 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
940 "Do not generate .size directives" },
941 {"function-sections", &flag_function_sections, 1,
942 "place each function into its own section" },
943 {"data-sections", &flag_data_sections, 1,
944 "place data items into their own section" },
945 {"verbose-asm", &flag_verbose_asm, 1,
946 "Add extra commentry to assembler output"},
947 {"gnu-linker", &flag_gnu_linker, 1,
948 "Output GNU ld formatted global initialisers"},
949 {"regmove", &flag_regmove, 1,
950 "Enables a register move optimisation"},
951 {"optimize-register-move", &flag_regmove, 1,
952 "Do the full regmove optimization pass"},
953 {"pack-struct", &flag_pack_struct, 1,
954 "Pack structure members together without holes" },
955 {"stack-check", &flag_stack_check, 1,
956 "Insert stack checking code into the program" },
957 {"argument-alias", &flag_argument_noalias, 0,
958 "Specify that arguments may alias each other & globals"},
959 {"argument-noalias", &flag_argument_noalias, 1,
960 "Assume arguments may alias globals but not each other"},
961 {"argument-noalias-global", &flag_argument_noalias, 2,
962 "Assume arguments do not alias each other or globals" },
963 {"strict-aliasing", &flag_strict_aliasing, 1,
964 "Assume strict aliasing rules apply" },
965 {"align-loops", &align_loops, 0,
966 "Align the start of loops" },
967 {"align-jumps", &align_jumps, 0,
968 "Align labels which are only reached by jumping" },
969 {"align-labels", &align_labels, 0,
970 "Align all labels" },
971 {"align-functions", &align_functions, 0,
972 "Align the start of functions" },
973 {"check-memory-usage", &flag_check_memory_usage, 1,
974 "Generate code to check every memory access" },
975 {"prefix-function-name", &flag_prefix_function_name, 1,
976 "Add a prefix to all function names" },
977 {"dump-unnumbered", &flag_dump_unnumbered, 1,
978 "Suppress output of instruction numbers and line number notes in debugging dumps"},
979 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
980 "Instrument function entry/exit with profiling calls"},
981 {"leading-underscore", &flag_leading_underscore, 1,
982 "External symbols have a leading underscore" },
983 {"ident", &flag_no_ident, 0,
984 "Process #ident directives"},
985 { "peephole2", &flag_peephole2, 1,
986 "Enables an rtl peephole pass run before sched2" },
987 {"math-errno", &flag_errno_math, 1,
988 "Set errno after built-in math functions"}
991 #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0]))
993 /* Table of language-specific options. */
995 static struct lang_opt
997 const char * option;
998 const char * description;
1000 documented_lang_options[] =
1002 /* In order not to overload the --help output, the convention
1003 used here is to only describe those options which are not
1004 enabled by default. */
1006 { "-ansi", "Compile just for ANSI C" },
1007 { "-fallow-single-precision",
1008 "Do not promote floats to double if using -traditional" },
1009 { "-std= ", "Determine language standard"},
1011 { "-fsigned-bitfields", "" },
1012 { "-funsigned-bitfields","Make bitfields by unsigned by default" },
1013 { "-fno-signed-bitfields", "" },
1014 { "-fno-unsigned-bitfields","" },
1015 { "-fsigned-char", "Make 'char' be signed by default"},
1016 { "-funsigned-char", "Make 'char' be unsigned by default"},
1017 { "-fno-signed-char", "" },
1018 { "-fno-unsigned-char", "" },
1020 { "-ftraditional", "" },
1021 { "-traditional", "Attempt to support traditional K&R style C"},
1022 { "-fnotraditional", "" },
1023 { "-fno-traditional", "" },
1025 { "-fasm", "" },
1026 { "-fno-asm", "Do not recognise the 'asm' keyword" },
1027 { "-fbuiltin", "" },
1028 { "-fno-builtin", "Do not recognise any built in functions" },
1029 { "-fhosted", "Assume normal C execution environment" },
1030 { "-fno-hosted", "" },
1031 { "-ffreestanding",
1032 "Assume that standard libraries & main might not exist" },
1033 { "-fno-freestanding", "" },
1034 { "-fcond-mismatch", "Allow different types as args of ? operator"},
1035 { "-fno-cond-mismatch", "" },
1036 { "-fdollars-in-identifiers", "Allow the use of $ inside identifiers" },
1037 { "-fno-dollars-in-identifiers", "" },
1038 { "-fpreprocessed", "" },
1039 { "-fno-preprocessed", "" },
1040 { "-fshort-double", "Use the same size for double as for float" },
1041 { "-fno-short-double", "" },
1042 { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
1043 { "-fno-short-enums", "" },
1044 { "-fshort-wchar", "Override the underlying type for wchar_t to `unsigned short'" },
1045 { "-fno-short-wchar", "" },
1047 { "-Wall", "Enable most warning messages" },
1048 { "-Wbad-function-cast",
1049 "Warn about casting functions to incompatible types" },
1050 { "-Wno-bad-function-cast", "" },
1051 { "-Wmissing-noreturn",
1052 "Warn about functions which might be candidates for attribute noreturn" },
1053 { "-Wno-missing-noreturn", "" },
1054 { "-Wcast-qual", "Warn about casts which discard qualifiers"},
1055 { "-Wno-cast-qual", "" },
1056 { "-Wchar-subscripts", "Warn about subscripts whose type is 'char'"},
1057 { "-Wno-char-subscripts", "" },
1058 { "-Wcomment", "Warn if nested comments are detected" },
1059 { "-Wno-comment", "" },
1060 { "-Wcomments", "Warn if nested comments are detected" },
1061 { "-Wno-comments", "" },
1062 { "-Wconversion", "Warn about possibly confusing type conversions" },
1063 { "-Wno-conversion", "" },
1064 { "-Wformat", "Warn about printf format anomalies" },
1065 { "-Wno-format", "" },
1066 { "-Wimplicit-function-declaration",
1067 "Warn about implicit function declarations" },
1068 { "-Wno-implicit-function-declaration", "" },
1069 { "-Werror-implicit-function-declaration", "" },
1070 { "-Wimplicit-int", "Warn when a declaration does not specify a type" },
1071 { "-Wno-implicit-int", "" },
1072 { "-Wimplicit", "" },
1073 { "-Wno-implicit", "" },
1074 { "-Wimport", "Warn about the use of the #import directive" },
1075 { "-Wno-import", "" },
1076 { "-Wlong-long","" },
1077 { "-Wno-long-long", "Do not warn about using 'long long' when -pedantic" },
1078 { "-Wmain", "Warn about suspicious declarations of main" },
1079 { "-Wno-main", "" },
1080 { "-Wmissing-braces",
1081 "Warn about possibly missing braces around initialisers" },
1082 { "-Wno-missing-braces", "" },
1083 { "-Wmissing-declarations",
1084 "Warn about global funcs without previous declarations"},
1085 { "-Wno-missing-declarations", "" },
1086 { "-Wmissing-prototypes", "Warn about global funcs without prototypes" },
1087 { "-Wno-missing-prototypes", "" },
1088 { "-Wmultichar", "Warn about use of multicharacter literals"},
1089 { "-Wno-multichar", "" },
1090 { "-Wnested-externs", "Warn about externs not at file scope level" },
1091 { "-Wno-nested-externs", "" },
1092 { "-Wparentheses", "Warn about possible missing parentheses" },
1093 { "-Wno-parentheses", "" },
1094 { "-Wpointer-arith", "Warn about function pointer arithmetic" },
1095 { "-Wno-pointer-arith", "" },
1096 { "-Wredundant-decls",
1097 "Warn about multiple declarations of the same object" },
1098 { "-Wno-redundant-decls", "" },
1099 { "-Wsign-compare", "Warn about signed/unsigned comparisons" },
1100 { "-Wno-sign-compare", "" },
1101 { "-Wfloat-equal", "Warn about testing equality of floating point numbers" },
1102 { "-Wno-float-equal", "" },
1103 { "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
1104 { "-Wno-unknown-pragmas", "" },
1105 { "-Wstrict-prototypes", "Warn about non-prototyped function decls" },
1106 { "-Wno-strict-prototypes", "" },
1107 { "-Wtraditional", "Warn about constructs whose meaning change in ANSI C"},
1108 { "-Wno-traditional", "" },
1109 { "-Wtrigraphs", "Warn when trigraphs are encountered" },
1110 { "-Wno-trigraphs", "" },
1111 { "-Wundef", "" },
1112 { "-Wno-undef", "" },
1113 { "-Wwrite-strings", "Mark strings as 'const char *'"},
1114 { "-Wno-write-strings", "" },
1116 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1118 /* These are for Objective C. */
1119 DEFINE_LANG_NAME ("Objective C")
1121 { "-lang-objc", "" },
1122 { "-gen-decls", "Dump decls to a .decl file" },
1123 { "-fgnu-runtime", "Generate code for GNU runtime environment" },
1124 { "-fno-gnu-runtime", "" },
1125 { "-fnext-runtime", "Generate code for NeXT runtime environment" },
1126 { "-fno-next-runtime", "" },
1127 { "-Wselector", "Warn if a selector has multiple methods" },
1128 { "-Wno-selector", "" },
1129 { "-Wprotocol", "" },
1130 { "-Wno-protocol", "Do not warn if inherited methods are unimplemented"},
1131 { "-print-objc-runtime-info",
1132 "Generate C header of platform specific features" },
1134 #include "options.h"
1138 /* Here is a table, controlled by the tm.h file, listing each -m switch
1139 and which bits in `target_switches' it should set or clear.
1140 If VALUE is positive, it is bits to set.
1141 If VALUE is negative, -VALUE is bits to clear.
1142 (The sign bit is not used so there is no confusion.) */
1144 struct
1146 const char * name;
1147 int value;
1148 const char * description;
1150 target_switches [] = TARGET_SWITCHES;
1152 /* This table is similar, but allows the switch to have a value. */
1154 #ifdef TARGET_OPTIONS
1155 struct
1157 const char * prefix;
1158 const char ** variable;
1159 const char * description;
1161 target_options [] = TARGET_OPTIONS;
1162 #endif
1164 /* Options controlling warnings */
1166 /* Don't print warning messages. -w. */
1168 int inhibit_warnings = 0;
1170 /* Print various extra warnings. -W. */
1172 int extra_warnings = 0;
1174 /* Treat warnings as errors. -Werror. */
1176 int warnings_are_errors = 0;
1178 /* Nonzero to warn about unused local variables. */
1180 int warn_unused;
1182 /* Nonzero to warn about code which is never reached. */
1184 int warn_notreached;
1186 /* Nonzero to warn about variables used before they are initialized. */
1188 int warn_uninitialized;
1190 /* Nonzero means warn about all declarations which shadow others. */
1192 int warn_shadow;
1194 /* Warn if a switch on an enum fails to have a case for every enum value. */
1196 int warn_switch;
1198 /* Nonzero means warn about function definitions that default the return type
1199 or that use a null return and have a return-type other than void. */
1201 int warn_return_type;
1203 /* Nonzero means warn about pointer casts that increase the required
1204 alignment of the target type (and might therefore lead to a crash
1205 due to a misaligned access). */
1207 int warn_cast_align;
1209 /* Nonzero means warn about any identifiers that match in the first N
1210 characters. The value N is in `id_clash_len'. */
1212 int warn_id_clash;
1213 unsigned id_clash_len;
1215 /* Nonzero means warn about any objects definitions whose size is larger
1216 than N bytes. Also want about function definitions whose returned
1217 values are larger than N bytes. The value N is in `larger_than_size'. */
1219 int warn_larger_than;
1220 unsigned larger_than_size;
1222 /* Nonzero means warn if inline function is too large. */
1224 int warn_inline;
1226 /* Warn if a function returns an aggregate,
1227 since there are often incompatible calling conventions for doing this. */
1229 int warn_aggregate_return;
1231 /* Likewise for -W. */
1233 lang_independent_options W_options[] =
1235 {"unused", &warn_unused, 1, "Warn when a variable is unused" },
1236 {"error", &warnings_are_errors, 1, ""},
1237 {"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
1238 {"switch", &warn_switch, 1,
1239 "Warn about enumerated switches missing a specific case" },
1240 {"aggregate-return", &warn_aggregate_return, 1,
1241 "Warn about returning structures, unions or arrays" },
1242 {"cast-align", &warn_cast_align, 1,
1243 "Warn about pointer casts which increase alignment" },
1244 {"unreachable-code", &warn_notreached, 1,
1245 "Warn about code that will never be executed" },
1246 {"uninitialized", &warn_uninitialized, 1,
1247 "Warn about unitialized automatic variables"},
1248 {"inline", &warn_inline, 1,
1249 "Warn when an inlined function cannot be inlined"}
1252 /* Output files for assembler code (real compiler output)
1253 and debugging dumps. */
1255 FILE *asm_out_file;
1256 FILE *aux_info_file;
1257 FILE *rtl_dump_file = NULL;
1259 /* Decode the string P as an integral parameter.
1260 If the string is indeed an integer return its numeric value else
1261 issue an Invalid Option error for the option PNAME and return DEFVAL.
1262 If PNAME is zero just return DEFVAL, do not call error. */
1265 read_integral_parameter (p, pname, defval)
1266 const char *p;
1267 const char *pname;
1268 const int defval;
1270 const char *endp = p;
1272 while (*endp)
1274 if (*endp >= '0' && *endp <= '9')
1275 endp++;
1276 else
1277 break;
1280 if (*endp != 0)
1282 if (pname != 0)
1283 error ("Invalid option `%s'", pname);
1284 return defval;
1287 return atoi (p);
1291 /* Time accumulators, to count the total time spent in various passes. */
1293 int parse_time;
1294 int varconst_time;
1295 int integration_time;
1296 int jump_time;
1297 int cse_time;
1298 int gcse_time;
1299 int loop_time;
1300 int cse2_time;
1301 int branch_prob_time;
1302 int flow_time;
1303 int combine_time;
1304 int regmove_time;
1305 int sched_time;
1306 int local_alloc_time;
1307 int global_alloc_time;
1308 int flow2_time;
1309 int sched2_time;
1310 #ifdef DELAY_SLOTS
1311 int dbr_sched_time;
1312 #endif
1313 int shorten_branch_time;
1314 int stack_reg_time;
1315 int final_time;
1316 int symout_time;
1317 int dump_time;
1318 int gc_time;
1319 int all_time;
1321 /* Return time used so far, in microseconds. */
1323 long
1324 get_run_time ()
1326 if (quiet_flag)
1327 return 0;
1329 #ifdef __BEOS__
1330 return 0;
1331 #else /* not BeOS */
1332 #if defined (_WIN32) && !defined (__CYGWIN__)
1333 if (clock() < 0)
1334 return 0;
1335 else
1336 return (clock() * 1000);
1337 #else /* not _WIN32 */
1338 #ifdef _SC_CLK_TCK
1340 static int tick;
1341 struct tms tms;
1342 if (tick == 0)
1343 tick = 1000000 / sysconf(_SC_CLK_TCK);
1344 times (&tms);
1345 return (tms.tms_utime + tms.tms_stime) * tick;
1347 #else
1348 #ifdef USG
1350 struct tms tms;
1351 # if HAVE_SYSCONF && defined _SC_CLK_TCK
1352 # define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
1353 # else
1354 # ifdef CLK_TCK
1355 # define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
1356 # else
1357 # define TICKS_PER_SECOND HZ /* traditional UNIX */
1358 # endif
1359 # endif
1360 times (&tms);
1361 return (tms.tms_utime + tms.tms_stime) * (1000000 / TICKS_PER_SECOND);
1363 #else
1364 #ifndef VMS
1366 struct rusage rusage;
1367 getrusage (0, &rusage);
1368 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1369 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1371 #else /* VMS */
1373 struct
1375 int proc_user_time;
1376 int proc_system_time;
1377 int child_user_time;
1378 int child_system_time;
1379 } vms_times;
1380 times ((void *) &vms_times);
1381 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
1383 #endif /* VMS */
1384 #endif /* USG */
1385 #endif /* _SC_CLK_TCK */
1386 #endif /* _WIN32 */
1387 #endif /* __BEOS__ */
1390 #define TIMEVAR(VAR, BODY) \
1391 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1393 void
1394 print_time (str, total)
1395 const char *str;
1396 int total;
1398 fprintf (stderr,
1399 "time in %s: %d.%06d (%.0f%%)\n",
1400 str, total / 1000000, total % 1000000,
1401 (double)total / (double)all_time * 100.0);
1404 /* Count an error or warning. Return 1 if the message should be printed. */
1407 count_error (warningp)
1408 int warningp;
1410 if (warningp && inhibit_warnings)
1411 return 0;
1413 if (warningp && !warnings_are_errors)
1414 warningcount++;
1415 else
1417 static int warning_message = 0;
1419 if (warningp && !warning_message)
1421 notice ("%s: warnings being treated as errors\n", progname);
1422 warning_message = 1;
1424 errorcount++;
1427 return 1;
1430 /* Print a fatal error message. NAME is the text.
1431 Also include a system error message based on `errno'. */
1433 void
1434 pfatal_with_name (name)
1435 const char *name;
1437 fprintf (stderr, "%s: ", progname);
1438 perror (name);
1439 exit (FATAL_EXIT_CODE);
1442 void
1443 fatal_io_error (name)
1444 const char *name;
1446 notice ("%s: %s: I/O error\n", progname, name);
1447 exit (FATAL_EXIT_CODE);
1450 /* This is the default decl_printable_name function. */
1452 static const char *
1453 decl_name (decl, verbosity)
1454 tree decl;
1455 int verbosity ATTRIBUTE_UNUSED;
1457 return IDENTIFIER_POINTER (DECL_NAME (decl));
1460 /* Mark P for GC. Also mark main_input_filename and input_filename. */
1461 static void
1462 mark_file_stack (p)
1463 void *p;
1465 struct file_stack *stack = *(struct file_stack **)p;
1467 /* We're only called for input_file_stack, so we can mark the current
1468 input_filename here as well. */
1469 ggc_mark_string (main_input_filename);
1470 ggc_mark_string (input_filename);
1472 while (stack)
1474 ggc_mark_string (stack->name);
1475 stack = stack->next;
1479 static int need_error_newline;
1481 /* Function of last error message;
1482 more generally, function such that if next error message is in it
1483 then we don't have to mention the function name. */
1484 static tree last_error_function = NULL;
1486 /* Used to detect when input_file_stack has changed since last described. */
1487 static int last_error_tick;
1489 /* Called when the start of a function definition is parsed,
1490 this function prints on stderr the name of the function. */
1492 void
1493 announce_function (decl)
1494 tree decl;
1496 if (! quiet_flag)
1498 if (rtl_dump_and_exit)
1499 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1500 else
1501 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1502 fflush (stderr);
1503 need_error_newline = 1;
1504 last_error_function = current_function_decl;
1508 /* The default function to print out name of current function that caused
1509 an error. */
1511 void
1512 default_print_error_function (file)
1513 const char *file;
1515 if (last_error_function != current_function_decl)
1517 if (file)
1518 fprintf (stderr, "%s: ", file);
1520 if (current_function_decl == NULL)
1521 notice ("At top level:\n");
1522 else
1523 notice ((TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE
1524 ? "In method `%s':\n"
1525 : "In function `%s':\n"),
1526 (*decl_printable_name) (current_function_decl, 2));
1528 last_error_function = current_function_decl;
1532 /* Called by report_error_function to print out function name.
1533 * Default may be overridden by language front-ends. */
1535 void (*print_error_function) PROTO((const char *)) =
1536 default_print_error_function;
1538 /* Prints out, if necessary, the name of the current function
1539 that caused an error. Called from all error and warning functions.
1540 We ignore the FILE parameter, as it cannot be relied upon. */
1542 void
1543 report_error_function (file)
1544 const char *file ATTRIBUTE_UNUSED;
1546 struct file_stack *p;
1548 if (need_error_newline)
1550 fprintf (stderr, "\n");
1551 need_error_newline = 0;
1554 if (input_file_stack && input_file_stack->next != 0
1555 && input_file_stack_tick != last_error_tick)
1557 for (p = input_file_stack->next; p; p = p->next)
1558 notice ((p == input_file_stack->next
1559 ? "In file included from %s:%d"
1560 : ",\n from %s:%d"),
1561 p->name, p->line);
1562 fprintf (stderr, ":\n");
1563 last_error_tick = input_file_stack_tick;
1566 (*print_error_function) (input_filename);
1569 /* Print a message. */
1571 static void
1572 vnotice (file, msgid, ap)
1573 FILE *file;
1574 const char *msgid;
1575 va_list ap;
1577 vfprintf (file, _(msgid), ap);
1580 static void
1581 notice VPROTO((const char *msgid, ...))
1583 #ifndef ANSI_PROTOTYPES
1584 char *msgid;
1585 #endif
1586 va_list ap;
1588 VA_START (ap, msgid);
1590 #ifndef ANSI_PROTOTYPES
1591 msgid = va_arg (ap, char *);
1592 #endif
1594 vnotice (stderr, msgid, ap);
1595 va_end (ap);
1598 void
1599 fnotice VPROTO((FILE *file, const char *msgid, ...))
1601 #ifndef ANSI_PROTOTYPES
1602 FILE *file;
1603 const char *msgid;
1604 #endif
1605 va_list ap;
1607 VA_START (ap, msgid);
1609 #ifndef ANSI_PROTOTYPES
1610 file = va_arg (ap, FILE *);
1611 msgid = va_arg (ap, const char *);
1612 #endif
1614 vnotice (file, msgid, ap);
1615 va_end (ap);
1618 /* Report FILE and LINE (or program name), and optionally just WARN. */
1620 static void
1621 report_file_and_line (file, line, warn)
1622 const char *file;
1623 int line;
1624 int warn;
1626 if (file)
1627 fprintf (stderr, "%s:%d: ", file, line);
1628 else
1629 fprintf (stderr, "%s: ", progname);
1631 if (warn)
1632 notice ("warning: ");
1635 /* Print a message. */
1637 static void
1638 vmessage (prefix, msgid, ap)
1639 const char *prefix;
1640 const char *msgid;
1641 va_list ap;
1643 if (prefix)
1644 fprintf (stderr, "%s: ", prefix);
1646 vfprintf (stderr, msgid, ap);
1649 /* Print a message relevant to line LINE of file FILE. */
1651 static void
1652 v_message_with_file_and_line (file, line, warn, msgid, ap)
1653 const char *file;
1654 int line;
1655 int warn;
1656 const char *msgid;
1657 va_list ap;
1659 report_file_and_line (file, line, warn);
1660 vnotice (stderr, msgid, ap);
1661 fputc ('\n', stderr);
1664 /* Print a message relevant to the given DECL. */
1666 static void
1667 v_message_with_decl (decl, warn, msgid, ap)
1668 tree decl;
1669 int warn;
1670 const char *msgid;
1671 va_list ap;
1673 const char *p;
1675 report_file_and_line (DECL_SOURCE_FILE (decl),
1676 DECL_SOURCE_LINE (decl), warn);
1678 /* Do magic to get around lack of varargs support for insertion
1679 of arguments into existing list. We know that the decl is first;
1680 we ass_u_me that it will be printed with "%s". */
1682 for (p = _(msgid); *p; ++p)
1684 if (*p == '%')
1686 if (*(p + 1) == '%')
1687 ++p;
1688 else if (*(p + 1) != 's')
1689 abort ();
1690 else
1691 break;
1695 if (p > _(msgid)) /* Print the left-hand substring. */
1697 char fmt[sizeof "%.255s"];
1698 long width = p - _(msgid);
1700 if (width > 255L) width = 255L; /* arbitrary */
1701 sprintf (fmt, "%%.%lds", width);
1702 fprintf (stderr, fmt, _(msgid));
1705 if (*p == '%') /* Print the name. */
1707 const char *n = (DECL_NAME (decl)
1708 ? (*decl_printable_name) (decl, 2)
1709 : "((anonymous))");
1710 fputs (n, stderr);
1711 while (*p)
1713 ++p;
1714 if (ISALPHA (*(p - 1) & 0xFF))
1715 break;
1719 if (*p) /* Print the rest of the message. */
1720 vmessage ((char *)NULL, p, ap);
1722 fputc ('\n', stderr);
1725 /* Figure file and line of the given INSN. */
1727 static void
1728 file_and_line_for_asm (insn, pfile, pline)
1729 rtx insn;
1730 char **pfile;
1731 int *pline;
1733 rtx body = PATTERN (insn);
1734 rtx asmop;
1736 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1737 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1738 asmop = SET_SRC (body);
1739 else if (GET_CODE (body) == ASM_OPERANDS)
1740 asmop = body;
1741 else if (GET_CODE (body) == PARALLEL
1742 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1743 asmop = SET_SRC (XVECEXP (body, 0, 0));
1744 else if (GET_CODE (body) == PARALLEL
1745 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1746 asmop = XVECEXP (body, 0, 0);
1747 else
1748 asmop = NULL;
1750 if (asmop)
1752 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1753 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1755 else
1757 *pfile = input_filename;
1758 *pline = lineno;
1762 /* Report an error at line LINE of file FILE. */
1764 static void
1765 v_error_with_file_and_line (file, line, msgid, ap)
1766 const char *file;
1767 int line;
1768 const char *msgid;
1769 va_list ap;
1771 count_error (0);
1772 report_error_function (file);
1773 v_message_with_file_and_line (file, line, 0, msgid, ap);
1776 void
1777 error_with_file_and_line VPROTO((const char *file, int line,
1778 const char *msgid, ...))
1780 #ifndef ANSI_PROTOTYPES
1781 const char *file;
1782 int line;
1783 const char *msgid;
1784 #endif
1785 va_list ap;
1787 VA_START (ap, msgid);
1789 #ifndef ANSI_PROTOTYPES
1790 file = va_arg (ap, const char *);
1791 line = va_arg (ap, int);
1792 msgid = va_arg (ap, const char *);
1793 #endif
1795 v_error_with_file_and_line (file, line, msgid, ap);
1796 va_end (ap);
1799 /* Report an error at the declaration DECL.
1800 MSGID is a format string which uses %s to substitute the declaration
1801 name; subsequent substitutions are a la printf. */
1803 static void
1804 v_error_with_decl (decl, msgid, ap)
1805 tree decl;
1806 const char *msgid;
1807 va_list ap;
1809 count_error (0);
1810 report_error_function (DECL_SOURCE_FILE (decl));
1811 v_message_with_decl (decl, 0, msgid, ap);
1814 void
1815 error_with_decl VPROTO((tree decl, const char *msgid, ...))
1817 #ifndef ANSI_PROTOTYPES
1818 tree decl;
1819 const char *msgid;
1820 #endif
1821 va_list ap;
1823 VA_START (ap, msgid);
1825 #ifndef ANSI_PROTOTYPES
1826 decl = va_arg (ap, tree);
1827 msgid = va_arg (ap, const char *);
1828 #endif
1830 v_error_with_decl (decl, msgid, ap);
1831 va_end (ap);
1834 /* Report an error at the line number of the insn INSN.
1835 This is used only when INSN is an `asm' with operands,
1836 and each ASM_OPERANDS records its own source file and line. */
1838 static void
1839 v_error_for_asm (insn, msgid, ap)
1840 rtx insn;
1841 const char *msgid;
1842 va_list ap;
1844 char *file;
1845 int line;
1847 count_error (0);
1848 file_and_line_for_asm (insn, &file, &line);
1849 report_error_function (file);
1850 v_message_with_file_and_line (file, line, 0, msgid, ap);
1853 void
1854 error_for_asm VPROTO((rtx insn, const char *msgid, ...))
1856 #ifndef ANSI_PROTOTYPES
1857 rtx insn;
1858 const char *msgid;
1859 #endif
1860 va_list ap;
1862 VA_START (ap, msgid);
1864 #ifndef ANSI_PROTOTYPES
1865 insn = va_arg (ap, rtx);
1866 msgid = va_arg (ap, const char *);
1867 #endif
1869 v_error_for_asm (insn, msgid, ap);
1870 va_end (ap);
1873 /* Report an error at the current line number. */
1875 static void
1876 verror (msgid, ap)
1877 const char *msgid;
1878 va_list ap;
1880 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1883 void
1884 error VPROTO((const char *msgid, ...))
1886 #ifndef ANSI_PROTOTYPES
1887 const char *msgid;
1888 #endif
1889 va_list ap;
1891 VA_START (ap, msgid);
1893 #ifndef ANSI_PROTOTYPES
1894 msgid = va_arg (ap, const char *);
1895 #endif
1897 verror (msgid, ap);
1898 va_end (ap);
1901 /* Report a fatal error at the current line number. Allow a front end to
1902 intercept the message. */
1904 static void (*fatal_function) PROTO ((const char *, va_list));
1906 /* Set the function to call when a fatal error occurs. */
1908 void
1909 set_fatal_function (f)
1910 void (*f) PROTO ((const char *, va_list));
1912 fatal_function = f;
1915 static void
1916 vfatal (msgid, ap)
1917 const char *msgid;
1918 va_list ap;
1920 if (fatal_function != 0)
1921 (*fatal_function) (_(msgid), ap);
1923 verror (msgid, ap);
1924 exit (FATAL_EXIT_CODE);
1927 void
1928 fatal VPROTO((const char *msgid, ...))
1930 #ifndef ANSI_PROTOTYPES
1931 const char *msgid;
1932 #endif
1933 va_list ap;
1935 VA_START (ap, msgid);
1937 #ifndef ANSI_PROTOTYPES
1938 msgid = va_arg (ap, const char *);
1939 #endif
1941 vfatal (msgid, ap);
1942 va_end (ap);
1945 void
1946 _fatal_insn (msgid, insn, file, line, function)
1947 const char *msgid;
1948 rtx insn;
1949 const char *file;
1950 int line;
1951 const char *function;
1953 error (msgid);
1954 debug_rtx (insn);
1955 fancy_abort (file, line, function);
1958 void
1959 _fatal_insn_not_found (insn, file, line, function)
1960 rtx insn;
1961 const char *file;
1962 int line;
1963 const char *function;
1965 if (INSN_CODE (insn) < 0)
1966 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1967 else
1968 _fatal_insn ("Insn does not satisfy its constraints:",
1969 insn, file, line, function);
1972 /* Report a warning at line LINE of file FILE. */
1974 static void
1975 v_warning_with_file_and_line (file, line, msgid, ap)
1976 const char *file;
1977 int line;
1978 const char *msgid;
1979 va_list ap;
1981 if (count_error (1))
1983 report_error_function (file);
1984 v_message_with_file_and_line (file, line, 1, msgid, ap);
1988 void
1989 warning_with_file_and_line VPROTO((const char *file, int line,
1990 const char *msgid, ...))
1992 #ifndef ANSI_PROTOTYPES
1993 const char *file;
1994 int line;
1995 const char *msgid;
1996 #endif
1997 va_list ap;
1999 VA_START (ap, msgid);
2001 #ifndef ANSI_PROTOTYPES
2002 file = va_arg (ap, const char *);
2003 line = va_arg (ap, int);
2004 msgid = va_arg (ap, const char *);
2005 #endif
2007 v_warning_with_file_and_line (file, line, msgid, ap);
2008 va_end (ap);
2011 /* Report a warning at the declaration DECL.
2012 MSGID is a format string which uses %s to substitute the declaration
2013 name; subsequent substitutions are a la printf. */
2015 static void
2016 v_warning_with_decl (decl, msgid, ap)
2017 tree decl;
2018 const char *msgid;
2019 va_list ap;
2021 if (count_error (1))
2023 report_error_function (DECL_SOURCE_FILE (decl));
2024 v_message_with_decl (decl, 1, msgid, ap);
2028 void
2029 warning_with_decl VPROTO((tree decl, const char *msgid, ...))
2031 #ifndef ANSI_PROTOTYPES
2032 tree decl;
2033 const char *msgid;
2034 #endif
2035 va_list ap;
2037 VA_START (ap, msgid);
2039 #ifndef ANSI_PROTOTYPES
2040 decl = va_arg (ap, tree);
2041 msgid = va_arg (ap, const char *);
2042 #endif
2044 v_warning_with_decl (decl, msgid, ap);
2045 va_end (ap);
2048 /* Report a warning at the line number of the insn INSN.
2049 This is used only when INSN is an `asm' with operands,
2050 and each ASM_OPERANDS records its own source file and line. */
2052 static void
2053 v_warning_for_asm (insn, msgid, ap)
2054 rtx insn;
2055 const char *msgid;
2056 va_list ap;
2058 if (count_error (1))
2060 char *file;
2061 int line;
2063 file_and_line_for_asm (insn, &file, &line);
2064 report_error_function (file);
2065 v_message_with_file_and_line (file, line, 1, msgid, ap);
2069 void
2070 warning_for_asm VPROTO((rtx insn, const char *msgid, ...))
2072 #ifndef ANSI_PROTOTYPES
2073 rtx insn;
2074 const char *msgid;
2075 #endif
2076 va_list ap;
2078 VA_START (ap, msgid);
2080 #ifndef ANSI_PROTOTYPES
2081 insn = va_arg (ap, rtx);
2082 msgid = va_arg (ap, const char *);
2083 #endif
2085 v_warning_for_asm (insn, msgid, ap);
2086 va_end (ap);
2089 /* Report a warning at the current line number. */
2091 static void
2092 vwarning (msgid, ap)
2093 const char *msgid;
2094 va_list ap;
2096 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
2099 void
2100 warning VPROTO((const char *msgid, ...))
2102 #ifndef ANSI_PROTOTYPES
2103 const char *msgid;
2104 #endif
2105 va_list ap;
2107 VA_START (ap, msgid);
2109 #ifndef ANSI_PROTOTYPES
2110 msgid = va_arg (ap, const char *);
2111 #endif
2113 vwarning (msgid, ap);
2114 va_end (ap);
2117 /* These functions issue either warnings or errors depending on
2118 -pedantic-errors. */
2120 static void
2121 vpedwarn (msgid, ap)
2122 const char *msgid;
2123 va_list ap;
2125 if (flag_pedantic_errors)
2126 verror (msgid, ap);
2127 else
2128 vwarning (msgid, ap);
2131 void
2132 pedwarn VPROTO((const char *msgid, ...))
2134 #ifndef ANSI_PROTOTYPES
2135 const char *msgid;
2136 #endif
2137 va_list ap;
2139 VA_START (ap, msgid);
2141 #ifndef ANSI_PROTOTYPES
2142 msgid = va_arg (ap, const char *);
2143 #endif
2145 vpedwarn (msgid, ap);
2146 va_end (ap);
2149 static void
2150 v_pedwarn_with_decl (decl, msgid, ap)
2151 tree decl;
2152 const char *msgid;
2153 va_list ap;
2155 /* We don't want -pedantic-errors to cause the compilation to fail from
2156 "errors" in system header files. Sometimes fixincludes can't fix what's
2157 broken (eg: unsigned char bitfields - fixing it may change the alignment
2158 which will cause programs to mysteriously fail because the C library
2159 or kernel uses the original layout). There's no point in issuing a
2160 warning either, it's just unnecessary noise. */
2162 if (! DECL_IN_SYSTEM_HEADER (decl))
2164 if (flag_pedantic_errors)
2165 v_error_with_decl (decl, msgid, ap);
2166 else
2167 v_warning_with_decl (decl, msgid, ap);
2171 void
2172 pedwarn_with_decl VPROTO((tree decl, const char *msgid, ...))
2174 #ifndef ANSI_PROTOTYPES
2175 tree decl;
2176 const char *msgid;
2177 #endif
2178 va_list ap;
2180 VA_START (ap, msgid);
2182 #ifndef ANSI_PROTOTYPES
2183 decl = va_arg (ap, tree);
2184 msgid = va_arg (ap, const char *);
2185 #endif
2187 v_pedwarn_with_decl (decl, msgid, ap);
2188 va_end (ap);
2191 static void
2192 v_pedwarn_with_file_and_line (file, line, msgid, ap)
2193 const char *file;
2194 int line;
2195 const char *msgid;
2196 va_list ap;
2198 if (flag_pedantic_errors)
2199 v_error_with_file_and_line (file, line, msgid, ap);
2200 else
2201 v_warning_with_file_and_line (file, line, msgid, ap);
2204 void
2205 pedwarn_with_file_and_line VPROTO((const char *file, int line,
2206 const char *msgid, ...))
2208 #ifndef ANSI_PROTOTYPES
2209 const char *file;
2210 int line;
2211 const char *msgid;
2212 #endif
2213 va_list ap;
2215 VA_START (ap, msgid);
2217 #ifndef ANSI_PROTOTYPES
2218 file = va_arg (ap, const char *);
2219 line = va_arg (ap, int);
2220 msgid = va_arg (ap, const char *);
2221 #endif
2223 v_pedwarn_with_file_and_line (file, line, msgid, ap);
2224 va_end (ap);
2227 /* Apologize for not implementing some feature. */
2229 static void
2230 vsorry (msgid, ap)
2231 const char *msgid;
2232 va_list ap;
2234 sorrycount++;
2235 if (input_filename)
2236 fprintf (stderr, "%s:%d: ", input_filename, lineno);
2237 else
2238 fprintf (stderr, "%s: ", progname);
2239 notice ("sorry, not implemented: ");
2240 vnotice (stderr, msgid, ap);
2241 fputc ('\n', stderr);
2244 void
2245 sorry VPROTO((const char *msgid, ...))
2247 #ifndef ANSI_PROTOTYPES
2248 const char *msgid;
2249 #endif
2250 va_list ap;
2252 VA_START (ap, msgid);
2254 #ifndef ANSI_PROTOTYPES
2255 msgid = va_arg (ap, const char *);
2256 #endif
2258 vsorry (msgid, ap);
2259 va_end (ap);
2263 /* This calls abort and is used to avoid problems when abort if a macro.
2264 It is used when we need to pass the address of abort. */
2266 void
2267 do_abort ()
2269 abort ();
2272 /* When `malloc.c' is compiled with `rcheck' defined,
2273 it calls this function to report clobberage. */
2275 void
2276 botch (s)
2277 const char * s ATTRIBUTE_UNUSED;
2279 abort ();
2282 /* Return the logarithm of X, base 2, considering X unsigned,
2283 if X is a power of 2. Otherwise, returns -1.
2285 This should be used via the `exact_log2' macro. */
2288 exact_log2_wide (x)
2289 register unsigned HOST_WIDE_INT x;
2291 register int log = 0;
2292 /* Test for 0 or a power of 2. */
2293 if (x == 0 || x != (x & -x))
2294 return -1;
2295 while ((x >>= 1) != 0)
2296 log++;
2297 return log;
2300 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
2301 If X is 0, return -1.
2303 This should be used via the floor_log2 macro. */
2306 floor_log2_wide (x)
2307 register unsigned HOST_WIDE_INT x;
2309 register int log = -1;
2310 while (x != 0)
2311 log++,
2312 x >>= 1;
2313 return log;
2316 static int float_handler_set;
2317 int float_handled;
2318 jmp_buf float_handler;
2320 /* Signals actually come here. */
2322 static void
2323 float_signal (signo)
2324 /* If this is missing, some compilers complain. */
2325 int signo ATTRIBUTE_UNUSED;
2327 if (float_handled == 0)
2328 abort ();
2329 #if defined (USG) || defined (hpux)
2330 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
2331 #endif
2332 float_handled = 0;
2333 signal (SIGFPE, float_signal);
2334 longjmp (float_handler, 1);
2337 /* Specify where to longjmp to when a floating arithmetic error happens.
2338 If HANDLER is 0, it means don't handle the errors any more. */
2340 void
2341 set_float_handler (handler)
2342 jmp_buf handler;
2344 float_handled = (handler != 0);
2345 if (handler)
2346 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2348 if (float_handled && ! float_handler_set)
2350 signal (SIGFPE, float_signal);
2351 float_handler_set = 1;
2355 /* This is a wrapper function for code which might elicit an
2356 arithmetic exception. That code should be passed in as a function
2357 pointer FN, and one argument DATA. DATA is usually a struct which
2358 contains the real input and output for function FN. This function
2359 returns 0 (failure) if longjmp was called (i.e. an exception
2360 occured.) It returns 1 (success) otherwise. */
2363 do_float_handler (fn, data)
2364 void (*fn) PROTO ((PTR));
2365 PTR data;
2367 jmp_buf buf;
2369 if (setjmp (buf))
2371 /* We got here via longjmp() caused by an exception in function fn() */
2372 set_float_handler (NULL);
2373 return 0;
2376 set_float_handler (buf);
2377 (*fn)(data);
2378 set_float_handler (NULL);
2379 return 1;
2382 /* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2383 error happens, pushing the previous specification into OLD_HANDLER.
2384 Return an indication of whether there was a previous handler in effect. */
2387 push_float_handler (handler, old_handler)
2388 jmp_buf handler, old_handler;
2390 int was_handled = float_handled;
2392 float_handled = 1;
2393 if (was_handled)
2394 memcpy ((char *) old_handler, (char *) float_handler,
2395 sizeof (float_handler));
2397 memcpy ((char *) float_handler, (char *) handler, sizeof (float_handler));
2398 return was_handled;
2401 /* Restore the previous specification of whether and where to longjmp to
2402 when a floating arithmetic error happens. */
2404 void
2405 pop_float_handler (handled, handler)
2406 int handled;
2407 jmp_buf handler;
2409 float_handled = handled;
2410 if (handled)
2411 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2414 /* Handler for SIGPIPE. */
2416 static void
2417 pipe_closed (signo)
2418 /* If this is missing, some compilers complain. */
2419 int signo ATTRIBUTE_UNUSED;
2421 fatal ("output pipe has been closed");
2424 /* Strip off a legitimate source ending from the input string NAME of
2425 length LEN. Rather than having to know the names used by all of
2426 our front ends, we strip off an ending of a period followed by
2427 up to five characters. (Java uses ".class".) */
2429 void
2430 strip_off_ending (name, len)
2431 char *name;
2432 int len;
2434 int i;
2435 for (i = 2; i < 6 && len > i; i++)
2437 if (name[len - i] == '.')
2439 name[len - i] = '\0';
2440 break;
2445 /* Output a quoted string. */
2447 void
2448 output_quoted_string (asm_file, string)
2449 FILE *asm_file;
2450 const char *string;
2452 #ifdef OUTPUT_QUOTED_STRING
2453 OUTPUT_QUOTED_STRING (asm_file, string);
2454 #else
2455 char c;
2457 putc ('\"', asm_file);
2458 while ((c = *string++) != 0)
2460 if (c == '\"' || c == '\\')
2461 putc ('\\', asm_file);
2462 putc (c, asm_file);
2464 putc ('\"', asm_file);
2465 #endif
2468 /* Output a file name in the form wanted by System V. */
2470 void
2471 output_file_directive (asm_file, input_name)
2472 FILE *asm_file;
2473 const char *input_name;
2475 int len = strlen (input_name);
2476 const char *na = input_name + len;
2478 /* NA gets INPUT_NAME sans directory names. */
2479 while (na > input_name)
2481 if (na[-1] == '/')
2482 break;
2483 #ifdef DIR_SEPARATOR
2484 if (na[-1] == DIR_SEPARATOR)
2485 break;
2486 #endif
2487 na--;
2490 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2491 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2492 #else
2493 #ifdef ASM_OUTPUT_SOURCE_FILENAME
2494 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2495 #else
2496 fprintf (asm_file, "\t.file\t");
2497 output_quoted_string (asm_file, na);
2498 fputc ('\n', asm_file);
2499 #endif
2500 #endif
2503 #ifdef ASM_IDENTIFY_LANGUAGE
2504 /* Routine to build language identifier for object file. */
2505 static void
2506 output_lang_identify (asm_out_file)
2507 FILE *asm_out_file;
2509 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2510 char *s = (char *) alloca (len);
2511 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2512 ASM_OUTPUT_LABEL (asm_out_file, s);
2514 #endif
2516 /* Routine to open a dump file. */
2517 static void
2518 open_dump_file (suffix, function_name)
2519 const char *suffix;
2520 const char *function_name;
2522 char *dumpname;
2524 TIMEVAR
2525 (dump_time,
2527 dumpname = concat (dump_base_name, suffix, NULL);
2529 if (rtl_dump_file != NULL)
2530 fclose (rtl_dump_file);
2532 rtl_dump_file = fopen (dumpname, "a");
2534 if (rtl_dump_file == NULL)
2535 pfatal_with_name (dumpname);
2537 free (dumpname);
2539 if (function_name)
2540 fprintf (rtl_dump_file, "\n;; Function %s\n\n", function_name);
2543 return;
2546 /* Routine to close a dump file. */
2547 static void
2548 close_dump_file (func, insns)
2549 void (*func) PROTO ((FILE *, rtx));
2550 rtx insns;
2552 TIMEVAR
2553 (dump_time,
2555 if (func)
2556 func (rtl_dump_file, insns);
2558 fflush (rtl_dump_file);
2559 fclose (rtl_dump_file);
2561 rtl_dump_file = NULL;
2564 return;
2567 /* Routine to dump rtl into a file. */
2568 static void
2569 dump_rtl (suffix, decl, func, insns)
2570 const char *suffix;
2571 tree decl;
2572 void (*func) PROTO ((FILE *, rtx));
2573 rtx insns;
2575 open_dump_file (suffix, decl_printable_name (decl, 2));
2576 close_dump_file (func, insns);
2579 /* Routine to empty a dump file. */
2580 static void
2581 clean_dump_file (suffix)
2582 const char *suffix;
2584 char * const dumpname = concat (dump_base_name, suffix, NULL);
2586 rtl_dump_file = fopen (dumpname, "w");
2588 if (rtl_dump_file == NULL)
2589 pfatal_with_name (dumpname);
2591 free (dumpname);
2593 fclose (rtl_dump_file);
2594 rtl_dump_file = NULL;
2596 return;
2599 /* Do any final processing required for the declarations in VEC, of
2600 which there are LEN. We write out inline functions and variables
2601 that have been deferred until this point, but which are required.
2602 Returns non-zero if anything was put out. */
2604 wrapup_global_declarations (vec, len)
2605 tree *vec;
2606 int len;
2608 tree decl;
2609 int i;
2610 int reconsider;
2611 int output_something = 0;
2613 for (i = 0; i < len; i++)
2615 decl = vec[i];
2617 /* We're not deferring this any longer. */
2618 DECL_DEFER_OUTPUT (decl) = 0;
2620 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2621 && incomplete_decl_finalize_hook != 0)
2622 (*incomplete_decl_finalize_hook) (decl);
2625 /* Now emit any global variables or functions that we have been
2626 putting off. We need to loop in case one of the things emitted
2627 here references another one which comes earlier in the list. */
2630 reconsider = 0;
2631 for (i = 0; i < len; i++)
2633 decl = vec[i];
2635 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2636 continue;
2638 /* Don't write out static consts, unless we still need them.
2640 We also keep static consts if not optimizing (for debugging),
2641 unless the user specified -fno-keep-static-consts.
2642 ??? They might be better written into the debug information.
2643 This is possible when using DWARF.
2645 A language processor that wants static constants to be always
2646 written out (even if it is not used) is responsible for
2647 calling rest_of_decl_compilation itself. E.g. the C front-end
2648 calls rest_of_decl_compilation from finish_decl.
2649 One motivation for this is that is conventional in some
2650 environments to write things like:
2651 static const char rcsid[] = "... version string ...";
2652 intending to force the string to be in the executable.
2654 A language processor that would prefer to have unneeded
2655 static constants "optimized away" would just defer writing
2656 them out until here. E.g. C++ does this, because static
2657 constants are often defined in header files.
2659 ??? A tempting alternative (for both C and C++) would be
2660 to force a constant to be written if and only if it is
2661 defined in a main file, as opposed to an include file. */
2663 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2664 && (! TREE_READONLY (decl)
2665 || TREE_PUBLIC (decl)
2666 || (!optimize && flag_keep_static_consts)
2667 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2669 reconsider = 1;
2670 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2673 if (TREE_CODE (decl) == FUNCTION_DECL
2674 && DECL_INITIAL (decl) != 0
2675 && DECL_SAVED_INSNS (decl) != 0
2676 && (flag_keep_inline_functions
2677 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
2678 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2680 reconsider = 1;
2681 temporary_allocation ();
2682 output_inline_function (decl);
2683 permanent_allocation (1);
2687 if (reconsider)
2688 output_something = 1;
2690 while (reconsider);
2692 return output_something;
2695 /* Issue appropriate warnings for the global declarations in VEC (of
2696 which there are LEN). Output debugging information for them. */
2697 void
2698 check_global_declarations (vec, len)
2699 tree *vec;
2700 int len;
2702 tree decl;
2703 int i;
2705 for (i = 0; i < len; i++)
2707 decl = vec[i];
2709 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2710 && ! TREE_ASM_WRITTEN (decl))
2711 /* Cancel the RTL for this decl so that, if debugging info
2712 output for global variables is still to come,
2713 this one will be omitted. */
2714 DECL_RTL (decl) = NULL;
2716 /* Warn about any function
2717 declared static but not defined.
2718 We don't warn about variables,
2719 because many programs have static variables
2720 that exist only to get some text into the object file. */
2721 if (TREE_CODE (decl) == FUNCTION_DECL
2722 && (warn_unused
2723 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2724 && DECL_INITIAL (decl) == 0
2725 && DECL_EXTERNAL (decl)
2726 && ! DECL_ARTIFICIAL (decl)
2727 && ! TREE_PUBLIC (decl))
2729 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2730 pedwarn_with_decl (decl,
2731 "`%s' used but never defined");
2732 else
2733 warning_with_decl (decl,
2734 "`%s' declared `static' but never defined");
2735 /* This symbol is effectively an "extern" declaration now. */
2736 TREE_PUBLIC (decl) = 1;
2737 assemble_external (decl);
2740 /* Warn about static fns or vars defined but not used,
2741 but not about inline functions or static consts
2742 since defining those in header files is normal practice. */
2743 if (warn_unused
2744 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2745 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2746 && ! DECL_IN_SYSTEM_HEADER (decl)
2747 && ! DECL_EXTERNAL (decl)
2748 && ! TREE_PUBLIC (decl)
2749 && ! TREE_USED (decl)
2750 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2751 /* The TREE_USED bit for file-scope decls
2752 is kept in the identifier, to handle multiple
2753 external decls in different scopes. */
2754 && ! TREE_USED (DECL_NAME (decl)))
2755 warning_with_decl (decl, "`%s' defined but not used");
2757 #ifdef SDB_DEBUGGING_INFO
2758 /* The COFF linker can move initialized global vars to the end.
2759 And that can screw up the symbol ordering.
2760 By putting the symbols in that order to begin with,
2761 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2762 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2763 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2764 && ! DECL_EXTERNAL (decl)
2765 && DECL_RTL (decl) != 0)
2766 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2768 /* Output COFF information for non-global
2769 file-scope initialized variables. */
2770 if (write_symbols == SDB_DEBUG
2771 && TREE_CODE (decl) == VAR_DECL
2772 && DECL_INITIAL (decl)
2773 && ! DECL_EXTERNAL (decl)
2774 && DECL_RTL (decl) != 0
2775 && GET_CODE (DECL_RTL (decl)) == MEM)
2776 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2777 #endif /* SDB_DEBUGGING_INFO */
2778 #ifdef DWARF_DEBUGGING_INFO
2779 /* Output DWARF information for file-scope tentative data object
2780 declarations, file-scope (extern) function declarations (which
2781 had no corresponding body) and file-scope tagged type declarations
2782 and definitions which have not yet been forced out. */
2784 if (write_symbols == DWARF_DEBUG
2785 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2786 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2787 #endif
2788 #ifdef DWARF2_DEBUGGING_INFO
2789 /* Output DWARF2 information for file-scope tentative data object
2790 declarations, file-scope (extern) function declarations (which
2791 had no corresponding body) and file-scope tagged type declarations
2792 and definitions which have not yet been forced out. */
2794 if (write_symbols == DWARF2_DEBUG
2795 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2796 TIMEVAR (symout_time, dwarf2out_decl (decl));
2797 #endif
2801 /* Compile an entire file of output from cpp, named NAME.
2802 Write a file of assembly output and various debugging dumps. */
2804 static void
2805 compile_file (name)
2806 char *name;
2808 tree globals;
2809 int start_time;
2811 int name_specified = name != 0;
2813 if (dump_base_name == 0)
2814 dump_base_name = name ? name : "gccdump";
2816 parse_time = 0;
2817 varconst_time = 0;
2818 integration_time = 0;
2819 jump_time = 0;
2820 cse_time = 0;
2821 gcse_time = 0;
2822 loop_time = 0;
2823 cse2_time = 0;
2824 branch_prob_time = 0;
2825 flow_time = 0;
2826 combine_time = 0;
2827 regmove_time = 0;
2828 sched_time = 0;
2829 local_alloc_time = 0;
2830 global_alloc_time = 0;
2831 flow2_time = 0;
2832 sched2_time = 0;
2833 #ifdef DELAY_SLOTS
2834 dbr_sched_time = 0;
2835 #endif
2836 shorten_branch_time = 0;
2837 stack_reg_time = 0;
2838 final_time = 0;
2839 symout_time = 0;
2840 dump_time = 0;
2842 /* Initialize data in various passes. */
2844 init_obstacks ();
2845 init_tree_codes ();
2846 name = init_parse (name);
2847 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2848 || debug_info_level == DINFO_LEVEL_VERBOSE
2849 || flag_test_coverage
2850 || warn_notreached);
2851 init_regs ();
2852 init_decl_processing ();
2853 init_optabs ();
2854 init_stmt ();
2855 init_eh ();
2856 init_loop ();
2857 init_reload ();
2858 init_alias_once ();
2859 init_function_once ();
2860 init_stor_layout_once ();
2861 init_varasm_once ();
2863 /* The following initialization functions need to generate rtl, so
2864 provide a dummy function context for them. */
2865 init_dummy_function_start ();
2866 init_expmed ();
2867 init_expr_once ();
2868 if (flag_caller_saves)
2869 init_caller_save ();
2870 expand_dummy_function_end ();
2872 /* If auxiliary info generation is desired, open the output file.
2873 This goes in the same directory as the source file--unlike
2874 all the other output files. */
2875 if (flag_gen_aux_info)
2877 aux_info_file = fopen (aux_info_file_name, "w");
2878 if (aux_info_file == 0)
2879 pfatal_with_name (aux_info_file_name);
2882 /* Clear the dump files. */
2883 if (rtl_dump)
2884 clean_dump_file (".rtl");
2885 if (jump_opt_dump)
2887 clean_dump_file (".jump");
2888 if (graph_dump_format != no_graph)
2889 clean_graph_dump_file (dump_base_name, ".jump");
2891 if (addressof_dump)
2893 clean_dump_file (".addressof");
2894 if (graph_dump_format != no_graph)
2895 clean_graph_dump_file (dump_base_name, ".addressof");
2897 if (cse_dump)
2899 clean_dump_file (".cse");
2900 if (graph_dump_format != no_graph)
2901 clean_graph_dump_file (dump_base_name, ".cse");
2903 if (loop_dump)
2905 clean_dump_file (".loop");
2906 if (graph_dump_format != no_graph)
2907 clean_graph_dump_file (dump_base_name, ".loop");
2909 if (cse2_dump)
2911 clean_dump_file (".cse2");
2912 if (graph_dump_format != no_graph)
2913 clean_graph_dump_file (dump_base_name, ".cse2");
2915 if (branch_prob_dump)
2917 clean_dump_file (".bp");
2918 if (graph_dump_format != no_graph)
2919 clean_graph_dump_file (dump_base_name, ".bp");
2921 if (flow_dump)
2923 clean_dump_file (".flow");
2924 if (graph_dump_format != no_graph)
2925 clean_graph_dump_file (dump_base_name, ".flow");
2927 if (combine_dump)
2929 clean_dump_file (".combine");
2930 if (graph_dump_format != no_graph)
2931 clean_graph_dump_file (dump_base_name, ".combine");
2933 if (regmove_dump)
2935 clean_dump_file (".regmove");
2936 if (graph_dump_format != no_graph)
2937 clean_graph_dump_file (dump_base_name, ".regmove");
2939 if (sched_dump)
2941 clean_dump_file (".sched");
2942 if (graph_dump_format != no_graph)
2943 clean_graph_dump_file (dump_base_name, ".sched");
2945 if (local_reg_dump)
2947 clean_dump_file (".lreg");
2948 if (graph_dump_format != no_graph)
2949 clean_graph_dump_file (dump_base_name, ".lreg");
2951 if (global_reg_dump)
2953 clean_dump_file (".greg");
2954 if (graph_dump_format != no_graph)
2955 clean_graph_dump_file (dump_base_name, ".greg");
2957 if (flow2_dump)
2959 clean_dump_file (".flow2");
2960 if (graph_dump_format != no_graph)
2961 clean_graph_dump_file (dump_base_name, ".flow2");
2963 if (peephole2_dump)
2965 clean_dump_file (".peephole2");
2966 if (graph_dump_format != no_graph)
2967 clean_graph_dump_file (dump_base_name, ".peephole2");
2969 if (sched2_dump)
2971 clean_dump_file (".sched2");
2972 if (graph_dump_format != no_graph)
2973 clean_graph_dump_file (dump_base_name, ".sched2");
2975 if (jump2_opt_dump)
2977 clean_dump_file (".jump2");
2978 if (graph_dump_format != no_graph)
2979 clean_graph_dump_file (dump_base_name, ".jump2");
2981 #ifdef DELAY_SLOTS
2982 if (dbr_sched_dump)
2984 clean_dump_file (".dbr");
2985 if (graph_dump_format != no_graph)
2986 clean_graph_dump_file (dump_base_name, ".dbr");
2988 #endif
2989 if (gcse_dump)
2991 clean_dump_file (".gcse");
2992 if (graph_dump_format != no_graph)
2993 clean_graph_dump_file (dump_base_name, ".gcse");
2995 #ifdef STACK_REGS
2996 if (stack_reg_dump)
2998 clean_dump_file (".stack");
2999 if (graph_dump_format != no_graph)
3000 clean_graph_dump_file (dump_base_name, ".stack");
3002 #endif
3003 #ifdef MACHINE_DEPENDENT_REORG
3004 if (mach_dep_reorg_dump)
3006 clean_dump_file (".mach");
3007 if (graph_dump_format != no_graph)
3008 clean_graph_dump_file (dump_base_name, ".mach");
3010 #endif
3012 /* Open assembler code output file. */
3014 if (flag_syntax_only)
3015 asm_out_file = NULL;
3016 else
3018 if (! name_specified && asm_file_name == 0)
3019 asm_out_file = stdout;
3020 else
3022 int len = strlen (dump_base_name);
3023 register char *dumpname = (char *) xmalloc (len + 6);
3024 strcpy (dumpname, dump_base_name);
3025 strip_off_ending (dumpname, len);
3026 strcat (dumpname, ".s");
3027 if (asm_file_name == 0)
3028 asm_file_name = xstrdup (dumpname);
3029 if (!strcmp (asm_file_name, "-"))
3030 asm_out_file = stdout;
3031 else
3032 asm_out_file = fopen (asm_file_name, "w");
3033 if (asm_out_file == 0)
3034 pfatal_with_name (asm_file_name);
3037 #ifdef IO_BUFFER_SIZE
3038 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
3039 _IOFBF, IO_BUFFER_SIZE);
3040 #endif
3043 if (ggc_p)
3044 name = ggc_alloc_string (name, strlen (name));
3045 input_filename = name;
3047 /* Put an entry on the input file stack for the main input file. */
3048 input_file_stack
3049 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
3050 input_file_stack->next = 0;
3051 input_file_stack->name = input_filename;
3053 /* Perform language-specific initialization.
3054 This may set main_input_filename. */
3055 lang_init ();
3057 /* If the input doesn't start with a #line, use the input name
3058 as the official input file name. */
3059 if (main_input_filename == 0)
3060 main_input_filename = name;
3062 if (flag_syntax_only)
3064 write_symbols = NO_DEBUG;
3065 profile_flag = 0;
3066 profile_block_flag = 0;
3068 else
3070 ASM_FILE_START (asm_out_file);
3072 #ifdef ASM_COMMENT_START
3073 if (flag_verbose_asm)
3075 /* Print the list of options in effect. */
3076 print_version (asm_out_file, ASM_COMMENT_START);
3077 print_switch_values (asm_out_file, 0, MAX_LINE,
3078 ASM_COMMENT_START, " ", "\n");
3079 /* Add a blank line here so it appears in assembler output but not
3080 screen output. */
3081 fprintf (asm_out_file, "\n");
3083 #endif
3085 /* Output something to inform GDB that this compilation was by GCC. */
3086 #ifndef ASM_IDENTIFY_GCC
3087 fprintf (asm_out_file, "gcc2_compiled.:\n");
3088 #else
3089 ASM_IDENTIFY_GCC (asm_out_file);
3090 #endif
3092 /* Output something to identify which front-end produced this file. */
3093 #ifdef ASM_IDENTIFY_LANGUAGE
3094 ASM_IDENTIFY_LANGUAGE (asm_out_file);
3095 #endif
3096 } /* ! flag_syntax_only */
3098 #ifndef ASM_OUTPUT_SECTION_NAME
3099 if (flag_function_sections)
3101 warning ("-ffunction-sections not supported for this target.");
3102 flag_function_sections = 0;
3104 if (flag_data_sections)
3106 warning ("-fdata-sections not supported for this target.");
3107 flag_data_sections = 0;
3109 #endif
3111 if (flag_function_sections
3112 && (profile_flag || profile_block_flag))
3114 warning ("-ffunction-sections disabled; it makes profiling impossible.");
3115 flag_function_sections = 0;
3118 #ifndef OBJECT_FORMAT_ELF
3119 if (flag_function_sections && write_symbols != NO_DEBUG)
3120 warning ("-ffunction-sections may affect debugging on some targets.");
3121 #endif
3123 /* ??? Note: There used to be a conditional here
3124 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
3125 This was to guarantee separation between gcc_compiled. and
3126 the first function, for the sake of dbx on Suns.
3127 However, having the extra zero here confused the Emacs
3128 code for unexec, and might confuse other programs too.
3129 Therefore, I took out that change.
3130 In future versions we should find another way to solve
3131 that dbx problem. -- rms, 23 May 93. */
3133 /* Don't let the first function fall at the same address
3134 as gcc_compiled., if profiling. */
3135 if (profile_flag || profile_block_flag)
3137 /* It's best if we can write a nop here since some
3138 assemblers don't tolerate zeros in the text section. */
3139 output_asm_insn (get_insn_template (CODE_FOR_nop, NULL), NULL_PTR);
3142 /* If dbx symbol table desired, initialize writing it
3143 and output the predefined types. */
3144 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3145 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3146 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
3147 getdecls ()));
3148 #endif
3149 #ifdef SDB_DEBUGGING_INFO
3150 if (write_symbols == SDB_DEBUG)
3151 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
3152 getdecls ()));
3153 #endif
3154 #ifdef DWARF_DEBUGGING_INFO
3155 if (write_symbols == DWARF_DEBUG)
3156 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
3157 #endif
3158 #ifdef DWARF2_UNWIND_INFO
3159 if (dwarf2out_do_frame ())
3160 dwarf2out_frame_init ();
3161 #endif
3162 #ifdef DWARF2_DEBUGGING_INFO
3163 if (write_symbols == DWARF2_DEBUG)
3164 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
3165 #endif
3167 /* Initialize yet another pass. */
3169 init_final (main_input_filename);
3170 init_branch_prob (dump_base_name);
3172 start_time = get_run_time ();
3174 /* Call the parser, which parses the entire file
3175 (calling rest_of_compilation for each function). */
3177 if (yyparse () != 0)
3179 if (errorcount == 0)
3180 notice ("Errors detected in input file (your bison.simple is out of date)\n");
3182 /* In case there were missing closebraces,
3183 get us back to the global binding level. */
3184 while (! global_bindings_p ())
3185 poplevel (0, 0, 0);
3188 /* Compilation is now finished except for writing
3189 what's left of the symbol table output. */
3191 parse_time += get_run_time () - start_time;
3193 parse_time -= integration_time;
3194 parse_time -= varconst_time;
3196 if (flag_syntax_only)
3197 goto finish_syntax;
3199 globals = getdecls ();
3201 /* Really define vars that have had only a tentative definition.
3202 Really output inline functions that must actually be callable
3203 and have not been output so far. */
3206 int len = list_length (globals);
3207 tree *vec = (tree *) alloca (sizeof (tree) * len);
3208 int i;
3209 tree decl;
3211 /* Process the decls in reverse order--earliest first.
3212 Put them into VEC from back to front, then take out from front. */
3214 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
3215 vec[len - i - 1] = decl;
3217 wrapup_global_declarations (vec, len);
3219 /* This must occur after the loop to output deferred functions. Else
3220 the profiler initializer would not be emitted if all the functions
3221 in this compilation unit were deferred.
3223 output_func_start_profiler can not cause any additional functions or
3224 data to need to be output, so it need not be in the deferred function
3225 loop above. */
3226 output_func_start_profiler ();
3228 /* Now that all possible functions have been output, we can dump
3229 the exception table. */
3231 output_exception_table ();
3233 check_global_declarations (vec, len);
3236 /* Write out any pending weak symbol declarations. */
3238 weak_finish ();
3240 /* Do dbx symbols */
3241 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3242 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3243 TIMEVAR (symout_time,
3245 dbxout_finish (asm_out_file, main_input_filename);
3247 #endif
3249 #ifdef DWARF_DEBUGGING_INFO
3250 if (write_symbols == DWARF_DEBUG)
3251 TIMEVAR (symout_time,
3253 dwarfout_finish ();
3255 #endif
3257 #ifdef DWARF2_UNWIND_INFO
3258 if (dwarf2out_do_frame ())
3259 dwarf2out_frame_finish ();
3260 #endif
3262 #ifdef DWARF2_DEBUGGING_INFO
3263 if (write_symbols == DWARF2_DEBUG)
3264 TIMEVAR (symout_time,
3266 dwarf2out_finish ();
3268 #endif
3270 /* Output some stuff at end of file if nec. */
3272 end_final (dump_base_name);
3274 if (branch_prob_dump)
3275 open_dump_file (".bp", NULL);
3277 TIMEVAR (dump_time, end_branch_prob (rtl_dump_file));
3279 if (branch_prob_dump)
3280 close_dump_file (NULL, NULL_RTX);
3282 #ifdef ASM_FILE_END
3283 ASM_FILE_END (asm_out_file);
3284 #endif
3287 /* Language-specific end of compilation actions. */
3288 finish_syntax:
3289 lang_finish ();
3291 /* Close the dump files. */
3293 if (flag_gen_aux_info)
3295 fclose (aux_info_file);
3296 if (errorcount)
3297 unlink (aux_info_file_name);
3300 if (combine_dump)
3302 open_dump_file (".combine", NULL);
3303 TIMEVAR (dump_time, dump_combine_total_stats (rtl_dump_file));
3304 close_dump_file (NULL, NULL_RTX);
3307 /* Close non-debugging input and output files. Take special care to note
3308 whether fclose returns an error, since the pages might still be on the
3309 buffer chain while the file is open. */
3311 finish_parse ();
3313 if (! flag_syntax_only
3314 && (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0))
3315 fatal_io_error (asm_file_name);
3317 /* Do whatever is necessary to finish printing the graphs. */
3318 if (graph_dump_format != no_graph)
3320 if (jump_opt_dump)
3321 finish_graph_dump_file (dump_base_name, ".jump");
3322 if (addressof_dump)
3323 finish_graph_dump_file (dump_base_name, ".addressof");
3324 if (cse_dump)
3325 finish_graph_dump_file (dump_base_name, ".cse");
3326 if (loop_dump)
3327 finish_graph_dump_file (dump_base_name, ".loop");
3328 if (cse2_dump)
3329 finish_graph_dump_file (dump_base_name, ".cse2");
3330 if (branch_prob_dump)
3331 finish_graph_dump_file (dump_base_name, ".bp");
3332 if (flow_dump)
3333 finish_graph_dump_file (dump_base_name, ".flow");
3334 if (combine_dump)
3335 finish_graph_dump_file (dump_base_name, ".combine");
3336 if (regmove_dump)
3337 finish_graph_dump_file (dump_base_name, ".regmove");
3338 if (sched_dump)
3339 finish_graph_dump_file (dump_base_name, ".sched");
3340 if (local_reg_dump)
3341 finish_graph_dump_file (dump_base_name, ".lreg");
3342 if (global_reg_dump)
3343 finish_graph_dump_file (dump_base_name, ".greg");
3344 if (flow2_dump)
3345 finish_graph_dump_file (dump_base_name, ".flow2");
3346 if (sched2_dump)
3347 finish_graph_dump_file (dump_base_name, ".sched2");
3348 if (jump2_opt_dump)
3349 finish_graph_dump_file (dump_base_name, ".jump2");
3350 #ifdef DELAY_SLOTS
3351 if (dbr_sched_dump)
3352 finish_graph_dump_file (dump_base_name, ".dbr");
3353 #endif
3354 if (gcse_dump)
3355 finish_graph_dump_file (dump_base_name, ".gcse");
3356 #ifdef STACK_REGS
3357 if (stack_reg_dump)
3358 finish_graph_dump_file (dump_base_name, ".stack");
3359 #endif
3360 #ifdef MACHINE_DEPENDENT_REORG
3361 if (mach_dep_reorg_dump)
3362 finish_graph_dump_file (dump_base_name, ".mach");
3363 #endif
3366 /* Free up memory for the benefit of leak detectors. */
3367 free_reg_info ();
3369 /* Print the times. */
3371 if (! quiet_flag)
3373 all_time = get_run_time ();
3375 fprintf (stderr,"\n");
3377 print_time ("parse", parse_time);
3378 print_time ("integration", integration_time);
3379 print_time ("jump", jump_time);
3380 print_time ("cse", cse_time);
3381 print_time ("gcse", gcse_time);
3382 print_time ("loop", loop_time);
3383 print_time ("cse2", cse2_time);
3384 print_time ("branch-prob", branch_prob_time);
3385 print_time ("flow", flow_time);
3386 print_time ("combine", combine_time);
3387 print_time ("regmove", regmove_time);
3388 print_time ("sched", sched_time);
3389 print_time ("local-alloc", local_alloc_time);
3390 print_time ("global-alloc", global_alloc_time);
3391 print_time ("flow2", flow2_time);
3392 print_time ("sched2", sched2_time);
3393 #ifdef DELAY_SLOTS
3394 print_time ("dbranch", dbr_sched_time);
3395 #endif
3396 print_time ("shorten-branch", shorten_branch_time);
3397 print_time ("stack-reg", stack_reg_time);
3398 print_time ("final", final_time);
3399 print_time ("varconst", varconst_time);
3400 print_time ("symout", symout_time);
3401 print_time ("dump", dump_time);
3402 print_time ("gc", gc_time);
3406 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
3407 and TYPE_DECL nodes.
3409 This does nothing for local (non-static) variables, unless the
3410 variable is a register variable with an ASMSPEC. In that case, or
3411 if the variable is not an automatice, it sets up the RTL and
3412 outputs any assembler code (label definition, storage allocation
3413 and initialization).
3415 DECL is the declaration. If ASMSPEC is nonzero, it specifies
3416 the assembler symbol name to be used. TOP_LEVEL is nonzero
3417 if this declaration is not within a function. */
3419 void
3420 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
3421 tree decl;
3422 const char *asmspec;
3423 int top_level;
3424 int at_end;
3426 /* Declarations of variables, and of functions defined elsewhere. */
3428 /* The most obvious approach, to put an #ifndef around where
3429 this macro is used, doesn't work since it's inside a macro call. */
3430 #ifndef ASM_FINISH_DECLARE_OBJECT
3431 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
3432 #endif
3434 /* Forward declarations for nested functions are not "external",
3435 but we need to treat them as if they were. */
3436 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
3437 || TREE_CODE (decl) == FUNCTION_DECL)
3438 TIMEVAR (varconst_time,
3440 make_decl_rtl (decl, asmspec, top_level);
3441 /* Initialized extern variable exists to be replaced
3442 with its value, or represents something that will be
3443 output in another file. */
3444 if (! (TREE_CODE (decl) == VAR_DECL
3445 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
3446 && DECL_INITIAL (decl) != 0
3447 && DECL_INITIAL (decl) != error_mark_node))
3448 /* Don't output anything
3449 when a tentative file-scope definition is seen.
3450 But at end of compilation, do output code for them. */
3451 if (! (! at_end && top_level
3452 && (DECL_INITIAL (decl) == 0
3453 || DECL_INITIAL (decl) == error_mark_node)))
3454 assemble_variable (decl, top_level, at_end, 0);
3455 if (decl == last_assemble_variable_decl)
3457 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
3458 top_level, at_end);
3461 else if (DECL_REGISTER (decl) && asmspec != 0)
3463 if (decode_reg_name (asmspec) >= 0)
3465 DECL_RTL (decl) = 0;
3466 make_decl_rtl (decl, asmspec, top_level);
3468 else
3469 error ("invalid register name `%s' for register variable", asmspec);
3471 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3472 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3473 && TREE_CODE (decl) == TYPE_DECL)
3474 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
3475 #endif
3476 #ifdef SDB_DEBUGGING_INFO
3477 else if (write_symbols == SDB_DEBUG && top_level
3478 && TREE_CODE (decl) == TYPE_DECL)
3479 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
3480 #endif
3483 /* Called after finishing a record, union or enumeral type. */
3485 void
3486 rest_of_type_compilation (type, toplev)
3487 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
3488 tree type;
3489 int toplev;
3490 #else
3491 tree type ATTRIBUTE_UNUSED;
3492 int toplev ATTRIBUTE_UNUSED;
3493 #endif
3495 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3496 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3497 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
3498 #endif
3499 #ifdef SDB_DEBUGGING_INFO
3500 if (write_symbols == SDB_DEBUG)
3501 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
3502 #endif
3505 /* This is called from finish_function (within yyparse)
3506 after each top-level definition is parsed.
3507 It is supposed to compile that function or variable
3508 and output the assembler code for it.
3509 After we return, the tree storage is freed. */
3511 void
3512 rest_of_compilation (decl)
3513 tree decl;
3515 register rtx insns;
3516 int start_time = get_run_time ();
3517 int tem;
3518 /* Nonzero if we have saved the original DECL_INITIAL of the function,
3519 to be restored after we finish compiling the function
3520 (for use when compiling inline calls to this function). */
3521 tree saved_block_tree = 0;
3522 /* Likewise, for DECL_ARGUMENTS. */
3523 tree saved_arguments = 0;
3524 int failure = 0;
3525 int rebuild_label_notes_after_reload;
3527 /* If we are reconsidering an inline function
3528 at the end of compilation, skip the stuff for making it inline. */
3530 if (DECL_SAVED_INSNS (decl) == 0)
3532 int inlinable = 0;
3533 const char *lose;
3535 /* If requested, consider whether to make this function inline. */
3536 if (DECL_INLINE (decl) || flag_inline_functions)
3537 TIMEVAR (integration_time,
3539 lose = function_cannot_inline_p (decl);
3540 if (lose || ! optimize)
3542 if (warn_inline && DECL_INLINE (decl))
3543 warning_with_decl (decl, lose);
3544 DECL_ABSTRACT_ORIGIN (decl) = 0;
3545 /* Don't really compile an extern inline function.
3546 If we can't make it inline, pretend
3547 it was only declared. */
3548 if (DECL_EXTERNAL (decl))
3550 DECL_INITIAL (decl) = 0;
3551 goto exit_rest_of_compilation;
3554 else
3555 /* ??? Note that this has the effect of making it look
3556 like "inline" was specified for a function if we choose
3557 to inline it. This isn't quite right, but it's
3558 probably not worth the trouble to fix. */
3559 inlinable = DECL_INLINE (decl) = 1;
3562 insns = get_insns ();
3564 /* Dump the rtl code if we are dumping rtl. */
3566 if (rtl_dump)
3568 open_dump_file (".rtl", decl_printable_name (decl, 2));
3570 if (DECL_SAVED_INSNS (decl))
3571 fprintf (rtl_dump_file, ";; (integrable)\n\n");
3573 close_dump_file (print_rtl, insns);
3576 /* If function is inline, and we don't yet know whether to
3577 compile it by itself, defer decision till end of compilation.
3578 finish_compilation will call rest_of_compilation again
3579 for those functions that need to be output. Also defer those
3580 functions that we are supposed to defer. */
3582 if (inlinable)
3583 DECL_DEFER_OUTPUT (decl) = 1;
3585 if (DECL_DEFER_OUTPUT (decl)
3586 || (DECL_INLINE (decl)
3587 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3588 && ! flag_keep_inline_functions)
3589 || DECL_EXTERNAL (decl))))
3591 DECL_DEFER_OUTPUT (decl) = 1;
3593 /* If -Wreturn-type, we have to do a bit of compilation.
3594 However, if we just fall through we will call
3595 save_for_inline_copying() which results in excessive
3596 memory use. Instead, we just want to call
3597 jump_optimize() to figure out whether or not we can fall
3598 off the end of the function; we do the minimum amount of
3599 work necessary to make that safe. And, we set optimize
3600 to zero to keep jump_optimize from working too hard. */
3601 if (warn_return_type)
3603 int saved_optimize = optimize;
3604 optimize = 0;
3605 find_exception_handler_labels ();
3606 jump_optimize (get_insns(), !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3607 !JUMP_AFTER_REGSCAN);
3608 optimize = saved_optimize;
3611 #ifdef DWARF_DEBUGGING_INFO
3612 /* Generate the DWARF info for the "abstract" instance
3613 of a function which we may later generate inlined and/or
3614 out-of-line instances of. */
3615 if (write_symbols == DWARF_DEBUG)
3617 set_decl_abstract_flags (decl, 1);
3618 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3619 set_decl_abstract_flags (decl, 0);
3621 #endif
3622 #ifdef DWARF2_DEBUGGING_INFO
3623 /* Generate the DWARF2 info for the "abstract" instance
3624 of a function which we may later generate inlined and/or
3625 out-of-line instances of. */
3626 if (write_symbols == DWARF2_DEBUG)
3628 set_decl_abstract_flags (decl, 1);
3629 TIMEVAR (symout_time, dwarf2out_decl (decl));
3630 set_decl_abstract_flags (decl, 0);
3632 #endif
3633 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3634 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
3635 goto exit_rest_of_compilation;
3638 /* If specified extern inline but we aren't inlining it, we are
3639 done. This goes for anything that gets here with DECL_EXTERNAL
3640 set, not just things with DECL_INLINE. */
3641 if (DECL_EXTERNAL (decl))
3642 goto exit_rest_of_compilation;
3645 /* Initialize some variables used by the optimizers. */
3646 init_function_for_compilation ();
3648 if (! DECL_DEFER_OUTPUT (decl))
3649 TREE_ASM_WRITTEN (decl) = 1;
3651 /* Now that integrate will no longer see our rtl, we need not distinguish
3652 between the return value of this function and the return value of called
3653 functions. */
3654 rtx_equal_function_value_matters = 0;
3656 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3657 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3659 goto exit_rest_of_compilation;
3662 /* Emit code to get eh context, if needed. */
3663 emit_eh_context ();
3665 #ifdef FINALIZE_PIC
3666 /* If we are doing position-independent code generation, now
3667 is the time to output special prologues and epilogues.
3668 We do not want to do this earlier, because it just clutters
3669 up inline functions with meaningless insns. */
3670 if (flag_pic)
3671 FINALIZE_PIC;
3672 #endif
3674 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3675 Note that that may have been done above, in save_for_inline_copying.
3676 The call to resume_temporary_allocation near the end of this function
3677 goes back to the usual state of affairs. This must be done after
3678 we've built up any unwinders for exception handling, and done
3679 the FINALIZE_PIC work, if necessary. */
3681 rtl_in_current_obstack ();
3683 insns = get_insns ();
3685 /* Copy any shared structure that should not be shared. */
3687 unshare_all_rtl (insns);
3689 init_EXPR_INSN_LIST_cache ();
3691 #ifdef SETJMP_VIA_SAVE_AREA
3692 /* This must be performed before virutal register instantiation. */
3693 if (current_function_calls_alloca)
3694 optimize_save_area_alloca (insns);
3695 #endif
3697 /* Instantiate all virtual registers. */
3699 instantiate_virtual_regs (current_function_decl, get_insns ());
3701 /* See if we have allocated stack slots that are not directly addressable.
3702 If so, scan all the insns and create explicit address computation
3703 for all references to such slots. */
3704 /* fixup_stack_slots (); */
3706 /* Find all the EH handlers. */
3707 find_exception_handler_labels ();
3709 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3710 are initialized and to compute whether control can drop off the end
3711 of the function. */
3712 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3713 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3714 JUMP_AFTER_REGSCAN));
3716 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3717 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3718 goto exit_rest_of_compilation;
3720 /* Try to identify useless null pointer tests and delete them. */
3721 if (flag_delete_null_pointer_checks)
3722 TIMEVAR (jump_time, delete_null_pointer_checks (get_insns ()));
3724 /* Dump rtl code after jump, if we are doing that. */
3725 if (jump_opt_dump)
3726 dump_rtl (".jump", decl, print_rtl, insns);
3728 if (ggc_p)
3729 ggc_collect ();
3731 /* Perform common subexpression elimination.
3732 Nonzero value from `cse_main' means that jumps were simplified
3733 and some code may now be unreachable, so do
3734 jump optimization again. */
3736 if (optimize > 0)
3738 if (cse_dump)
3739 open_dump_file (".cse", decl_printable_name (decl, 2));
3741 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3743 if (flag_thread_jumps)
3744 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3746 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3747 0, rtl_dump_file));
3748 /* If we are not running the second CSE pass, then we are no longer
3749 expecting CSE to be run. */
3750 cse_not_expected = !flag_rerun_cse_after_loop;
3752 if (tem || optimize > 1)
3753 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3754 !JUMP_NOOP_MOVES,
3755 !JUMP_AFTER_REGSCAN));
3757 /* Run this after jump optmizations remove all the unreachable code
3758 so that unreachable code will not keep values live. */
3759 TIMEVAR (cse_time, delete_trivially_dead_insns (insns, max_reg_num ()));
3761 /* Try to identify useless null pointer tests and delete them. */
3762 if (flag_delete_null_pointer_checks)
3763 TIMEVAR (jump_time, delete_null_pointer_checks (get_insns ()));
3765 /* Dump rtl code after cse, if we are doing that. */
3767 if (cse_dump)
3769 close_dump_file (print_rtl, insns);
3770 if (graph_dump_format != no_graph)
3771 print_rtl_graph_with_bb (dump_base_name, ".cse", insns);
3775 purge_addressof (insns);
3776 reg_scan (insns, max_reg_num (), 1);
3778 if (addressof_dump)
3780 dump_rtl (".addressof", decl, print_rtl, insns);
3781 if (graph_dump_format != no_graph)
3782 print_rtl_graph_with_bb (dump_base_name, ".addressof", insns);
3785 if (ggc_p)
3786 ggc_collect ();
3788 /* Perform global cse. */
3790 if (optimize > 0 && flag_gcse)
3792 if (gcse_dump)
3793 open_dump_file (".gcse", decl_printable_name (decl, 2));
3795 TIMEVAR (gcse_time, tem = gcse_main (insns, rtl_dump_file));
3797 /* If gcse altered any jumps, rerun jump optimizations to clean
3798 things up. */
3799 if (tem)
3801 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3802 !JUMP_NOOP_MOVES,
3803 !JUMP_AFTER_REGSCAN));
3806 if (gcse_dump)
3808 close_dump_file (print_rtl, insns);
3809 if (graph_dump_format != no_graph)
3810 print_rtl_graph_with_bb (dump_base_name, ".gcse", insns);
3813 if (ggc_p)
3814 ggc_collect ();
3816 /* Move constant computations out of loops. */
3818 if (optimize > 0)
3820 if (loop_dump)
3821 open_dump_file (".loop", decl_printable_name (decl, 2));
3823 TIMEVAR
3824 (loop_time,
3826 if (flag_rerun_loop_opt)
3828 /* We only want to perform unrolling once. */
3830 loop_optimize (insns, rtl_dump_file, 0, 0);
3833 /* The first call to loop_optimize makes some instructions
3834 trivially dead. We delete those instructions now in the
3835 hope that doing so will make the heuristics in loop work
3836 better and possibly speed up compilation. */
3837 delete_trivially_dead_insns (insns, max_reg_num ());
3839 /* The regscan pass is currently necessary as the alias
3840 analysis code depends on this information. */
3841 reg_scan (insns, max_reg_num (), 1);
3843 loop_optimize (insns, rtl_dump_file, flag_unroll_loops, 1);
3846 /* Dump rtl code after loop opt, if we are doing that. */
3848 if (loop_dump)
3850 close_dump_file (print_rtl, insns);
3851 if (graph_dump_format != no_graph)
3852 print_rtl_graph_with_bb (dump_base_name, ".loop", insns);
3855 if (ggc_p)
3856 ggc_collect ();
3859 if (optimize > 0)
3861 if (cse2_dump)
3862 open_dump_file (".cse2", decl_printable_name (decl, 2));
3864 if (flag_rerun_cse_after_loop)
3866 /* Running another jump optimization pass before the second
3867 cse pass sometimes simplifies the RTL enough to allow
3868 the second CSE pass to do a better job. Jump_optimize can change
3869 max_reg_num so we must rerun reg_scan afterwards.
3870 ??? Rework to not call reg_scan so often. */
3871 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3872 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3873 !JUMP_NOOP_MOVES,
3874 JUMP_AFTER_REGSCAN));
3876 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3877 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3878 1, rtl_dump_file));
3879 if (tem)
3880 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3881 !JUMP_NOOP_MOVES,
3882 !JUMP_AFTER_REGSCAN));
3885 if (flag_thread_jumps)
3887 /* This pass of jump threading straightens out code
3888 that was kinked by loop optimization. */
3889 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3890 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3893 /* Dump rtl code after cse, if we are doing that. */
3895 if (cse2_dump)
3897 close_dump_file (print_rtl, insns);
3898 if (graph_dump_format != no_graph)
3899 print_rtl_graph_with_bb (dump_base_name, ".cse2", insns);
3902 if (ggc_p)
3903 ggc_collect ();
3906 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3908 if (branch_prob_dump)
3909 open_dump_file (".bp", decl_printable_name (decl, 2));
3911 TIMEVAR
3912 (branch_prob_time,
3914 branch_prob (insns, rtl_dump_file);
3917 if (branch_prob_dump)
3919 close_dump_file (print_rtl, insns);
3920 if (graph_dump_format != no_graph)
3921 print_rtl_graph_with_bb (dump_base_name, ".bp", insns);
3924 if (ggc_p)
3925 ggc_collect ();
3928 /* We are no longer anticipating cse in this function, at least. */
3930 cse_not_expected = 1;
3932 /* Now we choose between stupid (pcc-like) register allocation
3933 (if we got the -noreg switch and not -opt)
3934 and smart register allocation. */
3936 if (optimize > 0) /* Stupid allocation probably won't work */
3937 obey_regdecls = 0; /* if optimizations being done. */
3939 regclass_init ();
3941 /* Print function header into flow dump now
3942 because doing the flow analysis makes some of the dump. */
3944 if (flow_dump)
3945 open_dump_file (".flow", decl_printable_name (decl, 2));
3947 if (obey_regdecls)
3949 TIMEVAR (flow_time,
3951 regclass (insns, max_reg_num ());
3952 stupid_life_analysis (insns, max_reg_num (),
3953 rtl_dump_file);
3956 else
3958 /* Do control and data flow analysis,
3959 and write some of the results to dump file. */
3961 TIMEVAR
3962 (flow_time,
3964 find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
3965 life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
3968 if (warn_uninitialized)
3970 uninitialized_vars_warning (DECL_INITIAL (decl));
3971 setjmp_args_warning ();
3975 /* Dump rtl after flow analysis. */
3977 if (flow_dump)
3979 close_dump_file (print_rtl_with_bb, insns);
3980 if (graph_dump_format != no_graph)
3981 print_rtl_graph_with_bb (dump_base_name, ".flow", insns);
3984 if (ggc_p)
3985 ggc_collect ();
3987 /* The first life analysis pass has finished. From now on we can not
3988 generate any new pseudos. */
3989 no_new_pseudos = 1;
3991 /* If -opt, try combining insns through substitution. */
3993 if (optimize > 0)
3995 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
3997 /* Dump rtl code after insn combination. */
3999 if (combine_dump)
4001 dump_rtl (".combine", decl, print_rtl_with_bb, insns);
4002 if (graph_dump_format != no_graph)
4003 print_rtl_graph_with_bb (dump_base_name, ".combine", insns);
4006 if (ggc_p)
4007 ggc_collect ();
4010 /* Register allocation pre-pass, to reduce number of moves
4011 necessary for two-address machines. */
4012 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
4014 if (regmove_dump)
4015 open_dump_file (".regmove", decl_printable_name (decl, 2));
4017 TIMEVAR (regmove_time, regmove_optimize (insns, max_reg_num (),
4018 rtl_dump_file));
4020 if (regmove_dump)
4022 close_dump_file (print_rtl_with_bb, insns);
4023 if (graph_dump_format != no_graph)
4024 print_rtl_graph_with_bb (dump_base_name, ".regmove", insns);
4027 if (ggc_p)
4028 ggc_collect ();
4031 /* Print function header into sched dump now
4032 because doing the sched analysis makes some of the dump. */
4034 if (optimize > 0 && flag_schedule_insns)
4036 if (sched_dump)
4037 open_dump_file (".sched", decl_printable_name (decl, 2));
4039 /* Do control and data sched analysis,
4040 and write some of the results to dump file. */
4042 TIMEVAR (sched_time, schedule_insns (rtl_dump_file));
4044 /* Dump rtl after instruction scheduling. */
4046 if (sched_dump)
4048 close_dump_file (print_rtl_with_bb, insns);
4049 if (graph_dump_format != no_graph)
4050 print_rtl_graph_with_bb (dump_base_name, ".sched", insns);
4053 if (ggc_p)
4054 ggc_collect ();
4057 /* Determine if the current function is a leaf before running reload
4058 since this can impact optimizations done by the prologue and
4059 epilogue thus changing register elimination offsets. */
4060 current_function_is_leaf = leaf_function_p ();
4062 /* Unless we did stupid register allocation,
4063 allocate pseudo-regs that are used only within 1 basic block.
4065 RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
4066 jump optimizer after register allocation and reloading are finished. */
4068 if (!obey_regdecls)
4069 TIMEVAR (local_alloc_time,
4071 recompute_reg_usage (insns, ! optimize_size);
4072 regclass (insns, max_reg_num ());
4073 rebuild_label_notes_after_reload = local_alloc ();
4075 else
4076 rebuild_label_notes_after_reload = 0;
4078 /* Dump rtl code after allocating regs within basic blocks. */
4080 if (local_reg_dump)
4082 open_dump_file (".lreg", decl_printable_name (decl, 2));
4084 TIMEVAR (dump_time, dump_flow_info (rtl_dump_file));
4085 TIMEVAR (dump_time, dump_local_alloc (rtl_dump_file));
4087 close_dump_file (print_rtl_with_bb, insns);
4088 if (graph_dump_format != no_graph)
4089 print_rtl_graph_with_bb (dump_base_name, ".lreg", insns);
4092 if (ggc_p)
4093 ggc_collect ();
4095 if (global_reg_dump)
4096 open_dump_file (".greg", decl_printable_name (decl, 2));
4098 /* Unless we did stupid register allocation,
4099 allocate remaining pseudo-regs, then do the reload pass
4100 fixing up any insns that are invalid. */
4102 TIMEVAR (global_alloc_time,
4104 if (!obey_regdecls)
4105 failure = global_alloc (rtl_dump_file);
4106 else
4107 failure = reload (insns, 0, rtl_dump_file);
4111 if (failure)
4112 goto exit_rest_of_compilation;
4114 if (ggc_p)
4115 ggc_collect ();
4117 /* Do a very simple CSE pass over just the hard registers. */
4118 if (optimize > 0)
4119 reload_cse_regs (insns);
4121 /* Register allocation and reloading may have turned an indirect jump into
4122 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
4123 jumping instructions. */
4124 if (rebuild_label_notes_after_reload)
4125 TIMEVAR (jump_time, rebuild_jump_labels (insns));
4127 /* If optimizing and we are performing instruction scheduling after
4128 reload, then go ahead and split insns now since we are about to
4129 recompute flow information anyway.
4131 reload_cse_regs may expose more splitting opportunities, expecially
4132 for double-word operations. */
4133 if (optimize > 0 && flag_schedule_insns_after_reload)
4135 rtx insn;
4137 for (insn = insns; insn; insn = NEXT_INSN (insn))
4139 rtx last;
4141 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
4142 continue;
4144 last = try_split (PATTERN (insn), insn, 1);
4146 if (last != insn)
4148 PUT_CODE (insn, NOTE);
4149 NOTE_SOURCE_FILE (insn) = 0;
4150 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
4155 if (global_reg_dump)
4157 TIMEVAR (dump_time, dump_global_regs (rtl_dump_file));
4158 close_dump_file (print_rtl_with_bb, insns);
4159 if (graph_dump_format != no_graph)
4160 print_rtl_graph_with_bb (dump_base_name, ".greg", insns);
4163 /* Re-create the death notes which were deleted during reload. */
4164 if (flow2_dump)
4165 open_dump_file (".flow2", decl_printable_name (decl, 2));
4167 if (optimize)
4169 TIMEVAR
4170 (flow2_time,
4172 find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
4173 life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
4176 if (ggc_p)
4177 ggc_collect ();
4180 flow2_completed = 1;
4182 /* On some machines, the prologue and epilogue code, or parts thereof,
4183 can be represented as RTL. Doing so lets us schedule insns between
4184 it and the rest of the code and also allows delayed branch
4185 scheduling to operate in the epilogue. */
4187 thread_prologue_and_epilogue_insns (insns);
4189 if (flow2_dump)
4191 close_dump_file (print_rtl_with_bb, insns);
4192 if (graph_dump_format != no_graph)
4193 print_rtl_graph_with_bb (dump_base_name, ".flow2", insns);
4196 #ifdef HAVE_peephole2
4197 if (optimize > 0 && flag_peephole2)
4199 if (peephole2_dump)
4200 open_dump_file (".peephole2", decl_printable_name (decl, 2));
4202 peephole2_optimize (rtl_dump_file);
4204 if (peephole2_dump)
4206 close_dump_file (print_rtl_with_bb, insns);
4207 if (graph_dump_format != no_graph)
4208 print_rtl_graph_with_bb (dump_base_name, ".peephole2", insns);
4211 #endif
4213 if (optimize > 0 && flag_schedule_insns_after_reload)
4215 if (sched2_dump)
4216 open_dump_file (".sched2", decl_printable_name (decl, 2));
4218 /* Do control and data sched analysis again,
4219 and write some more of the results to dump file. */
4221 TIMEVAR (sched2_time, schedule_insns (rtl_dump_file));
4223 /* Dump rtl after post-reorder instruction scheduling. */
4225 if (sched2_dump)
4227 close_dump_file (print_rtl_with_bb, insns);
4228 if (graph_dump_format != no_graph)
4229 print_rtl_graph_with_bb (dump_base_name, ".sched2", insns);
4232 if (ggc_p)
4233 ggc_collect ();
4236 #ifdef LEAF_REGISTERS
4237 current_function_uses_only_leaf_regs
4238 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
4239 #endif
4241 /* One more attempt to remove jumps to .+1
4242 left by dead-store-elimination.
4243 Also do cross-jumping this time
4244 and delete no-op move insns. */
4246 if (optimize > 0)
4248 TIMEVAR (jump_time, jump_optimize (insns, JUMP_CROSS_JUMP,
4249 JUMP_NOOP_MOVES,
4250 !JUMP_AFTER_REGSCAN));
4252 /* Dump rtl code after jump, if we are doing that. */
4254 if (jump2_opt_dump)
4256 dump_rtl (".jump2", decl, print_rtl_with_bb, insns);
4257 if (graph_dump_format != no_graph)
4258 print_rtl_graph_with_bb (dump_base_name, ".jump2", insns);
4262 /* If a machine dependent reorganization is needed, call it. */
4263 #ifdef MACHINE_DEPENDENT_REORG
4264 if (mach_dep_reorg_dump)
4265 open_dump_file (".mach", decl_printable_name (decl, 2));
4267 MACHINE_DEPENDENT_REORG (insns);
4269 if (mach_dep_reorg_dump)
4271 close_dump_file (print_rtl_with_bb, insns);
4272 if (graph_dump_format != no_graph)
4273 print_rtl_graph_with_bb (dump_base_name, ".mach", insns);
4276 if (ggc_p)
4277 ggc_collect ();
4278 #endif
4280 /* If a scheduling pass for delayed branches is to be done,
4281 call the scheduling code. */
4283 #ifdef DELAY_SLOTS
4284 if (optimize > 0 && flag_delayed_branch)
4286 if (dbr_sched_dump)
4287 open_dump_file (".dbr", decl_printable_name (decl, 2));
4289 TIMEVAR (dbr_sched_time, dbr_schedule (insns, rtl_dump_file));
4291 if (dbr_sched_dump)
4293 close_dump_file (print_rtl_with_bb, insns);
4294 if (graph_dump_format != no_graph)
4295 print_rtl_graph_with_bb (dump_base_name, ".dbr", insns);
4299 if (ggc_p)
4300 ggc_collect ();
4301 #endif
4303 /* Shorten branches. */
4304 TIMEVAR (shorten_branch_time,
4306 shorten_branches (get_insns ());
4309 #ifdef STACK_REGS
4310 if (stack_reg_dump)
4311 open_dump_file (".stack", decl_printable_name (decl, 2));
4313 TIMEVAR (stack_reg_time, reg_to_stack (insns, rtl_dump_file));
4315 if (stack_reg_dump)
4317 dump_rtl (".stack", decl, print_rtl_with_bb, insns);
4318 if (graph_dump_format != no_graph)
4319 print_rtl_graph_with_bb (dump_base_name, ".stack", insns);
4322 if (ggc_p)
4323 ggc_collect ();
4324 #endif
4326 /* Now turn the rtl into assembler code. */
4328 TIMEVAR (final_time,
4330 rtx x;
4331 char *fnname;
4333 /* Get the function's name, as described by its RTL.
4334 This may be different from the DECL_NAME name used
4335 in the source file. */
4337 x = DECL_RTL (decl);
4338 if (GET_CODE (x) != MEM)
4339 abort ();
4340 x = XEXP (x, 0);
4341 if (GET_CODE (x) != SYMBOL_REF)
4342 abort ();
4343 fnname = XSTR (x, 0);
4345 assemble_start_function (decl, fnname);
4346 final_start_function (insns, asm_out_file, optimize);
4347 final (insns, asm_out_file, optimize, 0);
4348 final_end_function (insns, asm_out_file, optimize);
4349 assemble_end_function (decl, fnname);
4350 if (! quiet_flag)
4351 fflush (asm_out_file);
4353 /* Release all memory allocated by flow. */
4354 free_basic_block_vars (0);
4356 /* Release all memory held by regsets now */
4357 regset_release_memory ();
4360 if (ggc_p)
4361 ggc_collect ();
4363 /* Write DBX symbols if requested */
4365 /* Note that for those inline functions where we don't initially
4366 know for certain that we will be generating an out-of-line copy,
4367 the first invocation of this routine (rest_of_compilation) will
4368 skip over this code by doing a `goto exit_rest_of_compilation;'.
4369 Later on, finish_compilation will call rest_of_compilation again
4370 for those inline functions that need to have out-of-line copies
4371 generated. During that call, we *will* be routed past here. */
4373 #ifdef DBX_DEBUGGING_INFO
4374 if (write_symbols == DBX_DEBUG)
4375 TIMEVAR (symout_time, dbxout_function (decl));
4376 #endif
4378 #ifdef DWARF_DEBUGGING_INFO
4379 if (write_symbols == DWARF_DEBUG)
4380 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
4381 #endif
4383 #ifdef DWARF2_DEBUGGING_INFO
4384 if (write_symbols == DWARF2_DEBUG)
4385 TIMEVAR (symout_time, dwarf2out_decl (decl));
4386 #endif
4388 exit_rest_of_compilation:
4390 free_bb_mem ();
4392 /* In case the function was not output,
4393 don't leave any temporary anonymous types
4394 queued up for sdb output. */
4395 #ifdef SDB_DEBUGGING_INFO
4396 if (write_symbols == SDB_DEBUG)
4397 sdbout_types (NULL_TREE);
4398 #endif
4400 /* Put back the tree of subblocks and list of arguments
4401 from before we copied them.
4402 Code generation and the output of debugging info may have modified
4403 the copy, but the original is unchanged. */
4405 if (saved_block_tree != 0)
4407 DECL_INITIAL (decl) = saved_block_tree;
4408 DECL_ARGUMENTS (decl) = saved_arguments;
4409 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
4412 reload_completed = 0;
4413 flow2_completed = 0;
4414 no_new_pseudos = 0;
4416 TIMEVAR (final_time,
4418 /* Clear out the insn_length contents now that they are no
4419 longer valid. */
4420 init_insn_lengths ();
4422 /* Clear out the real_constant_chain before some of the rtx's
4423 it runs through become garbage. */
4424 clear_const_double_mem ();
4426 /* Cancel the effect of rtl_in_current_obstack. */
4427 resume_temporary_allocation ();
4429 /* Show no temporary slots allocated. */
4430 init_temp_slots ();
4432 free_basic_block_vars (0);
4435 /* Make sure volatile mem refs aren't considered valid operands for
4436 arithmetic insns. We must call this here if this is a nested inline
4437 function, since the above code leaves us in the init_recog state
4438 (from final.c), and the function context push/pop code does not
4439 save/restore volatile_ok.
4441 ??? Maybe it isn't necessary for expand_start_function to call this
4442 anymore if we do it here? */
4444 init_recog_no_volatile ();
4446 /* We're done with this function. Free up memory if we can. */
4447 free_after_parsing (current_function);
4448 if (! DECL_DEFER_OUTPUT (decl))
4449 free_after_compilation (current_function);
4450 current_function = 0;
4452 if (ggc_p)
4453 ggc_collect ();
4455 /* The parsing time is all the time spent in yyparse
4456 *except* what is spent in this function. */
4458 parse_time -= get_run_time () - start_time;
4461 static void
4462 display_help ()
4464 int undoc;
4465 unsigned long i;
4466 const char * lang;
4468 #ifndef USE_CPPLIB
4469 printf ("Usage: %s input [switches]\n", progname);
4470 printf ("Switches:\n");
4471 #endif
4472 printf (" -ffixed-<register> Mark <register> as being unavailable to the compiler\n");
4473 printf (" -fcall-used-<register> Mark <register> as being corrupted by function calls\n");
4474 printf (" -fcall-saved-<register> Mark <register> as being preserved across functions\n");
4475 printf (" -finline-limit=<number> Limits the size of inlined functions to <number>\n");
4477 for (i = NUM_ELEM (f_options); i--;)
4479 const char * description = f_options[i].description;
4481 if (description != NULL && * description != 0)
4482 printf (" -f%-21s %s\n",
4483 f_options[i].string, description);
4486 printf (" -O[number] Set optimisation level to [number]\n");
4487 printf (" -Os Optimise for space rather than speed\n");
4488 printf (" -pedantic Issue warnings needed by strict compliance to ANSI C\n");
4489 printf (" -pedantic-errors Like -pedantic except that errors are produced\n");
4490 printf (" -w Suppress warnings\n");
4491 printf (" -W Enable extra warnings\n");
4493 for (i = NUM_ELEM (W_options); i--;)
4495 const char * description = W_options[i].description;
4497 if (description != NULL && * description != 0)
4498 printf (" -W%-21s %s\n",
4499 W_options[i].string, description);
4502 printf (" -Wid-clash-<num> Warn if 2 identifiers have the same first <num> chars\n");
4503 printf (" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n");
4504 printf (" -p Enable function profiling\n");
4505 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER)
4506 printf (" -a Enable block profiling \n");
4507 #endif
4508 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER) || defined FUNCTION_BLOCK_PROFILER_EXIT
4509 printf (" -ax Enable jump profiling \n");
4510 #endif
4511 printf (" -o <file> Place output into <file> \n");
4512 printf (" -G <number> Put global and static data smaller than <number>\n");
4513 printf (" bytes into a special section (on some targets)\n");
4515 for (i = NUM_ELEM (debug_args); i--;)
4517 if (debug_args[i].description != NULL)
4518 printf (" -g%-21s %s\n", debug_args[i].arg, debug_args[i].description);
4521 printf (" -aux-info <file> Emit declaration info into <file>.X\n");
4522 printf (" -quiet Do not display functions compiled or elapsed time\n");
4523 printf (" -version Display the compiler's version\n");
4524 printf (" -d[letters] Enable dumps from specific passes of the compiler\n");
4525 printf (" -dumpbase <file> Base name to be used for dumps from specific passes\n");
4526 #if defined INSN_SCHEDULING
4527 printf (" -sched-verbose=<number> Set the verbosity level of the scheduler\n");
4528 #endif
4529 printf (" --help Display this information\n");
4531 undoc = 0;
4532 lang = "language";
4534 /* Display descriptions of language specific options.
4535 If there is no description, note that there is an undocumented option.
4536 If the description is empty, do not display anything. (This allows
4537 options to be deliberately undocumented, for whatever reason).
4538 If the option string is missing, then this is a marker, indicating
4539 that the description string is in fact the name of a language, whose
4540 language specific options are to follow. */
4542 if (NUM_ELEM (documented_lang_options) > 1)
4544 printf ("\nLanguage specific options:\n");
4546 for (i = 0; i < NUM_ELEM (documented_lang_options); i++)
4548 const char * description = documented_lang_options[i].description;
4549 const char * option = documented_lang_options[i].option;
4551 if (description == NULL)
4553 undoc = 1;
4555 if (extra_warnings)
4556 printf (" %-23.23s [undocumented]\n", option);
4558 else if (* description == 0)
4559 continue;
4560 else if (option == NULL)
4562 if (undoc)
4563 printf
4564 ("\nThere are undocumented %s specific options as well.\n",
4565 lang);
4566 undoc = 0;
4568 printf ("\n Options for %s:\n", description);
4570 lang = description;
4572 else
4573 printf (" %-23.23s %s\n", option, description);
4577 if (undoc)
4578 printf ("\nThere are undocumented %s specific options as well.\n", lang);
4580 if (NUM_ELEM (target_switches) > 1
4581 #ifdef TARGET_OPTIONS
4582 || NUM_ELEM (target_options) > 1
4583 #endif
4586 int doc = 0;
4588 undoc = 0;
4590 printf ("\nTarget specific options:\n");
4592 for (i = NUM_ELEM (target_switches); i--;)
4594 const char * option = target_switches[i].name;
4595 const char * description = target_switches[i].description;
4597 if (option == NULL || * option == 0)
4598 continue;
4599 else if (description == NULL)
4601 undoc = 1;
4603 if (extra_warnings)
4604 printf (" -m%-21.21s [undocumented]\n", option);
4606 else if (* description != 0)
4607 doc += printf (" -m%-21.21s %s\n", option, description);
4610 #ifdef TARGET_OPTIONS
4611 for (i = NUM_ELEM (target_options); i--;)
4613 const char * option = target_options[i].prefix;
4614 const char * description = target_options[i].description;
4616 if (option == NULL || * option == 0)
4617 continue;
4618 else if (description == NULL)
4620 undoc = 1;
4622 if (extra_warnings)
4623 printf (" -m%-21.21s [undocumented]\n", option);
4625 else if (* description != 0)
4626 doc += printf (" -m%-21.21s %s\n", option, description);
4628 #endif
4629 if (undoc)
4631 if (doc)
4632 printf ("\nThere are undocumented target specific options as well.\n");
4633 else
4634 printf (" They exist, but they are not documented.\n");
4639 /* Parse a -d... comand line switch. */
4641 static void
4642 decode_d_option (arg)
4643 const char * arg;
4645 while (* arg)
4646 switch (* arg ++)
4648 case 'a':
4649 branch_prob_dump = 1;
4650 combine_dump = 1;
4651 #ifdef DELAY_SLOTS
4652 dbr_sched_dump = 1;
4653 #endif
4654 flow_dump = 1;
4655 flow2_dump = 1;
4656 global_reg_dump = 1;
4657 jump_opt_dump = 1;
4658 addressof_dump = 1;
4659 jump2_opt_dump = 1;
4660 local_reg_dump = 1;
4661 loop_dump = 1;
4662 regmove_dump = 1;
4663 rtl_dump = 1;
4664 cse_dump = 1;
4665 cse2_dump = 1;
4666 gcse_dump = 1;
4667 sched_dump = 1;
4668 sched2_dump = 1;
4669 #ifdef STACK_REGS
4670 stack_reg_dump = 1;
4671 #endif
4672 #ifdef MACHINE_DEPENDENT_REORG
4673 mach_dep_reorg_dump = 1;
4674 #endif
4675 peephole2_dump = 1;
4676 break;
4677 case 'A':
4678 flag_debug_asm = 1;
4679 break;
4680 case 'b':
4681 branch_prob_dump = 1;
4682 break;
4683 case 'c':
4684 combine_dump = 1;
4685 break;
4686 #ifdef DELAY_SLOTS
4687 case 'd':
4688 dbr_sched_dump = 1;
4689 break;
4690 #endif
4691 case 'f':
4692 flow_dump = 1;
4693 break;
4694 case 'F':
4695 addressof_dump = 1;
4696 break;
4697 case 'g':
4698 global_reg_dump = 1;
4699 break;
4700 case 'G':
4701 gcse_dump = 1;
4702 break;
4703 case 'j':
4704 jump_opt_dump = 1;
4705 break;
4706 case 'J':
4707 jump2_opt_dump = 1;
4708 break;
4709 #ifdef STACK_REGS
4710 case 'k':
4711 stack_reg_dump = 1;
4712 break;
4713 #endif
4714 case 'l':
4715 local_reg_dump = 1;
4716 break;
4717 case 'L':
4718 loop_dump = 1;
4719 break;
4720 case 'm':
4721 flag_print_mem = 1;
4722 break;
4723 #ifdef MACHINE_DEPENDENT_REORG
4724 case 'M':
4725 mach_dep_reorg_dump = 1;
4726 break;
4727 #endif
4728 case 'p':
4729 flag_print_asm_name = 1;
4730 break;
4731 case 'r':
4732 rtl_dump = 1;
4733 break;
4734 case 'R':
4735 sched2_dump = 1;
4736 break;
4737 case 's':
4738 cse_dump = 1;
4739 break;
4740 case 'S':
4741 sched_dump = 1;
4742 break;
4743 case 't':
4744 cse2_dump = 1;
4745 break;
4746 case 'N':
4747 regmove_dump = 1;
4748 break;
4749 case 'v':
4750 graph_dump_format = vcg;
4751 break;
4752 case 'w':
4753 flow2_dump = 1;
4754 break;
4755 case 'x':
4756 rtl_dump_and_exit = 1;
4757 break;
4758 case 'y':
4759 set_yydebug (1);
4760 break;
4761 case 'z':
4762 peephole2_dump = 1;
4763 break;
4764 case 'D': /* These are handled by the preprocessor. */
4765 case 'I':
4766 break;
4767 default:
4768 warning ("unrecognised gcc debugging option: %c", arg[-1]);
4769 break;
4773 /* Parse a -f... comand line switch. ARG is the value after the -f.
4774 It is safe to access 'ARG - 2' to generate the full switch name.
4775 Return the number of strings consumed. */
4777 static int
4778 decode_f_option (arg)
4779 const char * arg;
4781 int j;
4783 /* Search for the option in the table of binary f options. */
4784 for (j = sizeof (f_options) / sizeof (f_options[0]); j--;)
4786 if (!strcmp (arg, f_options[j].string))
4788 *f_options[j].variable = f_options[j].on_value;
4789 return 1;
4792 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4793 && ! strcmp (arg + 3, f_options[j].string))
4795 *f_options[j].variable = ! f_options[j].on_value;
4796 return 1;
4800 if (!strncmp (arg, "inline-limit-", 13)
4801 || !strncmp (arg, "inline-limit=", 13))
4802 inline_max_insns =
4803 read_integral_parameter (arg + 13, arg - 2, inline_max_insns);
4804 #ifdef INSN_SCHEDULING
4805 else if (!strncmp (arg, "sched-verbose=", 14))
4806 fix_sched_param ("verbose", (char *)(arg + 14));
4807 #endif
4808 else if (!strncmp (arg, "fixed-", 6))
4809 fix_register ((char *)(arg + 6), 1, 1);
4810 else if (!strncmp (arg, "call-used-", 10))
4811 fix_register ((char *)(arg + 10), 0, 1);
4812 else if (!strncmp (arg, "call-saved-", 11))
4813 fix_register ((char *)(arg + 11), 0, 0);
4814 else if (!strncmp (arg, "align-loops=", 12))
4815 align_loops = read_integral_parameter (arg + 12, arg - 2, align_loops);
4816 else if (!strncmp (arg, "align-functions=", 16))
4817 align_functions =
4818 read_integral_parameter (arg + 16, arg - 2, align_functions);
4819 else if (!strncmp (arg, "align-jumps=", 12))
4820 align_jumps = read_integral_parameter (arg + 12, arg - 2, align_jumps);
4821 else if (!strncmp (arg, "align-labels=", 13))
4822 align_labels = read_integral_parameter (arg + 13, arg - 2, align_labels);
4823 else if (!strcmp (arg, "preprocessed"))
4824 /* Recognise this switch but do nothing. This prevents warnings
4825 about an unrecognised switch if cpplib has not been linked in. */
4827 else
4828 return 0;
4830 return 1;
4833 /* Parse a -W... comand line switch. ARG is the value after the -W.
4834 It is safe to access 'ARG - 2' to generate the full switch name.
4835 Return the number of strings consumed. */
4836 static int
4837 decode_W_option (arg)
4838 const char * arg;
4840 int j;
4842 /* Search for the option in the table of binary W options. */
4844 for (j = sizeof (W_options) / sizeof (W_options[0]); j--;)
4846 if (!strcmp (arg, W_options[j].string))
4848 *W_options[j].variable = W_options[j].on_value;
4849 return 1;
4852 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-'
4853 && ! strcmp (arg + 3, W_options[j].string))
4855 *W_options[j].variable = ! W_options[j].on_value;
4856 return 1;
4860 if (!strncmp (arg, "id-clash-", 9))
4862 const int id_clash_val = read_integral_parameter (arg + 9, arg - 2, -1);
4864 if (id_clash_val != -1)
4866 id_clash_len = id_clash_val;
4867 warn_id_clash = 1;
4870 else if (!strncmp (arg, "larger-than-", 12))
4872 const int larger_than_val =
4873 read_integral_parameter (arg + 12, arg - 2, -1);
4874 if (larger_than_val != -1)
4876 larger_than_size = larger_than_val;
4877 warn_larger_than = 1;
4880 else
4881 return 0;
4883 return 1;
4886 /* Parse a -g... comand line switch. ARG is the value after the -g.
4887 It is safe to access 'ARG - 2' to generate the full switch name.
4888 Return the number of strings consumed. */
4889 static int
4890 decode_g_option (arg)
4891 const char * arg;
4893 unsigned level;
4894 /* A lot of code assumes write_symbols == NO_DEBUG if the
4895 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4896 of what debugging type has been selected). This records the
4897 selected type. It is an error to specify more than one
4898 debugging type. */
4899 static enum debug_info_type selected_debug_type = NO_DEBUG;
4900 /* Non-zero if debugging format has been explicitly set.
4901 -g and -ggdb don't explicitly set the debugging format so
4902 -gdwarf -g3 is equivalent to -gdwarf3. */
4903 static int type_explicitly_set_p = 0;
4904 /* Indexed by enum debug_info_type. */
4905 static const char * debug_type_names[] =
4907 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
4910 /* The maximum admissible debug level value. */
4911 static const unsigned max_debug_level = 3;
4913 /* Look up ARG in the table. */
4914 for (da = debug_args; da->arg; da++)
4916 const int da_len = strlen (da->arg);
4918 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
4920 enum debug_info_type type = da->debug_type;
4921 const char * p = arg + da_len;
4923 if (*p && (*p < '0' || *p > '9'))
4924 continue;
4926 /* A debug flag without a level defaults to level 2.
4927 Note we do not want to call read_integral_parameter
4928 for that case since it will call atoi which
4929 will return zero.
4931 ??? We may want to generalize the interface to
4932 read_integral_parameter to better handle this case
4933 if this case shows up often. */
4934 if (*p)
4935 level = read_integral_parameter (p, 0, max_debug_level + 1);
4936 else
4937 level = 2;
4939 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
4941 error ("use -gdwarf -g%d for DWARF v1, level %d",
4942 level, level);
4943 if (level == 2)
4944 error ("use -gdwarf-2 for DWARF v2");
4947 if (level > max_debug_level)
4949 warning ("\
4950 ignoring option `%s' due to invalid debug level specification",
4951 arg - 2);
4952 level = debug_info_level;
4955 if (type == NO_DEBUG)
4957 type = PREFERRED_DEBUGGING_TYPE;
4959 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
4961 #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
4962 type = DWARF2_DEBUG;
4963 #else
4964 #ifdef DBX_DEBUGGING_INFO
4965 type = DBX_DEBUG;
4966 #endif
4967 #endif
4971 if (type == NO_DEBUG)
4972 warning ("`%s' not supported by this configuration of GCC",
4973 arg - 2);
4975 /* Does it conflict with an already selected type? */
4976 if (type_explicitly_set_p
4977 /* -g/-ggdb don't conflict with anything */
4978 && da->debug_type != NO_DEBUG
4979 && type != selected_debug_type)
4980 warning ("`%s' ignored, conflicts with `-g%s'",
4981 arg - 2, debug_type_names[(int) selected_debug_type]);
4982 else
4984 /* If the format has already been set, -g/-ggdb
4985 only change the debug level. */
4986 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
4987 ; /* don't change debugging type */
4988 else
4990 selected_debug_type = type;
4991 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4994 write_symbols = (level == 0
4995 ? NO_DEBUG
4996 : selected_debug_type);
4997 use_gnu_debug_info_extensions = da->use_extensions_p;
4998 debug_info_level = (enum debug_info_level) level;
5001 break;
5005 if (! da->arg)
5006 warning ("`%s' not supported by this configuration of GCC", arg - 2);
5008 return 1;
5011 /* Decode the first argument in the argv as a language-independent option.
5012 Return the number of strings consumed. 'strings_processed' is the
5013 number of strings that have already been decoded in a language
5014 specific fashion before this function was invoked. */
5016 static unsigned
5017 independent_decode_option (argc, argv, strings_processed)
5018 int argc;
5019 char ** argv;
5020 unsigned strings_processed ATTRIBUTE_UNUSED;
5022 char * arg = argv[0];
5024 if (arg[0] != '-' || arg[1] == 0)
5026 if (arg[0] == '+')
5027 return 0;
5029 filename = arg;
5031 return 1;
5034 arg ++;
5036 if (!strcmp (arg, "-help"))
5038 display_help ();
5039 exit (0);
5042 if (* arg == 'Y')
5043 arg ++;
5045 switch (* arg)
5047 default:
5048 return 0;
5050 case 'O':
5051 /* Already been treated in main (). Do nothing. */
5052 break;
5054 case 'm':
5055 set_target_switch (arg + 1);
5056 break;
5058 case 'f':
5059 return decode_f_option (arg + 1);
5061 case 'g':
5062 return decode_g_option (arg + 1);
5064 case 'd':
5065 if (!strcmp (arg, "dumpbase"))
5067 if (argc == 1)
5068 return 0;
5070 dump_base_name = argv[1];
5071 return 2;
5073 else
5074 decode_d_option (arg + 1);
5075 break;
5077 case 'p':
5078 if (!strcmp (arg, "pedantic"))
5079 pedantic = 1;
5080 else if (!strcmp (arg, "pedantic-errors"))
5081 flag_pedantic_errors = pedantic = 1;
5082 else if (arg[1] == 0)
5083 profile_flag = 1;
5084 else
5085 return 0;
5086 break;
5088 case 'q':
5089 if (!strcmp (arg, "quiet"))
5090 quiet_flag = 1;
5091 else
5092 return 0;
5093 break;
5095 case 'v':
5096 if (!strcmp (arg, "version"))
5097 version_flag = 1;
5098 else
5099 return 0;
5100 break;
5102 case 'w':
5103 if (arg[1] == 0)
5104 inhibit_warnings = 1;
5105 else
5106 return 0;
5107 break;
5109 case 'W':
5110 if (arg[1] == 0)
5112 extra_warnings = 1;
5113 /* We save the value of warn_uninitialized, since if they put
5114 -Wuninitialized on the command line, we need to generate a
5115 warning about not using it without also specifying -O. */
5116 if (warn_uninitialized != 1)
5117 warn_uninitialized = 2;
5119 else
5120 return decode_W_option (arg + 1);
5121 break;
5123 case 'a':
5124 if (arg[1] == 0)
5126 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5127 warning ("`-a' option (basic block profile) not supported");
5128 #else
5129 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
5130 #endif
5132 else if (!strcmp (arg, "ax"))
5134 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5135 warning ("`-ax' option (jump profiling) not supported");
5136 #else
5137 profile_block_flag = (!profile_block_flag
5138 || profile_block_flag == 2) ? 2 : 3;
5139 #endif
5141 else if (!strncmp (arg, "aux-info", 8))
5143 flag_gen_aux_info = 1;
5144 if (arg[8] == '\0')
5146 if (argc == 1)
5147 return 0;
5149 aux_info_file_name = argv[1];
5150 return 2;
5152 else
5153 aux_info_file_name = arg + 8;
5155 else
5156 return 0;
5157 break;
5159 case 'o':
5160 if (arg[1] == 0)
5162 if (argc == 1)
5163 return 0;
5165 asm_file_name = argv[1];
5166 return 2;
5168 return 0;
5170 case 'G':
5172 int g_switch_val;
5173 int return_val;
5175 if (arg[1] == 0)
5177 if (argc == 1)
5178 return 0;
5180 g_switch_val = read_integral_parameter (argv[1], 0, -1);
5181 return_val = 2;
5183 else
5185 g_switch_val = read_integral_parameter (arg + 1, 0, -1);
5186 return_val = 1;
5189 if (g_switch_val == -1)
5190 return_val = 0;
5191 else
5193 g_switch_set = TRUE;
5194 g_switch_value = g_switch_val;
5197 return return_val;
5201 return 1;
5204 /* Entry point of cc1/c++. Decode command args, then call compile_file.
5205 Exit code is 35 if can't open files, 34 if fatal error,
5206 33 if had nonfatal errors, else success. */
5208 extern int main PROTO ((int, char **));
5211 main (argc, argv)
5212 int argc;
5213 char **argv;
5215 register int i;
5216 char *p;
5218 /* save in case md file wants to emit args as a comment. */
5219 save_argc = argc;
5220 save_argv = argv;
5222 p = argv[0] + strlen (argv[0]);
5223 while (p != argv[0] && p[-1] != '/'
5224 #ifdef DIR_SEPARATOR
5225 && p[-1] != DIR_SEPARATOR
5226 #endif
5228 --p;
5229 progname = p;
5231 #if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
5232 /* Get rid of any avoidable limit on stack size. */
5234 struct rlimit rlim;
5236 /* Set the stack limit huge so that alloca does not fail. */
5237 getrlimit (RLIMIT_STACK, &rlim);
5238 rlim.rlim_cur = rlim.rlim_max;
5239 setrlimit (RLIMIT_STACK, &rlim);
5241 #endif
5243 #ifdef HAVE_LC_MESSAGES
5244 setlocale (LC_MESSAGES, "");
5245 #endif
5246 (void) bindtextdomain (PACKAGE, localedir);
5247 (void) textdomain (PACKAGE);
5249 signal (SIGFPE, float_signal);
5251 #ifdef SIGPIPE
5252 signal (SIGPIPE, pipe_closed);
5253 #endif
5255 decl_printable_name = decl_name;
5256 lang_expand_expr = (lang_expand_expr_t) do_abort;
5258 /* Initialize whether `char' is signed. */
5259 flag_signed_char = DEFAULT_SIGNED_CHAR;
5260 #ifdef DEFAULT_SHORT_ENUMS
5261 /* Initialize how much space enums occupy, by default. */
5262 flag_short_enums = DEFAULT_SHORT_ENUMS;
5263 #endif
5265 /* Initialize the garbage-collector. */
5266 init_ggc ();
5267 ggc_add_root (&input_file_stack, 1, sizeof input_file_stack,
5268 &mark_file_stack);
5270 /* Perform language-specific options intialization. */
5271 lang_init_options ();
5273 /* Scan to see what optimization level has been specified. That will
5274 determine the default value of many flags. */
5275 for (i = 1; i < argc; i++)
5277 if (!strcmp (argv[i], "-O"))
5279 optimize = 1;
5280 optimize_size = 0;
5282 else if (argv[i][0] == '-' && argv[i][1] == 'O')
5284 /* Handle -Os, -O2, -O3, -O69, ... */
5285 char *p = &argv[i][2];
5287 if ((p[0] == 's') && (p[1] == 0))
5289 optimize_size = 1;
5291 /* Optimizing for size forces optimize to be 2. */
5292 optimize = 2;
5294 else
5296 const int optimize_val = read_integral_parameter (p, p - 2, -1);
5297 if (optimize_val != -1)
5299 optimize = optimize_val;
5300 optimize_size = 0;
5306 obey_regdecls = (optimize == 0);
5308 if (optimize >= 1)
5310 flag_defer_pop = 1;
5311 flag_thread_jumps = 1;
5312 #ifdef DELAY_SLOTS
5313 flag_delayed_branch = 1;
5314 #endif
5315 #ifdef CAN_DEBUG_WITHOUT_FP
5316 flag_omit_frame_pointer = 1;
5317 #endif
5320 if (optimize >= 2)
5322 flag_cse_follow_jumps = 1;
5323 flag_cse_skip_blocks = 1;
5324 flag_gcse = 1;
5325 flag_expensive_optimizations = 1;
5326 flag_strength_reduce = 1;
5327 flag_rerun_cse_after_loop = 1;
5328 flag_rerun_loop_opt = 1;
5329 flag_caller_saves = 1;
5330 flag_force_mem = 1;
5331 flag_peephole2 = 1;
5332 #ifdef INSN_SCHEDULING
5333 flag_schedule_insns = 1;
5334 flag_schedule_insns_after_reload = 1;
5335 #endif
5336 flag_regmove = 1;
5337 flag_strict_aliasing = 1;
5338 flag_delete_null_pointer_checks = 1;
5341 if (optimize >= 3)
5343 flag_inline_functions = 1;
5346 if (optimize < 2 || optimize_size)
5348 align_loops = 1;
5349 align_jumps = 1;
5350 align_labels = 1;
5351 align_functions = 1;
5354 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
5355 modify it. */
5356 target_flags = 0;
5357 set_target_switch ("");
5359 #ifdef OPTIMIZATION_OPTIONS
5360 /* Allow default optimizations to be specified on a per-machine basis. */
5361 OPTIMIZATION_OPTIONS (optimize, optimize_size);
5362 #endif
5364 /* Initialize register usage now so switches may override. */
5365 init_reg_sets ();
5367 /* Perform normal command line switch decoding. */
5368 for (i = 1; i < argc;)
5370 unsigned lang_processed;
5371 unsigned indep_processed;
5373 /* Give the language a chance to decode the option for itself. */
5374 lang_processed = lang_decode_option (argc - i, argv + i);
5376 /* Now see if the option also has a language independent meaning.
5377 Some options are both language specific and language independent,
5378 eg --help. It is possible that there might be options that should
5379 only be decoded in a language independent way if the were not
5380 decoded in a langauge specific way, which is why 'lang_processed'
5381 is passed in. */
5382 indep_processed = independent_decode_option (argc - i, argv + i, lang_processed);
5384 if (lang_processed || indep_processed)
5385 i += lang_processed > indep_processed ? lang_processed : indep_processed;
5386 else
5388 error ("Invalid option `%s'", argv[i]);
5389 i++;
5393 /* Checker uses the frame pointer. */
5394 if (flag_check_memory_usage)
5395 flag_omit_frame_pointer = 0;
5397 if (optimize == 0)
5399 /* Inlining does not work if not optimizing,
5400 so force it not to be done. */
5401 flag_no_inline = 1;
5402 warn_inline = 0;
5404 /* The c_decode_option and lang_decode_option functions set
5405 this to `2' if -Wall is used, so we can avoid giving out
5406 lots of errors for people who don't realize what -Wall does. */
5407 if (warn_uninitialized == 1)
5408 warning ("-Wuninitialized is not supported without -O");
5411 #ifdef OVERRIDE_OPTIONS
5412 /* Some machines may reject certain combinations of options. */
5413 OVERRIDE_OPTIONS;
5414 #endif
5416 if (exceptions_via_longjmp == 2)
5418 #ifdef DWARF2_UNWIND_INFO
5419 exceptions_via_longjmp = ! DWARF2_UNWIND_INFO;
5420 #else
5421 exceptions_via_longjmp = 1;
5422 #endif
5425 /* Set up the align_*_log variables, defaulting them to 1 if they
5426 were still unset. */
5427 if (align_loops <= 0) align_loops = 1;
5428 align_loops_log = floor_log2 (align_loops*2-1);
5429 if (align_jumps <= 0) align_jumps = 1;
5430 align_jumps_log = floor_log2 (align_jumps*2-1);
5431 if (align_labels <= 0) align_labels = 1;
5432 align_labels_log = floor_log2 (align_labels*2-1);
5433 if (align_functions <= 0) align_functions = 1;
5434 align_functions_log = floor_log2 (align_functions*2-1);
5436 if (profile_block_flag == 3)
5438 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
5439 profile_block_flag = 2;
5442 /* Unrolling all loops implies that standard loop unrolling must also
5443 be done. */
5444 if (flag_unroll_all_loops)
5445 flag_unroll_loops = 1;
5446 /* Loop unrolling requires that strength_reduction be on also. Silently
5447 turn on strength reduction here if it isn't already on. Also, the loop
5448 unrolling code assumes that cse will be run after loop, so that must
5449 be turned on also. */
5450 if (flag_unroll_loops)
5452 flag_strength_reduce = 1;
5453 flag_rerun_cse_after_loop = 1;
5456 /* Warn about options that are not supported on this machine. */
5457 #ifndef INSN_SCHEDULING
5458 if (flag_schedule_insns || flag_schedule_insns_after_reload)
5459 warning ("instruction scheduling not supported on this target machine");
5460 #endif
5461 #ifndef DELAY_SLOTS
5462 if (flag_delayed_branch)
5463 warning ("this target machine does not have delayed branches");
5464 #endif
5466 user_label_prefix = USER_LABEL_PREFIX;
5467 if (flag_leading_underscore != -1)
5469 /* If the default prefix is more complicated than "" or "_",
5470 issue a warning and ignore this option. */
5471 if (user_label_prefix[0] == 0 ||
5472 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
5474 user_label_prefix = flag_leading_underscore ? "_" : "";
5476 else
5477 warning ("-f%sleading-underscore not supported on this target machine",
5478 flag_leading_underscore ? "" : "no-");
5481 /* If we are in verbose mode, write out the version and maybe all the
5482 option flags in use. */
5483 if (version_flag)
5485 print_version (stderr, "");
5486 if (! quiet_flag)
5487 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
5490 compile_file (filename);
5492 #if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN__)) && !defined(__INTERIX)
5493 if (flag_print_mem)
5495 char *lim = (char *) sbrk (0);
5497 notice ("Data size %ld.\n", (long) (lim - (char *) &environ));
5498 fflush (stderr);
5500 #ifndef __MSDOS__
5501 #ifdef USG
5502 system ("ps -l 1>&2");
5503 #else /* not USG */
5504 system ("ps v");
5505 #endif /* not USG */
5506 #endif
5508 #endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN) && ! __INTERIX */
5510 if (errorcount)
5511 return (FATAL_EXIT_CODE);
5512 if (sorrycount)
5513 return (FATAL_EXIT_CODE);
5514 return (SUCCESS_EXIT_CODE);
5517 /* Decode -m switches. */
5518 /* Decode the switch -mNAME. */
5520 static void
5521 set_target_switch (name)
5522 const char *name;
5524 register size_t j;
5525 int valid_target_option = 0;
5527 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5528 if (!strcmp (target_switches[j].name, name))
5530 if (target_switches[j].value < 0)
5531 target_flags &= ~-target_switches[j].value;
5532 else
5533 target_flags |= target_switches[j].value;
5534 valid_target_option = 1;
5537 #ifdef TARGET_OPTIONS
5538 if (!valid_target_option)
5539 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5541 int len = strlen (target_options[j].prefix);
5542 if (!strncmp (target_options[j].prefix, name, len))
5544 *target_options[j].variable = name + len;
5545 valid_target_option = 1;
5548 #endif
5550 if (!valid_target_option)
5551 error ("Invalid option `%s'", name);
5554 /* Print version information to FILE.
5555 Each line begins with INDENT (for the case where FILE is the
5556 assembler output file). */
5558 static void
5559 print_version (file, indent)
5560 FILE *file;
5561 const char *indent;
5563 #ifndef __VERSION__
5564 #define __VERSION__ "[?]"
5565 #endif
5566 fnotice (file,
5567 #ifdef __GNUC__
5568 "%s%s%s version %s (%s) compiled by GNU C version %s.\n"
5569 #else
5570 "%s%s%s version %s (%s) compiled by CC.\n"
5571 #endif
5572 , indent, *indent != 0 ? " " : "",
5573 language_string, version_string, TARGET_NAME, __VERSION__);
5576 /* Print an option value and return the adjusted position in the line.
5577 ??? We don't handle error returns from fprintf (disk full); presumably
5578 other code will catch a disk full though. */
5580 static int
5581 print_single_switch (file, pos, max, indent, sep, term, type, name)
5582 FILE *file;
5583 int pos, max;
5584 const char *indent, *sep, *term, *type, *name;
5586 /* The ultrix fprintf returns 0 on success, so compute the result we want
5587 here since we need it for the following test. */
5588 int len = strlen (sep) + strlen (type) + strlen (name);
5590 if (pos != 0
5591 && pos + len > max)
5593 fprintf (file, "%s", term);
5594 pos = 0;
5596 if (pos == 0)
5598 fprintf (file, "%s", indent);
5599 pos = strlen (indent);
5601 fprintf (file, "%s%s%s", sep, type, name);
5602 pos += len;
5603 return pos;
5606 /* Print active target switches to FILE.
5607 POS is the current cursor position and MAX is the size of a "line".
5608 Each line begins with INDENT and ends with TERM.
5609 Each switch is separated from the next by SEP. */
5611 static void
5612 print_switch_values (file, pos, max, indent, sep, term)
5613 FILE *file;
5614 int pos, max;
5615 const char *indent, *sep, *term;
5617 size_t j;
5618 char **p;
5620 /* Print the options as passed. */
5622 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
5623 _("options passed: "), "");
5625 for (p = &save_argv[1]; *p != NULL; p++)
5626 if (**p == '-')
5628 /* Ignore these. */
5629 if (strcmp (*p, "-o") == 0)
5631 if (p[1] != NULL)
5632 p++;
5633 continue;
5635 if (strcmp (*p, "-quiet") == 0)
5636 continue;
5637 if (strcmp (*p, "-version") == 0)
5638 continue;
5639 if ((*p)[1] == 'd')
5640 continue;
5642 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
5644 if (pos > 0)
5645 fprintf (file, "%s", term);
5647 /* Print the -f and -m options that have been enabled.
5648 We don't handle language specific options but printing argv
5649 should suffice. */
5651 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
5652 _("options enabled: "), "");
5654 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
5655 if (*f_options[j].variable == f_options[j].on_value)
5656 pos = print_single_switch (file, pos, max, indent, sep, term,
5657 "-f", f_options[j].string);
5659 /* Print target specific options. */
5661 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5662 if (target_switches[j].name[0] != '\0'
5663 && target_switches[j].value > 0
5664 && ((target_switches[j].value & target_flags)
5665 == target_switches[j].value))
5667 pos = print_single_switch (file, pos, max, indent, sep, term,
5668 "-m", target_switches[j].name);
5671 #ifdef TARGET_OPTIONS
5672 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5673 if (*target_options[j].variable != NULL)
5675 char prefix[256];
5676 sprintf (prefix, "-m%s", target_options[j].prefix);
5677 pos = print_single_switch (file, pos, max, indent, sep, term,
5678 prefix, *target_options[j].variable);
5680 #endif
5682 fprintf (file, "%s", term);
5685 /* Record the beginning of a new source file, named FILENAME. */
5687 void
5688 debug_start_source_file (filename)
5689 register char *filename ATTRIBUTE_UNUSED;
5691 #ifdef DBX_DEBUGGING_INFO
5692 if (write_symbols == DBX_DEBUG)
5693 dbxout_start_new_source_file (filename);
5694 #endif
5695 #ifdef DWARF_DEBUGGING_INFO
5696 if (debug_info_level == DINFO_LEVEL_VERBOSE
5697 && write_symbols == DWARF_DEBUG)
5698 dwarfout_start_new_source_file (filename);
5699 #endif /* DWARF_DEBUGGING_INFO */
5700 #ifdef DWARF2_DEBUGGING_INFO
5701 if (debug_info_level == DINFO_LEVEL_VERBOSE
5702 && write_symbols == DWARF2_DEBUG)
5703 dwarf2out_start_source_file (filename);
5704 #endif /* DWARF2_DEBUGGING_INFO */
5705 #ifdef SDB_DEBUGGING_INFO
5706 if (write_symbols == SDB_DEBUG)
5707 sdbout_start_new_source_file (filename);
5708 #endif
5711 /* Record the resumption of a source file. LINENO is the line number in
5712 the source file we are returning to. */
5714 void
5715 debug_end_source_file (lineno)
5716 register unsigned lineno ATTRIBUTE_UNUSED;
5718 #ifdef DBX_DEBUGGING_INFO
5719 if (write_symbols == DBX_DEBUG)
5720 dbxout_resume_previous_source_file ();
5721 #endif
5722 #ifdef DWARF_DEBUGGING_INFO
5723 if (debug_info_level == DINFO_LEVEL_VERBOSE
5724 && write_symbols == DWARF_DEBUG)
5725 dwarfout_resume_previous_source_file (lineno);
5726 #endif /* DWARF_DEBUGGING_INFO */
5727 #ifdef DWARF2_DEBUGGING_INFO
5728 if (debug_info_level == DINFO_LEVEL_VERBOSE
5729 && write_symbols == DWARF2_DEBUG)
5730 dwarf2out_end_source_file ();
5731 #endif /* DWARF2_DEBUGGING_INFO */
5732 #ifdef SDB_DEBUGGING_INFO
5733 if (write_symbols == SDB_DEBUG)
5734 sdbout_resume_previous_source_file ();
5735 #endif
5738 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5739 the tail part of the directive line, i.e. the part which is past the
5740 initial whitespace, #, whitespace, directive-name, whitespace part. */
5742 void
5743 debug_define (lineno, buffer)
5744 register unsigned lineno ATTRIBUTE_UNUSED;
5745 register char *buffer ATTRIBUTE_UNUSED;
5747 #ifdef DWARF_DEBUGGING_INFO
5748 if (debug_info_level == DINFO_LEVEL_VERBOSE
5749 && write_symbols == DWARF_DEBUG)
5750 dwarfout_define (lineno, buffer);
5751 #endif /* DWARF_DEBUGGING_INFO */
5752 #ifdef DWARF2_DEBUGGING_INFO
5753 if (debug_info_level == DINFO_LEVEL_VERBOSE
5754 && write_symbols == DWARF2_DEBUG)
5755 dwarf2out_define (lineno, buffer);
5756 #endif /* DWARF2_DEBUGGING_INFO */
5759 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5760 the tail part of the directive line, i.e. the part which is past the
5761 initial whitespace, #, whitespace, directive-name, whitespace part. */
5763 void
5764 debug_undef (lineno, buffer)
5765 register unsigned lineno ATTRIBUTE_UNUSED;
5766 register char *buffer ATTRIBUTE_UNUSED;
5768 #ifdef DWARF_DEBUGGING_INFO
5769 if (debug_info_level == DINFO_LEVEL_VERBOSE
5770 && write_symbols == DWARF_DEBUG)
5771 dwarfout_undef (lineno, buffer);
5772 #endif /* DWARF_DEBUGGING_INFO */
5773 #ifdef DWARF2_DEBUGGING_INFO
5774 if (debug_info_level == DINFO_LEVEL_VERBOSE
5775 && write_symbols == DWARF2_DEBUG)
5776 dwarf2out_undef (lineno, buffer);
5777 #endif /* DWARF2_DEBUGGING_INFO */