OSDN Git Service

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