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