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