|
|
1.1 root 1: /* Top level of GNU C compiler
1.1.1.2 root 2: Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
6: GNU CC is distributed in the hope that it will be useful,
7: but WITHOUT ANY WARRANTY. No author or distributor
8: accepts responsibility to anyone for the consequences of using it
9: or for whether it serves any particular purpose or works at all,
10: unless he says so in writing. Refer to the GNU CC General Public
11: License for full details.
12:
13: Everyone is granted permission to copy, modify and redistribute
14: GNU CC, but only under the conditions described in the
15: GNU CC General Public License. A copy of this license is
16: supposed to have been given to you along with GNU CC so you
17: can know your rights and responsibilities. It should be in a
18: file named COPYING. Among other things, the copyright notice
19: and this notice must be preserved on all copies. */
20:
21:
22: /* This is the top level of cc1.
23: It parses command args, opens files, invokes the various passes
24: in the proper order, and counts the time used by each.
25: Error messages and low-level interface to malloc also handled here. */
26:
27: #include "config.h"
28: #include <stdio.h>
29: #include <signal.h>
1.1.1.10 root 30: #include <setjmp.h>
1.1.1.2 root 31:
1.1.1.4 root 32: #include <sys/types.h>
33: #include <sys/stat.h>
34:
1.1.1.2 root 35: #ifdef USG
36: #include <sys/param.h>
37: #include <sys/times.h>
38: #include <time.h> /* Correct for hpux at least. Is it good on other USG? */
39: #else
40: #ifndef VMS
1.1 root 41: #include <sys/time.h>
42: #include <sys/resource.h>
1.1.1.2 root 43: #endif
44: #endif
45:
1.1 root 46: #include "tree.h"
47: #include "c-tree.h"
48: #include "rtl.h"
1.1.1.2 root 49: #include "flags.h"
1.1 root 50:
51: extern int yydebug;
52:
53: extern FILE *finput;
54:
1.1.1.11 root 55: extern int reload_completed;
1.1.1.12 root 56: extern int rtx_equal_function_value_matters;
1.1.1.11 root 57:
1.1 root 58: extern void init_lex ();
59: extern void init_decl_processing ();
60: extern void init_tree ();
61: extern void init_rtl ();
62: extern void init_optabs ();
1.1.1.2 root 63: extern void init_reg_sets ();
1.1 root 64: extern void dump_flow_info ();
65: extern void dump_local_alloc ();
66:
1.1.1.2 root 67: void rest_of_decl_compilation ();
68: void error ();
69: void error_with_file_and_line ();
70: void set_target_switch ();
71:
1.1 root 72: /* Bit flags that specify the machine subtype we are compiling for.
73: Bits are tested using macros TARGET_... defined in the tm-...h file
74: and set by `-m...' switches. */
75:
76: int target_flags;
77:
1.1.1.2 root 78: /* Name of current original source file (what was input to cpp).
79: This comes from each #-command in the actual input. */
1.1 root 80:
1.1.1.2 root 81: char *input_filename;
82:
83: /* Name of top-level original source file (what was input to cpp).
1.1.1.8 root 84: This comes from the #-command at the beginning of the actual input.
85: If there isn't any there, then this is the cc1 input file name. */
1.1.1.2 root 86:
87: char *main_input_filename;
1.1 root 88:
89: /* Current line number in real source file. */
90:
91: extern int lineno;
92:
93: /* FUNCTION_DECL for function now being parsed or compiled. */
94:
95: extern tree current_function_decl;
96:
97: /* Name to use as base of names for dump output files. */
98:
99: char *dump_base_name;
100:
101: /* Flags saying which kinds of debugging dump have been requested. */
102:
103: int rtl_dump = 0;
104: int rtl_dump_and_exit = 0;
105: int jump_opt_dump = 0;
106: int cse_dump = 0;
107: int loop_dump = 0;
108: int flow_dump = 0;
109: int combine_dump = 0;
110: int local_reg_dump = 0;
111: int global_reg_dump = 0;
1.1.1.2 root 112: int jump2_opt_dump = 0;
1.1 root 113:
114: /* 1 => write gdb debugging output (using symout.c). -g
1.1.1.6 root 115: 2 => write dbx debugging output (using dbxout.c). -G
116: 3 => write sdb debugging output (using sdbout.c). -g. */
1.1 root 117:
1.1.1.4 root 118: enum debugger write_symbols = NO_DEBUG;
1.1 root 119:
1.1.1.6 root 120: /* Nonzero means can use our own extensions to DBX format.
121: Relevant only with write_symbols == DBX_DEBUG. */
122:
123: int use_gdb_dbx_extensions;
124:
1.1 root 125: /* Nonzero means do optimizations. -opt. */
126:
127: int optimize = 0;
128:
1.1.1.2 root 129: /* Nonzero for -fforce-mem: load memory value into a register
1.1 root 130: before arithmetic on it. This makes better cse but slower compilation. */
131:
1.1.1.2 root 132: int flag_force_mem = 0;
1.1 root 133:
1.1.1.2 root 134: /* Nonzero for -fforce-addr: load memory address into a register before
1.1 root 135: reference to memory. This makes better cse but slower compilation. */
136:
1.1.1.2 root 137: int flag_force_addr = 0;
138:
139: /* Nonzero for -fdefer-pop: don't pop args after each function call;
140: instead save them up to pop many calls' args with one insns. */
141:
142: int flag_defer_pop = 1;
143:
144: /* Nonzero for -ffloat-store: don't allocate floats and doubles
145: in extended-precision registers. */
146:
147: int flag_float_store = 0;
148:
149: /* Nonzero for -fcombine-regs:
150: allow instruction combiner to combine an insn
151: that just copies one reg to another. */
152:
153: int flag_combine_regs = 0;
154:
1.1.1.9 root 155: /* Nonzero enables strength-reduction in loop.c. */
156:
157: int flag_strength_reduce = 0;
158:
1.1.1.2 root 159: /* Nonzero for -fwritable-strings:
160: store string constants in data segment and don't uniquize them. */
161:
162: int flag_writable_strings = 0;
163:
164: /* Nonzero means don't put addresses of constant functions in registers.
165: Used for compiling the Unix kernel, where strange substitutions are
166: done on the assembly output. */
167:
168: int flag_no_function_cse = 0;
169:
170: /* Nonzero for -fomit-frame-pointer:
171: don't make a frame pointer in simple functions that don't require one. */
172:
173: int flag_omit_frame_pointer = 0;
174:
175: /* Nonzero to inhibit use of define_optimization peephole opts. */
176:
177: int flag_no_peephole = 0;
178:
179: /* Nonzero means all references through pointers are volatile. */
180:
181: int flag_volatile;
1.1 root 182:
183: /* Nonzero means do stupid register allocation. -noreg.
1.1.1.2 root 184: This and `optimize' are controlled by different switches in cc1,
1.1 root 185: but normally cc controls them both with the -O switch. */
186:
187: int obey_regdecls = 0;
188:
189: /* Don't print functions as they are compiled and don't print
190: times taken by the various passes. -quiet. */
191:
192: int quiet_flag = 0;
193:
194: /* Don't print warning messages. -w. */
195:
196: int inhibit_warnings = 0;
197:
1.1.1.2 root 198: /* Do print extra warnings (such as for uninitialized variables). -W. */
199:
200: int extra_warnings = 0;
201:
1.1.1.9 root 202: /* Nonzero to warn about unused local variables. */
203:
204: int warn_unused;
205:
1.1 root 206: /* Number of error messages and warning messages so far. */
207:
208: int errorcount = 0;
209: int warningcount = 0;
1.1.1.7 root 210: int sorrycount = 0;
1.1 root 211:
1.1.1.2 root 212: /* Nonzero if generating code to do profiling. */
213:
214: int profile_flag = 0;
215:
1.1 root 216: /* Nonzero for -pedantic switch: warn about anything
1.1.1.7 root 217: that standard spec forbids. */
1.1 root 218:
219: int pedantic = 0;
220:
1.1.1.2 root 221: /* Nonzero for -finline-functions: ok to inline functions that look like
222: good inline candidates. */
223:
224: int flag_inline_functions;
225:
226: /* Nonzero for -fkeep-inline-functions: even if we make a function
227: go inline everywhere, keep its defintion around for debugging
228: purposes. */
229:
230: int flag_keep_inline_functions;
231:
1.1.1.12 root 232: /* Nonzero if we are only using compiler to check syntax errors. */
233:
234: int flag_syntax_only;
235:
236: /* Nonzero means make the text shared if supported. */
237:
238: int flag_shared_data;
239:
1.1 root 240: /* Name for output file of assembly code, specified with -o. */
241:
242: char *asm_file_name;
243:
244: /* Name for output file of GDB symbol segment, specified with -symout. */
245:
246: char *sym_file_name;
247:
1.1.1.12 root 248: /* Table of language-independent -f options.
249: STRING is the option name. VARIABLE is the address of the variable.
250: ON_VALUE is the value to store in VARIABLE
251: if `-fSTRING' is seen as an option.
252: (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
253:
254: struct { char *string; int *variable; int on_value;} f_options[] =
255: {
256: {"float-store", &flag_float_store, 1},
257: {"volatile", &flag_volatile, 1},
258: {"defer-pop", &flag_defer_pop, 1},
259: {"omit-frame-pointer", &flag_omit_frame_pointer, 1},
260: {"strength-reduce", &flag_strength_reduce, 1},
261: {"writable-strings", &flag_writable_strings, 1},
262: {"peephole", &flag_no_peephole, 0},
263: {"force-mem", &flag_force_mem, 1},
264: {"force-addr", &flag_force_addr, 1},
265: {"combine-regs", &flag_combine_regs, 1},
266: {"function-cse", &flag_no_function_cse, 0},
267: {"inline-functions", &flag_inline_functions, 1},
268: {"keep-inline-functions", &flag_keep_inline_functions, 1},
269: {"syntax-only", &flag_syntax_only, 1},
270: {"shared-data", &flag_shared_data, 1}
271: };
272:
1.1 root 273: /* Output files for assembler code (real compiler output)
274: and debugging dumps. */
275:
276: FILE *asm_out_file;
277: FILE *rtl_dump_file;
278: FILE *jump_opt_dump_file;
279: FILE *cse_dump_file;
280: FILE *loop_dump_file;
281: FILE *flow_dump_file;
282: FILE *combine_dump_file;
283: FILE *local_reg_dump_file;
284: FILE *global_reg_dump_file;
1.1.1.2 root 285: FILE *jump2_opt_dump_file;
1.1 root 286:
287: /* Time accumulators, to count the total time spent in various passes. */
288:
289: int parse_time;
290: int varconst_time;
1.1.1.2 root 291: int integration_time;
1.1 root 292: int jump_time;
293: int cse_time;
294: int loop_time;
295: int flow_time;
296: int combine_time;
297: int local_alloc_time;
298: int global_alloc_time;
299: int final_time;
300: int symout_time;
301: int dump_time;
302:
303: /* Return time used so far, in microseconds. */
304:
1.1.1.2 root 305: int
1.1 root 306: gettime ()
307: {
1.1.1.2 root 308: #ifdef USG
309: struct tms tms;
310: #else
311: #ifndef VMS
1.1 root 312: struct rusage rusage;
1.1.1.2 root 313: #else /* VMS */
314: struct
315: {
316: int proc_user_time;
317: int proc_system_time;
318: int child_user_time;
319: int child_system_time;
320: } vms_times;
321: #endif
322: #endif
323:
1.1 root 324: if (quiet_flag)
325: return 0;
1.1.1.2 root 326:
327: #ifdef USG
328: times (&tms);
329: return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ);
330: #else
331: #ifndef VMS
1.1 root 332: getrusage (0, &rusage);
333: return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
334: + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
1.1.1.2 root 335: #else /* VMS */
336: times (&vms_times);
337: return (vms_times.proc_user_time + vms_times.proc_system_time) * 10000;
338: #endif
339: #endif
1.1 root 340: }
341:
342: #define TIMEVAR(VAR, BODY) \
1.1.1.3 root 343: do { int otime = gettime (); BODY; VAR += gettime () - otime; } while (0)
1.1 root 344:
1.1.1.2 root 345: void
1.1 root 346: print_time (str, total)
347: char *str;
348: int total;
349: {
1.1.1.2 root 350: fprintf (stderr,
351: "time in %s: %d.%06d\n",
352: str, total / 1000000, total % 1000000);
1.1 root 353: }
354:
355: /* Count an error or warning. Return 1 if the message should be printed. */
356:
357: int
358: count_error (warningp)
359: int warningp;
360: {
361: if (warningp && inhibit_warnings)
362: return 0;
363:
364: if (warningp)
365: warningcount++;
366: else
367: errorcount++;
368:
369: return 1;
370: }
371:
372: /* Print a fatal error message. NAME is the text.
373: Also include a system error message based on `errno'. */
374:
1.1.1.2 root 375: void
1.1 root 376: pfatal_with_name (name)
1.1.1.2 root 377: char *name;
1.1 root 378: {
379: fprintf (stderr, "cc1: ");
380: perror (name);
381: exit (35);
382: }
383:
384: void
1.1.1.2 root 385: fatal_io_error (name)
386: char *name;
387: {
388: fprintf (stderr, "cc1:%s: I/O error\n", name);
389: exit (35);
390: }
391:
392: void
1.1.1.7 root 393: fatal (s, v)
1.1 root 394: char *s;
395: {
1.1.1.7 root 396: error (s, v);
1.1 root 397: exit (34);
398: }
1.1.1.8 root 399:
400: static int need_error_newline;
401:
402: /* Function of last error message;
403: more generally, function such that if next error message is in it
404: then we don't have to mention the function name. */
405: static tree last_error_function = NULL;
1.1 root 406:
407: /* Called when the start of a function definition is parsed,
408: this function prints on stderr the name of the function. */
409:
410: void
411: announce_function (decl)
412: tree decl;
413: {
414: if (! quiet_flag)
415: {
416: fprintf (stderr, " %s", IDENTIFIER_POINTER (DECL_NAME (decl)));
417: fflush (stderr);
1.1.1.9 root 418: need_error_newline = 1;
419: last_error_function = current_function_decl;
1.1 root 420: }
421: }
1.1.1.8 root 422:
1.1.1.2 root 423: /* Prints out, if necessary, the name of the current function
424: which caused an error. Called from all error and warning functions. */
425:
1.1.1.9 root 426: static void
427: report_error_function (file)
428: char *file;
1.1.1.2 root 429: {
1.1.1.8 root 430: if (need_error_newline)
431: {
432: fprintf (stderr, "\n");
433: need_error_newline = 0;
434: }
1.1.1.2 root 435:
436: if (last_error_function != current_function_decl)
437: {
1.1.1.9 root 438: if (file)
439: fprintf (stderr, "%s: ", file);
440:
1.1.1.2 root 441: if (current_function_decl == NULL)
1.1.1.8 root 442: fprintf (stderr, "At top level:\n");
1.1.1.2 root 443: else
1.1.1.8 root 444: fprintf (stderr, "In function %s:\n",
445: IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
446:
1.1.1.2 root 447: last_error_function = current_function_decl;
448: }
449: }
1.1 root 450:
451: /* Report an error at the current line number.
452: S and V are a string and an arg for `printf'. */
453:
454: void
1.1.1.7 root 455: error (s, v, v2)
1.1 root 456: char *s;
457: int v; /* @@also used as pointer */
1.1.1.7 root 458: int v2; /* @@also used as pointer */
1.1 root 459: {
1.1.1.7 root 460: error_with_file_and_line (input_filename, lineno, s, v, v2);
1.1 root 461: }
462:
1.1.1.2 root 463: /* Report an error at line LINE of file FILE.
1.1 root 464: S and V are a string and an arg for `printf'. */
465:
1.1.1.2 root 466: void
1.1.1.7 root 467: error_with_file_and_line (file, line, s, v, v2)
1.1.1.2 root 468: char *file;
1.1 root 469: int line;
470: char *s;
471: int v;
1.1.1.7 root 472: int v2;
1.1 root 473: {
474: count_error (0);
475:
1.1.1.9 root 476: report_error_function (file);
1.1.1.2 root 477:
478: if (file)
479: fprintf (stderr, "%s:%d: ", file, line);
480: else
481: fprintf (stderr, "cc1: ");
1.1.1.7 root 482: fprintf (stderr, s, v, v2);
1.1 root 483: fprintf (stderr, "\n");
484: }
485:
1.1.1.2 root 486: /* Report an error at the declaration DECL.
1.1.1.12 root 487: S and V are a string and an arg which uses %s to substitute the declaration name. */
1.1 root 488:
489: void
1.1.1.12 root 490: error_with_decl (decl, s, v)
1.1.1.2 root 491: tree decl;
1.1 root 492: char *s;
1.1.1.12 root 493: int v;
1.1 root 494: {
1.1.1.2 root 495: count_error (0);
496:
1.1.1.9 root 497: report_error_function (DECL_SOURCE_FILE (decl));
1.1.1.2 root 498:
499: fprintf (stderr, "%s:%d: ",
500: DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
501:
502: if (DECL_NAME (decl))
1.1.1.12 root 503: fprintf (stderr, s, IDENTIFIER_POINTER (DECL_NAME (decl)), v);
1.1.1.2 root 504: else
1.1.1.12 root 505: fprintf (stderr, s, "((anonymous))", v);
1.1.1.2 root 506: fprintf (stderr, "\n");
1.1 root 507: }
508:
1.1.1.11 root 509: /* Report an error at the line number of the insn INSN.
510: S and V are a string and an arg for `printf'.
511: This is used only when INSN is an `asm' with operands,
512: and we make sure there is always a line-NOTE for that kind of statement. */
513:
514: void
515: error_for_asm (insn, s, v, v2)
516: rtx insn;
517: char *s;
518: int v; /* @@also used as pointer */
519: int v2; /* @@also used as pointer */
520: {
1.1.1.12 root 521: rtx temp;
522: char *filename;
523: int line;
524:
525: temp = find_reg_note (insn, REG_ASM_FILE, 0);
526: if (temp == 0)
527: abort ();
528: filename = XSTR (XEXP (temp, 0), 0);
529: temp = find_reg_note (insn, REG_ASM_LINE, 0);
530: line = INTVAL (XEXP (temp, 0));
531:
532: error_with_file_and_line (filename, line, s, v, v2);
1.1.1.11 root 533: }
534:
1.1 root 535: /* Report a warning at line LINE.
536: S and V are a string and an arg for `printf'. */
537:
1.1.1.2 root 538: void
1.1.1.11 root 539: warning_with_file_and_line (file, line, s, v, v2)
540: char *file;
1.1 root 541: int line;
542: char *s;
543: int v;
1.1.1.7 root 544: int v2;
1.1 root 545: {
546: if (count_error (1) == 0)
547: return;
548:
1.1.1.11 root 549: report_error_function (file);
1.1.1.2 root 550:
1.1.1.11 root 551: if (file)
552: fprintf (stderr, "%s:%d: ", file, line);
1.1.1.2 root 553: else
554: fprintf (stderr, "cc1: ");
1.1 root 555:
556: fprintf (stderr, "warning: ");
1.1.1.7 root 557: fprintf (stderr, s, v, v2);
1.1 root 558: fprintf (stderr, "\n");
559: }
1.1.1.2 root 560:
561: /* Report a warning at the current line number.
562: S and V are a string and an arg for `printf'. */
563:
564: void
1.1.1.7 root 565: warning (s, v, v2)
1.1.1.2 root 566: char *s;
567: int v; /* @@also used as pointer */
1.1.1.7 root 568: int v2;
1.1.1.2 root 569: {
1.1.1.11 root 570: warning_with_file_and_line (input_filename, lineno, s, v, v2);
1.1.1.2 root 571: }
572:
573: /* Report a warning at the declaration DECL.
574: S is string which uses %s to substitute the declaration name. */
575:
576: void
1.1.1.12 root 577: warning_with_decl (decl, s, v)
1.1.1.2 root 578: tree decl;
579: char *s;
1.1.1.12 root 580: int v;
1.1.1.2 root 581: {
582: if (count_error (1) == 0)
583: return;
584:
1.1.1.9 root 585: report_error_function (DECL_SOURCE_FILE (decl));
1.1.1.2 root 586:
587: fprintf (stderr, "%s:%d: ",
588: DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
589:
590: fprintf (stderr, "warning: ");
591: if (DECL_NAME (decl))
1.1.1.12 root 592: fprintf (stderr, s, IDENTIFIER_POINTER (DECL_NAME (decl)), v);
1.1.1.2 root 593: else
1.1.1.12 root 594: fprintf (stderr, s, "((anonymous))", v);
1.1.1.2 root 595: fprintf (stderr, "\n");
596: }
1.1.1.7 root 597:
598: /* Apologize for not implementing some feature.
599: S, V, and V2 are a string and args for `printf'. */
600:
601: void
602: sorry (s, v, v2)
603: char *s;
604: int v, v2;
605: {
606: sorrycount++;
607: if (input_filename)
608: fprintf (stderr, "%s:%d: ", input_filename, lineno);
609: else
610: fprintf (stderr, "cc1: ");
611:
612: fprintf (stderr, "sorry, not implemented: ");
613: fprintf (stderr, s, v, v2);
614: fprintf (stderr, "\n");
615: }
616:
617: /* Apologize for not implementing some feature, then quit.
618: S, V, and V2 are a string and args for `printf'. */
619:
620: void
621: really_sorry (s, v, v2)
622: char *s;
623: int v, v2;
624: {
625: if (input_filename)
626: fprintf (stderr, "%s:%d: ", input_filename, lineno);
627: else
628: fprintf (stderr, "c++: ");
629:
630: fprintf (stderr, "sorry, not implemented: ");
631: fprintf (stderr, s, v, v2);
632: fatal (" (fatal)\n");
633: }
1.1 root 634:
635: /* When `malloc.c' is compiled with `rcheck' defined,
636: it calls this function to report clobberage. */
637:
1.1.1.2 root 638: void
1.1 root 639: botch (s)
640: {
641: abort ();
642: }
643:
644: /* Same as `malloc' but report error if no memory available. */
645:
1.1.1.2 root 646: int
1.1 root 647: xmalloc (size)
648: unsigned size;
649: {
650: register int value = (int) malloc (size);
651: if (value == 0)
652: fatal ("Virtual memory exhausted.");
653: return value;
654: }
655:
656: /* Same as `realloc' but report error if no memory available. */
657:
658: int
659: xrealloc (ptr, size)
660: char *ptr;
661: int size;
662: {
663: int result = realloc (ptr, size);
664: if (!result)
1.1.1.2 root 665: fatal ("Virtual memory exhausted.");
1.1 root 666: return result;
667: }
668:
669: /* Return the logarithm of X, base 2, considering X unsigned,
670: if X is a power of 2. Otherwise, returns -1. */
671:
672: int
673: exact_log2 (x)
674: register unsigned int x;
675: {
676: register int log = 0;
677: for (log = 0; log < HOST_BITS_PER_INT; log++)
678: if (x == (1 << log))
679: return log;
680: return -1;
681: }
682:
683: /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
684: If X is 0, return -1. */
685:
686: int
687: floor_log2 (x)
688: register unsigned int x;
689: {
690: register int log = 0;
691: for (log = 0; log < HOST_BITS_PER_INT; log++)
692: if ((x & ((-1) << log)) == 0)
693: return log - 1;
694: return HOST_BITS_PER_INT - 1;
695: }
1.1.1.10 root 696:
697: int float_handled;
698: jmp_buf float_handler;
699:
700: /* Specify where to longjmp to when a floating arithmetic error happens.
701: If HANDLER is 0, it means don't handle the errors any more. */
702:
703: void
704: set_float_handler (handler)
705: jmp_buf handler;
706: {
707: float_handled = (handler != 0);
708: if (handler)
709: bcopy (handler, float_handler, sizeof (float_handler));
710: }
711:
712: /* Signals actually come here. */
713:
714: static void
715: float_signal ()
716: {
717: if (float_handled == 0)
718: abort ();
719: warning ("floating overflow in constant folding");
720: float_handled = 0;
721: longjmp (float_handler, 1);
722: }
1.1.1.13! root 723:
! 724: /* Handler for SIGPIPE. */
! 725:
! 726: static void
! 727: pipe_closed ()
! 728: {
! 729: fatal ("output pipe has been closed");
! 730: }
1.1 root 731:
732: /* Compile an entire file of output from cpp, named NAME.
733: Write a file of assembly output and various debugging dumps. */
734:
735: static void
736: compile_file (name)
737: char *name;
738: {
739: tree globals;
740: int start_time;
1.1.1.9 root 741: int dump_base_name_length;
742:
743: int name_specified = name != 0;
744:
745: if (dump_base_name == 0)
746: dump_base_name = name ? name : "gccdump";
747: dump_base_name_length = strlen (dump_base_name);
1.1 root 748:
749: parse_time = 0;
750: varconst_time = 0;
1.1.1.2 root 751: integration_time = 0;
1.1 root 752: jump_time = 0;
753: cse_time = 0;
754: loop_time = 0;
755: flow_time = 0;
756: combine_time = 0;
757: local_alloc_time = 0;
758: global_alloc_time = 0;
759: final_time = 0;
760: symout_time = 0;
1.1.1.2 root 761: dump_time = 0;
1.1 root 762:
763: /* Open input file. */
764:
1.1.1.9 root 765: if (name == 0 || !strcmp (name, "-"))
766: {
767: finput = stdin;
768: name = "stdin";
769: }
770: else
771: finput = fopen (name, "r");
1.1 root 772: if (finput == 0)
773: pfatal_with_name (name);
774:
775: /* Initialize data in various passes. */
776:
777: init_tree ();
778: init_lex ();
779: init_rtl ();
1.1.1.2 root 780: init_emit_once ();
1.1 root 781: init_decl_processing ();
782: init_optabs ();
783:
784: /* If rtl dump desired, open the output file. */
785: if (rtl_dump)
786: {
787: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
788: strcpy (dumpname, dump_base_name);
789: strcat (dumpname, ".rtl");
790: rtl_dump_file = fopen (dumpname, "w");
791: if (rtl_dump_file == 0)
792: pfatal_with_name (dumpname);
793: }
794:
795: /* If jump_opt dump desired, open the output file. */
796: if (jump_opt_dump)
797: {
798: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
799: strcpy (dumpname, dump_base_name);
800: strcat (dumpname, ".jump");
801: jump_opt_dump_file = fopen (dumpname, "w");
802: if (jump_opt_dump_file == 0)
803: pfatal_with_name (dumpname);
804: }
805:
806: /* If cse dump desired, open the output file. */
807: if (cse_dump)
808: {
809: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
810: strcpy (dumpname, dump_base_name);
811: strcat (dumpname, ".cse");
812: cse_dump_file = fopen (dumpname, "w");
813: if (cse_dump_file == 0)
814: pfatal_with_name (dumpname);
815: }
816:
817: /* If loop dump desired, open the output file. */
818: if (loop_dump)
819: {
820: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
821: strcpy (dumpname, dump_base_name);
822: strcat (dumpname, ".loop");
823: loop_dump_file = fopen (dumpname, "w");
824: if (loop_dump_file == 0)
825: pfatal_with_name (dumpname);
826: }
827:
828: /* If flow dump desired, open the output file. */
829: if (flow_dump)
830: {
831: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
832: strcpy (dumpname, dump_base_name);
833: strcat (dumpname, ".flow");
834: flow_dump_file = fopen (dumpname, "w");
835: if (flow_dump_file == 0)
836: pfatal_with_name (dumpname);
837: }
838:
839: /* If combine dump desired, open the output file. */
840: if (combine_dump)
841: {
842: register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
843: strcpy (dumpname, dump_base_name);
844: strcat (dumpname, ".combine");
845: combine_dump_file = fopen (dumpname, "w");
846: if (combine_dump_file == 0)
847: pfatal_with_name (dumpname);
848: }
849:
850: /* If local_reg dump desired, open the output file. */
851: if (local_reg_dump)
852: {
853: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
854: strcpy (dumpname, dump_base_name);
855: strcat (dumpname, ".lreg");
856: local_reg_dump_file = fopen (dumpname, "w");
857: if (local_reg_dump_file == 0)
858: pfatal_with_name (dumpname);
859: }
860:
861: /* If global_reg dump desired, open the output file. */
862: if (global_reg_dump)
863: {
864: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
865: strcpy (dumpname, dump_base_name);
866: strcat (dumpname, ".greg");
867: global_reg_dump_file = fopen (dumpname, "w");
868: if (global_reg_dump_file == 0)
869: pfatal_with_name (dumpname);
870: }
871:
1.1.1.2 root 872: /* If jump2_opt dump desired, open the output file. */
873: if (jump2_opt_dump)
874: {
875: register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
876: strcpy (dumpname, dump_base_name);
877: strcat (dumpname, ".jump2");
878: jump2_opt_dump_file = fopen (dumpname, "w");
879: if (jump2_opt_dump_file == 0)
880: pfatal_with_name (dumpname);
881: }
882:
1.1 root 883: /* Open assembler code output file. */
884:
1.1.1.9 root 885: if (! name_specified && asm_file_name == 0)
886: asm_out_file = stdout;
887: else
888: {
889: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
890: int len = strlen (dump_base_name);
891: strcpy (dumpname, dump_base_name);
892: if (len > 2 && ! strcmp (".c", dumpname + len - 2))
893: dumpname[len - 2] = 0;
894: else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
895: dumpname[len - 2] = 0;
896: else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
897: dumpname[len - 3] = 0;
898: strcat (dumpname, ".s");
899: if (asm_file_name == 0)
900: {
901: asm_file_name = (char *) malloc (strlen (dumpname) + 1);
902: strcpy (asm_file_name, dumpname);
903: }
904: if (!strcmp (asm_file_name, "-"))
905: asm_out_file = stdout;
906: else
907: asm_out_file = fopen (asm_file_name, "w");
908: if (asm_out_file == 0)
909: pfatal_with_name (asm_file_name);
910: }
1.1 root 911:
912: input_filename = name;
913:
914: /* the beginning of the file is a new line; check for # */
915: /* With luck, we discover the real source file's name from that
916: and put it in input_filename. */
1.1.1.4 root 917: ungetc (check_newline (), finput);
918:
1.1.1.8 root 919: /* If the input doesn't start with a #line, use the input name
920: as the official input file name. */
921: if (main_input_filename == 0)
922: main_input_filename = name;
923:
1.1.1.4 root 924: ASM_FILE_START (asm_out_file);
1.1 root 925:
1.1.1.12 root 926: /* Output something to inform GDB that this compilation was by GCC. */
927: #ifndef ASM_IDENTIFY_GCC
928: fprintf (asm_out_file, "gcc_compiled.:\n");
929: #else
930: ASM_IDENTIFY_GCC (asm_out_file);
931: #endif
932:
1.1 root 933: /* If GDB symbol table desired, open the GDB symbol output file. */
1.1.1.4 root 934: if (write_symbols == GDB_DEBUG)
1.1 root 935: {
936: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1.1.1.2 root 937: int len = strlen (dump_base_name);
1.1 root 938: strcpy (dumpname, dump_base_name);
1.1.1.2 root 939: if (len > 2 && ! strcmp (".c", dumpname + len - 2))
940: dumpname[len - 2] = 0;
1.1.1.7 root 941: else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
942: dumpname[len - 2] = 0;
1.1.1.2 root 943: else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
944: dumpname[len - 3] = 0;
1.1 root 945: strcat (dumpname, ".sym");
946: if (sym_file_name == 0)
947: sym_file_name = dumpname;
1.1.1.4 root 948: symout_init (sym_file_name, asm_out_file, main_input_filename);
1.1 root 949: }
950:
951: /* If dbx symbol table desired, initialize writing it
952: and output the predefined types. */
1.1.1.4 root 953: #ifdef DBX_DEBUGGING_INFO
954: if (write_symbols == DBX_DEBUG)
1.1.1.2 root 955: dbxout_init (asm_out_file, main_input_filename);
1.1.1.4 root 956: #endif
957: #ifdef SDB_DEBUGGING_INFO
958: if (write_symbols == SDB_DEBUG)
959: sdbout_init (asm_out_file, main_input_filename);
960: #endif
1.1 root 961:
962: /* Initialize yet another pass. */
963:
1.1.1.2 root 964: init_final (main_input_filename);
1.1 root 965:
966: start_time = gettime ();
967:
968: /* Call the parser, which parses the entire file
969: (calling rest_of_compilation for each function). */
970:
971: yyparse ();
972:
973: /* Compilation is now finished except for writing
974: what's left of the symbol table output. */
975:
976: parse_time += gettime () - start_time;
977:
1.1.1.2 root 978: parse_time -= varconst_time;
979:
1.1 root 980: globals = getdecls ();
981:
1.1.1.2 root 982: /* Really define vars that have had only a tentative definition.
983: Really output inline functions that must actually be callable
984: and have not been output so far. */
985:
986: {
987: tree decl;
988: for (decl = globals; decl; decl = TREE_CHAIN (decl))
989: {
990: if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
991: && ! TREE_ASM_WRITTEN (decl))
992: rest_of_decl_compilation (decl, 0, 1, 1);
993: if (TREE_CODE (decl) == FUNCTION_DECL
994: && ! TREE_ASM_WRITTEN (decl)
995: && DECL_INITIAL (decl) != 0
996: && TREE_ADDRESSABLE (decl))
997: output_inline_function (decl);
1.1.1.13! root 998: if (warn_unused
! 999: && TREE_CODE (decl) == FUNCTION_DECL
! 1000: && DECL_INITIAL (decl) == 0
! 1001: && TREE_EXTERNAL (decl)
! 1002: && ! TREE_PUBLIC (decl))
! 1003: warning_with_decl (decl, "`%s' declared but never defined");
1.1.1.2 root 1004: }
1005: }
1006:
1.1 root 1007: /* Do dbx symbols */
1.1.1.4 root 1008: #ifdef DBX_DEBUGGING_INFO
1009: if (write_symbols == DBX_DEBUG)
1.1 root 1010: TIMEVAR (symout_time,
1011: {
1012: dbxout_tags (gettags ());
1013: dbxout_types (get_permanent_types ());
1014: });
1.1.1.4 root 1015: #endif
1016:
1017: #ifdef SDB_DEBUGGING_INFO
1018: if (write_symbols == SDB_DEBUG)
1019: TIMEVAR (symout_time,
1020: {
1021: sdbout_tags (gettags ());
1022: sdbout_types (get_permanent_types ());
1023: });
1024: #endif
1.1 root 1025:
1026: /* Do gdb symbols */
1.1.1.4 root 1027: if (write_symbols == GDB_DEBUG)
1.1 root 1028: TIMEVAR (symout_time,
1029: {
1030: struct stat statbuf;
1031: fstat (fileno (finput), &statbuf);
1032: symout_types (get_permanent_types ());
1033: symout_top_blocks (globals, gettags ());
1034: symout_finish (name, statbuf.st_ctime);
1035: });
1036:
1.1.1.2 root 1037: /* Close the dump files. */
1.1 root 1038:
1039: if (rtl_dump)
1040: fclose (rtl_dump_file);
1041:
1042: if (jump_opt_dump)
1043: fclose (jump_opt_dump_file);
1044:
1045: if (cse_dump)
1046: fclose (cse_dump_file);
1047:
1048: if (loop_dump)
1049: fclose (loop_dump_file);
1050:
1051: if (flow_dump)
1052: fclose (flow_dump_file);
1053:
1054: if (combine_dump)
1055: {
1056: dump_combine_total_stats (combine_dump_file);
1057: fclose (combine_dump_file);
1058: }
1059:
1060: if (local_reg_dump)
1061: fclose (local_reg_dump_file);
1062:
1063: if (global_reg_dump)
1064: fclose (global_reg_dump_file);
1065:
1.1.1.2 root 1066: if (jump2_opt_dump)
1067: fclose (jump2_opt_dump_file);
1068:
1069: /* Close non-debugging input and output files. */
1070:
1071: fclose (finput);
1072: if (ferror (asm_out_file) != 0)
1073: fatal_io_error (asm_file_name);
1074: fclose (asm_out_file);
1075:
1.1 root 1076: /* Print the times. */
1077:
1078: if (! quiet_flag)
1079: {
1.1.1.2 root 1080: fprintf (stderr,"\n");
1.1 root 1081: print_time ("parse", parse_time);
1.1.1.2 root 1082: print_time ("integration", integration_time);
1.1 root 1083: print_time ("jump", jump_time);
1084: print_time ("cse", cse_time);
1085: print_time ("loop", loop_time);
1086: print_time ("flow", flow_time);
1087: print_time ("combine", combine_time);
1088: print_time ("local-alloc", local_alloc_time);
1089: print_time ("global-alloc", global_alloc_time);
1090: print_time ("final", final_time);
1091: print_time ("varconst", varconst_time);
1092: print_time ("symout", symout_time);
1093: print_time ("dump", dump_time);
1094: }
1095: }
1096:
1.1.1.2 root 1097: /* This is called from finish_decl (within yyparse)
1098: for each declaration of a function or variable.
1099: This does nothing for automatic variables.
1100: Otherwise, it sets up the RTL and outputs any assembler code
1101: (label definition, storage allocation and initialization).
1102:
1103: DECL is the declaration. If ASMSPEC is nonzero, it specifies
1104: the assembler symbol name to be used. TOP_LEVEL is nonzero
1105: if this declaration is not within a function. */
1106:
1107: void
1108: rest_of_decl_compilation (decl, asmspec, top_level, at_end)
1109: tree decl;
1110: tree asmspec;
1111: int top_level;
1112: int at_end;
1113: {
1114: /* Declarations of variables, and of functions defined elsewhere. */
1115:
1116: if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
1117: TIMEVAR (varconst_time,
1118: {
1.1.1.12 root 1119: make_decl_rtl (decl, asmspec, top_level);
1120: /* Don't output anything
1121: when a tentative file-scope definition is seen.
1122: But at end of compilation, do output code for them. */
1123: if (! (! at_end && top_level
1124: && (DECL_INITIAL (decl) == 0
1125: || DECL_INITIAL (decl) == error_mark_node)))
1126: assemble_variable (decl, top_level, write_symbols, at_end);
1.1.1.2 root 1127: });
1.1.1.4 root 1128: #ifdef DBX_DEBUGGING_INFO
1129: else if (write_symbols == DBX_DEBUG && TREE_CODE (decl) == TYPE_DECL)
1.1.1.3 root 1130: TIMEVAR (varconst_time, dbxout_symbol (decl, 0));
1.1.1.4 root 1131: #endif
1132: #ifdef SDB_DEBUGGING_INFO
1133: else if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == TYPE_DECL)
1134: TIMEVAR (varconst_time, sdbout_symbol (decl, 0));
1135: #endif
1.1.1.2 root 1136:
1137: if (top_level)
1138: {
1.1.1.4 root 1139: if (write_symbols == GDB_DEBUG)
1.1.1.2 root 1140: {
1141: TIMEVAR (symout_time,
1142: {
1143: /* The initizations make types when they contain
1144: string constants. The types are on the temporary
1145: obstack, so output them now before they go away. */
1146: symout_types (get_temporary_types ());
1147: });
1148: }
1149: else
1150: /* Clean out the temporary type list, since the types will go away. */
1151: get_temporary_types ();
1152: }
1153: }
1154:
1.1 root 1155: /* This is called from finish_function (within yyparse)
1.1.1.2 root 1156: after each top-level definition is parsed.
1.1 root 1157: It is supposed to compile that function or variable
1158: and output the assembler code for it.
1159: After we return, the tree storage is freed. */
1160:
1161: void
1.1.1.2 root 1162: rest_of_compilation (decl)
1.1 root 1163: tree decl;
1164: {
1165: register rtx insns;
1166: int start_time = gettime ();
1167: int tem;
1168:
1.1.1.2 root 1169: /* If we are reconsidering an inline function
1170: at the end of compilation, skip the stuff for making it inline. */
1.1 root 1171:
1.1.1.2 root 1172: if (DECL_SAVED_INSNS (decl) == 0)
1.1 root 1173: {
1174:
1.1.1.2 root 1175: /* If requested, consider whether to make this function inline. */
1176: if (flag_inline_functions || TREE_INLINE (decl))
1177: {
1178: TIMEVAR (integration_time,
1179: {
1180: int specd = TREE_INLINE (decl);
1181: char *lose = function_cannot_inline_p (decl);
1182: if (lose != 0 && specd)
1183: warning_with_decl (decl, lose);
1184: if (lose == 0)
1185: save_for_inline (decl);
1186: else
1187: TREE_INLINE (decl) = 0;
1188: });
1189: }
1.1 root 1190:
1.1.1.2 root 1191: insns = get_insns ();
1.1 root 1192:
1193: /* Dump the rtl code if we are dumping rtl. */
1194:
1195: if (rtl_dump)
1196: TIMEVAR (dump_time,
1197: {
1198: fprintf (rtl_dump_file, "\n;; Function %s\n\n",
1199: IDENTIFIER_POINTER (DECL_NAME (decl)));
1.1.1.2 root 1200: if (DECL_SAVED_INSNS (decl))
1201: fprintf (rtl_dump_file, ";; (integrable)\n\n");
1.1 root 1202: print_rtl (rtl_dump_file, insns);
1203: fflush (rtl_dump_file);
1204: });
1205:
1.1.1.2 root 1206: /* If function is inline, and we don't yet know whether to
1207: compile it by itself, defer decision till end of compilation.
1208: finish_compilation will call rest_of_compilation again
1209: for those functions that need to be output. */
1210:
1211: if (TREE_PUBLIC (decl) == 0
1212: && TREE_INLINE (decl)
1213: && ! flag_keep_inline_functions)
1.1 root 1214: goto exit_rest_of_compilation;
1.1.1.2 root 1215: }
1.1 root 1216:
1.1.1.2 root 1217: if (rtl_dump_and_exit)
1218: goto exit_rest_of_compilation;
1.1 root 1219:
1.1.1.2 root 1220: TREE_ASM_WRITTEN (decl) = 1;
1.1 root 1221:
1.1.1.2 root 1222: insns = get_insns ();
1.1 root 1223:
1.1.1.2 root 1224: /* Copy any shared structure that should not be shared. */
1.1 root 1225:
1.1.1.2 root 1226: unshare_all_rtl (insns);
1.1 root 1227:
1.1.1.2 root 1228: /* See if we have allocated stack slots that are not directly addressable.
1229: If so, scan all the insns and create explicit address computation
1230: for all references to such slots. */
1231: /* fixup_stack_slots (); */
1.1 root 1232:
1.1.1.2 root 1233: /* Do jump optimization the first time, if -opt.
1234: Also do it if -W, but in that case it doesn't change the rtl code,
1235: it only computes whether control can drop off the end of the function. */
1.1 root 1236:
1.1.1.13! root 1237: if (optimize || extra_warnings || warn_return_type
! 1238: /* If function is `volatile', we should warn if it tries to return. */
! 1239: || TREE_THIS_VOLATILE (decl))
1.1.1.2 root 1240: TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
1.1 root 1241:
1.1.1.2 root 1242: /* Dump rtl code after jump, if we are doing that. */
1.1 root 1243:
1.1.1.2 root 1244: if (jump_opt_dump)
1245: TIMEVAR (dump_time,
1246: {
1247: fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
1248: IDENTIFIER_POINTER (DECL_NAME (decl)));
1249: print_rtl (jump_opt_dump_file, insns);
1250: fflush (jump_opt_dump_file);
1251: });
1.1 root 1252:
1.1.1.2 root 1253: /* Perform common subexpression elimination.
1254: Nonzero value from `cse_main' means that jumps were simplified
1255: and some code may now be unreachable, so do
1256: jump optimization again. */
1.1 root 1257:
1.1.1.2 root 1258: if (optimize)
1259: {
1260: TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 0));
1.1 root 1261:
1.1.1.2 root 1262: TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num ()));
1.1 root 1263:
1.1.1.2 root 1264: if (tem)
1265: TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
1266: }
1.1 root 1267:
1.1.1.2 root 1268: /* Dump rtl code after cse, if we are doing that. */
1.1 root 1269:
1.1.1.2 root 1270: if (cse_dump)
1271: TIMEVAR (dump_time,
1272: {
1273: fprintf (cse_dump_file, "\n;; Function %s\n\n",
1274: IDENTIFIER_POINTER (DECL_NAME (decl)));
1275: print_rtl (cse_dump_file, insns);
1276: fflush (cse_dump_file);
1277: });
1.1 root 1278:
1.1.1.2 root 1279: if (loop_dump)
1280: TIMEVAR (dump_time,
1281: {
1282: fprintf (loop_dump_file, "\n;; Function %s\n\n",
1283: IDENTIFIER_POINTER (DECL_NAME (decl)));
1284: });
1.1 root 1285:
1.1.1.2 root 1286: /* Move constant computations out of loops. */
1.1 root 1287:
1.1.1.2 root 1288: if (optimize)
1289: {
1290: TIMEVAR (loop_time,
1291: {
1292: reg_scan (insns, max_reg_num (), 1);
1.1.1.9 root 1293: loop_optimize (insns, loop_dump ? loop_dump_file : 0);
1.1.1.2 root 1294: });
1295: }
1.1 root 1296:
1.1.1.2 root 1297: /* Dump rtl code after loop opt, if we are doing that. */
1.1 root 1298:
1.1.1.2 root 1299: if (loop_dump)
1300: TIMEVAR (dump_time,
1301: {
1302: print_rtl (loop_dump_file, insns);
1303: fflush (loop_dump_file);
1304: });
1.1 root 1305:
1.1.1.2 root 1306: /* Now we choose between stupid (pcc-like) register allocation
1307: (if we got the -noreg switch and not -opt)
1308: and smart register allocation. */
1.1 root 1309:
1.1.1.2 root 1310: if (optimize) /* Stupid allocation probably won't work */
1311: obey_regdecls = 0; /* if optimizations being done. */
1.1 root 1312:
1.1.1.2 root 1313: regclass_init ();
1.1 root 1314:
1.1.1.2 root 1315: /* Print function header into flow dump now
1316: because doing the flow analysis makes some of the dump. */
1.1 root 1317:
1.1.1.2 root 1318: if (flow_dump)
1319: TIMEVAR (dump_time,
1320: {
1321: fprintf (flow_dump_file, "\n;; Function %s\n\n",
1322: IDENTIFIER_POINTER (DECL_NAME (decl)));
1323: });
1324:
1325: if (obey_regdecls)
1326: {
1327: TIMEVAR (flow_time,
1328: {
1329: regclass (insns, max_reg_num ());
1330: stupid_life_analysis (insns, max_reg_num (),
1331: flow_dump_file);
1332: });
1333: }
1334: else
1335: {
1336: /* Do control and data flow analysis,
1337: and write some of the results to dump file. */
1.1 root 1338:
1.1.1.2 root 1339: TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
1340: flow_dump_file));
1341: if (extra_warnings)
1342: uninitialized_vars_warning (DECL_INITIAL (decl));
1343: }
1.1 root 1344:
1.1.1.2 root 1345: /* Dump rtl after flow analysis. */
1.1 root 1346:
1.1.1.2 root 1347: if (flow_dump)
1348: TIMEVAR (dump_time,
1349: {
1350: print_rtl (flow_dump_file, insns);
1351: fflush (flow_dump_file);
1352: });
1.1 root 1353:
1.1.1.2 root 1354: /* If -opt, try combining insns through substitution. */
1.1 root 1355:
1.1.1.2 root 1356: if (optimize)
1357: TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
1.1 root 1358:
1.1.1.2 root 1359: /* Dump rtl code after insn combination. */
1.1 root 1360:
1.1.1.2 root 1361: if (combine_dump)
1362: TIMEVAR (dump_time,
1363: {
1364: fprintf (combine_dump_file, "\n;; Function %s\n\n",
1365: IDENTIFIER_POINTER (DECL_NAME (decl)));
1366: dump_combine_stats (combine_dump_file);
1367: print_rtl (combine_dump_file, insns);
1368: fflush (combine_dump_file);
1369: });
1.1 root 1370:
1.1.1.2 root 1371: /* Unless we did stupid register allocation,
1372: allocate pseudo-regs that are used only within 1 basic block. */
1.1 root 1373:
1.1.1.2 root 1374: if (!obey_regdecls)
1375: TIMEVAR (local_alloc_time,
1376: {
1377: regclass (insns, max_reg_num ());
1378: local_alloc ();
1379: });
1.1 root 1380:
1.1.1.2 root 1381: /* Dump rtl code after allocating regs within basic blocks. */
1.1 root 1382:
1.1.1.2 root 1383: if (local_reg_dump)
1384: TIMEVAR (dump_time,
1385: {
1386: fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
1387: IDENTIFIER_POINTER (DECL_NAME (decl)));
1388: dump_flow_info (local_reg_dump_file);
1389: dump_local_alloc (local_reg_dump_file);
1390: print_rtl (local_reg_dump_file, insns);
1391: fflush (local_reg_dump_file);
1392: });
1.1 root 1393:
1.1.1.2 root 1394: if (global_reg_dump)
1395: TIMEVAR (dump_time,
1396: fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
1397: IDENTIFIER_POINTER (DECL_NAME (decl))));
1398:
1399: /* Unless we did stupid register allocation,
1400: allocate remaining pseudo-regs, then do the reload pass
1401: fixing up any insns that are invalid. */
1402:
1403: TIMEVAR (global_alloc_time,
1404: {
1405: if (!obey_regdecls)
1406: global_alloc (global_reg_dump ? global_reg_dump_file : 0);
1407: else
1408: reload (insns, 0,
1409: global_reg_dump ? global_reg_dump_file : 0);
1410: });
1411:
1412: if (global_reg_dump)
1413: TIMEVAR (dump_time,
1414: {
1415: dump_global_regs (global_reg_dump_file);
1416: print_rtl (global_reg_dump_file, insns);
1417: fflush (global_reg_dump_file);
1418: });
1.1 root 1419:
1.1.1.12 root 1420: rtx_equal_function_value_matters = 1;
1.1.1.11 root 1421: reload_completed = 1;
1422:
1.1.1.2 root 1423: /* One more attempt to remove jumps to .+1
1424: left by dead-store-elimination.
1425: Also do cross-jumping this time
1426: and delete no-op move insns. */
1.1 root 1427:
1.1.1.2 root 1428: if (optimize)
1429: {
1430: TIMEVAR (jump_time, jump_optimize (insns, 1, 1));
1431: }
1.1 root 1432:
1.1.1.2 root 1433: /* Dump rtl code after jump, if we are doing that. */
1434:
1435: if (jump2_opt_dump)
1436: TIMEVAR (dump_time,
1437: {
1438: fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
1439: IDENTIFIER_POINTER (DECL_NAME (decl)));
1440: print_rtl (jump2_opt_dump_file, insns);
1441: fflush (jump2_opt_dump_file);
1442: });
1443:
1444: /* Now turn the rtl into assembler code. */
1445:
1446: TIMEVAR (final_time,
1447: {
1448: assemble_function (decl);
1449: final_start_function (insns, asm_out_file,
1450: write_symbols, optimize);
1451: final (insns, asm_out_file,
1.1.1.9 root 1452: write_symbols, optimize, 0);
1.1.1.2 root 1453: final_end_function (insns, asm_out_file,
1454: write_symbols, optimize);
1455: fflush (asm_out_file);
1456: });
1.1 root 1457:
1.1.1.2 root 1458: /* Write GDB symbols if requested */
1.1 root 1459:
1.1.1.4 root 1460: if (write_symbols == GDB_DEBUG)
1.1.1.2 root 1461: {
1462: TIMEVAR (symout_time,
1463: {
1464: symout_types (get_permanent_types ());
1465: symout_types (get_temporary_types ());
1466:
1467: DECL_BLOCK_SYMTAB_ADDRESS (decl)
1468: = symout_function (DECL_INITIAL (decl),
1469: DECL_ARGUMENTS (decl), 0);
1.1.1.6 root 1470: symout_function_end ();
1.1.1.2 root 1471: });
1.1 root 1472: }
1.1.1.2 root 1473: else
1474: get_temporary_types ();
1475:
1476: /* Write DBX symbols if requested */
1477:
1.1.1.4 root 1478: #ifdef DBX_DEBUGGING_INFO
1479: if (write_symbols == DBX_DEBUG)
1.1.1.2 root 1480: TIMEVAR (symout_time, dbxout_function (decl));
1.1.1.4 root 1481: #endif
1.1 root 1482:
1483: exit_rest_of_compilation:
1484:
1.1.1.12 root 1485: rtx_equal_function_value_matters = 0;
1.1.1.11 root 1486: reload_completed = 0;
1487:
1.1.1.8 root 1488: /* Clear out the real_constant_chain before some of the rtx's
1489: it runs through become garbage. */
1490:
1491: clear_const_double_mem ();
1492:
1.1 root 1493: /* The parsing time is all the time spent in yyparse
1494: *except* what is spent in this function. */
1495:
1496: parse_time -= gettime () - start_time;
1497: }
1498:
1499: /* Entry point of cc1. Decode command args, then call compile_file.
1.1.1.2 root 1500: Exit code is 35 if can't open files, 34 if fatal error,
1501: 33 if had nonfatal errors, else success. */
1.1 root 1502:
1503: int
1504: main (argc, argv, envp)
1505: int argc;
1506: char **argv;
1507: char **envp;
1508: {
1509: register int i;
1.1.1.2 root 1510: char *filename = 0;
1511: int print_mem_flag = 0;
1512:
1513: #ifdef RLIMIT_STACK
1514: /* Get rid of any avoidable limit on stack size. */
1515: {
1516: struct rlimit rlim;
1517:
1518: /* Set the stack limit huge so that alloca does not fail. */
1519: getrlimit (RLIMIT_STACK, &rlim);
1520: rlim.rlim_cur = rlim.rlim_max;
1521: setrlimit (RLIMIT_STACK, &rlim);
1522: }
1523: #endif /* RLIMIT_STACK */
1524:
1.1.1.10 root 1525: signal (SIGFPE, float_signal);
1526:
1.1.1.13! root 1527: signal (SIGPIPE, pipe_closed);
! 1528:
1.1.1.2 root 1529: /* Initialize whether `char' is signed. */
1530: flag_signed_char = DEFAULT_SIGNED_CHAR;
1531:
1.1.1.4 root 1532: /* This is zeroed by -O. */
1533: obey_regdecls = 1;
1534:
1535: /* Initialize register usage now so switches may override. */
1.1.1.2 root 1536: init_reg_sets ();
1.1 root 1537:
1538: target_flags = 0;
1539: set_target_switch ("");
1540:
1541: for (i = 1; i < argc; i++)
1.1.1.13! root 1542: if (argv[i][0] == '-' && argv[i][1] != 0)
1.1 root 1543: {
1544: register char *str = argv[i] + 1;
1545: if (str[0] == 'Y')
1546: str++;
1547:
1548: if (str[0] == 'm')
1549: set_target_switch (&str[1]);
1550: else if (!strcmp (str, "dumpbase"))
1551: {
1552: dump_base_name = argv[++i];
1553: }
1554: else if (str[0] == 'd')
1555: {
1556: register char *p = &str[1];
1557: while (*p)
1558: switch (*p++)
1559: {
1560: case 'c':
1561: combine_dump = 1;
1562: break;
1563: case 'f':
1564: flow_dump = 1;
1565: break;
1566: case 'g':
1567: global_reg_dump = 1;
1568: break;
1569: case 'j':
1570: jump_opt_dump = 1;
1571: break;
1.1.1.2 root 1572: case 'J':
1573: jump2_opt_dump = 1;
1574: break;
1.1 root 1575: case 'l':
1576: local_reg_dump = 1;
1577: break;
1578: case 'L':
1579: loop_dump = 1;
1580: break;
1.1.1.2 root 1581: case 'm':
1582: print_mem_flag = 1;
1583: break;
1.1 root 1584: case 'r':
1585: rtl_dump = 1;
1586: break;
1587: case 's':
1588: cse_dump = 1;
1589: break;
1590: case 'y':
1591: yydebug = 1;
1592: break;
1593: }
1594: }
1.1.1.2 root 1595: else if (str[0] == 'f')
1596: {
1.1.1.12 root 1597: int j;
1.1.1.2 root 1598: register char *p = &str[1];
1.1.1.12 root 1599: int found = 0;
1600:
1601: /* Some kind of -f option.
1602: P's value is the option sans `-f'.
1603: Search for it in the table of options. */
1604:
1605: for (j = 0;
1606: !found && j < sizeof (f_options) / sizeof (f_options[0]);
1607: j++)
1608: {
1609: if (!strcmp (p, f_options[j].string))
1610: {
1611: *f_options[j].variable = f_options[j].on_value;
1612: /* A goto here would be cleaner,
1613: but breaks the vax pcc. */
1614: found = 1;
1615: }
1.1.1.13! root 1616: if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
1.1.1.12 root 1617: && ! strcmp (p+3, f_options[j].string))
1618: {
1619: *f_options[j].variable = ! f_options[j].on_value;
1620: found = 1;
1621: }
1622: }
1623:
1624: if (found)
1625: ;
1.1.1.2 root 1626: else if (!strncmp (p, "fixed-", 6))
1627: fix_register (&p[6], 1, 1);
1628: else if (!strncmp (p, "call-used-", 10))
1629: fix_register (&p[10], 0, 1);
1630: else if (!strncmp (p, "call-saved-", 11))
1631: fix_register (&p[11], 0, 0);
1.1.1.7 root 1632: else if (! lang_decode_option (argv[i]))
1633: error ("Invalid option `%s'", argv[i]);
1.1.1.2 root 1634: }
1.1 root 1635: else if (!strcmp (str, "noreg"))
1.1.1.4 root 1636: ;
1.1.1.2 root 1637: else if (!strcmp (str, "opt"))
1.1.1.4 root 1638: optimize = 1, obey_regdecls = 0;
1639: else if (!strcmp (str, "O"))
1640: optimize = 1, obey_regdecls = 0;
1.1.1.2 root 1641: else if (!strcmp (str, "pedantic"))
1642: pedantic = 1;
1.1.1.7 root 1643: else if (lang_decode_option (argv[i]))
1644: ;
1.1.1.2 root 1645: else if (!strcmp (str, "quiet"))
1646: quiet_flag = 1;
1647: else if (!strcmp (str, "version"))
1648: {
1.1.1.7 root 1649: extern char *version_string, *language_string;
1.1.1.12 root 1650: fprintf (stderr, "%s version %s", language_string, version_string);
1.1.1.2 root 1651: #ifdef TARGET_VERSION
1652: TARGET_VERSION;
1653: #endif
1654: #ifdef __GNUC__
1655: #ifndef __VERSION__
1656: #define __VERSION__ "[unknown]"
1657: #endif
1.1.1.12 root 1658: fprintf (stderr, " compiled by GNU C version %s.\n", __VERSION__);
1.1.1.2 root 1659: #else
1.1.1.12 root 1660: fprintf (stderr, " compiled by CC.\n");
1.1.1.2 root 1661: #endif
1662: }
1.1 root 1663: else if (!strcmp (str, "w"))
1664: inhibit_warnings = 1;
1.1.1.2 root 1665: else if (!strcmp (str, "W"))
1666: extra_warnings = 1;
1.1.1.9 root 1667: else if (!strcmp (str, "Wunused"))
1668: warn_unused = 1;
1.1.1.2 root 1669: else if (!strcmp (str, "p"))
1670: profile_flag = 1;
1.1.1.4 root 1671: else if (!strcmp (str, "gg"))
1672: write_symbols = GDB_DEBUG;
1673: #ifdef DBX_DEBUGGING_INFO
1.1 root 1674: else if (!strcmp (str, "g"))
1.1.1.4 root 1675: write_symbols = DBX_DEBUG;
1.1 root 1676: else if (!strcmp (str, "G"))
1.1.1.4 root 1677: write_symbols = DBX_DEBUG;
1678: #endif
1679: #ifdef SDB_DEBUGGING_INFO
1680: else if (!strcmp (str, "g"))
1681: write_symbols = SDB_DEBUG;
1682: else if (!strcmp (str, "G"))
1683: write_symbols = SDB_DEBUG;
1684: #endif
1.1 root 1685: else if (!strcmp (str, "symout"))
1686: {
1.1.1.4 root 1687: if (write_symbols == NO_DEBUG)
1688: write_symbols = GDB_DEBUG;
1.1 root 1689: sym_file_name = argv[++i];
1690: }
1691: else if (!strcmp (str, "o"))
1692: {
1693: asm_file_name = argv[++i];
1694: }
1695: else
1.1.1.7 root 1696: error ("Invalid option `%s'", argv[i]);
1.1 root 1697: }
1698: else
1699: filename = argv[i];
1700:
1.1.1.2 root 1701: #ifdef OVERRIDE_OPTIONS
1702: /* Some machines may reject certain combinations of options. */
1703: OVERRIDE_OPTIONS;
1704: #endif
1705:
1.1.1.4 root 1706: /* Now that register usage is specified, convert it to HARD_REG_SETs. */
1707: init_reg_sets_1 ();
1708:
1.1 root 1709: compile_file (filename);
1710:
1.1.1.2 root 1711: #ifndef USG
1712: #ifndef VMS
1713: if (print_mem_flag)
1714: {
1715: extern char **environ;
1716: caddr_t lim = (caddr_t) sbrk (0);
1717:
1718: fprintf (stderr, "Data size %d.\n",
1719: (int) lim - (int) &environ);
1720: fflush (stderr);
1721:
1722: system ("ps v");
1723: }
1724: #endif /* not VMS */
1725: #endif /* not USG */
1726:
1.1 root 1727: if (errorcount)
1.1.1.2 root 1728: exit (FATAL_EXIT_CODE);
1.1.1.7 root 1729: if (sorrycount)
1730: exit (FATAL_EXIT_CODE);
1.1.1.2 root 1731: exit (SUCCESS_EXIT_CODE);
1732: return 34;
1.1 root 1733: }
1734:
1735: /* Decode -m switches. */
1736:
1737: /* Here is a table, controlled by the tm-...h file, listing each -m switch
1738: and which bits in `target_switches' it should set or clear.
1739: If VALUE is positive, it is bits to set.
1740: If VALUE is negative, -VALUE is bits to clear.
1741: (The sign bit is not used so there is no confusion.) */
1742:
1743: struct {char *name; int value;} target_switches []
1744: = TARGET_SWITCHES;
1745:
1746: /* Decode the switch -mNAME. */
1747:
1.1.1.2 root 1748: void
1.1 root 1749: set_target_switch (name)
1750: char *name;
1751: {
1.1.1.2 root 1752: register int j;
1.1 root 1753: for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
1754: if (!strcmp (target_switches[j].name, name))
1755: {
1756: if (target_switches[j].value < 0)
1757: target_flags &= ~-target_switches[j].value;
1758: else
1759: target_flags |= target_switches[j].value;
1.1.1.7 root 1760: return;
1.1 root 1761: }
1.1.1.7 root 1762: error ("Invalid option `%s'", name);
1.1 root 1763: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.