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