* configure: Rebuilt.
[official-gcc.git] / gcc / toplev.c
blob4c332617966b3d92575bdeb8c028c61614fdea8f
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This is the top level of cc1/c++.
22 It parses command args, opens files, invokes the various passes
23 in the proper order, and counts the time used by each.
24 Error messages and low-level interface to malloc also handled here. */
26 #include "config.h"
27 #undef FLOAT /* This is for hpux. They should change hpux. */
28 #undef FFS /* Some systems define this in param.h. */
29 #include "system.h"
30 #include <signal.h>
31 #include <setjmp.h>
33 #ifdef HAVE_SYS_RESOURCE_H
34 # include <sys/resource.h>
35 #endif
37 #ifdef HAVE_SYS_TIMES_H
38 # include <sys/times.h>
39 #endif
41 #include "input.h"
42 #include "tree.h"
43 #include "rtl.h"
44 #include "flags.h"
45 #include "insn-attr.h"
46 #include "insn-codes.h"
47 #include "insn-config.h"
48 #include "recog.h"
49 #include "defaults.h"
50 #include "output.h"
51 #include "except.h"
52 #include "toplev.h"
53 #include "expr.h"
54 #include "basic-block.h"
55 #include "intl.h"
57 #ifdef DWARF_DEBUGGING_INFO
58 #include "dwarfout.h"
59 #endif
61 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
62 #include "dwarf2out.h"
63 #endif
65 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
66 #include "dbxout.h"
67 #endif
69 #ifdef SDB_DEBUGGING_INFO
70 #include "sdbout.h"
71 #endif
73 #ifdef XCOFF_DEBUGGING_INFO
74 #include "xcoffout.h"
75 #endif
77 #ifdef VMS
78 /* The extra parameters substantially improve the I/O performance. */
79 static FILE *
80 vms_fopen (fname, type)
81 char * fname;
82 char * type;
84 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
85 fixed arguments, which matches ANSI's specification but not VAXCRTL's
86 pre-ANSI implementation. This hack circumvents the mismatch problem. */
87 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
89 if (*type == 'w')
90 return (*vmslib_fopen) (fname, type, "mbc=32",
91 "deq=64", "fop=tef", "shr=nil");
92 else
93 return (*vmslib_fopen) (fname, type, "mbc=32");
95 #define fopen vms_fopen
96 #endif /* VMS */
98 #ifndef DEFAULT_GDB_EXTENSIONS
99 #define DEFAULT_GDB_EXTENSIONS 1
100 #endif
102 /* If more than one debugging type is supported, you must define
103 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
105 This is one long line cause VAXC can't handle a \-newline. */
106 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
107 #ifndef PREFERRED_DEBUGGING_TYPE
108 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
109 #endif /* no PREFERRED_DEBUGGING_TYPE */
110 #else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
111 so the following code needn't care. */
112 #ifdef DBX_DEBUGGING_INFO
113 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
114 #endif
115 #ifdef SDB_DEBUGGING_INFO
116 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
117 #endif
118 #ifdef DWARF_DEBUGGING_INFO
119 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
120 #endif
121 #ifdef DWARF2_DEBUGGING_INFO
122 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
123 #endif
124 #ifdef XCOFF_DEBUGGING_INFO
125 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
126 #endif
127 #endif /* More than one debugger format enabled. */
129 /* If still not defined, must have been because no debugging formats
130 are supported. */
131 #ifndef PREFERRED_DEBUGGING_TYPE
132 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
133 #endif
135 extern int rtx_equal_function_value_matters;
137 #if ! (defined (VMS) || defined (OS2))
138 extern char **environ;
139 #endif
140 extern char *version_string, *language_string;
142 /* Carry information from ASM_DECLARE_OBJECT_NAME
143 to ASM_FINISH_DECLARE_OBJECT. */
145 extern int size_directive_output;
146 extern tree last_assemble_variable_decl;
148 extern char *init_parse PVPROTO((char *));
149 extern void finish_parse ();
150 extern void init_decl_processing ();
151 extern void init_obstacks ();
152 extern void init_tree_codes ();
153 extern void init_rtl ();
154 extern void init_regs ();
155 extern void init_optabs ();
156 extern void init_stmt ();
157 extern void init_reg_sets ();
158 extern void dump_flow_info ();
159 extern void dump_sched_info ();
160 extern void dump_local_alloc ();
161 extern void regset_release_memory ();
163 extern void print_rtl ();
164 extern void print_rtl_with_bb ();
166 void rest_of_decl_compilation ();
167 void error_with_file_and_line PVPROTO((const char *file,
168 int line, const char *s, ...));
169 void error_with_decl PVPROTO((tree decl, const char *s, ...));
170 void error_for_asm PVPROTO((rtx insn, const char *s, ...));
171 void notice PVPROTO((const char *s, ...));
172 void error PVPROTO((const char *s, ...));
173 void fatal PVPROTO((const char *s, ...));
174 void warning_with_file_and_line PVPROTO((const char *file,
175 int line, const char *s, ...));
176 void warning_with_decl PVPROTO((tree decl, const char *s, ...));
177 void warning PVPROTO((const char *s, ...));
178 void pedwarn PVPROTO((const char *s, ...));
179 void pedwarn_with_decl PVPROTO((tree decl, const char *s, ...));
180 void pedwarn_with_file_and_line PVPROTO((const char *file,
181 int line, const char *s, ...));
182 void sorry PVPROTO((const char *s, ...));
183 static void set_target_switch PROTO((const char *));
184 static char *decl_name PROTO((tree, int));
185 static void vmessage PROTO((const char *, const char *, va_list));
186 static void v_message_with_file_and_line PROTO((const char *, int, int,
187 const char *, va_list));
188 static void v_message_with_decl PROTO((tree, int, const char *, va_list));
189 static void file_and_line_for_asm PROTO((rtx, char **, int *));
190 static void v_error_with_file_and_line PROTO((const char *, int,
191 const char *, va_list));
192 static void v_error_with_decl PROTO((tree, const char *, va_list));
193 static void v_error_for_asm PROTO((rtx, const char *, va_list));
194 static void verror PROTO((const char *, va_list));
195 static void vfatal PROTO((const char *, va_list)) ATTRIBUTE_NORETURN;
196 static void v_warning_with_file_and_line PROTO ((const char *, int,
197 const char *, va_list));
198 static void v_warning_with_decl PROTO((tree, const char *, va_list));
199 static void v_warning_for_asm PROTO((rtx, const char *, va_list));
200 static void vwarning PROTO((const char *, va_list));
201 static void vpedwarn PROTO((const char *, va_list));
202 static void v_pedwarn_with_decl PROTO((tree, const char *, va_list));
203 static void v_pedwarn_with_file_and_line PROTO((const char *, int,
204 const char *, va_list));
205 static void vsorry PROTO((const char *, va_list));
206 static void float_signal PROTO((int)) ATTRIBUTE_NORETURN;
207 static void pipe_closed PROTO((int)) ATTRIBUTE_NORETURN;
208 #ifdef ASM_IDENTIFY_LANGUAGE
209 /* This might or might not be used in ASM_IDENTIFY_LANGUAGE. */
210 static void output_lang_identify PROTO((FILE *)) ATTRIBUTE_UNUSED;
211 #endif
212 static void open_dump_file PROTO((const char *, const char *));
213 static void close_dump_file PROTO((void (*) (FILE *, rtx), rtx));
214 static void dump_rtl PROTO((const char *, tree, void (*) (FILE *, rtx), rtx));
215 static void clean_dump_file PROTO((const char *));
216 static void compile_file PROTO((char *));
217 static void display_help PROTO ((void));
219 static void print_version PROTO((FILE *, const char *));
220 static int print_single_switch PROTO((FILE *, int, int, const char *,
221 const char *, const char *,
222 const char *, const char *));
223 static void print_switch_values PROTO((FILE *, int, int, const char *,
224 const char *, const char *));
226 void print_rtl_graph_with_bb PROTO ((const char *, const char *, rtx));
227 void clean_graph_dump_file PROTO ((const char *, const char *));
228 void finish_graph_dump_file PROTO ((const char *, const char *));
229 /* Length of line when printing switch values. */
230 #define MAX_LINE 75
232 /* Name of program invoked, sans directories. */
234 char *progname;
236 /* Copy of arguments to main. */
237 int save_argc;
238 char **save_argv;
240 /* Name of current original source file (what was input to cpp).
241 This comes from each #-command in the actual input. */
243 char *input_filename;
245 /* Name of top-level original source file (what was input to cpp).
246 This comes from the #-command at the beginning of the actual input.
247 If there isn't any there, then this is the cc1 input file name. */
249 char *main_input_filename;
251 /* Current line number in real source file. */
253 int lineno;
255 /* Nonzero if it is unsafe to create any new pseudo registers. */
256 int no_new_pseudos;
258 /* Stack of currently pending input files. */
260 struct file_stack *input_file_stack;
262 /* Incremented on each change to input_file_stack. */
263 int input_file_stack_tick;
265 /* FUNCTION_DECL for function now being parsed or compiled. */
267 extern tree current_function_decl;
269 /* Name to use as base of names for dump output files. */
271 const char *dump_base_name;
273 /* Bit flags that specify the machine subtype we are compiling for.
274 Bits are tested using macros TARGET_... defined in the tm.h file
275 and set by `-m...' switches. Must be defined in rtlanal.c. */
277 extern int target_flags;
279 /* Flags saying which kinds of debugging dump have been requested. */
281 int rtl_dump = 0;
282 int rtl_dump_and_exit = 0;
283 int jump_opt_dump = 0;
284 int addressof_dump = 0;
285 int cse_dump = 0;
286 int gcse_dump = 0;
287 int loop_dump = 0;
288 int cse2_dump = 0;
289 int branch_prob_dump = 0;
290 int flow_dump = 0;
291 int combine_dump = 0;
292 int regmove_dump = 0;
293 int sched_dump = 0;
294 int local_reg_dump = 0;
295 int global_reg_dump = 0;
296 int flow2_dump = 0;
297 int sched2_dump = 0;
298 int jump2_opt_dump = 0;
299 #ifdef DELAY_SLOTS
300 int dbr_sched_dump = 0;
301 #endif
302 int flag_print_asm_name = 0;
303 #ifdef STACK_REGS
304 int stack_reg_dump = 0;
305 #endif
306 #ifdef MACHINE_DEPENDENT_REORG
307 int mach_dep_reorg_dump = 0;
308 #endif
309 enum graph_dump_types graph_dump_format;
311 /* Name for output file of assembly code, specified with -o. */
313 char *asm_file_name;
315 /* Value of the -G xx switch, and whether it was passed or not. */
316 int g_switch_value;
317 int g_switch_set;
319 /* Type(s) of debugging information we are producing (if any).
320 See flags.h for the definitions of the different possible
321 types of debugging information. */
322 enum debug_info_type write_symbols = NO_DEBUG;
324 /* Level of debugging information we are producing. See flags.h
325 for the definitions of the different possible levels. */
326 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
328 /* Nonzero means use GNU-only extensions in the generated symbolic
329 debugging information. */
330 /* Currently, this only has an effect when write_symbols is set to
331 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
332 int use_gnu_debug_info_extensions = 0;
334 /* Nonzero means do optimizations. -O.
335 Particular numeric values stand for particular amounts of optimization;
336 thus, -O2 stores 2 here. However, the optimizations beyond the basic
337 ones are not controlled directly by this variable. Instead, they are
338 controlled by individual `flag_...' variables that are defaulted
339 based on this variable. */
341 int optimize = 0;
343 /* Nonzero means optimize for size. -Os.
344 The only valid values are zero and non-zero. When optimize_size is
345 non-zero, optimize defaults to 2, but certain individual code
346 bloating optimizations are disabled. */
348 int optimize_size = 0;
350 /* Number of error messages and warning messages so far. */
352 int errorcount = 0;
353 int warningcount = 0;
354 int sorrycount = 0;
356 /* Pointer to function to compute the name to use to print a declaration.
357 DECL is the declaration in question.
358 VERBOSITY determines what information will be printed:
359 0: DECL_NAME, demangled as necessary.
360 1: and scope information.
361 2: and any other information that might be interesting, such as function
362 parameter types in C++. */
364 char *(*decl_printable_name) PROTO ((tree, int));
366 /* Pointer to function to compute rtl for a language-specific tree code. */
368 typedef rtx (*lang_expand_expr_t)
369 PROTO ((union tree_node *, rtx, enum machine_mode,
370 enum expand_modifier modifier));
372 lang_expand_expr_t lang_expand_expr = 0;
374 /* Pointer to function to finish handling an incomplete decl at the
375 end of compilation. */
377 void (*incomplete_decl_finalize_hook) PROTO((tree)) = 0;
379 /* Nonzero if generating code to do profiling. */
381 int profile_flag = 0;
383 /* Nonzero if generating code to do profiling on a line-by-line basis. */
385 int profile_block_flag;
387 /* Nonzero if generating code to profile program flow graph arcs. */
389 int profile_arc_flag = 0;
391 /* Nonzero if generating info for gcov to calculate line test coverage. */
393 int flag_test_coverage = 0;
395 /* Nonzero indicates that branch taken probabilities should be calculated. */
397 int flag_branch_probabilities = 0;
399 /* Nonzero for -pedantic switch: warn about anything
400 that standard spec forbids. */
402 int pedantic = 0;
404 /* Temporarily suppress certain warnings.
405 This is set while reading code from a system header file. */
407 int in_system_header = 0;
409 /* Nonzero means do stupid register allocation.
410 Currently, this is 1 if `optimize' is 0. */
412 int obey_regdecls = 0;
414 /* Don't print functions as they are compiled and don't print
415 times taken by the various passes. -quiet. */
417 int quiet_flag = 0;
419 /* -f flags. */
421 /* Nonzero means `char' should be signed. */
423 int flag_signed_char;
425 /* Nonzero means give an enum type only as many bytes as it needs. */
427 int flag_short_enums;
429 /* Nonzero for -fcaller-saves: allocate values in regs that need to
430 be saved across function calls, if that produces overall better code.
431 Optional now, so people can test it. */
433 #ifdef DEFAULT_CALLER_SAVES
434 int flag_caller_saves = 1;
435 #else
436 int flag_caller_saves = 0;
437 #endif
439 /* Nonzero if structures and unions should be returned in memory.
441 This should only be defined if compatibility with another compiler or
442 with an ABI is needed, because it results in slower code. */
444 #ifndef DEFAULT_PCC_STRUCT_RETURN
445 #define DEFAULT_PCC_STRUCT_RETURN 1
446 #endif
448 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
450 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
452 /* Nonzero for -fforce-mem: load memory value into a register
453 before arithmetic on it. This makes better cse but slower compilation. */
455 int flag_force_mem = 0;
457 /* Nonzero for -fforce-addr: load memory address into a register before
458 reference to memory. This makes better cse but slower compilation. */
460 int flag_force_addr = 0;
462 /* Nonzero for -fdefer-pop: don't pop args after each function call;
463 instead save them up to pop many calls' args with one insns. */
465 int flag_defer_pop = 0;
467 /* Nonzero for -ffloat-store: don't allocate floats and doubles
468 in extended-precision registers. */
470 int flag_float_store = 0;
472 /* Nonzero for -fcse-follow-jumps:
473 have cse follow jumps to do a more extensive job. */
475 int flag_cse_follow_jumps;
477 /* Nonzero for -fcse-skip-blocks:
478 have cse follow a branch around a block. */
479 int flag_cse_skip_blocks;
481 /* Nonzero for -fexpensive-optimizations:
482 perform miscellaneous relatively-expensive optimizations. */
483 int flag_expensive_optimizations;
485 /* Nonzero for -fthread-jumps:
486 have jump optimize output of loop. */
488 int flag_thread_jumps;
490 /* Nonzero enables strength-reduction in loop.c. */
492 int flag_strength_reduce = 0;
494 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
495 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
496 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
497 unrolled. */
499 int flag_unroll_loops;
501 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
502 This is generally not a win. */
504 int flag_unroll_all_loops;
506 /* Nonzero forces all invariant computations in loops to be moved
507 outside the loop. */
509 int flag_move_all_movables = 0;
511 /* Nonzero forces all general induction variables in loops to be
512 strength reduced. */
514 int flag_reduce_all_givs = 0;
516 /* Nonzero to perform full register move optimization passes. This is the
517 default for -O2. */
519 int flag_regmove = 0;
521 /* Nonzero for -fwritable-strings:
522 store string constants in data segment and don't uniquize them. */
524 int flag_writable_strings = 0;
526 /* Nonzero means don't put addresses of constant functions in registers.
527 Used for compiling the Unix kernel, where strange substitutions are
528 done on the assembly output. */
530 int flag_no_function_cse = 0;
532 /* Nonzero for -fomit-frame-pointer:
533 don't make a frame pointer in simple functions that don't require one. */
535 int flag_omit_frame_pointer = 0;
537 /* Nonzero means place each function into its own section on those platforms
538 which support arbitrary section names and unlimited numbers of sections. */
540 int flag_function_sections = 0;
542 /* ... and similar for data. */
544 int flag_data_sections = 0;
546 /* Nonzero to inhibit use of define_optimization peephole opts. */
548 int flag_no_peephole = 0;
550 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
551 operations in the interest of optimization. For example it allows
552 GCC to assume arguments to sqrt are nonnegative numbers, allowing
553 faster code for sqrt to be generated. */
555 int flag_fast_math = 0;
557 /* Nonzero means all references through pointers are volatile. */
559 int flag_volatile;
561 /* Nonzero means treat all global and extern variables as volatile. */
563 int flag_volatile_global;
565 /* Nonzero means treat all static variables as volatile. */
567 int flag_volatile_static;
569 /* Nonzero means just do syntax checking; don't output anything. */
571 int flag_syntax_only = 0;
573 /* Nonzero means perform global cse. */
575 static int flag_gcse;
577 /* Nonzero means to rerun cse after loop optimization. This increases
578 compilation time about 20% and picks up a few more common expressions. */
580 static int flag_rerun_cse_after_loop;
582 /* Nonzero means to run loop optimizations twice. */
584 int flag_rerun_loop_opt;
586 /* Nonzero for -finline-functions: ok to inline functions that look like
587 good inline candidates. */
589 int flag_inline_functions;
591 /* Nonzero for -fkeep-inline-functions: even if we make a function
592 go inline everywhere, keep its definition around for debugging
593 purposes. */
595 int flag_keep_inline_functions;
597 /* Nonzero means that functions will not be inlined. */
599 int flag_no_inline;
601 /* Nonzero means that we should emit static const variables
602 regardless of whether or not optimization is turned on. */
604 int flag_keep_static_consts = 1;
606 /* Nonzero means we should be saving declaration info into a .X file. */
608 int flag_gen_aux_info = 0;
610 /* Specified name of aux-info file. */
612 static char *aux_info_file_name;
614 /* Nonzero means make the text shared if supported. */
616 int flag_shared_data;
618 /* Nonzero means schedule into delayed branch slots if supported. */
620 int flag_delayed_branch;
622 /* Nonzero if we are compiling pure (sharable) code.
623 Value is 1 if we are doing reasonable (i.e. simple
624 offset into offset table) pic. Value is 2 if we can
625 only perform register offsets. */
627 int flag_pic;
629 /* Nonzero means generate extra code for exception handling and enable
630 exception handling. */
632 int flag_exceptions;
634 /* Nonzero means use the new model for exception handling. Replaces
635 -DNEW_EH_MODEL as a compile option. */
637 int flag_new_exceptions = 0;
639 /* Nonzero means don't place uninitialized global data in common storage
640 by default. */
642 int flag_no_common;
644 /* Nonzero means pretend it is OK to examine bits of target floats,
645 even if that isn't true. The resulting code will have incorrect constants,
646 but the same series of instructions that the native compiler would make. */
648 int flag_pretend_float;
650 /* Nonzero means change certain warnings into errors.
651 Usually these are warnings about failure to conform to some standard. */
653 int flag_pedantic_errors = 0;
655 /* flag_schedule_insns means schedule insns within basic blocks (before
656 local_alloc).
657 flag_schedule_insns_after_reload means schedule insns after
658 global_alloc. */
660 int flag_schedule_insns = 0;
661 int flag_schedule_insns_after_reload = 0;
663 #ifdef HAIFA
664 /* The following flags have effect only for scheduling before register
665 allocation:
667 flag_schedule_interblock means schedule insns accross basic blocks.
668 flag_schedule_speculative means allow speculative motion of non-load insns.
669 flag_schedule_speculative_load means allow speculative motion of some
670 load insns.
671 flag_schedule_speculative_load_dangerous allows speculative motion of more
672 load insns. */
674 int flag_schedule_interblock = 1;
675 int flag_schedule_speculative = 1;
676 int flag_schedule_speculative_load = 0;
677 int flag_schedule_speculative_load_dangerous = 0;
678 #endif /* HAIFA */
680 /* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
681 by a cheaper branch, on a count register. */
682 int flag_branch_on_count_reg;
684 /* -finhibit-size-directive inhibits output of .size for ELF.
685 This is used only for compiling crtstuff.c,
686 and it may be extended to other effects
687 needed for crtstuff.c on other systems. */
688 int flag_inhibit_size_directive = 0;
690 /* -fverbose-asm causes extra commentary information to be produced in
691 the generated assembly code (to make it more readable). This option
692 is generally only of use to those who actually need to read the
693 generated assembly code (perhaps while debugging the compiler itself).
694 -fno-verbose-asm, the default, causes the extra information
695 to be omitted and is useful when comparing two assembler files. */
697 int flag_verbose_asm = 0;
699 /* -dA causes debug commentary information to be produced in
700 the generated assembly code (to make it more readable). This option
701 is generally only of use to those who actually need to read the
702 generated assembly code (perhaps while debugging the compiler itself).
703 Currently, this switch is only used by dwarfout.c; however, it is intended
704 to be a catchall for printing debug information in the assembler file. */
706 int flag_debug_asm = 0;
708 /* -fgnu-linker specifies use of the GNU linker for initializations.
709 (Or, more generally, a linker that handles initializations.)
710 -fno-gnu-linker says that collect2 will be used. */
711 #ifdef USE_COLLECT2
712 int flag_gnu_linker = 0;
713 #else
714 int flag_gnu_linker = 1;
715 #endif
717 /* Tag all structures with __attribute__(packed) */
718 int flag_pack_struct = 0;
720 /* Emit code to check for stack overflow; also may cause large objects
721 to be allocated dynamically. */
722 int flag_stack_check;
724 /* -fcheck-memory-usage causes extra code to be generated in order to check
725 memory accesses. This is used by a detector of bad memory accesses such
726 as Checker. */
727 int flag_check_memory_usage = 0;
729 /* -fprefix-function-name causes function name to be prefixed. This
730 can be used with -fcheck-memory-usage to isolate code compiled with
731 -fcheck-memory-usage. */
732 int flag_prefix_function_name = 0;
734 /* 0 if pointer arguments may alias each other. True in C.
735 1 if pointer arguments may not alias each other but may alias
736 global variables.
737 2 if pointer arguments may not alias each other and may not
738 alias global variables. True in Fortran.
739 This defaults to 0 for C. */
740 int flag_argument_noalias = 0;
742 /* Nonzero if we should do (language-dependent) alias analysis.
743 Typically, this analysis will assume that expressions of certain
744 types do not alias expressions of certain other types. Only used
745 if alias analysis (in general) is enabled. */
746 int flag_strict_aliasing = 0;
748 /* Instrument functions with calls at entry and exit, for profiling. */
749 int flag_instrument_function_entry_exit = 0;
751 /* Nonzero means ignore `#ident' directives. 0 means handle them.
752 On SVR4 targets, it also controls whether or not to emit a
753 string identifying the compiler. */
755 int flag_no_ident = 0;
757 /* Table of supported debugging formats. */
758 static struct
760 const char * arg;
761 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
762 constant expression, we use NO_DEBUG in its place. */
763 enum debug_info_type debug_type;
764 int use_extensions_p;
765 const char * description;
766 } *da,
767 debug_args[] =
769 { "g", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
770 "Generate default debug format output" },
771 { "ggdb", NO_DEBUG, 1, "Generate default extended debug format output" },
772 #ifdef DBX_DEBUGGING_INFO
773 { "gstabs", DBX_DEBUG, 0, "Generate STABS format debug output" },
774 { "gstabs+", DBX_DEBUG, 1, "Generate extended STABS format debug output" },
775 #endif
776 #ifdef DWARF_DEBUGGING_INFO
777 { "gdwarf", DWARF_DEBUG, 0, "Generate DWARF-1 format debug output"},
778 { "gdwarf+", DWARF_DEBUG, 1,
779 "Generated extended DWARF-1 format debug output" },
780 #endif
781 #ifdef DWARF2_DEBUGGING_INFO
782 { "gdwarf-2", DWARF2_DEBUG, 0, "Enable DWARF-2 debug output" },
783 #endif
784 #ifdef XCOFF_DEBUGGING_INFO
785 { "gxcoff", XCOFF_DEBUG, 0, "Generate XCOFF format debug output" },
786 { "gxcoff+", XCOFF_DEBUG, 1, "Generate extended XCOFF format debug output" },
787 #endif
788 #ifdef SDB_DEBUGGING_INFO
789 { "gcoff", SDB_DEBUG, 0, "Generate COFF format debug output" },
790 #endif
791 { 0, 0, 0, 0 }
794 typedef struct
796 const char * string;
797 int * variable;
798 int on_value;
799 const char * description;
801 lang_independent_options;
803 /* Add or remove a leading underscore from user symbols. */
804 int flag_leading_underscore = -1;
806 /* The user symbol prefix after having resolved same. */
807 const char *user_label_prefix;
809 /* A default for same. */
810 #ifndef USER_LABEL_PREFIX
811 #define USER_LABEL_PREFIX ""
812 #endif
814 /* Table of language-independent -f options.
815 STRING is the option name. VARIABLE is the address of the variable.
816 ON_VALUE is the value to store in VARIABLE
817 if `-fSTRING' is seen as an option.
818 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
820 lang_independent_options f_options[] =
822 {"float-store", &flag_float_store, 1,
823 "Do not store floats in registers" },
824 {"volatile", &flag_volatile, 1,
825 "Consider all mem refs through pointers as volatile"},
826 {"volatile-global", &flag_volatile_global, 1,
827 "Consider all mem refs to global data to be volatile" },
828 {"volatile-static", &flag_volatile_static, 1,
829 "Consider all mem refs to static data to be volatile" },
830 {"defer-pop", &flag_defer_pop, 1,
831 "Defer popping functions args from stack until later" },
832 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
833 "When possible do not generate stack frames"},
834 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
835 "When running CSE, follow jumps to their targets" },
836 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
837 "When running CSE, follow conditional jumps" },
838 {"expensive-optimizations", &flag_expensive_optimizations, 1,
839 "Perform a number of minor, expensive optimisations" },
840 {"thread-jumps", &flag_thread_jumps, 1,
841 "Perform jump threading optimisations"},
842 {"strength-reduce", &flag_strength_reduce, 1,
843 "Perform strength reduction optimisations" },
844 {"unroll-loops", &flag_unroll_loops, 1,
845 "Perform loop unrolling when iteration count is known" },
846 {"unroll-all-loops", &flag_unroll_all_loops, 1,
847 "Perform loop unrolling for all loops" },
848 {"move-all-movables", &flag_move_all_movables, 1,
849 "Force all loop invariant computations out of loops" },
850 {"reduce-all-givs", &flag_reduce_all_givs, 1,
851 "Strength reduce all loop general induction variables" },
852 {"writable-strings", &flag_writable_strings, 1,
853 "Store strings in writable data section" },
854 {"peephole", &flag_no_peephole, 0,
855 "Enable machine specific peephole optimisations" },
856 {"force-mem", &flag_force_mem, 1,
857 "Copy memory operands into registers before using" },
858 {"force-addr", &flag_force_addr, 1,
859 "Copy memory address constants into regs before using" },
860 {"function-cse", &flag_no_function_cse, 0,
861 "Allow function addresses to be held in registers" },
862 {"inline-functions", &flag_inline_functions, 1,
863 "Integrate simple functions into their callers" },
864 {"keep-inline-functions", &flag_keep_inline_functions, 1,
865 "Generate code for funcs even if they are fully inlined" },
866 {"inline", &flag_no_inline, 0,
867 "Pay attention to the 'inline' keyword"},
868 {"keep-static-consts", &flag_keep_static_consts, 1,
869 "Emit static const variables even if they are not used" },
870 {"syntax-only", &flag_syntax_only, 1,
871 "Check for syntax errors, then stop" },
872 {"shared-data", &flag_shared_data, 1,
873 "Mark data as shared rather than private" },
874 {"caller-saves", &flag_caller_saves, 1,
875 "Enable saving registers around function calls" },
876 {"pcc-struct-return", &flag_pcc_struct_return, 1,
877 "Return 'short' aggregates in memory, not registers" },
878 {"reg-struct-return", &flag_pcc_struct_return, 0,
879 "Return 'short' aggregates in registers" },
880 {"delayed-branch", &flag_delayed_branch, 1,
881 "Attempt to fill delay slots of branch instructions" },
882 {"gcse", &flag_gcse, 1,
883 "Perform the global common subexpression elimination" },
884 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
885 "Run CSE pass after loop optimisations"},
886 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
887 "Run the loop optimiser twice"},
888 {"pretend-float", &flag_pretend_float, 1,
889 "Pretend that host and target use the same FP format"},
890 {"schedule-insns", &flag_schedule_insns, 1,
891 "Reschedule instructions to avoid pipeline stalls"},
892 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
893 "Run two passes of the instruction scheduler"},
894 #ifdef HAIFA
895 {"sched-interblock",&flag_schedule_interblock, 1,
896 "Enable scheduling across basic blocks" },
897 {"sched-spec",&flag_schedule_speculative, 1,
898 "Allow speculative motion of non-loads" },
899 {"sched-spec-load",&flag_schedule_speculative_load, 1,
900 "Allow speculative motion of some loads" },
901 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
902 "Allow speculative motion of more loads" },
903 #endif /* HAIFA */
904 {"branch-count-reg",&flag_branch_on_count_reg, 1,
905 "Replace add,compare,branch with branch on count reg"},
906 {"pic", &flag_pic, 1,
907 "Generate position independent code, if possible"},
908 {"PIC", &flag_pic, 2, ""},
909 {"exceptions", &flag_exceptions, 1,
910 "Enable exception handling" },
911 {"new-exceptions", &flag_new_exceptions, 1,
912 "Use the new model for exception handling" },
913 {"sjlj-exceptions", &exceptions_via_longjmp, 1,
914 "Use setjmp/longjmp to handle exceptions" },
915 {"asynchronous-exceptions", &asynchronous_exceptions, 1,
916 "Support asynchronous exceptions" },
917 {"profile-arcs", &profile_arc_flag, 1,
918 "Insert arc based program profiling code" },
919 {"test-coverage", &flag_test_coverage, 1,
920 "Create data files needed by gcov" },
921 {"branch-probabilities", &flag_branch_probabilities, 1,
922 "Use profiling information for branch probabilities" },
923 {"fast-math", &flag_fast_math, 1,
924 "Improve FP speed by violating ANSI & IEEE rules" },
925 {"common", &flag_no_common, 0,
926 "Do not put unitialised globals in the common section" },
927 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
928 "Do not generate .size directives" },
929 {"function-sections", &flag_function_sections, 1,
930 "place each function into its own section" },
931 {"data-sections", &flag_data_sections, 1,
932 "place data items into their own section" },
933 {"verbose-asm", &flag_verbose_asm, 1,
934 "Add extra commentry to assembler output"},
935 {"gnu-linker", &flag_gnu_linker, 1,
936 "Output GNU ld formatted global initialisers"},
937 {"regmove", &flag_regmove, 1,
938 "Enables a register move optimisation"},
939 {"optimize-register-move", &flag_regmove, 1,
940 "Do the full regmove optimization pass"},
941 {"pack-struct", &flag_pack_struct, 1,
942 "Pack structure members together without holes" },
943 {"stack-check", &flag_stack_check, 1,
944 "Insert stack checking code into the program" },
945 {"argument-alias", &flag_argument_noalias, 0,
946 "Specify that arguments may alias each other & globals"},
947 {"argument-noalias", &flag_argument_noalias, 1,
948 "Assume arguments may alias globals but not each other"},
949 {"argument-noalias-global", &flag_argument_noalias, 2,
950 "Assume arguments do not alias each other or globals" },
951 {"strict-aliasing", &flag_strict_aliasing, 1,
952 "Assume strict aliasing rules apply" },
953 {"check-memory-usage", &flag_check_memory_usage, 1,
954 "Generate code to check every memory access" },
955 {"prefix-function-name", &flag_prefix_function_name, 1,
956 "Add a prefix to all function names" },
957 {"dump-unnumbered", &flag_dump_unnumbered, 1,
958 "Suppress output of instruction numbers and line number notes in debugging dumps"},
959 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
960 "Instrument function entry/exit with profiling calls"},
961 {"leading-underscore", &flag_leading_underscore, 1,
962 "External symbols have a leading underscore" },
963 {"ident", &flag_no_ident, 0,
964 "Process #ident directives"}
967 #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0]))
969 /* Table of language-specific options. */
971 static struct lang_opt
973 const char * option;
974 const char * description;
976 documented_lang_options[] =
978 /* In order not to overload the --help output, the convention
979 used here is to only describe those options which are not
980 enabled by default. */
982 { "-ansi", "Compile just for ANSI C" },
983 { "-fallow-single-precision",
984 "Do not promote floats to double if using -traditional" },
985 { "-std= ", "Determine language standard"},
987 { "-fsigned-bitfields", "" },
988 { "-funsigned-bitfields","Make bitfields by unsigned by default" },
989 { "-fno-signed-bitfields", "" },
990 { "-fno-unsigned-bitfields","" },
991 { "-fsigned-char", "Make 'char' be signed by default"},
992 { "-funsigned-char", "Make 'char' be unsigned by default"},
993 { "-fno-signed-char", "" },
994 { "-fno-unsigned-char", "" },
996 { "-ftraditional", "" },
997 { "-traditional", "Attempt to support traditional K&R style C"},
998 { "-fnotraditional", "" },
999 { "-fno-traditional", "" },
1001 { "-fasm", "" },
1002 { "-fno-asm", "Do not recognise the 'asm' keyword" },
1003 { "-fbuiltin", "" },
1004 { "-fno-builtin", "Do not recognise any built in functions" },
1005 { "-fhosted", "Assume normal C execution environment" },
1006 { "-fno-hosted", "" },
1007 { "-ffreestanding",
1008 "Assume that standard libraries & main might not exist" },
1009 { "-fno-freestanding", "" },
1010 { "-fcond-mismatch", "Allow different types as args of ? operator"},
1011 { "-fno-cond-mismatch", "" },
1012 { "-fdollars-in-identifiers", "Allow the use of $ inside identifiers" },
1013 { "-fno-dollars-in-identifiers", "" },
1014 { "-fshort-double", "Use the same size for double as for float" },
1015 { "-fno-short-double", "" },
1016 { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
1017 { "-fno-short-enums", "" },
1019 { "-Wall", "Enable most warning messages" },
1020 { "-Wbad-function-cast",
1021 "Warn about casting functions to incompatible types" },
1022 { "-Wno-bad-function-cast", "" },
1023 { "-Wmissing-noreturn",
1024 "Warn about functions which might be candidates for attribute noreturn" },
1025 { "-Wno-missing-noreturn", "" },
1026 { "-Wcast-qual", "Warn about casts which discard qualifiers"},
1027 { "-Wno-cast-qual", "" },
1028 { "-Wchar-subscripts", "Warn about subscripts whose type is 'char'"},
1029 { "-Wno-char-subscripts", "" },
1030 { "-Wcomment", "Warn if nested comments are detected" },
1031 { "-Wno-comment", "" },
1032 { "-Wcomments", "Warn if nested comments are detected" },
1033 { "-Wno-comments", "" },
1034 { "-Wconversion", "Warn about possibly confusing type conversions" },
1035 { "-Wno-conversion", "" },
1036 { "-Wformat", "Warn about printf format anomalies" },
1037 { "-Wno-format", "" },
1038 { "-Wimplicit-function-declaration",
1039 "Warn about implicit function declarations" },
1040 { "-Wno-implicit-function-declaration", "" },
1041 { "-Werror-implicit-function-declaration", "" },
1042 { "-Wimplicit-int", "Warn when a declaration does not specify a type" },
1043 { "-Wno-implicit-int", "" },
1044 { "-Wimplicit", "" },
1045 { "-Wno-implicit", "" },
1046 { "-Wimport", "Warn about the use of the #import directive" },
1047 { "-Wno-import", "" },
1048 { "-Wlong-long","" },
1049 { "-Wno-long-long", "Do not warn about using 'long long' when -pedantic" },
1050 { "-Wmain", "Warn about suspicious declarations of main" },
1051 { "-Wno-main", "" },
1052 { "-Wmissing-braces",
1053 "Warn about possibly missing braces around initialisers" },
1054 { "-Wno-missing-braces", "" },
1055 { "-Wmissing-declarations",
1056 "Warn about global funcs without previous declarations"},
1057 { "-Wno-missing-declarations", "" },
1058 { "-Wmissing-prototypes", "Warn about global funcs without prototypes" },
1059 { "-Wno-missing-prototypes", "" },
1060 { "-Wmultichar", "Warn about use of multicharacter literals"},
1061 { "-Wno-multichar", "" },
1062 { "-Wnested-externs", "Warn about externs not at file scope level" },
1063 { "-Wno-nested-externs", "" },
1064 { "-Wparentheses", "Warn about possible missing parentheses" },
1065 { "-Wno-parentheses", "" },
1066 { "-Wpointer-arith", "Warn about function pointer arithmetic" },
1067 { "-Wno-pointer-arith", "" },
1068 { "-Wredundant-decls",
1069 "Warn about multiple declarations of the same object" },
1070 { "-Wno-redundant-decls", "" },
1071 { "-Wsign-compare", "Warn about signed/unsigned comparisons" },
1072 { "-Wno-sign-compare", "" },
1073 { "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
1074 { "-Wno-unknown-pragmas", "" },
1075 { "-Wstrict-prototypes", "Warn about non-prototyped function decls" },
1076 { "-Wno-strict-prototypes", "" },
1077 { "-Wtraditional", "Warn about constructs whose meaning change in ANSI C"},
1078 { "-Wno-traditional", "" },
1079 { "-Wtrigraphs", "Warn when trigraphs are encountered" },
1080 { "-Wno-trigraphs", "" },
1081 { "-Wundef", "" },
1082 { "-Wno-undef", "" },
1083 { "-Wwrite-strings", "Mark strings as 'const char *'"},
1084 { "-Wno-write-strings", "" },
1086 /* These are for languages with USE_CPPLIB. */
1087 /* These options are already documented in cpplib.c */
1088 { "--help", "" },
1089 { "-A", "" },
1090 { "-D", "" },
1091 { "-I", "" },
1092 { "-U", "" },
1093 { "-H", "" },
1094 { "-idirafter", "" },
1095 { "-imacros", "" },
1096 { "-include", "" },
1097 { "-iprefix", "" },
1098 { "-isystem", "" },
1099 { "-iwithprefix", "" },
1100 { "-iwithprefixbefore", "" },
1101 { "-lang-c", "" },
1102 { "-lang-c89", "" },
1103 { "-lang-c++", "" },
1104 { "-remap", "" },
1105 { "-nostdinc", "" },
1106 { "-nostdinc++", "" },
1107 { "-trigraphs", "" },
1108 { "-undef", "" },
1110 #define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1112 /* These are for obj c. */
1113 DEFINE_LANG_NAME ("Objective C")
1115 { "-lang-objc", "" },
1116 { "-gen-decls", "Dump decls to a .decl file" },
1117 { "-fgnu-runtime", "Generate code for GNU runtime environment" },
1118 { "-fno-gnu-runtime", "" },
1119 { "-fnext-runtime", "Generate code for NeXT runtime environment" },
1120 { "-fno-next-runtime", "" },
1121 { "-Wselector", "Warn if a selector has multiple methods" },
1122 { "-Wno-selector", "" },
1123 { "-Wprotocol", "" },
1124 { "-Wno-protocol", "Do not warn if inherited methods are unimplemented"},
1125 { "-print-objc-runtime-info",
1126 "Generate C header of platform specific features" },
1128 #include "options.h"
1132 /* Here is a table, controlled by the tm.h file, listing each -m switch
1133 and which bits in `target_switches' it should set or clear.
1134 If VALUE is positive, it is bits to set.
1135 If VALUE is negative, -VALUE is bits to clear.
1136 (The sign bit is not used so there is no confusion.) */
1138 struct
1140 const char * name;
1141 int value;
1142 const char * description;
1144 target_switches [] = TARGET_SWITCHES;
1146 /* This table is similar, but allows the switch to have a value. */
1148 #ifdef TARGET_OPTIONS
1149 struct
1151 const char * prefix;
1152 const char ** variable;
1153 const char * description;
1155 target_options [] = TARGET_OPTIONS;
1156 #endif
1158 /* Options controlling warnings */
1160 /* Don't print warning messages. -w. */
1162 int inhibit_warnings = 0;
1164 /* Print various extra warnings. -W. */
1166 int extra_warnings = 0;
1168 /* Treat warnings as errors. -Werror. */
1170 int warnings_are_errors = 0;
1172 /* Nonzero to warn about unused local variables. */
1174 int warn_unused;
1176 /* Nonzero to warn about variables used before they are initialized. */
1178 int warn_uninitialized;
1180 /* Nonzero means warn about all declarations which shadow others. */
1182 int warn_shadow;
1184 /* Warn if a switch on an enum fails to have a case for every enum value. */
1186 int warn_switch;
1188 /* Nonzero means warn about function definitions that default the return type
1189 or that use a null return and have a return-type other than void. */
1191 int warn_return_type;
1193 /* Nonzero means warn about pointer casts that increase the required
1194 alignment of the target type (and might therefore lead to a crash
1195 due to a misaligned access). */
1197 int warn_cast_align;
1199 /* Nonzero means warn about any identifiers that match in the first N
1200 characters. The value N is in `id_clash_len'. */
1202 int warn_id_clash;
1203 unsigned id_clash_len;
1205 /* Nonzero means warn about any objects definitions whose size is larger
1206 than N bytes. Also want about function definitions whose returned
1207 values are larger than N bytes. The value N is in `larger_than_size'. */
1209 int warn_larger_than;
1210 unsigned larger_than_size;
1212 /* Nonzero means warn if inline function is too large. */
1214 int warn_inline;
1216 /* Warn if a function returns an aggregate,
1217 since there are often incompatible calling conventions for doing this. */
1219 int warn_aggregate_return;
1221 /* Likewise for -W. */
1223 lang_independent_options W_options[] =
1225 {"unused", &warn_unused, 1, "Warn when a variable is unused" },
1226 {"error", &warnings_are_errors, 1, ""},
1227 {"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
1228 {"switch", &warn_switch, 1,
1229 "Warn about enumerated switches missing a specific case" },
1230 {"aggregate-return", &warn_aggregate_return, 1,
1231 "Warn about returning structures, unions or arrays" },
1232 {"cast-align", &warn_cast_align, 1,
1233 "Warn about pointer casts which increase alignment" },
1234 {"uninitialized", &warn_uninitialized, 1,
1235 "Warn about unitialized automatic variables"},
1236 {"inline", &warn_inline, 1,
1237 "Warn when an inlined function cannot be inlined"}
1240 /* Output files for assembler code (real compiler output)
1241 and debugging dumps. */
1243 FILE *asm_out_file;
1244 FILE *aux_info_file;
1245 FILE *rtl_dump_file = NULL;
1247 /* Decode the string P as an integral parameter.
1248 If the string is indeed an integer return its numeric value else
1249 issue an Invalid Option error for the option PNAME and return DEFVAL.
1250 If PNAME is zero just return DEFVAL, do not call error. */
1253 read_integral_parameter (p, pname, defval)
1254 const char *p;
1255 const char *pname;
1256 const int defval;
1258 const char *endp = p;
1260 while (*endp)
1262 if (*endp >= '0' && *endp <= '9')
1263 endp++;
1264 else
1265 break;
1268 if (*endp != 0)
1270 if (pname != 0)
1271 error ("Invalid option `%s'", pname);
1272 return defval;
1275 return atoi (p);
1279 /* Time accumulators, to count the total time spent in various passes. */
1281 int parse_time;
1282 int varconst_time;
1283 int integration_time;
1284 int jump_time;
1285 int cse_time;
1286 int gcse_time;
1287 int loop_time;
1288 int cse2_time;
1289 int branch_prob_time;
1290 int flow_time;
1291 int combine_time;
1292 int regmove_time;
1293 int sched_time;
1294 int local_alloc_time;
1295 int global_alloc_time;
1296 int flow2_time;
1297 int sched2_time;
1298 #ifdef DELAY_SLOTS
1299 int dbr_sched_time;
1300 #endif
1301 int shorten_branch_time;
1302 int stack_reg_time;
1303 int final_time;
1304 int symout_time;
1305 int dump_time;
1307 /* Return time used so far, in microseconds. */
1309 long
1310 get_run_time ()
1312 if (quiet_flag)
1313 return 0;
1315 #ifdef __BEOS__
1316 return 0;
1317 #else /* not BeOS */
1318 #if defined (_WIN32) && !defined (__CYGWIN__)
1319 if (clock() < 0)
1320 return 0;
1321 else
1322 return (clock() * 1000);
1323 #else /* not _WIN32 */
1324 #ifdef _SC_CLK_TCK
1326 static int tick;
1327 struct tms tms;
1328 if (tick == 0)
1329 tick = 1000000 / sysconf(_SC_CLK_TCK);
1330 times (&tms);
1331 return (tms.tms_utime + tms.tms_stime) * tick;
1333 #else
1334 #ifdef USG
1336 struct tms tms;
1337 # if HAVE_SYSCONF && defined _SC_CLK_TCK
1338 # define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
1339 # else
1340 # ifdef CLK_TCK
1341 # define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
1342 # else
1343 # define TICKS_PER_SECOND HZ /* traditional UNIX */
1344 # endif
1345 # endif
1346 times (&tms);
1347 return (tms.tms_utime + tms.tms_stime) * (1000000 / TICKS_PER_SECOND);
1349 #else
1350 #ifndef VMS
1352 struct rusage rusage;
1353 getrusage (0, &rusage);
1354 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1355 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1357 #else /* VMS */
1359 struct
1361 int proc_user_time;
1362 int proc_system_time;
1363 int child_user_time;
1364 int child_system_time;
1365 } vms_times;
1366 times ((void *) &vms_times);
1367 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
1369 #endif /* VMS */
1370 #endif /* USG */
1371 #endif /* _SC_CLK_TCK */
1372 #endif /* _WIN32 */
1373 #endif /* __BEOS__ */
1376 #define TIMEVAR(VAR, BODY) \
1377 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1379 void
1380 print_time (str, total)
1381 const char *str;
1382 int total;
1384 fprintf (stderr,
1385 "time in %s: %d.%06d\n",
1386 str, total / 1000000, total % 1000000);
1389 /* Count an error or warning. Return 1 if the message should be printed. */
1392 count_error (warningp)
1393 int warningp;
1395 if (warningp && inhibit_warnings)
1396 return 0;
1398 if (warningp && !warnings_are_errors)
1399 warningcount++;
1400 else
1402 static int warning_message = 0;
1404 if (warningp && !warning_message)
1406 notice ("%s: warnings being treated as errors\n", progname);
1407 warning_message = 1;
1409 errorcount++;
1412 return 1;
1415 /* Print a fatal error message. NAME is the text.
1416 Also include a system error message based on `errno'. */
1418 void
1419 pfatal_with_name (name)
1420 const char *name;
1422 fprintf (stderr, "%s: ", progname);
1423 perror (name);
1424 exit (FATAL_EXIT_CODE);
1427 void
1428 fatal_io_error (name)
1429 const char *name;
1431 notice ("%s: %s: I/O error\n", progname, name);
1432 exit (FATAL_EXIT_CODE);
1435 /* Called to give a better error message for a bad insn rather than
1436 just calling abort(). */
1438 void
1439 fatal_insn VPROTO((const char *msgid, rtx insn, ...))
1441 #ifndef ANSI_PROTOTYPES
1442 const char *msgid;
1443 rtx insn;
1444 #endif
1445 va_list ap;
1447 VA_START (ap, insn);
1449 #ifndef ANSI_PROTOTYPES
1450 msgid = va_arg (ap, const char *);
1451 insn = va_arg (ap, rtx);
1452 #endif
1454 verror (msgid, ap);
1455 debug_rtx (insn);
1456 exit (FATAL_EXIT_CODE);
1459 /* Called to give a better error message when we don't have an insn to match
1460 what we are looking for or if the insn's constraints aren't satisfied,
1461 rather than just calling abort(). */
1463 void
1464 fatal_insn_not_found (insn)
1465 rtx insn;
1467 if (INSN_CODE (insn) < 0)
1468 fatal_insn ("internal error--unrecognizable insn:", insn);
1469 else
1470 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1473 /* This is the default decl_printable_name function. */
1475 static char *
1476 decl_name (decl, verbosity)
1477 tree decl;
1478 int verbosity ATTRIBUTE_UNUSED;
1480 return IDENTIFIER_POINTER (DECL_NAME (decl));
1483 static int need_error_newline;
1485 /* Function of last error message;
1486 more generally, function such that if next error message is in it
1487 then we don't have to mention the function name. */
1488 static tree last_error_function = NULL;
1490 /* Used to detect when input_file_stack has changed since last described. */
1491 static int last_error_tick;
1493 /* Called when the start of a function definition is parsed,
1494 this function prints on stderr the name of the function. */
1496 void
1497 announce_function (decl)
1498 tree decl;
1500 if (! quiet_flag)
1502 if (rtl_dump_and_exit)
1503 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1504 else
1505 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1506 fflush (stderr);
1507 need_error_newline = 1;
1508 last_error_function = current_function_decl;
1512 /* The default function to print out name of current function that caused
1513 an error. */
1515 void
1516 default_print_error_function (file)
1517 const char *file;
1519 if (last_error_function != current_function_decl)
1521 if (file)
1522 fprintf (stderr, "%s: ", file);
1524 if (current_function_decl == NULL)
1525 notice ("At top level:\n");
1526 else
1527 notice ((TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE
1528 ? "In method `%s':\n"
1529 : "In function `%s':\n"),
1530 (*decl_printable_name) (current_function_decl, 2));
1532 last_error_function = current_function_decl;
1536 /* Called by report_error_function to print out function name.
1537 * Default may be overridden by language front-ends. */
1539 void (*print_error_function) PROTO((const char *)) =
1540 default_print_error_function;
1542 /* Prints out, if necessary, the name of the current function
1543 that caused an error. Called from all error and warning functions. */
1545 void
1546 report_error_function (file)
1547 const char *file;
1549 struct file_stack *p;
1551 if (need_error_newline)
1553 fprintf (stderr, "\n");
1554 need_error_newline = 0;
1557 (*print_error_function) (file);
1559 if (input_file_stack && input_file_stack->next != 0
1560 && input_file_stack_tick != last_error_tick
1561 && file == input_filename)
1563 for (p = input_file_stack->next; p; p = p->next)
1564 notice ((p == input_file_stack->next
1565 ? "In file included from %s:%d"
1566 : ",\n from %s:%d"),
1567 p->name, p->line);
1568 fprintf (stderr, ":\n");
1569 last_error_tick = input_file_stack_tick;
1573 /* Print a message. */
1575 static void
1576 vnotice (file, msgid, ap)
1577 FILE *file;
1578 char *msgid;
1579 va_list ap;
1581 vfprintf (file, _(msgid), ap);
1584 void
1585 notice VPROTO((const char *msgid, ...))
1587 #ifndef ANSI_PROTOTYPES
1588 char *msgid;
1589 #endif
1590 va_list ap;
1592 VA_START (ap, msgid);
1594 #ifndef ANSI_PROTOTYPES
1595 msgid = va_arg (ap, char *);
1596 #endif
1598 vnotice (stderr, msgid, ap);
1599 va_end (ap);
1602 void
1603 fnotice VPROTO((FILE *file, const char *msgid, ...))
1605 #ifndef ANSI_PROTOTYPES
1606 FILE *file;
1607 const char *msgid;
1608 #endif
1609 va_list ap;
1611 VA_START (ap, msgid);
1613 #ifndef ANSI_PROTOTYPES
1614 file = va_arg (ap, FILE *);
1615 msgid = va_arg (ap, const char *);
1616 #endif
1618 vnotice (file, msgid, ap);
1619 va_end (ap);
1622 /* Report FILE and LINE (or program name), and optionally just WARN. */
1624 static void
1625 report_file_and_line (file, line, warn)
1626 char *file;
1627 int line;
1628 int warn;
1630 if (file)
1631 fprintf (stderr, "%s:%d: ", file, line);
1632 else
1633 fprintf (stderr, "%s: ", progname);
1635 if (warn)
1636 notice ("warning: ");
1639 /* Print a message. */
1641 static void
1642 vmessage (prefix, msgid, ap)
1643 const char *prefix;
1644 const char *msgid;
1645 va_list ap;
1647 if (prefix)
1648 fprintf (stderr, "%s: ", prefix);
1650 vfprintf (stderr, msgid, ap);
1653 /* Print a message relevant to line LINE of file FILE. */
1655 static void
1656 v_message_with_file_and_line (file, line, warn, msgid, ap)
1657 const char *file;
1658 int line;
1659 int warn;
1660 const char *msgid;
1661 va_list ap;
1663 report_file_and_line (file, line, warn);
1664 vnotice (stderr, msgid, ap);
1665 fputc ('\n', stderr);
1668 /* Print a message relevant to the given DECL. */
1670 static void
1671 v_message_with_decl (decl, warn, msgid, ap)
1672 tree decl;
1673 int warn;
1674 const char *msgid;
1675 va_list ap;
1677 const char *p;
1679 report_file_and_line (DECL_SOURCE_FILE (decl),
1680 DECL_SOURCE_LINE (decl), warn);
1682 /* Do magic to get around lack of varargs support for insertion
1683 of arguments into existing list. We know that the decl is first;
1684 we ass_u_me that it will be printed with "%s". */
1686 for (p = _(msgid); *p; ++p)
1688 if (*p == '%')
1690 if (*(p + 1) == '%')
1691 ++p;
1692 else if (*(p + 1) != 's')
1693 abort ();
1694 else
1695 break;
1699 if (p > _(msgid)) /* Print the left-hand substring. */
1701 char fmt[sizeof "%.255s"];
1702 long width = p - _(msgid);
1704 if (width > 255L) width = 255L; /* arbitrary */
1705 sprintf (fmt, "%%.%lds", width);
1706 fprintf (stderr, fmt, _(msgid));
1709 if (*p == '%') /* Print the name. */
1711 const char *n = (DECL_NAME (decl)
1712 ? (*decl_printable_name) (decl, 2)
1713 : "((anonymous))");
1714 fputs (n, stderr);
1715 while (*p)
1717 ++p;
1718 if (ISALPHA (*(p - 1) & 0xFF))
1719 break;
1723 if (*p) /* Print the rest of the message. */
1724 vmessage ((char *)NULL, p, ap);
1726 fputc ('\n', stderr);
1729 /* Figure file and line of the given INSN. */
1731 static void
1732 file_and_line_for_asm (insn, pfile, pline)
1733 rtx insn;
1734 char **pfile;
1735 int *pline;
1737 rtx body = PATTERN (insn);
1738 rtx asmop;
1740 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1741 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1742 asmop = SET_SRC (body);
1743 else if (GET_CODE (body) == ASM_OPERANDS)
1744 asmop = body;
1745 else if (GET_CODE (body) == PARALLEL
1746 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1747 asmop = SET_SRC (XVECEXP (body, 0, 0));
1748 else if (GET_CODE (body) == PARALLEL
1749 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1750 asmop = XVECEXP (body, 0, 0);
1751 else
1752 asmop = NULL;
1754 if (asmop)
1756 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1757 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1759 else
1761 *pfile = input_filename;
1762 *pline = lineno;
1766 /* Report an error at line LINE of file FILE. */
1768 static void
1769 v_error_with_file_and_line (file, line, msgid, ap)
1770 const char *file;
1771 int line;
1772 const char *msgid;
1773 va_list ap;
1775 count_error (0);
1776 report_error_function (file);
1777 v_message_with_file_and_line (file, line, 0, msgid, ap);
1780 void
1781 error_with_file_and_line VPROTO((const char *file, int line,
1782 const char *msgid, ...))
1784 #ifndef ANSI_PROTOTYPES
1785 const char *file;
1786 int line;
1787 const char *msgid;
1788 #endif
1789 va_list ap;
1791 VA_START (ap, msgid);
1793 #ifndef ANSI_PROTOTYPES
1794 file = va_arg (ap, const char *);
1795 line = va_arg (ap, int);
1796 msgid = va_arg (ap, const char *);
1797 #endif
1799 v_error_with_file_and_line (file, line, msgid, ap);
1800 va_end (ap);
1803 /* Report an error at the declaration DECL.
1804 MSGID is a format string which uses %s to substitute the declaration
1805 name; subsequent substitutions are a la printf. */
1807 static void
1808 v_error_with_decl (decl, msgid, ap)
1809 tree decl;
1810 const char *msgid;
1811 va_list ap;
1813 count_error (0);
1814 report_error_function (DECL_SOURCE_FILE (decl));
1815 v_message_with_decl (decl, 0, msgid, ap);
1818 void
1819 error_with_decl VPROTO((tree decl, const char *msgid, ...))
1821 #ifndef ANSI_PROTOTYPES
1822 tree decl;
1823 const char *msgid;
1824 #endif
1825 va_list ap;
1827 VA_START (ap, msgid);
1829 #ifndef ANSI_PROTOTYPES
1830 decl = va_arg (ap, tree);
1831 msgid = va_arg (ap, const char *);
1832 #endif
1834 v_error_with_decl (decl, msgid, ap);
1835 va_end (ap);
1838 /* Report an error at the line number of the insn INSN.
1839 This is used only when INSN is an `asm' with operands,
1840 and each ASM_OPERANDS records its own source file and line. */
1842 static void
1843 v_error_for_asm (insn, msgid, ap)
1844 rtx insn;
1845 const char *msgid;
1846 va_list ap;
1848 char *file;
1849 int line;
1851 count_error (0);
1852 file_and_line_for_asm (insn, &file, &line);
1853 report_error_function (file);
1854 v_message_with_file_and_line (file, line, 0, msgid, ap);
1857 void
1858 error_for_asm VPROTO((rtx insn, const char *msgid, ...))
1860 #ifndef ANSI_PROTOTYPES
1861 rtx insn;
1862 const char *msgid;
1863 #endif
1864 va_list ap;
1866 VA_START (ap, msgid);
1868 #ifndef ANSI_PROTOTYPES
1869 insn = va_arg (ap, rtx);
1870 msgid = va_arg (ap, const char *);
1871 #endif
1873 v_error_for_asm (insn, msgid, ap);
1874 va_end (ap);
1877 /* Report an error at the current line number. */
1879 static void
1880 verror (msgid, ap)
1881 const char *msgid;
1882 va_list ap;
1884 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1887 void
1888 error VPROTO((const char *msgid, ...))
1890 #ifndef ANSI_PROTOTYPES
1891 const char *msgid;
1892 #endif
1893 va_list ap;
1895 VA_START (ap, msgid);
1897 #ifndef ANSI_PROTOTYPES
1898 msgid = va_arg (ap, const char *);
1899 #endif
1901 verror (msgid, ap);
1902 va_end (ap);
1905 /* Report a fatal error at the current line number. */
1907 static void
1908 vfatal (msgid, ap)
1909 const char *msgid;
1910 va_list ap;
1912 verror (msgid, ap);
1913 exit (FATAL_EXIT_CODE);
1916 void
1917 fatal VPROTO((const char *msgid, ...))
1919 #ifndef ANSI_PROTOTYPES
1920 const char *msgid;
1921 #endif
1922 va_list ap;
1924 VA_START (ap, msgid);
1926 #ifndef ANSI_PROTOTYPES
1927 msgid = va_arg (ap, const char *);
1928 #endif
1930 vfatal (msgid, ap);
1931 va_end (ap);
1934 /* Report a warning at line LINE of file FILE. */
1936 static void
1937 v_warning_with_file_and_line (file, line, msgid, ap)
1938 const char *file;
1939 int line;
1940 const char *msgid;
1941 va_list ap;
1943 if (count_error (1))
1945 report_error_function (file);
1946 v_message_with_file_and_line (file, line, 1, msgid, ap);
1950 void
1951 warning_with_file_and_line VPROTO((const char *file, int line,
1952 const char *msgid, ...))
1954 #ifndef ANSI_PROTOTYPES
1955 const char *file;
1956 int line;
1957 const char *msgid;
1958 #endif
1959 va_list ap;
1961 VA_START (ap, msgid);
1963 #ifndef ANSI_PROTOTYPES
1964 file = va_arg (ap, const char *);
1965 line = va_arg (ap, int);
1966 msgid = va_arg (ap, const char *);
1967 #endif
1969 v_warning_with_file_and_line (file, line, msgid, ap);
1970 va_end (ap);
1973 /* Report a warning at the declaration DECL.
1974 MSGID is a format string which uses %s to substitute the declaration
1975 name; subsequent substitutions are a la printf. */
1977 static void
1978 v_warning_with_decl (decl, msgid, ap)
1979 tree decl;
1980 const char *msgid;
1981 va_list ap;
1983 if (count_error (1))
1985 report_error_function (DECL_SOURCE_FILE (decl));
1986 v_message_with_decl (decl, 1, msgid, ap);
1990 void
1991 warning_with_decl VPROTO((tree decl, const char *msgid, ...))
1993 #ifndef ANSI_PROTOTYPES
1994 tree decl;
1995 const char *msgid;
1996 #endif
1997 va_list ap;
1999 VA_START (ap, msgid);
2001 #ifndef ANSI_PROTOTYPES
2002 decl = va_arg (ap, tree);
2003 msgid = va_arg (ap, const char *);
2004 #endif
2006 v_warning_with_decl (decl, msgid, ap);
2007 va_end (ap);
2010 /* Report a warning at the line number of the insn INSN.
2011 This is used only when INSN is an `asm' with operands,
2012 and each ASM_OPERANDS records its own source file and line. */
2014 static void
2015 v_warning_for_asm (insn, msgid, ap)
2016 rtx insn;
2017 const char *msgid;
2018 va_list ap;
2020 if (count_error (1))
2022 char *file;
2023 int line;
2025 file_and_line_for_asm (insn, &file, &line);
2026 report_error_function (file);
2027 v_message_with_file_and_line (file, line, 1, msgid, ap);
2031 void
2032 warning_for_asm VPROTO((rtx insn, const char *msgid, ...))
2034 #ifndef ANSI_PROTOTYPES
2035 rtx insn;
2036 const char *msgid;
2037 #endif
2038 va_list ap;
2040 VA_START (ap, msgid);
2042 #ifndef ANSI_PROTOTYPES
2043 insn = va_arg (ap, rtx);
2044 msgid = va_arg (ap, const char *);
2045 #endif
2047 v_warning_for_asm (insn, msgid, ap);
2048 va_end (ap);
2051 /* Report a warning at the current line number. */
2053 static void
2054 vwarning (msgid, ap)
2055 const char *msgid;
2056 va_list ap;
2058 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
2061 void
2062 warning VPROTO((const char *msgid, ...))
2064 #ifndef ANSI_PROTOTYPES
2065 const char *msgid;
2066 #endif
2067 va_list ap;
2069 VA_START (ap, msgid);
2071 #ifndef ANSI_PROTOTYPES
2072 msgid = va_arg (ap, const char *);
2073 #endif
2075 vwarning (msgid, ap);
2076 va_end (ap);
2079 /* These functions issue either warnings or errors depending on
2080 -pedantic-errors. */
2082 static void
2083 vpedwarn (msgid, ap)
2084 const char *msgid;
2085 va_list ap;
2087 if (flag_pedantic_errors)
2088 verror (msgid, ap);
2089 else
2090 vwarning (msgid, ap);
2093 void
2094 pedwarn VPROTO((const char *msgid, ...))
2096 #ifndef ANSI_PROTOTYPES
2097 const char *msgid;
2098 #endif
2099 va_list ap;
2101 VA_START (ap, msgid);
2103 #ifndef ANSI_PROTOTYPES
2104 msgid = va_arg (ap, const char *);
2105 #endif
2107 vpedwarn (msgid, ap);
2108 va_end (ap);
2111 static void
2112 v_pedwarn_with_decl (decl, msgid, ap)
2113 tree decl;
2114 const char *msgid;
2115 va_list ap;
2117 /* We don't want -pedantic-errors to cause the compilation to fail from
2118 "errors" in system header files. Sometimes fixincludes can't fix what's
2119 broken (eg: unsigned char bitfields - fixing it may change the alignment
2120 which will cause programs to mysteriously fail because the C library
2121 or kernel uses the original layout). There's no point in issuing a
2122 warning either, it's just unnecessary noise. */
2124 if (! DECL_IN_SYSTEM_HEADER (decl))
2126 if (flag_pedantic_errors)
2127 v_error_with_decl (decl, msgid, ap);
2128 else
2129 v_warning_with_decl (decl, msgid, ap);
2133 void
2134 pedwarn_with_decl VPROTO((tree decl, const char *msgid, ...))
2136 #ifndef ANSI_PROTOTYPES
2137 tree decl;
2138 const char *msgid;
2139 #endif
2140 va_list ap;
2142 VA_START (ap, msgid);
2144 #ifndef ANSI_PROTOTYPES
2145 decl = va_arg (ap, tree);
2146 msgid = va_arg (ap, const char *);
2147 #endif
2149 v_pedwarn_with_decl (decl, msgid, ap);
2150 va_end (ap);
2153 static void
2154 v_pedwarn_with_file_and_line (file, line, msgid, ap)
2155 const char *file;
2156 int line;
2157 const char *msgid;
2158 va_list ap;
2160 if (flag_pedantic_errors)
2161 v_error_with_file_and_line (file, line, msgid, ap);
2162 else
2163 v_warning_with_file_and_line (file, line, msgid, ap);
2166 void
2167 pedwarn_with_file_and_line VPROTO((const char *file, int line,
2168 const char *msgid, ...))
2170 #ifndef ANSI_PROTOTYPES
2171 const char *file;
2172 int line;
2173 const char *msgid;
2174 #endif
2175 va_list ap;
2177 VA_START (ap, msgid);
2179 #ifndef ANSI_PROTOTYPES
2180 file = va_arg (ap, const char *);
2181 line = va_arg (ap, int);
2182 msgid = va_arg (ap, const char *);
2183 #endif
2185 v_pedwarn_with_file_and_line (file, line, msgid, ap);
2186 va_end (ap);
2189 /* Apologize for not implementing some feature. */
2191 static void
2192 vsorry (msgid, ap)
2193 const char *msgid;
2194 va_list ap;
2196 sorrycount++;
2197 if (input_filename)
2198 fprintf (stderr, "%s:%d: ", input_filename, lineno);
2199 else
2200 fprintf (stderr, "%s: ", progname);
2201 notice ("sorry, not implemented: ");
2202 vnotice (stderr, msgid, ap);
2203 fputc ('\n', stderr);
2206 void
2207 sorry VPROTO((const char *msgid, ...))
2209 #ifndef ANSI_PROTOTYPES
2210 const char *msgid;
2211 #endif
2212 va_list ap;
2214 VA_START (ap, msgid);
2216 #ifndef ANSI_PROTOTYPES
2217 msgid = va_arg (ap, const char *);
2218 #endif
2220 vsorry (msgid, ap);
2221 va_end (ap);
2224 /* More 'friendly' abort that prints the line and file.
2225 config.h can #define abort fancy_abort if you like that sort of thing.
2227 I don't think this is actually a good idea.
2228 Other sorts of crashes will look a certain way.
2229 It is a good thing if crashes from calling abort look the same way.
2230 -- RMS */
2232 void
2233 fancy_abort ()
2235 fatal ("internal gcc abort");
2238 /* This calls abort and is used to avoid problems when abort if a macro.
2239 It is used when we need to pass the address of abort. */
2241 void
2242 do_abort ()
2244 abort ();
2247 /* When `malloc.c' is compiled with `rcheck' defined,
2248 it calls this function to report clobberage. */
2250 void
2251 botch (s)
2252 const char * s ATTRIBUTE_UNUSED;
2254 abort ();
2257 /* Same as `malloc' but report error if no memory available. */
2260 xmalloc (size)
2261 size_t size;
2263 register PTR value;
2265 if (size == 0)
2266 size = 1;
2268 value = (PTR) malloc (size);
2269 if (value == 0)
2270 fatal ("virtual memory exhausted");
2271 return value;
2274 /* Same as `calloc' but report error if no memory available. */
2277 xcalloc (size1, size2)
2278 size_t size1, size2;
2280 register PTR value;
2282 if (size1 == 0 || size2 == 0)
2283 size1 = size2 = 1;
2285 value = (PTR) calloc (size1, size2);
2286 if (value == 0)
2287 fatal ("virtual memory exhausted");
2288 return value;
2292 /* Same as `realloc' but report error if no memory available.
2293 Also handle null PTR even if the vendor realloc gets it wrong. */
2296 xrealloc (ptr, size)
2297 PTR ptr;
2298 size_t size;
2300 register PTR result;
2302 if (size == 0)
2303 size = 1;
2305 result = (ptr ? (PTR) realloc (ptr, size) : (PTR) malloc (size));
2307 if (!result)
2308 fatal ("virtual memory exhausted");
2310 return result;
2313 /* Same as `strdup' but report error if no memory available. */
2315 char *
2316 xstrdup (s)
2317 register const char *s;
2319 register char *result = (char *) malloc (strlen (s) + 1);
2321 if (! result)
2322 fatal ("virtual memory exhausted");
2323 strcpy (result, s);
2324 return result;
2327 /* Return the logarithm of X, base 2, considering X unsigned,
2328 if X is a power of 2. Otherwise, returns -1.
2330 This should be used via the `exact_log2' macro. */
2333 exact_log2_wide (x)
2334 register unsigned HOST_WIDE_INT x;
2336 register int log = 0;
2337 /* Test for 0 or a power of 2. */
2338 if (x == 0 || x != (x & -x))
2339 return -1;
2340 while ((x >>= 1) != 0)
2341 log++;
2342 return log;
2345 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
2346 If X is 0, return -1.
2348 This should be used via the floor_log2 macro. */
2351 floor_log2_wide (x)
2352 register unsigned HOST_WIDE_INT x;
2354 register int log = -1;
2355 while (x != 0)
2356 log++,
2357 x >>= 1;
2358 return log;
2361 static int float_handler_set;
2362 int float_handled;
2363 jmp_buf float_handler;
2365 /* Signals actually come here. */
2367 static void
2368 float_signal (signo)
2369 /* If this is missing, some compilers complain. */
2370 int signo ATTRIBUTE_UNUSED;
2372 if (float_handled == 0)
2373 abort ();
2374 #if defined (USG) || defined (hpux)
2375 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
2376 #endif
2377 float_handled = 0;
2378 signal (SIGFPE, float_signal);
2379 longjmp (float_handler, 1);
2382 /* Specify where to longjmp to when a floating arithmetic error happens.
2383 If HANDLER is 0, it means don't handle the errors any more. */
2385 void
2386 set_float_handler (handler)
2387 jmp_buf handler;
2389 float_handled = (handler != 0);
2390 if (handler)
2391 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2393 if (float_handled && ! float_handler_set)
2395 signal (SIGFPE, float_signal);
2396 float_handler_set = 1;
2400 /* This is a wrapper function for code which might elicit an
2401 arithmetic exception. That code should be passed in as a function
2402 pointer FN, and one argument DATA. DATA is usually a struct which
2403 contains the real input and output for function FN. This function
2404 returns 0 (failure) if longjmp was called (i.e. an exception
2405 occured.) It returns 1 (success) otherwise. */
2408 do_float_handler (fn, data)
2409 void (*fn) PROTO ((PTR));
2410 PTR data;
2412 jmp_buf buf;
2414 if (setjmp (buf))
2416 /* We got here via longjmp() caused by an exception in function fn() */
2417 set_float_handler (NULL);
2418 return 0;
2421 set_float_handler (buf);
2422 (*fn)(data);
2423 set_float_handler (NULL);
2424 return 1;
2427 /* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2428 error happens, pushing the previous specification into OLD_HANDLER.
2429 Return an indication of whether there was a previous handler in effect. */
2432 push_float_handler (handler, old_handler)
2433 jmp_buf handler, old_handler;
2435 int was_handled = float_handled;
2437 float_handled = 1;
2438 if (was_handled)
2439 memcpy ((char *) old_handler, (char *) float_handler,
2440 sizeof (float_handler));
2442 memcpy ((char *) float_handler, (char *) handler, sizeof (float_handler));
2443 return was_handled;
2446 /* Restore the previous specification of whether and where to longjmp to
2447 when a floating arithmetic error happens. */
2449 void
2450 pop_float_handler (handled, handler)
2451 int handled;
2452 jmp_buf handler;
2454 float_handled = handled;
2455 if (handled)
2456 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2459 /* Handler for SIGPIPE. */
2461 static void
2462 pipe_closed (signo)
2463 /* If this is missing, some compilers complain. */
2464 int signo ATTRIBUTE_UNUSED;
2466 fatal ("output pipe has been closed");
2469 /* Strip off a legitimate source ending from the input string NAME of
2470 length LEN. Rather than having to know the names used by all of
2471 our front ends, we strip off an ending of a period followed by
2472 up to five characters. (Java uses ".class".) */
2474 void
2475 strip_off_ending (name, len)
2476 char *name;
2477 int len;
2479 int i;
2480 for (i = 2; i < 6 && len > i; i++)
2482 if (name[len - i] == '.')
2484 name[len - i] = '\0';
2485 break;
2490 /* Output a quoted string. */
2492 void
2493 output_quoted_string (asm_file, string)
2494 FILE *asm_file;
2495 const char *string;
2497 #ifdef OUTPUT_QUOTED_STRING
2498 OUTPUT_QUOTED_STRING (asm_file, string);
2499 #else
2500 char c;
2502 putc ('\"', asm_file);
2503 while ((c = *string++) != 0)
2505 if (c == '\"' || c == '\\')
2506 putc ('\\', asm_file);
2507 putc (c, asm_file);
2509 putc ('\"', asm_file);
2510 #endif
2513 /* Output a file name in the form wanted by System V. */
2515 void
2516 output_file_directive (asm_file, input_name)
2517 FILE *asm_file;
2518 const char *input_name;
2520 int len = strlen (input_name);
2521 const char *na = input_name + len;
2523 /* NA gets INPUT_NAME sans directory names. */
2524 while (na > input_name)
2526 if (na[-1] == '/')
2527 break;
2528 #ifdef DIR_SEPARATOR
2529 if (na[-1] == DIR_SEPARATOR)
2530 break;
2531 #endif
2532 na--;
2535 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2536 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2537 #else
2538 #ifdef ASM_OUTPUT_SOURCE_FILENAME
2539 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2540 #else
2541 fprintf (asm_file, "\t.file\t");
2542 output_quoted_string (asm_file, na);
2543 fputc ('\n', asm_file);
2544 #endif
2545 #endif
2548 #ifdef ASM_IDENTIFY_LANGUAGE
2549 /* Routine to build language identifier for object file. */
2550 static void
2551 output_lang_identify (asm_out_file)
2552 FILE *asm_out_file;
2554 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2555 char *s = (char *) alloca (len);
2556 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2557 ASM_OUTPUT_LABEL (asm_out_file, s);
2559 #endif
2561 /* Routine to open a dump file. */
2562 static void
2563 open_dump_file (suffix, function_name)
2564 const char *suffix;
2565 const char *function_name;
2567 char *dumpname;
2569 TIMEVAR
2570 (dump_time,
2572 dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
2574 if (rtl_dump_file != NULL)
2575 fclose (rtl_dump_file);
2577 strcpy (dumpname, dump_base_name);
2578 strcat (dumpname, suffix);
2580 rtl_dump_file = fopen (dumpname, "a");
2582 if (rtl_dump_file == NULL)
2583 pfatal_with_name (dumpname);
2585 free (dumpname);
2587 if (function_name)
2588 fprintf (rtl_dump_file, "\n;; Function %s\n\n", function_name);
2591 return;
2594 /* Routine to close a dump file. */
2595 static void
2596 close_dump_file (func, insns)
2597 void (*func) PROTO ((FILE *, rtx));
2598 rtx insns;
2600 TIMEVAR
2601 (dump_time,
2603 if (func)
2604 func (rtl_dump_file, insns);
2606 fflush (rtl_dump_file);
2607 fclose (rtl_dump_file);
2609 rtl_dump_file = NULL;
2612 return;
2615 /* Routine to dump rtl into a file. */
2616 static void
2617 dump_rtl (suffix, decl, func, insns)
2618 const char *suffix;
2619 tree decl;
2620 void (*func) PROTO ((FILE *, rtx));
2621 rtx insns;
2623 open_dump_file (suffix, decl_printable_name (decl, 2));
2624 close_dump_file (func, insns);
2627 /* Routine to empty a dump file. */
2628 static void
2629 clean_dump_file (suffix)
2630 const char *suffix;
2632 char *dumpname;
2634 dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
2636 strcpy (dumpname, dump_base_name);
2637 strcat (dumpname, suffix);
2639 rtl_dump_file = fopen (dumpname, "w");
2641 if (rtl_dump_file == NULL)
2642 pfatal_with_name (dumpname);
2644 free (dumpname);
2646 fclose (rtl_dump_file);
2647 rtl_dump_file = NULL;
2649 return;
2653 /* Compile an entire file of output from cpp, named NAME.
2654 Write a file of assembly output and various debugging dumps. */
2656 static void
2657 compile_file (name)
2658 char *name;
2660 tree globals;
2661 int start_time;
2663 int name_specified = name != 0;
2665 if (dump_base_name == 0)
2666 dump_base_name = name ? name : "gccdump";
2668 parse_time = 0;
2669 varconst_time = 0;
2670 integration_time = 0;
2671 jump_time = 0;
2672 cse_time = 0;
2673 gcse_time = 0;
2674 loop_time = 0;
2675 cse2_time = 0;
2676 branch_prob_time = 0;
2677 flow_time = 0;
2678 combine_time = 0;
2679 regmove_time = 0;
2680 sched_time = 0;
2681 local_alloc_time = 0;
2682 global_alloc_time = 0;
2683 flow2_time = 0;
2684 sched2_time = 0;
2685 #ifdef DELAY_SLOTS
2686 dbr_sched_time = 0;
2687 #endif
2688 shorten_branch_time = 0;
2689 stack_reg_time = 0;
2690 final_time = 0;
2691 symout_time = 0;
2692 dump_time = 0;
2694 /* Initialize data in various passes. */
2696 init_obstacks ();
2697 init_tree_codes ();
2698 name = init_parse (name);
2699 init_rtl ();
2700 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2701 || debug_info_level == DINFO_LEVEL_VERBOSE
2702 || flag_test_coverage);
2703 init_regs ();
2704 init_decl_processing ();
2705 init_optabs ();
2706 init_stmt ();
2707 init_expmed ();
2708 init_expr_once ();
2709 init_loop ();
2710 init_reload ();
2711 init_alias_once ();
2713 if (flag_caller_saves)
2714 init_caller_save ();
2716 /* If auxiliary info generation is desired, open the output file.
2717 This goes in the same directory as the source file--unlike
2718 all the other output files. */
2719 if (flag_gen_aux_info)
2721 aux_info_file = fopen (aux_info_file_name, "w");
2722 if (aux_info_file == 0)
2723 pfatal_with_name (aux_info_file_name);
2726 /* Clear the dump files. */
2727 if (rtl_dump)
2728 clean_dump_file (".rtl");
2729 if (jump_opt_dump)
2731 clean_dump_file (".jump");
2732 if (graph_dump_format != no_graph)
2733 clean_graph_dump_file (dump_base_name, ".jump");
2735 if (addressof_dump)
2737 clean_dump_file (".addressof");
2738 if (graph_dump_format != no_graph)
2739 clean_graph_dump_file (dump_base_name, ".addressof");
2741 if (cse_dump)
2743 clean_dump_file (".cse");
2744 if (graph_dump_format != no_graph)
2745 clean_graph_dump_file (dump_base_name, ".cse");
2747 if (loop_dump)
2749 clean_dump_file (".loop");
2750 if (graph_dump_format != no_graph)
2751 clean_graph_dump_file (dump_base_name, ".loop");
2753 if (cse2_dump)
2755 clean_dump_file (".cse2");
2756 if (graph_dump_format != no_graph)
2757 clean_graph_dump_file (dump_base_name, ".cse2");
2759 if (branch_prob_dump)
2761 clean_dump_file (".bp");
2762 if (graph_dump_format != no_graph)
2763 clean_graph_dump_file (dump_base_name, ".bp");
2765 if (flow_dump)
2767 clean_dump_file (".flow");
2768 if (graph_dump_format != no_graph)
2769 clean_graph_dump_file (dump_base_name, ".flow");
2771 if (combine_dump)
2773 clean_dump_file (".combine");
2774 if (graph_dump_format != no_graph)
2775 clean_graph_dump_file (dump_base_name, ".combine");
2777 if (regmove_dump)
2779 clean_dump_file (".regmove");
2780 if (graph_dump_format != no_graph)
2781 clean_graph_dump_file (dump_base_name, ".regmove");
2783 if (sched_dump)
2785 clean_dump_file (".sched");
2786 if (graph_dump_format != no_graph)
2787 clean_graph_dump_file (dump_base_name, ".sched");
2789 if (local_reg_dump)
2791 clean_dump_file (".lreg");
2792 if (graph_dump_format != no_graph)
2793 clean_graph_dump_file (dump_base_name, ".lreg");
2795 if (global_reg_dump)
2797 clean_dump_file (".greg");
2798 if (graph_dump_format != no_graph)
2799 clean_graph_dump_file (dump_base_name, ".greg");
2801 if (flow2_dump)
2803 clean_dump_file (".flow2");
2804 if (graph_dump_format != no_graph)
2805 clean_graph_dump_file (dump_base_name, ".flow2");
2807 if (sched2_dump)
2809 clean_dump_file (".sched2");
2810 if (graph_dump_format != no_graph)
2811 clean_graph_dump_file (dump_base_name, ".sched2");
2813 if (jump2_opt_dump)
2815 clean_dump_file (".jump2");
2816 if (graph_dump_format != no_graph)
2817 clean_graph_dump_file (dump_base_name, ".jump2");
2819 #ifdef DELAY_SLOTS
2820 if (dbr_sched_dump)
2822 clean_dump_file (".dbr");
2823 if (graph_dump_format != no_graph)
2824 clean_graph_dump_file (dump_base_name, ".dbr");
2826 #endif
2827 if (gcse_dump)
2829 clean_dump_file (".gcse");
2830 if (graph_dump_format != no_graph)
2831 clean_graph_dump_file (dump_base_name, ".gcse");
2833 #ifdef STACK_REGS
2834 if (stack_reg_dump)
2836 clean_dump_file (".stack");
2837 if (graph_dump_format != no_graph)
2838 clean_graph_dump_file (dump_base_name, ".stack");
2840 #endif
2841 #ifdef MACHINE_DEPENDENT_REORG
2842 if (mach_dep_reorg_dump)
2844 clean_dump_file (".mach");
2845 if (graph_dump_format != no_graph)
2846 clean_graph_dump_file (dump_base_name, ".mach");
2848 #endif
2850 /* Open assembler code output file. */
2852 if (flag_syntax_only)
2853 asm_out_file = NULL;
2854 else
2856 if (! name_specified && asm_file_name == 0)
2857 asm_out_file = stdout;
2858 else
2860 int len = strlen (dump_base_name);
2861 register char *dumpname = (char *) xmalloc (len + 6);
2862 strcpy (dumpname, dump_base_name);
2863 strip_off_ending (dumpname, len);
2864 strcat (dumpname, ".s");
2865 if (asm_file_name == 0)
2867 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
2868 strcpy (asm_file_name, dumpname);
2870 if (!strcmp (asm_file_name, "-"))
2871 asm_out_file = stdout;
2872 else
2873 asm_out_file = fopen (asm_file_name, "w");
2874 if (asm_out_file == 0)
2875 pfatal_with_name (asm_file_name);
2878 #ifdef IO_BUFFER_SIZE
2879 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2880 _IOFBF, IO_BUFFER_SIZE);
2881 #endif
2884 input_filename = name;
2886 /* Put an entry on the input file stack for the main input file. */
2887 input_file_stack
2888 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2889 input_file_stack->next = 0;
2890 input_file_stack->name = input_filename;
2892 /* Perform language-specific initialization.
2893 This may set main_input_filename. */
2894 lang_init ();
2896 /* If the input doesn't start with a #line, use the input name
2897 as the official input file name. */
2898 if (main_input_filename == 0)
2899 main_input_filename = name;
2901 if (flag_syntax_only)
2903 write_symbols = NO_DEBUG;
2904 profile_flag = 0;
2905 profile_block_flag = 0;
2907 else
2909 ASM_FILE_START (asm_out_file);
2911 #ifdef ASM_COMMENT_START
2912 if (flag_verbose_asm)
2914 /* Print the list of options in effect. */
2915 print_version (asm_out_file, ASM_COMMENT_START);
2916 print_switch_values (asm_out_file, 0, MAX_LINE,
2917 ASM_COMMENT_START, " ", "\n");
2918 /* Add a blank line here so it appears in assembler output but not
2919 screen output. */
2920 fprintf (asm_out_file, "\n");
2922 #endif
2924 /* Output something to inform GDB that this compilation was by GCC. */
2925 #ifndef ASM_IDENTIFY_GCC
2926 fprintf (asm_out_file, "gcc2_compiled.:\n");
2927 #else
2928 ASM_IDENTIFY_GCC (asm_out_file);
2929 #endif
2931 /* Output something to identify which front-end produced this file. */
2932 #ifdef ASM_IDENTIFY_LANGUAGE
2933 ASM_IDENTIFY_LANGUAGE (asm_out_file);
2934 #endif
2935 } /* ! flag_syntax_only */
2937 #ifndef ASM_OUTPUT_SECTION_NAME
2938 if (flag_function_sections)
2940 warning ("-ffunction-sections not supported for this target.");
2941 flag_function_sections = 0;
2943 if (flag_data_sections)
2945 warning ("-fdata-sections not supported for this target.");
2946 flag_data_sections = 0;
2948 #endif
2950 if (flag_function_sections
2951 && (profile_flag || profile_block_flag))
2953 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2954 flag_function_sections = 0;
2957 #ifndef OBJECT_FORMAT_ELF
2958 if (flag_function_sections && write_symbols != NO_DEBUG)
2959 warning ("-ffunction-sections may affect debugging on some targets.");
2960 #endif
2962 /* ??? Note: There used to be a conditional here
2963 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2964 This was to guarantee separation between gcc_compiled. and
2965 the first function, for the sake of dbx on Suns.
2966 However, having the extra zero here confused the Emacs
2967 code for unexec, and might confuse other programs too.
2968 Therefore, I took out that change.
2969 In future versions we should find another way to solve
2970 that dbx problem. -- rms, 23 May 93. */
2972 /* Don't let the first function fall at the same address
2973 as gcc_compiled., if profiling. */
2974 if (profile_flag || profile_block_flag)
2976 /* It's best if we can write a nop here since some
2977 assemblers don't tolerate zeros in the text section. */
2978 if (insn_template[CODE_FOR_nop] != 0)
2979 output_asm_insn (insn_template[CODE_FOR_nop], NULL_PTR);
2980 else
2981 assemble_zeros (UNITS_PER_WORD);
2984 /* If dbx symbol table desired, initialize writing it
2985 and output the predefined types. */
2986 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2987 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2988 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2989 getdecls ()));
2990 #endif
2991 #ifdef SDB_DEBUGGING_INFO
2992 if (write_symbols == SDB_DEBUG)
2993 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2994 getdecls ()));
2995 #endif
2996 #ifdef DWARF_DEBUGGING_INFO
2997 if (write_symbols == DWARF_DEBUG)
2998 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2999 #endif
3000 #ifdef DWARF2_UNWIND_INFO
3001 if (dwarf2out_do_frame ())
3002 dwarf2out_frame_init ();
3003 #endif
3004 #ifdef DWARF2_DEBUGGING_INFO
3005 if (write_symbols == DWARF2_DEBUG)
3006 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
3007 #endif
3009 /* Initialize yet another pass. */
3011 init_final (main_input_filename);
3012 init_branch_prob (dump_base_name);
3014 start_time = get_run_time ();
3016 /* Call the parser, which parses the entire file
3017 (calling rest_of_compilation for each function). */
3019 if (yyparse () != 0)
3021 if (errorcount == 0)
3022 notice ("Errors detected in input file (your bison.simple is out of date)\n");
3024 /* In case there were missing closebraces,
3025 get us back to the global binding level. */
3026 while (! global_bindings_p ())
3027 poplevel (0, 0, 0);
3030 /* Compilation is now finished except for writing
3031 what's left of the symbol table output. */
3033 parse_time += get_run_time () - start_time;
3035 parse_time -= integration_time;
3036 parse_time -= varconst_time;
3038 if (flag_syntax_only)
3039 goto finish_syntax;
3041 globals = getdecls ();
3043 /* Really define vars that have had only a tentative definition.
3044 Really output inline functions that must actually be callable
3045 and have not been output so far. */
3048 int len = list_length (globals);
3049 tree *vec = (tree *) alloca (sizeof (tree) * len);
3050 int i;
3051 tree decl;
3052 int reconsider = 1;
3054 /* Process the decls in reverse order--earliest first.
3055 Put them into VEC from back to front, then take out from front. */
3057 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
3058 vec[len - i - 1] = decl;
3060 for (i = 0; i < len; i++)
3062 decl = vec[i];
3064 /* We're not deferring this any longer. */
3065 DECL_DEFER_OUTPUT (decl) = 0;
3067 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
3068 && incomplete_decl_finalize_hook != 0)
3069 (*incomplete_decl_finalize_hook) (decl);
3072 /* Now emit any global variables or functions that we have been putting
3073 off. We need to loop in case one of the things emitted here
3074 references another one which comes earlier in the list. */
3075 while (reconsider)
3077 reconsider = 0;
3078 for (i = 0; i < len; i++)
3080 decl = vec[i];
3082 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
3083 continue;
3085 /* Don't write out static consts, unless we still need them.
3087 We also keep static consts if not optimizing (for debugging),
3088 unless the user specified -fno-keep-static-consts.
3089 ??? They might be better written into the debug information.
3090 This is possible when using DWARF.
3092 A language processor that wants static constants to be always
3093 written out (even if it is not used) is responsible for
3094 calling rest_of_decl_compilation itself. E.g. the C front-end
3095 calls rest_of_decl_compilation from finish_decl.
3096 One motivation for this is that is conventional in some
3097 environments to write things like:
3098 static const char rcsid[] = "... version string ...";
3099 intending to force the string to be in the executable.
3101 A language processor that would prefer to have unneeded
3102 static constants "optimized away" would just defer writing
3103 them out until here. E.g. C++ does this, because static
3104 constants are often defined in header files.
3106 ??? A tempting alternative (for both C and C++) would be
3107 to force a constant to be written if and only if it is
3108 defined in a main file, as opposed to an include file. */
3110 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
3111 && (! TREE_READONLY (decl)
3112 || TREE_PUBLIC (decl)
3113 || (!optimize && flag_keep_static_consts)
3114 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
3116 reconsider = 1;
3117 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
3120 if (TREE_CODE (decl) == FUNCTION_DECL
3121 && DECL_INITIAL (decl) != 0
3122 && DECL_SAVED_INSNS (decl) != 0
3123 && (flag_keep_inline_functions
3124 || TREE_PUBLIC (decl)
3125 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
3127 reconsider = 1;
3128 temporary_allocation ();
3129 output_inline_function (decl);
3130 permanent_allocation (1);
3135 /* This must occur after the loop to output deferred functions. Else
3136 the profiler initializer would not be emitted if all the functions
3137 in this compilation unit were deferred.
3139 output_func_start_profiler can not cause any additional functions or
3140 data to need to be output, so it need not be in the deferred function
3141 loop above. */
3142 output_func_start_profiler ();
3144 /* Now that all possible functions have been output, we can dump
3145 the exception table. */
3147 output_exception_table ();
3149 for (i = 0; i < len; i++)
3151 decl = vec[i];
3153 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
3154 && ! TREE_ASM_WRITTEN (decl))
3155 /* Cancel the RTL for this decl so that, if debugging info
3156 output for global variables is still to come,
3157 this one will be omitted. */
3158 DECL_RTL (decl) = NULL;
3160 /* Warn about any function
3161 declared static but not defined.
3162 We don't warn about variables,
3163 because many programs have static variables
3164 that exist only to get some text into the object file. */
3165 if (TREE_CODE (decl) == FUNCTION_DECL
3166 && (warn_unused
3167 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
3168 && DECL_INITIAL (decl) == 0
3169 && DECL_EXTERNAL (decl)
3170 && ! DECL_ARTIFICIAL (decl)
3171 && ! TREE_PUBLIC (decl))
3173 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
3174 pedwarn_with_decl (decl,
3175 "`%s' used but never defined");
3176 else
3177 warning_with_decl (decl,
3178 "`%s' declared `static' but never defined");
3179 /* This symbol is effectively an "extern" declaration now. */
3180 TREE_PUBLIC (decl) = 1;
3181 assemble_external (decl);
3184 /* Warn about static fns or vars defined but not used,
3185 but not about inline functions or static consts
3186 since defining those in header files is normal practice. */
3187 if (warn_unused
3188 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
3189 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
3190 && ! DECL_IN_SYSTEM_HEADER (decl)
3191 && ! DECL_EXTERNAL (decl)
3192 && ! TREE_PUBLIC (decl)
3193 && ! TREE_USED (decl)
3194 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
3195 /* The TREE_USED bit for file-scope decls
3196 is kept in the identifier, to handle multiple
3197 external decls in different scopes. */
3198 && ! TREE_USED (DECL_NAME (decl)))
3199 warning_with_decl (decl, "`%s' defined but not used");
3201 #ifdef SDB_DEBUGGING_INFO
3202 /* The COFF linker can move initialized global vars to the end.
3203 And that can screw up the symbol ordering.
3204 By putting the symbols in that order to begin with,
3205 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
3206 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
3207 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
3208 && ! DECL_EXTERNAL (decl)
3209 && DECL_RTL (decl) != 0)
3210 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
3212 /* Output COFF information for non-global
3213 file-scope initialized variables. */
3214 if (write_symbols == SDB_DEBUG
3215 && TREE_CODE (decl) == VAR_DECL
3216 && DECL_INITIAL (decl)
3217 && ! DECL_EXTERNAL (decl)
3218 && DECL_RTL (decl) != 0
3219 && GET_CODE (DECL_RTL (decl)) == MEM)
3220 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
3221 #endif /* SDB_DEBUGGING_INFO */
3222 #ifdef DWARF_DEBUGGING_INFO
3223 /* Output DWARF information for file-scope tentative data object
3224 declarations, file-scope (extern) function declarations (which
3225 had no corresponding body) and file-scope tagged type declarations
3226 and definitions which have not yet been forced out. */
3228 if (write_symbols == DWARF_DEBUG
3229 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
3230 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
3231 #endif
3232 #ifdef DWARF2_DEBUGGING_INFO
3233 /* Output DWARF2 information for file-scope tentative data object
3234 declarations, file-scope (extern) function declarations (which
3235 had no corresponding body) and file-scope tagged type declarations
3236 and definitions which have not yet been forced out. */
3238 if (write_symbols == DWARF2_DEBUG
3239 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
3240 TIMEVAR (symout_time, dwarf2out_decl (decl));
3241 #endif
3245 /* Write out any pending weak symbol declarations. */
3247 weak_finish ();
3249 /* Do dbx symbols */
3250 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3251 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3252 TIMEVAR (symout_time,
3254 dbxout_finish (asm_out_file, main_input_filename);
3256 #endif
3258 #ifdef DWARF_DEBUGGING_INFO
3259 if (write_symbols == DWARF_DEBUG)
3260 TIMEVAR (symout_time,
3262 dwarfout_finish ();
3264 #endif
3266 #ifdef DWARF2_UNWIND_INFO
3267 if (dwarf2out_do_frame ())
3268 dwarf2out_frame_finish ();
3269 #endif
3271 #ifdef DWARF2_DEBUGGING_INFO
3272 if (write_symbols == DWARF2_DEBUG)
3273 TIMEVAR (symout_time,
3275 dwarf2out_finish ();
3277 #endif
3279 /* Output some stuff at end of file if nec. */
3281 end_final (dump_base_name);
3283 if (branch_prob_dump)
3284 open_dump_file (".bp", NULL);
3286 TIMEVAR (dump_time, end_branch_prob (rtl_dump_file));
3288 if (branch_prob_dump)
3289 close_dump_file (NULL, NULL_RTX);
3291 #ifdef ASM_FILE_END
3292 ASM_FILE_END (asm_out_file);
3293 #endif
3296 /* Language-specific end of compilation actions. */
3297 finish_syntax:
3298 lang_finish ();
3300 /* Close the dump files. */
3302 if (flag_gen_aux_info)
3304 fclose (aux_info_file);
3305 if (errorcount)
3306 unlink (aux_info_file_name);
3309 if (combine_dump)
3311 open_dump_file (".combine", NULL);
3312 TIMEVAR (dump_time, dump_combine_total_stats (rtl_dump_file));
3313 close_dump_file (NULL, NULL_RTX);
3316 /* Close non-debugging input and output files. Take special care to note
3317 whether fclose returns an error, since the pages might still be on the
3318 buffer chain while the file is open. */
3320 finish_parse ();
3322 if (! flag_syntax_only
3323 && (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0))
3324 fatal_io_error (asm_file_name);
3326 /* Do whatever is necessary to finish printing the graphs. */
3327 if (graph_dump_format != no_graph)
3329 if (jump_opt_dump)
3330 finish_graph_dump_file (dump_base_name, ".jump");
3331 if (addressof_dump)
3332 finish_graph_dump_file (dump_base_name, ".addressof");
3333 if (cse_dump)
3334 finish_graph_dump_file (dump_base_name, ".cse");
3335 if (loop_dump)
3336 finish_graph_dump_file (dump_base_name, ".loop");
3337 if (cse2_dump)
3338 finish_graph_dump_file (dump_base_name, ".cse2");
3339 if (branch_prob_dump)
3340 finish_graph_dump_file (dump_base_name, ".bp");
3341 if (flow_dump)
3342 finish_graph_dump_file (dump_base_name, ".flow");
3343 if (combine_dump)
3344 finish_graph_dump_file (dump_base_name, ".combine");
3345 if (regmove_dump)
3346 finish_graph_dump_file (dump_base_name, ".regmove");
3347 if (sched_dump)
3348 finish_graph_dump_file (dump_base_name, ".sched");
3349 if (local_reg_dump)
3350 finish_graph_dump_file (dump_base_name, ".lreg");
3351 if (global_reg_dump)
3352 finish_graph_dump_file (dump_base_name, ".greg");
3353 if (flow2_dump)
3354 finish_graph_dump_file (dump_base_name, ".flow2");
3355 if (sched2_dump)
3356 finish_graph_dump_file (dump_base_name, ".sched2");
3357 if (jump2_opt_dump)
3358 finish_graph_dump_file (dump_base_name, ".jump2");
3359 #ifdef DELAY_SLOTS
3360 if (dbr_sched_dump)
3361 finish_graph_dump_file (dump_base_name, ".dbr");
3362 #endif
3363 if (gcse_dump)
3364 finish_graph_dump_file (dump_base_name, ".gcse");
3365 #ifdef STACK_REGS
3366 if (stack_reg_dump)
3367 finish_graph_dump_file (dump_base_name, ".stack");
3368 #endif
3369 #ifdef MACHINE_DEPENDENT_REORG
3370 if (mach_dep_reorg_dump)
3371 finish_graph_dump_file (dump_base_name, ".mach");
3372 #endif
3375 /* Free up memory for the benefit of leak detectors. */
3376 free_reg_info ();
3378 /* Print the times. */
3380 if (! quiet_flag)
3382 fprintf (stderr,"\n");
3383 print_time ("parse", parse_time);
3385 print_time ("integration", integration_time);
3386 print_time ("jump", jump_time);
3387 print_time ("cse", cse_time);
3388 print_time ("gcse", gcse_time);
3389 print_time ("loop", loop_time);
3390 print_time ("cse2", cse2_time);
3391 print_time ("branch-prob", branch_prob_time);
3392 print_time ("flow", flow_time);
3393 print_time ("combine", combine_time);
3394 print_time ("regmove", regmove_time);
3395 print_time ("sched", sched_time);
3396 print_time ("local-alloc", local_alloc_time);
3397 print_time ("global-alloc", global_alloc_time);
3398 print_time ("flow2", flow2_time);
3399 print_time ("sched2", sched2_time);
3400 #ifdef DELAY_SLOTS
3401 print_time ("dbranch", dbr_sched_time);
3402 #endif
3403 print_time ("shorten-branch", shorten_branch_time);
3404 print_time ("stack-reg", stack_reg_time);
3405 print_time ("final", final_time);
3406 print_time ("varconst", varconst_time);
3407 print_time ("symout", symout_time);
3408 print_time ("dump", dump_time);
3412 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
3413 and TYPE_DECL nodes.
3415 This does nothing for local (non-static) variables.
3416 Otherwise, it sets up the RTL and outputs any assembler code
3417 (label definition, storage allocation and initialization).
3419 DECL is the declaration. If ASMSPEC is nonzero, it specifies
3420 the assembler symbol name to be used. TOP_LEVEL is nonzero
3421 if this declaration is not within a function. */
3423 void
3424 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
3425 tree decl;
3426 const char *asmspec;
3427 int top_level;
3428 int at_end;
3430 /* Declarations of variables, and of functions defined elsewhere. */
3432 /* The most obvious approach, to put an #ifndef around where
3433 this macro is used, doesn't work since it's inside a macro call. */
3434 #ifndef ASM_FINISH_DECLARE_OBJECT
3435 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
3436 #endif
3438 /* Forward declarations for nested functions are not "external",
3439 but we need to treat them as if they were. */
3440 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
3441 || TREE_CODE (decl) == FUNCTION_DECL)
3442 TIMEVAR (varconst_time,
3444 make_decl_rtl (decl, asmspec, top_level);
3445 /* Initialized extern variable exists to be replaced
3446 with its value, or represents something that will be
3447 output in another file. */
3448 if (! (TREE_CODE (decl) == VAR_DECL
3449 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
3450 && DECL_INITIAL (decl) != 0
3451 && DECL_INITIAL (decl) != error_mark_node))
3452 /* Don't output anything
3453 when a tentative file-scope definition is seen.
3454 But at end of compilation, do output code for them. */
3455 if (! (! at_end && top_level
3456 && (DECL_INITIAL (decl) == 0
3457 || DECL_INITIAL (decl) == error_mark_node)))
3458 assemble_variable (decl, top_level, at_end, 0);
3459 if (decl == last_assemble_variable_decl)
3461 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
3462 top_level, at_end);
3465 else if (DECL_REGISTER (decl) && asmspec != 0)
3467 if (decode_reg_name (asmspec) >= 0)
3469 DECL_RTL (decl) = 0;
3470 make_decl_rtl (decl, asmspec, top_level);
3472 else
3473 error ("invalid register name `%s' for register variable", asmspec);
3475 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3476 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3477 && TREE_CODE (decl) == TYPE_DECL)
3478 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
3479 #endif
3480 #ifdef SDB_DEBUGGING_INFO
3481 else if (write_symbols == SDB_DEBUG && top_level
3482 && TREE_CODE (decl) == TYPE_DECL)
3483 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
3484 #endif
3487 /* Called after finishing a record, union or enumeral type. */
3489 void
3490 rest_of_type_compilation (type, toplev)
3491 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
3492 tree type;
3493 int toplev;
3494 #else
3495 tree type ATTRIBUTE_UNUSED;
3496 int toplev ATTRIBUTE_UNUSED;
3497 #endif
3499 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3500 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3501 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
3502 #endif
3503 #ifdef SDB_DEBUGGING_INFO
3504 if (write_symbols == SDB_DEBUG)
3505 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
3506 #endif
3509 /* This is called from finish_function (within yyparse)
3510 after each top-level definition is parsed.
3511 It is supposed to compile that function or variable
3512 and output the assembler code for it.
3513 After we return, the tree storage is freed. */
3515 void
3516 rest_of_compilation (decl)
3517 tree decl;
3519 register rtx insns;
3520 int start_time = get_run_time ();
3521 int tem;
3522 /* Nonzero if we have saved the original DECL_INITIAL of the function,
3523 to be restored after we finish compiling the function
3524 (for use when compiling inline calls to this function). */
3525 tree saved_block_tree = 0;
3526 /* Likewise, for DECL_ARGUMENTS. */
3527 tree saved_arguments = 0;
3528 int failure = 0;
3529 int rebuild_label_notes_after_reload;
3531 /* If we are reconsidering an inline function
3532 at the end of compilation, skip the stuff for making it inline. */
3534 if (DECL_SAVED_INSNS (decl) == 0)
3536 int inlinable = 0;
3537 const char *lose;
3539 /* If requested, consider whether to make this function inline. */
3540 if (DECL_INLINE (decl) || flag_inline_functions)
3541 TIMEVAR (integration_time,
3543 lose = function_cannot_inline_p (decl);
3544 if (lose || ! optimize)
3546 if (warn_inline && DECL_INLINE (decl))
3547 warning_with_decl (decl, lose);
3548 DECL_ABSTRACT_ORIGIN (decl) = 0;
3549 /* Don't really compile an extern inline function.
3550 If we can't make it inline, pretend
3551 it was only declared. */
3552 if (DECL_EXTERNAL (decl))
3554 DECL_INITIAL (decl) = 0;
3555 goto exit_rest_of_compilation;
3558 else
3559 /* ??? Note that this has the effect of making it look
3560 like "inline" was specified for a function if we choose
3561 to inline it. This isn't quite right, but it's
3562 probably not worth the trouble to fix. */
3563 inlinable = DECL_INLINE (decl) = 1;
3566 insns = get_insns ();
3568 /* Dump the rtl code if we are dumping rtl. */
3570 if (rtl_dump)
3572 open_dump_file (".rtl", decl_printable_name (decl, 2));
3574 if (DECL_SAVED_INSNS (decl))
3575 fprintf (rtl_dump_file, ";; (integrable)\n\n");
3577 close_dump_file (print_rtl, insns);
3580 /* If we can, defer compiling inlines until EOF.
3581 save_for_inline_copying can be extremely expensive. */
3582 if (inlinable && ! decl_function_context (decl))
3583 DECL_DEFER_OUTPUT (decl) = 1;
3585 /* If function is inline, and we don't yet know whether to
3586 compile it by itself, defer decision till end of compilation.
3587 finish_compilation will call rest_of_compilation again
3588 for those functions that need to be output. Also defer those
3589 functions that we are supposed to defer. We cannot defer
3590 functions containing nested functions since the nested function
3591 data is in our non-saved obstack. We cannot defer nested
3592 functions for the same reason. */
3594 /* If this is a nested inline, remove ADDRESSOF now so we can
3595 finish compiling ourselves. Otherwise, wait until EOF.
3596 We have to do this because the purge_addressof transformation
3597 changes the DECL_RTL for many variables, which confuses integrate. */
3598 if (inlinable)
3600 if (decl_function_context (decl))
3601 purge_addressof (insns);
3602 else
3603 DECL_DEFER_OUTPUT (decl) = 1;
3606 if (! current_function_contains_functions
3607 && (DECL_DEFER_OUTPUT (decl)
3608 || (DECL_INLINE (decl)
3609 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3610 && ! flag_keep_inline_functions)
3611 || DECL_EXTERNAL (decl)))))
3613 DECL_DEFER_OUTPUT (decl) = 1;
3615 /* If -Wreturn-type, we have to do a bit of compilation.
3616 However, if we just fall through we will call
3617 save_for_inline_copying() which results in excessive
3618 memory use. Instead, we just want to call
3619 jump_optimize() to figure out whether or not we can fall
3620 off the end of the function; we do the minimum amount of
3621 work necessary to make that safe. And, we set optimize
3622 to zero to keep jump_optimize from working too hard. */
3623 if (warn_return_type)
3625 int saved_optimize = optimize;
3626 optimize = 0;
3627 find_exception_handler_labels ();
3628 jump_optimize (get_insns(), !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3629 !JUMP_AFTER_REGSCAN);
3630 optimize = saved_optimize;
3633 #ifdef DWARF_DEBUGGING_INFO
3634 /* Generate the DWARF info for the "abstract" instance
3635 of a function which we may later generate inlined and/or
3636 out-of-line instances of. */
3637 if (write_symbols == DWARF_DEBUG)
3639 set_decl_abstract_flags (decl, 1);
3640 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3641 set_decl_abstract_flags (decl, 0);
3643 #endif
3644 #ifdef DWARF2_DEBUGGING_INFO
3645 /* Generate the DWARF2 info for the "abstract" instance
3646 of a function which we may later generate inlined and/or
3647 out-of-line instances of. */
3648 if (write_symbols == DWARF2_DEBUG)
3650 set_decl_abstract_flags (decl, 1);
3651 TIMEVAR (symout_time, dwarf2out_decl (decl));
3652 set_decl_abstract_flags (decl, 0);
3654 #endif
3655 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3656 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
3657 goto exit_rest_of_compilation;
3660 /* If we have to compile the function now, save its rtl and subdecls
3661 so that its compilation will not affect what others get. */
3662 if (inlinable || DECL_DEFER_OUTPUT (decl))
3664 #ifdef DWARF_DEBUGGING_INFO
3665 /* Generate the DWARF info for the "abstract" instance of
3666 a function which we will generate an out-of-line instance
3667 of almost immediately (and which we may also later generate
3668 various inlined instances of). */
3669 if (write_symbols == DWARF_DEBUG)
3671 set_decl_abstract_flags (decl, 1);
3672 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3673 set_decl_abstract_flags (decl, 0);
3675 #endif
3676 #ifdef DWARF2_DEBUGGING_INFO
3677 /* Generate the DWARF2 info for the "abstract" instance of
3678 a function which we will generate an out-of-line instance
3679 of almost immediately (and which we may also later generate
3680 various inlined instances of). */
3681 if (write_symbols == DWARF2_DEBUG)
3683 set_decl_abstract_flags (decl, 1);
3684 TIMEVAR (symout_time, dwarf2out_decl (decl));
3685 set_decl_abstract_flags (decl, 0);
3687 #endif
3688 saved_block_tree = DECL_INITIAL (decl);
3689 saved_arguments = DECL_ARGUMENTS (decl);
3690 TIMEVAR (integration_time, save_for_inline_copying (decl));
3691 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
3694 /* If specified extern inline but we aren't inlining it, we are
3695 done. This goes for anything that gets here with DECL_EXTERNAL
3696 set, not just things with DECL_INLINE. */
3697 if (DECL_EXTERNAL (decl))
3698 goto exit_rest_of_compilation;
3701 if (! DECL_DEFER_OUTPUT (decl))
3702 TREE_ASM_WRITTEN (decl) = 1;
3704 /* Now that integrate will no longer see our rtl, we need not distinguish
3705 between the return value of this function and the return value of called
3706 functions. */
3707 rtx_equal_function_value_matters = 0;
3709 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3710 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3712 goto exit_rest_of_compilation;
3715 /* Emit code to get eh context, if needed. */
3716 emit_eh_context ();
3718 #ifdef FINALIZE_PIC
3719 /* If we are doing position-independent code generation, now
3720 is the time to output special prologues and epilogues.
3721 We do not want to do this earlier, because it just clutters
3722 up inline functions with meaningless insns. */
3723 if (flag_pic)
3724 FINALIZE_PIC;
3725 #endif
3727 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3728 Note that that may have been done above, in save_for_inline_copying.
3729 The call to resume_temporary_allocation near the end of this function
3730 goes back to the usual state of affairs. This must be done after
3731 we've built up any unwinders for exception handling, and done
3732 the FINALIZE_PIC work, if necessary. */
3734 rtl_in_current_obstack ();
3736 insns = get_insns ();
3738 /* Copy any shared structure that should not be shared. */
3740 unshare_all_rtl (insns);
3742 #ifdef SETJMP_VIA_SAVE_AREA
3743 /* This must be performed before virutal register instantiation. */
3744 if (current_function_calls_alloca)
3745 optimize_save_area_alloca (insns);
3746 #endif
3748 /* Instantiate all virtual registers. */
3750 instantiate_virtual_regs (current_function_decl, get_insns ());
3752 /* See if we have allocated stack slots that are not directly addressable.
3753 If so, scan all the insns and create explicit address computation
3754 for all references to such slots. */
3755 /* fixup_stack_slots (); */
3757 /* Find all the EH handlers. */
3758 find_exception_handler_labels ();
3760 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3761 are initialized and to compute whether control can drop off the end
3762 of the function. */
3763 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3764 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3765 JUMP_AFTER_REGSCAN));
3767 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3768 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3769 goto exit_rest_of_compilation;
3771 /* Dump rtl code after jump, if we are doing that. */
3773 if (jump_opt_dump)
3774 dump_rtl (".jump", decl, print_rtl, insns);
3776 /* Perform common subexpression elimination.
3777 Nonzero value from `cse_main' means that jumps were simplified
3778 and some code may now be unreachable, so do
3779 jump optimization again. */
3781 if (optimize > 0)
3783 if (cse_dump)
3784 open_dump_file (".cse", decl_printable_name (decl, 2));
3786 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3788 if (flag_thread_jumps)
3789 /* Hacks by tiemann & kenner. */
3790 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3792 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3793 0, rtl_dump_file));
3794 TIMEVAR (cse_time, delete_trivially_dead_insns (insns, max_reg_num ()));
3796 if (tem || optimize > 1)
3797 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3798 !JUMP_NOOP_MOVES,
3799 !JUMP_AFTER_REGSCAN));
3801 /* Dump rtl code after cse, if we are doing that. */
3803 if (cse_dump)
3805 close_dump_file (print_rtl, insns);
3806 if (graph_dump_format != no_graph)
3807 print_rtl_graph_with_bb (dump_base_name, ".cse", insns);
3811 purge_addressof (insns);
3812 reg_scan (insns, max_reg_num (), 1);
3814 if (addressof_dump)
3816 dump_rtl (".addressof", decl, print_rtl, insns);
3817 if (graph_dump_format != no_graph)
3818 print_rtl_graph_with_bb (dump_base_name, ".addressof", insns);
3821 /* Perform global cse. */
3823 if (optimize > 0 && flag_gcse)
3825 if (gcse_dump)
3826 open_dump_file (".gcse", IDENTIFIER_POINTER (DECL_NAME (decl)));
3828 TIMEVAR (gcse_time, tem = gcse_main (insns, rtl_dump_file));
3830 /* If gcse altered any jumps, rerun jump optimizations to clean
3831 things up. */
3832 if (tem)
3834 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3835 !JUMP_NOOP_MOVES,
3836 !JUMP_AFTER_REGSCAN));
3839 if (gcse_dump)
3841 close_dump_file (print_rtl, insns);
3842 if (graph_dump_format != no_graph)
3843 print_rtl_graph_with_bb (dump_base_name, ".gcse", insns);
3846 /* Move constant computations out of loops. */
3848 if (optimize > 0)
3850 if (loop_dump)
3851 open_dump_file (".loop", decl_printable_name (decl, 2));
3853 TIMEVAR
3854 (loop_time,
3856 if (flag_rerun_loop_opt)
3858 /* We only want to perform unrolling once. */
3860 loop_optimize (insns, rtl_dump_file, 0, 0);
3863 /* The first call to loop_optimize makes some instructions
3864 trivially dead. We delete those instructions now in the
3865 hope that doing so will make the heuristics in loop work
3866 better and possibly speed up compilation. */
3867 delete_trivially_dead_insns (insns, max_reg_num ());
3869 /* The regscan pass is currently necessary as the alias
3870 analysis code depends on this information. */
3871 reg_scan (insns, max_reg_num (), 1);
3873 loop_optimize (insns, rtl_dump_file, flag_unroll_loops, 1);
3876 /* Dump rtl code after loop opt, if we are doing that. */
3878 if (loop_dump)
3880 close_dump_file (print_rtl, insns);
3881 if (graph_dump_format != no_graph)
3882 print_rtl_graph_with_bb (dump_base_name, ".loop", insns);
3886 if (optimize > 0)
3888 if (cse2_dump)
3889 open_dump_file (".cse2", decl_printable_name (decl, 2));
3891 if (flag_rerun_cse_after_loop)
3893 /* Running another jump optimization pass before the second
3894 cse pass sometimes simplifies the RTL enough to allow
3895 the second CSE pass to do a better job. Jump_optimize can change
3896 max_reg_num so we must rerun reg_scan afterwards.
3897 ??? Rework to not call reg_scan so often. */
3898 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3899 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3900 !JUMP_NOOP_MOVES,
3901 JUMP_AFTER_REGSCAN));
3903 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3904 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3905 1, rtl_dump_file));
3906 if (tem)
3907 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3908 !JUMP_NOOP_MOVES,
3909 !JUMP_AFTER_REGSCAN));
3912 if (flag_thread_jumps)
3914 /* This pass of jump threading straightens out code
3915 that was kinked by loop optimization. */
3916 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3917 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3920 /* Dump rtl code after cse, if we are doing that. */
3922 if (cse2_dump)
3924 close_dump_file (print_rtl, insns);
3925 if (graph_dump_format != no_graph)
3926 print_rtl_graph_with_bb (dump_base_name, ".cse2", insns);
3930 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3932 if (branch_prob_dump)
3933 open_dump_file (".bp", decl_printable_name (decl, 2));
3935 TIMEVAR
3936 (branch_prob_time,
3938 branch_prob (insns, rtl_dump_file);
3941 if (branch_prob_dump)
3943 close_dump_file (print_rtl, insns);
3944 if (graph_dump_format != no_graph)
3945 print_rtl_graph_with_bb (dump_base_name, ".bp", insns);
3949 /* We are no longer anticipating cse in this function, at least. */
3951 cse_not_expected = 1;
3953 /* Now we choose between stupid (pcc-like) register allocation
3954 (if we got the -noreg switch and not -opt)
3955 and smart register allocation. */
3957 if (optimize > 0) /* Stupid allocation probably won't work */
3958 obey_regdecls = 0; /* if optimizations being done. */
3960 regclass_init ();
3962 /* Print function header into flow dump now
3963 because doing the flow analysis makes some of the dump. */
3965 if (flow_dump)
3966 open_dump_file (".flow", decl_printable_name (decl, 2));
3968 if (obey_regdecls)
3970 TIMEVAR (flow_time,
3972 regclass (insns, max_reg_num ());
3973 stupid_life_analysis (insns, max_reg_num (),
3974 rtl_dump_file);
3977 else
3979 /* Do control and data flow analysis,
3980 and write some of the results to dump file. */
3982 TIMEVAR
3983 (flow_time,
3985 find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
3986 life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
3989 if (warn_uninitialized)
3991 uninitialized_vars_warning (DECL_INITIAL (decl));
3992 setjmp_args_warning ();
3996 /* Dump rtl after flow analysis. */
3998 if (flow_dump)
4000 close_dump_file (print_rtl_with_bb, insns);
4001 if (graph_dump_format != no_graph)
4002 print_rtl_graph_with_bb (dump_base_name, ".flow", insns);
4005 /* The first life analysis pass has finished. From now on we can not
4006 generate any new pseudos. */
4007 no_new_pseudos = 1;
4009 /* If -opt, try combining insns through substitution. */
4011 if (optimize > 0)
4013 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
4015 /* Dump rtl code after insn combination. */
4017 if (combine_dump)
4019 dump_rtl (".combine", decl, print_rtl_with_bb, insns);
4020 if (graph_dump_format != no_graph)
4021 print_rtl_graph_with_bb (dump_base_name, ".combine", insns);
4025 /* Register allocation pre-pass, to reduce number of moves
4026 necessary for two-address machines. */
4027 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
4029 if (regmove_dump)
4030 open_dump_file (".regmove", decl_printable_name (decl, 2));
4032 TIMEVAR (regmove_time, regmove_optimize (insns, max_reg_num (),
4033 rtl_dump_file));
4035 if (regmove_dump)
4037 close_dump_file (print_rtl_with_bb, insns);
4038 if (graph_dump_format != no_graph)
4039 print_rtl_graph_with_bb (dump_base_name, ".regmove", insns);
4043 /* Print function header into sched dump now
4044 because doing the sched analysis makes some of the dump. */
4046 if (optimize > 0 && flag_schedule_insns)
4048 if (sched_dump)
4049 open_dump_file (".sched", decl_printable_name (decl, 2));
4051 /* Do control and data sched analysis,
4052 and write some of the results to dump file. */
4054 TIMEVAR (sched_time, schedule_insns (rtl_dump_file));
4056 /* Dump rtl after instruction scheduling. */
4058 if (sched_dump)
4060 close_dump_file (print_rtl_with_bb, insns);
4061 if (graph_dump_format != no_graph)
4062 print_rtl_graph_with_bb (dump_base_name, ".sched", insns);
4066 /* Unless we did stupid register allocation,
4067 allocate pseudo-regs that are used only within 1 basic block.
4069 RUN_JUMP_AFTER_RELOAD records whether or not we need to rerun the
4070 jump optimizer after register allocation and reloading are finished. */
4072 if (!obey_regdecls)
4073 TIMEVAR (local_alloc_time,
4075 recompute_reg_usage (insns, ! optimize_size);
4076 regclass (insns, max_reg_num ());
4077 rebuild_label_notes_after_reload = local_alloc ();
4079 else
4080 rebuild_label_notes_after_reload = 0;
4082 /* Dump rtl code after allocating regs within basic blocks. */
4084 if (local_reg_dump)
4086 open_dump_file (".lreg", decl_printable_name (decl, 2));
4088 TIMEVAR (dump_time, dump_flow_info (rtl_dump_file));
4089 TIMEVAR (dump_time, dump_local_alloc (rtl_dump_file));
4091 close_dump_file (print_rtl_with_bb, insns);
4092 if (graph_dump_format != no_graph)
4093 print_rtl_graph_with_bb (dump_base_name, ".lreg", insns);
4096 if (global_reg_dump)
4097 open_dump_file (".greg", decl_printable_name (decl, 2));
4099 /* Unless we did stupid register allocation,
4100 allocate remaining pseudo-regs, then do the reload pass
4101 fixing up any insns that are invalid. */
4103 TIMEVAR (global_alloc_time,
4105 if (!obey_regdecls)
4106 failure = global_alloc (rtl_dump_file);
4107 else
4108 failure = reload (insns, 0, rtl_dump_file);
4112 if (failure)
4113 goto exit_rest_of_compilation;
4115 /* Do a very simple CSE pass over just the hard registers. */
4116 if (optimize > 0)
4117 reload_cse_regs (insns);
4119 /* Register allocation and reloading may have turned an indirect jump into
4120 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
4121 jumping instructions. */
4122 if (rebuild_label_notes_after_reload)
4123 TIMEVAR (jump_time, rebuild_jump_labels (insns));
4125 /* If optimizing and we are performing instruction scheduling after
4126 reload, then go ahead and split insns now since we are about to
4127 recompute flow information anyway.
4129 reload_cse_regs may expose more splitting opportunities, expecially
4130 for double-word operations. */
4131 if (optimize > 0 && flag_schedule_insns_after_reload)
4133 rtx insn;
4135 for (insn = insns; insn; insn = NEXT_INSN (insn))
4137 rtx last;
4139 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
4140 continue;
4142 last = try_split (PATTERN (insn), insn, 1);
4144 if (last != insn)
4146 PUT_CODE (insn, NOTE);
4147 NOTE_SOURCE_FILE (insn) = 0;
4148 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
4153 if (global_reg_dump)
4155 TIMEVAR (dump_time, dump_global_regs (rtl_dump_file));
4156 close_dump_file (print_rtl_with_bb, insns);
4157 if (graph_dump_format != no_graph)
4158 print_rtl_graph_with_bb (dump_base_name, ".greg", insns);
4161 /* Re-create the death notes which were deleted during reload. */
4162 if (flow2_dump)
4163 open_dump_file (".flow2", decl_printable_name (decl, 2));
4165 if (optimize)
4167 TIMEVAR
4168 (flow2_time,
4170 find_basic_blocks (insns, max_reg_num (), rtl_dump_file, 1);
4171 life_analysis (insns, max_reg_num (), rtl_dump_file, 1);
4175 flow2_completed = 1;
4177 /* On some machines, the prologue and epilogue code, or parts thereof,
4178 can be represented as RTL. Doing so lets us schedule insns between
4179 it and the rest of the code and also allows delayed branch
4180 scheduling to operate in the epilogue. */
4182 thread_prologue_and_epilogue_insns (insns);
4184 if (flow2_dump)
4186 close_dump_file (print_rtl_with_bb, insns);
4187 if (graph_dump_format != no_graph)
4188 print_rtl_graph_with_bb (dump_base_name, ".flow2", insns);
4191 if (optimize > 0 && flag_schedule_insns_after_reload)
4193 if (sched2_dump)
4194 open_dump_file (".sched2", decl_printable_name (decl, 2));
4196 /* Do control and data sched analysis again,
4197 and write some more of the results to dump file. */
4199 TIMEVAR (sched2_time, schedule_insns (rtl_dump_file));
4201 /* Dump rtl after post-reorder instruction scheduling. */
4203 if (sched2_dump)
4205 close_dump_file (print_rtl_with_bb, insns);
4206 if (graph_dump_format != no_graph)
4207 print_rtl_graph_with_bb (dump_base_name, ".sched2", insns);
4211 #ifdef LEAF_REGISTERS
4212 leaf_function = 0;
4213 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
4214 leaf_function = 1;
4215 #endif
4217 /* One more attempt to remove jumps to .+1
4218 left by dead-store-elimination.
4219 Also do cross-jumping this time
4220 and delete no-op move insns. */
4222 if (optimize > 0)
4224 TIMEVAR (jump_time, jump_optimize (insns, JUMP_CROSS_JUMP,
4225 JUMP_NOOP_MOVES,
4226 !JUMP_AFTER_REGSCAN));
4228 /* Dump rtl code after jump, if we are doing that. */
4230 if (jump2_opt_dump)
4232 dump_rtl (".jump2", decl, print_rtl_with_bb, insns);
4233 if (graph_dump_format != no_graph)
4234 print_rtl_graph_with_bb (dump_base_name, ".jump2", insns);
4238 /* If a machine dependent reorganization is needed, call it. */
4239 #ifdef MACHINE_DEPENDENT_REORG
4240 MACHINE_DEPENDENT_REORG (insns);
4242 if (mach_dep_reorg_dump)
4244 dump_rtl (".mach", decl, print_rtl_with_bb, insns);
4245 if (graph_dump_format != no_graph)
4246 print_rtl_graph_with_bb (dump_base_name, ".mach", insns);
4248 #endif
4250 /* If a scheduling pass for delayed branches is to be done,
4251 call the scheduling code. */
4253 #ifdef DELAY_SLOTS
4254 if (optimize > 0 && flag_delayed_branch)
4256 if (dbr_sched_dump)
4257 open_dump_file (".dbr", decl_printable_name (decl, 2));
4259 TIMEVAR (dbr_sched_time, dbr_schedule (insns, rtl_dump_file));
4261 if (dbr_sched_dump)
4263 close_dump_file (print_rtl_with_bb, insns);
4264 if (graph_dump_format != no_graph)
4265 print_rtl_graph_with_bb (dump_base_name, ".dbr", insns);
4268 #endif
4270 /* Shorten branches. */
4271 TIMEVAR (shorten_branch_time,
4273 shorten_branches (get_insns ());
4276 #ifdef STACK_REGS
4277 if (stack_reg_dump)
4278 open_dump_file (".stack", decl_printable_name (decl, 2));
4280 TIMEVAR (stack_reg_time, reg_to_stack (insns, rtl_dump_file));
4282 if (stack_reg_dump)
4284 dump_rtl (".stack", decl, print_rtl_with_bb, insns);
4285 if (graph_dump_format != no_graph)
4286 print_rtl_graph_with_bb (dump_base_name, ".stack", insns);
4288 #endif
4290 /* Now turn the rtl into assembler code. */
4292 TIMEVAR (final_time,
4294 rtx x;
4295 char *fnname;
4297 /* Get the function's name, as described by its RTL.
4298 This may be different from the DECL_NAME name used
4299 in the source file. */
4301 x = DECL_RTL (decl);
4302 if (GET_CODE (x) != MEM)
4303 abort ();
4304 x = XEXP (x, 0);
4305 if (GET_CODE (x) != SYMBOL_REF)
4306 abort ();
4307 fnname = XSTR (x, 0);
4309 assemble_start_function (decl, fnname);
4310 final_start_function (insns, asm_out_file, optimize);
4311 final (insns, asm_out_file, optimize, 0);
4312 final_end_function (insns, asm_out_file, optimize);
4313 assemble_end_function (decl, fnname);
4314 if (! quiet_flag)
4315 fflush (asm_out_file);
4317 /* Release all memory allocated by flow. */
4318 free_basic_block_vars (0);
4320 /* Release all memory held by regsets now */
4321 regset_release_memory ();
4324 /* Write DBX symbols if requested */
4326 /* Note that for those inline functions where we don't initially
4327 know for certain that we will be generating an out-of-line copy,
4328 the first invocation of this routine (rest_of_compilation) will
4329 skip over this code by doing a `goto exit_rest_of_compilation;'.
4330 Later on, finish_compilation will call rest_of_compilation again
4331 for those inline functions that need to have out-of-line copies
4332 generated. During that call, we *will* be routed past here. */
4334 #ifdef DBX_DEBUGGING_INFO
4335 if (write_symbols == DBX_DEBUG)
4336 TIMEVAR (symout_time, dbxout_function (decl));
4337 #endif
4339 #ifdef DWARF_DEBUGGING_INFO
4340 if (write_symbols == DWARF_DEBUG)
4341 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
4342 #endif
4344 #ifdef DWARF2_DEBUGGING_INFO
4345 if (write_symbols == DWARF2_DEBUG)
4346 TIMEVAR (symout_time, dwarf2out_decl (decl));
4347 #endif
4349 exit_rest_of_compilation:
4351 free_bb_mem ();
4353 /* In case the function was not output,
4354 don't leave any temporary anonymous types
4355 queued up for sdb output. */
4356 #ifdef SDB_DEBUGGING_INFO
4357 if (write_symbols == SDB_DEBUG)
4358 sdbout_types (NULL_TREE);
4359 #endif
4361 /* Put back the tree of subblocks and list of arguments
4362 from before we copied them.
4363 Code generation and the output of debugging info may have modified
4364 the copy, but the original is unchanged. */
4366 if (saved_block_tree != 0)
4368 DECL_INITIAL (decl) = saved_block_tree;
4369 DECL_ARGUMENTS (decl) = saved_arguments;
4370 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
4373 reload_completed = 0;
4374 flow2_completed = 0;
4375 no_new_pseudos = 0;
4377 TIMEVAR (final_time,
4379 /* Clear out the insn_length contents now that they are no
4380 longer valid. */
4381 init_insn_lengths ();
4383 /* Clear out the real_constant_chain before some of the rtx's
4384 it runs through become garbage. */
4385 clear_const_double_mem ();
4387 /* Cancel the effect of rtl_in_current_obstack. */
4388 resume_temporary_allocation ();
4390 /* Show no temporary slots allocated. */
4391 init_temp_slots ();
4394 /* Make sure volatile mem refs aren't considered valid operands for
4395 arithmetic insns. We must call this here if this is a nested inline
4396 function, since the above code leaves us in the init_recog state
4397 (from final.c), and the function context push/pop code does not
4398 save/restore volatile_ok.
4400 ??? Maybe it isn't necessary for expand_start_function to call this
4401 anymore if we do it here? */
4403 init_recog_no_volatile ();
4405 /* The parsing time is all the time spent in yyparse
4406 *except* what is spent in this function. */
4408 parse_time -= get_run_time () - start_time;
4410 /* Reset global variables. */
4411 free_basic_block_vars (0);
4414 static void
4415 display_help ()
4417 int undoc;
4418 unsigned long i;
4419 const char * lang;
4421 #ifndef USE_CPPLIB
4422 printf ("Usage: %s input [switches]\n", progname);
4423 printf ("Switches:\n");
4424 #endif
4425 printf (" -ffixed-<register> Mark <register> as being unavailable to the compiler\n");
4426 printf (" -fcall-used-<register> Mark <register> as being corrupted by function calls\n");
4427 printf (" -fcall-saved-<register> Mark <register> as being preserved across functions\n");
4429 for (i = NUM_ELEM (f_options); i--;)
4431 const char * description = f_options[i].description;
4433 if (description != NULL && * description != 0)
4434 printf (" -f%-21s %s\n",
4435 f_options[i].string, description);
4438 printf (" -O[number] Set optimisation level to [number]\n");
4439 printf (" -Os Optimise for space rather than speed\n");
4440 printf (" -pedantic Issue warnings needed by strict compliance to ANSI C\n");
4441 printf (" -pedantic-errors Like -pedantic except that errors are produced\n");
4442 printf (" -w Suppress warnings\n");
4443 printf (" -W Enable extra warnings\n");
4445 for (i = NUM_ELEM (W_options); i--;)
4447 const char * description = W_options[i].description;
4449 if (description != NULL && * description != 0)
4450 printf (" -W%-21s %s\n",
4451 W_options[i].string, description);
4454 printf (" -Wid-clash-<num> Warn if 2 identifiers have the same first <num> chars\n");
4455 printf (" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n");
4456 printf (" -p Enable function profiling\n");
4457 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER)
4458 printf (" -a Enable block profiling \n");
4459 #endif
4460 #if defined (BLOCK_PROFILER) || defined (FUNCTION_BLOCK_PROFILER) || defined FUNCTION_BLOCK_PROFILER_EXIT
4461 printf (" -ax Enable jump profiling \n");
4462 #endif
4463 printf (" -o <file> Place output into <file> \n");
4464 printf (" -G <number> Put global and static data smaller than <number>\n");
4465 printf (" bytes into a special section (on some targets)\n");
4467 for (i = NUM_ELEM (debug_args); i--;)
4469 if (debug_args[i].description != NULL)
4470 printf (" -%-22s %s\n", debug_args[i].arg, debug_args[i].description);
4473 printf (" -aux-info <file> Emit declaration info into <file>.X\n");
4474 printf (" -quiet Do not display functions compiled or elapsed time\n");
4475 printf (" -version Display the compiler's version\n");
4476 printf (" -d[letters] Enable dumps from specific passes of the compiler\n");
4477 printf (" -dumpbase <file> Base name to be used for dumps from specific passes\n");
4478 #if defined HAIFA || defined INSN_SCHEDULING
4479 printf (" -sched-verbose-<number> Set the verbosity level of the scheduler\n");
4480 #endif
4481 printf (" --help Display this information\n");
4483 undoc = 0;
4484 lang = "language";
4486 /* Display descriptions of language specific options.
4487 If there is no description, note that there is an undocumented option.
4488 If the description is empty, do not display anything. (This allows
4489 options to be deliberately undocumented, for whatever reason).
4490 If the option string is missing, then this is a marker, indicating
4491 that the description string is in fact the name of a language, whose
4492 language specific options are to follow. */
4494 if (NUM_ELEM (documented_lang_options) > 1)
4496 printf ("\nLanguage specific options:\n");
4498 for (i = 0; i < NUM_ELEM (documented_lang_options); i++)
4500 const char * description = documented_lang_options[i].description;
4501 const char * option = documented_lang_options[i].option;
4503 if (description == NULL)
4505 undoc = 1;
4507 if (extra_warnings)
4508 printf (" %-23.23s [undocumented]\n", option);
4510 else if (* description == 0)
4511 continue;
4512 else if (option == NULL)
4514 if (undoc)
4515 printf
4516 ("\nThere are undocumented %s specific options as well.\n",
4517 lang);
4518 undoc = 0;
4520 printf ("\n Options for %s:\n", description);
4522 lang = description;
4524 else
4525 printf (" %-23.23s %s\n", option, description);
4529 if (undoc)
4530 printf ("\nThere are undocumented %s specific options as well.\n", lang);
4532 if (NUM_ELEM (target_switches) > 1
4533 #ifdef TARGET_OPTIONS
4534 || NUM_ELEM (target_options) > 1
4535 #endif
4538 int doc = 0;
4540 undoc = 0;
4542 printf ("\nTarget specific options:\n");
4544 for (i = NUM_ELEM (target_switches); i--;)
4546 const char * option = target_switches[i].name;
4547 const char * description = target_switches[i].description;
4549 if (option == NULL || * option == 0)
4550 continue;
4551 else if (description == NULL)
4553 undoc = 1;
4555 if (extra_warnings)
4556 printf (" -m%-21.21s [undocumented]\n", option);
4558 else if (* description != 0)
4559 doc += printf (" -m%-21.21s %s\n", option, description);
4562 #ifdef TARGET_OPTIONS
4563 for (i = NUM_ELEM (target_options); i--;)
4565 const char * option = target_options[i].prefix;
4566 const char * description = target_options[i].description;
4568 if (option == NULL || * option == 0)
4569 continue;
4570 else if (description == NULL)
4572 undoc = 1;
4574 if (extra_warnings)
4575 printf (" -m%-21.21s [undocumented]\n", option);
4577 else if (* description != 0)
4578 doc += printf (" -m%-21.21s %s\n", option, description);
4580 #endif
4581 if (undoc)
4583 if (doc)
4584 printf ("\nThere are undocumented target specific options as well.\n");
4585 else
4586 printf (" They exist, but they are not documented.\n");
4591 /* Compare the user specified 'option' with the language
4592 specific 'lang_option'. Return true if they match, or
4593 if 'option' is a viable prefix of 'lang_option'. */
4595 static int
4596 check_lang_option (option, lang_option)
4597 char * option;
4598 char * lang_option;
4600 lang_independent_options * indep_options;
4601 int len;
4602 long k;
4603 char * space;
4605 /* Ignore NULL entries. */
4606 if (option == NULL || lang_option == NULL)
4607 return 0;
4609 if ((space = strchr (lang_option, ' ')) != NULL)
4610 len = space - lang_option;
4611 else
4612 len = strlen (lang_option);
4614 /* If they do not match to the first n characters then fail. */
4615 if (strncmp (option, lang_option, len) != 0)
4616 return 0;
4618 /* Do not accept a lang option, if it matches a normal -f or -W
4619 option. Chill defines a -fpack, but we want to support
4620 -fpack-struct. */
4622 /* An exact match is OK */
4623 if ((int) strlen (option) == len)
4624 return 1;
4626 /* If it is not an -f or -W option allow the match */
4627 if (option[0] != '-')
4628 return 1;
4630 switch (option[1])
4632 case 'f': indep_options = f_options; break;
4633 case 'W': indep_options = W_options; break;
4634 default: return 1;
4637 /* The option is a -f or -W option.
4638 Skip past the prefix and search for the remainder in the
4639 appropriate table of options. */
4640 option += 2;
4642 if (option[0] == 'n' && option[1] == 'o' && option[2] == '-')
4643 option += 3;
4645 for (k = NUM_ELEM (indep_options); k--;)
4647 if (!strcmp (option, indep_options[k].string))
4649 /* The option matched a language independent option,
4650 do not allow the language specific match. */
4652 return 0;
4656 /* The option matches the start of the langauge specific option
4657 and it is not an exact match for a language independent option. */
4658 return 1;
4661 /* Entry point of cc1/c++. Decode command args, then call compile_file.
4662 Exit code is 35 if can't open files, 34 if fatal error,
4663 33 if had nonfatal errors, else success. */
4666 main (argc, argv)
4667 int argc;
4668 char **argv;
4670 register int i;
4671 char *filename = 0;
4672 int flag_print_mem = 0;
4673 int version_flag = 0;
4674 char *p;
4676 /* save in case md file wants to emit args as a comment. */
4677 save_argc = argc;
4678 save_argv = argv;
4680 p = argv[0] + strlen (argv[0]);
4681 while (p != argv[0] && p[-1] != '/'
4682 #ifdef DIR_SEPARATOR
4683 && p[-1] != DIR_SEPARATOR
4684 #endif
4686 --p;
4687 progname = p;
4689 #if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
4690 /* Get rid of any avoidable limit on stack size. */
4692 struct rlimit rlim;
4694 /* Set the stack limit huge so that alloca does not fail. */
4695 getrlimit (RLIMIT_STACK, &rlim);
4696 rlim.rlim_cur = rlim.rlim_max;
4697 setrlimit (RLIMIT_STACK, &rlim);
4699 #endif
4701 #ifdef HAVE_LC_MESSAGES
4702 setlocale (LC_MESSAGES, "");
4703 #endif
4704 (void) bindtextdomain (PACKAGE, localedir);
4705 (void) textdomain (PACKAGE);
4707 signal (SIGFPE, float_signal);
4709 #ifdef SIGPIPE
4710 signal (SIGPIPE, pipe_closed);
4711 #endif
4713 decl_printable_name = decl_name;
4714 lang_expand_expr = (lang_expand_expr_t) do_abort;
4716 /* Initialize whether `char' is signed. */
4717 flag_signed_char = DEFAULT_SIGNED_CHAR;
4718 #ifdef DEFAULT_SHORT_ENUMS
4719 /* Initialize how much space enums occupy, by default. */
4720 flag_short_enums = DEFAULT_SHORT_ENUMS;
4721 #endif
4723 /* Perform language-specific options intialization. */
4724 lang_init_options ();
4726 /* Scan to see what optimization level has been specified. That will
4727 determine the default value of many flags. */
4728 for (i = 1; i < argc; i++)
4730 if (!strcmp (argv[i], "-O"))
4732 optimize = 1;
4733 optimize_size = 0;
4735 else if (argv[i][0] == '-' && argv[i][1] == 'O')
4737 /* Handle -Os, -O2, -O3, -O69, ... */
4738 char *p = &argv[i][2];
4740 if ((p[0] == 's') && (p[1] == 0))
4742 optimize_size = 1;
4744 /* Optimizing for size forces optimize to be 2. */
4745 optimize = 2;
4747 else
4749 const int optimize_val = read_integral_parameter (p, p - 2, -1);
4750 if (optimize_val != -1)
4752 optimize = optimize_val;
4753 optimize_size = 0;
4759 obey_regdecls = (optimize == 0);
4761 if (optimize >= 1)
4763 flag_defer_pop = 1;
4764 flag_thread_jumps = 1;
4765 #ifdef DELAY_SLOTS
4766 flag_delayed_branch = 1;
4767 #endif
4768 #ifdef CAN_DEBUG_WITHOUT_FP
4769 flag_omit_frame_pointer = 1;
4770 #endif
4773 if (optimize >= 2)
4775 flag_cse_follow_jumps = 1;
4776 flag_cse_skip_blocks = 1;
4777 flag_gcse = 1;
4778 flag_expensive_optimizations = 1;
4779 flag_strength_reduce = 1;
4780 flag_rerun_cse_after_loop = 1;
4781 flag_rerun_loop_opt = 1;
4782 flag_caller_saves = 1;
4783 flag_force_mem = 1;
4784 #ifdef INSN_SCHEDULING
4785 flag_schedule_insns = 1;
4786 flag_schedule_insns_after_reload = 1;
4787 #endif
4788 flag_regmove = 1;
4789 flag_strict_aliasing = 1;
4792 if (optimize >= 3)
4794 flag_inline_functions = 1;
4797 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
4798 modify it. */
4799 target_flags = 0;
4800 set_target_switch ("");
4802 #ifdef OPTIMIZATION_OPTIONS
4803 /* Allow default optimizations to be specified on a per-machine basis. */
4804 OPTIMIZATION_OPTIONS (optimize, optimize_size);
4805 #endif
4807 /* Initialize register usage now so switches may override. */
4808 init_reg_sets ();
4810 for (i = 1; i < argc; i++)
4812 size_t j;
4814 /* If this is a language-specific option,
4815 decode it in a language-specific way. */
4816 for (j = NUM_ELEM (documented_lang_options); j--;)
4817 if (check_lang_option (argv[i], documented_lang_options[j].option))
4818 break;
4820 if (j != (size_t)-1)
4822 /* If the option is valid for *some* language,
4823 treat it as valid even if this language doesn't understand it. */
4824 int strings_processed = lang_decode_option (argc - i, argv + i);
4826 if (!strcmp (argv[i], "--help"))
4828 display_help ();
4829 exit (0);
4832 if (strings_processed != 0)
4833 i += strings_processed - 1;
4835 else if (argv[i][0] == '-' && argv[i][1] != 0)
4837 register char *str = argv[i] + 1;
4838 if (str[0] == 'Y')
4839 str++;
4841 if (str[0] == 'm')
4842 set_target_switch (&str[1]);
4843 else if (!strcmp (str, "dumpbase"))
4845 dump_base_name = argv[++i];
4847 else if (str[0] == 'd')
4849 register char *p = &str[1];
4850 while (*p)
4851 switch (*p++)
4853 case 'a':
4854 branch_prob_dump = 1;
4855 combine_dump = 1;
4856 #ifdef DELAY_SLOTS
4857 dbr_sched_dump = 1;
4858 #endif
4859 flow_dump = 1;
4860 flow2_dump = 1;
4861 global_reg_dump = 1;
4862 jump_opt_dump = 1;
4863 addressof_dump = 1;
4864 jump2_opt_dump = 1;
4865 local_reg_dump = 1;
4866 loop_dump = 1;
4867 regmove_dump = 1;
4868 rtl_dump = 1;
4869 cse_dump = 1, cse2_dump = 1;
4870 gcse_dump = 1;
4871 sched_dump = 1;
4872 sched2_dump = 1;
4873 #ifdef STACK_REGS
4874 stack_reg_dump = 1;
4875 #endif
4876 #ifdef MACHINE_DEPENDENT_REORG
4877 mach_dep_reorg_dump = 1;
4878 #endif
4879 break;
4880 case 'A':
4881 flag_debug_asm = 1;
4882 break;
4883 case 'b':
4884 branch_prob_dump = 1;
4885 break;
4886 case 'c':
4887 combine_dump = 1;
4888 break;
4889 #ifdef DELAY_SLOTS
4890 case 'd':
4891 dbr_sched_dump = 1;
4892 break;
4893 #endif
4894 case 'f':
4895 flow_dump = 1;
4896 break;
4897 case 'F':
4898 addressof_dump = 1;
4899 break;
4900 case 'g':
4901 global_reg_dump = 1;
4902 break;
4903 case 'G':
4904 gcse_dump = 1;
4905 break;
4906 case 'j':
4907 jump_opt_dump = 1;
4908 break;
4909 case 'J':
4910 jump2_opt_dump = 1;
4911 break;
4912 #ifdef STACK_REGS
4913 case 'k':
4914 stack_reg_dump = 1;
4915 break;
4916 #endif
4917 case 'l':
4918 local_reg_dump = 1;
4919 break;
4920 case 'L':
4921 loop_dump = 1;
4922 break;
4923 case 'm':
4924 flag_print_mem = 1;
4925 break;
4926 #ifdef MACHINE_DEPENDENT_REORG
4927 case 'M':
4928 mach_dep_reorg_dump = 1;
4929 break;
4930 #endif
4931 case 'p':
4932 flag_print_asm_name = 1;
4933 break;
4934 case 'r':
4935 rtl_dump = 1;
4936 break;
4937 case 'R':
4938 sched2_dump = 1;
4939 break;
4940 case 's':
4941 cse_dump = 1;
4942 break;
4943 case 'S':
4944 sched_dump = 1;
4945 break;
4946 case 't':
4947 cse2_dump = 1;
4948 break;
4949 case 'N':
4950 regmove_dump = 1;
4951 break;
4952 case 'v':
4953 graph_dump_format = vcg;
4954 break;
4955 case 'w':
4956 flow2_dump = 1;
4957 break;
4958 case 'y':
4959 set_yydebug (1);
4960 break;
4961 case 'x':
4962 rtl_dump_and_exit = 1;
4963 break;
4964 case 'D': /* these are handled by the preprocessor */
4965 case 'I':
4966 break;
4967 default:
4968 warning ("unrecognised gcc debugging option: %c", p[-1]);
4969 break;
4972 else if (str[0] == 'f')
4974 register char *p = &str[1];
4975 int found = 0;
4977 /* Some kind of -f option.
4978 P's value is the option sans `-f'.
4979 Search for it in the table of options. */
4981 for (j = 0;
4982 !found && j < sizeof (f_options) / sizeof (f_options[0]);
4983 j++)
4985 if (!strcmp (p, f_options[j].string))
4987 *f_options[j].variable = f_options[j].on_value;
4988 /* A goto here would be cleaner,
4989 but breaks the vax pcc. */
4990 found = 1;
4992 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
4993 && ! strcmp (p+3, f_options[j].string))
4995 *f_options[j].variable = ! f_options[j].on_value;
4996 found = 1;
5000 if (found)
5002 #ifdef HAIFA
5003 #ifdef INSN_SCHEDULING
5004 else if (!strncmp (p, "sched-verbose-",14))
5005 fix_sched_param("verbose",&p[14]);
5006 #endif
5007 #endif /* HAIFA */
5008 else if (!strncmp (p, "fixed-", 6))
5009 fix_register (&p[6], 1, 1);
5010 else if (!strncmp (p, "call-used-", 10))
5011 fix_register (&p[10], 0, 1);
5012 else if (!strncmp (p, "call-saved-", 11))
5013 fix_register (&p[11], 0, 0);
5014 else
5015 error ("Invalid option `%s'", argv[i]);
5017 else if (str[0] == 'O')
5019 /* Already been treated above. Do nothing. */
5021 else if (!strcmp (str, "pedantic"))
5022 pedantic = 1;
5023 else if (!strcmp (str, "pedantic-errors"))
5024 flag_pedantic_errors = pedantic = 1;
5025 else if (!strcmp (str, "quiet"))
5026 quiet_flag = 1;
5027 else if (!strcmp (str, "version"))
5028 version_flag = 1;
5029 else if (!strcmp (str, "w"))
5030 inhibit_warnings = 1;
5031 else if (!strcmp (str, "W"))
5033 extra_warnings = 1;
5034 /* We save the value of warn_uninitialized, since if they put
5035 -Wuninitialized on the command line, we need to generate a
5036 warning about not using it without also specifying -O. */
5037 if (warn_uninitialized != 1)
5038 warn_uninitialized = 2;
5040 else if (str[0] == 'W')
5042 register char *p = &str[1];
5043 int found = 0;
5045 /* Some kind of -W option.
5046 P's value is the option sans `-W'.
5047 Search for it in the table of options. */
5049 for (j = 0;
5050 !found && j < sizeof (W_options) / sizeof (W_options[0]);
5051 j++)
5053 if (!strcmp (p, W_options[j].string))
5055 *W_options[j].variable = W_options[j].on_value;
5056 /* A goto here would be cleaner,
5057 but breaks the vax pcc. */
5058 found = 1;
5060 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
5061 && ! strcmp (p+3, W_options[j].string))
5063 *W_options[j].variable = ! W_options[j].on_value;
5064 found = 1;
5068 if (found)
5070 else if (!strncmp (p, "id-clash-", 9))
5072 const int id_clash_val
5073 = read_integral_parameter (p + 9, p - 2, -1);
5074 if (id_clash_val != -1)
5076 id_clash_len = id_clash_val;
5077 warn_id_clash = 1;
5080 else if (!strncmp (p, "larger-than-", 12))
5082 const int larger_than_val
5083 = read_integral_parameter (p + 12, p - 2, -1);
5084 if (larger_than_val != -1)
5086 larger_than_size = larger_than_val;
5087 warn_larger_than = 1;
5090 else
5091 error ("Invalid option `%s'", argv[i]);
5093 else if (!strcmp (str, "p"))
5095 profile_flag = 1;
5097 else if (!strcmp (str, "a"))
5099 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5100 warning ("`-a' option (basic block profile) not supported");
5101 #else
5102 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
5103 #endif
5105 else if (!strcmp (str, "ax"))
5107 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
5108 warning ("`-ax' option (jump profiling) not supported");
5109 #else
5110 profile_block_flag = (!profile_block_flag
5111 || profile_block_flag == 2) ? 2 : 3;
5112 #endif
5114 else if (str[0] == 'g')
5116 unsigned level;
5117 /* A lot of code assumes write_symbols == NO_DEBUG if the
5118 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
5119 of what debugging type has been selected). This records the
5120 selected type. It is an error to specify more than one
5121 debugging type. */
5122 static enum debug_info_type selected_debug_type = NO_DEBUG;
5123 /* Non-zero if debugging format has been explicitly set.
5124 -g and -ggdb don't explicitly set the debugging format so
5125 -gdwarf -g3 is equivalent to -gdwarf3. */
5126 static int type_explicitly_set_p = 0;
5127 /* Indexed by enum debug_info_type. */
5128 static const char *debug_type_names[] =
5130 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
5133 /* The maximum admissible debug level value. */
5134 static const unsigned max_debug_level = 3;
5136 /* Look up STR in the table. */
5137 for (da = debug_args; da->arg; da++)
5139 const int da_len = strlen (da->arg);
5141 if (! strncmp (str, da->arg, da_len))
5143 enum debug_info_type type = da->debug_type;
5144 const char *p = str + da_len;
5146 if (*p && (*p < '0' || *p > '9'))
5147 continue;
5149 /* A debug flag without a level defaults to level 2.
5150 Note we do not want to call read_integral_parameter
5151 for that case since it will call atoi which
5152 will return zero.
5154 ??? We may want to generalize the interface to
5155 read_integral_parameter to better handle this case
5156 if this case shows up often. */
5157 if (*p)
5158 level = read_integral_parameter (p, 0,
5159 max_debug_level + 1);
5160 else
5161 level = 2;
5163 if (da_len > 1 && !strncmp (str, "gdwarf", da_len))
5165 error ("use -gdwarf -g%d for DWARF v1, level %d",
5166 level, level);
5167 if (level == 2)
5168 error ("use -gdwarf-2 for DWARF v2");
5171 if (level > max_debug_level)
5173 warning ("ignoring option `%s' due to invalid debug level specification",
5174 str - 1);
5175 level = debug_info_level;
5178 if (type == NO_DEBUG)
5180 type = PREFERRED_DEBUGGING_TYPE;
5181 if (da_len > 1 && strncmp (str, "ggdb", da_len) == 0)
5183 #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
5184 type = DWARF2_DEBUG;
5185 #else
5186 #ifdef DBX_DEBUGGING_INFO
5187 type = DBX_DEBUG;
5188 #endif
5189 #endif
5193 if (type == NO_DEBUG)
5194 warning ("`-%s' not supported by this configuration of GCC",
5195 str);
5197 /* Does it conflict with an already selected type? */
5198 if (type_explicitly_set_p
5199 /* -g/-ggdb don't conflict with anything */
5200 && da->debug_type != NO_DEBUG
5201 && type != selected_debug_type)
5202 warning ("`-%s' ignored, conflicts with `-g%s'",
5203 str, debug_type_names[(int) selected_debug_type]);
5204 else
5206 /* If the format has already been set, -g/-ggdb
5207 only change the debug level. */
5208 if (type_explicitly_set_p
5209 && da->debug_type == NO_DEBUG)
5210 ; /* don't change debugging type */
5211 else
5213 selected_debug_type = type;
5214 type_explicitly_set_p = da->debug_type != NO_DEBUG;
5216 write_symbols = (level == 0
5217 ? NO_DEBUG
5218 : selected_debug_type);
5219 use_gnu_debug_info_extensions = da->use_extensions_p;
5220 debug_info_level = (enum debug_info_level) level;
5222 break;
5225 if (! da->arg)
5226 warning ("`-%s' not supported by this configuration of GCC",
5227 str);
5229 else if (!strcmp (str, "o"))
5231 asm_file_name = argv[++i];
5233 else if (str[0] == 'G')
5235 const int g_switch_val = (str[1] != '\0') ?
5236 read_integral_parameter(str + 1, 0, -1) :
5237 read_integral_parameter(argv[++i], 0, -1);
5239 if (g_switch_val != -1)
5241 g_switch_set = TRUE;
5242 g_switch_value = g_switch_val;
5244 else
5246 error("Invalid option `-%s'",str);
5249 else if (!strncmp (str, "aux-info", 8))
5251 flag_gen_aux_info = 1;
5252 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
5254 else if (!strcmp (str, "-help"))
5256 display_help ();
5257 exit (0);
5259 else
5260 error ("Invalid option `%s'", argv[i]);
5262 else if (argv[i][0] == '+')
5263 error ("Invalid option `%s'", argv[i]);
5264 else
5265 filename = argv[i];
5268 /* Checker uses the frame pointer. */
5269 if (flag_check_memory_usage)
5270 flag_omit_frame_pointer = 0;
5272 if (optimize == 0)
5274 /* Inlining does not work if not optimizing,
5275 so force it not to be done. */
5276 flag_no_inline = 1;
5277 warn_inline = 0;
5279 /* The c_decode_option and lang_decode_option functions set
5280 this to `2' if -Wall is used, so we can avoid giving out
5281 lots of errors for people who don't realize what -Wall does. */
5282 if (warn_uninitialized == 1)
5283 warning ("-Wuninitialized is not supported without -O");
5286 #ifdef OVERRIDE_OPTIONS
5287 /* Some machines may reject certain combinations of options. */
5288 OVERRIDE_OPTIONS;
5289 #endif
5291 if (exceptions_via_longjmp == 2)
5293 #ifdef DWARF2_UNWIND_INFO
5294 exceptions_via_longjmp = ! DWARF2_UNWIND_INFO;
5295 #else
5296 exceptions_via_longjmp = 1;
5297 #endif
5300 if (profile_block_flag == 3)
5302 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
5303 profile_block_flag = 2;
5306 /* Unrolling all loops implies that standard loop unrolling must also
5307 be done. */
5308 if (flag_unroll_all_loops)
5309 flag_unroll_loops = 1;
5310 /* Loop unrolling requires that strength_reduction be on also. Silently
5311 turn on strength reduction here if it isn't already on. Also, the loop
5312 unrolling code assumes that cse will be run after loop, so that must
5313 be turned on also. */
5314 if (flag_unroll_loops)
5316 flag_strength_reduce = 1;
5317 flag_rerun_cse_after_loop = 1;
5320 /* Warn about options that are not supported on this machine. */
5321 #ifndef INSN_SCHEDULING
5322 if (flag_schedule_insns || flag_schedule_insns_after_reload)
5323 warning ("instruction scheduling not supported on this target machine");
5324 #endif
5325 #ifndef DELAY_SLOTS
5326 if (flag_delayed_branch)
5327 warning ("this target machine does not have delayed branches");
5328 #endif
5330 user_label_prefix = USER_LABEL_PREFIX;
5331 if (flag_leading_underscore != -1)
5333 /* If the default prefix is more complicated than "" or "_",
5334 issue a warning and ignore this option. */
5335 if (user_label_prefix[0] == 0 ||
5336 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
5338 user_label_prefix = flag_leading_underscore ? "_" : "";
5340 else
5341 warning ("-f%sleading-underscore not supported on this target machine",
5342 flag_leading_underscore ? "" : "no-");
5345 /* If we are in verbose mode, write out the version and maybe all the
5346 option flags in use. */
5347 if (version_flag)
5349 print_version (stderr, "");
5350 if (! quiet_flag)
5351 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
5354 compile_file (filename);
5356 #if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN__)) && !defined(__INTERIX)
5357 if (flag_print_mem)
5359 char *lim = (char *) sbrk (0);
5361 notice ("Data size %ld.\n", (long) (lim - (char *) &environ));
5362 fflush (stderr);
5364 #ifndef __MSDOS__
5365 #ifdef USG
5366 system ("ps -l 1>&2");
5367 #else /* not USG */
5368 system ("ps v");
5369 #endif /* not USG */
5370 #endif
5372 #endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN) && ! __INTERIX */
5374 if (errorcount)
5375 exit (FATAL_EXIT_CODE);
5376 if (sorrycount)
5377 exit (FATAL_EXIT_CODE);
5378 exit (SUCCESS_EXIT_CODE);
5379 return 0;
5382 /* Decode -m switches. */
5383 /* Decode the switch -mNAME. */
5385 static void
5386 set_target_switch (name)
5387 const char *name;
5389 register size_t j;
5390 int valid_target_option = 0;
5392 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5393 if (!strcmp (target_switches[j].name, name))
5395 if (target_switches[j].value < 0)
5396 target_flags &= ~-target_switches[j].value;
5397 else
5398 target_flags |= target_switches[j].value;
5399 valid_target_option = 1;
5402 #ifdef TARGET_OPTIONS
5403 if (!valid_target_option)
5404 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5406 int len = strlen (target_options[j].prefix);
5407 if (!strncmp (target_options[j].prefix, name, len))
5409 *target_options[j].variable = name + len;
5410 valid_target_option = 1;
5413 #endif
5415 if (!valid_target_option)
5416 error ("Invalid option `%s'", name);
5419 /* Print version information to FILE.
5420 Each line begins with INDENT (for the case where FILE is the
5421 assembler output file). */
5423 static void
5424 print_version (file, indent)
5425 FILE *file;
5426 const char *indent;
5428 #ifndef __VERSION__
5429 #define __VERSION__ "[?]"
5430 #endif
5431 fnotice (file,
5432 #ifdef __GNUC__
5433 "%s%s%s version %s (%s) compiled by GNU C version %s.\n"
5434 #else
5435 "%s%s%s version %s (%s) compiled by CC.\n"
5436 #endif
5437 , indent, *indent != 0 ? " " : "",
5438 language_string, version_string, TARGET_NAME, __VERSION__);
5441 /* Print an option value and return the adjusted position in the line.
5442 ??? We don't handle error returns from fprintf (disk full); presumably
5443 other code will catch a disk full though. */
5445 static int
5446 print_single_switch (file, pos, max, indent, sep, term, type, name)
5447 FILE *file;
5448 int pos, max;
5449 const char *indent, *sep, *term, *type, *name;
5451 /* The ultrix fprintf returns 0 on success, so compute the result we want
5452 here since we need it for the following test. */
5453 int len = strlen (sep) + strlen (type) + strlen (name);
5455 if (pos != 0
5456 && pos + len > max)
5458 fprintf (file, "%s", term);
5459 pos = 0;
5461 if (pos == 0)
5463 fprintf (file, "%s", indent);
5464 pos = strlen (indent);
5466 fprintf (file, "%s%s%s", sep, type, name);
5467 pos += len;
5468 return pos;
5471 /* Print active target switches to FILE.
5472 POS is the current cursor position and MAX is the size of a "line".
5473 Each line begins with INDENT and ends with TERM.
5474 Each switch is separated from the next by SEP. */
5476 static void
5477 print_switch_values (file, pos, max, indent, sep, term)
5478 FILE *file;
5479 int pos, max;
5480 const char *indent, *sep, *term;
5482 size_t j;
5483 char **p;
5485 /* Print the options as passed. */
5487 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
5488 _("options passed: "), "");
5490 for (p = &save_argv[1]; *p != NULL; p++)
5491 if (**p == '-')
5493 /* Ignore these. */
5494 if (strcmp (*p, "-o") == 0)
5496 if (p[1] != NULL)
5497 p++;
5498 continue;
5500 if (strcmp (*p, "-quiet") == 0)
5501 continue;
5502 if (strcmp (*p, "-version") == 0)
5503 continue;
5504 if ((*p)[1] == 'd')
5505 continue;
5507 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
5509 if (pos > 0)
5510 fprintf (file, "%s", term);
5512 /* Print the -f and -m options that have been enabled.
5513 We don't handle language specific options but printing argv
5514 should suffice. */
5516 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
5517 _("options enabled: "), "");
5519 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
5520 if (*f_options[j].variable == f_options[j].on_value)
5521 pos = print_single_switch (file, pos, max, indent, sep, term,
5522 "-f", f_options[j].string);
5524 /* Print target specific options. */
5526 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
5527 if (target_switches[j].name[0] != '\0'
5528 && target_switches[j].value > 0
5529 && ((target_switches[j].value & target_flags)
5530 == target_switches[j].value))
5532 pos = print_single_switch (file, pos, max, indent, sep, term,
5533 "-m", target_switches[j].name);
5536 #ifdef TARGET_OPTIONS
5537 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
5538 if (*target_options[j].variable != NULL)
5540 char prefix[256];
5541 sprintf (prefix, "-m%s", target_options[j].prefix);
5542 pos = print_single_switch (file, pos, max, indent, sep, term,
5543 prefix, *target_options[j].variable);
5545 #endif
5547 fprintf (file, "%s", term);
5550 /* Record the beginning of a new source file, named FILENAME. */
5552 void
5553 debug_start_source_file (filename)
5554 register char *filename ATTRIBUTE_UNUSED;
5556 #ifdef DBX_DEBUGGING_INFO
5557 if (write_symbols == DBX_DEBUG)
5558 dbxout_start_new_source_file (filename);
5559 #endif
5560 #ifdef DWARF_DEBUGGING_INFO
5561 if (debug_info_level == DINFO_LEVEL_VERBOSE
5562 && write_symbols == DWARF_DEBUG)
5563 dwarfout_start_new_source_file (filename);
5564 #endif /* DWARF_DEBUGGING_INFO */
5565 #ifdef DWARF2_DEBUGGING_INFO
5566 if (debug_info_level == DINFO_LEVEL_VERBOSE
5567 && write_symbols == DWARF2_DEBUG)
5568 dwarf2out_start_source_file (filename);
5569 #endif /* DWARF2_DEBUGGING_INFO */
5570 #ifdef SDB_DEBUGGING_INFO
5571 if (write_symbols == SDB_DEBUG)
5572 sdbout_start_new_source_file (filename);
5573 #endif
5576 /* Record the resumption of a source file. LINENO is the line number in
5577 the source file we are returning to. */
5579 void
5580 debug_end_source_file (lineno)
5581 register unsigned lineno ATTRIBUTE_UNUSED;
5583 #ifdef DBX_DEBUGGING_INFO
5584 if (write_symbols == DBX_DEBUG)
5585 dbxout_resume_previous_source_file ();
5586 #endif
5587 #ifdef DWARF_DEBUGGING_INFO
5588 if (debug_info_level == DINFO_LEVEL_VERBOSE
5589 && write_symbols == DWARF_DEBUG)
5590 dwarfout_resume_previous_source_file (lineno);
5591 #endif /* DWARF_DEBUGGING_INFO */
5592 #ifdef DWARF2_DEBUGGING_INFO
5593 if (debug_info_level == DINFO_LEVEL_VERBOSE
5594 && write_symbols == DWARF2_DEBUG)
5595 dwarf2out_end_source_file ();
5596 #endif /* DWARF2_DEBUGGING_INFO */
5597 #ifdef SDB_DEBUGGING_INFO
5598 if (write_symbols == SDB_DEBUG)
5599 sdbout_resume_previous_source_file ();
5600 #endif
5603 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5604 the tail part of the directive line, i.e. the part which is past the
5605 initial whitespace, #, whitespace, directive-name, whitespace part. */
5607 void
5608 debug_define (lineno, buffer)
5609 register unsigned lineno ATTRIBUTE_UNUSED;
5610 register char *buffer ATTRIBUTE_UNUSED;
5612 #ifdef DWARF_DEBUGGING_INFO
5613 if (debug_info_level == DINFO_LEVEL_VERBOSE
5614 && write_symbols == DWARF_DEBUG)
5615 dwarfout_define (lineno, buffer);
5616 #endif /* DWARF_DEBUGGING_INFO */
5617 #ifdef DWARF2_DEBUGGING_INFO
5618 if (debug_info_level == DINFO_LEVEL_VERBOSE
5619 && write_symbols == DWARF2_DEBUG)
5620 dwarf2out_define (lineno, buffer);
5621 #endif /* DWARF2_DEBUGGING_INFO */
5624 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
5625 the tail part of the directive line, i.e. the part which is past the
5626 initial whitespace, #, whitespace, directive-name, whitespace part. */
5628 void
5629 debug_undef (lineno, buffer)
5630 register unsigned lineno ATTRIBUTE_UNUSED;
5631 register char *buffer ATTRIBUTE_UNUSED;
5633 #ifdef DWARF_DEBUGGING_INFO
5634 if (debug_info_level == DINFO_LEVEL_VERBOSE
5635 && write_symbols == DWARF_DEBUG)
5636 dwarfout_undef (lineno, buffer);
5637 #endif /* DWARF_DEBUGGING_INFO */
5638 #ifdef DWARF2_DEBUGGING_INFO
5639 if (debug_info_level == DINFO_LEVEL_VERBOSE
5640 && write_symbols == DWARF2_DEBUG)
5641 dwarf2out_undef (lineno, buffer);
5642 #endif /* DWARF2_DEBUGGING_INFO */