2 * This code is derived from software copyrighted by the Free Software
5 * Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
9 static char sccsid
[] = "@(#)toplev.c 6.3 (Berkeley) 5/8/91";
12 /* Top level of GNU C compiler
13 Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
15 This file is part of GNU CC.
17 GNU CC is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 1, or (at your option)
22 GNU CC is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with GNU CC; see the file COPYING. If not, write to
29 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
32 /* This is the top level of cc1/c++.
33 It parses command args, opens files, invokes the various passes
34 in the proper order, and counts the time used by each.
35 Error messages and low-level interface to malloc also handled here. */
42 #include <sys/types.h>
47 #define SEEK_SET L_SET
48 #define SEEK_CUR L_INCR
49 #define SEEK_END L_XTND
55 #include <sys/fcntl.h>
57 #include <sys/param.h>
58 /* This is for hpux. It is a real screw. They should change hpux. */
60 #include <sys/times.h>
61 #include <time.h> /* Correct for hpux at least. Is it good on other USG? */
62 #undef FFS /* Some systems define this in param.h. */
66 #include <sys/resource.h>
77 #define _bufsiz(p) ((p)->_bufsiz)
80 /* Change by Bryan Boreham, Kewill, Sun Jul 23 14:41:26 1989.
81 Added some stuff for unexec-ing a part-done compilation. */
83 int been_here_before
= 0; /* Is this an unexec'd program? */
84 int just_done_unexec
= 0; /* Is this the process that *was* unexec'd? */
85 char *dump_source_name
; /* Keep argv[0] for dumping. */
87 /* @@ Should there be a filename length limit? */
88 char previous_asm_file_name
[128]; /* asm_file_name from the first run. */
94 extern int reload_completed
;
95 extern int rtx_equal_function_value_matters
;
97 extern void init_lex ();
98 extern void init_decl_processing ();
99 extern void init_tree ();
100 extern void init_rtl ();
101 extern void init_optabs ();
102 extern void init_stmt ();
103 extern void init_reg_sets ();
104 extern void dump_flow_info ();
105 extern void dump_local_alloc ();
107 void rest_of_decl_compilation ();
109 void error_with_file_and_line ();
111 void set_target_switch ();
112 void print_target_switch_defaults ();
113 static char *decl_name ();
115 /* Bit flags that specify the machine subtype we are compiling for.
116 Bits are tested using macros TARGET_... defined in the tm-...h file
117 and set by `-m...' switches. */
121 /* Name of current original source file (what was input to cpp).
122 This comes from each #-command in the actual input. */
124 char *input_filename
;
126 /* Name of top-level original source file (what was input to cpp).
127 This comes from the #-command at the beginning of the actual input.
128 If there isn't any there, then this is the cc1 input file name. */
130 char *main_input_filename
;
132 /* Current line number in real source file. */
136 /* Stack of currently pending input files. */
138 struct file_stack
*input_file_stack
;
140 /* Incremented on each change to input_file_stack. */
141 int input_file_stack_tick
;
143 /* FUNCTION_DECL for function now being parsed or compiled. */
145 extern tree current_function_decl
;
147 /* Name to use as base of names for dump output files. */
149 char *dump_base_name
;
151 /* Flags saying which kinds of debugging dump have been requested. */
154 int rtl_dump_and_exit
= 0;
155 int jump_opt_dump
= 0;
159 int combine_dump
= 0;
160 int local_reg_dump
= 0;
161 int global_reg_dump
= 0;
162 int jump2_opt_dump
= 0;
163 int dbr_sched_dump
= 0;
165 /* 1 => write gdb debugging output (using symout.c). -g0
166 2 => write dbx debugging output (using dbxout.c). -G0 */
168 enum debugger write_symbols
= NO_DEBUG
;
170 /* Nonzero means can use our own extensions to DBX format.
171 Relevant only with write_symbols == DBX_DEBUG. */
173 int use_gdb_dbx_extensions
;
175 /* Nonzero means do optimizations. -opt. */
179 /* Nonzero means `char' should be signed. */
181 int flag_signed_char
;
183 /* Nonzero means give an enum type only as many bytes as it needs. */
185 int flag_short_enums
;
187 /* Nonzero for -fcaller-saves: allocate values in regs that need to
188 be saved across function calls, if that produces overall better code.
189 Optional now, so people can test it. */
191 #ifdef DEFAULT_CALLER_SAVES
192 int flag_caller_saves
= 1;
194 int flag_caller_saves
= 0;
197 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
199 int flag_pcc_struct_return
= 0;
201 /* Nonzero for -fforce-mem: load memory value into a register
202 before arithmetic on it. This makes better cse but slower compilation. */
204 int flag_force_mem
= 0;
206 /* Nonzero for -fforce-addr: load memory address into a register before
207 reference to memory. This makes better cse but slower compilation. */
209 int flag_force_addr
= 0;
211 /* Nonzero for -fdefer-pop: don't pop args after each function call;
212 instead save them up to pop many calls' args with one insns. */
214 int flag_defer_pop
= 1;
216 /* Nonzero for -ffloat-store: don't allocate floats and doubles
217 in extended-precision registers. */
219 int flag_float_store
= 0;
221 /* Nonzero for -fcombine-regs:
222 allow instruction combiner to combine an insn
223 that just copies one reg to another. */
225 int flag_combine_regs
= 0;
227 /* Nonzero for -fcse-follow-jumps:
228 have cse follow jumps to do a more extensive job. */
230 int flag_cse_follow_jumps
;
232 /* Nonzero enables strength-reduction in loop.c. */
234 int flag_strength_reduce
= 0;
236 /* Nonzero for -fwritable-strings:
237 store string constants in data segment and don't uniquize them. */
239 int flag_writable_strings
= 0;
241 /* Nonzero means don't put addresses of constant functions in registers.
242 Used for compiling the Unix kernel, where strange substitutions are
243 done on the assembly output. */
245 int flag_no_function_cse
= 0;
247 /* Nonzero for -fomit-frame-pointer:
248 don't make a frame pointer in simple functions that don't require one. */
250 int flag_omit_frame_pointer
= 0;
252 /* Nonzero to inhibit use of define_optimization peephole opts. */
254 int flag_no_peephole
= 0;
256 /* Nonzero means all references through pointers are volatile. */
260 /* Nonzero means just do syntax checking; don't output anything. */
262 int flag_syntax_only
= 0;
264 /* Nonzero means do stupid register allocation.
265 Currently, this is 1 if `optimize' is 0. */
267 int obey_regdecls
= 0;
269 /* Don't print functions as they are compiled and don't print
270 times taken by the various passes. -quiet. */
274 /* Don't print warning messages. -w. */
276 int inhibit_warnings
= 0;
278 /* Do print extra warnings (such as for uninitialized variables). -W. */
280 int extra_warnings
= 0;
282 /* Nonzero to warn about unused local variables. */
286 /* Nonzero means warn about all declarations which shadow others. */
290 /* Warn if a switch on an enum fails to have a case for every enum value. */
294 /* Warn if a type conversion is done that might have confusing results. */
298 /* Nonzero means warn about any identifiers that match in the first N
299 characters. The value N is in `id_clash_len'. */
304 /* Nonzero means warn if inline function is too large. */
308 /* Number of error messages and warning messages so far. */
311 int warningcount
= 0;
314 /* Pointer to function to compute the name to use to print a declaration. */
316 char *(*decl_printable_name
) ();
318 /* Pointer to function to compute rtl for a language-specific tree code. */
320 struct rtx_def
*(*lang_expand_expr
) ();
322 /* Name of program invoked, sans directories. */
326 /* Nonzero if generating code to do profiling. */
328 int profile_flag
= 0;
330 /* Nonzero if generating code to do profiling on a line-by-line basis. */
332 int profile_block_flag
;
334 /* Nonzero for -pedantic switch: warn about anything
335 that standard spec forbids. */
339 /* Nonzero for -finline-functions: ok to inline functions that look like
340 good inline candidates. */
342 int flag_inline_functions
;
344 /* Nonzero for -fkeep-inline-functions: even if we make a function
345 go inline everywhere, keep its defintion around for debugging
348 int flag_keep_inline_functions
;
350 /* Nonzero means make the text shared if supported. */
352 int flag_shared_data
;
354 /* Nonzero means schedule into delayed branch slots if supported. */
356 int flag_delayed_branch
;
358 /* Copy of arguments to main. */
362 /* Nonzero means schedule instructions within basic blocks. */
364 int flag_schedule_insns
= 0;
366 /* Name for output file of assembly code, specified with -o. */
371 /* Name for output file of GDB symbol segment, specified with -symout. */
377 /* Value of the -G nn switch if the machine needs it. */
379 int g_switch_value
= 0;
380 int g_switch_used
= 0;
383 /* Table of language-independent -f options.
384 STRING is the option name. VARIABLE is the address of the variable.
385 ON_VALUE is the value to store in VARIABLE
386 if `-fSTRING' is seen as an option.
387 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
389 static struct { char *string
; int *variable
; int on_value
;} f_options
[] =
391 {"float-store", &flag_float_store
, 1},
392 {"volatile", &flag_volatile
, 1},
393 {"defer-pop", &flag_defer_pop
, 1},
394 {"omit-frame-pointer", &flag_omit_frame_pointer
, 1},
395 {"cse-follow-jumps", &flag_cse_follow_jumps
, 1},
396 {"strength-reduce", &flag_strength_reduce
, 1},
397 {"writable-strings", &flag_writable_strings
, 1},
398 {"peephole", &flag_no_peephole
, 0},
399 {"force-mem", &flag_force_mem
, 1},
400 {"force-addr", &flag_force_addr
, 1},
401 {"combine-regs", &flag_combine_regs
, 1},
402 {"function-cse", &flag_no_function_cse
, 0},
403 {"inline-functions", &flag_inline_functions
, 1},
404 {"keep-inline-functions", &flag_keep_inline_functions
, 1},
405 {"syntax-only", &flag_syntax_only
, 1},
406 {"shared-data", &flag_shared_data
, 1},
407 {"caller-saves", &flag_caller_saves
, 1},
408 {"pcc-struct-return", &flag_pcc_struct_return
, 1},
409 {"delayed-branch", &flag_delayed_branch
, 1},
410 {"schedule-insns", &flag_schedule_insns
, 1}
413 /* Output files for assembler code (real compiler output)
414 and debugging dumps. */
418 FILE *jump_opt_dump_file
;
420 FILE *loop_dump_file
;
421 FILE *flow_dump_file
;
422 FILE *combine_dump_file
;
423 FILE *local_reg_dump_file
;
424 FILE *global_reg_dump_file
;
425 FILE *jump2_opt_dump_file
;
426 FILE *dbr_sched_dump_file
;
428 /* Time accumulators, to count the total time spent in various passes. */
432 int integration_time
;
438 int local_alloc_time
;
439 int global_alloc_time
;
441 int shorten_branch_time
;
447 int field_xref
= 0; /* cross referencing flag */
450 /* Return time used so far, in microseconds. */
459 struct rusage rusage
;
464 int proc_system_time
;
466 int child_system_time
;
476 return (tms
.tms_utime
+ tms
.tms_stime
) * (1000000 / HZ
);
479 getrusage (0, &rusage
);
480 return (rusage
.ru_utime
.tv_sec
* 1000000 + rusage
.ru_utime
.tv_usec
481 + rusage
.ru_stime
.tv_sec
* 1000000 + rusage
.ru_stime
.tv_usec
);
484 return (vms_times
.proc_user_time
+ vms_times
.proc_system_time
) * 10000;
489 #define TIMEVAR(VAR, BODY) \
490 do { int otime = gettime (); BODY; VAR += gettime () - otime; } while (0)
493 print_time (str
, total
)
498 "time in %s: %d.%06d\n",
499 str
, total
/ 1000000, total
% 1000000);
502 /* Count an error or warning. Return 1 if the message should be printed. */
505 count_error (warningp
)
508 if (warningp
&& inhibit_warnings
)
519 /* Print a fatal error message. NAME is the text.
520 Also include a system error message based on `errno'. */
523 pfatal_with_name (name
)
526 fprintf (stderr
, "%s: ", progname
);
532 fatal_io_error (name
)
535 fprintf (stderr
, "%s: %s: I/O error\n", progname
, name
);
548 /* Called from insn-extract to give a better error message when we
549 don't have an insn to match what we are looking for, rather
550 than just calling abort(). */
553 fatal_insn_not_found (insn
)
556 error ("The following insn was not recognizable:", 0);
561 /* This is the default decl_printable_name function. */
567 return IDENTIFIER_POINTER (DECL_NAME (decl
));
570 static int need_error_newline
;
572 /* Function of last error message;
573 more generally, function such that if next error message is in it
574 then we don't have to mention the function name. */
575 static tree last_error_function
= NULL
;
577 /* Used to detect when input_file_stack has changed since last described. */
578 static int last_error_tick
;
580 /* Called when the start of a function definition is parsed,
581 this function prints on stderr the name of the function. */
584 announce_function (decl
)
589 if (rtl_dump_and_exit
)
590 fprintf (stderr
, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl
)));
592 fprintf (stderr
, " %s", (*decl_printable_name
) (decl
));
594 need_error_newline
= 1;
595 last_error_function
= current_function_decl
;
599 /* Prints out, if necessary, the name of the current function
600 which caused an error. Called from all error and warning functions. */
603 report_error_function (file
)
606 struct file_stack
*p
;
608 if (need_error_newline
)
610 fprintf (stderr
, "\n");
611 need_error_newline
= 0;
614 if (last_error_function
!= current_function_decl
)
617 fprintf (stderr
, "%s: ", file
);
619 if (current_function_decl
== NULL
)
620 fprintf (stderr
, "At top level:\n");
621 else if (TREE_CODE (TREE_TYPE (current_function_decl
)) == METHOD_TYPE
)
622 fprintf (stderr
, "In method %s:\n",
623 (*decl_printable_name
) (current_function_decl
));
625 fprintf (stderr
, "In function %s:\n",
626 (*decl_printable_name
) (current_function_decl
));
628 last_error_function
= current_function_decl
;
630 if (input_file_stack
&& input_file_stack
->next
!= 0
631 && input_file_stack_tick
!= last_error_tick
)
633 fprintf (stderr
, "In file included");
634 for (p
= input_file_stack
->next
; p
; p
= p
->next
)
636 fprintf (stderr
, " from %s:%d", p
->name
, p
->line
);
638 fprintf (stderr
, ",");
640 fprintf (stderr
, ":\n");
641 last_error_tick
= input_file_stack_tick
;
645 /* Report an error at the current line number.
646 S and V are a string and an arg for `printf'. */
651 int v
; /* @@also used as pointer */
652 int v2
; /* @@also used as pointer */
654 error_with_file_and_line (input_filename
, lineno
, s
, v
, v2
);
657 /* Report an error at line LINE of file FILE.
658 S and V are a string and an arg for `printf'. */
661 error_with_file_and_line (file
, line
, s
, v
, v2
)
670 report_error_function (file
);
673 fprintf (stderr
, "%s:%d: ", file
, line
);
675 fprintf (stderr
, "%s: ", progname
);
676 fprintf (stderr
, s
, v
, v2
);
677 fprintf (stderr
, "\n");
680 /* Report an error at the declaration DECL.
681 S and V are a string and an arg which uses %s to substitute the declaration name. */
684 error_with_decl (decl
, s
, v
)
691 report_error_function (DECL_SOURCE_FILE (decl
));
693 if (TREE_CODE (decl
) == PARM_DECL
)
694 fprintf (stderr
, "%s:%d: ",
695 DECL_SOURCE_FILE (DECL_CONTEXT (decl
)),
696 DECL_SOURCE_LINE (DECL_CONTEXT (decl
)));
698 fprintf (stderr
, "%s:%d: ",
699 DECL_SOURCE_FILE (decl
), DECL_SOURCE_LINE (decl
));
701 if (DECL_NAME (decl
))
702 fprintf (stderr
, s
, (*decl_printable_name
) (decl
), v
);
704 fprintf (stderr
, s
, "((anonymous))", v
);
705 fprintf (stderr
, "\n");
708 /* Report an error at the line number of the insn INSN.
709 S and V are a string and an arg for `printf'.
710 This is used only when INSN is an `asm' with operands,
711 and each ASM_OPERANDS records its own source file and line. */
714 error_for_asm (insn
, s
, v
, v2
)
717 int v
; /* @@also used as pointer */
718 int v2
; /* @@also used as pointer */
722 rtx body
= PATTERN (insn
);
725 /* Find the (or one of the) ASM_OPERANDS in the insn. */
726 if (GET_CODE (body
) == SET
&& GET_CODE (SET_SRC (body
)) == ASM_OPERANDS
)
727 asmop
= SET_SRC (body
);
728 else if (GET_CODE (body
) == ASM_OPERANDS
)
730 else if (GET_CODE (body
) == PARALLEL
731 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
)
732 asmop
= SET_SRC (XVECEXP (body
, 0, 0));
733 else if (GET_CODE (body
) == PARALLEL
734 && GET_CODE (XVECEXP (body
, 0, 0)) == ASM_OPERANDS
)
735 asmop
= XVECEXP (body
, 0, 0);
737 filename
= ASM_OPERANDS_SOURCE_FILE (asmop
);
738 line
= ASM_OPERANDS_SOURCE_LINE (asmop
);
740 error_with_file_and_line (filename
, line
, s
, v
, v2
);
743 /* Report a warning at line LINE.
744 S and V are a string and an arg for `printf'. */
747 warning_with_file_and_line (file
, line
, s
, v
, v2
)
754 if (count_error (1) == 0)
757 report_error_function (file
);
760 fprintf (stderr
, "%s:%d: ", file
, line
);
762 fprintf (stderr
, "%s: ", progname
);
764 fprintf (stderr
, "warning: ");
765 fprintf (stderr
, s
, v
, v2
);
766 fprintf (stderr
, "\n");
769 /* Report a warning at the current line number.
770 S and V are a string and an arg for `printf'. */
775 int v
; /* @@also used as pointer */
778 warning_with_file_and_line (input_filename
, lineno
, s
, v
, v2
);
781 /* Report a warning at the declaration DECL.
782 S is string which uses %s to substitute the declaration name.
783 V is a second parameter that S can refer to. */
786 warning_with_decl (decl
, s
, v
)
791 if (count_error (1) == 0)
794 report_error_function (DECL_SOURCE_FILE (decl
));
796 if (TREE_CODE (decl
) == PARM_DECL
)
797 fprintf (stderr
, "%s:%d: ",
798 DECL_SOURCE_FILE (DECL_CONTEXT (decl
)),
799 DECL_SOURCE_LINE (DECL_CONTEXT (decl
)));
801 fprintf (stderr
, "%s:%d: ",
802 DECL_SOURCE_FILE (decl
), DECL_SOURCE_LINE (decl
));
804 fprintf (stderr
, "warning: ");
805 if (DECL_NAME (decl
))
806 fprintf (stderr
, s
, (*decl_printable_name
) (decl
), v
);
808 fprintf (stderr
, s
, "((anonymous))", v
);
809 fprintf (stderr
, "\n");
812 /* Apologize for not implementing some feature.
813 S, V, and V2 are a string and args for `printf'. */
822 fprintf (stderr
, "%s:%d: ", input_filename
, lineno
);
824 fprintf (stderr
, "%s: ", progname
);
826 fprintf (stderr
, "sorry, not implemented: ");
827 fprintf (stderr
, s
, v
, v2
);
828 fprintf (stderr
, "\n");
831 /* Apologize for not implementing some feature, then quit.
832 S, V, and V2 are a string and args for `printf'. */
835 really_sorry (s
, v
, v2
)
840 fprintf (stderr
, "%s:%d: ", input_filename
, lineno
);
842 fprintf (stderr
, "c++: ");
844 fprintf (stderr
, "sorry, not implemented: ");
845 fprintf (stderr
, s
, v
, v2
);
846 fatal (" (fatal)\n");
849 /* More 'friendly' abort that prints the line and file.
850 config.h can #define abort fancy_abort if you like that sort of thing. */
855 fatal ("Internal gcc abort.");
858 /* When `malloc.c' is compiled with `rcheck' defined,
859 it calls this function to report clobberage. */
867 /* Same as `malloc' but report error if no memory available. */
873 register int value
= (int) malloc (size
);
875 fatal ("Virtual memory exhausted.");
879 /* Same as `realloc' but report error if no memory available. */
886 int result
= realloc (ptr
, size
);
888 fatal ("Virtual memory exhausted.");
892 /* Return the logarithm of X, base 2, considering X unsigned,
893 if X is a power of 2. Otherwise, returns -1. */
897 register unsigned int x
;
899 register int log
= 0;
900 /* Test for 0 or a power of 2. */
901 if (x
== 0 || x
!= (x
& -x
))
903 while ((x
>>= 1) != 0)
908 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
909 If X is 0, return -1. */
913 register unsigned int x
;
915 register int log
= -1;
923 jmp_buf float_handler
;
926 /* Specify where to longjmp to when a floating arithmetic error happens.
927 If HANDLER is 0, it means don't handle the errors any more. */
930 set_float_handler (handler
)
933 float_handled
= (handler
!= 0);
935 bcopy (handler
, float_handler
, sizeof (float_handler
));
938 /* Signals actually come here. */
943 if (float_handled
== 0)
946 longjmp (float_handler
, 1);
949 /* Handler for SIGPIPE. */
954 fatal ("output pipe has been closed");
957 /* Compile an entire file of output from cpp, named NAME.
958 Write a file of assembly output and various debugging dumps. */
966 int dump_base_name_length
;
968 int name_specified
= name
!= 0;
970 if (dump_base_name
== 0 || been_here_before
)
971 dump_base_name
= name
? name
: "gccdump";
972 dump_base_name_length
= strlen (dump_base_name
);
976 integration_time
= 0;
982 local_alloc_time
= 0;
983 global_alloc_time
= 0;
985 shorten_branch_time
= 0;
990 /* Open input file. */
992 if (name
== 0 || !strcmp (name
, "-"))
998 finput
= fopen (name
, "r");
1000 pfatal_with_name (name
);
1002 /* Initialize data in various passes,
1003 checking if this is an unexec'd program - bryan@kewill.uucp. */
1005 if (!been_here_before
)
1011 init_decl_processing ();
1017 extern void reinit_lex_for_unexec ();
1018 main_input_filename
= 0;
1019 reinit_lex_for_unexec ();
1020 reinit_search_statistics ();
1024 if (field_xref
) FIELD_xref_begin(input_filename
);
1027 /* If rtl dump desired, open the output file. */
1030 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1031 strcpy (dumpname
, dump_base_name
);
1032 strcat (dumpname
, ".rtl");
1033 rtl_dump_file
= fopen (dumpname
, "w");
1034 if (rtl_dump_file
== 0)
1035 pfatal_with_name (dumpname
);
1038 /* If jump_opt dump desired, open the output file. */
1041 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1042 strcpy (dumpname
, dump_base_name
);
1043 strcat (dumpname
, ".jump");
1044 jump_opt_dump_file
= fopen (dumpname
, "w");
1045 if (jump_opt_dump_file
== 0)
1046 pfatal_with_name (dumpname
);
1049 /* If cse dump desired, open the output file. */
1052 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1053 strcpy (dumpname
, dump_base_name
);
1054 strcat (dumpname
, ".cse");
1055 cse_dump_file
= fopen (dumpname
, "w");
1056 if (cse_dump_file
== 0)
1057 pfatal_with_name (dumpname
);
1060 /* If loop dump desired, open the output file. */
1063 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1064 strcpy (dumpname
, dump_base_name
);
1065 strcat (dumpname
, ".loop");
1066 loop_dump_file
= fopen (dumpname
, "w");
1067 if (loop_dump_file
== 0)
1068 pfatal_with_name (dumpname
);
1071 /* If flow dump desired, open the output file. */
1074 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1075 strcpy (dumpname
, dump_base_name
);
1076 strcat (dumpname
, ".flow");
1077 flow_dump_file
= fopen (dumpname
, "w");
1078 if (flow_dump_file
== 0)
1079 pfatal_with_name (dumpname
);
1082 /* If combine dump desired, open the output file. */
1085 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 10);
1086 strcpy (dumpname
, dump_base_name
);
1087 strcat (dumpname
, ".combine");
1088 combine_dump_file
= fopen (dumpname
, "w");
1089 if (combine_dump_file
== 0)
1090 pfatal_with_name (dumpname
);
1093 /* If local_reg dump desired, open the output file. */
1096 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1097 strcpy (dumpname
, dump_base_name
);
1098 strcat (dumpname
, ".lreg");
1099 local_reg_dump_file
= fopen (dumpname
, "w");
1100 if (local_reg_dump_file
== 0)
1101 pfatal_with_name (dumpname
);
1104 /* If global_reg dump desired, open the output file. */
1105 if (global_reg_dump
)
1107 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1108 strcpy (dumpname
, dump_base_name
);
1109 strcat (dumpname
, ".greg");
1110 global_reg_dump_file
= fopen (dumpname
, "w");
1111 if (global_reg_dump_file
== 0)
1112 pfatal_with_name (dumpname
);
1115 /* If jump2_opt dump desired, open the output file. */
1118 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 7);
1119 strcpy (dumpname
, dump_base_name
);
1120 strcat (dumpname
, ".jump2");
1121 jump2_opt_dump_file
= fopen (dumpname
, "w");
1122 if (jump2_opt_dump_file
== 0)
1123 pfatal_with_name (dumpname
);
1126 /* If dbr_sched dump desired, open the output file. */
1129 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 7);
1130 strcpy (dumpname
, dump_base_name
);
1131 strcat (dumpname
, ".dbr");
1132 dbr_sched_dump_file
= fopen (dumpname
, "w");
1133 if (dbr_sched_dump_file
== 0)
1134 pfatal_with_name (dumpname
);
1137 /* Open assembler code output file. */
1139 if (! name_specified
&& asm_file_name
== 0)
1140 asm_out_file
= stdout
;
1143 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1144 int len
= strlen (dump_base_name
);
1145 strcpy (dumpname
, dump_base_name
);
1146 if (len
> 2 && ! strcmp (".c", dumpname
+ len
- 2))
1147 dumpname
[len
- 2] = 0;
1148 else if (len
> 2 && ! strcmp (".i", dumpname
+ len
- 2))
1149 dumpname
[len
- 2] = 0;
1150 else if (len
> 3 && ! strcmp (".co", dumpname
+ len
- 3))
1151 dumpname
[len
- 3] = 0;
1152 strcat (dumpname
, ".s");
1153 if (asm_file_name
== 0)
1155 asm_file_name
= (char *) malloc (strlen (dumpname
) + 1);
1156 strcpy (asm_file_name
, dumpname
);
1158 if (!strcmp (asm_file_name
, "-"))
1159 asm_out_file
= stdout
;
1161 asm_out_file
= fopen (asm_file_name
, "w");
1162 if (asm_out_file
== 0)
1163 pfatal_with_name (asm_file_name
);
1166 input_filename
= name
;
1168 /* the beginning of the file is a new line; check for # */
1169 /* With luck, we discover the real source file's name from that
1170 and put it in input_filename. */
1171 ungetc (check_newline (), finput
);
1173 /* If the input doesn't start with a #line, use the input name
1174 as the official input file name. */
1175 if (main_input_filename
== 0)
1176 main_input_filename
= name
;
1178 /* Put an entry on the input file stack for the main input file. */
1180 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
1181 input_file_stack
->next
= 0;
1182 input_file_stack
->name
= input_filename
;
1185 if (!been_here_before
)
1188 ASM_FILE_START (asm_out_file
);
1190 /* Output something to inform GDB that this compilation was by GCC. */
1191 #ifndef ASM_IDENTIFY_GCC
1192 fprintf (asm_out_file
, "gcc_compiled.:\n");
1194 ASM_IDENTIFY_GCC (asm_out_file
);
1201 /* Copy what we output during the first run into this asm file. */
1204 prev_file
= fopen (previous_asm_file_name
, "r");
1206 pfatal_with_name (previous_asm_file_name
);
1209 if (_bufsiz(asm_out_file
) != _bufsiz(prev_file
))
1213 while ((c
= getc (prev_file
)) != EOF
)
1214 putc (c
, asm_out_file
);
1223 fwrite (&dummy
, 1, 1, asm_out_file
);
1224 asm_out_file
->_ptr
= asm_out_file
->_base
;
1225 asm_out_file
->_cnt
= _bufsiz(asm_out_file
);
1228 size
= fread (asm_out_file
->_base
, 1, _bufsiz(asm_out_file
), prev_file
);
1229 asm_out_file
->_ptr
+= size
;
1230 asm_out_file
->_cnt
-= size
;
1231 fflush (asm_out_file
);
1233 while (size
== _bufsiz(asm_out_file
));
1239 #endif /* HAVE_UNDUMP */
1241 #if 0 /* This mode is discontinued. */
1242 /* If GDB symbol table desired, open the GDB symbol output file. */
1243 if (write_symbols
== GDB_DEBUG
)
1245 register char *dumpname
= (char *) xmalloc (dump_base_name_length
+ 6);
1246 int len
= strlen (dump_base_name
);
1247 strcpy (dumpname
, dump_base_name
);
1248 if (len
> 2 && ! strcmp (".c", dumpname
+ len
- 2))
1249 dumpname
[len
- 2] = 0;
1250 else if (len
> 2 && ! strcmp (".i", dumpname
+ len
- 2))
1251 dumpname
[len
- 2] = 0;
1252 else if (len
> 3 && ! strcmp (".co", dumpname
+ len
- 3))
1253 dumpname
[len
- 3] = 0;
1254 strcat (dumpname
, ".sym");
1255 if (sym_file_name
== 0)
1256 sym_file_name
= dumpname
;
1257 symout_init (sym_file_name
, asm_out_file
, main_input_filename
);
1261 /* If dbx symbol table desired, initialize writing it
1262 and output the predefined types. */
1263 #ifdef DBX_DEBUGGING_INFO
1264 if (write_symbols
== DBX_DEBUG
)
1266 if (!been_here_before
)
1267 dbxout_init (asm_out_file
, main_input_filename
);
1270 extern void re_init_dbxout_for_unexec ();
1271 re_init_dbxout_for_unexec (asm_out_file
, main_input_filename
);
1275 #ifdef SDB_DEBUGGING_INFO
1276 if (write_symbols
== SDB_DEBUG
)
1277 sdbout_init (asm_out_file
, main_input_filename
);
1280 /* Initialize yet another pass. */
1282 if (!been_here_before
)
1283 init_final (main_input_filename
);
1285 start_time
= gettime ();
1287 /* Call the parser, which parses the entire file
1288 (calling rest_of_compilation for each function). */
1290 if (setjmp (toplevel
) == 0)
1292 if (yyparse () != 0)
1294 if (errorcount
== 0)
1296 fprintf (stderr
, "Errors detected in input file (your bison.simple is out of date)");
1301 /* Compilation is now finished except for writing
1302 what's left of the symbol table output. */
1304 parse_time
+= gettime () - start_time
;
1306 parse_time
-= integration_time
;
1307 parse_time
-= varconst_time
;
1311 /* Change by Bryan Boreham, Kewill, Sat Aug 5 19:05:44 1989.
1312 We'll be coming back later, so skip the finish.
1313 Modified by Michael Tiemann. */
1315 /* Compilation is now finished except for now. */
1317 parse_time
+= gettime () - start_time
;
1319 parse_time
-= integration_time
;
1320 parse_time
-= varconst_time
;
1322 goto after_finish_compilation
;
1325 globals
= getdecls ();
1327 /* Really define vars that have had only a tentative definition.
1328 Really output inline functions that must actually be callable
1329 and have not been output so far. */
1333 for (decl
= globals
; decl
; decl
= TREE_CHAIN (decl
))
1335 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
)
1336 && ! TREE_ASM_WRITTEN (decl
))
1338 /* Don't write out static consts, unless we needed
1339 to take their address for some reason. */
1340 if (! TREE_READONLY (decl
)
1341 || TREE_PUBLIC (decl
)
1342 || TREE_ADDRESSABLE (decl
)
1343 || TREE_ADDRESSABLE (DECL_NAME (decl
)))
1344 rest_of_decl_compilation (decl
, 0, 1, 1);
1345 /* Otherwise maybe mention them just for the debugger. */
1346 #ifdef DBX_DEBUGGING_INFO
1347 else if (DECL_INITIAL (decl
) && write_symbols
== DBX_DEBUG
)
1348 TIMEVAR (varconst_time
, dbxout_symbol (decl
, 0));
1350 #ifdef SDB_DEBUGGING_INFO
1351 else if (DECL_INITIAL (decl
) && write_symbols
== SDB_DEBUG
)
1352 TIMEVAR (varconst_time
, sdbout_symbol (decl
, 0));
1355 if (TREE_CODE (decl
) == FUNCTION_DECL
1356 && ! TREE_ASM_WRITTEN (decl
)
1357 && DECL_INITIAL (decl
) != 0
1358 && (TREE_ADDRESSABLE (decl
) || TREE_ADDRESSABLE (DECL_NAME (decl
)))
1359 && ! TREE_EXTERNAL (decl
))
1360 output_inline_function (decl
);
1362 /* Warn about any function or variable
1363 declared static but not defined. */
1364 if ((warn_unused
|| TREE_USED (decl
) || TREE_USED (DECL_NAME (decl
)))
1365 /* && TREE_CODE (decl) == FUNCTION_DECL */
1366 && DECL_INITIAL (decl
) == 0
1367 && TREE_EXTERNAL (decl
)
1368 && ! TREE_PUBLIC (decl
))
1369 warning_with_decl (decl
, "`%s' declared `static' but never defined");
1370 /* Warn about static fns or vars defined but not used,
1371 but not about inline functions
1372 since unused inline statics is normal practice. */
1374 && (TREE_CODE (decl
) == FUNCTION_DECL
1375 || TREE_CODE (decl
) == VAR_DECL
)
1376 && ! TREE_EXTERNAL (decl
)
1377 && ! TREE_PUBLIC (decl
)
1378 && ! TREE_USED (decl
)
1379 && ! TREE_INLINE (decl
)
1380 /* The TREE_USED bit for file-scope decls
1381 is kept in the identifier, to handle multiple
1382 external decls in different scopes. */
1383 && ! TREE_USED (DECL_NAME (decl
)))
1384 warning_with_decl (decl
, "`%s' defined but not used");
1388 /* Do dbx symbols */
1389 #ifdef DBX_DEBUGGING_INFO
1390 if (write_symbols
== DBX_DEBUG
)
1391 TIMEVAR (symout_time
,
1393 dbxout_tags (gettags ());
1394 dbxout_types (get_permanent_types ());
1398 #ifdef SDB_DEBUGGING_INFO
1399 if (write_symbols
== SDB_DEBUG
)
1400 TIMEVAR (symout_time
,
1402 sdbout_tags (gettags ());
1403 sdbout_types (get_permanent_types ());
1407 #if 0 /* This mode is discontinued */
1408 /* Do gdb symbols */
1409 if (write_symbols
== GDB_DEBUG
)
1410 TIMEVAR (symout_time
,
1412 struct stat statbuf
;
1413 fstat (fileno (finput
), &statbuf
);
1414 symout_types (get_permanent_types ());
1415 symout_top_blocks (globals
, gettags ());
1416 symout_finish (name
, statbuf
.st_ctime
);
1420 /* Output some stuff at end of file if nec. */
1422 end_final (main_input_filename
);
1425 ASM_FILE_END (asm_out_file
);
1428 after_finish_compilation
:
1430 /* Close the dump files. */
1433 fclose (rtl_dump_file
);
1436 fclose (jump_opt_dump_file
);
1439 fclose (cse_dump_file
);
1442 fclose (loop_dump_file
);
1445 fclose (flow_dump_file
);
1449 dump_combine_total_stats (combine_dump_file
);
1450 fclose (combine_dump_file
);
1454 fclose (local_reg_dump_file
);
1456 if (global_reg_dump
)
1457 fclose (global_reg_dump_file
);
1460 fclose (jump2_opt_dump_file
);
1463 fclose (dbr_sched_dump_file
);
1465 /* Close non-debugging input and output files. Take special care to note
1466 whether fclose returns an error, since the pages might still be on the
1467 buffer chain while the file is open. */
1470 if (ferror (asm_out_file
) != 0 || fclose (asm_out_file
) != 0)
1471 fatal_io_error (asm_file_name
);
1473 /* Print the times. */
1477 fprintf (stderr
,"\n");
1478 print_time ("parse", parse_time
);
1479 print_time ("integration", integration_time
);
1480 print_time ("jump", jump_time
);
1481 print_time ("cse", cse_time
);
1482 print_time ("loop", loop_time
);
1483 print_time ("flow", flow_time
);
1484 print_time ("combine", combine_time
);
1485 print_time ("local-alloc", local_alloc_time
);
1486 print_time ("global-alloc", global_alloc_time
);
1487 print_time ("shorten-branch", shorten_branch_time
);
1488 print_time ("dbranch", dbr_sched_time
);
1489 print_time ("final", final_time
);
1490 print_time ("varconst", varconst_time
);
1491 print_time ("symout", symout_time
);
1492 print_time ("dump", dump_time
);
1496 /* This is called from finish_decl (within yyparse)
1497 for each declaration of a function or variable.
1498 This does nothing for automatic variables.
1499 Otherwise, it sets up the RTL and outputs any assembler code
1500 (label definition, storage allocation and initialization).
1502 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1503 the assembler symbol name to be used. TOP_LEVEL is nonzero
1504 if this declaration is not within a function. */
1507 rest_of_decl_compilation (decl
, asmspec
, top_level
, at_end
)
1513 /* Declarations of variables, and of functions defined elsewhere. */
1515 if (TREE_STATIC (decl
) || TREE_EXTERNAL (decl
))
1516 TIMEVAR (varconst_time
,
1518 make_decl_rtl (decl
, asmspec
, top_level
);
1519 /* Don't output anything
1520 when a tentative file-scope definition is seen.
1521 But at end of compilation, do output code for them. */
1522 if (! (! at_end
&& top_level
1523 && (DECL_INITIAL (decl
) == 0
1524 || DECL_INITIAL (decl
) == error_mark_node
)))
1525 assemble_variable (decl
, top_level
, write_symbols
, at_end
);
1527 else if (TREE_REGDECL (decl
) && asmspec
!= 0)
1529 if (decode_reg_name (asmspec
) >= 0)
1531 if (TREE_CODE (decl
) == PARM_DECL
)
1532 error ("parameter cannot have special register declaration");
1535 DECL_RTL (decl
) = 0;
1536 make_decl_rtl (decl
, asmspec
, top_level
);
1540 error ("invalid register name `%s' for register variable", asmspec
);
1542 #ifdef DBX_DEBUGGING_INFO
1543 else if (write_symbols
== DBX_DEBUG
&& TREE_CODE (decl
) == TYPE_DECL
)
1544 TIMEVAR (varconst_time
, dbxout_symbol (decl
, 0));
1546 #ifdef SDB_DEBUGGING_INFO
1547 else if (write_symbols
== SDB_DEBUG
&& TREE_CODE (decl
) == TYPE_DECL
)
1548 TIMEVAR (varconst_time
, sdbout_symbol (decl
, 0));
1553 #if 0 /* This mode is discontinued */
1554 if (write_symbols
== GDB_DEBUG
)
1556 TIMEVAR (symout_time
,
1558 /* The initizations make types when they contain
1559 string constants. The types are on the temporary
1560 obstack, so output them now before they go away. */
1561 symout_types (get_temporary_types ());
1566 /* Clean out the temporary type list, since the types will go away. */
1567 get_temporary_types ();
1571 /* This is called from finish_function (within yyparse)
1572 after each top-level definition is parsed.
1573 It is supposed to compile that function or variable
1574 and output the assembler code for it.
1575 After we return, the tree storage is freed. */
1578 rest_of_compilation (decl
)
1582 int start_time
= gettime ();
1585 /* If we are reconsidering an inline function
1586 at the end of compilation, skip the stuff for making it inline. */
1588 if (DECL_SAVED_INSNS (decl
) == 0)
1590 int specd
= TREE_INLINE (decl
);
1593 if (specd
|| flag_inline_functions
)
1595 lose
= function_cannot_inline_p (decl
);
1598 if (warn_inline
&& specd
)
1599 warning_with_decl (decl
, lose
);
1600 TREE_INLINE (decl
) = 0;
1604 lose
= "compiler error";
1606 insns
= get_insns ();
1608 /* Dump the rtl code if we are dumping rtl. */
1613 fprintf (rtl_dump_file
, "\n;; Function %s\n\n",
1614 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1616 fprintf (rtl_dump_file
, ";; (integrable)\n\n");
1617 print_rtl (rtl_dump_file
, insns
);
1618 fflush (rtl_dump_file
);
1621 /* If function is inline, and we don't yet know whether to
1622 compile it by itself, defer decision till end of compilation.
1623 finish_compilation will call rest_of_compilation again
1624 for those functions that need to be output. */
1626 if (TREE_INLINE (decl
)
1627 && ((! TREE_PUBLIC (decl
) && ! TREE_ADDRESSABLE (decl
)
1628 && ! flag_keep_inline_functions
)
1629 || TREE_EXTERNAL (decl
)))
1631 save_for_outline (decl
);
1632 goto exit_rest_of_compilation
;
1635 /* If we have to compile the function now, save its rtl
1636 so that its compilation will not affect what others get. */
1637 if (TREE_INLINE (decl
))
1638 TIMEVAR (integration_time
, save_for_inline (decl
));
1641 TREE_ASM_WRITTEN (decl
) = 1;
1643 if (rtl_dump_and_exit
|| flag_syntax_only
)
1645 get_temporary_types ();
1646 goto exit_rest_of_compilation
;
1649 insns
= get_insns ();
1651 /* Copy any shared structure that should not be shared. */
1653 unshare_all_rtl (insns
);
1655 /* See if we have allocated stack slots that are not directly addressable.
1656 If so, scan all the insns and create explicit address computation
1657 for all references to such slots. */
1658 /* fixup_stack_slots (); */
1660 /* Do jump optimization the first time, if -opt.
1661 Also do it if -W, but in that case it doesn't change the rtl code,
1662 it only computes whether control can drop off the end of the function. */
1664 if (optimize
|| extra_warnings
|| warn_return_type
1665 /* If function is `volatile', we should warn if it tries to return. */
1666 || TREE_THIS_VOLATILE (decl
))
1667 TIMEVAR (jump_time
, jump_optimize (insns
, 0, 0));
1669 /* Dump rtl code after jump, if we are doing that. */
1674 fprintf (jump_opt_dump_file
, "\n;; Function %s\n\n",
1675 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1676 print_rtl (jump_opt_dump_file
, insns
);
1677 fflush (jump_opt_dump_file
);
1680 /* Perform common subexpression elimination.
1681 Nonzero value from `cse_main' means that jumps were simplified
1682 and some code may now be unreachable, so do
1683 jump optimization again. */
1688 fprintf (cse_dump_file
, "\n;; Function %s\n\n",
1689 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1694 TIMEVAR (cse_time
, reg_scan (insns
, max_reg_num (), 0));
1696 TIMEVAR (cse_time
, tem
= cse_main (insns
, max_reg_num (), cse_dump_file
));
1699 TIMEVAR (jump_time
, jump_optimize (insns
, 0, 0));
1702 /* Dump rtl code after cse, if we are doing that. */
1707 print_rtl (cse_dump_file
, insns
);
1708 fflush (cse_dump_file
);
1714 fprintf (loop_dump_file
, "\n;; Function %s\n\n",
1715 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1718 /* Move constant computations out of loops. */
1724 reg_scan (insns
, max_reg_num (), 1);
1725 loop_optimize (insns
, loop_dump
? loop_dump_file
: 0);
1729 /* Dump rtl code after loop opt, if we are doing that. */
1734 print_rtl (loop_dump_file
, insns
);
1735 fflush (loop_dump_file
);
1738 /* Now we choose between stupid (pcc-like) register allocation
1739 (if we got the -noreg switch and not -opt)
1740 and smart register allocation. */
1742 if (optimize
) /* Stupid allocation probably won't work */
1743 obey_regdecls
= 0; /* if optimizations being done. */
1747 /* Print function header into flow dump now
1748 because doing the flow analysis makes some of the dump. */
1753 fprintf (flow_dump_file
, "\n;; Function %s\n\n",
1754 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1761 regclass (insns
, max_reg_num ());
1762 stupid_life_analysis (insns
, max_reg_num (),
1768 /* Do control and data flow analysis,
1769 and write some of the results to dump file. */
1771 TIMEVAR (flow_time
, flow_analysis (insns
, max_reg_num (),
1774 uninitialized_vars_warning (DECL_INITIAL (decl
));
1777 /* Dump rtl after flow analysis. */
1782 print_rtl (flow_dump_file
, insns
);
1783 fflush (flow_dump_file
);
1786 /* If -opt, try combining insns through substitution. */
1789 TIMEVAR (combine_time
, combine_instructions (insns
, max_reg_num ()));
1791 /* Dump rtl code after insn combination. */
1796 fprintf (combine_dump_file
, "\n;; Function %s\n\n",
1797 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1798 dump_combine_stats (combine_dump_file
);
1799 print_rtl (combine_dump_file
, insns
);
1800 fflush (combine_dump_file
);
1803 /* Unless we did stupid register allocation,
1804 allocate pseudo-regs that are used only within 1 basic block. */
1807 TIMEVAR (local_alloc_time
,
1809 regclass (insns
, max_reg_num ());
1813 /* Dump rtl code after allocating regs within basic blocks. */
1818 fprintf (local_reg_dump_file
, "\n;; Function %s\n\n",
1819 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1820 dump_flow_info (local_reg_dump_file
);
1821 dump_local_alloc (local_reg_dump_file
);
1822 print_rtl (local_reg_dump_file
, insns
);
1823 fflush (local_reg_dump_file
);
1826 if (global_reg_dump
)
1828 fprintf (global_reg_dump_file
, "\n;; Function %s\n\n",
1829 IDENTIFIER_POINTER (DECL_NAME (decl
))));
1831 /* Unless we did stupid register allocation,
1832 allocate remaining pseudo-regs, then do the reload pass
1833 fixing up any insns that are invalid. */
1835 TIMEVAR (global_alloc_time
,
1838 global_alloc (global_reg_dump
? global_reg_dump_file
: 0);
1841 global_reg_dump
? global_reg_dump_file
: 0);
1844 if (global_reg_dump
)
1847 dump_global_regs (global_reg_dump_file
);
1848 print_rtl (global_reg_dump_file
, insns
);
1849 fflush (global_reg_dump_file
);
1852 rtx_equal_function_value_matters
= 1;
1853 reload_completed
= 1;
1855 /* One more attempt to remove jumps to .+1
1856 left by dead-store-elimination.
1857 Also do cross-jumping this time
1858 and delete no-op move insns. */
1862 TIMEVAR (jump_time
, jump_optimize (insns
, 1, 1));
1865 /* Dump rtl code after jump, if we are doing that. */
1870 fprintf (jump2_opt_dump_file
, "\n;; Function %s\n\n",
1871 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1872 print_rtl (jump2_opt_dump_file
, insns
);
1873 fflush (jump2_opt_dump_file
);
1876 /* If a scheduling pass for delayed branches is to be done,
1877 call the scheduling code. */
1879 #ifdef HAVE_DELAYED_BRANCH
1880 if (optimize
&& flag_delayed_branch
)
1882 TIMEVAR (dbr_sched_time
, dbr_schedule (insns
, dbr_sched_dump_file
));
1887 fprintf (dbr_sched_dump_file
, "\n;; Function %s\n\n",
1888 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1889 print_rtl (dbr_sched_dump_file
, insns
);
1890 fflush (dbr_sched_dump_file
);
1898 /* Shorten branches. */
1899 TIMEVAR (shorten_branch_time
,
1901 shorten_branches (get_insns ());
1905 /* Now turn the rtl into assembler code. */
1907 TIMEVAR (final_time
,
1909 assemble_function (decl
);
1910 final_start_function (insns
, asm_out_file
,
1911 write_symbols
, optimize
);
1912 final (insns
, asm_out_file
,
1913 write_symbols
, optimize
, 0);
1914 final_end_function (insns
, asm_out_file
,
1915 write_symbols
, optimize
);
1916 fflush (asm_out_file
);
1919 #if 0 /* This mode is discontinued */
1920 /* Write GDB symbols if requested */
1922 if (write_symbols
== GDB_DEBUG
)
1924 TIMEVAR (symout_time
,
1926 symout_types (get_permanent_types ());
1927 symout_types (get_temporary_types ());
1929 DECL_BLOCK_SYMTAB_ADDRESS (decl
)
1930 = symout_function (DECL_INITIAL (decl
),
1931 DECL_ARGUMENTS (decl
), 0);
1932 symout_function_end ();
1937 get_temporary_types ();
1939 /* Write DBX symbols if requested */
1941 #ifdef DBX_DEBUGGING_INFO
1942 if (write_symbols
== DBX_DEBUG
)
1943 TIMEVAR (symout_time
, dbxout_function (decl
));
1946 exit_rest_of_compilation
:
1948 rtx_equal_function_value_matters
= 0;
1949 reload_completed
= 0;
1951 /* Clear out the real_constant_chain before some of the rtx's
1952 it runs through become garbage. */
1954 clear_const_double_mem ();
1956 /* The parsing time is all the time spent in yyparse
1957 *except* what is spent in this function. */
1959 parse_time
-= gettime () - start_time
;
1964 #include <sys/mman.h>
1965 /* Hacky routine to read back entire data segment saved earlier.
1966 Michael Tiemann (tiemann@cygnus.com). */
1968 void undump_data (path
, name
)
1971 extern char *rindex ();
1974 extern int my_edata
;
1977 if ((file
= open (name
, O_RDONLY
)) == -1)
1981 p
= rindex (buf
, '/');
1985 file
= open (buf
, O_RDONLY
);
1994 file_size
= lseek (file
, 0L, SEEK_END
);
1995 brk ((char*)(&my_edata
) + file_size
);
1997 data
= (char *)((int)&my_edata
&~(getpagesize()-1));
1998 if ((int)mmap (data
, file_size
, PROT_READ
|PROT_WRITE
,
1999 MAP_PRIVATE
|MAP_FIXED
, file
, 0) < 0)
2006 /* Hacky routine to read back entire data segment saved earlier.
2007 Bryan Boreham (bryan@kewill.uucp) */
2009 void undump_data (path
, name
)
2014 extern int my_edata
;
2015 char buf
[256] = "/usr/local/lib/";
2019 if ((file
= open(name
, O_RDONLY
)) == -1)
2020 if ((file
= open(buf
, O_RDONLY
)) == -1)
2025 file_size
= lseek(file
, 0L, SEEK_END
);
2026 lseek(file
, 0L, SEEK_SET
);
2027 brk((char*)((int)&my_edata
&~(getpagesize()-1)) + file_size
);
2028 if (read (file
, &my_edata
, file_size
) != file_size
)
2032 #endif /* HAVE_UNDUMP */
2034 /* Entry point of c++. Decode command args, then call compile_file.
2035 Exit code is 35 if can't open files, 34 if fatal error,
2036 33 if had nonfatal errors, else success. */
2039 main (argc
, argv
, envp
)
2046 int print_mem_flag
= 0;
2049 /* save in case md file wants to emit args as a comment. */
2053 p
= argv
[0] + strlen (argv
[0]);
2054 while (p
!= argv
[0] && p
[-1] != '/') --p
;
2057 /* Change by Bryan Boreham, Kewill, Sun Aug 6 13:42:47 1989.
2058 Stuff for unexec'ing */
2059 dump_source_name
= argv
[0];
2060 asm_file_name
= (char*) 0;
2063 /* Get rid of any avoidable limit on stack size. */
2067 /* Set the stack limit huge so that alloca does not fail. */
2068 getrlimit (RLIMIT_STACK
, &rlim
);
2069 rlim
.rlim_cur
= rlim
.rlim_max
;
2070 setrlimit (RLIMIT_STACK
, &rlim
);
2072 #endif /* RLIMIT_STACK */
2074 signal (SIGFPE
, float_signal
);
2076 signal (SIGPIPE
, pipe_closed
);
2078 decl_printable_name
= decl_name
;
2079 lang_expand_expr
= fancy_abort
;
2081 /* Initialize whether `char' is signed. */
2082 flag_signed_char
= DEFAULT_SIGNED_CHAR
;
2083 #ifdef DEFAULT_SHORT_ENUMS
2084 /* Initialize how much space enums occupy, by default. */
2085 flag_short_enums
= DEFAULT_SHORT_ENUMS
;
2088 /* This is zeroed by -O. */
2091 /* Initialize register usage now so switches may override. */
2095 set_target_switch ("");
2097 for (i
= 1; i
< argc
; i
++)
2099 if (argv
[i
][0] == '-' && argv
[i
][1] != 0)
2101 register char *str
= argv
[i
] + 1;
2106 set_target_switch (&str
[1]);
2107 else if (!strcmp (str
, "dumpbase"))
2109 dump_base_name
= argv
[++i
];
2111 else if (str
[0] == 'd')
2113 register char *p
= &str
[1];
2127 global_reg_dump
= 1;
2154 rtl_dump_and_exit
= 1;
2158 else if (str
[0] == 'f')
2161 register char *p
= &str
[1];
2164 /* Some kind of -f option.
2165 P's value is the option sans `-f'.
2166 Search for it in the table of options. */
2169 !found
&& j
< sizeof (f_options
) / sizeof (f_options
[0]);
2172 if (!strcmp (p
, f_options
[j
].string
))
2174 *f_options
[j
].variable
= f_options
[j
].on_value
;
2175 /* A goto here would be cleaner,
2176 but breaks the vax pcc. */
2179 if (p
[0] == 'n' && p
[1] == 'o' && p
[2] == '-'
2180 && ! strcmp (p
+3, f_options
[j
].string
))
2182 *f_options
[j
].variable
= ! f_options
[j
].on_value
;
2190 else if (!strncmp (p
, "undump-", 7))
2191 undump_data (argv
[0], &p
[7]);
2193 else if (!strncmp (p
, "fixed-", 6))
2194 fix_register (&p
[6], 1, 1);
2195 else if (!strncmp (p
, "call-used-", 10))
2196 fix_register (&p
[10], 0, 1);
2197 else if (!strncmp (p
, "call-saved-", 11))
2198 fix_register (&p
[11], 0, 0);
2199 else if (! lang_decode_option (argv
[i
]))
2200 error ("Invalid option `%s'", argv
[i
]);
2202 else if (!strcmp (str
, "noreg"))
2204 else if (!strcmp (str
, "opt"))
2205 optimize
= 1, obey_regdecls
= 0;
2206 else if (!strcmp (str
, "O"))
2207 optimize
= 1, obey_regdecls
= 0;
2208 else if (!strcmp (str
, "pedantic"))
2210 else if (lang_decode_option (argv
[i
]))
2212 else if (!strcmp (str
, "quiet"))
2214 else if (!strcmp (str
, "version"))
2216 extern char *version_string
, *language_string
;
2217 fprintf (stderr
, "%s version %s", language_string
, version_string
);
2218 #ifdef TARGET_VERSION
2223 #define __VERSION__ "[unknown]"
2225 fprintf (stderr
, " compiled by GNU C version %s.\n", __VERSION__
);
2227 fprintf (stderr
, " compiled by CC.\n");
2229 print_target_switch_defaults ();
2231 else if (!strcmp (str
, "w"))
2232 inhibit_warnings
= 1;
2233 else if (!strcmp (str
, "W"))
2235 else if (!strcmp (str
, "Wunused"))
2237 else if (!strcmp (str
, "Wshadow"))
2239 else if (!strcmp (str
, "Wswitch"))
2241 else if (!strcmp (str
, "Wconversion"))
2242 warn_conversion
= 1;
2243 else if (!strncmp (str
, "Wid-clash-", 10))
2245 char *endp
= str
+ 10;
2249 if (*endp
>= '0' && *endp
<= '9')
2252 error ("Invalid option `%s'", argv
[i
]);
2255 id_clash_len
= atoi (str
+ 10);
2257 else if (!strcmp (str
, "Winline"))
2259 else if (!strcmp (str
, "p"))
2261 else if (!strcmp (str
, "a"))
2263 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
2264 warning ("`-a' option (basic block profile) not supported");
2266 profile_block_flag
= 1;
2270 else if (!strcmp (str
, "gg"))
2271 write_symbols
= GDB_DEBUG
;
2273 #ifdef DBX_DEBUGGING_INFO
2274 else if (!strcmp (str
, "g0"))
2275 write_symbols
= DBX_DEBUG
;
2276 else if (!strcmp (str
, "G0"))
2277 write_symbols
= DBX_DEBUG
;
2278 #ifdef SDB_DEBUGGING_INFO
2279 else if (!strcmp (str
, "gsdb"))
2280 write_symbols
= SDB_DEBUG
;
2282 else if (!strcmp (str
, "g"))
2284 write_symbols
= DBX_DEBUG
;
2285 use_gdb_dbx_extensions
= 1;
2287 else if (!strcmp (str
, "G"))
2289 write_symbols
= DBX_DEBUG
;
2290 use_gdb_dbx_extensions
= 1;
2292 #endif /* DBX_DEBUGGING_INFO */
2293 #ifdef SDB_DEBUGGING_INFO
2294 else if (!strcmp (str
, "g"))
2295 write_symbols
= SDB_DEBUG
;
2296 else if (!strcmp (str
, "G"))
2297 write_symbols
= SDB_DEBUG
;
2298 else if (!strcmp (str
, "g0"))
2299 write_symbols
= SDB_DEBUG
;
2300 else if (!strcmp (str
, "G0"))
2301 write_symbols
= SDB_DEBUG
;
2302 else if (!strcmp (str
, "gsdb"))
2303 write_symbols
= SDB_DEBUG
;
2304 #endif /* SDB_DEBUGGING_INFO */
2305 #if defined(ASM_OUTPUT_SOURCE_FILENAME) && defined(ASM_OUTPUT_SOURCE_LINE)
2306 else if (!strcmp (str
, "gline"))
2307 write_symbols
= LINENO_DEBUG
;
2310 else if (!strcmp (str
, "symout"))
2312 if (write_symbols
== NO_DEBUG
)
2313 write_symbols
= GDB_DEBUG
;
2314 sym_file_name
= argv
[++i
];
2317 else if (!strcmp (str
, "o"))
2319 asm_file_name
= argv
[++i
];
2322 else if (!strcmp(str
,"xref"))
2326 error ("Invalid option `%s'", argv
[i
]);
2328 else if (argv
[i
][0] == '+')
2330 if (lang_decode_option (argv
[i
]))
2333 error ("Invalid option `%s'", argv
[i
]);
2338 #ifdef OVERRIDE_OPTIONS
2339 /* Some machines may reject certain combinations of options. */
2343 /* Now that register usage is specified, convert it to HARD_REG_SETs. */
2346 compile_file (filename
);
2352 extern char **environ
;
2353 char *lim
= (char *) sbrk (0);
2355 fprintf (stderr
, "Data size %d.\n",
2356 (int) lim
- (int) &environ
);
2361 #endif /* not VMS */
2362 #endif /* not USG */
2365 FIELD_xref_end(errorcount
+sorrycount
);
2369 exit (FATAL_EXIT_CODE
);
2371 exit (FATAL_EXIT_CODE
);
2372 exit (SUCCESS_EXIT_CODE
);
2376 /* Decode -m switches. */
2378 /* Here is a table, controlled by the tm-...h file, listing each -m switch
2379 and which bits in `target_switches' it should set or clear.
2380 If VALUE is positive, it is bits to set.
2381 If VALUE is negative, -VALUE is bits to clear.
2382 (The sign bit is not used so there is no confusion.) */
2384 struct {char *name
; int value
;} target_switches
[]
2387 /* Decode the switch -mNAME. */
2390 set_target_switch (name
)
2396 for (j
= 0; j
< sizeof target_switches
/ sizeof target_switches
[0]; j
++)
2397 if (!strcmp (target_switches
[j
].name
, name
))
2399 if (target_switches
[j
].value
< 0)
2400 target_flags
&= ~-target_switches
[j
].value
;
2402 target_flags
|= target_switches
[j
].value
;
2407 error ("Invalid option `%s'", name
);
2410 /* Print default target switches for -version. */
2413 print_target_switch_defaults ()
2416 register int mask
= TARGET_DEFAULT
;
2418 fprintf (stderr
, "default target switches:");
2419 for (j
= 0; j
< sizeof target_switches
/ sizeof target_switches
[0]; j
++)
2420 if (target_switches
[j
].name
[0] != '\0'
2421 && target_switches
[j
].value
> 0
2422 && (target_switches
[j
].value
& mask
) == target_switches
[j
].value
)
2423 fprintf (stderr
, " -m%s", target_switches
[j
].name
);
2425 fprintf (stderr
, "\n");