]> gcc.gnu.org Git - gcc.git/blame - gcc/toplev.c
configure.in (build_xm_file): Add auto-config.h if host=build.
[gcc.git] / gcc / toplev.c
CommitLineData
4291d9c8 1/* Top level of GNU C compiler
5ae3bec5 2 Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.
4291d9c8
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
4291d9c8 20
4291d9c8
RS
21/* This is the top level of cc1/c++.
22 It parses command args, opens files, invokes the various passes
23 in the proper order, and counts the time used by each.
24 Error messages and low-level interface to malloc also handled here. */
25
26#include "config.h"
e0e2a8da 27#ifdef __STDC__
04fe4385 28#include <stdarg.h>
e0e2a8da 29#else
04fe4385 30#include <varargs.h>
e0e2a8da 31#endif
4291d9c8
RS
32#include <stdio.h>
33#include <signal.h>
34#include <setjmp.h>
eb711c86 35#include <sys/types.h>
ea9182cd 36#include <ctype.h>
4291d9c8 37#include <sys/stat.h>
4291d9c8 38#undef FLOAT
956d6950 39#ifdef HAVE_SYS_PARAM_H
4291d9c8 40#include <sys/param.h>
956d6950 41#endif
c5d0345e
RH
42#ifdef HAVE_UNISTD_H
43#include <unistd.h>
44#endif
956d6950
JL
45
46#undef FLOAT /* This is for hpux. They should change hpux. */
4291d9c8 47#undef FFS /* Some systems define this in param.h. */
956d6950
JL
48
49#ifdef TIME_WITH_SYS_TIME
50# include <sys/time.h>
51# include <time.h>
4291d9c8 52#else
956d6950
JL
53# if HAVE_SYS_TIME_H
54# include <sys/time.h>
55# else
56# include <time.h>
4291d9c8
RS
57#endif
58#endif
956d6950
JL
59
60#ifdef HAVE_SYS_RESOURCE_H
61# include <sys/resource.h>
62#endif
63
64#ifdef HAVE_SYS_TIMES_H
65# include <sys/times.h>
eb910b5a 66#endif
4291d9c8
RS
67
68#include "input.h"
69#include "tree.h"
4291d9c8
RS
70#include "rtl.h"
71#include "flags.h"
72#include "insn-attr.h"
d0d4af87 73#include "defaults.h"
e14417fa 74#include "output.h"
3d195391 75#include "except.h"
f246a305
RS
76
77#ifdef XCOFF_DEBUGGING_INFO
78#include "xcoffout.h"
79#endif
4291d9c8
RS
80\f
81#ifdef VMS
82/* The extra parameters substantially improve the I/O performance. */
83static FILE *
37c9f674 84vms_fopen (fname, type)
4291d9c8
RS
85 char * fname;
86 char * type;
87{
37c9f674
RK
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");
4291d9c8 98}
37c9f674
RK
99#define fopen vms_fopen
100#endif /* VMS */
4291d9c8
RS
101
102#ifndef DEFAULT_GDB_EXTENSIONS
103#define DEFAULT_GDB_EXTENSIONS 1
104#endif
105
30657ee3
RK
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. */
9a666dda 110#if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
30657ee3
RK
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
9a666dda
JM
125#ifdef DWARF2_DEBUGGING_INFO
126#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
127#endif
30657ee3
RK
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
4291d9c8
RS
139extern int rtx_equal_function_value_matters;
140
72c8bb7f 141#if ! (defined (VMS) || defined (OS2))
4291d9c8 142extern char **environ;
4d7e336b 143#endif
4291d9c8
RS
144extern char *version_string, *language_string;
145
b0316e35
RS
146/* Carry information from ASM_DECLARE_OBJECT_NAME
147 to ASM_FINISH_DECLARE_OBJECT. */
148
149extern int size_directive_output;
5e10b3cc 150extern tree last_assemble_variable_decl;
b0316e35 151
4291d9c8
RS
152extern void init_lex ();
153extern void init_decl_processing ();
154extern void init_obstacks ();
155extern void init_tree_codes ();
156extern void init_rtl ();
34d0205f 157extern void init_regs ();
4291d9c8
RS
158extern void init_optabs ();
159extern void init_stmt ();
160extern void init_reg_sets ();
161extern void dump_flow_info ();
162extern void dump_sched_info ();
163extern void dump_local_alloc ();
9ddca353 164extern void regset_release_memory ();
4291d9c8
RS
165
166void rest_of_decl_compilation ();
d18225c4
RK
167void error_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
168void error_with_decl PVPROTO((tree decl, char *s, ...));
169void error_for_asm PVPROTO((rtx insn, char *s, ...));
170void error PVPROTO((char *s, ...));
171void fatal PVPROTO((char *s, ...));
172void warning_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
173void warning_with_decl PVPROTO((tree decl, char *s, ...));
174void warning_for_asm PVPROTO((rtx insn, char *s, ...));
175void warning PVPROTO((char *s, ...));
176void pedwarn PVPROTO((char *s, ...));
177void pedwarn_with_decl PVPROTO((tree decl, char *s, ...));
178void pedwarn_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
179void sorry PVPROTO((char *s, ...));
180void really_sorry PVPROTO((char *s, ...));
4291d9c8
RS
181void fancy_abort ();
182#ifndef abort
183void abort ();
184#endif
185void set_target_switch ();
4291d9c8
RS
186static char *decl_name ();
187
3d5cdd42
DE
188void print_version ();
189int print_single_switch ();
190void print_switch_values ();
191/* Length of line when printing switch values. */
192#define MAX_LINE 75
193
c5d0345e 194#ifdef NEED_DECLARATION_SBRK
efa00f4e
RK
195extern char *sbrk ();
196#endif
197
4291d9c8
RS
198/* Name of program invoked, sans directories. */
199
200char *progname;
201
202/* Copy of arguments to main. */
203int save_argc;
204char **save_argv;
205\f
206/* Name of current original source file (what was input to cpp).
207 This comes from each #-command in the actual input. */
208
209char *input_filename;
210
211/* Name of top-level original source file (what was input to cpp).
212 This comes from the #-command at the beginning of the actual input.
213 If there isn't any there, then this is the cc1 input file name. */
214
215char *main_input_filename;
216
e3d1fd32 217#if !USE_CPPLIB
4291d9c8 218/* Stream for reading from the input file. */
4291d9c8 219FILE *finput;
e3d1fd32 220#endif
4291d9c8
RS
221
222/* Current line number in real source file. */
223
224int lineno;
225
226/* Stack of currently pending input files. */
227
228struct file_stack *input_file_stack;
229
230/* Incremented on each change to input_file_stack. */
231int input_file_stack_tick;
232
233/* FUNCTION_DECL for function now being parsed or compiled. */
234
235extern tree current_function_decl;
236
237/* Name to use as base of names for dump output files. */
238
239char *dump_base_name;
240
241/* Bit flags that specify the machine subtype we are compiling for.
242 Bits are tested using macros TARGET_... defined in the tm.h file
243 and set by `-m...' switches. Must be defined in rtlanal.c. */
244
245extern int target_flags;
246
247/* Flags saying which kinds of debugging dump have been requested. */
248
249int rtl_dump = 0;
250int rtl_dump_and_exit = 0;
251int jump_opt_dump = 0;
e9a25f70 252int addressof_dump = 0;
4291d9c8
RS
253int cse_dump = 0;
254int loop_dump = 0;
255int cse2_dump = 0;
0d332add 256int branch_prob_dump = 0;
4291d9c8
RS
257int flow_dump = 0;
258int combine_dump = 0;
8c660648 259int regmove_dump = 0;
4291d9c8
RS
260int sched_dump = 0;
261int local_reg_dump = 0;
262int global_reg_dump = 0;
263int sched2_dump = 0;
264int jump2_opt_dump = 0;
265int dbr_sched_dump = 0;
266int flag_print_asm_name = 0;
267int stack_reg_dump = 0;
268
269/* Name for output file of assembly code, specified with -o. */
270
271char *asm_file_name;
272
273/* Value of the -G xx switch, and whether it was passed or not. */
274int g_switch_value;
275int g_switch_set;
276
277/* Type(s) of debugging information we are producing (if any).
278 See flags.h for the definitions of the different possible
279 types of debugging information. */
280enum debug_info_type write_symbols = NO_DEBUG;
281
282/* Level of debugging information we are producing. See flags.h
283 for the definitions of the different possible levels. */
284enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
285
a53d0bcc
RS
286/* Nonzero means use GNU-only extensions in the generated symbolic
287 debugging information. */
288/* Currently, this only has an effect when write_symbols is set to
289 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
290int use_gnu_debug_info_extensions = 0;
4291d9c8
RS
291
292/* Nonzero means do optimizations. -O.
293 Particular numeric values stand for particular amounts of optimization;
294 thus, -O2 stores 2 here. However, the optimizations beyond the basic
295 ones are not controlled directly by this variable. Instead, they are
296 controlled by individual `flag_...' variables that are defaulted
297 based on this variable. */
298
299int optimize = 0;
300
301/* Number of error messages and warning messages so far. */
302
303int errorcount = 0;
304int warningcount = 0;
305int sorrycount = 0;
306
a1d7ffe3
JM
307/* Pointer to function to compute the name to use to print a declaration.
308 DECL is the declaration in question.
309 VERBOSITY determines what information will be printed:
310 0: DECL_NAME, demangled as necessary.
311 1: and scope information.
312 2: and any other information that might be interesting, such as function
313 parameter types in C++. */
4291d9c8 314
a1d7ffe3 315char *(*decl_printable_name) (/* tree decl, int verbosity */);
4291d9c8
RS
316
317/* Pointer to function to compute rtl for a language-specific tree code. */
318
319struct rtx_def *(*lang_expand_expr) ();
320
2b599527
RS
321/* Pointer to function to finish handling an incomplete decl at the
322 end of compilation. */
323
324void (*incomplete_decl_finalize_hook) () = 0;
325
bf8b4985
RK
326/* Highest label number used at the end of reload. */
327
328int max_label_num_after_reload;
329
4291d9c8
RS
330/* Nonzero if generating code to do profiling. */
331
332int profile_flag = 0;
333
334/* Nonzero if generating code to do profiling on a line-by-line basis. */
335
336int profile_block_flag;
337
0d332add
DE
338/* Nonzero if generating code to profile program flow graph arcs. */
339
340int profile_arc_flag = 0;
341
342/* Nonzero if generating info for gcov to calculate line test coverage. */
343
344int flag_test_coverage = 0;
345
346/* Nonzero indicates that branch taken probabilities should be calculated. */
347
348int flag_branch_probabilities = 0;
349
4291d9c8
RS
350/* Nonzero for -pedantic switch: warn about anything
351 that standard spec forbids. */
352
353int pedantic = 0;
354
355/* Temporarily suppress certain warnings.
356 This is set while reading code from a system header file. */
357
358int in_system_header = 0;
359
360/* Nonzero means do stupid register allocation.
361 Currently, this is 1 if `optimize' is 0. */
362
363int obey_regdecls = 0;
364
365/* Don't print functions as they are compiled and don't print
366 times taken by the various passes. -quiet. */
367
368int quiet_flag = 0;
369\f
370/* -f flags. */
371
372/* Nonzero means `char' should be signed. */
373
374int flag_signed_char;
375
376/* Nonzero means give an enum type only as many bytes as it needs. */
377
378int flag_short_enums;
379
380/* Nonzero for -fcaller-saves: allocate values in regs that need to
381 be saved across function calls, if that produces overall better code.
382 Optional now, so people can test it. */
383
384#ifdef DEFAULT_CALLER_SAVES
385int flag_caller_saves = 1;
386#else
387int flag_caller_saves = 0;
388#endif
389
958ec8ca
JW
390/* Nonzero if structures and unions should be returned in memory.
391
392 This should only be defined if compatibility with another compiler or
393 with an ABI is needed, because it results in slower code. */
394
395#ifndef DEFAULT_PCC_STRUCT_RETURN
396#define DEFAULT_PCC_STRUCT_RETURN 1
397#endif
398
4291d9c8
RS
399/* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
400
958ec8ca 401int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
4291d9c8
RS
402
403/* Nonzero for -fforce-mem: load memory value into a register
404 before arithmetic on it. This makes better cse but slower compilation. */
405
406int flag_force_mem = 0;
407
408/* Nonzero for -fforce-addr: load memory address into a register before
409 reference to memory. This makes better cse but slower compilation. */
410
411int flag_force_addr = 0;
412
413/* Nonzero for -fdefer-pop: don't pop args after each function call;
414 instead save them up to pop many calls' args with one insns. */
415
6731a3e3 416int flag_defer_pop = 0;
4291d9c8
RS
417
418/* Nonzero for -ffloat-store: don't allocate floats and doubles
419 in extended-precision registers. */
420
421int flag_float_store = 0;
422
423/* Nonzero for -fcse-follow-jumps:
424 have cse follow jumps to do a more extensive job. */
425
426int flag_cse_follow_jumps;
427
8b3686ed
RK
428/* Nonzero for -fcse-skip-blocks:
429 have cse follow a branch around a block. */
430int flag_cse_skip_blocks;
431
4291d9c8
RS
432/* Nonzero for -fexpensive-optimizations:
433 perform miscellaneous relatively-expensive optimizations. */
434int flag_expensive_optimizations;
435
436/* Nonzero for -fthread-jumps:
437 have jump optimize output of loop. */
438
439int flag_thread_jumps;
440
441/* Nonzero enables strength-reduction in loop.c. */
442
443int flag_strength_reduce = 0;
444
445/* Nonzero enables loop unrolling in unroll.c. Only loops for which the
446 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
447 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
448 unrolled. */
449
450int flag_unroll_loops;
451
452/* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
453 This is generally not a win. */
454
455int flag_unroll_all_loops;
456
e5eb27e5
JL
457/* Nonzero forces all invariant computations in loops to be moved
458 outside the loop. */
459
460int flag_move_all_movables = 0;
461
462/* Nonzero forces all general induction variables in loops to be
463 strength reduced. */
464
465int flag_reduce_all_givs = 0;
466
4291d9c8
RS
467/* Nonzero for -fwritable-strings:
468 store string constants in data segment and don't uniquize them. */
469
470int flag_writable_strings = 0;
471
472/* Nonzero means don't put addresses of constant functions in registers.
473 Used for compiling the Unix kernel, where strange substitutions are
474 done on the assembly output. */
475
476int flag_no_function_cse = 0;
477
478/* Nonzero for -fomit-frame-pointer:
479 don't make a frame pointer in simple functions that don't require one. */
480
481int flag_omit_frame_pointer = 0;
482
cf440348
JL
483/* Nonzero means place each function into its own section on those platforms
484 which support arbitrary section names and unlimited numbers of sections. */
485
486int flag_function_sections = 0;
487
4291d9c8
RS
488/* Nonzero to inhibit use of define_optimization peephole opts. */
489
490int flag_no_peephole = 0;
491
43855b28
JL
492/* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
493 operations in the interest of optimization. For example it allows
494 GCC to assume arguments to sqrt are nonnegative numbers, allowing
0f41302f 495 faster code for sqrt to be generated. */
43855b28
JL
496
497int flag_fast_math = 0;
498
4291d9c8
RS
499/* Nonzero means all references through pointers are volatile. */
500
501int flag_volatile;
c6e75897
RS
502
503/* Nonzero means treat all global and extern variables as global. */
504
38d4d0c2 505int flag_volatile_global;
4291d9c8
RS
506
507/* Nonzero means just do syntax checking; don't output anything. */
508
509int flag_syntax_only = 0;
510
511/* Nonzero means to rerun cse after loop optimization. This increases
512 compilation time about 20% and picks up a few more common expressions. */
513
514static int flag_rerun_cse_after_loop;
515
6d6d0fa0
JL
516/* Nonzero means to run loop optimizations twice. */
517
64fde701 518int flag_rerun_loop_opt;
6d6d0fa0 519
4291d9c8
RS
520/* Nonzero for -finline-functions: ok to inline functions that look like
521 good inline candidates. */
522
523int flag_inline_functions;
524
525/* Nonzero for -fkeep-inline-functions: even if we make a function
ac2a9454 526 go inline everywhere, keep its definition around for debugging
4291d9c8
RS
527 purposes. */
528
529int flag_keep_inline_functions;
530
fadb3bc9 531/* Nonzero means that functions will not be inlined. */
4291d9c8
RS
532
533int flag_no_inline;
534
fbe912dd
BK
535/* Nonzero means that we should emit static const variables
536 regardless of whether or not optimization is turned on. */
537
538int flag_keep_static_consts = 1;
539
4291d9c8
RS
540/* Nonzero means we should be saving declaration info into a .X file. */
541
542int flag_gen_aux_info = 0;
543
f246a305
RS
544/* Specified name of aux-info file. */
545
546static char *aux_info_file_name;
547
4291d9c8
RS
548/* Nonzero means make the text shared if supported. */
549
550int flag_shared_data;
551
552/* Nonzero means schedule into delayed branch slots if supported. */
553
554int flag_delayed_branch;
555
556/* Nonzero if we are compiling pure (sharable) code.
557 Value is 1 if we are doing reasonable (i.e. simple
558 offset into offset table) pic. Value is 2 if we can
559 only perform register offsets. */
560
561int flag_pic;
562
3d195391
MS
563/* Nonzero means generate extra code for exception handling and enable
564 exception handling. */
565
56bf1fd9 566int flag_exceptions = 2;
3d195391 567
2786cbad 568/* Nonzero means don't place uninitialized global data in common storage
3d195391 569 by default. */
4291d9c8
RS
570
571int flag_no_common;
572
573/* Nonzero means pretend it is OK to examine bits of target floats,
574 even if that isn't true. The resulting code will have incorrect constants,
575 but the same series of instructions that the native compiler would make. */
576
577int flag_pretend_float;
578
579/* Nonzero means change certain warnings into errors.
580 Usually these are warnings about failure to conform to some standard. */
581
582int flag_pedantic_errors = 0;
583
584/* flag_schedule_insns means schedule insns within basic blocks (before
585 local_alloc).
586 flag_schedule_insns_after_reload means schedule insns after
587 global_alloc. */
588
589int flag_schedule_insns = 0;
590int flag_schedule_insns_after_reload = 0;
591
8c660648
JL
592#ifdef HAIFA
593/* The following flags have effect only for scheduling before register
594 allocation:
595
596 flag_schedule_interblock means schedule insns accross basic blocks.
597 flag_schedule_speculative means allow speculative motion of non-load insns.
598 flag_schedule_speculative_load means allow speculative motion of some
599 load insns.
600 flag_schedule_speculative_load_dangerous allows speculative motion of more
601 load insns.
602 flag_schedule_reverse_before_reload means try to reverse original order
603 of insns (S).
604 flag_schedule_reverse_after_reload means try to reverse original order
605 of insns (R). */
606
607int flag_schedule_interblock = 1;
608int flag_schedule_speculative = 1;
609int flag_schedule_speculative_load = 0;
610int flag_schedule_speculative_load_dangerous = 0;
611int flag_schedule_reverse_before_reload = 0;
612int flag_schedule_reverse_after_reload = 0;
613
614
615/* flag_on_branch_count_reg means try to replace add-1,compare,branch tupple
616 by a cheaper branch, on a count register. */
617int flag_branch_on_count_reg;
618#endif /* HAIFA */
619
620
4291d9c8
RS
621/* -finhibit-size-directive inhibits output of .size for ELF.
622 This is used only for compiling crtstuff.c,
623 and it may be extended to other effects
624 needed for crtstuff.c on other systems. */
625int flag_inhibit_size_directive = 0;
626
9a631e8e
RS
627/* -fverbose-asm causes extra commentary information to be produced in
628 the generated assembly code (to make it more readable). This option
629 is generally only of use to those who actually need to read the
3d5cdd42 630 generated assembly code (perhaps while debugging the compiler itself).
c85f7c16 631 -fno-verbose-asm, the default, causes the extra information
3d5cdd42
DE
632 to be omitted and is useful when comparing two assembler files. */
633
c85f7c16 634int flag_verbose_asm = 0;
9a631e8e 635
3d5cdd42
DE
636/* -dA causes debug commentary information to be produced in
637 the generated assembly code (to make it more readable). This option
638 is generally only of use to those who actually need to read the
639 generated assembly code (perhaps while debugging the compiler itself).
640 Currently, this switch is only used by dwarfout.c; however, it is intended
641 to be a catchall for printing debug information in the assembler file. */
642
643int flag_debug_asm = 0;
9a631e8e 644
4291d9c8 645/* -fgnu-linker specifies use of the GNU linker for initializations.
d68c507d
RS
646 (Or, more generally, a linker that handles initializations.)
647 -fno-gnu-linker says that collect2 will be used. */
648#ifdef USE_COLLECT2
649int flag_gnu_linker = 0;
650#else
4291d9c8 651int flag_gnu_linker = 1;
d68c507d 652#endif
4291d9c8 653
566cdc73
MM
654/* Tag all structures with __attribute__(packed) */
655int flag_pack_struct = 0;
656
bd83d0ac
RK
657/* Emit code to check for stack overflow; also may cause large objects
658 to be allocated dynamically. */
659int flag_stack_check;
660
f602c208
RK
661/* -fcheck-memory-usage causes extra code to be generated in order to check
662 memory accesses. This is used by a detector of bad memory accesses such
663 as Checker. */
664int flag_check_memory_usage = 0;
665
666/* -fprefix-function-name causes function name to be prefixed. This
667 can be used with -fcheck-memory-usage to isolate code compiled with
668 -fcheck-memory-usage. */
669int flag_prefix_function_name = 0;
670
8c660648
JL
671int flag_regmove = 0;
672
9ae8ffe7
JL
673/* 0 if pointer arguments may alias each other. True in C.
674 1 if pointer arguments may not alias each other but may alias
675 global variables.
676 2 if pointer arguments may not alias each other and may not
677 alias global variables. True in Fortran.
678 This defaults to 0 for C. */
679int flag_argument_noalias = 0;
680
4291d9c8
RS
681/* Table of language-independent -f options.
682 STRING is the option name. VARIABLE is the address of the variable.
683 ON_VALUE is the value to store in VARIABLE
684 if `-fSTRING' is seen as an option.
685 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
686
687struct { char *string; int *variable; int on_value;} f_options[] =
688{
689 {"float-store", &flag_float_store, 1},
690 {"volatile", &flag_volatile, 1},
38d4d0c2 691 {"volatile-global", &flag_volatile_global, 1},
4291d9c8
RS
692 {"defer-pop", &flag_defer_pop, 1},
693 {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
694 {"cse-follow-jumps", &flag_cse_follow_jumps, 1},
8b3686ed 695 {"cse-skip-blocks", &flag_cse_skip_blocks, 1},
4291d9c8
RS
696 {"expensive-optimizations", &flag_expensive_optimizations, 1},
697 {"thread-jumps", &flag_thread_jumps, 1},
698 {"strength-reduce", &flag_strength_reduce, 1},
699 {"unroll-loops", &flag_unroll_loops, 1},
700 {"unroll-all-loops", &flag_unroll_all_loops, 1},
e5eb27e5
JL
701 {"move-all-movables", &flag_move_all_movables, 1},
702 {"reduce-all-givs", &flag_reduce_all_givs, 1},
4291d9c8
RS
703 {"writable-strings", &flag_writable_strings, 1},
704 {"peephole", &flag_no_peephole, 0},
705 {"force-mem", &flag_force_mem, 1},
706 {"force-addr", &flag_force_addr, 1},
707 {"function-cse", &flag_no_function_cse, 0},
708 {"inline-functions", &flag_inline_functions, 1},
709 {"keep-inline-functions", &flag_keep_inline_functions, 1},
710 {"inline", &flag_no_inline, 0},
fbe912dd 711 {"keep-static-consts", &flag_keep_static_consts, 1},
4291d9c8 712 {"syntax-only", &flag_syntax_only, 1},
4291d9c8
RS
713 {"shared-data", &flag_shared_data, 1},
714 {"caller-saves", &flag_caller_saves, 1},
715 {"pcc-struct-return", &flag_pcc_struct_return, 1},
958ec8ca 716 {"reg-struct-return", &flag_pcc_struct_return, 0},
4291d9c8
RS
717 {"delayed-branch", &flag_delayed_branch, 1},
718 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1},
6d6d0fa0 719 {"rerun-loop-opt", &flag_rerun_loop_opt, 1},
4291d9c8
RS
720 {"pretend-float", &flag_pretend_float, 1},
721 {"schedule-insns", &flag_schedule_insns, 1},
722 {"schedule-insns2", &flag_schedule_insns_after_reload, 1},
8c660648
JL
723#ifdef HAIFA
724 {"sched-interblock",&flag_schedule_interblock, 1},
725 {"sched-spec",&flag_schedule_speculative, 1},
726 {"sched-spec-load",&flag_schedule_speculative_load, 1},
727 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1},
728 {"sched-reverse-S",&flag_schedule_reverse_before_reload, 1},
729 {"sched-reverse-R",&flag_schedule_reverse_after_reload, 1},
730 {"branch-count-reg",&flag_branch_on_count_reg, 1},
731#endif /* HAIFA */
4291d9c8
RS
732 {"pic", &flag_pic, 1},
733 {"PIC", &flag_pic, 2},
3d195391 734 {"exceptions", &flag_exceptions, 1},
e976b8b2
MS
735 {"sjlj-exceptions", &exceptions_via_longjmp, 1},
736 {"asynchronous-exceptions", &asynchronous_exceptions, 1},
0d332add
DE
737 {"profile-arcs", &profile_arc_flag, 1},
738 {"test-coverage", &flag_test_coverage, 1},
739 {"branch-probabilities", &flag_branch_probabilities, 1},
43855b28 740 {"fast-math", &flag_fast_math, 1},
4291d9c8
RS
741 {"common", &flag_no_common, 0},
742 {"inhibit-size-directive", &flag_inhibit_size_directive, 1},
cf440348 743 {"function-sections", &flag_function_sections, 1},
9a631e8e 744 {"verbose-asm", &flag_verbose_asm, 1},
422e2ed3 745 {"gnu-linker", &flag_gnu_linker, 1},
8c660648 746 {"regmove", &flag_regmove, 1},
566cdc73 747 {"pack-struct", &flag_pack_struct, 1},
bd83d0ac 748 {"stack-check", &flag_stack_check, 1},
9ae8ffe7
JL
749 {"argument-alias", &flag_argument_noalias, 0},
750 {"argument-noalias", &flag_argument_noalias, 1},
751 {"argument-noalias-global", &flag_argument_noalias, 2},
f602c208
RK
752 {"check-memory-usage", &flag_check_memory_usage, 1},
753 {"prefix-function-name", &flag_prefix_function_name, 1}
4291d9c8 754};
b99933c7
RS
755
756/* Table of language-specific options. */
757
758char *lang_options[] =
759{
4200c8de 760 "-ansi",
8305445b 761 "-fallow-single-precision",
4200c8de 762
b99933c7
RS
763 "-fsigned-bitfields",
764 "-funsigned-bitfields",
765 "-fno-signed-bitfields",
766 "-fno-unsigned-bitfields",
4200c8de
RK
767 "-fsigned-char",
768 "-funsigned-char",
769 "-fno-signed-char",
770 "-fno-unsigned-char",
771
772 "-ftraditional",
773 "-traditional",
774 "-fnotraditional",
775 "-fno-traditional",
776
b99933c7
RS
777 "-fasm",
778 "-fno-asm",
779 "-fbuiltin",
780 "-fno-builtin",
5ae3bec5
RK
781 "-fhosted",
782 "-fno-hosted",
783 "-ffreestanding",
784 "-fno-freestanding",
4200c8de
RK
785 "-fcond-mismatch",
786 "-fno-cond-mismatch",
c7daad38 787 "-fdollars-in-identifiers",
57f0a224 788 "-fno-dollars-in-identifiers",
4200c8de
RK
789 "-fident",
790 "-fno-ident",
791 "-fshort-double",
792 "-fno-short-double",
793 "-fshort-enums",
794 "-fno-short-enums",
795
796 "-Wall",
289871f0
RK
797 "-Wbad-function-cast",
798 "-Wno-bad-function-cast",
b99933c7
RS
799 "-Wcast-qual",
800 "-Wno-cast-qual",
b99933c7
RS
801 "-Wchar-subscripts",
802 "-Wno-char-subscripts",
b99933c7
RS
803 "-Wcomment",
804 "-Wno-comment",
805 "-Wcomments",
806 "-Wno-comments",
4200c8de
RK
807 "-Wconversion",
808 "-Wno-conversion",
809 "-Wformat",
810 "-Wno-format",
b99933c7
RS
811 "-Wimport",
812 "-Wno-import",
e9a25f70
JL
813 "-Wimplicit-function-declaration",
814 "-Wno-implicit-function-declaration",
815 "-Werror-implicit-function-declaration",
816 "-Wimplicit-int",
817 "-Wno-implicit-int",
4200c8de
RK
818 "-Wimplicit",
819 "-Wno-implicit",
5ae3bec5
RK
820 "-Wmain",
821 "-Wno-main",
f41372d4
RS
822 "-Wmissing-braces",
823 "-Wno-missing-braces",
4200c8de
RK
824 "-Wmissing-declarations",
825 "-Wno-missing-declarations",
826 "-Wmissing-prototypes",
827 "-Wno-missing-prototypes",
828 "-Wnested-externs",
829 "-Wno-nested-externs",
830 "-Wparentheses",
831 "-Wno-parentheses",
832 "-Wpointer-arith",
833 "-Wno-pointer-arith",
834 "-Wredundant-decls",
835 "-Wno-redundant-decls",
d51f9363
JM
836 "-Wsign-compare",
837 "-Wno-sign-compare",
eb96c120
NC
838 "-Wunknown-pragmas",
839 "-Wno-unknown-pragmas",
4200c8de
RK
840 "-Wstrict-prototypes",
841 "-Wno-strict-prototypes",
842 "-Wtraditional",
843 "-Wno-traditional",
844 "-Wtrigraphs",
845 "-Wno-trigraphs",
c7710c1f
RK
846 "-Wundef",
847 "-Wno-undef",
4200c8de
RK
848 "-Wwrite-strings",
849 "-Wno-write-strings",
b99933c7 850
65faa6a4
RS
851 /* these are for obj c */
852 "-lang-objc",
853 "-gen-decls",
f5309ddf
TW
854 "-fgnu-runtime",
855 "-fno-gnu-runtime",
856 "-fnext-runtime",
857 "-fno-next-runtime",
65faa6a4
RS
858 "-Wselector",
859 "-Wno-selector",
b800a01b
KKT
860 "-Wprotocol",
861 "-Wno-protocol",
956d6950 862 "-print-objc-runtime-info",
a457294f 863
2a95de17 864#include "options.h"
b99933c7
RS
865 0
866};
4291d9c8
RS
867\f
868/* Options controlling warnings */
869
870/* Don't print warning messages. -w. */
871
872int inhibit_warnings = 0;
873
874/* Print various extra warnings. -W. */
875
876int extra_warnings = 0;
877
878/* Treat warnings as errors. -Werror. */
879
880int warnings_are_errors = 0;
881
882/* Nonzero to warn about unused local variables. */
883
884int warn_unused;
885
886/* Nonzero to warn about variables used before they are initialized. */
887
888int warn_uninitialized;
889
890/* Nonzero means warn about all declarations which shadow others. */
891
892int warn_shadow;
893
894/* Warn if a switch on an enum fails to have a case for every enum value. */
895
896int warn_switch;
897
898/* Nonzero means warn about function definitions that default the return type
899 or that use a null return and have a return-type other than void. */
900
901int warn_return_type;
902
903/* Nonzero means warn about pointer casts that increase the required
904 alignment of the target type (and might therefore lead to a crash
905 due to a misaligned access). */
906
907int warn_cast_align;
908
909/* Nonzero means warn about any identifiers that match in the first N
910 characters. The value N is in `id_clash_len'. */
911
912int warn_id_clash;
b51e9c62
RK
913unsigned id_clash_len;
914
915/* Nonzero means warn about any objects definitions whose size is larger
916 than N bytes. Also want about function definitions whose returned
917 values are larger than N bytes. The value N is in `larger_than_size'. */
918
919int warn_larger_than;
920unsigned larger_than_size;
4291d9c8
RS
921
922/* Nonzero means warn if inline function is too large. */
923
924int warn_inline;
925
926/* Warn if a function returns an aggregate,
927 since there are often incompatible calling conventions for doing this. */
928
929int warn_aggregate_return;
930
931/* Likewise for -W. */
932
933struct { char *string; int *variable; int on_value;} W_options[] =
934{
935 {"unused", &warn_unused, 1},
936 {"error", &warnings_are_errors, 1},
937 {"shadow", &warn_shadow, 1},
938 {"switch", &warn_switch, 1},
4291d9c8
RS
939 {"aggregate-return", &warn_aggregate_return, 1},
940 {"cast-align", &warn_cast_align, 1},
f246a305
RS
941 {"uninitialized", &warn_uninitialized, 1},
942 {"inline", &warn_inline, 1}
4291d9c8
RS
943};
944\f
945/* Output files for assembler code (real compiler output)
946 and debugging dumps. */
947
948FILE *asm_out_file;
949FILE *aux_info_file;
950FILE *rtl_dump_file;
951FILE *jump_opt_dump_file;
e9a25f70 952FILE *addressof_dump_file;
4291d9c8
RS
953FILE *cse_dump_file;
954FILE *loop_dump_file;
955FILE *cse2_dump_file;
0d332add 956FILE *branch_prob_dump_file;
4291d9c8
RS
957FILE *flow_dump_file;
958FILE *combine_dump_file;
8c660648 959FILE *regmove_dump_file;
4291d9c8
RS
960FILE *sched_dump_file;
961FILE *local_reg_dump_file;
962FILE *global_reg_dump_file;
963FILE *sched2_dump_file;
964FILE *jump2_opt_dump_file;
965FILE *dbr_sched_dump_file;
966FILE *stack_reg_dump_file;
967
968/* Time accumulators, to count the total time spent in various passes. */
969
970int parse_time;
971int varconst_time;
972int integration_time;
973int jump_time;
974int cse_time;
975int loop_time;
976int cse2_time;
0d332add 977int branch_prob_time;
4291d9c8
RS
978int flow_time;
979int combine_time;
8c660648 980int regmove_time;
4291d9c8
RS
981int sched_time;
982int local_alloc_time;
983int global_alloc_time;
984int sched2_time;
985int dbr_sched_time;
986int shorten_branch_time;
987int stack_reg_time;
988int final_time;
989int symout_time;
990int dump_time;
991\f
992/* Return time used so far, in microseconds. */
993
994int
995get_run_time ()
996{
ea466196 997#if !defined (_WIN32) || defined (__CYGWIN32__)
4291d9c8
RS
998#ifdef USG
999 struct tms tms;
1000#else
1001#ifndef VMS
1002 struct rusage rusage;
15f00097 1003#else
4291d9c8
RS
1004 struct
1005 {
1006 int proc_user_time;
1007 int proc_system_time;
1008 int child_user_time;
1009 int child_system_time;
1010 } vms_times;
1011#endif
15f00097 1012#endif
4291d9c8
RS
1013#endif
1014
1015 if (quiet_flag)
1016 return 0;
332c1bb4
JL
1017#ifdef __BEOS__
1018 return 0;
1019#else /* not BeOS */
ea466196 1020#if defined (_WIN32) && !defined (__CYGWIN32__)
15f00097
RK
1021 if (clock() < 0)
1022 return 0;
1023 else
1024 return (clock() * 1000);
9580b583 1025#else /* not _WIN32 */
4e762a38
JC
1026#ifdef _SC_CLK_TCK
1027 {
1028 static int tick;
1029 if (tick == 0)
1030 tick = 1000000 / sysconf(_SC_CLK_TCK);
1031 times (&tms);
1032 return (tms.tms_utime + tms.tms_stime) * tick;
1033 }
1034#else
4291d9c8
RS
1035#ifdef USG
1036 times (&tms);
1037 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
1038#else
1039#ifndef VMS
1040 getrusage (0, &rusage);
1041 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
1042 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1043#else /* VMS */
b472527b 1044 times ((void *) &vms_times);
4291d9c8 1045 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
c55dcc7d
FF
1046#endif /* VMS */
1047#endif /* USG */
4e762a38 1048#endif /* _SC_CLK_TCK */
c55dcc7d
FF
1049#endif /* _WIN32 */
1050#endif /* __BEOS__ */
4291d9c8
RS
1051}
1052
1053#define TIMEVAR(VAR, BODY) \
1054do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
1055
1056void
1057print_time (str, total)
1058 char *str;
1059 int total;
1060{
1061 fprintf (stderr,
1062 "time in %s: %d.%06d\n",
1063 str, total / 1000000, total % 1000000);
1064}
1065
1066/* Count an error or warning. Return 1 if the message should be printed. */
1067
1068int
1069count_error (warningp)
1070 int warningp;
1071{
1072 if (warningp && inhibit_warnings)
1073 return 0;
1074
1075 if (warningp && !warnings_are_errors)
1076 warningcount++;
1077 else
1078 {
1079 static int warning_message = 0;
1080
1081 if (warningp && !warning_message)
1082 {
1083 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
1084 warning_message = 1;
1085 }
1086 errorcount++;
1087 }
1088
1089 return 1;
1090}
1091
1092/* Print a fatal error message. NAME is the text.
1093 Also include a system error message based on `errno'. */
1094
1095void
1096pfatal_with_name (name)
1097 char *name;
1098{
1099 fprintf (stderr, "%s: ", progname);
1100 perror (name);
299846f2 1101 exit (FATAL_EXIT_CODE);
4291d9c8
RS
1102}
1103
1104void
1105fatal_io_error (name)
1106 char *name;
1107{
1108 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
299846f2 1109 exit (FATAL_EXIT_CODE);
4291d9c8
RS
1110}
1111
a89b2cc4
MM
1112/* Called to give a better error message for a bad insn rather than
1113 just calling abort(). */
4291d9c8
RS
1114
1115void
a89b2cc4
MM
1116fatal_insn (message, insn)
1117 char *message;
4291d9c8
RS
1118 rtx insn;
1119{
b93a436e
JL
1120 error (message);
1121 debug_rtx (insn);
4291d9c8
RS
1122 if (asm_out_file)
1123 fflush (asm_out_file);
1124 if (aux_info_file)
1125 fflush (aux_info_file);
1126 if (rtl_dump_file)
1127 fflush (rtl_dump_file);
1128 if (jump_opt_dump_file)
1129 fflush (jump_opt_dump_file);
e9a25f70
JL
1130 if (addressof_dump_file)
1131 fflush (addressof_dump_file);
4291d9c8
RS
1132 if (cse_dump_file)
1133 fflush (cse_dump_file);
1134 if (loop_dump_file)
1135 fflush (loop_dump_file);
1136 if (cse2_dump_file)
1137 fflush (cse2_dump_file);
1138 if (flow_dump_file)
1139 fflush (flow_dump_file);
1140 if (combine_dump_file)
1141 fflush (combine_dump_file);
8c660648
JL
1142 if (regmove_dump_file)
1143 fflush (regmove_dump_file);
4291d9c8
RS
1144 if (sched_dump_file)
1145 fflush (sched_dump_file);
1146 if (local_reg_dump_file)
1147 fflush (local_reg_dump_file);
1148 if (global_reg_dump_file)
1149 fflush (global_reg_dump_file);
1150 if (sched2_dump_file)
1151 fflush (sched2_dump_file);
1152 if (jump2_opt_dump_file)
1153 fflush (jump2_opt_dump_file);
1154 if (dbr_sched_dump_file)
1155 fflush (dbr_sched_dump_file);
1156 if (stack_reg_dump_file)
1157 fflush (stack_reg_dump_file);
1902f7fd
MM
1158 fflush (stdout);
1159 fflush (stderr);
4291d9c8
RS
1160 abort ();
1161}
1162
a89b2cc4
MM
1163/* Called to give a better error message when we don't have an insn to match
1164 what we are looking for or if the insn's constraints aren't satisfied,
1165 rather than just calling abort(). */
1166
1167void
1168fatal_insn_not_found (insn)
1169 rtx insn;
1170{
1171 if (INSN_CODE (insn) < 0)
1172 fatal_insn ("internal error--unrecognizable insn:", insn);
1173 else
1174 fatal_insn ("internal error--insn does not satisfy its constraints:", insn);
1175}
1176
4291d9c8
RS
1177/* This is the default decl_printable_name function. */
1178
1179static char *
a1d7ffe3 1180decl_name (decl, verbosity)
4291d9c8 1181 tree decl;
a1d7ffe3 1182 int verbosity;
4291d9c8
RS
1183{
1184 return IDENTIFIER_POINTER (DECL_NAME (decl));
1185}
1186\f
1187static int need_error_newline;
1188
1189/* Function of last error message;
1190 more generally, function such that if next error message is in it
1191 then we don't have to mention the function name. */
1192static tree last_error_function = NULL;
1193
1194/* Used to detect when input_file_stack has changed since last described. */
1195static int last_error_tick;
1196
1197/* Called when the start of a function definition is parsed,
1198 this function prints on stderr the name of the function. */
1199
1200void
1201announce_function (decl)
1202 tree decl;
1203{
1204 if (! quiet_flag)
1205 {
4291d9c8
RS
1206 if (rtl_dump_and_exit)
1207 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1208 else
a1d7ffe3 1209 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
4291d9c8
RS
1210 fflush (stderr);
1211 need_error_newline = 1;
1212 last_error_function = current_function_decl;
1213 }
1214}
1215
b64e9948
PB
1216/* The default function to print out name of current function that caused
1217 an error. */
4291d9c8
RS
1218
1219void
b64e9948 1220default_print_error_function (file)
4291d9c8
RS
1221 char *file;
1222{
4291d9c8
RS
1223 if (last_error_function != current_function_decl)
1224 {
1225 char *kind = "function";
1226 if (current_function_decl != 0
1227 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1228 kind = "method";
1229
1230 if (file)
1231 fprintf (stderr, "%s: ", file);
1232
1233 if (current_function_decl == NULL)
1234 fprintf (stderr, "At top level:\n");
1235 else
1236 {
a1d7ffe3 1237 char *name = (*decl_printable_name) (current_function_decl, 2);
4291d9c8
RS
1238 fprintf (stderr, "In %s `%s':\n", kind, name);
1239 }
1240
1241 last_error_function = current_function_decl;
1242 }
b64e9948
PB
1243}
1244
1245/* Called by report_error_function to print out function name.
0f41302f 1246 * Default may be overridden by language front-ends. */
b64e9948 1247
0f41302f 1248void (*print_error_function) PROTO((char *)) = default_print_error_function;
b64e9948
PB
1249
1250/* Prints out, if necessary, the name of the current function
1251 that caused an error. Called from all error and warning functions. */
1252
1253void
1254report_error_function (file)
1255 char *file;
1256{
1257 struct file_stack *p;
1258
1259 if (need_error_newline)
1260 {
1261 fprintf (stderr, "\n");
1262 need_error_newline = 0;
1263 }
1264
1265 (*print_error_function) (file);
1266
4291d9c8 1267 if (input_file_stack && input_file_stack->next != 0
2efc92ed
RK
1268 && input_file_stack_tick != last_error_tick
1269 && file == input_filename)
4291d9c8
RS
1270 {
1271 fprintf (stderr, "In file included");
1272 for (p = input_file_stack->next; p; p = p->next)
1273 {
1274 fprintf (stderr, " from %s:%d", p->name, p->line);
1275 if (p->next)
e5301904 1276 fprintf (stderr, ",\n ");
4291d9c8
RS
1277 }
1278 fprintf (stderr, ":\n");
1279 last_error_tick = input_file_stack_tick;
1280 }
1281}
eb711c86
RK
1282\f
1283/* Print a message. */
4291d9c8 1284
eb711c86
RK
1285static void
1286vmessage (prefix, s, ap)
1287 char *prefix;
4291d9c8 1288 char *s;
eb711c86 1289 va_list ap;
4291d9c8 1290{
eb711c86
RK
1291 if (prefix)
1292 fprintf (stderr, "%s: ", prefix);
1293
1294#ifdef HAVE_VPRINTF
1295 vfprintf (stderr, s, ap);
1296#else
1297 {
1298 HOST_WIDE_INT v1 = va_arg(ap, HOST_WIDE_INT);
1299 HOST_WIDE_INT v2 = va_arg(ap, HOST_WIDE_INT);
1300 HOST_WIDE_INT v3 = va_arg(ap, HOST_WIDE_INT);
a4326b4d
RK
1301 HOST_WIDE_INT v4 = va_arg(ap, HOST_WIDE_INT);
1302 fprintf (stderr, s, v1, v2, v3, v4);
eb711c86
RK
1303 }
1304#endif
4291d9c8
RS
1305}
1306
eb711c86 1307/* Print a message relevant to line LINE of file FILE. */
4291d9c8 1308
eb711c86
RK
1309static void
1310v_message_with_file_and_line (file, line, prefix, s, ap)
4291d9c8
RS
1311 char *file;
1312 int line;
eb711c86 1313 char *prefix;
4291d9c8 1314 char *s;
eb711c86 1315 va_list ap;
4291d9c8 1316{
4291d9c8
RS
1317 if (file)
1318 fprintf (stderr, "%s:%d: ", file, line);
1319 else
1320 fprintf (stderr, "%s: ", progname);
d78c6ad5 1321
eb711c86
RK
1322 vmessage (prefix, s, ap);
1323 fputc ('\n', stderr);
4291d9c8
RS
1324}
1325
eb711c86 1326/* Print a message relevant to the given DECL. */
4291d9c8 1327
eb711c86
RK
1328static void
1329v_message_with_decl (decl, prefix, s, ap)
4291d9c8 1330 tree decl;
eb711c86 1331 char *prefix;
4291d9c8 1332 char *s;
eb711c86 1333 va_list ap;
4291d9c8 1334{
a1d7ffe3 1335 char *n, *p;
4291d9c8
RS
1336
1337 fprintf (stderr, "%s:%d: ",
1338 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1339
eb711c86
RK
1340 if (prefix)
1341 fprintf (stderr, "%s: ", prefix);
1342
1343 /* Do magic to get around lack of varargs support for insertion
1344 of arguments into existing list. We know that the decl is first;
1345 we ass_u_me that it will be printed with "%s". */
1346
1347 for (p = s; *p; ++p)
1348 {
1349 if (*p == '%')
1350 {
1351 if (*(p + 1) == '%')
1352 ++p;
1353 else
1354 break;
1355 }
1356 }
1357
cb039f8a
RK
1358 if (p > s) /* Print the left-hand substring. */
1359 {
1360 char fmt[sizeof "%.255s"];
1361 long width = p - s;
1362
1363 if (width > 255L) width = 255L; /* arbitrary */
1364 sprintf (fmt, "%%.%lds", width);
1365 fprintf (stderr, fmt, s);
1366 }
eb711c86 1367
cb039f8a 1368 if (*p == '%') /* Print the name. */
eb711c86
RK
1369 {
1370 char *n = (DECL_NAME (decl)
a1d7ffe3 1371 ? (*decl_printable_name) (decl, 2)
eb711c86
RK
1372 : "((anonymous))");
1373 fputs (n, stderr);
1374 while (*p)
1375 {
1376 ++p;
1377 if (isalpha (*(p - 1) & 0xFF))
1378 break;
1379 }
1380 }
1381
cb039f8a 1382 if (*p) /* Print the rest of the message. */
eb711c86
RK
1383 vmessage ((char *)NULL, p, ap);
1384
1385 fputc ('\n', stderr);
4291d9c8
RS
1386}
1387
eb711c86 1388/* Figure file and line of the given INSN. */
4291d9c8 1389
eb711c86
RK
1390static void
1391file_and_line_for_asm (insn, pfile, pline)
4291d9c8 1392 rtx insn;
eb711c86
RK
1393 char **pfile;
1394 int *pline;
4291d9c8 1395{
4291d9c8
RS
1396 rtx body = PATTERN (insn);
1397 rtx asmop;
1398
1399 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1400 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1401 asmop = SET_SRC (body);
1402 else if (GET_CODE (body) == ASM_OPERANDS)
1403 asmop = body;
1404 else if (GET_CODE (body) == PARALLEL
1405 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1406 asmop = SET_SRC (XVECEXP (body, 0, 0));
1407 else if (GET_CODE (body) == PARALLEL
1408 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1409 asmop = XVECEXP (body, 0, 0);
eb711c86
RK
1410 else
1411 asmop = NULL;
1412
1413 if (asmop)
1414 {
1415 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1416 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1417 }
1418 else
1419 {
1420 *pfile = input_filename;
1421 *pline = lineno;
1422 }
1423}
4291d9c8 1424
eb711c86 1425/* Report an error at line LINE of file FILE. */
4291d9c8 1426
eb711c86
RK
1427static void
1428v_error_with_file_and_line (file, line, s, ap)
1429 char *file;
1430 int line;
1431 char *s;
1432 va_list ap;
1433{
1434 count_error (0);
1435 report_error_function (file);
1436 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
d78c6ad5
RK
1437}
1438
1439void
e0e2a8da 1440error_with_file_and_line VPROTO((char *file, int line, char *s, ...))
d78c6ad5 1441{
e0e2a8da 1442#ifndef __STDC__
eb711c86
RK
1443 char *file;
1444 int line;
1445 char *s;
e0e2a8da
RK
1446#endif
1447 va_list ap;
1448
1449 VA_START (ap, s);
eb711c86 1450
e0e2a8da 1451#ifndef __STDC__
eb711c86
RK
1452 file = va_arg (ap, char *);
1453 line = va_arg (ap, int);
1454 s = va_arg (ap, char *);
e0e2a8da
RK
1455#endif
1456
eb711c86
RK
1457 v_error_with_file_and_line (file, line, s, ap);
1458 va_end (ap);
4291d9c8
RS
1459}
1460
eb711c86
RK
1461/* Report an error at the declaration DECL.
1462 S is a format string which uses %s to substitute the declaration
1463 name; subsequent substitutions are a la printf. */
1464
1465static void
1466v_error_with_decl (decl, s, ap)
1467 tree decl;
1468 char *s;
1469 va_list ap;
1470{
1471 count_error (0);
1472 report_error_function (DECL_SOURCE_FILE (decl));
1473 v_message_with_decl (decl, (char *)NULL, s, ap);
1474}
4291d9c8
RS
1475
1476void
e0e2a8da 1477error_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1478{
e0e2a8da 1479#ifndef __STDC__
eb711c86
RK
1480 tree decl;
1481 char *s;
e0e2a8da
RK
1482#endif
1483 va_list ap;
eb711c86 1484
e0e2a8da
RK
1485 VA_START (ap, s);
1486
1487#ifndef __STDC__
eb711c86
RK
1488 decl = va_arg (ap, tree);
1489 s = va_arg (ap, char *);
e0e2a8da
RK
1490#endif
1491
eb711c86
RK
1492 v_error_with_decl (decl, s, ap);
1493 va_end (ap);
1494}
1495
1496/* Report an error at the line number of the insn INSN.
1497 This is used only when INSN is an `asm' with operands,
1498 and each ASM_OPERANDS records its own source file and line. */
1499
1500static void
1501v_error_for_asm (insn, s, ap)
1502 rtx insn;
4291d9c8 1503 char *s;
eb711c86 1504 va_list ap;
4291d9c8 1505{
eb711c86
RK
1506 char *file;
1507 int line;
4291d9c8 1508
eb711c86
RK
1509 count_error (0);
1510 file_and_line_for_asm (insn, &file, &line);
4291d9c8 1511 report_error_function (file);
eb711c86
RK
1512 v_message_with_file_and_line (file, line, (char *)NULL, s, ap);
1513}
4291d9c8 1514
eb711c86 1515void
e0e2a8da 1516error_for_asm VPROTO((rtx insn, char *s, ...))
eb711c86 1517{
e0e2a8da 1518#ifndef __STDC__
eb711c86
RK
1519 rtx insn;
1520 char *s;
e0e2a8da
RK
1521#endif
1522 va_list ap;
eb711c86 1523
e0e2a8da
RK
1524 VA_START (ap, s);
1525
1526#ifndef __STDC__
eb711c86
RK
1527 insn = va_arg (ap, rtx);
1528 s = va_arg (ap, char *);
e0e2a8da
RK
1529#endif
1530
eb711c86
RK
1531 v_error_for_asm (insn, s, ap);
1532 va_end (ap);
4291d9c8
RS
1533}
1534
eb711c86 1535/* Report an error at the current line number. */
4291d9c8 1536
eb711c86
RK
1537static void
1538verror (s, ap)
4291d9c8 1539 char *s;
eb711c86 1540 va_list ap;
4291d9c8 1541{
eb711c86 1542 v_error_with_file_and_line (input_filename, lineno, s, ap);
4291d9c8
RS
1543}
1544
eb711c86 1545void
e0e2a8da 1546error VPROTO((char *s, ...))
eb711c86 1547{
e0e2a8da 1548#ifndef __STDC__
eb711c86 1549 char *s;
e0e2a8da
RK
1550#endif
1551 va_list ap;
1552
1553 VA_START (ap, s);
eb711c86 1554
e0e2a8da 1555#ifndef __STDC__
eb711c86 1556 s = va_arg (ap, char *);
e0e2a8da
RK
1557#endif
1558
eb711c86
RK
1559 verror (s, ap);
1560 va_end (ap);
1561}
1562
1563/* Report a fatal error at the current line number. */
1564
1565static void
1566vfatal (s, ap)
1567 char *s;
1568 va_list ap;
1569{
1570 verror (s, ap);
299846f2 1571 exit (FATAL_EXIT_CODE);
eb711c86 1572}
4291d9c8
RS
1573
1574void
e0e2a8da 1575fatal VPROTO((char *s, ...))
eb711c86 1576{
e0e2a8da 1577#ifndef __STDC__
eb711c86 1578 char *s;
e0e2a8da
RK
1579#endif
1580 va_list ap;
1581
1582 VA_START (ap, s);
eb711c86 1583
e0e2a8da 1584#ifndef __STDC__
eb711c86 1585 s = va_arg (ap, char *);
e0e2a8da
RK
1586#endif
1587
eb711c86
RK
1588 vfatal (s, ap);
1589 va_end (ap);
1590}
1591
1592/* Report a warning at line LINE of file FILE. */
1593
1594static void
1595v_warning_with_file_and_line (file, line, s, ap)
1596 char *file;
1597 int line;
4291d9c8 1598 char *s;
eb711c86 1599 va_list ap;
4291d9c8 1600{
eb711c86
RK
1601 if (count_error (1))
1602 {
1603 report_error_function (file);
1604 v_message_with_file_and_line (file, line, "warning", s, ap);
1605 }
1606}
4291d9c8 1607
eb711c86 1608void
e0e2a8da 1609warning_with_file_and_line VPROTO((char *file, int line, char *s, ...))
eb711c86 1610{
e0e2a8da 1611#ifndef __STDC__
eb711c86
RK
1612 char *file;
1613 int line;
1614 char *s;
e0e2a8da
RK
1615#endif
1616 va_list ap;
1617
1618 VA_START (ap, s);
eb711c86 1619
e0e2a8da 1620#ifndef __STDC__
eb711c86
RK
1621 file = va_arg (ap, char *);
1622 line = va_arg (ap, int);
1623 s = va_arg (ap, char *);
e0e2a8da
RK
1624#endif
1625
eb711c86
RK
1626 v_warning_with_file_and_line (file, line, s, ap);
1627 va_end (ap);
1628}
4291d9c8 1629
eb711c86
RK
1630/* Report a warning at the declaration DECL.
1631 S is a format string which uses %s to substitute the declaration
1632 name; subsequent substitutions are a la printf. */
4291d9c8 1633
eb711c86
RK
1634static void
1635v_warning_with_decl (decl, s, ap)
1636 tree decl;
1637 char *s;
1638 va_list ap;
1639{
1640 if (count_error (1))
1641 {
1642 report_error_function (DECL_SOURCE_FILE (decl));
1643 v_message_with_decl (decl, "warning", s, ap);
1644 }
1645}
4291d9c8 1646
eb711c86 1647void
e0e2a8da 1648warning_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1649{
e0e2a8da 1650#ifndef __STDC__
eb711c86
RK
1651 tree decl;
1652 char *s;
e0e2a8da
RK
1653#endif
1654 va_list ap;
eb711c86 1655
e0e2a8da
RK
1656 VA_START (ap, s);
1657
1658#ifndef __STDC__
eb711c86
RK
1659 decl = va_arg (ap, tree);
1660 s = va_arg (ap, char *);
e0e2a8da
RK
1661#endif
1662
eb711c86
RK
1663 v_warning_with_decl (decl, s, ap);
1664 va_end (ap);
4291d9c8
RS
1665}
1666
1667/* Report a warning at the line number of the insn INSN.
4291d9c8
RS
1668 This is used only when INSN is an `asm' with operands,
1669 and each ASM_OPERANDS records its own source file and line. */
1670
eb711c86
RK
1671static void
1672v_warning_for_asm (insn, s, ap)
4291d9c8
RS
1673 rtx insn;
1674 char *s;
eb711c86 1675 va_list ap;
4291d9c8 1676{
eb711c86
RK
1677 if (count_error (1))
1678 {
1679 char *file;
1680 int line;
4291d9c8 1681
eb711c86
RK
1682 file_and_line_for_asm (insn, &file, &line);
1683 report_error_function (file);
1684 v_message_with_file_and_line (file, line, "warning", s, ap);
1685 }
1686}
4291d9c8 1687
eb711c86 1688void
e0e2a8da 1689warning_for_asm VPROTO((rtx insn, char *s, ...))
eb711c86 1690{
e0e2a8da 1691#ifndef __STDC__
eb711c86
RK
1692 rtx insn;
1693 char *s;
e0e2a8da
RK
1694#endif
1695 va_list ap;
1696
1697 VA_START (ap, s);
eb711c86 1698
e0e2a8da 1699#ifndef __STDC__
eb711c86
RK
1700 insn = va_arg (ap, rtx);
1701 s = va_arg (ap, char *);
e0e2a8da
RK
1702#endif
1703
eb711c86
RK
1704 v_warning_for_asm (insn, s, ap);
1705 va_end (ap);
1706}
4291d9c8 1707
eb711c86
RK
1708/* Report a warning at the current line number. */
1709
1710static void
1711vwarning (s, ap)
1712 char *s;
1713 va_list ap;
1714{
1715 v_warning_with_file_and_line (input_filename, lineno, s, ap);
4291d9c8 1716}
eb711c86
RK
1717
1718void
e0e2a8da 1719warning VPROTO((char *s, ...))
eb711c86 1720{
e0e2a8da 1721#ifndef __STDC__
eb711c86 1722 char *s;
e0e2a8da
RK
1723#endif
1724 va_list ap;
1725
1726 VA_START (ap, s);
eb711c86 1727
e0e2a8da 1728#ifndef __STDC__
eb711c86 1729 s = va_arg (ap, char *);
e0e2a8da
RK
1730#endif
1731
eb711c86
RK
1732 vwarning (s, ap);
1733 va_end (ap);
1734}
1735
4291d9c8
RS
1736/* These functions issue either warnings or errors depending on
1737 -pedantic-errors. */
1738
eb711c86
RK
1739static void
1740vpedwarn (s, ap)
4291d9c8 1741 char *s;
eb711c86 1742 va_list ap;
4291d9c8
RS
1743{
1744 if (flag_pedantic_errors)
eb711c86 1745 verror (s, ap);
4291d9c8 1746 else
eb711c86 1747 vwarning (s, ap);
4291d9c8
RS
1748}
1749
1750void
e0e2a8da 1751pedwarn VPROTO((char *s, ...))
eb711c86 1752{
e0e2a8da 1753#ifndef __STDC__
eb711c86 1754 char *s;
e0e2a8da
RK
1755#endif
1756 va_list ap;
1757
1758 VA_START (ap, s);
eb711c86 1759
e0e2a8da 1760#ifndef __STDC__
eb711c86 1761 s = va_arg (ap, char *);
e0e2a8da
RK
1762#endif
1763
eb711c86
RK
1764 vpedwarn (s, ap);
1765 va_end (ap);
1766}
1767
1768static void
1769v_pedwarn_with_decl (decl, s, ap)
4291d9c8
RS
1770 tree decl;
1771 char *s;
eb711c86 1772 va_list ap;
4291d9c8 1773{
1554cdf5
DE
1774 /* We don't want -pedantic-errors to cause the compilation to fail from
1775 "errors" in system header files. Sometimes fixincludes can't fix what's
1776 broken (eg: unsigned char bitfields - fixing it may change the alignment
1777 which will cause programs to mysteriously fail because the C library
22d74562
DE
1778 or kernel uses the original layout). There's no point in issuing a
1779 warning either, it's just unnecessary noise. */
1554cdf5 1780
22d74562
DE
1781 if (! DECL_IN_SYSTEM_HEADER (decl))
1782 {
1783 if (flag_pedantic_errors)
1784 v_error_with_decl (decl, s, ap);
1785 else
1786 v_warning_with_decl (decl, s, ap);
1787 }
4291d9c8
RS
1788}
1789
1790void
e0e2a8da 1791pedwarn_with_decl VPROTO((tree decl, char *s, ...))
eb711c86 1792{
e0e2a8da 1793#ifndef __STDC__
eb711c86
RK
1794 tree decl;
1795 char *s;
e0e2a8da
RK
1796#endif
1797 va_list ap;
eb711c86 1798
e0e2a8da
RK
1799 VA_START (ap, s);
1800
1801#ifndef __STDC__
eb711c86
RK
1802 decl = va_arg (ap, tree);
1803 s = va_arg (ap, char *);
e0e2a8da
RK
1804#endif
1805
eb711c86
RK
1806 v_pedwarn_with_decl (decl, s, ap);
1807 va_end (ap);
1808}
1809
1810static void
1811v_pedwarn_with_file_and_line (file, line, s, ap)
4291d9c8
RS
1812 char *file;
1813 int line;
1814 char *s;
eb711c86 1815 va_list ap;
4291d9c8
RS
1816{
1817 if (flag_pedantic_errors)
eb711c86 1818 v_error_with_file_and_line (file, line, s, ap);
4291d9c8 1819 else
eb711c86 1820 v_warning_with_file_and_line (file, line, s, ap);
4291d9c8
RS
1821}
1822
4291d9c8 1823void
e0e2a8da 1824pedwarn_with_file_and_line VPROTO((char *file, int line, char *s, ...))
eb711c86 1825{
e0e2a8da 1826#ifndef __STDC__
eb711c86
RK
1827 char *file;
1828 int line;
1829 char *s;
e0e2a8da
RK
1830#endif
1831 va_list ap;
eb711c86 1832
e0e2a8da
RK
1833 VA_START (ap, s);
1834
1835#ifndef __STDC__
eb711c86
RK
1836 file = va_arg (ap, char *);
1837 line = va_arg (ap, int);
1838 s = va_arg (ap, char *);
e0e2a8da
RK
1839#endif
1840
eb711c86
RK
1841 v_pedwarn_with_file_and_line (file, line, s, ap);
1842 va_end (ap);
1843}
1844
1845/* Apologize for not implementing some feature. */
1846
1847static void
1848vsorry (s, ap)
4291d9c8 1849 char *s;
eb711c86 1850 va_list ap;
4291d9c8
RS
1851{
1852 sorrycount++;
1853 if (input_filename)
1854 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1855 else
1856 fprintf (stderr, "%s: ", progname);
eb711c86
RK
1857 vmessage ("sorry, not implemented", s, ap);
1858 fputc ('\n', stderr);
1859}
4291d9c8 1860
eb711c86 1861void
e0e2a8da 1862sorry VPROTO((char *s, ...))
eb711c86 1863{
e0e2a8da 1864#ifndef __STDC__
eb711c86 1865 char *s;
e0e2a8da
RK
1866#endif
1867 va_list ap;
1868
1869 VA_START (ap, s);
eb711c86 1870
e0e2a8da 1871#ifndef __STDC__
eb711c86 1872 s = va_arg (ap, char *);
e0e2a8da
RK
1873#endif
1874
eb711c86
RK
1875 vsorry (s, ap);
1876 va_end (ap);
4291d9c8
RS
1877}
1878
eb711c86 1879/* Apologize for not implementing some feature, then quit. */
4291d9c8 1880
eb711c86
RK
1881static void
1882v_really_sorry (s, ap)
4291d9c8 1883 char *s;
eb711c86 1884 va_list ap;
4291d9c8 1885{
eb711c86 1886 sorrycount++;
4291d9c8
RS
1887 if (input_filename)
1888 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1889 else
c10afc44 1890 fprintf (stderr, "%s: ", progname);
eb711c86 1891 vmessage ("sorry, not implemented", s, ap);
4291d9c8
RS
1892 fatal (" (fatal)\n");
1893}
eb711c86
RK
1894
1895void
e0e2a8da 1896really_sorry VPROTO((char *s, ...))
eb711c86 1897{
e0e2a8da 1898#ifndef __STDC__
eb711c86 1899 char *s;
e0e2a8da
RK
1900#endif
1901 va_list ap;
1902
1903 VA_START (ap, s);
eb711c86 1904
e0e2a8da 1905#ifndef __STDC__
eb711c86 1906 s = va_arg (ap, char *);
e0e2a8da
RK
1907#endif
1908
eb711c86
RK
1909 v_really_sorry (s, ap);
1910 va_end (ap);
1911}
4291d9c8
RS
1912\f
1913/* More 'friendly' abort that prints the line and file.
1914 config.h can #define abort fancy_abort if you like that sort of thing.
1915
1916 I don't think this is actually a good idea.
1917 Other sorts of crashes will look a certain way.
1918 It is a good thing if crashes from calling abort look the same way.
1919 -- RMS */
1920
1921void
1922fancy_abort ()
1923{
1924 fatal ("internal gcc abort");
1925}
1926
1927/* This calls abort and is used to avoid problems when abort if a macro.
1928 It is used when we need to pass the address of abort. */
1929
1930void
1931do_abort ()
1932{
1933 abort ();
1934}
1935
1936/* When `malloc.c' is compiled with `rcheck' defined,
1937 it calls this function to report clobberage. */
1938
1939void
1940botch (s)
1941{
1942 abort ();
1943}
1944
1945/* Same as `malloc' but report error if no memory available. */
1946
4b980e20 1947char *
4291d9c8
RS
1948xmalloc (size)
1949 unsigned size;
1950{
4b980e20 1951 register char *value = (char *) malloc (size);
809d135d 1952 if (value == 0 && size != 0)
4291d9c8
RS
1953 fatal ("virtual memory exhausted");
1954 return value;
1955}
1956
e9a25f70
JL
1957/* Same as `realloc' but report error if no memory available.
1958 Also handle null PTR even if the vendor realloc gets it wrong. */
4291d9c8 1959
4b980e20 1960char *
4291d9c8
RS
1961xrealloc (ptr, size)
1962 char *ptr;
1963 int size;
1964{
e9a25f70
JL
1965 char *result = (ptr
1966 ? (char *) realloc (ptr, size)
1967 : (char *) malloc (size));
4291d9c8
RS
1968 if (!result)
1969 fatal ("virtual memory exhausted");
1970 return result;
1971}
3e386b9e
RK
1972
1973/* Same as `strdup' but report error if no memory available. */
1974
1975char *
1976xstrdup (s)
1977 register char *s;
1978{
1979 register char *result = (char *) malloc (strlen (s) + 1);
1980
1981 if (! result)
1982 fatal ("virtual memory exhausted");
1983 strcpy (result, s);
1984 return result;
1985}
4291d9c8
RS
1986\f
1987/* Return the logarithm of X, base 2, considering X unsigned,
37366632
RK
1988 if X is a power of 2. Otherwise, returns -1.
1989
1990 This should be used via the `exact_log2' macro. */
4291d9c8
RS
1991
1992int
37366632
RK
1993exact_log2_wide (x)
1994 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
1995{
1996 register int log = 0;
1997 /* Test for 0 or a power of 2. */
1998 if (x == 0 || x != (x & -x))
1999 return -1;
2000 while ((x >>= 1) != 0)
2001 log++;
2002 return log;
2003}
2004
2005/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
37366632
RK
2006 If X is 0, return -1.
2007
2008 This should be used via the floor_log2 macro. */
4291d9c8
RS
2009
2010int
37366632
RK
2011floor_log2_wide (x)
2012 register unsigned HOST_WIDE_INT x;
4291d9c8
RS
2013{
2014 register int log = -1;
2015 while (x != 0)
2016 log++,
2017 x >>= 1;
2018 return log;
2019}
2020
3bbfa296 2021static int float_handler_set;
4291d9c8
RS
2022int float_handled;
2023jmp_buf float_handler;
2024
3bbfa296
RK
2025/* Signals actually come here. */
2026
2027static void
2028float_signal (signo)
2029 /* If this is missing, some compilers complain. */
2030 int signo;
2031{
2032 if (float_handled == 0)
2033 abort ();
2034#if defined (USG) || defined (hpux)
2035 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
2036#endif
2037 float_handled = 0;
2038 signal (SIGFPE, float_signal);
2039 longjmp (float_handler, 1);
2040}
2041
4291d9c8
RS
2042/* Specify where to longjmp to when a floating arithmetic error happens.
2043 If HANDLER is 0, it means don't handle the errors any more. */
2044
2045void
2046set_float_handler (handler)
2047 jmp_buf handler;
2048{
2049 float_handled = (handler != 0);
2050 if (handler)
4c9a05bc 2051 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
3bbfa296
RK
2052
2053 if (float_handled && ! float_handler_set)
2054 {
2055 signal (SIGFPE, float_signal);
2056 float_handler_set = 1;
2057 }
4291d9c8
RS
2058}
2059
bff4b641
RS
2060/* Specify, in HANDLER, where to longjmp to when a floating arithmetic
2061 error happens, pushing the previous specification into OLD_HANDLER.
2062 Return an indication of whether there was a previous handler in effect. */
2063
2064int
2065push_float_handler (handler, old_handler)
dc2b15dc 2066 jmp_buf handler, old_handler;
bff4b641
RS
2067{
2068 int was_handled = float_handled;
2069
2070 float_handled = 1;
2071 if (was_handled)
4c9a05bc
RK
2072 bcopy ((char *) float_handler, (char *) old_handler,
2073 sizeof (float_handler));
2074
2075 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
bff4b641
RS
2076 return was_handled;
2077}
2078
2079/* Restore the previous specification of whether and where to longjmp to
2080 when a floating arithmetic error happens. */
2081
2082void
2083pop_float_handler (handled, handler)
2084 int handled;
2085 jmp_buf handler;
2086{
2087 float_handled = handled;
2088 if (handled)
4c9a05bc 2089 bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
bff4b641
RS
2090}
2091
4291d9c8
RS
2092/* Handler for SIGPIPE. */
2093
2094static void
2095pipe_closed (signo)
2096 /* If this is missing, some compilers complain. */
2097 int signo;
2098{
2099 fatal ("output pipe has been closed");
2100}
2101
2102/* Strip off a legitimate source ending from the input string NAME of
c62bdc79
RK
2103 length LEN. Rather than having to know the names used by all of
2104 our front ends, we strip off an ending of a period followed by one,
2105 two, or three characters. */
4291d9c8
RS
2106
2107void
2108strip_off_ending (name, len)
2109 char *name;
2110 int len;
2111{
c62bdc79
RK
2112 if (len > 2 && name[len - 2] == '.')
2113 name[len - 2] = '\0';
2114 else if (len > 3 && name[len - 3] == '.')
2115 name[len - 3] = '\0';
2116 else if (len > 4 && name[len - 4] == '.')
2117 name[len - 4] = '\0';
4291d9c8
RS
2118}
2119
7dce5088 2120/* Output a quoted string. */
0f41302f 2121
7dce5088
PE
2122void
2123output_quoted_string (asm_file, string)
2124 FILE *asm_file;
2125 char *string;
2126{
e9a25f70
JL
2127#ifdef OUTPUT_QUOTED_STRING
2128 OUTPUT_QUOTED_STRING (asm_file, string);
2129#else
7dce5088
PE
2130 char c;
2131
2132 putc ('\"', asm_file);
2133 while ((c = *string++) != 0)
2134 {
2135 if (c == '\"' || c == '\\')
2136 putc ('\\', asm_file);
2137 putc (c, asm_file);
2138 }
2139 putc ('\"', asm_file);
e9a25f70 2140#endif
7dce5088
PE
2141}
2142
4291d9c8
RS
2143/* Output a file name in the form wanted by System V. */
2144
2145void
2146output_file_directive (asm_file, input_name)
2147 FILE *asm_file;
2148 char *input_name;
2149{
2150 int len = strlen (input_name);
2151 char *na = input_name + len;
2152
2153 /* NA gets INPUT_NAME sans directory names. */
2154 while (na > input_name)
2155 {
2156 if (na[-1] == '/')
2157 break;
2158 na--;
2159 }
2160
2161#ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
2162 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
2163#else
2164#ifdef ASM_OUTPUT_SOURCE_FILENAME
2165 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
2166#else
7dce5088
PE
2167 fprintf (asm_file, "\t.file\t");
2168 output_quoted_string (asm_file, na);
2169 fputc ('\n', asm_file);
4291d9c8
RS
2170#endif
2171#endif
2172}
2173\f
0f41302f
MS
2174/* Routine to build language identifier for object file. */
2175
d0d4af87
MS
2176static void
2177output_lang_identify (asm_out_file)
2178 FILE *asm_out_file;
2179{
2180 int len = strlen (lang_identify ()) + sizeof ("__gnu_compiled_") + 1;
2181 char *s = (char *) alloca (len);
2182 sprintf (s, "__gnu_compiled_%s", lang_identify ());
2183 ASM_OUTPUT_LABEL (asm_out_file, s);
2184}
2185
dfe1a916 2186/* Routine to open a dump file. */
0f41302f 2187
dfe1a916
DE
2188static FILE *
2189open_dump_file (base_name, suffix)
2190 char *base_name;
2191 char *suffix;
2192{
2193 FILE *f;
2194 char *dumpname = (char *) alloca (strlen (base_name) + strlen (suffix) + 1);
2195
2196 strcpy (dumpname, base_name);
2197 strcat (dumpname, suffix);
2198 f = fopen (dumpname, "w");
2199 if (f == 0)
2200 pfatal_with_name (dumpname);
2201 return f;
2202}
2203
4291d9c8
RS
2204/* Compile an entire file of output from cpp, named NAME.
2205 Write a file of assembly output and various debugging dumps. */
2206
2207static void
2208compile_file (name)
2209 char *name;
2210{
2211 tree globals;
2212 int start_time;
4291d9c8
RS
2213
2214 int name_specified = name != 0;
2215
2216 if (dump_base_name == 0)
2217 dump_base_name = name ? name : "gccdump";
4291d9c8
RS
2218
2219 parse_time = 0;
2220 varconst_time = 0;
2221 integration_time = 0;
2222 jump_time = 0;
2223 cse_time = 0;
2224 loop_time = 0;
2225 cse2_time = 0;
0d332add 2226 branch_prob_time = 0;
4291d9c8
RS
2227 flow_time = 0;
2228 combine_time = 0;
8c660648 2229 regmove_time = 0;
4291d9c8
RS
2230 sched_time = 0;
2231 local_alloc_time = 0;
2232 global_alloc_time = 0;
2233 sched2_time = 0;
2234 dbr_sched_time = 0;
2235 shorten_branch_time = 0;
2236 stack_reg_time = 0;
2237 final_time = 0;
2238 symout_time = 0;
2239 dump_time = 0;
2240
e3d1fd32 2241#if !USE_CPPLIB
4291d9c8
RS
2242 /* Open input file. */
2243
2244 if (name == 0 || !strcmp (name, "-"))
2245 {
2246 finput = stdin;
2247 name = "stdin";
2248 }
2249 else
2250 finput = fopen (name, "r");
2251 if (finput == 0)
2252 pfatal_with_name (name);
2253
282ea52a 2254#ifdef IO_BUFFER_SIZE
d7cedf4b 2255 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
282ea52a 2256#endif
e3d1fd32 2257#endif /* !USE_CPPLIB */
282ea52a 2258
4291d9c8
RS
2259 /* Initialize data in various passes. */
2260
2261 init_obstacks ();
2262 init_tree_codes ();
e3d1fd32
PB
2263#if USE_CPPLIB
2264 init_parse (name);
2265#else
4291d9c8 2266 init_lex ();
e3d1fd32 2267#endif
4291d9c8
RS
2268 init_rtl ();
2269 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
0d332add
DE
2270 || debug_info_level == DINFO_LEVEL_VERBOSE
2271 || flag_test_coverage);
7f21d440 2272 init_regs ();
4291d9c8
RS
2273 init_decl_processing ();
2274 init_optabs ();
2275 init_stmt ();
2276 init_expmed ();
4fa52007 2277 init_expr_once ();
4291d9c8
RS
2278 init_loop ();
2279 init_reload ();
6e73e666 2280 init_alias_once ();
4291d9c8
RS
2281
2282 if (flag_caller_saves)
2283 init_caller_save ();
2284
f246a305
RS
2285 /* If auxiliary info generation is desired, open the output file.
2286 This goes in the same directory as the source file--unlike
2287 all the other output files. */
4291d9c8
RS
2288 if (flag_gen_aux_info)
2289 {
4291d9c8
RS
2290 aux_info_file = fopen (aux_info_file_name, "w");
2291 if (aux_info_file == 0)
2292 pfatal_with_name (aux_info_file_name);
2293 }
2294
2295 /* If rtl dump desired, open the output file. */
2296 if (rtl_dump)
dfe1a916 2297 rtl_dump_file = open_dump_file (dump_base_name, ".rtl");
4291d9c8
RS
2298
2299 /* If jump_opt dump desired, open the output file. */
2300 if (jump_opt_dump)
dfe1a916 2301 jump_opt_dump_file = open_dump_file (dump_base_name, ".jump");
4291d9c8 2302
e9a25f70
JL
2303 /* If addressof dump desired, open the output file. */
2304 if (addressof_dump)
2305 addressof_dump_file = open_dump_file (dump_base_name, ".addressof");
2306
4291d9c8
RS
2307 /* If cse dump desired, open the output file. */
2308 if (cse_dump)
dfe1a916 2309 cse_dump_file = open_dump_file (dump_base_name, ".cse");
4291d9c8
RS
2310
2311 /* If loop dump desired, open the output file. */
2312 if (loop_dump)
dfe1a916 2313 loop_dump_file = open_dump_file (dump_base_name, ".loop");
4291d9c8
RS
2314
2315 /* If cse2 dump desired, open the output file. */
2316 if (cse2_dump)
dfe1a916 2317 cse2_dump_file = open_dump_file (dump_base_name, ".cse2");
4291d9c8 2318
0d332add
DE
2319 /* If branch_prob dump desired, open the output file. */
2320 if (branch_prob_dump)
2321 branch_prob_dump_file = open_dump_file (dump_base_name, ".bp");
2322
4291d9c8
RS
2323 /* If flow dump desired, open the output file. */
2324 if (flow_dump)
dfe1a916 2325 flow_dump_file = open_dump_file (dump_base_name, ".flow");
4291d9c8
RS
2326
2327 /* If combine dump desired, open the output file. */
2328 if (combine_dump)
dfe1a916 2329 combine_dump_file = open_dump_file (dump_base_name, ".combine");
4291d9c8 2330
8c660648
JL
2331 /* If regmove dump desired, open the output file. */
2332 if (regmove_dump)
2333 regmove_dump_file = open_dump_file (dump_base_name, ".regmove");
2334
4291d9c8
RS
2335 /* If scheduling dump desired, open the output file. */
2336 if (sched_dump)
dfe1a916 2337 sched_dump_file = open_dump_file (dump_base_name, ".sched");
4291d9c8
RS
2338
2339 /* If local_reg dump desired, open the output file. */
2340 if (local_reg_dump)
dfe1a916 2341 local_reg_dump_file = open_dump_file (dump_base_name, ".lreg");
4291d9c8
RS
2342
2343 /* If global_reg dump desired, open the output file. */
2344 if (global_reg_dump)
dfe1a916 2345 global_reg_dump_file = open_dump_file (dump_base_name, ".greg");
4291d9c8
RS
2346
2347 /* If 2nd scheduling dump desired, open the output file. */
2348 if (sched2_dump)
dfe1a916 2349 sched2_dump_file = open_dump_file (dump_base_name, ".sched2");
4291d9c8
RS
2350
2351 /* If jump2_opt dump desired, open the output file. */
2352 if (jump2_opt_dump)
dfe1a916 2353 jump2_opt_dump_file = open_dump_file (dump_base_name, ".jump2");
4291d9c8
RS
2354
2355 /* If dbr_sched dump desired, open the output file. */
2356 if (dbr_sched_dump)
dfe1a916 2357 dbr_sched_dump_file = open_dump_file (dump_base_name, ".dbr");
4291d9c8
RS
2358
2359#ifdef STACK_REGS
2360
2361 /* If stack_reg dump desired, open the output file. */
2362 if (stack_reg_dump)
dfe1a916 2363 stack_reg_dump_file = open_dump_file (dump_base_name, ".stack");
4291d9c8
RS
2364
2365#endif
2366
2367 /* Open assembler code output file. */
2368
2369 if (! name_specified && asm_file_name == 0)
2370 asm_out_file = stdout;
2371 else
2372 {
4291d9c8 2373 int len = strlen (dump_base_name);
dfe1a916 2374 register char *dumpname = (char *) xmalloc (len + 6);
4291d9c8
RS
2375 strcpy (dumpname, dump_base_name);
2376 strip_off_ending (dumpname, len);
2377 strcat (dumpname, ".s");
2378 if (asm_file_name == 0)
2379 {
2380 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
2381 strcpy (asm_file_name, dumpname);
2382 }
2383 if (!strcmp (asm_file_name, "-"))
2384 asm_out_file = stdout;
2385 else
2386 asm_out_file = fopen (asm_file_name, "w");
2387 if (asm_out_file == 0)
2388 pfatal_with_name (asm_file_name);
2389 }
2390
f246a305 2391#ifdef IO_BUFFER_SIZE
d7cedf4b
RS
2392 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
2393 _IOFBF, IO_BUFFER_SIZE);
f246a305
RS
2394#endif
2395
4291d9c8
RS
2396 input_filename = name;
2397
18736654
RK
2398 /* Put an entry on the input file stack for the main input file. */
2399 input_file_stack
2400 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2401 input_file_stack->next = 0;
2402 input_file_stack->name = input_filename;
2403
56bf1fd9
JL
2404 /* Gross. Gross. lang_init is (I think) the first callback into
2405 the language front end, and is thus the first opportunity to
2406 have the selected language override the default value for any
2407 -f option.
2408
2409 So the default value for flag_exceptions is 2 (uninitialized).
2410 If we encounter -fno-exceptions or -fexceptions, then flag_exceptions
2411 will be set to zero or one respectively.
2412
2413 flag_exceptions can also be set by lang_init to something other
2414 than the default "uninitialized" value of 2.
2415
2416 After lang_init, if the value is still 2, then we default to
2417 -fno-exceptions (value will be reset to zero).
2418
2419 When our EH mechanism is low enough overhead that we can enable
2420 it by default for languages other than C++, then all this braindamage
2421 will go away. */
2422
4291d9c8
RS
2423 /* Perform language-specific initialization.
2424 This may set main_input_filename. */
2425 lang_init ();
2426
56bf1fd9
JL
2427 if (flag_exceptions == 2)
2428 flag_exceptions = 0;
2429
4291d9c8
RS
2430 /* If the input doesn't start with a #line, use the input name
2431 as the official input file name. */
2432 if (main_input_filename == 0)
2433 main_input_filename = name;
2434
b93a436e 2435 ASM_FILE_START (asm_out_file);
3d5cdd42
DE
2436
2437#ifdef ASM_COMMENT_START
b93a436e
JL
2438 if (flag_verbose_asm)
2439 {
2440 /* Print the list of options in effect. */
2441 print_version (asm_out_file, ASM_COMMENT_START);
2442 print_switch_values (asm_out_file, 0, MAX_LINE,
3d5cdd42 2443 ASM_COMMENT_START, " ", "\n");
b93a436e
JL
2444 /* Add a blank line here so it appears in assembler output but not
2445 screen output. */
2446 fprintf (asm_out_file, "\n");
ca695ac9 2447 }
b93a436e 2448#endif
4291d9c8 2449
b93a436e 2450 /* Output something to inform GDB that this compilation was by GCC. */
4291d9c8 2451#ifndef ASM_IDENTIFY_GCC
b93a436e 2452 fprintf (asm_out_file, "gcc2_compiled.:\n");
4291d9c8 2453#else
b93a436e 2454 ASM_IDENTIFY_GCC (asm_out_file);
4291d9c8 2455#endif
d0d4af87 2456
0f41302f 2457 /* Output something to identify which front-end produced this file. */
d0d4af87
MS
2458#ifdef ASM_IDENTIFY_LANGUAGE
2459 ASM_IDENTIFY_LANGUAGE (asm_out_file);
2460#endif
2461
cf440348
JL
2462#ifndef ASM_OUTPUT_SECTION_NAME
2463 if (flag_function_sections)
2464 {
2465 warning ("-ffunction-sections not supported for this target.");
2466 flag_function_sections = 0;
2467 }
2468#endif
2469
2470 if (flag_function_sections
2471 && (profile_flag || profile_block_flag))
2472 {
2473 warning ("-ffunction-sections disabled; it makes profiling impossible.");
2474 flag_function_sections = 0;
2475 }
2476
2477 if (flag_function_sections && write_symbols != NO_DEBUG)
2478 warning ("-ffunction-sections may affect debugging on some targets.");
2479
b93a436e
JL
2480 /* ??? Note: There used to be a conditional here
2481 to call assemble_zeros without fail if DBX_DEBUGGING_INFO is defined.
2482 This was to guarantee separation between gcc_compiled. and
2483 the first function, for the sake of dbx on Suns.
2484 However, having the extra zero here confused the Emacs
2485 code for unexec, and might confuse other programs too.
2486 Therefore, I took out that change.
2487 In future versions we should find another way to solve
2488 that dbx problem. -- rms, 23 May 93. */
ca695ac9 2489
b93a436e
JL
2490 /* Don't let the first function fall at the same address
2491 as gcc_compiled., if profiling. */
2492 if (profile_flag || profile_block_flag)
2493 assemble_zeros (UNITS_PER_WORD);
4291d9c8
RS
2494
2495 /* If dbx symbol table desired, initialize writing it
2496 and output the predefined types. */
f246a305
RS
2497#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2498 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2499 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
2500 getdecls ()));
2501#endif
2502#ifdef SDB_DEBUGGING_INFO
2503 if (write_symbols == SDB_DEBUG)
2504 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
2505 getdecls ()));
2506#endif
2507#ifdef DWARF_DEBUGGING_INFO
2508 if (write_symbols == DWARF_DEBUG)
2509 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
2510#endif
0021b564
JM
2511#ifdef DWARF2_UNWIND_INFO
2512 if (dwarf2out_do_frame ())
2513 dwarf2out_frame_init ();
2514#endif
9a666dda
JM
2515#ifdef DWARF2_DEBUGGING_INFO
2516 if (write_symbols == DWARF2_DEBUG)
2517 TIMEVAR (symout_time, dwarf2out_init (asm_out_file, main_input_filename));
2518#endif
4291d9c8
RS
2519
2520 /* Initialize yet another pass. */
2521
b93a436e 2522 init_final (main_input_filename);
0d332add 2523 init_branch_prob (dump_base_name);
4291d9c8
RS
2524
2525 start_time = get_run_time ();
2526
2527 /* Call the parser, which parses the entire file
2528 (calling rest_of_compilation for each function). */
2529
2530 if (yyparse () != 0)
453dfc78
JW
2531 {
2532 if (errorcount == 0)
2533 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
2534
2535 /* In case there were missing closebraces,
2536 get us back to the global binding level. */
2537 while (! global_bindings_p ())
2538 poplevel (0, 0, 0);
2539 }
4291d9c8 2540
0d332add
DE
2541 output_func_start_profiler ();
2542
4291d9c8
RS
2543 /* Compilation is now finished except for writing
2544 what's left of the symbol table output. */
2545
2546 parse_time += get_run_time () - start_time;
2547
2548 parse_time -= integration_time;
2549 parse_time -= varconst_time;
2550
2551 globals = getdecls ();
2552
2553 /* Really define vars that have had only a tentative definition.
2554 Really output inline functions that must actually be callable
2555 and have not been output so far. */
2556
2557 {
2558 int len = list_length (globals);
2559 tree *vec = (tree *) alloca (sizeof (tree) * len);
2560 int i;
2561 tree decl;
2b6c54d6 2562 int reconsider = 1;
4291d9c8
RS
2563
2564 /* Process the decls in reverse order--earliest first.
2565 Put them into VEC from back to front, then take out from front. */
2566
2567 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
2568 vec[len - i - 1] = decl;
2569
2570 for (i = 0; i < len; i++)
2571 {
2572 decl = vec[i];
07af9d16
JM
2573
2574 /* We're not deferring this any longer. */
2575 DECL_DEFER_OUTPUT (decl) = 0;
2576
488b1f4f
RS
2577 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0
2578 && incomplete_decl_finalize_hook != 0)
2b599527 2579 (*incomplete_decl_finalize_hook) (decl);
2b6c54d6 2580 }
2b599527 2581
2b6c54d6
JM
2582 /* Now emit any global variables or functions that we have been putting
2583 off. We need to loop in case one of the things emitted here
2584 references another one which comes earlier in the list. */
2585 while (reconsider)
2586 {
2587 reconsider = 0;
2588 for (i = 0; i < len; i++)
4291d9c8 2589 {
2b6c54d6
JM
2590 decl = vec[i];
2591
2592 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
2593 continue;
2594
6b2bd61e
PB
2595 /* Don't write out static consts, unless we still need them.
2596
fbe912dd
BK
2597 We also keep static consts if not optimizing (for debugging),
2598 unless the user specified -fno-keep-static-consts.
6b2bd61e
PB
2599 ??? They might be better written into the debug information.
2600 This is possible when using DWARF.
2601
2602 A language processor that wants static constants to be always
2603 written out (even if it is not used) is responsible for
2604 calling rest_of_decl_compilation itself. E.g. the C front-end
2605 calls rest_of_decl_compilation from finish_decl.
2606 One motivation for this is that is conventional in some
2607 environments to write things like:
2608 static const char rcsid[] = "... version string ...";
2609 intending to force the string to be in the executable.
2610
2611 A language processor that would prefer to have unneeded
2612 static constants "optimized away" would just defer writing
2613 them out until here. E.g. C++ does this, because static
2614 constants are often defined in header files.
2615
2616 ??? A tempting alternative (for both C and C++) would be
2617 to force a constant to be written if and only if it is
0f41302f 2618 defined in a main file, as opposed to an include file. */
6b2bd61e 2619
2b6c54d6
JM
2620 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2621 && (! TREE_READONLY (decl)
2622 || TREE_PUBLIC (decl)
fbe912dd 2623 || (!optimize && flag_keep_static_consts)
2b6c54d6
JM
2624 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2625 {
2626 reconsider = 1;
2627 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
2628 }
2629
2630 if (TREE_CODE (decl) == FUNCTION_DECL
2631 && DECL_INITIAL (decl) != 0
2632 && DECL_SAVED_INSNS (decl) != 0
2633 && (flag_keep_inline_functions
2f8844a8 2634 || TREE_PUBLIC (decl)
2b6c54d6
JM
2635 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
2636 {
2637 reconsider = 1;
2638 temporary_allocation ();
2639 output_inline_function (decl);
2640 permanent_allocation (1);
2641 }
4291d9c8 2642 }
2b6c54d6 2643 }
4291d9c8 2644
3d195391
MS
2645 /* Now that all possible functions have been output, we can dump
2646 the exception table. */
2647
0021b564 2648 output_exception_table ();
3d195391 2649
2b6c54d6
JM
2650 for (i = 0; i < len; i++)
2651 {
2652 decl = vec[i];
2653
2654 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
2655 && ! TREE_ASM_WRITTEN (decl))
2656 /* Cancel the RTL for this decl so that, if debugging info
2657 output for global variables is still to come,
2658 this one will be omitted. */
2659 DECL_RTL (decl) = NULL;
4291d9c8 2660
ac266247
RS
2661 /* Warn about any function
2662 declared static but not defined.
2663 We don't warn about variables,
2664 because many programs have static variables
2665 that exist only to get some text into the object file. */
8c461ea1
JM
2666 if (TREE_CODE (decl) == FUNCTION_DECL
2667 && (warn_unused
2668 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
4291d9c8 2669 && DECL_INITIAL (decl) == 0
216d5cdd 2670 && DECL_EXTERNAL (decl)
d1b01681 2671 && ! DECL_ARTIFICIAL (decl)
4291d9c8 2672 && ! TREE_PUBLIC (decl))
7d429c41 2673 {
8c461ea1 2674 pedwarn_with_decl (decl,
7d429c41
RS
2675 "`%s' declared `static' but never defined");
2676 /* This symbol is effectively an "extern" declaration now. */
2677 TREE_PUBLIC (decl) = 1;
2678 assemble_external (decl);
7d429c41 2679 }
8c461ea1 2680
4291d9c8 2681 /* Warn about static fns or vars defined but not used,
7062b881
PB
2682 but not about inline functions or static consts
2683 since defining those in header files is normal practice. */
4291d9c8 2684 if (warn_unused
7062b881
PB
2685 && ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
2686 || (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
0c20aabf 2687 && ! DECL_IN_SYSTEM_HEADER (decl)
216d5cdd 2688 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2689 && ! TREE_PUBLIC (decl)
2690 && ! TREE_USED (decl)
f843649d 2691 && (TREE_CODE (decl) == FUNCTION_DECL || ! DECL_REGISTER (decl))
4291d9c8
RS
2692 /* The TREE_USED bit for file-scope decls
2693 is kept in the identifier, to handle multiple
2694 external decls in different scopes. */
2695 && ! TREE_USED (DECL_NAME (decl)))
2696 warning_with_decl (decl, "`%s' defined but not used");
2697
2698#ifdef SDB_DEBUGGING_INFO
2699 /* The COFF linker can move initialized global vars to the end.
2700 And that can screw up the symbol ordering.
2701 By putting the symbols in that order to begin with,
2702 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
2703 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
2704 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
7efad3f7 2705 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2706 && DECL_RTL (decl) != 0)
2707 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2708
2709 /* Output COFF information for non-global
0f41302f 2710 file-scope initialized variables. */
4291d9c8
RS
2711 if (write_symbols == SDB_DEBUG
2712 && TREE_CODE (decl) == VAR_DECL
2713 && DECL_INITIAL (decl)
7efad3f7 2714 && ! DECL_EXTERNAL (decl)
4291d9c8
RS
2715 && DECL_RTL (decl) != 0
2716 && GET_CODE (DECL_RTL (decl)) == MEM)
2717 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
2718#endif /* SDB_DEBUGGING_INFO */
2719#ifdef DWARF_DEBUGGING_INFO
6dc42e49 2720 /* Output DWARF information for file-scope tentative data object
4291d9c8
RS
2721 declarations, file-scope (extern) function declarations (which
2722 had no corresponding body) and file-scope tagged type declarations
2723 and definitions which have not yet been forced out. */
2724
2725 if (write_symbols == DWARF_DEBUG
2726 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
2727 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
9a666dda
JM
2728#endif
2729#ifdef DWARF2_DEBUGGING_INFO
2730 /* Output DWARF2 information for file-scope tentative data object
2731 declarations, file-scope (extern) function declarations (which
2732 had no corresponding body) and file-scope tagged type declarations
2733 and definitions which have not yet been forced out. */
2734
2735 if (write_symbols == DWARF2_DEBUG
2736 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
88dad228 2737 TIMEVAR (symout_time, dwarf2out_decl (decl));
4291d9c8
RS
2738#endif
2739 }
2740 }
2741
4b8af8d9
JM
2742 /* Write out any pending weak symbol declarations. */
2743
2744 weak_finish ();
2745
4291d9c8 2746 /* Do dbx symbols */
f246a305
RS
2747#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2748 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2749 TIMEVAR (symout_time,
2750 {
2751 dbxout_finish (asm_out_file, main_input_filename);
2752 });
2753#endif
2754
2755#ifdef DWARF_DEBUGGING_INFO
2756 if (write_symbols == DWARF_DEBUG)
2757 TIMEVAR (symout_time,
2758 {
2759 dwarfout_finish ();
2760 });
2761#endif
2762
0021b564
JM
2763#ifdef DWARF2_UNWIND_INFO
2764 if (dwarf2out_do_frame ())
2765 dwarf2out_frame_finish ();
2766#endif
2767
9a666dda
JM
2768#ifdef DWARF2_DEBUGGING_INFO
2769 if (write_symbols == DWARF2_DEBUG)
2770 TIMEVAR (symout_time,
2771 {
2772 dwarf2out_finish ();
2773 });
2774#endif
2775
4291d9c8
RS
2776 /* Output some stuff at end of file if nec. */
2777
b93a436e
JL
2778 end_final (dump_base_name);
2779 end_branch_prob (branch_prob_dump_file);
4291d9c8
RS
2780
2781#ifdef ASM_FILE_END
b93a436e 2782 ASM_FILE_END (asm_out_file);
4291d9c8
RS
2783#endif
2784
4291d9c8
RS
2785 /* Language-specific end of compilation actions. */
2786
2787 lang_finish ();
2788
2789 /* Close the dump files. */
2790
2791 if (flag_gen_aux_info)
2792 {
2793 fclose (aux_info_file);
2794 if (errorcount)
2795 unlink (aux_info_file_name);
2796 }
2797
2798 if (rtl_dump)
2799 fclose (rtl_dump_file);
2800
2801 if (jump_opt_dump)
2802 fclose (jump_opt_dump_file);
2803
e9a25f70
JL
2804 if (addressof_dump)
2805 fclose (addressof_dump_file);
2806
4291d9c8
RS
2807 if (cse_dump)
2808 fclose (cse_dump_file);
2809
2810 if (loop_dump)
2811 fclose (loop_dump_file);
2812
2813 if (cse2_dump)
2814 fclose (cse2_dump_file);
2815
0d332add
DE
2816 if (branch_prob_dump)
2817 fclose (branch_prob_dump_file);
2818
4291d9c8
RS
2819 if (flow_dump)
2820 fclose (flow_dump_file);
2821
2822 if (combine_dump)
2823 {
2824 dump_combine_total_stats (combine_dump_file);
2825 fclose (combine_dump_file);
2826 }
2827
8c660648
JL
2828 if (regmove_dump)
2829 fclose (regmove_dump_file);
2830
4291d9c8
RS
2831 if (sched_dump)
2832 fclose (sched_dump_file);
2833
2834 if (local_reg_dump)
2835 fclose (local_reg_dump_file);
2836
2837 if (global_reg_dump)
2838 fclose (global_reg_dump_file);
2839
2840 if (sched2_dump)
2841 fclose (sched2_dump_file);
2842
2843 if (jump2_opt_dump)
2844 fclose (jump2_opt_dump_file);
2845
2846 if (dbr_sched_dump)
2847 fclose (dbr_sched_dump_file);
2848
2849#ifdef STACK_REGS
2850 if (stack_reg_dump)
2851 fclose (stack_reg_dump_file);
2852#endif
2853
2854 /* Close non-debugging input and output files. Take special care to note
2855 whether fclose returns an error, since the pages might still be on the
2856 buffer chain while the file is open. */
2857
e3d1fd32
PB
2858#if USE_CPPLIB
2859 finish_parse ();
2860#else
4291d9c8 2861 fclose (finput);
e3d1fd32 2862#endif
4291d9c8
RS
2863 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
2864 fatal_io_error (asm_file_name);
2865
2866 /* Print the times. */
2867
2868 if (! quiet_flag)
2869 {
2870 fprintf (stderr,"\n");
2871 print_time ("parse", parse_time);
ca695ac9 2872
b93a436e
JL
2873 print_time ("integration", integration_time);
2874 print_time ("jump", jump_time);
2875 print_time ("cse", cse_time);
2876 print_time ("loop", loop_time);
2877 print_time ("cse2", cse2_time);
2878 print_time ("branch-prob", branch_prob_time);
2879 print_time ("flow", flow_time);
2880 print_time ("combine", combine_time);
2881 print_time ("regmove", regmove_time);
2882 print_time ("sched", sched_time);
2883 print_time ("local-alloc", local_alloc_time);
2884 print_time ("global-alloc", global_alloc_time);
2885 print_time ("sched2", sched2_time);
2886 print_time ("dbranch", dbr_sched_time);
2887 print_time ("shorten-branch", shorten_branch_time);
2888 print_time ("stack-reg", stack_reg_time);
2889 print_time ("final", final_time);
2890 print_time ("varconst", varconst_time);
2891 print_time ("symout", symout_time);
2892 print_time ("dump", dump_time);
4291d9c8
RS
2893 }
2894}
2895\f
2896/* This is called from various places for FUNCTION_DECL, VAR_DECL,
2897 and TYPE_DECL nodes.
2898
2899 This does nothing for local (non-static) variables.
2900 Otherwise, it sets up the RTL and outputs any assembler code
2901 (label definition, storage allocation and initialization).
2902
2903 DECL is the declaration. If ASMSPEC is nonzero, it specifies
2904 the assembler symbol name to be used. TOP_LEVEL is nonzero
2905 if this declaration is not within a function. */
2906
2907void
2908rest_of_decl_compilation (decl, asmspec, top_level, at_end)
2909 tree decl;
2910 char *asmspec;
2911 int top_level;
2912 int at_end;
2913{
2914 /* Declarations of variables, and of functions defined elsewhere. */
2915
928eb380
RS
2916/* The most obvious approach, to put an #ifndef around where
2917 this macro is used, doesn't work since it's inside a macro call. */
2918#ifndef ASM_FINISH_DECLARE_OBJECT
2919#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP, END)
2920#endif
2921
4291d9c8
RS
2922 /* Forward declarations for nested functions are not "external",
2923 but we need to treat them as if they were. */
216d5cdd 2924 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
4291d9c8
RS
2925 || TREE_CODE (decl) == FUNCTION_DECL)
2926 TIMEVAR (varconst_time,
2927 {
2928 make_decl_rtl (decl, asmspec, top_level);
9a9a9643
RS
2929 /* Initialized extern variable exists to be replaced
2930 with its value, or represents something that will be
2931 output in another file. */
6dbf678a 2932 if (! (TREE_CODE (decl) == VAR_DECL
9a9a9643
RS
2933 && DECL_EXTERNAL (decl) && TREE_READONLY (decl)
2934 && DECL_INITIAL (decl) != 0
5b272d50 2935 && DECL_INITIAL (decl) != error_mark_node))
6dbf678a
RS
2936 /* Don't output anything
2937 when a tentative file-scope definition is seen.
2938 But at end of compilation, do output code for them. */
2939 if (! (! at_end && top_level
2940 && (DECL_INITIAL (decl) == 0
9a9a9643 2941 || DECL_INITIAL (decl) == error_mark_node)))
8380e2f2 2942 assemble_variable (decl, top_level, at_end, 0);
b93a436e 2943 if (decl == last_assemble_variable_decl)
5e10b3cc
RS
2944 {
2945 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
2946 top_level, at_end);
2947 }
4291d9c8 2948 });
216d5cdd 2949 else if (DECL_REGISTER (decl) && asmspec != 0)
4291d9c8
RS
2950 {
2951 if (decode_reg_name (asmspec) >= 0)
2952 {
2953 DECL_RTL (decl) = 0;
2954 make_decl_rtl (decl, asmspec, top_level);
2955 }
2956 else
2957 error ("invalid register name `%s' for register variable", asmspec);
2958 }
f246a305
RS
2959#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2960 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2961 && TREE_CODE (decl) == TYPE_DECL)
4291d9c8
RS
2962 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
2963#endif
2964#ifdef SDB_DEBUGGING_INFO
2965 else if (write_symbols == SDB_DEBUG && top_level
2966 && TREE_CODE (decl) == TYPE_DECL)
2967 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
2968#endif
2969}
2970
2971/* Called after finishing a record, union or enumeral type. */
2972
2973void
2974rest_of_type_compilation (type, toplev)
2975 tree type;
2976 int toplev;
2977{
f246a305
RS
2978#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2979 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
4291d9c8
RS
2980 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
2981#endif
2982#ifdef SDB_DEBUGGING_INFO
2983 if (write_symbols == SDB_DEBUG)
2984 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
2985#endif
2986}
2987
2988/* This is called from finish_function (within yyparse)
2989 after each top-level definition is parsed.
2990 It is supposed to compile that function or variable
2991 and output the assembler code for it.
2992 After we return, the tree storage is freed. */
2993
2994void
2995rest_of_compilation (decl)
2996 tree decl;
2997{
2998 register rtx insns;
2999 int start_time = get_run_time ();
3000 int tem;
3001 /* Nonzero if we have saved the original DECL_INITIAL of the function,
3002 to be restored after we finish compiling the function
3003 (for use when compiling inline calls to this function). */
3004 tree saved_block_tree = 0;
8a958768
RS
3005 /* Likewise, for DECL_ARGUMENTS. */
3006 tree saved_arguments = 0;
ab40ad2b 3007 int failure = 0;
4291d9c8
RS
3008
3009 /* If we are reconsidering an inline function
3010 at the end of compilation, skip the stuff for making it inline. */
3011
3012 if (DECL_SAVED_INSNS (decl) == 0)
3013 {
956d6950 3014 int inlinable = 0;
4291d9c8
RS
3015 char *lose;
3016
3017 /* If requested, consider whether to make this function inline. */
9deaf1b1 3018 if (DECL_INLINE (decl) || flag_inline_functions)
4291d9c8
RS
3019 TIMEVAR (integration_time,
3020 {
3021 lose = function_cannot_inline_p (decl);
caa0eccd 3022 if (lose || ! optimize)
4291d9c8 3023 {
9deaf1b1 3024 if (warn_inline && DECL_INLINE (decl))
4291d9c8 3025 warning_with_decl (decl, lose);
9548c538 3026 DECL_ABSTRACT_ORIGIN (decl) = 0;
46dbb914
RS
3027 /* Don't really compile an extern inline function.
3028 If we can't make it inline, pretend
3029 it was only declared. */
3030 if (DECL_EXTERNAL (decl))
27937f46
RS
3031 {
3032 DECL_INITIAL (decl) = 0;
3033 goto exit_rest_of_compilation;
3034 }
4291d9c8
RS
3035 }
3036 else
9deaf1b1
RK
3037 /* ??? Note that this has the effect of making it look
3038 like "inline" was specified for a function if we choose
3039 to inline it. This isn't quite right, but it's
3040 probably not worth the trouble to fix. */
956d6950 3041 inlinable = DECL_INLINE (decl) = 1;
4291d9c8
RS
3042 });
3043
3044 insns = get_insns ();
3045
3046 /* Dump the rtl code if we are dumping rtl. */
3047
3048 if (rtl_dump)
3049 TIMEVAR (dump_time,
3050 {
3051 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2f8844a8 3052 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3053 if (DECL_SAVED_INSNS (decl))
3054 fprintf (rtl_dump_file, ";; (integrable)\n\n");
3055 print_rtl (rtl_dump_file, insns);
3056 fflush (rtl_dump_file);
3057 });
3058
c0da11c4
JM
3059 /* If we can, defer compiling inlines until EOF.
3060 save_for_inline_copying can be extremely expensive. */
956d6950 3061 if (inlinable && ! decl_function_context (decl))
c0da11c4
JM
3062 DECL_DEFER_OUTPUT (decl) = 1;
3063
4291d9c8
RS
3064 /* If function is inline, and we don't yet know whether to
3065 compile it by itself, defer decision till end of compilation.
3066 finish_compilation will call rest_of_compilation again
16411ea6 3067 for those functions that need to be output. Also defer those
ec6c615d
RK
3068 functions that we are supposed to defer. We cannot defer
3069 functions containing nested functions since the nested function
3070 data is in our non-saved obstack. */
3071
e9a25f70
JL
3072 /* If this is a nested inline, remove ADDRESSOF now so we can
3073 finish compiling ourselves. Otherwise, wait until EOF.
3074 We have to do this because the purge_addressof transformation
3075 changes the DECL_RTL for many variables, which confuses integrate. */
956d6950 3076 if (inlinable)
e9a25f70
JL
3077 {
3078 if (decl_function_context (decl))
3079 purge_addressof (insns);
3080 else
3081 DECL_DEFER_OUTPUT (decl) = 1;
3082 }
3083
ec6c615d
RK
3084 if (! current_function_contains_functions
3085 && (DECL_DEFER_OUTPUT (decl)
9deaf1b1 3086 || (DECL_INLINE (decl)
ec6c615d
RK
3087 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
3088 && ! flag_keep_inline_functions)
3089 || DECL_EXTERNAL (decl)))))
4291d9c8 3090 {
951af26e
JM
3091 DECL_DEFER_OUTPUT (decl) = 1;
3092
a701efba
MM
3093 /* If -Wreturn-type, we have to do a bit of compilation.
3094 However, if we just fall through we will call
3095 save_for_inline_copying() which results in excessive
3096 memory use. Instead, we just want to call
3097 jump_optimize() to figure out whether or not we can fall
3098 off the end of the function; we do the minimum amount of
3099 work necessary to make that safe. And, we set optimize
3100 to zero to keep jump_optimize from working too hard. */
3101 if (warn_return_type)
937522b5 3102 {
a701efba
MM
3103 int saved_optimize = optimize;
3104 optimize = 0;
3105 find_exception_handler_labels ();
3106 jump_optimize (get_insns(), 0, 0, 0);
3107 optimize = saved_optimize;
3108 }
3109
951af26e 3110#ifdef DWARF_DEBUGGING_INFO
a701efba
MM
3111 /* Generate the DWARF info for the "abstract" instance
3112 of a function which we may later generate inlined and/or
3113 out-of-line instances of. */
3114 if (write_symbols == DWARF_DEBUG)
3115 {
3116 set_decl_abstract_flags (decl, 1);
3117 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3118 set_decl_abstract_flags (decl, 0);
3119 }
9a666dda
JM
3120#endif
3121#ifdef DWARF2_DEBUGGING_INFO
a701efba
MM
3122 /* Generate the DWARF2 info for the "abstract" instance
3123 of a function which we may later generate inlined and/or
3124 out-of-line instances of. */
3125 if (write_symbols == DWARF2_DEBUG)
3126 {
3127 set_decl_abstract_flags (decl, 1);
3128 TIMEVAR (symout_time, dwarf2out_decl (decl));
3129 set_decl_abstract_flags (decl, 0);
937522b5 3130 }
a701efba
MM
3131#endif
3132 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
3133 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
3134 goto exit_rest_of_compilation;
4291d9c8
RS
3135 }
3136
8a958768 3137 /* If we have to compile the function now, save its rtl and subdecls
4291d9c8 3138 so that its compilation will not affect what others get. */
956d6950 3139 if (inlinable || DECL_DEFER_OUTPUT (decl))
4291d9c8 3140 {
937522b5
RS
3141#ifdef DWARF_DEBUGGING_INFO
3142 /* Generate the DWARF info for the "abstract" instance of
3143 a function which we will generate an out-of-line instance
3144 of almost immediately (and which we may also later generate
3145 various inlined instances of). */
3146 if (write_symbols == DWARF_DEBUG)
3147 {
3148 set_decl_abstract_flags (decl, 1);
3149 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3150 set_decl_abstract_flags (decl, 0);
3151 }
9a666dda
JM
3152#endif
3153#ifdef DWARF2_DEBUGGING_INFO
3154 /* Generate the DWARF2 info for the "abstract" instance of
3155 a function which we will generate an out-of-line instance
3156 of almost immediately (and which we may also later generate
3157 various inlined instances of). */
3158 if (write_symbols == DWARF2_DEBUG)
3159 {
3160 set_decl_abstract_flags (decl, 1);
88dad228 3161 TIMEVAR (symout_time, dwarf2out_decl (decl));
9a666dda
JM
3162 set_decl_abstract_flags (decl, 0);
3163 }
937522b5 3164#endif
4291d9c8 3165 saved_block_tree = DECL_INITIAL (decl);
8a958768 3166 saved_arguments = DECL_ARGUMENTS (decl);
4291d9c8 3167 TIMEVAR (integration_time, save_for_inline_copying (decl));
956d6950 3168 RTX_INTEGRATED_P (DECL_SAVED_INSNS (decl)) = inlinable;
4291d9c8 3169 }
4291d9c8 3170
b8471b65
RK
3171 /* If specified extern inline but we aren't inlining it, we are
3172 done. */
9deaf1b1 3173 if (DECL_INLINE (decl) && DECL_EXTERNAL (decl))
b8471b65
RK
3174 goto exit_rest_of_compilation;
3175 }
07af9d16 3176
951af26e
JM
3177 if (! DECL_DEFER_OUTPUT (decl))
3178 TREE_ASM_WRITTEN (decl) = 1;
4291d9c8
RS
3179
3180 /* Now that integrate will no longer see our rtl, we need not distinguish
3181 between the return value of this function and the return value of called
3182 functions. */
3183 rtx_equal_function_value_matters = 0;
3184
32235b30
RS
3185 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
3186 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
4291d9c8
RS
3187 {
3188 goto exit_rest_of_compilation;
3189 }
3190
154bba13
TT
3191 /* Emit code to get eh context, if needed. */
3192 emit_eh_context ();
3193
4291d9c8
RS
3194#ifdef FINALIZE_PIC
3195 /* If we are doing position-independent code generation, now
3196 is the time to output special prologues and epilogues.
3197 We do not want to do this earlier, because it just clutters
3198 up inline functions with meaningless insns. */
3199 if (flag_pic)
3200 FINALIZE_PIC;
3201#endif
3202
89418a92
BK
3203 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
3204 Note that that may have been done above, in save_for_inline_copying.
3205 The call to resume_temporary_allocation near the end of this function
3206 goes back to the usual state of affairs. This must be done after
3207 we've built up any unwinders for exception handling, and done
3208 the FINALIZE_PIC work, if necessary. */
3209
3210 rtl_in_current_obstack ();
3d195391 3211
4291d9c8
RS
3212 insns = get_insns ();
3213
3214 /* Copy any shared structure that should not be shared. */
3215
3216 unshare_all_rtl (insns);
3217
c9ec4f99
DM
3218#ifdef SETJMP_VIA_SAVE_AREA
3219 /* This must be performed before virutal register instantiation. */
3220 if (current_function_calls_alloca)
3221 optimize_save_area_alloca (insns);
3222#endif
3223
4291d9c8
RS
3224 /* Instantiate all virtual registers. */
3225
3226 instantiate_virtual_regs (current_function_decl, get_insns ());
3227
3228 /* See if we have allocated stack slots that are not directly addressable.
3229 If so, scan all the insns and create explicit address computation
3230 for all references to such slots. */
3231/* fixup_stack_slots (); */
3232
3d195391
MS
3233 /* Find all the EH handlers. */
3234 find_exception_handler_labels ();
3235
cc4e79d8
JL
3236 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3237 are initialized and to compute whether control can drop off the end
3238 of the function. */
3239 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3240 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
4291d9c8 3241
32235b30 3242 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
951af26e 3243 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
32235b30
RS
3244 goto exit_rest_of_compilation;
3245
4291d9c8
RS
3246 /* Dump rtl code after jump, if we are doing that. */
3247
3248 if (jump_opt_dump)
3249 TIMEVAR (dump_time,
3250 {
3251 fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
2f8844a8 3252 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3253 print_rtl (jump_opt_dump_file, insns);
3254 fflush (jump_opt_dump_file);
3255 });
3256
3257 /* Perform common subexpression elimination.
3258 Nonzero value from `cse_main' means that jumps were simplified
3259 and some code may now be unreachable, so do
3260 jump optimization again. */
3261
3262 if (cse_dump)
3263 TIMEVAR (dump_time,
3264 {
3265 fprintf (cse_dump_file, "\n;; Function %s\n\n",
2f8844a8 3266 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3267 });
3268
3269 if (optimize > 0)
3270 {
3271 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
3272
3273 if (flag_thread_jumps)
3274 /* Hacks by tiemann & kenner. */
6f606d63 3275 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 1));
4291d9c8
RS
3276
3277 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
3278 0, cse_dump_file));
3279 TIMEVAR (cse_time, delete_dead_from_cse (insns, max_reg_num ()));
3280
534bfae4 3281 if (tem || optimize > 1)
4291d9c8
RS
3282 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3283 }
3284
3285 /* Dump rtl code after cse, if we are doing that. */
3286
3287 if (cse_dump)
3288 TIMEVAR (dump_time,
3289 {
3290 print_rtl (cse_dump_file, insns);
3291 fflush (cse_dump_file);
3292 });
3293
e9a25f70
JL
3294 purge_addressof (insns);
3295 reg_scan (insns, max_reg_num (), 1);
3296
3297 if (addressof_dump)
3298 TIMEVAR (dump_time,
3299 {
3300 fprintf (addressof_dump_file, "\n;; Function %s\n\n",
3301 (*decl_printable_name) (decl, 2));
3302 print_rtl (addressof_dump_file, insns);
3303 fflush (addressof_dump_file);
3304 });
3305
4291d9c8
RS
3306 if (loop_dump)
3307 TIMEVAR (dump_time,
3308 {
3309 fprintf (loop_dump_file, "\n;; Function %s\n\n",
2f8844a8 3310 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3311 });
3312
3313 /* Move constant computations out of loops. */
3314
3315 if (optimize > 0)
3316 {
3317 TIMEVAR (loop_time,
3318 {
6d6d0fa0
JL
3319 if (flag_rerun_loop_opt)
3320 {
3321 /* We only want to perform unrolling once. */
6d6d0fa0 3322
81797aba 3323 loop_optimize (insns, loop_dump_file, 0);
6d6d0fa0
JL
3324
3325 /* The regscan pass may not be necessary, but let's
3326 be safe until we can prove otherwise. */
3327 reg_scan (insns, max_reg_num (), 1);
6d6d0fa0 3328 }
81797aba 3329 loop_optimize (insns, loop_dump_file, flag_unroll_loops);
4291d9c8
RS
3330 });
3331 }
3332
3333 /* Dump rtl code after loop opt, if we are doing that. */
3334
3335 if (loop_dump)
3336 TIMEVAR (dump_time,
3337 {
3338 print_rtl (loop_dump_file, insns);
3339 fflush (loop_dump_file);
3340 });
3341
3342 if (cse2_dump)
3343 TIMEVAR (dump_time,
3344 {
3345 fprintf (cse2_dump_file, "\n;; Function %s\n\n",
2f8844a8 3346 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3347 });
3348
3349 if (optimize > 0 && flag_rerun_cse_after_loop)
3350 {
44333223
JL
3351 /* Running another jump optimization pass before the second
3352 cse pass sometimes simplifies the RTL enough to allow
9e9b48a4
DE
3353 the second CSE pass to do a better job. Jump_optimize can change
3354 max_reg_num so we must rerun reg_scan afterwards.
3355 ??? Rework to not call reg_scan so often. */
3356 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
44333223 3357 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
4291d9c8 3358
9e9b48a4 3359 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
4291d9c8
RS
3360 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
3361 1, cse2_dump_file));
3362 if (tem)
3363 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
3364 }
3365
3366 if (optimize > 0 && flag_thread_jumps)
c2f006ec
RK
3367 {
3368 /* This pass of jump threading straightens out code
3369 that was kinked by loop optimization. */
3370 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
3371 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
3372 }
4291d9c8
RS
3373 /* Dump rtl code after cse, if we are doing that. */
3374
3375 if (cse2_dump)
3376 TIMEVAR (dump_time,
3377 {
3378 print_rtl (cse2_dump_file, insns);
3379 fflush (cse2_dump_file);
3380 });
3381
0d332add
DE
3382 if (branch_prob_dump)
3383 TIMEVAR (dump_time,
3384 {
3385 fprintf (branch_prob_dump_file, "\n;; Function %s\n\n",
2f8844a8 3386 (*decl_printable_name) (decl, 2));
0d332add
DE
3387 });
3388
3389 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3390 TIMEVAR (branch_prob_time,
3391 {
3392 branch_prob (insns, branch_prob_dump_file);
3393 });
3394
3395 if (branch_prob_dump)
3396 TIMEVAR (dump_time,
3397 {
3398 print_rtl (branch_prob_dump_file, insns);
3399 fflush (branch_prob_dump_file);
3400 });
4291d9c8
RS
3401 /* We are no longer anticipating cse in this function, at least. */
3402
3403 cse_not_expected = 1;
3404
3405 /* Now we choose between stupid (pcc-like) register allocation
3406 (if we got the -noreg switch and not -opt)
3407 and smart register allocation. */
3408
3409 if (optimize > 0) /* Stupid allocation probably won't work */
3410 obey_regdecls = 0; /* if optimizations being done. */
3411
3412 regclass_init ();
3413
3414 /* Print function header into flow dump now
3415 because doing the flow analysis makes some of the dump. */
3416
3417 if (flow_dump)
3418 TIMEVAR (dump_time,
3419 {
3420 fprintf (flow_dump_file, "\n;; Function %s\n\n",
2f8844a8 3421 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3422 });
3423
3424 if (obey_regdecls)
3425 {
3426 TIMEVAR (flow_time,
3427 {
3428 regclass (insns, max_reg_num ());
3429 stupid_life_analysis (insns, max_reg_num (),
3430 flow_dump_file);
3431 });
3432 }
3433 else
3434 {
3435 /* Do control and data flow analysis,
3436 and write some of the results to dump file. */
3437
3438 TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
3439 flow_dump_file));
3440 if (warn_uninitialized)
3441 {
3442 uninitialized_vars_warning (DECL_INITIAL (decl));
3443 setjmp_args_warning ();
3444 }
3445 }
3446
3447 /* Dump rtl after flow analysis. */
3448
3449 if (flow_dump)
3450 TIMEVAR (dump_time,
3451 {
3e28fe44 3452 print_rtl_with_bb (flow_dump_file, insns);
4291d9c8
RS
3453 fflush (flow_dump_file);
3454 });
3455
3456 /* If -opt, try combining insns through substitution. */
3457
3458 if (optimize > 0)
3459 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
3460
3461 /* Dump rtl code after insn combination. */
3462
3463 if (combine_dump)
3464 TIMEVAR (dump_time,
3465 {
3466 fprintf (combine_dump_file, "\n;; Function %s\n\n",
2f8844a8 3467 (*decl_printable_name) (decl, 2));
4291d9c8 3468 dump_combine_stats (combine_dump_file);
3e28fe44 3469 print_rtl_with_bb (combine_dump_file, insns);
4291d9c8
RS
3470 fflush (combine_dump_file);
3471 });
3472
8c660648
JL
3473 if (regmove_dump)
3474 TIMEVAR (dump_time,
3475 {
3476 fprintf (regmove_dump_file, "\n;; Function %s\n\n",
3477 (*decl_printable_name) (decl, 2));
3478 });
3479
3480 /* Register allocation pre-pass, to reduce number of moves
3481 necessary for two-address machines. */
3482 if (optimize > 0 && flag_regmove)
3483 TIMEVAR (regmove_time, regmove_optimize (insns, max_reg_num (),
3484 regmove_dump_file));
3485
3486 if (regmove_dump)
3487 TIMEVAR (dump_time,
3488 {
3e28fe44 3489 print_rtl_with_bb (regmove_dump_file, insns);
8c660648
JL
3490 fflush (regmove_dump_file);
3491 });
3492
4291d9c8
RS
3493 /* Print function header into sched dump now
3494 because doing the sched analysis makes some of the dump. */
3495
3496 if (sched_dump)
3497 TIMEVAR (dump_time,
3498 {
3499 fprintf (sched_dump_file, "\n;; Function %s\n\n",
2f8844a8 3500 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3501 });
3502
3503 if (optimize > 0 && flag_schedule_insns)
3504 {
3505 /* Do control and data sched analysis,
3506 and write some of the results to dump file. */
3507
3508 TIMEVAR (sched_time, schedule_insns (sched_dump_file));
3509 }
3510
3511 /* Dump rtl after instruction scheduling. */
3512
3513 if (sched_dump)
3514 TIMEVAR (dump_time,
3515 {
3e28fe44 3516 print_rtl_with_bb (sched_dump_file, insns);
4291d9c8
RS
3517 fflush (sched_dump_file);
3518 });
3519
3520 /* Unless we did stupid register allocation,
3521 allocate pseudo-regs that are used only within 1 basic block. */
3522
3523 if (!obey_regdecls)
3524 TIMEVAR (local_alloc_time,
3525 {
3526 regclass (insns, max_reg_num ());
3527 local_alloc ();
3528 });
3529
3530 /* Dump rtl code after allocating regs within basic blocks. */
3531
3532 if (local_reg_dump)
3533 TIMEVAR (dump_time,
3534 {
3535 fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
2f8844a8 3536 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3537 dump_flow_info (local_reg_dump_file);
3538 dump_local_alloc (local_reg_dump_file);
3e28fe44 3539 print_rtl_with_bb (local_reg_dump_file, insns);
4291d9c8
RS
3540 fflush (local_reg_dump_file);
3541 });
3542
3543 if (global_reg_dump)
3544 TIMEVAR (dump_time,
3545 fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
2f8844a8 3546 (*decl_printable_name) (decl, 2)));
4291d9c8 3547
bf8b4985
RK
3548 /* Save the last label number used so far, so reorg can tell
3549 when it's safe to kill spill regs. */
3550 max_label_num_after_reload = max_label_num ();
3551
4291d9c8
RS
3552 /* Unless we did stupid register allocation,
3553 allocate remaining pseudo-regs, then do the reload pass
3554 fixing up any insns that are invalid. */
3555
3556 TIMEVAR (global_alloc_time,
3557 {
3558 if (!obey_regdecls)
37366632 3559 failure = global_alloc (global_reg_dump_file);
4291d9c8 3560 else
37366632 3561 failure = reload (insns, 0, global_reg_dump_file);
4291d9c8
RS
3562 });
3563
3564 if (global_reg_dump)
3565 TIMEVAR (dump_time,
3566 {
3567 dump_global_regs (global_reg_dump_file);
3e28fe44 3568 print_rtl_with_bb (global_reg_dump_file, insns);
4291d9c8
RS
3569 fflush (global_reg_dump_file);
3570 });
3571
ab40ad2b
RS
3572 if (failure)
3573 goto exit_rest_of_compilation;
3574
4291d9c8
RS
3575 reload_completed = 1;
3576
c8ed219d
RK
3577 /* Do a very simple CSE pass over just the hard registers. */
3578 if (optimize > 0)
3579 reload_cse_regs (insns);
3580
bdac5f58
TW
3581 /* On some machines, the prologue and epilogue code, or parts thereof,
3582 can be represented as RTL. Doing so lets us schedule insns between
3583 it and the rest of the code and also allows delayed branch
3584 scheduling to operate in the epilogue. */
3585
3586 thread_prologue_and_epilogue_insns (insns);
3587
4291d9c8
RS
3588 if (optimize > 0 && flag_schedule_insns_after_reload)
3589 {
3590 if (sched2_dump)
3591 TIMEVAR (dump_time,
3592 {
3593 fprintf (sched2_dump_file, "\n;; Function %s\n\n",
2f8844a8 3594 (*decl_printable_name) (decl, 2));
4291d9c8
RS
3595 });
3596
3597 /* Do control and data sched analysis again,
3598 and write some more of the results to dump file. */
3599
3600 TIMEVAR (sched2_time, schedule_insns (sched2_dump_file));
3601
3602 /* Dump rtl after post-reorder instruction scheduling. */
3603
3604 if (sched2_dump)
3605 TIMEVAR (dump_time,
3606 {
3e28fe44 3607 print_rtl_with_bb (sched2_dump_file, insns);
4291d9c8
RS
3608 fflush (sched2_dump_file);
3609 });
3610 }
3611
3612#ifdef LEAF_REGISTERS
3613 leaf_function = 0;
3614 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
ab40ad2b 3615 leaf_function = 1;
4291d9c8
RS
3616#endif
3617
3618 /* One more attempt to remove jumps to .+1
3619 left by dead-store-elimination.
3620 Also do cross-jumping this time
3621 and delete no-op move insns. */
3622
3623 if (optimize > 0)
3624 {
3625 TIMEVAR (jump_time, jump_optimize (insns, 1, 1, 0));
3626 }
3627
3628 /* Dump rtl code after jump, if we are doing that. */
3629
3630 if (jump2_opt_dump)
3631 TIMEVAR (dump_time,
3632 {
3633 fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
2f8844a8 3634 (*decl_printable_name) (decl, 2));
3e28fe44 3635 print_rtl_with_bb (jump2_opt_dump_file, insns);
4291d9c8
RS
3636 fflush (jump2_opt_dump_file);
3637 });
3638
2c65021a
RK
3639 /* If a machine dependent reorganization is needed, call it. */
3640#ifdef MACHINE_DEPENDENT_REORG
3641 MACHINE_DEPENDENT_REORG (insns);
3642#endif
3643
4291d9c8 3644 /* If a scheduling pass for delayed branches is to be done,
0f41302f 3645 call the scheduling code. */
4291d9c8
RS
3646
3647#ifdef DELAY_SLOTS
3648 if (optimize > 0 && flag_delayed_branch)
3649 {
3650 TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
3651 if (dbr_sched_dump)
3652 {
3653 TIMEVAR (dump_time,
3654 {
3655 fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
2f8844a8 3656 (*decl_printable_name) (decl, 2));
3e28fe44 3657 print_rtl_with_bb (dbr_sched_dump_file, insns);
4291d9c8
RS
3658 fflush (dbr_sched_dump_file);
3659 });
3660 }
3661 }
3662#endif
3663
d0c874f6
TG
3664 /* Shorten branches. */
3665 TIMEVAR (shorten_branch_time,
3666 {
3667 shorten_branches (get_insns ());
3668 });
4291d9c8
RS
3669
3670#ifdef STACK_REGS
3671 TIMEVAR (stack_reg_time, reg_to_stack (insns, stack_reg_dump_file));
3672 if (stack_reg_dump)
3673 {
3674 TIMEVAR (dump_time,
3675 {
3676 fprintf (stack_reg_dump_file, "\n;; Function %s\n\n",
2f8844a8 3677 (*decl_printable_name) (decl, 2));
3e28fe44 3678 print_rtl_with_bb (stack_reg_dump_file, insns);
4291d9c8
RS
3679 fflush (stack_reg_dump_file);
3680 });
3681 }
3682#endif
3683
3684 /* Now turn the rtl into assembler code. */
3685
3686 TIMEVAR (final_time,
3687 {
3688 rtx x;
3689 char *fnname;
3690
3691 /* Get the function's name, as described by its RTL.
3692 This may be different from the DECL_NAME name used
3693 in the source file. */
3694
3695 x = DECL_RTL (decl);
3696 if (GET_CODE (x) != MEM)
3697 abort ();
3698 x = XEXP (x, 0);
3699 if (GET_CODE (x) != SYMBOL_REF)
3700 abort ();
3701 fnname = XSTR (x, 0);
3702
3703 assemble_start_function (decl, fnname);
3704 final_start_function (insns, asm_out_file, optimize);
3705 final (insns, asm_out_file, optimize, 0);
3706 final_end_function (insns, asm_out_file, optimize);
3707 assemble_end_function (decl, fnname);
3708 fflush (asm_out_file);
9ddca353
RK
3709
3710 /* Release all memory held by regsets now */
3711 regset_release_memory ();
4291d9c8
RS
3712 });
3713
3714 /* Write DBX symbols if requested */
3715
3716 /* Note that for those inline functions where we don't initially
3717 know for certain that we will be generating an out-of-line copy,
3718 the first invocation of this routine (rest_of_compilation) will
3719 skip over this code by doing a `goto exit_rest_of_compilation;'.
3720 Later on, finish_compilation will call rest_of_compilation again
3721 for those inline functions that need to have out-of-line copies
3722 generated. During that call, we *will* be routed past here. */
3723
3724#ifdef DBX_DEBUGGING_INFO
3725 if (write_symbols == DBX_DEBUG)
3726 TIMEVAR (symout_time, dbxout_function (decl));
3727#endif
3728
3729#ifdef DWARF_DEBUGGING_INFO
3730 if (write_symbols == DWARF_DEBUG)
3731 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
3732#endif
3733
9a666dda
JM
3734#ifdef DWARF2_DEBUGGING_INFO
3735 if (write_symbols == DWARF2_DEBUG)
88dad228 3736 TIMEVAR (symout_time, dwarf2out_decl (decl));
9a666dda
JM
3737#endif
3738
4291d9c8
RS
3739 exit_rest_of_compilation:
3740
f246a305
RS
3741 /* In case the function was not output,
3742 don't leave any temporary anonymous types
3743 queued up for sdb output. */
3744#ifdef SDB_DEBUGGING_INFO
3745 if (write_symbols == SDB_DEBUG)
37366632 3746 sdbout_types (NULL_TREE);
f246a305
RS
3747#endif
3748
8a958768
RS
3749 /* Put back the tree of subblocks and list of arguments
3750 from before we copied them.
4291d9c8
RS
3751 Code generation and the output of debugging info may have modified
3752 the copy, but the original is unchanged. */
3753
3754 if (saved_block_tree != 0)
fb19c456
JM
3755 {
3756 DECL_INITIAL (decl) = saved_block_tree;
3757 DECL_ARGUMENTS (decl) = saved_arguments;
3758 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
3759 }
4291d9c8
RS
3760
3761 reload_completed = 0;
3762
9fe320d7
RK
3763 /* Clear out the insn_length contents now that they are no longer valid. */
3764 init_insn_lengths ();
3765
4291d9c8
RS
3766 /* Clear out the real_constant_chain before some of the rtx's
3767 it runs through become garbage. */
3768
3769 clear_const_double_mem ();
3770
3771 /* Cancel the effect of rtl_in_current_obstack. */
3772
3773 resume_temporary_allocation ();
3774
adcd38c9
RK
3775 /* Show no temporary slots allocated. */
3776
3777 init_temp_slots ();
3778
4291d9c8
RS
3779 /* The parsing time is all the time spent in yyparse
3780 *except* what is spent in this function. */
3781
3782 parse_time -= get_run_time () - start_time;
3783}
3784\f
3785/* Entry point of cc1/c++. Decode command args, then call compile_file.
3786 Exit code is 35 if can't open files, 34 if fatal error,
3787 33 if had nonfatal errors, else success. */
3788
3789int
3790main (argc, argv, envp)
3791 int argc;
3792 char **argv;
3793 char **envp;
3794{
3795 register int i;
3796 char *filename = 0;
3797 int flag_print_mem = 0;
3798 int version_flag = 0;
3799 char *p;
3800
3801 /* save in case md file wants to emit args as a comment. */
3802 save_argc = argc;
3803 save_argv = argv;
3804
3805 p = argv[0] + strlen (argv[0]);
128373ac
RK
3806 while (p != argv[0] && p[-1] != '/'
3807#ifdef DIR_SEPARATOR
3808 && p[-1] != DIR_SEPARATOR
3809#endif
3810 )
3811 --p;
4291d9c8
RS
3812 progname = p;
3813
08ce3276 3814#if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
4291d9c8
RS
3815 /* Get rid of any avoidable limit on stack size. */
3816 {
3817 struct rlimit rlim;
3818
0f41302f 3819 /* Set the stack limit huge so that alloca does not fail. */
4291d9c8
RS
3820 getrlimit (RLIMIT_STACK, &rlim);
3821 rlim.rlim_cur = rlim.rlim_max;
3822 setrlimit (RLIMIT_STACK, &rlim);
3823 }
c85f7c16 3824#endif
4291d9c8
RS
3825
3826 signal (SIGFPE, float_signal);
3827
935d4b07 3828#ifdef SIGPIPE
4291d9c8 3829 signal (SIGPIPE, pipe_closed);
935d4b07 3830#endif
4291d9c8
RS
3831
3832 decl_printable_name = decl_name;
3833 lang_expand_expr = (struct rtx_def *(*)()) do_abort;
3834
3835 /* Initialize whether `char' is signed. */
3836 flag_signed_char = DEFAULT_SIGNED_CHAR;
3837#ifdef DEFAULT_SHORT_ENUMS
3838 /* Initialize how much space enums occupy, by default. */
3839 flag_short_enums = DEFAULT_SHORT_ENUMS;
3840#endif
3841
3842 /* Scan to see what optimization level has been specified. That will
3843 determine the default value of many flags. */
3844 for (i = 1; i < argc; i++)
3845 {
3846 if (!strcmp (argv[i], "-O"))
3847 {
3848 optimize = 1;
3849 }
3850 else if (argv[i][0] == '-' && argv[i][1] == 'O')
3851 {
3852 /* Handle -O2, -O3, -O69, ... */
3853 char *p = &argv[i][2];
3854 int c;
3855
3856 while (c = *p++)
3857 if (! (c >= '0' && c <= '9'))
3858 break;
3859 if (c == 0)
3860 optimize = atoi (&argv[i][2]);
3861 }
3862 }
3863
3864 obey_regdecls = (optimize == 0);
4291d9c8
RS
3865
3866 if (optimize >= 1)
3867 {
6731a3e3 3868 flag_defer_pop = 1;
4291d9c8
RS
3869 flag_thread_jumps = 1;
3870#ifdef DELAY_SLOTS
3871 flag_delayed_branch = 1;
7e89c3a3
RK
3872#endif
3873#ifdef CAN_DEBUG_WITHOUT_FP
3874 flag_omit_frame_pointer = 1;
4291d9c8
RS
3875#endif
3876 }
3877
3878 if (optimize >= 2)
3879 {
3880 flag_cse_follow_jumps = 1;
8b3686ed 3881 flag_cse_skip_blocks = 1;
4291d9c8
RS
3882 flag_expensive_optimizations = 1;
3883 flag_strength_reduce = 1;
3884 flag_rerun_cse_after_loop = 1;
6d6d0fa0 3885 flag_rerun_loop_opt = 1;
ac266247 3886 flag_caller_saves = 1;
4ac8e06e 3887 flag_force_mem = 1;
4291d9c8
RS
3888#ifdef INSN_SCHEDULING
3889 flag_schedule_insns = 1;
3890 flag_schedule_insns_after_reload = 1;
3891#endif
8c660648 3892 flag_regmove = 1;
4291d9c8
RS
3893 }
3894
7e89c3a3
RK
3895 if (optimize >= 3)
3896 {
3897 flag_inline_functions = 1;
3898 }
3899
c1da383f
DE
3900 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
3901 modify it. */
3902 target_flags = 0;
3903 set_target_switch ("");
3904
4291d9c8
RS
3905#ifdef OPTIMIZATION_OPTIONS
3906 /* Allow default optimizations to be specified on a per-machine basis. */
3907 OPTIMIZATION_OPTIONS (optimize);
3908#endif
3909
3910 /* Initialize register usage now so switches may override. */
3911 init_reg_sets ();
3912
4291d9c8
RS
3913 for (i = 1; i < argc; i++)
3914 {
b99933c7
RS
3915 int j;
3916 /* If this is a language-specific option,
3917 decode it in a language-specific way. */
3918 for (j = 0; lang_options[j] != 0; j++)
7e6c0864
RK
3919 if (!strncmp (argv[i], lang_options[j],
3920 strlen (lang_options[j])))
b99933c7
RS
3921 break;
3922 if (lang_options[j] != 0)
3923 /* If the option is valid for *some* language,
3924 treat it as valid even if this language doesn't understand it. */
3925 lang_decode_option (argv[i]);
3926 else if (argv[i][0] == '-' && argv[i][1] != 0)
4291d9c8
RS
3927 {
3928 register char *str = argv[i] + 1;
3929 if (str[0] == 'Y')
3930 str++;
3931
3932 if (str[0] == 'm')
3933 set_target_switch (&str[1]);
3934 else if (!strcmp (str, "dumpbase"))
3935 {
3936 dump_base_name = argv[++i];
3937 }
3938 else if (str[0] == 'd')
3939 {
3940 register char *p = &str[1];
3941 while (*p)
3942 switch (*p++)
3943 {
3944 case 'a':
0d332add 3945 branch_prob_dump = 1;
4291d9c8
RS
3946 combine_dump = 1;
3947 dbr_sched_dump = 1;
3948 flow_dump = 1;
3949 global_reg_dump = 1;
3950 jump_opt_dump = 1;
e9a25f70 3951 addressof_dump = 1;
4291d9c8
RS
3952 jump2_opt_dump = 1;
3953 local_reg_dump = 1;
3954 loop_dump = 1;
8c660648 3955 regmove_dump = 1;
4291d9c8
RS
3956 rtl_dump = 1;
3957 cse_dump = 1, cse2_dump = 1;
3958 sched_dump = 1;
3959 sched2_dump = 1;
3960 stack_reg_dump = 1;
3961 break;
0d332add
DE
3962 case 'b':
3963 branch_prob_dump = 1;
3964 break;
4291d9c8
RS
3965 case 'k':
3966 stack_reg_dump = 1;
3967 break;
3968 case 'c':
3969 combine_dump = 1;
3970 break;
3971 case 'd':
3972 dbr_sched_dump = 1;
3973 break;
3974 case 'f':
3975 flow_dump = 1;
3976 break;
3977 case 'g':
3978 global_reg_dump = 1;
3979 break;
3980 case 'j':
3981 jump_opt_dump = 1;
3982 break;
e9a25f70
JL
3983 case 'D':
3984 addressof_dump = 1;
3985 break;
4291d9c8
RS
3986 case 'J':
3987 jump2_opt_dump = 1;
3988 break;
3989 case 'l':
3990 local_reg_dump = 1;
3991 break;
3992 case 'L':
3993 loop_dump = 1;
3994 break;
3995 case 'm':
3996 flag_print_mem = 1;
3997 break;
3998 case 'p':
3999 flag_print_asm_name = 1;
4000 break;
4001 case 'r':
4002 rtl_dump = 1;
4003 break;
4004 case 's':
4005 cse_dump = 1;
4006 break;
4007 case 't':
4008 cse2_dump = 1;
4009 break;
8c660648
JL
4010 case 'N':
4011 regmove_dump = 1;
4012 break;
4291d9c8
RS
4013 case 'S':
4014 sched_dump = 1;
4015 break;
4016 case 'R':
4017 sched2_dump = 1;
4018 break;
4019 case 'y':
4020 set_yydebug (1);
4021 break;
4291d9c8
RS
4022 case 'x':
4023 rtl_dump_and_exit = 1;
4024 break;
3d5cdd42
DE
4025 case 'A':
4026 flag_debug_asm = 1;
4027 break;
4291d9c8
RS
4028 }
4029 }
4030 else if (str[0] == 'f')
4031 {
4291d9c8
RS
4032 register char *p = &str[1];
4033 int found = 0;
4034
4035 /* Some kind of -f option.
4036 P's value is the option sans `-f'.
4037 Search for it in the table of options. */
4038
4039 for (j = 0;
4040 !found && j < sizeof (f_options) / sizeof (f_options[0]);
4041 j++)
4042 {
4043 if (!strcmp (p, f_options[j].string))
4044 {
4045 *f_options[j].variable = f_options[j].on_value;
4046 /* A goto here would be cleaner,
4047 but breaks the vax pcc. */
4048 found = 1;
4049 }
4050 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
4051 && ! strcmp (p+3, f_options[j].string))
4052 {
4053 *f_options[j].variable = ! f_options[j].on_value;
4054 found = 1;
4055 }
4056 }
4057
4058 if (found)
4059 ;
8c660648
JL
4060#ifdef HAIFA
4061#ifdef INSN_SCHEDULING
4062 else if (!strncmp (p, "sched-verbose-",14))
4063 fix_sched_param("verbose",&p[14]);
4064 else if (!strncmp (p, "sched-max-",10))
4065 fix_sched_param("max",&p[10]);
4066 else if (!strncmp (p, "sched-inter-max-b-",18))
4067 fix_sched_param("interblock-max-blocks",&p[18]);
4068 else if (!strncmp (p, "sched-inter-max-i-",18))
4069 fix_sched_param("interblock-max-insns",&p[18]);
4070#endif
4071#endif /* HAIFA */
4291d9c8
RS
4072 else if (!strncmp (p, "fixed-", 6))
4073 fix_register (&p[6], 1, 1);
4074 else if (!strncmp (p, "call-used-", 10))
4075 fix_register (&p[10], 0, 1);
4076 else if (!strncmp (p, "call-saved-", 11))
4077 fix_register (&p[11], 0, 0);
b99933c7 4078 else
4291d9c8
RS
4079 error ("Invalid option `%s'", argv[i]);
4080 }
4081 else if (str[0] == 'O')
4082 {
4083 register char *p = str+1;
4084 while (*p && *p >= '0' && *p <= '9')
4085 p++;
4086 if (*p == '\0')
4087 ;
4088 else
4089 error ("Invalid option `%s'", argv[i]);
4090 }
4091 else if (!strcmp (str, "pedantic"))
4092 pedantic = 1;
4093 else if (!strcmp (str, "pedantic-errors"))
4094 flag_pedantic_errors = pedantic = 1;
4291d9c8
RS
4095 else if (!strcmp (str, "quiet"))
4096 quiet_flag = 1;
4097 else if (!strcmp (str, "version"))
4098 version_flag = 1;
4099 else if (!strcmp (str, "w"))
4100 inhibit_warnings = 1;
4101 else if (!strcmp (str, "W"))
4102 {
4103 extra_warnings = 1;
fa1a4543
RS
4104 /* We save the value of warn_uninitialized, since if they put
4105 -Wuninitialized on the command line, we need to generate a
4106 warning about not using it without also specifying -O. */
4107 if (warn_uninitialized != 1)
4108 warn_uninitialized = 2;
4291d9c8
RS
4109 }
4110 else if (str[0] == 'W')
4111 {
4291d9c8
RS
4112 register char *p = &str[1];
4113 int found = 0;
4114
4115 /* Some kind of -W option.
4116 P's value is the option sans `-W'.
4117 Search for it in the table of options. */
4118
4119 for (j = 0;
4120 !found && j < sizeof (W_options) / sizeof (W_options[0]);
4121 j++)
4122 {
4123 if (!strcmp (p, W_options[j].string))
4124 {
4125 *W_options[j].variable = W_options[j].on_value;
4126 /* A goto here would be cleaner,
4127 but breaks the vax pcc. */
4128 found = 1;
4129 }
4130 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
4131 && ! strcmp (p+3, W_options[j].string))
4132 {
4133 *W_options[j].variable = ! W_options[j].on_value;
4134 found = 1;
4135 }
4136 }
4137
4138 if (found)
4139 ;
4140 else if (!strncmp (p, "id-clash-", 9))
4141 {
4142 char *endp = p + 9;
4143
4144 while (*endp)
4145 {
4146 if (*endp >= '0' && *endp <= '9')
4147 endp++;
4148 else
7085b873
RS
4149 {
4150 error ("Invalid option `%s'", argv[i]);
4151 goto id_clash_lose;
4152 }
4291d9c8
RS
4153 }
4154 warn_id_clash = 1;
4155 id_clash_len = atoi (str + 10);
7085b873 4156 id_clash_lose: ;
4291d9c8 4157 }
b51e9c62
RK
4158 else if (!strncmp (p, "larger-than-", 12))
4159 {
4160 char *endp = p + 12;
4161
4162 while (*endp)
4163 {
4164 if (*endp >= '0' && *endp <= '9')
4165 endp++;
4166 else
4167 {
4168 error ("Invalid option `%s'", argv[i]);
4169 goto larger_than_lose;
4170 }
4171 }
4172 warn_larger_than = 1;
4173 larger_than_size = atoi (str + 13);
4174 larger_than_lose: ;
4175 }
4291d9c8
RS
4176 else
4177 error ("Invalid option `%s'", argv[i]);
4178 }
4179 else if (!strcmp (str, "p"))
ca695ac9 4180 {
c2d12c8b 4181 profile_flag = 1;
ca695ac9 4182 }
4291d9c8
RS
4183 else if (!strcmp (str, "a"))
4184 {
4185#if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4186 warning ("`-a' option (basic block profile) not supported");
4187#else
ec6c615d
RK
4188 profile_block_flag = (profile_block_flag < 2) ? 1 : 3;
4189#endif
4190 }
4191 else if (!strcmp (str, "ax"))
4192 {
4193#if !defined (FUNCTION_BLOCK_PROFILER_EXIT) || !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
4194 warning ("`-ax' option (jump profiling) not supported");
4195#else
4196 profile_block_flag = (!profile_block_flag
4197 || profile_block_flag == 2) ? 2 : 3;
4291d9c8
RS
4198#endif
4199 }
4200 else if (str[0] == 'g')
4201 {
4291d9c8
RS
4202 unsigned len;
4203 unsigned level;
ff482cef
DE
4204 /* A lot of code assumes write_symbols == NO_DEBUG if the
4205 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
4206 of what debugging type has been selected). This records the
4207 selected type. It is an error to specify more than one
4208 debugging type. */
4209 static enum debug_info_type selected_debug_type = NO_DEBUG;
4210 /* Non-zero if debugging format has been explicitly set.
4211 -g and -ggdb don't explicitly set the debugging format so
4212 -gdwarf -g3 is equivalent to -gdwarf3. */
4213 static int type_explicitly_set_p = 0;
4214 /* Table of supported debugging formats. */
4215 static struct {
4216 char *arg;
4217 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
4218 constant expression, we use NO_DEBUG in its place. */
4219 enum debug_info_type debug_type;
4220 int use_extensions_p;
4221 } *da, debug_args[] = {
4222 { "g", NO_DEBUG, DEFAULT_GDB_EXTENSIONS },
4223 { "ggdb", NO_DEBUG, 1 },
4224#ifdef DBX_DEBUGGING_INFO
4225 { "gstabs", DBX_DEBUG, 0 },
4226 { "gstabs+", DBX_DEBUG, 1 },
4227#endif
4228#ifdef DWARF_DEBUGGING_INFO
4229 { "gdwarf", DWARF_DEBUG, 0 },
4230 { "gdwarf+", DWARF_DEBUG, 1 },
9a666dda 4231#endif
a94dbf2c
JM
4232#ifdef DWARF2_DEBUGGING_INFO
4233 { "gdwarf-2", DWARF2_DEBUG, 0 },
ff482cef
DE
4234#endif
4235#ifdef XCOFF_DEBUGGING_INFO
4236 { "gxcoff", XCOFF_DEBUG, 0 },
4237 { "gxcoff+", XCOFF_DEBUG, 1 },
4238#endif
4239#ifdef SDB_DEBUGGING_INFO
4240 { "gcoff", SDB_DEBUG, 0 },
4241#endif
4242 { 0, 0, 0 }
4243 };
4244 /* Indexed by enum debug_info_type. */
4245 static char *debug_type_names[] = {
9a666dda 4246 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
ff482cef 4247 };
4291d9c8 4248
ff482cef
DE
4249 /* Look up STR in the table. */
4250 for (da = debug_args; da->arg; da++)
4251 {
9a666dda 4252 if (! strncmp (str, da->arg, strlen (da->arg)))
ff482cef
DE
4253 {
4254 enum debug_info_type type = da->debug_type;
9a666dda
JM
4255 char *p, *q;
4256
4257 p = str + strlen (da->arg);
4258 if (*p && (*p < '0' || *p > '9'))
4259 continue;
5d38efae 4260 len = p - str;
e9a25f70 4261 q = p;
9a666dda
JM
4262 while (*q && (*q >= '0' && *q <= '9'))
4263 q++;
4264 if (*p)
33e5c8c3
JM
4265 {
4266 level = atoi (p);
4267 if (len > 1 && !strncmp (str, "gdwarf", len))
4268 {
4269 error ("use -gdwarf -g%d for DWARF v1, level %d",
4270 level, level);
4271 if (level == 2)
4272 error ("use -gdwarf-2 for DWARF v2");
4273 }
4274 }
9a666dda
JM
4275 else
4276 level = 2; /* default debugging info level */
4277 if (*q || level > 3)
4278 {
4279 warning ("invalid debug level specification in option: `-%s'",
4280 str);
4281 /* ??? This error message is incorrect in the case of
4282 -g4 -g. */
4283 warning ("no debugging information will be generated");
4284 level = 0;
4285 }
4286
ff482cef 4287 if (type == NO_DEBUG)
fe0986b4
JM
4288 {
4289 type = PREFERRED_DEBUGGING_TYPE;
4290 if (len > 1 && strncmp (str, "ggdb", len) == 0)
4291 {
4292#ifdef DWARF2_DEBUGGING_INFO
4293 type = DWARF2_DEBUG;
417b0fa2
JW
4294#else
4295#ifdef DBX_DEBUGGING_INFO
fe0986b4 4296 type = DBX_DEBUG;
417b0fa2 4297#endif
fe0986b4
JM
4298#endif
4299 }
4300 }
ff482cef 4301
e38eaffd
RK
4302 if (type == NO_DEBUG)
4303 warning ("`-%s' not supported by this configuration of GCC",
4304 str);
4305
ff482cef
DE
4306 /* Does it conflict with an already selected type? */
4307 if (type_explicitly_set_p
4308 /* -g/-ggdb don't conflict with anything */
4309 && da->debug_type != NO_DEBUG
4310 && type != selected_debug_type)
4311 warning ("`-%s' ignored, conflicts with `-g%s'",
4312 str, debug_type_names[(int) selected_debug_type]);
4313 else
4314 {
4315 /* If the format has already been set, -g/-ggdb
4316 only change the debug level. */
4317 if (type_explicitly_set_p
4318 && da->debug_type == NO_DEBUG)
4319 ; /* don't change debugging type */
4320 else
4321 {
4322 selected_debug_type = type;
4323 type_explicitly_set_p = da->debug_type != NO_DEBUG;
4324 }
4325 write_symbols = (level == 0
4326 ? NO_DEBUG
4327 : selected_debug_type);
4328 use_gnu_debug_info_extensions = da->use_extensions_p;
4329 debug_info_level = (enum debug_info_level) level;
4330 }
4331 break;
4332 }
4333 }
4334 if (! da->arg)
7276e85d
RK
4335 warning ("`-%s' not supported by this configuration of GCC",
4336 str);
4291d9c8
RS
4337 }
4338 else if (!strcmp (str, "o"))
4339 {
4340 asm_file_name = argv[++i];
4341 }
4342 else if (str[0] == 'G')
4343 {
4344 g_switch_set = TRUE;
4345 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
4346 }
f246a305
RS
4347 else if (!strncmp (str, "aux-info", 8))
4348 {
4349 flag_gen_aux_info = 1;
4350 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
4351 }
4291d9c8
RS
4352 else
4353 error ("Invalid option `%s'", argv[i]);
4354 }
4355 else if (argv[i][0] == '+')
b99933c7 4356 error ("Invalid option `%s'", argv[i]);
4291d9c8
RS
4357 else
4358 filename = argv[i];
4359 }
4360
f602c208
RK
4361 /* Checker uses the frame pointer. */
4362 if (flag_check_memory_usage)
4363 flag_omit_frame_pointer = 0;
4364
f246a305
RS
4365 if (optimize == 0)
4366 {
a2468e45
BK
4367 /* Inlining does not work if not optimizing,
4368 so force it not to be done. */
f246a305
RS
4369 flag_no_inline = 1;
4370 warn_inline = 0;
a2468e45
BK
4371
4372 /* The c_decode_option and lang_decode_option functions set
4373 this to `2' if -Wall is used, so we can avoid giving out
4374 lots of errors for people who don't realize what -Wall does. */
4375 if (warn_uninitialized == 1)
4376 warning ("-Wuninitialized is not supported without -O");
f246a305
RS
4377 }
4378
4291d9c8
RS
4379#ifdef OVERRIDE_OPTIONS
4380 /* Some machines may reject certain combinations of options. */
4381 OVERRIDE_OPTIONS;
4382#endif
4383
d1485032
JM
4384 if (exceptions_via_longjmp == 2)
4385 {
4386#ifdef DWARF2_UNWIND_INFO
4387 exceptions_via_longjmp = ! DWARF2_UNWIND_INFO;
4388#else
4389 exceptions_via_longjmp = 1;
4390#endif
4391 }
4392
ec6c615d
RK
4393 if (profile_block_flag == 3)
4394 {
4395 warning ("`-ax' and `-a' are conflicting options. `-a' ignored.");
4396 profile_block_flag = 2;
4397 }
4398
4291d9c8
RS
4399 /* Unrolling all loops implies that standard loop unrolling must also
4400 be done. */
4401 if (flag_unroll_all_loops)
4402 flag_unroll_loops = 1;
4403 /* Loop unrolling requires that strength_reduction be on also. Silently
4404 turn on strength reduction here if it isn't already on. Also, the loop
4405 unrolling code assumes that cse will be run after loop, so that must
4406 be turned on also. */
4407 if (flag_unroll_loops)
4408 {
4409 flag_strength_reduce = 1;
4410 flag_rerun_cse_after_loop = 1;
4411 }
4412
4413 /* Warn about options that are not supported on this machine. */
4414#ifndef INSN_SCHEDULING
4415 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4416 warning ("instruction scheduling not supported on this target machine");
4417#endif
4418#ifndef DELAY_SLOTS
4419 if (flag_delayed_branch)
4420 warning ("this target machine does not have delayed branches");
4421#endif
4422
4423 /* If we are in verbose mode, write out the version and maybe all the
4424 option flags in use. */
4425 if (version_flag)
4426 {
3d5cdd42 4427 print_version (stderr, "");
4291d9c8 4428 if (! quiet_flag)
3d5cdd42 4429 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4291d9c8
RS
4430 }
4431
4291d9c8
RS
4432 compile_file (filename);
4433
876ac40d 4434#if !defined(OS2) && !defined(VMS) && (!defined(_WIN32) || defined (__CYGWIN32__))
4291d9c8
RS
4435 if (flag_print_mem)
4436 {
4437 char *lim = (char *) sbrk (0);
4438
4439 fprintf (stderr, "Data size %d.\n",
b61b1c91 4440 lim - (char *) &environ);
4291d9c8
RS
4441 fflush (stderr);
4442
e9a25f70 4443#ifndef __MSDOS__
4291d9c8
RS
4444#ifdef USG
4445 system ("ps -l 1>&2");
4446#else /* not USG */
4447 system ("ps v");
4448#endif /* not USG */
e9a25f70 4449#endif
4291d9c8 4450 }
876ac40d 4451#endif /* ! OS2 && ! VMS && (! _WIN32 || CYGWIN32) */
4291d9c8
RS
4452
4453 if (errorcount)
4454 exit (FATAL_EXIT_CODE);
4455 if (sorrycount)
4456 exit (FATAL_EXIT_CODE);
4457 exit (SUCCESS_EXIT_CODE);
299846f2 4458 return 0;
4291d9c8
RS
4459}
4460\f
4461/* Decode -m switches. */
4462
4463/* Here is a table, controlled by the tm.h file, listing each -m switch
4464 and which bits in `target_switches' it should set or clear.
4465 If VALUE is positive, it is bits to set.
4466 If VALUE is negative, -VALUE is bits to clear.
4467 (The sign bit is not used so there is no confusion.) */
4468
4469struct {char *name; int value;} target_switches []
4470 = TARGET_SWITCHES;
4471
4472/* This table is similar, but allows the switch to have a value. */
4473
4474#ifdef TARGET_OPTIONS
4475struct {char *prefix; char ** variable;} target_options []
4476 = TARGET_OPTIONS;
4477#endif
4478
4479/* Decode the switch -mNAME. */
4480
4481void
4482set_target_switch (name)
4483 char *name;
4484{
4485 register int j;
4486 int valid = 0;
4487
4488 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4489 if (!strcmp (target_switches[j].name, name))
4490 {
4491 if (target_switches[j].value < 0)
4492 target_flags &= ~-target_switches[j].value;
4493 else
4494 target_flags |= target_switches[j].value;
4495 valid = 1;
4496 }
4497
4498#ifdef TARGET_OPTIONS
4499 if (!valid)
4500 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4501 {
4502 int len = strlen (target_options[j].prefix);
4503 if (!strncmp (target_options[j].prefix, name, len))
4504 {
4505 *target_options[j].variable = name + len;
4506 valid = 1;
4507 }
4508 }
4509#endif
4510
4511 if (!valid)
4512 error ("Invalid option `%s'", name);
4513}
4514\f
3d5cdd42
DE
4515/* Print version information to FILE.
4516 Each line begins with INDENT (for the case where FILE is the
4517 assembler output file). */
4291d9c8 4518
3d5cdd42
DE
4519void
4520print_version (file, indent)
4521 FILE *file;
4522 char *indent;
4291d9c8 4523{
3d5cdd42
DE
4524 fprintf (file, "%s%s%s version %s", indent, *indent != 0 ? " " : "",
4525 language_string, version_string);
4526 fprintf (file, " (%s)", TARGET_NAME);
4527#ifdef __GNUC__
4528#ifndef __VERSION__
4529#define __VERSION__ "[unknown]"
4530#endif
4531 fprintf (file, " compiled by GNU C version %s.\n", __VERSION__);
4532#else
4533 fprintf (file, " compiled by CC.\n");
4534#endif
4535}
4291d9c8 4536
3d5cdd42 4537/* Print an option value and return the adjusted position in the line.
309a8875
DE
4538 ??? We don't handle error returns from fprintf (disk full); presumably
4539 other code will catch a disk full though. */
4291d9c8 4540
3d5cdd42
DE
4541int
4542print_single_switch (file, pos, max, indent, sep, term, type, name)
4543 FILE *file;
4544 int pos, max;
4545 char *indent, *sep, *term, *type, *name;
4546{
309a8875
DE
4547 /* The ultrix fprintf returns 0 on success, so compute the result we want
4548 here since we need it for the following test. */
4549 int len = strlen (sep) + strlen (type) + strlen (name);
4550
3d5cdd42 4551 if (pos != 0
309a8875 4552 && pos + len > max)
4291d9c8 4553 {
3d5cdd42
DE
4554 fprintf (file, "%s", term);
4555 pos = 0;
4291d9c8 4556 }
3d5cdd42
DE
4557 if (pos == 0)
4558 {
309a8875
DE
4559 fprintf (file, "%s", indent);
4560 pos = strlen (indent);
3d5cdd42 4561 }
309a8875
DE
4562 fprintf (file, "%s%s%s", sep, type, name);
4563 pos += len;
3d5cdd42 4564 return pos;
4291d9c8
RS
4565}
4566
3d5cdd42
DE
4567/* Print active target switches to FILE.
4568 POS is the current cursor position and MAX is the size of a "line".
4569 Each line begins with INDENT and ends with TERM.
4570 Each switch is separated from the next by SEP. */
4291d9c8 4571
3d5cdd42
DE
4572void
4573print_switch_values (file, pos, max, indent, sep, term)
4574 FILE *file;
4575 int pos, max;
4576 char *indent, *sep, *term;
4291d9c8 4577{
3d5cdd42
DE
4578 int j, flags;
4579 char **p;
4580
4581 /* Print the options as passed. */
4291d9c8 4582
3d5cdd42
DE
4583 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4584 "options passed: ", "");
4585
520e7ff5 4586 for (p = &save_argv[1]; *p != NULL; p++)
3d5cdd42
DE
4587 if (**p == '-')
4588 {
4589 /* Ignore these. */
520e7ff5
DE
4590 if (strcmp (*p, "-o") == 0)
4591 {
4592 if (p[1] != NULL)
4593 p++;
4594 continue;
4595 }
3d5cdd42
DE
4596 if (strcmp (*p, "-quiet") == 0)
4597 continue;
4598 if (strcmp (*p, "-version") == 0)
4599 continue;
4600 if ((*p)[1] == 'd')
4601 continue;
4602
4603 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4604 }
4605 if (pos > 0)
4606 fprintf (file, "%s", term);
4607
4608 /* Print the -f and -m options that have been enabled.
4609 We don't handle language specific options but printing argv
4610 should suffice. */
4611
4612 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4613 "options enabled: ", "");
4291d9c8
RS
4614
4615 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
4616 if (*f_options[j].variable == f_options[j].on_value)
3d5cdd42
DE
4617 pos = print_single_switch (file, pos, max, indent, sep, term,
4618 "-f", f_options[j].string);
4291d9c8 4619
3d5cdd42 4620 /* Print target specific options. */
4291d9c8 4621
3d5cdd42 4622 flags = target_flags;
4291d9c8
RS
4623 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
4624 if (target_switches[j].name[0] != '\0'
4625 && target_switches[j].value > 0
4626 && ((target_switches[j].value & target_flags)
4627 == target_switches[j].value))
3d5cdd42
DE
4628 {
4629 pos = print_single_switch (file, pos, max, indent, sep, term,
4630 "-m", target_switches[j].name);
4631 flags &= ~ target_switches[j].value;
4632 }
4633
4634#ifdef TARGET_OPTIONS
4635 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
4636 if (*target_options[j].variable != NULL)
4637 {
4638 char prefix[256];
4639 sprintf (prefix, "-m%s", target_options[j].prefix);
4640 pos = print_single_switch (file, pos, max, indent, sep, term,
4641 prefix, *target_options[j].variable);
4642 }
4643#endif
4291d9c8 4644
3d5cdd42 4645 fprintf (file, "%s", term);
4291d9c8 4646}
9a666dda
JM
4647
4648/* Record the beginning of a new source file, named FILENAME. */
4649
4650void
4651debug_start_source_file (filename)
4652 register char *filename;
4653{
4654#ifdef DBX_DEBUGGING_INFO
4655 if (write_symbols == DBX_DEBUG)
4656 dbxout_start_new_source_file (filename);
4657#endif
4658#ifdef DWARF_DEBUGGING_INFO
4659 if (debug_info_level == DINFO_LEVEL_VERBOSE
4660 && write_symbols == DWARF_DEBUG)
4661 dwarfout_start_new_source_file (filename);
4662#endif /* DWARF_DEBUGGING_INFO */
4663#ifdef DWARF2_DEBUGGING_INFO
4664 if (debug_info_level == DINFO_LEVEL_VERBOSE
4665 && write_symbols == DWARF2_DEBUG)
4666 dwarf2out_start_source_file (filename);
4667#endif /* DWARF2_DEBUGGING_INFO */
cc694a81
DE
4668#ifdef SDB_DEBUGGING_INFO
4669 if (write_symbols == SDB_DEBUG)
4670 sdbout_start_new_source_file (filename);
4671#endif
9a666dda
JM
4672}
4673
4674/* Record the resumption of a source file. LINENO is the line number in
4675 the source file we are returning to. */
4676
4677void
4678debug_end_source_file (lineno)
4679 register unsigned lineno;
4680{
4681#ifdef DBX_DEBUGGING_INFO
4682 if (write_symbols == DBX_DEBUG)
4683 dbxout_resume_previous_source_file ();
4684#endif
4685#ifdef DWARF_DEBUGGING_INFO
4686 if (debug_info_level == DINFO_LEVEL_VERBOSE
4687 && write_symbols == DWARF_DEBUG)
4688 dwarfout_resume_previous_source_file (lineno);
4689#endif /* DWARF_DEBUGGING_INFO */
4690#ifdef DWARF2_DEBUGGING_INFO
4691 if (debug_info_level == DINFO_LEVEL_VERBOSE
4692 && write_symbols == DWARF2_DEBUG)
4693 dwarf2out_end_source_file ();
4694#endif /* DWARF2_DEBUGGING_INFO */
cc694a81
DE
4695#ifdef SDB_DEBUGGING_INFO
4696 if (write_symbols == SDB_DEBUG)
4697 sdbout_resume_previous_source_file ();
4698#endif
9a666dda
JM
4699}
4700
4701/* Called from check_newline in c-parse.y. The `buffer' parameter contains
4702 the tail part of the directive line, i.e. the part which is past the
4703 initial whitespace, #, whitespace, directive-name, whitespace part. */
4704
4705void
4706debug_define (lineno, buffer)
4707 register unsigned lineno;
4708 register char *buffer;
4709{
4710#ifdef DWARF_DEBUGGING_INFO
4711 if (debug_info_level == DINFO_LEVEL_VERBOSE
4712 && write_symbols == DWARF_DEBUG)
4713 dwarfout_define (lineno, buffer);
4714#endif /* DWARF_DEBUGGING_INFO */
4715#ifdef DWARF2_DEBUGGING_INFO
4716 if (debug_info_level == DINFO_LEVEL_VERBOSE
4717 && write_symbols == DWARF2_DEBUG)
4718 dwarf2out_define (lineno, buffer);
4719#endif /* DWARF2_DEBUGGING_INFO */
4720}
4721
4722/* Called from check_newline in c-parse.y. The `buffer' parameter contains
4723 the tail part of the directive line, i.e. the part which is past the
4724 initial whitespace, #, whitespace, directive-name, whitespace part. */
4725
4726void
4727debug_undef (lineno, buffer)
4728 register unsigned lineno;
4729 register char *buffer;
4730{
4731#ifdef DWARF_DEBUGGING_INFO
4732 if (debug_info_level == DINFO_LEVEL_VERBOSE
4733 && write_symbols == DWARF_DEBUG)
4734 dwarfout_undef (lineno, buffer);
4735#endif /* DWARF_DEBUGGING_INFO */
4736#ifdef DWARF2_DEBUGGING_INFO
4737 if (debug_info_level == DINFO_LEVEL_VERBOSE
4738 && write_symbols == DWARF2_DEBUG)
4739 dwarf2out_undef (lineno, buffer);
4740#endif /* DWARF2_DEBUGGING_INFO */
4741}
This page took 1.268026 seconds and 5 git commands to generate.