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