1998-09-21 Ben Elliston <bje@cygnus.com>
[official-gcc.git] / gcc / toplev.c
blobcc4d8d0803113a8de4e8300799570f9109b33f39
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 88, 89, 92-7, 1998 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>
32 #include <sys/stat.h>
34 #ifdef HAVE_SYS_RESOURCE_H
35 # include <sys/resource.h>
36 #endif
38 #ifdef HAVE_SYS_TIMES_H
39 # include <sys/times.h>
40 #endif
42 #include "input.h"
43 #include "tree.h"
44 #include "rtl.h"
45 #include "flags.h"
46 #include "insn-attr.h"
47 #include "insn-codes.h"
48 #include "insn-config.h"
49 #include "recog.h"
50 #include "defaults.h"
51 #include "output.h"
52 #include "except.h"
53 #include "toplev.h"
54 #include "expr.h"
56 #ifdef DWARF_DEBUGGING_INFO
57 #include "dwarfout.h"
58 #endif
60 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
61 #include "dwarf2out.h"
62 #endif
64 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
65 #include "dbxout.h"
66 #endif
68 #ifdef SDB_DEBUGGING_INFO
69 #include "sdbout.h"
70 #endif
72 #ifdef XCOFF_DEBUGGING_INFO
73 #include "xcoffout.h"
74 #endif
76 #ifdef VMS
77 /* The extra parameters substantially improve the I/O performance. */
78 static FILE *
79 vms_fopen (fname, type)
80 char * fname;
81 char * type;
83 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
84 fixed arguments, which matches ANSI's specification but not VAXCRTL's
85 pre-ANSI implementation. This hack circumvents the mismatch problem. */
86 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
88 if (*type == 'w')
89 return (*vmslib_fopen) (fname, type, "mbc=32",
90 "deq=64", "fop=tef", "shr=nil");
91 else
92 return (*vmslib_fopen) (fname, type, "mbc=32");
94 #define fopen vms_fopen
95 #endif /* VMS */
97 #ifndef DEFAULT_GDB_EXTENSIONS
98 #define DEFAULT_GDB_EXTENSIONS 1
99 #endif
101 /* If more than one debugging type is supported, you must define
102 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
104 This is one long line cause VAXC can't handle a \-newline. */
105 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
106 #ifndef PREFERRED_DEBUGGING_TYPE
107 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
108 #endif /* no PREFERRED_DEBUGGING_TYPE */
109 #else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
110 so the following code needn't care. */
111 #ifdef DBX_DEBUGGING_INFO
112 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
113 #endif
114 #ifdef SDB_DEBUGGING_INFO
115 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
116 #endif
117 #ifdef DWARF_DEBUGGING_INFO
118 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
119 #endif
120 #ifdef DWARF2_DEBUGGING_INFO
121 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
122 #endif
123 #ifdef XCOFF_DEBUGGING_INFO
124 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
125 #endif
126 #endif /* More than one debugger format enabled. */
128 /* If still not defined, must have been because no debugging formats
129 are supported. */
130 #ifndef PREFERRED_DEBUGGING_TYPE
131 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
132 #endif
134 extern int rtx_equal_function_value_matters;
136 #if ! (defined (VMS) || defined (OS2))
137 extern char **environ;
138 #endif
139 extern char *version_string, *language_string;
141 /* Carry information from ASM_DECLARE_OBJECT_NAME
142 to ASM_FINISH_DECLARE_OBJECT. */
144 extern int size_directive_output;
145 extern tree last_assemble_variable_decl;
147 extern char *init_parse PVPROTO((char *));
148 extern void finish_parse ();
149 extern void init_decl_processing ();
150 extern void init_obstacks ();
151 extern void init_tree_codes ();
152 extern void init_rtl ();
153 extern void init_regs ();
154 extern void init_optabs ();
155 extern void init_stmt ();
156 extern void init_reg_sets ();
157 extern void dump_flow_info ();
158 extern void dump_sched_info ();
159 extern void dump_local_alloc ();
160 extern void regset_release_memory ();
162 extern void print_rtl ();
163 extern void print_rtl_with_bb ();
165 void rest_of_decl_compilation ();
166 void error_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
167 void error_with_decl PVPROTO((tree decl, char *s, ...));
168 void error PVPROTO((char *s, ...));
169 void fatal PVPROTO((char *s, ...));
170 void warning_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
171 void warning_with_decl PVPROTO((tree decl, char *s, ...));
172 void warning PVPROTO((char *s, ...));
173 void pedwarn PVPROTO((char *s, ...));
174 void pedwarn_with_decl PVPROTO((tree decl, char *s, ...));
175 void pedwarn_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
176 void sorry PVPROTO((char *s, ...));
177 static void set_target_switch PROTO((char *));
178 static char *decl_name PROTO((tree, int));
179 static void vmessage PROTO((char *, char *, va_list));
180 static void v_message_with_file_and_line PROTO((char *, int, char *,
181 char *, va_list));
182 static void v_message_with_decl PROTO((tree, char *, char *, va_list));
183 static void file_and_line_for_asm PROTO((rtx, char **, int *));
184 static void v_error_with_file_and_line PROTO((char *, int, char *, va_list));
185 static void v_error_with_decl PROTO((tree, char *, va_list));
186 static void v_error_for_asm PROTO((rtx, char *, va_list));
187 static void verror PROTO((char *, va_list));
188 static void vfatal PROTO((char *, va_list)) ATTRIBUTE_NORETURN;
189 static void v_warning_with_file_and_line PROTO ((char *, int, char *, va_list));
190 static void v_warning_with_decl PROTO((tree, char *, va_list));
191 static void v_warning_for_asm PROTO((rtx, char *, va_list));
192 static void vwarning PROTO((char *, va_list));
193 static void vpedwarn PROTO((char *, va_list));
194 static void v_pedwarn_with_decl PROTO((tree, char *, va_list));
195 static void v_pedwarn_with_file_and_line PROTO((char *, int, char *, va_list));
196 static void vsorry PROTO((char *, va_list));
197 static void v_really_sorry PROTO((char *, va_list)) ATTRIBUTE_NORETURN;
198 static void float_signal PROTO((int));
199 static void pipe_closed PROTO((int));
200 static void output_lang_identify PROTO((FILE *));
201 static void open_dump_file PROTO((char *, char *));
202 static void close_dump_file PROTO((void (*) (FILE *, rtx), rtx));
203 static void dump_rtl PROTO((char *, tree, void (*) (FILE *, rtx), rtx));
204 static void clean_dump_file PROTO((char *));
205 static void compile_file PROTO((char *));
206 static void display_help PROTO ((void));
208 static void print_version PROTO((FILE *, char *));
209 static int print_single_switch PROTO((FILE *, int, int, char *, char *, char *,
210 char *, char *));
211 static void print_switch_values PROTO((FILE *, int, int, char *, char *,
212 char *));
213 /* Length of line when printing switch values. */
214 #define MAX_LINE 75
216 /* Name of program invoked, sans directories. */
218 char *progname;
220 /* Copy of arguments to main. */
221 int save_argc;
222 char **save_argv;
224 /* Name of current original source file (what was input to cpp).
225 This comes from each #-command in the actual input. */
227 char *input_filename;
229 /* Name of top-level original source file (what was input to cpp).
230 This comes from the #-command at the beginning of the actual input.
231 If there isn't any there, then this is the cc1 input file name. */
233 char *main_input_filename;
235 /* Current line number in real source file. */
237 int lineno;
239 /* Stack of currently pending input files. */
241 struct file_stack *input_file_stack;
243 /* Incremented on each change to input_file_stack. */
244 int input_file_stack_tick;
246 /* FUNCTION_DECL for function now being parsed or compiled. */
248 extern tree current_function_decl;
250 /* Name to use as base of names for dump output files. */
252 char *dump_base_name;
254 /* Bit flags that specify the machine subtype we are compiling for.
255 Bits are tested using macros TARGET_... defined in the tm.h file
256 and set by `-m...' switches. Must be defined in rtlanal.c. */
258 extern int target_flags;
260 /* Flags saying which kinds of debugging dump have been requested. */
262 int rtl_dump = 0;
263 int rtl_dump_and_exit = 0;
264 int jump_opt_dump = 0;
265 int addressof_dump = 0;
266 int cse_dump = 0;
267 int gcse_dump = 0;
268 int loop_dump = 0;
269 int cse2_dump = 0;
270 int branch_prob_dump = 0;
271 int flow_dump = 0;
272 int combine_dump = 0;
273 int regmove_dump = 0;
274 int sched_dump = 0;
275 int local_reg_dump = 0;
276 int global_reg_dump = 0;
277 int sched2_dump = 0;
278 int jump2_opt_dump = 0;
279 #ifdef DELAY_SLOTS
280 int dbr_sched_dump = 0;
281 #endif
282 int flag_print_asm_name = 0;
283 #ifdef STACK_REGS
284 int stack_reg_dump = 0;
285 #endif
286 #ifdef MACHINE_DEPENDENT_REORG
287 int mach_dep_reorg_dump = 0;
288 #endif
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 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 /* Pointer to function to finish handling an incomplete decl at the
354 end of compilation. */
356 void (*incomplete_decl_finalize_hook) PROTO((tree)) = 0;
358 /* Highest label number used at the end of reload. */
360 int max_label_num_after_reload;
362 /* Nonzero if generating code to do profiling. */
364 int profile_flag = 0;
366 /* Nonzero if generating code to do profiling on a line-by-line basis. */
368 int profile_block_flag;
370 /* Nonzero if generating code to profile program flow graph arcs. */
372 int profile_arc_flag = 0;
374 /* Nonzero if generating info for gcov to calculate line test coverage. */
376 int flag_test_coverage = 0;
378 /* Nonzero indicates that branch taken probabilities should be calculated. */
380 int flag_branch_probabilities = 0;
382 /* Nonzero for -pedantic switch: warn about anything
383 that standard spec forbids. */
385 int pedantic = 0;
387 /* Temporarily suppress certain warnings.
388 This is set while reading code from a system header file. */
390 int in_system_header = 0;
392 /* Nonzero means do stupid register allocation.
393 Currently, this is 1 if `optimize' is 0. */
395 int obey_regdecls = 0;
397 /* Don't print functions as they are compiled and don't print
398 times taken by the various passes. -quiet. */
400 int quiet_flag = 0;
402 /* -f flags. */
404 /* Nonzero means `char' should be signed. */
406 int flag_signed_char;
408 /* Nonzero means give an enum type only as many bytes as it needs. */
410 int flag_short_enums;
412 /* Nonzero for -fcaller-saves: allocate values in regs that need to
413 be saved across function calls, if that produces overall better code.
414 Optional now, so people can test it. */
416 #ifdef DEFAULT_CALLER_SAVES
417 int flag_caller_saves = 1;
418 #else
419 int flag_caller_saves = 0;
420 #endif
422 /* Nonzero if structures and unions should be returned in memory.
424 This should only be defined if compatibility with another compiler or
425 with an ABI is needed, because it results in slower code. */
427 #ifndef DEFAULT_PCC_STRUCT_RETURN
428 #define DEFAULT_PCC_STRUCT_RETURN 1
429 #endif
431 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
433 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
435 /* Nonzero for -fforce-mem: load memory value into a register
436 before arithmetic on it. This makes better cse but slower compilation. */
438 int flag_force_mem = 0;
440 /* Nonzero for -fforce-addr: load memory address into a register before
441 reference to memory. This makes better cse but slower compilation. */
443 int flag_force_addr = 0;
445 /* Nonzero for -fdefer-pop: don't pop args after each function call;
446 instead save them up to pop many calls' args with one insns. */
448 int flag_defer_pop = 0;
450 /* Nonzero for -ffloat-store: don't allocate floats and doubles
451 in extended-precision registers. */
453 int flag_float_store = 0;
455 /* Nonzero for -fcse-follow-jumps:
456 have cse follow jumps to do a more extensive job. */
458 int flag_cse_follow_jumps;
460 /* Nonzero for -fcse-skip-blocks:
461 have cse follow a branch around a block. */
462 int flag_cse_skip_blocks;
464 /* Nonzero for -fexpensive-optimizations:
465 perform miscellaneous relatively-expensive optimizations. */
466 int flag_expensive_optimizations;
468 /* Nonzero for -fthread-jumps:
469 have jump optimize output of loop. */
471 int flag_thread_jumps;
473 /* Nonzero enables strength-reduction in loop.c. */
475 int flag_strength_reduce = 0;
477 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
478 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
479 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
480 unrolled. */
482 int flag_unroll_loops;
484 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
485 This is generally not a win. */
487 int flag_unroll_all_loops;
489 /* Nonzero forces all invariant computations in loops to be moved
490 outside the loop. */
492 int flag_move_all_movables = 0;
494 /* Nonzero forces all general induction variables in loops to be
495 strength reduced. */
497 int flag_reduce_all_givs = 0;
499 /* Nonzero to perform full register move optimization passes. This is the
500 default for -O2. */
502 int flag_regmove = 0;
504 /* Nonzero for -fwritable-strings:
505 store string constants in data segment and don't uniquize them. */
507 int flag_writable_strings = 0;
509 /* Nonzero means don't put addresses of constant functions in registers.
510 Used for compiling the Unix kernel, where strange substitutions are
511 done on the assembly output. */
513 int flag_no_function_cse = 0;
515 /* Nonzero for -fomit-frame-pointer:
516 don't make a frame pointer in simple functions that don't require one. */
518 int flag_omit_frame_pointer = 0;
520 /* Nonzero means place each function into its own section on those platforms
521 which support arbitrary section names and unlimited numbers of sections. */
523 int flag_function_sections = 0;
525 /* Nonzero to inhibit use of define_optimization peephole opts. */
527 int flag_no_peephole = 0;
529 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
530 operations in the interest of optimization. For example it allows
531 GCC to assume arguments to sqrt are nonnegative numbers, allowing
532 faster code for sqrt to be generated. */
534 int flag_fast_math = 0;
536 /* Nonzero means all references through pointers are volatile. */
538 int flag_volatile;
540 /* Nonzero means treat all global and extern variables as global. */
542 int flag_volatile_global;
544 /* Nonzero means just do syntax checking; don't output anything. */
546 int flag_syntax_only = 0;
548 /* Nonzero means perform global cse. */
550 static int flag_gcse;
552 /* Nonzero means to rerun cse after loop optimization. This increases
553 compilation time about 20% and picks up a few more common expressions. */
555 static int flag_rerun_cse_after_loop;
557 /* Nonzero means to run loop optimizations twice. */
559 int flag_rerun_loop_opt;
561 /* Nonzero for -finline-functions: ok to inline functions that look like
562 good inline candidates. */
564 int flag_inline_functions;
566 /* Nonzero for -fkeep-inline-functions: even if we make a function
567 go inline everywhere, keep its definition around for debugging
568 purposes. */
570 int flag_keep_inline_functions;
572 /* Nonzero means that functions will not be inlined. */
574 int flag_no_inline;
576 /* Nonzero means that we should emit static const variables
577 regardless of whether or not optimization is turned on. */
579 int flag_keep_static_consts = 1;
581 /* Nonzero means we should be saving declaration info into a .X file. */
583 int flag_gen_aux_info = 0;
585 /* Specified name of aux-info file. */
587 static char *aux_info_file_name;
589 /* Nonzero means make the text shared if supported. */
591 int flag_shared_data;
593 /* Nonzero means schedule into delayed branch slots if supported. */
595 int flag_delayed_branch;
597 /* Nonzero if we are compiling pure (sharable) code.
598 Value is 1 if we are doing reasonable (i.e. simple
599 offset into offset table) pic. Value is 2 if we can
600 only perform register offsets. */
602 int flag_pic;
604 /* Nonzero means generate extra code for exception handling and enable
605 exception handling. */
607 int flag_exceptions;
609 /* Nonzero means use the new model for exception handling. Replaces
610 -DNEW_EH_MODEL as a compile option. */
612 int flag_new_exceptions = 0;
614 /* Nonzero means don't place uninitialized global data in common storage
615 by default. */
617 int flag_no_common;
619 /* Nonzero means pretend it is OK to examine bits of target floats,
620 even if that isn't true. The resulting code will have incorrect constants,
621 but the same series of instructions that the native compiler would make. */
623 int flag_pretend_float;
625 /* Nonzero means change certain warnings into errors.
626 Usually these are warnings about failure to conform to some standard. */
628 int flag_pedantic_errors = 0;
630 /* flag_schedule_insns means schedule insns within basic blocks (before
631 local_alloc).
632 flag_schedule_insns_after_reload means schedule insns after
633 global_alloc. */
635 int flag_schedule_insns = 0;
636 int flag_schedule_insns_after_reload = 0;
638 #ifdef HAIFA
639 /* The following flags have effect only for scheduling before register
640 allocation:
642 flag_schedule_interblock means schedule insns accross basic blocks.
643 flag_schedule_speculative means allow speculative motion of non-load insns.
644 flag_schedule_speculative_load means allow speculative motion of some
645 load insns.
646 flag_schedule_speculative_load_dangerous allows speculative motion of more
647 load insns. */
649 int flag_schedule_interblock = 1;
650 int flag_schedule_speculative = 1;
651 int flag_schedule_speculative_load = 0;
652 int flag_schedule_speculative_load_dangerous = 0;
654 /* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
655 by a cheaper branch, on a count register. */
656 int flag_branch_on_count_reg;
657 #endif /* HAIFA */
660 /* -finhibit-size-directive inhibits output of .size for ELF.
661 This is used only for compiling crtstuff.c,
662 and it may be extended to other effects
663 needed for crtstuff.c on other systems. */
664 int flag_inhibit_size_directive = 0;
666 /* -fverbose-asm causes extra commentary information to be produced in
667 the generated assembly code (to make it more readable). This option
668 is generally only of use to those who actually need to read the
669 generated assembly code (perhaps while debugging the compiler itself).
670 -fno-verbose-asm, the default, causes the extra information
671 to be omitted and is useful when comparing two assembler files. */
673 int flag_verbose_asm = 0;
675 /* -dA causes debug commentary information to be produced in
676 the generated assembly code (to make it more readable). This option
677 is generally only of use to those who actually need to read the
678 generated assembly code (perhaps while debugging the compiler itself).
679 Currently, this switch is only used by dwarfout.c; however, it is intended
680 to be a catchall for printing debug information in the assembler file. */
682 int flag_debug_asm = 0;
684 /* -fgnu-linker specifies use of the GNU linker for initializations.
685 (Or, more generally, a linker that handles initializations.)
686 -fno-gnu-linker says that collect2 will be used. */
687 #ifdef USE_COLLECT2
688 int flag_gnu_linker = 0;
689 #else
690 int flag_gnu_linker = 1;
691 #endif
693 /* Tag all structures with __attribute__(packed) */
694 int flag_pack_struct = 0;
696 /* Emit code to check for stack overflow; also may cause large objects
697 to be allocated dynamically. */
698 int flag_stack_check;
700 /* -fcheck-memory-usage causes extra code to be generated in order to check
701 memory accesses. This is used by a detector of bad memory accesses such
702 as Checker. */
703 int flag_check_memory_usage = 0;
705 /* -fprefix-function-name causes function name to be prefixed. This
706 can be used with -fcheck-memory-usage to isolate code compiled with
707 -fcheck-memory-usage. */
708 int flag_prefix_function_name = 0;
710 /* 0 if pointer arguments may alias each other. True in C.
711 1 if pointer arguments may not alias each other but may alias
712 global variables.
713 2 if pointer arguments may not alias each other and may not
714 alias global variables. True in Fortran.
715 This defaults to 0 for C. */
716 int flag_argument_noalias = 0;
718 /* Nonzero if we should do (language-dependent) alias analysis.
719 Typically, this analysis will assume that expressions of certain
720 types do not alias expressions of certain other types. Only used
721 if alias analysis (in general) is enabled. */
722 int flag_strict_aliasing = 0;
724 extern int flag_dump_unnumbered;
726 /* Instrument functions with calls at entry and exit, for profiling. */
727 int flag_instrument_function_entry_exit = 0;
730 /* Table of supported debugging formats. */
731 static struct
733 char * arg;
734 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
735 constant expression, we use NO_DEBUG in its place. */
736 enum debug_info_type debug_type;
737 int use_extensions_p;
738 char * description;
739 } *da,
740 debug_args[] =
742 { "g", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
743 "Generate default debug format output" },
744 { "ggdb", NO_DEBUG, 1, "Generate default extended debug format output" },
745 #ifdef DBX_DEBUGGING_INFO
746 { "gstabs", DBX_DEBUG, 0, "Generate STABS format debug output" },
747 { "gstabs+", DBX_DEBUG, 1, "Generate extended STABS format debug output" },
748 #endif
749 #ifdef DWARF_DEBUGGING_INFO
750 { "gdwarf", DWARF_DEBUG, 0, "Generate DWARF-1 format debug output"},
751 { "gdwarf+", DWARF_DEBUG, 1,
752 "Generated extended DWARF-1 format debug output" },
753 #endif
754 #ifdef DWARF2_DEBUGGING_INFO
755 { "gdwarf-2", DWARF2_DEBUG, 0, "Enable DWARF-2 debug output" },
756 #endif
757 #ifdef XCOFF_DEBUGGING_INFO
758 { "gxcoff", XCOFF_DEBUG, 0, "Generate XCOFF format debug output" },
759 { "gxcoff+", XCOFF_DEBUG, 1, "Generate extended XCOFF format debug output" },
760 #endif
761 #ifdef SDB_DEBUGGING_INFO
762 { "gcoff", SDB_DEBUG, 0, "Generate COFF format debug output" },
763 #endif
764 { 0, 0, 0 }
767 typedef struct
769 char * string;
770 int * variable;
771 int on_value;
772 char * description;
774 lang_independent_options;
776 /* Table of language-independent -f options.
777 STRING is the option name. VARIABLE is the address of the variable.
778 ON_VALUE is the value to store in VARIABLE
779 if `-fSTRING' is seen as an option.
780 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
782 lang_independent_options f_options[] =
784 {"float-store", &flag_float_store, 1,
785 "Do not store floats in registers" },
786 {"volatile", &flag_volatile, 1,
787 "Consider all mem refs through pointers as volatile"},
788 {"volatile-global", &flag_volatile_global, 1,
789 "Consider all mem refs to global data to be volatile" },
790 {"defer-pop", &flag_defer_pop, 1,
791 "Defer popping functions args from stack until later" },
792 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
793 "When possible do not generate stack frames"},
794 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
795 "When running CSE, follow jumps to their targets" },
796 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
797 "When running CSE, follow conditional jumps" },
798 {"expensive-optimizations", &flag_expensive_optimizations, 1,
799 "Perform a number of minor, expensive optimisations" },
800 {"thread-jumps", &flag_thread_jumps, 1,
801 "Perform jump threading optimisations"},
802 {"strength-reduce", &flag_strength_reduce, 1,
803 "Perform strength reduction optimisations" },
804 {"unroll-loops", &flag_unroll_loops, 1,
805 "Perform loop unrolling when interation count is known" },
806 {"unroll-all-loops", &flag_unroll_all_loops, 1,
807 "Perofm loop onrolling for all loops" },
808 {"move-all-movables", &flag_move_all_movables, 1,
809 "Force all loop invariant computations out of loops" },
810 {"reduce-all-givs", &flag_reduce_all_givs, 1,
811 "Strength reduce all loop general induction variables" },
812 {"writable-strings", &flag_writable_strings, 1,
813 "Store strings in writable data section" },
814 {"peephole", &flag_no_peephole, 0,
815 "Enable machine specific peephole optimisations" },
816 {"force-mem", &flag_force_mem, 1,
817 "Copy memory operands into registers before using" },
818 {"force-addr", &flag_force_addr, 1,
819 "Copy memory address constants into regs before using" },
820 {"function-cse", &flag_no_function_cse, 0,
821 "Allow function addresses to be held in registers" },
822 {"inline-functions", &flag_inline_functions, 1,
823 "Integrate simple functions into their callers" },
824 {"keep-inline-functions", &flag_keep_inline_functions, 1,
825 "Generate code for funcs even if they are fully inlined" },
826 {"inline", &flag_no_inline, 0,
827 "Pay attention to the 'inline' keyword"},
828 {"keep-static-consts", &flag_keep_static_consts, 1,
829 "Emit static const variables even if they are not used" },
830 {"syntax-only", &flag_syntax_only, 1,
831 "Check for syntax errors, then stop" },
832 {"shared-data", &flag_shared_data, 1,
833 "Mark data as shared rather than private" },
834 {"caller-saves", &flag_caller_saves, 1,
835 "Enable saving registers around function calls" },
836 {"pcc-struct-return", &flag_pcc_struct_return, 1,
837 "Return 'short' aggregates in memory, not registers" },
838 {"reg-struct-return", &flag_pcc_struct_return, 0,
839 "Return 'short' aggregates in registers" },
840 {"delayed-branch", &flag_delayed_branch, 1,
841 "Attempt to fill delay slots of branch instructions" },
842 {"gcse", &flag_gcse, 1,
843 "Perform the global common subexpression elimination" },
844 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
845 "Run CSE pass after loop optimisations"},
846 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
847 "Run the loop optimiser twice"},
848 {"pretend-float", &flag_pretend_float, 1,
849 "Pretend that host and target use the same FP format"},
850 {"schedule-insns", &flag_schedule_insns, 1,
851 "Reschedule instructions to avoid pipeline stalls"},
852 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
853 "Run two passes of the instruction scheduler"},
854 #ifdef HAIFA
855 {"sched-interblock",&flag_schedule_interblock, 1,
856 "Enable scheduling across basic blocks" },
857 {"sched-spec",&flag_schedule_speculative, 1,
858 "Allow speculative motion of non-loads" },
859 {"sched-spec-load",&flag_schedule_speculative_load, 1,
860 "Allow speculative motion of some loads" },
861 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
862 "Allow speculative motion of more loads" },
863 {"branch-count-reg",&flag_branch_on_count_reg, 1,
864 "Replace add,compare,branch with branch on count reg"},
865 #endif /* HAIFA */
866 {"pic", &flag_pic, 1,
867 "Generate position independent code, if possible"},
868 {"PIC", &flag_pic, 2, ""},
869 {"exceptions", &flag_exceptions, 1,
870 "Enable exception handling" },
871 {"new-exceptions", &flag_new_exceptions, 1,
872 "Use the new model for exception handling" },
873 {"sjlj-exceptions", &exceptions_via_longjmp, 1,
874 "Use setjmp/longjmp to handle exceptions" },
875 {"asynchronous-exceptions", &asynchronous_exceptions, 1,
876 "Support asynchronous exceptions" },
877 {"profile-arcs", &profile_arc_flag, 1,
878 "Insert arc based program profiling code" },
879 {"test-coverage", &flag_test_coverage, 1,
880 "Create data files needed by gcov" },
881 {"branch-probabilities", &flag_branch_probabilities, 1,
882 "Use profiling information for branch porbabilities" },
883 {"fast-math", &flag_fast_math, 1,
884 "Improve FP speed by violating ANSI & IEEE rules" },
885 {"common", &flag_no_common, 0,
886 "Do not put unitialised globals in the common section" },
887 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
888 "Do not generate .size directives" },
889 {"function-sections", &flag_function_sections, 1,
890 "place each function into its own section" },
891 {"verbose-asm", &flag_verbose_asm, 1,
892 "Add extra commentry to assembler output"},
893 {"gnu-linker", &flag_gnu_linker, 1,
894 "Output GNU ld formatted global initialisers"},
895 {"regmove", &flag_regmove, 1,
896 "Enables a regoster move optimisation"},
897 {"optimize-register-move", &flag_regmove, 1},
898 {"pack-struct", &flag_pack_struct, 1,
899 "Pack structure members together without holes" },
900 {"stack-check", &flag_stack_check, 1,
901 "Insert stack checking code into the program" },
902 {"argument-alias", &flag_argument_noalias, 0,
903 "Specify that arguments may alias each other & globals"},
904 {"argument-noalias", &flag_argument_noalias, 1,
905 "Assume arguments may alias globals but not each other"},
906 {"argument-noalias-global", &flag_argument_noalias, 2,
907 "Assume arguments do not alias each other or globals" },
908 {"strict-aliasing", &flag_strict_aliasing, 1,
909 "Assume strict aliasing rules apply" },
910 {"check-memory-usage", &flag_check_memory_usage, 1,
911 "Generate code to check every memory access" },
912 {"prefix-function-name", &flag_prefix_function_name, 1,
913 "Add a prefix to all function names" },
914 {"dump-unnumbered", &flag_dump_unnumbered, 1},
915 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
916 "Instrument function entry/exit with profiling calls"},
919 #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0]))
921 /* Table of language-specific options. */
923 static struct lang_opt
925 char * option;
926 char * description;
928 documented_lang_options[] =
930 /* In order not to overload the --help output, the convention
931 used here is to only describe those options which are not
932 enabled by default. */
934 { "-ansi", "Compile just for ANSI C" },
935 { "-fallow-single-precision",
936 "Do not promote floats to double if using -traditional" },
938 { "-fsigned-bitfields", "" },
939 { "-funsigned-bitfields","Make bitfields by unsigned by default" },
940 { "-fno-signed-bitfields", "" },
941 { "-fno-unsigned-bitfields","" },
942 { "-fsigned-char", "Make 'char' be signed by default"},
943 { "-funsigned-char", "Make 'char' be unsigned by default"},
944 { "-fno-signed-char", "" },
945 { "-fno-unsigned-char", "" },
947 { "-ftraditional", "" },
948 { "-traditional", "Attempt to support traditional K&R style C"},
949 { "-fnotraditional", "" },
950 { "-fno-traditional", "" },
952 { "-fasm", "" },
953 { "-fno-asm", "Do not recognise the 'asm' keyword" },
954 { "-fbuiltin", "" },
955 { "-fno-builtin", "Do not recognise any built in functions" },
956 { "-fhosted", "Assume normal C execution environment" },
957 { "-fno-hosted", "" },
958 { "-ffreestanding",
959 "Assume that standard libraries & main might not exist" },
960 { "-fno-freestanding", "" },
961 { "-fcond-mismatch", "Allow different types as args of ? operator"},
962 { "-fno-cond-mismatch", "" },
963 { "-fdollars-in-identifiers", "Allow the use of $ inside indentifiers" },
964 { "-fno-dollars-in-identifiers", "" },
965 { "-fident", "" },
966 { "-fno-ident", "Ignore #ident directives" },
967 { "-fshort-double", "Use the same size for double as for float" },
968 { "-fno-short-double", "" },
969 { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
970 { "-fno-short-enums", "" },
972 { "-Wall", "Enable most warning messages" },
973 { "-Wbad-function-cast",
974 "Warn about casting functions to incompatible types" },
975 { "-Wno-bad-function-cast", "" },
976 { "-Wcast-qual", "Warn about casts which discard qualifiers"},
977 { "-Wno-cast-qual", "" },
978 { "-Wchar-subscripts", "Warn about subscripts whoes type is 'char'"},
979 { "-Wno-char-subscripts", "" },
980 { "-Wcomment", "Warn if nested comments are detected" },
981 { "-Wno-comment", },
982 { "-Wcomments", },
983 { "-Wno-comments", },
984 { "-Wconversion", "Warn about possibly confusing type conversions" },
985 { "-Wno-conversion", "" },
986 { "-Wformat", "Warn about printf format anomalies" },
987 { "-Wno-format", "" },
988 { "-Wimplicit-function-declaration",
989 "Warn about implicit function declarations" },
990 { "-Wno-implicit-function-declaration", "" },
991 { "-Werror-implicit-function-declaration", "" },
992 { "-Wimplicit-int", "Warn when a declaration does not specify a type" },
993 { "-Wno-implicit-int", "" },
994 { "-Wimplicit", "" },
995 { "-Wno-implicit", "" },
996 { "-Wimport", "Warn about the use of the #import directive" },
997 { "-Wno-import", "" },
998 { "-Wlong-long","" },
999 { "-Wno-long-long", "Do not warn about using 'long long' when -pedantic" },
1000 { "-Wmain", "Warn about suspicious declarations of main" },
1001 { "-Wno-main", "" },
1002 { "-Wmissing-braces",
1003 "Warn about possibly missing braces around initialisers" },
1004 { "-Wno-missing-braces", "" },
1005 { "-Wmissing-declarations",
1006 "Warn about global funcs without previous declarations"},
1007 { "-Wno-missing-declarations", "" },
1008 { "-Wmissing-prototypes", "Warn about global funcs without prototypes" },
1009 { "-Wno-missing-prototypes", "" },
1010 { "-Wmultichar", "Warn about use of multicharacter literals"},
1011 { "-Wno-multichar", "" },
1012 { "-Wnested-externs", "Warn about externs not at file scope level" },
1013 { "-Wno-nested-externs", "" },
1014 { "-Wparentheses", "Warn about possible missing parentheses" },
1015 { "-Wno-parentheses", "" },
1016 { "-Wpointer-arith", "Warn about function pointer arithmetic" },
1017 { "-Wno-pointer-arith", "" },
1018 { "-Wredundant-decls",
1019 "Warn about multiple declarations of the same object" },
1020 { "-Wno-redundant-decls", "" },
1021 { "-Wsign-compare", "Warn about signed/unsigned comparisons" },
1022 { "-Wno-sign-compare", "" },
1023 { "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
1024 { "-Wno-unknown-pragmas", "" },
1025 { "-Wstrict-prototypes", "Warn about non-prototyped function decls" },
1026 { "-Wno-strict-prototypes", "" },
1027 { "-Wtraditional", "Warn about constructs whoes meaning change in ANSI C"},
1028 { "-Wno-traditional", "" },
1029 { "-Wtrigraphs", "Warn when trigraphs are encountered" },
1030 { "-Wno-trigraphs", "" },
1031 { "-Wundef", "" },
1032 { "-Wno-undef", "" },
1033 { "-Wwrite-strings", "Mark strings as 'const char *'"},
1034 { "-Wno-write-strings", "" },
1036 /* These are for languages with USE_CPPLIB. */
1037 /* These options are already documented in cpplib.c */
1038 { "--help", "" },
1039 { "-A", "" },
1040 { "-D", "" },
1041 { "-I", "" },
1042 { "-U", "" },
1043 { "-idirafter", "" },
1044 { "-iprefix", "" },
1045 { "-isystem", "" },
1046 { "-lang-c", "" },
1047 { "-lang-c89", "" },
1048 { "-lang-c++", "" },
1049 { "-nostdinc", "" },
1050 { "-nostdinc++", "" },
1051 { "-trigraphs", "" },
1052 { "-undef", "" },
1053 { "-remap", "" },
1055 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1057 /* These are for obj c. */
1058 DEFINE_LANG_NAME ("Objective C")
1060 { "-lang-objc", "" },
1061 { "-gen-decls", "Dump decls to a .decl file" },
1062 { "-fgnu-runtime", "Generate code for GNU runtime envrionment" },
1063 { "-fno-gnu-runtime", "" },
1064 { "-fnext-runtime", "Generate code for NeXT runtime environment" },
1065 { "-fno-next-runtime", "" },
1066 { "-Wselector", "Warn if a selector has multiple methods" },
1067 { "-Wno-selector", "" },
1068 { "-Wprotocol", "" },
1069 { "-Wno-protocol", "Do not warn if inherited methods are unimplemented"},
1070 { "-print-objc-runtime-info",
1071 "Generate C header of platform specific features" },
1073 #include "options.h"
1077 /* Here is a table, controlled by the tm.h file, listing each -m switch
1078 and which bits in `target_switches' it should set or clear.
1079 If VALUE is positive, it is bits to set.
1080 If VALUE is negative, -VALUE is bits to clear.
1081 (The sign bit is not used so there is no confusion.) */
1083 struct
1085 char * name;
1086 int value;
1087 char * description;
1089 target_switches [] = TARGET_SWITCHES;
1091 /* This table is similar, but allows the switch to have a value. */
1093 #ifdef TARGET_OPTIONS
1094 struct
1096 char * prefix;
1097 char ** variable;
1098 char * description;
1100 target_options [] = TARGET_OPTIONS;
1101 #endif
1103 /* Options controlling warnings */
1105 /* Don't print warning messages. -w. */
1107 int inhibit_warnings = 0;
1109 /* Print various extra warnings. -W. */
1111 int extra_warnings = 0;
1113 /* Treat warnings as errors. -Werror. */
1115 int warnings_are_errors = 0;
1117 /* Nonzero to warn about unused local variables. */
1119 int warn_unused;
1121 /* Nonzero to warn about variables used before they are initialized. */
1123 int warn_uninitialized;
1125 /* Nonzero means warn about all declarations which shadow others. */
1127 int warn_shadow;
1129 /* Warn if a switch on an enum fails to have a case for every enum value. */
1131 int warn_switch;
1133 /* Nonzero means warn about function definitions that default the return type
1134 or that use a null return and have a return-type other than void. */
1136 int warn_return_type;
1138 /* Nonzero means warn about pointer casts that increase the required
1139 alignment of the target type (and might therefore lead to a crash
1140 due to a misaligned access). */
1142 int warn_cast_align;
1144 /* Nonzero means warn about any identifiers that match in the first N
1145 characters. The value N is in `id_clash_len'. */
1147 int warn_id_clash;
1148 unsigned id_clash_len;
1150 /* Nonzero means warn about any objects definitions whose size is larger
1151 than N bytes. Also want about function definitions whose returned
1152 values are larger than N bytes. The value N is in `larger_than_size'. */
1154 int warn_larger_than;
1155 unsigned larger_than_size;
1157 /* Nonzero means warn if inline function is too large. */
1159 int warn_inline;
1161 /* Warn if a function returns an aggregate,
1162 since there are often incompatible calling conventions for doing this. */
1164 int warn_aggregate_return;
1166 /* Likewise for -W. */
1168 lang_independent_options W_options[] =
1170 {"unused", &warn_unused, 1, "Warn when a variable is unused" },
1171 {"error", &warnings_are_errors, 1, ""},
1172 {"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
1173 {"switch", &warn_switch, 1,
1174 "Warn about enumerated switches missing a specific case" },
1175 {"aggregate-return", &warn_aggregate_return, 1,
1176 "Warn about returning structures, unions or arrays" },
1177 {"cast-align", &warn_cast_align, 1,
1178 "Warn about pointer casts which increase alignment" },
1179 {"uninitialized", &warn_uninitialized, 1,
1180 "Warn about unitialized automatic variables"},
1181 {"inline", &warn_inline, 1,
1182 "Warn when an inlined function cannot be inlined"}
1185 /* Output files for assembler code (real compiler output)
1186 and debugging dumps. */
1188 FILE *asm_out_file;
1189 FILE *aux_info_file;
1190 FILE *rtl_dump_file = NULL;
1192 /* Time accumulators, to count the total time spent in various passes. */
1194 int parse_time;
1195 int varconst_time;
1196 int integration_time;
1197 int jump_time;
1198 int cse_time;
1199 int gcse_time;
1200 int loop_time;
1201 int cse2_time;
1202 int branch_prob_time;
1203 int flow_time;
1204 int combine_time;
1205 int regmove_time;
1206 int sched_time;
1207 int local_alloc_time;
1208 int global_alloc_time;
1209 int sched2_time;
1210 #ifdef DELAY_SLOTS
1211 int dbr_sched_time;
1212 #endif
1213 int shorten_branch_time;
1214 int stack_reg_time;
1215 int final_time;
1216 int symout_time;
1217 int dump_time;
1219 /* Return time used so far, in microseconds. */
1222 get_run_time ()
1224 if (quiet_flag)
1225 return 0;
1227 #ifdef __BEOS__
1228 return 0;
1229 #else /* not BeOS */
1230 #if defined (_WIN32) && !defined (__CYGWIN32__)
1231 if (clock() < 0)
1232 return 0;
1233 else
1234 return (clock() * 1000);
1235 #else /* not _WIN32 */
1236 #ifdef _SC_CLK_TCK
1238 static int tick;
1239 struct tms tms;
1240 if (tick == 0)
1241 tick = 1000000 / sysconf(_SC_CLK_TCK);
1242 times (&tms);
1243 return (tms.tms_utime + tms.tms_stime) * tick;
1245 #else
1246 #ifdef USG
1248 struct tms tms;
1249 # if HAVE_SYSCONF && defined _SC_CLK_TCK
1250 # define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
1251 # else
1252 # ifdef CLK_TCK
1253 # define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
1254 # else
1255 # define TICKS_PER_SECOND HZ /* traditional UNIX */
1256 # endif
1257 # endif
1258 times (&tms);
1259 return (tms.tms_utime + tms.tms_stime) * (1000000 / TICKS_PER_SECOND);
1261 #else
1262 #ifndef VMS
1264 struct rusage rusage;
1265 getrusage (0, &rusage);
1266 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1267 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1269 #else /* VMS */
1271 struct
1273 int proc_user_time;
1274 int proc_system_time;
1275 int child_user_time;
1276 int child_system_time;
1277 } vms_times;
1278 times ((void *) &vms_times);
1279 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
1281 #endif /* VMS */
1282 #endif /* USG */
1283 #endif /* _SC_CLK_TCK */
1284 #endif /* _WIN32 */
1285 #endif /* __BEOS__ */
1288 #define TIMEVAR(VAR, BODY) \
1289 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1291 void
1292 print_time (str, total)
1293 char *str;
1294 int total;
1296 fprintf (stderr,
1297 "time in %s: %d.%06d\n",
1298 str, total / 1000000, total % 1000000);
1301 /* Count an error or warning. Return 1 if the message should be printed. */
1304 count_error (warningp)
1305 int warningp;
1307 if (warningp && inhibit_warnings)
1308 return 0;
1310 if (warningp && !warnings_are_errors)
1311 warningcount++;
1312 else
1314 static int warning_message = 0;
1316 if (warningp && !warning_message)
1318 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
1319 warning_message = 1;
1321 errorcount++;
1324 return 1;
1327 /* Print a fatal error message. NAME is the text.
1328 Also include a system error message based on `errno'. */
1330 void
1331 pfatal_with_name (name)
1332 char *name;
1334 fprintf (stderr, "%s: ", progname);
1335 perror (name);
1336 exit (FATAL_EXIT_CODE);
1339 void
1340 fatal_io_error (name)
1341 char *name;
1343 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
1344 exit (FATAL_EXIT_CODE);
1347 /* Called to give a better error message for a bad insn rather than
1348 just calling abort(). */
1350 void
1351 fatal_insn (message, insn)
1352 char *message;
1353 rtx insn;
1355 error (message);
1356 debug_rtx (insn);
1357 if (asm_out_file)
1358 fflush (asm_out_file);
1359 if (aux_info_file)
1360 fflush (aux_info_file);
1361 if (rtl_dump_file != NULL)
1362 fflush (rtl_dump_file);
1363 fflush (stdout);
1364 fflush (stderr);
1365 abort ();
1368 /* Called to give a better error message when we don't have an insn to match
1369 what we are looking for or if the insn's constraints aren't satisfied,
1370 rather than just calling abort(). */
1372 void
1373 fatal_insn_not_found (insn)
1374 rtx insn;
1376 if (INSN_CODE (insn) < 0)
1377 fatal_insn ("internal error--unrecognizable insn:", insn);
1378 else
1379 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1382 /* This is the default decl_printable_name function. */
1384 static char *
1385 decl_name (decl, verbosity)
1386 tree decl;
1387 int verbosity ATTRIBUTE_UNUSED;
1389 return IDENTIFIER_POINTER (DECL_NAME (decl));
1392 static int need_error_newline;
1394 /* Function of last error message;
1395 more generally, function such that if next error message is in it
1396 then we don't have to mention the function name. */
1397 static tree last_error_function = NULL;
1399 /* Used to detect when input_file_stack has changed since last described. */
1400 static int last_error_tick;
1402 /* Called when the start of a function definition is parsed,
1403 this function prints on stderr the name of the function. */
1405 void
1406 announce_function (decl)
1407 tree decl;
1409 if (! quiet_flag)
1411 if (rtl_dump_and_exit)
1412 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1413 else
1414 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1415 fflush (stderr);
1416 need_error_newline = 1;
1417 last_error_function = current_function_decl;
1421 /* The default function to print out name of current function that caused
1422 an error. */
1424 void
1425 default_print_error_function (file)
1426 char *file;
1428 if (last_error_function != current_function_decl)
1430 char *kind = "function";
1431 if (current_function_decl != 0
1432 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1433 kind = "method";
1435 if (file)
1436 fprintf (stderr, "%s: ", file);
1438 if (current_function_decl == NULL)
1439 fprintf (stderr, "At top level:\n");
1440 else
1442 char *name = (*decl_printable_name) (current_function_decl, 2);
1443 fprintf (stderr, "In %s `%s':\n", kind, name);
1446 last_error_function = current_function_decl;
1450 /* Called by report_error_function to print out function name.
1451 * Default may be overridden by language front-ends. */
1453 void (*print_error_function) PROTO((char *)) = default_print_error_function;
1455 /* Prints out, if necessary, the name of the current function
1456 that caused an error. Called from all error and warning functions. */
1458 void
1459 report_error_function (file)
1460 char *file;
1462 struct file_stack *p;
1464 if (need_error_newline)
1466 fprintf (stderr, "\n");
1467 need_error_newline = 0;
1470 (*print_error_function) (file);
1472 if (input_file_stack && input_file_stack->next != 0
1473 && input_file_stack_tick != last_error_tick
1474 && file == input_filename)
1476 fprintf (stderr, "In file included");
1477 for (p = input_file_stack->next; p; p = p->next)
1479 fprintf (stderr, " from %s:%d", p->name, p->line);
1480 if (p->next)
1481 fprintf (stderr, ",\n ");
1483 fprintf (stderr, ":\n");
1484 last_error_tick = input_file_stack_tick;
1488 /* Print a message. */
1490 static void
1491 vmessage (prefix, s, ap)
1492 char *prefix;
1493 char *s;
1494 va_list ap;
1496 if (prefix)
1497 fprintf (stderr, "%s: ", prefix);
1499 vfprintf (stderr, s, ap);
1502 /* Print a message relevant to line LINE of file FILE. */
1504 static void
1505 v_message_with_file_and_line (file, line, prefix, s, ap)
1506 char *file;
1507 int line;
1508 char *prefix;
1509 char *s;
1510 va_list ap;
1512 if (file)
1513 fprintf (stderr, "%s:%d: ", file, line);
1514 else
1515 fprintf (stderr, "%s: ", progname);
1517 vmessage (prefix, s, ap);
1518 fputc ('\n', stderr);
1521 /* Print a message relevant to the given DECL. */
1523 static void
1524 v_message_with_decl (decl, prefix, s, ap)
1525 tree decl;
1526 char *prefix;
1527 char *s;
1528 va_list ap;
1530 char *p;
1532 fprintf (stderr, "%s:%d: ",
1533 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1535 if (prefix)
1536 fprintf (stderr, "%s: ", prefix);
1538 /* Do magic to get around lack of varargs support for insertion
1539 of arguments into existing list. We know that the decl is first;
1540 we ass_u_me that it will be printed with "%s". */
1542 for (p = s; *p; ++p)
1544 if (*p == '%')
1546 if (*(p + 1) == '%')
1547 ++p;
1548 else
1549 break;
1553 if (p > s) /* Print the left-hand substring. */
1555 char fmt[sizeof "%.255s"];
1556 long width = p - s;
1558 if (width > 255L) width = 255L; /* arbitrary */
1559 sprintf (fmt, "%%.%lds", width);
1560 fprintf (stderr, fmt, s);
1563 if (*p == '%') /* Print the name. */
1565 char *n = (DECL_NAME (decl)
1566 ? (*decl_printable_name) (decl, 2)
1567 : "((anonymous))");
1568 fputs (n, stderr);
1569 while (*p)
1571 ++p;
1572 if (ISALPHA (*(p - 1) & 0xFF))
1573 break;
1577 if (*p) /* Print the rest of the message. */
1578 vmessage ((char *)NULL, p, ap);
1580 fputc ('\n', stderr);
1583 /* Figure file and line of the given INSN. */
1585 static void
1586 file_and_line_for_asm (insn, pfile, pline)
1587 rtx insn;
1588 char **pfile;
1589 int *pline;
1591 rtx body = PATTERN (insn);
1592 rtx asmop;
1594 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1595 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1596 asmop = SET_SRC (body);
1597 else if (GET_CODE (body) == ASM_OPERANDS)
1598 asmop = body;
1599 else if (GET_CODE (body) == PARALLEL
1600 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1601 asmop = SET_SRC (XVECEXP (body, 0, 0));
1602 else if (GET_CODE (body) == PARALLEL
1603 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1604 asmop = XVECEXP (body, 0, 0);
1605 else
1606 asmop = NULL;
1608 if (asmop)
1610 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1611 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1613 else
1615 *pfile = input_filename;
1616 *pline = lineno;
1620 /* Report an error at line LINE of file FILE. */
1622 static void
1623 v_error_with_file_and_line (file, line, s, ap)
1624 char *file;
1625 int line;
1626 char *s;
1627 va_list ap;
1629 count_error (0);
1630 report_error_function (file);
1631 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1634 void
1635 error_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1637 #ifndef __STDC__
1638 char *file;
1639 int line;
1640 char *s;
1641 #endif
1642 va_list ap;
1644 VA_START (ap, s);
1646 #ifndef __STDC__
1647 file = va_arg (ap, char *);
1648 line = va_arg (ap, int);
1649 s = va_arg (ap, char *);
1650 #endif
1652 v_error_with_file_and_line (file, line, s, ap);
1653 va_end (ap);
1656 /* Report an error at the declaration DECL.
1657 S is a format string which uses %s to substitute the declaration
1658 name; subsequent substitutions are a la printf. */
1660 static void
1661 v_error_with_decl (decl, s, ap)
1662 tree decl;
1663 char *s;
1664 va_list ap;
1666 count_error (0);
1667 report_error_function (DECL_SOURCE_FILE (decl));
1668 v_message_with_decl (decl, (char *)NULL, s, ap);
1671 void
1672 error_with_decl VPROTO((tree decl, char *s, ...))
1674 #ifndef __STDC__
1675 tree decl;
1676 char *s;
1677 #endif
1678 va_list ap;
1680 VA_START (ap, s);
1682 #ifndef __STDC__
1683 decl = va_arg (ap, tree);
1684 s = va_arg (ap, char *);
1685 #endif
1687 v_error_with_decl (decl, s, ap);
1688 va_end (ap);
1691 /* Report an error at the line number of the insn INSN.
1692 This is used only when INSN is an `asm' with operands,
1693 and each ASM_OPERANDS records its own source file and line. */
1695 static void
1696 v_error_for_asm (insn, s, ap)
1697 rtx insn;
1698 char *s;
1699 va_list ap;
1701 char *file;
1702 int line;
1704 count_error (0);
1705 file_and_line_for_asm (insn, &file, &line);
1706 report_error_function (file);
1707 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1710 void
1711 error_for_asm VPROTO((rtx insn, char *s, ...))
1713 #ifndef __STDC__
1714 rtx insn;
1715 char *s;
1716 #endif
1717 va_list ap;
1719 VA_START (ap, s);
1721 #ifndef __STDC__
1722 insn = va_arg (ap, rtx);
1723 s = va_arg (ap, char *);
1724 #endif
1726 v_error_for_asm (insn, s, ap);
1727 va_end (ap);
1730 /* Report an error at the current line number. */
1732 static void
1733 verror (s, ap)
1734 char *s;
1735 va_list ap;
1737 v_error_with_file_and_line (input_filename, lineno, s, ap);
1740 void
1741 error VPROTO((char *s, ...))
1743 #ifndef __STDC__
1744 char *s;
1745 #endif
1746 va_list ap;
1748 VA_START (ap, s);
1750 #ifndef __STDC__
1751 s = va_arg (ap, char *);
1752 #endif
1754 verror (s, ap);
1755 va_end (ap);
1758 /* Report a fatal error at the current line number. */
1760 static void
1761 vfatal (s, ap)
1762 char *s;
1763 va_list ap;
1765 verror (s, ap);
1766 exit (FATAL_EXIT_CODE);
1769 void
1770 fatal VPROTO((char *s, ...))
1772 #ifndef __STDC__
1773 char *s;
1774 #endif
1775 va_list ap;
1777 VA_START (ap, s);
1779 #ifndef __STDC__
1780 s = va_arg (ap, char *);
1781 #endif
1783 vfatal (s, ap);
1784 va_end (ap);
1787 /* Report a warning at line LINE of file FILE. */
1789 static void
1790 v_warning_with_file_and_line (file, line, s, ap)
1791 char *file;
1792 int line;
1793 char *s;
1794 va_list ap;
1796 if (count_error (1))
1798 report_error_function (file);
1799 v_message_with_file_and_line (file, line, "warning", s, ap);
1803 void
1804 warning_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1806 #ifndef __STDC__
1807 char *file;
1808 int line;
1809 char *s;
1810 #endif
1811 va_list ap;
1813 VA_START (ap, s);
1815 #ifndef __STDC__
1816 file = va_arg (ap, char *);
1817 line = va_arg (ap, int);
1818 s = va_arg (ap, char *);
1819 #endif
1821 v_warning_with_file_and_line (file, line, s, ap);
1822 va_end (ap);
1825 /* Report a warning at the declaration DECL.
1826 S is a format string which uses %s to substitute the declaration
1827 name; subsequent substitutions are a la printf. */
1829 static void
1830 v_warning_with_decl (decl, s, ap)
1831 tree decl;
1832 char *s;
1833 va_list ap;
1835 if (count_error (1))
1837 report_error_function (DECL_SOURCE_FILE (decl));
1838 v_message_with_decl (decl, "warning", s, ap);
1842 void
1843 warning_with_decl VPROTO((tree decl, char *s, ...))
1845 #ifndef __STDC__
1846 tree decl;
1847 char *s;
1848 #endif
1849 va_list ap;
1851 VA_START (ap, s);
1853 #ifndef __STDC__
1854 decl = va_arg (ap, tree);
1855 s = va_arg (ap, char *);
1856 #endif
1858 v_warning_with_decl (decl, s, ap);
1859 va_end (ap);
1862 /* Report a warning at the line number of the insn INSN.
1863 This is used only when INSN is an `asm' with operands,
1864 and each ASM_OPERANDS records its own source file and line. */
1866 static void
1867 v_warning_for_asm (insn, s, ap)
1868 rtx insn;
1869 char *s;
1870 va_list ap;
1872 if (count_error (1))
1874 char *file;
1875 int line;
1877 file_and_line_for_asm (insn, &file, &line);
1878 report_error_function (file);
1879 v_message_with_file_and_line (file, line, "warning", s, ap);
1883 void
1884 warning_for_asm VPROTO((rtx insn, char *s, ...))
1886 #ifndef __STDC__
1887 rtx insn;
1888 char *s;
1889 #endif
1890 va_list ap;
1892 VA_START (ap, s);
1894 #ifndef __STDC__
1895 insn = va_arg (ap, rtx);
1896 s = va_arg (ap, char *);
1897 #endif
1899 v_warning_for_asm (insn, s, ap);
1900 va_end (ap);
1903 /* Report a warning at the current line number. */
1905 static void
1906 vwarning (s, ap)
1907 char *s;
1908 va_list ap;
1910 v_warning_with_file_and_line (input_filename, lineno, s, ap);
1913 void
1914 warning VPROTO((char *s, ...))
1916 #ifndef __STDC__
1917 char *s;
1918 #endif
1919 va_list ap;
1921 VA_START (ap, s);
1923 #ifndef __STDC__
1924 s = va_arg (ap, char *);
1925 #endif
1927 vwarning (s, ap);
1928 va_end (ap);
1931 /* These functions issue either warnings or errors depending on
1932 -pedantic-errors. */
1934 static void
1935 vpedwarn (s, ap)
1936 char *s;
1937 va_list ap;
1939 if (flag_pedantic_errors)
1940 verror (s, ap);
1941 else
1942 vwarning (s, ap);
1945 void
1946 pedwarn VPROTO((char *s, ...))
1948 #ifndef __STDC__
1949 char *s;
1950 #endif
1951 va_list ap;
1953 VA_START (ap, s);
1955 #ifndef __STDC__
1956 s = va_arg (ap, char *);
1957 #endif
1959 vpedwarn (s, ap);
1960 va_end (ap);
1963 static void
1964 v_pedwarn_with_decl (decl, s, ap)
1965 tree decl;
1966 char *s;
1967 va_list ap;
1969 /* We don't want -pedantic-errors to cause the compilation to fail from
1970 "errors" in system header files. Sometimes fixincludes can't fix what's
1971 broken (eg: unsigned char bitfields - fixing it may change the alignment
1972 which will cause programs to mysteriously fail because the C library
1973 or kernel uses the original layout). There's no point in issuing a
1974 warning either, it's just unnecessary noise. */
1976 if (! DECL_IN_SYSTEM_HEADER (decl))
1978 if (flag_pedantic_errors)
1979 v_error_with_decl (decl, s, ap);
1980 else
1981 v_warning_with_decl (decl, s, ap);
1985 void
1986 pedwarn_with_decl VPROTO((tree decl, char *s, ...))
1988 #ifndef __STDC__
1989 tree decl;
1990 char *s;
1991 #endif
1992 va_list ap;
1994 VA_START (ap, s);
1996 #ifndef __STDC__
1997 decl = va_arg (ap, tree);
1998 s = va_arg (ap, char *);
1999 #endif
2001 v_pedwarn_with_decl (decl, s, ap);
2002 va_end (ap);
2005 static void
2006 v_pedwarn_with_file_and_line (file, line, s, ap)
2007 char *file;
2008 int line;
2009 char *s;
2010 va_list ap;
2012 if (flag_pedantic_errors)
2013 v_error_with_file_and_line (file, line, s, ap);
2014 else
2015 v_warning_with_file_and_line (file, line, s, ap);
2018 void
2019 pedwarn_with_file_and_line VPROTO((char *file, int line, char *s, ...))
2021 #ifndef __STDC__
2022 char *file;
2023 int line;
2024 char *s;
2025 #endif
2026 va_list ap;
2028 VA_START (ap, s);
2030 #ifndef __STDC__
2031 file = va_arg (ap, char *);
2032 line = va_arg (ap, int);
2033 s = va_arg (ap, char *);
2034 #endif
2036 v_pedwarn_with_file_and_line (file, line, s, ap);
2037 va_end (ap);
2040 /* Apologize for not implementing some feature. */
2042 static void
2043 vsorry (s, ap)
2044 char *s;
2045 va_list ap;
2047 sorrycount++;
2048 if (input_filename)
2049 fprintf (stderr, "%s:%d: ", input_filename, lineno);
2050 else
2051 fprintf (stderr, "%s: ", progname);
2052 vmessage ("sorry, not implemented", s, ap);
2053 fputc ('\n', stderr);
2056 void
2057 sorry VPROTO((char *s, ...))
2059 #ifndef __STDC__
2060 char *s;
2061 #endif
2062 va_list ap;
2064 VA_START (ap, s);
2066 #ifndef __STDC__
2067 s = va_arg (ap, char *);
2068 #endif
2070 vsorry (s, ap);
2071 va_end (ap);
2074 /* Apologize for not implementing some feature, then quit. */
2076 static void
2077 v_really_sorry (s, ap)
2078 char *s;
2079 va_list ap;
2081 sorrycount++;
2082 if (input_filename)
2083 fprintf (stderr, "%s:%d: ", input_filename, lineno);
2084 else
2085 fprintf (stderr, "%s: ", progname);
2086 vmessage ("sorry, not implemented", s, ap);
2087 fatal (" (fatal)\n");
2090 void
2091 really_sorry VPROTO((char *s, ...))
2093 #ifndef __STDC__
2094 char *s;
2095 #endif
2096 va_list ap;
2098 VA_START (ap, s);
2100 #ifndef __STDC__
2101 s = va_arg (ap, char *);
2102 #endif
2104 v_really_sorry (s, ap);
2105 va_end (ap);
2108 /* More 'friendly' abort that prints the line and file.
2109 config.h can #define abort fancy_abort if you like that sort of thing.
2111 I don't think this is actually a good idea.
2112 Other sorts of crashes will look a certain way.
2113 It is a good thing if crashes from calling abort look the same way.
2114 -- RMS */
2116 void
2117 fancy_abort ()
2119 fatal ("internal gcc abort");
2122 /* This calls abort and is used to avoid problems when abort if a macro.
2123 It is used when we need to pass the address of abort. */
2125 void
2126 do_abort ()
2128 abort ();
2131 /* When `malloc.c' is compiled with `rcheck' defined,
2132 it calls this function to report clobberage. */
2134 void
2135 botch (s)
2136 char * s ATTRIBUTE_UNUSED;
2138 abort ();
2141 /* Same as `malloc' but report error if no memory available. */
2143 char *
2144 xmalloc (size)
2145 unsigned size;
2147 register char *value;
2149 if (size == 0)
2150 size = 1;
2152 value = (char *) malloc (size);
2153 if (value == 0)
2154 fatal ("virtual memory exhausted");
2155 return value;
2158 /* Same as `calloc' but report error if no memory available. */
2160 char *
2161 xcalloc (size1, size2)
2162 unsigned size1, size2;
2164 register char *value;
2166 if (size1 == 0 || size2 == 0)
2167 size1 = size2 = 1;
2169 value = (char *) calloc (size1, size2);
2170 if (value == 0)
2171 fatal ("virtual memory exhausted");
2172 return value;
2176 /* Same as `realloc' but report error if no memory available.
2177 Also handle null PTR even if the vendor realloc gets it wrong. */
2179 char *
2180 xrealloc (ptr, size)
2181 char *ptr;
2182 int size;
2184 char *result;
2186 if (size == 0)
2187 size = 1;
2189 result = (ptr
2190 ? (char *) realloc (ptr, size)
2191 : (char *) malloc (size));
2193 if (!result)
2194 fatal ("virtual memory exhausted");
2196 return result;
2199 /* Same as `strdup' but report error if no memory available. */
2201 char *
2202 xstrdup (s)
2203 register char *s;
2205 register char *result = (char *) malloc (strlen (s) + 1);
2207 if (! result)
2208 fatal ("virtual memory exhausted");
2209 strcpy (result, s);
2210 return result;
2213 /* Return the logarithm of X, base 2, considering X unsigned,
2214 if X is a power of 2. Otherwise, returns -1.
2216 This should be used via the `exact_log2' macro. */
2219 exact_log2_wide (x)
2220 register unsigned HOST_WIDE_INT x;
2222 register int log = 0;
2223 /* Test for 0 or a power of 2. */
2224 if (x == 0 || x != (x & -x))
2225 return -1;
2226 while ((x >>= 1) != 0)
2227 log++;
2228 return log;
2231 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
2232 If X is 0, return -1.
2234 This should be used via the floor_log2 macro. */
2237 floor_log2_wide (x)
2238 register unsigned HOST_WIDE_INT x;
2240 register int log = -1;
2241 while (x != 0)
2242 log++,
2243 x >>= 1;
2244 return log;
2247 static int float_handler_set;
2248 int float_handled;
2249 jmp_buf float_handler;
2251 /* Signals actually come here. */
2253 static void
2254 float_signal (signo)
2255 /* If this is missing, some compilers complain. */
2256 int signo ATTRIBUTE_UNUSED;
2258 if (float_handled == 0)
2259 abort ();
2260 #if defined (USG) || defined (hpux)
2261 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
2262 #endif
2263 float_handled = 0;
2264 signal (SIGFPE, float_signal);
2265 longjmp (float_handler, 1);
2268 /* Specify where to longjmp to when a floating arithmetic error happens.
2269 If HANDLER is 0, it means don't handle the errors any more. */
2271 void
2272 set_float_handler (handler)
2273 jmp_buf handler;
2275 float_handled = (handler != 0);
2276 if (handler)
2277 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2279 if (float_handled && ! float_handler_set)
2281 signal (SIGFPE, float_signal);
2282 float_handler_set = 1;
2286 /* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2287 error happens, pushing the previous specification into OLD_HANDLER.
2288 Return an indication of whether there was a previous handler in effect. */
2291 push_float_handler (handler, old_handler)
2292 jmp_buf handler, old_handler;
2294 int was_handled = float_handled;
2296 float_handled = 1;
2297 if (was_handled)
2298 memcpy ((char *) old_handler, (char *) float_handler,
2299 sizeof (float_handler));
2301 memcpy ((char *) float_handler, (char *) handler, sizeof (float_handler));
2302 return was_handled;
2305 /* Restore the previous specification of whether and where to longjmp to
2306 when a floating arithmetic error happens. */
2308 void
2309 pop_float_handler (handled, handler)
2310 int handled;
2311 jmp_buf handler;
2313 float_handled = handled;
2314 if (handled)
2315 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2318 /* Handler for SIGPIPE. */
2320 static void
2321 pipe_closed (signo)
2322 /* If this is missing, some compilers complain. */
2323 int signo ATTRIBUTE_UNUSED;
2325 fatal ("output pipe has been closed");
2328 /* Strip off a legitimate source ending from the input string NAME of
2329 length LEN. Rather than having to know the names used by all of
2330 our front ends, we strip off an ending of a period followed by
2331 up to five characters. (Java uses ".class".) */
2333 void
2334 strip_off_ending (name, len)
2335 char *name;
2336 int len;
2338 int i;
2339 for (i = 2; i < 6 && len > i; i++)
2341 if (name[len - i] == '.')
2343 name[len - i] = '\0';
2344 break;
2349 /* Output a quoted string. */
2351 void
2352 output_quoted_string (asm_file, string)
2353 FILE *asm_file;
2354 char *string;
2356 #ifdef OUTPUT_QUOTED_STRING
2357 OUTPUT_QUOTED_STRING (asm_file, string);
2358 #else
2359 char c;
2361 putc ('\"', asm_file);
2362 while ((c = *string++) != 0)
2364 if (c == '\"' || c == '\\')
2365 putc ('\\', asm_file);
2366 putc (c, asm_file);
2368 putc ('\"', asm_file);
2369 #endif
2372 /* Output a file name in the form wanted by System V. */
2374 void
2375 output_file_directive (asm_file, input_name)
2376 FILE *asm_file;
2377 char *input_name;
2379 int len = strlen (input_name);
2380 char *na = input_name + len;
2382 /* NA gets INPUT_NAME sans directory names. */
2383 while (na > input_name)
2385 if (na[-1] == '/')
2386 break;
2387 na--;
2390 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2391 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2392 #else
2393 #ifdef ASM_OUTPUT_SOURCE_FILENAME
2394 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2395 #else
2396 fprintf (asm_file, "\t.file\t");
2397 output_quoted_string (asm_file, na);
2398 fputc ('\n', asm_file);
2399 #endif
2400 #endif
2403 /* Routine to build language identifier for object file. */
2405 static void
2406 output_lang_identify (asm_out_file)
2407 FILE *asm_out_file;
2409 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2410 char *s = (char *) alloca (len);
2411 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2412 ASM_OUTPUT_LABEL (asm_out_file, s);
2415 /* Routine to open a dump file. */
2416 static void
2417 open_dump_file (suffix, function_name)
2418 char *suffix;
2419 char *function_name;
2421 char *dumpname;
2423 TIMEVAR
2424 (dump_time,
2426 dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
2428 if (rtl_dump_file != NULL)
2429 fclose (rtl_dump_file);
2431 strcpy (dumpname, dump_base_name);
2432 strcat (dumpname, suffix);
2434 rtl_dump_file = fopen (dumpname, "a");
2436 if (rtl_dump_file == NULL)
2437 pfatal_with_name (dumpname);
2439 free (dumpname);
2441 if (function_name)
2442 fprintf (rtl_dump_file, "\n;; Function %s\n\n", function_name);
2445 return;
2448 /* Routine to close a dump file. */
2449 static void
2450 close_dump_file (func, insns)
2451 void (*func) PROTO ((FILE *, rtx));
2452 rtx insns;
2454 TIMEVAR
2455 (dump_time,
2457 if (func)
2458 func (rtl_dump_file, insns);
2460 fflush (rtl_dump_file);
2461 fclose (rtl_dump_file);
2463 rtl_dump_file = NULL;
2466 return;
2469 /* Routine to dump rtl into a file. */
2470 static void
2471 dump_rtl (suffix, decl, func, insns)
2472 char *suffix;
2473 tree decl;
2474 void (*func) PROTO ((FILE *, rtx));
2475 rtx insns;
2477 open_dump_file (suffix, decl_printable_name (decl, 2));
2478 close_dump_file (func, insns);
2481 /* Routine to empty a dump file. */
2482 static void
2483 clean_dump_file (suffix)
2484 char * suffix;
2486 char * dumpname;
2488 dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
2490 strcpy (dumpname, dump_base_name);
2491 strcat (dumpname, suffix);
2493 rtl_dump_file = fopen (dumpname, "w");
2495 if (rtl_dump_file == NULL)
2496 pfatal_with_name (dumpname);
2498 free (dumpname);
2500 fclose (rtl_dump_file);
2501 rtl_dump_file = NULL;
2503 return;
2507 /* Compile an entire file of output from cpp, named NAME.
2508 Write a file of assembly output and various debugging dumps. */
2510 static void
2511 compile_file (name)
2512 char *name;
2514 tree globals;
2515 int start_time;
2517 int name_specified = name != 0;
2519 if (dump_base_name == 0)
2520 dump_base_name = name ? name : "gccdump";
2522 parse_time = 0;
2523 varconst_time = 0;
2524 integration_time = 0;
2525 jump_time = 0;
2526 cse_time = 0;
2527 gcse_time = 0;
2528 loop_time = 0;
2529 cse2_time = 0;
2530 branch_prob_time = 0;
2531 flow_time = 0;
2532 combine_time = 0;
2533 regmove_time = 0;
2534 sched_time = 0;
2535 local_alloc_time = 0;
2536 global_alloc_time = 0;
2537 sched2_time = 0;
2538 #ifdef DELAY_SLOTS
2539 dbr_sched_time = 0;
2540 #endif
2541 shorten_branch_time = 0;
2542 stack_reg_time = 0;
2543 final_time = 0;
2544 symout_time = 0;
2545 dump_time = 0;
2547 /* Initialize data in various passes. */
2549 init_obstacks ();
2550 init_tree_codes ();
2551 name = init_parse (name);
2552 init_rtl ();
2553 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2554 || debug_info_level == DINFO_LEVEL_VERBOSE
2555 || flag_test_coverage);
2556 init_regs ();
2557 init_decl_processing ();
2558 init_optabs ();
2559 init_stmt ();
2560 init_expmed ();
2561 init_expr_once ();
2562 init_loop ();
2563 init_reload ();
2564 init_alias_once ();
2566 if (flag_caller_saves)
2567 init_caller_save ();
2569 /* If auxiliary info generation is desired, open the output file.
2570 This goes in the same directory as the source file--unlike
2571 all the other output files. */
2572 if (flag_gen_aux_info)
2574 aux_info_file = fopen (aux_info_file_name, "w");
2575 if (aux_info_file == 0)
2576 pfatal_with_name (aux_info_file_name);
2579 /* Clear the dump files file. */
2580 if (rtl_dump)
2581 clean_dump_file (".rtl");
2582 if (jump_opt_dump)
2583 clean_dump_file (".jump");
2584 if (addressof_dump)
2585 clean_dump_file (".addressof");
2586 if (cse_dump)
2587 clean_dump_file (".cse");
2588 if (loop_dump)
2589 clean_dump_file (".loop");
2590 if (cse2_dump)
2591 clean_dump_file (".cse2");
2592 if (branch_prob_dump)
2593 clean_dump_file (".bp");
2594 if (flow_dump)
2595 clean_dump_file (".flow");
2596 if (combine_dump)
2597 clean_dump_file (".combine");
2598 if (regmove_dump)
2599 clean_dump_file (".regmove");
2600 if (sched_dump)
2601 clean_dump_file (".sched");
2602 if (local_reg_dump)
2603 clean_dump_file (".lreg");
2604 if (global_reg_dump)
2605 clean_dump_file (".greg");
2606 if (sched2_dump)
2607 clean_dump_file (".sched2");
2608 if (jump2_opt_dump)
2609 clean_dump_file (".jump2");
2610 #ifdef DELAY_SLOTS
2611 if (dbr_sched_dump)
2612 clean_dump_file (".dbr");
2613 #endif
2614 if (gcse_dump)
2615 clean_dump_file (".gcse");
2616 #ifdef STACK_REGS
2617 if (stack_reg_dump)
2618 clean_dump_file (".stack");
2619 #endif
2620 #ifdef MACHINE_DEPENDENT_REORG
2621 if (mach_dep_reorg_dump)
2622 clean_dump_file (".mach");
2623 #endif
2625 /* Open assembler code output file. */
2627 if (! name_specified && asm_file_name == 0)
2628 asm_out_file = stdout;
2629 else
2631 int len = strlen (dump_base_name);
2632 register char *dumpname = (char *) xmalloc (len + 6);
2633 strcpy (dumpname, dump_base_name);
2634 strip_off_ending (dumpname, len);
2635 strcat (dumpname, ".s");
2636 if (asm_file_name == 0)
2638 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
2639 strcpy (asm_file_name, dumpname);
2641 if (!strcmp (asm_file_name, "-"))
2642 asm_out_file = stdout;
2643 else
2644 asm_out_file = fopen (asm_file_name, "w");
2645 if (asm_out_file == 0)
2646 pfatal_with_name (asm_file_name);
2649 #ifdef IO_BUFFER_SIZE
2650 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2651 _IOFBF, IO_BUFFER_SIZE);
2652 #endif
2654 input_filename = name;
2656 /* Put an entry on the input file stack for the main input file. */
2657 input_file_stack
2658 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2659 input_file_stack->next = 0;
2660 input_file_stack->name = input_filename;
2662 /* Perform language-specific initialization.
2663 This may set main_input_filename. */
2664 lang_init ();
2666 /* If the input doesn't start with a #line, use the input name
2667 as the official input file name. */
2668 if (main_input_filename == 0)
2669 main_input_filename = name;
2671 ASM_FILE_START (asm_out_file);
2673 #ifdef ASM_COMMENT_START
2674 if (flag_verbose_asm)
2676 /* Print the list of options in effect. */
2677 print_version (asm_out_file, ASM_COMMENT_START);
2678 print_switch_values (asm_out_file, 0, MAX_LINE,
2679 ASM_COMMENT_START, " ", "\n");
2680 /* Add a blank line here so it appears in assembler output but not
2681 screen output. */
2682 fprintf (asm_out_file, "\n");
2684 #endif
2686 /* Output something to inform GDB that this compilation was by GCC. */
2687 #ifndef ASM_IDENTIFY_GCC
2688 fprintf (asm_out_file, "gcc2_compiled.:\n");
2689 #else
2690 ASM_IDENTIFY_GCC (asm_out_file);
2691 #endif
2693 /* Output something to identify which front-end produced this file. */
2694 #ifdef ASM_IDENTIFY_LANGUAGE
2695 ASM_IDENTIFY_LANGUAGE (asm_out_file);
2696 #endif
2698 #ifndef ASM_OUTPUT_SECTION_NAME
2699 if (flag_function_sections)
2701 warning ("-ffunction-sections not supported for this target.");
2702 flag_function_sections = 0;
2704 #endif
2706 if (flag_function_sections
2707 && (profile_flag || profile_block_flag))
2709 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2710 flag_function_sections = 0;
2713 if (flag_function_sections && write_symbols != NO_DEBUG)
2714 warning ("-ffunction-sections may affect debugging on some targets.");
2716 /* ??? Note: There used to be a conditional here
2717 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2718 This was to guarantee separation between gcc_compiled. and
2719 the first function, for the sake of dbx on Suns.
2720 However, having the extra zero here confused the Emacs
2721 code for unexec, and might confuse other programs too.
2722 Therefore, I took out that change.
2723 In future versions we should find another way to solve
2724 that dbx problem. -- rms, 23 May 93. */
2726 /* Don't let the first function fall at the same address
2727 as gcc_compiled., if profiling. */
2728 if (profile_flag || profile_block_flag)
2730 /* It's best if we can write a nop here since some
2731 assemblers don't tolerate zeros in the text section. */
2732 if (insn_template[CODE_FOR_nop] != 0)
2733 output_asm_insn (insn_template[CODE_FOR_nop], NULL_PTR);
2734 else
2735 assemble_zeros (UNITS_PER_WORD);
2738 /* If dbx symbol table desired, initialize writing it
2739 and output the predefined types. */
2740 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2741 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2742 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2743 getdecls ()));
2744 #endif
2745 #ifdef SDB_DEBUGGING_INFO
2746 if (write_symbols == SDB_DEBUG)
2747 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2748 getdecls ()));
2749 #endif
2750 #ifdef DWARF_DEBUGGING_INFO
2751 if (write_symbols == DWARF_DEBUG)
2752 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2753 #endif
2754 #ifdef DWARF2_UNWIND_INFO
2755 if (dwarf2out_do_frame ())
2756 dwarf2out_frame_init ();
2757 #endif
2758 #ifdef DWARF2_DEBUGGING_INFO
2759 if (write_symbols == DWARF2_DEBUG)
2760 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
2761 #endif
2763 /* Initialize yet another pass. */
2765 init_final (main_input_filename);
2766 init_branch_prob (dump_base_name);
2768 start_time = get_run_time ();
2770 /* Call the parser, which parses the entire file
2771 (calling rest_of_compilation for each function). */
2773 if (yyparse () != 0)
2775 if (errorcount == 0)
2776 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
2778 /* In case there were missing closebraces,
2779 get us back to the global binding level. */
2780 while (! global_bindings_p ())
2781 poplevel (0, 0, 0);
2784 output_func_start_profiler ();
2786 /* Compilation is now finished except for writing
2787 what's left of the symbol table output. */
2789 parse_time += get_run_time () - start_time;
2791 parse_time -= integration_time;
2792 parse_time -= varconst_time;
2794 globals = getdecls ();
2796 /* Really define vars that have had only a tentative definition.
2797 Really output inline functions that must actually be callable
2798 and have not been output so far. */
2801 int len = list_length (globals);
2802 tree *vec = (tree *) alloca (sizeof (tree) * len);
2803 int i;
2804 tree decl;
2805 int reconsider = 1;
2807 /* Process the decls in reverse order--earliest first.
2808 Put them into VEC from back to front, then take out from front. */
2810 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2811 vec[len - i - 1] = decl;
2813 for (i = 0; i < len; i++)
2815 decl = vec[i];
2817 /* We're not deferring this any longer. */
2818 DECL_DEFER_OUTPUT (decl) = 0;
2820 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2821 && incomplete_decl_finalize_hook != 0)
2822 (*incomplete_decl_finalize_hook) (decl);
2825 /* Now emit any global variables or functions that we have been putting
2826 off. We need to loop in case one of the things emitted here
2827 references another one which comes earlier in the list. */
2828 while (reconsider)
2830 reconsider = 0;
2831 for (i = 0; i < len; i++)
2833 decl = vec[i];
2835 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2836 continue;
2838 /* Don't write out static consts, unless we still need them.
2840 We also keep static consts if not optimizing (for debugging),
2841 unless the user specified -fno-keep-static-consts.
2842 ??? They might be better written into the debug information.
2843 This is possible when using DWARF.
2845 A language processor that wants static constants to be always
2846 written out (even if it is not used) is responsible for
2847 calling rest_of_decl_compilation itself. E.g. the C front-end
2848 calls rest_of_decl_compilation from finish_decl.
2849 One motivation for this is that is conventional in some
2850 environments to write things like:
2851 static const char rcsid[] = "... version string ...";
2852 intending to force the string to be in the executable.
2854 A language processor that would prefer to have unneeded
2855 static constants "optimized away" would just defer writing
2856 them out until here. E.g. C++ does this, because static
2857 constants are often defined in header files.
2859 ??? A tempting alternative (for both C and C++) would be
2860 to force a constant to be written if and only if it is
2861 defined in a main file, as opposed to an include file. */
2863 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2864 && (! TREE_READONLY (decl)
2865 || TREE_PUBLIC (decl)
2866 || (!optimize && flag_keep_static_consts)
2867 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2869 reconsider = 1;
2870 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2873 if (TREE_CODE (decl) == FUNCTION_DECL
2874 && DECL_INITIAL (decl) != 0
2875 && DECL_SAVED_INSNS (decl) != 0
2876 && (flag_keep_inline_functions
2877 || TREE_PUBLIC (decl)
2878 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2880 reconsider = 1;
2881 temporary_allocation ();
2882 output_inline_function (decl);
2883 permanent_allocation (1);
2888 /* Now that all possible functions have been output, we can dump
2889 the exception table. */
2891 output_exception_table ();
2893 for (i = 0; i < len; i++)
2895 decl = vec[i];
2897 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2898 && ! TREE_ASM_WRITTEN (decl))
2899 /* Cancel the RTL for this decl so that, if debugging info
2900 output for global variables is still to come,
2901 this one will be omitted. */
2902 DECL_RTL (decl) = NULL;
2904 /* Warn about any function
2905 declared static but not defined.
2906 We don't warn about variables,
2907 because many programs have static variables
2908 that exist only to get some text into the object file. */
2909 if (TREE_CODE (decl) == FUNCTION_DECL
2910 && (warn_unused
2911 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2912 && DECL_INITIAL (decl) == 0
2913 && DECL_EXTERNAL (decl)
2914 && ! DECL_ARTIFICIAL (decl)
2915 && ! TREE_PUBLIC (decl))
2917 pedwarn_with_decl (decl,
2918 "`%s' declared `static' but never defined");
2919 /* This symbol is effectively an "extern" declaration now. */
2920 TREE_PUBLIC (decl) = 1;
2921 assemble_external (decl);
2924 /* Warn about static fns or vars defined but not used,
2925 but not about inline functions or static consts
2926 since defining those in header files is normal practice. */
2927 if (warn_unused
2928 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2929 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2930 && ! DECL_IN_SYSTEM_HEADER (decl)
2931 && ! DECL_EXTERNAL (decl)
2932 && ! TREE_PUBLIC (decl)
2933 && ! TREE_USED (decl)
2934 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2935 /* The TREE_USED bit for file-scope decls
2936 is kept in the identifier, to handle multiple
2937 external decls in different scopes. */
2938 && ! TREE_USED (DECL_NAME (decl)))
2939 warning_with_decl (decl, "`%s' defined but not used");
2941 #ifdef SDB_DEBUGGING_INFO
2942 /* The COFF linker can move initialized global vars to the end.
2943 And that can screw up the symbol ordering.
2944 By putting the symbols in that order to begin with,
2945 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2946 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2947 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2948 && ! DECL_EXTERNAL (decl)
2949 && DECL_RTL (decl) != 0)
2950 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2952 /* Output COFF information for non-global
2953 file-scope initialized variables. */
2954 if (write_symbols == SDB_DEBUG
2955 && TREE_CODE (decl) == VAR_DECL
2956 && DECL_INITIAL (decl)
2957 && ! DECL_EXTERNAL (decl)
2958 && DECL_RTL (decl) != 0
2959 && GET_CODE (DECL_RTL (decl)) == MEM)
2960 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2961 #endif /* SDB_DEBUGGING_INFO */
2962 #ifdef DWARF_DEBUGGING_INFO
2963 /* Output DWARF information for file-scope tentative data object
2964 declarations, file-scope (extern) function declarations (which
2965 had no corresponding body) and file-scope tagged type declarations
2966 and definitions which have not yet been forced out. */
2968 if (write_symbols == DWARF_DEBUG
2969 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2970 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2971 #endif
2972 #ifdef DWARF2_DEBUGGING_INFO
2973 /* Output DWARF2 information for file-scope tentative data object
2974 declarations, file-scope (extern) function declarations (which
2975 had no corresponding body) and file-scope tagged type declarations
2976 and definitions which have not yet been forced out. */
2978 if (write_symbols == DWARF2_DEBUG
2979 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2980 TIMEVAR (symout_time, dwarf2out_decl (decl));
2981 #endif
2985 /* Write out any pending weak symbol declarations. */
2987 weak_finish ();
2989 /* Do dbx symbols */
2990 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2991 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2992 TIMEVAR (symout_time,
2994 dbxout_finish (asm_out_file, main_input_filename);
2996 #endif
2998 #ifdef DWARF_DEBUGGING_INFO
2999 if (write_symbols == DWARF_DEBUG)
3000 TIMEVAR (symout_time,
3002 dwarfout_finish ();
3004 #endif
3006 #ifdef DWARF2_UNWIND_INFO
3007 if (dwarf2out_do_frame ())
3008 dwarf2out_frame_finish ();
3009 #endif
3011 #ifdef DWARF2_DEBUGGING_INFO
3012 if (write_symbols == DWARF2_DEBUG)
3013 TIMEVAR (symout_time,
3015 dwarf2out_finish ();
3017 #endif
3019 /* Output some stuff at end of file if nec. */
3021 end_final (dump_base_name);
3023 if (branch_prob_dump)
3024 open_dump_file (".bp", NULL);
3026 TIMEVAR (dump_time, end_branch_prob (rtl_dump_file));
3028 if (branch_prob_dump)
3029 close_dump_file (NULL, NULL_RTX);
3031 #ifdef ASM_FILE_END
3032 ASM_FILE_END (asm_out_file);
3033 #endif
3035 /* Language-specific end of compilation actions. */
3037 lang_finish ();
3039 /* Close the dump files. */
3041 if (flag_gen_aux_info)
3043 fclose (aux_info_file);
3044 if (errorcount)
3045 unlink (aux_info_file_name);
3048 if (combine_dump)
3050 open_dump_file (".combine", NULL);
3051 TIMEVAR (dump_time, dump_combine_total_stats (rtl_dump_file));
3052 close_dump_file (NULL, NULL_RTX);
3055 /* Close non-debugging input and output files. Take special care to note
3056 whether fclose returns an error, since the pages might still be on the
3057 buffer chain while the file is open. */
3059 finish_parse ();
3061 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
3062 fatal_io_error (asm_file_name);
3064 /* Print the times. */
3066 if (! quiet_flag)
3068 fprintf (stderr,"\n");
3069 print_time ("parse", parse_time);
3071 print_time ("integration", integration_time);
3072 print_time ("jump", jump_time);
3073 print_time ("cse", cse_time);
3074 print_time ("gcse", gcse_time);
3075 print_time ("loop", loop_time);
3076 print_time ("cse2", cse2_time);
3077 print_time ("branch-prob", branch_prob_time);
3078 print_time ("flow", flow_time);
3079 print_time ("combine", combine_time);
3080 print_time ("regmove", regmove_time);
3081 print_time ("sched", sched_time);
3082 print_time ("local-alloc", local_alloc_time);
3083 print_time ("global-alloc", global_alloc_time);
3084 print_time ("sched2", sched2_time);
3085 #ifdef DELAY_SLOTS
3086 print_time ("dbranch", dbr_sched_time);
3087 #endif
3088 print_time ("shorten-branch", shorten_branch_time);
3089 print_time ("stack-reg", stack_reg_time);
3090 print_time ("final", final_time);
3091 print_time ("varconst", varconst_time);
3092 print_time ("symout", symout_time);
3093 print_time ("dump", dump_time);
3097 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
3098 and TYPE_DECL nodes.
3100 This does nothing for local (non-static) variables.
3101 Otherwise, it sets up the RTL and outputs any assembler code
3102 (label definition, storage allocation and initialization).
3104 DECL is the declaration. If ASMSPEC is nonzero, it specifies
3105 the assembler symbol name to be used. TOP_LEVEL is nonzero
3106 if this declaration is not within a function. */
3108 void
3109 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
3110 tree decl;
3111 char *asmspec;
3112 int top_level;
3113 int at_end;
3115 /* Declarations of variables, and of functions defined elsewhere. */
3117 /* The most obvious approach, to put an #ifndef around where
3118 this macro is used, doesn't work since it's inside a macro call. */
3119 #ifndef ASM_FINISH_DECLARE_OBJECT
3120 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
3121 #endif
3123 /* Forward declarations for nested functions are not "external",
3124 but we need to treat them as if they were. */
3125 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
3126 || TREE_CODE (decl) == FUNCTION_DECL)
3127 TIMEVAR (varconst_time,
3129 make_decl_rtl (decl, asmspec, top_level);
3130 /* Initialized extern variable exists to be replaced
3131 with its value, or represents something that will be
3132 output in another file. */
3133 if (! (TREE_CODE (decl) == VAR_DECL
3134 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
3135 && DECL_INITIAL (decl) != 0
3136 && DECL_INITIAL (decl) != error_mark_node))
3137 /* Don't output anything
3138 when a tentative file-scope definition is seen.
3139 But at end of compilation, do output code for them. */
3140 if (! (! at_end && top_level
3141 && (DECL_INITIAL (decl) == 0
3142 || DECL_INITIAL (decl) == error_mark_node)))
3143 assemble_variable (decl, top_level, at_end, 0);
3144 if (decl == last_assemble_variable_decl)
3146 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
3147 top_level, at_end);
3150 else if (DECL_REGISTER (decl) && asmspec != 0)
3152 if (decode_reg_name (asmspec) >= 0)
3154 DECL_RTL (decl) = 0;
3155 make_decl_rtl (decl, asmspec, top_level);
3157 else
3158 error ("invalid register name `%s' for register variable", asmspec);
3160 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3161 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3162 && TREE_CODE (decl) == TYPE_DECL)
3163 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
3164 #endif
3165 #ifdef SDB_DEBUGGING_INFO
3166 else if (write_symbols == SDB_DEBUG && top_level
3167 && TREE_CODE (decl) == TYPE_DECL)
3168 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
3169 #endif
3172 /* Called after finishing a record, union or enumeral type. */
3174 void
3175 rest_of_type_compilation (type, toplev)
3176 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
3177 tree type;
3178 int toplev;
3179 #else
3180 tree type ATTRIBUTE_UNUSED;
3181 int toplev ATTRIBUTE_UNUSED;
3182 #endif
3184 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3185 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3186 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
3187 #endif
3188 #ifdef SDB_DEBUGGING_INFO
3189 if (write_symbols == SDB_DEBUG)
3190 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
3191 #endif
3194 /* This is called from finish_function (within yyparse)
3195 after each top-level definition is parsed.
3196 It is supposed to compile that function or variable
3197 and output the assembler code for it.
3198 After we return, the tree storage is freed. */
3200 void
3201 rest_of_compilation (decl)
3202 tree decl;
3204 register rtx insns;
3205 int start_time = get_run_time ();
3206 int tem;
3207 /* Nonzero if we have saved the original DECL_INITIAL of the function,
3208 to be restored after we finish compiling the function
3209 (for use when compiling inline calls to this function). */
3210 tree saved_block_tree = 0;
3211 /* Likewise, for DECL_ARGUMENTS. */
3212 tree saved_arguments = 0;
3213 int failure = 0;
3215 /* If we are reconsidering an inline function
3216 at the end of compilation, skip the stuff for making it inline. */
3218 if (DECL_SAVED_INSNS (decl) == 0)
3220 int inlinable = 0;
3221 char *lose;
3223 /* If requested, consider whether to make this function inline. */
3224 if (DECL_INLINE (decl) || flag_inline_functions)
3225 TIMEVAR (integration_time,
3227 lose = function_cannot_inline_p (decl);
3228 if (lose || ! optimize)
3230 if (warn_inline && DECL_INLINE (decl))
3231 warning_with_decl (decl, lose);
3232 DECL_ABSTRACT_ORIGIN (decl) = 0;
3233 /* Don't really compile an extern inline function.
3234 If we can't make it inline, pretend
3235 it was only declared. */
3236 if (DECL_EXTERNAL (decl))
3238 DECL_INITIAL (decl) = 0;
3239 goto exit_rest_of_compilation;
3242 else
3243 /* ??? Note that this has the effect of making it look
3244 like "inline" was specified for a function if we choose
3245 to inline it. This isn't quite right, but it's
3246 probably not worth the trouble to fix. */
3247 inlinable = DECL_INLINE (decl) = 1;
3250 insns = get_insns ();
3252 /* Dump the rtl code if we are dumping rtl. */
3254 if (rtl_dump)
3256 open_dump_file (".rtl", decl_printable_name (decl, 2));
3258 if (DECL_SAVED_INSNS (decl))
3259 fprintf (rtl_dump_file, ";; (integrable)\n\n");
3261 close_dump_file (print_rtl, insns);
3264 /* If we can, defer compiling inlines until EOF.
3265 save_for_inline_copying can be extremely expensive. */
3266 if (inlinable && ! decl_function_context (decl))
3267 DECL_DEFER_OUTPUT (decl) = 1;
3269 /* If function is inline, and we don't yet know whether to
3270 compile it by itself, defer decision till end of compilation.
3271 finish_compilation will call rest_of_compilation again
3272 for those functions that need to be output. Also defer those
3273 functions that we are supposed to defer. We cannot defer
3274 functions containing nested functions since the nested function
3275 data is in our non-saved obstack. We cannot defer nested
3276 functions for the same reason. */
3278 /* If this is a nested inline, remove ADDRESSOF now so we can
3279 finish compiling ourselves. Otherwise, wait until EOF.
3280 We have to do this because the purge_addressof transformation
3281 changes the DECL_RTL for many variables, which confuses integrate. */
3282 if (inlinable)
3284 if (decl_function_context (decl))
3285 purge_addressof (insns);
3286 else
3287 DECL_DEFER_OUTPUT (decl) = 1;
3290 if (! current_function_contains_functions
3291 && (DECL_DEFER_OUTPUT (decl)
3292 || (DECL_INLINE (decl)
3293 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3294 && ! flag_keep_inline_functions)
3295 || DECL_EXTERNAL (decl)))))
3297 DECL_DEFER_OUTPUT (decl) = 1;
3299 /* If -Wreturn-type, we have to do a bit of compilation.
3300 However, if we just fall through we will call
3301 save_for_inline_copying() which results in excessive
3302 memory use. Instead, we just want to call
3303 jump_optimize() to figure out whether or not we can fall
3304 off the end of the function; we do the minimum amount of
3305 work necessary to make that safe. And, we set optimize
3306 to zero to keep jump_optimize from working too hard. */
3307 if (warn_return_type)
3309 int saved_optimize = optimize;
3310 optimize = 0;
3311 find_exception_handler_labels ();
3312 jump_optimize (get_insns(), !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3313 !JUMP_AFTER_REGSCAN);
3314 optimize = saved_optimize;
3317 #ifdef DWARF_DEBUGGING_INFO
3318 /* Generate the DWARF info for the "abstract" instance
3319 of a function which we may later generate inlined and/or
3320 out-of-line instances of. */
3321 if (write_symbols == DWARF_DEBUG)
3323 set_decl_abstract_flags (decl, 1);
3324 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3325 set_decl_abstract_flags (decl, 0);
3327 #endif
3328 #ifdef DWARF2_DEBUGGING_INFO
3329 /* Generate the DWARF2 info for the "abstract" instance
3330 of a function which we may later generate inlined and/or
3331 out-of-line instances of. */
3332 if (write_symbols == DWARF2_DEBUG)
3334 set_decl_abstract_flags (decl, 1);
3335 TIMEVAR (symout_time, dwarf2out_decl (decl));
3336 set_decl_abstract_flags (decl, 0);
3338 #endif
3339 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3340 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
3341 goto exit_rest_of_compilation;
3344 /* If we have to compile the function now, save its rtl and subdecls
3345 so that its compilation will not affect what others get. */
3346 if (inlinable || DECL_DEFER_OUTPUT (decl))
3348 #ifdef DWARF_DEBUGGING_INFO
3349 /* Generate the DWARF info for the "abstract" instance of
3350 a function which we will generate an out-of-line instance
3351 of almost immediately (and which we may also later generate
3352 various inlined instances of). */
3353 if (write_symbols == DWARF_DEBUG)
3355 set_decl_abstract_flags (decl, 1);
3356 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3357 set_decl_abstract_flags (decl, 0);
3359 #endif
3360 #ifdef DWARF2_DEBUGGING_INFO
3361 /* Generate the DWARF2 info for the "abstract" instance of
3362 a function which we will generate an out-of-line instance
3363 of almost immediately (and which we may also later generate
3364 various inlined instances of). */
3365 if (write_symbols == DWARF2_DEBUG)
3367 set_decl_abstract_flags (decl, 1);
3368 TIMEVAR (symout_time, dwarf2out_decl (decl));
3369 set_decl_abstract_flags (decl, 0);
3371 #endif
3372 saved_block_tree = DECL_INITIAL (decl);
3373 saved_arguments = DECL_ARGUMENTS (decl);
3374 TIMEVAR (integration_time, save_for_inline_copying (decl));
3375 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
3378 /* If specified extern inline but we aren't inlining it, we are
3379 done. */
3380 if (DECL_INLINE (decl) && DECL_EXTERNAL (decl))
3381 goto exit_rest_of_compilation;
3384 if (! DECL_DEFER_OUTPUT (decl))
3385 TREE_ASM_WRITTEN (decl) = 1;
3387 /* Now that integrate will no longer see our rtl, we need not distinguish
3388 between the return value of this function and the return value of called
3389 functions. */
3390 rtx_equal_function_value_matters = 0;
3392 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3393 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3395 goto exit_rest_of_compilation;
3398 /* Emit code to get eh context, if needed. */
3399 emit_eh_context ();
3401 #ifdef FINALIZE_PIC
3402 /* If we are doing position-independent code generation, now
3403 is the time to output special prologues and epilogues.
3404 We do not want to do this earlier, because it just clutters
3405 up inline functions with meaningless insns. */
3406 if (flag_pic)
3407 FINALIZE_PIC;
3408 #endif
3410 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3411 Note that that may have been done above, in save_for_inline_copying.
3412 The call to resume_temporary_allocation near the end of this function
3413 goes back to the usual state of affairs. This must be done after
3414 we've built up any unwinders for exception handling, and done
3415 the FINALIZE_PIC work, if necessary. */
3417 rtl_in_current_obstack ();
3419 insns = get_insns ();
3421 /* Copy any shared structure that should not be shared. */
3423 unshare_all_rtl (insns);
3425 #ifdef SETJMP_VIA_SAVE_AREA
3426 /* This must be performed before virutal register instantiation. */
3427 if (current_function_calls_alloca)
3428 optimize_save_area_alloca (insns);
3429 #endif
3431 /* Instantiate all virtual registers. */
3433 instantiate_virtual_regs (current_function_decl, get_insns ());
3435 /* See if we have allocated stack slots that are not directly addressable.
3436 If so, scan all the insns and create explicit address computation
3437 for all references to such slots. */
3438 /* fixup_stack_slots (); */
3440 /* Find all the EH handlers. */
3441 find_exception_handler_labels ();
3443 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3444 are initialized and to compute whether control can drop off the end
3445 of the function. */
3446 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3447 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3448 JUMP_AFTER_REGSCAN));
3450 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3451 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3452 goto exit_rest_of_compilation;
3454 /* Dump rtl code after jump, if we are doing that. */
3456 if (jump_opt_dump)
3457 dump_rtl (".jump", decl, print_rtl, insns);
3459 /* Perform common subexpression elimination.
3460 Nonzero value from `cse_main' means that jumps were simplified
3461 and some code may now be unreachable, so do
3462 jump optimization again. */
3464 if (optimize > 0)
3466 if (cse_dump)
3467 open_dump_file (".cse", decl_printable_name (decl, 2));
3469 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3471 if (flag_thread_jumps)
3472 /* Hacks by tiemann & kenner. */
3473 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3475 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3476 0, rtl_dump_file));
3477 TIMEVAR (cse_time, delete_trivially_dead_insns (insns, max_reg_num ()));
3479 if (tem || optimize > 1)
3480 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3481 !JUMP_NOOP_MOVES,
3482 !JUMP_AFTER_REGSCAN));
3484 /* Dump rtl code after cse, if we are doing that. */
3486 if (cse_dump)
3487 close_dump_file (print_rtl, insns);
3490 purge_addressof (insns);
3491 reg_scan (insns, max_reg_num (), 1);
3493 if (addressof_dump)
3494 dump_rtl (".addressof", decl, print_rtl, insns);
3496 /* Perform global cse. */
3498 if (optimize > 0 && flag_gcse)
3500 if (gcse_dump)
3501 open_dump_file (".gcse", IDENTIFIER_POINTER (DECL_NAME (decl)));
3503 TIMEVAR (gcse_time, gcse_main (insns, rtl_dump_file));
3505 if (gcse_dump)
3506 close_dump_file (print_rtl, insns);
3508 /* Move constant computations out of loops. */
3510 if (optimize > 0)
3512 if (loop_dump)
3513 open_dump_file (".loop", decl_printable_name (decl, 2));
3515 TIMEVAR
3516 (loop_time,
3518 if (flag_rerun_loop_opt)
3520 /* We only want to perform unrolling once. */
3522 loop_optimize (insns, rtl_dump_file, 0, 0);
3525 /* The first call to loop_optimize makes some instructions
3526 trivially dead. We delete those instructions now in the
3527 hope that doing so will make the heuristics in loop work
3528 better and possibly speed up compilation. */
3529 delete_trivially_dead_insns (insns, max_reg_num ());
3531 /* The regscan pass is currently necessary as the alias
3532 analysis code depends on this information. */
3533 reg_scan (insns, max_reg_num (), 1);
3535 loop_optimize (insns, rtl_dump_file, flag_unroll_loops, 1);
3538 /* Dump rtl code after loop opt, if we are doing that. */
3540 if (loop_dump)
3541 close_dump_file (print_rtl, insns);
3544 if (optimize > 0)
3546 if (cse2_dump)
3547 open_dump_file (".cse2", decl_printable_name (decl, 2));
3549 if (flag_rerun_cse_after_loop)
3551 /* Running another jump optimization pass before the second
3552 cse pass sometimes simplifies the RTL enough to allow
3553 the second CSE pass to do a better job. Jump_optimize can change
3554 max_reg_num so we must rerun reg_scan afterwards.
3555 ??? Rework to not call reg_scan so often. */
3556 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3557 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3558 !JUMP_NOOP_MOVES,
3559 JUMP_AFTER_REGSCAN));
3561 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3562 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3563 1, rtl_dump_file));
3564 if (tem)
3565 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3566 !JUMP_NOOP_MOVES,
3567 !JUMP_AFTER_REGSCAN));
3570 if (flag_thread_jumps)
3572 /* This pass of jump threading straightens out code
3573 that was kinked by loop optimization. */
3574 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3575 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3578 /* Dump rtl code after cse, if we are doing that. */
3580 if (cse2_dump)
3581 close_dump_file (print_rtl, insns);
3584 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3586 if (branch_prob_dump)
3587 open_dump_file (".bp", decl_printable_name (decl, 2));
3589 TIMEVAR
3590 (branch_prob_time,
3592 branch_prob (insns, rtl_dump_file);
3595 if (branch_prob_dump)
3596 close_dump_file (print_rtl, insns);
3599 /* We are no longer anticipating cse in this function, at least. */
3601 cse_not_expected = 1;
3603 /* Now we choose between stupid (pcc-like) register allocation
3604 (if we got the -noreg switch and not -opt)
3605 and smart register allocation. */
3607 if (optimize > 0) /* Stupid allocation probably won't work */
3608 obey_regdecls = 0; /* if optimizations being done. */
3610 regclass_init ();
3612 /* Print function header into flow dump now
3613 because doing the flow analysis makes some of the dump. */
3615 if (flow_dump)
3616 open_dump_file (".flow", decl_printable_name (decl, 2));
3618 if (obey_regdecls)
3620 TIMEVAR (flow_time,
3622 regclass (insns, max_reg_num ());
3623 stupid_life_analysis (insns, max_reg_num (),
3624 rtl_dump_file);
3627 else
3629 /* Do control and data flow analysis,
3630 and write some of the results to dump file. */
3632 TIMEVAR
3633 (flow_time,
3635 find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
3636 life_analysis (insns, max_reg_num (), rtl_dump_file);
3639 if (warn_uninitialized)
3641 uninitialized_vars_warning (DECL_INITIAL (decl));
3642 setjmp_args_warning ();
3646 /* Dump rtl after flow analysis. */
3648 if (flow_dump)
3649 close_dump_file (print_rtl_with_bb, insns);
3651 /* If -opt, try combining insns through substitution. */
3653 if (optimize > 0)
3655 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
3657 /* Dump rtl code after insn combination. */
3659 if (combine_dump)
3660 dump_rtl (".combine", decl, print_rtl_with_bb, insns);
3663 /* Register allocation pre-pass, to reduce number of moves
3664 necessary for two-address machines. */
3665 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3667 if (regmove_dump)
3668 open_dump_file (".regmove", decl_printable_name (decl, 2));
3670 TIMEVAR (regmove_time, regmove_optimize (insns, max_reg_num (),
3671 rtl_dump_file));
3673 if (regmove_dump)
3674 close_dump_file (print_rtl_with_bb, insns);
3677 /* Print function header into sched dump now
3678 because doing the sched analysis makes some of the dump. */
3680 if (optimize > 0 && flag_schedule_insns)
3682 if (sched_dump)
3683 open_dump_file (".sched", decl_printable_name (decl, 2));
3685 /* Do control and data sched analysis,
3686 and write some of the results to dump file. */
3688 TIMEVAR (sched_time, schedule_insns (rtl_dump_file));
3690 /* Dump rtl after instruction scheduling. */
3692 if (sched_dump)
3693 close_dump_file (print_rtl_with_bb, insns);
3696 /* Unless we did stupid register allocation,
3697 allocate pseudo-regs that are used only within 1 basic block. */
3699 if (!obey_regdecls)
3700 TIMEVAR (local_alloc_time,
3702 recompute_reg_usage (insns);
3703 regclass (insns, max_reg_num ());
3704 local_alloc ();
3707 /* Dump rtl code after allocating regs within basic blocks. */
3709 if (local_reg_dump)
3711 open_dump_file (".lreg", decl_printable_name (decl, 2));
3713 TIMEVAR (dump_time, dump_flow_info (rtl_dump_file));
3714 TIMEVAR (dump_time, dump_local_alloc (rtl_dump_file));
3716 close_dump_file (print_rtl_with_bb, insns);
3719 if (global_reg_dump)
3720 open_dump_file (".greg", decl_printable_name (decl, 2));
3722 /* Save the last label number used so far, so reorg can tell
3723 when it's safe to kill spill regs. */
3724 max_label_num_after_reload = max_label_num ();
3726 /* Unless we did stupid register allocation,
3727 allocate remaining pseudo-regs, then do the reload pass
3728 fixing up any insns that are invalid. */
3730 TIMEVAR (global_alloc_time,
3732 if (!obey_regdecls)
3733 failure = global_alloc (rtl_dump_file);
3734 else
3735 failure = reload (insns, 0, rtl_dump_file);
3739 if (failure)
3740 goto exit_rest_of_compilation;
3742 reload_completed = 1;
3744 /* Do a very simple CSE pass over just the hard registers. */
3745 if (optimize > 0)
3746 reload_cse_regs (insns);
3748 /* On some machines, the prologue and epilogue code, or parts thereof,
3749 can be represented as RTL. Doing so lets us schedule insns between
3750 it and the rest of the code and also allows delayed branch
3751 scheduling to operate in the epilogue. */
3753 thread_prologue_and_epilogue_insns (insns);
3755 if (global_reg_dump)
3757 TIMEVAR (dump_time, dump_global_regs (rtl_dump_file));
3758 close_dump_file (print_rtl_with_bb, insns);
3760 if (optimize > 0 && flag_schedule_insns_after_reload)
3762 if (sched2_dump)
3763 open_dump_file (".sched2", decl_printable_name (decl, 2));
3765 /* Do control and data sched analysis again,
3766 and write some more of the results to dump file. */
3768 TIMEVAR (sched2_time, schedule_insns (rtl_dump_file));
3770 /* Dump rtl after post-reorder instruction scheduling. */
3772 if (sched2_dump)
3773 close_dump_file (print_rtl_with_bb, insns);
3776 #ifdef LEAF_REGISTERS
3777 leaf_function = 0;
3778 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
3779 leaf_function = 1;
3780 #endif
3782 /* One more attempt to remove jumps to .+1
3783 left by dead-store-elimination.
3784 Also do cross-jumping this time
3785 and delete no-op move insns. */
3787 if (optimize > 0)
3789 TIMEVAR (jump_time, jump_optimize (insns, JUMP_CROSS_JUMP,
3790 JUMP_NOOP_MOVES,
3791 !JUMP_AFTER_REGSCAN));
3793 /* Dump rtl code after jump, if we are doing that. */
3795 if (jump2_opt_dump)
3796 dump_rtl (".jump2", decl, print_rtl_with_bb, insns);
3799 /* If a machine dependent reorganization is needed, call it. */
3800 #ifdef MACHINE_DEPENDENT_REORG
3801 MACHINE_DEPENDENT_REORG (insns);
3803 if (mach_dep_reorg_dump)
3804 dump_rtl (".mach", decl, print_rtl_with_bb, insns);
3805 #endif
3807 /* If a scheduling pass for delayed branches is to be done,
3808 call the scheduling code. */
3810 #ifdef DELAY_SLOTS
3811 if (optimize > 0 && flag_delayed_branch)
3813 TIMEVAR (dbr_sched_time, dbr_schedule (insns, rtl_dump_file));
3815 if (dbr_sched_dump)
3816 dump_rtl (".dbr", decl, print_rtl_with_bb, insns);
3818 #endif
3820 /* Shorten branches. */
3821 TIMEVAR (shorten_branch_time,
3823 shorten_branches (get_insns ());
3826 #ifdef STACK_REGS
3827 if (stack_reg_dump)
3828 open_dump_file (".stack", decl_printable_name (decl, 2));
3830 TIMEVAR (stack_reg_time, reg_to_stack (insns, rtl_dump_file));
3832 if (stack_reg_dump)
3833 dump_rtl (".stack", decl, print_rtl_with_bb, insns);
3834 #endif
3836 /* Now turn the rtl into assembler code. */
3838 TIMEVAR (final_time,
3840 rtx x;
3841 char *fnname;
3843 /* Get the function's name, as described by its RTL.
3844 This may be different from the DECL_NAME name used
3845 in the source file. */
3847 x = DECL_RTL (decl);
3848 if (GET_CODE (x) != MEM)
3849 abort ();
3850 x = XEXP (x, 0);
3851 if (GET_CODE (x) != SYMBOL_REF)
3852 abort ();
3853 fnname = XSTR (x, 0);
3855 assemble_start_function (decl, fnname);
3856 final_start_function (insns, asm_out_file, optimize);
3857 final (insns, asm_out_file, optimize, 0);
3858 final_end_function (insns, asm_out_file, optimize);
3859 assemble_end_function (decl, fnname);
3860 if (! quiet_flag)
3861 fflush (asm_out_file);
3863 /* Release all memory held by regsets now */
3864 regset_release_memory ();
3867 /* Write DBX symbols if requested */
3869 /* Note that for those inline functions where we don't initially
3870 know for certain that we will be generating an out-of-line copy,
3871 the first invocation of this routine (rest_of_compilation) will
3872 skip over this code by doing a `goto exit_rest_of_compilation;'.
3873 Later on, finish_compilation will call rest_of_compilation again
3874 for those inline functions that need to have out-of-line copies
3875 generated. During that call, we *will* be routed past here. */
3877 #ifdef DBX_DEBUGGING_INFO
3878 if (write_symbols == DBX_DEBUG)
3879 TIMEVAR (symout_time, dbxout_function (decl));
3880 #endif
3882 #ifdef DWARF_DEBUGGING_INFO
3883 if (write_symbols == DWARF_DEBUG)
3884 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3885 #endif
3887 #ifdef DWARF2_DEBUGGING_INFO
3888 if (write_symbols == DWARF2_DEBUG)
3889 TIMEVAR (symout_time, dwarf2out_decl (decl));
3890 #endif
3892 exit_rest_of_compilation:
3894 /* In case the function was not output,
3895 don't leave any temporary anonymous types
3896 queued up for sdb output. */
3897 #ifdef SDB_DEBUGGING_INFO
3898 if (write_symbols == SDB_DEBUG)
3899 sdbout_types (NULL_TREE);
3900 #endif
3902 /* Put back the tree of subblocks and list of arguments
3903 from before we copied them.
3904 Code generation and the output of debugging info may have modified
3905 the copy, but the original is unchanged. */
3907 if (saved_block_tree != 0)
3909 DECL_INITIAL (decl) = saved_block_tree;
3910 DECL_ARGUMENTS (decl) = saved_arguments;
3911 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
3914 reload_completed = 0;
3916 TIMEVAR (final_time,
3918 /* Clear out the insn_length contents now that they are no
3919 longer valid. */
3920 init_insn_lengths ();
3922 /* Clear out the real_constant_chain before some of the rtx's
3923 it runs through become garbage. */
3924 clear_const_double_mem ();
3926 /* Cancel the effect of rtl_in_current_obstack. */
3927 resume_temporary_allocation ();
3929 /* Show no temporary slots allocated. */
3930 init_temp_slots ();
3933 /* Make sure volatile mem refs aren't considered valid operands for
3934 arithmetic insns. We must call this here if this is a nested inline
3935 function, since the above code leaves us in the init_recog state
3936 (from final.c), and the function context push/pop code does not
3937 save/restore volatile_ok.
3939 ??? Maybe it isn't necessary for expand_start_function to call this
3940 anymore if we do it here? */
3942 init_recog_no_volatile ();
3944 /* The parsing time is all the time spent in yyparse
3945 *except* what is spent in this function. */
3947 parse_time -= get_run_time () - start_time;
3950 static void
3951 display_help ()
3953 int undoc;
3954 unsigned long i;
3955 char * lang;
3957 #ifndef USE_CPPLIB
3958 printf ("Usage: %s input [switches]\n", progname);
3959 printf ("Switches:\n");
3960 #endif
3961 printf (" -ffixed-<register> Mark <register> as being unavailable to the compiler\n");
3962 printf (" -fcall-used-<register> Mark <register> as being corrupted by function calls\n");
3963 printf (" -fcall-saved-<register> Mark <register> as being preserved across functions\n");
3965 for (i = NUM_ELEM (f_options); i--;)
3967 char * description = f_options[i].description;
3969 if (description != NULL && * description != 0)
3970 printf (" -f%-21s %s\n",
3971 f_options[i].string, description);
3974 printf (" -O[number] Set optimisation level to [number]\n");
3975 printf (" -Os Optimise for space rather than speed\n");
3976 printf (" -pedantic Issue warnings needed by strict compliance to ANSI C\n");
3977 printf (" -pedantic-errors Like -pedantic except that errors are produced\n");
3978 printf (" -w Suppress warnings\n");
3979 printf (" -W Enable extra warnings\n");
3981 for (i = NUM_ELEM (W_options); i--;)
3983 char * description = W_options[i].description;
3985 if (description != NULL && * description != 0)
3986 printf (" -W%-21s %s\n",
3987 W_options[i].string, description);
3990 printf (" -Wid-clash-<num> Warn if 2 identifiers have the same first <num> chars\n");
3991 printf (" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n");
3992 printf (" -p Enable function profiling\n");
3993 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER)
3994 printf (" -a Enable block profiling \n");
3995 #endif
3996 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER) || defined FUNCTION_BLOCK_PROFILER_EXIT
3997 printf (" -ax Enable jump profiling \n");
3998 #endif
3999 printf (" -o <file> Place output into <file> \n");
4000 printf (" -G <number> Put global and static data smaller than <number>\n");
4001 printf (" bytes into a special section (on some targets)\n");
4003 for (i = NUM_ELEM (debug_args); i--;)
4005 if (debug_args[i].description != NULL)
4006 printf (" -%-22s %s\n", debug_args[i].arg, debug_args[i].description);
4009 printf (" -aux-info <file> Emit declaration info into <file>.X\n");
4010 printf (" -quiet Do not display functions compiled or elapsed time\n");
4011 printf (" -version Display the compiler's version\n");
4012 printf (" -d[letters] Enable dumps from specific passes of the compiler\n");
4013 printf (" -dumpbase <file> Base name to be used for dumps from specific passes\n");
4014 #if defined HAIFA || defined INSN_SCHEDULING
4015 printf (" -sched-verbose-<number> Set the verbosity level of the scheduler\n");
4016 #endif
4017 printf (" --help Display this information\n");
4019 undoc = 0;
4020 lang = "language";
4022 /* Display descriptions of language specific options.
4023 If there is no description, note that there is an undocumented option.
4024 If the description is empty, do not display anything. (This allows
4025 options to be deliberately undocumented, for whatever reason).
4026 If the option string is missing, then this is a marker, indicating
4027 that the description string is in fact the name of a language, whoes
4028 language specific options are to follow. */
4030 if (NUM_ELEM (documented_lang_options) > 1)
4032 printf ("\nLanguage specific options:\n");
4034 for (i = 0; i < NUM_ELEM (documented_lang_options); i++)
4036 char * description = documented_lang_options[i].description;
4037 char * option = documented_lang_options[i].option;
4039 if (description == NULL)
4040 undoc = 1;
4041 else if (* description == 0)
4042 continue;
4043 else if (option == NULL)
4045 if (undoc)
4046 printf
4047 ("\nThere are undocumented %s specific options as well.\n",
4048 lang);
4049 undoc = 0;
4051 printf ("\n Options for %s:\n", description);
4053 lang = description;
4055 else
4056 printf (" %-23.23s %s\n", option, description);
4060 if (undoc)
4061 printf ("\nThere are undocumented %s specific options as well.\n", lang);
4063 if (NUM_ELEM (target_switches) > 1
4064 #ifdef TARGET_OPTIONS
4065 || NUM_ELEM (target_options) > 1
4066 #endif
4069 int doc = 0;
4071 undoc = 0;
4073 printf ("\nTarget specific options:\n");
4075 for (i = NUM_ELEM (target_switches); i--;)
4077 char * option = target_switches[i].name;
4078 char * description = target_switches[i].description;
4080 if (option == NULL)
4081 continue;
4082 else if (description == NULL)
4083 undoc = 1;
4084 else if (* description != 0)
4085 doc += printf (" %-23.23s %s\n", option, description);
4088 #ifdef TARGET_OPTIONS
4089 for (i = NUM_ELEM (target_options); i--;)
4091 char * option = target_options[i].prefix;
4092 char * description = target_options[i].description;
4094 if (option == NULL)
4095 continue;
4096 else if (description == NULL)
4097 undoc = 1;
4098 else if (* description != 0)
4099 doc += printf (" %-23.23s %s\n", option, description);
4101 #endif
4102 if (undoc)
4104 if (doc)
4105 printf ("\nThere are undocumented target specific options as well.\n");
4106 else
4107 printf (" They exist, but they are not documented.\n");
4112 /* Compare the user specified 'option' with the language
4113 specific 'lang_option'. Return true if they match, or
4114 if 'option' is a viable prefix of 'lang_option'. */
4116 static int
4117 check_lang_option (option, lang_option)
4118 char * option;
4119 char * lang_option;
4121 lang_independent_options * indep_options;
4122 int len;
4123 long k;
4125 /* Ignore NULL entries. */
4126 if (option == NULL || lang_option == NULL)
4127 return 0;
4129 len = strlen (lang_option);
4131 /* If they do not match to the first n characters then fail. */
4132 if (strncmp (option, lang_option, len) != 0)
4133 return 0;
4135 /* Do not accept a lang option, if it matches a normal -f or -W
4136 option. Chill defines a -fpack, but we want to support
4137 -fpack-struct. */
4139 /* An exact match is OK */
4140 if (strlen (option) == len)
4141 return 1;
4143 /* If it is not an -f or -W option allow the match */
4144 if (option[0] != '-')
4145 return 1;
4147 switch (option[1])
4149 case 'f': indep_options = f_options; break;
4150 case 'W': indep_options = W_options; break;
4151 default: return 1;
4154 /* The option is a -f or -W option.
4155 Skip past the prefix and search for the remainder in the
4156 appropriate table of options. */
4157 option += 2;
4159 if (option[0] == 'n' && option[1] == 'o' && option[2] == '-')
4160 option += 3;
4162 for (k = NUM_ELEM (indep_options); k--;)
4164 if (!strcmp (option, indep_options[k].string))
4166 /* The option matched a language independent option,
4167 do not allow the language specific match. */
4169 return 0;
4173 /* The option matches the start of the langauge specific option
4174 and it is not an exact match for a language independent option. */
4175 return 1;
4178 /* Entry point of cc1/c++. Decode command args, then call compile_file.
4179 Exit code is 35 if can't open files, 34 if fatal error,
4180 33 if had nonfatal errors, else success. */
4183 main (argc, argv)
4184 int argc;
4185 char **argv;
4187 register int i;
4188 char *filename = 0;
4189 int flag_print_mem = 0;
4190 int version_flag = 0;
4191 char *p;
4193 /* save in case md file wants to emit args as a comment. */
4194 save_argc = argc;
4195 save_argv = argv;
4197 p = argv[0] + strlen (argv[0]);
4198 while (p != argv[0] && p[-1] != '/'
4199 #ifdef DIR_SEPARATOR
4200 && p[-1] != DIR_SEPARATOR
4201 #endif
4203 --p;
4204 progname = p;
4206 #if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
4207 /* Get rid of any avoidable limit on stack size. */
4209 struct rlimit rlim;
4211 /* Set the stack limit huge so that alloca does not fail. */
4212 getrlimit (RLIMIT_STACK, &rlim);
4213 rlim.rlim_cur = rlim.rlim_max;
4214 setrlimit (RLIMIT_STACK, &rlim);
4216 #endif
4218 signal (SIGFPE, float_signal);
4220 #ifdef SIGPIPE
4221 signal (SIGPIPE, pipe_closed);
4222 #endif
4224 decl_printable_name = decl_name;
4225 lang_expand_expr = (lang_expand_expr_t) do_abort;
4227 /* Initialize whether `char' is signed. */
4228 flag_signed_char = DEFAULT_SIGNED_CHAR;
4229 #ifdef DEFAULT_SHORT_ENUMS
4230 /* Initialize how much space enums occupy, by default. */
4231 flag_short_enums = DEFAULT_SHORT_ENUMS;
4232 #endif
4234 /* Perform language-specific options intialization. */
4235 lang_init_options ();
4237 /* Scan to see what optimization level has been specified. That will
4238 determine the default value of many flags. */
4239 for (i = 1; i < argc; i++)
4241 if (!strcmp (argv[i], "-O"))
4243 optimize = 1;
4245 else if (argv[i][0] == '-' && argv[i][1] == 'O')
4247 /* Handle -Os, -O2, -O3, -O69, ... */
4248 char *p = &argv[i][2];
4249 int c;
4251 if ((p[0] == 's') && (p[1] == 0))
4252 optimize_size = 1;
4253 else
4255 while ((c = *p++))
4256 if (! (c >= '0' && c <= '9'))
4257 break;
4258 if (c == 0)
4259 optimize = atoi (&argv[i][2]);
4264 /* Optimizing for size forces optimize to be no less than 2. */
4265 if (optimize_size && (optimize < 2))
4266 optimize = 2;
4268 obey_regdecls = (optimize == 0);
4270 if (optimize >= 1)
4272 flag_defer_pop = 1;
4273 flag_thread_jumps = 1;
4274 #ifdef DELAY_SLOTS
4275 flag_delayed_branch = 1;
4276 #endif
4277 #ifdef CAN_DEBUG_WITHOUT_FP
4278 flag_omit_frame_pointer = 1;
4279 #endif
4282 if (optimize >= 2)
4284 flag_cse_follow_jumps = 1;
4285 flag_cse_skip_blocks = 1;
4286 flag_gcse = 1;
4287 flag_expensive_optimizations = 1;
4288 flag_strength_reduce = 1;
4289 flag_rerun_cse_after_loop = 1;
4290 flag_rerun_loop_opt = 1;
4291 flag_caller_saves = 1;
4292 flag_force_mem = 1;
4293 #ifdef INSN_SCHEDULING
4294 flag_schedule_insns = 1;
4295 flag_schedule_insns_after_reload = 1;
4296 #endif
4297 flag_regmove = 1;
4298 flag_strict_aliasing = 1;
4301 if (optimize >= 3)
4303 flag_inline_functions = 1;
4306 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
4307 modify it. */
4308 target_flags = 0;
4309 set_target_switch ("");
4311 #ifdef OPTIMIZATION_OPTIONS
4312 /* Allow default optimizations to be specified on a per-machine basis. */
4313 OPTIMIZATION_OPTIONS (optimize, optimize_size);
4314 #endif
4316 /* Initialize register usage now so switches may override. */
4317 init_reg_sets ();
4319 for (i = 1; i < argc; i++)
4321 size_t j;
4323 /* If this is a language-specific option,
4324 decode it in a language-specific way. */
4325 for (j = NUM_ELEM (documented_lang_options); j--;)
4326 if (check_lang_option (argv[i], documented_lang_options[j].option))
4327 break;
4329 if (j != (size_t)-1)
4331 /* If the option is valid for *some* language,
4332 treat it as valid even if this language doesn't understand it. */
4333 int strings_processed = lang_decode_option (argc - i, argv + i);
4335 if (!strcmp (argv[i], "--help"))
4337 display_help ();
4338 exit (0);
4341 if (strings_processed != 0)
4342 i += strings_processed - 1;
4344 else if (argv[i][0] == '-' && argv[i][1] != 0)
4346 register char *str = argv[i] + 1;
4347 if (str[0] == 'Y')
4348 str++;
4350 if (str[0] == 'm')
4351 set_target_switch (&str[1]);
4352 else if (!strcmp (str, "dumpbase"))
4354 dump_base_name = argv[++i];
4356 else if (str[0] == 'd')
4358 register char *p = &str[1];
4359 while (*p)
4360 switch (*p++)
4362 case 'a':
4363 branch_prob_dump = 1;
4364 combine_dump = 1;
4365 #ifdef DELAY_SLOTS
4366 dbr_sched_dump = 1;
4367 #endif
4368 flow_dump = 1;
4369 global_reg_dump = 1;
4370 jump_opt_dump = 1;
4371 addressof_dump = 1;
4372 jump2_opt_dump = 1;
4373 local_reg_dump = 1;
4374 loop_dump = 1;
4375 regmove_dump = 1;
4376 rtl_dump = 1;
4377 cse_dump = 1, cse2_dump = 1;
4378 gcse_dump = 1;
4379 sched_dump = 1;
4380 sched2_dump = 1;
4381 #ifdef STACK_REGS
4382 stack_reg_dump = 1;
4383 #endif
4384 #ifdef MACHINE_DEPENDENT_REORG
4385 mach_dep_reorg_dump = 1;
4386 #endif
4387 break;
4388 case 'A':
4389 flag_debug_asm = 1;
4390 break;
4391 case 'b':
4392 branch_prob_dump = 1;
4393 break;
4394 case 'c':
4395 combine_dump = 1;
4396 break;
4397 #ifdef DELAY_SLOTS
4398 case 'd':
4399 dbr_sched_dump = 1;
4400 break;
4401 #endif
4402 case 'f':
4403 flow_dump = 1;
4404 break;
4405 case 'F':
4406 addressof_dump = 1;
4407 break;
4408 case 'g':
4409 global_reg_dump = 1;
4410 break;
4411 case 'G':
4412 gcse_dump = 1;
4413 break;
4414 case 'j':
4415 jump_opt_dump = 1;
4416 break;
4417 case 'J':
4418 jump2_opt_dump = 1;
4419 break;
4420 #ifdef STACK_REGS
4421 case 'k':
4422 stack_reg_dump = 1;
4423 break;
4424 #endif
4425 case 'l':
4426 local_reg_dump = 1;
4427 break;
4428 case 'L':
4429 loop_dump = 1;
4430 break;
4431 case 'm':
4432 flag_print_mem = 1;
4433 break;
4434 #ifdef MACHINE_DEPENDENT_REORG
4435 case 'M':
4436 mach_dep_reorg_dump = 1;
4437 break;
4438 #endif
4439 case 'p':
4440 flag_print_asm_name = 1;
4441 break;
4442 case 'r':
4443 rtl_dump = 1;
4444 break;
4445 case 'R':
4446 sched2_dump = 1;
4447 break;
4448 case 's':
4449 cse_dump = 1;
4450 break;
4451 case 'S':
4452 sched_dump = 1;
4453 break;
4454 case 't':
4455 cse2_dump = 1;
4456 break;
4457 case 'N':
4458 regmove_dump = 1;
4459 break;
4460 case 'y':
4461 set_yydebug (1);
4462 break;
4463 case 'x':
4464 rtl_dump_and_exit = 1;
4465 break;
4466 default:
4467 warning ("unrecognised gcc debugging option: %c", p[-1]);
4468 break;
4471 else if (str[0] == 'f')
4473 register char *p = &str[1];
4474 int found = 0;
4476 /* Some kind of -f option.
4477 P's value is the option sans `-f'.
4478 Search for it in the table of options. */
4480 for (j = 0;
4481 !found && j < sizeof (f_options) / sizeof (f_options[0]);
4482 j++)
4484 if (!strcmp (p, f_options[j].string))
4486 *f_options[j].variable = f_options[j].on_value;
4487 /* A goto here would be cleaner,
4488 but breaks the vax pcc. */
4489 found = 1;
4491 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
4492 && ! strcmp (p+3, f_options[j].string))
4494 *f_options[j].variable = ! f_options[j].on_value;
4495 found = 1;
4499 if (found)
4501 #ifdef HAIFA
4502 #ifdef INSN_SCHEDULING
4503 else if (!strncmp (p, "sched-verbose-",14))
4504 fix_sched_param("verbose",&p[14]);
4505 #endif
4506 #endif /* HAIFA */
4507 else if (!strncmp (p, "fixed-", 6))
4508 fix_register (&p[6], 1, 1);
4509 else if (!strncmp (p, "call-used-", 10))
4510 fix_register (&p[10], 0, 1);
4511 else if (!strncmp (p, "call-saved-", 11))
4512 fix_register (&p[11], 0, 0);
4513 else
4514 error ("Invalid option `%s'", argv[i]);
4516 else if (str[0] == 'O')
4518 register char *p = str+1;
4519 if (*p == 's')
4520 p++;
4521 else
4522 while (*p && *p >= '0' && *p <= '9')
4523 p++;
4524 if (*p == '\0')
4526 else
4527 error ("Invalid option `%s'", argv[i]);
4529 else if (!strcmp (str, "pedantic"))
4530 pedantic = 1;
4531 else if (!strcmp (str, "pedantic-errors"))
4532 flag_pedantic_errors = pedantic = 1;
4533 else if (!strcmp (str, "quiet"))
4534 quiet_flag = 1;
4535 else if (!strcmp (str, "version"))
4536 version_flag = 1;
4537 else if (!strcmp (str, "w"))
4538 inhibit_warnings = 1;
4539 else if (!strcmp (str, "W"))
4541 extra_warnings = 1;
4542 /* We save the value of warn_uninitialized, since if they put
4543 -Wuninitialized on the command line, we need to generate a
4544 warning about not using it without also specifying -O. */
4545 if (warn_uninitialized != 1)
4546 warn_uninitialized = 2;
4548 else if (str[0] == 'W')
4550 register char *p = &str[1];
4551 int found = 0;
4553 /* Some kind of -W option.
4554 P's value is the option sans `-W'.
4555 Search for it in the table of options. */
4557 for (j = 0;
4558 !found && j < sizeof (W_options) / sizeof (W_options[0]);
4559 j++)
4561 if (!strcmp (p, W_options[j].string))
4563 *W_options[j].variable = W_options[j].on_value;
4564 /* A goto here would be cleaner,
4565 but breaks the vax pcc. */
4566 found = 1;
4568 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
4569 && ! strcmp (p+3, W_options[j].string))
4571 *W_options[j].variable = ! W_options[j].on_value;
4572 found = 1;
4576 if (found)
4578 else if (!strncmp (p, "id-clash-", 9))
4580 char *endp = p + 9;
4582 while (*endp)
4584 if (*endp >= '0' && *endp <= '9')
4585 endp++;
4586 else
4588 error ("Invalid option `%s'", argv[i]);
4589 goto id_clash_lose;
4592 warn_id_clash = 1;
4593 id_clash_len = atoi (str + 10);
4594 id_clash_lose: ;
4596 else if (!strncmp (p, "larger-than-", 12))
4598 char *endp = p + 12;
4600 while (*endp)
4602 if (*endp >= '0' && *endp <= '9')
4603 endp++;
4604 else
4606 error ("Invalid option `%s'", argv[i]);
4607 goto larger_than_lose;
4610 warn_larger_than = 1;
4611 larger_than_size = atoi (str + 13);
4612 larger_than_lose: ;
4614 else
4615 error ("Invalid option `%s'", argv[i]);
4617 else if (!strcmp (str, "p"))
4619 profile_flag = 1;
4621 else if (!strcmp (str, "a"))
4623 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4624 warning ("`-a' option (basic block profile) not supported");
4625 #else
4626 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
4627 #endif
4629 else if (!strcmp (str, "ax"))
4631 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4632 warning ("`-ax' option (jump profiling) not supported");
4633 #else
4634 profile_block_flag = (!profile_block_flag
4635 || profile_block_flag == 2) ? 2 : 3;
4636 #endif
4638 else if (str[0] == 'g')
4640 unsigned len;
4641 unsigned level;
4642 /* A lot of code assumes write_symbols == NO_DEBUG if the
4643 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4644 of what debugging type has been selected). This records the
4645 selected type. It is an error to specify more than one
4646 debugging type. */
4647 static enum debug_info_type selected_debug_type = NO_DEBUG;
4648 /* Non-zero if debugging format has been explicitly set.
4649 -g and -ggdb don't explicitly set the debugging format so
4650 -gdwarf -g3 is equivalent to -gdwarf3. */
4651 static int type_explicitly_set_p = 0;
4652 /* Indexed by enum debug_info_type. */
4653 static char *debug_type_names[] =
4655 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
4658 /* Look up STR in the table. */
4659 for (da = debug_args; da->arg; da++)
4661 if (! strncmp (str, da->arg, strlen (da->arg)))
4663 enum debug_info_type type = da->debug_type;
4664 char *p, *q;
4666 p = str + strlen (da->arg);
4667 if (*p && (*p < '0' || *p > '9'))
4668 continue;
4669 len = p - str;
4670 q = p;
4671 while (*q && (*q >= '0' && *q <= '9'))
4672 q++;
4673 if (*p)
4675 level = atoi (p);
4676 if (len > 1 && !strncmp (str, "gdwarf", len))
4678 error ("use -gdwarf -g%d for DWARF v1, level %d",
4679 level, level);
4680 if (level == 2)
4681 error ("use -gdwarf-2 for DWARF v2");
4684 else
4685 level = 2; /* default debugging info level */
4686 if (*q || level > 3)
4688 warning ("invalid debug level specification in option: `-%s'",
4689 str);
4690 /* ??? This error message is incorrect in the case of
4691 -g4 -g. */
4692 warning ("no debugging information will be generated");
4693 level = 0;
4696 if (type == NO_DEBUG)
4698 type = PREFERRED_DEBUGGING_TYPE;
4699 if (len > 1 && strncmp (str, "ggdb", len) == 0)
4701 #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
4702 type = DWARF2_DEBUG;
4703 #else
4704 #ifdef DBX_DEBUGGING_INFO
4705 type = DBX_DEBUG;
4706 #endif
4707 #endif
4711 if (type == NO_DEBUG)
4712 warning ("`-%s' not supported by this configuration of GCC",
4713 str);
4715 /* Does it conflict with an already selected type? */
4716 if (type_explicitly_set_p
4717 /* -g/-ggdb don't conflict with anything */
4718 && da->debug_type != NO_DEBUG
4719 && type != selected_debug_type)
4720 warning ("`-%s' ignored, conflicts with `-g%s'",
4721 str, debug_type_names[(int) selected_debug_type]);
4722 else
4724 /* If the format has already been set, -g/-ggdb
4725 only change the debug level. */
4726 if (type_explicitly_set_p
4727 && da->debug_type == NO_DEBUG)
4728 ; /* don't change debugging type */
4729 else
4731 selected_debug_type = type;
4732 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4734 write_symbols = (level == 0
4735 ? NO_DEBUG
4736 : selected_debug_type);
4737 use_gnu_debug_info_extensions = da->use_extensions_p;
4738 debug_info_level = (enum debug_info_level) level;
4740 break;
4743 if (! da->arg)
4744 warning ("`-%s' not supported by this configuration of GCC",
4745 str);
4747 else if (!strcmp (str, "o"))
4749 asm_file_name = argv[++i];
4751 else if (str[0] == 'G')
4753 g_switch_set = TRUE;
4754 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
4756 else if (!strncmp (str, "aux-info", 8))
4758 flag_gen_aux_info = 1;
4759 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
4761 else if (!strcmp (str, "-help"))
4763 display_help ();
4764 exit (0);
4766 else
4767 error ("Invalid option `%s'", argv[i]);
4769 else if (argv[i][0] == '+')
4770 error ("Invalid option `%s'", argv[i]);
4771 else
4772 filename = argv[i];
4775 /* Checker uses the frame pointer. */
4776 if (flag_check_memory_usage)
4777 flag_omit_frame_pointer = 0;
4779 if (optimize == 0)
4781 /* Inlining does not work if not optimizing,
4782 so force it not to be done. */
4783 flag_no_inline = 1;
4784 warn_inline = 0;
4786 /* The c_decode_option and lang_decode_option functions set
4787 this to `2' if -Wall is used, so we can avoid giving out
4788 lots of errors for people who don't realize what -Wall does. */
4789 if (warn_uninitialized == 1)
4790 warning ("-Wuninitialized is not supported without -O");
4793 #ifdef OVERRIDE_OPTIONS
4794 /* Some machines may reject certain combinations of options. */
4795 OVERRIDE_OPTIONS;
4796 #endif
4798 if (exceptions_via_longjmp == 2)
4800 #ifdef DWARF2_UNWIND_INFO
4801 exceptions_via_longjmp = ! DWARF2_UNWIND_INFO;
4802 #else
4803 exceptions_via_longjmp = 1;
4804 #endif
4807 if (profile_block_flag == 3)
4809 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
4810 profile_block_flag = 2;
4813 /* Unrolling all loops implies that standard loop unrolling must also
4814 be done. */
4815 if (flag_unroll_all_loops)
4816 flag_unroll_loops = 1;
4817 /* Loop unrolling requires that strength_reduction be on also. Silently
4818 turn on strength reduction here if it isn't already on. Also, the loop
4819 unrolling code assumes that cse will be run after loop, so that must
4820 be turned on also. */
4821 if (flag_unroll_loops)
4823 flag_strength_reduce = 1;
4824 flag_rerun_cse_after_loop = 1;
4827 /* Warn about options that are not supported on this machine. */
4828 #ifndef INSN_SCHEDULING
4829 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4830 warning ("instruction scheduling not supported on this target machine");
4831 #endif
4832 #ifndef DELAY_SLOTS
4833 if (flag_delayed_branch)
4834 warning ("this target machine does not have delayed branches");
4835 #endif
4837 /* If we are in verbose mode, write out the version and maybe all the
4838 option flags in use. */
4839 if (version_flag)
4841 print_version (stderr, "");
4842 if (! quiet_flag)
4843 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4846 compile_file (filename);
4848 #if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN32__))
4849 if (flag_print_mem)
4851 char *lim = (char *) sbrk (0);
4853 fprintf (stderr, "Data size %ld.\n", (long)(lim - (char *) &environ));
4854 fflush (stderr);
4856 #ifndef __MSDOS__
4857 #ifdef USG
4858 system ("ps -l 1>&2");
4859 #else /* not USG */
4860 system ("ps v");
4861 #endif /* not USG */
4862 #endif
4864 #endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN32) */
4866 if (errorcount)
4867 exit (FATAL_EXIT_CODE);
4868 if (sorrycount)
4869 exit (FATAL_EXIT_CODE);
4870 exit (SUCCESS_EXIT_CODE);
4871 return 0;
4874 /* Decode -m switches. */
4875 /* Decode the switch -mNAME. */
4877 static void
4878 set_target_switch (name)
4879 char *name;
4881 register size_t j;
4882 int valid = 0;
4884 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4885 if (!strcmp (target_switches[j].name, name))
4887 if (target_switches[j].value < 0)
4888 target_flags &= ~-target_switches[j].value;
4889 else
4890 target_flags |= target_switches[j].value;
4891 valid = 1;
4894 #ifdef TARGET_OPTIONS
4895 if (!valid)
4896 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4898 int len = strlen (target_options[j].prefix);
4899 if (!strncmp (target_options[j].prefix, name, len))
4901 *target_options[j].variable = name + len;
4902 valid = 1;
4905 #endif
4907 if (!valid)
4908 error ("Invalid option `%s'", name);
4911 /* Print version information to FILE.
4912 Each line begins with INDENT (for the case where FILE is the
4913 assembler output file). */
4915 static void
4916 print_version (file, indent)
4917 FILE *file;
4918 char *indent;
4920 fprintf (file, "%s%s%s version %s", indent, *indent != 0 ? " " : "",
4921 language_string, version_string);
4922 fprintf (file, " (%s)", TARGET_NAME);
4923 #ifdef __GNUC__
4924 #ifndef __VERSION__
4925 #define __VERSION__ "[unknown]"
4926 #endif
4927 fprintf (file, " compiled by GNU C version %s.\n", __VERSION__);
4928 #else
4929 fprintf (file, " compiled by CC.\n");
4930 #endif
4933 /* Print an option value and return the adjusted position in the line.
4934 ??? We don't handle error returns from fprintf (disk full); presumably
4935 other code will catch a disk full though. */
4937 static int
4938 print_single_switch (file, pos, max, indent, sep, term, type, name)
4939 FILE *file;
4940 int pos, max;
4941 char *indent, *sep, *term, *type, *name;
4943 /* The ultrix fprintf returns 0 on success, so compute the result we want
4944 here since we need it for the following test. */
4945 int len = strlen (sep) + strlen (type) + strlen (name);
4947 if (pos != 0
4948 && pos + len > max)
4950 fprintf (file, "%s", term);
4951 pos = 0;
4953 if (pos == 0)
4955 fprintf (file, "%s", indent);
4956 pos = strlen (indent);
4958 fprintf (file, "%s%s%s", sep, type, name);
4959 pos += len;
4960 return pos;
4963 /* Print active target switches to FILE.
4964 POS is the current cursor position and MAX is the size of a "line".
4965 Each line begins with INDENT and ends with TERM.
4966 Each switch is separated from the next by SEP. */
4968 static void
4969 print_switch_values (file, pos, max, indent, sep, term)
4970 FILE *file;
4971 int pos, max;
4972 char *indent, *sep, *term;
4974 size_t j;
4975 char **p;
4977 /* Print the options as passed. */
4979 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4980 "options passed: ", "");
4982 for (p = &save_argv[1]; *p != NULL; p++)
4983 if (**p == '-')
4985 /* Ignore these. */
4986 if (strcmp (*p, "-o") == 0)
4988 if (p[1] != NULL)
4989 p++;
4990 continue;
4992 if (strcmp (*p, "-quiet") == 0)
4993 continue;
4994 if (strcmp (*p, "-version") == 0)
4995 continue;
4996 if ((*p)[1] == 'd')
4997 continue;
4999 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
5001 if (pos > 0)
5002 fprintf (file, "%s", term);
5004 /* Print the -f and -m options that have been enabled.
5005 We don't handle language specific options but printing argv
5006 should suffice. */
5008 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
5009 "options enabled: ", "");
5011 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
5012 if (*f_options[j].variable == f_options[j].on_value)
5013 pos = print_single_switch (file, pos, max, indent, sep, term,
5014 "-f", f_options[j].string);
5016 /* Print target specific options. */
5018 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5019 if (target_switches[j].name[0] != '\0'
5020 && target_switches[j].value > 0
5021 && ((target_switches[j].value & target_flags)
5022 == target_switches[j].value))
5024 pos = print_single_switch (file, pos, max, indent, sep, term,
5025 "-m", target_switches[j].name);
5028 #ifdef TARGET_OPTIONS
5029 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5030 if (*target_options[j].variable != NULL)
5032 char prefix[256];
5033 sprintf (prefix, "-m%s", target_options[j].prefix);
5034 pos = print_single_switch (file, pos, max, indent, sep, term,
5035 prefix, *target_options[j].variable);
5037 #endif
5039 fprintf (file, "%s", term);
5042 /* Record the beginning of a new source file, named FILENAME. */
5044 void
5045 debug_start_source_file (filename)
5046 register char *filename;
5048 #ifdef DBX_DEBUGGING_INFO
5049 if (write_symbols == DBX_DEBUG)
5050 dbxout_start_new_source_file (filename);
5051 #endif
5052 #ifdef DWARF_DEBUGGING_INFO
5053 if (debug_info_level == DINFO_LEVEL_VERBOSE
5054 && write_symbols == DWARF_DEBUG)
5055 dwarfout_start_new_source_file (filename);
5056 #endif /* DWARF_DEBUGGING_INFO */
5057 #ifdef DWARF2_DEBUGGING_INFO
5058 if (debug_info_level == DINFO_LEVEL_VERBOSE
5059 && write_symbols == DWARF2_DEBUG)
5060 dwarf2out_start_source_file (filename);
5061 #endif /* DWARF2_DEBUGGING_INFO */
5062 #ifdef SDB_DEBUGGING_INFO
5063 if (write_symbols == SDB_DEBUG)
5064 sdbout_start_new_source_file (filename);
5065 #endif
5068 /* Record the resumption of a source file. LINENO is the line number in
5069 the source file we are returning to. */
5071 void
5072 debug_end_source_file (lineno)
5073 register unsigned lineno;
5075 #ifdef DBX_DEBUGGING_INFO
5076 if (write_symbols == DBX_DEBUG)
5077 dbxout_resume_previous_source_file ();
5078 #endif
5079 #ifdef DWARF_DEBUGGING_INFO
5080 if (debug_info_level == DINFO_LEVEL_VERBOSE
5081 && write_symbols == DWARF_DEBUG)
5082 dwarfout_resume_previous_source_file (lineno);
5083 #endif /* DWARF_DEBUGGING_INFO */
5084 #ifdef DWARF2_DEBUGGING_INFO
5085 if (debug_info_level == DINFO_LEVEL_VERBOSE
5086 && write_symbols == DWARF2_DEBUG)
5087 dwarf2out_end_source_file ();
5088 #endif /* DWARF2_DEBUGGING_INFO */
5089 #ifdef SDB_DEBUGGING_INFO
5090 if (write_symbols == SDB_DEBUG)
5091 sdbout_resume_previous_source_file ();
5092 #endif
5095 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5096 the tail part of the directive line, i.e. the part which is past the
5097 initial whitespace, #, whitespace, directive-name, whitespace part. */
5099 void
5100 debug_define (lineno, buffer)
5101 register unsigned lineno;
5102 register char *buffer;
5104 #ifdef DWARF_DEBUGGING_INFO
5105 if (debug_info_level == DINFO_LEVEL_VERBOSE
5106 && write_symbols == DWARF_DEBUG)
5107 dwarfout_define (lineno, buffer);
5108 #endif /* DWARF_DEBUGGING_INFO */
5109 #ifdef DWARF2_DEBUGGING_INFO
5110 if (debug_info_level == DINFO_LEVEL_VERBOSE
5111 && write_symbols == DWARF2_DEBUG)
5112 dwarf2out_define (lineno, buffer);
5113 #endif /* DWARF2_DEBUGGING_INFO */
5116 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5117 the tail part of the directive line, i.e. the part which is past the
5118 initial whitespace, #, whitespace, directive-name, whitespace part. */
5120 void
5121 debug_undef (lineno, buffer)
5122 register unsigned lineno;
5123 register char *buffer;
5125 #ifdef DWARF_DEBUGGING_INFO
5126 if (debug_info_level == DINFO_LEVEL_VERBOSE
5127 && write_symbols == DWARF_DEBUG)
5128 dwarfout_undef (lineno, buffer);
5129 #endif /* DWARF_DEBUGGING_INFO */
5130 #ifdef DWARF2_DEBUGGING_INFO
5131 if (debug_info_level == DINFO_LEVEL_VERBOSE
5132 && write_symbols == DWARF2_DEBUG)
5133 dwarf2out_undef (lineno, buffer);
5134 #endif /* DWARF2_DEBUGGING_INFO */