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