Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / contrib / gcc / toplev.c
CommitLineData
984263bc
MD
1/* Top level of GNU C compiler
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22/* $FreeBSD: src/contrib/gcc/toplev.c,v 1.6.2.8 2002/07/03 17:56:20 ambrisko Exp $ */
1de703da 23/* $DragonFly: src/contrib/gcc/Attic/toplev.c,v 1.2 2003/06/17 04:24:01 dillon Exp $ */
984263bc
MD
24
25/* This is the top level of cc1/c++.
26 It parses command args, opens files, invokes the various passes
27 in the proper order, and counts the time used by each.
28 Error messages and low-level interface to malloc also handled here. */
29
30#include "config.h"
31#undef FLOAT /* This is for hpux. They should change hpux. */
32#undef FFS /* Some systems define this in param.h. */
33#include "system.h"
34#include <signal.h>
35#include <setjmp.h>
36
37#ifdef HAVE_SYS_RESOURCE_H
38# include <sys/resource.h>
39#endif
40
41#ifdef HAVE_SYS_TIMES_H
42# include <sys/times.h>
43#endif
44
45#include "input.h"
46#include "tree.h"
47#include "rtl.h"
48#include "flags.h"
49#include "insn-attr.h"
50#include "insn-codes.h"
51#include "insn-config.h"
52#include "recog.h"
53#include "defaults.h"
54#include "output.h"
55#include "except.h"
56#include "toplev.h"
57#include "expr.h"
58#include "basic-block.h"
59#include "intl.h"
60
61#ifdef DWARF_DEBUGGING_INFO
62#include "dwarfout.h"
63#endif
64
65#if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
66#include "dwarf2out.h"
67#endif
68
69#if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
70#include "dbxout.h"
71#endif
72
73#ifdef SDB_DEBUGGING_INFO
74#include "sdbout.h"
75#endif
76
77#ifdef XCOFF_DEBUGGING_INFO
78#include "xcoffout.h"
79#endif
80\f
81#ifdef VMS
82/* The extra parameters substantially improve the I/O performance. */
83static FILE *
84vms_fopen (fname, type)
85 char * fname;
86 char * type;
87{
88 /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two
89 fixed arguments, which matches ANSI's specification but not VAXCRTL's
90 pre-ANSI implementation. This hack circumvents the mismatch problem. */
91 FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;
92
93 if (*type == 'w')
94 return (*vmslib_fopen) (fname, type, "mbc=32",
95 "deq=64", "fop=tef", "shr=nil");
96 else
97 return (*vmslib_fopen) (fname, type, "mbc=32");
98}
99#define fopen vms_fopen
100#endif /* VMS */
101
102#ifndef DEFAULT_GDB_EXTENSIONS
103#define DEFAULT_GDB_EXTENSIONS 1
104#endif
105
106/* If more than one debugging type is supported, you must define
107 PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.
108
109 This is one long line cause VAXC can't handle a \-newline. */
110#if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
111#ifndef PREFERRED_DEBUGGING_TYPE
112You Lose! You must define PREFERRED_DEBUGGING_TYPE!
113#endif /* no PREFERRED_DEBUGGING_TYPE */
114#else /* Only one debugging format supported. Define PREFERRED_DEBUGGING_TYPE
115 so the following code needn't care. */
116#ifdef DBX_DEBUGGING_INFO
117#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
118#endif
119#ifdef SDB_DEBUGGING_INFO
120#define PREFERRED_DEBUGGING_TYPE SDB_DEBUG
121#endif
122#ifdef DWARF_DEBUGGING_INFO
123#define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG
124#endif
125#ifdef DWARF2_DEBUGGING_INFO
126#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
127#endif
128#ifdef XCOFF_DEBUGGING_INFO
129#define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG
130#endif
131#endif /* More than one debugger format enabled. */
132
133/* If still not defined, must have been because no debugging formats
134 are supported. */
135#ifndef PREFERRED_DEBUGGING_TYPE
136#define PREFERRED_DEBUGGING_TYPE NO_DEBUG
137#endif
138
139#ifndef DIR_SEPARATOR
140#define DIR_SEPARATOR '/'
141#endif
142
143#if ! (defined (VMS) || defined (OS2))
144extern char **environ;
145#endif
146extern char *version_string, *language_string;
147
148/* Carry information from ASM_DECLARE_OBJECT_NAME
149 to ASM_FINISH_DECLARE_OBJECT. */
150
151extern int size_directive_output;
152extern tree last_assemble_variable_decl;
153
154extern char *init_parse PVPROTO((char *));
155extern void finish_parse ();
156extern void init_decl_processing ();
157extern void init_obstacks ();
158extern void init_tree_codes ();
159extern void init_rtl ();
160extern void init_regs ();
161extern void init_optabs ();
162extern void init_stmt ();
163extern void init_reg_sets ();
164extern void dump_flow_info ();
165extern void dump_sched_info ();
166extern void dump_local_alloc ();
167extern void regset_release_memory ();
168
169extern void print_rtl ();
170extern void print_rtl_with_bb ();
171
172void rest_of_decl_compilation ();
173void error_with_file_and_line PVPROTO((const char *file,
174 int line, const char *s, ...));
175void error_with_decl PVPROTO((tree decl, const char *s, ...));
176void error_for_asm PVPROTO((rtx insn, const char *s, ...));
177void notice PVPROTO((const char *s, ...));
178void error PVPROTO((const char *s, ...));
179void fatal PVPROTO((const char *s, ...));
180void warning_with_file_and_line PVPROTO((const char *file,
181 int line, const char *s, ...));
182void warning_with_decl PVPROTO((tree decl, const char *s, ...));
183void warning PVPROTO((const char *s, ...));
184void pedwarn PVPROTO((const char *s, ...));
185void pedwarn_with_decl PVPROTO((tree decl, const char *s, ...));
186void pedwarn_with_file_and_line PVPROTO((const char *file,
187 int line, const char *s, ...));
188void sorry PVPROTO((const char *s, ...));
189static void set_target_switch PROTO((const char *));
190static char *decl_name PROTO((tree, int));
191static void vmessage PROTO((const char *, const char *, va_list));
192static void v_message_with_file_and_line PROTO((const char *, int, int,
193 const char *, va_list));
194static void v_message_with_decl PROTO((tree, int, const char *, va_list));
195static void file_and_line_for_asm PROTO((rtx, char **, int *));
196static void v_error_with_file_and_line PROTO((const char *, int,
197 const char *, va_list));
198static void v_error_with_decl PROTO((tree, const char *, va_list));
199static void v_error_for_asm PROTO((rtx, const char *, va_list));
200static void verror PROTO((const char *, va_list));
201static void vfatal PROTO((const char *, va_list)) ATTRIBUTE_NORETURN;
202static void v_warning_with_file_and_line PROTO ((const char *, int,
203 const char *, va_list));
204static void v_warning_with_decl PROTO((tree, const char *, va_list));
205static void v_warning_for_asm PROTO((rtx, const char *, va_list));
206static void vwarning PROTO((const char *, va_list));
207static void vpedwarn PROTO((const char *, va_list));
208static void v_pedwarn_with_decl PROTO((tree, const char *, va_list));
209static void v_pedwarn_with_file_and_line PROTO((const char *, int,
210 const char *, va_list));
211static void vsorry PROTO((const char *, va_list));
212static void float_signal PROTO((int)) ATTRIBUTE_NORETURN;
213static void pipe_closed PROTO((int)) ATTRIBUTE_NORETURN;
214#ifdef ASM_IDENTIFY_LANGUAGE
215/* This might or might not be used in ASM_IDENTIFY_LANGUAGE. */
216static void output_lang_identify PROTO((FILE *)) ATTRIBUTE_UNUSED;
217#endif
218static void open_dump_file PROTO((const char *, const char *));
219static void close_dump_file PROTO((void (*) (FILE *, rtx), rtx));
220static void dump_rtl PROTO((const char *, tree, void (*) (FILE *, rtx), rtx));
221static void clean_dump_file PROTO((const char *));
222static void compile_file PROTO((char *));
223static void display_help PROTO ((void));
224
225static void print_version PROTO((FILE *, const char *));
226static int print_single_switch PROTO((FILE *, int, int, const char *,
227 const char *, const char *,
228 const char *, const char *));
229static void print_switch_values PROTO((FILE *, int, int, const char *,
230 const char *, const char *));
231
232void print_rtl_graph_with_bb PROTO ((const char *, const char *, rtx));
233void clean_graph_dump_file PROTO ((const char *, const char *));
234void finish_graph_dump_file PROTO ((const char *, const char *));
235/* Length of line when printing switch values. */
236#define MAX_LINE 75
237
238/* Name of program invoked, sans directories. */
239
240char *progname;
241
242/* Copy of arguments to main. */
243int save_argc;
244char **save_argv;
245\f
246/* Name of current original source file (what was input to cpp).
247 This comes from each #-command in the actual input. */
248
249char *input_filename;
250
251/* Name of top-level original source file (what was input to cpp).
252 This comes from the #-command at the beginning of the actual input.
253 If there isn't any there, then this is the cc1 input file name. */
254
255char *main_input_filename;
256
257/* Current line number in real source file. */
258
259int lineno;
260
261/* Nonzero if it is unsafe to create any new pseudo registers. */
262int no_new_pseudos;
263
264/* Stack of currently pending input files. */
265
266struct file_stack *input_file_stack;
267
268/* Incremented on each change to input_file_stack. */
269int input_file_stack_tick;
270
271/* FUNCTION_DECL for function now being parsed or compiled. */
272
273extern tree current_function_decl;
274
275/* Name to use as base of names for dump output files. */
276
277const char *dump_base_name;
278
279/* Bit flags that specify the machine subtype we are compiling for.
280 Bits are tested using macros TARGET_... defined in the tm.h file
281 and set by `-m...' switches. Must be defined in rtlanal.c. */
282
283extern int target_flags;
284
285/* Flags saying which kinds of debugging dump have been requested. */
286
287int rtl_dump = 0;
288int rtl_dump_and_exit = 0;
289int jump_opt_dump = 0;
290int addressof_dump = 0;
291int cse_dump = 0;
292int gcse_dump = 0;
293int loop_dump = 0;
294int cse2_dump = 0;
295int branch_prob_dump = 0;
296int flow_dump = 0;
297int combine_dump = 0;
298int regmove_dump = 0;
299int sched_dump = 0;
300int local_reg_dump = 0;
301int global_reg_dump = 0;
302int flow2_dump = 0;
303int sched2_dump = 0;
304int jump2_opt_dump = 0;
305#ifdef DELAY_SLOTS
306int dbr_sched_dump = 0;
307#endif
308int flag_print_asm_name = 0;
309#ifdef STACK_REGS
310int stack_reg_dump = 0;
311#endif
312#ifdef MACHINE_DEPENDENT_REORG
313int mach_dep_reorg_dump = 0;
314#endif
315enum graph_dump_types graph_dump_format;
316
317/* Name for output file of assembly code, specified with -o. */
318
319char *asm_file_name;
320
321/* Value of the -G xx switch, and whether it was passed or not. */
322int g_switch_value;
323int g_switch_set;
324
325/* Type(s) of debugging information we are producing (if any).
326 See flags.h for the definitions of the different possible
327 types of debugging information. */
328enum debug_info_type write_symbols = NO_DEBUG;
329
330/* Level of debugging information we are producing. See flags.h
331 for the definitions of the different possible levels. */
332enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
333
334/* Nonzero means use GNU-only extensions in the generated symbolic
335 debugging information. */
336/* Currently, this only has an effect when write_symbols is set to
337 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
338int use_gnu_debug_info_extensions = 0;
339
340/* Nonzero means do optimizations. -O.
341 Particular numeric values stand for particular amounts of optimization;
342 thus, -O2 stores 2 here. However, the optimizations beyond the basic
343 ones are not controlled directly by this variable. Instead, they are
344 controlled by individual `flag_...' variables that are defaulted
345 based on this variable. */
346
347int optimize = 0;
348
349/* Nonzero means optimize for size. -Os.
350 The only valid values are zero and non-zero. When optimize_size is
351 non-zero, optimize defaults to 2, but certain individual code
352 bloating optimizations are disabled. */
353
354int optimize_size = 0;
355
356/* Number of error messages and warning messages so far. */
357
358int errorcount = 0;
359int warningcount = 0;
360int sorrycount = 0;
361
362/* Pointer to function to compute the name to use to print a declaration.
363 DECL is the declaration in question.
364 VERBOSITY determines what information will be printed:
365 0: DECL_NAME, demangled as necessary.
366 1: and scope information.
367 2: and any other information that might be interesting, such as function
368 parameter types in C++. */
369
370char *(*decl_printable_name) PROTO ((tree, int));
371
372/* Pointer to function to compute rtl for a language-specific tree code. */
373
374typedef rtx (*lang_expand_expr_t)
375 PROTO ((union tree_node *, rtx, enum machine_mode,
376 enum expand_modifier modifier));
377
378lang_expand_expr_t lang_expand_expr = 0;
379
380tree (*lang_expand_constant) PROTO((tree)) = 0;
381
382/* Pointer to function to finish handling an incomplete decl at the
383 end of compilation. */
384
385void (*incomplete_decl_finalize_hook) PROTO((tree)) = 0;
386
387/* Nonzero if generating code to do profiling. */
388
389int profile_flag = 0;
390
391/* Nonzero if generating code to do profiling on a line-by-line basis. */
392
393int profile_block_flag;
394
395/* Nonzero if generating code to profile program flow graph arcs. */
396
397int profile_arc_flag = 0;
398
399/* Nonzero if generating info for gcov to calculate line test coverage. */
400
401int flag_test_coverage = 0;
402
403/* Nonzero indicates that branch taken probabilities should be calculated. */
404
405int flag_branch_probabilities = 0;
406
407/* Nonzero for -pedantic switch: warn about anything
408 that standard spec forbids. */
409
410int pedantic = 0;
411
412/* Temporarily suppress certain warnings.
413 This is set while reading code from a system header file. */
414
415int in_system_header = 0;
416
417/* Nonzero means do stupid register allocation.
418 Currently, this is 1 if `optimize' is 0. */
419
420int obey_regdecls = 0;
421
422/* Don't print functions as they are compiled and don't print
423 times taken by the various passes. -quiet. */
424
425int quiet_flag = 0;
426\f
427/* -f flags. */
428
429/* Nonzero means `char' should be signed. */
430
431int flag_signed_char;
432
433/* Nonzero means give an enum type only as many bytes as it needs. */
434
435int flag_short_enums;
436
437/* Nonzero for -fcaller-saves: allocate values in regs that need to
438 be saved across function calls, if that produces overall better code.
439 Optional now, so people can test it. */
440
441#ifdef DEFAULT_CALLER_SAVES
442int flag_caller_saves = 1;
443#else
444int flag_caller_saves = 0;
445#endif
446
447/* Nonzero if structures and unions should be returned in memory.
448
449 This should only be defined if compatibility with another compiler or
450 with an ABI is needed, because it results in slower code. */
451
452#ifndef DEFAULT_PCC_STRUCT_RETURN
453#define DEFAULT_PCC_STRUCT_RETURN 1
454#endif
455
456/* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
457
458int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
459
460/* Nonzero for -fforce-mem: load memory value into a register
461 before arithmetic on it. This makes better cse but slower compilation. */
462
463int flag_force_mem = 0;
464
465/* Nonzero for -fforce-addr: load memory address into a register before
466 reference to memory. This makes better cse but slower compilation. */
467
468int flag_force_addr = 0;
469
470/* Nonzero for -fdefer-pop: don't pop args after each function call;
471 instead save them up to pop many calls' args with one insns. */
472
473int flag_defer_pop = 0;
474
475/* Nonzero for -ffloat-store: don't allocate floats and doubles
476 in extended-precision registers. */
477
478int flag_float_store = 0;
479
480/* Nonzero for -fcse-follow-jumps:
481 have cse follow jumps to do a more extensive job. */
482
483int flag_cse_follow_jumps;
484
485/* Nonzero for -fcse-skip-blocks:
486 have cse follow a branch around a block. */
487int flag_cse_skip_blocks;
488
489/* Nonzero for -fexpensive-optimizations:
490 perform miscellaneous relatively-expensive optimizations. */
491int flag_expensive_optimizations;
492
493/* Nonzero for -fthread-jumps:
494 have jump optimize output of loop. */
495
496int flag_thread_jumps;
497
498/* Nonzero enables strength-reduction in loop.c. */
499
500int flag_strength_reduce = 0;
501
502/* Nonzero enables loop unrolling in unroll.c. Only loops for which the
503 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
504 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
505 unrolled. */
506
507int flag_unroll_loops;
508
509/* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
510 This is generally not a win. */
511
512int flag_unroll_all_loops;
513
514/* Nonzero forces all invariant computations in loops to be moved
515 outside the loop. */
516
517int flag_move_all_movables = 0;
518
519/* Nonzero forces all general induction variables in loops to be
520 strength reduced. */
521
522int flag_reduce_all_givs = 0;
523
524/* Nonzero to perform full register move optimization passes. This is the
525 default for -O2. */
526
527int flag_regmove = 0;
528
529/* Nonzero for -fwritable-strings:
530 store string constants in data segment and don't uniquize them. */
531
532int flag_writable_strings = 0;
533
534/* Nonzero means don't put addresses of constant functions in registers.
535 Used for compiling the Unix kernel, where strange substitutions are
536 done on the assembly output. */
537
538int flag_no_function_cse = 0;
539
540/* Nonzero for -fomit-frame-pointer:
541 don't make a frame pointer in simple functions that don't require one. */
542
543int flag_omit_frame_pointer = 0;
544
545/* Nonzero means place each function into its own section on those platforms
546 which support arbitrary section names and unlimited numbers of sections. */
547
548int flag_function_sections = 0;
549
550/* ... and similar for data. */
551
552int flag_data_sections = 0;
553
554/* Nonzero to inhibit use of define_optimization peephole opts. */
555
556int flag_no_peephole = 0;
557
558/* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
559 operations in the interest of optimization. For example it allows
560 GCC to assume arguments to sqrt are nonnegative numbers, allowing
561 faster code for sqrt to be generated. */
562
563int flag_fast_math = 0;
564
565/* Nonzero means the front end generally wants `errno' maintained by math
566 operations, like built-in SQRT, unless overridden by flag_fast_math. */
567
568int flag_errno_math = 1;
569
570/* 0 means straightforward implementation of complex divide acceptable.
571 1 means wide ranges of inputs must work for complex divide.
572 2 means C9X-like requirements for complex divide (not yet implemented). */
573
574int flag_complex_divide_method = 0;
575
576/* Nonzero means all references through pointers are volatile. */
577
578int flag_volatile;
579
580/* Nonzero means treat all global and extern variables as volatile. */
581
582int flag_volatile_global;
583
584/* Nonzero means treat all static variables as volatile. */
585
586int flag_volatile_static;
587
588/* Nonzero means just do syntax checking; don't output anything. */
589
590int flag_syntax_only = 0;
591
592/* Nonzero means perform global cse. */
593
594static int flag_gcse;
595
596/* Nonzero means to rerun cse after loop optimization. This increases
597 compilation time about 20% and picks up a few more common expressions. */
598
599static int flag_rerun_cse_after_loop;
600
601/* Nonzero means to run loop optimizations twice. */
602
603int flag_rerun_loop_opt;
604
605/* Nonzero for -finline-functions: ok to inline functions that look like
606 good inline candidates. */
607
608int flag_inline_functions;
609
610/* Nonzero for -fkeep-inline-functions: even if we make a function
611 go inline everywhere, keep its definition around for debugging
612 purposes. */
613
614int flag_keep_inline_functions;
615
616/* Nonzero means that functions will not be inlined. */
617
618int flag_no_inline;
619
620/* Nonzero means that we should emit static const variables
621 regardless of whether or not optimization is turned on. */
622
623int flag_keep_static_consts = 1;
624
625/* Nonzero means we should be saving declaration info into a .X file. */
626
627int flag_gen_aux_info = 0;
628
629/* Specified name of aux-info file. */
630
631static char *aux_info_file_name;
632
633/* Nonzero means make the text shared if supported. */
634
635int flag_shared_data;
636
637/* Nonzero means schedule into delayed branch slots if supported. */
638
639int flag_delayed_branch;
640
641/* Nonzero if we are compiling pure (sharable) code.
642 Value is 1 if we are doing reasonable (i.e. simple
643 offset into offset table) pic. Value is 2 if we can
644 only perform register offsets. */
645
646int flag_pic;
647
648/* Nonzero means generate extra code for exception handling and enable
649 exception handling. */
650
651int flag_exceptions;
652
653/* Nonzero means use the new model for exception handling. Replaces
654 -DNEW_EH_MODEL as a compile option. */
655
656int flag_new_exceptions = 0;
657
658/* Nonzero means don't place uninitialized global data in common storage
659 by default. */
660
661int flag_no_common;
662
663/* Nonzero means pretend it is OK to examine bits of target floats,
664 even if that isn't true. The resulting code will have incorrect constants,
665 but the same series of instructions that the native compiler would make. */
666
667int flag_pretend_float;
668
669/* Nonzero means change certain warnings into errors.
670 Usually these are warnings about failure to conform to some standard. */
671
672int flag_pedantic_errors = 0;
673
674/* flag_schedule_insns means schedule insns within basic blocks (before
675 local_alloc).
676 flag_schedule_insns_after_reload means schedule insns after
677 global_alloc. */
678
679int flag_schedule_insns = 0;
680int flag_schedule_insns_after_reload = 0;
681
682#ifdef HAIFA
683/* The following flags have effect only for scheduling before register
684 allocation:
685
686 flag_schedule_interblock means schedule insns accross basic blocks.
687 flag_schedule_speculative means allow speculative motion of non-load insns.
688 flag_schedule_speculative_load means allow speculative motion of some
689 load insns.
690 flag_schedule_speculative_load_dangerous allows speculative motion of more
691 load insns. */
692
693int flag_schedule_interblock = 1;
694int flag_schedule_speculative = 1;
695int flag_schedule_speculative_load = 0;
696int flag_schedule_speculative_load_dangerous = 0;
697#endif /* HAIFA */
698
699/* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
700 by a cheaper branch, on a count register. */
701int flag_branch_on_count_reg;
702
703/* -finhibit-size-directive inhibits output of .size for ELF.
704 This is used only for compiling crtstuff.c,
705 and it may be extended to other effects
706 needed for crtstuff.c on other systems. */
707int flag_inhibit_size_directive = 0;
708
709/* -fverbose-asm causes extra commentary information to be produced in
710 the generated assembly code (to make it more readable). This option
711 is generally only of use to those who actually need to read the
712 generated assembly code (perhaps while debugging the compiler itself).
713 -fno-verbose-asm, the default, causes the extra information
714 to be omitted and is useful when comparing two assembler files. */
715
716int flag_verbose_asm = 0;
717
718/* -dA causes debug commentary information to be produced in
719 the generated assembly code (to make it more readable). This option
720 is generally only of use to those who actually need to read the
721 generated assembly code (perhaps while debugging the compiler itself).
722 Currently, this switch is only used by dwarfout.c; however, it is intended
723 to be a catchall for printing debug information in the assembler file. */
724
725int flag_debug_asm = 0;
726
727/* -fgnu-linker specifies use of the GNU linker for initializations.
728 (Or, more generally, a linker that handles initializations.)
729 -fno-gnu-linker says that collect2 will be used. */
730#ifdef USE_COLLECT2
731int flag_gnu_linker = 0;
732#else
733int flag_gnu_linker = 1;
734#endif
735
736/* Tag all structures with __attribute__(packed) */
737int flag_pack_struct = 0;
738
739/* Nonzero means that -Wformat accepts certain system-dependent formats. */
740int flag_format_extensions = 0;
741
742/* Emit code to check for stack overflow; also may cause large objects
743 to be allocated dynamically. */
744int flag_stack_check;
745
746/* -fcheck-memory-usage causes extra code to be generated in order to check
747 memory accesses. This is used by a detector of bad memory accesses such
748 as Checker. */
749int flag_check_memory_usage = 0;
750
751/* -fprefix-function-name causes function name to be prefixed. This
752 can be used with -fcheck-memory-usage to isolate code compiled with
753 -fcheck-memory-usage. */
754int flag_prefix_function_name = 0;
755
756/* 0 if pointer arguments may alias each other. True in C.
757 1 if pointer arguments may not alias each other but may alias
758 global variables.
759 2 if pointer arguments may not alias each other and may not
760 alias global variables. True in Fortran.
761 This defaults to 0 for C. */
762int flag_argument_noalias = 0;
763
764/* Nonzero if we should do (language-dependent) alias analysis.
765 Typically, this analysis will assume that expressions of certain
766 types do not alias expressions of certain other types. Only used
767 if alias analysis (in general) is enabled. */
768int flag_strict_aliasing = 0;
769
770/* Instrument functions with calls at entry and exit, for profiling. */
771int flag_instrument_function_entry_exit = 0;
772
773/* Nonzero means ignore `#ident' directives. 0 means handle them.
774 On SVR4 targets, it also controls whether or not to emit a
775 string identifying the compiler. */
776
777int flag_no_ident = 0;
778
779/* Table of supported debugging formats. */
780static struct
781{
782 const char * arg;
783 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
784 constant expression, we use NO_DEBUG in its place. */
785 enum debug_info_type debug_type;
786 int use_extensions_p;
787 const char * description;
788} *da,
789debug_args[] =
790{
791 { "g", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
792 "Generate default debug format output" },
793 { "ggdb", NO_DEBUG, 1, "Generate default extended debug format output" },
794#ifdef DBX_DEBUGGING_INFO
795 { "gstabs", DBX_DEBUG, 0, "Generate STABS format debug output" },
796 { "gstabs+", DBX_DEBUG, 1, "Generate extended STABS format debug output" },
797#endif
798#ifdef DWARF_DEBUGGING_INFO
799 { "gdwarf", DWARF_DEBUG, 0, "Generate DWARF-1 format debug output"},
800 { "gdwarf+", DWARF_DEBUG, 1,
801 "Generated extended DWARF-1 format debug output" },
802#endif
803#ifdef DWARF2_DEBUGGING_INFO
804 { "gdwarf-2", DWARF2_DEBUG, 0, "Enable DWARF-2 debug output" },
805#endif
806#ifdef XCOFF_DEBUGGING_INFO
807 { "gxcoff", XCOFF_DEBUG, 0, "Generate XCOFF format debug output" },
808 { "gxcoff+", XCOFF_DEBUG, 1, "Generate extended XCOFF format debug output" },
809#endif
810#ifdef SDB_DEBUGGING_INFO
811 { "gcoff", SDB_DEBUG, 0, "Generate COFF format debug output" },
812#endif
813 { 0, 0, 0, 0 }
814};
815
816typedef struct
817{
818 const char * string;
819 int * variable;
820 int on_value;
821 const char * description;
822}
823lang_independent_options;
824
825/* Add or remove a leading underscore from user symbols. */
826int flag_leading_underscore = -1;
827
828/* The user symbol prefix after having resolved same. */
829const char *user_label_prefix;
830
831/* A default for same. */
832#ifndef USER_LABEL_PREFIX
833#define USER_LABEL_PREFIX ""
834#endif
835
836/* Table of language-independent -f options.
837 STRING is the option name. VARIABLE is the address of the variable.
838 ON_VALUE is the value to store in VARIABLE
839 if `-fSTRING' is seen as an option.
840 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
841
842lang_independent_options f_options[] =
843{
844 {"float-store", &flag_float_store, 1,
845 "Do not store floats in registers" },
846 {"volatile", &flag_volatile, 1,
847 "Consider all mem refs through pointers as volatile"},
848 {"volatile-global", &flag_volatile_global, 1,
849 "Consider all mem refs to global data to be volatile" },
850 {"volatile-static", &flag_volatile_static, 1,
851 "Consider all mem refs to static data to be volatile" },
852 {"defer-pop", &flag_defer_pop, 1,
853 "Defer popping functions args from stack until later" },
854 {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
855 "When possible do not generate stack frames"},
856 {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
857 "When running CSE, follow jumps to their targets" },
858 {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
859 "When running CSE, follow conditional jumps" },
860 {"expensive-optimizations", &flag_expensive_optimizations, 1,
861 "Perform a number of minor, expensive optimisations" },
862 {"thread-jumps", &flag_thread_jumps, 1,
863 "Perform jump threading optimisations"},
864 {"strength-reduce", &flag_strength_reduce, 1,
865 "Perform strength reduction optimisations" },
866 {"unroll-loops", &flag_unroll_loops, 1,
867 "Perform loop unrolling when iteration count is known" },
868 {"unroll-all-loops", &flag_unroll_all_loops, 1,
869 "Perform loop unrolling for all loops" },
870 {"move-all-movables", &flag_move_all_movables, 1,
871 "Force all loop invariant computations out of loops" },
872 {"reduce-all-givs", &flag_reduce_all_givs, 1,
873 "Strength reduce all loop general induction variables" },
874 {"writable-strings", &flag_writable_strings, 1,
875 "Store strings in writable data section" },
876 {"peephole", &flag_no_peephole, 0,
877 "Enable machine specific peephole optimisations" },
878 {"force-mem", &flag_force_mem, 1,
879 "Copy memory operands into registers before using" },
880 {"force-addr", &flag_force_addr, 1,
881 "Copy memory address constants into regs before using" },
882 {"function-cse", &flag_no_function_cse, 0,
883 "Allow function addresses to be held in registers" },
884 {"inline-functions", &flag_inline_functions, 1,
885 "Integrate simple functions into their callers" },
886 {"keep-inline-functions", &flag_keep_inline_functions, 1,
887 "Generate code for funcs even if they are fully inlined" },
888 {"inline", &flag_no_inline, 0,
889 "Pay attention to the 'inline' keyword"},
890 {"keep-static-consts", &flag_keep_static_consts, 1,
891 "Emit static const variables even if they are not used" },
892 {"syntax-only", &flag_syntax_only, 1,
893 "Check for syntax errors, then stop" },
894 {"shared-data", &flag_shared_data, 1,
895 "Mark data as shared rather than private" },
896 {"caller-saves", &flag_caller_saves, 1,
897 "Enable saving registers around function calls" },
898 {"pcc-struct-return", &flag_pcc_struct_return, 1,
899 "Return 'short' aggregates in memory, not registers" },
900 {"reg-struct-return", &flag_pcc_struct_return, 0,
901 "Return 'short' aggregates in registers" },
902 {"delayed-branch", &flag_delayed_branch, 1,
903 "Attempt to fill delay slots of branch instructions" },
904 {"gcse", &flag_gcse, 1,
905 "Perform the global common subexpression elimination" },
906 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1,
907 "Run CSE pass after loop optimisations"},
908 {"rerun-loop-opt", &flag_rerun_loop_opt, 1,
909 "Run the loop optimiser twice"},
910 {"pretend-float", &flag_pretend_float, 1,
911 "Pretend that host and target use the same FP format"},
912 {"schedule-insns", &flag_schedule_insns, 1,
913 "Reschedule instructions to avoid pipeline stalls"},
914 {"schedule-insns2", &flag_schedule_insns_after_reload, 1,
915 "Run two passes of the instruction scheduler"},
916#ifdef HAIFA
917 {"sched-interblock",&flag_schedule_interblock, 1,
918 "Enable scheduling across basic blocks" },
919 {"sched-spec",&flag_schedule_speculative, 1,
920 "Allow speculative motion of non-loads" },
921 {"sched-spec-load",&flag_schedule_speculative_load, 1,
922 "Allow speculative motion of some loads" },
923 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1,
924 "Allow speculative motion of more loads" },
925#endif /* HAIFA */
926 {"branch-count-reg",&flag_branch_on_count_reg, 1,
927 "Replace add,compare,branch with branch on count reg"},
928 {"pic", &flag_pic, 1,
929 "Generate position independent code, if possible"},
930 {"PIC", &flag_pic, 2, ""},
931 {"exceptions", &flag_exceptions, 1,
932 "Enable exception handling" },
933 {"new-exceptions", &flag_new_exceptions, 1,
934 "Use the new model for exception handling" },
935 {"sjlj-exceptions", &exceptions_via_longjmp, 1,
936 "Use setjmp/longjmp to handle exceptions" },
937 {"asynchronous-exceptions", &asynchronous_exceptions, 1,
938 "Support asynchronous exceptions" },
939 {"profile-arcs", &profile_arc_flag, 1,
940 "Insert arc based program profiling code" },
941 {"test-coverage", &flag_test_coverage, 1,
942 "Create data files needed by gcov" },
943 {"branch-probabilities", &flag_branch_probabilities, 1,
944 "Use profiling information for branch probabilities" },
945 {"fast-math", &flag_fast_math, 1,
946 "Improve FP speed by violating ANSI & IEEE rules" },
947 {"common", &flag_no_common, 0,
948 "Do not put unitialised globals in the common section" },
949 {"inhibit-size-directive", &flag_inhibit_size_directive, 1,
950 "Do not generate .size directives" },
951 {"function-sections", &flag_function_sections, 1,
952 "place each function into its own section" },
953 {"data-sections", &flag_data_sections, 1,
954 "place data items into their own section" },
955 {"verbose-asm", &flag_verbose_asm, 1,
956 "Add extra commentry to assembler output"},
957 {"gnu-linker", &flag_gnu_linker, 1,
958 "Output GNU ld formatted global initialisers"},
959 {"regmove", &flag_regmove, 1,
960 "Enables a register move optimisation"},
961 {"optimize-register-move", &flag_regmove, 1,
962 "Do the full regmove optimization pass"},
963 {"pack-struct", &flag_pack_struct, 1,
964 "Pack structure members together without holes" },
965 {"format-extensions", &flag_format_extensions, 1,
966 "-Wformat accepts certain FreeBSD system-dependent formats" },
967 {"stack-check", &flag_stack_check, 1,
968 "Insert stack checking code into the program" },
969 {"argument-alias", &flag_argument_noalias, 0,
970 "Specify that arguments may alias each other & globals"},
971 {"argument-noalias", &flag_argument_noalias, 1,
972 "Assume arguments may alias globals but not each other"},
973 {"argument-noalias-global", &flag_argument_noalias, 2,
974 "Assume arguments do not alias each other or globals" },
975 {"strict-aliasing", &flag_strict_aliasing, 1,
976 "Assume strict aliasing rules apply" },
977 {"check-memory-usage", &flag_check_memory_usage, 1,
978 "Generate code to check every memory access" },
979 {"prefix-function-name", &flag_prefix_function_name, 1,
980 "Add a prefix to all function names" },
981 {"dump-unnumbered", &flag_dump_unnumbered, 1,
982 "Suppress output of instruction numbers and line number notes in debugging dumps"},
983 {"instrument-functions", &flag_instrument_function_entry_exit, 1,
984 "Instrument function entry/exit with profiling calls"},
985 {"leading-underscore", &flag_leading_underscore, 1,
986 "External symbols have a leading underscore" },
987 {"ident", &flag_no_ident, 0,
988 "Process #ident directives"}
989};
990
991#define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0]))
992
993/* Table of language-specific options. */
994
995static struct lang_opt
996{
997 const char * option;
998 const char * description;
999}
1000documented_lang_options[] =
1001{
1002 /* In order not to overload the --help output, the convention
1003 used here is to only describe those options which are not
1004 enabled by default. */
1005
1006 { "-ansi", "Compile just for ANSI C" },
1007 { "-fallow-single-precision",
1008 "Do not promote floats to double if using -traditional" },
1009 { "-std= ", "Determine language standard"},
1010
1011 { "-fsigned-bitfields", "" },
1012 { "-funsigned-bitfields","Make bitfields by unsigned by default" },
1013 { "-fno-signed-bitfields", "" },
1014 { "-fno-unsigned-bitfields","" },
1015 { "-fsigned-char", "Make 'char' be signed by default"},
1016 { "-funsigned-char", "Make 'char' be unsigned by default"},
1017 { "-fno-signed-char", "" },
1018 { "-fno-unsigned-char", "" },
1019
1020 { "-ftraditional", "" },
1021 { "-traditional", "Attempt to support traditional K&R style C"},
1022 { "-fnotraditional", "" },
1023 { "-fno-traditional", "" },
1024
1025 { "-fasm", "" },
1026 { "-fno-asm", "Do not recognise the 'asm' keyword" },
1027 { "-fbuiltin", "" },
1028 { "-fno-builtin", "Do not recognise any built in functions" },
1029 { "-fhosted", "Assume normal C execution environment" },
1030 { "-fno-hosted", "" },
1031 { "-ffreestanding",
1032 "Assume that standard libraries & main might not exist" },
1033 { "-fno-freestanding", "" },
1034 { "-fcond-mismatch", "Allow different types as args of ? operator"},
1035 { "-fno-cond-mismatch", "" },
1036 { "-fdollars-in-identifiers", "Allow the use of $ inside identifiers" },
1037 { "-fno-dollars-in-identifiers", "" },
1038 { "-fshort-double", "Use the same size for double as for float" },
1039 { "-fno-short-double", "" },
1040 { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
1041 { "-fno-short-enums", "" },
1042
1043 { "-Wall", "Enable most warning messages" },
1044 { "-Wbad-function-cast",
1045 "Warn about casting functions to incompatible types" },
1046 { "-Wno-bad-function-cast", "" },
1047 { "-Wmissing-noreturn",
1048 "Warn about functions which might be candidates for attribute noreturn" },
1049 { "-Wno-missing-noreturn", "" },
1050 { "-Wcast-qual", "Warn about casts which discard qualifiers"},
1051 { "-Wno-cast-qual", "" },
1052 { "-Wchar-subscripts", "Warn about subscripts whose type is 'char'"},
1053 { "-Wno-char-subscripts", "" },
1054 { "-Wcomment", "Warn if nested comments are detected" },
1055 { "-Wno-comment", "" },
1056 { "-Wcomments", "Warn if nested comments are detected" },
1057 { "-Wno-comments", "" },
1058 { "-Wconversion", "Warn about possibly confusing type conversions" },
1059 { "-Wno-conversion", "" },
1060 { "-Wformat", "Warn about printf format anomalies" },
1061 { "-Wnon-const-format", "Warn about printf-like format strings" },
1062 { "-Wno-format", "" },
1063 { "-Wno-format-extra-args", "" },
1064 { "-Wimplicit-function-declaration",
1065 "Warn about implicit function declarations" },
1066 { "-Wno-implicit-function-declaration", "" },
1067 { "-Werror-implicit-function-declaration", "" },
1068 { "-Wimplicit-int", "Warn when a declaration does not specify a type" },
1069 { "-Wno-implicit-int", "" },
1070 { "-Wimplicit", "" },
1071 { "-Wno-implicit", "" },
1072 { "-Wimport", "Warn about the use of the #import directive" },
1073 { "-Wno-import", "" },
1074 { "-Wlong-long","" },
1075 { "-Wno-long-long", "Do not warn about using 'long long' when -pedantic" },
1076 { "-Wmain", "Warn about suspicious declarations of main" },
1077 { "-Wframe-size-<N>",
1078 "Warn if frame uses greater than <N> bytes." },
1079 { "-Warglist-size-<N>",
1080 "Warn if function argument list uses greater than <N> bytes." },
1081 { "-Wno-main", "" },
1082 { "-Wmissing-braces",
1083 "Warn about possibly missing braces around initialisers" },
1084 { "-Wno-missing-braces", "" },
1085 { "-Wmissing-declarations",
1086 "Warn about global funcs without previous declarations"},
1087 { "-Wno-missing-declarations", "" },
1088 { "-Wmissing-prototypes", "Warn about global funcs without prototypes" },
1089 { "-Wno-missing-prototypes", "" },
1090 { "-Wmultichar", "Warn about use of multicharacter literals"},
1091 { "-Wno-multichar", "" },
1092 { "-Wnested-externs", "Warn about externs not at file scope level" },
1093 { "-Wno-nested-externs", "" },
1094 { "-Wparentheses", "Warn about possible missing parentheses" },
1095 { "-Wno-parentheses", "" },
1096 { "-Wpointer-arith", "Warn about function pointer arithmetic" },
1097 { "-Wno-pointer-arith", "" },
1098 { "-Wredundant-decls",
1099 "Warn about multiple declarations of the same object" },
1100 { "-Wno-redundant-decls", "" },
1101 { "-Wsign-compare", "Warn about signed/unsigned comparisons" },
1102 { "-Wno-sign-compare", "" },
1103 { "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
1104 { "-Wno-unknown-pragmas", "" },
1105 { "-Wstrict-prototypes", "Warn about non-prototyped function decls" },
1106 { "-Wno-strict-prototypes", "" },
1107 { "-Wtraditional", "Warn about constructs whose meaning change in ANSI C"},
1108 { "-Wno-traditional", "" },
1109 { "-Wtrigraphs", "Warn when trigraphs are encountered" },
1110 { "-Wno-trigraphs", "" },
1111 { "-Wundef", "" },
1112 { "-Wno-undef", "" },
1113 { "-Wwrite-strings", "Mark strings as 'const char *'"},
1114 { "-Wno-write-strings", "" },
1115
1116 /* These are for languages with USE_CPPLIB. */
1117 /* These options are already documented in cpplib.c */
1118 { "--help", "" },
1119 { "-A", "" },
1120 { "-D", "" },
1121 { "-I", "" },
1122#if USE_CPPLIB
1123 { "-MD", "Print dependencies to FILE.d" },
1124 { "-MMD", "Print dependencies to FILE.d" },
1125 { "-M", "Print dependencies to stdout" },
1126 { "-MM", "Print dependencies to stdout" },
1127#endif /* USE_CPPLIB */
1128 { "-U", "" },
1129 { "-H", "" },
1130 { "-idirafter", "" },
1131 { "-imacros", "" },
1132 { "-include", "" },
1133 { "-iprefix", "" },
1134 { "-isystem", "" },
1135 { "-iwithprefix", "" },
1136 { "-iwithprefixbefore", "" },
1137 { "-lang-c", "" },
1138 { "-lang-c89", "" },
1139 { "-lang-c++", "" },
1140 { "-remap", "" },
1141 { "-nostdinc", "" },
1142 { "-nostdinc++", "" },
1143 { "-trigraphs", "" },
1144 { "-undef", "" },
1145
1146#define DEFINE_LANG_NAME(NAME) { NULL, NAME },
1147
1148 /* These are for obj c. */
1149 DEFINE_LANG_NAME ("Objective C")
1150
1151 { "-lang-objc", "" },
1152 { "-gen-decls", "Dump decls to a .decl file" },
1153 { "-fgnu-runtime", "Generate code for GNU runtime environment" },
1154 { "-fno-gnu-runtime", "" },
1155 { "-fnext-runtime", "Generate code for NeXT runtime environment" },
1156 { "-fno-next-runtime", "" },
1157 { "-Wselector", "Warn if a selector has multiple methods" },
1158 { "-Wno-selector", "" },
1159 { "-Wprotocol", "" },
1160 { "-Wno-protocol", "Do not warn if inherited methods are unimplemented"},
1161 { "-print-objc-runtime-info",
1162 "Generate C header of platform specific features" },
1163
1164#include "options.h"
1165
1166};
1167
1168/* Here is a table, controlled by the tm.h file, listing each -m switch
1169 and which bits in `target_switches' it should set or clear.
1170 If VALUE is positive, it is bits to set.
1171 If VALUE is negative, -VALUE is bits to clear.
1172 (The sign bit is not used so there is no confusion.) */
1173
1174struct
1175{
1176 const char * name;
1177 int value;
1178 const char * description;
1179}
1180target_switches [] = TARGET_SWITCHES;
1181
1182/* This table is similar, but allows the switch to have a value. */
1183
1184#ifdef TARGET_OPTIONS
1185struct
1186{
1187 const char * prefix;
1188 const char ** variable;
1189 const char * description;
1190}
1191target_options [] = TARGET_OPTIONS;
1192#endif
1193\f
1194/* Options controlling warnings */
1195
1196/* Don't print warning messages. -w. */
1197
1198int inhibit_warnings = 0;
1199
1200/* Print various extra warnings. -W. */
1201
1202int extra_warnings = 0;
1203
1204/* Treat warnings as errors. -Werror. */
1205
1206int warnings_are_errors = 0;
1207
1208/* Nonzero to warn about unused local variables. */
1209
1210int warn_unused;
1211
1212/* Nonzero to warn about variables used before they are initialized. */
1213
1214int warn_uninitialized;
1215
1216/* Nonzero means warn about all declarations which shadow others. */
1217
1218int warn_shadow;
1219
1220/* Warn if a switch on an enum fails to have a case for every enum value. */
1221
1222int warn_switch;
1223
1224/* Nonzero means warn about function definitions that default the return type
1225 or that use a null return and have a return-type other than void. */
1226
1227int warn_return_type;
1228
1229/* Nonzero means warn about pointer casts that increase the required
1230 alignment of the target type (and might therefore lead to a crash
1231 due to a misaligned access). */
1232
1233int warn_cast_align;
1234
1235/* Nonzero means warn if a frame is larger that N bytes. The value
1236 of N is warn_frame_size. */
1237
1238int warn_frame_size_flag = 0;
1239int warn_frame_size;
1240
1241/* Nonzero means warn if a function call pushes more than N bytes
1242 onto the stack. The value of N is warn_arglist_size. */
1243
1244int warn_arglist_size_flag = 0;
1245int warn_arglist_size;
1246
1247/* Nonzero means warn about any identifiers that match in the first N
1248 characters. The value N is in `id_clash_len'. */
1249
1250int warn_id_clash;
1251unsigned id_clash_len;
1252
1253/* Nonzero means warn about any objects definitions whose size is larger
1254 than N bytes. Also want about function definitions whose returned
1255 values are larger than N bytes. The value N is in `larger_than_size'. */
1256
1257int warn_larger_than;
1258unsigned larger_than_size;
1259
1260/* Nonzero means warn if inline function is too large. */
1261
1262int warn_inline;
1263
1264/* Warn if a function returns an aggregate,
1265 since there are often incompatible calling conventions for doing this. */
1266
1267int warn_aggregate_return;
1268
1269/* Likewise for -W. */
1270
1271lang_independent_options W_options[] =
1272{
1273 {"unused", &warn_unused, 1, "Warn when a variable is unused" },
1274 {"error", &warnings_are_errors, 1, ""},
1275 {"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
1276 {"switch", &warn_switch, 1,
1277 "Warn about enumerated switches missing a specific case" },
1278 {"aggregate-return", &warn_aggregate_return, 1,
1279 "Warn about returning structures, unions or arrays" },
1280 {"cast-align", &warn_cast_align, 1,
1281 "Warn about pointer casts which increase alignment" },
1282 {"uninitialized", &warn_uninitialized, 1,
1283 "Warn about unitialized automatic variables"},
1284 {"inline", &warn_inline, 1,
1285 "Warn when an inlined function cannot be inlined"}
1286};
1287\f
1288/* Output files for assembler code (real compiler output)
1289 and debugging dumps. */
1290
1291FILE *asm_out_file;
1292FILE *aux_info_file;
1293FILE *rtl_dump_file = NULL;
1294
1295/* Decode the string P as an integral parameter.
1296 If the string is indeed an integer return its numeric value else
1297 issue an Invalid Option error for the option PNAME and return DEFVAL.
1298 If PNAME is zero just return DEFVAL, do not call error. */
1299
1300int
1301read_integral_parameter (p, pname, defval)
1302 const char *p;
1303 const char *pname;
1304 const int defval;
1305{
1306 const char *endp = p;
1307
1308 while (*endp)
1309 {
1310 if (*endp >= '0' && *endp <= '9')
1311 endp++;
1312 else
1313 break;
1314 }
1315
1316 if (*endp != 0)
1317 {
1318 if (pname != 0)
1319 error ("Invalid option `%s'", pname);
1320 return defval;
1321 }
1322
1323 return atoi (p);
1324}
1325
1326
1327/* Time accumulators, to count the total time spent in various passes. */
1328
1329int parse_time;
1330int varconst_time;
1331int integration_time;
1332int jump_time;
1333int cse_time;
1334int gcse_time;
1335int loop_time;
1336int cse2_time;
1337int branch_prob_time;
1338int flow_time;
1339int combine_time;
1340int regmove_time;
1341int sched_time;
1342int local_alloc_time;
1343int global_alloc_time;
1344int flow2_time;
1345int sched2_time;
1346#ifdef DELAY_SLOTS
1347int dbr_sched_time;
1348#endif
1349int shorten_branch_time;
1350int stack_reg_time;
1351int final_time;
1352int symout_time;
1353int dump_time;
1354\f
1355/* Return time used so far, in microseconds. */
1356
1357long
1358get_run_time ()
1359{
1360 if (quiet_flag)
1361 return 0;
1362
1363#ifdef __BEOS__
1364 return 0;
1365#else /* not BeOS */
1366#if defined (_WIN32) && !defined (__CYGWIN__)
1367 if (clock() < 0)
1368 return 0;
1369 else
1370 return (clock() * 1000);
1371#else /* not _WIN32 */
1372#ifdef _SC_CLK_TCK
1373 {
1374 static int tick;
1375 struct tms tms;
1376 if (tick == 0)
1377 tick = 1000000 / sysconf(_SC_CLK_TCK);
1378 times (&tms);
1379 return (tms.tms_utime + tms.tms_stime) * tick;
1380 }
1381#else
1382#ifdef USG
1383 {
1384 struct tms tms;
1385# if HAVE_SYSCONF && defined _SC_CLK_TCK
1386# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
1387# else
1388# ifdef CLK_TCK
1389# define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
1390# else
1391# define TICKS_PER_SECOND HZ /* traditional UNIX */
1392# endif
1393# endif
1394 times (&tms);
1395 return (tms.tms_utime + tms.tms_stime) * (1000000 / TICKS_PER_SECOND);
1396 }
1397#else
1398#ifndef VMS
1399 {
1400 struct rusage rusage;
1401 getrusage (0, &rusage);
1402 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1403 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1404 }
1405#else /* VMS */
1406 {
1407 struct
1408 {
1409 int proc_user_time;
1410 int proc_system_time;
1411 int child_user_time;
1412 int child_system_time;
1413 } vms_times;
1414 times ((void *) &vms_times);
1415 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
1416 }
1417#endif /* VMS */
1418#endif /* USG */
1419#endif /* _SC_CLK_TCK */
1420#endif /* _WIN32 */
1421#endif /* __BEOS__ */
1422}
1423
1424#define TIMEVAR(VAR, BODY) \
1425do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1426
1427void
1428print_time (str, total)
1429 const char *str;
1430 int total;
1431{
1432 fprintf (stderr,
1433 "time in %s: %d.%06d\n",
1434 str, total / 1000000, total % 1000000);
1435}
1436
1437/* Count an error or warning. Return 1 if the message should be printed. */
1438
1439int
1440count_error (warningp)
1441 int warningp;
1442{
1443 if (warningp && inhibit_warnings)
1444 return 0;
1445
1446 if (warningp && !warnings_are_errors)
1447 warningcount++;
1448 else
1449 {
1450 static int warning_message = 0;
1451
1452 if (warningp && !warning_message)
1453 {
1454 notice ("%s: warnings being treated as errors\n", progname);
1455 warning_message = 1;
1456 }
1457 errorcount++;
1458 }
1459
1460 return 1;
1461}
1462
1463/* Print a fatal error message. NAME is the text.
1464 Also include a system error message based on `errno'. */
1465
1466void
1467pfatal_with_name (name)
1468 const char *name;
1469{
1470 fprintf (stderr, "%s: ", progname);
1471 perror (name);
1472 exit (FATAL_EXIT_CODE);
1473}
1474
1475void
1476fatal_io_error (name)
1477 const char *name;
1478{
1479 notice ("%s: %s: I/O error\n", progname, name);
1480 exit (FATAL_EXIT_CODE);
1481}
1482
1483/* Called to give a better error message for a bad insn rather than
1484 just calling abort(). */
1485
1486void
1487fatal_insn VPROTO((const char *msgid, rtx insn, ...))
1488{
1489#ifndef ANSI_PROTOTYPES
1490 const char *msgid;
1491 rtx insn;
1492#endif
1493 va_list ap;
1494
1495 VA_START (ap, insn);
1496
1497#ifndef ANSI_PROTOTYPES
1498 msgid = va_arg (ap, const char *);
1499 insn = va_arg (ap, rtx);
1500#endif
1501
1502 verror (msgid, ap);
1503 debug_rtx (insn);
1504 exit (FATAL_EXIT_CODE);
1505}
1506
1507/* Called to give a better error message when we don't have an insn to match
1508 what we are looking for or if the insn's constraints aren't satisfied,
1509 rather than just calling abort(). */
1510
1511void
1512fatal_insn_not_found (insn)
1513 rtx insn;
1514{
1515 if (INSN_CODE (insn) < 0)
1516 fatal_insn ("internal error--unrecognizable insn:", insn);
1517 else
1518 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1519}
1520
1521/* This is the default decl_printable_name function. */
1522
1523static char *
1524decl_name (decl, verbosity)
1525 tree decl;
1526 int verbosity ATTRIBUTE_UNUSED;
1527{
1528 return IDENTIFIER_POINTER (DECL_NAME (decl));
1529}
1530\f
1531static int need_error_newline;
1532
1533/* Function of last error message;
1534 more generally, function such that if next error message is in it
1535 then we don't have to mention the function name. */
1536static tree last_error_function = NULL;
1537
1538/* Used to detect when input_file_stack has changed since last described. */
1539static int last_error_tick;
1540
1541/* Called when the start of a function definition is parsed,
1542 this function prints on stderr the name of the function. */
1543
1544void
1545announce_function (decl)
1546 tree decl;
1547{
1548 if (! quiet_flag)
1549 {
1550 if (rtl_dump_and_exit)
1551 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1552 else
1553 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1554 fflush (stderr);
1555 need_error_newline = 1;
1556 last_error_function = current_function_decl;
1557 }
1558}
1559
1560/* The default function to print out name of current function that caused
1561 an error. */
1562
1563void
1564default_print_error_function (file)
1565 const char *file;
1566{
1567 if (last_error_function != current_function_decl)
1568 {
1569 if (file)
1570 fprintf (stderr, "%s: ", file);
1571
1572 if (current_function_decl == NULL)
1573 notice ("At top level:\n");
1574 else
1575 notice ((TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE
1576 ? "In method `%s':\n"
1577 : "In function `%s':\n"),
1578 (*decl_printable_name) (current_function_decl, 2));
1579
1580 last_error_function = current_function_decl;
1581 }
1582}
1583
1584/* Called by report_error_function to print out function name.
1585 * Default may be overridden by language front-ends. */
1586
1587void (*print_error_function) PROTO((const char *)) =
1588 default_print_error_function;
1589
1590/* Prints out, if necessary, the name of the current function
1591 that caused an error. Called from all error and warning functions.
1592 We ignore the FILE parameter, as it cannot be relied upon. */
1593
1594void
1595report_error_function (file)
1596 const char *file ATTRIBUTE_UNUSED;
1597{
1598 struct file_stack *p;
1599
1600 if (need_error_newline)
1601 {
1602 fprintf (stderr, "\n");
1603 need_error_newline = 0;
1604 }
1605
1606 if (input_file_stack && input_file_stack->next != 0
1607 && input_file_stack_tick != last_error_tick)
1608 {
1609 for (p = input_file_stack->next; p; p = p->next)
1610 notice ((p == input_file_stack->next
1611 ? "In file included from %s:%d"
1612 : ",\n from %s:%d"),
1613 p->name, p->line);
1614 fprintf (stderr, ":\n");
1615 last_error_tick = input_file_stack_tick;
1616 }
1617
1618 (*print_error_function) (input_filename);
1619}
1620\f
1621/* Print a message. */
1622
1623static void
1624vnotice (file, msgid, ap)
1625 FILE *file;
1626 char *msgid;
1627 va_list ap;
1628{
1629 vfprintf (file, _(msgid), ap);
1630}
1631
1632void
1633notice VPROTO((const char *msgid, ...))
1634{
1635#ifndef ANSI_PROTOTYPES
1636 char *msgid;
1637#endif
1638 va_list ap;
1639
1640 VA_START (ap, msgid);
1641
1642#ifndef ANSI_PROTOTYPES
1643 msgid = va_arg (ap, char *);
1644#endif
1645
1646 vnotice (stderr, msgid, ap);
1647 va_end (ap);
1648}
1649
1650void
1651fnotice VPROTO((FILE *file, const char *msgid, ...))
1652{
1653#ifndef ANSI_PROTOTYPES
1654 FILE *file;
1655 const char *msgid;
1656#endif
1657 va_list ap;
1658
1659 VA_START (ap, msgid);
1660
1661#ifndef ANSI_PROTOTYPES
1662 file = va_arg (ap, FILE *);
1663 msgid = va_arg (ap, const char *);
1664#endif
1665
1666 vnotice (file, msgid, ap);
1667 va_end (ap);
1668}
1669
1670/* Report FILE and LINE (or program name), and optionally just WARN. */
1671
1672static void
1673report_file_and_line (file, line, warn)
1674 char *file;
1675 int line;
1676 int warn;
1677{
1678 if (file)
1679 fprintf (stderr, "%s:%d: ", file, line);
1680 else
1681 fprintf (stderr, "%s: ", progname);
1682
1683 if (warn)
1684 notice ("warning: ");
1685}
1686
1687/* Print a message. */
1688
1689static void
1690vmessage (prefix, msgid, ap)
1691 const char *prefix;
1692 const char *msgid;
1693 va_list ap;
1694{
1695 if (prefix)
1696 fprintf (stderr, "%s: ", prefix);
1697
1698 vfprintf (stderr, msgid, ap);
1699}
1700
1701/* Print a message relevant to line LINE of file FILE. */
1702
1703static void
1704v_message_with_file_and_line (file, line, warn, msgid, ap)
1705 const char *file;
1706 int line;
1707 int warn;
1708 const char *msgid;
1709 va_list ap;
1710{
1711 report_file_and_line (file, line, warn);
1712 vnotice (stderr, msgid, ap);
1713 fputc ('\n', stderr);
1714}
1715
1716/* Print a message relevant to the given DECL. */
1717
1718static void
1719v_message_with_decl (decl, warn, msgid, ap)
1720 tree decl;
1721 int warn;
1722 const char *msgid;
1723 va_list ap;
1724{
1725 const char *p;
1726
1727 report_file_and_line (DECL_SOURCE_FILE (decl),
1728 DECL_SOURCE_LINE (decl), warn);
1729
1730 /* Do magic to get around lack of varargs support for insertion
1731 of arguments into existing list. We know that the decl is first;
1732 we ass_u_me that it will be printed with "%s". */
1733
1734 for (p = _(msgid); *p; ++p)
1735 {
1736 if (*p == '%')
1737 {
1738 if (*(p + 1) == '%')
1739 ++p;
1740 else if (*(p + 1) != 's')
1741 abort ();
1742 else
1743 break;
1744 }
1745 }
1746
1747 if (p > _(msgid)) /* Print the left-hand substring. */
1748 {
1749 char fmt[sizeof "%.255s"];
1750 long width = p - _(msgid);
1751
1752 if (width > 255L) width = 255L; /* arbitrary */
1753 sprintf (fmt, "%%.%lds", width);
1754 fprintf (stderr, fmt, _(msgid));
1755 }
1756
1757 if (*p == '%') /* Print the name. */
1758 {
1759 const char *n = (DECL_NAME (decl)
1760 ? (*decl_printable_name) (decl, 2)
1761 : "((anonymous))");
1762 fputs (n, stderr);
1763 while (*p)
1764 {
1765 ++p;
1766 if (ISALPHA (*(p - 1) & 0xFF))
1767 break;
1768 }
1769 }
1770
1771 if (*p) /* Print the rest of the message. */
1772 vmessage ((char *)NULL, p, ap);
1773
1774 fputc ('\n', stderr);
1775}
1776
1777/* Figure file and line of the given INSN. */
1778
1779static void
1780file_and_line_for_asm (insn, pfile, pline)
1781 rtx insn;
1782 char **pfile;
1783 int *pline;
1784{
1785 rtx body = PATTERN (insn);
1786 rtx asmop;
1787
1788 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1789 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1790 asmop = SET_SRC (body);
1791 else if (GET_CODE (body) == ASM_OPERANDS)
1792 asmop = body;
1793 else if (GET_CODE (body) == PARALLEL
1794 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1795 asmop = SET_SRC (XVECEXP (body, 0, 0));
1796 else if (GET_CODE (body) == PARALLEL
1797 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1798 asmop = XVECEXP (body, 0, 0);
1799 else
1800 asmop = NULL;
1801
1802 if (asmop)
1803 {
1804 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1805 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1806 }
1807 else
1808 {
1809 *pfile = input_filename;
1810 *pline = lineno;
1811 }
1812}
1813
1814/* Report an error at line LINE of file FILE. */
1815
1816static void
1817v_error_with_file_and_line (file, line, msgid, ap)
1818 const char *file;
1819 int line;
1820 const char *msgid;
1821 va_list ap;
1822{
1823 count_error (0);
1824 report_error_function (file);
1825 v_message_with_file_and_line (file, line, 0, msgid, ap);
1826}
1827
1828void
1829error_with_file_and_line VPROTO((const char *file, int line,
1830 const char *msgid, ...))
1831{
1832#ifndef ANSI_PROTOTYPES
1833 const char *file;
1834 int line;
1835 const char *msgid;
1836#endif
1837 va_list ap;
1838
1839 VA_START (ap, msgid);
1840
1841#ifndef ANSI_PROTOTYPES
1842 file = va_arg (ap, const char *);
1843 line = va_arg (ap, int);
1844 msgid = va_arg (ap, const char *);
1845#endif
1846
1847 v_error_with_file_and_line (file, line, msgid, ap);
1848 va_end (ap);
1849}
1850
1851/* Report an error at the declaration DECL.
1852 MSGID is a format string which uses %s to substitute the declaration
1853 name; subsequent substitutions are a la printf. */
1854
1855static void
1856v_error_with_decl (decl, msgid, ap)
1857 tree decl;
1858 const char *msgid;
1859 va_list ap;
1860{
1861 count_error (0);
1862 report_error_function (DECL_SOURCE_FILE (decl));
1863 v_message_with_decl (decl, 0, msgid, ap);
1864}
1865
1866void
1867error_with_decl VPROTO((tree decl, const char *msgid, ...))
1868{
1869#ifndef ANSI_PROTOTYPES
1870 tree decl;
1871 const char *msgid;
1872#endif
1873 va_list ap;
1874
1875 VA_START (ap, msgid);
1876
1877#ifndef ANSI_PROTOTYPES
1878 decl = va_arg (ap, tree);
1879 msgid = va_arg (ap, const char *);
1880#endif
1881
1882 v_error_with_decl (decl, msgid, ap);
1883 va_end (ap);
1884}
1885
1886/* Report an error at the line number of the insn INSN.
1887 This is used only when INSN is an `asm' with operands,
1888 and each ASM_OPERANDS records its own source file and line. */
1889
1890static void
1891v_error_for_asm (insn, msgid, ap)
1892 rtx insn;
1893 const char *msgid;
1894 va_list ap;
1895{
1896 char *file;
1897 int line;
1898
1899 count_error (0);
1900 file_and_line_for_asm (insn, &file, &line);
1901 report_error_function (file);
1902 v_message_with_file_and_line (file, line, 0, msgid, ap);
1903}
1904
1905void
1906error_for_asm VPROTO((rtx insn, const char *msgid, ...))
1907{
1908#ifndef ANSI_PROTOTYPES
1909 rtx insn;
1910 const char *msgid;
1911#endif
1912 va_list ap;
1913
1914 VA_START (ap, msgid);
1915
1916#ifndef ANSI_PROTOTYPES
1917 insn = va_arg (ap, rtx);
1918 msgid = va_arg (ap, const char *);
1919#endif
1920
1921 v_error_for_asm (insn, msgid, ap);
1922 va_end (ap);
1923}
1924
1925/* Report an error at the current line number. */
1926
1927static void
1928verror (msgid, ap)
1929 const char *msgid;
1930 va_list ap;
1931{
1932 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1933}
1934
1935void
1936error VPROTO((const char *msgid, ...))
1937{
1938#ifndef ANSI_PROTOTYPES
1939 const char *msgid;
1940#endif
1941 va_list ap;
1942
1943 VA_START (ap, msgid);
1944
1945#ifndef ANSI_PROTOTYPES
1946 msgid = va_arg (ap, const char *);
1947#endif
1948
1949 verror (msgid, ap);
1950 va_end (ap);
1951}
1952
1953/* Report a fatal error at the current line number. */
1954
1955static void
1956vfatal (msgid, ap)
1957 const char *msgid;
1958 va_list ap;
1959{
1960 verror (msgid, ap);
1961 exit (FATAL_EXIT_CODE);
1962}
1963
1964void
1965fatal VPROTO((const char *msgid, ...))
1966{
1967#ifndef ANSI_PROTOTYPES
1968 const char *msgid;
1969#endif
1970 va_list ap;
1971
1972 VA_START (ap, msgid);
1973
1974#ifndef ANSI_PROTOTYPES
1975 msgid = va_arg (ap, const char *);
1976#endif
1977
1978 vfatal (msgid, ap);
1979 va_end (ap);
1980}
1981
1982/* Report a warning at line LINE of file FILE. */
1983
1984static void
1985v_warning_with_file_and_line (file, line, msgid, ap)
1986 const char *file;
1987 int line;
1988 const char *msgid;
1989 va_list ap;
1990{
1991 if (count_error (1))
1992 {
1993 report_error_function (file);
1994 v_message_with_file_and_line (file, line, 1, msgid, ap);
1995 }
1996}
1997
1998void
1999warning_with_file_and_line VPROTO((const char *file, int line,
2000 const char *msgid, ...))
2001{
2002#ifndef ANSI_PROTOTYPES
2003 const char *file;
2004 int line;
2005 const char *msgid;
2006#endif
2007 va_list ap;
2008
2009 VA_START (ap, msgid);
2010
2011#ifndef ANSI_PROTOTYPES
2012 file = va_arg (ap, const char *);
2013 line = va_arg (ap, int);
2014 msgid = va_arg (ap, const char *);
2015#endif
2016
2017 v_warning_with_file_and_line (file, line, msgid, ap);
2018 va_end (ap);
2019}
2020
2021/* Report a warning at the declaration DECL.
2022 MSGID is a format string which uses %s to substitute the declaration
2023 name; subsequent substitutions are a la printf. */
2024
2025static void
2026v_warning_with_decl (decl, msgid, ap)
2027 tree decl;
2028 const char *msgid;
2029 va_list ap;
2030{
2031 if (count_error (1))
2032 {
2033 report_error_function (DECL_SOURCE_FILE (decl));
2034 v_message_with_decl (decl, 1, msgid, ap);
2035 }
2036}
2037
2038void
2039warning_with_decl VPROTO((tree decl, const char *msgid, ...))
2040{
2041#ifndef ANSI_PROTOTYPES
2042 tree decl;
2043 const char *msgid;
2044#endif
2045 va_list ap;
2046
2047 VA_START (ap, msgid);
2048
2049#ifndef ANSI_PROTOTYPES
2050 decl = va_arg (ap, tree);
2051 msgid = va_arg (ap, const char *);
2052#endif
2053
2054 v_warning_with_decl (decl, msgid, ap);
2055 va_end (ap);
2056}
2057
2058/* Report a warning at the line number of the insn INSN.
2059 This is used only when INSN is an `asm' with operands,
2060 and each ASM_OPERANDS records its own source file and line. */
2061
2062static void
2063v_warning_for_asm (insn, msgid, ap)
2064 rtx insn;
2065 const char *msgid;
2066 va_list ap;
2067{
2068 if (count_error (1))
2069 {
2070 char *file;
2071 int line;
2072
2073 file_and_line_for_asm (insn, &file, &line);
2074 report_error_function (file);
2075 v_message_with_file_and_line (file, line, 1, msgid, ap);
2076 }
2077}
2078
2079void
2080warning_for_asm VPROTO((rtx insn, const char *msgid, ...))
2081{
2082#ifndef ANSI_PROTOTYPES
2083 rtx insn;
2084 const char *msgid;
2085#endif
2086 va_list ap;
2087
2088 VA_START (ap, msgid);
2089
2090#ifndef ANSI_PROTOTYPES
2091 insn = va_arg (ap, rtx);
2092 msgid = va_arg (ap, const char *);
2093#endif
2094
2095 v_warning_for_asm (insn, msgid, ap);
2096 va_end (ap);
2097}
2098
2099/* Report a warning at the current line number. */
2100
2101static void
2102vwarning (msgid, ap)
2103 const char *msgid;
2104 va_list ap;
2105{
2106 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
2107}
2108
2109void
2110warning VPROTO((const char *msgid, ...))
2111{
2112#ifndef ANSI_PROTOTYPES
2113 const char *msgid;
2114#endif
2115 va_list ap;
2116
2117 VA_START (ap, msgid);
2118
2119#ifndef ANSI_PROTOTYPES
2120 msgid = va_arg (ap, const char *);
2121#endif
2122
2123 vwarning (msgid, ap);
2124 va_end (ap);
2125}
2126
2127/* These functions issue either warnings or errors depending on
2128 -pedantic-errors. */
2129
2130static void
2131vpedwarn (msgid, ap)
2132 const char *msgid;
2133 va_list ap;
2134{
2135 if (flag_pedantic_errors)
2136 verror (msgid, ap);
2137 else
2138 vwarning (msgid, ap);
2139}
2140
2141void
2142pedwarn VPROTO((const char *msgid, ...))
2143{
2144#ifndef ANSI_PROTOTYPES
2145 const char *msgid;
2146#endif
2147 va_list ap;
2148
2149 VA_START (ap, msgid);
2150
2151#ifndef ANSI_PROTOTYPES
2152 msgid = va_arg (ap, const char *);
2153#endif
2154
2155 vpedwarn (msgid, ap);
2156 va_end (ap);
2157}
2158
2159static void
2160v_pedwarn_with_decl (decl, msgid, ap)
2161 tree decl;
2162 const char *msgid;
2163 va_list ap;
2164{
2165 /* We don't want -pedantic-errors to cause the compilation to fail from
2166 "errors" in system header files. Sometimes fixincludes can't fix what's
2167 broken (eg: unsigned char bitfields - fixing it may change the alignment
2168 which will cause programs to mysteriously fail because the C library
2169 or kernel uses the original layout). There's no point in issuing a
2170 warning either, it's just unnecessary noise. */
2171
2172 if (! DECL_IN_SYSTEM_HEADER (decl))
2173 {
2174 if (flag_pedantic_errors)
2175 v_error_with_decl (decl, msgid, ap);
2176 else
2177 v_warning_with_decl (decl, msgid, ap);
2178 }
2179}
2180
2181void
2182pedwarn_with_decl VPROTO((tree decl, const char *msgid, ...))
2183{
2184#ifndef ANSI_PROTOTYPES
2185 tree decl;
2186 const char *msgid;
2187#endif
2188 va_list ap;
2189
2190 VA_START (ap, msgid);
2191
2192#ifndef ANSI_PROTOTYPES
2193 decl = va_arg (ap, tree);
2194 msgid = va_arg (ap, const char *);
2195#endif
2196
2197 v_pedwarn_with_decl (decl, msgid, ap);
2198 va_end (ap);
2199}
2200
2201static void
2202v_pedwarn_with_file_and_line (file, line, msgid, ap)
2203 const char *file;
2204 int line;
2205 const char *msgid;
2206 va_list ap;
2207{
2208 if (flag_pedantic_errors)
2209 v_error_with_file_and_line (file, line, msgid, ap);
2210 else
2211 v_warning_with_file_and_line (file, line, msgid, ap);
2212}
2213
2214void
2215pedwarn_with_file_and_line VPROTO((const char *file, int line,
2216 const char *msgid, ...))
2217{
2218#ifndef ANSI_PROTOTYPES
2219 const char *file;
2220 int line;
2221 const char *msgid;
2222#endif
2223 va_list ap;
2224
2225 VA_START (ap, msgid);
2226
2227#ifndef ANSI_PROTOTYPES
2228 file = va_arg (ap, const char *);
2229 line = va_arg (ap, int);
2230 msgid = va_arg (ap, const char *);
2231#endif
2232
2233 v_pedwarn_with_file_and_line (file, line, msgid, ap);
2234 va_end (ap);
2235}
2236
2237/* Apologize for not implementing some feature. */
2238
2239static void
2240vsorry (msgid, ap)
2241 const char *msgid;
2242 va_list ap;
2243{
2244 sorrycount++;
2245 if (input_filename)
2246 fprintf (stderr, "%s:%d: ", input_filename, lineno);
2247 else
2248 fprintf (stderr, "%s: ", progname);
2249 notice ("sorry, not implemented: ");
2250 vnotice (stderr, msgid, ap);
2251 fputc ('\n', stderr);
2252}
2253
2254void
2255sorry VPROTO((const char *msgid, ...))
2256{
2257#ifndef ANSI_PROTOTYPES
2258 const char *msgid;
2259#endif
2260 va_list ap;
2261
2262 VA_START (ap, msgid);
2263
2264#ifndef ANSI_PROTOTYPES
2265 msgid = va_arg (ap, const char *);
2266#endif
2267
2268 vsorry (msgid, ap);
2269 va_end (ap);
2270}
2271\f
2272/* Given a partial pathname as input, return another pathname that shares
2273 no elements with the pathname of __FILE__. This is used by abort() to
2274 print `Internal compiler error in expr.c' instead of `Internal compiler
2275 error in ../../egcs/gcc/expr.c'. */
2276const char *
2277trim_filename (name)
2278 const char *name;
2279{
2280 static const char *this_file = __FILE__;
2281 const char *p = name, *q = this_file;
2282
2283 while (*p == *q && *p != 0 && *q != 0) p++, q++;
2284 while (p > name && p[-1] != DIR_SEPARATOR
2285#ifdef DIR_SEPARATOR_2
2286 && p[-1] != DIR_SEPARATOR_2
2287#endif
2288 )
2289 p--;
2290
2291 return p;
2292}
2293
2294/* More 'friendly' abort that prints the line and file.
2295 config.h can #define abort fancy_abort if you like that sort of thing.
2296
2297 I don't think this is actually a good idea.
2298 Other sorts of crashes will look a certain way.
2299 It is a good thing if crashes from calling abort look the same way.
2300 -- RMS */
2301
2302void
2303fancy_abort ()
2304{
2305 fatal ("internal gcc abort");
2306}
2307
2308/* This calls abort and is used to avoid problems when abort if a macro.
2309 It is used when we need to pass the address of abort. */
2310
2311void
2312do_abort ()
2313{
2314 abort ();
2315}
2316
2317/* When `malloc.c' is compiled with `rcheck' defined,
2318 it calls this function to report clobberage. */
2319
2320void
2321botch (s)
2322 const char * s ATTRIBUTE_UNUSED;
2323{
2324 abort ();
2325}
2326
2327/* Same as `malloc' but report error if no memory available. */
2328
2329PTR
2330xmalloc (size)
2331 size_t size;
2332{
2333 register PTR value;
2334
2335 if (size == 0)
2336 size = 1;
2337
2338 value = (PTR) malloc (size);
2339 if (value == 0)
2340 fatal ("virtual memory exhausted");
2341 return value;
2342}
2343
2344/* Same as `calloc' but report error if no memory available. */
2345
2346PTR
2347xcalloc (size1, size2)
2348 size_t size1, size2;
2349{
2350 register PTR value;
2351
2352 if (size1 == 0 || size2 == 0)
2353 size1 = size2 = 1;
2354
2355 value = (PTR) calloc (size1, size2);
2356 if (value == 0)
2357 fatal ("virtual memory exhausted");
2358 return value;
2359}
2360
2361
2362/* Same as `realloc' but report error if no memory available.
2363 Also handle null PTR even if the vendor realloc gets it wrong. */
2364
2365PTR
2366xrealloc (ptr, size)
2367 PTR ptr;
2368 size_t size;
2369{
2370 register PTR result;
2371
2372 if (size == 0)
2373 size = 1;
2374
2375 result = (ptr ? (PTR) realloc (ptr, size) : (PTR) malloc (size));
2376
2377 if (!result)
2378 fatal ("virtual memory exhausted");
2379
2380 return result;
2381}
2382
2383/* Same as `strdup' but report error if no memory available. */
2384
2385char *
2386xstrdup (s)
2387 register const char *s;
2388{
2389 register char *result = (char *) malloc (strlen (s) + 1);
2390
2391 if (! result)
2392 fatal ("virtual memory exhausted");
2393 strcpy (result, s);
2394 return result;
2395}
2396\f
2397/* Return the logarithm of X, base 2, considering X unsigned,
2398 if X is a power of 2. Otherwise, returns -1.
2399
2400 This should be used via the `exact_log2' macro. */
2401
2402int
2403exact_log2_wide (x)
2404 register unsigned HOST_WIDE_INT x;
2405{
2406 register int log = 0;
2407 /* Test for 0 or a power of 2. */
2408 if (x == 0 || x != (x & -x))
2409 return -1;
2410 while ((x >>= 1) != 0)
2411 log++;
2412 return log;
2413}
2414
2415/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
2416 If X is 0, return -1.
2417
2418 This should be used via the floor_log2 macro. */
2419
2420int
2421floor_log2_wide (x)
2422 register unsigned HOST_WIDE_INT x;
2423{
2424 register int log = -1;
2425 while (x != 0)
2426 log++,
2427 x >>= 1;
2428 return log;
2429}
2430
2431static int float_handler_set;
2432int float_handled;
2433jmp_buf float_handler;
2434
2435/* Signals actually come here. */
2436
2437static void
2438float_signal (signo)
2439 /* If this is missing, some compilers complain. */
2440 int signo ATTRIBUTE_UNUSED;
2441{
2442 if (float_handled == 0)
2443 abort ();
2444#if defined (USG) || defined (hpux)
2445 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
2446#endif
2447 float_handled = 0;
2448 signal (SIGFPE, float_signal);
2449 longjmp (float_handler, 1);
2450}
2451
2452/* Specify where to longjmp to when a floating arithmetic error happens.
2453 If HANDLER is 0, it means don't handle the errors any more. */
2454
2455void
2456set_float_handler (handler)
2457 jmp_buf handler;
2458{
2459 float_handled = (handler != 0);
2460 if (handler)
2461 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2462
2463 if (float_handled && ! float_handler_set)
2464 {
2465 signal (SIGFPE, float_signal);
2466 float_handler_set = 1;
2467 }
2468}
2469
2470/* This is a wrapper function for code which might elicit an
2471 arithmetic exception. That code should be passed in as a function
2472 pointer FN, and one argument DATA. DATA is usually a struct which
2473 contains the real input and output for function FN. This function
2474 returns 0 (failure) if longjmp was called (i.e. an exception
2475 occured.) It returns 1 (success) otherwise. */
2476
2477int
2478do_float_handler (fn, data)
2479 void (*fn) PROTO ((PTR));
2480 PTR data;
2481{
2482 jmp_buf buf;
2483
2484 if (setjmp (buf))
2485 {
2486 /* We got here via longjmp() caused by an exception in function fn() */
2487 set_float_handler (NULL);
2488 return 0;
2489 }
2490
2491 set_float_handler (buf);
2492 (*fn)(data);
2493 set_float_handler (NULL);
2494 return 1;
2495}
2496
2497/* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2498 error happens, pushing the previous specification into OLD_HANDLER.
2499 Return an indication of whether there was a previous handler in effect. */
2500
2501int
2502push_float_handler (handler, old_handler)
2503 jmp_buf handler, old_handler;
2504{
2505 int was_handled = float_handled;
2506
2507 float_handled = 1;
2508 if (was_handled)
2509 memcpy ((char *) old_handler, (char *) float_handler,
2510 sizeof (float_handler));
2511
2512 memcpy ((char *) float_handler, (char *) handler, sizeof (float_handler));
2513 return was_handled;
2514}
2515
2516/* Restore the previous specification of whether and where to longjmp to
2517 when a floating arithmetic error happens. */
2518
2519void
2520pop_float_handler (handled, handler)
2521 int handled;
2522 jmp_buf handler;
2523{
2524 float_handled = handled;
2525 if (handled)
2526 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
2527}
2528
2529/* Handler for SIGPIPE. */
2530
2531static void
2532pipe_closed (signo)
2533 /* If this is missing, some compilers complain. */
2534 int signo ATTRIBUTE_UNUSED;
2535{
2536 fatal ("output pipe has been closed");
2537}
2538
2539/* Strip off a legitimate source ending from the input string NAME of
2540 length LEN. Rather than having to know the names used by all of
2541 our front ends, we strip off an ending of a period followed by
2542 up to five characters. (Java uses ".class".) */
2543
2544void
2545strip_off_ending (name, len)
2546 char *name;
2547 int len;
2548{
2549 int i;
2550 for (i = 2; i < 6 && len > i; i++)
2551 {
2552 if (name[len - i] == '.')
2553 {
2554 name[len - i] = '\0';
2555 break;
2556 }
2557 }
2558}
2559
2560/* Output a quoted string. */
2561
2562void
2563output_quoted_string (asm_file, string)
2564 FILE *asm_file;
2565 const char *string;
2566{
2567#ifdef OUTPUT_QUOTED_STRING
2568 OUTPUT_QUOTED_STRING (asm_file, string);
2569#else
2570 char c;
2571
2572 putc ('\"', asm_file);
2573 while ((c = *string++) != 0)
2574 {
2575 if (c == '\"' || c == '\\')
2576 putc ('\\', asm_file);
2577 putc (c, asm_file);
2578 }
2579 putc ('\"', asm_file);
2580#endif
2581}
2582
2583/* Output a file name in the form wanted by System V. */
2584
2585void
2586output_file_directive (asm_file, input_name)
2587 FILE *asm_file;
2588 const char *input_name;
2589{
2590 int len = strlen (input_name);
2591 const char *na = input_name + len;
2592
2593 /* NA gets INPUT_NAME sans directory names. */
2594 while (na > input_name)
2595 {
2596 if (na[-1] == '/')
2597 break;
2598#ifdef DIR_SEPARATOR
2599 if (na[-1] == DIR_SEPARATOR)
2600 break;
2601#endif
2602 na--;
2603 }
2604
2605#ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2606 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2607#else
2608#ifdef ASM_OUTPUT_SOURCE_FILENAME
2609 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2610#else
2611 fprintf (asm_file, "\t.file\t");
2612 output_quoted_string (asm_file, na);
2613 fputc ('\n', asm_file);
2614#endif
2615#endif
2616}
2617\f
2618#ifdef ASM_IDENTIFY_LANGUAGE
2619/* Routine to build language identifier for object file. */
2620static void
2621output_lang_identify (asm_out_file)
2622 FILE *asm_out_file;
2623{
2624 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2625 char *s = (char *) alloca (len);
2626 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2627 ASM_OUTPUT_LABEL (asm_out_file, s);
2628}
2629#endif
2630
2631/* Routine to open a dump file. */
2632static void
2633open_dump_file (suffix, function_name)
2634 const char *suffix;
2635 const char *function_name;
2636{
2637 char *dumpname;
2638
2639 TIMEVAR
2640 (dump_time,
2641 {
2642 dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
2643
2644 if (rtl_dump_file != NULL)
2645 fclose (rtl_dump_file);
2646
2647 strcpy (dumpname, dump_base_name);
2648 strcat (dumpname, suffix);
2649
2650 rtl_dump_file = fopen (dumpname, "a");
2651
2652 if (rtl_dump_file == NULL)
2653 pfatal_with_name (dumpname);
2654
2655 free (dumpname);
2656
2657 if (function_name)
2658 fprintf (rtl_dump_file, "\n;; Function %s\n\n", function_name);
2659 });
2660
2661 return;
2662}
2663
2664/* Routine to close a dump file. */
2665static void
2666close_dump_file (func, insns)
2667 void (*func) PROTO ((FILE *, rtx));
2668 rtx insns;
2669{
2670 TIMEVAR
2671 (dump_time,
2672 {
2673 if (func)
2674 func (rtl_dump_file, insns);
2675
2676 fflush (rtl_dump_file);
2677 fclose (rtl_dump_file);
2678
2679 rtl_dump_file = NULL;
2680 });
2681
2682 return;
2683}
2684
2685/* Routine to dump rtl into a file. */
2686static void
2687dump_rtl (suffix, decl, func, insns)
2688 const char *suffix;
2689 tree decl;
2690 void (*func) PROTO ((FILE *, rtx));
2691 rtx insns;
2692{
2693 open_dump_file (suffix, decl_printable_name (decl, 2));
2694 close_dump_file (func, insns);
2695}
2696
2697/* Routine to empty a dump file. */
2698static void
2699clean_dump_file (suffix)
2700 const char *suffix;
2701{
2702 char *dumpname;
2703
2704 dumpname = (char *) xmalloc (strlen (dump_base_name) + strlen (suffix) + 1);
2705
2706 strcpy (dumpname, dump_base_name);
2707 strcat (dumpname, suffix);
2708
2709 rtl_dump_file = fopen (dumpname, "w");
2710
2711 if (rtl_dump_file == NULL)
2712 pfatal_with_name (dumpname);
2713
2714 free (dumpname);
2715
2716 fclose (rtl_dump_file);
2717 rtl_dump_file = NULL;
2718
2719 return;
2720}
2721
2722/* Do any final processing required for the declarations in VEC, of
2723 which there are LEN. We write out inline functions and variables
2724 that have been deferred until this point, but which are required.
2725 Returns non-zero if anything was put out. */
2726int
2727wrapup_global_declarations (vec, len)
2728 tree *vec;
2729 int len;
2730{
2731 tree decl;
2732 int i;
2733 int reconsider;
2734 int output_something = 0;
2735
2736 for (i = 0; i < len; i++)
2737 {
2738 decl = vec[i];
2739
2740 /* We're not deferring this any longer. */
2741 DECL_DEFER_OUTPUT (decl) = 0;
2742
2743 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2744 && incomplete_decl_finalize_hook != 0)
2745 (*incomplete_decl_finalize_hook) (decl);
2746 }
2747
2748 /* Now emit any global variables or functions that we have been
2749 putting off. We need to loop in case one of the things emitted
2750 here references another one which comes earlier in the list. */
2751 do
2752 {
2753 reconsider = 0;
2754 for (i = 0; i < len; i++)
2755 {
2756 decl = vec[i];
2757
2758 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2759 continue;
2760
2761 /* Don't write out static consts, unless we still need them.
2762
2763 We also keep static consts if not optimizing (for debugging),
2764 unless the user specified -fno-keep-static-consts.
2765 ??? They might be better written into the debug information.
2766 This is possible when using DWARF.
2767
2768 A language processor that wants static constants to be always
2769 written out (even if it is not used) is responsible for
2770 calling rest_of_decl_compilation itself. E.g. the C front-end
2771 calls rest_of_decl_compilation from finish_decl.
2772 One motivation for this is that is conventional in some
2773 environments to write things like:
2774 static const char rcsid[] = "... version string ...";
2775 intending to force the string to be in the executable.
2776
2777 A language processor that would prefer to have unneeded
2778 static constants "optimized away" would just defer writing
2779 them out until here. E.g. C++ does this, because static
2780 constants are often defined in header files.
2781
2782 ??? A tempting alternative (for both C and C++) would be
2783 to force a constant to be written if and only if it is
2784 defined in a main file, as opposed to an include file. */
2785
2786 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2787 && (! TREE_READONLY (decl)
2788 || TREE_PUBLIC (decl)
2789 || (!optimize && flag_keep_static_consts)
2790 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2791 {
2792 reconsider = 1;
2793 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2794 }
2795
2796 if (TREE_CODE (decl) == FUNCTION_DECL
2797 && DECL_INITIAL (decl) != 0
2798 && DECL_SAVED_INSNS (decl) != 0
2799 && (flag_keep_inline_functions
2800 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
2801 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2802 {
2803 reconsider = 1;
2804 temporary_allocation ();
2805 output_inline_function (decl);
2806 permanent_allocation (1);
2807 }
2808 }
2809
2810 if (reconsider)
2811 output_something = 1;
2812 }
2813 while (reconsider);
2814
2815 return output_something;
2816}
2817
2818/* Issue appropriate warnings for the global declarations in VEC (of
2819 which there are LEN). Output debugging information for them. */
2820void
2821check_global_declarations (vec, len)
2822 tree *vec;
2823 int len;
2824{
2825 tree decl;
2826 int i;
2827
2828 for (i = 0; i < len; i++)
2829 {
2830 decl = vec[i];
2831
2832 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2833 && ! TREE_ASM_WRITTEN (decl))
2834 /* Cancel the RTL for this decl so that, if debugging info
2835 output for global variables is still to come,
2836 this one will be omitted. */
2837 DECL_RTL (decl) = NULL;
2838
2839 /* Warn about any function
2840 declared static but not defined.
2841 We don't warn about variables,
2842 because many programs have static variables
2843 that exist only to get some text into the object file. */
2844 if (TREE_CODE (decl) == FUNCTION_DECL
2845 && (warn_unused
2846 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2847 && DECL_INITIAL (decl) == 0
2848 && DECL_EXTERNAL (decl)
2849 && ! DECL_ARTIFICIAL (decl)
2850 && ! TREE_PUBLIC (decl))
2851 {
2852 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
2853 pedwarn_with_decl (decl,
2854 "`%s' used but never defined");
2855 else
2856 warning_with_decl (decl,
2857 "`%s' declared `static' but never defined");
2858 /* This symbol is effectively an "extern" declaration now. */
2859 TREE_PUBLIC (decl) = 1;
2860 assemble_external (decl);
2861 }
2862
2863 /* Warn about static fns or vars defined but not used,
2864 but not about inline functions or static consts
2865 since defining those in header files is normal practice. */
2866 if (warn_unused
2867 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2868 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
2869 && ! DECL_IN_SYSTEM_HEADER (decl)
2870 && ! DECL_EXTERNAL (decl)
2871 && ! TREE_PUBLIC (decl)
2872 && ! TREE_USED (decl)
2873 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
2874 /* The TREE_USED bit for file-scope decls
2875 is kept in the identifier, to handle multiple
2876 external decls in different scopes. */
2877 && ! TREE_USED (DECL_NAME (decl)))
2878 warning_with_decl (decl, "`%s' defined but not used");
2879
2880#ifdef SDB_DEBUGGING_INFO
2881 /* The COFF linker can move initialized global vars to the end.
2882 And that can screw up the symbol ordering.
2883 By putting the symbols in that order to begin with,
2884 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2885 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2886 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
2887 && ! DECL_EXTERNAL (decl)
2888 && DECL_RTL (decl) != 0)
2889 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2890
2891 /* Output COFF information for non-global
2892 file-scope initialized variables. */
2893 if (write_symbols == SDB_DEBUG
2894 && TREE_CODE (decl) == VAR_DECL
2895 && DECL_INITIAL (decl)
2896 && ! DECL_EXTERNAL (decl)
2897 && DECL_RTL (decl) != 0
2898 && GET_CODE (DECL_RTL (decl)) == MEM)
2899 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2900#endif /* SDB_DEBUGGING_INFO */
2901#ifdef DWARF_DEBUGGING_INFO
2902 /* Output DWARF information for file-scope tentative data object
2903 declarations, file-scope (extern) function declarations (which
2904 had no corresponding body) and file-scope tagged type declarations
2905 and definitions which have not yet been forced out. */
2906
2907 if (write_symbols == DWARF_DEBUG
2908 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2909 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
2910#endif
2911#ifdef DWARF2_DEBUGGING_INFO
2912 /* Output DWARF2 information for file-scope tentative data object
2913 declarations, file-scope (extern) function declarations (which
2914 had no corresponding body) and file-scope tagged type declarations
2915 and definitions which have not yet been forced out. */
2916
2917 if (write_symbols == DWARF2_DEBUG
2918 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2919 TIMEVAR (symout_time, dwarf2out_decl (decl));
2920#endif
2921 }
2922}
2923
2924/* Compile an entire file of output from cpp, named NAME.
2925 Write a file of assembly output and various debugging dumps. */
2926
2927static void
2928compile_file (name)
2929 char *name;
2930{
2931 tree globals;
2932 int start_time;
2933
2934 int name_specified = name != 0;
2935
2936 if (dump_base_name == 0)
2937 dump_base_name = name ? name : "gccdump";
2938
2939 parse_time = 0;
2940 varconst_time = 0;
2941 integration_time = 0;
2942 jump_time = 0;
2943 cse_time = 0;
2944 gcse_time = 0;
2945 loop_time = 0;
2946 cse2_time = 0;
2947 branch_prob_time = 0;
2948 flow_time = 0;
2949 combine_time = 0;
2950 regmove_time = 0;
2951 sched_time = 0;
2952 local_alloc_time = 0;
2953 global_alloc_time = 0;
2954 flow2_time = 0;
2955 sched2_time = 0;
2956#ifdef DELAY_SLOTS
2957 dbr_sched_time = 0;
2958#endif
2959 shorten_branch_time = 0;
2960 stack_reg_time = 0;
2961 final_time = 0;
2962 symout_time = 0;
2963 dump_time = 0;
2964
2965 /* Initialize data in various passes. */
2966
2967 init_obstacks ();
2968 init_tree_codes ();
2969 name = init_parse (name);
2970 init_rtl ();
2971 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2972 || debug_info_level == DINFO_LEVEL_VERBOSE
2973 || flag_test_coverage);
2974 init_regs ();
2975 init_decl_processing ();
2976 init_optabs ();
2977 init_stmt ();
2978 init_expmed ();
2979 init_expr_once ();
2980 init_loop ();
2981 init_reload ();
2982 init_alias_once ();
2983
2984 if (flag_caller_saves)
2985 init_caller_save ();
2986
2987 /* If auxiliary info generation is desired, open the output file.
2988 This goes in the same directory as the source file--unlike
2989 all the other output files. */
2990 if (flag_gen_aux_info)
2991 {
2992 aux_info_file = fopen (aux_info_file_name, "w");
2993 if (aux_info_file == 0)
2994 pfatal_with_name (aux_info_file_name);
2995 }
2996
2997 /* Clear the dump files. */
2998 if (rtl_dump)
2999 clean_dump_file (".rtl");
3000 if (jump_opt_dump)
3001 {
3002 clean_dump_file (".jump");
3003 if (graph_dump_format != no_graph)
3004 clean_graph_dump_file (dump_base_name, ".jump");
3005 }
3006 if (addressof_dump)
3007 {
3008 clean_dump_file (".addressof");
3009 if (graph_dump_format != no_graph)
3010 clean_graph_dump_file (dump_base_name, ".addressof");
3011 }
3012 if (cse_dump)
3013 {
3014 clean_dump_file (".cse");
3015 if (graph_dump_format != no_graph)
3016 clean_graph_dump_file (dump_base_name, ".cse");
3017 }
3018 if (loop_dump)
3019 {
3020 clean_dump_file (".loop");
3021 if (graph_dump_format != no_graph)
3022 clean_graph_dump_file (dump_base_name, ".loop");
3023 }
3024 if (cse2_dump)
3025 {
3026 clean_dump_file (".cse2");
3027 if (graph_dump_format != no_graph)
3028 clean_graph_dump_file (dump_base_name, ".cse2");
3029 }
3030 if (branch_prob_dump)
3031 {
3032 clean_dump_file (".bp");
3033 if (graph_dump_format != no_graph)
3034 clean_graph_dump_file (dump_base_name, ".bp");
3035 }
3036 if (flow_dump)
3037 {
3038 clean_dump_file (".flow");
3039 if (graph_dump_format != no_graph)
3040 clean_graph_dump_file (dump_base_name, ".flow");
3041 }
3042 if (combine_dump)
3043 {
3044 clean_dump_file (".combine");
3045 if (graph_dump_format != no_graph)
3046 clean_graph_dump_file (dump_base_name, ".combine");
3047 }
3048 if (regmove_dump)
3049 {
3050 clean_dump_file (".regmove");
3051 if (graph_dump_format != no_graph)
3052 clean_graph_dump_file (dump_base_name, ".regmove");
3053 }
3054 if (sched_dump)
3055 {
3056 clean_dump_file (".sched");
3057 if (graph_dump_format != no_graph)
3058 clean_graph_dump_file (dump_base_name, ".sched");
3059 }
3060 if (local_reg_dump)
3061 {
3062 clean_dump_file (".lreg");
3063 if (graph_dump_format != no_graph)
3064 clean_graph_dump_file (dump_base_name, ".lreg");
3065 }
3066 if (global_reg_dump)
3067 {
3068 clean_dump_file (".greg");
3069 if (graph_dump_format != no_graph)
3070 clean_graph_dump_file (dump_base_name, ".greg");
3071 }
3072 if (flow2_dump)
3073 {
3074 clean_dump_file (".flow2");
3075 if (graph_dump_format != no_graph)
3076 clean_graph_dump_file (dump_base_name, ".flow2");
3077 }
3078 if (sched2_dump)
3079 {
3080 clean_dump_file (".sched2");
3081 if (graph_dump_format != no_graph)
3082 clean_graph_dump_file (dump_base_name, ".sched2");
3083 }
3084 if (jump2_opt_dump)
3085 {
3086 clean_dump_file (".jump2");
3087 if (graph_dump_format != no_graph)
3088 clean_graph_dump_file (dump_base_name, ".jump2");
3089 }
3090#ifdef DELAY_SLOTS
3091 if (dbr_sched_dump)
3092 {
3093 clean_dump_file (".dbr");
3094 if (graph_dump_format != no_graph)
3095 clean_graph_dump_file (dump_base_name, ".dbr");
3096 }
3097#endif
3098 if (gcse_dump)
3099 {
3100 clean_dump_file (".gcse");
3101 if (graph_dump_format != no_graph)
3102 clean_graph_dump_file (dump_base_name, ".gcse");
3103 }
3104#ifdef STACK_REGS
3105 if (stack_reg_dump)
3106 {
3107 clean_dump_file (".stack");
3108 if (graph_dump_format != no_graph)
3109 clean_graph_dump_file (dump_base_name, ".stack");
3110 }
3111#endif
3112#ifdef MACHINE_DEPENDENT_REORG
3113 if (mach_dep_reorg_dump)
3114 {
3115 clean_dump_file (".mach");
3116 if (graph_dump_format != no_graph)
3117 clean_graph_dump_file (dump_base_name, ".mach");
3118 }
3119#endif
3120
3121 /* Open assembler code output file. */
3122
3123 if (flag_syntax_only)
3124 asm_out_file = NULL;
3125 else
3126 {
3127 if (! name_specified && asm_file_name == 0)
3128 asm_out_file = stdout;
3129 else
3130 {
3131 int len = strlen (dump_base_name);
3132 register char *dumpname = (char *) xmalloc (len + 6);
3133 strcpy (dumpname, dump_base_name);
3134 strip_off_ending (dumpname, len);
3135 strcat (dumpname, ".s");
3136 if (asm_file_name == 0)
3137 {
3138 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
3139 strcpy (asm_file_name, dumpname);
3140 }
3141 if (!strcmp (asm_file_name, "-"))
3142 asm_out_file = stdout;
3143 else
3144 asm_out_file = fopen (asm_file_name, "w");
3145 if (asm_out_file == 0)
3146 pfatal_with_name (asm_file_name);
3147 }
3148
3149#ifdef IO_BUFFER_SIZE
3150 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
3151 _IOFBF, IO_BUFFER_SIZE);
3152#endif
3153 }
3154
3155 input_filename = name;
3156
3157 /* Put an entry on the input file stack for the main input file. */
3158 input_file_stack
3159 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
3160 input_file_stack->next = 0;
3161 input_file_stack->name = input_filename;
3162
3163 /* Perform language-specific initialization.
3164 This may set main_input_filename. */
3165 lang_init ();
3166
3167 /* If the input doesn't start with a #line, use the input name
3168 as the official input file name. */
3169 if (main_input_filename == 0)
3170 main_input_filename = name;
3171
3172 if (flag_syntax_only)
3173 {
3174 write_symbols = NO_DEBUG;
3175 profile_flag = 0;
3176 profile_block_flag = 0;
3177 }
3178 else
3179 {
3180 ASM_FILE_START (asm_out_file);
3181
3182#ifdef ASM_COMMENT_START
3183 if (flag_verbose_asm)
3184 {
3185 /* Print the list of options in effect. */
3186 print_version (asm_out_file, ASM_COMMENT_START);
3187 print_switch_values (asm_out_file, 0, MAX_LINE,
3188 ASM_COMMENT_START, " ", "\n");
3189 /* Add a blank line here so it appears in assembler output but not
3190 screen output. */
3191 fprintf (asm_out_file, "\n");
3192 }
3193#endif
3194
3195 /* Output something to inform GDB that this compilation was by GCC. */
3196#ifndef ASM_IDENTIFY_GCC
3197 fprintf (asm_out_file, "gcc2_compiled.:\n");
3198#else
3199 ASM_IDENTIFY_GCC (asm_out_file);
3200#endif
3201
3202 /* Output something to identify which front-end produced this file. */
3203#ifdef ASM_IDENTIFY_LANGUAGE
3204 ASM_IDENTIFY_LANGUAGE (asm_out_file);
3205#endif
3206 } /* ! flag_syntax_only */
3207
3208#ifndef ASM_OUTPUT_SECTION_NAME
3209 if (flag_function_sections)
3210 {
3211 warning ("-ffunction-sections not supported for this target.");
3212 flag_function_sections = 0;
3213 }
3214 if (flag_data_sections)
3215 {
3216 warning ("-fdata-sections not supported for this target.");
3217 flag_data_sections = 0;
3218 }
3219#endif
3220
3221 if (flag_function_sections
3222 && (profile_flag || profile_block_flag))
3223 {
3224 warning ("-ffunction-sections disabled; it makes profiling impossible.");
3225 flag_function_sections = 0;
3226 }
3227
3228#ifndef OBJECT_FORMAT_ELF
3229 if (flag_function_sections && write_symbols != NO_DEBUG)
3230 warning ("-ffunction-sections may affect debugging on some targets.");
3231#endif
3232
3233 /* ??? Note: There used to be a conditional here
3234 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
3235 This was to guarantee separation between gcc_compiled. and
3236 the first function, for the sake of dbx on Suns.
3237 However, having the extra zero here confused the Emacs
3238 code for unexec, and might confuse other programs too.
3239 Therefore, I took out that change.
3240 In future versions we should find another way to solve
3241 that dbx problem. -- rms, 23 May 93. */
3242
3243 /* Don't let the first function fall at the same address
3244 as gcc_compiled., if profiling. */
3245 if (profile_flag || profile_block_flag)
3246 {
3247 /* It's best if we can write a nop here since some
3248 assemblers don't tolerate zeros in the text section. */
3249 if (insn_template[CODE_FOR_nop] != 0)
3250 output_asm_insn (insn_template[CODE_FOR_nop], NULL_PTR);
3251 else
3252 assemble_zeros (UNITS_PER_WORD);
3253 }
3254
3255 /* If dbx symbol table desired, initialize writing it
3256 and output the predefined types. */
3257#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3258 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3259 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
3260 getdecls ()));
3261#endif
3262#ifdef SDB_DEBUGGING_INFO
3263 if (write_symbols == SDB_DEBUG)
3264 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
3265 getdecls ()));
3266#endif
3267#ifdef DWARF_DEBUGGING_INFO
3268 if (write_symbols == DWARF_DEBUG)
3269 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
3270#endif
3271#ifdef DWARF2_UNWIND_INFO
3272 if (dwarf2out_do_frame ())
3273 dwarf2out_frame_init ();
3274#endif
3275#ifdef DWARF2_DEBUGGING_INFO
3276 if (write_symbols == DWARF2_DEBUG)
3277 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
3278#endif
3279
3280 /* Initialize yet another pass. */
3281
3282 init_final (main_input_filename);
3283 init_branch_prob (dump_base_name);
3284
3285 start_time = get_run_time ();
3286
3287 /* Call the parser, which parses the entire file
3288 (calling rest_of_compilation for each function). */
3289
3290 if (yyparse () != 0)
3291 {
3292 if (errorcount == 0)
3293 notice ("Errors detected in input file (your bison.simple is out of date)\n");
3294
3295 /* In case there were missing closebraces,
3296 get us back to the global binding level. */
3297 while (! global_bindings_p ())
3298 poplevel (0, 0, 0);
3299 }
3300
3301 /* Compilation is now finished except for writing
3302 what's left of the symbol table output. */
3303
3304 parse_time += get_run_time () - start_time;
3305
3306 parse_time -= integration_time;
3307 parse_time -= varconst_time;
3308
3309 if (flag_syntax_only)
3310 goto finish_syntax;
3311
3312 globals = getdecls ();
3313
3314 /* Really define vars that have had only a tentative definition.
3315 Really output inline functions that must actually be callable
3316 and have not been output so far. */
3317
3318 {
3319 int len = list_length (globals);
3320 tree *vec = (tree *) alloca (sizeof (tree) * len);
3321 int i;
3322 tree decl;
3323
3324 /* Process the decls in reverse order--earliest first.
3325 Put them into VEC from back to front, then take out from front. */
3326
3327 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
3328 vec[len - i - 1] = decl;
3329
3330 wrapup_global_declarations (vec, len);
3331
3332 /* This must occur after the loop to output deferred functions. Else
3333 the profiler initializer would not be emitted if all the functions
3334 in this compilation unit were deferred.
3335
3336 output_func_start_profiler can not cause any additional functions or
3337 data to need to be output, so it need not be in the deferred function
3338 loop above. */
3339 output_func_start_profiler ();
3340
3341 /* Now that all possible functions have been output, we can dump
3342 the exception table. */
3343
3344 output_exception_table ();
3345
3346 check_global_declarations (vec, len);
3347 }
3348
3349 /* Write out any pending weak symbol declarations. */
3350
3351 weak_finish ();
3352
3353 /* Do dbx symbols */
3354#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3355 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3356 TIMEVAR (symout_time,
3357 {
3358 dbxout_finish (asm_out_file, main_input_filename);
3359 });
3360#endif
3361
3362#ifdef DWARF_DEBUGGING_INFO
3363 if (write_symbols == DWARF_DEBUG)
3364 TIMEVAR (symout_time,
3365 {
3366 dwarfout_finish ();
3367 });
3368#endif
3369
3370#ifdef DWARF2_UNWIND_INFO
3371 if (dwarf2out_do_frame ())
3372 dwarf2out_frame_finish ();
3373#endif
3374
3375#ifdef DWARF2_DEBUGGING_INFO
3376 if (write_symbols == DWARF2_DEBUG)
3377 TIMEVAR (symout_time,
3378 {
3379 dwarf2out_finish ();
3380 });
3381#endif
3382
3383 /* Output some stuff at end of file if nec. */
3384
3385 end_final (dump_base_name);
3386
3387 if (branch_prob_dump)
3388 open_dump_file (".bp", NULL);
3389
3390 TIMEVAR (dump_time, end_branch_prob (rtl_dump_file));
3391
3392 if (branch_prob_dump)
3393 close_dump_file (NULL, NULL_RTX);
3394
3395#ifdef ASM_FILE_END
3396 ASM_FILE_END (asm_out_file);
3397#endif
3398
3399
3400 /* Language-specific end of compilation actions. */
3401 finish_syntax:
3402 lang_finish ();
3403
3404 /* Close the dump files. */
3405
3406 if (flag_gen_aux_info)
3407 {
3408 fclose (aux_info_file);
3409 if (errorcount)
3410 unlink (aux_info_file_name);
3411 }
3412
3413 if (combine_dump)
3414 {
3415 open_dump_file (".combine", NULL);
3416 TIMEVAR (dump_time, dump_combine_total_stats (rtl_dump_file));
3417 close_dump_file (NULL, NULL_RTX);
3418 }
3419
3420 /* Close non-debugging input and output files. Take special care to note
3421 whether fclose returns an error, since the pages might still be on the
3422 buffer chain while the file is open. */
3423
3424 finish_parse ();
3425
3426 if (! flag_syntax_only
3427 && (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0))
3428 fatal_io_error (asm_file_name);
3429
3430 /* Do whatever is necessary to finish printing the graphs. */
3431 if (graph_dump_format != no_graph)
3432 {
3433 if (jump_opt_dump)
3434 finish_graph_dump_file (dump_base_name, ".jump");
3435 if (addressof_dump)
3436 finish_graph_dump_file (dump_base_name, ".addressof");
3437 if (cse_dump)
3438 finish_graph_dump_file (dump_base_name, ".cse");
3439 if (loop_dump)
3440 finish_graph_dump_file (dump_base_name, ".loop");
3441 if (cse2_dump)
3442 finish_graph_dump_file (dump_base_name, ".cse2");
3443 if (branch_prob_dump)
3444 finish_graph_dump_file (dump_base_name, ".bp");
3445 if (flow_dump)
3446 finish_graph_dump_file (dump_base_name, ".flow");
3447 if (combine_dump)
3448 finish_graph_dump_file (dump_base_name, ".combine");
3449 if (regmove_dump)
3450 finish_graph_dump_file (dump_base_name, ".regmove");
3451 if (sched_dump)
3452 finish_graph_dump_file (dump_base_name, ".sched");
3453 if (local_reg_dump)
3454 finish_graph_dump_file (dump_base_name, ".lreg");
3455 if (global_reg_dump)
3456 finish_graph_dump_file (dump_base_name, ".greg");
3457 if (flow2_dump)
3458 finish_graph_dump_file (dump_base_name, ".flow2");
3459 if (sched2_dump)
3460 finish_graph_dump_file (dump_base_name, ".sched2");
3461 if (jump2_opt_dump)
3462 finish_graph_dump_file (dump_base_name, ".jump2");
3463#ifdef DELAY_SLOTS
3464 if (dbr_sched_dump)
3465 finish_graph_dump_file (dump_base_name, ".dbr");
3466#endif
3467 if (gcse_dump)
3468 finish_graph_dump_file (dump_base_name, ".gcse");
3469#ifdef STACK_REGS
3470 if (stack_reg_dump)
3471 finish_graph_dump_file (dump_base_name, ".stack");
3472#endif
3473#ifdef MACHINE_DEPENDENT_REORG
3474 if (mach_dep_reorg_dump)
3475 finish_graph_dump_file (dump_base_name, ".mach");
3476#endif
3477 }
3478
3479 /* Free up memory for the benefit of leak detectors. */
3480 free_reg_info ();
3481
3482 /* Print the times. */
3483
3484 if (! quiet_flag)
3485 {
3486 fprintf (stderr,"\n");
3487 print_time ("parse", parse_time);
3488
3489 print_time ("integration", integration_time);
3490 print_time ("jump", jump_time);
3491 print_time ("cse", cse_time);
3492 print_time ("gcse", gcse_time);
3493 print_time ("loop", loop_time);
3494 print_time ("cse2", cse2_time);
3495 print_time ("branch-prob", branch_prob_time);
3496 print_time ("flow", flow_time);
3497 print_time ("combine", combine_time);
3498 print_time ("regmove", regmove_time);
3499 print_time ("sched", sched_time);
3500 print_time ("local-alloc", local_alloc_time);
3501 print_time ("global-alloc", global_alloc_time);
3502 print_time ("flow2", flow2_time);
3503 print_time ("sched2", sched2_time);
3504#ifdef DELAY_SLOTS
3505 print_time ("dbranch", dbr_sched_time);
3506#endif
3507 print_time ("shorten-branch", shorten_branch_time);
3508 print_time ("stack-reg", stack_reg_time);
3509 print_time ("final", final_time);
3510 print_time ("varconst", varconst_time);
3511 print_time ("symout", symout_time);
3512 print_time ("dump", dump_time);
3513 }
3514}
3515\f
3516/* This is called from various places for FUNCTION_DECL, VAR_DECL,
3517 and TYPE_DECL nodes.
3518
3519 This does nothing for local (non-static) variables.
3520 Otherwise, it sets up the RTL and outputs any assembler code
3521 (label definition, storage allocation and initialization).
3522
3523 DECL is the declaration. If ASMSPEC is nonzero, it specifies
3524 the assembler symbol name to be used. TOP_LEVEL is nonzero
3525 if this declaration is not within a function. */
3526
3527void
3528rest_of_decl_compilation (decl, asmspec, top_level, at_end)
3529 tree decl;
3530 const char *asmspec;
3531 int top_level;
3532 int at_end;
3533{
3534 /* Declarations of variables, and of functions defined elsewhere. */
3535
3536/* The most obvious approach, to put an #ifndef around where
3537 this macro is used, doesn't work since it's inside a macro call. */
3538#ifndef ASM_FINISH_DECLARE_OBJECT
3539#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
3540#endif
3541
3542 /* Forward declarations for nested functions are not "external",
3543 but we need to treat them as if they were. */
3544 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
3545 || TREE_CODE (decl) == FUNCTION_DECL)
3546 TIMEVAR (varconst_time,
3547 {
3548 make_decl_rtl (decl, asmspec, top_level);
3549 /* Initialized extern variable exists to be replaced
3550 with its value, or represents something that will be
3551 output in another file. */
3552 if (! (TREE_CODE (decl) == VAR_DECL
3553 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
3554 && DECL_INITIAL (decl) != 0
3555 && DECL_INITIAL (decl) != error_mark_node))
3556 /* Don't output anything
3557 when a tentative file-scope definition is seen.
3558 But at end of compilation, do output code for them. */
3559 if (! (! at_end && top_level
3560 && (DECL_INITIAL (decl) == 0
3561 || DECL_INITIAL (decl) == error_mark_node)))
3562 assemble_variable (decl, top_level, at_end, 0);
3563 if (decl == last_assemble_variable_decl)
3564 {
3565 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
3566 top_level, at_end);
3567 }
3568 });
3569 else if (DECL_REGISTER (decl) && asmspec != 0)
3570 {
3571 if (decode_reg_name (asmspec) >= 0)
3572 {
3573 DECL_RTL (decl) = 0;
3574 make_decl_rtl (decl, asmspec, top_level);
3575 }
3576 else
3577 error ("invalid register name `%s' for register variable", asmspec);
3578 }
3579#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3580 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3581 && TREE_CODE (decl) == TYPE_DECL)
3582 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
3583#endif
3584#ifdef SDB_DEBUGGING_INFO
3585 else if (write_symbols == SDB_DEBUG && top_level
3586 && TREE_CODE (decl) == TYPE_DECL)
3587 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
3588#endif
3589}
3590
3591/* Called after finishing a record, union or enumeral type. */
3592
3593void
3594rest_of_type_compilation (type, toplev)
3595#if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) || defined (SDB_DEBUGGING_INFO)
3596 tree type;
3597 int toplev;
3598#else
3599 tree type ATTRIBUTE_UNUSED;
3600 int toplev ATTRIBUTE_UNUSED;
3601#endif
3602{
3603#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
3604 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
3605 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
3606#endif
3607#ifdef SDB_DEBUGGING_INFO
3608 if (write_symbols == SDB_DEBUG)
3609 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
3610#endif
3611}
3612
3613/* This is called from finish_function (within yyparse)
3614 after each top-level definition is parsed.
3615 It is supposed to compile that function or variable
3616 and output the assembler code for it.
3617 After we return, the tree storage is freed. */
3618
3619void
3620rest_of_compilation (decl)
3621 tree decl;
3622{
3623 register rtx insns;
3624 int start_time = get_run_time ();
3625 int tem;
3626 /* Nonzero if we have saved the original DECL_INITIAL of the function,
3627 to be restored after we finish compiling the function
3628 (for use when compiling inline calls to this function). */
3629 tree saved_block_tree = 0;
3630 /* Likewise, for DECL_ARGUMENTS. */
3631 tree saved_arguments = 0;
3632 int failure = 0;
3633 int rebuild_label_notes_after_reload;
3634
3635 /* If we are reconsidering an inline function
3636 at the end of compilation, skip the stuff for making it inline. */
3637
3638 if (DECL_SAVED_INSNS (decl) == 0)
3639 {
3640 int inlinable = 0;
3641 const char *lose;
3642
3643 /* If requested, consider whether to make this function inline. */
3644 if (DECL_INLINE (decl) || flag_inline_functions)
3645 TIMEVAR (integration_time,
3646 {
3647 lose = function_cannot_inline_p (decl);
3648 if (lose || ! optimize)
3649 {
3650 if (warn_inline && DECL_INLINE (decl))
3651 warning_with_decl (decl, lose);
3652 DECL_ABSTRACT_ORIGIN (decl) = 0;
3653 /* Don't really compile an extern inline function.
3654 If we can't make it inline, pretend
3655 it was only declared. */
3656 if (DECL_EXTERNAL (decl))
3657 {
3658 DECL_INITIAL (decl) = 0;
3659 goto exit_rest_of_compilation;
3660 }
3661 }
3662 else
3663 /* ??? Note that this has the effect of making it look
3664 like "inline" was specified for a function if we choose
3665 to inline it. This isn't quite right, but it's
3666 probably not worth the trouble to fix. */
3667 inlinable = DECL_INLINE (decl) = 1;
3668 });
3669
3670 insns = get_insns ();
3671
3672 /* Dump the rtl code if we are dumping rtl. */
3673
3674 if (rtl_dump)
3675 {
3676 open_dump_file (".rtl", decl_printable_name (decl, 2));
3677
3678 if (DECL_SAVED_INSNS (decl))
3679 fprintf (rtl_dump_file, ";; (integrable)\n\n");
3680
3681 close_dump_file (print_rtl, insns);
3682 }
3683
3684 /* If we can, defer compiling inlines until EOF.
3685 save_for_inline_copying can be extremely expensive. */
3686 if (inlinable && ! decl_function_context (decl))
3687 DECL_DEFER_OUTPUT (decl) = 1;
3688
3689 /* If function is inline, and we don't yet know whether to
3690 compile it by itself, defer decision till end of compilation.
3691 finish_compilation will call rest_of_compilation again
3692 for those functions that need to be output. Also defer those
3693 functions that we are supposed to defer. We cannot defer
3694 functions containing nested functions since the nested function
3695 data is in our non-saved obstack. We cannot defer nested
3696 functions for the same reason. */
3697
3698 /* If this is a nested inline, remove ADDRESSOF now so we can
3699 finish compiling ourselves. Otherwise, wait until EOF.
3700 We have to do this because the purge_addressof transformation
3701 changes the DECL_RTL for many variables, which confuses integrate. */
3702 if (inlinable)
3703 {
3704 if (decl_function_context (decl))
3705 purge_addressof (insns);
3706 else
3707 DECL_DEFER_OUTPUT (decl) = 1;
3708 }
3709
3710 if (! current_function_contains_functions
3711 && (DECL_DEFER_OUTPUT (decl)
3712 || (DECL_INLINE (decl)
3713 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3714 && ! flag_keep_inline_functions)
3715 || DECL_EXTERNAL (decl)))))
3716 {
3717 DECL_DEFER_OUTPUT (decl) = 1;
3718
3719 /* If -Wreturn-type, we have to do a bit of compilation.
3720 However, if we just fall through we will call
3721 save_for_inline_copying() which results in excessive
3722 memory use. Instead, we just want to call
3723 jump_optimize() to figure out whether or not we can fall
3724 off the end of the function; we do the minimum amount of
3725 work necessary to make that safe. And, we set optimize
3726 to zero to keep jump_optimize from working too hard. */
3727 if (warn_return_type)
3728 {
3729 int saved_optimize = optimize;
3730 optimize = 0;
3731 find_exception_handler_labels ();
3732 jump_optimize (get_insns(), !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3733 !JUMP_AFTER_REGSCAN);
3734 optimize = saved_optimize;
3735 }
3736
3737#ifdef DWARF_DEBUGGING_INFO
3738 /* Generate the DWARF info for the "abstract" instance
3739 of a function which we may later generate inlined and/or
3740 out-of-line instances of. */
3741 if (write_symbols == DWARF_DEBUG)
3742 {
3743 set_decl_abstract_flags (decl, 1);
3744 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3745 set_decl_abstract_flags (decl, 0);
3746 }
3747#endif
3748#ifdef DWARF2_DEBUGGING_INFO
3749 /* Generate the DWARF2 info for the "abstract" instance
3750 of a function which we may later generate inlined and/or
3751 out-of-line instances of. */
3752 if (write_symbols == DWARF2_DEBUG)
3753 {
3754 set_decl_abstract_flags (decl, 1);
3755 TIMEVAR (symout_time, dwarf2out_decl (decl));
3756 set_decl_abstract_flags (decl, 0);
3757 }
3758#endif
3759 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3760 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
3761 goto exit_rest_of_compilation;
3762 }
3763
3764 /* If we have to compile the function now, save its rtl and subdecls
3765 so that its compilation will not affect what others get. */
3766 if (inlinable || DECL_DEFER_OUTPUT (decl))
3767 {
3768#ifdef DWARF_DEBUGGING_INFO
3769 /* Generate the DWARF info for the "abstract" instance of
3770 a function which we will generate an out-of-line instance
3771 of almost immediately (and which we may also later generate
3772 various inlined instances of). */
3773 if (write_symbols == DWARF_DEBUG)
3774 {
3775 set_decl_abstract_flags (decl, 1);
3776 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3777 set_decl_abstract_flags (decl, 0);
3778 }
3779#endif
3780#ifdef DWARF2_DEBUGGING_INFO
3781 /* Generate the DWARF2 info for the "abstract" instance of
3782 a function which we will generate an out-of-line instance
3783 of almost immediately (and which we may also later generate
3784 various inlined instances of). */
3785 if (write_symbols == DWARF2_DEBUG)
3786 {
3787 set_decl_abstract_flags (decl, 1);
3788 TIMEVAR (symout_time, dwarf2out_decl (decl));
3789 set_decl_abstract_flags (decl, 0);
3790 }
3791#endif
3792 saved_block_tree = DECL_INITIAL (decl);
3793 saved_arguments = DECL_ARGUMENTS (decl);
3794 TIMEVAR (integration_time, save_for_inline_copying (decl));
3795 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
3796 }
3797
3798 /* If specified extern inline but we aren't inlining it, we are
3799 done. This goes for anything that gets here with DECL_EXTERNAL
3800 set, not just things with DECL_INLINE. */
3801 if (DECL_EXTERNAL (decl))
3802 goto exit_rest_of_compilation;
3803 }
3804
3805 if (! DECL_DEFER_OUTPUT (decl))
3806 TREE_ASM_WRITTEN (decl) = 1;
3807
3808 /* Now that integrate will no longer see our rtl, we need not distinguish
3809 between the return value of this function and the return value of called
3810 functions. */
3811 rtx_equal_function_value_matters = 0;
3812
3813 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3814 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3815 {
3816 goto exit_rest_of_compilation;
3817 }
3818
3819 /* Emit code to get eh context, if needed. */
3820 emit_eh_context ();
3821
3822#ifdef FINALIZE_PIC
3823 /* If we are doing position-independent code generation, now
3824 is the time to output special prologues and epilogues.
3825 We do not want to do this earlier, because it just clutters
3826 up inline functions with meaningless insns. */
3827 if (flag_pic)
3828 FINALIZE_PIC;
3829#endif
3830
3831 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3832 Note that that may have been done above, in save_for_inline_copying.
3833 The call to resume_temporary_allocation near the end of this function
3834 goes back to the usual state of affairs. This must be done after
3835 we've built up any unwinders for exception handling, and done
3836 the FINALIZE_PIC work, if necessary. */
3837
3838 rtl_in_current_obstack ();
3839
3840 insns = get_insns ();
3841
3842 /* Copy any shared structure that should not be shared. */
3843
3844 unshare_all_rtl (current_function_decl, insns);
3845
3846#ifdef SETJMP_VIA_SAVE_AREA
3847 /* This must be performed before virutal register instantiation. */
3848 if (current_function_calls_alloca)
3849 optimize_save_area_alloca (insns);
3850#endif
3851
3852 /* Instantiate all virtual registers. */
3853
3854 instantiate_virtual_regs (current_function_decl, get_insns ());
3855
3856 /* See if we have allocated stack slots that are not directly addressable.
3857 If so, scan all the insns and create explicit address computation
3858 for all references to such slots. */
3859/* fixup_stack_slots (); */
3860
3861 /* Find all the EH handlers. */
3862 find_exception_handler_labels ();
3863
3864 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3865 are initialized and to compute whether control can drop off the end
3866 of the function. */
3867 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3868 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP, !JUMP_NOOP_MOVES,
3869 JUMP_AFTER_REGSCAN));
3870
3871 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3872 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3873 goto exit_rest_of_compilation;
3874
3875 /* Dump rtl code after jump, if we are doing that. */
3876
3877 if (jump_opt_dump)
3878 dump_rtl (".jump", decl, print_rtl, insns);
3879
3880 /* Perform common subexpression elimination.
3881 Nonzero value from `cse_main' means that jumps were simplified
3882 and some code may now be unreachable, so do
3883 jump optimization again. */
3884
3885 if (optimize > 0)
3886 {
3887 if (cse_dump)
3888 open_dump_file (".cse", decl_printable_name (decl, 2));
3889
3890 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3891
3892 if (flag_thread_jumps)
3893 /* Hacks by tiemann & kenner. */
3894 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
3895
3896 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3897 0, rtl_dump_file));
3898 if (tem || optimize > 1)
3899 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3900 !JUMP_NOOP_MOVES,
3901 !JUMP_AFTER_REGSCAN));
3902
3903 /* Run this after jump optmizations remove all the unreachable code
3904 so that unreachable code will not keep values live. */
3905 TIMEVAR (cse_time, delete_trivially_dead_insns (insns, max_reg_num ()));
3906
3907 /* Dump rtl code after cse, if we are doing that. */
3908
3909 if (cse_dump)
3910 {
3911 close_dump_file (print_rtl, insns);
3912 if (graph_dump_format != no_graph)
3913 print_rtl_graph_with_bb (dump_base_name, ".cse", insns);
3914 }
3915 }
3916
3917 purge_addressof (insns);
3918 reg_scan (insns, max_reg_num (), 1);
3919
3920 if (addressof_dump)
3921 {
3922 dump_rtl (".addressof", decl, print_rtl, insns);
3923 if (graph_dump_format != no_graph)
3924 print_rtl_graph_with_bb (dump_base_name, ".addressof", insns);
3925 }
3926
3927 /* Perform global cse. */
3928
3929 if (optimize > 0 && flag_gcse)
3930 {
3931 if (gcse_dump)
3932 open_dump_file (".gcse", IDENTIFIER_POINTER (DECL_NAME (decl)));
3933
3934 TIMEVAR (gcse_time, tem = gcse_main (insns, rtl_dump_file));
3935
3936 /* If gcse altered any jumps, rerun jump optimizations to clean
3937 things up. */
3938 if (tem)
3939 {
3940 TIMEVAR (jump_time, jump_optimize (insns, !JUMP_CROSS_JUMP,
3941 !JUMP_NOOP_MOVES,
3942 !JUMP_AFTER_REGSCAN));
3943 }
3944
3945 if (gcse_dump)
3946 {
3947 close_dump_file (print_rtl, insns);
3948 if (graph_dump_format != no_graph)
3949 print_rtl_graph_with_bb (dump_base_name, ".gcse", insns);
3950 }
3951 }
3952 /* Move constant computations out of loops. */
3953
3954 if (optimize > 0)
3955 {
3956 if (loop_dump)
3957 open_dump_file (".loop", decl_printable_name (decl, 2));
3958
3959 TIMEVAR
3960 (loop_time,
3961 {
3962 if (flag_rerun_loop_opt)
3963 {
3964 /* We only want to perform unrolling once. */
3965
3966 loop_optimize (insns, rtl_dump_file, 0, 0);
3967
3968
3969 /* The first call to loop_optimize makes some instructions
3970 trivially dead. We delete those instructions now in the
3971 hope that doing so will make the heuristics in loop work
3972 better and possibly speed up compilation. */
3973