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