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