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