|
|
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 root 723:
724: /* Compile an entire file of output from cpp, named NAME.
725: Write a file of assembly output and various debugging dumps. */
726:
727: static void
728: compile_file (name)
729: char *name;
730: {
731: tree globals;
732: int start_time;
1.1.1.9 root 733: int dump_base_name_length;
734:
735: int name_specified = name != 0;
736:
737: if (dump_base_name == 0)
738: dump_base_name = name ? name : "gccdump";
739: dump_base_name_length = strlen (dump_base_name);
1.1 root 740:
741: parse_time = 0;
742: varconst_time = 0;
1.1.1.2 root 743: integration_time = 0;
1.1 root 744: jump_time = 0;
745: cse_time = 0;
746: loop_time = 0;
747: flow_time = 0;
748: combine_time = 0;
749: local_alloc_time = 0;
750: global_alloc_time = 0;
751: final_time = 0;
752: symout_time = 0;
1.1.1.2 root 753: dump_time = 0;
1.1 root 754:
755: /* Open input file. */
756:
1.1.1.9 root 757: if (name == 0 || !strcmp (name, "-"))
758: {
759: finput = stdin;
760: name = "stdin";
761: }
762: else
763: finput = fopen (name, "r");
1.1 root 764: if (finput == 0)
765: pfatal_with_name (name);
766:
767: /* Initialize data in various passes. */
768:
769: init_tree ();
770: init_lex ();
771: init_rtl ();
1.1.1.2 root 772: init_emit_once ();
1.1 root 773: init_decl_processing ();
774: init_optabs ();
775:
776: /* If rtl dump desired, open the output file. */
777: if (rtl_dump)
778: {
779: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
780: strcpy (dumpname, dump_base_name);
781: strcat (dumpname, ".rtl");
782: rtl_dump_file = fopen (dumpname, "w");
783: if (rtl_dump_file == 0)
784: pfatal_with_name (dumpname);
785: }
786:
787: /* If jump_opt dump desired, open the output file. */
788: if (jump_opt_dump)
789: {
790: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
791: strcpy (dumpname, dump_base_name);
792: strcat (dumpname, ".jump");
793: jump_opt_dump_file = fopen (dumpname, "w");
794: if (jump_opt_dump_file == 0)
795: pfatal_with_name (dumpname);
796: }
797:
798: /* If cse dump desired, open the output file. */
799: if (cse_dump)
800: {
801: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
802: strcpy (dumpname, dump_base_name);
803: strcat (dumpname, ".cse");
804: cse_dump_file = fopen (dumpname, "w");
805: if (cse_dump_file == 0)
806: pfatal_with_name (dumpname);
807: }
808:
809: /* If loop dump desired, open the output file. */
810: if (loop_dump)
811: {
812: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
813: strcpy (dumpname, dump_base_name);
814: strcat (dumpname, ".loop");
815: loop_dump_file = fopen (dumpname, "w");
816: if (loop_dump_file == 0)
817: pfatal_with_name (dumpname);
818: }
819:
820: /* If flow dump desired, open the output file. */
821: if (flow_dump)
822: {
823: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
824: strcpy (dumpname, dump_base_name);
825: strcat (dumpname, ".flow");
826: flow_dump_file = fopen (dumpname, "w");
827: if (flow_dump_file == 0)
828: pfatal_with_name (dumpname);
829: }
830:
831: /* If combine dump desired, open the output file. */
832: if (combine_dump)
833: {
834: register char *dumpname = (char *) xmalloc (dump_base_name_length + 10);
835: strcpy (dumpname, dump_base_name);
836: strcat (dumpname, ".combine");
837: combine_dump_file = fopen (dumpname, "w");
838: if (combine_dump_file == 0)
839: pfatal_with_name (dumpname);
840: }
841:
842: /* If local_reg dump desired, open the output file. */
843: if (local_reg_dump)
844: {
845: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
846: strcpy (dumpname, dump_base_name);
847: strcat (dumpname, ".lreg");
848: local_reg_dump_file = fopen (dumpname, "w");
849: if (local_reg_dump_file == 0)
850: pfatal_with_name (dumpname);
851: }
852:
853: /* If global_reg dump desired, open the output file. */
854: if (global_reg_dump)
855: {
856: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
857: strcpy (dumpname, dump_base_name);
858: strcat (dumpname, ".greg");
859: global_reg_dump_file = fopen (dumpname, "w");
860: if (global_reg_dump_file == 0)
861: pfatal_with_name (dumpname);
862: }
863:
1.1.1.2 root 864: /* If jump2_opt dump desired, open the output file. */
865: if (jump2_opt_dump)
866: {
867: register char *dumpname = (char *) xmalloc (dump_base_name_length + 7);
868: strcpy (dumpname, dump_base_name);
869: strcat (dumpname, ".jump2");
870: jump2_opt_dump_file = fopen (dumpname, "w");
871: if (jump2_opt_dump_file == 0)
872: pfatal_with_name (dumpname);
873: }
874:
1.1 root 875: /* Open assembler code output file. */
876:
1.1.1.9 root 877: if (! name_specified && asm_file_name == 0)
878: asm_out_file = stdout;
879: else
880: {
881: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
882: int len = strlen (dump_base_name);
883: strcpy (dumpname, dump_base_name);
884: if (len > 2 && ! strcmp (".c", dumpname + len - 2))
885: dumpname[len - 2] = 0;
886: else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
887: dumpname[len - 2] = 0;
888: else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
889: dumpname[len - 3] = 0;
890: strcat (dumpname, ".s");
891: if (asm_file_name == 0)
892: {
893: asm_file_name = (char *) malloc (strlen (dumpname) + 1);
894: strcpy (asm_file_name, dumpname);
895: }
896: if (!strcmp (asm_file_name, "-"))
897: asm_out_file = stdout;
898: else
899: asm_out_file = fopen (asm_file_name, "w");
900: if (asm_out_file == 0)
901: pfatal_with_name (asm_file_name);
902: }
1.1 root 903:
904: input_filename = name;
905:
906: /* the beginning of the file is a new line; check for # */
907: /* With luck, we discover the real source file's name from that
908: and put it in input_filename. */
1.1.1.4 root 909: ungetc (check_newline (), finput);
910:
1.1.1.8 root 911: /* If the input doesn't start with a #line, use the input name
912: as the official input file name. */
913: if (main_input_filename == 0)
914: main_input_filename = name;
915:
1.1.1.4 root 916: ASM_FILE_START (asm_out_file);
1.1 root 917:
1.1.1.12! root 918: /* Output something to inform GDB that this compilation was by GCC. */
! 919: #ifndef ASM_IDENTIFY_GCC
! 920: fprintf (asm_out_file, "gcc_compiled.:\n");
! 921: #else
! 922: ASM_IDENTIFY_GCC (asm_out_file);
! 923: #endif
! 924:
1.1 root 925: /* If GDB symbol table desired, open the GDB symbol output file. */
1.1.1.4 root 926: if (write_symbols == GDB_DEBUG)
1.1 root 927: {
928: register char *dumpname = (char *) xmalloc (dump_base_name_length + 6);
1.1.1.2 root 929: int len = strlen (dump_base_name);
1.1 root 930: strcpy (dumpname, dump_base_name);
1.1.1.2 root 931: if (len > 2 && ! strcmp (".c", dumpname + len - 2))
932: dumpname[len - 2] = 0;
1.1.1.7 root 933: else if (len > 2 && ! strcmp (".i", dumpname + len - 2))
934: dumpname[len - 2] = 0;
1.1.1.2 root 935: else if (len > 3 && ! strcmp (".co", dumpname + len - 3))
936: dumpname[len - 3] = 0;
1.1 root 937: strcat (dumpname, ".sym");
938: if (sym_file_name == 0)
939: sym_file_name = dumpname;
1.1.1.4 root 940: symout_init (sym_file_name, asm_out_file, main_input_filename);
1.1 root 941: }
942:
943: /* If dbx symbol table desired, initialize writing it
944: and output the predefined types. */
1.1.1.4 root 945: #ifdef DBX_DEBUGGING_INFO
946: if (write_symbols == DBX_DEBUG)
1.1.1.2 root 947: dbxout_init (asm_out_file, main_input_filename);
1.1.1.4 root 948: #endif
949: #ifdef SDB_DEBUGGING_INFO
950: if (write_symbols == SDB_DEBUG)
951: sdbout_init (asm_out_file, main_input_filename);
952: #endif
1.1 root 953:
954: /* Initialize yet another pass. */
955:
1.1.1.2 root 956: init_final (main_input_filename);
1.1 root 957:
958: start_time = gettime ();
959:
960: /* Call the parser, which parses the entire file
961: (calling rest_of_compilation for each function). */
962:
963: yyparse ();
964:
965: /* Compilation is now finished except for writing
966: what's left of the symbol table output. */
967:
968: parse_time += gettime () - start_time;
969:
1.1.1.2 root 970: parse_time -= varconst_time;
971:
1.1 root 972: globals = getdecls ();
973:
1.1.1.2 root 974: /* Really define vars that have had only a tentative definition.
975: Really output inline functions that must actually be callable
976: and have not been output so far. */
977:
978: {
979: tree decl;
980: for (decl = globals; decl; decl = TREE_CHAIN (decl))
981: {
982: if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
983: && ! TREE_ASM_WRITTEN (decl))
984: rest_of_decl_compilation (decl, 0, 1, 1);
985: if (TREE_CODE (decl) == FUNCTION_DECL
986: && ! TREE_ASM_WRITTEN (decl)
987: && DECL_INITIAL (decl) != 0
988: && TREE_ADDRESSABLE (decl))
989: output_inline_function (decl);
990: }
991: }
992:
1.1 root 993: /* Do dbx symbols */
1.1.1.4 root 994: #ifdef DBX_DEBUGGING_INFO
995: if (write_symbols == DBX_DEBUG)
1.1 root 996: TIMEVAR (symout_time,
997: {
998: dbxout_tags (gettags ());
999: dbxout_types (get_permanent_types ());
1000: });
1.1.1.4 root 1001: #endif
1002:
1003: #ifdef SDB_DEBUGGING_INFO
1004: if (write_symbols == SDB_DEBUG)
1005: TIMEVAR (symout_time,
1006: {
1007: sdbout_tags (gettags ());
1008: sdbout_types (get_permanent_types ());
1009: });
1010: #endif
1.1 root 1011:
1012: /* Do gdb symbols */
1.1.1.4 root 1013: if (write_symbols == GDB_DEBUG)
1.1 root 1014: TIMEVAR (symout_time,
1015: {
1016: struct stat statbuf;
1017: fstat (fileno (finput), &statbuf);
1018: symout_types (get_permanent_types ());
1019: symout_top_blocks (globals, gettags ());
1020: symout_finish (name, statbuf.st_ctime);
1021: });
1022:
1.1.1.2 root 1023: /* Close the dump files. */
1.1 root 1024:
1025: if (rtl_dump)
1026: fclose (rtl_dump_file);
1027:
1028: if (jump_opt_dump)
1029: fclose (jump_opt_dump_file);
1030:
1031: if (cse_dump)
1032: fclose (cse_dump_file);
1033:
1034: if (loop_dump)
1035: fclose (loop_dump_file);
1036:
1037: if (flow_dump)
1038: fclose (flow_dump_file);
1039:
1040: if (combine_dump)
1041: {
1042: dump_combine_total_stats (combine_dump_file);
1043: fclose (combine_dump_file);
1044: }
1045:
1046: if (local_reg_dump)
1047: fclose (local_reg_dump_file);
1048:
1049: if (global_reg_dump)
1050: fclose (global_reg_dump_file);
1051:
1.1.1.2 root 1052: if (jump2_opt_dump)
1053: fclose (jump2_opt_dump_file);
1054:
1055: /* Close non-debugging input and output files. */
1056:
1057: fclose (finput);
1058: if (ferror (asm_out_file) != 0)
1059: fatal_io_error (asm_file_name);
1060: fclose (asm_out_file);
1061:
1.1 root 1062: /* Print the times. */
1063:
1064: if (! quiet_flag)
1065: {
1.1.1.2 root 1066: fprintf (stderr,"\n");
1.1 root 1067: print_time ("parse", parse_time);
1.1.1.2 root 1068: print_time ("integration", integration_time);
1.1 root 1069: print_time ("jump", jump_time);
1070: print_time ("cse", cse_time);
1071: print_time ("loop", loop_time);
1072: print_time ("flow", flow_time);
1073: print_time ("combine", combine_time);
1074: print_time ("local-alloc", local_alloc_time);
1075: print_time ("global-alloc", global_alloc_time);
1076: print_time ("final", final_time);
1077: print_time ("varconst", varconst_time);
1078: print_time ("symout", symout_time);
1079: print_time ("dump", dump_time);
1080: }
1081: }
1082:
1.1.1.2 root 1083: /* This is called from finish_decl (within yyparse)
1084: for each declaration of a function or variable.
1085: This does nothing for automatic variables.
1086: Otherwise, it sets up the RTL and outputs any assembler code
1087: (label definition, storage allocation and initialization).
1088:
1089: DECL is the declaration. If ASMSPEC is nonzero, it specifies
1090: the assembler symbol name to be used. TOP_LEVEL is nonzero
1091: if this declaration is not within a function. */
1092:
1093: void
1094: rest_of_decl_compilation (decl, asmspec, top_level, at_end)
1095: tree decl;
1096: tree asmspec;
1097: int top_level;
1098: int at_end;
1099: {
1100: /* Declarations of variables, and of functions defined elsewhere. */
1101:
1102: if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
1103: TIMEVAR (varconst_time,
1104: {
1.1.1.12! root 1105: make_decl_rtl (decl, asmspec, top_level);
! 1106: /* Don't output anything
! 1107: when a tentative file-scope definition is seen.
! 1108: But at end of compilation, do output code for them. */
! 1109: if (! (! at_end && top_level
! 1110: && (DECL_INITIAL (decl) == 0
! 1111: || DECL_INITIAL (decl) == error_mark_node)))
! 1112: assemble_variable (decl, top_level, write_symbols, at_end);
1.1.1.2 root 1113: });
1.1.1.4 root 1114: #ifdef DBX_DEBUGGING_INFO
1115: else if (write_symbols == DBX_DEBUG && TREE_CODE (decl) == TYPE_DECL)
1.1.1.3 root 1116: TIMEVAR (varconst_time, dbxout_symbol (decl, 0));
1.1.1.4 root 1117: #endif
1118: #ifdef SDB_DEBUGGING_INFO
1119: else if (write_symbols == SDB_DEBUG && TREE_CODE (decl) == TYPE_DECL)
1120: TIMEVAR (varconst_time, sdbout_symbol (decl, 0));
1121: #endif
1.1.1.2 root 1122:
1123: if (top_level)
1124: {
1.1.1.4 root 1125: if (write_symbols == GDB_DEBUG)
1.1.1.2 root 1126: {
1127: TIMEVAR (symout_time,
1128: {
1129: /* The initizations make types when they contain
1130: string constants. The types are on the temporary
1131: obstack, so output them now before they go away. */
1132: symout_types (get_temporary_types ());
1133: });
1134: }
1135: else
1136: /* Clean out the temporary type list, since the types will go away. */
1137: get_temporary_types ();
1138: }
1139: }
1140:
1.1 root 1141: /* This is called from finish_function (within yyparse)
1.1.1.2 root 1142: after each top-level definition is parsed.
1.1 root 1143: It is supposed to compile that function or variable
1144: and output the assembler code for it.
1145: After we return, the tree storage is freed. */
1146:
1147: void
1.1.1.2 root 1148: rest_of_compilation (decl)
1.1 root 1149: tree decl;
1150: {
1151: register rtx insns;
1152: int start_time = gettime ();
1153: int tem;
1154:
1.1.1.2 root 1155: /* If we are reconsidering an inline function
1156: at the end of compilation, skip the stuff for making it inline. */
1.1 root 1157:
1.1.1.2 root 1158: if (DECL_SAVED_INSNS (decl) == 0)
1.1 root 1159: {
1160:
1.1.1.2 root 1161: /* If requested, consider whether to make this function inline. */
1162: if (flag_inline_functions || TREE_INLINE (decl))
1163: {
1164: TIMEVAR (integration_time,
1165: {
1166: int specd = TREE_INLINE (decl);
1167: char *lose = function_cannot_inline_p (decl);
1168: if (lose != 0 && specd)
1169: warning_with_decl (decl, lose);
1170: if (lose == 0)
1171: save_for_inline (decl);
1172: else
1173: TREE_INLINE (decl) = 0;
1174: });
1175: }
1.1 root 1176:
1.1.1.2 root 1177: insns = get_insns ();
1.1 root 1178:
1179: /* Dump the rtl code if we are dumping rtl. */
1180:
1181: if (rtl_dump)
1182: TIMEVAR (dump_time,
1183: {
1184: fprintf (rtl_dump_file, "\n;; Function %s\n\n",
1185: IDENTIFIER_POINTER (DECL_NAME (decl)));
1.1.1.2 root 1186: if (DECL_SAVED_INSNS (decl))
1187: fprintf (rtl_dump_file, ";; (integrable)\n\n");
1.1 root 1188: print_rtl (rtl_dump_file, insns);
1189: fflush (rtl_dump_file);
1190: });
1191:
1.1.1.2 root 1192: /* If function is inline, and we don't yet know whether to
1193: compile it by itself, defer decision till end of compilation.
1194: finish_compilation will call rest_of_compilation again
1195: for those functions that need to be output. */
1196:
1197: if (TREE_PUBLIC (decl) == 0
1198: && TREE_INLINE (decl)
1199: && ! flag_keep_inline_functions)
1.1 root 1200: goto exit_rest_of_compilation;
1.1.1.2 root 1201: }
1.1 root 1202:
1.1.1.2 root 1203: if (rtl_dump_and_exit)
1204: goto exit_rest_of_compilation;
1.1 root 1205:
1.1.1.2 root 1206: TREE_ASM_WRITTEN (decl) = 1;
1.1 root 1207:
1.1.1.2 root 1208: insns = get_insns ();
1.1 root 1209:
1.1.1.2 root 1210: /* Copy any shared structure that should not be shared. */
1.1 root 1211:
1.1.1.2 root 1212: unshare_all_rtl (insns);
1.1 root 1213:
1.1.1.2 root 1214: /* See if we have allocated stack slots that are not directly addressable.
1215: If so, scan all the insns and create explicit address computation
1216: for all references to such slots. */
1217: /* fixup_stack_slots (); */
1.1 root 1218:
1.1.1.2 root 1219: /* Do jump optimization the first time, if -opt.
1220: Also do it if -W, but in that case it doesn't change the rtl code,
1221: it only computes whether control can drop off the end of the function. */
1.1 root 1222:
1.1.1.2 root 1223: if (optimize || extra_warnings || warn_return_type)
1224: TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
1.1 root 1225:
1.1.1.2 root 1226: /* Dump rtl code after jump, if we are doing that. */
1.1 root 1227:
1.1.1.2 root 1228: if (jump_opt_dump)
1229: TIMEVAR (dump_time,
1230: {
1231: fprintf (jump_opt_dump_file, "\n;; Function %s\n\n",
1232: IDENTIFIER_POINTER (DECL_NAME (decl)));
1233: print_rtl (jump_opt_dump_file, insns);
1234: fflush (jump_opt_dump_file);
1235: });
1.1 root 1236:
1.1.1.2 root 1237: /* Perform common subexpression elimination.
1238: Nonzero value from `cse_main' means that jumps were simplified
1239: and some code may now be unreachable, so do
1240: jump optimization again. */
1.1 root 1241:
1.1.1.2 root 1242: if (optimize)
1243: {
1244: TIMEVAR (cse_time, reg_scan (insns, max_reg_num (), 0));
1.1 root 1245:
1.1.1.2 root 1246: TIMEVAR (cse_time, tem = cse_main (insns, max_reg_num ()));
1.1 root 1247:
1.1.1.2 root 1248: if (tem)
1249: TIMEVAR (jump_time, jump_optimize (insns, 0, 0));
1250: }
1.1 root 1251:
1.1.1.2 root 1252: /* Dump rtl code after cse, if we are doing that. */
1.1 root 1253:
1.1.1.2 root 1254: if (cse_dump)
1255: TIMEVAR (dump_time,
1256: {
1257: fprintf (cse_dump_file, "\n;; Function %s\n\n",
1258: IDENTIFIER_POINTER (DECL_NAME (decl)));
1259: print_rtl (cse_dump_file, insns);
1260: fflush (cse_dump_file);
1261: });
1.1 root 1262:
1.1.1.2 root 1263: if (loop_dump)
1264: TIMEVAR (dump_time,
1265: {
1266: fprintf (loop_dump_file, "\n;; Function %s\n\n",
1267: IDENTIFIER_POINTER (DECL_NAME (decl)));
1268: });
1.1 root 1269:
1.1.1.2 root 1270: /* Move constant computations out of loops. */
1.1 root 1271:
1.1.1.2 root 1272: if (optimize)
1273: {
1274: TIMEVAR (loop_time,
1275: {
1276: reg_scan (insns, max_reg_num (), 1);
1.1.1.9 root 1277: loop_optimize (insns, loop_dump ? loop_dump_file : 0);
1.1.1.2 root 1278: });
1279: }
1.1 root 1280:
1.1.1.2 root 1281: /* Dump rtl code after loop opt, if we are doing that. */
1.1 root 1282:
1.1.1.2 root 1283: if (loop_dump)
1284: TIMEVAR (dump_time,
1285: {
1286: print_rtl (loop_dump_file, insns);
1287: fflush (loop_dump_file);
1288: });
1.1 root 1289:
1.1.1.2 root 1290: /* Now we choose between stupid (pcc-like) register allocation
1291: (if we got the -noreg switch and not -opt)
1292: and smart register allocation. */
1.1 root 1293:
1.1.1.2 root 1294: if (optimize) /* Stupid allocation probably won't work */
1295: obey_regdecls = 0; /* if optimizations being done. */
1.1 root 1296:
1.1.1.2 root 1297: regclass_init ();
1.1 root 1298:
1.1.1.2 root 1299: /* Print function header into flow dump now
1300: because doing the flow analysis makes some of the dump. */
1.1 root 1301:
1.1.1.2 root 1302: if (flow_dump)
1303: TIMEVAR (dump_time,
1304: {
1305: fprintf (flow_dump_file, "\n;; Function %s\n\n",
1306: IDENTIFIER_POINTER (DECL_NAME (decl)));
1307: });
1308:
1309: if (obey_regdecls)
1310: {
1311: TIMEVAR (flow_time,
1312: {
1313: regclass (insns, max_reg_num ());
1314: stupid_life_analysis (insns, max_reg_num (),
1315: flow_dump_file);
1316: });
1317: }
1318: else
1319: {
1320: /* Do control and data flow analysis,
1321: and write some of the results to dump file. */
1.1 root 1322:
1.1.1.2 root 1323: TIMEVAR (flow_time, flow_analysis (insns, max_reg_num (),
1324: flow_dump_file));
1325: if (extra_warnings)
1326: uninitialized_vars_warning (DECL_INITIAL (decl));
1327: }
1.1 root 1328:
1.1.1.2 root 1329: /* Dump rtl after flow analysis. */
1.1 root 1330:
1.1.1.2 root 1331: if (flow_dump)
1332: TIMEVAR (dump_time,
1333: {
1334: print_rtl (flow_dump_file, insns);
1335: fflush (flow_dump_file);
1336: });
1.1 root 1337:
1.1.1.2 root 1338: /* If -opt, try combining insns through substitution. */
1.1 root 1339:
1.1.1.2 root 1340: if (optimize)
1341: TIMEVAR (combine_time, combine_instructions (insns, max_reg_num ()));
1.1 root 1342:
1.1.1.2 root 1343: /* Dump rtl code after insn combination. */
1.1 root 1344:
1.1.1.2 root 1345: if (combine_dump)
1346: TIMEVAR (dump_time,
1347: {
1348: fprintf (combine_dump_file, "\n;; Function %s\n\n",
1349: IDENTIFIER_POINTER (DECL_NAME (decl)));
1350: dump_combine_stats (combine_dump_file);
1351: print_rtl (combine_dump_file, insns);
1352: fflush (combine_dump_file);
1353: });
1.1 root 1354:
1.1.1.2 root 1355: /* Unless we did stupid register allocation,
1356: allocate pseudo-regs that are used only within 1 basic block. */
1.1 root 1357:
1.1.1.2 root 1358: if (!obey_regdecls)
1359: TIMEVAR (local_alloc_time,
1360: {
1361: regclass (insns, max_reg_num ());
1362: local_alloc ();
1363: });
1.1 root 1364:
1.1.1.2 root 1365: /* Dump rtl code after allocating regs within basic blocks. */
1.1 root 1366:
1.1.1.2 root 1367: if (local_reg_dump)
1368: TIMEVAR (dump_time,
1369: {
1370: fprintf (local_reg_dump_file, "\n;; Function %s\n\n",
1371: IDENTIFIER_POINTER (DECL_NAME (decl)));
1372: dump_flow_info (local_reg_dump_file);
1373: dump_local_alloc (local_reg_dump_file);
1374: print_rtl (local_reg_dump_file, insns);
1375: fflush (local_reg_dump_file);
1376: });
1.1 root 1377:
1.1.1.2 root 1378: if (global_reg_dump)
1379: TIMEVAR (dump_time,
1380: fprintf (global_reg_dump_file, "\n;; Function %s\n\n",
1381: IDENTIFIER_POINTER (DECL_NAME (decl))));
1382:
1383: /* Unless we did stupid register allocation,
1384: allocate remaining pseudo-regs, then do the reload pass
1385: fixing up any insns that are invalid. */
1386:
1387: TIMEVAR (global_alloc_time,
1388: {
1389: if (!obey_regdecls)
1390: global_alloc (global_reg_dump ? global_reg_dump_file : 0);
1391: else
1392: reload (insns, 0,
1393: global_reg_dump ? global_reg_dump_file : 0);
1394: });
1395:
1396: if (global_reg_dump)
1397: TIMEVAR (dump_time,
1398: {
1399: dump_global_regs (global_reg_dump_file);
1400: print_rtl (global_reg_dump_file, insns);
1401: fflush (global_reg_dump_file);
1402: });
1.1 root 1403:
1.1.1.12! root 1404: rtx_equal_function_value_matters = 1;
1.1.1.11 root 1405: reload_completed = 1;
1406:
1.1.1.2 root 1407: /* One more attempt to remove jumps to .+1
1408: left by dead-store-elimination.
1409: Also do cross-jumping this time
1410: and delete no-op move insns. */
1.1 root 1411:
1.1.1.2 root 1412: if (optimize)
1413: {
1414: TIMEVAR (jump_time, jump_optimize (insns, 1, 1));
1415: }
1.1 root 1416:
1.1.1.2 root 1417: /* Dump rtl code after jump, if we are doing that. */
1418:
1419: if (jump2_opt_dump)
1420: TIMEVAR (dump_time,
1421: {
1422: fprintf (jump2_opt_dump_file, "\n;; Function %s\n\n",
1423: IDENTIFIER_POINTER (DECL_NAME (decl)));
1424: print_rtl (jump2_opt_dump_file, insns);
1425: fflush (jump2_opt_dump_file);
1426: });
1427:
1428: /* Now turn the rtl into assembler code. */
1429:
1430: TIMEVAR (final_time,
1431: {
1432: assemble_function (decl);
1433: final_start_function (insns, asm_out_file,
1434: write_symbols, optimize);
1435: final (insns, asm_out_file,
1.1.1.9 root 1436: write_symbols, optimize, 0);
1.1.1.2 root 1437: final_end_function (insns, asm_out_file,
1438: write_symbols, optimize);
1439: fflush (asm_out_file);
1440: });
1.1 root 1441:
1.1.1.2 root 1442: /* Write GDB symbols if requested */
1.1 root 1443:
1.1.1.4 root 1444: if (write_symbols == GDB_DEBUG)
1.1.1.2 root 1445: {
1446: TIMEVAR (symout_time,
1447: {
1448: symout_types (get_permanent_types ());
1449: symout_types (get_temporary_types ());
1450:
1451: DECL_BLOCK_SYMTAB_ADDRESS (decl)
1452: = symout_function (DECL_INITIAL (decl),
1453: DECL_ARGUMENTS (decl), 0);
1.1.1.6 root 1454: symout_function_end ();
1.1.1.2 root 1455: });
1.1 root 1456: }
1.1.1.2 root 1457: else
1458: get_temporary_types ();
1459:
1460: /* Write DBX symbols if requested */
1461:
1.1.1.4 root 1462: #ifdef DBX_DEBUGGING_INFO
1463: if (write_symbols == DBX_DEBUG)
1.1.1.2 root 1464: TIMEVAR (symout_time, dbxout_function (decl));
1.1.1.4 root 1465: #endif
1.1 root 1466:
1467: exit_rest_of_compilation:
1468:
1.1.1.12! root 1469: rtx_equal_function_value_matters = 0;
1.1.1.11 root 1470: reload_completed = 0;
1471:
1.1.1.8 root 1472: /* Clear out the real_constant_chain before some of the rtx's
1473: it runs through become garbage. */
1474:
1475: clear_const_double_mem ();
1476:
1.1 root 1477: /* The parsing time is all the time spent in yyparse
1478: *except* what is spent in this function. */
1479:
1480: parse_time -= gettime () - start_time;
1481: }
1482:
1483: /* Entry point of cc1. Decode command args, then call compile_file.
1.1.1.2 root 1484: Exit code is 35 if can't open files, 34 if fatal error,
1485: 33 if had nonfatal errors, else success. */
1.1 root 1486:
1487: int
1488: main (argc, argv, envp)
1489: int argc;
1490: char **argv;
1491: char **envp;
1492: {
1493: register int i;
1.1.1.2 root 1494: char *filename = 0;
1495: int print_mem_flag = 0;
1496:
1497: #ifdef RLIMIT_STACK
1498: /* Get rid of any avoidable limit on stack size. */
1499: {
1500: struct rlimit rlim;
1501:
1502: /* Set the stack limit huge so that alloca does not fail. */
1503: getrlimit (RLIMIT_STACK, &rlim);
1504: rlim.rlim_cur = rlim.rlim_max;
1505: setrlimit (RLIMIT_STACK, &rlim);
1506: }
1507: #endif /* RLIMIT_STACK */
1508:
1.1.1.10 root 1509: signal (SIGFPE, float_signal);
1510:
1.1.1.2 root 1511: /* Initialize whether `char' is signed. */
1512: flag_signed_char = DEFAULT_SIGNED_CHAR;
1513:
1.1.1.4 root 1514: /* This is zeroed by -O. */
1515: obey_regdecls = 1;
1516:
1517: /* Initialize register usage now so switches may override. */
1.1.1.2 root 1518: init_reg_sets ();
1.1 root 1519:
1520: target_flags = 0;
1521: set_target_switch ("");
1522:
1523: for (i = 1; i < argc; i++)
1524: if (argv[i][0] == '-')
1525: {
1526: register char *str = argv[i] + 1;
1527: if (str[0] == 'Y')
1528: str++;
1529:
1530: if (str[0] == 'm')
1531: set_target_switch (&str[1]);
1532: else if (!strcmp (str, "dumpbase"))
1533: {
1534: dump_base_name = argv[++i];
1535: }
1536: else if (str[0] == 'd')
1537: {
1538: register char *p = &str[1];
1539: while (*p)
1540: switch (*p++)
1541: {
1542: case 'c':
1543: combine_dump = 1;
1544: break;
1545: case 'f':
1546: flow_dump = 1;
1547: break;
1548: case 'g':
1549: global_reg_dump = 1;
1550: break;
1551: case 'j':
1552: jump_opt_dump = 1;
1553: break;
1.1.1.2 root 1554: case 'J':
1555: jump2_opt_dump = 1;
1556: break;
1.1 root 1557: case 'l':
1558: local_reg_dump = 1;
1559: break;
1560: case 'L':
1561: loop_dump = 1;
1562: break;
1.1.1.2 root 1563: case 'm':
1564: print_mem_flag = 1;
1565: break;
1.1 root 1566: case 'r':
1567: rtl_dump = 1;
1568: break;
1569: case 's':
1570: cse_dump = 1;
1571: break;
1572: case 'y':
1573: yydebug = 1;
1574: break;
1575: }
1576: }
1.1.1.2 root 1577: else if (str[0] == 'f')
1578: {
1.1.1.12! root 1579: int j;
1.1.1.2 root 1580: register char *p = &str[1];
1.1.1.12! root 1581: int found = 0;
! 1582:
! 1583: /* Some kind of -f option.
! 1584: P's value is the option sans `-f'.
! 1585: Search for it in the table of options. */
! 1586:
! 1587: for (j = 0;
! 1588: !found && j < sizeof (f_options) / sizeof (f_options[0]);
! 1589: j++)
! 1590: {
! 1591: if (!strcmp (p, f_options[j].string))
! 1592: {
! 1593: *f_options[j].variable = f_options[j].on_value;
! 1594: /* A goto here would be cleaner,
! 1595: but breaks the vax pcc. */
! 1596: found = 1;
! 1597: }
! 1598: if (p[0] == 'n' && p[1] == 'o' && p[3] == '-'
! 1599: && ! strcmp (p+3, f_options[j].string))
! 1600: {
! 1601: *f_options[j].variable = ! f_options[j].on_value;
! 1602: found = 1;
! 1603: }
! 1604: }
! 1605:
! 1606: if (found)
! 1607: ;
1.1.1.2 root 1608: else if (!strncmp (p, "fixed-", 6))
1609: fix_register (&p[6], 1, 1);
1610: else if (!strncmp (p, "call-used-", 10))
1611: fix_register (&p[10], 0, 1);
1612: else if (!strncmp (p, "call-saved-", 11))
1613: fix_register (&p[11], 0, 0);
1.1.1.7 root 1614: else if (! lang_decode_option (argv[i]))
1615: error ("Invalid option `%s'", argv[i]);
1.1.1.2 root 1616: }
1.1 root 1617: else if (!strcmp (str, "noreg"))
1.1.1.4 root 1618: ;
1.1.1.2 root 1619: else if (!strcmp (str, "opt"))
1.1.1.4 root 1620: optimize = 1, obey_regdecls = 0;
1621: else if (!strcmp (str, "O"))
1622: optimize = 1, obey_regdecls = 0;
1.1.1.2 root 1623: else if (!strcmp (str, "pedantic"))
1624: pedantic = 1;
1.1.1.7 root 1625: else if (lang_decode_option (argv[i]))
1626: ;
1.1.1.2 root 1627: else if (!strcmp (str, "quiet"))
1628: quiet_flag = 1;
1629: else if (!strcmp (str, "version"))
1630: {
1.1.1.7 root 1631: extern char *version_string, *language_string;
1.1.1.12! root 1632: fprintf (stderr, "%s version %s", language_string, version_string);
1.1.1.2 root 1633: #ifdef TARGET_VERSION
1634: TARGET_VERSION;
1635: #endif
1636: #ifdef __GNUC__
1637: #ifndef __VERSION__
1638: #define __VERSION__ "[unknown]"
1639: #endif
1.1.1.12! root 1640: fprintf (stderr, " compiled by GNU C version %s.\n", __VERSION__);
1.1.1.2 root 1641: #else
1.1.1.12! root 1642: fprintf (stderr, " compiled by CC.\n");
1.1.1.2 root 1643: #endif
1644: }
1.1 root 1645: else if (!strcmp (str, "w"))
1646: inhibit_warnings = 1;
1.1.1.2 root 1647: else if (!strcmp (str, "W"))
1648: extra_warnings = 1;
1.1.1.9 root 1649: else if (!strcmp (str, "Wunused"))
1650: warn_unused = 1;
1.1.1.2 root 1651: else if (!strcmp (str, "p"))
1652: profile_flag = 1;
1.1.1.4 root 1653: else if (!strcmp (str, "gg"))
1654: write_symbols = GDB_DEBUG;
1655: #ifdef DBX_DEBUGGING_INFO
1.1 root 1656: else if (!strcmp (str, "g"))
1.1.1.4 root 1657: write_symbols = DBX_DEBUG;
1.1 root 1658: else if (!strcmp (str, "G"))
1.1.1.4 root 1659: write_symbols = DBX_DEBUG;
1660: #endif
1661: #ifdef SDB_DEBUGGING_INFO
1662: else if (!strcmp (str, "g"))
1663: write_symbols = SDB_DEBUG;
1664: else if (!strcmp (str, "G"))
1665: write_symbols = SDB_DEBUG;
1666: #endif
1.1 root 1667: else if (!strcmp (str, "symout"))
1668: {
1.1.1.4 root 1669: if (write_symbols == NO_DEBUG)
1670: write_symbols = GDB_DEBUG;
1.1 root 1671: sym_file_name = argv[++i];
1672: }
1673: else if (!strcmp (str, "o"))
1674: {
1675: asm_file_name = argv[++i];
1676: }
1677: else
1.1.1.7 root 1678: error ("Invalid option `%s'", argv[i]);
1.1 root 1679: }
1680: else
1681: filename = argv[i];
1682:
1.1.1.2 root 1683: #ifdef OVERRIDE_OPTIONS
1684: /* Some machines may reject certain combinations of options. */
1685: OVERRIDE_OPTIONS;
1686: #endif
1687:
1.1.1.4 root 1688: /* Now that register usage is specified, convert it to HARD_REG_SETs. */
1689: init_reg_sets_1 ();
1690:
1.1 root 1691: compile_file (filename);
1692:
1.1.1.2 root 1693: #ifndef USG
1694: #ifndef VMS
1695: if (print_mem_flag)
1696: {
1697: extern char **environ;
1698: caddr_t lim = (caddr_t) sbrk (0);
1699:
1700: fprintf (stderr, "Data size %d.\n",
1701: (int) lim - (int) &environ);
1702: fflush (stderr);
1703:
1704: system ("ps v");
1705: }
1706: #endif /* not VMS */
1707: #endif /* not USG */
1708:
1.1 root 1709: if (errorcount)
1.1.1.2 root 1710: exit (FATAL_EXIT_CODE);
1.1.1.7 root 1711: if (sorrycount)
1712: exit (FATAL_EXIT_CODE);
1.1.1.2 root 1713: exit (SUCCESS_EXIT_CODE);
1714: return 34;
1.1 root 1715: }
1716:
1717: /* Decode -m switches. */
1718:
1719: /* Here is a table, controlled by the tm-...h file, listing each -m switch
1720: and which bits in `target_switches' it should set or clear.
1721: If VALUE is positive, it is bits to set.
1722: If VALUE is negative, -VALUE is bits to clear.
1723: (The sign bit is not used so there is no confusion.) */
1724:
1725: struct {char *name; int value;} target_switches []
1726: = TARGET_SWITCHES;
1727:
1728: /* Decode the switch -mNAME. */
1729:
1.1.1.2 root 1730: void
1.1 root 1731: set_target_switch (name)
1732: char *name;
1733: {
1.1.1.2 root 1734: register int j;
1.1 root 1735: for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
1736: if (!strcmp (target_switches[j].name, name))
1737: {
1738: if (target_switches[j].value < 0)
1739: target_flags &= ~-target_switches[j].value;
1740: else
1741: target_flags |= target_switches[j].value;
1.1.1.7 root 1742: return;
1.1 root 1743: }
1.1.1.7 root 1744: error ("Invalid option `%s'", name);
1.1 root 1745: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.