]> gcc.gnu.org Git - gcc.git/blob - gcc/toplev.c
(environ): Make declaration conditional.
[gcc.git] / gcc / toplev.c
1 /* Top level of GNU C compiler
2 Copyright (C) 1987, 1988, 1989, 1992 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21 /* This is the top level of cc1/c++.
22 It parses command args, opens files, invokes the various passes
23 in the proper order, and counts the time used by each.
24 Error messages and low-level interface to malloc also handled here. */
25
26 #include "config.h"
27 #include <sys/types.h>
28 #include <stdio.h>
29 #include <signal.h>
30 #include <setjmp.h>
31
32 #include <sys/stat.h>
33
34 #ifdef USG
35 #undef FLOAT
36 #include <sys/param.h>
37 /* This is for hpux. It is a real screw. They should change hpux. */
38 #undef FLOAT
39 #include <sys/times.h>
40 #include <time.h> /* Correct for hpux at least. Is it good on other USG? */
41 #undef FFS /* Some systems define this in param.h. */
42 #else
43 #ifndef VMS
44 #include <sys/time.h>
45 #include <sys/resource.h>
46 #endif
47 #endif
48
49 #include "input.h"
50 #include "tree.h"
51 /* #include "c-tree.h" */
52 #include "rtl.h"
53 #include "flags.h"
54 #include "insn-attr.h"
55
56 #ifdef XCOFF_DEBUGGING_INFO
57 #include "xcoffout.h"
58 #endif
59 \f
60 #ifdef VMS
61 /* The extra parameters substantially improve the I/O performance. */
62 static FILE *
63 VMS_fopen (fname, type)
64 char * fname;
65 char * type;
66 {
67 if (strcmp (type, "w") == 0)
68 return fopen (fname, type, "mbc=16", "deq=64", "fop=tef", "shr=nil");
69 return fopen (fname, type, "mbc=16");
70 }
71 #define fopen VMS_fopen
72 #endif
73
74 #ifndef DEFAULT_GDB_EXTENSIONS
75 #define DEFAULT_GDB_EXTENSIONS 1
76 #endif
77
78 extern int rtx_equal_function_value_matters;
79
80 #if ! (defined (VMS) && defined (OS2))
81 extern char **environ;
82 #endif
83 extern char *version_string, *language_string;
84
85 extern void init_lex ();
86 extern void init_decl_processing ();
87 extern void init_obstacks ();
88 extern void init_tree_codes ();
89 extern void init_rtl ();
90 extern void init_optabs ();
91 extern void init_stmt ();
92 extern void init_reg_sets ();
93 extern void dump_flow_info ();
94 extern void dump_sched_info ();
95 extern void dump_local_alloc ();
96
97 void rest_of_decl_compilation ();
98 void error ();
99 void error_with_file_and_line ();
100 void fancy_abort ();
101 #ifndef abort
102 void abort ();
103 #endif
104 void set_target_switch ();
105 static void print_switch_values ();
106 static char *decl_name ();
107
108 /* Name of program invoked, sans directories. */
109
110 char *progname;
111
112 /* Copy of arguments to main. */
113 int save_argc;
114 char **save_argv;
115 \f
116 /* Name of current original source file (what was input to cpp).
117 This comes from each #-command in the actual input. */
118
119 char *input_filename;
120
121 /* Name of top-level original source file (what was input to cpp).
122 This comes from the #-command at the beginning of the actual input.
123 If there isn't any there, then this is the cc1 input file name. */
124
125 char *main_input_filename;
126
127 /* Stream for reading from the input file. */
128
129 FILE *finput;
130
131 /* Current line number in real source file. */
132
133 int lineno;
134
135 /* Stack of currently pending input files. */
136
137 struct file_stack *input_file_stack;
138
139 /* Incremented on each change to input_file_stack. */
140 int input_file_stack_tick;
141
142 /* FUNCTION_DECL for function now being parsed or compiled. */
143
144 extern tree current_function_decl;
145
146 /* Name to use as base of names for dump output files. */
147
148 char *dump_base_name;
149
150 /* Bit flags that specify the machine subtype we are compiling for.
151 Bits are tested using macros TARGET_... defined in the tm.h file
152 and set by `-m...' switches. Must be defined in rtlanal.c. */
153
154 extern int target_flags;
155
156 /* Flags saying which kinds of debugging dump have been requested. */
157
158 int rtl_dump = 0;
159 int rtl_dump_and_exit = 0;
160 int jump_opt_dump = 0;
161 int cse_dump = 0;
162 int loop_dump = 0;
163 int cse2_dump = 0;
164 int flow_dump = 0;
165 int combine_dump = 0;
166 int sched_dump = 0;
167 int local_reg_dump = 0;
168 int global_reg_dump = 0;
169 int sched2_dump = 0;
170 int jump2_opt_dump = 0;
171 int dbr_sched_dump = 0;
172 int flag_print_asm_name = 0;
173 int stack_reg_dump = 0;
174
175 /* Name for output file of assembly code, specified with -o. */
176
177 char *asm_file_name;
178
179 /* Value of the -G xx switch, and whether it was passed or not. */
180 int g_switch_value;
181 int g_switch_set;
182
183 /* Type(s) of debugging information we are producing (if any).
184 See flags.h for the definitions of the different possible
185 types of debugging information. */
186 enum debug_info_type write_symbols = NO_DEBUG;
187
188 /* Level of debugging information we are producing. See flags.h
189 for the definitions of the different possible levels. */
190 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
191
192 /* Nonzero means use GNU-only extensions in the generated symbolic
193 debugging information. */
194 /* Currently, this only has an effect when write_symbols is set to
195 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
196 int use_gnu_debug_info_extensions = 0;
197
198 /* Nonzero means do optimizations. -O.
199 Particular numeric values stand for particular amounts of optimization;
200 thus, -O2 stores 2 here. However, the optimizations beyond the basic
201 ones are not controlled directly by this variable. Instead, they are
202 controlled by individual `flag_...' variables that are defaulted
203 based on this variable. */
204
205 int optimize = 0;
206
207 /* Number of error messages and warning messages so far. */
208
209 int errorcount = 0;
210 int warningcount = 0;
211 int sorrycount = 0;
212
213 /* Pointer to function to compute the name to use to print a declaration. */
214
215 char *(*decl_printable_name) ();
216
217 /* Pointer to function to compute rtl for a language-specific tree code. */
218
219 struct rtx_def *(*lang_expand_expr) ();
220
221 /* Nonzero if generating code to do profiling. */
222
223 int profile_flag = 0;
224
225 /* Nonzero if generating code to do profiling on a line-by-line basis. */
226
227 int profile_block_flag;
228
229 /* Nonzero for -pedantic switch: warn about anything
230 that standard spec forbids. */
231
232 int pedantic = 0;
233
234 /* Temporarily suppress certain warnings.
235 This is set while reading code from a system header file. */
236
237 int in_system_header = 0;
238
239 /* Nonzero means do stupid register allocation.
240 Currently, this is 1 if `optimize' is 0. */
241
242 int obey_regdecls = 0;
243
244 /* Don't print functions as they are compiled and don't print
245 times taken by the various passes. -quiet. */
246
247 int quiet_flag = 0;
248 \f
249 /* -f flags. */
250
251 /* Nonzero means `char' should be signed. */
252
253 int flag_signed_char;
254
255 /* Nonzero means give an enum type only as many bytes as it needs. */
256
257 int flag_short_enums;
258
259 /* Nonzero for -fcaller-saves: allocate values in regs that need to
260 be saved across function calls, if that produces overall better code.
261 Optional now, so people can test it. */
262
263 #ifdef DEFAULT_CALLER_SAVES
264 int flag_caller_saves = 1;
265 #else
266 int flag_caller_saves = 0;
267 #endif
268
269 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
270
271 int flag_pcc_struct_return = 0;
272
273 /* Nonzero for -fforce-mem: load memory value into a register
274 before arithmetic on it. This makes better cse but slower compilation. */
275
276 int flag_force_mem = 0;
277
278 /* Nonzero for -fforce-addr: load memory address into a register before
279 reference to memory. This makes better cse but slower compilation. */
280
281 int flag_force_addr = 0;
282
283 /* Nonzero for -fdefer-pop: don't pop args after each function call;
284 instead save them up to pop many calls' args with one insns. */
285
286 int flag_defer_pop = 1;
287
288 /* Nonzero for -ffloat-store: don't allocate floats and doubles
289 in extended-precision registers. */
290
291 int flag_float_store = 0;
292
293 /* Nonzero for -fcse-follow-jumps:
294 have cse follow jumps to do a more extensive job. */
295
296 int flag_cse_follow_jumps;
297
298 /* Nonzero for -fcse-skip-blocks:
299 have cse follow a branch around a block. */
300 int flag_cse_skip_blocks;
301
302 /* Nonzero for -fexpensive-optimizations:
303 perform miscellaneous relatively-expensive optimizations. */
304 int flag_expensive_optimizations;
305
306 /* Nonzero for -fthread-jumps:
307 have jump optimize output of loop. */
308
309 int flag_thread_jumps;
310
311 /* Nonzero enables strength-reduction in loop.c. */
312
313 int flag_strength_reduce = 0;
314
315 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
316 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
317 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
318 unrolled. */
319
320 int flag_unroll_loops;
321
322 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
323 This is generally not a win. */
324
325 int flag_unroll_all_loops;
326
327 /* Nonzero for -fwritable-strings:
328 store string constants in data segment and don't uniquize them. */
329
330 int flag_writable_strings = 0;
331
332 /* Nonzero means don't put addresses of constant functions in registers.
333 Used for compiling the Unix kernel, where strange substitutions are
334 done on the assembly output. */
335
336 int flag_no_function_cse = 0;
337
338 /* Nonzero for -fomit-frame-pointer:
339 don't make a frame pointer in simple functions that don't require one. */
340
341 int flag_omit_frame_pointer = 0;
342
343 /* Nonzero to inhibit use of define_optimization peephole opts. */
344
345 int flag_no_peephole = 0;
346
347 /* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math
348 operations in the interest of optimization. For example it allows
349 GCC to assume arguments to sqrt are nonnegative numbers, allowing
350 faster code for sqrt to be generated. */
351
352 int flag_fast_math = 0;
353
354 /* Nonzero means all references through pointers are volatile. */
355
356 int flag_volatile;
357
358 /* Nonzero means just do syntax checking; don't output anything. */
359
360 int flag_syntax_only = 0;
361
362 /* Nonzero means to rerun cse after loop optimization. This increases
363 compilation time about 20% and picks up a few more common expressions. */
364
365 static int flag_rerun_cse_after_loop;
366
367 /* Nonzero for -finline-functions: ok to inline functions that look like
368 good inline candidates. */
369
370 int flag_inline_functions;
371
372 /* Nonzero for -fkeep-inline-functions: even if we make a function
373 go inline everywhere, keep its defintion around for debugging
374 purposes. */
375
376 int flag_keep_inline_functions;
377
378 /* Nonzero means that functions declared `inline' will be treated
379 as `static'. Prevents generation of zillions of copies of unused
380 static inline functions; instead, `inlines' are written out
381 only when actually used. Used in conjunction with -g. Also
382 does the right thing with #pragma interface. */
383
384 int flag_no_inline;
385
386 /* Nonzero means we should be saving declaration info into a .X file. */
387
388 int flag_gen_aux_info = 0;
389
390 /* Specified name of aux-info file. */
391
392 static char *aux_info_file_name;
393
394 /* Nonzero means make the text shared if supported. */
395
396 int flag_shared_data;
397
398 /* Nonzero means schedule into delayed branch slots if supported. */
399
400 int flag_delayed_branch;
401
402 /* Nonzero if we are compiling pure (sharable) code.
403 Value is 1 if we are doing reasonable (i.e. simple
404 offset into offset table) pic. Value is 2 if we can
405 only perform register offsets. */
406
407 int flag_pic;
408
409 /* Nonzero means place uninitialized global data in the bss section. */
410
411 int flag_no_common;
412
413 /* Nonzero means pretend it is OK to examine bits of target floats,
414 even if that isn't true. The resulting code will have incorrect constants,
415 but the same series of instructions that the native compiler would make. */
416
417 int flag_pretend_float;
418
419 /* Nonzero means change certain warnings into errors.
420 Usually these are warnings about failure to conform to some standard. */
421
422 int flag_pedantic_errors = 0;
423
424 /* flag_schedule_insns means schedule insns within basic blocks (before
425 local_alloc).
426 flag_schedule_insns_after_reload means schedule insns after
427 global_alloc. */
428
429 int flag_schedule_insns = 0;
430 int flag_schedule_insns_after_reload = 0;
431
432 /* -finhibit-size-directive inhibits output of .size for ELF.
433 This is used only for compiling crtstuff.c,
434 and it may be extended to other effects
435 needed for crtstuff.c on other systems. */
436 int flag_inhibit_size_directive = 0;
437
438 /* -fverbose-asm causes extra commentary information to be produced in
439 the generated assembly code (to make it more readable). This option
440 is generally only of use to those who actually need to read the
441 generated assembly code (perhaps while debugging the compiler itself). */
442
443 int flag_verbose_asm = 0;
444
445 /* -fgnu-linker specifies use of the GNU linker for initializations.
446 (Or, more generally, a linker that handles initializations.)
447 -fno-gnu-linker says that collect2 will be used. */
448 #ifdef USE_COLLECT2
449 int flag_gnu_linker = 0;
450 #else
451 int flag_gnu_linker = 1;
452 #endif
453
454 /* Table of language-independent -f options.
455 STRING is the option name. VARIABLE is the address of the variable.
456 ON_VALUE is the value to store in VARIABLE
457 if `-fSTRING' is seen as an option.
458 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
459
460 struct { char *string; int *variable; int on_value;} f_options[] =
461 {
462 {"float-store", &flag_float_store, 1},
463 {"volatile", &flag_volatile, 1},
464 {"defer-pop", &flag_defer_pop, 1},
465 {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
466 {"cse-follow-jumps", &flag_cse_follow_jumps, 1},
467 {"cse-skip-blocks", &flag_cse_skip_blocks, 1},
468 {"expensive-optimizations", &flag_expensive_optimizations, 1},
469 {"thread-jumps", &flag_thread_jumps, 1},
470 {"strength-reduce", &flag_strength_reduce, 1},
471 {"unroll-loops", &flag_unroll_loops, 1},
472 {"unroll-all-loops", &flag_unroll_all_loops, 1},
473 {"writable-strings", &flag_writable_strings, 1},
474 {"peephole", &flag_no_peephole, 0},
475 {"force-mem", &flag_force_mem, 1},
476 {"force-addr", &flag_force_addr, 1},
477 {"function-cse", &flag_no_function_cse, 0},
478 {"inline-functions", &flag_inline_functions, 1},
479 {"keep-inline-functions", &flag_keep_inline_functions, 1},
480 {"inline", &flag_no_inline, 0},
481 {"syntax-only", &flag_syntax_only, 1},
482 {"shared-data", &flag_shared_data, 1},
483 {"caller-saves", &flag_caller_saves, 1},
484 {"pcc-struct-return", &flag_pcc_struct_return, 1},
485 {"delayed-branch", &flag_delayed_branch, 1},
486 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1},
487 {"pretend-float", &flag_pretend_float, 1},
488 {"schedule-insns", &flag_schedule_insns, 1},
489 {"schedule-insns2", &flag_schedule_insns_after_reload, 1},
490 {"pic", &flag_pic, 1},
491 {"PIC", &flag_pic, 2},
492 {"fast-math", &flag_fast_math, 1},
493 {"common", &flag_no_common, 0},
494 {"inhibit-size-directive", &flag_inhibit_size_directive, 1},
495 {"verbose-asm", &flag_verbose_asm, 1},
496 {"gnu-linker", &flag_gnu_linker, 1}
497 };
498 \f
499 /* Options controlling warnings */
500
501 /* Don't print warning messages. -w. */
502
503 int inhibit_warnings = 0;
504
505 /* Print various extra warnings. -W. */
506
507 int extra_warnings = 0;
508
509 /* Treat warnings as errors. -Werror. */
510
511 int warnings_are_errors = 0;
512
513 /* Nonzero to warn about unused local variables. */
514
515 int warn_unused;
516
517 /* Nonzero to warn about variables used before they are initialized. */
518
519 int warn_uninitialized;
520
521 /* Nonzero means warn about all declarations which shadow others. */
522
523 int warn_shadow;
524
525 /* Warn if a switch on an enum fails to have a case for every enum value. */
526
527 int warn_switch;
528
529 /* Nonzero means warn about function definitions that default the return type
530 or that use a null return and have a return-type other than void. */
531
532 int warn_return_type;
533
534 /* Nonzero means warn about pointer casts that increase the required
535 alignment of the target type (and might therefore lead to a crash
536 due to a misaligned access). */
537
538 int warn_cast_align;
539
540 /* Nonzero means warn about any identifiers that match in the first N
541 characters. The value N is in `id_clash_len'. */
542
543 int warn_id_clash;
544 int id_clash_len;
545
546 /* Nonzero means warn if inline function is too large. */
547
548 int warn_inline;
549
550 /* Warn if a function returns an aggregate,
551 since there are often incompatible calling conventions for doing this. */
552
553 int warn_aggregate_return;
554
555 /* Likewise for -W. */
556
557 struct { char *string; int *variable; int on_value;} W_options[] =
558 {
559 {"unused", &warn_unused, 1},
560 {"error", &warnings_are_errors, 1},
561 {"shadow", &warn_shadow, 1},
562 {"switch", &warn_switch, 1},
563 {"return-type", &warn_return_type, 1},
564 {"aggregate-return", &warn_aggregate_return, 1},
565 {"cast-align", &warn_cast_align, 1},
566 {"uninitialized", &warn_uninitialized, 1},
567 {"inline", &warn_inline, 1}
568 };
569 \f
570 /* Output files for assembler code (real compiler output)
571 and debugging dumps. */
572
573 FILE *asm_out_file;
574 FILE *aux_info_file;
575 FILE *rtl_dump_file;
576 FILE *jump_opt_dump_file;
577 FILE *cse_dump_file;
578 FILE *loop_dump_file;
579 FILE *cse2_dump_file;
580 FILE *flow_dump_file;
581 FILE *combine_dump_file;
582 FILE *sched_dump_file;
583 FILE *local_reg_dump_file;
584 FILE *global_reg_dump_file;
585 FILE *sched2_dump_file;
586 FILE *jump2_opt_dump_file;
587 FILE *dbr_sched_dump_file;
588 FILE *stack_reg_dump_file;
589
590 /* Time accumulators, to count the total time spent in various passes. */
591
592 int parse_time;
593 int varconst_time;
594 int integration_time;
595 int jump_time;
596 int cse_time;
597 int loop_time;
598 int cse2_time;
599 int flow_time;
600 int combine_time;
601 int sched_time;
602 int local_alloc_time;
603 int global_alloc_time;
604 int sched2_time;
605 int dbr_sched_time;
606 int shorten_branch_time;
607 int stack_reg_time;
608 int final_time;
609 int symout_time;
610 int dump_time;
611 \f
612 /* Return time used so far, in microseconds. */
613
614 int
615 get_run_time ()
616 {
617 #ifdef USG
618 struct tms tms;
619 #else
620 #ifndef VMS
621 struct rusage rusage;
622 #else /* VMS */
623 struct
624 {
625 int proc_user_time;
626 int proc_system_time;
627 int child_user_time;
628 int child_system_time;
629 } vms_times;
630 #endif
631 #endif
632
633 if (quiet_flag)
634 return 0;
635
636 #ifdef USG
637 times (&tms);
638 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
639 #else
640 #ifndef VMS
641 getrusage (0, &rusage);
642 return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
643 + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
644 #else /* VMS */
645 times (&vms_times);
646 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
647 #endif
648 #endif
649 }
650
651 #define TIMEVAR(VAR, BODY) \
652 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
653
654 void
655 print_time (str, total)
656 char *str;
657 int total;
658 {
659 fprintf (stderr,
660 "time in %s: %d.%06d\n",
661 str, total / 1000000, total % 1000000);
662 }
663
664 /* Count an error or warning. Return 1 if the message should be printed. */
665
666 int
667 count_error (warningp)
668 int warningp;
669 {
670 if (warningp && inhibit_warnings)
671 return 0;
672
673 if (warningp && !warnings_are_errors)
674 warningcount++;
675 else
676 {
677 static int warning_message = 0;
678
679 if (warningp && !warning_message)
680 {
681 fprintf (stderr, "%s: warnings being treated as errors\n", progname);
682 warning_message = 1;
683 }
684 errorcount++;
685 }
686
687 return 1;
688 }
689
690 /* Print a fatal error message. NAME is the text.
691 Also include a system error message based on `errno'. */
692
693 void
694 pfatal_with_name (name)
695 char *name;
696 {
697 fprintf (stderr, "%s: ", progname);
698 perror (name);
699 exit (35);
700 }
701
702 void
703 fatal_io_error (name)
704 char *name;
705 {
706 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
707 exit (35);
708 }
709
710 void
711 fatal (s, v)
712 char *s;
713 int v;
714 {
715 error (s, v);
716 exit (34);
717 }
718
719 /* Called to give a better error message when we don't have an insn to match
720 what we are looking for or if the insn's constraints aren't satisfied,
721 rather than just calling abort(). */
722
723 void
724 fatal_insn_not_found (insn)
725 rtx insn;
726 {
727 if (INSN_CODE (insn) < 0)
728 error ("internal error--unrecognizable insn:", 0);
729 else
730 error ("internal error--insn does not satisfy its constraints:", 0);
731 debug_rtx (insn);
732 if (asm_out_file)
733 fflush (asm_out_file);
734 if (aux_info_file)
735 fflush (aux_info_file);
736 if (rtl_dump_file)
737 fflush (rtl_dump_file);
738 if (jump_opt_dump_file)
739 fflush (jump_opt_dump_file);
740 if (cse_dump_file)
741 fflush (cse_dump_file);
742 if (loop_dump_file)
743 fflush (loop_dump_file);
744 if (cse2_dump_file)
745 fflush (cse2_dump_file);
746 if (flow_dump_file)
747 fflush (flow_dump_file);
748 if (combine_dump_file)
749 fflush (combine_dump_file);
750 if (sched_dump_file)
751 fflush (sched_dump_file);
752 if (local_reg_dump_file)
753 fflush (local_reg_dump_file);
754 if (global_reg_dump_file)
755 fflush (global_reg_dump_file);
756 if (sched2_dump_file)
757 fflush (sched2_dump_file);
758 if (jump2_opt_dump_file)
759 fflush (jump2_opt_dump_file);
760 if (dbr_sched_dump_file)
761 fflush (dbr_sched_dump_file);
762 if (stack_reg_dump_file)
763 fflush (stack_reg_dump_file);
764 abort ();
765 }
766
767 /* This is the default decl_printable_name function. */
768
769 static char *
770 decl_name (decl, kind)
771 tree decl;
772 char **kind;
773 {
774 return IDENTIFIER_POINTER (DECL_NAME (decl));
775 }
776 \f
777 static int need_error_newline;
778
779 /* Function of last error message;
780 more generally, function such that if next error message is in it
781 then we don't have to mention the function name. */
782 static tree last_error_function = NULL;
783
784 /* Used to detect when input_file_stack has changed since last described. */
785 static int last_error_tick;
786
787 /* Called when the start of a function definition is parsed,
788 this function prints on stderr the name of the function. */
789
790 void
791 announce_function (decl)
792 tree decl;
793 {
794 if (! quiet_flag)
795 {
796 char *junk;
797 if (rtl_dump_and_exit)
798 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
799 else
800 fprintf (stderr, " %s", (*decl_printable_name) (decl, &junk));
801 fflush (stderr);
802 need_error_newline = 1;
803 last_error_function = current_function_decl;
804 }
805 }
806
807 /* Prints out, if necessary, the name of the current function
808 which caused an error. Called from all error and warning functions. */
809
810 void
811 report_error_function (file)
812 char *file;
813 {
814 struct file_stack *p;
815
816 if (need_error_newline)
817 {
818 fprintf (stderr, "\n");
819 need_error_newline = 0;
820 }
821
822 if (last_error_function != current_function_decl)
823 {
824 char *kind = "function";
825 if (current_function_decl != 0
826 && TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
827 kind = "method";
828
829 if (file)
830 fprintf (stderr, "%s: ", file);
831
832 if (current_function_decl == NULL)
833 fprintf (stderr, "At top level:\n");
834 else
835 {
836 char *name = (*decl_printable_name) (current_function_decl, &kind);
837 fprintf (stderr, "In %s `%s':\n", kind, name);
838 }
839
840 last_error_function = current_function_decl;
841 }
842 if (input_file_stack && input_file_stack->next != 0
843 && input_file_stack_tick != last_error_tick)
844 {
845 fprintf (stderr, "In file included");
846 for (p = input_file_stack->next; p; p = p->next)
847 {
848 fprintf (stderr, " from %s:%d", p->name, p->line);
849 if (p->next)
850 fprintf (stderr, ",");
851 }
852 fprintf (stderr, ":\n");
853 last_error_tick = input_file_stack_tick;
854 }
855 }
856
857 /* Report an error at the current line number.
858 S is a string and V and V2 are args for `printf'. We use HOST_WIDE_INT
859 as the type for these args assuming it is wide enough to hold a
860 pointer. This isn't terribly portable, but is the best we can do
861 without vprintf universally available. */
862
863 void
864 error (s, v, v2)
865 char *s;
866 HOST_WIDE_INT v; /* Also used as pointer */
867 HOST_WIDE_INT v2; /* Also used as pointer */
868 {
869 error_with_file_and_line (input_filename, lineno, s, v, v2);
870 }
871
872 /* Report an error at line LINE of file FILE.
873 S and V are a string and an arg for `printf'. */
874
875 void
876 error_with_file_and_line (file, line, s, v, v2)
877 char *file;
878 int line;
879 char *s;
880 HOST_WIDE_INT v;
881 HOST_WIDE_INT v2;
882 {
883 count_error (0);
884
885 report_error_function (file);
886
887 if (file)
888 fprintf (stderr, "%s:%d: ", file, line);
889 else
890 fprintf (stderr, "%s: ", progname);
891 fprintf (stderr, s, v, v2);
892 fprintf (stderr, "\n");
893 }
894
895 /* Report an error at the declaration DECL.
896 S and V are a string and an arg which uses %s to substitute
897 the declaration name. */
898
899 void
900 error_with_decl (decl, s, v)
901 tree decl;
902 char *s;
903 HOST_WIDE_INT v;
904 {
905 char *junk;
906 count_error (0);
907
908 report_error_function (DECL_SOURCE_FILE (decl));
909
910 fprintf (stderr, "%s:%d: ",
911 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
912
913 if (DECL_NAME (decl))
914 fprintf (stderr, s, (*decl_printable_name) (decl, &junk), v);
915 else
916 fprintf (stderr, s, "((anonymous))", v);
917 fprintf (stderr, "\n");
918 }
919
920 /* Report an error at the line number of the insn INSN.
921 S and V are a string and an arg for `printf'.
922 This is used only when INSN is an `asm' with operands,
923 and each ASM_OPERANDS records its own source file and line. */
924
925 void
926 error_for_asm (insn, s, v, v2)
927 rtx insn;
928 char *s;
929 HOST_WIDE_INT v; /* Also used as pointer */
930 HOST_WIDE_INT v2; /* Also used as pointer */
931 {
932 char *filename;
933 int line;
934 rtx body = PATTERN (insn);
935 rtx asmop;
936
937 /* Find the (or one of the) ASM_OPERANDS in the insn. */
938 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
939 asmop = SET_SRC (body);
940 else if (GET_CODE (body) == ASM_OPERANDS)
941 asmop = body;
942 else if (GET_CODE (body) == PARALLEL
943 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
944 asmop = SET_SRC (XVECEXP (body, 0, 0));
945 else if (GET_CODE (body) == PARALLEL
946 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
947 asmop = XVECEXP (body, 0, 0);
948
949 filename = ASM_OPERANDS_SOURCE_FILE (asmop);
950 line = ASM_OPERANDS_SOURCE_LINE (asmop);
951
952 error_with_file_and_line (filename, line, s, v, v2);
953 }
954
955 /* Report a warning at line LINE.
956 S and V are a string and an arg for `printf'. */
957
958 void
959 warning_with_file_and_line (file, line, s, v, v2, v3)
960 char *file;
961 int line;
962 char *s;
963 HOST_WIDE_INT v, v2, v3;
964 {
965 if (count_error (1) == 0)
966 return;
967
968 report_error_function (file);
969
970 if (file)
971 fprintf (stderr, "%s:%d: ", file, line);
972 else
973 fprintf (stderr, "%s: ", progname);
974
975 fprintf (stderr, "warning: ");
976 fprintf (stderr, s, v, v2, v3);
977 fprintf (stderr, "\n");
978 }
979
980 /* Report a warning at the current line number.
981 S and V are a string and an arg for `printf'. */
982
983 void
984 warning (s, v, v2, v3)
985 char *s;
986 HOST_WIDE_INT v, v2, v3; /* Also used as pointer */
987 {
988 warning_with_file_and_line (input_filename, lineno, s, v, v2, v3);
989 }
990
991 /* Report a warning at the declaration DECL.
992 S is string which uses %s to substitute the declaration name.
993 V is a second parameter that S can refer to. */
994
995 void
996 warning_with_decl (decl, s, v)
997 tree decl;
998 char *s;
999 HOST_WIDE_INT v;
1000 {
1001 char *junk;
1002
1003 if (count_error (1) == 0)
1004 return;
1005
1006 report_error_function (DECL_SOURCE_FILE (decl));
1007
1008 fprintf (stderr, "%s:%d: ",
1009 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1010
1011 fprintf (stderr, "warning: ");
1012 if (DECL_NAME (decl))
1013 fprintf (stderr, s, (*decl_printable_name) (decl, &junk), v);
1014 else
1015 fprintf (stderr, s, "((anonymous))", v);
1016 fprintf (stderr, "\n");
1017 }
1018
1019 /* Report a warning at the line number of the insn INSN.
1020 S and V are a string and an arg for `printf'.
1021 This is used only when INSN is an `asm' with operands,
1022 and each ASM_OPERANDS records its own source file and line. */
1023
1024 void
1025 warning_for_asm (insn, s, v, v2)
1026 rtx insn;
1027 char *s;
1028 HOST_WIDE_INT v; /* Also used as pointer */
1029 HOST_WIDE_INT v2; /* Also used as pointer */
1030 {
1031 char *filename;
1032 int line;
1033 rtx body = PATTERN (insn);
1034 rtx asmop;
1035
1036 /* Find the (or one of the) ASM_OPERANDS in the insn. */
1037 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1038 asmop = SET_SRC (body);
1039 else if (GET_CODE (body) == ASM_OPERANDS)
1040 asmop = body;
1041 else if (GET_CODE (body) == PARALLEL
1042 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1043 asmop = SET_SRC (XVECEXP (body, 0, 0));
1044 else if (GET_CODE (body) == PARALLEL
1045 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1046 asmop = XVECEXP (body, 0, 0);
1047
1048 filename = ASM_OPERANDS_SOURCE_FILE (asmop);
1049 line = ASM_OPERANDS_SOURCE_LINE (asmop);
1050
1051 warning_with_file_and_line (filename, line, s, v, v2);
1052 }
1053 \f
1054 /* These functions issue either warnings or errors depending on
1055 -pedantic-errors. */
1056
1057 void
1058 pedwarn (s, v, v2)
1059 char *s;
1060 HOST_WIDE_INT v; /* Also used as pointer */
1061 HOST_WIDE_INT v2;
1062 {
1063 if (flag_pedantic_errors)
1064 error (s, v, v2);
1065 else
1066 warning (s, v, v2);
1067 }
1068
1069 void
1070 pedwarn_with_decl (decl, s, v)
1071 tree decl;
1072 char *s;
1073 HOST_WIDE_INT v;
1074 {
1075 if (flag_pedantic_errors)
1076 error_with_decl (decl, s, v);
1077 else
1078 warning_with_decl (decl, s, v);
1079 }
1080
1081 void
1082 pedwarn_with_file_and_line (file, line, s, v, v2)
1083 char *file;
1084 int line;
1085 char *s;
1086 HOST_WIDE_INT v;
1087 HOST_WIDE_INT v2;
1088 {
1089 if (flag_pedantic_errors)
1090 error_with_file_and_line (file, line, s, v, v2);
1091 else
1092 warning_with_file_and_line (file, line, s, v, v2);
1093 }
1094
1095 /* Apologize for not implementing some feature.
1096 S, V, and V2 are a string and args for `printf'. */
1097
1098 void
1099 sorry (s, v, v2)
1100 char *s;
1101 HOST_WIDE_INT v, v2;
1102 {
1103 sorrycount++;
1104 if (input_filename)
1105 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1106 else
1107 fprintf (stderr, "%s: ", progname);
1108
1109 fprintf (stderr, "sorry, not implemented: ");
1110 fprintf (stderr, s, v, v2);
1111 fprintf (stderr, "\n");
1112 }
1113
1114 /* Apologize for not implementing some feature, then quit.
1115 S, V, and V2 are a string and args for `printf'. */
1116
1117 void
1118 really_sorry (s, v, v2)
1119 char *s;
1120 HOST_WIDE_INT v, v2;
1121 {
1122 if (input_filename)
1123 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1124 else
1125 fprintf (stderr, "c++: ");
1126
1127 fprintf (stderr, "sorry, not implemented: ");
1128 fprintf (stderr, s, v, v2);
1129 fatal (" (fatal)\n");
1130 }
1131 \f
1132 /* More 'friendly' abort that prints the line and file.
1133 config.h can #define abort fancy_abort if you like that sort of thing.
1134
1135 I don't think this is actually a good idea.
1136 Other sorts of crashes will look a certain way.
1137 It is a good thing if crashes from calling abort look the same way.
1138 -- RMS */
1139
1140 void
1141 fancy_abort ()
1142 {
1143 fatal ("internal gcc abort");
1144 }
1145
1146 /* This calls abort and is used to avoid problems when abort if a macro.
1147 It is used when we need to pass the address of abort. */
1148
1149 void
1150 do_abort ()
1151 {
1152 abort ();
1153 }
1154
1155 /* When `malloc.c' is compiled with `rcheck' defined,
1156 it calls this function to report clobberage. */
1157
1158 void
1159 botch (s)
1160 {
1161 abort ();
1162 }
1163
1164 /* Same as `malloc' but report error if no memory available. */
1165
1166 char *
1167 xmalloc (size)
1168 unsigned size;
1169 {
1170 register char *value = (char *) malloc (size);
1171 if (value == 0)
1172 fatal ("virtual memory exhausted");
1173 return value;
1174 }
1175
1176 /* Same as `realloc' but report error if no memory available. */
1177
1178 char *
1179 xrealloc (ptr, size)
1180 char *ptr;
1181 int size;
1182 {
1183 char *result = (char *) realloc (ptr, size);
1184 if (!result)
1185 fatal ("virtual memory exhausted");
1186 return result;
1187 }
1188 \f
1189 /* Return the logarithm of X, base 2, considering X unsigned,
1190 if X is a power of 2. Otherwise, returns -1.
1191
1192 This should be used via the `exact_log2' macro. */
1193
1194 int
1195 exact_log2_wide (x)
1196 register unsigned HOST_WIDE_INT x;
1197 {
1198 register int log = 0;
1199 /* Test for 0 or a power of 2. */
1200 if (x == 0 || x != (x & -x))
1201 return -1;
1202 while ((x >>= 1) != 0)
1203 log++;
1204 return log;
1205 }
1206
1207 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1208 If X is 0, return -1.
1209
1210 This should be used via the floor_log2 macro. */
1211
1212 int
1213 floor_log2_wide (x)
1214 register unsigned HOST_WIDE_INT x;
1215 {
1216 register int log = -1;
1217 while (x != 0)
1218 log++,
1219 x >>= 1;
1220 return log;
1221 }
1222
1223 int float_handled;
1224 jmp_buf float_handler;
1225
1226 /* Specify where to longjmp to when a floating arithmetic error happens.
1227 If HANDLER is 0, it means don't handle the errors any more. */
1228
1229 void
1230 set_float_handler (handler)
1231 jmp_buf handler;
1232 {
1233 float_handled = (handler != 0);
1234 if (handler)
1235 bcopy (handler, float_handler, sizeof (float_handler));
1236 }
1237
1238 /* Signals actually come here. */
1239
1240 static void
1241 float_signal (signo)
1242 /* If this is missing, some compilers complain. */
1243 int signo;
1244 {
1245 if (float_handled == 0)
1246 abort ();
1247 #if defined (USG) || defined (hpux)
1248 signal (SIGFPE, float_signal); /* re-enable the signal catcher */
1249 #endif
1250 float_handled = 0;
1251 signal (SIGFPE, float_signal);
1252 longjmp (float_handler, 1);
1253 }
1254
1255 /* Handler for SIGPIPE. */
1256
1257 static void
1258 pipe_closed (signo)
1259 /* If this is missing, some compilers complain. */
1260 int signo;
1261 {
1262 fatal ("output pipe has been closed");
1263 }
1264
1265 /* Strip off a legitimate source ending from the input string NAME of
1266 length LEN. */
1267
1268 void
1269 strip_off_ending (name, len)
1270 char *name;
1271 int len;
1272 {
1273 if (len > 2 && ! strcmp (".c", name + len - 2))
1274 name[len - 2] = 0;
1275 else if (len > 2 && ! strcmp (".m", name + len - 2))
1276 name[len - 2] = 0;
1277 else if (len > 2 && ! strcmp (".i", name + len - 2))
1278 name[len - 2] = 0;
1279 else if (len > 3 && ! strcmp (".ii", name + len - 3))
1280 name[len - 3] = 0;
1281 else if (len > 3 && ! strcmp (".co", name + len - 3))
1282 name[len - 3] = 0;
1283 else if (len > 3 && ! strcmp (".cc", name + len - 3))
1284 name[len - 3] = 0;
1285 else if (len > 2 && ! strcmp (".C", name + len - 2))
1286 name[len - 2] = 0;
1287 else if (len > 4 && ! strcmp (".cxx", name + len - 4))
1288 name[len - 4] = 0;
1289 else if (len > 2 && ! strcmp (".f", name + len - 2))
1290 name[len - 2] = 0;
1291 else if (len > 4 && ! strcmp (".ada", name + len - 4))
1292 name[len - 4] = 0;
1293 }
1294
1295 /* Output a file name in the form wanted by System V. */
1296
1297 void
1298 output_file_directive (asm_file, input_name)
1299 FILE *asm_file;
1300 char *input_name;
1301 {
1302 int len = strlen (input_name);
1303 char *na = input_name + len;
1304
1305 /* NA gets INPUT_NAME sans directory names. */
1306 while (na > input_name)
1307 {
1308 if (na[-1] == '/')
1309 break;
1310 na--;
1311 }
1312
1313 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1314 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1315 #else
1316 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1317 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1318 #else
1319 fprintf (asm_file, "\t.file\t\"%s\"\n", na);
1320 #endif
1321 #endif
1322 }
1323 \f
1324 /* Compile an entire file of output from cpp, named NAME.
1325 Write a file of assembly output and various debugging dumps. */
1326
1327 static void
1328 compile_file (name)
1329 char *name;
1330 {
1331 tree globals;
1332 int start_time;
1333 int dump_base_name_length;
1334
1335 int name_specified = name != 0;
1336
1337 if (dump_base_name == 0)
1338 dump_base_name = name ? name : "gccdump";
1339 dump_base_name_length = strlen (dump_base_name);
1340
1341 parse_time = 0;
1342 varconst_time = 0;
1343 integration_time = 0;
1344 jump_time = 0;
1345 cse_time = 0;
1346 loop_time = 0;
1347 cse2_time = 0;
1348 flow_time = 0;
1349 combine_time = 0;
1350 sched_time = 0;
1351 local_alloc_time = 0;
1352 global_alloc_time = 0;
1353 sched2_time = 0;
1354 dbr_sched_time = 0;
1355 shorten_branch_time = 0;
1356 stack_reg_time = 0;
1357 final_time = 0;
1358 symout_time = 0;
1359 dump_time = 0;
1360
1361 /* Open input file. */
1362
1363 if (name == 0 || !strcmp (name, "-"))
1364 {
1365 finput = stdin;
1366 name = "stdin";
1367 }
1368 else
1369 finput = fopen (name, "r");
1370 if (finput == 0)
1371 pfatal_with_name (name);
1372
1373 #ifdef IO_BUFFER_SIZE
1374 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
1375 #endif
1376
1377 /* Initialize data in various passes. */
1378
1379 init_obstacks ();
1380 init_tree_codes ();
1381 init_lex ();
1382 init_rtl ();
1383 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1384 || debug_info_level == DINFO_LEVEL_VERBOSE);
1385 init_decl_processing ();
1386 init_optabs ();
1387 init_stmt ();
1388 init_expmed ();
1389 init_expr_once ();
1390 init_loop ();
1391 init_reload ();
1392
1393 if (flag_caller_saves)
1394 init_caller_save ();
1395
1396 /* If auxiliary info generation is desired, open the output file.
1397 This goes in the same directory as the source file--unlike
1398 all the other output files. */
1399 if (flag_gen_aux_info)
1400 {
1401 aux_info_file = fopen (aux_info_file_name, "w");
1402 if (aux_info_file == 0)
1403 pfatal_with_name (aux_info_file_name);
1404 }
1405
1406 /* If rtl dump desired, open the output file. */
1407 if (rtl_dump)
1408 {
1409 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1410 strcpy (dumpname, dump_base_name);
1411 strcat (dumpname, ".rtl");
1412 rtl_dump_file = fopen (dumpname, "w");
1413 if (rtl_dump_file == 0)
1414 pfatal_with_name (dumpname);
1415 }
1416
1417 /* If jump_opt dump desired, open the output file. */
1418 if (jump_opt_dump)
1419 {
1420 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1421 strcpy (dumpname, dump_base_name);
1422 strcat (dumpname, ".jump");
1423 jump_opt_dump_file = fopen (dumpname, "w");
1424 if (jump_opt_dump_file == 0)
1425 pfatal_with_name (dumpname);
1426 }
1427
1428 /* If cse dump desired, open the output file. */
1429 if (cse_dump)
1430 {
1431 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1432 strcpy (dumpname, dump_base_name);
1433 strcat (dumpname, ".cse");
1434 cse_dump_file = fopen (dumpname, "w");
1435 if (cse_dump_file == 0)
1436 pfatal_with_name (dumpname);
1437 }
1438
1439 /* If loop dump desired, open the output file. */
1440 if (loop_dump)
1441 {
1442 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1443 strcpy (dumpname, dump_base_name);
1444 strcat (dumpname, ".loop");
1445 loop_dump_file = fopen (dumpname, "w");
1446 if (loop_dump_file == 0)
1447 pfatal_with_name (dumpname);
1448 }
1449
1450 /* If cse2 dump desired, open the output file. */
1451 if (cse2_dump)
1452 {
1453 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1454 strcpy (dumpname, dump_base_name);
1455 strcat (dumpname, ".cse2");
1456 cse2_dump_file = fopen (dumpname, "w");
1457 if (cse2_dump_file == 0)
1458 pfatal_with_name (dumpname);
1459 }
1460
1461 /* If flow dump desired, open the output file. */
1462 if (flow_dump)
1463 {
1464 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1465 strcpy (dumpname, dump_base_name);
1466 strcat (dumpname, ".flow");
1467 flow_dump_file = fopen (dumpname, "w");
1468 if (flow_dump_file == 0)
1469 pfatal_with_name (dumpname);
1470 }
1471
1472 /* If combine dump desired, open the output file. */
1473 if (combine_dump)
1474 {
1475 register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
1476 strcpy (dumpname, dump_base_name);
1477 strcat (dumpname, ".combine");
1478 combine_dump_file = fopen (dumpname, "w");
1479 if (combine_dump_file == 0)
1480 pfatal_with_name (dumpname);
1481 }
1482
1483 /* If scheduling dump desired, open the output file. */
1484 if (sched_dump)
1485 {
1486 register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
1487 strcpy (dumpname, dump_base_name);
1488 strcat (dumpname, ".sched");
1489 sched_dump_file = fopen (dumpname, "w");
1490 if (sched_dump_file == 0)
1491 pfatal_with_name (dumpname);
1492 }
1493
1494 /* If local_reg dump desired, open the output file. */
1495 if (local_reg_dump)
1496 {
1497 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1498 strcpy (dumpname, dump_base_name);
1499 strcat (dumpname, ".lreg");
1500 local_reg_dump_file = fopen (dumpname, "w");
1501 if (local_reg_dump_file == 0)
1502 pfatal_with_name (dumpname);
1503 }
1504
1505 /* If global_reg dump desired, open the output file. */
1506 if (global_reg_dump)
1507 {
1508 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1509 strcpy (dumpname, dump_base_name);
1510 strcat (dumpname, ".greg");
1511 global_reg_dump_file = fopen (dumpname, "w");
1512 if (global_reg_dump_file == 0)
1513 pfatal_with_name (dumpname);
1514 }
1515
1516 /* If 2nd scheduling dump desired, open the output file. */
1517 if (sched2_dump)
1518 {
1519 register char *dumpname = (char *) xmalloc (dump_base_name_length + 8);
1520 strcpy (dumpname, dump_base_name);
1521 strcat (dumpname, ".sched2");
1522 sched2_dump_file = fopen (dumpname, "w");
1523 if (sched2_dump_file == 0)
1524 pfatal_with_name (dumpname);
1525 }
1526
1527 /* If jump2_opt dump desired, open the output file. */
1528 if (jump2_opt_dump)
1529 {
1530 register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
1531 strcpy (dumpname, dump_base_name);
1532 strcat (dumpname, ".jump2");
1533 jump2_opt_dump_file = fopen (dumpname, "w");
1534 if (jump2_opt_dump_file == 0)
1535 pfatal_with_name (dumpname);
1536 }
1537
1538 /* If dbr_sched dump desired, open the output file. */
1539 if (dbr_sched_dump)
1540 {
1541 register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
1542 strcpy (dumpname, dump_base_name);
1543 strcat (dumpname, ".dbr");
1544 dbr_sched_dump_file = fopen (dumpname, "w");
1545 if (dbr_sched_dump_file == 0)
1546 pfatal_with_name (dumpname);
1547 }
1548
1549 #ifdef STACK_REGS
1550
1551 /* If stack_reg dump desired, open the output file. */
1552 if (stack_reg_dump)
1553 {
1554 register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
1555 strcpy (dumpname, dump_base_name);
1556 strcat (dumpname, ".stack");
1557 stack_reg_dump_file = fopen (dumpname, "w");
1558 if (stack_reg_dump_file == 0)
1559 pfatal_with_name (dumpname);
1560 }
1561
1562 #endif
1563
1564 /* Open assembler code output file. */
1565
1566 if (! name_specified && asm_file_name == 0)
1567 asm_out_file = stdout;
1568 else
1569 {
1570 register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1571 int len = strlen (dump_base_name);
1572 strcpy (dumpname, dump_base_name);
1573 strip_off_ending (dumpname, len);
1574 strcat (dumpname, ".s");
1575 if (asm_file_name == 0)
1576 {
1577 asm_file_name = (char *) xmalloc (strlen (dumpname) + 1);
1578 strcpy (asm_file_name, dumpname);
1579 }
1580 if (!strcmp (asm_file_name, "-"))
1581 asm_out_file = stdout;
1582 else
1583 asm_out_file = fopen (asm_file_name, "w");
1584 if (asm_out_file == 0)
1585 pfatal_with_name (asm_file_name);
1586 }
1587
1588 #ifdef IO_BUFFER_SIZE
1589 setvbuf (asm_out_file, (char *) xmalloc (IO_BUFFER_SIZE),
1590 _IOFBF, IO_BUFFER_SIZE);
1591 #endif
1592
1593 input_filename = name;
1594
1595 /* Perform language-specific initialization.
1596 This may set main_input_filename. */
1597 lang_init ();
1598
1599 /* If the input doesn't start with a #line, use the input name
1600 as the official input file name. */
1601 if (main_input_filename == 0)
1602 main_input_filename = name;
1603
1604 /* Put an entry on the input file stack for the main input file. */
1605 input_file_stack
1606 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
1607 input_file_stack->next = 0;
1608 input_file_stack->name = input_filename;
1609
1610 ASM_FILE_START (asm_out_file);
1611
1612 /* Output something to inform GDB that this compilation was by GCC. */
1613 #ifndef ASM_IDENTIFY_GCC
1614 fprintf (asm_out_file, "gcc2_compiled.:\n");
1615 #else
1616 ASM_IDENTIFY_GCC (asm_out_file);
1617 #endif
1618 /* Don't let the first function fall at the same address
1619 as gcc_compiled., if profiling. */
1620 if (profile_flag || profile_block_flag)
1621 assemble_zeros (UNITS_PER_WORD);
1622
1623 /* If dbx symbol table desired, initialize writing it
1624 and output the predefined types. */
1625 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1626 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1627 TIMEVAR (symout_time, dbxout_init (asm_out_file, main_input_filename,
1628 getdecls ()));
1629 #endif
1630 #ifdef SDB_DEBUGGING_INFO
1631 if (write_symbols == SDB_DEBUG)
1632 TIMEVAR (symout_time, sdbout_init (asm_out_file, main_input_filename,
1633 getdecls ()));
1634 #endif
1635 #ifdef DWARF_DEBUGGING_INFO
1636 if (write_symbols == DWARF_DEBUG)
1637 TIMEVAR (symout_time, dwarfout_init (asm_out_file, main_input_filename));
1638 #endif
1639
1640 /* Initialize yet another pass. */
1641
1642 init_final (main_input_filename);
1643
1644 start_time = get_run_time ();
1645
1646 /* Call the parser, which parses the entire file
1647 (calling rest_of_compilation for each function). */
1648
1649 if (yyparse () != 0)
1650 if (errorcount == 0)
1651 fprintf (stderr, "Errors detected in input file (your bison.simple is out of date)");
1652
1653 /* Compilation is now finished except for writing
1654 what's left of the symbol table output. */
1655
1656 parse_time += get_run_time () - start_time;
1657
1658 parse_time -= integration_time;
1659 parse_time -= varconst_time;
1660
1661 globals = getdecls ();
1662
1663 /* Really define vars that have had only a tentative definition.
1664 Really output inline functions that must actually be callable
1665 and have not been output so far. */
1666
1667 {
1668 int len = list_length (globals);
1669 tree *vec = (tree *) alloca (sizeof (tree) * len);
1670 int i;
1671 tree decl;
1672
1673 /* Process the decls in reverse order--earliest first.
1674 Put them into VEC from back to front, then take out from front. */
1675
1676 for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl))
1677 vec[len - i - 1] = decl;
1678
1679 for (i = 0; i < len; i++)
1680 {
1681 decl = vec[i];
1682 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1683 && ! TREE_ASM_WRITTEN (decl))
1684 {
1685 /* Don't write out static consts, unless we used them.
1686 (This used to write them out only if the address was
1687 taken, but that was wrong; if the variable was simply
1688 referred to, it still needs to exist or else it will
1689 be undefined in the linker.) */
1690 if (! TREE_READONLY (decl)
1691 || TREE_PUBLIC (decl)
1692 || TREE_USED (decl)
1693 || TREE_ADDRESSABLE (decl)
1694 || TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl)))
1695 rest_of_decl_compilation (decl, NULL_PTR, 1, 1);
1696 else
1697 /* Cancel the RTL for this decl so that, if debugging info
1698 output for global variables is still to come,
1699 this one will be omitted. */
1700 DECL_RTL (decl) = NULL;
1701 }
1702
1703 if (TREE_CODE (decl) == FUNCTION_DECL
1704 && ! TREE_ASM_WRITTEN (decl)
1705 && DECL_INITIAL (decl) != 0
1706 && (TREE_ADDRESSABLE (decl)
1707 || TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl)))
1708 && ! DECL_EXTERNAL (decl))
1709 output_inline_function (decl);
1710
1711 /* Warn about any function
1712 declared static but not defined.
1713 We don't warn about variables,
1714 because many programs have static variables
1715 that exist only to get some text into the object file. */
1716 if ((warn_unused
1717 || TREE_USED (decl)
1718 || (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl))))
1719 && TREE_CODE (decl) == FUNCTION_DECL
1720 && DECL_INITIAL (decl) == 0
1721 && DECL_EXTERNAL (decl)
1722 && ! TREE_PUBLIC (decl))
1723 warning_with_decl (decl, "`%s' declared `static' but never defined");
1724 /* Warn about static fns or vars defined but not used,
1725 but not about inline functions
1726 since unused inline statics is normal practice. */
1727 if (warn_unused
1728 && (TREE_CODE (decl) == FUNCTION_DECL
1729 || TREE_CODE (decl) == VAR_DECL)
1730 && ! DECL_IN_SYSTEM_HEADER (decl)
1731 && ! DECL_EXTERNAL (decl)
1732 && ! TREE_PUBLIC (decl)
1733 && ! TREE_USED (decl)
1734 && ! DECL_INLINE (decl)
1735 /* The TREE_USED bit for file-scope decls
1736 is kept in the identifier, to handle multiple
1737 external decls in different scopes. */
1738 && ! TREE_USED (DECL_NAME (decl)))
1739 warning_with_decl (decl, "`%s' defined but not used");
1740
1741 #ifdef SDB_DEBUGGING_INFO
1742 /* The COFF linker can move initialized global vars to the end.
1743 And that can screw up the symbol ordering.
1744 By putting the symbols in that order to begin with,
1745 we avoid a problem. mcsun!unido!fauern!tumuc!pes@uunet.uu.net. */
1746 if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == VAR_DECL
1747 && TREE_PUBLIC (decl) && DECL_INITIAL (decl)
1748 && DECL_RTL (decl) != 0)
1749 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
1750
1751 /* Output COFF information for non-global
1752 file-scope initialized variables. */
1753 if (write_symbols == SDB_DEBUG
1754 && TREE_CODE (decl) == VAR_DECL
1755 && DECL_INITIAL (decl)
1756 && DECL_RTL (decl) != 0
1757 && GET_CODE (DECL_RTL (decl)) == MEM)
1758 TIMEVAR (symout_time, sdbout_toplevel_data (decl));
1759 #endif /* SDB_DEBUGGING_INFO */
1760 #ifdef DWARF_DEBUGGING_INFO
1761 /* Output DWARF information for file-scope tentative data object
1762 declarations, file-scope (extern) function declarations (which
1763 had no corresponding body) and file-scope tagged type declarations
1764 and definitions which have not yet been forced out. */
1765
1766 if (write_symbols == DWARF_DEBUG
1767 && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)))
1768 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 1));
1769 #endif
1770 }
1771 }
1772
1773 /* Do dbx symbols */
1774 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1775 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1776 TIMEVAR (symout_time,
1777 {
1778 dbxout_finish (asm_out_file, main_input_filename);
1779 });
1780 #endif
1781
1782 #ifdef DWARF_DEBUGGING_INFO
1783 if (write_symbols == DWARF_DEBUG)
1784 TIMEVAR (symout_time,
1785 {
1786 dwarfout_finish ();
1787 });
1788 #endif
1789
1790 /* Output some stuff at end of file if nec. */
1791
1792 end_final (main_input_filename);
1793
1794 #ifdef ASM_FILE_END
1795 ASM_FILE_END (asm_out_file);
1796 #endif
1797
1798 after_finish_compilation:
1799
1800 /* Language-specific end of compilation actions. */
1801
1802 lang_finish ();
1803
1804 /* Close the dump files. */
1805
1806 if (flag_gen_aux_info)
1807 {
1808 fclose (aux_info_file);
1809 if (errorcount)
1810 unlink (aux_info_file_name);
1811 }
1812
1813 if (rtl_dump)
1814 fclose (rtl_dump_file);
1815
1816 if (jump_opt_dump)
1817 fclose (jump_opt_dump_file);
1818
1819 if (cse_dump)
1820 fclose (cse_dump_file);
1821
1822 if (loop_dump)
1823 fclose (loop_dump_file);
1824
1825 if (cse2_dump)
1826 fclose (cse2_dump_file);
1827
1828 if (flow_dump)
1829 fclose (flow_dump_file);
1830
1831 if (combine_dump)
1832 {
1833 dump_combine_total_stats (combine_dump_file);
1834 fclose (combine_dump_file);
1835 }
1836
1837 if (sched_dump)
1838 fclose (sched_dump_file);
1839
1840 if (local_reg_dump)
1841 fclose (local_reg_dump_file);
1842
1843 if (global_reg_dump)
1844 fclose (global_reg_dump_file);
1845
1846 if (sched2_dump)
1847 fclose (sched2_dump_file);
1848
1849 if (jump2_opt_dump)
1850 fclose (jump2_opt_dump_file);
1851
1852 if (dbr_sched_dump)
1853 fclose (dbr_sched_dump_file);
1854
1855 #ifdef STACK_REGS
1856 if (stack_reg_dump)
1857 fclose (stack_reg_dump_file);
1858 #endif
1859
1860 /* Close non-debugging input and output files. Take special care to note
1861 whether fclose returns an error, since the pages might still be on the
1862 buffer chain while the file is open. */
1863
1864 fclose (finput);
1865 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
1866 fatal_io_error (asm_file_name);
1867
1868 /* Print the times. */
1869
1870 if (! quiet_flag)
1871 {
1872 fprintf (stderr,"\n");
1873 print_time ("parse", parse_time);
1874 print_time ("integration", integration_time);
1875 print_time ("jump", jump_time);
1876 print_time ("cse", cse_time);
1877 print_time ("loop", loop_time);
1878 print_time ("cse2", cse2_time);
1879 print_time ("flow", flow_time);
1880 print_time ("combine", combine_time);
1881 print_time ("sched", sched_time);
1882 print_time ("local-alloc", local_alloc_time);
1883 print_time ("global-alloc", global_alloc_time);
1884 print_time ("sched2", sched2_time);
1885 print_time ("dbranch", dbr_sched_time);
1886 print_time ("shorten-branch", shorten_branch_time);
1887 print_time ("stack-reg", stack_reg_time);
1888 print_time ("final", final_time);
1889 print_time ("varconst", varconst_time);
1890 print_time ("symout", symout_time);
1891 print_time ("dump", dump_time);
1892 }
1893 }
1894 \f
1895 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1896 and TYPE_DECL nodes.
1897
1898 This does nothing for local (non-static) variables.
1899 Otherwise, it sets up the RTL and outputs any assembler code
1900 (label definition, storage allocation and initialization).
1901
1902 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1903 the assembler symbol name to be used. TOP_LEVEL is nonzero
1904 if this declaration is not within a function. */
1905
1906 void
1907 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
1908 tree decl;
1909 char *asmspec;
1910 int top_level;
1911 int at_end;
1912 {
1913 /* Declarations of variables, and of functions defined elsewhere. */
1914
1915 /* Forward declarations for nested functions are not "external",
1916 but we need to treat them as if they were. */
1917 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1918 || TREE_CODE (decl) == FUNCTION_DECL)
1919 TIMEVAR (varconst_time,
1920 {
1921 make_decl_rtl (decl, asmspec, top_level);
1922 /* For a user-invisible decl that should be replaced
1923 by its value when used, don't output anything. */
1924 if (! (TREE_CODE (decl) == VAR_DECL
1925 && DECL_IGNORED_P (decl) && TREE_READONLY (decl)
1926 && DECL_INITIAL (decl) != 0))
1927 /* Don't output anything
1928 when a tentative file-scope definition is seen.
1929 But at end of compilation, do output code for them. */
1930 if (! (! at_end && top_level
1931 && (DECL_INITIAL (decl) == 0
1932 || DECL_INITIAL (decl) == error_mark_node
1933 || DECL_IGNORED_P (decl))))
1934 assemble_variable (decl, top_level, at_end);
1935 });
1936 else if (DECL_REGISTER (decl) && asmspec != 0)
1937 {
1938 if (decode_reg_name (asmspec) >= 0)
1939 {
1940 DECL_RTL (decl) = 0;
1941 make_decl_rtl (decl, asmspec, top_level);
1942 }
1943 else
1944 error ("invalid register name `%s' for register variable", asmspec);
1945 }
1946 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1947 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1948 && TREE_CODE (decl) == TYPE_DECL)
1949 TIMEVAR (symout_time, dbxout_symbol (decl, 0));
1950 #endif
1951 #ifdef SDB_DEBUGGING_INFO
1952 else if (write_symbols == SDB_DEBUG && top_level
1953 && TREE_CODE (decl) == TYPE_DECL)
1954 TIMEVAR (symout_time, sdbout_symbol (decl, 0));
1955 #endif
1956 }
1957
1958 /* Called after finishing a record, union or enumeral type. */
1959
1960 void
1961 rest_of_type_compilation (type, toplev)
1962 tree type;
1963 int toplev;
1964 {
1965 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1966 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1967 TIMEVAR (symout_time, dbxout_symbol (TYPE_STUB_DECL (type), !toplev));
1968 #endif
1969 #ifdef SDB_DEBUGGING_INFO
1970 if (write_symbols == SDB_DEBUG)
1971 TIMEVAR (symout_time, sdbout_symbol (TYPE_STUB_DECL (type), !toplev));
1972 #endif
1973 }
1974
1975 /* This is called from finish_function (within yyparse)
1976 after each top-level definition is parsed.
1977 It is supposed to compile that function or variable
1978 and output the assembler code for it.
1979 After we return, the tree storage is freed. */
1980
1981 void
1982 rest_of_compilation (decl)
1983 tree decl;
1984 {
1985 register rtx insns;
1986 int start_time = get_run_time ();
1987 int tem;
1988 /* Nonzero if we have saved the original DECL_INITIAL of the function,
1989 to be restored after we finish compiling the function
1990 (for use when compiling inline calls to this function). */
1991 tree saved_block_tree = 0;
1992 /* Likewise, for DECL_ARGUMENTS. */
1993 tree saved_arguments = 0;
1994 int failure = 0;
1995
1996 /* If we are reconsidering an inline function
1997 at the end of compilation, skip the stuff for making it inline. */
1998
1999 if (DECL_SAVED_INSNS (decl) == 0)
2000 {
2001 int specd = DECL_INLINE (decl);
2002 char *lose;
2003
2004 /* If requested, consider whether to make this function inline. */
2005 if (specd || flag_inline_functions)
2006 TIMEVAR (integration_time,
2007 {
2008 lose = function_cannot_inline_p (decl);
2009 if (lose)
2010 {
2011 if (warn_inline && specd)
2012 warning_with_decl (decl, lose);
2013 DECL_INLINE (decl) = 0;
2014 }
2015 else
2016 DECL_INLINE (decl) = 1;
2017 });
2018
2019 insns = get_insns ();
2020
2021 /* Dump the rtl code if we are dumping rtl. */
2022
2023 if (rtl_dump)
2024 TIMEVAR (dump_time,
2025 {
2026 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
2027 IDENTIFIER_POINTER (DECL_NAME (decl)));
2028 if (DECL_SAVED_INSNS (decl))
2029 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2030 print_rtl (rtl_dump_file, insns);
2031 fflush (rtl_dump_file);
2032 });
2033
2034 /* If function is inline, and we don't yet know whether to
2035 compile it by itself, defer decision till end of compilation.
2036 finish_compilation will call rest_of_compilation again
2037 for those functions that need to be output. */
2038
2039 if (DECL_INLINE (decl)
2040 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2041 && ! flag_keep_inline_functions)
2042 || DECL_EXTERNAL (decl)))
2043 {
2044 #ifdef DWARF_DEBUGGING_INFO
2045 /* Generate the DWARF info for the "abstract" instance
2046 of a function which we may later generate inlined and/or
2047 out-of-line instances of. */
2048 if (write_symbols == DWARF_DEBUG)
2049 {
2050 set_decl_abstract_flags (decl, 1);
2051 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2052 set_decl_abstract_flags (decl, 0);
2053 }
2054 #endif
2055 TIMEVAR (integration_time, save_for_inline_nocopy (decl));
2056 goto exit_rest_of_compilation;
2057 }
2058
2059 /* If we have to compile the function now, save its rtl and subdecls
2060 so that its compilation will not affect what others get. */
2061 if (DECL_INLINE (decl))
2062 {
2063 #ifdef DWARF_DEBUGGING_INFO
2064 /* Generate the DWARF info for the "abstract" instance of
2065 a function which we will generate an out-of-line instance
2066 of almost immediately (and which we may also later generate
2067 various inlined instances of). */
2068 if (write_symbols == DWARF_DEBUG)
2069 {
2070 set_decl_abstract_flags (decl, 1);
2071 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2072 set_decl_abstract_flags (decl, 0);
2073 }
2074 #endif
2075 saved_block_tree = DECL_INITIAL (decl);
2076 saved_arguments = DECL_ARGUMENTS (decl);
2077 TIMEVAR (integration_time, save_for_inline_copying (decl));
2078 }
2079 }
2080
2081 TREE_ASM_WRITTEN (decl) = 1;
2082
2083 /* Now that integrate will no longer see our rtl, we need not distinguish
2084 between the return value of this function and the return value of called
2085 functions. */
2086 rtx_equal_function_value_matters = 0;
2087
2088 /* Don't return yet if -Wreturn-type; we need to do jump_optimize. */
2089 if ((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
2090 {
2091 goto exit_rest_of_compilation;
2092 }
2093
2094 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
2095 Note that that may have been done above, in save_for_inline_copying.
2096 The call to resume_temporary_allocation near the end of this function
2097 goes back to the usual state of affairs. */
2098
2099 rtl_in_current_obstack ();
2100
2101 #ifdef FINALIZE_PIC
2102 /* If we are doing position-independent code generation, now
2103 is the time to output special prologues and epilogues.
2104 We do not want to do this earlier, because it just clutters
2105 up inline functions with meaningless insns. */
2106 if (flag_pic)
2107 FINALIZE_PIC;
2108 #endif
2109
2110 insns = get_insns ();
2111
2112 /* Copy any shared structure that should not be shared. */
2113
2114 unshare_all_rtl (insns);
2115
2116 /* Instantiate all virtual registers. */
2117
2118 instantiate_virtual_regs (current_function_decl, get_insns ());
2119
2120 /* See if we have allocated stack slots that are not directly addressable.
2121 If so, scan all the insns and create explicit address computation
2122 for all references to such slots. */
2123 /* fixup_stack_slots (); */
2124
2125 /* Do jump optimization the first time, if -opt.
2126 Also do it if -W, but in that case it doesn't change the rtl code,
2127 it only computes whether control can drop off the end of the function. */
2128
2129 if (optimize > 0 || extra_warnings || warn_return_type
2130 /* If function is `volatile', we should warn if it tries to return. */
2131 || TREE_THIS_VOLATILE (decl))
2132 {
2133 TIMEVAR (jump_time, reg_scan (insns, max_reg_num (), 0));
2134 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 1));
2135 }
2136
2137 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
2138 if (rtl_dump_and_exit || flag_syntax_only)
2139 goto exit_rest_of_compilation;
2140
2141 /* Dump rtl code after jump, if we are doing that. */
2142
2143 if (jump_opt_dump)
2144 TIMEVAR (dump_time,
2145 {
2146 fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
2147 IDENTIFIER_POINTER (DECL_NAME (decl)));
2148 print_rtl (jump_opt_dump_file, insns);
2149 fflush (jump_opt_dump_file);
2150 });
2151
2152 /* Perform common subexpression elimination.
2153 Nonzero value from `cse_main' means that jumps were simplified
2154 and some code may now be unreachable, so do
2155 jump optimization again. */
2156
2157 if (cse_dump)
2158 TIMEVAR (dump_time,
2159 {
2160 fprintf (cse_dump_file, "\n;; Function %s\n\n",
2161 IDENTIFIER_POINTER (DECL_NAME (decl)));
2162 });
2163
2164 if (optimize > 0)
2165 {
2166 TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 1));
2167
2168 if (flag_thread_jumps)
2169 /* Hacks by tiemann & kenner. */
2170 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
2171
2172 TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num (),
2173 0, cse_dump_file));
2174 TIMEVAR (cse_time, delete_dead_from_cse (insns, max_reg_num ()));
2175
2176 if (tem)
2177 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
2178 }
2179
2180 /* Dump rtl code after cse, if we are doing that. */
2181
2182 if (cse_dump)
2183 TIMEVAR (dump_time,
2184 {
2185 print_rtl (cse_dump_file, insns);
2186 fflush (cse_dump_file);
2187 });
2188
2189 if (loop_dump)
2190 TIMEVAR (dump_time,
2191 {
2192 fprintf (loop_dump_file, "\n;; Function %s\n\n",
2193 IDENTIFIER_POINTER (DECL_NAME (decl)));
2194 });
2195
2196 /* Move constant computations out of loops. */
2197
2198 if (optimize > 0)
2199 {
2200 TIMEVAR (loop_time,
2201 {
2202 loop_optimize (insns, loop_dump_file);
2203 });
2204 }
2205
2206 /* Dump rtl code after loop opt, if we are doing that. */
2207
2208 if (loop_dump)
2209 TIMEVAR (dump_time,
2210 {
2211 print_rtl (loop_dump_file, insns);
2212 fflush (loop_dump_file);
2213 });
2214
2215 if (cse2_dump)
2216 TIMEVAR (dump_time,
2217 {
2218 fprintf (cse2_dump_file, "\n;; Function %s\n\n",
2219 IDENTIFIER_POINTER (DECL_NAME (decl)));
2220 });
2221
2222 if (optimize > 0 && flag_rerun_cse_after_loop)
2223 {
2224 TIMEVAR (cse2_time, reg_scan (insns, max_reg_num (), 0));
2225
2226 TIMEVAR (cse2_time, tem = cse_main (insns, max_reg_num (),
2227 1, cse2_dump_file));
2228 if (tem)
2229 TIMEVAR (jump_time, jump_optimize (insns, 0, 0, 0));
2230 }
2231
2232 if (optimize > 0 && flag_thread_jumps)
2233 /* This pass of jump threading straightens out code
2234 that was kinked by loop optimization. */
2235 TIMEVAR (jump_time, thread_jumps (insns, max_reg_num (), 0));
2236
2237 /* Dump rtl code after cse, if we are doing that. */
2238
2239 if (cse2_dump)
2240 TIMEVAR (dump_time,
2241 {
2242 print_rtl (cse2_dump_file, insns);
2243 fflush (cse2_dump_file);
2244 });
2245
2246 /* We are no longer anticipating cse in this function, at least. */
2247
2248 cse_not_expected = 1;
2249
2250 /* Now we choose between stupid (pcc-like) register allocation
2251 (if we got the -noreg switch and not -opt)
2252 and smart register allocation. */
2253
2254 if (optimize > 0) /* Stupid allocation probably won't work */
2255 obey_regdecls = 0; /* if optimizations being done. */
2256
2257 regclass_init ();
2258
2259 /* Print function header into flow dump now
2260 because doing the flow analysis makes some of the dump. */
2261
2262 if (flow_dump)
2263 TIMEVAR (dump_time,
2264 {
2265 fprintf (flow_dump_file, "\n;; Function %s\n\n",
2266 IDENTIFIER_POINTER (DECL_NAME (decl)));
2267 });
2268
2269 if (obey_regdecls)
2270 {
2271 TIMEVAR (flow_time,
2272 {
2273 regclass (insns, max_reg_num ());
2274 stupid_life_analysis (insns, max_reg_num (),
2275 flow_dump_file);
2276 });
2277 }
2278 else
2279 {
2280 /* Do control and data flow analysis,
2281 and write some of the results to dump file. */
2282
2283 TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
2284 flow_dump_file));
2285 if (warn_uninitialized)
2286 {
2287 uninitialized_vars_warning (DECL_INITIAL (decl));
2288 setjmp_args_warning ();
2289 }
2290 }
2291
2292 /* Dump rtl after flow analysis. */
2293
2294 if (flow_dump)
2295 TIMEVAR (dump_time,
2296 {
2297 print_rtl (flow_dump_file, insns);
2298 fflush (flow_dump_file);
2299 });
2300
2301 /* If -opt, try combining insns through substitution. */
2302
2303 if (optimize > 0)
2304 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
2305
2306 /* Dump rtl code after insn combination. */
2307
2308 if (combine_dump)
2309 TIMEVAR (dump_time,
2310 {
2311 fprintf (combine_dump_file, "\n;; Function %s\n\n",
2312 IDENTIFIER_POINTER (DECL_NAME (decl)));
2313 dump_combine_stats (combine_dump_file);
2314 print_rtl (combine_dump_file, insns);
2315 fflush (combine_dump_file);
2316 });
2317
2318 /* Print function header into sched dump now
2319 because doing the sched analysis makes some of the dump. */
2320
2321 if (sched_dump)
2322 TIMEVAR (dump_time,
2323 {
2324 fprintf (sched_dump_file, "\n;; Function %s\n\n",
2325 IDENTIFIER_POINTER (DECL_NAME (decl)));
2326 });
2327
2328 if (optimize > 0 && flag_schedule_insns)
2329 {
2330 /* Do control and data sched analysis,
2331 and write some of the results to dump file. */
2332
2333 TIMEVAR (sched_time, schedule_insns (sched_dump_file));
2334 }
2335
2336 /* Dump rtl after instruction scheduling. */
2337
2338 if (sched_dump)
2339 TIMEVAR (dump_time,
2340 {
2341 print_rtl (sched_dump_file, insns);
2342 fflush (sched_dump_file);
2343 });
2344
2345 /* Unless we did stupid register allocation,
2346 allocate pseudo-regs that are used only within 1 basic block. */
2347
2348 if (!obey_regdecls)
2349 TIMEVAR (local_alloc_time,
2350 {
2351 regclass (insns, max_reg_num ());
2352 local_alloc ();
2353 });
2354
2355 /* Dump rtl code after allocating regs within basic blocks. */
2356
2357 if (local_reg_dump)
2358 TIMEVAR (dump_time,
2359 {
2360 fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
2361 IDENTIFIER_POINTER (DECL_NAME (decl)));
2362 dump_flow_info (local_reg_dump_file);
2363 dump_local_alloc (local_reg_dump_file);
2364 print_rtl (local_reg_dump_file, insns);
2365 fflush (local_reg_dump_file);
2366 });
2367
2368 if (global_reg_dump)
2369 TIMEVAR (dump_time,
2370 fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
2371 IDENTIFIER_POINTER (DECL_NAME (decl))));
2372
2373 /* Unless we did stupid register allocation,
2374 allocate remaining pseudo-regs, then do the reload pass
2375 fixing up any insns that are invalid. */
2376
2377 TIMEVAR (global_alloc_time,
2378 {
2379 if (!obey_regdecls)
2380 failure = global_alloc (global_reg_dump_file);
2381 else
2382 failure = reload (insns, 0, global_reg_dump_file);
2383 });
2384
2385 if (global_reg_dump)
2386 TIMEVAR (dump_time,
2387 {
2388 dump_global_regs (global_reg_dump_file);
2389 print_rtl (global_reg_dump_file, insns);
2390 fflush (global_reg_dump_file);
2391 });
2392
2393 if (failure)
2394 goto exit_rest_of_compilation;
2395
2396 reload_completed = 1;
2397
2398 /* On some machines, the prologue and epilogue code, or parts thereof,
2399 can be represented as RTL. Doing so lets us schedule insns between
2400 it and the rest of the code and also allows delayed branch
2401 scheduling to operate in the epilogue. */
2402
2403 thread_prologue_and_epilogue_insns (insns);
2404
2405 if (optimize > 0 && flag_schedule_insns_after_reload)
2406 {
2407 if (sched2_dump)
2408 TIMEVAR (dump_time,
2409 {
2410 fprintf (sched2_dump_file, "\n;; Function %s\n\n",
2411 IDENTIFIER_POINTER (DECL_NAME (decl)));
2412 });
2413
2414 /* Do control and data sched analysis again,
2415 and write some more of the results to dump file. */
2416
2417 TIMEVAR (sched2_time, schedule_insns (sched2_dump_file));
2418
2419 /* Dump rtl after post-reorder instruction scheduling. */
2420
2421 if (sched2_dump)
2422 TIMEVAR (dump_time,
2423 {
2424 print_rtl (sched2_dump_file, insns);
2425 fflush (sched2_dump_file);
2426 });
2427 }
2428
2429 #ifdef LEAF_REGISTERS
2430 leaf_function = 0;
2431 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
2432 leaf_function = 1;
2433 #endif
2434
2435 /* One more attempt to remove jumps to .+1
2436 left by dead-store-elimination.
2437 Also do cross-jumping this time
2438 and delete no-op move insns. */
2439
2440 if (optimize > 0)
2441 {
2442 TIMEVAR (jump_time, jump_optimize (insns, 1, 1, 0));
2443 }
2444
2445 /* Dump rtl code after jump, if we are doing that. */
2446
2447 if (jump2_opt_dump)
2448 TIMEVAR (dump_time,
2449 {
2450 fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
2451 IDENTIFIER_POINTER (DECL_NAME (decl)));
2452 print_rtl (jump2_opt_dump_file, insns);
2453 fflush (jump2_opt_dump_file);
2454 });
2455
2456 /* If a scheduling pass for delayed branches is to be done,
2457 call the scheduling code. */
2458
2459 #ifdef DELAY_SLOTS
2460 if (optimize > 0 && flag_delayed_branch)
2461 {
2462 TIMEVAR (dbr_sched_time, dbr_schedule (insns, dbr_sched_dump_file));
2463 if (dbr_sched_dump)
2464 {
2465 TIMEVAR (dump_time,
2466 {
2467 fprintf (dbr_sched_dump_file, "\n;; Function %s\n\n",
2468 IDENTIFIER_POINTER (DECL_NAME (decl)));
2469 print_rtl (dbr_sched_dump_file, insns);
2470 fflush (dbr_sched_dump_file);
2471 });
2472 }
2473 }
2474 #endif
2475
2476 if (optimize > 0)
2477 /* Shorten branches. */
2478 TIMEVAR (shorten_branch_time,
2479 {
2480 shorten_branches (get_insns ());
2481 });
2482
2483 #ifdef STACK_REGS
2484 TIMEVAR (stack_reg_time, reg_to_stack (insns, stack_reg_dump_file));
2485 if (stack_reg_dump)
2486 {
2487 TIMEVAR (dump_time,
2488 {
2489 fprintf (stack_reg_dump_file, "\n;; Function %s\n\n",
2490 IDENTIFIER_POINTER (DECL_NAME (decl)));
2491 print_rtl (stack_reg_dump_file, insns);
2492 fflush (stack_reg_dump_file);
2493 });
2494 }
2495 #endif
2496
2497 /* Now turn the rtl into assembler code. */
2498
2499 TIMEVAR (final_time,
2500 {
2501 rtx x;
2502 char *fnname;
2503
2504 /* Get the function's name, as described by its RTL.
2505 This may be different from the DECL_NAME name used
2506 in the source file. */
2507
2508 x = DECL_RTL (decl);
2509 if (GET_CODE (x) != MEM)
2510 abort ();
2511 x = XEXP (x, 0);
2512 if (GET_CODE (x) != SYMBOL_REF)
2513 abort ();
2514 fnname = XSTR (x, 0);
2515
2516 assemble_start_function (decl, fnname);
2517 final_start_function (insns, asm_out_file, optimize);
2518 final (insns, asm_out_file, optimize, 0);
2519 final_end_function (insns, asm_out_file, optimize);
2520 assemble_end_function (decl, fnname);
2521 fflush (asm_out_file);
2522 });
2523
2524 /* Write DBX symbols if requested */
2525
2526 /* Note that for those inline functions where we don't initially
2527 know for certain that we will be generating an out-of-line copy,
2528 the first invocation of this routine (rest_of_compilation) will
2529 skip over this code by doing a `goto exit_rest_of_compilation;'.
2530 Later on, finish_compilation will call rest_of_compilation again
2531 for those inline functions that need to have out-of-line copies
2532 generated. During that call, we *will* be routed past here. */
2533
2534 #ifdef DBX_DEBUGGING_INFO
2535 if (write_symbols == DBX_DEBUG)
2536 TIMEVAR (symout_time, dbxout_function (decl));
2537 #endif
2538
2539 #ifdef DWARF_DEBUGGING_INFO
2540 if (write_symbols == DWARF_DEBUG)
2541 TIMEVAR (symout_time, dwarfout_file_scope_decl (decl, 0));
2542 #endif
2543
2544 exit_rest_of_compilation:
2545
2546 /* In case the function was not output,
2547 don't leave any temporary anonymous types
2548 queued up for sdb output. */
2549 #ifdef SDB_DEBUGGING_INFO
2550 if (write_symbols == SDB_DEBUG)
2551 sdbout_types (NULL_TREE);
2552 #endif
2553
2554 /* Put back the tree of subblocks and list of arguments
2555 from before we copied them.
2556 Code generation and the output of debugging info may have modified
2557 the copy, but the original is unchanged. */
2558
2559 if (saved_block_tree != 0)
2560 DECL_INITIAL (decl) = saved_block_tree;
2561 if (saved_arguments != 0)
2562 DECL_ARGUMENTS (decl) = saved_arguments;
2563
2564 reload_completed = 0;
2565
2566 /* Clear out the real_constant_chain before some of the rtx's
2567 it runs through become garbage. */
2568
2569 clear_const_double_mem ();
2570
2571 /* Cancel the effect of rtl_in_current_obstack. */
2572
2573 resume_temporary_allocation ();
2574
2575 /* The parsing time is all the time spent in yyparse
2576 *except* what is spent in this function. */
2577
2578 parse_time -= get_run_time () - start_time;
2579 }
2580 \f
2581 /* Entry point of cc1/c++. Decode command args, then call compile_file.
2582 Exit code is 35 if can't open files, 34 if fatal error,
2583 33 if had nonfatal errors, else success. */
2584
2585 int
2586 main (argc, argv, envp)
2587 int argc;
2588 char **argv;
2589 char **envp;
2590 {
2591 register int i;
2592 char *filename = 0;
2593 int flag_print_mem = 0;
2594 int version_flag = 0;
2595 char *p;
2596
2597 /* save in case md file wants to emit args as a comment. */
2598 save_argc = argc;
2599 save_argv = argv;
2600
2601 p = argv[0] + strlen (argv[0]);
2602 while (p != argv[0] && p[-1] != '/') --p;
2603 progname = p;
2604
2605 #ifdef RLIMIT_STACK
2606 /* Get rid of any avoidable limit on stack size. */
2607 {
2608 struct rlimit rlim;
2609
2610 /* Set the stack limit huge so that alloca does not fail. */
2611 getrlimit (RLIMIT_STACK, &rlim);
2612 rlim.rlim_cur = rlim.rlim_max;
2613 setrlimit (RLIMIT_STACK, &rlim);
2614 }
2615 #endif /* RLIMIT_STACK */
2616
2617 signal (SIGFPE, float_signal);
2618
2619 signal (SIGPIPE, pipe_closed);
2620
2621 decl_printable_name = decl_name;
2622 lang_expand_expr = (struct rtx_def *(*)()) do_abort;
2623
2624 /* Initialize whether `char' is signed. */
2625 flag_signed_char = DEFAULT_SIGNED_CHAR;
2626 #ifdef DEFAULT_SHORT_ENUMS
2627 /* Initialize how much space enums occupy, by default. */
2628 flag_short_enums = DEFAULT_SHORT_ENUMS;
2629 #endif
2630
2631 /* Scan to see what optimization level has been specified. That will
2632 determine the default value of many flags. */
2633 for (i = 1; i < argc; i++)
2634 {
2635 if (!strcmp (argv[i], "-O"))
2636 {
2637 optimize = 1;
2638 }
2639 else if (argv[i][0] == '-' && argv[i][1] == 'O')
2640 {
2641 /* Handle -O2, -O3, -O69, ... */
2642 char *p = &argv[i][2];
2643 int c;
2644
2645 while (c = *p++)
2646 if (! (c >= '0' && c <= '9'))
2647 break;
2648 if (c == 0)
2649 optimize = atoi (&argv[i][2]);
2650 }
2651 }
2652
2653 obey_regdecls = (optimize == 0);
2654 if (optimize == 0)
2655 {
2656 flag_no_inline = 1;
2657 warn_inline = 0;
2658 }
2659
2660 if (optimize >= 1)
2661 {
2662 flag_thread_jumps = 1;
2663 #ifdef DELAY_SLOTS
2664 flag_delayed_branch = 1;
2665 #endif
2666 }
2667
2668 if (optimize >= 2)
2669 {
2670 flag_cse_follow_jumps = 1;
2671 flag_cse_skip_blocks = 1;
2672 flag_expensive_optimizations = 1;
2673 flag_strength_reduce = 1;
2674 flag_rerun_cse_after_loop = 1;
2675 flag_caller_saves = 1;
2676 #ifdef INSN_SCHEDULING
2677 flag_schedule_insns = 1;
2678 flag_schedule_insns_after_reload = 1;
2679 #endif
2680 }
2681
2682 #ifdef OPTIMIZATION_OPTIONS
2683 /* Allow default optimizations to be specified on a per-machine basis. */
2684 OPTIMIZATION_OPTIONS (optimize);
2685 #endif
2686
2687 /* Initialize register usage now so switches may override. */
2688 init_reg_sets ();
2689
2690 target_flags = 0;
2691 set_target_switch ("");
2692
2693 for (i = 1; i < argc; i++)
2694 {
2695 if (argv[i][0] == '-' && argv[i][1] != 0)
2696 {
2697 register char *str = argv[i] + 1;
2698 if (str[0] == 'Y')
2699 str++;
2700
2701 if (str[0] == 'm')
2702 set_target_switch (&str[1]);
2703 else if (!strcmp (str, "dumpbase"))
2704 {
2705 dump_base_name = argv[++i];
2706 }
2707 else if (str[0] == 'd')
2708 {
2709 register char *p = &str[1];
2710 while (*p)
2711 switch (*p++)
2712 {
2713 case 'a':
2714 combine_dump = 1;
2715 dbr_sched_dump = 1;
2716 flow_dump = 1;
2717 global_reg_dump = 1;
2718 jump_opt_dump = 1;
2719 jump2_opt_dump = 1;
2720 local_reg_dump = 1;
2721 loop_dump = 1;
2722 rtl_dump = 1;
2723 cse_dump = 1, cse2_dump = 1;
2724 sched_dump = 1;
2725 sched2_dump = 1;
2726 stack_reg_dump = 1;
2727 break;
2728 case 'k':
2729 stack_reg_dump = 1;
2730 break;
2731 case 'c':
2732 combine_dump = 1;
2733 break;
2734 case 'd':
2735 dbr_sched_dump = 1;
2736 break;
2737 case 'f':
2738 flow_dump = 1;
2739 break;
2740 case 'g':
2741 global_reg_dump = 1;
2742 break;
2743 case 'j':
2744 jump_opt_dump = 1;
2745 break;
2746 case 'J':
2747 jump2_opt_dump = 1;
2748 break;
2749 case 'l':
2750 local_reg_dump = 1;
2751 break;
2752 case 'L':
2753 loop_dump = 1;
2754 break;
2755 case 'm':
2756 flag_print_mem = 1;
2757 break;
2758 case 'p':
2759 flag_print_asm_name = 1;
2760 break;
2761 case 'r':
2762 rtl_dump = 1;
2763 break;
2764 case 's':
2765 cse_dump = 1;
2766 break;
2767 case 't':
2768 cse2_dump = 1;
2769 break;
2770 case 'S':
2771 sched_dump = 1;
2772 break;
2773 case 'R':
2774 sched2_dump = 1;
2775 break;
2776 case 'y':
2777 set_yydebug (1);
2778 break;
2779
2780 case 'x':
2781 rtl_dump_and_exit = 1;
2782 break;
2783 }
2784 }
2785 else if (str[0] == 'f')
2786 {
2787 int j;
2788 register char *p = &str[1];
2789 int found = 0;
2790
2791 /* Some kind of -f option.
2792 P's value is the option sans `-f'.
2793 Search for it in the table of options. */
2794
2795 for (j = 0;
2796 !found && j < sizeof (f_options) / sizeof (f_options[0]);
2797 j++)
2798 {
2799 if (!strcmp (p, f_options[j].string))
2800 {
2801 *f_options[j].variable = f_options[j].on_value;
2802 /* A goto here would be cleaner,
2803 but breaks the vax pcc. */
2804 found = 1;
2805 }
2806 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
2807 && ! strcmp (p+3, f_options[j].string))
2808 {
2809 *f_options[j].variable = ! f_options[j].on_value;
2810 found = 1;
2811 }
2812 }
2813
2814 if (found)
2815 ;
2816 else if (!strncmp (p, "fixed-", 6))
2817 fix_register (&p[6], 1, 1);
2818 else if (!strncmp (p, "call-used-", 10))
2819 fix_register (&p[10], 0, 1);
2820 else if (!strncmp (p, "call-saved-", 11))
2821 fix_register (&p[11], 0, 0);
2822 else if (! lang_decode_option (argv[i]))
2823 error ("Invalid option `%s'", argv[i]);
2824 }
2825 else if (str[0] == 'O')
2826 {
2827 register char *p = str+1;
2828 while (*p && *p >= '0' && *p <= '9')
2829 p++;
2830 if (*p == '\0')
2831 ;
2832 else
2833 error ("Invalid option `%s'", argv[i]);
2834 }
2835 else if (!strcmp (str, "pedantic"))
2836 pedantic = 1;
2837 else if (!strcmp (str, "pedantic-errors"))
2838 flag_pedantic_errors = pedantic = 1;
2839 else if (lang_decode_option (argv[i]))
2840 ;
2841 else if (!strcmp (str, "quiet"))
2842 quiet_flag = 1;
2843 else if (!strcmp (str, "version"))
2844 version_flag = 1;
2845 else if (!strcmp (str, "w"))
2846 inhibit_warnings = 1;
2847 else if (!strcmp (str, "W"))
2848 {
2849 extra_warnings = 1;
2850 warn_uninitialized = 1;
2851 }
2852 else if (str[0] == 'W')
2853 {
2854 int j;
2855 register char *p = &str[1];
2856 int found = 0;
2857
2858 /* Some kind of -W option.
2859 P's value is the option sans `-W'.
2860 Search for it in the table of options. */
2861
2862 for (j = 0;
2863 !found && j < sizeof (W_options) / sizeof (W_options[0]);
2864 j++)
2865 {
2866 if (!strcmp (p, W_options[j].string))
2867 {
2868 *W_options[j].variable = W_options[j].on_value;
2869 /* A goto here would be cleaner,
2870 but breaks the vax pcc. */
2871 found = 1;
2872 }
2873 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
2874 && ! strcmp (p+3, W_options[j].string))
2875 {
2876 *W_options[j].variable = ! W_options[j].on_value;
2877 found = 1;
2878 }
2879 }
2880
2881 if (found)
2882 ;
2883 else if (!strncmp (p, "id-clash-", 9))
2884 {
2885 char *endp = p + 9;
2886
2887 while (*endp)
2888 {
2889 if (*endp >= '0' && *endp <= '9')
2890 endp++;
2891 else
2892 error ("Invalid option `%s'", argv[i]);
2893 }
2894 warn_id_clash = 1;
2895 id_clash_len = atoi (str + 10);
2896 }
2897 else
2898 error ("Invalid option `%s'", argv[i]);
2899 }
2900 else if (!strcmp (str, "p"))
2901 profile_flag = 1;
2902 else if (!strcmp (str, "a"))
2903 {
2904 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
2905 warning ("`-a' option (basic block profile) not supported");
2906 #else
2907 profile_block_flag = 1;
2908 #endif
2909 }
2910 else if (str[0] == 'g')
2911 {
2912 char *p = str + 1;
2913 char *q;
2914 unsigned len;
2915 unsigned level;
2916
2917 while (*p && (*p < '0' || *p > '9'))
2918 p++;
2919 len = p - str;
2920 q = p;
2921 while (*q && (*q >= '0' && *q <= '9'))
2922 q++;
2923 if (*p)
2924 level = atoi (p);
2925 else
2926 level = 2; /* default debugging info level */
2927 if (*q || level > 3)
2928 {
2929 warning ("invalid debug level specification in option: `-%s'",
2930 str);
2931 warning ("no debugging information will be generated");
2932 level = 0;
2933 }
2934
2935 /* If more than one debugging type is supported,
2936 you must define PREFERRED_DEBUGGING_TYPE
2937 to choose a format in a system-dependent way. */
2938 /* This is one long line cause VAXC can't handle a \-newline. */
2939 #if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))
2940 #ifdef PREFERRED_DEBUGGING_TYPE
2941 if (!strncmp (str, "ggdb", len))
2942 write_symbols = PREFERRED_DEBUGGING_TYPE;
2943 #else /* no PREFERRED_DEBUGGING_TYPE */
2944 You Lose! You must define PREFERRED_DEBUGGING_TYPE!
2945 #endif /* no PREFERRED_DEBUGGING_TYPE */
2946 #endif /* More than one debugger format enabled. */
2947 #ifdef DBX_DEBUGGING_INFO
2948 if (write_symbols != NO_DEBUG)
2949 ;
2950 else if (!strncmp (str, "ggdb", len))
2951 write_symbols = DBX_DEBUG;
2952 else if (!strncmp (str, "gstabs", len))
2953 write_symbols = DBX_DEBUG;
2954
2955 /* Always enable extensions for -ggdb or -gstabs+,
2956 always disable for -gstabs.
2957 For plain -g, use system-specific default. */
2958 if (write_symbols == DBX_DEBUG && !strncmp (str, "ggdb", len)
2959 && len >= 2)
2960 use_gnu_debug_info_extensions = 1;
2961 else if (write_symbols == DBX_DEBUG && !strcmp (str, "gstabs+"))
2962 use_gnu_debug_info_extensions = 1;
2963 else if (write_symbols == DBX_DEBUG
2964 && !strncmp (str, "gstabs", len) && len >= 2)
2965 use_gnu_debug_info_extensions = 0;
2966 else
2967 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
2968 #endif /* DBX_DEBUGGING_INFO */
2969 #ifdef DWARF_DEBUGGING_INFO
2970 if (write_symbols != NO_DEBUG)
2971 ;
2972 else if (!strncmp (str, "g", len))
2973 write_symbols = DWARF_DEBUG;
2974 else if (!strncmp (str, "ggdb", len))
2975 write_symbols = DWARF_DEBUG;
2976 else if (!strncmp (str, "gdwarf", len))
2977 write_symbols = DWARF_DEBUG;
2978
2979 /* Always enable extensions for -ggdb or -gdwarf+,
2980 always disable for -gdwarf.
2981 For plain -g, use system-specific default. */
2982 if (write_symbols == DWARF_DEBUG && !strncmp (str, "ggdb", len)
2983 && len >= 2)
2984 use_gnu_debug_info_extensions = 1;
2985 else if (write_symbols == DWARF_DEBUG && !strcmp (str, "gdwarf+"))
2986 use_gnu_debug_info_extensions = 1;
2987 else if (write_symbols == DWARF_DEBUG
2988 && !strncmp (str, "gdwarf", len) && len >= 2)
2989 use_gnu_debug_info_extensions = 0;
2990 else
2991 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
2992 #endif
2993 #ifdef SDB_DEBUGGING_INFO
2994 if (write_symbols != NO_DEBUG)
2995 ;
2996 else if (!strncmp (str, "g", len))
2997 write_symbols = SDB_DEBUG;
2998 else if (!strncmp (str, "gdb", len))
2999 write_symbols = SDB_DEBUG;
3000 else if (!strncmp (str, "gcoff", len))
3001 write_symbols = SDB_DEBUG;
3002 #endif /* SDB_DEBUGGING_INFO */
3003 #ifdef XCOFF_DEBUGGING_INFO
3004 if (write_symbols != NO_DEBUG)
3005 ;
3006 else if (!strncmp (str, "g", len))
3007 write_symbols = XCOFF_DEBUG;
3008 else if (!strncmp (str, "ggdb", len))
3009 write_symbols = XCOFF_DEBUG;
3010 else if (!strncmp (str, "gxcoff", len))
3011 write_symbols = XCOFF_DEBUG;
3012
3013 /* Always enable extensions for -ggdb or -gxcoff+,
3014 always disable for -gxcoff.
3015 For plain -g, use system-specific default. */
3016 if (write_symbols == XCOFF_DEBUG && !strncmp (str, "ggdb", len)
3017 && len >= 2)
3018 use_gnu_debug_info_extensions = 1;
3019 else if (write_symbols == XCOFF_DEBUG && !strcmp (str, "gxcoff+"))
3020 use_gnu_debug_info_extensions = 1;
3021 else if (write_symbols == XCOFF_DEBUG
3022 && !strncmp (str, "gxcoff", len) && len >= 2)
3023 use_gnu_debug_info_extensions = 0;
3024 else
3025 use_gnu_debug_info_extensions = DEFAULT_GDB_EXTENSIONS;
3026 #endif
3027 if (write_symbols == NO_DEBUG)
3028 warning ("`-%s' option not supported on this version of GCC", str);
3029 else if (level == 0)
3030 write_symbols = NO_DEBUG;
3031 else
3032 debug_info_level = (enum debug_info_level) level;
3033 }
3034 else if (!strcmp (str, "o"))
3035 {
3036 asm_file_name = argv[++i];
3037 }
3038 else if (str[0] == 'G')
3039 {
3040 g_switch_set = TRUE;
3041 g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]);
3042 }
3043 else if (!strncmp (str, "aux-info", 8))
3044 {
3045 flag_gen_aux_info = 1;
3046 aux_info_file_name = (str[8] != '\0' ? str+8 : argv[++i]);
3047 }
3048 else
3049 error ("Invalid option `%s'", argv[i]);
3050 }
3051 else if (argv[i][0] == '+')
3052 {
3053 if (lang_decode_option (argv[i]))
3054 ;
3055 else
3056 error ("Invalid option `%s'", argv[i]);
3057 }
3058 else
3059 filename = argv[i];
3060 }
3061
3062 /* Inlining does not work if not optimizing,
3063 so force it not to be done. */
3064 if (optimize == 0)
3065 {
3066 flag_no_inline = 1;
3067 warn_inline = 0;
3068 }
3069
3070 #ifdef OVERRIDE_OPTIONS
3071 /* Some machines may reject certain combinations of options. */
3072 OVERRIDE_OPTIONS;
3073 #endif
3074
3075 /* Unrolling all loops implies that standard loop unrolling must also
3076 be done. */
3077 if (flag_unroll_all_loops)
3078 flag_unroll_loops = 1;
3079 /* Loop unrolling requires that strength_reduction be on also. Silently
3080 turn on strength reduction here if it isn't already on. Also, the loop
3081 unrolling code assumes that cse will be run after loop, so that must
3082 be turned on also. */
3083 if (flag_unroll_loops)
3084 {
3085 flag_strength_reduce = 1;
3086 flag_rerun_cse_after_loop = 1;
3087 }
3088
3089 /* Warn about options that are not supported on this machine. */
3090 #ifndef INSN_SCHEDULING
3091 if (flag_schedule_insns || flag_schedule_insns_after_reload)
3092 warning ("instruction scheduling not supported on this target machine");
3093 #endif
3094 #ifndef DELAY_SLOTS
3095 if (flag_delayed_branch)
3096 warning ("this target machine does not have delayed branches");
3097 #endif
3098
3099 /* If we are in verbose mode, write out the version and maybe all the
3100 option flags in use. */
3101 if (version_flag)
3102 {
3103 fprintf (stderr, "%s version %s", language_string, version_string);
3104 #ifdef TARGET_VERSION
3105 TARGET_VERSION;
3106 #endif
3107 #ifdef __GNUC__
3108 #ifndef __VERSION__
3109 #define __VERSION__ "[unknown]"
3110 #endif
3111 fprintf (stderr, " compiled by GNU C version %s.\n", __VERSION__);
3112 #else
3113 fprintf (stderr, " compiled by CC.\n");
3114 #endif
3115 if (! quiet_flag)
3116 print_switch_values ();
3117 }
3118
3119 /* Now that register usage is specified, convert it to HARD_REG_SETs. */
3120 init_reg_sets_1 ();
3121
3122 compile_file (filename);
3123
3124 #ifndef OS2
3125 #ifndef VMS
3126 if (flag_print_mem)
3127 {
3128 char *lim = (char *) sbrk (0);
3129
3130 fprintf (stderr, "Data size %d.\n",
3131 lim - (char *) &environ);
3132 fflush (stderr);
3133
3134 #ifdef USG
3135 system ("ps -l 1>&2");
3136 #else /* not USG */
3137 system ("ps v");
3138 #endif /* not USG */
3139 }
3140 #endif /* not VMS */
3141 #endif /* not OS2 */
3142
3143 if (errorcount)
3144 exit (FATAL_EXIT_CODE);
3145 if (sorrycount)
3146 exit (FATAL_EXIT_CODE);
3147 exit (SUCCESS_EXIT_CODE);
3148 return 34;
3149 }
3150 \f
3151 /* Decode -m switches. */
3152
3153 /* Here is a table, controlled by the tm.h file, listing each -m switch
3154 and which bits in `target_switches' it should set or clear.
3155 If VALUE is positive, it is bits to set.
3156 If VALUE is negative, -VALUE is bits to clear.
3157 (The sign bit is not used so there is no confusion.) */
3158
3159 struct {char *name; int value;} target_switches []
3160 = TARGET_SWITCHES;
3161
3162 /* This table is similar, but allows the switch to have a value. */
3163
3164 #ifdef TARGET_OPTIONS
3165 struct {char *prefix; char ** variable;} target_options []
3166 = TARGET_OPTIONS;
3167 #endif
3168
3169 /* Decode the switch -mNAME. */
3170
3171 void
3172 set_target_switch (name)
3173 char *name;
3174 {
3175 register int j;
3176 int valid = 0;
3177
3178 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
3179 if (!strcmp (target_switches[j].name, name))
3180 {
3181 if (target_switches[j].value < 0)
3182 target_flags &= ~-target_switches[j].value;
3183 else
3184 target_flags |= target_switches[j].value;
3185 valid = 1;
3186 }
3187
3188 #ifdef TARGET_OPTIONS
3189 if (!valid)
3190 for (j = 0; j < sizeof target_options / sizeof target_options[0]; j++)
3191 {
3192 int len = strlen (target_options[j].prefix);
3193 if (!strncmp (target_options[j].prefix, name, len))
3194 {
3195 *target_options[j].variable = name + len;
3196 valid = 1;
3197 }
3198 }
3199 #endif
3200
3201 if (!valid)
3202 error ("Invalid option `%s'", name);
3203 }
3204 \f
3205 /* Variable used for communication between the following two routines. */
3206
3207 static int line_position;
3208
3209 /* Print an option value and adjust the position in the line. */
3210
3211 static void
3212 print_single_switch (type, name)
3213 char *type, *name;
3214 {
3215 fprintf (stderr, " %s%s", type, name);
3216
3217 line_position += strlen (type) + strlen (name) + 1;
3218
3219 if (line_position > 65)
3220 {
3221 fprintf (stderr, "\n\t");
3222 line_position = 8;
3223 }
3224 }
3225
3226 /* Print default target switches for -version. */
3227
3228 static void
3229 print_switch_values ()
3230 {
3231 register int j;
3232
3233 fprintf (stderr, "enabled:");
3234 line_position = 8;
3235
3236 for (j = 0; j < sizeof f_options / sizeof f_options[0]; j++)
3237 if (*f_options[j].variable == f_options[j].on_value)
3238 print_single_switch ("-f", f_options[j].string);
3239
3240 for (j = 0; j < sizeof W_options / sizeof W_options[0]; j++)
3241 if (*W_options[j].variable == W_options[j].on_value)
3242 print_single_switch ("-W", W_options[j].string);
3243
3244 for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
3245 if (target_switches[j].name[0] != '\0'
3246 && target_switches[j].value > 0
3247 && ((target_switches[j].value & target_flags)
3248 == target_switches[j].value))
3249 print_single_switch ("-m", target_switches[j].name);
3250
3251 fprintf (stderr, "\n");
3252 }
This page took 0.199626 seconds and 6 git commands to generate.