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