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.
6 This file is part of GCC.
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
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
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/>. */
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. */
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
31 #include "coretypes.h"
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
60 #include "basic-block.h"
66 #include "diagnostic.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
77 #include "hosthooks.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
83 #include "tree-mudflap.h"
84 #include "tree-pass.h"
87 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
88 #include "dwarf2out.h"
91 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
95 #ifdef SDB_DEBUGGING_INFO
99 #ifdef XCOFF_DEBUGGING_INFO
100 #include "xcoffout.h" /* Needed for external data
101 declarations for e.g. AIX 4.x. */
104 static void general_init (const char *);
105 static void do_compile (void);
106 static void process_options (void);
107 static void backend_init (void);
108 static int lang_dependent_init (const char *);
109 static void init_asm_output (const char *);
110 static void finalize (void);
112 static void crash_signal (int) ATTRIBUTE_NORETURN;
113 static void setup_core_dumping (void);
114 static void compile_file (void);
116 /* Nonzero to dump debug info whilst parsing (-dy option). */
117 static int set_yydebug;
119 /* True if we don't need a backend (e.g. preprocessing only). */
120 static bool no_backend;
122 /* Length of line when printing switch values. */
125 /* Name of program invoked, sans directories. */
127 const char *progname;
129 /* Copy of argument vector to toplev_main. */
130 static const char **save_argv;
132 /* Name of top-level original source file (what was input to cpp).
133 This comes from the #-command at the beginning of the actual input.
134 If there isn't any there, then this is the cc1 input file name. */
136 const char *main_input_filename;
138 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
139 to optimize and default_debug_hooks in process_options (). */
140 #define AUTODETECT_VALUE 2
142 /* Current position in real source file. */
144 location_t input_location;
146 struct line_maps *line_table;
148 /* Name to use as base of names for dump output files. */
150 const char *dump_base_name;
152 /* Name to use as a base for auxiliary output files. */
154 const char *aux_base_name;
156 /* Prefix for profile data files */
157 const char *profile_data_prefix;
159 /* A mask of target_flags that includes bit X if X was set or cleared
160 on the command line. */
162 int target_flags_explicit;
164 /* Debug hooks - dependent upon command line options. */
166 const struct gcc_debug_hooks *debug_hooks;
168 /* Debug hooks - target default. */
170 static const struct gcc_debug_hooks *default_debug_hooks;
172 /* Other flags saying which kinds of debugging dump have been requested. */
174 int rtl_dump_and_exit;
175 int flag_print_asm_name;
176 enum graph_dump_types graph_dump_format;
178 /* Name for output file of assembly code, specified with -o. */
180 const char *asm_file_name;
182 /* Nonzero means do optimizations. -O.
183 Particular numeric values stand for particular amounts of optimization;
184 thus, -O2 stores 2 here. However, the optimizations beyond the basic
185 ones are not controlled directly by this variable. Instead, they are
186 controlled by individual `flag_...' variables that are defaulted
187 based on this variable. */
191 /* Nonzero means optimize for size. -Os.
192 The only valid values are zero and nonzero. When optimize_size is
193 nonzero, optimize defaults to 2, but certain individual code
194 bloating optimizations are disabled. */
196 int optimize_size = 0;
198 /* The FUNCTION_DECL for the function currently being compiled,
199 or 0 if between functions. */
200 tree current_function_decl;
202 /* Set to the FUNC_BEGIN label of the current function, or NULL
204 const char * current_function_func_begin_label;
206 /* Nonzero means to collect statistics which might be expensive
207 and to print them when we are done. */
208 int flag_detailed_statistics = 0;
210 /* A random sequence of characters, unless overridden by user. */
211 static const char *flag_random_seed;
213 /* A local time stamp derived from the time of compilation. It will be
214 zero if the system cannot provide a time. It will be -1u, if the
215 user has specified a particular random seed. */
220 /* Nonzero means `char' should be signed. */
222 int flag_signed_char;
224 /* Nonzero means give an enum type only as many bytes as it needs. A value
225 of 2 means it has not yet been initialized. */
227 int flag_short_enums;
229 /* Nonzero if structures and unions should be returned in memory.
231 This should only be defined if compatibility with another compiler or
232 with an ABI is needed, because it results in slower code. */
234 #ifndef DEFAULT_PCC_STRUCT_RETURN
235 #define DEFAULT_PCC_STRUCT_RETURN 1
238 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
240 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
242 /* 0 means straightforward implementation of complex divide acceptable.
243 1 means wide ranges of inputs must work for complex divide.
244 2 means C99-like requirements for complex multiply and divide. */
246 int flag_complex_method = 1;
248 /* Nonzero means we should be saving declaration info into a .X file. */
250 int flag_gen_aux_info = 0;
252 /* Specified name of aux-info file. */
254 const char *aux_info_file_name;
256 /* Nonzero if we are compiling code for a shared library, zero for
261 /* Generate code for GNU or NeXT Objective-C runtime environment. */
263 #ifdef NEXT_OBJC_RUNTIME
264 int flag_next_runtime = 1;
266 int flag_next_runtime = 0;
269 /* Set to the default thread-local storage (tls) model to use. */
271 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
273 /* Nonzero means change certain warnings into errors.
274 Usually these are warnings about failure to conform to some standard. */
276 int flag_pedantic_errors = 0;
278 /* Nonzero means make permerror produce warnings instead of errors. */
280 int flag_permissive = 0;
282 /* -dA causes debug commentary information to be produced in
283 the generated assembly code (to make it more readable). This option
284 is generally only of use to those who actually need to read the
285 generated assembly code (perhaps while debugging the compiler itself).
286 Currently, this switch is only used by dwarfout.c; however, it is intended
287 to be a catchall for printing debug information in the assembler file. */
289 int flag_debug_asm = 0;
291 /* -dP causes the rtl to be emitted as a comment in assembly. */
293 int flag_dump_rtl_in_asm = 0;
295 /* When non-NULL, indicates that whenever space is allocated on the
296 stack, the resulting stack pointer must not pass this
297 address---that is, for stacks that grow downward, the stack pointer
298 must always be greater than or equal to this address; for stacks
299 that grow upward, the stack pointer must be less than this address.
300 At present, the rtx may be either a REG or a SYMBOL_REF, although
301 the support provided depends on the backend. */
304 /* Nonzero if we should track variables. When
305 flag_var_tracking == AUTODETECT_VALUE it will be set according
306 to optimize, debug_info_level and debug_hooks in process_options (). */
307 int flag_var_tracking = AUTODETECT_VALUE;
309 /* True if the user has tagged the function with the 'section'
312 bool user_defined_section_attribute = false;
314 /* Values of the -falign-* flags: how much to align labels in code.
315 0 means `use default', 1 means `don't align'.
316 For each variable, there is an _log variant which is the power
317 of two not less than the variable, for .align output. */
320 int align_loops_max_skip;
322 int align_jumps_max_skip;
323 int align_labels_log;
324 int align_labels_max_skip;
325 int align_functions_log;
329 const char *const string;
333 lang_independent_options;
335 /* Nonzero if subexpressions must be evaluated from left-to-right. */
336 int flag_evaluation_order = 0;
338 /* The user symbol prefix after having resolved same. */
339 const char *user_label_prefix;
341 static const param_info lang_independent_params[] = {
342 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
343 { OPTION, DEFAULT, false, MIN, MAX, HELP },
344 #include "params.def"
346 { NULL, 0, false, 0, 0, NULL }
349 /* Output files for assembler code (real compiler output)
350 and debugging dumps. */
354 FILE *dump_file = NULL;
355 const char *dump_file_name;
357 /* The current working directory of a translation. It's generally the
358 directory from which compilation was initiated, but a preprocessed
359 file may specify the original directory in which it was
362 static const char *src_pwd;
364 /* Initialize src_pwd with the given string, and return true. If it
365 was already initialized, return false. As a special case, it may
366 be called with a NULL argument to test whether src_pwd has NOT been
370 set_src_pwd (const char *pwd)
374 if (strcmp (src_pwd, pwd) == 0)
380 src_pwd = xstrdup (pwd);
384 /* Return the directory from which the translation unit was initiated,
385 in case set_src_pwd() was not called before to assign it a
401 /* Called when the start of a function definition is parsed,
402 this function prints on stderr the name of the function. */
404 announce_function (tree decl)
408 if (rtl_dump_and_exit)
409 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
411 fprintf (stderr, " %s", lang_hooks.decl_printable_name (decl, 2));
413 pp_needs_newline (global_dc->printer) = true;
414 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
418 /* Initialize local_tick with the time of day, or -1 if
419 flag_random_seed is set. */
422 init_local_tick (void)
424 if (!flag_random_seed)
426 /* Get some more or less random data. */
427 #ifdef HAVE_GETTIMEOFDAY
431 gettimeofday (&tv, NULL);
432 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
436 time_t now = time (NULL);
438 if (now != (time_t)-1)
439 local_tick = (unsigned) now;
447 /* Set up a default flag_random_seed and local_tick, unless the user
448 already specified one. Must be called after init_local_tick. */
451 init_random_seed (void)
453 unsigned HOST_WIDE_INT value;
454 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
456 value = local_tick ^ getpid ();
458 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
459 flag_random_seed = random_seed;
462 /* Obtain the random_seed string. Unless NOINIT, initialize it if
463 it's not provided in the command line. */
466 get_random_seed (bool noinit)
468 if (!flag_random_seed && !noinit)
470 return flag_random_seed;
473 /* Modify the random_seed string to VAL. Return its previous
477 set_random_seed (const char *val)
479 const char *old = flag_random_seed;
480 flag_random_seed = val;
484 /* Decode the string P as an integral parameter.
485 If the string is indeed an integer return its numeric value else
486 issue an Invalid Option error for the option PNAME and return DEFVAL.
487 If PNAME is zero just return DEFVAL, do not call error. */
490 read_integral_parameter (const char *p, const char *pname, const int defval)
492 const char *endp = p;
505 error ("invalid option argument %qs", pname);
512 /* When compiling with a recent enough GCC, we use the GNU C "extern inline"
513 for floor_log2 and exact_log2; see toplev.h. That construct, however,
514 conflicts with the ISO C++ One Definition Rule. */
516 #if GCC_VERSION < 3004 || !defined (__cplusplus)
518 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
519 If X is 0, return -1. */
522 floor_log2 (unsigned HOST_WIDE_INT x)
530 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
532 if (HOST_BITS_PER_WIDE_INT > 64)
533 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
535 if (HOST_BITS_PER_WIDE_INT > 32)
536 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
538 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
540 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
542 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
544 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
546 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
553 /* Return the logarithm of X, base 2, considering X unsigned,
554 if X is a power of 2. Otherwise, returns -1. */
557 exact_log2 (unsigned HOST_WIDE_INT x)
562 return x ? CTZ_HWI (x) : -1;
564 return floor_log2 (x);
568 #endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */
570 /* Handler for fatal signals, such as SIGSEGV. These are transformed
571 into ICE messages, which is much more user friendly. In case the
572 error printer crashes, reset the signal to prevent infinite recursion. */
575 crash_signal (int signo)
577 signal (signo, SIG_DFL);
579 /* If we crashed while processing an ASM statement, then be a little more
580 graceful. It's most likely the user's fault. */
581 if (this_is_asm_operands)
583 output_operand_lossage ("unrecoverable error");
584 exit (FATAL_EXIT_CODE);
587 internal_error ("%s", strsignal (signo));
590 /* Arrange to dump core on error. (The regular error message is still
591 printed first, except in the case of abort().) */
594 setup_core_dumping (void)
597 signal (SIGABRT, SIG_DFL);
599 #if defined(HAVE_SETRLIMIT)
602 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
603 fatal_error ("getting core file size maximum limit: %m");
604 rlim.rlim_cur = rlim.rlim_max;
605 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
606 fatal_error ("setting core file size limit to maximum: %m");
609 diagnostic_abort_on_error (global_dc);
613 /* Strip off a legitimate source ending from the input string NAME of
614 length LEN. Rather than having to know the names used by all of
615 our front ends, we strip off an ending of a period followed by
616 up to five characters. (Java uses ".class".) */
619 strip_off_ending (char *name, int len)
622 for (i = 2; i < 6 && len > i; i++)
624 if (name[len - i] == '.')
626 name[len - i] = '\0';
632 /* Output a quoted string. */
635 output_quoted_string (FILE *asm_file, const char *string)
637 #ifdef OUTPUT_QUOTED_STRING
638 OUTPUT_QUOTED_STRING (asm_file, string);
642 putc ('\"', asm_file);
643 while ((c = *string++) != 0)
647 if (c == '\"' || c == '\\')
648 putc ('\\', asm_file);
652 fprintf (asm_file, "\\%03o", (unsigned char) c);
654 putc ('\"', asm_file);
658 /* Output a file name in the form wanted by System V. */
661 output_file_directive (FILE *asm_file, const char *input_name)
666 if (input_name == NULL)
667 input_name = "<stdin>";
669 input_name = remap_debug_filename (input_name);
671 len = strlen (input_name);
672 na = input_name + len;
674 /* NA gets INPUT_NAME sans directory names. */
675 while (na > input_name)
677 if (IS_DIR_SEPARATOR (na[-1]))
682 #ifdef ASM_OUTPUT_SOURCE_FILENAME
683 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
685 fprintf (asm_file, "\t.file\t");
686 output_quoted_string (asm_file, na);
687 fputc ('\n', asm_file);
691 /* A subroutine of wrapup_global_declarations. We've come to the end of
692 the compilation unit. All deferred variables should be undeferred,
693 and all incomplete decls should be finalized. */
696 wrapup_global_declaration_1 (tree decl)
698 /* We're not deferring this any longer. Assignment is conditional to
699 avoid needlessly dirtying PCH pages. */
700 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
701 && DECL_DEFER_OUTPUT (decl) != 0)
702 DECL_DEFER_OUTPUT (decl) = 0;
704 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
705 lang_hooks.finish_incomplete_decl (decl);
708 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
709 needs to be output. Return true if it is output. */
712 wrapup_global_declaration_2 (tree decl)
714 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
717 /* Don't write out static consts, unless we still need them.
719 We also keep static consts if not optimizing (for debugging),
720 unless the user specified -fno-keep-static-consts.
721 ??? They might be better written into the debug information.
722 This is possible when using DWARF.
724 A language processor that wants static constants to be always
725 written out (even if it is not used) is responsible for
726 calling rest_of_decl_compilation itself. E.g. the C front-end
727 calls rest_of_decl_compilation from finish_decl.
728 One motivation for this is that is conventional in some
729 environments to write things like:
730 static const char rcsid[] = "... version string ...";
731 intending to force the string to be in the executable.
733 A language processor that would prefer to have unneeded
734 static constants "optimized away" would just defer writing
735 them out until here. E.g. C++ does this, because static
736 constants are often defined in header files.
738 ??? A tempting alternative (for both C and C++) would be
739 to force a constant to be written if and only if it is
740 defined in a main file, as opposed to an include file. */
742 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
744 struct varpool_node *node;
746 node = varpool_node (decl);
750 else if (node->alias)
752 else if (!cgraph_global_info_ready
754 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
756 else if (node->needed)
758 else if (DECL_COMDAT (decl))
760 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
761 && (optimize || !flag_keep_static_consts
762 || DECL_ARTIFICIAL (decl)))
767 rest_of_decl_compilation (decl, 1, 1);
775 /* Do any final processing required for the declarations in VEC, of
776 which there are LEN. We write out inline functions and variables
777 that have been deferred until this point, but which are required.
778 Returns nonzero if anything was put out. */
781 wrapup_global_declarations (tree *vec, int len)
783 bool reconsider, output_something = false;
786 for (i = 0; i < len; i++)
787 wrapup_global_declaration_1 (vec[i]);
789 /* Now emit any global variables or functions that we have been
790 putting off. We need to loop in case one of the things emitted
791 here references another one which comes earlier in the list. */
795 for (i = 0; i < len; i++)
796 reconsider |= wrapup_global_declaration_2 (vec[i]);
798 output_something = true;
802 return output_something;
805 /* A subroutine of check_global_declarations. Issue appropriate warnings
806 for the global declaration DECL. */
809 check_global_declaration_1 (tree decl)
811 /* Warn about any function declared static but not defined. We don't
812 warn about variables, because many programs have static variables
813 that exist only to get some text into the object file. */
814 if (TREE_CODE (decl) == FUNCTION_DECL
815 && DECL_INITIAL (decl) == 0
816 && DECL_EXTERNAL (decl)
817 && ! DECL_ARTIFICIAL (decl)
818 && ! TREE_NO_WARNING (decl)
819 && ! TREE_PUBLIC (decl)
820 && (warn_unused_function
821 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
823 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
824 pedwarn (0, "%q+F used but never defined", decl);
826 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
827 /* This symbol is effectively an "extern" declaration now. */
828 TREE_PUBLIC (decl) = 1;
829 assemble_external (decl);
832 /* Warn about static fns or vars defined but not used. */
833 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
834 /* We don't warn about "static const" variables because the
835 "rcs_id" idiom uses that construction. */
836 || (warn_unused_variable
837 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
838 && ! DECL_IN_SYSTEM_HEADER (decl)
839 && ! TREE_USED (decl)
840 /* The TREE_USED bit for file-scope decls is kept in the identifier,
841 to handle multiple external decls in different scopes. */
842 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
843 && ! DECL_EXTERNAL (decl)
844 && ! TREE_PUBLIC (decl)
845 /* A volatile variable might be used in some non-obvious way. */
846 && ! TREE_THIS_VOLATILE (decl)
847 /* Global register variables must be declared to reserve them. */
848 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
849 /* Otherwise, ask the language. */
850 && lang_hooks.decls.warn_unused_global (decl))
851 warning ((TREE_CODE (decl) == FUNCTION_DECL)
852 ? OPT_Wunused_function
853 : OPT_Wunused_variable,
854 "%q+D defined but not used", decl);
857 /* Issue appropriate warnings for the global declarations in VEC (of
858 which there are LEN). */
861 check_global_declarations (tree *vec, int len)
865 for (i = 0; i < len; i++)
866 check_global_declaration_1 (vec[i]);
869 /* Emit debugging information for all global declarations in VEC. */
872 emit_debug_global_declarations (tree *vec, int len)
876 /* Avoid confusing the debug information machinery when there are errors. */
877 if (errorcount != 0 || sorrycount != 0)
880 timevar_push (TV_SYMOUT);
881 for (i = 0; i < len; i++)
882 debug_hooks->global_decl (vec[i]);
883 timevar_pop (TV_SYMOUT);
886 /* Warn about a use of an identifier which was marked deprecated. */
888 warn_deprecated_use (tree node)
890 if (node == 0 || !warn_deprecated_decl)
895 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
896 warning (OPT_Wdeprecated_declarations,
897 "%qD is deprecated (declared at %s:%d)",
898 node, xloc.file, xloc.line);
900 else if (TYPE_P (node))
902 const char *what = NULL;
903 tree decl = TYPE_STUB_DECL (node);
905 if (TYPE_NAME (node))
907 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
908 what = IDENTIFIER_POINTER (TYPE_NAME (node));
909 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
910 && DECL_NAME (TYPE_NAME (node)))
911 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
916 expanded_location xloc
917 = expand_location (DECL_SOURCE_LOCATION (decl));
919 warning (OPT_Wdeprecated_declarations,
920 "%qs is deprecated (declared at %s:%d)", what,
921 xloc.file, xloc.line);
923 warning (OPT_Wdeprecated_declarations,
924 "type is deprecated (declared at %s:%d)",
925 xloc.file, xloc.line);
930 warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what);
932 warning (OPT_Wdeprecated_declarations, "type is deprecated");
937 /* Compile an entire translation unit. Write a file of assembly
938 output and various debugging dumps. */
943 /* Initialize yet another pass. */
945 ggc_protect_identifiers = true;
948 init_final (main_input_filename);
949 coverage_init (aux_base_name);
952 timevar_push (TV_PARSE);
954 /* Call the parser, which parses the entire file (calling
955 rest_of_compilation for each function). */
956 lang_hooks.parse_file (set_yydebug);
958 /* Compilation is now finished except for writing
959 what's left of the symbol table output. */
960 timevar_pop (TV_PARSE);
962 if (flag_syntax_only)
965 ggc_protect_identifiers = false;
967 lang_hooks.decls.final_write_globals ();
969 if (errorcount || sorrycount)
972 varpool_assemble_pending_decls ();
975 /* This must occur after the loop to output deferred functions.
976 Else the coverage initializer would not be emitted if all the
977 functions in this compilation unit were deferred. */
980 /* Likewise for mudflap static object registrations. */
982 mudflap_finish_file ();
984 /* Likewise for emulated thread-local storage. */
985 if (!targetm.have_tls)
988 output_shared_constant_pool ();
989 output_object_blocks ();
991 /* Write out any pending weak symbol declarations. */
994 /* Do dbx symbols. */
995 timevar_push (TV_SYMOUT);
997 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
998 if (dwarf2out_do_frame ())
999 dwarf2out_frame_finish ();
1002 (*debug_hooks->finish) (main_input_filename);
1003 timevar_pop (TV_SYMOUT);
1005 /* Output some stuff at end of file if nec. */
1007 dw2_output_indirect_constants ();
1009 /* Flush any pending external directives. */
1010 process_pending_assemble_externals ();
1012 /* Attach a special .ident directive to the end of the file to identify
1013 the version of GCC which compiled this code. The format of the .ident
1014 string is patterned after the ones produced by native SVR4 compilers. */
1018 const char *pkg_version = "(GNU) ";
1020 if (strcmp ("(GCC) ", pkgversion_string))
1021 pkg_version = pkgversion_string;
1022 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1023 IDENT_ASM_OP, pkg_version, version_string);
1027 /* This must be at the end. Some target ports emit end of file directives
1028 into the assembly file here, and hence we can not output anything to the
1029 assembly file after this point. */
1030 targetm.asm_out.file_end ();
1033 /* Parse a -d... command line switch. */
1036 decode_d_option (const char *arg)
1047 flag_print_asm_name = 1;
1050 flag_dump_rtl_in_asm = 1;
1051 flag_print_asm_name = 1;
1054 graph_dump_format = vcg;
1057 rtl_dump_and_exit = 1;
1062 case 'D': /* These are handled by the preprocessor. */
1069 setup_core_dumping();
1072 enable_rtl_dump_file ();
1076 warning (0, "unrecognized gcc debugging option: %c", c);
1081 /* Indexed by enum debug_info_type. */
1082 const char *const debug_type_names[] =
1084 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1087 /* Print version information to FILE.
1088 Each line begins with INDENT (for the case where FILE is the
1089 assembler output file). */
1092 print_version (FILE *file, const char *indent)
1094 static const char fmt1[] =
1096 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1098 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1101 static const char fmt2[] =
1102 N_("GMP version %s, MPFR version %s.\n");
1103 static const char fmt3[] =
1104 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1105 static const char fmt4[] =
1106 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1108 #define __VERSION__ "[?]"
1111 file == stderr ? _(fmt1) : fmt1,
1112 indent, *indent != 0 ? " " : "",
1113 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1114 indent, __VERSION__);
1116 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1117 two string formats, "i.j.k" and "i.j" when k is zero. */
1118 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1119 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1120 #if __GNU_MP_VERSION_PATCHLEVEL == 0
1121 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1122 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1124 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1125 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1126 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1129 file == stderr ? _(fmt2) : fmt2,
1130 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING);
1131 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1133 file == stderr ? _(fmt3) : fmt3,
1134 indent, *indent != 0 ? " " : "",
1135 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1136 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1138 file == stderr ? _(fmt3) : fmt3,
1139 indent, *indent != 0 ? " " : "",
1140 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1142 file == stderr ? _(fmt4) : fmt4,
1143 indent, *indent != 0 ? " " : "",
1144 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1147 #ifdef ASM_COMMENT_START
1149 print_to_asm_out_file (print_switch_type type, const char * text)
1151 bool prepend_sep = true;
1155 case SWITCH_TYPE_LINE_END:
1156 putc ('\n', asm_out_file);
1159 case SWITCH_TYPE_LINE_START:
1160 fputs (ASM_COMMENT_START, asm_out_file);
1161 return strlen (ASM_COMMENT_START);
1163 case SWITCH_TYPE_DESCRIPTIVE:
1164 if (ASM_COMMENT_START[0] == 0)
1165 prepend_sep = false;
1167 case SWITCH_TYPE_PASSED:
1168 case SWITCH_TYPE_ENABLED:
1170 fputc (' ', asm_out_file);
1171 fprintf (asm_out_file, text);
1172 /* No need to return the length here as
1173 print_single_switch has already done it. */
1183 print_to_stderr (print_switch_type type, const char * text)
1187 case SWITCH_TYPE_LINE_END:
1188 putc ('\n', stderr);
1191 case SWITCH_TYPE_LINE_START:
1194 case SWITCH_TYPE_PASSED:
1195 case SWITCH_TYPE_ENABLED:
1196 fputc (' ', stderr);
1199 case SWITCH_TYPE_DESCRIPTIVE:
1200 fprintf (stderr, text);
1201 /* No need to return the length here as
1202 print_single_switch has already done it. */
1210 /* Print an option value and return the adjusted position in the line.
1211 ??? print_fn doesn't handle errors, eg disk full; presumably other
1212 code will catch a disk full though. */
1215 print_single_switch (print_switch_fn_type print_fn,
1217 print_switch_type type,
1220 /* The ultrix fprintf returns 0 on success, so compute the result
1221 we want here since we need it for the following test. The +1
1222 is for the separator character that will probably be emitted. */
1223 int len = strlen (text) + 1;
1226 && pos + len > MAX_LINE)
1228 print_fn (SWITCH_TYPE_LINE_END, NULL);
1233 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1235 print_fn (type, text);
1239 /* Print active target switches using PRINT_FN.
1240 POS is the current cursor position and MAX is the size of a "line".
1241 Each line begins with INDENT and ends with TERM.
1242 Each switch is separated from the next by SEP. */
1245 print_switch_values (print_switch_fn_type print_fn)
1251 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1252 that it can be printed below. This helps reproducibility. */
1253 if (!flag_random_seed)
1254 init_random_seed ();
1256 /* Print the options as passed. */
1257 pos = print_single_switch (print_fn, pos,
1258 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1260 for (p = &save_argv[1]; *p != NULL; p++)
1265 if (strcmp (*p, "-o") == 0
1266 || strcmp (*p, "-dumpbase") == 0
1267 || strcmp (*p, "-auxbase") == 0)
1274 if (strcmp (*p, "-quiet") == 0
1275 || strcmp (*p, "-version") == 0)
1282 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1286 print_fn (SWITCH_TYPE_LINE_END, NULL);
1288 /* Print the -f and -m options that have been enabled.
1289 We don't handle language specific options but printing argv
1291 pos = print_single_switch (print_fn, 0,
1292 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1294 for (j = 0; j < cl_options_count; j++)
1295 if ((cl_options[j].flags & CL_REPORT)
1296 && option_enabled (j) > 0)
1297 pos = print_single_switch (print_fn, pos,
1298 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1300 print_fn (SWITCH_TYPE_LINE_END, NULL);
1303 /* Open assembly code output file. Do this even if -fsyntax-only is
1304 on, because then the driver will have provided the name of a
1305 temporary file or bit bucket for us. NAME is the file specified on
1306 the command line, possibly NULL. */
1308 init_asm_output (const char *name)
1310 if (name == NULL && asm_file_name == 0)
1311 asm_out_file = stdout;
1314 if (asm_file_name == 0)
1316 int len = strlen (dump_base_name);
1317 char *dumpname = XNEWVEC (char, len + 6);
1319 memcpy (dumpname, dump_base_name, len + 1);
1320 strip_off_ending (dumpname, len);
1321 strcat (dumpname, ".s");
1322 asm_file_name = dumpname;
1324 if (!strcmp (asm_file_name, "-"))
1325 asm_out_file = stdout;
1327 asm_out_file = fopen (asm_file_name, "w+b");
1328 if (asm_out_file == 0)
1329 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1332 if (!flag_syntax_only)
1334 targetm.asm_out.file_start ();
1336 if (flag_record_gcc_switches)
1338 if (targetm.asm_out.record_gcc_switches)
1340 /* Let the target know that we are about to start recording. */
1341 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1343 /* Now record the switches. */
1344 print_switch_values (targetm.asm_out.record_gcc_switches);
1345 /* Let the target know that the recording is over. */
1346 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1350 inform ("-frecord-gcc-switches is not supported by the current target");
1353 #ifdef ASM_COMMENT_START
1354 if (flag_verbose_asm)
1356 /* Print the list of switches in effect
1357 into the assembler file as comments. */
1358 print_version (asm_out_file, ASM_COMMENT_START);
1359 print_switch_values (print_to_asm_out_file);
1360 fprintf (asm_out_file, "\n");
1366 /* Return true if the state of option OPTION should be stored in PCH files
1367 and checked by default_pch_valid_p. Store the option's current state
1371 option_affects_pch_p (int option, struct cl_option_state *state)
1373 if ((cl_options[option].flags & CL_TARGET) == 0)
1375 if (cl_options[option].flag_var == &target_flags)
1376 if (targetm.check_pch_target_flags)
1378 return get_option_state (option, state);
1381 /* Default version of get_pch_validity.
1382 By default, every flag difference is fatal; that will be mostly right for
1383 most targets, but completely right for very few. */
1386 default_get_pch_validity (size_t *len)
1388 struct cl_option_state state;
1393 if (targetm.check_pch_target_flags)
1394 *len += sizeof (target_flags);
1395 for (i = 0; i < cl_options_count; i++)
1396 if (option_affects_pch_p (i, &state))
1399 result = r = XNEWVEC (char, *len);
1403 if (targetm.check_pch_target_flags)
1405 memcpy (r, &target_flags, sizeof (target_flags));
1406 r += sizeof (target_flags);
1409 for (i = 0; i < cl_options_count; i++)
1410 if (option_affects_pch_p (i, &state))
1412 memcpy (r, state.data, state.size);
1419 /* Return a message which says that a PCH file was created with a different
1420 setting of OPTION. */
1423 pch_option_mismatch (const char *option)
1427 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1429 return _("out of memory");
1433 /* Default version of pch_valid_p. */
1436 default_pch_valid_p (const void *data_p, size_t len)
1438 struct cl_option_state state;
1439 const char *data = (const char *)data_p;
1442 /* -fpic and -fpie also usually make a PCH invalid. */
1443 if (data[0] != flag_pic)
1444 return _("created and used with different settings of -fpic");
1445 if (data[1] != flag_pie)
1446 return _("created and used with different settings of -fpie");
1449 /* Check target_flags. */
1450 if (targetm.check_pch_target_flags)
1455 memcpy (&tf, data, sizeof (target_flags));
1456 data += sizeof (target_flags);
1457 len -= sizeof (target_flags);
1458 r = targetm.check_pch_target_flags (tf);
1463 for (i = 0; i < cl_options_count; i++)
1464 if (option_affects_pch_p (i, &state))
1466 if (memcmp (data, state.data, state.size) != 0)
1467 return pch_option_mismatch (cl_options[i].opt_text);
1475 /* Default tree printer. Handles declarations only. */
1477 default_tree_printer (pretty_printer * pp, text_info *text, const char *spec,
1478 int precision, bool wide, bool set_locus, bool hash)
1482 /* FUTURE: %+x should set the locus. */
1483 if (precision != 0 || wide || hash)
1489 t = va_arg (*text->args_ptr, tree);
1490 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1491 t = DECL_DEBUG_EXPR (t);
1496 t = va_arg (*text->args_ptr, tree);
1503 if (set_locus && text->locus)
1504 *text->locus = DECL_SOURCE_LOCATION (t);
1508 const char *n = DECL_NAME (t)
1509 ? lang_hooks.decl_printable_name (t, 2)
1514 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1519 /* A helper function; used as the reallocator function for cpp's line
1522 realloc_for_line_map (void *ptr, size_t len)
1524 return ggc_realloc (ptr, len);
1527 /* Initialization of the front end environment, before command line
1528 options are parsed. Signal handlers, internationalization etc.
1529 ARGV0 is main's argv[0]. */
1531 general_init (const char *argv0)
1535 p = argv0 + strlen (argv0);
1536 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1540 xmalloc_set_program_name (progname);
1544 /* Unlock the stdio streams. */
1545 unlock_std_streams ();
1547 gcc_init_libintl ();
1549 /* Initialize the diagnostics reporting machinery, so option parsing
1550 can give warnings and errors. */
1551 diagnostic_initialize (global_dc);
1552 /* Set a default printer. Language specific initializations will
1553 override it later. */
1554 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1556 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1558 signal (SIGSEGV, crash_signal);
1561 signal (SIGILL, crash_signal);
1564 signal (SIGBUS, crash_signal);
1567 signal (SIGABRT, crash_signal);
1569 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1570 signal (SIGIOT, crash_signal);
1573 signal (SIGFPE, crash_signal);
1576 /* Other host-specific signal setup. */
1577 (*host_hooks.extra_signals)();
1579 /* Initialize the garbage-collector, string pools and tree type hash
1583 line_table = GGC_NEW (struct line_maps);
1584 linemap_init (line_table);
1585 line_table->reallocator = realloc_for_line_map;
1588 /* Initialize register usage now so switches may override. */
1591 /* Register the language-independent parameters. */
1592 add_params (lang_independent_params, LAST_PARAM);
1594 /* This must be done after add_params but before argument processing. */
1595 init_ggc_heuristics();
1596 init_optimization_passes ();
1597 statistics_early_init ();
1600 /* Return true if the current target supports -fsection-anchors. */
1603 target_supports_section_anchors_p (void)
1605 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1608 if (targetm.asm_out.output_anchor == NULL)
1614 /* Default the align_* variables to 1 if they're still unset, and
1615 set up the align_*_log variables. */
1617 init_alignments (void)
1619 if (align_loops <= 0)
1621 if (align_loops_max_skip > align_loops)
1622 align_loops_max_skip = align_loops - 1;
1623 align_loops_log = floor_log2 (align_loops * 2 - 1);
1624 if (align_jumps <= 0)
1626 if (align_jumps_max_skip > align_jumps)
1627 align_jumps_max_skip = align_jumps - 1;
1628 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1629 if (align_labels <= 0)
1631 align_labels_log = floor_log2 (align_labels * 2 - 1);
1632 if (align_labels_max_skip > align_labels)
1633 align_labels_max_skip = align_labels - 1;
1634 if (align_functions <= 0)
1635 align_functions = 1;
1636 align_functions_log = floor_log2 (align_functions * 2 - 1);
1639 /* Process the options that have been parsed. */
1641 process_options (void)
1643 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1644 This can happen with incorrect pre-processed input. */
1645 debug_hooks = &do_nothing_debug_hooks;
1647 /* This replaces set_Wunused. */
1648 if (warn_unused_function == -1)
1649 warn_unused_function = warn_unused;
1650 if (warn_unused_label == -1)
1651 warn_unused_label = warn_unused;
1652 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1653 if (warn_unused_parameter == -1)
1654 warn_unused_parameter = (warn_unused && extra_warnings);
1655 if (warn_unused_variable == -1)
1656 warn_unused_variable = warn_unused;
1657 if (warn_unused_value == -1)
1658 warn_unused_value = warn_unused;
1660 /* Allow the front end to perform consistency checks and do further
1661 initialization based on the command line options. This hook also
1662 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1663 so we can correctly initialize debug output. */
1664 no_backend = lang_hooks.post_options (&main_input_filename);
1666 #ifdef OVERRIDE_OPTIONS
1667 /* Some machines may reject certain combinations of options. */
1671 if (flag_section_anchors && !target_supports_section_anchors_p ())
1673 warning (OPT_fsection_anchors,
1674 "this target does not support %qs", "-fsection-anchors");
1675 flag_section_anchors = 0;
1678 if (flag_short_enums == 2)
1679 flag_short_enums = targetm.default_short_enums ();
1681 /* Set aux_base_name if not already set. */
1684 else if (main_input_filename)
1686 char *name = xstrdup (lbasename (main_input_filename));
1688 strip_off_ending (name, strlen (name));
1689 aux_base_name = name;
1692 aux_base_name = "gccaux";
1694 /* Unrolling all loops implies that standard loop unrolling must also
1696 if (flag_unroll_all_loops)
1697 flag_unroll_loops = 1;
1699 /* The loop unrolling code assumes that cse will be run after loop.
1700 web and rename-registers also help when run after loop unrolling. */
1702 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1703 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1704 if (flag_web == AUTODETECT_VALUE)
1705 flag_web = flag_unroll_loops || flag_peel_loops;
1706 if (flag_rename_registers == AUTODETECT_VALUE)
1707 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1709 if (flag_non_call_exceptions)
1710 flag_asynchronous_unwind_tables = 1;
1711 if (flag_asynchronous_unwind_tables)
1712 flag_unwind_tables = 1;
1714 if (flag_value_profile_transformations)
1715 flag_profile_values = 1;
1717 /* Warn about options that are not supported on this machine. */
1718 #ifndef INSN_SCHEDULING
1719 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1720 warning (0, "instruction scheduling not supported on this target machine");
1723 if (flag_delayed_branch)
1724 warning (0, "this target machine does not have delayed branches");
1727 user_label_prefix = USER_LABEL_PREFIX;
1728 if (flag_leading_underscore != -1)
1730 /* If the default prefix is more complicated than "" or "_",
1731 issue a warning and ignore this option. */
1732 if (user_label_prefix[0] == 0 ||
1733 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1735 user_label_prefix = flag_leading_underscore ? "_" : "";
1738 warning (0, "-f%sleading-underscore not supported on this target machine",
1739 flag_leading_underscore ? "" : "no-");
1742 /* If we are in verbose mode, write out the version and maybe all the
1743 option flags in use. */
1746 print_version (stderr, "");
1748 print_switch_values (print_to_stderr);
1751 if (flag_syntax_only)
1753 write_symbols = NO_DEBUG;
1757 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1759 if (debug_info_level == DINFO_LEVEL_NONE)
1760 write_symbols = NO_DEBUG;
1762 /* Now we know write_symbols, set up the debug hooks based on it.
1763 By default we do nothing for debug output. */
1764 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1765 default_debug_hooks = &do_nothing_debug_hooks;
1766 #if defined(DBX_DEBUGGING_INFO)
1767 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1768 default_debug_hooks = &dbx_debug_hooks;
1770 #if defined(XCOFF_DEBUGGING_INFO)
1771 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1772 default_debug_hooks = &xcoff_debug_hooks;
1774 #ifdef SDB_DEBUGGING_INFO
1775 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1776 default_debug_hooks = &sdb_debug_hooks;
1778 #ifdef DWARF2_DEBUGGING_INFO
1779 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1780 default_debug_hooks = &dwarf2_debug_hooks;
1782 #ifdef VMS_DEBUGGING_INFO
1783 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1784 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1785 default_debug_hooks = &vmsdbg_debug_hooks;
1788 if (write_symbols == NO_DEBUG)
1790 #if defined(DBX_DEBUGGING_INFO)
1791 else if (write_symbols == DBX_DEBUG)
1792 debug_hooks = &dbx_debug_hooks;
1794 #if defined(XCOFF_DEBUGGING_INFO)
1795 else if (write_symbols == XCOFF_DEBUG)
1796 debug_hooks = &xcoff_debug_hooks;
1798 #ifdef SDB_DEBUGGING_INFO
1799 else if (write_symbols == SDB_DEBUG)
1800 debug_hooks = &sdb_debug_hooks;
1802 #ifdef DWARF2_DEBUGGING_INFO
1803 else if (write_symbols == DWARF2_DEBUG)
1804 debug_hooks = &dwarf2_debug_hooks;
1806 #ifdef VMS_DEBUGGING_INFO
1807 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1808 debug_hooks = &vmsdbg_debug_hooks;
1811 error ("target system does not support the \"%s\" debug format",
1812 debug_type_names[write_symbols]);
1814 /* Now we know which debug output will be used so we can set
1815 flag_var_tracking, flag_rename_registers if the user has
1816 not specified them. */
1817 if (debug_info_level < DINFO_LEVEL_NORMAL
1818 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1820 if (flag_var_tracking == 1
1821 || flag_var_tracking_uninit == 1)
1823 if (debug_info_level < DINFO_LEVEL_NORMAL)
1824 warning (0, "variable tracking requested, but useless unless "
1825 "producing debug info");
1827 warning (0, "variable tracking requested, but not supported "
1828 "by this debug format");
1830 flag_var_tracking = 0;
1831 flag_var_tracking_uninit = 0;
1834 if (flag_rename_registers == AUTODETECT_VALUE)
1835 flag_rename_registers = default_debug_hooks->var_location
1836 != do_nothing_debug_hooks.var_location;
1838 if (flag_var_tracking == AUTODETECT_VALUE)
1839 flag_var_tracking = optimize >= 1;
1841 if (flag_tree_cselim == AUTODETECT_VALUE)
1842 #ifdef HAVE_conditional_move
1843 flag_tree_cselim = 1;
1845 flag_tree_cselim = 0;
1848 /* If the user specifically requested variable tracking with tagging
1849 uninitialized variables, we need to turn on variable tracking.
1850 (We already determined above that variable tracking is feasible.) */
1851 if (flag_var_tracking_uninit)
1852 flag_var_tracking = 1;
1854 /* If auxiliary info generation is desired, open the output file.
1855 This goes in the same directory as the source file--unlike
1856 all the other output files. */
1857 if (flag_gen_aux_info)
1859 aux_info_file = fopen (aux_info_file_name, "w");
1860 if (aux_info_file == 0)
1861 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1864 if (! targetm.have_named_sections)
1866 if (flag_function_sections)
1868 warning (0, "-ffunction-sections not supported for this target");
1869 flag_function_sections = 0;
1871 if (flag_data_sections)
1873 warning (0, "-fdata-sections not supported for this target");
1874 flag_data_sections = 0;
1878 if (flag_function_sections && profile_flag)
1880 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
1881 flag_function_sections = 0;
1884 #ifndef HAVE_prefetch
1885 if (flag_prefetch_loop_arrays)
1887 warning (0, "-fprefetch-loop-arrays not supported for this target");
1888 flag_prefetch_loop_arrays = 0;
1891 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1893 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
1894 flag_prefetch_loop_arrays = 0;
1898 /* This combination of options isn't handled for i386 targets and doesn't
1899 make much sense anyway, so don't allow it. */
1900 if (flag_prefetch_loop_arrays && optimize_size)
1902 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
1903 flag_prefetch_loop_arrays = 0;
1906 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1907 if (flag_signaling_nans)
1908 flag_trapping_math = 1;
1910 /* We cannot reassociate if we want traps or signed zeros. Â */
1911 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
1913 warning (0, "-fassociative-math disabled; other options take precedence");
1914 flag_associative_math = 0;
1917 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1918 if (flag_cx_limited_range)
1919 flag_complex_method = 0;
1921 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
1922 if (flag_cx_fortran_rules)
1923 flag_complex_method = 1;
1925 /* Targets must be able to place spill slots at lower addresses. If the
1926 target already uses a soft frame pointer, the transition is trivial. */
1927 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
1929 warning (0, "-fstack-protector not supported for this target");
1930 flag_stack_protect = 0;
1932 if (!flag_stack_protect)
1933 warn_stack_protect = 0;
1935 /* ??? Unwind info is not correct around the CFG unless either a frame
1936 pointer is present or A_O_A is set. Fixing this requires rewriting
1937 unwind info generation to be aware of the CFG and propagating states
1939 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
1940 && flag_omit_frame_pointer)
1942 warning (0, "unwind tables currently require a frame pointer "
1944 flag_omit_frame_pointer = 0;
1948 /* This function can be called multiple times to reinitialize the compiler
1949 back end when register classes or instruction sets have changed,
1950 before each function. */
1952 backend_init_target (void)
1954 /* Initialize alignment variables. */
1957 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
1958 to initialize reg_raw_mode[]. */
1961 /* This invokes target hooks to set fixed_reg[] etc, which is
1965 /* This depends on stack_pointer_rtx. */
1966 init_fake_stack_mems ();
1968 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
1970 init_alias_target ();
1972 /* Depends on HARD_FRAME_POINTER_REGNUM. */
1975 /* The following initialization functions need to generate rtl, so
1976 provide a dummy function context for them. */
1977 init_dummy_function_start ();
1979 /* rtx_cost is mode-dependent, so cached values need to be recomputed
1980 on a mode change. */
1983 /* We may need to recompute regno_save_code[] and regno_restore_code[]
1984 after a mode change as well. */
1985 if (flag_caller_saves)
1986 init_caller_save ();
1987 expand_dummy_function_end ();
1990 /* Initialize the compiler back end. This function is called only once,
1991 when starting the compiler. */
1995 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1996 || debug_info_level == DINFO_LEVEL_VERBOSE
1997 #ifdef VMS_DEBUGGING_INFO
1998 /* Enable line number info for traceback. */
1999 || debug_info_level > DINFO_LEVEL_NONE
2001 || flag_test_coverage);
2004 init_inline_once ();
2005 init_varasm_once ();
2006 save_register_info ();
2008 /* Initialize the target-specific back end pieces. */
2009 backend_init_target ();
2012 /* Initialize things that are both lang-dependent and target-dependent.
2013 This function can be called more than once if target parameters change. */
2015 lang_dependent_init_target (void)
2017 /* This creates various _DECL nodes, so needs to be called after the
2018 front end is initialized. It also depends on the HAVE_xxx macros
2019 generated from the target machine description. */
2022 /* The following initialization functions need to generate rtl, so
2023 provide a dummy function context for them. */
2024 init_dummy_function_start ();
2026 /* Do the target-specific parts of expr initialization. */
2027 init_expr_target ();
2029 /* Although the actions of init_set_costs are language-independent,
2030 it uses optabs, so we cannot call it from backend_init. */
2033 expand_dummy_function_end ();
2036 /* Language-dependent initialization. Returns nonzero on success. */
2038 lang_dependent_init (const char *name)
2040 location_t save_loc = input_location;
2041 if (dump_base_name == 0)
2042 dump_base_name = name && name[0] ? name : "gccdump";
2044 /* Other front-end initialization. */
2045 input_location = BUILTINS_LOCATION;
2046 if (lang_hooks.init () == 0)
2048 input_location = save_loc;
2050 init_asm_output (name);
2052 /* This creates various _DECL nodes, so needs to be called after the
2053 front end is initialized. */
2056 /* Do the target-specific parts of the initialization. */
2057 lang_dependent_init_target ();
2059 /* If dbx symbol table desired, initialize writing it and output the
2060 predefined types. */
2061 timevar_push (TV_SYMOUT);
2063 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2064 if (dwarf2out_do_frame ())
2065 dwarf2out_frame_init ();
2068 /* Now we have the correct original filename, we can initialize
2070 (*debug_hooks->init) (name);
2072 timevar_pop (TV_SYMOUT);
2078 /* Reinitialize everything when target parameters, such as register usage,
2081 target_reinit (void)
2083 /* Reinitialize RTL backend. */
2084 backend_init_target ();
2086 /* Reinitialize lang-dependent parts. */
2087 lang_dependent_init_target ();
2091 dump_memory_report (bool final)
2093 ggc_print_statistics ();
2094 stringpool_statistics ();
2095 dump_tree_statistics ();
2096 dump_gimple_statistics ();
2097 dump_rtx_statistics ();
2098 dump_varray_statistics ();
2099 dump_alloc_pool_statistics ();
2100 dump_bitmap_statistics ();
2101 dump_ggc_loc_statistics (final);
2104 /* Clean up: close opened files, etc. */
2109 /* Close the dump files. */
2110 if (flag_gen_aux_info)
2112 fclose (aux_info_file);
2114 unlink (aux_info_file_name);
2117 /* Close non-debugging input and output files. Take special care to note
2118 whether fclose returns an error, since the pages might still be on the
2119 buffer chain while the file is open. */
2123 if (ferror (asm_out_file) != 0)
2124 fatal_error ("error writing to %s: %m", asm_file_name);
2125 if (fclose (asm_out_file) != 0)
2126 fatal_error ("error closing %s: %m", asm_file_name);
2130 finish_optimization_passes ();
2133 dump_memory_report (true);
2135 /* Language-specific end of compilation actions. */
2136 lang_hooks.finish ();
2139 /* Initialize the compiler, and compile the input file. */
2143 /* Initialize timing first. The C front ends read the main file in
2144 the post_options hook, and C++ does file timings. */
2145 if (time_report || !quiet_flag || flag_detailed_statistics)
2147 timevar_start (TV_TOTAL);
2151 /* Don't do any more if an error has already occurred. */
2154 /* This must be run always, because it is needed to compute the FP
2155 predefined macros, such as __LDBL_MAX__, for targets using non
2156 default FP formats. */
2157 init_adjust_machine_modes ();
2159 /* Set up the back-end if requested. */
2163 /* Language-dependent initialization. Returns true on success. */
2164 if (lang_dependent_init (main_input_filename))
2170 /* Stop timing and print the times. */
2171 timevar_stop (TV_TOTAL);
2172 timevar_print (stderr);
2175 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2176 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2177 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2179 It is not safe to call this function more than once. */
2182 toplev_main (unsigned int argc, const char **argv)
2186 /* Initialization of GCC's environment, and diagnostics. */
2187 general_init (argv[0]);
2189 /* Parse the options and do minimal processing; basically just
2190 enough to default flags appropriately. */
2191 decode_options (argc, argv);
2195 /* Exit early if we can (e.g. -help). */
2196 if (!exit_after_options)
2199 if (warningcount || errorcount)
2200 print_ignored_options ();
2202 if (errorcount || sorrycount)
2203 return (FATAL_EXIT_CODE);
2205 return (SUCCESS_EXIT_CODE);