Mercurial > hg > CbC > CbC_gcc
annotate gcc/toplev.c @ 37:d096b2ff82d9
Added tag gcc.4.4.2 for changeset 855418dad1a3
author | e075725 |
---|---|
date | Tue, 22 Dec 2009 21:52:56 +0900 |
parents | 58ad6c70ea60 |
children | 77e2b8dfacca |
rev | line source |
---|---|
0 | 1 /* Top level of GCC compilers (cc1, cc1plus, etc.) |
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | |
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 | |
4 Free Software Foundation, Inc. | |
5 | |
6 This file is part of GCC. | |
7 | |
8 GCC is free software; you can redistribute it and/or modify it under | |
9 the terms of the GNU General Public License as published by the Free | |
10 Software Foundation; either version 3, or (at your option) any later | |
11 version. | |
12 | |
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with GCC; see the file COPYING3. If not see | |
20 <http://www.gnu.org/licenses/>. */ | |
21 | |
22 /* This is the top level of cc1/c++. | |
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 #undef FLOAT /* This is for hpux. They should change hpux. */ | |
29 #undef FFS /* Some systems define this in param.h. */ | |
30 #include "system.h" | |
31 #include "coretypes.h" | |
32 #include "tm.h" | |
33 #include <signal.h> | |
34 | |
35 #ifdef HAVE_SYS_RESOURCE_H | |
36 # include <sys/resource.h> | |
37 #endif | |
38 | |
39 #ifdef HAVE_SYS_TIMES_H | |
40 # include <sys/times.h> | |
41 #endif | |
42 | |
43 #include "line-map.h" | |
44 #include "input.h" | |
45 #include "tree.h" | |
46 #include "version.h" | |
47 #include "rtl.h" | |
48 #include "tm_p.h" | |
49 #include "flags.h" | |
50 #include "insn-attr.h" | |
51 #include "insn-config.h" | |
52 #include "insn-flags.h" | |
53 #include "hard-reg-set.h" | |
54 #include "recog.h" | |
55 #include "output.h" | |
56 #include "except.h" | |
57 #include "function.h" | |
58 #include "toplev.h" | |
59 #include "expr.h" | |
60 #include "basic-block.h" | |
61 #include "intl.h" | |
62 #include "ggc.h" | |
63 #include "graph.h" | |
64 #include "regs.h" | |
65 #include "timevar.h" | |
66 #include "diagnostic.h" | |
67 #include "params.h" | |
68 #include "reload.h" | |
69 #include "ira.h" | |
70 #include "dwarf2asm.h" | |
71 #include "integrate.h" | |
72 #include "real.h" | |
73 #include "debug.h" | |
74 #include "target.h" | |
75 #include "langhooks.h" | |
76 #include "cfglayout.h" | |
77 #include "cfgloop.h" | |
78 #include "hosthooks.h" | |
79 #include "cgraph.h" | |
80 #include "opts.h" | |
81 #include "coverage.h" | |
82 #include "value-prof.h" | |
83 #include "alloc-pool.h" | |
84 #include "tree-mudflap.h" | |
85 #include "tree-pass.h" | |
86 #include "gimple.h" | |
87 | |
88 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO) | |
89 #include "dwarf2out.h" | |
90 #endif | |
91 | |
92 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) | |
93 #include "dbxout.h" | |
94 #endif | |
95 | |
96 #ifdef SDB_DEBUGGING_INFO | |
97 #include "sdbout.h" | |
98 #endif | |
99 | |
100 #ifdef XCOFF_DEBUGGING_INFO | |
101 #include "xcoffout.h" /* Needed for external data | |
102 declarations for e.g. AIX 4.x. */ | |
103 #endif | |
104 | |
105 static void general_init (const char *); | |
106 static void do_compile (void); | |
107 static void process_options (void); | |
108 static void backend_init (void); | |
109 static int lang_dependent_init (const char *); | |
110 static void init_asm_output (const char *); | |
111 static void finalize (void); | |
112 | |
113 static void crash_signal (int) ATTRIBUTE_NORETURN; | |
114 static void setup_core_dumping (void); | |
115 static void compile_file (void); | |
116 | |
117 /* Nonzero to dump debug info whilst parsing (-dy option). */ | |
118 static int set_yydebug; | |
119 | |
120 /* True if we don't need a backend (e.g. preprocessing only). */ | |
121 static bool no_backend; | |
122 | |
123 /* Length of line when printing switch values. */ | |
124 #define MAX_LINE 75 | |
125 | |
126 /* Name of program invoked, sans directories. */ | |
127 | |
128 const char *progname; | |
129 | |
130 /* Copy of argument vector to toplev_main. */ | |
131 static const char **save_argv; | |
132 | |
133 /* Name of top-level original source file (what was input to cpp). | |
134 This comes from the #-command at the beginning of the actual input. | |
135 If there isn't any there, then this is the cc1 input file name. */ | |
136 | |
137 const char *main_input_filename; | |
138 | |
139 /* Used to enable -fvar-tracking, -fweb and -frename-registers according | |
140 to optimize and default_debug_hooks in process_options (). */ | |
141 #define AUTODETECT_VALUE 2 | |
142 | |
143 /* Current position in real source file. */ | |
144 | |
145 location_t input_location; | |
146 | |
147 struct line_maps *line_table; | |
148 | |
149 /* Name to use as base of names for dump output files. */ | |
150 | |
151 const char *dump_base_name; | |
152 | |
153 /* Name to use as a base for auxiliary output files. */ | |
154 | |
155 const char *aux_base_name; | |
156 | |
157 /* Prefix for profile data files */ | |
158 const char *profile_data_prefix; | |
159 | |
160 /* A mask of target_flags that includes bit X if X was set or cleared | |
161 on the command line. */ | |
162 | |
163 int target_flags_explicit; | |
164 | |
165 /* Debug hooks - dependent upon command line options. */ | |
166 | |
167 const struct gcc_debug_hooks *debug_hooks; | |
168 | |
169 /* Debug hooks - target default. */ | |
170 | |
171 static const struct gcc_debug_hooks *default_debug_hooks; | |
172 | |
173 /* Other flags saying which kinds of debugging dump have been requested. */ | |
174 | |
175 int rtl_dump_and_exit; | |
176 int flag_print_asm_name; | |
177 enum graph_dump_types graph_dump_format; | |
178 | |
179 /* Name for output file of assembly code, specified with -o. */ | |
180 | |
181 const char *asm_file_name; | |
182 | |
183 /* Nonzero means do optimizations. -O. | |
184 Particular numeric values stand for particular amounts of optimization; | |
185 thus, -O2 stores 2 here. However, the optimizations beyond the basic | |
186 ones are not controlled directly by this variable. Instead, they are | |
187 controlled by individual `flag_...' variables that are defaulted | |
188 based on this variable. */ | |
189 | |
190 int optimize = 0; | |
191 | |
192 /* Nonzero means optimize for size. -Os. | |
193 The only valid values are zero and nonzero. When optimize_size is | |
194 nonzero, optimize defaults to 2, but certain individual code | |
195 bloating optimizations are disabled. */ | |
196 | |
197 int optimize_size = 0; | |
198 | |
199 /* The FUNCTION_DECL for the function currently being compiled, | |
200 or 0 if between functions. */ | |
201 tree current_function_decl; | |
202 | |
203 /* Set to the FUNC_BEGIN label of the current function, or NULL | |
204 if none. */ | |
205 const char * current_function_func_begin_label; | |
206 | |
207 /* Nonzero means to collect statistics which might be expensive | |
208 and to print them when we are done. */ | |
209 int flag_detailed_statistics = 0; | |
210 | |
211 /* A random sequence of characters, unless overridden by user. */ | |
212 static const char *flag_random_seed; | |
213 | |
214 /* A local time stamp derived from the time of compilation. It will be | |
215 zero if the system cannot provide a time. It will be -1u, if the | |
216 user has specified a particular random seed. */ | |
217 unsigned local_tick; | |
218 | |
219 /* -f flags. */ | |
220 | |
221 /* Nonzero means `char' should be signed. */ | |
222 | |
223 int flag_signed_char; | |
224 | |
225 /* Nonzero means give an enum type only as many bytes as it needs. A value | |
226 of 2 means it has not yet been initialized. */ | |
227 | |
228 int flag_short_enums; | |
229 | |
230 /* Nonzero if structures and unions should be returned in memory. | |
231 | |
232 This should only be defined if compatibility with another compiler or | |
233 with an ABI is needed, because it results in slower code. */ | |
234 | |
235 #ifndef DEFAULT_PCC_STRUCT_RETURN | |
236 #define DEFAULT_PCC_STRUCT_RETURN 1 | |
237 #endif | |
238 | |
239 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */ | |
240 | |
241 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN; | |
242 | |
243 /* 0 means straightforward implementation of complex divide acceptable. | |
244 1 means wide ranges of inputs must work for complex divide. | |
245 2 means C99-like requirements for complex multiply and divide. */ | |
246 | |
247 int flag_complex_method = 1; | |
248 | |
249 /* Nonzero means we should be saving declaration info into a .X file. */ | |
250 | |
251 int flag_gen_aux_info = 0; | |
252 | |
253 /* Specified name of aux-info file. */ | |
254 | |
255 const char *aux_info_file_name; | |
256 | |
257 /* Nonzero if we are compiling code for a shared library, zero for | |
258 executable. */ | |
259 | |
260 int flag_shlib; | |
261 | |
262 /* Generate code for GNU or NeXT Objective-C runtime environment. */ | |
263 | |
264 #ifdef NEXT_OBJC_RUNTIME | |
265 int flag_next_runtime = 1; | |
266 #else | |
267 int flag_next_runtime = 0; | |
268 #endif | |
269 | |
270 /* Set to the default thread-local storage (tls) model to use. */ | |
271 | |
272 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC; | |
273 | |
274 /* Set the default region and algorithm for the integrated register | |
275 allocator. */ | |
276 | |
277 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB; | |
278 enum ira_region flag_ira_region = IRA_REGION_MIXED; | |
279 | |
280 /* Set the default value for -fira-verbose. */ | |
281 | |
282 unsigned int flag_ira_verbose = 5; | |
283 | |
284 /* Nonzero means change certain warnings into errors. | |
285 Usually these are warnings about failure to conform to some standard. */ | |
286 | |
287 int flag_pedantic_errors = 0; | |
288 | |
289 /* Nonzero means make permerror produce warnings instead of errors. */ | |
290 | |
291 int flag_permissive = 0; | |
292 | |
293 /* -dA causes debug commentary information to be produced in | |
294 the generated assembly code (to make it more readable). This option | |
295 is generally only of use to those who actually need to read the | |
296 generated assembly code (perhaps while debugging the compiler itself). | |
297 Currently, this switch is only used by dwarfout.c; however, it is intended | |
298 to be a catchall for printing debug information in the assembler file. */ | |
299 | |
300 int flag_debug_asm = 0; | |
301 | |
302 /* -dP causes the rtl to be emitted as a comment in assembly. */ | |
303 | |
304 int flag_dump_rtl_in_asm = 0; | |
305 | |
306 /* When non-NULL, indicates that whenever space is allocated on the | |
307 stack, the resulting stack pointer must not pass this | |
308 address---that is, for stacks that grow downward, the stack pointer | |
309 must always be greater than or equal to this address; for stacks | |
310 that grow upward, the stack pointer must be less than this address. | |
311 At present, the rtx may be either a REG or a SYMBOL_REF, although | |
312 the support provided depends on the backend. */ | |
313 rtx stack_limit_rtx; | |
314 | |
315 /* Nonzero if we should track variables. When | |
316 flag_var_tracking == AUTODETECT_VALUE it will be set according | |
317 to optimize, debug_info_level and debug_hooks in process_options (). */ | |
318 int flag_var_tracking = AUTODETECT_VALUE; | |
319 | |
320 /* Type of stack check. */ | |
321 enum stack_check_type flag_stack_check = NO_STACK_CHECK; | |
322 | |
323 /* True if the user has tagged the function with the 'section' | |
324 attribute. */ | |
325 | |
326 bool user_defined_section_attribute = false; | |
327 | |
328 /* Values of the -falign-* flags: how much to align labels in code. | |
329 0 means `use default', 1 means `don't align'. | |
330 For each variable, there is an _log variant which is the power | |
331 of two not less than the variable, for .align output. */ | |
332 | |
333 int align_loops_log; | |
334 int align_loops_max_skip; | |
335 int align_jumps_log; | |
336 int align_jumps_max_skip; | |
337 int align_labels_log; | |
338 int align_labels_max_skip; | |
339 int align_functions_log; | |
340 | |
341 typedef struct | |
342 { | |
343 const char *const string; | |
344 int *const variable; | |
345 const int on_value; | |
346 } | |
347 lang_independent_options; | |
348 | |
349 /* Nonzero if subexpressions must be evaluated from left-to-right. */ | |
350 int flag_evaluation_order = 0; | |
351 | |
352 /* The user symbol prefix after having resolved same. */ | |
353 const char *user_label_prefix; | |
354 | |
355 static const param_info lang_independent_params[] = { | |
356 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \ | |
357 { OPTION, DEFAULT, false, MIN, MAX, HELP }, | |
358 #include "params.def" | |
359 #undef DEFPARAM | |
360 { NULL, 0, false, 0, 0, NULL } | |
361 }; | |
362 | |
363 /* Output files for assembler code (real compiler output) | |
364 and debugging dumps. */ | |
365 | |
366 FILE *asm_out_file; | |
367 FILE *aux_info_file; | |
368 FILE *dump_file = NULL; | |
369 const char *dump_file_name; | |
370 | |
371 /* The current working directory of a translation. It's generally the | |
372 directory from which compilation was initiated, but a preprocessed | |
373 file may specify the original directory in which it was | |
374 created. */ | |
375 | |
376 static const char *src_pwd; | |
377 | |
378 /* Initialize src_pwd with the given string, and return true. If it | |
379 was already initialized, return false. As a special case, it may | |
380 be called with a NULL argument to test whether src_pwd has NOT been | |
381 initialized yet. */ | |
382 | |
383 bool | |
384 set_src_pwd (const char *pwd) | |
385 { | |
386 if (src_pwd) | |
387 { | |
388 if (strcmp (src_pwd, pwd) == 0) | |
389 return true; | |
390 else | |
391 return false; | |
392 } | |
393 | |
394 src_pwd = xstrdup (pwd); | |
395 return true; | |
396 } | |
397 | |
398 /* Return the directory from which the translation unit was initiated, | |
399 in case set_src_pwd() was not called before to assign it a | |
400 different value. */ | |
401 | |
402 const char * | |
403 get_src_pwd (void) | |
404 { | |
405 if (! src_pwd) | |
406 { | |
407 src_pwd = getpwd (); | |
408 if (!src_pwd) | |
409 src_pwd = "."; | |
410 } | |
411 | |
412 return src_pwd; | |
413 } | |
414 | |
415 /* Called when the start of a function definition is parsed, | |
416 this function prints on stderr the name of the function. */ | |
417 void | |
418 announce_function (tree decl) | |
419 { | |
420 if (!quiet_flag) | |
421 { | |
422 if (rtl_dump_and_exit) | |
423 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl))); | |
424 else | |
425 fprintf (stderr, " %s", lang_hooks.decl_printable_name (decl, 2)); | |
426 fflush (stderr); | |
427 pp_needs_newline (global_dc->printer) = true; | |
428 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL); | |
429 } | |
430 } | |
431 | |
432 /* Initialize local_tick with the time of day, or -1 if | |
433 flag_random_seed is set. */ | |
434 | |
435 static void | |
436 init_local_tick (void) | |
437 { | |
438 if (!flag_random_seed) | |
439 { | |
440 /* Get some more or less random data. */ | |
441 #ifdef HAVE_GETTIMEOFDAY | |
442 { | |
443 struct timeval tv; | |
444 | |
445 gettimeofday (&tv, NULL); | |
446 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000; | |
447 } | |
448 #else | |
449 { | |
450 time_t now = time (NULL); | |
451 | |
452 if (now != (time_t)-1) | |
453 local_tick = (unsigned) now; | |
454 } | |
455 #endif | |
456 } | |
457 else | |
458 local_tick = -1; | |
459 } | |
460 | |
461 /* Set up a default flag_random_seed and local_tick, unless the user | |
462 already specified one. Must be called after init_local_tick. */ | |
463 | |
464 static void | |
465 init_random_seed (void) | |
466 { | |
467 unsigned HOST_WIDE_INT value; | |
468 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; | |
469 | |
470 value = local_tick ^ getpid (); | |
471 | |
472 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); | |
473 flag_random_seed = random_seed; | |
474 } | |
475 | |
476 /* Obtain the random_seed string. Unless NOINIT, initialize it if | |
477 it's not provided in the command line. */ | |
478 | |
479 const char * | |
480 get_random_seed (bool noinit) | |
481 { | |
482 if (!flag_random_seed && !noinit) | |
483 init_random_seed (); | |
484 return flag_random_seed; | |
485 } | |
486 | |
487 /* Modify the random_seed string to VAL. Return its previous | |
488 value. */ | |
489 | |
490 const char * | |
491 set_random_seed (const char *val) | |
492 { | |
493 const char *old = flag_random_seed; | |
494 flag_random_seed = val; | |
495 return old; | |
496 } | |
497 | |
498 /* Decode the string P as an integral parameter. | |
499 If the string is indeed an integer return its numeric value else | |
500 issue an Invalid Option error for the option PNAME and return DEFVAL. | |
501 If PNAME is zero just return DEFVAL, do not call error. */ | |
502 | |
503 int | |
504 read_integral_parameter (const char *p, const char *pname, const int defval) | |
505 { | |
506 const char *endp = p; | |
507 | |
508 while (*endp) | |
509 { | |
510 if (ISDIGIT (*endp)) | |
511 endp++; | |
512 else | |
513 break; | |
514 } | |
515 | |
516 if (*endp != 0) | |
517 { | |
518 if (pname != 0) | |
519 error ("invalid option argument %qs", pname); | |
520 return defval; | |
521 } | |
522 | |
523 return atoi (p); | |
524 } | |
525 | |
526 /* When compiling with a recent enough GCC, we use the GNU C "extern inline" | |
527 for floor_log2 and exact_log2; see toplev.h. That construct, however, | |
528 conflicts with the ISO C++ One Definition Rule. */ | |
529 | |
530 #if GCC_VERSION < 3004 || !defined (__cplusplus) | |
531 | |
532 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X. | |
533 If X is 0, return -1. */ | |
534 | |
535 int | |
536 floor_log2 (unsigned HOST_WIDE_INT x) | |
537 { | |
538 int t = 0; | |
539 | |
540 if (x == 0) | |
541 return -1; | |
542 | |
543 #ifdef CLZ_HWI | |
544 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x); | |
545 #else | |
546 if (HOST_BITS_PER_WIDE_INT > 64) | |
547 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64)) | |
548 t += 64; | |
549 if (HOST_BITS_PER_WIDE_INT > 32) | |
550 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32)) | |
551 t += 32; | |
552 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16)) | |
553 t += 16; | |
554 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8)) | |
555 t += 8; | |
556 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4)) | |
557 t += 4; | |
558 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2)) | |
559 t += 2; | |
560 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1)) | |
561 t += 1; | |
562 #endif | |
563 | |
564 return t; | |
565 } | |
566 | |
567 /* Return the logarithm of X, base 2, considering X unsigned, | |
568 if X is a power of 2. Otherwise, returns -1. */ | |
569 | |
570 int | |
571 exact_log2 (unsigned HOST_WIDE_INT x) | |
572 { | |
573 if (x != (x & -x)) | |
574 return -1; | |
575 #ifdef CTZ_HWI | |
576 return x ? CTZ_HWI (x) : -1; | |
577 #else | |
578 return floor_log2 (x); | |
579 #endif | |
580 } | |
581 | |
582 #endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */ | |
583 | |
584 /* Handler for fatal signals, such as SIGSEGV. These are transformed | |
585 into ICE messages, which is much more user friendly. In case the | |
586 error printer crashes, reset the signal to prevent infinite recursion. */ | |
587 | |
588 static void | |
589 crash_signal (int signo) | |
590 { | |
591 signal (signo, SIG_DFL); | |
592 | |
593 /* If we crashed while processing an ASM statement, then be a little more | |
594 graceful. It's most likely the user's fault. */ | |
595 if (this_is_asm_operands) | |
596 { | |
597 output_operand_lossage ("unrecoverable error"); | |
598 exit (FATAL_EXIT_CODE); | |
599 } | |
600 | |
601 internal_error ("%s", strsignal (signo)); | |
602 } | |
603 | |
604 /* Arrange to dump core on error. (The regular error message is still | |
605 printed first, except in the case of abort().) */ | |
606 | |
607 static void | |
608 setup_core_dumping (void) | |
609 { | |
610 #ifdef SIGABRT | |
611 signal (SIGABRT, SIG_DFL); | |
612 #endif | |
613 #if defined(HAVE_SETRLIMIT) | |
614 { | |
615 struct rlimit rlim; | |
616 if (getrlimit (RLIMIT_CORE, &rlim) != 0) | |
617 fatal_error ("getting core file size maximum limit: %m"); | |
618 rlim.rlim_cur = rlim.rlim_max; | |
619 if (setrlimit (RLIMIT_CORE, &rlim) != 0) | |
620 fatal_error ("setting core file size limit to maximum: %m"); | |
621 } | |
622 #endif | |
623 diagnostic_abort_on_error (global_dc); | |
624 } | |
625 | |
626 | |
627 /* Strip off a legitimate source ending from the input string NAME of | |
628 length LEN. Rather than having to know the names used by all of | |
629 our front ends, we strip off an ending of a period followed by | |
630 up to five characters. (Java uses ".class".) */ | |
631 | |
632 void | |
633 strip_off_ending (char *name, int len) | |
634 { | |
635 int i; | |
636 for (i = 2; i < 6 && len > i; i++) | |
637 { | |
638 if (name[len - i] == '.') | |
639 { | |
640 name[len - i] = '\0'; | |
641 break; | |
642 } | |
643 } | |
644 } | |
645 | |
646 /* Output a quoted string. */ | |
647 | |
648 void | |
649 output_quoted_string (FILE *asm_file, const char *string) | |
650 { | |
651 #ifdef OUTPUT_QUOTED_STRING | |
652 OUTPUT_QUOTED_STRING (asm_file, string); | |
653 #else | |
654 char c; | |
655 | |
656 putc ('\"', asm_file); | |
657 while ((c = *string++) != 0) | |
658 { | |
659 if (ISPRINT (c)) | |
660 { | |
661 if (c == '\"' || c == '\\') | |
662 putc ('\\', asm_file); | |
663 putc (c, asm_file); | |
664 } | |
665 else | |
666 fprintf (asm_file, "\\%03o", (unsigned char) c); | |
667 } | |
668 putc ('\"', asm_file); | |
669 #endif | |
670 } | |
671 | |
672 /* Output a file name in the form wanted by System V. */ | |
673 | |
674 void | |
675 output_file_directive (FILE *asm_file, const char *input_name) | |
676 { | |
677 int len; | |
678 const char *na; | |
679 | |
680 if (input_name == NULL) | |
681 input_name = "<stdin>"; | |
682 else | |
683 input_name = remap_debug_filename (input_name); | |
684 | |
685 len = strlen (input_name); | |
686 na = input_name + len; | |
687 | |
688 /* NA gets INPUT_NAME sans directory names. */ | |
689 while (na > input_name) | |
690 { | |
691 if (IS_DIR_SEPARATOR (na[-1])) | |
692 break; | |
693 na--; | |
694 } | |
695 | |
696 #ifdef ASM_OUTPUT_SOURCE_FILENAME | |
697 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na); | |
698 #else | |
699 fprintf (asm_file, "\t.file\t"); | |
700 output_quoted_string (asm_file, na); | |
701 fputc ('\n', asm_file); | |
702 #endif | |
703 } | |
704 | |
705 /* A subroutine of wrapup_global_declarations. We've come to the end of | |
706 the compilation unit. All deferred variables should be undeferred, | |
707 and all incomplete decls should be finalized. */ | |
708 | |
709 void | |
710 wrapup_global_declaration_1 (tree decl) | |
711 { | |
712 /* We're not deferring this any longer. Assignment is conditional to | |
713 avoid needlessly dirtying PCH pages. */ | |
714 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS) | |
715 && DECL_DEFER_OUTPUT (decl) != 0) | |
716 DECL_DEFER_OUTPUT (decl) = 0; | |
717 | |
718 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0) | |
719 lang_hooks.finish_incomplete_decl (decl); | |
720 } | |
721 | |
722 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL | |
723 needs to be output. Return true if it is output. */ | |
724 | |
725 bool | |
726 wrapup_global_declaration_2 (tree decl) | |
727 { | |
728 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)) | |
729 return false; | |
730 | |
731 /* Don't write out static consts, unless we still need them. | |
732 | |
733 We also keep static consts if not optimizing (for debugging), | |
734 unless the user specified -fno-keep-static-consts. | |
735 ??? They might be better written into the debug information. | |
736 This is possible when using DWARF. | |
737 | |
738 A language processor that wants static constants to be always | |
739 written out (even if it is not used) is responsible for | |
740 calling rest_of_decl_compilation itself. E.g. the C front-end | |
741 calls rest_of_decl_compilation from finish_decl. | |
742 One motivation for this is that is conventional in some | |
743 environments to write things like: | |
744 static const char rcsid[] = "... version string ..."; | |
745 intending to force the string to be in the executable. | |
746 | |
747 A language processor that would prefer to have unneeded | |
748 static constants "optimized away" would just defer writing | |
749 them out until here. E.g. C++ does this, because static | |
750 constants are often defined in header files. | |
751 | |
752 ??? A tempting alternative (for both C and C++) would be | |
753 to force a constant to be written if and only if it is | |
754 defined in a main file, as opposed to an include file. */ | |
755 | |
756 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)) | |
757 { | |
758 struct varpool_node *node; | |
759 bool needed = true; | |
760 node = varpool_node (decl); | |
761 | |
762 if (node->finalized) | |
763 needed = false; | |
764 else if (node->alias) | |
765 needed = false; | |
766 else if (!cgraph_global_info_ready | |
767 && (TREE_USED (decl) | |
768 || TREE_USED (DECL_ASSEMBLER_NAME (decl)))) | |
769 /* needed */; | |
770 else if (node->needed) | |
771 /* needed */; | |
772 else if (DECL_COMDAT (decl)) | |
773 needed = false; | |
774 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl) | |
775 && (optimize || !flag_keep_static_consts | |
776 || DECL_ARTIFICIAL (decl))) | |
777 needed = false; | |
778 | |
779 if (needed) | |
780 { | |
781 rest_of_decl_compilation (decl, 1, 1); | |
782 return true; | |
783 } | |
784 } | |
785 | |
786 return false; | |
787 } | |
788 | |
789 /* Do any final processing required for the declarations in VEC, of | |
790 which there are LEN. We write out inline functions and variables | |
791 that have been deferred until this point, but which are required. | |
792 Returns nonzero if anything was put out. */ | |
793 | |
794 bool | |
795 wrapup_global_declarations (tree *vec, int len) | |
796 { | |
797 bool reconsider, output_something = false; | |
798 int i; | |
799 | |
800 for (i = 0; i < len; i++) | |
801 wrapup_global_declaration_1 (vec[i]); | |
802 | |
803 /* Now emit any global variables or functions that we have been | |
804 putting off. We need to loop in case one of the things emitted | |
805 here references another one which comes earlier in the list. */ | |
806 do | |
807 { | |
808 reconsider = false; | |
809 for (i = 0; i < len; i++) | |
810 reconsider |= wrapup_global_declaration_2 (vec[i]); | |
811 if (reconsider) | |
812 output_something = true; | |
813 } | |
814 while (reconsider); | |
815 | |
816 return output_something; | |
817 } | |
818 | |
819 /* A subroutine of check_global_declarations. Issue appropriate warnings | |
820 for the global declaration DECL. */ | |
821 | |
822 void | |
823 check_global_declaration_1 (tree decl) | |
824 { | |
825 /* Warn about any function declared static but not defined. We don't | |
826 warn about variables, because many programs have static variables | |
827 that exist only to get some text into the object file. */ | |
828 if (TREE_CODE (decl) == FUNCTION_DECL | |
829 && DECL_INITIAL (decl) == 0 | |
830 && DECL_EXTERNAL (decl) | |
831 && ! DECL_ARTIFICIAL (decl) | |
832 && ! TREE_NO_WARNING (decl) | |
833 && ! TREE_PUBLIC (decl) | |
834 && (warn_unused_function | |
835 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))) | |
836 { | |
837 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))) | |
838 pedwarn (input_location, 0, "%q+F used but never defined", decl); | |
839 else | |
840 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl); | |
841 /* This symbol is effectively an "extern" declaration now. */ | |
842 TREE_PUBLIC (decl) = 1; | |
843 assemble_external (decl); | |
844 } | |
845 | |
846 /* Warn about static fns or vars defined but not used. */ | |
847 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL) | |
848 /* We don't warn about "static const" variables because the | |
849 "rcs_id" idiom uses that construction. */ | |
850 || (warn_unused_variable | |
851 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl))) | |
852 && ! DECL_IN_SYSTEM_HEADER (decl) | |
853 && ! TREE_USED (decl) | |
854 /* The TREE_USED bit for file-scope decls is kept in the identifier, | |
855 to handle multiple external decls in different scopes. */ | |
856 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl))) | |
857 && ! DECL_EXTERNAL (decl) | |
858 && ! TREE_PUBLIC (decl) | |
859 /* A volatile variable might be used in some non-obvious way. */ | |
860 && ! TREE_THIS_VOLATILE (decl) | |
861 /* Global register variables must be declared to reserve them. */ | |
862 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)) | |
863 /* Otherwise, ask the language. */ | |
864 && lang_hooks.decls.warn_unused_global (decl)) | |
865 warning ((TREE_CODE (decl) == FUNCTION_DECL) | |
866 ? OPT_Wunused_function | |
867 : OPT_Wunused_variable, | |
868 "%q+D defined but not used", decl); | |
869 } | |
870 | |
871 /* Issue appropriate warnings for the global declarations in VEC (of | |
872 which there are LEN). */ | |
873 | |
874 void | |
875 check_global_declarations (tree *vec, int len) | |
876 { | |
877 int i; | |
878 | |
879 for (i = 0; i < len; i++) | |
880 check_global_declaration_1 (vec[i]); | |
881 } | |
882 | |
883 /* Emit debugging information for all global declarations in VEC. */ | |
884 | |
885 void | |
886 emit_debug_global_declarations (tree *vec, int len) | |
887 { | |
888 int i; | |
889 | |
890 /* Avoid confusing the debug information machinery when there are errors. */ | |
891 if (errorcount != 0 || sorrycount != 0) | |
892 return; | |
893 | |
894 timevar_push (TV_SYMOUT); | |
895 for (i = 0; i < len; i++) | |
896 debug_hooks->global_decl (vec[i]); | |
897 timevar_pop (TV_SYMOUT); | |
898 } | |
899 | |
900 /* Warn about a use of an identifier which was marked deprecated. */ | |
901 void | |
902 warn_deprecated_use (tree node) | |
903 { | |
904 if (node == 0 || !warn_deprecated_decl) | |
905 return; | |
906 | |
907 if (DECL_P (node)) | |
908 { | |
909 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node)); | |
910 warning (OPT_Wdeprecated_declarations, | |
911 "%qD is deprecated (declared at %s:%d)", | |
912 node, xloc.file, xloc.line); | |
913 } | |
914 else if (TYPE_P (node)) | |
915 { | |
916 const char *what = NULL; | |
917 tree decl = TYPE_STUB_DECL (node); | |
918 | |
919 if (TYPE_NAME (node)) | |
920 { | |
921 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE) | |
922 what = IDENTIFIER_POINTER (TYPE_NAME (node)); | |
923 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL | |
924 && DECL_NAME (TYPE_NAME (node))) | |
925 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))); | |
926 } | |
927 | |
928 if (decl) | |
929 { | |
930 expanded_location xloc | |
931 = expand_location (DECL_SOURCE_LOCATION (decl)); | |
932 if (what) | |
933 warning (OPT_Wdeprecated_declarations, | |
934 "%qs is deprecated (declared at %s:%d)", what, | |
935 xloc.file, xloc.line); | |
936 else | |
937 warning (OPT_Wdeprecated_declarations, | |
938 "type is deprecated (declared at %s:%d)", | |
939 xloc.file, xloc.line); | |
940 } | |
941 else | |
942 { | |
943 if (what) | |
944 warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what); | |
945 else | |
946 warning (OPT_Wdeprecated_declarations, "type is deprecated"); | |
947 } | |
948 } | |
949 } | |
950 | |
951 /* Compile an entire translation unit. Write a file of assembly | |
952 output and various debugging dumps. */ | |
953 | |
954 static void | |
955 compile_file (void) | |
956 { | |
957 /* Initialize yet another pass. */ | |
958 | |
959 ggc_protect_identifiers = true; | |
960 | |
961 init_cgraph (); | |
962 init_final (main_input_filename); | |
963 coverage_init (aux_base_name); | |
964 statistics_init (); | |
965 | |
966 timevar_push (TV_PARSE); | |
967 | |
968 /* Call the parser, which parses the entire file (calling | |
969 rest_of_compilation for each function). */ | |
970 lang_hooks.parse_file (set_yydebug); | |
971 | |
972 /* Compilation is now finished except for writing | |
973 what's left of the symbol table output. */ | |
974 timevar_pop (TV_PARSE); | |
975 | |
976 if (flag_syntax_only) | |
977 return; | |
978 | |
979 ggc_protect_identifiers = false; | |
980 | |
981 lang_hooks.decls.final_write_globals (); | |
982 | |
983 if (errorcount || sorrycount) | |
984 return; | |
985 | |
986 varpool_assemble_pending_decls (); | |
987 finish_aliases_2 (); | |
988 | |
989 /* This must occur after the loop to output deferred functions. | |
990 Else the coverage initializer would not be emitted if all the | |
991 functions in this compilation unit were deferred. */ | |
992 coverage_finish (); | |
993 | |
994 /* Likewise for mudflap static object registrations. */ | |
995 if (flag_mudflap) | |
996 mudflap_finish_file (); | |
997 | |
998 /* Likewise for emulated thread-local storage. */ | |
999 if (!targetm.have_tls) | |
1000 emutls_finish (); | |
1001 | |
1002 output_shared_constant_pool (); | |
1003 output_object_blocks (); | |
1004 | |
1005 /* Write out any pending weak symbol declarations. */ | |
1006 weak_finish (); | |
1007 | |
1008 /* Do dbx symbols. */ | |
1009 timevar_push (TV_SYMOUT); | |
1010 | |
1011 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO | |
1012 if (dwarf2out_do_frame ()) | |
1013 dwarf2out_frame_finish (); | |
1014 #endif | |
1015 | |
1016 (*debug_hooks->finish) (main_input_filename); | |
1017 timevar_pop (TV_SYMOUT); | |
1018 | |
1019 /* Output some stuff at end of file if nec. */ | |
1020 | |
1021 dw2_output_indirect_constants (); | |
1022 | |
1023 /* Flush any pending external directives. */ | |
1024 process_pending_assemble_externals (); | |
1025 | |
1026 /* Attach a special .ident directive to the end of the file to identify | |
1027 the version of GCC which compiled this code. The format of the .ident | |
1028 string is patterned after the ones produced by native SVR4 compilers. */ | |
1029 #ifdef IDENT_ASM_OP | |
1030 if (!flag_no_ident) | |
1031 { | |
1032 const char *pkg_version = "(GNU) "; | |
1033 | |
1034 if (strcmp ("(GCC) ", pkgversion_string)) | |
1035 pkg_version = pkgversion_string; | |
1036 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n", | |
1037 IDENT_ASM_OP, pkg_version, version_string); | |
1038 } | |
1039 #endif | |
1040 | |
1041 /* This must be at the end. Some target ports emit end of file directives | |
1042 into the assembly file here, and hence we can not output anything to the | |
1043 assembly file after this point. */ | |
1044 targetm.asm_out.file_end (); | |
1045 } | |
1046 | |
1047 /* Parse a -d... command line switch. */ | |
1048 | |
1049 void | |
1050 decode_d_option (const char *arg) | |
1051 { | |
1052 int c; | |
1053 | |
1054 while (*arg) | |
1055 switch (c = *arg++) | |
1056 { | |
1057 case 'A': | |
1058 flag_debug_asm = 1; | |
1059 break; | |
1060 case 'p': | |
1061 flag_print_asm_name = 1; | |
1062 break; | |
1063 case 'P': | |
1064 flag_dump_rtl_in_asm = 1; | |
1065 flag_print_asm_name = 1; | |
1066 break; | |
1067 case 'v': | |
1068 graph_dump_format = vcg; | |
1069 break; | |
1070 case 'x': | |
1071 rtl_dump_and_exit = 1; | |
1072 break; | |
1073 case 'y': | |
1074 set_yydebug = 1; | |
1075 break; | |
1076 case 'D': /* These are handled by the preprocessor. */ | |
1077 case 'I': | |
1078 case 'M': | |
1079 case 'N': | |
1080 case 'U': | |
1081 break; | |
1082 case 'H': | |
1083 setup_core_dumping(); | |
1084 break; | |
1085 case 'a': | |
1086 enable_rtl_dump_file (); | |
1087 break; | |
1088 | |
1089 default: | |
1090 warning (0, "unrecognized gcc debugging option: %c", c); | |
1091 break; | |
1092 } | |
1093 } | |
1094 | |
1095 /* Indexed by enum debug_info_type. */ | |
1096 const char *const debug_type_names[] = | |
1097 { | |
1098 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms" | |
1099 }; | |
1100 | |
1101 /* Print version information to FILE. | |
1102 Each line begins with INDENT (for the case where FILE is the | |
1103 assembler output file). */ | |
1104 | |
1105 void | |
1106 print_version (FILE *file, const char *indent) | |
1107 { | |
1108 static const char fmt1[] = | |
1109 #ifdef __GNUC__ | |
1110 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ") | |
1111 #else | |
1112 N_("%s%s%s %sversion %s (%s) compiled by CC, ") | |
1113 #endif | |
1114 ; | |
1115 static const char fmt2[] = | |
1116 N_("GMP version %s, MPFR version %s.\n"); | |
1117 static const char fmt3[] = | |
1118 N_("%s%swarning: %s header version %s differs from library version %s.\n"); | |
1119 static const char fmt4[] = | |
1120 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n"); | |
1121 #ifndef __VERSION__ | |
1122 #define __VERSION__ "[?]" | |
1123 #endif | |
1124 fprintf (file, | |
1125 file == stderr ? _(fmt1) : fmt1, | |
1126 indent, *indent != 0 ? " " : "", | |
1127 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME, | |
1128 indent, __VERSION__); | |
1129 | |
1130 /* We need to stringify the GMP macro values. Ugh, gmp_version has | |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1131 two string formats, "i.j.k" and "i.j" when k is zero. As of |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1132 gmp-4.3.0, GMP always uses the 3 number format. */ |
0 | 1133 #define GCC_GMP_STRINGIFY_VERSION3(X) #X |
1134 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X) | |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1135 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z)) |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1136 #define GCC_GMP_VERSION \ |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1137 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL) |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1138 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0 |
0 | 1139 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \ |
1140 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) | |
1141 #else | |
1142 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \ | |
1143 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \ | |
1144 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL) | |
1145 #endif | |
1146 fprintf (file, | |
1147 file == stderr ? _(fmt2) : fmt2, | |
1148 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING); | |
1149 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version)) | |
1150 fprintf (file, | |
1151 file == stderr ? _(fmt3) : fmt3, | |
1152 indent, *indent != 0 ? " " : "", | |
1153 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version); | |
1154 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ())) | |
1155 fprintf (file, | |
1156 file == stderr ? _(fmt3) : fmt3, | |
1157 indent, *indent != 0 ? " " : "", | |
1158 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ()); | |
1159 fprintf (file, | |
1160 file == stderr ? _(fmt4) : fmt4, | |
1161 indent, *indent != 0 ? " " : "", | |
1162 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE)); | |
1163 } | |
1164 | |
1165 #ifdef ASM_COMMENT_START | |
1166 static int | |
1167 print_to_asm_out_file (print_switch_type type, const char * text) | |
1168 { | |
1169 bool prepend_sep = true; | |
1170 | |
1171 switch (type) | |
1172 { | |
1173 case SWITCH_TYPE_LINE_END: | |
1174 putc ('\n', asm_out_file); | |
1175 return 1; | |
1176 | |
1177 case SWITCH_TYPE_LINE_START: | |
1178 fputs (ASM_COMMENT_START, asm_out_file); | |
1179 return strlen (ASM_COMMENT_START); | |
1180 | |
1181 case SWITCH_TYPE_DESCRIPTIVE: | |
1182 if (ASM_COMMENT_START[0] == 0) | |
1183 prepend_sep = false; | |
1184 /* Drop through. */ | |
1185 case SWITCH_TYPE_PASSED: | |
1186 case SWITCH_TYPE_ENABLED: | |
1187 if (prepend_sep) | |
1188 fputc (' ', asm_out_file); | |
1189 fprintf (asm_out_file, text); | |
1190 /* No need to return the length here as | |
1191 print_single_switch has already done it. */ | |
1192 return 0; | |
1193 | |
1194 default: | |
1195 return -1; | |
1196 } | |
1197 } | |
1198 #endif | |
1199 | |
1200 static int | |
1201 print_to_stderr (print_switch_type type, const char * text) | |
1202 { | |
1203 switch (type) | |
1204 { | |
1205 case SWITCH_TYPE_LINE_END: | |
1206 putc ('\n', stderr); | |
1207 return 1; | |
1208 | |
1209 case SWITCH_TYPE_LINE_START: | |
1210 return 0; | |
1211 | |
1212 case SWITCH_TYPE_PASSED: | |
1213 case SWITCH_TYPE_ENABLED: | |
1214 fputc (' ', stderr); | |
1215 /* Drop through. */ | |
1216 | |
1217 case SWITCH_TYPE_DESCRIPTIVE: | |
1218 fprintf (stderr, text); | |
1219 /* No need to return the length here as | |
1220 print_single_switch has already done it. */ | |
1221 return 0; | |
1222 | |
1223 default: | |
1224 return -1; | |
1225 } | |
1226 } | |
1227 | |
1228 /* Print an option value and return the adjusted position in the line. | |
1229 ??? print_fn doesn't handle errors, eg disk full; presumably other | |
1230 code will catch a disk full though. */ | |
1231 | |
1232 static int | |
1233 print_single_switch (print_switch_fn_type print_fn, | |
1234 int pos, | |
1235 print_switch_type type, | |
1236 const char * text) | |
1237 { | |
1238 /* The ultrix fprintf returns 0 on success, so compute the result | |
1239 we want here since we need it for the following test. The +1 | |
1240 is for the separator character that will probably be emitted. */ | |
1241 int len = strlen (text) + 1; | |
1242 | |
1243 if (pos != 0 | |
1244 && pos + len > MAX_LINE) | |
1245 { | |
1246 print_fn (SWITCH_TYPE_LINE_END, NULL); | |
1247 pos = 0; | |
1248 } | |
1249 | |
1250 if (pos == 0) | |
1251 pos += print_fn (SWITCH_TYPE_LINE_START, NULL); | |
1252 | |
1253 print_fn (type, text); | |
1254 return pos + len; | |
1255 } | |
1256 | |
1257 /* Print active target switches using PRINT_FN. | |
1258 POS is the current cursor position and MAX is the size of a "line". | |
1259 Each line begins with INDENT and ends with TERM. | |
1260 Each switch is separated from the next by SEP. */ | |
1261 | |
1262 static void | |
1263 print_switch_values (print_switch_fn_type print_fn) | |
1264 { | |
1265 int pos = 0; | |
1266 size_t j; | |
1267 const char **p; | |
1268 | |
1269 /* Fill in the -frandom-seed option, if the user didn't pass it, so | |
1270 that it can be printed below. This helps reproducibility. */ | |
1271 if (!flag_random_seed) | |
1272 init_random_seed (); | |
1273 | |
1274 /* Print the options as passed. */ | |
1275 pos = print_single_switch (print_fn, pos, | |
1276 SWITCH_TYPE_DESCRIPTIVE, _("options passed: ")); | |
1277 | |
1278 for (p = &save_argv[1]; *p != NULL; p++) | |
1279 { | |
1280 if (**p == '-') | |
1281 { | |
1282 /* Ignore these. */ | |
1283 if (strcmp (*p, "-o") == 0 | |
1284 || strcmp (*p, "-dumpbase") == 0 | |
1285 || strcmp (*p, "-auxbase") == 0) | |
1286 { | |
1287 if (p[1] != NULL) | |
1288 p++; | |
1289 continue; | |
1290 } | |
1291 | |
1292 if (strcmp (*p, "-quiet") == 0 | |
1293 || strcmp (*p, "-version") == 0) | |
1294 continue; | |
1295 | |
1296 if ((*p)[1] == 'd') | |
1297 continue; | |
1298 } | |
1299 | |
1300 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p); | |
1301 } | |
1302 | |
1303 if (pos > 0) | |
1304 print_fn (SWITCH_TYPE_LINE_END, NULL); | |
1305 | |
1306 /* Print the -f and -m options that have been enabled. | |
1307 We don't handle language specific options but printing argv | |
1308 should suffice. */ | |
1309 pos = print_single_switch (print_fn, 0, | |
1310 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: ")); | |
1311 | |
1312 for (j = 0; j < cl_options_count; j++) | |
1313 if ((cl_options[j].flags & CL_REPORT) | |
1314 && option_enabled (j) > 0) | |
1315 pos = print_single_switch (print_fn, pos, | |
1316 SWITCH_TYPE_ENABLED, cl_options[j].opt_text); | |
1317 | |
1318 print_fn (SWITCH_TYPE_LINE_END, NULL); | |
1319 } | |
1320 | |
1321 /* Open assembly code output file. Do this even if -fsyntax-only is | |
1322 on, because then the driver will have provided the name of a | |
1323 temporary file or bit bucket for us. NAME is the file specified on | |
1324 the command line, possibly NULL. */ | |
1325 static void | |
1326 init_asm_output (const char *name) | |
1327 { | |
1328 if (name == NULL && asm_file_name == 0) | |
1329 asm_out_file = stdout; | |
1330 else | |
1331 { | |
1332 if (asm_file_name == 0) | |
1333 { | |
1334 int len = strlen (dump_base_name); | |
1335 char *dumpname = XNEWVEC (char, len + 6); | |
1336 | |
1337 memcpy (dumpname, dump_base_name, len + 1); | |
1338 strip_off_ending (dumpname, len); | |
1339 strcat (dumpname, ".s"); | |
1340 asm_file_name = dumpname; | |
1341 } | |
1342 if (!strcmp (asm_file_name, "-")) | |
1343 asm_out_file = stdout; | |
1344 else | |
1345 asm_out_file = fopen (asm_file_name, "w+b"); | |
1346 if (asm_out_file == 0) | |
1347 fatal_error ("can%'t open %s for writing: %m", asm_file_name); | |
1348 } | |
1349 | |
1350 if (!flag_syntax_only) | |
1351 { | |
1352 targetm.asm_out.file_start (); | |
1353 | |
1354 if (flag_record_gcc_switches) | |
1355 { | |
1356 if (targetm.asm_out.record_gcc_switches) | |
1357 { | |
1358 /* Let the target know that we are about to start recording. */ | |
1359 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE, | |
1360 NULL); | |
1361 /* Now record the switches. */ | |
1362 print_switch_values (targetm.asm_out.record_gcc_switches); | |
1363 /* Let the target know that the recording is over. */ | |
1364 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE, | |
1365 NULL); | |
1366 } | |
1367 else | |
1368 inform (input_location, "-frecord-gcc-switches is not supported by the current target"); | |
1369 } | |
1370 | |
1371 #ifdef ASM_COMMENT_START | |
1372 if (flag_verbose_asm) | |
1373 { | |
1374 /* Print the list of switches in effect | |
1375 into the assembler file as comments. */ | |
1376 print_version (asm_out_file, ASM_COMMENT_START); | |
1377 print_switch_values (print_to_asm_out_file); | |
1378 fprintf (asm_out_file, "\n"); | |
1379 } | |
1380 #endif | |
1381 } | |
1382 } | |
1383 | |
1384 /* Return true if the state of option OPTION should be stored in PCH files | |
1385 and checked by default_pch_valid_p. Store the option's current state | |
1386 in STATE if so. */ | |
1387 | |
1388 static inline bool | |
1389 option_affects_pch_p (int option, struct cl_option_state *state) | |
1390 { | |
1391 if ((cl_options[option].flags & CL_TARGET) == 0) | |
1392 return false; | |
1393 if (cl_options[option].flag_var == &target_flags) | |
1394 if (targetm.check_pch_target_flags) | |
1395 return false; | |
1396 return get_option_state (option, state); | |
1397 } | |
1398 | |
1399 /* Default version of get_pch_validity. | |
1400 By default, every flag difference is fatal; that will be mostly right for | |
1401 most targets, but completely right for very few. */ | |
1402 | |
1403 void * | |
1404 default_get_pch_validity (size_t *len) | |
1405 { | |
1406 struct cl_option_state state; | |
1407 size_t i; | |
1408 char *result, *r; | |
1409 | |
1410 *len = 2; | |
1411 if (targetm.check_pch_target_flags) | |
1412 *len += sizeof (target_flags); | |
1413 for (i = 0; i < cl_options_count; i++) | |
1414 if (option_affects_pch_p (i, &state)) | |
1415 *len += state.size; | |
1416 | |
1417 result = r = XNEWVEC (char, *len); | |
1418 r[0] = flag_pic; | |
1419 r[1] = flag_pie; | |
1420 r += 2; | |
1421 if (targetm.check_pch_target_flags) | |
1422 { | |
1423 memcpy (r, &target_flags, sizeof (target_flags)); | |
1424 r += sizeof (target_flags); | |
1425 } | |
1426 | |
1427 for (i = 0; i < cl_options_count; i++) | |
1428 if (option_affects_pch_p (i, &state)) | |
1429 { | |
1430 memcpy (r, state.data, state.size); | |
1431 r += state.size; | |
1432 } | |
1433 | |
1434 return result; | |
1435 } | |
1436 | |
1437 /* Return a message which says that a PCH file was created with a different | |
1438 setting of OPTION. */ | |
1439 | |
1440 static const char * | |
1441 pch_option_mismatch (const char *option) | |
1442 { | |
1443 char *r; | |
1444 | |
1445 asprintf (&r, _("created and used with differing settings of '%s'"), option); | |
1446 if (r == NULL) | |
1447 return _("out of memory"); | |
1448 return r; | |
1449 } | |
1450 | |
1451 /* Default version of pch_valid_p. */ | |
1452 | |
1453 const char * | |
1454 default_pch_valid_p (const void *data_p, size_t len) | |
1455 { | |
1456 struct cl_option_state state; | |
1457 const char *data = (const char *)data_p; | |
1458 size_t i; | |
1459 | |
1460 /* -fpic and -fpie also usually make a PCH invalid. */ | |
1461 if (data[0] != flag_pic) | |
1462 return _("created and used with different settings of -fpic"); | |
1463 if (data[1] != flag_pie) | |
1464 return _("created and used with different settings of -fpie"); | |
1465 data += 2; | |
1466 | |
1467 /* Check target_flags. */ | |
1468 if (targetm.check_pch_target_flags) | |
1469 { | |
1470 int tf; | |
1471 const char *r; | |
1472 | |
1473 memcpy (&tf, data, sizeof (target_flags)); | |
1474 data += sizeof (target_flags); | |
1475 len -= sizeof (target_flags); | |
1476 r = targetm.check_pch_target_flags (tf); | |
1477 if (r != NULL) | |
1478 return r; | |
1479 } | |
1480 | |
1481 for (i = 0; i < cl_options_count; i++) | |
1482 if (option_affects_pch_p (i, &state)) | |
1483 { | |
1484 if (memcmp (data, state.data, state.size) != 0) | |
1485 return pch_option_mismatch (cl_options[i].opt_text); | |
1486 data += state.size; | |
1487 len -= state.size; | |
1488 } | |
1489 | |
1490 return NULL; | |
1491 } | |
1492 | |
1493 /* Default tree printer. Handles declarations only. */ | |
1494 static bool | |
1495 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec, | |
1496 int precision, bool wide, bool set_locus, bool hash) | |
1497 { | |
1498 tree t; | |
1499 | |
1500 /* FUTURE: %+x should set the locus. */ | |
1501 if (precision != 0 || wide || hash) | |
1502 return false; | |
1503 | |
1504 switch (*spec) | |
1505 { | |
1506 case 'D': | |
1507 t = va_arg (*text->args_ptr, tree); | |
1508 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t)) | |
1509 t = DECL_DEBUG_EXPR (t); | |
1510 break; | |
1511 | |
1512 case 'F': | |
1513 case 'T': | |
1514 t = va_arg (*text->args_ptr, tree); | |
1515 break; | |
1516 | |
1517 default: | |
1518 return false; | |
1519 } | |
1520 | |
1521 if (set_locus && text->locus) | |
1522 *text->locus = DECL_SOURCE_LOCATION (t); | |
1523 | |
1524 if (DECL_P (t)) | |
1525 { | |
1526 const char *n = DECL_NAME (t) | |
1527 ? lang_hooks.decl_printable_name (t, 2) | |
1528 : "<anonymous>"; | |
1529 pp_string (pp, n); | |
1530 } | |
1531 else | |
1532 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0); | |
1533 | |
1534 return true; | |
1535 } | |
1536 | |
1537 /* A helper function; used as the reallocator function for cpp's line | |
1538 table. */ | |
1539 static void * | |
1540 realloc_for_line_map (void *ptr, size_t len) | |
1541 { | |
1542 return ggc_realloc (ptr, len); | |
1543 } | |
1544 | |
1545 /* Initialization of the front end environment, before command line | |
1546 options are parsed. Signal handlers, internationalization etc. | |
1547 ARGV0 is main's argv[0]. */ | |
1548 static void | |
1549 general_init (const char *argv0) | |
1550 { | |
1551 const char *p; | |
1552 | |
1553 p = argv0 + strlen (argv0); | |
1554 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1])) | |
1555 --p; | |
1556 progname = p; | |
1557 | |
1558 xmalloc_set_program_name (progname); | |
1559 | |
1560 hex_init (); | |
1561 | |
1562 /* Unlock the stdio streams. */ | |
1563 unlock_std_streams (); | |
1564 | |
1565 gcc_init_libintl (); | |
1566 | |
1567 /* Initialize the diagnostics reporting machinery, so option parsing | |
1568 can give warnings and errors. */ | |
1569 diagnostic_initialize (global_dc); | |
1570 /* Set a default printer. Language specific initializations will | |
1571 override it later. */ | |
1572 pp_format_decoder (global_dc->printer) = &default_tree_printer; | |
1573 | |
1574 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */ | |
1575 #ifdef SIGSEGV | |
1576 signal (SIGSEGV, crash_signal); | |
1577 #endif | |
1578 #ifdef SIGILL | |
1579 signal (SIGILL, crash_signal); | |
1580 #endif | |
1581 #ifdef SIGBUS | |
1582 signal (SIGBUS, crash_signal); | |
1583 #endif | |
1584 #ifdef SIGABRT | |
1585 signal (SIGABRT, crash_signal); | |
1586 #endif | |
1587 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT) | |
1588 signal (SIGIOT, crash_signal); | |
1589 #endif | |
1590 #ifdef SIGFPE | |
1591 signal (SIGFPE, crash_signal); | |
1592 #endif | |
1593 | |
1594 /* Other host-specific signal setup. */ | |
1595 (*host_hooks.extra_signals)(); | |
1596 | |
1597 /* Initialize the garbage-collector, string pools and tree type hash | |
1598 table. */ | |
1599 init_ggc (); | |
1600 init_stringpool (); | |
1601 line_table = GGC_NEW (struct line_maps); | |
1602 linemap_init (line_table); | |
1603 line_table->reallocator = realloc_for_line_map; | |
1604 init_ttree (); | |
1605 | |
1606 /* Initialize register usage now so switches may override. */ | |
1607 init_reg_sets (); | |
1608 | |
1609 /* Register the language-independent parameters. */ | |
1610 add_params (lang_independent_params, LAST_PARAM); | |
1611 | |
1612 /* This must be done after add_params but before argument processing. */ | |
1613 init_ggc_heuristics(); | |
1614 init_optimization_passes (); | |
1615 statistics_early_init (); | |
1616 } | |
1617 | |
1618 /* Return true if the current target supports -fsection-anchors. */ | |
1619 | |
1620 static bool | |
1621 target_supports_section_anchors_p (void) | |
1622 { | |
1623 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0) | |
1624 return false; | |
1625 | |
1626 if (targetm.asm_out.output_anchor == NULL) | |
1627 return false; | |
1628 | |
1629 return true; | |
1630 } | |
1631 | |
1632 /* Default the align_* variables to 1 if they're still unset, and | |
1633 set up the align_*_log variables. */ | |
1634 static void | |
1635 init_alignments (void) | |
1636 { | |
1637 if (align_loops <= 0) | |
1638 align_loops = 1; | |
1639 if (align_loops_max_skip > align_loops) | |
1640 align_loops_max_skip = align_loops - 1; | |
1641 align_loops_log = floor_log2 (align_loops * 2 - 1); | |
1642 if (align_jumps <= 0) | |
1643 align_jumps = 1; | |
1644 if (align_jumps_max_skip > align_jumps) | |
1645 align_jumps_max_skip = align_jumps - 1; | |
1646 align_jumps_log = floor_log2 (align_jumps * 2 - 1); | |
1647 if (align_labels <= 0) | |
1648 align_labels = 1; | |
1649 align_labels_log = floor_log2 (align_labels * 2 - 1); | |
1650 if (align_labels_max_skip > align_labels) | |
1651 align_labels_max_skip = align_labels - 1; | |
1652 if (align_functions <= 0) | |
1653 align_functions = 1; | |
1654 align_functions_log = floor_log2 (align_functions * 2 - 1); | |
1655 } | |
1656 | |
1657 /* Process the options that have been parsed. */ | |
1658 static void | |
1659 process_options (void) | |
1660 { | |
1661 /* Just in case lang_hooks.post_options ends up calling a debug_hook. | |
1662 This can happen with incorrect pre-processed input. */ | |
1663 debug_hooks = &do_nothing_debug_hooks; | |
1664 | |
1665 /* This replaces set_Wunused. */ | |
1666 if (warn_unused_function == -1) | |
1667 warn_unused_function = warn_unused; | |
1668 if (warn_unused_label == -1) | |
1669 warn_unused_label = warn_unused; | |
1670 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */ | |
1671 if (warn_unused_parameter == -1) | |
1672 warn_unused_parameter = (warn_unused && extra_warnings); | |
1673 if (warn_unused_variable == -1) | |
1674 warn_unused_variable = warn_unused; | |
1675 if (warn_unused_value == -1) | |
1676 warn_unused_value = warn_unused; | |
1677 | |
1678 /* Allow the front end to perform consistency checks and do further | |
1679 initialization based on the command line options. This hook also | |
1680 sets the original filename if appropriate (e.g. foo.i -> foo.c) | |
1681 so we can correctly initialize debug output. */ | |
1682 no_backend = lang_hooks.post_options (&main_input_filename); | |
1683 | |
1684 #ifdef OVERRIDE_OPTIONS | |
1685 /* Some machines may reject certain combinations of options. */ | |
1686 OVERRIDE_OPTIONS; | |
1687 #endif | |
1688 | |
1689 if (flag_section_anchors && !target_supports_section_anchors_p ()) | |
1690 { | |
1691 warning (OPT_fsection_anchors, | |
1692 "this target does not support %qs", "-fsection-anchors"); | |
1693 flag_section_anchors = 0; | |
1694 } | |
1695 | |
1696 if (flag_short_enums == 2) | |
1697 flag_short_enums = targetm.default_short_enums (); | |
1698 | |
1699 /* Set aux_base_name if not already set. */ | |
1700 if (aux_base_name) | |
1701 ; | |
1702 else if (main_input_filename) | |
1703 { | |
1704 char *name = xstrdup (lbasename (main_input_filename)); | |
1705 | |
1706 strip_off_ending (name, strlen (name)); | |
1707 aux_base_name = name; | |
1708 } | |
1709 else | |
1710 aux_base_name = "gccaux"; | |
1711 | |
1712 #ifndef HAVE_cloog | |
1713 if (flag_graphite | |
1714 || flag_loop_block | |
1715 || flag_loop_interchange | |
1716 || flag_loop_strip_mine | |
1717 || flag_graphite_identity) | |
1718 sorry ("Graphite loop optimizations cannot be used"); | |
1719 #endif | |
1720 | |
1721 /* Unrolling all loops implies that standard loop unrolling must also | |
1722 be done. */ | |
1723 if (flag_unroll_all_loops) | |
1724 flag_unroll_loops = 1; | |
1725 | |
1726 /* The loop unrolling code assumes that cse will be run after loop. | |
1727 web and rename-registers also help when run after loop unrolling. */ | |
1728 | |
1729 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE) | |
1730 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops; | |
1731 if (flag_web == AUTODETECT_VALUE) | |
1732 flag_web = flag_unroll_loops || flag_peel_loops; | |
1733 if (flag_rename_registers == AUTODETECT_VALUE) | |
1734 flag_rename_registers = flag_unroll_loops || flag_peel_loops; | |
1735 | |
1736 if (flag_non_call_exceptions) | |
1737 flag_asynchronous_unwind_tables = 1; | |
1738 if (flag_asynchronous_unwind_tables) | |
1739 flag_unwind_tables = 1; | |
1740 | |
1741 if (flag_value_profile_transformations) | |
1742 flag_profile_values = 1; | |
1743 | |
1744 /* Warn about options that are not supported on this machine. */ | |
1745 #ifndef INSN_SCHEDULING | |
1746 if (flag_schedule_insns || flag_schedule_insns_after_reload) | |
1747 warning (0, "instruction scheduling not supported on this target machine"); | |
1748 #endif | |
1749 #ifndef DELAY_SLOTS | |
1750 if (flag_delayed_branch) | |
1751 warning (0, "this target machine does not have delayed branches"); | |
1752 #endif | |
1753 | |
1754 user_label_prefix = USER_LABEL_PREFIX; | |
1755 if (flag_leading_underscore != -1) | |
1756 { | |
1757 /* If the default prefix is more complicated than "" or "_", | |
1758 issue a warning and ignore this option. */ | |
1759 if (user_label_prefix[0] == 0 || | |
1760 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0)) | |
1761 { | |
1762 user_label_prefix = flag_leading_underscore ? "_" : ""; | |
1763 } | |
1764 else | |
1765 warning (0, "-f%sleading-underscore not supported on this target machine", | |
1766 flag_leading_underscore ? "" : "no-"); | |
1767 } | |
1768 | |
1769 /* If we are in verbose mode, write out the version and maybe all the | |
1770 option flags in use. */ | |
1771 if (version_flag) | |
1772 { | |
1773 print_version (stderr, ""); | |
1774 if (! quiet_flag) | |
1775 print_switch_values (print_to_stderr); | |
1776 } | |
1777 | |
1778 if (flag_syntax_only) | |
1779 { | |
1780 write_symbols = NO_DEBUG; | |
1781 profile_flag = 0; | |
1782 } | |
1783 | |
1784 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging | |
1785 level is 0. */ | |
1786 if (debug_info_level == DINFO_LEVEL_NONE) | |
1787 write_symbols = NO_DEBUG; | |
1788 | |
1789 /* Now we know write_symbols, set up the debug hooks based on it. | |
1790 By default we do nothing for debug output. */ | |
1791 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG) | |
1792 default_debug_hooks = &do_nothing_debug_hooks; | |
1793 #if defined(DBX_DEBUGGING_INFO) | |
1794 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG) | |
1795 default_debug_hooks = &dbx_debug_hooks; | |
1796 #endif | |
1797 #if defined(XCOFF_DEBUGGING_INFO) | |
1798 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG) | |
1799 default_debug_hooks = &xcoff_debug_hooks; | |
1800 #endif | |
1801 #ifdef SDB_DEBUGGING_INFO | |
1802 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG) | |
1803 default_debug_hooks = &sdb_debug_hooks; | |
1804 #endif | |
1805 #ifdef DWARF2_DEBUGGING_INFO | |
1806 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG) | |
1807 default_debug_hooks = &dwarf2_debug_hooks; | |
1808 #endif | |
1809 #ifdef VMS_DEBUGGING_INFO | |
1810 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG | |
1811 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG) | |
1812 default_debug_hooks = &vmsdbg_debug_hooks; | |
1813 #endif | |
1814 | |
1815 if (write_symbols == NO_DEBUG) | |
1816 ; | |
1817 #if defined(DBX_DEBUGGING_INFO) | |
1818 else if (write_symbols == DBX_DEBUG) | |
1819 debug_hooks = &dbx_debug_hooks; | |
1820 #endif | |
1821 #if defined(XCOFF_DEBUGGING_INFO) | |
1822 else if (write_symbols == XCOFF_DEBUG) | |
1823 debug_hooks = &xcoff_debug_hooks; | |
1824 #endif | |
1825 #ifdef SDB_DEBUGGING_INFO | |
1826 else if (write_symbols == SDB_DEBUG) | |
1827 debug_hooks = &sdb_debug_hooks; | |
1828 #endif | |
1829 #ifdef DWARF2_DEBUGGING_INFO | |
1830 else if (write_symbols == DWARF2_DEBUG) | |
1831 debug_hooks = &dwarf2_debug_hooks; | |
1832 #endif | |
1833 #ifdef VMS_DEBUGGING_INFO | |
1834 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) | |
1835 debug_hooks = &vmsdbg_debug_hooks; | |
1836 #endif | |
1837 else | |
1838 error ("target system does not support the \"%s\" debug format", | |
1839 debug_type_names[write_symbols]); | |
1840 | |
1841 /* Now we know which debug output will be used so we can set | |
1842 flag_var_tracking, flag_rename_registers if the user has | |
1843 not specified them. */ | |
1844 if (debug_info_level < DINFO_LEVEL_NORMAL | |
1845 || debug_hooks->var_location == do_nothing_debug_hooks.var_location) | |
1846 { | |
1847 if (flag_var_tracking == 1 | |
1848 || flag_var_tracking_uninit == 1) | |
1849 { | |
1850 if (debug_info_level < DINFO_LEVEL_NORMAL) | |
1851 warning (0, "variable tracking requested, but useless unless " | |
1852 "producing debug info"); | |
1853 else | |
1854 warning (0, "variable tracking requested, but not supported " | |
1855 "by this debug format"); | |
1856 } | |
1857 flag_var_tracking = 0; | |
1858 flag_var_tracking_uninit = 0; | |
1859 } | |
1860 | |
1861 if (flag_rename_registers == AUTODETECT_VALUE) | |
1862 flag_rename_registers = default_debug_hooks->var_location | |
1863 != do_nothing_debug_hooks.var_location; | |
1864 | |
1865 if (flag_var_tracking == AUTODETECT_VALUE) | |
1866 flag_var_tracking = optimize >= 1; | |
1867 | |
1868 if (flag_tree_cselim == AUTODETECT_VALUE) | |
1869 #ifdef HAVE_conditional_move | |
1870 flag_tree_cselim = 1; | |
1871 #else | |
1872 flag_tree_cselim = 0; | |
1873 #endif | |
1874 | |
1875 /* If the user specifically requested variable tracking with tagging | |
1876 uninitialized variables, we need to turn on variable tracking. | |
1877 (We already determined above that variable tracking is feasible.) */ | |
1878 if (flag_var_tracking_uninit) | |
1879 flag_var_tracking = 1; | |
1880 | |
1881 /* If auxiliary info generation is desired, open the output file. | |
1882 This goes in the same directory as the source file--unlike | |
1883 all the other output files. */ | |
1884 if (flag_gen_aux_info) | |
1885 { | |
1886 aux_info_file = fopen (aux_info_file_name, "w"); | |
1887 if (aux_info_file == 0) | |
1888 fatal_error ("can%'t open %s: %m", aux_info_file_name); | |
1889 } | |
1890 | |
1891 if (! targetm.have_named_sections) | |
1892 { | |
1893 if (flag_function_sections) | |
1894 { | |
1895 warning (0, "-ffunction-sections not supported for this target"); | |
1896 flag_function_sections = 0; | |
1897 } | |
1898 if (flag_data_sections) | |
1899 { | |
1900 warning (0, "-fdata-sections not supported for this target"); | |
1901 flag_data_sections = 0; | |
1902 } | |
1903 } | |
1904 | |
1905 if (flag_function_sections && profile_flag) | |
1906 { | |
1907 warning (0, "-ffunction-sections disabled; it makes profiling impossible"); | |
1908 flag_function_sections = 0; | |
1909 } | |
1910 | |
1911 #ifndef HAVE_prefetch | |
1912 if (flag_prefetch_loop_arrays) | |
1913 { | |
1914 warning (0, "-fprefetch-loop-arrays not supported for this target"); | |
1915 flag_prefetch_loop_arrays = 0; | |
1916 } | |
1917 #else | |
1918 if (flag_prefetch_loop_arrays && !HAVE_prefetch) | |
1919 { | |
1920 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)"); | |
1921 flag_prefetch_loop_arrays = 0; | |
1922 } | |
1923 #endif | |
1924 | |
1925 /* This combination of options isn't handled for i386 targets and doesn't | |
1926 make much sense anyway, so don't allow it. */ | |
1927 if (flag_prefetch_loop_arrays && optimize_size) | |
1928 { | |
1929 warning (0, "-fprefetch-loop-arrays is not supported with -Os"); | |
1930 flag_prefetch_loop_arrays = 0; | |
1931 } | |
1932 | |
1933 /* The presence of IEEE signaling NaNs, implies all math can trap. */ | |
1934 if (flag_signaling_nans) | |
1935 flag_trapping_math = 1; | |
1936 | |
1937 /* We cannot reassociate if we want traps or signed zeros. */ | |
1938 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros)) | |
1939 { | |
1940 warning (0, "-fassociative-math disabled; other options take precedence"); | |
1941 flag_associative_math = 0; | |
1942 } | |
1943 | |
1944 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */ | |
1945 if (flag_cx_limited_range) | |
1946 flag_complex_method = 0; | |
1947 | |
1948 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */ | |
1949 if (flag_cx_fortran_rules) | |
1950 flag_complex_method = 1; | |
1951 | |
1952 /* Targets must be able to place spill slots at lower addresses. If the | |
1953 target already uses a soft frame pointer, the transition is trivial. */ | |
1954 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect) | |
1955 { | |
1956 warning (0, "-fstack-protector not supported for this target"); | |
1957 flag_stack_protect = 0; | |
1958 } | |
1959 if (!flag_stack_protect) | |
1960 warn_stack_protect = 0; | |
1961 | |
1962 /* ??? Unwind info is not correct around the CFG unless either a frame | |
1963 pointer is present or A_O_A is set. Fixing this requires rewriting | |
1964 unwind info generation to be aware of the CFG and propagating states | |
1965 around edges. */ | |
1966 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS | |
1967 && flag_omit_frame_pointer) | |
1968 { | |
1969 warning (0, "unwind tables currently require a frame pointer " | |
1970 "for correctness"); | |
1971 flag_omit_frame_pointer = 0; | |
1972 } | |
1973 } | |
1974 | |
1975 /* This function can be called multiple times to reinitialize the compiler | |
1976 back end when register classes or instruction sets have changed, | |
1977 before each function. */ | |
1978 static void | |
1979 backend_init_target (void) | |
1980 { | |
1981 /* Initialize alignment variables. */ | |
1982 init_alignments (); | |
1983 | |
1984 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target() | |
1985 to initialize reg_raw_mode[]. */ | |
1986 init_emit_regs (); | |
1987 | |
1988 /* This invokes target hooks to set fixed_reg[] etc, which is | |
1989 mode-dependent. */ | |
1990 init_regs (); | |
1991 | |
1992 /* This depends on stack_pointer_rtx. */ | |
1993 init_fake_stack_mems (); | |
1994 | |
1995 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is | |
1996 mode-dependent. */ | |
1997 init_alias_target (); | |
1998 | |
1999 /* Depends on HARD_FRAME_POINTER_REGNUM. */ | |
2000 init_reload (); | |
2001 | |
2002 /* The following initialization functions need to generate rtl, so | |
2003 provide a dummy function context for them. */ | |
2004 init_dummy_function_start (); | |
2005 | |
2006 /* rtx_cost is mode-dependent, so cached values need to be recomputed | |
2007 on a mode change. */ | |
2008 init_expmed (); | |
2009 | |
2010 /* We may need to recompute regno_save_code[] and regno_restore_code[] | |
2011 after a mode change as well. */ | |
2012 if (flag_caller_saves) | |
2013 init_caller_save (); | |
2014 expand_dummy_function_end (); | |
2015 } | |
2016 | |
2017 /* Initialize the compiler back end. This function is called only once, | |
2018 when starting the compiler. */ | |
2019 static void | |
2020 backend_init (void) | |
2021 { | |
2022 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL | |
2023 || debug_info_level == DINFO_LEVEL_VERBOSE | |
2024 #ifdef VMS_DEBUGGING_INFO | |
2025 /* Enable line number info for traceback. */ | |
2026 || debug_info_level > DINFO_LEVEL_NONE | |
2027 #endif | |
2028 || flag_test_coverage); | |
2029 | |
2030 init_rtlanal (); | |
2031 init_inline_once (); | |
2032 init_varasm_once (); | |
2033 save_register_info (); | |
2034 | |
2035 /* Initialize the target-specific back end pieces. */ | |
2036 ira_init_once (); | |
2037 backend_init_target (); | |
2038 } | |
2039 | |
2040 /* Initialize things that are both lang-dependent and target-dependent. | |
2041 This function can be called more than once if target parameters change. */ | |
2042 static void | |
2043 lang_dependent_init_target (void) | |
2044 { | |
2045 /* This creates various _DECL nodes, so needs to be called after the | |
2046 front end is initialized. It also depends on the HAVE_xxx macros | |
2047 generated from the target machine description. */ | |
2048 init_optabs (); | |
2049 | |
2050 /* The following initialization functions need to generate rtl, so | |
2051 provide a dummy function context for them. */ | |
2052 init_dummy_function_start (); | |
2053 | |
2054 /* Do the target-specific parts of expr initialization. */ | |
2055 init_expr_target (); | |
2056 | |
2057 /* Although the actions of these functions are language-independent, | |
2058 they use optabs, so we cannot call them from backend_init. */ | |
2059 init_set_costs (); | |
2060 ira_init (); | |
2061 | |
2062 expand_dummy_function_end (); | |
2063 } | |
2064 | |
2065 /* Language-dependent initialization. Returns nonzero on success. */ | |
2066 static int | |
2067 lang_dependent_init (const char *name) | |
2068 { | |
2069 location_t save_loc = input_location; | |
2070 if (dump_base_name == 0) | |
2071 dump_base_name = name && name[0] ? name : "gccdump"; | |
2072 | |
2073 /* Other front-end initialization. */ | |
2074 input_location = BUILTINS_LOCATION; | |
2075 if (lang_hooks.init () == 0) | |
2076 return 0; | |
2077 input_location = save_loc; | |
2078 | |
2079 init_asm_output (name); | |
2080 | |
2081 /* This creates various _DECL nodes, so needs to be called after the | |
2082 front end is initialized. */ | |
2083 init_eh (); | |
2084 | |
2085 /* Do the target-specific parts of the initialization. */ | |
2086 lang_dependent_init_target (); | |
2087 | |
2088 /* If dbx symbol table desired, initialize writing it and output the | |
2089 predefined types. */ | |
2090 timevar_push (TV_SYMOUT); | |
2091 | |
2092 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO | |
2093 if (dwarf2out_do_frame ()) | |
2094 dwarf2out_frame_init (); | |
2095 #endif | |
2096 | |
2097 /* Now we have the correct original filename, we can initialize | |
2098 debug output. */ | |
2099 (*debug_hooks->init) (name); | |
2100 | |
2101 timevar_pop (TV_SYMOUT); | |
2102 | |
2103 return 1; | |
2104 } | |
2105 | |
2106 | |
2107 /* Reinitialize everything when target parameters, such as register usage, | |
2108 have changed. */ | |
2109 void | |
2110 target_reinit (void) | |
2111 { | |
2112 /* Reinitialize RTL backend. */ | |
2113 backend_init_target (); | |
2114 | |
2115 /* Reinitialize lang-dependent parts. */ | |
2116 lang_dependent_init_target (); | |
2117 } | |
2118 | |
2119 void | |
2120 dump_memory_report (bool final) | |
2121 { | |
2122 ggc_print_statistics (); | |
2123 stringpool_statistics (); | |
2124 dump_tree_statistics (); | |
2125 dump_gimple_statistics (); | |
2126 dump_rtx_statistics (); | |
2127 dump_varray_statistics (); | |
2128 dump_alloc_pool_statistics (); | |
2129 dump_bitmap_statistics (); | |
2130 dump_vec_loc_statistics (); | |
2131 dump_ggc_loc_statistics (final); | |
2132 } | |
2133 | |
2134 /* Clean up: close opened files, etc. */ | |
2135 | |
2136 static void | |
2137 finalize (void) | |
2138 { | |
2139 /* Close the dump files. */ | |
2140 if (flag_gen_aux_info) | |
2141 { | |
2142 fclose (aux_info_file); | |
2143 if (errorcount) | |
2144 unlink (aux_info_file_name); | |
2145 } | |
2146 | |
2147 /* Close non-debugging input and output files. Take special care to note | |
2148 whether fclose returns an error, since the pages might still be on the | |
2149 buffer chain while the file is open. */ | |
2150 | |
2151 if (asm_out_file) | |
2152 { | |
2153 if (ferror (asm_out_file) != 0) | |
2154 fatal_error ("error writing to %s: %m", asm_file_name); | |
2155 if (fclose (asm_out_file) != 0) | |
2156 fatal_error ("error closing %s: %m", asm_file_name); | |
2157 } | |
2158 | |
2159 statistics_fini (); | |
2160 finish_optimization_passes (); | |
2161 | |
2162 ira_finish_once (); | |
2163 | |
2164 if (mem_report) | |
2165 dump_memory_report (true); | |
2166 | |
2167 /* Language-specific end of compilation actions. */ | |
2168 lang_hooks.finish (); | |
2169 } | |
2170 | |
2171 /* Initialize the compiler, and compile the input file. */ | |
2172 static void | |
2173 do_compile (void) | |
2174 { | |
2175 /* Initialize timing first. The C front ends read the main file in | |
2176 the post_options hook, and C++ does file timings. */ | |
2177 if (time_report || !quiet_flag || flag_detailed_statistics) | |
2178 timevar_init (); | |
2179 timevar_start (TV_TOTAL); | |
2180 | |
2181 process_options (); | |
2182 | |
2183 /* Don't do any more if an error has already occurred. */ | |
2184 if (!errorcount) | |
2185 { | |
2186 /* This must be run always, because it is needed to compute the FP | |
2187 predefined macros, such as __LDBL_MAX__, for targets using non | |
2188 default FP formats. */ | |
2189 init_adjust_machine_modes (); | |
2190 | |
2191 /* Set up the back-end if requested. */ | |
2192 if (!no_backend) | |
2193 backend_init (); | |
2194 | |
2195 /* Language-dependent initialization. Returns true on success. */ | |
2196 if (lang_dependent_init (main_input_filename)) | |
2197 compile_file (); | |
2198 | |
2199 finalize (); | |
2200 } | |
2201 | |
2202 /* Stop timing and print the times. */ | |
2203 timevar_stop (TV_TOTAL); | |
2204 timevar_print (stderr); | |
2205 } | |
2206 | |
2207 /* Entry point of cc1, cc1plus, jc1, f771, etc. | |
2208 Exit code is FATAL_EXIT_CODE if can't open files or if there were | |
2209 any errors, or SUCCESS_EXIT_CODE if compilation succeeded. | |
2210 | |
2211 It is not safe to call this function more than once. */ | |
2212 | |
2213 int | |
2214 toplev_main (unsigned int argc, const char **argv) | |
2215 { | |
2216 save_argv = argv; | |
2217 | |
2218 /* Initialization of GCC's environment, and diagnostics. */ | |
2219 general_init (argv[0]); | |
2220 | |
2221 /* Parse the options and do minimal processing; basically just | |
2222 enough to default flags appropriately. */ | |
2223 decode_options (argc, argv); | |
2224 | |
2225 init_local_tick (); | |
2226 | |
2227 /* Exit early if we can (e.g. -help). */ | |
2228 if (!exit_after_options) | |
2229 do_compile (); | |
2230 | |
2231 if (warningcount || errorcount) | |
2232 print_ignored_options (); | |
2233 | |
2234 if (errorcount || sorrycount) | |
2235 return (FATAL_EXIT_CODE); | |
2236 | |
2237 return (SUCCESS_EXIT_CODE); | |
2238 } |