No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / usr.bin / g++ / cc1plus / toplev.c
blob6e854437daf78381c8a6e9fa7372a08fe14ebd6f
1 /*-
2 * This code is derived from software copyrighted by the Free Software
3 * Foundation.
5 * Modified 1991 by Donn Seeley at UUNET Technologies, Inc.
6 */
8 #ifndef lint
9 static char sccsid[] = "@(#)toplev.c 6.3 (Berkeley) 5/8/91";
10 #endif /* not lint */
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)
20 any later version.
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. */
37 #include "config.h"
38 #include <stdio.h>
39 #include <signal.h>
40 #include <setjmp.h>
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #include <sys/file.h>
46 #ifdef NO_UNISTD_H
47 #define SEEK_SET L_SET
48 #define SEEK_CUR L_INCR
49 #define SEEK_END L_XTND
50 #else
51 #include <unistd.h>
52 #endif
54 #ifdef USG
55 #include <sys/fcntl.h>
56 #undef FLOAT
57 #include <sys/param.h>
58 /* This is for hpux. It is a real screw. They should change hpux. */
59 #undef FLOAT
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. */
63 #else
64 #ifndef VMS
65 #include <sys/time.h>
66 #include <sys/resource.h>
67 #endif
68 #endif
70 #include "input.h"
71 #include "tree.h"
72 #include "c-tree.h"
73 #include "rtl.h"
74 #include "flags.h"
76 #ifndef _bufsiz
77 #define _bufsiz(p) ((p)->_bufsiz)
78 #endif
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. */
90 extern int yydebug;
92 extern FILE *finput;
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 ();
108 void error ();
109 void error_with_file_and_line ();
110 void fancy_abort ();
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. */
119 int target_flags;
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. */
134 int lineno;
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. */
153 int rtl_dump = 0;
154 int rtl_dump_and_exit = 0;
155 int jump_opt_dump = 0;
156 int cse_dump = 0;
157 int loop_dump = 0;
158 int flow_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. */
177 int optimize = 0;
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;
193 #else
194 int flag_caller_saves = 0;
195 #endif
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. */
258 int flag_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. */
272 int quiet_flag = 0;
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. */
284 int warn_unused;
286 /* Nonzero means warn about all declarations which shadow others. */
288 int warn_shadow;
290 /* Warn if a switch on an enum fails to have a case for every enum value. */
292 int warn_switch;
294 /* Warn if a type conversion is done that might have confusing results. */
296 int warn_conversion;
298 /* Nonzero means warn about any identifiers that match in the first N
299 characters. The value N is in `id_clash_len'. */
301 int warn_id_clash;
302 int id_clash_len;
304 /* Nonzero means warn if inline function is too large. */
306 int warn_inline;
308 /* Number of error messages and warning messages so far. */
310 int errorcount = 0;
311 int warningcount = 0;
312 int sorrycount = 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. */
324 char *progname;
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. */
337 int pedantic = 0;
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
346 purposes. */
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. */
359 int save_argc;
360 char **save_argv;
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. */
368 char *asm_file_name;
370 #if 0
371 /* Name for output file of GDB symbol segment, specified with -symout. */
373 char *sym_file_name;
374 #endif /* 0 */
376 #ifdef G_SWITCH
377 /* Value of the -G nn switch if the machine needs it. */
379 int g_switch_value = 0;
380 int g_switch_used = 0;
381 #endif
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. */
416 FILE *asm_out_file;
417 FILE *rtl_dump_file;
418 FILE *jump_opt_dump_file;
419 FILE *cse_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. */
430 int parse_time;
431 int varconst_time;
432 int integration_time;
433 int jump_time;
434 int cse_time;
435 int loop_time;
436 int flow_time;
437 int combine_time;
438 int local_alloc_time;
439 int global_alloc_time;
440 int dbr_sched_time;
441 int shorten_branch_time;
442 int final_time;
443 int symout_time;
444 int dump_time;
446 #ifdef FIELD_XREF
447 int field_xref = 0; /* cross referencing flag */
448 #endif
450 /* Return time used so far, in microseconds. */
453 gettime ()
455 #ifdef USG
456 struct tms tms;
457 #else
458 #ifndef VMS
459 struct rusage rusage;
460 #else /* VMS */
461 struct
463 int proc_user_time;
464 int proc_system_time;
465 int child_user_time;
466 int child_system_time;
467 } vms_times;
468 #endif
469 #endif
471 if (quiet_flag)
472 return 0;
474 #ifdef USG
475 times (&tms);
476 return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
477 #else
478 #ifndef VMS
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);
482 #else /* VMS */
483 times (&vms_times);
484 return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
485 #endif
486 #endif
489 #define TIMEVAR(VAR, BODY) \
490 do { int otime = gettime (); BODY; VAR += gettime () - otime; } while (0)
492 void
493 print_time (str, total)
494 char *str;
495 int total;
497 fprintf (stderr,
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)
506 int warningp;
508 if (warningp && inhibit_warnings)
509 return 0;
511 if (warningp)
512 warningcount++;
513 else
514 errorcount++;
516 return 1;
519 /* Print a fatal error message. NAME is the text.
520 Also include a system error message based on `errno'. */
522 void
523 pfatal_with_name (name)
524 char *name;
526 fprintf (stderr, "%s: ", progname);
527 perror (name);
528 exit (35);
531 void
532 fatal_io_error (name)
533 char *name;
535 fprintf (stderr, "%s: %s: I/O error\n", progname, name);
536 exit (35);
539 void
540 fatal (s, v)
541 char *s;
542 int v;
544 error (s, v);
545 exit (34);
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(). */
552 void
553 fatal_insn_not_found (insn)
554 rtx insn;
556 error ("The following insn was not recognizable:", 0);
557 debug_rtx (insn);
558 abort ();
561 /* This is the default decl_printable_name function. */
563 static char *
564 decl_name (decl)
565 tree decl;
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. */
583 void
584 announce_function (decl)
585 tree decl;
587 if (! quiet_flag)
589 if (rtl_dump_and_exit)
590 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
591 else
592 fprintf (stderr, " %s", (*decl_printable_name) (decl));
593 fflush (stderr);
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. */
602 void
603 report_error_function (file)
604 char *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)
616 if (file)
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));
624 else
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);
637 if (p->next)
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'. */
648 void
649 error (s, v, v2)
650 char *s;
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'. */
660 void
661 error_with_file_and_line (file, line, s, v, v2)
662 char *file;
663 int line;
664 char *s;
665 int v;
666 int v2;
668 count_error (0);
670 report_error_function (file);
672 if (file)
673 fprintf (stderr, "%s:%d: ", file, line);
674 else
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. */
683 void
684 error_with_decl (decl, s, v)
685 tree decl;
686 char *s;
687 int v;
689 count_error (0);
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)));
697 else
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);
703 else
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. */
713 void
714 error_for_asm (insn, s, v, v2)
715 rtx insn;
716 char *s;
717 int v; /* @@also used as pointer */
718 int v2; /* @@also used as pointer */
720 char *filename;
721 int line;
722 rtx body = PATTERN (insn);
723 rtx asmop;
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)
729 asmop = body;
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'. */
746 void
747 warning_with_file_and_line (file, line, s, v, v2)
748 char *file;
749 int line;
750 char *s;
751 int v;
752 int v2;
754 if (count_error (1) == 0)
755 return;
757 report_error_function (file);
759 if (file)
760 fprintf (stderr, "%s:%d: ", file, line);
761 else
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'. */
772 void
773 warning (s, v, v2)
774 char *s;
775 int v; /* @@also used as pointer */
776 int v2;
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. */
785 void
786 warning_with_decl (decl, s, v)
787 tree decl;
788 char *s;
789 int v;
791 if (count_error (1) == 0)
792 return;
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)));
800 else
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);
807 else
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'. */
815 void
816 sorry (s, v, v2)
817 char *s;
818 int v, v2;
820 sorrycount++;
821 if (input_filename)
822 fprintf (stderr, "%s:%d: ", input_filename, lineno);
823 else
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'. */
834 void
835 really_sorry (s, v, v2)
836 char *s;
837 int v, v2;
839 if (input_filename)
840 fprintf (stderr, "%s:%d: ", input_filename, lineno);
841 else
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. */
852 void
853 fancy_abort ()
855 fatal ("Internal gcc abort.");
858 /* When `malloc.c' is compiled with `rcheck' defined,
859 it calls this function to report clobberage. */
861 void
862 botch (s)
864 abort ();
867 /* Same as `malloc' but report error if no memory available. */
870 xmalloc (size)
871 unsigned size;
873 register int value = (int) malloc (size);
874 if (value == 0)
875 fatal ("Virtual memory exhausted.");
876 return value;
879 /* Same as `realloc' but report error if no memory available. */
882 xrealloc (ptr, size)
883 char *ptr;
884 int size;
886 int result = realloc (ptr, size);
887 if (!result)
888 fatal ("Virtual memory exhausted.");
889 return result;
892 /* Return the logarithm of X, base 2, considering X unsigned,
893 if X is a power of 2. Otherwise, returns -1. */
896 exact_log2 (x)
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))
902 return -1;
903 while ((x >>= 1) != 0)
904 log++;
905 return log;
908 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
909 If X is 0, return -1. */
912 floor_log2 (x)
913 register unsigned int x;
915 register int log = -1;
916 while (x != 0)
917 log++,
918 x >>= 1;
919 return log;
922 int float_handled;
923 jmp_buf float_handler;
924 jmp_buf toplevel;
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. */
929 void
930 set_float_handler (handler)
931 jmp_buf handler;
933 float_handled = (handler != 0);
934 if (handler)
935 bcopy (handler, float_handler, sizeof (float_handler));
938 /* Signals actually come here. */
940 static void
941 float_signal ()
943 if (float_handled == 0)
944 abort ();
945 float_handled = 0;
946 longjmp (float_handler, 1);
949 /* Handler for SIGPIPE. */
951 static void
952 pipe_closed ()
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. */
960 static void
961 compile_file (name)
962 char *name;
964 tree globals;
965 int start_time;
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);
974 parse_time = 0;
975 varconst_time = 0;
976 integration_time = 0;
977 jump_time = 0;
978 cse_time = 0;
979 loop_time = 0;
980 flow_time = 0;
981 combine_time = 0;
982 local_alloc_time = 0;
983 global_alloc_time = 0;
984 dbr_sched_time = 0;
985 shorten_branch_time = 0;
986 final_time = 0;
987 symout_time = 0;
988 dump_time = 0;
990 /* Open input file. */
992 if (name == 0 || !strcmp (name, "-"))
994 finput = stdin;
995 name = "stdin";
997 else
998 finput = fopen (name, "r");
999 if (finput == 0)
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)
1007 init_tree ();
1008 init_lex ();
1009 init_rtl ();
1010 init_emit_once ();
1011 init_decl_processing ();
1012 init_optabs ();
1013 init_stmt ();
1015 else
1017 extern void reinit_lex_for_unexec ();
1018 main_input_filename = 0;
1019 reinit_lex_for_unexec ();
1020 reinit_search_statistics ();
1023 #ifdef FIELD_XREF
1024 if (field_xref) FIELD_xref_begin(input_filename);
1025 #endif
1027 /* If rtl dump desired, open the output file. */
1028 if (rtl_dump)
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. */
1039 if (jump_opt_dump)
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. */
1050 if (cse_dump)
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. */
1061 if (loop_dump)
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. */
1072 if (flow_dump)
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. */
1083 if (combine_dump)
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. */
1094 if (local_reg_dump)
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. */
1116 if (jump2_opt_dump)
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. */
1127 if (dbr_sched_dump)
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;
1141 else
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;
1160 else
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. */
1179 input_file_stack
1180 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
1181 input_file_stack->next = 0;
1182 input_file_stack->name = input_filename;
1184 #ifdef HAVE_UNDUMP
1185 if (!been_here_before)
1187 #endif
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");
1193 #else
1194 ASM_IDENTIFY_GCC (asm_out_file);
1195 #endif
1197 #ifdef HAVE_UNDUMP
1199 else
1201 /* Copy what we output during the first run into this asm file. */
1202 FILE *prev_file;
1203 int c;
1204 prev_file = fopen (previous_asm_file_name, "r");
1205 if (prev_file == 0)
1206 pfatal_with_name (previous_asm_file_name);
1207 #ifndef VMS
1208 #ifndef MASSCOMP
1209 if (_bufsiz(asm_out_file) != _bufsiz(prev_file))
1210 #endif
1211 #endif
1213 while ((c = getc (prev_file)) != EOF)
1214 putc (c, asm_out_file);
1216 #ifndef VMS
1217 #ifndef MASSCOMP
1218 else
1220 /* Copy quickly. */
1221 int dummy, size;
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));
1235 #endif
1236 #endif
1237 fclose (prev_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);
1259 #endif /* 0 */
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);
1268 else
1270 extern void re_init_dbxout_for_unexec ();
1271 re_init_dbxout_for_unexec (asm_out_file, main_input_filename);
1274 #endif
1275 #ifdef SDB_DEBUGGING_INFO
1276 if (write_symbols == SDB_DEBUG)
1277 sdbout_init (asm_out_file, main_input_filename);
1278 #endif
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)");
1297 errorcount = 1;
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;
1309 else
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. */
1332 tree decl;
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));
1349 #endif
1350 #ifdef SDB_DEBUGGING_INFO
1351 else if (DECL_INITIAL (decl) && write_symbols == SDB_DEBUG)
1352 TIMEVAR (varconst_time, sdbout_symbol (decl, 0));
1353 #endif
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. */
1373 if (warn_unused
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 ());
1396 #endif
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 ());
1405 #endif
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);
1418 #endif /* 0 */
1420 /* Output some stuff at end of file if nec. */
1422 end_final (main_input_filename);
1424 #ifdef ASM_FILE_END
1425 ASM_FILE_END (asm_out_file);
1426 #endif
1428 after_finish_compilation:
1430 /* Close the dump files. */
1432 if (rtl_dump)
1433 fclose (rtl_dump_file);
1435 if (jump_opt_dump)
1436 fclose (jump_opt_dump_file);
1438 if (cse_dump)
1439 fclose (cse_dump_file);
1441 if (loop_dump)
1442 fclose (loop_dump_file);
1444 if (flow_dump)
1445 fclose (flow_dump_file);
1447 if (combine_dump)
1449 dump_combine_total_stats (combine_dump_file);
1450 fclose (combine_dump_file);
1453 if (local_reg_dump)
1454 fclose (local_reg_dump_file);
1456 if (global_reg_dump)
1457 fclose (global_reg_dump_file);
1459 if (jump2_opt_dump)
1460 fclose (jump2_opt_dump_file);
1462 if (dbr_sched_dump)
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. */
1469 fclose (finput);
1470 if (ferror (asm_out_file) != 0 || fclose (asm_out_file) != 0)
1471 fatal_io_error (asm_file_name);
1473 /* Print the times. */
1475 if (! quiet_flag)
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. */
1506 void
1507 rest_of_decl_compilation (decl, asmspec, top_level, at_end)
1508 tree decl;
1509 char *asmspec;
1510 int top_level;
1511 int 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");
1533 else
1535 DECL_RTL (decl) = 0;
1536 make_decl_rtl (decl, asmspec, top_level);
1539 else
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));
1545 #endif
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));
1549 #endif
1551 if (top_level)
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 ());
1564 else
1565 #endif /* 0 */
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. */
1577 void
1578 rest_of_compilation (decl)
1579 tree decl;
1581 register rtx insns;
1582 int start_time = gettime ();
1583 int tem;
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);
1591 char *lose;
1593 if (specd || flag_inline_functions)
1595 lose = function_cannot_inline_p (decl);
1596 if (lose)
1598 if (warn_inline && specd)
1599 warning_with_decl (decl, lose);
1600 TREE_INLINE (decl) = 0;
1603 else
1604 lose = "compiler error";
1606 insns = get_insns ();
1608 /* Dump the rtl code if we are dumping rtl. */
1610 if (rtl_dump)
1611 TIMEVAR (dump_time,
1613 fprintf (rtl_dump_file, "\n;; Function %s\n\n",
1614 IDENTIFIER_POINTER (DECL_NAME (decl)));
1615 if (lose == 0)
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. */
1671 if (jump_opt_dump)
1672 TIMEVAR (dump_time,
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. */
1685 if (cse_dump)
1686 TIMEVAR (dump_time,
1688 fprintf (cse_dump_file, "\n;; Function %s\n\n",
1689 IDENTIFIER_POINTER (DECL_NAME (decl)));
1692 if (optimize)
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));
1698 if (tem)
1699 TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
1702 /* Dump rtl code after cse, if we are doing that. */
1704 if (cse_dump)
1705 TIMEVAR (dump_time,
1707 print_rtl (cse_dump_file, insns);
1708 fflush (cse_dump_file);
1711 if (loop_dump)
1712 TIMEVAR (dump_time,
1714 fprintf (loop_dump_file, "\n;; Function %s\n\n",
1715 IDENTIFIER_POINTER (DECL_NAME (decl)));
1718 /* Move constant computations out of loops. */
1720 if (optimize)
1722 TIMEVAR (loop_time,
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. */
1731 if (loop_dump)
1732 TIMEVAR (dump_time,
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. */
1745 regclass_init ();
1747 /* Print function header into flow dump now
1748 because doing the flow analysis makes some of the dump. */
1750 if (flow_dump)
1751 TIMEVAR (dump_time,
1753 fprintf (flow_dump_file, "\n;; Function %s\n\n",
1754 IDENTIFIER_POINTER (DECL_NAME (decl)));
1757 if (obey_regdecls)
1759 TIMEVAR (flow_time,
1761 regclass (insns, max_reg_num ());
1762 stupid_life_analysis (insns, max_reg_num (),
1763 flow_dump_file);
1766 else
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 (),
1772 flow_dump_file));
1773 if (extra_warnings)
1774 uninitialized_vars_warning (DECL_INITIAL (decl));
1777 /* Dump rtl after flow analysis. */
1779 if (flow_dump)
1780 TIMEVAR (dump_time,
1782 print_rtl (flow_dump_file, insns);
1783 fflush (flow_dump_file);
1786 /* If -opt, try combining insns through substitution. */
1788 if (optimize)
1789 TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
1791 /* Dump rtl code after insn combination. */
1793 if (combine_dump)
1794 TIMEVAR (dump_time,
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. */
1806 if (!obey_regdecls)
1807 TIMEVAR (local_alloc_time,
1809 regclass (insns, max_reg_num ());
1810 local_alloc ();
1813 /* Dump rtl code after allocating regs within basic blocks. */
1815 if (local_reg_dump)
1816 TIMEVAR (dump_time,
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)
1827 TIMEVAR (dump_time,
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,
1837 if (!obey_regdecls)
1838 global_alloc (global_reg_dump ? global_reg_dump_file : 0);
1839 else
1840 reload (insns, 0,
1841 global_reg_dump ? global_reg_dump_file : 0);
1844 if (global_reg_dump)
1845 TIMEVAR (dump_time,
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. */
1860 if (optimize)
1862 TIMEVAR (jump_time, jump_optimize (insns, 1, 1));
1865 /* Dump rtl code after jump, if we are doing that. */
1867 if (jump2_opt_dump)
1868 TIMEVAR (dump_time,
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));
1883 if (dbr_sched_dump)
1885 TIMEVAR (dump_time,
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);
1894 #endif
1896 #if 0
1897 if (optimize)
1898 /* Shorten branches. */
1899 TIMEVAR (shorten_branch_time,
1901 shorten_branches (get_insns ());
1903 #endif
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 ();
1935 else
1936 #endif /* 0 */
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));
1944 #endif
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;
1962 #ifdef HAVE_UNDUMP
1963 #ifdef sun
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)
1969 char *path, *name;
1971 extern char *rindex ();
1972 int file;
1973 long file_size;
1974 extern int my_edata;
1975 char *data;
1977 if ((file = open (name, O_RDONLY)) == -1)
1979 char buf[256], *p;
1980 strcpy (buf, path);
1981 p = rindex (buf, '/');
1982 if (p)
1984 strcpy (p+1, name);
1985 file = open (buf, O_RDONLY);
1988 if (file == -1)
1990 perror(name);
1991 exit (-1);
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)
2001 perror (name);
2002 exit (-1);
2005 #else
2006 /* Hacky routine to read back entire data segment saved earlier.
2007 Bryan Boreham (bryan@kewill.uucp) */
2009 void undump_data (path, name)
2010 char *name;
2012 int file;
2013 long file_size;
2014 extern int my_edata;
2015 char buf[256] = "/usr/local/lib/";
2017 strcat (buf, name);
2019 if ((file = open(name, O_RDONLY)) == -1)
2020 if ((file = open(buf, O_RDONLY)) == -1)
2022 perror(name);
2023 return;
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)
2029 perror(name);
2031 #endif
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)
2040 int argc;
2041 char **argv;
2042 char **envp;
2044 register int i;
2045 char *filename = 0;
2046 int print_mem_flag = 0;
2047 char *p;
2049 /* save in case md file wants to emit args as a comment. */
2050 save_argc = argc;
2051 save_argv = argv;
2053 p = argv[0] + strlen (argv[0]);
2054 while (p != argv[0] && p[-1] != '/') --p;
2055 progname = 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;
2062 #ifdef RLIMIT_STACK
2063 /* Get rid of any avoidable limit on stack size. */
2065 struct rlimit rlim;
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;
2086 #endif
2088 /* This is zeroed by -O. */
2089 obey_regdecls = 1;
2091 /* Initialize register usage now so switches may override. */
2092 init_reg_sets ();
2094 target_flags = 0;
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;
2102 if (str[0] == 'Y')
2103 str++;
2105 if (str[0] == 'm')
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];
2114 while (*p)
2115 switch (*p++)
2117 case 'c':
2118 combine_dump = 1;
2119 break;
2120 case 'd':
2121 dbr_sched_dump = 1;
2122 break;
2123 case 'f':
2124 flow_dump = 1;
2125 break;
2126 case 'g':
2127 global_reg_dump = 1;
2128 break;
2129 case 'j':
2130 jump_opt_dump = 1;
2131 break;
2132 case 'J':
2133 jump2_opt_dump = 1;
2134 break;
2135 case 'l':
2136 local_reg_dump = 1;
2137 break;
2138 case 'L':
2139 loop_dump = 1;
2140 break;
2141 case 'm':
2142 print_mem_flag = 1;
2143 break;
2144 case 'r':
2145 rtl_dump = 1;
2146 break;
2147 case 's':
2148 cse_dump = 1;
2149 break;
2150 case 'y':
2151 yydebug = 1;
2152 break;
2153 case 'x':
2154 rtl_dump_and_exit = 1;
2155 break;
2158 else if (str[0] == 'f')
2160 int j;
2161 register char *p = &str[1];
2162 int found = 0;
2164 /* Some kind of -f option.
2165 P's value is the option sans `-f'.
2166 Search for it in the table of options. */
2168 for (j = 0;
2169 !found && j < sizeof (f_options) / sizeof (f_options[0]);
2170 j++)
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. */
2177 found = 1;
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;
2183 found = 1;
2187 if (found)
2189 #ifdef HAVE_UNDUMP
2190 else if (!strncmp (p, "undump-", 7))
2191 undump_data (argv[0], &p[7]);
2192 #endif
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"))
2209 pedantic = 1;
2210 else if (lang_decode_option (argv[i]))
2212 else if (!strcmp (str, "quiet"))
2213 quiet_flag = 1;
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
2219 TARGET_VERSION;
2220 #endif
2221 #ifdef __GNUC__
2222 #ifndef __VERSION__
2223 #define __VERSION__ "[unknown]"
2224 #endif
2225 fprintf (stderr, " compiled by GNU C version %s.\n", __VERSION__);
2226 #else
2227 fprintf (stderr, " compiled by CC.\n");
2228 #endif
2229 print_target_switch_defaults ();
2231 else if (!strcmp (str, "w"))
2232 inhibit_warnings = 1;
2233 else if (!strcmp (str, "W"))
2234 extra_warnings = 1;
2235 else if (!strcmp (str, "Wunused"))
2236 warn_unused = 1;
2237 else if (!strcmp (str, "Wshadow"))
2238 warn_shadow = 1;
2239 else if (!strcmp (str, "Wswitch"))
2240 warn_switch = 1;
2241 else if (!strcmp (str, "Wconversion"))
2242 warn_conversion = 1;
2243 else if (!strncmp (str, "Wid-clash-", 10))
2245 char *endp = str + 10;
2247 while (*endp)
2249 if (*endp >= '0' && *endp <= '9')
2250 endp++;
2251 else
2252 error ("Invalid option `%s'", argv[i]);
2254 warn_id_clash = 1;
2255 id_clash_len = atoi (str + 10);
2257 else if (!strcmp (str, "Winline"))
2258 warn_inline = 1;
2259 else if (!strcmp (str, "p"))
2260 profile_flag = 1;
2261 else if (!strcmp (str, "a"))
2263 #if !defined (BLOCK_PROFILER) || !defined (FUNCTION_BLOCK_PROFILER)
2264 warning ("`-a' option (basic block profile) not supported");
2265 #else
2266 profile_block_flag = 1;
2267 #endif
2269 #ifdef 0
2270 else if (!strcmp (str, "gg"))
2271 write_symbols = GDB_DEBUG;
2272 #endif
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;
2281 #endif
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;
2308 #endif
2309 #if 0
2310 else if (!strcmp (str, "symout"))
2312 if (write_symbols == NO_DEBUG)
2313 write_symbols = GDB_DEBUG;
2314 sym_file_name = argv[++i];
2316 #endif /* 0 */
2317 else if (!strcmp (str, "o"))
2319 asm_file_name = argv[++i];
2321 #ifdef FIELD_XREF
2322 else if (!strcmp(str,"xref"))
2323 field_xref = 1;
2324 #endif
2325 else
2326 error ("Invalid option `%s'", argv[i]);
2328 else if (argv[i][0] == '+')
2330 if (lang_decode_option (argv[i]))
2332 else
2333 error ("Invalid option `%s'", argv[i]);
2335 else
2336 filename = argv[i];
2338 #ifdef OVERRIDE_OPTIONS
2339 /* Some machines may reject certain combinations of options. */
2340 OVERRIDE_OPTIONS;
2341 #endif
2343 /* Now that register usage is specified, convert it to HARD_REG_SETs. */
2344 init_reg_sets_1 ();
2346 compile_file (filename);
2348 #ifndef USG
2349 #ifndef VMS
2350 if (print_mem_flag)
2352 extern char **environ;
2353 char *lim = (char *) sbrk (0);
2355 fprintf (stderr, "Data size %d.\n",
2356 (int) lim - (int) &environ);
2357 fflush (stderr);
2359 system ("ps v");
2361 #endif /* not VMS */
2362 #endif /* not USG */
2364 #ifdef FIELD_XREF
2365 FIELD_xref_end(errorcount+sorrycount);
2366 #endif
2368 if (errorcount)
2369 exit (FATAL_EXIT_CODE);
2370 if (sorrycount)
2371 exit (FATAL_EXIT_CODE);
2372 exit (SUCCESS_EXIT_CODE);
2373 return 34;
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 []
2385 = TARGET_SWITCHES;
2387 /* Decode the switch -mNAME. */
2389 void
2390 set_target_switch (name)
2391 char *name;
2393 register int j;
2394 int valid = 0;
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;
2401 else
2402 target_flags |= target_switches[j].value;
2403 valid = 1;
2406 if (!valid)
2407 error ("Invalid option `%s'", name);
2410 /* Print default target switches for -version. */
2412 void
2413 print_target_switch_defaults ()
2415 register int j;
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");