OSDN Git Service

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