OSDN Git Service

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