OSDN Git Service

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