(CPP_SPEC): add %(subtarget_cpp_spec).
[official-gcc.git] / gcc / toplev.c
blobcb11ab46d0d6fe404dbc239f6fd9f33ab373bce5
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This is the top level of cc1/c++.
22 It parses command args, opens files, invokes the various passes
23 in the proper order, and counts the time used by each.
24 Error messages and low-level interface to malloc also handled here. */
26 #include "config.h"
27 #ifdef __STDC__
28 #include <stdarg.h>
29 #else
30 #include <varargs.h>
31 #endif
32 #include <stdio.h>
33 #include <signal.h>
34 #include <setjmp.h>
35 #include <sys/types.h>
36 #include <ctype.h>
37 #include <sys/stat.h>
39 #ifndef _WIN32
40 #ifdef USG
41 #undef FLOAT
42 #include <sys/param.h>
43 /* This is for hpux. It is a real screw. They should change hpux. */
44 #undef FLOAT
45 #include <sys/times.h>
46 #include <time.h> /* Correct for hpux at least. Is it good on other USG? */
47 #undef FFS /* Some systems define this in param.h. */
48 #else
49 #ifndef VMS
50 #include <sys/time.h>
51 #include <sys/resource.h>
52 #endif
53 #endif
54 #endif
56 #include "input.h"
57 #include "tree.h"
58 #include "rtl.h"
59 #include "flags.h"
60 #include "insn-attr.h"
61 #include "defaults.h"
62 #include "output.h"
63 #include "bytecode.h"
64 #include "bc-emit.h"
65 #include "except.h"
67 #ifdef XCOFF_DEBUGGING_INFO
68 #include "xcoffout.h"
69 #endif
71 #ifdef VMS
72 /* The extra parameters substantially improve the I/O performance. */
73 static FILE *
74 vms_fopen (fname, type)
75 char * fname;
76 char * type;
78 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
79 fixed arguments, which matches ANSI's specification but not VAXCRTL's
80 pre-ANSI implementation. This hack circumvents the mismatch problem. */
81 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
83 if (*type == 'w')
84 return (*vmslib_fopen) (fname, type, "mbc=32",
85 "deq=64", "fop=tef", "shr=nil");
86 else
87 return (*vmslib_fopen) (fname, type, "mbc=32");
89 #define fopen vms_fopen
90 #endif /* VMS */
92 #ifndef DEFAULT_GDB_EXTENSIONS
93 #define DEFAULT_GDB_EXTENSIONS 1
94 #endif
96 /* If more than one debugging type is supported, you must define
97 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
99 This is one long line cause VAXC can't handle a \-newline. */
100 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
101 #ifndef PREFERRED_DEBUGGING_TYPE
102 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
103 #endif /* no PREFERRED_DEBUGGING_TYPE */
104 #else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
105 so the following code needn't care. */
106 #ifdef DBX_DEBUGGING_INFO
107 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
108 #endif
109 #ifdef SDB_DEBUGGING_INFO
110 #define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
111 #endif
112 #ifdef DWARF_DEBUGGING_INFO
113 #define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
114 #endif
115 #ifdef DWARF2_DEBUGGING_INFO
116 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
117 #endif
118 #ifdef XCOFF_DEBUGGING_INFO
119 #define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
120 #endif
121 #endif /* More than one debugger format enabled. */
123 /* If still not defined, must have been because no debugging formats
124 are supported. */
125 #ifndef PREFERRED_DEBUGGING_TYPE
126 #define PREFERRED_DEBUGGING_TYPE NO_DEBUG
127 #endif
129 #ifdef DWARF2_DEBUGGING_INFO
130 #undef PREFERRED_DEBUGGING_TYPE
131 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
132 #endif
134 extern int rtx_equal_function_value_matters;
136 #if ! (defined (VMS) || defined (OS2))
137 extern char **environ;
138 #endif
139 extern char *version_string, *language_string;
141 /* Carry information from ASM_DECLARE_OBJECT_NAME
142 to ASM_FINISH_DECLARE_OBJECT. */
144 extern int size_directive_output;
145 extern tree last_assemble_variable_decl;
147 extern void init_lex ();
148 extern void init_decl_processing ();
149 extern void init_obstacks ();
150 extern void init_tree_codes ();
151 extern void init_rtl ();
152 extern void init_regs ();
153 extern void init_optabs ();
154 extern void init_stmt ();
155 extern void init_reg_sets ();
156 extern void dump_flow_info ();
157 extern void dump_sched_info ();
158 extern void dump_local_alloc ();
159 extern void regset_release_memory ();
161 void rest_of_decl_compilation ();
162 void error_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
163 void error_with_decl PVPROTO((tree decl, char *s, ...));
164 void error_for_asm PVPROTO((rtx insn, char *s, ...));
165 void error PVPROTO((char *s, ...));
166 void fatal PVPROTO((char *s, ...));
167 void warning_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
168 void warning_with_decl PVPROTO((tree decl, char *s, ...));
169 void warning_for_asm PVPROTO((rtx insn, char *s, ...));
170 void warning PVPROTO((char *s, ...));
171 void pedwarn PVPROTO((char *s, ...));
172 void pedwarn_with_decl PVPROTO((tree decl, char *s, ...));
173 void pedwarn_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
174 void sorry PVPROTO((char *s, ...));
175 void really_sorry PVPROTO((char *s, ...));
176 void fancy_abort ();
177 #ifndef abort
178 void abort ();
179 #endif
180 void set_target_switch ();
181 static char *decl_name ();
183 void print_version ();
184 int print_single_switch ();
185 void print_switch_values ();
186 /* Length of line when printing switch values. */
187 #define MAX_LINE 75
189 #ifdef __alpha
190 extern char *sbrk ();
191 #endif
193 /* Name of program invoked, sans directories. */
195 char *progname;
197 /* Copy of arguments to main. */
198 int save_argc;
199 char **save_argv;
201 /* Name of current original source file (what was input to cpp).
202 This comes from each #-command in the actual input. */
204 char *input_filename;
206 /* Name of top-level original source file (what was input to cpp).
207 This comes from the #-command at the beginning of the actual input.
208 If there isn't any there, then this is the cc1 input file name. */
210 char *main_input_filename;
212 #if !USE_CPPLIB
213 /* Stream for reading from the input file. */
214 FILE *finput;
215 #endif
217 /* Current line number in real source file. */
219 int lineno;
221 /* Stack of currently pending input files. */
223 struct file_stack *input_file_stack;
225 /* Incremented on each change to input_file_stack. */
226 int input_file_stack_tick;
228 /* FUNCTION_DECL for function now being parsed or compiled. */
230 extern tree current_function_decl;
232 /* Name to use as base of names for dump output files. */
234 char *dump_base_name;
236 /* Bit flags that specify the machine subtype we are compiling for.
237 Bits are tested using macros TARGET_... defined in the tm.h file
238 and set by `-m...' switches. Must be defined in rtlanal.c. */
240 extern int target_flags;
242 /* Flags saying which kinds of debugging dump have been requested. */
244 int rtl_dump = 0;
245 int rtl_dump_and_exit = 0;
246 int jump_opt_dump = 0;
247 int addressof_dump = 0;
248 int cse_dump = 0;
249 int loop_dump = 0;
250 int cse2_dump = 0;
251 int branch_prob_dump = 0;
252 int flow_dump = 0;
253 int combine_dump = 0;
254 int sched_dump = 0;
255 int local_reg_dump = 0;
256 int global_reg_dump = 0;
257 int sched2_dump = 0;
258 int jump2_opt_dump = 0;
259 int dbr_sched_dump = 0;
260 int flag_print_asm_name = 0;
261 int stack_reg_dump = 0;
263 /* Name for output file of assembly code, specified with -o. */
265 char *asm_file_name;
267 /* Value of the -G xx switch, and whether it was passed or not. */
268 int g_switch_value;
269 int g_switch_set;
271 /* Type(s) of debugging information we are producing (if any).
272 See flags.h for the definitions of the different possible
273 types of debugging information. */
274 enum debug_info_type write_symbols = NO_DEBUG;
276 /* Level of debugging information we are producing. See flags.h
277 for the definitions of the different possible levels. */
278 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
280 /* Nonzero means use GNU-only extensions in the generated symbolic
281 debugging information. */
282 /* Currently, this only has an effect when write_symbols is set to
283 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
284 int use_gnu_debug_info_extensions = 0;
286 /* Nonzero means do optimizations. -O.
287 Particular numeric values stand for particular amounts of optimization;
288 thus, -O2 stores 2 here. However, the optimizations beyond the basic
289 ones are not controlled directly by this variable. Instead, they are
290 controlled by individual `flag_...' variables that are defaulted
291 based on this variable. */
293 int optimize = 0;
295 /* Number of error messages and warning messages so far. */
297 int errorcount = 0;
298 int warningcount = 0;
299 int sorrycount = 0;
301 /* Flag to output bytecode instead of native assembler */
302 int output_bytecode = 0;
304 /* Pointer to function to compute the name to use to print a declaration.
305 DECL is the declaration in question.
306 VERBOSITY determines what information will be printed:
307 0: DECL_NAME, demangled as necessary.
308 1: and scope information.
309 2: and any other information that might be interesting, such as function
310 parameter types in C++. */
312 char *(*decl_printable_name) (/* tree decl, int verbosity */);
314 /* Pointer to function to compute rtl for a language-specific tree code. */
316 struct rtx_def *(*lang_expand_expr) ();
318 /* Pointer to function to finish handling an incomplete decl at the
319 end of compilation. */
321 void (*incomplete_decl_finalize_hook) () = 0;
323 /* Highest label number used at the end of reload. */
325 int max_label_num_after_reload;
327 /* Nonzero if generating code to do profiling. */
329 int profile_flag = 0;
331 /* Nonzero if generating code to do profiling on a line-by-line basis. */
333 int profile_block_flag;
335 /* Nonzero if generating code to profile program flow graph arcs. */
337 int profile_arc_flag = 0;
339 /* Nonzero if generating info for gcov to calculate line test coverage. */
341 int flag_test_coverage = 0;
343 /* Nonzero indicates that branch taken probabilities should be calculated. */
345 int flag_branch_probabilities = 0;
347 /* Nonzero for -pedantic switch: warn about anything
348 that standard spec forbids. */
350 int pedantic = 0;
352 /* Temporarily suppress certain warnings.
353 This is set while reading code from a system header file. */
355 int in_system_header = 0;
357 /* Nonzero means do stupid register allocation.
358 Currently, this is 1 if `optimize' is 0. */
360 int obey_regdecls = 0;
362 /* Don't print functions as they are compiled and don't print
363 times taken by the various passes. -quiet. */
365 int quiet_flag = 0;
367 /* -f flags. */
369 /* Nonzero means `char' should be signed. */
371 int flag_signed_char;
373 /* Nonzero means give an enum type only as many bytes as it needs. */
375 int flag_short_enums;
377 /* Nonzero for -fcaller-saves: allocate values in regs that need to
378 be saved across function calls, if that produces overall better code.
379 Optional now, so people can test it. */
381 #ifdef DEFAULT_CALLER_SAVES
382 int flag_caller_saves = 1;
383 #else
384 int flag_caller_saves = 0;
385 #endif
387 /* Nonzero if structures and unions should be returned in memory.
389 This should only be defined if compatibility with another compiler or
390 with an ABI is needed, because it results in slower code. */
392 #ifndef DEFAULT_PCC_STRUCT_RETURN
393 #define DEFAULT_PCC_STRUCT_RETURN 1
394 #endif
396 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
398 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
400 /* Nonzero for -fforce-mem: load memory value into a register
401 before arithmetic on it. This makes better cse but slower compilation. */
403 int flag_force_mem = 0;
405 /* Nonzero for -fforce-addr: load memory address into a register before
406 reference to memory. This makes better cse but slower compilation. */
408 int flag_force_addr = 0;
410 /* Nonzero for -fdefer-pop: don't pop args after each function call;
411 instead save them up to pop many calls' args with one insns. */
413 int flag_defer_pop = 0;
415 /* Nonzero for -ffloat-store: don't allocate floats and doubles
416 in extended-precision registers. */
418 int flag_float_store = 0;
420 /* Nonzero for -fcse-follow-jumps:
421 have cse follow jumps to do a more extensive job. */
423 int flag_cse_follow_jumps;
425 /* Nonzero for -fcse-skip-blocks:
426 have cse follow a branch around a block. */
427 int flag_cse_skip_blocks;
429 /* Nonzero for -fexpensive-optimizations:
430 perform miscellaneous relatively-expensive optimizations. */
431 int flag_expensive_optimizations;
433 /* Nonzero for -fthread-jumps:
434 have jump optimize output of loop. */
436 int flag_thread_jumps;
438 /* Nonzero enables strength-reduction in loop.c. */
440 int flag_strength_reduce = 0;
442 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
443 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
444 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
445 unrolled. */
447 int flag_unroll_loops;
449 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
450 This is generally not a win. */
452 int flag_unroll_all_loops;
454 /* Nonzero for -fwritable-strings:
455 store string constants in data segment and don't uniquize them. */
457 int flag_writable_strings = 0;
459 /* Nonzero means don't put addresses of constant functions in registers.
460 Used for compiling the Unix kernel, where strange substitutions are
461 done on the assembly output. */
463 int flag_no_function_cse = 0;
465 /* Nonzero for -fomit-frame-pointer:
466 don't make a frame pointer in simple functions that don't require one. */
468 int flag_omit_frame_pointer = 0;
470 /* Nonzero means place each function into its own section on those platforms
471 which support arbitrary section names and unlimited numbers of sections. */
473 int flag_function_sections = 0;
475 /* Nonzero to inhibit use of define_optimization peephole opts. */
477 int flag_no_peephole = 0;
479 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
480 operations in the interest of optimization. For example it allows
481 GCC to assume arguments to sqrt are nonnegative numbers, allowing
482 faster code for sqrt to be generated. */
484 int flag_fast_math = 0;
486 /* Nonzero means all references through pointers are volatile. */
488 int flag_volatile;
490 /* Nonzero means treat all global and extern variables as global. */
492 int flag_volatile_global;
494 /* Nonzero means just do syntax checking; don't output anything. */
496 int flag_syntax_only = 0;
498 /* Nonzero means to rerun cse after loop optimization. This increases
499 compilation time about 20% and picks up a few more common expressions. */
501 static int flag_rerun_cse_after_loop;
503 /* Nonzero for -finline-functions: ok to inline functions that look like
504 good inline candidates. */
506 int flag_inline_functions;
508 /* Nonzero for -fkeep-inline-functions: even if we make a function
509 go inline everywhere, keep its definition around for debugging
510 purposes. */
512 int flag_keep_inline_functions;
514 /* Nonzero means that functions will not be inlined. */
516 int flag_no_inline;
518 /* Nonzero means that we should emit static const variables
519 regardless of whether or not optimization is turned on. */
521 int flag_keep_static_consts = 1;
523 /* Nonzero means we should be saving declaration info into a .X file. */
525 int flag_gen_aux_info = 0;
527 /* Specified name of aux-info file. */
529 static char *aux_info_file_name;
531 /* Nonzero means make the text shared if supported. */
533 int flag_shared_data;
535 /* Nonzero means schedule into delayed branch slots if supported. */
537 int flag_delayed_branch;
539 /* Nonzero if we are compiling pure (sharable) code.
540 Value is 1 if we are doing reasonable (i.e. simple
541 offset into offset table) pic. Value is 2 if we can
542 only perform register offsets. */
544 int flag_pic;
546 /* Nonzero means generate extra code for exception handling and enable
547 exception handling. */
549 int flag_exceptions = 1;
551 /* Nonzero means don't place uninitialized global data in common storage
552 by default. */
554 int flag_no_common;
556 /* Nonzero means pretend it is OK to examine bits of target floats,
557 even if that isn't true. The resulting code will have incorrect constants,
558 but the same series of instructions that the native compiler would make. */
560 int flag_pretend_float;
562 /* Nonzero means change certain warnings into errors.
563 Usually these are warnings about failure to conform to some standard. */
565 int flag_pedantic_errors = 0;
567 /* flag_schedule_insns means schedule insns within basic blocks (before
568 local_alloc).
569 flag_schedule_insns_after_reload means schedule insns after
570 global_alloc. */
572 int flag_schedule_insns = 0;
573 int flag_schedule_insns_after_reload = 0;
575 /* -finhibit-size-directive inhibits output of .size for ELF.
576 This is used only for compiling crtstuff.c,
577 and it may be extended to other effects
578 needed for crtstuff.c on other systems. */
579 int flag_inhibit_size_directive = 0;
581 /* -fverbose-asm causes extra commentary information to be produced in
582 the generated assembly code (to make it more readable). This option
583 is generally only of use to those who actually need to read the
584 generated assembly code (perhaps while debugging the compiler itself).
585 -fverbose-asm is the default. -fno-verbose-asm causes the extra information
586 to be omitted and is useful when comparing two assembler files. */
588 int flag_verbose_asm = 1;
590 /* -dA causes debug commentary information to be produced in
591 the generated assembly code (to make it more readable). This option
592 is generally only of use to those who actually need to read the
593 generated assembly code (perhaps while debugging the compiler itself).
594 Currently, this switch is only used by dwarfout.c; however, it is intended
595 to be a catchall for printing debug information in the assembler file. */
597 int flag_debug_asm = 0;
599 /* -fgnu-linker specifies use of the GNU linker for initializations.
600 (Or, more generally, a linker that handles initializations.)
601 -fno-gnu-linker says that collect2 will be used. */
602 #ifdef USE_COLLECT2
603 int flag_gnu_linker = 0;
604 #else
605 int flag_gnu_linker = 1;
606 #endif
608 /* Tag all structures with __attribute__(packed) */
609 int flag_pack_struct = 0;
611 /* Emit code to check for stack overflow; also may cause large objects
612 to be allocated dynamically. */
613 int flag_stack_check;
615 /* Table of language-independent -f options.
616 STRING is the option name. VARIABLE is the address of the variable.
617 ON_VALUE is the value to store in VARIABLE
618 if `-fSTRING' is seen as an option.
619 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
621 struct { char *string; int *variable; int on_value;} f_options[] =
623 {"float-store", &flag_float_store, 1},
624 {"volatile", &flag_volatile, 1},
625 {"volatile-global", &flag_volatile_global, 1},
626 {"defer-pop", &flag_defer_pop, 1},
627 {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
628 {"cse-follow-jumps", &flag_cse_follow_jumps, 1},
629 {"cse-skip-blocks", &flag_cse_skip_blocks, 1},
630 {"expensive-optimizations", &flag_expensive_optimizations, 1},
631 {"thread-jumps", &flag_thread_jumps, 1},
632 {"strength-reduce", &flag_strength_reduce, 1},
633 {"unroll-loops", &flag_unroll_loops, 1},
634 {"unroll-all-loops", &flag_unroll_all_loops, 1},
635 {"writable-strings", &flag_writable_strings, 1},
636 {"peephole", &flag_no_peephole, 0},
637 {"force-mem", &flag_force_mem, 1},
638 {"force-addr", &flag_force_addr, 1},
639 {"function-cse", &flag_no_function_cse, 0},
640 {"inline-functions", &flag_inline_functions, 1},
641 {"keep-inline-functions", &flag_keep_inline_functions, 1},
642 {"inline", &flag_no_inline, 0},
643 {"keep-static-consts", &flag_keep_static_consts, 1},
644 {"syntax-only", &flag_syntax_only, 1},
645 {"shared-data", &flag_shared_data, 1},
646 {"caller-saves", &flag_caller_saves, 1},
647 {"pcc-struct-return", &flag_pcc_struct_return, 1},
648 {"reg-struct-return", &flag_pcc_struct_return, 0},
649 {"delayed-branch", &flag_delayed_branch, 1},
650 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1},
651 {"pretend-float", &flag_pretend_float, 1},
652 {"schedule-insns", &flag_schedule_insns, 1},
653 {"schedule-insns2", &flag_schedule_insns_after_reload, 1},
654 {"pic", &flag_pic, 1},
655 {"PIC", &flag_pic, 2},
656 {"exceptions", &flag_exceptions, 1},
657 {"sjlj-exceptions", &exceptions_via_longjmp, 1},
658 {"asynchronous-exceptions", &asynchronous_exceptions, 1},
659 {"profile-arcs", &profile_arc_flag, 1},
660 {"test-coverage", &flag_test_coverage, 1},
661 {"branch-probabilities", &flag_branch_probabilities, 1},
662 {"fast-math", &flag_fast_math, 1},
663 {"common", &flag_no_common, 0},
664 {"inhibit-size-directive", &flag_inhibit_size_directive, 1},
665 {"function-sections", &flag_function_sections, 1},
666 {"verbose-asm", &flag_verbose_asm, 1},
667 {"gnu-linker", &flag_gnu_linker, 1},
668 {"pack-struct", &flag_pack_struct, 1},
669 {"stack-check", &flag_stack_check, 1},
670 {"bytecode", &output_bytecode, 1}
673 /* Table of language-specific options. */
675 char *lang_options[] =
677 "-ansi",
678 "-fallow-single-precision",
680 "-fsigned-bitfields",
681 "-funsigned-bitfields",
682 "-fno-signed-bitfields",
683 "-fno-unsigned-bitfields",
684 "-fsigned-char",
685 "-funsigned-char",
686 "-fno-signed-char",
687 "-fno-unsigned-char",
689 "-ftraditional",
690 "-traditional",
691 "-fnotraditional",
692 "-fno-traditional",
694 "-fasm",
695 "-fno-asm",
696 "-fbuiltin",
697 "-fno-builtin",
698 "-fhosted",
699 "-fno-hosted",
700 "-ffreestanding",
701 "-fno-freestanding",
702 "-fcond-mismatch",
703 "-fno-cond-mismatch",
704 "-fdollars-in-identifiers",
705 "-fno-dollars-in-identifiers",
706 "-fident",
707 "-fno-ident",
708 "-fshort-double",
709 "-fno-short-double",
710 "-fshort-enums",
711 "-fno-short-enums",
713 "-Wall",
714 "-Wbad-function-cast",
715 "-Wno-bad-function-cast",
716 "-Wcast-qual",
717 "-Wno-cast-qual",
718 "-Wchar-subscripts",
719 "-Wno-char-subscripts",
720 "-Wcomment",
721 "-Wno-comment",
722 "-Wcomments",
723 "-Wno-comments",
724 "-Wconversion",
725 "-Wno-conversion",
726 "-Wformat",
727 "-Wno-format",
728 "-Wimport",
729 "-Wno-import",
730 "-Wimplicit",
731 "-Wno-implicit",
732 "-Wmain",
733 "-Wno-main",
734 "-Wmissing-braces",
735 "-Wno-missing-braces",
736 "-Wmissing-declarations",
737 "-Wno-missing-declarations",
738 "-Wmissing-prototypes",
739 "-Wno-missing-prototypes",
740 "-Wnested-externs",
741 "-Wno-nested-externs",
742 "-Wparentheses",
743 "-Wno-parentheses",
744 "-Wpointer-arith",
745 "-Wno-pointer-arith",
746 "-Wredundant-decls",
747 "-Wno-redundant-decls",
748 "-Wsign-compare",
749 "-Wno-sign-compare",
750 "-Wstrict-prototypes",
751 "-Wno-strict-prototypes",
752 "-Wtraditional",
753 "-Wno-traditional",
754 "-Wtrigraphs",
755 "-Wno-trigraphs",
756 "-Wundef",
757 "-Wno-undef",
758 "-Wwrite-strings",
759 "-Wno-write-strings",
761 /* these are for obj c */
762 "-lang-objc",
763 "-gen-decls",
764 "-fgnu-runtime",
765 "-fno-gnu-runtime",
766 "-fnext-runtime",
767 "-fno-next-runtime",
768 "-Wselector",
769 "-Wno-selector",
770 "-Wprotocol",
771 "-Wno-protocol",
773 #include "options.h"
777 /* Options controlling warnings */
779 /* Don't print warning messages. -w. */
781 int inhibit_warnings = 0;
783 /* Print various extra warnings. -W. */
785 int extra_warnings = 0;
787 /* Treat warnings as errors. -Werror. */
789 int warnings_are_errors = 0;
791 /* Nonzero to warn about unused local variables. */
793 int warn_unused;
795 /* Nonzero to warn about variables used before they are initialized. */
797 int warn_uninitialized;
799 /* Nonzero means warn about all declarations which shadow others. */
801 int warn_shadow;
803 /* Warn if a switch on an enum fails to have a case for every enum value. */
805 int warn_switch;
807 /* Nonzero means warn about function definitions that default the return type
808 or that use a null return and have a return-type other than void. */
810 int warn_return_type;
812 /* Nonzero means warn about pointer casts that increase the required
813 alignment of the target type (and might therefore lead to a crash
814 due to a misaligned access). */
816 int warn_cast_align;
818 /* Nonzero means warn about any identifiers that match in the first N
819 characters. The value N is in `id_clash_len'. */
821 int warn_id_clash;
822 unsigned id_clash_len;
824 /* Nonzero means warn about any objects definitions whose size is larger
825 than N bytes. Also want about function definitions whose returned
826 values are larger than N bytes. The value N is in `larger_than_size'. */
828 int warn_larger_than;
829 unsigned larger_than_size;
831 /* Nonzero means warn if inline function is too large. */
833 int warn_inline;
835 /* Warn if a function returns an aggregate,
836 since there are often incompatible calling conventions for doing this. */
838 int warn_aggregate_return;
840 /* Likewise for -W. */
842 struct { char *string; int *variable; int on_value;} W_options[] =
844 {"unused", &warn_unused, 1},
845 {"error", &warnings_are_errors, 1},
846 {"shadow", &warn_shadow, 1},
847 {"switch", &warn_switch, 1},
848 {"aggregate-return", &warn_aggregate_return, 1},
849 {"cast-align", &warn_cast_align, 1},
850 {"uninitialized", &warn_uninitialized, 1},
851 {"inline", &warn_inline, 1}
854 /* Output files for assembler code (real compiler output)
855 and debugging dumps. */
857 FILE *asm_out_file;
858 FILE *aux_info_file;
859 FILE *rtl_dump_file;
860 FILE *jump_opt_dump_file;
861 FILE *addressof_dump_file;
862 FILE *cse_dump_file;
863 FILE *loop_dump_file;
864 FILE *cse2_dump_file;
865 FILE *branch_prob_dump_file;
866 FILE *flow_dump_file;
867 FILE *combine_dump_file;
868 FILE *sched_dump_file;
869 FILE *local_reg_dump_file;
870 FILE *global_reg_dump_file;
871 FILE *sched2_dump_file;
872 FILE *jump2_opt_dump_file;
873 FILE *dbr_sched_dump_file;
874 FILE *stack_reg_dump_file;
876 /* Time accumulators, to count the total time spent in various passes. */
878 int parse_time;
879 int varconst_time;
880 int integration_time;
881 int jump_time;
882 int cse_time;
883 int loop_time;
884 int cse2_time;
885 int branch_prob_time;
886 int flow_time;
887 int combine_time;
888 int sched_time;
889 int local_alloc_time;
890 int global_alloc_time;
891 int sched2_time;
892 int dbr_sched_time;
893 int shorten_branch_time;
894 int stack_reg_time;
895 int final_time;
896 int symout_time;
897 int dump_time;
899 /* Return time used so far, in microseconds. */
902 get_run_time ()
904 #ifndef _WIN32
905 #ifdef USG
906 struct tms tms;
907 #else
908 #ifndef VMS
909 struct rusage rusage;
910 #else
911 struct
913 int proc_user_time;
914 int proc_system_time;
915 int child_user_time;
916 int child_system_time;
917 } vms_times;
918 #endif
919 #endif
920 #endif
922 if (quiet_flag)
923 return 0;
924 #ifdef _WIN32
925 if (clock() < 0)
926 return 0;
927 else
928 return (clock() * 1000);
929 #else /* not _WIN32 */
930 #ifdef USG
931 times (&tms);
932 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
933 #else
934 #ifndef VMS
935 getrusage (0, &rusage);
936 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
937 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
938 #else /* VMS */
939 times (&vms_times);
940 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
941 #endif
942 #endif
943 #endif
946 #define TIMEVAR(VAR, BODY) \
947 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
949 void
950 print_time (str, total)
951 char *str;
952 int total;
954 fprintf (stderr,
955 "time in %s: %d.%06d\n",
956 str, total / 1000000, total % 1000000);
959 /* Count an error or warning. Return 1 if the message should be printed. */
962 count_error (warningp)
963 int warningp;
965 if (warningp && inhibit_warnings)
966 return 0;
968 if (warningp && !warnings_are_errors)
969 warningcount++;
970 else
972 static int warning_message = 0;
974 if (warningp && !warning_message)
976 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
977 warning_message = 1;
979 errorcount++;
982 return 1;
985 /* Print a fatal error message. NAME is the text.
986 Also include a system error message based on `errno'. */
988 void
989 pfatal_with_name (name)
990 char *name;
992 fprintf (stderr, "%s: ", progname);
993 perror (name);
994 exit (FATAL_EXIT_CODE);
997 void
998 fatal_io_error (name)
999 char *name;
1001 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
1002 exit (FATAL_EXIT_CODE);
1005 /* Called to give a better error message for a bad insn rather than
1006 just calling abort(). */
1008 void
1009 fatal_insn (message, insn)
1010 char *message;
1011 rtx insn;
1013 if (!output_bytecode)
1015 error (message);
1016 debug_rtx (insn);
1018 if (asm_out_file)
1019 fflush (asm_out_file);
1020 if (aux_info_file)
1021 fflush (aux_info_file);
1022 if (rtl_dump_file)
1023 fflush (rtl_dump_file);
1024 if (jump_opt_dump_file)
1025 fflush (jump_opt_dump_file);
1026 if (addressof_dump_file)
1027 fflush (addressof_dump_file);
1028 if (cse_dump_file)
1029 fflush (cse_dump_file);
1030 if (loop_dump_file)
1031 fflush (loop_dump_file);
1032 if (cse2_dump_file)
1033 fflush (cse2_dump_file);
1034 if (flow_dump_file)
1035 fflush (flow_dump_file);
1036 if (combine_dump_file)
1037 fflush (combine_dump_file);
1038 if (sched_dump_file)
1039 fflush (sched_dump_file);
1040 if (local_reg_dump_file)
1041 fflush (local_reg_dump_file);
1042 if (global_reg_dump_file)
1043 fflush (global_reg_dump_file);
1044 if (sched2_dump_file)
1045 fflush (sched2_dump_file);
1046 if (jump2_opt_dump_file)
1047 fflush (jump2_opt_dump_file);
1048 if (dbr_sched_dump_file)
1049 fflush (dbr_sched_dump_file);
1050 if (stack_reg_dump_file)
1051 fflush (stack_reg_dump_file);
1052 fflush (stdout);
1053 fflush (stderr);
1054 abort ();
1057 /* Called to give a better error message when we don't have an insn to match
1058 what we are looking for or if the insn's constraints aren't satisfied,
1059 rather than just calling abort(). */
1061 void
1062 fatal_insn_not_found (insn)
1063 rtx insn;
1065 if (INSN_CODE (insn) < 0)
1066 fatal_insn ("internal error--unrecognizable insn:", insn);
1067 else
1068 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1071 /* This is the default decl_printable_name function. */
1073 static char *
1074 decl_name (decl, verbosity)
1075 tree decl;
1076 int verbosity;
1078 return IDENTIFIER_POINTER (DECL_NAME (decl));
1081 static int need_error_newline;
1083 /* Function of last error message;
1084 more generally, function such that if next error message is in it
1085 then we don't have to mention the function name. */
1086 static tree last_error_function = NULL;
1088 /* Used to detect when input_file_stack has changed since last described. */
1089 static int last_error_tick;
1091 /* Called when the start of a function definition is parsed,
1092 this function prints on stderr the name of the function. */
1094 void
1095 announce_function (decl)
1096 tree decl;
1098 if (! quiet_flag)
1100 if (rtl_dump_and_exit)
1101 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1102 else
1103 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1104 fflush (stderr);
1105 need_error_newline = 1;
1106 last_error_function = current_function_decl;
1110 /* The default function to print out name of current function that caused
1111 an error. */
1113 void
1114 default_print_error_function (file)
1115 char *file;
1117 if (last_error_function != current_function_decl)
1119 char *kind = "function";
1120 if (current_function_decl != 0
1121 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1122 kind = "method";
1124 if (file)
1125 fprintf (stderr, "%s: ", file);
1127 if (current_function_decl == NULL)
1128 fprintf (stderr, "At top level:\n");
1129 else
1131 char *name = (*decl_printable_name) (current_function_decl, 2);
1132 fprintf (stderr, "In %s `%s':\n", kind, name);
1135 last_error_function = current_function_decl;
1139 /* Called by report_error_function to print out function name.
1140 * Default may be overridden by language front-ends. */
1142 void (*print_error_function) PROTO((char *)) = default_print_error_function;
1144 /* Prints out, if necessary, the name of the current function
1145 that caused an error. Called from all error and warning functions. */
1147 void
1148 report_error_function (file)
1149 char *file;
1151 struct file_stack *p;
1153 if (need_error_newline)
1155 fprintf (stderr, "\n");
1156 need_error_newline = 0;
1159 (*print_error_function) (file);
1161 if (input_file_stack && input_file_stack->next != 0
1162 && input_file_stack_tick != last_error_tick
1163 && file == input_filename)
1165 fprintf (stderr, "In file included");
1166 for (p = input_file_stack->next; p; p = p->next)
1168 fprintf (stderr, " from %s:%d", p->name, p->line);
1169 if (p->next)
1170 fprintf (stderr, ",\n ");
1172 fprintf (stderr, ":\n");
1173 last_error_tick = input_file_stack_tick;
1177 /* Print a message. */
1179 static void
1180 vmessage (prefix, s, ap)
1181 char *prefix;
1182 char *s;
1183 va_list ap;
1185 if (prefix)
1186 fprintf (stderr, "%s: ", prefix);
1188 #ifdef HAVE_VPRINTF
1189 vfprintf (stderr, s, ap);
1190 #else
1192 HOST_WIDE_INT v1 = va_arg(ap, HOST_WIDE_INT);
1193 HOST_WIDE_INT v2 = va_arg(ap, HOST_WIDE_INT);
1194 HOST_WIDE_INT v3 = va_arg(ap, HOST_WIDE_INT);
1195 HOST_WIDE_INT v4 = va_arg(ap, HOST_WIDE_INT);
1196 fprintf (stderr, s, v1, v2, v3, v4);
1198 #endif
1201 /* Print a message relevant to line LINE of file FILE. */
1203 static void
1204 v_message_with_file_and_line (file, line, prefix, s, ap)
1205 char *file;
1206 int line;
1207 char *prefix;
1208 char *s;
1209 va_list ap;
1211 if (file)
1212 fprintf (stderr, "%s:%d: ", file, line);
1213 else
1214 fprintf (stderr, "%s: ", progname);
1216 vmessage (prefix, s, ap);
1217 fputc ('\n', stderr);
1220 /* Print a message relevant to the given DECL. */
1222 static void
1223 v_message_with_decl (decl, prefix, s, ap)
1224 tree decl;
1225 char *prefix;
1226 char *s;
1227 va_list ap;
1229 char *n, *p;
1231 fprintf (stderr, "%s:%d: ",
1232 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1234 if (prefix)
1235 fprintf (stderr, "%s: ", prefix);
1237 /* Do magic to get around lack of varargs support for insertion
1238 of arguments into existing list. We know that the decl is first;
1239 we ass_u_me that it will be printed with "%s". */
1241 for (p = s; *p; ++p)
1243 if (*p == '%')
1245 if (*(p + 1) == '%')
1246 ++p;
1247 else
1248 break;
1252 if (p > s) /* Print the left-hand substring. */
1254 char fmt[sizeof "%.255s"];
1255 long width = p - s;
1257 if (width > 255L) width = 255L; /* arbitrary */
1258 sprintf (fmt, "%%.%lds", width);
1259 fprintf (stderr, fmt, s);
1262 if (*p == '%') /* Print the name. */
1264 char *n = (DECL_NAME (decl)
1265 ? (*decl_printable_name) (decl, 2)
1266 : "((anonymous))");
1267 fputs (n, stderr);
1268 while (*p)
1270 ++p;
1271 if (isalpha (*(p - 1) & 0xFF))
1272 break;
1276 if (*p) /* Print the rest of the message. */
1277 vmessage ((char *)NULL, p, ap);
1279 fputc ('\n', stderr);
1282 /* Figure file and line of the given INSN. */
1284 static void
1285 file_and_line_for_asm (insn, pfile, pline)
1286 rtx insn;
1287 char **pfile;
1288 int *pline;
1290 rtx body = PATTERN (insn);
1291 rtx asmop;
1293 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1294 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1295 asmop = SET_SRC (body);
1296 else if (GET_CODE (body) == ASM_OPERANDS)
1297 asmop = body;
1298 else if (GET_CODE (body) == PARALLEL
1299 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1300 asmop = SET_SRC (XVECEXP (body, 0, 0));
1301 else if (GET_CODE (body) == PARALLEL
1302 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1303 asmop = XVECEXP (body, 0, 0);
1304 else
1305 asmop = NULL;
1307 if (asmop)
1309 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1310 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1312 else
1314 *pfile = input_filename;
1315 *pline = lineno;
1319 /* Report an error at line LINE of file FILE. */
1321 static void
1322 v_error_with_file_and_line (file, line, s, ap)
1323 char *file;
1324 int line;
1325 char *s;
1326 va_list ap;
1328 count_error (0);
1329 report_error_function (file);
1330 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1333 void
1334 error_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1336 #ifndef __STDC__
1337 char *file;
1338 int line;
1339 char *s;
1340 #endif
1341 va_list ap;
1343 VA_START (ap, s);
1345 #ifndef __STDC__
1346 file = va_arg (ap, char *);
1347 line = va_arg (ap, int);
1348 s = va_arg (ap, char *);
1349 #endif
1351 v_error_with_file_and_line (file, line, s, ap);
1352 va_end (ap);
1355 /* Report an error at the declaration DECL.
1356 S is a format string which uses %s to substitute the declaration
1357 name; subsequent substitutions are a la printf. */
1359 static void
1360 v_error_with_decl (decl, s, ap)
1361 tree decl;
1362 char *s;
1363 va_list ap;
1365 count_error (0);
1366 report_error_function (DECL_SOURCE_FILE (decl));
1367 v_message_with_decl (decl, (char *)NULL, s, ap);
1370 void
1371 error_with_decl VPROTO((tree decl, char *s, ...))
1373 #ifndef __STDC__
1374 tree decl;
1375 char *s;
1376 #endif
1377 va_list ap;
1379 VA_START (ap, s);
1381 #ifndef __STDC__
1382 decl = va_arg (ap, tree);
1383 s = va_arg (ap, char *);
1384 #endif
1386 v_error_with_decl (decl, s, ap);
1387 va_end (ap);
1390 /* Report an error at the line number of the insn INSN.
1391 This is used only when INSN is an `asm' with operands,
1392 and each ASM_OPERANDS records its own source file and line. */
1394 static void
1395 v_error_for_asm (insn, s, ap)
1396 rtx insn;
1397 char *s;
1398 va_list ap;
1400 char *file;
1401 int line;
1403 count_error (0);
1404 file_and_line_for_asm (insn, &file, &line);
1405 report_error_function (file);
1406 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1409 void
1410 error_for_asm VPROTO((rtx insn, char *s, ...))
1412 #ifndef __STDC__
1413 rtx insn;
1414 char *s;
1415 #endif
1416 va_list ap;
1418 VA_START (ap, s);
1420 #ifndef __STDC__
1421 insn = va_arg (ap, rtx);
1422 s = va_arg (ap, char *);
1423 #endif
1425 v_error_for_asm (insn, s, ap);
1426 va_end (ap);
1429 /* Report an error at the current line number. */
1431 static void
1432 verror (s, ap)
1433 char *s;
1434 va_list ap;
1436 v_error_with_file_and_line (input_filename, lineno, s, ap);
1439 void
1440 error VPROTO((char *s, ...))
1442 #ifndef __STDC__
1443 char *s;
1444 #endif
1445 va_list ap;
1447 VA_START (ap, s);
1449 #ifndef __STDC__
1450 s = va_arg (ap, char *);
1451 #endif
1453 verror (s, ap);
1454 va_end (ap);
1457 /* Report a fatal error at the current line number. */
1459 static void
1460 vfatal (s, ap)
1461 char *s;
1462 va_list ap;
1464 verror (s, ap);
1465 exit (FATAL_EXIT_CODE);
1468 void
1469 fatal VPROTO((char *s, ...))
1471 #ifndef __STDC__
1472 char *s;
1473 #endif
1474 va_list ap;
1476 VA_START (ap, s);
1478 #ifndef __STDC__
1479 s = va_arg (ap, char *);
1480 #endif
1482 vfatal (s, ap);
1483 va_end (ap);
1486 /* Report a warning at line LINE of file FILE. */
1488 static void
1489 v_warning_with_file_and_line (file, line, s, ap)
1490 char *file;
1491 int line;
1492 char *s;
1493 va_list ap;
1495 if (count_error (1))
1497 report_error_function (file);
1498 v_message_with_file_and_line (file, line, "warning", s, ap);
1502 void
1503 warning_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1505 #ifndef __STDC__
1506 char *file;
1507 int line;
1508 char *s;
1509 #endif
1510 va_list ap;
1512 VA_START (ap, s);
1514 #ifndef __STDC__
1515 file = va_arg (ap, char *);
1516 line = va_arg (ap, int);
1517 s = va_arg (ap, char *);
1518 #endif
1520 v_warning_with_file_and_line (file, line, s, ap);
1521 va_end (ap);
1524 /* Report a warning at the declaration DECL.
1525 S is a format string which uses %s to substitute the declaration
1526 name; subsequent substitutions are a la printf. */
1528 static void
1529 v_warning_with_decl (decl, s, ap)
1530 tree decl;
1531 char *s;
1532 va_list ap;
1534 if (count_error (1))
1536 report_error_function (DECL_SOURCE_FILE (decl));
1537 v_message_with_decl (decl, "warning", s, ap);
1541 void
1542 warning_with_decl VPROTO((tree decl, char *s, ...))
1544 #ifndef __STDC__
1545 tree decl;
1546 char *s;
1547 #endif
1548 va_list ap;
1550 VA_START (ap, s);
1552 #ifndef __STDC__
1553 decl = va_arg (ap, tree);
1554 s = va_arg (ap, char *);
1555 #endif
1557 v_warning_with_decl (decl, s, ap);
1558 va_end (ap);
1561 /* Report a warning at the line number of the insn INSN.
1562 This is used only when INSN is an `asm' with operands,
1563 and each ASM_OPERANDS records its own source file and line. */
1565 static void
1566 v_warning_for_asm (insn, s, ap)
1567 rtx insn;
1568 char *s;
1569 va_list ap;
1571 if (count_error (1))
1573 char *file;
1574 int line;
1576 file_and_line_for_asm (insn, &file, &line);
1577 report_error_function (file);
1578 v_message_with_file_and_line (file, line, "warning", s, ap);
1582 void
1583 warning_for_asm VPROTO((rtx insn, char *s, ...))
1585 #ifndef __STDC__
1586 rtx insn;
1587 char *s;
1588 #endif
1589 va_list ap;
1591 VA_START (ap, s);
1593 #ifndef __STDC__
1594 insn = va_arg (ap, rtx);
1595 s = va_arg (ap, char *);
1596 #endif
1598 v_warning_for_asm (insn, s, ap);
1599 va_end (ap);
1602 /* Report a warning at the current line number. */
1604 static void
1605 vwarning (s, ap)
1606 char *s;
1607 va_list ap;
1609 v_warning_with_file_and_line (input_filename, lineno, s, ap);
1612 void
1613 warning VPROTO((char *s, ...))
1615 #ifndef __STDC__
1616 char *s;
1617 #endif
1618 va_list ap;
1620 VA_START (ap, s);
1622 #ifndef __STDC__
1623 s = va_arg (ap, char *);
1624 #endif
1626 vwarning (s, ap);
1627 va_end (ap);
1630 /* These functions issue either warnings or errors depending on
1631 -pedantic-errors. */
1633 static void
1634 vpedwarn (s, ap)
1635 char *s;
1636 va_list ap;
1638 if (flag_pedantic_errors)
1639 verror (s, ap);
1640 else
1641 vwarning (s, ap);
1644 void
1645 pedwarn VPROTO((char *s, ...))
1647 #ifndef __STDC__
1648 char *s;
1649 #endif
1650 va_list ap;
1652 VA_START (ap, s);
1654 #ifndef __STDC__
1655 s = va_arg (ap, char *);
1656 #endif
1658 vpedwarn (s, ap);
1659 va_end (ap);
1662 static void
1663 v_pedwarn_with_decl (decl, s, ap)
1664 tree decl;
1665 char *s;
1666 va_list ap;
1668 /* We don't want -pedantic-errors to cause the compilation to fail from
1669 "errors" in system header files. Sometimes fixincludes can't fix what's
1670 broken (eg: unsigned char bitfields - fixing it may change the alignment
1671 which will cause programs to mysteriously fail because the C library
1672 or kernel uses the original layout). There's no point in issuing a
1673 warning either, it's just unnecessary noise. */
1675 if (! DECL_IN_SYSTEM_HEADER (decl))
1677 if (flag_pedantic_errors)
1678 v_error_with_decl (decl, s, ap);
1679 else
1680 v_warning_with_decl (decl, s, ap);
1684 void
1685 pedwarn_with_decl VPROTO((tree decl, char *s, ...))
1687 #ifndef __STDC__
1688 tree decl;
1689 char *s;
1690 #endif
1691 va_list ap;
1693 VA_START (ap, s);
1695 #ifndef __STDC__
1696 decl = va_arg (ap, tree);
1697 s = va_arg (ap, char *);
1698 #endif
1700 v_pedwarn_with_decl (decl, s, ap);
1701 va_end (ap);
1704 static void
1705 v_pedwarn_with_file_and_line (file, line, s, ap)
1706 char *file;
1707 int line;
1708 char *s;
1709 va_list ap;
1711 if (flag_pedantic_errors)
1712 v_error_with_file_and_line (file, line, s, ap);
1713 else
1714 v_warning_with_file_and_line (file, line, s, ap);
1717 void
1718 pedwarn_with_file_and_line VPROTO((char *file, int line, char *s, ...))
1720 #ifndef __STDC__
1721 char *file;
1722 int line;
1723 char *s;
1724 #endif
1725 va_list ap;
1727 VA_START (ap, s);
1729 #ifndef __STDC__
1730 file = va_arg (ap, char *);
1731 line = va_arg (ap, int);
1732 s = va_arg (ap, char *);
1733 #endif
1735 v_pedwarn_with_file_and_line (file, line, s, ap);
1736 va_end (ap);
1739 /* Apologize for not implementing some feature. */
1741 static void
1742 vsorry (s, ap)
1743 char *s;
1744 va_list ap;
1746 sorrycount++;
1747 if (input_filename)
1748 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1749 else
1750 fprintf (stderr, "%s: ", progname);
1751 vmessage ("sorry, not implemented", s, ap);
1752 fputc ('\n', stderr);
1755 void
1756 sorry VPROTO((char *s, ...))
1758 #ifndef __STDC__
1759 char *s;
1760 #endif
1761 va_list ap;
1763 VA_START (ap, s);
1765 #ifndef __STDC__
1766 s = va_arg (ap, char *);
1767 #endif
1769 vsorry (s, ap);
1770 va_end (ap);
1773 /* Apologize for not implementing some feature, then quit. */
1775 static void
1776 v_really_sorry (s, ap)
1777 char *s;
1778 va_list ap;
1780 sorrycount++;
1781 if (input_filename)
1782 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1783 else
1784 fprintf (stderr, "%s: ", progname);
1785 vmessage ("sorry, not implemented", s, ap);
1786 fatal (" (fatal)\n");
1789 void
1790 really_sorry VPROTO((char *s, ...))
1792 #ifndef __STDC__
1793 char *s;
1794 #endif
1795 va_list ap;
1797 VA_START (ap, s);
1799 #ifndef __STDC__
1800 s = va_arg (ap, char *);
1801 #endif
1803 v_really_sorry (s, ap);
1804 va_end (ap);
1807 /* More 'friendly' abort that prints the line and file.
1808 config.h can #define abort fancy_abort if you like that sort of thing.
1810 I don't think this is actually a good idea.
1811 Other sorts of crashes will look a certain way.
1812 It is a good thing if crashes from calling abort look the same way.
1813 -- RMS */
1815 void
1816 fancy_abort ()
1818 fatal ("internal gcc abort");
1821 /* This calls abort and is used to avoid problems when abort if a macro.
1822 It is used when we need to pass the address of abort. */
1824 void
1825 do_abort ()
1827 abort ();
1830 /* When `malloc.c' is compiled with `rcheck' defined,
1831 it calls this function to report clobberage. */
1833 void
1834 botch (s)
1836 abort ();
1839 /* Same as `malloc' but report error if no memory available. */
1841 char *
1842 xmalloc (size)
1843 unsigned size;
1845 register char *value = (char *) malloc (size);
1846 if (value == 0 && size != 0)
1847 fatal ("virtual memory exhausted");
1848 return value;
1851 /* Same as `realloc' but report error if no memory available. */
1853 char *
1854 xrealloc (ptr, size)
1855 char *ptr;
1856 int size;
1858 char *result = (char *) realloc (ptr, size);
1859 if (!result)
1860 fatal ("virtual memory exhausted");
1861 return result;
1864 /* Same as `strdup' but report error if no memory available. */
1866 char *
1867 xstrdup (s)
1868 register char *s;
1870 register char *result = (char *) malloc (strlen (s) + 1);
1872 if (! result)
1873 fatal ("virtual memory exhausted");
1874 strcpy (result, s);
1875 return result;
1878 /* Return the logarithm of X, base 2, considering X unsigned,
1879 if X is a power of 2. Otherwise, returns -1.
1881 This should be used via the `exact_log2' macro. */
1884 exact_log2_wide (x)
1885 register unsigned HOST_WIDE_INT x;
1887 register int log = 0;
1888 /* Test for 0 or a power of 2. */
1889 if (x == 0 || x != (x & -x))
1890 return -1;
1891 while ((x >>= 1) != 0)
1892 log++;
1893 return log;
1896 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1897 If X is 0, return -1.
1899 This should be used via the floor_log2 macro. */
1902 floor_log2_wide (x)
1903 register unsigned HOST_WIDE_INT x;
1905 register int log = -1;
1906 while (x != 0)
1907 log++,
1908 x >>= 1;
1909 return log;
1912 static int float_handler_set;
1913 int float_handled;
1914 jmp_buf float_handler;
1916 /* Signals actually come here. */
1918 static void
1919 float_signal (signo)
1920 /* If this is missing, some compilers complain. */
1921 int signo;
1923 if (float_handled == 0)
1924 abort ();
1925 #if defined (USG) || defined (hpux)
1926 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
1927 #endif
1928 float_handled = 0;
1929 signal (SIGFPE, float_signal);
1930 longjmp (float_handler, 1);
1933 /* Specify where to longjmp to when a floating arithmetic error happens.
1934 If HANDLER is 0, it means don't handle the errors any more. */
1936 void
1937 set_float_handler (handler)
1938 jmp_buf handler;
1940 float_handled = (handler != 0);
1941 if (handler)
1942 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
1944 if (float_handled && ! float_handler_set)
1946 signal (SIGFPE, float_signal);
1947 float_handler_set = 1;
1951 /* Specify, in HANDLER, where to longjmp to when a floating arithmetic
1952 error happens, pushing the previous specification into OLD_HANDLER.
1953 Return an indication of whether there was a previous handler in effect. */
1956 push_float_handler (handler, old_handler)
1957 jmp_buf handler, old_handler;
1959 int was_handled = float_handled;
1961 float_handled = 1;
1962 if (was_handled)
1963 bcopy ((char *) float_handler, (char *) old_handler,
1964 sizeof (float_handler));
1966 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
1967 return was_handled;
1970 /* Restore the previous specification of whether and where to longjmp to
1971 when a floating arithmetic error happens. */
1973 void
1974 pop_float_handler (handled, handler)
1975 int handled;
1976 jmp_buf handler;
1978 float_handled = handled;
1979 if (handled)
1980 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
1983 /* Handler for SIGPIPE. */
1985 static void
1986 pipe_closed (signo)
1987 /* If this is missing, some compilers complain. */
1988 int signo;
1990 fatal ("output pipe has been closed");
1993 /* Strip off a legitimate source ending from the input string NAME of
1994 length LEN. Rather than having to know the names used by all of
1995 our front ends, we strip off an ending of a period followed by one,
1996 two, or three characters. */
1998 void
1999 strip_off_ending (name, len)
2000 char *name;
2001 int len;
2003 if (len > 2 && name[len - 2] == '.')
2004 name[len - 2] = '\0';
2005 else if (len > 3 && name[len - 3] == '.')
2006 name[len - 3] = '\0';
2007 else if (len > 4 && name[len - 4] == '.')
2008 name[len - 4] = '\0';
2011 /* Output a quoted string. */
2013 void
2014 output_quoted_string (asm_file, string)
2015 FILE *asm_file;
2016 char *string;
2018 char c;
2020 putc ('\"', asm_file);
2021 while ((c = *string++) != 0)
2023 if (c == '\"' || c == '\\')
2024 putc ('\\', asm_file);
2025 putc (c, asm_file);
2027 putc ('\"', asm_file);
2030 /* Output a file name in the form wanted by System V. */
2032 void
2033 output_file_directive (asm_file, input_name)
2034 FILE *asm_file;
2035 char *input_name;
2037 int len = strlen (input_name);
2038 char *na = input_name + len;
2040 /* NA gets INPUT_NAME sans directory names. */
2041 while (na > input_name)
2043 if (na[-1] == '/')
2044 break;
2045 na--;
2048 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2049 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2050 #else
2051 #ifdef ASM_OUTPUT_SOURCE_FILENAME
2052 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2053 #else
2054 fprintf (asm_file, "\t.file\t");
2055 output_quoted_string (asm_file, na);
2056 fputc ('\n', asm_file);
2057 #endif
2058 #endif
2061 /* Routine to build language identifier for object file. */
2063 static void
2064 output_lang_identify (asm_out_file)
2065 FILE *asm_out_file;
2067 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2068 char *s = (char *) alloca (len);
2069 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2070 ASM_OUTPUT_LABEL (asm_out_file, s);
2073 /* Routine to open a dump file. */
2075 static FILE *
2076 open_dump_file (base_name, suffix)
2077 char *base_name;
2078 char *suffix;
2080 FILE *f;
2081 char *dumpname = (char *) alloca (strlen (base_name) + strlen (suffix) + 1);
2083 strcpy (dumpname, base_name);
2084 strcat (dumpname, suffix);
2085 f = fopen (dumpname, "w");
2086 if (f == 0)
2087 pfatal_with_name (dumpname);
2088 return f;
2091 /* Compile an entire file of output from cpp, named NAME.
2092 Write a file of assembly output and various debugging dumps. */
2094 static void
2095 compile_file (name)
2096 char *name;
2098 tree globals;
2099 int start_time;
2101 int name_specified = name != 0;
2103 if (dump_base_name == 0)
2104 dump_base_name = name ? name : "gccdump";
2106 parse_time = 0;
2107 varconst_time = 0;
2108 integration_time = 0;
2109 jump_time = 0;
2110 cse_time = 0;
2111 loop_time = 0;
2112 cse2_time = 0;
2113 branch_prob_time = 0;
2114 flow_time = 0;
2115 combine_time = 0;
2116 sched_time = 0;
2117 local_alloc_time = 0;
2118 global_alloc_time = 0;
2119 sched2_time = 0;
2120 dbr_sched_time = 0;
2121 shorten_branch_time = 0;
2122 stack_reg_time = 0;
2123 final_time = 0;
2124 symout_time = 0;
2125 dump_time = 0;
2127 #if !USE_CPPLIB
2128 /* Open input file. */
2130 if (name == 0 || !strcmp (name, "-"))
2132 finput = stdin;
2133 name = "stdin";
2135 else
2136 finput = fopen (name, "r");
2137 if (finput == 0)
2138 pfatal_with_name (name);
2140 #ifdef IO_BUFFER_SIZE
2141 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
2142 #endif
2143 #endif /* !USE_CPPLIB */
2145 /* Initialize data in various passes. */
2147 init_obstacks ();
2148 init_tree_codes ();
2149 #if USE_CPPLIB
2150 init_parse (name);
2151 #else
2152 init_lex ();
2153 #endif
2154 /* Some of these really don't need to be called when generating bytecode,
2155 but the options would have to be parsed first to know that. -bson */
2156 init_rtl ();
2157 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2158 || debug_info_level == DINFO_LEVEL_VERBOSE
2159 || flag_test_coverage);
2160 init_regs ();
2161 init_decl_processing ();
2162 init_optabs ();
2163 init_stmt ();
2164 init_expmed ();
2165 init_expr_once ();
2166 init_loop ();
2167 init_reload ();
2169 if (flag_caller_saves)
2170 init_caller_save ();
2172 /* If auxiliary info generation is desired, open the output file.
2173 This goes in the same directory as the source file--unlike
2174 all the other output files. */
2175 if (flag_gen_aux_info)
2177 aux_info_file = fopen (aux_info_file_name, "w");
2178 if (aux_info_file == 0)
2179 pfatal_with_name (aux_info_file_name);
2182 /* If rtl dump desired, open the output file. */
2183 if (rtl_dump)
2184 rtl_dump_file = open_dump_file (dump_base_name, ".rtl");
2186 /* If jump_opt dump desired, open the output file. */
2187 if (jump_opt_dump)
2188 jump_opt_dump_file = open_dump_file (dump_base_name, ".jump");
2190 /* If addressof dump desired, open the output file. */
2191 if (addressof_dump)
2192 addressof_dump_file = open_dump_file (dump_base_name, ".addressof");
2194 /* If cse dump desired, open the output file. */
2195 if (cse_dump)
2196 cse_dump_file = open_dump_file (dump_base_name, ".cse");
2198 /* If loop dump desired, open the output file. */
2199 if (loop_dump)
2200 loop_dump_file = open_dump_file (dump_base_name, ".loop");
2202 /* If cse2 dump desired, open the output file. */
2203 if (cse2_dump)
2204 cse2_dump_file = open_dump_file (dump_base_name, ".cse2");
2206 /* If branch_prob dump desired, open the output file. */
2207 if (branch_prob_dump)
2208 branch_prob_dump_file = open_dump_file (dump_base_name, ".bp");
2210 /* If flow dump desired, open the output file. */
2211 if (flow_dump)
2212 flow_dump_file = open_dump_file (dump_base_name, ".flow");
2214 /* If combine dump desired, open the output file. */
2215 if (combine_dump)
2216 combine_dump_file = open_dump_file (dump_base_name, ".combine");
2218 /* If scheduling dump desired, open the output file. */
2219 if (sched_dump)
2220 sched_dump_file = open_dump_file (dump_base_name, ".sched");
2222 /* If local_reg dump desired, open the output file. */
2223 if (local_reg_dump)
2224 local_reg_dump_file = open_dump_file (dump_base_name, ".lreg");
2226 /* If global_reg dump desired, open the output file. */
2227 if (global_reg_dump)
2228 global_reg_dump_file = open_dump_file (dump_base_name, ".greg");
2230 /* If 2nd scheduling dump desired, open the output file. */
2231 if (sched2_dump)
2232 sched2_dump_file = open_dump_file (dump_base_name, ".sched2");
2234 /* If jump2_opt dump desired, open the output file. */
2235 if (jump2_opt_dump)
2236 jump2_opt_dump_file = open_dump_file (dump_base_name, ".jump2");
2238 /* If dbr_sched dump desired, open the output file. */
2239 if (dbr_sched_dump)
2240 dbr_sched_dump_file = open_dump_file (dump_base_name, ".dbr");
2242 #ifdef STACK_REGS
2244 /* If stack_reg dump desired, open the output file. */
2245 if (stack_reg_dump)
2246 stack_reg_dump_file = open_dump_file (dump_base_name, ".stack");
2248 #endif
2250 /* Open assembler code output file. */
2252 if (! name_specified && asm_file_name == 0)
2253 asm_out_file = stdout;
2254 else
2256 int len = strlen (dump_base_name);
2257 register char *dumpname = (char *) xmalloc (len + 6);
2258 strcpy (dumpname, dump_base_name);
2259 strip_off_ending (dumpname, len);
2260 strcat (dumpname, ".s");
2261 if (asm_file_name == 0)
2263 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
2264 strcpy (asm_file_name, dumpname);
2266 if (!strcmp (asm_file_name, "-"))
2267 asm_out_file = stdout;
2268 else
2269 asm_out_file = fopen (asm_file_name, "w");
2270 if (asm_out_file == 0)
2271 pfatal_with_name (asm_file_name);
2274 #ifdef IO_BUFFER_SIZE
2275 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2276 _IOFBF, IO_BUFFER_SIZE);
2277 #endif
2279 input_filename = name;
2281 /* Put an entry on the input file stack for the main input file. */
2282 input_file_stack
2283 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2284 input_file_stack->next = 0;
2285 input_file_stack->name = input_filename;
2287 /* Perform language-specific initialization.
2288 This may set main_input_filename. */
2289 lang_init ();
2291 /* If the input doesn't start with a #line, use the input name
2292 as the official input file name. */
2293 if (main_input_filename == 0)
2294 main_input_filename = name;
2296 if (!output_bytecode)
2298 ASM_FILE_START (asm_out_file);
2300 #ifdef ASM_COMMENT_START
2301 if (flag_verbose_asm)
2303 /* Print the list of options in effect. */
2304 print_version (asm_out_file, ASM_COMMENT_START);
2305 print_switch_values (asm_out_file, 0, MAX_LINE,
2306 ASM_COMMENT_START, " ", "\n");
2307 /* Add a blank line here so it appears in assembler output but not
2308 screen output. */
2309 fprintf (asm_out_file, "\n");
2311 #endif
2314 /* Output something to inform GDB that this compilation was by GCC. Also
2315 serves to tell GDB file consists of bytecodes. */
2316 if (output_bytecode)
2317 fprintf (asm_out_file, "bc_gcc2_compiled.:\n");
2318 else
2320 #ifndef ASM_IDENTIFY_GCC
2321 fprintf (asm_out_file, "gcc2_compiled.:\n");
2322 #else
2323 ASM_IDENTIFY_GCC (asm_out_file);
2324 #endif
2327 /* Output something to identify which front-end produced this file. */
2328 #ifdef ASM_IDENTIFY_LANGUAGE
2329 ASM_IDENTIFY_LANGUAGE (asm_out_file);
2330 #endif
2332 #ifndef ASM_OUTPUT_SECTION_NAME
2333 if (flag_function_sections)
2335 warning ("-ffunction-sections not supported for this target.");
2336 flag_function_sections = 0;
2338 #endif
2340 if (flag_function_sections
2341 && (profile_flag || profile_block_flag))
2343 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2344 flag_function_sections = 0;
2347 if (flag_function_sections && write_symbols != NO_DEBUG)
2348 warning ("-ffunction-sections may affect debugging on some targets.");
2350 if (output_bytecode)
2352 if (profile_flag || profile_block_flag)
2353 error ("profiling not supported in bytecode compilation");
2355 else
2357 /* ??? Note: There used to be a conditional here
2358 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2359 This was to guarantee separation between gcc_compiled. and
2360 the first function, for the sake of dbx on Suns.
2361 However, having the extra zero here confused the Emacs
2362 code for unexec, and might confuse other programs too.
2363 Therefore, I took out that change.
2364 In future versions we should find another way to solve
2365 that dbx problem. -- rms, 23 May 93. */
2367 /* Don't let the first function fall at the same address
2368 as gcc_compiled., if profiling. */
2369 if (profile_flag || profile_block_flag)
2370 assemble_zeros (UNITS_PER_WORD);
2373 /* If dbx symbol table desired, initialize writing it
2374 and output the predefined types. */
2375 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2376 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2377 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2378 getdecls ()));
2379 #endif
2380 #ifdef SDB_DEBUGGING_INFO
2381 if (write_symbols == SDB_DEBUG)
2382 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2383 getdecls ()));
2384 #endif
2385 #ifdef DWARF_DEBUGGING_INFO
2386 if (write_symbols == DWARF_DEBUG)
2387 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2388 #endif
2389 #ifdef DWARF2_DEBUGGING_INFO
2390 if (write_symbols == DWARF2_DEBUG)
2391 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
2392 #endif
2394 /* Initialize yet another pass. */
2396 if (!output_bytecode)
2397 init_final (main_input_filename);
2398 init_branch_prob (dump_base_name);
2400 start_time = get_run_time ();
2402 /* Call the parser, which parses the entire file
2403 (calling rest_of_compilation for each function). */
2405 if (yyparse () != 0)
2407 if (errorcount == 0)
2408 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
2410 /* In case there were missing closebraces,
2411 get us back to the global binding level. */
2412 while (! global_bindings_p ())
2413 poplevel (0, 0, 0);
2416 output_func_start_profiler ();
2418 /* Compilation is now finished except for writing
2419 what's left of the symbol table output. */
2421 parse_time += get_run_time () - start_time;
2423 parse_time -= integration_time;
2424 parse_time -= varconst_time;
2426 globals = getdecls ();
2428 /* Really define vars that have had only a tentative definition.
2429 Really output inline functions that must actually be callable
2430 and have not been output so far. */
2433 int len = list_length (globals);
2434 tree *vec = (tree *) alloca (sizeof (tree) * len);
2435 int i;
2436 tree decl;
2437 int reconsider = 1;
2439 /* Process the decls in reverse order--earliest first.
2440 Put them into VEC from back to front, then take out from front. */
2442 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2443 vec[len - i - 1] = decl;
2445 for (i = 0; i < len; i++)
2447 decl = vec[i];
2449 /* We're not deferring this any longer. */
2450 DECL_DEFER_OUTPUT (decl) = 0;
2452 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2453 && incomplete_decl_finalize_hook != 0)
2454 (*incomplete_decl_finalize_hook) (decl);
2457 /* Now emit any global variables or functions that we have been putting
2458 off. We need to loop in case one of the things emitted here
2459 references another one which comes earlier in the list. */
2460 while (reconsider)
2462 reconsider = 0;
2463 for (i = 0; i < len; i++)
2465 decl = vec[i];
2467 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2468 continue;
2470 /* Don't write out static consts, unless we still need them.
2472 We also keep static consts if not optimizing (for debugging),
2473 unless the user specified -fno-keep-static-consts.
2474 ??? They might be better written into the debug information.
2475 This is possible when using DWARF.
2477 A language processor that wants static constants to be always
2478 written out (even if it is not used) is responsible for
2479 calling rest_of_decl_compilation itself. E.g. the C front-end
2480 calls rest_of_decl_compilation from finish_decl.
2481 One motivation for this is that is conventional in some
2482 environments to write things like:
2483 static const char rcsid[] = "... version string ...";
2484 intending to force the string to be in the executable.
2486 A language processor that would prefer to have unneeded
2487 static constants "optimized away" would just defer writing
2488 them out until here. E.g. C++ does this, because static
2489 constants are often defined in header files.
2491 ??? A tempting alternative (for both C and C++) would be
2492 to force a constant to be written if and only if it is
2493 defined in a main file, as opposed to an include file. */
2495 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2496 && (! TREE_READONLY (decl)
2497 || TREE_PUBLIC (decl)
2498 || (!optimize && flag_keep_static_consts)
2499 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2501 reconsider = 1;
2502 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2505 if (TREE_CODE (decl) == FUNCTION_DECL
2506 && DECL_INITIAL (decl) != 0
2507 && DECL_SAVED_INSNS (decl) != 0
2508 && (flag_keep_inline_functions
2509 || TREE_PUBLIC (decl)
2510 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2512 reconsider = 1;
2513 temporary_allocation ();
2514 output_inline_function (decl);
2515 permanent_allocation (1);
2520 /* Now that all possible functions have been output, we can dump
2521 the exception table. */
2523 if (exception_table_p ())
2524 output_exception_table ();
2526 for (i = 0; i < len; i++)
2528 decl = vec[i];
2530 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2531 && ! TREE_ASM_WRITTEN (decl))
2532 /* Cancel the RTL for this decl so that, if debugging info
2533 output for global variables is still to come,
2534 this one will be omitted. */
2535 DECL_RTL (decl) = NULL;
2537 /* Warn about any function
2538 declared static but not defined.
2539 We don't warn about variables,
2540 because many programs have static variables
2541 that exist only to get some text into the object file. */
2542 if (TREE_CODE (decl) == FUNCTION_DECL
2543 && (warn_unused
2544 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2545 && DECL_INITIAL (decl) == 0
2546 && DECL_EXTERNAL (decl)
2547 && ! DECL_ARTIFICIAL (decl)
2548 && ! TREE_PUBLIC (decl))
2550 pedwarn_with_decl (decl,
2551 "`%s' declared `static' but never defined");
2552 /* This symbol is effectively an "extern" declaration now. */
2553 TREE_PUBLIC (decl) = 1;
2554 assemble_external (decl);
2557 /* Warn about static fns or vars defined but not used,
2558 but not about inline functions or static consts
2559 since defining those in header files is normal practice. */
2560 if (warn_unused
2561 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2562 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2563 && ! DECL_IN_SYSTEM_HEADER (decl)
2564 && ! DECL_EXTERNAL (decl)
2565 && ! TREE_PUBLIC (decl)
2566 && ! TREE_USED (decl)
2567 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2568 /* The TREE_USED bit for file-scope decls
2569 is kept in the identifier, to handle multiple
2570 external decls in different scopes. */
2571 && ! TREE_USED (DECL_NAME (decl)))
2572 warning_with_decl (decl, "`%s' defined but not used");
2574 #ifdef SDB_DEBUGGING_INFO
2575 /* The COFF linker can move initialized global vars to the end.
2576 And that can screw up the symbol ordering.
2577 By putting the symbols in that order to begin with,
2578 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2579 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2580 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2581 && ! DECL_EXTERNAL (decl)
2582 && DECL_RTL (decl) != 0)
2583 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2585 /* Output COFF information for non-global
2586 file-scope initialized variables. */
2587 if (write_symbols == SDB_DEBUG
2588 && TREE_CODE (decl) == VAR_DECL
2589 && DECL_INITIAL (decl)
2590 && ! DECL_EXTERNAL (decl)
2591 && DECL_RTL (decl) != 0
2592 && GET_CODE (DECL_RTL (decl)) == MEM)
2593 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2594 #endif /* SDB_DEBUGGING_INFO */
2595 #ifdef DWARF_DEBUGGING_INFO
2596 /* Output DWARF information for file-scope tentative data object
2597 declarations, file-scope (extern) function declarations (which
2598 had no corresponding body) and file-scope tagged type declarations
2599 and definitions which have not yet been forced out. */
2601 if (write_symbols == DWARF_DEBUG
2602 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2603 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2604 #endif
2605 #ifdef DWARF2_DEBUGGING_INFO
2606 /* Output DWARF2 information for file-scope tentative data object
2607 declarations, file-scope (extern) function declarations (which
2608 had no corresponding body) and file-scope tagged type declarations
2609 and definitions which have not yet been forced out. */
2611 if (write_symbols == DWARF2_DEBUG
2612 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2613 TIMEVAR (symout_time, dwarf2out_decl (decl));
2614 #endif
2618 /* Write out any pending weak symbol declarations. */
2620 weak_finish ();
2622 /* Do dbx symbols */
2623 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2624 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2625 TIMEVAR (symout_time,
2627 dbxout_finish (asm_out_file, main_input_filename);
2629 #endif
2631 #ifdef DWARF_DEBUGGING_INFO
2632 if (write_symbols == DWARF_DEBUG)
2633 TIMEVAR (symout_time,
2635 dwarfout_finish ();
2637 #endif
2639 #ifdef DWARF2_DEBUGGING_INFO
2640 if (write_symbols == DWARF2_DEBUG)
2641 TIMEVAR (symout_time,
2643 dwarf2out_finish ();
2645 #endif
2647 /* Output some stuff at end of file if nec. */
2649 if (!output_bytecode)
2651 end_final (dump_base_name);
2652 end_branch_prob (branch_prob_dump_file);
2654 #ifdef ASM_FILE_END
2655 ASM_FILE_END (asm_out_file);
2656 #endif
2659 /* Language-specific end of compilation actions. */
2661 lang_finish ();
2663 if (output_bytecode)
2664 bc_write_file (asm_out_file);
2666 /* Close the dump files. */
2668 if (flag_gen_aux_info)
2670 fclose (aux_info_file);
2671 if (errorcount)
2672 unlink (aux_info_file_name);
2675 if (rtl_dump)
2676 fclose (rtl_dump_file);
2678 if (jump_opt_dump)
2679 fclose (jump_opt_dump_file);
2681 if (addressof_dump)
2682 fclose (addressof_dump_file);
2684 if (cse_dump)
2685 fclose (cse_dump_file);
2687 if (loop_dump)
2688 fclose (loop_dump_file);
2690 if (cse2_dump)
2691 fclose (cse2_dump_file);
2693 if (branch_prob_dump)
2694 fclose (branch_prob_dump_file);
2696 if (flow_dump)
2697 fclose (flow_dump_file);
2699 if (combine_dump)
2701 dump_combine_total_stats (combine_dump_file);
2702 fclose (combine_dump_file);
2705 if (sched_dump)
2706 fclose (sched_dump_file);
2708 if (local_reg_dump)
2709 fclose (local_reg_dump_file);
2711 if (global_reg_dump)
2712 fclose (global_reg_dump_file);
2714 if (sched2_dump)
2715 fclose (sched2_dump_file);
2717 if (jump2_opt_dump)
2718 fclose (jump2_opt_dump_file);
2720 if (dbr_sched_dump)
2721 fclose (dbr_sched_dump_file);
2723 #ifdef STACK_REGS
2724 if (stack_reg_dump)
2725 fclose (stack_reg_dump_file);
2726 #endif
2728 /* Close non-debugging input and output files. Take special care to note
2729 whether fclose returns an error, since the pages might still be on the
2730 buffer chain while the file is open. */
2732 #if USE_CPPLIB
2733 finish_parse ();
2734 #else
2735 fclose (finput);
2736 #endif
2737 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
2738 fatal_io_error (asm_file_name);
2740 /* Print the times. */
2742 if (! quiet_flag)
2744 fprintf (stderr,"\n");
2745 print_time ("parse", parse_time);
2747 if (!output_bytecode)
2749 print_time ("integration", integration_time);
2750 print_time ("jump", jump_time);
2751 print_time ("cse", cse_time);
2752 print_time ("loop", loop_time);
2753 print_time ("cse2", cse2_time);
2754 print_time ("branch-prob", branch_prob_time);
2755 print_time ("flow", flow_time);
2756 print_time ("combine", combine_time);
2757 print_time ("sched", sched_time);
2758 print_time ("local-alloc", local_alloc_time);
2759 print_time ("global-alloc", global_alloc_time);
2760 print_time ("sched2", sched2_time);
2761 print_time ("dbranch", dbr_sched_time);
2762 print_time ("shorten-branch", shorten_branch_time);
2763 print_time ("stack-reg", stack_reg_time);
2764 print_time ("final", final_time);
2765 print_time ("varconst", varconst_time);
2766 print_time ("symout", symout_time);
2767 print_time ("dump", dump_time);
2772 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
2773 and TYPE_DECL nodes.
2775 This does nothing for local (non-static) variables.
2776 Otherwise, it sets up the RTL and outputs any assembler code
2777 (label definition, storage allocation and initialization).
2779 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2780 the assembler symbol name to be used. TOP_LEVEL is nonzero
2781 if this declaration is not within a function. */
2783 void
2784 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2785 tree decl;
2786 char *asmspec;
2787 int top_level;
2788 int at_end;
2790 /* Declarations of variables, and of functions defined elsewhere. */
2792 /* The most obvious approach, to put an #ifndef around where
2793 this macro is used, doesn't work since it's inside a macro call. */
2794 #ifndef ASM_FINISH_DECLARE_OBJECT
2795 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2796 #endif
2798 /* Forward declarations for nested functions are not "external",
2799 but we need to treat them as if they were. */
2800 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
2801 || TREE_CODE (decl) == FUNCTION_DECL)
2802 TIMEVAR (varconst_time,
2804 make_decl_rtl (decl, asmspec, top_level);
2805 /* Initialized extern variable exists to be replaced
2806 with its value, or represents something that will be
2807 output in another file. */
2808 if (! (TREE_CODE (decl) == VAR_DECL
2809 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
2810 && DECL_INITIAL (decl) != 0
2811 && DECL_INITIAL (decl) != error_mark_node))
2812 /* Don't output anything
2813 when a tentative file-scope definition is seen.
2814 But at end of compilation, do output code for them. */
2815 if (! (! at_end && top_level
2816 && (DECL_INITIAL (decl) == 0
2817 || DECL_INITIAL (decl) == error_mark_node)))
2818 assemble_variable (decl, top_level, at_end, 0);
2819 if (!output_bytecode
2820 && decl == last_assemble_variable_decl)
2822 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2823 top_level, at_end);
2826 else if (DECL_REGISTER (decl) && asmspec != 0)
2828 if (decode_reg_name (asmspec) >= 0)
2830 DECL_RTL (decl) = 0;
2831 make_decl_rtl (decl, asmspec, top_level);
2833 else
2834 error ("invalid register name `%s' for register variable", asmspec);
2836 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2837 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2838 && TREE_CODE (decl) == TYPE_DECL)
2839 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
2840 #endif
2841 #ifdef SDB_DEBUGGING_INFO
2842 else if (write_symbols == SDB_DEBUG && top_level
2843 && TREE_CODE (decl) == TYPE_DECL)
2844 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2845 #endif
2848 /* Called after finishing a record, union or enumeral type. */
2850 void
2851 rest_of_type_compilation (type, toplev)
2852 tree type;
2853 int toplev;
2855 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2856 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2857 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
2858 #endif
2859 #ifdef SDB_DEBUGGING_INFO
2860 if (write_symbols == SDB_DEBUG)
2861 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
2862 #endif
2865 /* This is called from finish_function (within yyparse)
2866 after each top-level definition is parsed.
2867 It is supposed to compile that function or variable
2868 and output the assembler code for it.
2869 After we return, the tree storage is freed. */
2871 void
2872 rest_of_compilation (decl)
2873 tree decl;
2875 register rtx insns;
2876 int start_time = get_run_time ();
2877 int tem;
2878 /* Nonzero if we have saved the original DECL_INITIAL of the function,
2879 to be restored after we finish compiling the function
2880 (for use when compiling inline calls to this function). */
2881 tree saved_block_tree = 0;
2882 /* Likewise, for DECL_ARGUMENTS. */
2883 tree saved_arguments = 0;
2884 int failure = 0;
2886 if (output_bytecode)
2887 return;
2889 /* If we are reconsidering an inline function
2890 at the end of compilation, skip the stuff for making it inline. */
2892 if (DECL_SAVED_INSNS (decl) == 0)
2894 int inlineable = 0;
2895 char *lose;
2897 /* If requested, consider whether to make this function inline. */
2898 if (DECL_INLINE (decl) || flag_inline_functions)
2899 TIMEVAR (integration_time,
2901 lose = function_cannot_inline_p (decl);
2902 if (lose || ! optimize)
2904 if (warn_inline && DECL_INLINE (decl))
2905 warning_with_decl (decl, lose);
2906 DECL_ABSTRACT_ORIGIN (decl) = 0;
2907 /* Don't really compile an extern inline function.
2908 If we can't make it inline, pretend
2909 it was only declared. */
2910 if (DECL_EXTERNAL (decl))
2912 DECL_INITIAL (decl) = 0;
2913 goto exit_rest_of_compilation;
2916 else
2917 /* ??? Note that this has the effect of making it look
2918 like "inline" was specified for a function if we choose
2919 to inline it. This isn't quite right, but it's
2920 probably not worth the trouble to fix. */
2921 inlineable = DECL_INLINE (decl) = 1;
2924 insns = get_insns ();
2926 /* Dump the rtl code if we are dumping rtl. */
2928 if (rtl_dump)
2929 TIMEVAR (dump_time,
2931 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2932 (*decl_printable_name) (decl, 2));
2933 if (DECL_SAVED_INSNS (decl))
2934 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2935 print_rtl (rtl_dump_file, insns);
2936 fflush (rtl_dump_file);
2939 /* If function is inline, and we don't yet know whether to
2940 compile it by itself, defer decision till end of compilation.
2941 finish_compilation will call rest_of_compilation again
2942 for those functions that need to be output. Also defer those
2943 functions that we are supposed to defer. We cannot defer
2944 functions containing nested functions since the nested function
2945 data is in our non-saved obstack. */
2947 /* If this is a nested inline, remove ADDRESSOF now so we can
2948 finish compiling ourselves. Otherwise, wait until EOF.
2949 We have to do this because the purge_addressof transformation
2950 changes the DECL_RTL for many variables, which confuses integrate. */
2951 if (DECL_INLINE (decl))
2953 if (decl_function_context (decl))
2954 purge_addressof (insns);
2955 else
2956 DECL_DEFER_OUTPUT (decl) = 1;
2959 if (! current_function_contains_functions
2960 && (DECL_DEFER_OUTPUT (decl)
2961 || (DECL_INLINE (decl)
2962 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2963 && ! flag_keep_inline_functions)
2964 || DECL_EXTERNAL (decl)))))
2966 DECL_DEFER_OUTPUT (decl) = 1;
2968 /* If -Wreturn-type, we have to do a bit of compilation. */
2969 if (! warn_return_type)
2971 #ifdef DWARF_DEBUGGING_INFO
2972 /* Generate the DWARF info for the "abstract" instance
2973 of a function which we may later generate inlined and/or
2974 out-of-line instances of. */
2975 if (write_symbols == DWARF_DEBUG)
2977 set_decl_abstract_flags (decl, 1);
2978 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2979 set_decl_abstract_flags (decl, 0);
2981 #endif
2982 #ifdef DWARF2_DEBUGGING_INFO
2983 /* Generate the DWARF2 info for the "abstract" instance
2984 of a function which we may later generate inlined and/or
2985 out-of-line instances of. */
2986 if (write_symbols == DWARF2_DEBUG)
2988 set_decl_abstract_flags (decl, 1);
2989 TIMEVAR (symout_time, dwarf2out_decl (decl));
2990 set_decl_abstract_flags (decl, 0);
2992 #endif
2993 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
2994 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
2995 goto exit_rest_of_compilation;
2999 /* If we have to compile the function now, save its rtl and subdecls
3000 so that its compilation will not affect what others get. */
3001 if (inlineable || DECL_DEFER_OUTPUT (decl))
3003 #ifdef DWARF_DEBUGGING_INFO
3004 /* Generate the DWARF info for the "abstract" instance of
3005 a function which we will generate an out-of-line instance
3006 of almost immediately (and which we may also later generate
3007 various inlined instances of). */
3008 if (write_symbols == DWARF_DEBUG)
3010 set_decl_abstract_flags (decl, 1);
3011 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3012 set_decl_abstract_flags (decl, 0);
3014 #endif
3015 #ifdef DWARF2_DEBUGGING_INFO
3016 /* Generate the DWARF2 info for the "abstract" instance of
3017 a function which we will generate an out-of-line instance
3018 of almost immediately (and which we may also later generate
3019 various inlined instances of). */
3020 if (write_symbols == DWARF2_DEBUG)
3022 set_decl_abstract_flags (decl, 1);
3023 TIMEVAR (symout_time, dwarf2out_decl (decl));
3024 set_decl_abstract_flags (decl, 0);
3026 #endif
3027 saved_block_tree = DECL_INITIAL (decl);
3028 saved_arguments = DECL_ARGUMENTS (decl);
3029 TIMEVAR (integration_time, save_for_inline_copying (decl));
3030 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlineable;
3033 /* If specified extern inline but we aren't inlining it, we are
3034 done. */
3035 if (DECL_INLINE (decl) && DECL_EXTERNAL (decl))
3036 goto exit_rest_of_compilation;
3039 if (! DECL_DEFER_OUTPUT (decl))
3040 TREE_ASM_WRITTEN (decl) = 1;
3042 /* Now that integrate will no longer see our rtl, we need not distinguish
3043 between the return value of this function and the return value of called
3044 functions. */
3045 rtx_equal_function_value_matters = 0;
3047 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3048 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3050 goto exit_rest_of_compilation;
3053 /* Add an unwinder for exception handling, if needed.
3054 This must be done before we finalize PIC code. */
3055 emit_unwinder ();
3057 #ifdef FINALIZE_PIC
3058 /* If we are doing position-independent code generation, now
3059 is the time to output special prologues and epilogues.
3060 We do not want to do this earlier, because it just clutters
3061 up inline functions with meaningless insns. */
3062 if (flag_pic)
3063 FINALIZE_PIC;
3064 #endif
3066 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3067 Note that that may have been done above, in save_for_inline_copying.
3068 The call to resume_temporary_allocation near the end of this function
3069 goes back to the usual state of affairs. This must be done after
3070 we've built up any unwinders for exception handling, and done
3071 the FINALIZE_PIC work, if necessary. */
3073 rtl_in_current_obstack ();
3075 insns = get_insns ();
3077 /* Copy any shared structure that should not be shared. */
3079 unshare_all_rtl (insns);
3081 /* Instantiate all virtual registers. */
3083 instantiate_virtual_regs (current_function_decl, get_insns ());
3085 /* See if we have allocated stack slots that are not directly addressable.
3086 If so, scan all the insns and create explicit address computation
3087 for all references to such slots. */
3088 /* fixup_stack_slots (); */
3090 /* Find all the EH handlers. */
3091 find_exception_handler_labels ();
3093 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3094 are initialized and to compute whether control can drop off the end
3095 of the function. */
3096 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3097 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
3099 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3100 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3101 goto exit_rest_of_compilation;
3103 /* Dump rtl code after jump, if we are doing that. */
3105 if (jump_opt_dump)
3106 TIMEVAR (dump_time,
3108 fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
3109 (*decl_printable_name) (decl, 2));
3110 print_rtl (jump_opt_dump_file, insns);
3111 fflush (jump_opt_dump_file);
3114 /* Perform common subexpression elimination.
3115 Nonzero value from `cse_main' means that jumps were simplified
3116 and some code may now be unreachable, so do
3117 jump optimization again. */
3119 if (cse_dump)
3120 TIMEVAR (dump_time,
3122 fprintf (cse_dump_file, "\n;; Function %s\n\n",
3123 (*decl_printable_name) (decl, 2));
3126 if (optimize > 0)
3128 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3130 if (flag_thread_jumps)
3131 /* Hacks by tiemann & kenner. */
3132 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3134 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3135 0, cse_dump_file));
3136 TIMEVAR (cse_time, delete_dead_from_cse (insns, max_reg_num ()));
3138 if (tem || optimize > 1)
3139 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3142 /* Dump rtl code after cse, if we are doing that. */
3144 if (cse_dump)
3145 TIMEVAR (dump_time,
3147 print_rtl (cse_dump_file, insns);
3148 fflush (cse_dump_file);
3151 purge_addressof (insns);
3152 reg_scan (insns, max_reg_num (), 1);
3154 if (addressof_dump)
3155 TIMEVAR (dump_time,
3157 fprintf (addressof_dump_file, "\n;; Function %s\n\n",
3158 (*decl_printable_name) (decl, 2));
3159 print_rtl (addressof_dump_file, insns);
3160 fflush (addressof_dump_file);
3163 if (loop_dump)
3164 TIMEVAR (dump_time,
3166 fprintf (loop_dump_file, "\n;; Function %s\n\n",
3167 (*decl_printable_name) (decl, 2));
3170 /* Move constant computations out of loops. */
3172 if (optimize > 0)
3174 TIMEVAR (loop_time,
3176 loop_optimize (insns, loop_dump_file);
3180 /* Dump rtl code after loop opt, if we are doing that. */
3182 if (loop_dump)
3183 TIMEVAR (dump_time,
3185 print_rtl (loop_dump_file, insns);
3186 fflush (loop_dump_file);
3189 if (cse2_dump)
3190 TIMEVAR (dump_time,
3192 fprintf (cse2_dump_file, "\n;; Function %s\n\n",
3193 (*decl_printable_name) (decl, 2));
3196 if (optimize > 0 && flag_rerun_cse_after_loop)
3198 /* Running another jump optimization pass before the second
3199 cse pass sometimes simplifies the RTL enough to allow
3200 the second CSE pass to do a better job. Jump_optimize can change
3201 max_reg_num so we must rerun reg_scan afterwards.
3202 ??? Rework to not call reg_scan so often. */
3203 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3204 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
3206 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
3207 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3208 1, cse2_dump_file));
3209 if (tem)
3210 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3213 if (optimize > 0 && flag_thread_jumps)
3215 /* This pass of jump threading straightens out code
3216 that was kinked by loop optimization. */
3217 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3218 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3220 /* Dump rtl code after cse, if we are doing that. */
3222 if (cse2_dump)
3223 TIMEVAR (dump_time,
3225 print_rtl (cse2_dump_file, insns);
3226 fflush (cse2_dump_file);
3229 if (branch_prob_dump)
3230 TIMEVAR (dump_time,
3232 fprintf (branch_prob_dump_file, "\n;; Function %s\n\n",
3233 (*decl_printable_name) (decl, 2));
3236 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3237 TIMEVAR (branch_prob_time,
3239 branch_prob (insns, branch_prob_dump_file);
3242 if (branch_prob_dump)
3243 TIMEVAR (dump_time,
3245 print_rtl (branch_prob_dump_file, insns);
3246 fflush (branch_prob_dump_file);
3248 /* We are no longer anticipating cse in this function, at least. */
3250 cse_not_expected = 1;
3252 /* Now we choose between stupid (pcc-like) register allocation
3253 (if we got the -noreg switch and not -opt)
3254 and smart register allocation. */
3256 if (optimize > 0) /* Stupid allocation probably won't work */
3257 obey_regdecls = 0; /* if optimizations being done. */
3259 regclass_init ();
3261 /* Print function header into flow dump now
3262 because doing the flow analysis makes some of the dump. */
3264 if (flow_dump)
3265 TIMEVAR (dump_time,
3267 fprintf (flow_dump_file, "\n;; Function %s\n\n",
3268 (*decl_printable_name) (decl, 2));
3271 if (obey_regdecls)
3273 TIMEVAR (flow_time,
3275 regclass (insns, max_reg_num ());
3276 stupid_life_analysis (insns, max_reg_num (),
3277 flow_dump_file);
3280 else
3282 /* Do control and data flow analysis,
3283 and write some of the results to dump file. */
3285 TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
3286 flow_dump_file));
3287 if (warn_uninitialized)
3289 uninitialized_vars_warning (DECL_INITIAL (decl));
3290 setjmp_args_warning ();
3294 /* Dump rtl after flow analysis. */
3296 if (flow_dump)
3297 TIMEVAR (dump_time,
3299 print_rtl (flow_dump_file, insns);
3300 fflush (flow_dump_file);
3303 /* If -opt, try combining insns through substitution. */
3305 if (optimize > 0)
3306 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
3308 /* Dump rtl code after insn combination. */
3310 if (combine_dump)
3311 TIMEVAR (dump_time,
3313 fprintf (combine_dump_file, "\n;; Function %s\n\n",
3314 (*decl_printable_name) (decl, 2));
3315 dump_combine_stats (combine_dump_file);
3316 print_rtl (combine_dump_file, insns);
3317 fflush (combine_dump_file);
3320 /* Print function header into sched dump now
3321 because doing the sched analysis makes some of the dump. */
3323 if (sched_dump)
3324 TIMEVAR (dump_time,
3326 fprintf (sched_dump_file, "\n;; Function %s\n\n",
3327 (*decl_printable_name) (decl, 2));
3330 if (optimize > 0 && flag_schedule_insns)
3332 /* Do control and data sched analysis,
3333 and write some of the results to dump file. */
3335 TIMEVAR (sched_time, schedule_insns (sched_dump_file));
3338 /* Dump rtl after instruction scheduling. */
3340 if (sched_dump)
3341 TIMEVAR (dump_time,
3343 print_rtl (sched_dump_file, insns);
3344 fflush (sched_dump_file);
3347 /* Unless we did stupid register allocation,
3348 allocate pseudo-regs that are used only within 1 basic block. */
3350 if (!obey_regdecls)
3351 TIMEVAR (local_alloc_time,
3353 regclass (insns, max_reg_num ());
3354 local_alloc ();
3357 /* Dump rtl code after allocating regs within basic blocks. */
3359 if (local_reg_dump)
3360 TIMEVAR (dump_time,
3362 fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
3363 (*decl_printable_name) (decl, 2));
3364 dump_flow_info (local_reg_dump_file);
3365 dump_local_alloc (local_reg_dump_file);
3366 print_rtl (local_reg_dump_file, insns);
3367 fflush (local_reg_dump_file);
3370 if (global_reg_dump)
3371 TIMEVAR (dump_time,
3372 fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
3373 (*decl_printable_name) (decl, 2)));
3375 /* Save the last label number used so far, so reorg can tell
3376 when it's safe to kill spill regs. */
3377 max_label_num_after_reload = max_label_num ();
3379 /* Unless we did stupid register allocation,
3380 allocate remaining pseudo-regs, then do the reload pass
3381 fixing up any insns that are invalid. */
3383 TIMEVAR (global_alloc_time,
3385 if (!obey_regdecls)
3386 failure = global_alloc (global_reg_dump_file);
3387 else
3388 failure = reload (insns, 0, global_reg_dump_file);
3391 if (global_reg_dump)
3392 TIMEVAR (dump_time,
3394 dump_global_regs (global_reg_dump_file);
3395 print_rtl (global_reg_dump_file, insns);
3396 fflush (global_reg_dump_file);
3399 if (failure)
3400 goto exit_rest_of_compilation;
3402 reload_completed = 1;
3404 /* Do a very simple CSE pass over just the hard registers. */
3405 if (optimize > 0)
3406 reload_cse_regs (insns);
3408 /* On some machines, the prologue and epilogue code, or parts thereof,
3409 can be represented as RTL. Doing so lets us schedule insns between
3410 it and the rest of the code and also allows delayed branch
3411 scheduling to operate in the epilogue. */
3413 thread_prologue_and_epilogue_insns (insns);
3415 if (optimize > 0 && flag_schedule_insns_after_reload)
3417 if (sched2_dump)
3418 TIMEVAR (dump_time,
3420 fprintf (sched2_dump_file, "\n;; Function %s\n\n",
3421 (*decl_printable_name) (decl, 2));
3424 /* Do control and data sched analysis again,
3425 and write some more of the results to dump file. */
3427 TIMEVAR (sched2_time, schedule_insns (sched2_dump_file));
3429 /* Dump rtl after post-reorder instruction scheduling. */
3431 if (sched2_dump)
3432 TIMEVAR (dump_time,
3434 print_rtl (sched2_dump_file, insns);
3435 fflush (sched2_dump_file);
3439 #ifdef LEAF_REGISTERS
3440 leaf_function = 0;
3441 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
3442 leaf_function = 1;
3443 #endif
3445 /* One more attempt to remove jumps to .+1
3446 left by dead-store-elimination.
3447 Also do cross-jumping this time
3448 and delete no-op move insns. */
3450 if (optimize > 0)
3452 TIMEVAR (jump_time, jump_optimize (insns, 1, 1, 0));
3455 /* Dump rtl code after jump, if we are doing that. */
3457 if (jump2_opt_dump)
3458 TIMEVAR (dump_time,
3460 fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
3461 (*decl_printable_name) (decl, 2));
3462 print_rtl (jump2_opt_dump_file, insns);
3463 fflush (jump2_opt_dump_file);
3466 /* If a machine dependent reorganization is needed, call it. */
3467 #ifdef MACHINE_DEPENDENT_REORG
3468 MACHINE_DEPENDENT_REORG (insns);
3469 #endif
3471 /* If a scheduling pass for delayed branches is to be done,
3472 call the scheduling code. */
3474 #ifdef DELAY_SLOTS
3475 if (optimize > 0 && flag_delayed_branch)
3477 TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
3478 if (dbr_sched_dump)
3480 TIMEVAR (dump_time,
3482 fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
3483 (*decl_printable_name) (decl, 2));
3484 print_rtl (dbr_sched_dump_file, insns);
3485 fflush (dbr_sched_dump_file);
3489 #endif
3491 /* Shorten branches. */
3492 TIMEVAR (shorten_branch_time,
3494 shorten_branches (get_insns ());
3497 #ifdef STACK_REGS
3498 TIMEVAR (stack_reg_time, reg_to_stack (insns, stack_reg_dump_file));
3499 if (stack_reg_dump)
3501 TIMEVAR (dump_time,
3503 fprintf (stack_reg_dump_file, "\n;; Function %s\n\n",
3504 (*decl_printable_name) (decl, 2));
3505 print_rtl (stack_reg_dump_file, insns);
3506 fflush (stack_reg_dump_file);
3509 #endif
3511 /* Now turn the rtl into assembler code. */
3513 TIMEVAR (final_time,
3515 rtx x;
3516 char *fnname;
3518 /* Get the function's name, as described by its RTL.
3519 This may be different from the DECL_NAME name used
3520 in the source file. */
3522 x = DECL_RTL (decl);
3523 if (GET_CODE (x) != MEM)
3524 abort ();
3525 x = XEXP (x, 0);
3526 if (GET_CODE (x) != SYMBOL_REF)
3527 abort ();
3528 fnname = XSTR (x, 0);
3530 assemble_start_function (decl, fnname);
3531 final_start_function (insns, asm_out_file, optimize);
3532 final (insns, asm_out_file, optimize, 0);
3533 final_end_function (insns, asm_out_file, optimize);
3534 assemble_end_function (decl, fnname);
3535 fflush (asm_out_file);
3537 /* Release all memory held by regsets now */
3538 regset_release_memory ();
3541 /* Write DBX symbols if requested */
3543 /* Note that for those inline functions where we don't initially
3544 know for certain that we will be generating an out-of-line copy,
3545 the first invocation of this routine (rest_of_compilation) will
3546 skip over this code by doing a `goto exit_rest_of_compilation;'.
3547 Later on, finish_compilation will call rest_of_compilation again
3548 for those inline functions that need to have out-of-line copies
3549 generated. During that call, we *will* be routed past here. */
3551 #ifdef DBX_DEBUGGING_INFO
3552 if (write_symbols == DBX_DEBUG)
3553 TIMEVAR (symout_time, dbxout_function (decl));
3554 #endif
3556 #ifdef DWARF_DEBUGGING_INFO
3557 if (write_symbols == DWARF_DEBUG)
3558 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3559 #endif
3561 #ifdef DWARF2_DEBUGGING_INFO
3562 if (write_symbols == DWARF2_DEBUG)
3563 TIMEVAR (symout_time, dwarf2out_decl (decl));
3564 #endif
3566 exit_rest_of_compilation:
3568 /* In case the function was not output,
3569 don't leave any temporary anonymous types
3570 queued up for sdb output. */
3571 #ifdef SDB_DEBUGGING_INFO
3572 if (write_symbols == SDB_DEBUG)
3573 sdbout_types (NULL_TREE);
3574 #endif
3576 /* Put back the tree of subblocks and list of arguments
3577 from before we copied them.
3578 Code generation and the output of debugging info may have modified
3579 the copy, but the original is unchanged. */
3581 if (saved_block_tree != 0)
3583 DECL_INITIAL (decl) = saved_block_tree;
3584 DECL_ARGUMENTS (decl) = saved_arguments;
3585 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
3588 reload_completed = 0;
3590 /* Clear out the insn_length contents now that they are no longer valid. */
3591 init_insn_lengths ();
3593 /* Clear out the real_constant_chain before some of the rtx's
3594 it runs through become garbage. */
3596 clear_const_double_mem ();
3598 /* Cancel the effect of rtl_in_current_obstack. */
3600 resume_temporary_allocation ();
3602 /* Show no temporary slots allocated. */
3604 init_temp_slots ();
3606 /* The parsing time is all the time spent in yyparse
3607 *except* what is spent in this function. */
3609 parse_time -= get_run_time () - start_time;
3612 /* Entry point of cc1/c++. Decode command args, then call compile_file.
3613 Exit code is 35 if can't open files, 34 if fatal error,
3614 33 if had nonfatal errors, else success. */
3617 main (argc, argv, envp)
3618 int argc;
3619 char **argv;
3620 char **envp;
3622 register int i;
3623 char *filename = 0;
3624 int flag_print_mem = 0;
3625 int version_flag = 0;
3626 char *p;
3628 /* save in case md file wants to emit args as a comment. */
3629 save_argc = argc;
3630 save_argv = argv;
3632 p = argv[0] + strlen (argv[0]);
3633 while (p != argv[0] && p[-1] != '/'
3634 #ifdef DIR_SEPARATOR
3635 && p[-1] != DIR_SEPARATOR
3636 #endif
3638 --p;
3639 progname = p;
3641 #ifdef RLIMIT_STACK
3642 /* Get rid of any avoidable limit on stack size. */
3644 struct rlimit rlim;
3646 /* Set the stack limit huge so that alloca does not fail. */
3647 getrlimit (RLIMIT_STACK, &rlim);
3648 rlim.rlim_cur = rlim.rlim_max;
3649 setrlimit (RLIMIT_STACK, &rlim);
3651 #endif /* RLIMIT_STACK */
3653 signal (SIGFPE, float_signal);
3655 #ifdef SIGPIPE
3656 signal (SIGPIPE, pipe_closed);
3657 #endif
3659 decl_printable_name = decl_name;
3660 lang_expand_expr = (struct rtx_def *(*)()) do_abort;
3662 /* Initialize whether `char' is signed. */
3663 flag_signed_char = DEFAULT_SIGNED_CHAR;
3664 #ifdef DEFAULT_SHORT_ENUMS
3665 /* Initialize how much space enums occupy, by default. */
3666 flag_short_enums = DEFAULT_SHORT_ENUMS;
3667 #endif
3669 /* Scan to see what optimization level has been specified. That will
3670 determine the default value of many flags. */
3671 for (i = 1; i < argc; i++)
3673 if (!strcmp (argv[i], "-O"))
3675 optimize = 1;
3677 else if (argv[i][0] == '-' && argv[i][1] == 'O')
3679 /* Handle -O2, -O3, -O69, ... */
3680 char *p = &argv[i][2];
3681 int c;
3683 while (c = *p++)
3684 if (! (c >= '0' && c <= '9'))
3685 break;
3686 if (c == 0)
3687 optimize = atoi (&argv[i][2]);
3691 obey_regdecls = (optimize == 0);
3693 if (optimize >= 1)
3695 flag_defer_pop = 1;
3696 flag_thread_jumps = 1;
3697 #ifdef DELAY_SLOTS
3698 flag_delayed_branch = 1;
3699 #endif
3700 #ifdef CAN_DEBUG_WITHOUT_FP
3701 flag_omit_frame_pointer = 1;
3702 #endif
3705 if (optimize >= 2)
3707 flag_cse_follow_jumps = 1;
3708 flag_cse_skip_blocks = 1;
3709 flag_expensive_optimizations = 1;
3710 flag_strength_reduce = 1;
3711 flag_rerun_cse_after_loop = 1;
3712 flag_caller_saves = 1;
3713 flag_force_mem = 1;
3714 #ifdef INSN_SCHEDULING
3715 flag_schedule_insns = 1;
3716 flag_schedule_insns_after_reload = 1;
3717 #endif
3720 if (optimize >= 3)
3722 flag_inline_functions = 1;
3725 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
3726 modify it. */
3727 target_flags = 0;
3728 set_target_switch ("");
3730 #ifdef OPTIMIZATION_OPTIONS
3731 /* Allow default optimizations to be specified on a per-machine basis. */
3732 OPTIMIZATION_OPTIONS (optimize);
3733 #endif
3735 /* Initialize register usage now so switches may override. */
3736 init_reg_sets ();
3738 for (i = 1; i < argc; i++)
3740 int j;
3741 /* If this is a language-specific option,
3742 decode it in a language-specific way. */
3743 for (j = 0; lang_options[j] != 0; j++)
3744 if (!strncmp (argv[i], lang_options[j],
3745 strlen (lang_options[j])))
3746 break;
3747 if (lang_options[j] != 0)
3748 /* If the option is valid for *some* language,
3749 treat it as valid even if this language doesn't understand it. */
3750 lang_decode_option (argv[i]);
3751 else if (argv[i][0] == '-' && argv[i][1] != 0)
3753 register char *str = argv[i] + 1;
3754 if (str[0] == 'Y')
3755 str++;
3757 if (str[0] == 'm')
3758 set_target_switch (&str[1]);
3759 else if (!strcmp (str, "dumpbase"))
3761 dump_base_name = argv[++i];
3763 else if (str[0] == 'd')
3765 register char *p = &str[1];
3766 while (*p)
3767 switch (*p++)
3769 case 'a':
3770 branch_prob_dump = 1;
3771 combine_dump = 1;
3772 dbr_sched_dump = 1;
3773 flow_dump = 1;
3774 global_reg_dump = 1;
3775 jump_opt_dump = 1;
3776 addressof_dump = 1;
3777 jump2_opt_dump = 1;
3778 local_reg_dump = 1;
3779 loop_dump = 1;
3780 rtl_dump = 1;
3781 cse_dump = 1, cse2_dump = 1;
3782 sched_dump = 1;
3783 sched2_dump = 1;
3784 stack_reg_dump = 1;
3785 break;
3786 case 'b':
3787 branch_prob_dump = 1;
3788 break;
3789 case 'k':
3790 stack_reg_dump = 1;
3791 break;
3792 case 'c':
3793 combine_dump = 1;
3794 break;
3795 case 'd':
3796 dbr_sched_dump = 1;
3797 break;
3798 case 'f':
3799 flow_dump = 1;
3800 break;
3801 case 'g':
3802 global_reg_dump = 1;
3803 break;
3804 case 'j':
3805 jump_opt_dump = 1;
3806 break;
3807 case 'D':
3808 addressof_dump = 1;
3809 break;
3810 case 'J':
3811 jump2_opt_dump = 1;
3812 break;
3813 case 'l':
3814 local_reg_dump = 1;
3815 break;
3816 case 'L':
3817 loop_dump = 1;
3818 break;
3819 case 'm':
3820 flag_print_mem = 1;
3821 break;
3822 case 'p':
3823 flag_print_asm_name = 1;
3824 break;
3825 case 'r':
3826 rtl_dump = 1;
3827 break;
3828 case 's':
3829 cse_dump = 1;
3830 break;
3831 case 't':
3832 cse2_dump = 1;
3833 break;
3834 case 'S':
3835 sched_dump = 1;
3836 break;
3837 case 'R':
3838 sched2_dump = 1;
3839 break;
3840 case 'y':
3841 set_yydebug (1);
3842 break;
3843 case 'x':
3844 rtl_dump_and_exit = 1;
3845 break;
3846 case 'A':
3847 flag_debug_asm = 1;
3848 break;
3851 else if (str[0] == 'f')
3853 register char *p = &str[1];
3854 int found = 0;
3856 /* Some kind of -f option.
3857 P's value is the option sans `-f'.
3858 Search for it in the table of options. */
3860 for (j = 0;
3861 !found && j < sizeof (f_options) / sizeof (f_options[0]);
3862 j++)
3864 if (!strcmp (p, f_options[j].string))
3866 *f_options[j].variable = f_options[j].on_value;
3867 /* A goto here would be cleaner,
3868 but breaks the vax pcc. */
3869 found = 1;
3871 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3872 && ! strcmp (p+3, f_options[j].string))
3874 *f_options[j].variable = ! f_options[j].on_value;
3875 found = 1;
3879 if (found)
3881 else if (!strncmp (p, "fixed-", 6))
3882 fix_register (&p[6], 1, 1);
3883 else if (!strncmp (p, "call-used-", 10))
3884 fix_register (&p[10], 0, 1);
3885 else if (!strncmp (p, "call-saved-", 11))
3886 fix_register (&p[11], 0, 0);
3887 else
3888 error ("Invalid option `%s'", argv[i]);
3890 else if (str[0] == 'O')
3892 register char *p = str+1;
3893 while (*p && *p >= '0' && *p <= '9')
3894 p++;
3895 if (*p == '\0')
3897 else
3898 error ("Invalid option `%s'", argv[i]);
3900 else if (!strcmp (str, "pedantic"))
3901 pedantic = 1;
3902 else if (!strcmp (str, "pedantic-errors"))
3903 flag_pedantic_errors = pedantic = 1;
3904 else if (!strcmp (str, "quiet"))
3905 quiet_flag = 1;
3906 else if (!strcmp (str, "version"))
3907 version_flag = 1;
3908 else if (!strcmp (str, "w"))
3909 inhibit_warnings = 1;
3910 else if (!strcmp (str, "W"))
3912 extra_warnings = 1;
3913 /* We save the value of warn_uninitialized, since if they put
3914 -Wuninitialized on the command line, we need to generate a
3915 warning about not using it without also specifying -O. */
3916 if (warn_uninitialized != 1)
3917 warn_uninitialized = 2;
3919 else if (str[0] == 'W')
3921 register char *p = &str[1];
3922 int found = 0;
3924 /* Some kind of -W option.
3925 P's value is the option sans `-W'.
3926 Search for it in the table of options. */
3928 for (j = 0;
3929 !found && j < sizeof (W_options) / sizeof (W_options[0]);
3930 j++)
3932 if (!strcmp (p, W_options[j].string))
3934 *W_options[j].variable = W_options[j].on_value;
3935 /* A goto here would be cleaner,
3936 but breaks the vax pcc. */
3937 found = 1;
3939 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
3940 && ! strcmp (p+3, W_options[j].string))
3942 *W_options[j].variable = ! W_options[j].on_value;
3943 found = 1;
3947 if (found)
3949 else if (!strncmp (p, "id-clash-", 9))
3951 char *endp = p + 9;
3953 while (*endp)
3955 if (*endp >= '0' && *endp <= '9')
3956 endp++;
3957 else
3959 error ("Invalid option `%s'", argv[i]);
3960 goto id_clash_lose;
3963 warn_id_clash = 1;
3964 id_clash_len = atoi (str + 10);
3965 id_clash_lose: ;
3967 else if (!strncmp (p, "larger-than-", 12))
3969 char *endp = p + 12;
3971 while (*endp)
3973 if (*endp >= '0' && *endp <= '9')
3974 endp++;
3975 else
3977 error ("Invalid option `%s'", argv[i]);
3978 goto larger_than_lose;
3981 warn_larger_than = 1;
3982 larger_than_size = atoi (str + 13);
3983 larger_than_lose: ;
3985 else
3986 error ("Invalid option `%s'", argv[i]);
3988 else if (!strcmp (str, "p"))
3990 profile_flag = 1;
3992 else if (!strcmp (str, "a"))
3994 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
3995 warning ("`-a' option (basic block profile) not supported");
3996 #else
3997 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
3998 #endif
4000 else if (!strcmp (str, "ax"))
4002 #if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4003 warning ("`-ax' option (jump profiling) not supported");
4004 #else
4005 profile_block_flag = (!profile_block_flag
4006 || profile_block_flag == 2) ? 2 : 3;
4007 #endif
4009 else if (str[0] == 'g')
4011 unsigned len;
4012 unsigned level;
4013 /* A lot of code assumes write_symbols == NO_DEBUG if the
4014 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4015 of what debugging type has been selected). This records the
4016 selected type. It is an error to specify more than one
4017 debugging type. */
4018 static enum debug_info_type selected_debug_type = NO_DEBUG;
4019 /* Non-zero if debugging format has been explicitly set.
4020 -g and -ggdb don't explicitly set the debugging format so
4021 -gdwarf -g3 is equivalent to -gdwarf3. */
4022 static int type_explicitly_set_p = 0;
4023 /* Table of supported debugging formats. */
4024 static struct {
4025 char *arg;
4026 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
4027 constant expression, we use NO_DEBUG in its place. */
4028 enum debug_info_type debug_type;
4029 int use_extensions_p;
4030 } *da, debug_args[] = {
4031 { "g", NO_DEBUG, DEFAULT_GDB_EXTENSIONS },
4032 { "ggdb", NO_DEBUG, 1 },
4033 #ifdef DBX_DEBUGGING_INFO
4034 { "gstabs", DBX_DEBUG, 0 },
4035 { "gstabs+", DBX_DEBUG, 1 },
4036 #endif
4037 #ifdef DWARF_DEBUGGING_INFO
4038 { "gdwarf", DWARF_DEBUG, 0 },
4039 { "gdwarf+", DWARF_DEBUG, 1 },
4040 #endif
4041 #ifdef DWARF2_DEBUGGING_INFO
4042 { "gdwarf-2", DWARF2_DEBUG, 0 },
4043 #endif
4044 #ifdef XCOFF_DEBUGGING_INFO
4045 { "gxcoff", XCOFF_DEBUG, 0 },
4046 { "gxcoff+", XCOFF_DEBUG, 1 },
4047 #endif
4048 #ifdef SDB_DEBUGGING_INFO
4049 { "gcoff", SDB_DEBUG, 0 },
4050 #endif
4051 { 0, 0, 0 }
4053 /* Indexed by enum debug_info_type. */
4054 static char *debug_type_names[] = {
4055 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
4058 /* Look up STR in the table. */
4059 for (da = debug_args; da->arg; da++)
4061 if (! strncmp (str, da->arg, strlen (da->arg)))
4063 enum debug_info_type type = da->debug_type;
4064 char *p, *q;
4066 p = str + strlen (da->arg);
4067 if (*p && (*p < '0' || *p > '9'))
4068 continue;
4069 q = p;
4070 while (*q && (*q >= '0' && *q <= '9'))
4071 q++;
4072 if (*p)
4073 level = atoi (p);
4074 else
4075 level = 2; /* default debugging info level */
4076 if (*q || level > 3)
4078 warning ("invalid debug level specification in option: `-%s'",
4079 str);
4080 /* ??? This error message is incorrect in the case of
4081 -g4 -g. */
4082 warning ("no debugging information will be generated");
4083 level = 0;
4086 if (type == NO_DEBUG)
4088 type = PREFERRED_DEBUGGING_TYPE;
4089 if (len > 1 && strncmp (str, "ggdb", len) == 0)
4091 #ifdef DWARF2_DEBUGGING_INFO
4092 type = DWARF2_DEBUG;
4093 #elif defined DBX_DEBUGGING_INFO
4094 type = DBX_DEBUG;
4095 #endif
4099 if (type == NO_DEBUG)
4100 warning ("`-%s' not supported by this configuration of GCC",
4101 str);
4103 /* Does it conflict with an already selected type? */
4104 if (type_explicitly_set_p
4105 /* -g/-ggdb don't conflict with anything */
4106 && da->debug_type != NO_DEBUG
4107 && type != selected_debug_type)
4108 warning ("`-%s' ignored, conflicts with `-g%s'",
4109 str, debug_type_names[(int) selected_debug_type]);
4110 else
4112 /* If the format has already been set, -g/-ggdb
4113 only change the debug level. */
4114 if (type_explicitly_set_p
4115 && da->debug_type == NO_DEBUG)
4116 ; /* don't change debugging type */
4117 else
4119 selected_debug_type = type;
4120 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4122 write_symbols = (level == 0
4123 ? NO_DEBUG
4124 : selected_debug_type);
4125 use_gnu_debug_info_extensions = da->use_extensions_p;
4126 debug_info_level = (enum debug_info_level) level;
4128 break;
4131 if (! da->arg)
4132 warning ("`-%s' not supported by this configuration of GCC",
4133 str);
4135 else if (!strcmp (str, "o"))
4137 asm_file_name = argv[++i];
4139 else if (str[0] == 'G')
4141 g_switch_set = TRUE;
4142 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
4144 else if (!strncmp (str, "aux-info", 8))
4146 flag_gen_aux_info = 1;
4147 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
4149 else
4150 error ("Invalid option `%s'", argv[i]);
4152 else if (argv[i][0] == '+')
4153 error ("Invalid option `%s'", argv[i]);
4154 else
4155 filename = argv[i];
4158 /* Initialize for bytecode output. A good idea to do this as soon as
4159 possible after the "-f" options have been parsed. */
4160 if (output_bytecode)
4162 #ifndef TARGET_SUPPORTS_BYTECODE
4163 /* Just die with a fatal error if not supported */
4164 fatal ("-fbytecode not supported for this target");
4165 #else
4166 bc_initialize ();
4167 #endif
4170 if (optimize == 0)
4172 /* Inlining does not work if not optimizing,
4173 so force it not to be done. */
4174 flag_no_inline = 1;
4175 warn_inline = 0;
4177 /* The c_decode_option and lang_decode_option functions set
4178 this to `2' if -Wall is used, so we can avoid giving out
4179 lots of errors for people who don't realize what -Wall does. */
4180 if (warn_uninitialized == 1)
4181 warning ("-Wuninitialized is not supported without -O");
4184 #ifdef OVERRIDE_OPTIONS
4185 /* Some machines may reject certain combinations of options. */
4186 OVERRIDE_OPTIONS;
4187 #endif
4189 if (profile_block_flag == 3)
4191 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
4192 profile_block_flag = 2;
4195 /* Unrolling all loops implies that standard loop unrolling must also
4196 be done. */
4197 if (flag_unroll_all_loops)
4198 flag_unroll_loops = 1;
4199 /* Loop unrolling requires that strength_reduction be on also. Silently
4200 turn on strength reduction here if it isn't already on. Also, the loop
4201 unrolling code assumes that cse will be run after loop, so that must
4202 be turned on also. */
4203 if (flag_unroll_loops)
4205 flag_strength_reduce = 1;
4206 flag_rerun_cse_after_loop = 1;
4209 /* Warn about options that are not supported on this machine. */
4210 #ifndef INSN_SCHEDULING
4211 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4212 warning ("instruction scheduling not supported on this target machine");
4213 #endif
4214 #ifndef DELAY_SLOTS
4215 if (flag_delayed_branch)
4216 warning ("this target machine does not have delayed branches");
4217 #endif
4219 /* If we are in verbose mode, write out the version and maybe all the
4220 option flags in use. */
4221 if (version_flag)
4223 print_version (stderr, "");
4224 if (! quiet_flag)
4225 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4228 compile_file (filename);
4230 #if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN32__))
4231 if (flag_print_mem)
4233 char *lim = (char *) sbrk (0);
4235 fprintf (stderr, "Data size %d.\n",
4236 lim - (char *) &environ);
4237 fflush (stderr);
4239 #ifdef USG
4240 system ("ps -l 1>&2");
4241 #else /* not USG */
4242 system ("ps v");
4243 #endif /* not USG */
4245 #endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN32) */
4247 if (errorcount)
4248 exit (FATAL_EXIT_CODE);
4249 if (sorrycount)
4250 exit (FATAL_EXIT_CODE);
4251 exit (SUCCESS_EXIT_CODE);
4252 return 0;
4255 /* Decode -m switches. */
4257 /* Here is a table, controlled by the tm.h file, listing each -m switch
4258 and which bits in `target_switches' it should set or clear.
4259 If VALUE is positive, it is bits to set.
4260 If VALUE is negative, -VALUE is bits to clear.
4261 (The sign bit is not used so there is no confusion.) */
4263 struct {char *name; int value;} target_switches []
4264 = TARGET_SWITCHES;
4266 /* This table is similar, but allows the switch to have a value. */
4268 #ifdef TARGET_OPTIONS
4269 struct {char *prefix; char ** variable;} target_options []
4270 = TARGET_OPTIONS;
4271 #endif
4273 /* Decode the switch -mNAME. */
4275 void
4276 set_target_switch (name)
4277 char *name;
4279 register int j;
4280 int valid = 0;
4282 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4283 if (!strcmp (target_switches[j].name, name))
4285 if (target_switches[j].value < 0)
4286 target_flags &= ~-target_switches[j].value;
4287 else
4288 target_flags |= target_switches[j].value;
4289 valid = 1;
4292 #ifdef TARGET_OPTIONS
4293 if (!valid)
4294 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4296 int len = strlen (target_options[j].prefix);
4297 if (!strncmp (target_options[j].prefix, name, len))
4299 *target_options[j].variable = name + len;
4300 valid = 1;
4303 #endif
4305 if (!valid)
4306 error ("Invalid option `%s'", name);
4309 /* Print version information to FILE.
4310 Each line begins with INDENT (for the case where FILE is the
4311 assembler output file). */
4313 void
4314 print_version (file, indent)
4315 FILE *file;
4316 char *indent;
4318 fprintf (file, "%s%s%s version %s", indent, *indent != 0 ? " " : "",
4319 language_string, version_string);
4320 fprintf (file, " (%s)", TARGET_NAME);
4321 #ifdef __GNUC__
4322 #ifndef __VERSION__
4323 #define __VERSION__ "[unknown]"
4324 #endif
4325 fprintf (file, " compiled by GNU C version %s.\n", __VERSION__);
4326 #else
4327 fprintf (file, " compiled by CC.\n");
4328 #endif
4331 /* Print an option value and return the adjusted position in the line.
4332 ??? We don't handle error returns from fprintf (disk full); presumably
4333 other code will catch a disk full though. */
4336 print_single_switch (file, pos, max, indent, sep, term, type, name)
4337 FILE *file;
4338 int pos, max;
4339 char *indent, *sep, *term, *type, *name;
4341 /* The ultrix fprintf returns 0 on success, so compute the result we want
4342 here since we need it for the following test. */
4343 int len = strlen (sep) + strlen (type) + strlen (name);
4345 if (pos != 0
4346 && pos + len > max)
4348 fprintf (file, "%s", term);
4349 pos = 0;
4351 if (pos == 0)
4353 fprintf (file, "%s", indent);
4354 pos = strlen (indent);
4356 fprintf (file, "%s%s%s", sep, type, name);
4357 pos += len;
4358 return pos;
4361 /* Print active target switches to FILE.
4362 POS is the current cursor position and MAX is the size of a "line".
4363 Each line begins with INDENT and ends with TERM.
4364 Each switch is separated from the next by SEP. */
4366 void
4367 print_switch_values (file, pos, max, indent, sep, term)
4368 FILE *file;
4369 int pos, max;
4370 char *indent, *sep, *term;
4372 int j, flags;
4373 char **p;
4375 /* Print the options as passed. */
4377 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4378 "options passed: ", "");
4380 for (p = &save_argv[1]; *p != NULL; p++)
4381 if (**p == '-')
4383 /* Ignore these. */
4384 if (strcmp (*p, "-o") == 0)
4386 if (p[1] != NULL)
4387 p++;
4388 continue;
4390 if (strcmp (*p, "-quiet") == 0)
4391 continue;
4392 if (strcmp (*p, "-version") == 0)
4393 continue;
4394 if ((*p)[1] == 'd')
4395 continue;
4397 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4399 if (pos > 0)
4400 fprintf (file, "%s", term);
4402 /* Print the -f and -m options that have been enabled.
4403 We don't handle language specific options but printing argv
4404 should suffice. */
4406 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4407 "options enabled: ", "");
4409 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
4410 if (*f_options[j].variable == f_options[j].on_value)
4411 pos = print_single_switch (file, pos, max, indent, sep, term,
4412 "-f", f_options[j].string);
4414 /* Print target specific options. */
4416 flags = target_flags;
4417 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4418 if (target_switches[j].name[0] != '\0'
4419 && target_switches[j].value > 0
4420 && ((target_switches[j].value & target_flags)
4421 == target_switches[j].value))
4423 pos = print_single_switch (file, pos, max, indent, sep, term,
4424 "-m", target_switches[j].name);
4425 flags &= ~ target_switches[j].value;
4428 #ifdef TARGET_OPTIONS
4429 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4430 if (*target_options[j].variable != NULL)
4432 char prefix[256];
4433 sprintf (prefix, "-m%s", target_options[j].prefix);
4434 pos = print_single_switch (file, pos, max, indent, sep, term,
4435 prefix, *target_options[j].variable);
4437 #endif
4439 fprintf (file, "%s", term);
4442 /* Record the beginning of a new source file, named FILENAME. */
4444 void
4445 debug_start_source_file (filename)
4446 register char *filename;
4448 #ifdef DBX_DEBUGGING_INFO
4449 if (write_symbols == DBX_DEBUG)
4450 dbxout_start_new_source_file (filename);
4451 #endif
4452 #ifdef DWARF_DEBUGGING_INFO
4453 if (debug_info_level == DINFO_LEVEL_VERBOSE
4454 && write_symbols == DWARF_DEBUG)
4455 dwarfout_start_new_source_file (filename);
4456 #endif /* DWARF_DEBUGGING_INFO */
4457 #ifdef DWARF2_DEBUGGING_INFO
4458 if (debug_info_level == DINFO_LEVEL_VERBOSE
4459 && write_symbols == DWARF2_DEBUG)
4460 dwarf2out_start_source_file (filename);
4461 #endif /* DWARF2_DEBUGGING_INFO */
4462 #ifdef SDB_DEBUGGING_INFO
4463 if (write_symbols == SDB_DEBUG)
4464 sdbout_start_new_source_file (filename);
4465 #endif
4468 /* Record the resumption of a source file. LINENO is the line number in
4469 the source file we are returning to. */
4471 void
4472 debug_end_source_file (lineno)
4473 register unsigned lineno;
4475 #ifdef DBX_DEBUGGING_INFO
4476 if (write_symbols == DBX_DEBUG)
4477 dbxout_resume_previous_source_file ();
4478 #endif
4479 #ifdef DWARF_DEBUGGING_INFO
4480 if (debug_info_level == DINFO_LEVEL_VERBOSE
4481 && write_symbols == DWARF_DEBUG)
4482 dwarfout_resume_previous_source_file (lineno);
4483 #endif /* DWARF_DEBUGGING_INFO */
4484 #ifdef DWARF2_DEBUGGING_INFO
4485 if (debug_info_level == DINFO_LEVEL_VERBOSE
4486 && write_symbols == DWARF2_DEBUG)
4487 dwarf2out_end_source_file ();
4488 #endif /* DWARF2_DEBUGGING_INFO */
4489 #ifdef SDB_DEBUGGING_INFO
4490 if (write_symbols == SDB_DEBUG)
4491 sdbout_resume_previous_source_file ();
4492 #endif
4495 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
4496 the tail part of the directive line, i.e. the part which is past the
4497 initial whitespace, #, whitespace, directive-name, whitespace part. */
4499 void
4500 debug_define (lineno, buffer)
4501 register unsigned lineno;
4502 register char *buffer;
4504 #ifdef DWARF_DEBUGGING_INFO
4505 if (debug_info_level == DINFO_LEVEL_VERBOSE
4506 && write_symbols == DWARF_DEBUG)
4507 dwarfout_define (lineno, buffer);
4508 #endif /* DWARF_DEBUGGING_INFO */
4509 #ifdef DWARF2_DEBUGGING_INFO
4510 if (debug_info_level == DINFO_LEVEL_VERBOSE
4511 && write_symbols == DWARF2_DEBUG)
4512 dwarf2out_define (lineno, buffer);
4513 #endif /* DWARF2_DEBUGGING_INFO */
4516 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
4517 the tail part of the directive line, i.e. the part which is past the
4518 initial whitespace, #, whitespace, directive-name, whitespace part. */
4520 void
4521 debug_undef (lineno, buffer)
4522 register unsigned lineno;
4523 register char *buffer;
4525 #ifdef DWARF_DEBUGGING_INFO
4526 if (debug_info_level == DINFO_LEVEL_VERBOSE
4527 && write_symbols == DWARF_DEBUG)
4528 dwarfout_undef (lineno, buffer);
4529 #endif /* DWARF_DEBUGGING_INFO */
4530 #ifdef DWARF2_DEBUGGING_INFO
4531 if (debug_info_level == DINFO_LEVEL_VERBOSE
4532 && write_symbols == DWARF2_DEBUG)
4533 dwarf2out_undef (lineno, buffer);
4534 #endif /* DWARF2_DEBUGGING_INFO */