OSDN Git Service

2004-06-03 Chris Demetriou <cgd@broadcom.com>
[pf3gnuchains/gcc-fork.git] / gcc / toplev.c
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 /* This is the top level of cc1/c++.
23    It parses command args, opens files, invokes the various passes
24    in the proper order, and counts the time used by each.
25    Error messages and low-level interface to malloc also handled here.  */
26
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux.  */
29 #undef FFS  /* Some systems define this in param.h.  */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
34
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
38
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
42
43 #include "line-map.h"
44 #include "input.h"
45 #include "tree.h"
46 #include "version.h"
47 #include "rtl.h"
48 #include "tm_p.h"
49 #include "flags.h"
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "except.h"
57 #include "function.h"
58 #include "toplev.h"
59 #include "expr.h"
60 #include "basic-block.h"
61 #include "intl.h"
62 #include "ggc.h"
63 #include "graph.h"
64 #include "loop.h"
65 #include "regs.h"
66 #include "timevar.h"
67 #include "diagnostic.h"
68 #include "params.h"
69 #include "reload.h"
70 #include "dwarf2asm.h"
71 #include "integrate.h"
72 #include "real.h"
73 #include "debug.h"
74 #include "target.h"
75 #include "langhooks.h"
76 #include "cfglayout.h"
77 #include "tree-alias-common.h" 
78 #include "cfgloop.h"
79 #include "hosthooks.h"
80 #include "cgraph.h"
81 #include "opts.h"
82 #include "coverage.h"
83 #include "value-prof.h"
84 #include "alloc-pool.h"
85
86 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
87 #include "dwarf2out.h"
88 #endif
89
90 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
91 #include "dbxout.h"
92 #endif
93
94 #ifdef SDB_DEBUGGING_INFO
95 #include "sdbout.h"
96 #endif
97
98 #ifdef XCOFF_DEBUGGING_INFO
99 #include "xcoffout.h"           /* Needed for external data
100                                    declarations for e.g. AIX 4.x.  */
101 #endif
102
103 static void general_init (const char *);
104 static void do_compile (void);
105 static void process_options (void);
106 static void backend_init (void);
107 static int lang_dependent_init (const char *);
108 static void init_asm_output (const char *);
109 static void finalize (void);
110
111 static void crash_signal (int) ATTRIBUTE_NORETURN;
112 static void setup_core_dumping (void);
113 static void compile_file (void);
114
115 static int print_single_switch (FILE *, int, int, const char *,
116                                 const char *, const char *,
117                                 const char *, const char *);
118 static void print_switch_values (FILE *, int, int, const char *,
119                                  const char *, const char *);
120
121 /* Nonzero to dump debug info whilst parsing (-dy option).  */
122 static int set_yydebug;
123
124 /* True if we don't need a backend (e.g. preprocessing only).  */
125 static bool no_backend;
126
127 /* Length of line when printing switch values.  */
128 #define MAX_LINE 75
129
130 /* Name of program invoked, sans directories.  */
131
132 const char *progname;
133
134 /* Copy of argument vector to toplev_main.  */
135 static const char **save_argv;
136
137 /* Name of top-level original source file (what was input to cpp).
138    This comes from the #-command at the beginning of the actual input.
139    If there isn't any there, then this is the cc1 input file name.  */
140
141 const char *main_input_filename;
142
143 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
144    to optimize and default_debug_hooks in process_options ().  */
145 #define AUTODETECT_FLAG_VAR_TRACKING 2
146
147 /* Current position in real source file.  */
148
149 location_t input_location;
150
151 struct line_maps line_table;
152
153 /* Nonzero if it is unsafe to create any new pseudo registers.  */
154 int no_new_pseudos;
155
156 /* Stack of currently pending input files.  */
157
158 struct file_stack *input_file_stack;
159
160 /* Incremented on each change to input_file_stack.  */
161 int input_file_stack_tick;
162
163 /* Name to use as base of names for dump output files.  */
164
165 const char *dump_base_name;
166
167 /* Name to use as a base for auxiliary output files.  */
168
169 const char *aux_base_name;
170
171 /* Bit flags that specify the machine subtype we are compiling for.
172    Bits are tested using macros TARGET_... defined in the tm.h file
173    and set by `-m...' switches.  Must be defined in rtlanal.c.  */
174
175 extern int target_flags;
176
177 /* A mask of target_flags that includes bit X if X was set or cleared
178    on the command line.  */
179
180 int target_flags_explicit;
181
182 /* Debug hooks - dependent upon command line options.  */
183
184 const struct gcc_debug_hooks *debug_hooks;
185
186 /* Debug hooks - target default.  */
187
188 static const struct gcc_debug_hooks *default_debug_hooks;
189
190 /* Other flags saying which kinds of debugging dump have been requested.  */
191
192 int rtl_dump_and_exit;
193 int flag_print_asm_name;
194 enum graph_dump_types graph_dump_format;
195
196 /* Name for output file of assembly code, specified with -o.  */
197
198 const char *asm_file_name;
199
200 /* Nonzero means do optimizations.  -O.
201    Particular numeric values stand for particular amounts of optimization;
202    thus, -O2 stores 2 here.  However, the optimizations beyond the basic
203    ones are not controlled directly by this variable.  Instead, they are
204    controlled by individual `flag_...' variables that are defaulted
205    based on this variable.  */
206
207 int optimize = 0;
208
209 /* Nonzero means optimize for size.  -Os.
210    The only valid values are zero and nonzero. When optimize_size is
211    nonzero, optimize defaults to 2, but certain individual code
212    bloating optimizations are disabled.  */
213
214 int optimize_size = 0;
215
216 /* The FUNCTION_DECL for the function currently being compiled,
217    or 0 if between functions.  */
218 tree current_function_decl;
219
220 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
221    if none.  */
222 tree current_function_func_begin_label;
223
224 /* A DECL for the current file-scope context.  When using IMA, this heads a
225    chain of FILE_DECLs; currently only C uses it.  */
226
227 tree current_file_decl;
228
229 /* Nonzero if doing dwarf2 duplicate elimination.  */
230
231 int flag_eliminate_dwarf2_dups = 0;
232
233 /* Nonzero if doing unused type elimination.  */
234
235 int flag_eliminate_unused_debug_types = 1;
236
237 /* Nonzero means emit debugging information only for symbols which are used.  */
238 int flag_debug_only_used_symbols = 0;
239
240 /* Nonzero if generating code to do profiling.  */
241
242 int profile_flag = 0;
243
244 /* Nonzero if generating code to profile program flow graph arcs.  */
245
246 int profile_arc_flag = 0;
247
248 /* Nonzero if value histograms should be measured.  */
249
250 int flag_profile_values = 0;
251
252 /* Nonzero if value histograms should be used to optimize code.  */
253 int flag_value_profile_transformations = 0;
254
255 /* Nonzero if generating info for gcov to calculate line test coverage.  */
256
257 int flag_test_coverage = 0;
258
259 /* Nonzero indicates that branch taken probabilities should be calculated.  */
260
261 int flag_branch_probabilities = 0;
262
263 /* Nonzero if basic blocks should be reordered.  */
264
265 int flag_reorder_blocks = 0;
266
267 /* Nonzero if blocks should be partitioned into hot and cold sections in
268    addition to being reordered.  */
269
270 int flag_reorder_blocks_and_partition = 0;
271
272 /* Nonzero if functions should be reordered.  */
273
274 int flag_reorder_functions = 0;
275
276 /* Nonzero if registers should be renamed.  When
277    flag_rename_registers == AUTODETECT_FLAG_VAR_TRACKING it will be set
278    according to optimize and default_debug_hooks in process_options (),
279    but we do not do this yet because it triggers aborts in flow.c.  */
280 int flag_rename_registers = 0;
281 int flag_cprop_registers = 0;
282
283 /* Nonzero for -pedantic switch: warn about anything
284    that standard spec forbids.  */
285
286 int pedantic = 0;
287
288 /* Temporarily suppress certain warnings.
289    This is set while reading code from a system header file.  */
290
291 int in_system_header = 0;
292
293 /* Don't print functions as they are compiled.  -quiet.  */
294
295 int quiet_flag = 0;
296
297 /* Print times taken by the various passes.  -ftime-report.  */
298
299 int time_report = 0;
300
301 /* Print memory still in use at end of compilation (which may have little
302    to do with peak memory consumption).  -fmem-report.  */
303
304 int mem_report = 0;
305
306 /* Nonzero means to collect statistics which might be expensive
307    and to print them when we are done.  */
308 int flag_detailed_statistics = 0;
309
310 /* A random sequence of characters, unless overridden by user.  */
311 const char *flag_random_seed;
312
313 /* A local time stamp derived from the time of compilation. It will be
314    zero if the system cannot provide a time.  It will be -1u, if the
315    user has specified a particular random seed.  */
316 unsigned local_tick;
317
318 /* -f flags.  */
319
320 /* Nonzero means `char' should be signed.  */
321
322 int flag_signed_char;
323
324 /* Nonzero means give an enum type only as many bytes as it needs.  A value
325    of 2 means it has not yet been initialized.  */
326
327 int flag_short_enums;
328
329 /* Nonzero for -fcaller-saves: allocate values in regs that need to
330    be saved across function calls, if that produces overall better code.
331    Optional now, so people can test it.  */
332
333 int flag_caller_saves = 0;
334
335 /* Nonzero if structures and unions should be returned in memory.
336
337    This should only be defined if compatibility with another compiler or
338    with an ABI is needed, because it results in slower code.  */
339
340 #ifndef DEFAULT_PCC_STRUCT_RETURN
341 #define DEFAULT_PCC_STRUCT_RETURN 1
342 #endif
343
344 /* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */
345
346 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
347
348 /* Nonzero for -fforce-mem: load memory value into a register
349    before arithmetic on it.  This makes better cse but slower compilation.  */
350
351 int flag_force_mem = 0;
352
353 /* Nonzero for -fforce-addr: load memory address into a register before
354    reference to memory.  This makes better cse but slower compilation.  */
355
356 int flag_force_addr = 0;
357
358 /* Nonzero for -fdefer-pop: don't pop args after each function call;
359    instead save them up to pop many calls' args with one insns.  */
360
361 int flag_defer_pop = 0;
362
363 /* Nonzero for -ffloat-store: don't allocate floats and doubles
364    in extended-precision registers.  */
365
366 int flag_float_store = 0;
367
368 /* Nonzero for -fcse-follow-jumps:
369    have cse follow jumps to do a more extensive job.  */
370
371 int flag_cse_follow_jumps;
372
373 /* Nonzero for -fcse-skip-blocks:
374    have cse follow a branch around a block.  */
375 int flag_cse_skip_blocks;
376
377 /* Nonzero for -fexpensive-optimizations:
378    perform miscellaneous relatively-expensive optimizations.  */
379 int flag_expensive_optimizations;
380
381 /* Nonzero for -fthread-jumps:
382    have jump optimize output of loop.  */
383
384 int flag_thread_jumps;
385
386 /* Nonzero enables strength-reduction in loop.c.  */
387
388 int flag_strength_reduce = 0;
389
390 /* Nonzero enables loop unrolling in unroll.c.  Only loops for which the
391    number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
392    UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
393    unrolled.  */
394
395 int flag_old_unroll_loops;
396
397 /* Nonzero enables loop unrolling in unroll.c.  All loops are unrolled.
398    This is generally not a win.  */
399
400 int flag_old_unroll_all_loops;
401
402 /* Enables unrolling of simple loops in loop-unroll.c.  */
403 int flag_unroll_loops;
404
405 /* Enables unrolling of all loops in loop-unroll.c.  */
406 int flag_unroll_all_loops;
407
408 /* Nonzero enables loop peeling.  */
409 int flag_peel_loops;
410
411 /* Nonzero enables loop unswitching.  */
412 int flag_unswitch_loops;
413
414 /* Nonzero enables prefetch optimizations for arrays in loops.  */
415
416 int flag_prefetch_loop_arrays;
417
418 /* Nonzero forces all invariant computations in loops to be moved
419    outside the loop.  */
420
421 int flag_move_all_movables = 0;
422
423 /* Nonzero forces all general induction variables in loops to be
424    strength reduced.  */
425
426 int flag_reduce_all_givs = 0;
427
428 /* Nonzero to perform full register move optimization passes.  This is the
429    default for -O2.  */
430
431 int flag_regmove = 0;
432
433 /* Nonzero means don't put addresses of constant functions in registers.
434    Used for compiling the Unix kernel, where strange substitutions are
435    done on the assembly output.  */
436
437 int flag_no_function_cse = 0;
438
439 /* Nonzero for -fomit-frame-pointer:
440    don't make a frame pointer in simple functions that don't require one.  */
441
442 int flag_omit_frame_pointer = 0;
443
444 /* Nonzero means place each function into its own section on those platforms
445    which support arbitrary section names and unlimited numbers of sections.  */
446
447 int flag_function_sections = 0;
448
449 /* ... and similar for data.  */
450
451 int flag_data_sections = 0;
452
453 /* Nonzero to inhibit use of define_optimization peephole opts.  */
454
455 int flag_no_peephole = 0;
456
457 /* Nonzero allows GCC to optimize sibling and tail recursive calls.  */
458
459 int flag_optimize_sibling_calls = 0;
460
461 /* Nonzero means the front end generally wants `errno' maintained by math
462    operations, like built-in SQRT.  */
463
464 int flag_errno_math = 1;
465
466 /* Nonzero means that unsafe floating-point math optimizations are allowed
467    for the sake of speed.  IEEE compliance is not guaranteed, and operations
468    are allowed to assume that their arguments and results are "normal"
469    (e.g., nonnegative for SQRT).  */
470
471 int flag_unsafe_math_optimizations = 0;
472
473 /* Nonzero means that no NaNs or +-Infs are expected.  */
474
475 int flag_finite_math_only = 0;
476
477 /* Zero means that floating-point math operations cannot generate a
478    (user-visible) trap.  This is the case, for example, in nonstop
479    IEEE 754 arithmetic.  Trapping conditions include division by zero,
480    overflow, underflow, invalid and inexact, but does not include
481    operations on signaling NaNs (see below).  */
482
483 int flag_trapping_math = 1;
484
485 /* Nonzero means disable transformations that assume default floating
486    point rounding behavior.  */
487
488 int flag_rounding_math = 0;
489
490 /* Nonzero means disable transformations observable by signaling NaNs.
491    This option implies that any operation on an IEEE signaling NaN can
492    generate a (user-visible) trap.  */
493
494 int flag_signaling_nans = 0;
495
496 /* 0 means straightforward implementation of complex divide acceptable.
497    1 means wide ranges of inputs must work for complex divide.
498    2 means C99-like requirements for complex divide (not yet implemented).  */
499
500 int flag_complex_divide_method = 0;
501
502 /* Nonzero means just do syntax checking; don't output anything.  */
503
504 int flag_syntax_only = 0;
505
506 /* Nonzero means performs web construction pass.  When flag_web ==
507    AUTODETECT_FLAG_VAR_TRACKING it will be set according to optimize
508    and default_debug_hooks in process_options ().  */
509
510 int flag_web = AUTODETECT_FLAG_VAR_TRACKING;
511
512 /* Nonzero means perform loop optimizer.  */
513
514 int flag_loop_optimize;
515
516 /* Nonzero means perform crossjumping.  */
517
518 int flag_crossjumping;
519
520 /* Nonzero means perform if conversion.  */
521
522 int flag_if_conversion;
523
524 /* Nonzero means perform if conversion after reload.  */
525
526 int flag_if_conversion2;
527
528 /* Nonzero means to use global dataflow analysis to eliminate
529    useless null pointer tests.  */
530
531 int flag_delete_null_pointer_checks;
532
533 /* Nonzero means perform global CSE.  */
534
535 int flag_gcse = 0;
536
537 /* Nonzero means to do the enhanced load motion during gcse, which trys
538    to hoist loads by not killing them when a store to the same location
539    is seen.  */
540
541 int flag_gcse_lm = 1;
542
543 /* Nonzero means to perform store motion after gcse, which will try to
544    move stores closer to the exit block.  Its not very effective without
545    flag_gcse_lm.  */
546
547 int flag_gcse_sm = 1;
548
549 /* Nonzero if we want to perform redundant load after store elimination
550    in gcse.  */
551
552 int flag_gcse_las = 1;
553
554 /* Nonzero means perform global cse after register allocation.  */
555 int flag_gcse_after_reload = 0;
556
557 /* Perform target register optimization before prologue / epilogue
558    threading.  */
559
560 int flag_branch_target_load_optimize = 0;
561
562 /* Perform target register optimization after prologue / epilogue
563    threading and jump2.  */
564
565 int flag_branch_target_load_optimize2 = 0;
566
567 /* For the bt-load pass, nonzero means don't re-use branch target registers
568    in any basic block.  */
569
570 int flag_btr_bb_exclusive;
571
572 /* Nonzero means to rerun cse after loop optimization.  This increases
573    compilation time about 20% and picks up a few more common expressions.  */
574
575 int flag_rerun_cse_after_loop;
576
577 /* Nonzero means to run loop optimizations twice.  */
578
579 int flag_rerun_loop_opt;
580
581 /* Nonzero for -finline-functions: ok to inline functions that look like
582    good inline candidates.  */
583
584 int flag_inline_functions;
585
586 /* Nonzero for -fkeep-inline-functions: even if we make a function
587    go inline everywhere, keep its definition around for debugging
588    purposes.  */
589
590 int flag_keep_inline_functions;
591
592 /* Nonzero means that functions will not be inlined.  */
593
594 int flag_no_inline = 2;
595
596 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
597    not just because the tree inliner turned us off.  */
598
599 int flag_really_no_inline = 2;
600
601 /* Nonzero means that we should emit static const variables
602    regardless of whether or not optimization is turned on.  */
603
604 int flag_keep_static_consts = 1;
605
606 /* Nonzero means we should be saving declaration info into a .X file.  */
607
608 int flag_gen_aux_info = 0;
609
610 /* Specified name of aux-info file.  */
611
612 const char *aux_info_file_name;
613
614 /* Nonzero means make the text shared if supported.  */
615
616 int flag_shared_data;
617
618 /* Nonzero means schedule into delayed branch slots if supported.  */
619
620 int flag_delayed_branch;
621
622 /* Nonzero if we are compiling pure (sharable) code.
623    Value is 1 if we are doing "small" pic; value is 2 if we're doing
624    "large" pic.  */
625
626 int flag_pic;
627
628 /* Nonzero if we are compiling position independent code for executable.
629    The value is 1 if we are doing "small" pic; value is 2 if we're doing
630    "large" pic.  */
631
632 int flag_pie;
633
634 /* Nonzero if we are compiling code for a shared library, zero for
635    executable.  */
636
637 int flag_shlib;
638
639 /* Set to the default thread-local storage (tls) model to use.  */
640
641 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
642
643 /* Nonzero means generate extra code for exception handling and enable
644    exception handling.  */
645
646 int flag_exceptions;
647
648 /* Nonzero means generate frame unwind info table when supported.  */
649
650 int flag_unwind_tables = 0;
651
652 /* Nonzero means generate frame unwind info table exact at each insn
653    boundary.  */
654
655 int flag_asynchronous_unwind_tables = 0;
656
657 /* Nonzero means don't place uninitialized global data in common storage
658    by default.  */
659
660 int flag_no_common;
661
662 /* Nonzero means change certain warnings into errors.
663    Usually these are warnings about failure to conform to some standard.  */
664
665 int flag_pedantic_errors = 0;
666
667 /* flag_schedule_insns means schedule insns within basic blocks (before
668    local_alloc).
669    flag_schedule_insns_after_reload means schedule insns after
670    global_alloc.  */
671
672 int flag_schedule_insns = 0;
673 int flag_schedule_insns_after_reload = 0;
674
675 /* When flag_schedule_insns_after_reload is set, use EBB scheduler.  */
676 int flag_sched2_use_superblocks = 0;
677
678 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
679    scheduler.  */
680 int flag_sched2_use_traces = 0;
681
682 /* The following flags have effect only for scheduling before register
683    allocation:
684
685    flag_schedule_interblock means schedule insns across basic blocks.
686    flag_schedule_speculative means allow speculative motion of non-load insns.
687    flag_schedule_speculative_load means allow speculative motion of some
688    load insns.
689    flag_schedule_speculative_load_dangerous allows speculative motion of more
690    load insns.  */
691
692 int flag_schedule_interblock = 1;
693 int flag_schedule_speculative = 1;
694 int flag_schedule_speculative_load = 0;
695 int flag_schedule_speculative_load_dangerous = 0;
696
697 /* The following flags have an effect during scheduling after register
698    allocation:
699
700    flag_sched_stalled_insns means that insns can be moved prematurely from the queue
701    of stalled insns into the ready list.
702
703    flag_sched_stalled_insns_dep controls how many insn groups will be examined
704    for a dependency on a stalled insn that is candidate for premature removal
705    from the queue of stalled insns into the ready list (has an effect only if
706    the flag 'sched_stalled_insns' is set).  */
707
708 int flag_sched_stalled_insns = 0;
709 int flag_sched_stalled_insns_dep = 1;
710
711 /* The following flag controls the module scheduling activation.  */
712 int flag_modulo_sched = 0;
713
714 int flag_single_precision_constant;
715
716 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
717    by a cheaper branch on a count register.  */
718 int flag_branch_on_count_reg = 1;
719
720 /* -finhibit-size-directive inhibits output of .size for ELF.
721    This is used only for compiling crtstuff.c,
722    and it may be extended to other effects
723    needed for crtstuff.c on other systems.  */
724 int flag_inhibit_size_directive = 0;
725
726 /* -fverbose-asm causes extra commentary information to be produced in
727    the generated assembly code (to make it more readable).  This option
728    is generally only of use to those who actually need to read the
729    generated assembly code (perhaps while debugging the compiler itself).
730    -fno-verbose-asm, the default, causes the extra information
731    to be omitted and is useful when comparing two assembler files.  */
732
733 int flag_verbose_asm = 0;
734
735 /* -dA causes debug commentary information to be produced in
736    the generated assembly code (to make it more readable).  This option
737    is generally only of use to those who actually need to read the
738    generated assembly code (perhaps while debugging the compiler itself).
739    Currently, this switch is only used by dwarfout.c; however, it is intended
740    to be a catchall for printing debug information in the assembler file.  */
741
742 int flag_debug_asm = 0;
743
744 /* -dP causes the rtl to be emitted as a comment in assembly.  */
745
746 int flag_dump_rtl_in_asm = 0;
747
748 /* Nonzero means put zero initialized data in the bss section.  */
749 int flag_zero_initialized_in_bss = 1;
750
751 /* Tag all structures with __attribute__(packed).  */
752 int flag_pack_struct = 0;
753
754 /* Emit code to check for stack overflow; also may cause large objects
755    to be allocated dynamically.  */
756 int flag_stack_check;
757
758 /* When non-NULL, indicates that whenever space is allocated on the
759    stack, the resulting stack pointer must not pass this
760    address---that is, for stacks that grow downward, the stack pointer
761    must always be greater than or equal to this address; for stacks
762    that grow upward, the stack pointer must be less than this address.
763    At present, the rtx may be either a REG or a SYMBOL_REF, although
764    the support provided depends on the backend.  */
765 rtx stack_limit_rtx;
766
767 /* 0 if pointer arguments may alias each other.  True in C.
768    1 if pointer arguments may not alias each other but may alias
769    global variables.
770    2 if pointer arguments may not alias each other and may not
771    alias global variables.  True in Fortran.
772    This defaults to 0 for C.  */
773 int flag_argument_noalias = 0;
774
775 /* Nonzero if we should do (language-dependent) alias analysis.
776    Typically, this analysis will assume that expressions of certain
777    types do not alias expressions of certain other types.  Only used
778    if alias analysis (in general) is enabled.  */
779 int flag_strict_aliasing = 0;
780
781 /* Instrument functions with calls at entry and exit, for profiling.  */
782 int flag_instrument_function_entry_exit = 0;
783
784 /* Nonzero means ignore `#ident' directives.  0 means handle them.
785    On SVR4 targets, it also controls whether or not to emit a
786    string identifying the compiler.  */
787
788 int flag_no_ident = 0;
789
790 /* This will perform a peephole pass before sched2.  */
791 int flag_peephole2 = 0;
792
793 /* This will try to guess branch probabilities.  */
794 int flag_guess_branch_prob = 0;
795
796 /* -fcheck-bounds causes gcc to generate array bounds checks.
797    For C, C++, ObjC: defaults to off.
798    For Java: defaults to on.
799    For Fortran: defaults to off.  */
800 int flag_bounds_check = 0;
801
802 /* Mudflap bounds-checking transform.  */
803 int flag_mudflap = 0;
804 int flag_mudflap_threads = 0;
805 int flag_mudflap_ignore_reads = 0;
806
807 /* This will attempt to merge constant section constants, if 1 only
808    string constants and constants from constant pool, if 2 also constant
809    variables.  */
810 int flag_merge_constants = 1;
811
812 /* If one, renumber instruction UIDs to reduce the number of
813    unused UIDs if there are a lot of instructions.  If greater than
814    one, unconditionally renumber instruction UIDs.  */
815 int flag_renumber_insns = 1;
816
817 /* If nonzero, use the graph coloring register allocator.  */
818 int flag_new_regalloc = 0;
819
820 /* If nonzero, use tree-based instead of rtl-based profiling.  */
821 int flag_tree_based_profiling = 0;
822
823 /* Enable SSA-GVN on trees.  */
824 int flag_tree_gvn = 0;
825
826 /* Enable the SSA-PRE tree optimization.  */
827 int flag_tree_pre = 0;
828
829 /* Enable points-to analysis on trees.  */
830 enum pta_type flag_tree_points_to = PTA_NONE;
831
832 /* Enable SSA-CCP on trees.  */
833 int flag_tree_ccp = 0;
834
835 /* Enable SSA-DCE on trees.  */
836 int flag_tree_dce = 0;
837
838 /* Enable loop header copying on tree-ssa.  */
839 int flag_tree_ch = 0;
840
841 /* Enable scalar replacement of aggregates.  */
842 int flag_tree_sra = 0;
843
844 /* Enable SSA->normal pass memory location coalescing.  */
845 int flag_tree_combine_temps = 0;
846
847 /* Enable SSA->normal pass expression replacement.  */
848 int flag_tree_ter = 0;
849
850 /* Enable SSA->normal live range splitting.  */
851 int flag_tree_live_range_split = 0;
852
853 /* Enable dominator optimizations.  */
854 int flag_tree_dom = 0;
855
856 /* Enable copy rename optimization.  */
857 int flag_tree_copyrename = 0;
858
859 /* Enable dead store elimination.  */
860 int flag_tree_dse = 0;
861
862 /* Nonzero if we perform superblock formation.  */
863 int flag_tracer = 0;
864
865 /* Nonzero if we perform whole unit at a time compilation.  */
866
867 int flag_unit_at_a_time = 0;
868
869 /* Nonzero if we should track variables.  When
870    flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
871    to optimize, debug_info_level and debug_hooks in process_options ().  */
872 int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
873
874 /* Values of the -falign-* flags: how much to align labels in code.
875    0 means `use default', 1 means `don't align'.
876    For each variable, there is an _log variant which is the power
877    of two not less than the variable, for .align output.  */
878
879 int align_loops;
880 int align_loops_log;
881 int align_loops_max_skip;
882 int align_jumps;
883 int align_jumps_log;
884 int align_jumps_max_skip;
885 int align_labels;
886 int align_labels_log;
887 int align_labels_max_skip;
888 int align_functions;
889 int align_functions_log;
890
891 /* Like align_functions_log above, but used by front-ends to force the
892    minimum function alignment.  Zero means no alignment is forced.  */
893 int force_align_functions_log;
894
895 typedef struct
896 {
897   const char *const string;
898   int *const variable;
899   const int on_value;
900 }
901 lang_independent_options;
902
903 /* Nonzero if signed arithmetic overflow should trap.  */
904 int flag_trapv = 0;
905
906 /* Nonzero if signed arithmetic overflow should wrap around.  */
907 int flag_wrapv = 0;
908
909 /* Nonzero if subexpressions must be evaluated from left-to-right.  */
910 int flag_evaluation_order = 0;
911
912 /* Add or remove a leading underscore from user symbols.  */
913 int flag_leading_underscore = -1;
914
915 /*  The version of the C++ ABI in use.  The following values are
916     allowed:
917
918     0: The version of the ABI believed most conformant with the
919        C++ ABI specification.  This ABI may change as bugs are
920        discovered and fixed.  Therefore, 0 will not necessarily
921        indicate the same ABI in different versions of G++.
922
923     1: The version of the ABI first used in G++ 3.2.
924
925     2: The version of the ABI first used in G++ 3.4.
926
927     Additional positive integers will be assigned as new versions of
928     the ABI become the default version of the ABI.  */
929
930 int flag_abi_version = 2;
931
932 /* The user symbol prefix after having resolved same.  */
933 const char *user_label_prefix;
934
935 static const param_info lang_independent_params[] = {
936 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
937   { OPTION, DEFAULT, HELP },
938 #include "params.def"
939 #undef DEFPARAM
940   { NULL, 0, NULL }
941 };
942
943 /* Table of language-independent -f options.
944    STRING is the option name.  VARIABLE is the address of the variable.
945    ON_VALUE is the value to store in VARIABLE
946     if `-fSTRING' is seen as an option.
947    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
948
949 static const lang_independent_options f_options[] =
950 {
951   {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
952   {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
953   {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
954   {"float-store", &flag_float_store, 1 },
955   {"defer-pop", &flag_defer_pop, 1 },
956   {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
957   {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
958   {"tracer", &flag_tracer, 1 },
959   {"unit-at-a-time", &flag_unit_at_a_time, 1 },
960   {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
961   {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
962   {"expensive-optimizations", &flag_expensive_optimizations, 1 },
963   {"thread-jumps", &flag_thread_jumps, 1 },
964   {"strength-reduce", &flag_strength_reduce, 1 },
965   {"unroll-loops", &flag_unroll_loops, 1 },
966   {"unroll-all-loops", &flag_unroll_all_loops, 1 },
967   {"old-unroll-loops", &flag_old_unroll_loops, 1 },
968   {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
969   {"peel-loops", &flag_peel_loops, 1 },
970   {"unswitch-loops", &flag_unswitch_loops, 1 },
971   {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
972   {"move-all-movables", &flag_move_all_movables, 1 },
973   {"reduce-all-givs", &flag_reduce_all_givs, 1 },
974   {"peephole", &flag_no_peephole, 0 },
975   {"force-mem", &flag_force_mem, 1 },
976   {"force-addr", &flag_force_addr, 1 },
977   {"function-cse", &flag_no_function_cse, 0 },
978   {"inline-functions", &flag_inline_functions, 1 },
979   {"keep-inline-functions", &flag_keep_inline_functions, 1 },
980   {"inline", &flag_no_inline, 0 },
981   {"keep-static-consts", &flag_keep_static_consts, 1 },
982   {"syntax-only", &flag_syntax_only, 1 },
983   {"shared-data", &flag_shared_data, 1 },
984   {"caller-saves", &flag_caller_saves, 1 },
985   {"pcc-struct-return", &flag_pcc_struct_return, 1 },
986   {"reg-struct-return", &flag_pcc_struct_return, 0 },
987   {"delayed-branch", &flag_delayed_branch, 1 },
988   {"web", &flag_web, 1},
989   {"gcse", &flag_gcse, 1 },
990   {"gcse-lm", &flag_gcse_lm, 1 },
991   {"gcse-sm", &flag_gcse_sm, 1 },
992   {"gcse-las", &flag_gcse_las, 1 },
993   {"gcse-after-reload", &flag_gcse_after_reload, 1},
994   {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
995   {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
996   {"btr-bb-exclusive", &flag_btr_bb_exclusive, 1 },
997   {"loop-optimize", &flag_loop_optimize, 1 },
998   {"crossjumping", &flag_crossjumping, 1 },
999   {"if-conversion", &flag_if_conversion, 1 },
1000   {"if-conversion2", &flag_if_conversion2, 1 },
1001   {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1002   {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1003   {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1004   {"schedule-insns", &flag_schedule_insns, 1 },
1005   {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1006   {"sched-interblock",&flag_schedule_interblock, 1 },
1007   {"sched-spec",&flag_schedule_speculative, 1 },
1008   {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1009   {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1010   {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
1011   {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
1012   {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1013   {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1014   {"modulo-sched", &flag_modulo_sched, 1 },
1015   {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1016   {"pic", &flag_pic, 1 },
1017   {"PIC", &flag_pic, 2 },
1018   {"pie", &flag_pie, 1 },
1019   {"PIE", &flag_pie, 2 },
1020   {"exceptions", &flag_exceptions, 1 },
1021   {"unwind-tables", &flag_unwind_tables, 1 },
1022   {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1023   {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1024   {"profile-arcs", &profile_arc_flag, 1 },
1025   {"profile-values", &flag_profile_values, 1 },
1026   {"vpt", &flag_value_profile_transformations, 1 },
1027   {"test-coverage", &flag_test_coverage, 1 },
1028   {"branch-probabilities", &flag_branch_probabilities, 1 },
1029   {"profile", &profile_flag, 1 },
1030   {"tree-based-profiling", &flag_tree_based_profiling, 1 },
1031   {"reorder-blocks", &flag_reorder_blocks, 1 },
1032   {"reorder-blocks-and-partition", &flag_reorder_blocks_and_partition, 1},
1033   {"reorder-functions", &flag_reorder_functions, 1 },
1034   {"rename-registers", &flag_rename_registers, 1 },
1035   {"cprop-registers", &flag_cprop_registers, 1 },
1036   {"common", &flag_no_common, 0 },
1037   {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1038   {"function-sections", &flag_function_sections, 1 },
1039   {"data-sections", &flag_data_sections, 1 },
1040   {"verbose-asm", &flag_verbose_asm, 1 },
1041   {"regmove", &flag_regmove, 1 },
1042   {"optimize-register-move", &flag_regmove, 1 },
1043   {"pack-struct", &flag_pack_struct, 1 },
1044   {"stack-check", &flag_stack_check, 1 },
1045   {"argument-alias", &flag_argument_noalias, 0 },
1046   {"argument-noalias", &flag_argument_noalias, 1 },
1047   {"argument-noalias-global", &flag_argument_noalias, 2 },
1048   {"strict-aliasing", &flag_strict_aliasing, 1 },
1049   {"align-loops", &align_loops, 0 },
1050   {"align-jumps", &align_jumps, 0 },
1051   {"align-labels", &align_labels, 0 },
1052   {"align-functions", &align_functions, 0 },
1053   {"merge-constants", &flag_merge_constants, 1 },
1054   {"merge-all-constants", &flag_merge_constants, 2 },
1055   {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1056   {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1057   {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1058   {"leading-underscore", &flag_leading_underscore, 1 },
1059   {"ident", &flag_no_ident, 0 },
1060   { "peephole2", &flag_peephole2, 1 },
1061   {"finite-math-only", &flag_finite_math_only, 1 },
1062   { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1063   {"math-errno", &flag_errno_math, 1 },
1064   {"trapping-math", &flag_trapping_math, 1 },
1065   {"rounding-math", &flag_rounding_math, 1 },
1066   {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1067   {"signaling-nans", &flag_signaling_nans, 1 },
1068   {"bounds-check", &flag_bounds_check, 1 },
1069   {"single-precision-constant", &flag_single_precision_constant, 1 },
1070   {"time-report", &time_report, 1 },
1071   {"mem-report", &mem_report, 1 },
1072   { "trapv", &flag_trapv, 1 },
1073   { "wrapv", &flag_wrapv, 1 },
1074   { "new-ra", &flag_new_regalloc, 1 },
1075   { "var-tracking", &flag_var_tracking, 1},
1076   { "tree-gvn", &flag_tree_gvn, 1 },
1077   { "tree-pre", &flag_tree_pre, 1 },
1078   { "tree-ccp", &flag_tree_ccp, 1 },
1079   { "tree-dce", &flag_tree_dce, 1 },
1080   { "tree-dominator-opts", &flag_tree_dom, 1 },
1081   { "tree-copyrename", &flag_tree_copyrename, 1 },
1082   { "tree-dse", &flag_tree_dse, 1 },
1083   { "tree-combine-temps", &flag_tree_combine_temps, 1 },
1084   { "tree-ter", &flag_tree_ter, 1 },
1085   { "tree-lrs", &flag_tree_live_range_split, 1 },
1086   { "tree-ch", &flag_tree_ch, 1 }
1087 };
1088
1089 /* Here is a table, controlled by the tm.h file, listing each -m switch
1090    and which bits in `target_switches' it should set or clear.
1091    If VALUE is positive, it is bits to set.
1092    If VALUE is negative, -VALUE is bits to clear.
1093    (The sign bit is not used so there is no confusion.)  */
1094
1095 static const struct
1096 {
1097   const char *const name;
1098   const int value;
1099   const char *const description;
1100 }
1101 target_switches[] = TARGET_SWITCHES;
1102
1103 /* This table is similar, but allows the switch to have a value.  */
1104
1105 #ifdef TARGET_OPTIONS
1106 static const struct
1107 {
1108   const char *const prefix;
1109   const char **const variable;
1110   const char *const description;
1111   const char *const value;
1112 }
1113 target_options[] = TARGET_OPTIONS;
1114 #endif
1115
1116 /* Nonzero means warn about function definitions that default the return type
1117    or that use a null return and have a return-type other than void.  */
1118
1119 int warn_return_type;
1120
1121 /* Output files for assembler code (real compiler output)
1122    and debugging dumps.  */
1123
1124 FILE *asm_out_file;
1125 FILE *aux_info_file;
1126 FILE *dump_file = NULL;
1127 FILE *cgraph_dump_file = NULL;
1128
1129 /* The current working directory of a translation.  It's generally the
1130    directory from which compilation was initiated, but a preprocessed
1131    file may specify the original directory in which it was
1132    created.  */
1133
1134 static const char *src_pwd;
1135
1136 /* Initialize src_pwd with the given string, and return true.  If it
1137    was already initialized, return false.  As a special case, it may
1138    be called with a NULL argument to test whether src_pwd has NOT been
1139    initialized yet.  */
1140
1141 bool
1142 set_src_pwd (const char *pwd)
1143 {
1144   if (src_pwd)
1145     {
1146       if (strcmp (src_pwd, pwd) == 0)
1147         return true;
1148       else
1149         return false;
1150     }
1151
1152   src_pwd = xstrdup (pwd);
1153   return true;
1154 }
1155
1156 /* Return the directory from which the translation unit was initiated,
1157    in case set_src_pwd() was not called before to assign it a
1158    different value.  */
1159
1160 const char *
1161 get_src_pwd (void)
1162 {
1163   if (! src_pwd)
1164     src_pwd = getpwd ();
1165
1166    return src_pwd;
1167 }
1168
1169 /* Called when the start of a function definition is parsed,
1170    this function prints on stderr the name of the function.  */
1171 void
1172 announce_function (tree decl)
1173 {
1174   if (!quiet_flag)
1175     {
1176       if (rtl_dump_and_exit)
1177         verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1178       else
1179         verbatim (" %s", lang_hooks.decl_printable_name (decl, 2));
1180       fflush (stderr);
1181       pp_needs_newline (global_dc->printer) = true;
1182       diagnostic_set_last_function (global_dc);
1183     }
1184 }
1185
1186 /* Set up a default flag_random_seed and local_tick, unless the user
1187    already specified one.  */
1188
1189 static void
1190 randomize (void)
1191 {
1192   if (!flag_random_seed)
1193     {
1194       unsigned HOST_WIDE_INT value;
1195       static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1196
1197       /* Get some more or less random data.  */
1198 #ifdef HAVE_GETTIMEOFDAY
1199       {
1200         struct timeval tv;
1201
1202         gettimeofday (&tv, NULL);
1203         local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1204       }
1205 #else
1206       {
1207         time_t now = time (NULL);
1208
1209         if (now != (time_t)-1)
1210           local_tick = (unsigned) now;
1211       }
1212 #endif
1213       value = local_tick ^ getpid ();
1214
1215       sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1216       flag_random_seed = random_seed;
1217     }
1218   else if (!local_tick)
1219     local_tick = -1;
1220 }
1221
1222
1223 /* Decode the string P as an integral parameter.
1224    If the string is indeed an integer return its numeric value else
1225    issue an Invalid Option error for the option PNAME and return DEFVAL.
1226    If PNAME is zero just return DEFVAL, do not call error.  */
1227
1228 int
1229 read_integral_parameter (const char *p, const char *pname, const int  defval)
1230 {
1231   const char *endp = p;
1232
1233   while (*endp)
1234     {
1235       if (ISDIGIT (*endp))
1236         endp++;
1237       else
1238         break;
1239     }
1240
1241   if (*endp != 0)
1242     {
1243       if (pname != 0)
1244         error ("invalid option argument `%s'", pname);
1245       return defval;
1246     }
1247
1248   return atoi (p);
1249 }
1250
1251 /* Return the logarithm of X, base 2, considering X unsigned,
1252    if X is a power of 2.  Otherwise, returns -1.
1253
1254    This should be used via the `exact_log2' macro.  */
1255
1256 int
1257 exact_log2_wide (unsigned HOST_WIDE_INT x)
1258 {
1259   int log = 0;
1260   /* Test for 0 or a power of 2.  */
1261   if (x == 0 || x != (x & -x))
1262     return -1;
1263   while ((x >>= 1) != 0)
1264     log++;
1265   return log;
1266 }
1267
1268 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1269    If X is 0, return -1.
1270
1271    This should be used via the floor_log2 macro.  */
1272
1273 int
1274 floor_log2_wide (unsigned HOST_WIDE_INT x)
1275 {
1276   int log = -1;
1277   while (x != 0)
1278     log++,
1279     x >>= 1;
1280   return log;
1281 }
1282
1283 /* Handler for fatal signals, such as SIGSEGV.  These are transformed
1284    into ICE messages, which is much more user friendly.  In case the
1285    error printer crashes, reset the signal to prevent infinite recursion.  */
1286
1287 static void
1288 crash_signal (int signo)
1289 {
1290   signal (signo, SIG_DFL);
1291   internal_error ("%s", strsignal (signo));
1292 }
1293
1294 /* Arrange to dump core on error.  (The regular error message is still
1295    printed first, except in the case of abort().)  */
1296
1297 static void
1298 setup_core_dumping (void)
1299 {
1300 #ifdef SIGABRT
1301   signal (SIGABRT, SIG_DFL);
1302 #endif
1303 #if defined(HAVE_SETRLIMIT)
1304   {
1305     struct rlimit rlim;
1306     if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1307       fatal_error ("getting core file size maximum limit: %m");
1308     rlim.rlim_cur = rlim.rlim_max;
1309     if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1310       fatal_error ("setting core file size limit to maximum: %m");
1311   }
1312 #endif
1313   diagnostic_abort_on_error (global_dc);
1314 }
1315
1316
1317 /* Strip off a legitimate source ending from the input string NAME of
1318    length LEN.  Rather than having to know the names used by all of
1319    our front ends, we strip off an ending of a period followed by
1320    up to five characters.  (Java uses ".class".)  */
1321
1322 void
1323 strip_off_ending (char *name, int len)
1324 {
1325   int i;
1326   for (i = 2; i < 6 && len > i; i++)
1327     {
1328       if (name[len - i] == '.')
1329         {
1330           name[len - i] = '\0';
1331           break;
1332         }
1333     }
1334 }
1335
1336 /* Output a quoted string.  */
1337
1338 void
1339 output_quoted_string (FILE *asm_file, const char *string)
1340 {
1341 #ifdef OUTPUT_QUOTED_STRING
1342   OUTPUT_QUOTED_STRING (asm_file, string);
1343 #else
1344   char c;
1345
1346   putc ('\"', asm_file);
1347   while ((c = *string++) != 0)
1348     {
1349       if (ISPRINT (c))
1350         {
1351           if (c == '\"' || c == '\\')
1352             putc ('\\', asm_file);
1353           putc (c, asm_file);
1354         }
1355       else
1356         fprintf (asm_file, "\\%03o", (unsigned char) c);
1357     }
1358   putc ('\"', asm_file);
1359 #endif
1360 }
1361
1362 /* Output a file name in the form wanted by System V.  */
1363
1364 void
1365 output_file_directive (FILE *asm_file, const char *input_name)
1366 {
1367   int len;
1368   const char *na;
1369
1370   if (input_name == NULL)
1371     input_name = "<stdin>";
1372
1373   len = strlen (input_name);
1374   na = input_name + len;
1375
1376   /* NA gets INPUT_NAME sans directory names.  */
1377   while (na > input_name)
1378     {
1379       if (IS_DIR_SEPARATOR (na[-1]))
1380         break;
1381       na--;
1382     }
1383
1384 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1385   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1386 #else
1387   fprintf (asm_file, "\t.file\t");
1388   output_quoted_string (asm_file, na);
1389   fputc ('\n', asm_file);
1390 #endif
1391 }
1392
1393 /* Do any final processing required for the declarations in VEC, of
1394    which there are LEN.  We write out inline functions and variables
1395    that have been deferred until this point, but which are required.
1396    Returns nonzero if anything was put out.  */
1397
1398 int
1399 wrapup_global_declarations (tree *vec, int len)
1400 {
1401   tree decl;
1402   int i;
1403   int reconsider;
1404   int output_something = 0;
1405
1406   for (i = 0; i < len; i++)
1407     {
1408       decl = vec[i];
1409
1410       /* We're not deferring this any longer.  Assignment is
1411          conditional to avoid needlessly dirtying PCH pages.  */
1412       if (DECL_DEFER_OUTPUT (decl) != 0)
1413         DECL_DEFER_OUTPUT (decl) = 0;
1414
1415       if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1416         lang_hooks.finish_incomplete_decl (decl);
1417     }
1418
1419   /* Now emit any global variables or functions that we have been
1420      putting off.  We need to loop in case one of the things emitted
1421      here references another one which comes earlier in the list.  */
1422   do
1423     {
1424       reconsider = 0;
1425       for (i = 0; i < len; i++)
1426         {
1427           decl = vec[i];
1428
1429           if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1430             continue;
1431
1432           /* Don't write out static consts, unless we still need them.
1433
1434              We also keep static consts if not optimizing (for debugging),
1435              unless the user specified -fno-keep-static-consts.
1436              ??? They might be better written into the debug information.
1437              This is possible when using DWARF.
1438
1439              A language processor that wants static constants to be always
1440              written out (even if it is not used) is responsible for
1441              calling rest_of_decl_compilation itself.  E.g. the C front-end
1442              calls rest_of_decl_compilation from finish_decl.
1443              One motivation for this is that is conventional in some
1444              environments to write things like:
1445              static const char rcsid[] = "... version string ...";
1446              intending to force the string to be in the executable.
1447
1448              A language processor that would prefer to have unneeded
1449              static constants "optimized away" would just defer writing
1450              them out until here.  E.g. C++ does this, because static
1451              constants are often defined in header files.
1452
1453              ??? A tempting alternative (for both C and C++) would be
1454              to force a constant to be written if and only if it is
1455              defined in a main file, as opposed to an include file.  */
1456
1457           if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1458             {
1459               bool needed = 1;
1460
1461               if (flag_unit_at_a_time
1462                   && cgraph_varpool_node (decl)->finalized)
1463                 needed = 0;
1464               else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1465                        && (TREE_USED (decl)
1466                            || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1467                 /* needed */;
1468               else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1469                 /* needed */;
1470               else if (DECL_COMDAT (decl))
1471                 needed = 0;
1472               else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1473                        && (optimize || !flag_keep_static_consts
1474                            || DECL_ARTIFICIAL (decl)))
1475                 needed = 0;
1476
1477               if (needed)
1478                 {
1479                   reconsider = 1;
1480                   rest_of_decl_compilation (decl, NULL, 1, 1);
1481                 }
1482             }
1483         }
1484
1485       if (reconsider)
1486         output_something = 1;
1487     }
1488   while (reconsider);
1489
1490   return output_something;
1491 }
1492
1493 /* Issue appropriate warnings for the global declarations in VEC (of
1494    which there are LEN).  Output debugging information for them.  */
1495
1496 void
1497 check_global_declarations (tree *vec, int len)
1498 {
1499   tree decl;
1500   int i;
1501
1502   for (i = 0; i < len; i++)
1503     {
1504       decl = vec[i];
1505
1506       if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1507           && ! TREE_ASM_WRITTEN (decl))
1508         /* Cancel the RTL for this decl so that, if debugging info
1509            output for global variables is still to come,
1510            this one will be omitted.  */
1511         SET_DECL_RTL (decl, NULL_RTX);
1512
1513       /* Warn about any function
1514          declared static but not defined.
1515          We don't warn about variables,
1516          because many programs have static variables
1517          that exist only to get some text into the object file.  */
1518       if (TREE_CODE (decl) == FUNCTION_DECL
1519           && DECL_INITIAL (decl) == 0
1520           && DECL_EXTERNAL (decl)
1521           && ! DECL_ARTIFICIAL (decl)
1522           && ! TREE_PUBLIC (decl)
1523           && (warn_unused_function
1524               || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1525         {
1526           if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1527             pedwarn ("%J'%F' used but never defined", decl, decl);
1528           else
1529             warning ("%J'%F' declared `static' but never defined", decl, decl);
1530           /* This symbol is effectively an "extern" declaration now.  */
1531           TREE_PUBLIC (decl) = 1;
1532           assemble_external (decl);
1533         }
1534
1535       /* Warn about static fns or vars defined but not used.  */
1536       if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1537            /* We don't warn about "static const" variables because the
1538               "rcs_id" idiom uses that construction.  */
1539            || (warn_unused_variable
1540                && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
1541           && ! DECL_IN_SYSTEM_HEADER (decl)
1542           && ! TREE_USED (decl)
1543           /* The TREE_USED bit for file-scope decls is kept in the identifier,
1544              to handle multiple external decls in different scopes.  */
1545           && ! TREE_USED (DECL_NAME (decl))
1546           && ! DECL_EXTERNAL (decl)
1547           && ! TREE_PUBLIC (decl)
1548           /* A volatile variable might be used in some non-obvious way.  */
1549           && ! TREE_THIS_VOLATILE (decl)
1550           /* Global register variables must be declared to reserve them.  */
1551           && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1552           /* Otherwise, ask the language.  */
1553           && lang_hooks.decls.warn_unused_global (decl))
1554         warning ("%J'%D' defined but not used", decl, decl);
1555
1556       /* Avoid confusing the debug information machinery when there are
1557          errors.  */
1558       if (errorcount == 0 && sorrycount == 0)
1559         {
1560           timevar_push (TV_SYMOUT);
1561           (*debug_hooks->global_decl) (decl);
1562           timevar_pop (TV_SYMOUT);
1563         }
1564     }
1565 }
1566
1567 /* Warn about a use of an identifier which was marked deprecated.  */
1568 void
1569 warn_deprecated_use (tree node)
1570 {
1571   if (node == 0 || !warn_deprecated_decl)
1572     return;
1573
1574   if (DECL_P (node))
1575     warning ("`%s' is deprecated (declared at %s:%d)",
1576              IDENTIFIER_POINTER (DECL_NAME (node)),
1577              DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1578   else if (TYPE_P (node))
1579     {
1580       const char *what = NULL;
1581       tree decl = TYPE_STUB_DECL (node);
1582
1583       if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1584         what = IDENTIFIER_POINTER (TYPE_NAME (node));
1585       else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1586                && DECL_NAME (TYPE_NAME (node)))
1587         what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1588
1589       if (what)
1590         {
1591           if (decl)
1592             warning ("`%s' is deprecated (declared at %s:%d)", what,
1593                      DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1594           else
1595             warning ("`%s' is deprecated", what);
1596         }
1597       else if (decl)
1598         warning ("type is deprecated (declared at %s:%d)",
1599                  DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1600       else
1601         warning ("type is deprecated");
1602     }
1603 }
1604
1605 /* Save the current INPUT_LOCATION on the top entry in the
1606    INPUT_FILE_STACK.  Push a new entry for FILE and LINE, and set the
1607    INPUT_LOCATION accordingly.  */
1608
1609 void
1610 push_srcloc (const char *file, int line)
1611 {
1612   struct file_stack *fs;
1613
1614   fs = xmalloc (sizeof (struct file_stack));
1615   fs->location = input_location;
1616   fs->next = input_file_stack;
1617   input_filename = file;
1618   input_line = line;
1619   input_file_stack = fs;
1620   input_file_stack_tick++;
1621 }
1622
1623 /* Pop the top entry off the stack of presently open source files.
1624    Restore the INPUT_LOCATION from the new topmost entry on the
1625    stack.  */
1626
1627 void
1628 pop_srcloc (void)
1629 {
1630   struct file_stack *fs;
1631
1632   fs = input_file_stack;
1633   input_location = fs->location;
1634   input_file_stack = fs->next;
1635   free (fs);
1636   input_file_stack_tick++;
1637 }
1638
1639 /* Compile an entire translation unit.  Write a file of assembly
1640    output and various debugging dumps.  */
1641
1642 static void
1643 compile_file (void)
1644 {
1645   /* Initialize yet another pass.  */
1646
1647   init_final (main_input_filename);
1648   coverage_init (aux_base_name);
1649
1650   timevar_push (TV_PARSE);
1651
1652   /* Call the parser, which parses the entire file (calling
1653      rest_of_compilation for each function).  */
1654   lang_hooks.parse_file (set_yydebug);
1655
1656   /* In case there were missing block closers,
1657      get us back to the global binding level.  */
1658   lang_hooks.clear_binding_stack ();
1659
1660   /* Compilation is now finished except for writing
1661      what's left of the symbol table output.  */
1662   timevar_pop (TV_PARSE);
1663
1664   if (flag_syntax_only)
1665     return;
1666
1667   lang_hooks.decls.final_write_globals ();
1668
1669   cgraph_varpool_assemble_pending_decls ();
1670
1671   /* This must occur after the loop to output deferred functions.
1672      Else the coverage initializer would not be emitted if all the
1673      functions in this compilation unit were deferred.  */
1674   coverage_finish ();
1675
1676   /* Write out any pending weak symbol declarations.  */
1677
1678   weak_finish ();
1679
1680   /* Do dbx symbols.  */
1681   timevar_push (TV_SYMOUT);
1682
1683 #ifdef DWARF2_UNWIND_INFO
1684   if (dwarf2out_do_frame ())
1685     dwarf2out_frame_finish ();
1686 #endif
1687
1688   (*debug_hooks->finish) (main_input_filename);
1689   timevar_pop (TV_SYMOUT);
1690
1691   /* Output some stuff at end of file if nec.  */
1692
1693   dw2_output_indirect_constants ();
1694
1695   /* Attach a special .ident directive to the end of the file to identify
1696      the version of GCC which compiled this code.  The format of the .ident
1697      string is patterned after the ones produced by native SVR4 compilers.  */
1698 #ifdef IDENT_ASM_OP
1699   if (!flag_no_ident)
1700     fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1701              IDENT_ASM_OP, version_string);
1702 #endif
1703
1704   /* This must be at the end.  Some target ports emit end of file directives
1705      into the assembly file here, and hence we can not output anything to the
1706      assembly file after this point.  */
1707   targetm.asm_out.file_end ();
1708 }
1709
1710 /* Display help for target options.  */
1711 void
1712 display_target_options (void)
1713 {
1714   int undoc, i;
1715   static bool displayed = false;
1716
1717   /* Avoid double printing for --help --target-help.  */
1718   if (displayed)
1719     return;
1720
1721   displayed = true;
1722
1723   if (ARRAY_SIZE (target_switches) > 1
1724 #ifdef TARGET_OPTIONS
1725       || ARRAY_SIZE (target_options) > 1
1726 #endif
1727       )
1728     {
1729       int doc = 0;
1730
1731       undoc = 0;
1732
1733       printf (_("\nTarget specific options:\n"));
1734
1735       for (i = ARRAY_SIZE (target_switches); i--;)
1736         {
1737           const char *option      = target_switches[i].name;
1738           const char *description = target_switches[i].description;
1739
1740           if (option == NULL || *option == 0)
1741             continue;
1742           else if (description == NULL)
1743             {
1744               undoc = 1;
1745
1746               if (extra_warnings)
1747                 printf (_("  -m%-23s [undocumented]\n"), option);
1748             }
1749           else if (*description != 0)
1750             doc += printf ("  -m%-23s %s\n", option, _(description));
1751         }
1752
1753 #ifdef TARGET_OPTIONS
1754       for (i = ARRAY_SIZE (target_options); i--;)
1755         {
1756           const char *option      = target_options[i].prefix;
1757           const char *description = target_options[i].description;
1758
1759           if (option == NULL || *option == 0)
1760             continue;
1761           else if (description == NULL)
1762             {
1763               undoc = 1;
1764
1765               if (extra_warnings)
1766                 printf (_("  -m%-23s [undocumented]\n"), option);
1767             }
1768           else if (*description != 0)
1769             doc += printf ("  -m%-23s %s\n", option, _(description));
1770         }
1771 #endif
1772       if (undoc)
1773         {
1774           if (doc)
1775             printf (_("\nThere are undocumented target specific options as well.\n"));
1776           else
1777             printf (_("  They exist, but they are not documented.\n"));
1778         }
1779     }
1780 }
1781
1782 /* Parse a -d... command line switch.  */
1783
1784 void
1785 decode_d_option (const char *arg)
1786 {
1787   int c;
1788
1789   while (*arg)
1790     switch (c = *arg++)
1791       {
1792       case 'A':
1793         flag_debug_asm = 1;
1794         break;
1795       case 'p':
1796         flag_print_asm_name = 1;
1797         break;
1798       case 'P':
1799         flag_dump_rtl_in_asm = 1;
1800         flag_print_asm_name = 1;
1801         break;
1802       case 'v':
1803         graph_dump_format = vcg;
1804         break;
1805       case 'x':
1806         rtl_dump_and_exit = 1;
1807         break;
1808       case 'y':
1809         set_yydebug = 1;
1810         break;
1811       case 'D': /* These are handled by the preprocessor.  */
1812       case 'I':
1813         break;
1814       case 'H':
1815         setup_core_dumping();
1816         break;
1817
1818       case 'a':
1819       default:
1820         if (!enable_rtl_dump_file (c))
1821           warning ("unrecognized gcc debugging option: %c", c);
1822         break;
1823       }
1824 }
1825
1826 /* Indexed by enum debug_info_type.  */
1827 const char *const debug_type_names[] =
1828 {
1829   "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
1830 };
1831
1832 /* Decode -m switches.  */
1833 /* Decode the switch -mNAME.  */
1834
1835 void
1836 set_target_switch (const char *name)
1837 {
1838   size_t j;
1839   int valid_target_option = 0;
1840
1841   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1842     if (!strcmp (target_switches[j].name, name))
1843       {
1844         if (target_switches[j].value < 0)
1845           target_flags &= ~-target_switches[j].value;
1846         else
1847           target_flags |= target_switches[j].value;
1848         if (name[0] != 0)
1849           {
1850             if (target_switches[j].value < 0)
1851               target_flags_explicit |= -target_switches[j].value;
1852             else
1853               target_flags_explicit |= target_switches[j].value;
1854           }
1855         valid_target_option = 1;
1856       }
1857
1858 #ifdef TARGET_OPTIONS
1859   if (!valid_target_option)
1860     for (j = 0; j < ARRAY_SIZE (target_options); j++)
1861       {
1862         int len = strlen (target_options[j].prefix);
1863         if (target_options[j].value)
1864           {
1865             if (!strcmp (target_options[j].prefix, name))
1866               {
1867                 *target_options[j].variable = target_options[j].value;
1868                 valid_target_option = 1;
1869               }
1870           }
1871         else
1872           {
1873             if (!strncmp (target_options[j].prefix, name, len))
1874               {
1875                 *target_options[j].variable = name + len;
1876                 valid_target_option = 1;
1877               }
1878           }
1879       }
1880 #endif
1881
1882   if (!valid_target_option)
1883     error ("invalid option `%s'", name);
1884 }
1885
1886 /* Print version information to FILE.
1887    Each line begins with INDENT (for the case where FILE is the
1888    assembler output file).  */
1889
1890 void
1891 print_version (FILE *file, const char *indent)
1892 {
1893 #ifndef __VERSION__
1894 #define __VERSION__ "[?]"
1895 #endif
1896   fnotice (file,
1897 #ifdef __GNUC__
1898            "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
1899 #else
1900            "%s%s%s version %s (%s) compiled by CC.\n"
1901 #endif
1902            , indent, *indent != 0 ? " " : "",
1903            lang_hooks.name, version_string, TARGET_NAME,
1904            indent, __VERSION__);
1905   fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
1906            indent, *indent != 0 ? " " : "",
1907            PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1908 }
1909
1910 /* Print an option value and return the adjusted position in the line.
1911    ??? We don't handle error returns from fprintf (disk full); presumably
1912    other code will catch a disk full though.  */
1913
1914 static int
1915 print_single_switch (FILE *file, int pos, int max,
1916                      const char *indent, const char *sep, const char *term,
1917                      const char *type, const char *name)
1918 {
1919   /* The ultrix fprintf returns 0 on success, so compute the result we want
1920      here since we need it for the following test.  */
1921   int len = strlen (sep) + strlen (type) + strlen (name);
1922
1923   if (pos != 0
1924       && pos + len > max)
1925     {
1926       fprintf (file, "%s", term);
1927       pos = 0;
1928     }
1929   if (pos == 0)
1930     {
1931       fprintf (file, "%s", indent);
1932       pos = strlen (indent);
1933     }
1934   fprintf (file, "%s%s%s", sep, type, name);
1935   pos += len;
1936   return pos;
1937 }
1938
1939 /* Print active target switches to FILE.
1940    POS is the current cursor position and MAX is the size of a "line".
1941    Each line begins with INDENT and ends with TERM.
1942    Each switch is separated from the next by SEP.  */
1943
1944 static void
1945 print_switch_values (FILE *file, int pos, int max,
1946                      const char *indent, const char *sep, const char *term)
1947 {
1948   size_t j;
1949   const char **p;
1950
1951   /* Fill in the -frandom-seed option, if the user didn't pass it, so
1952      that it can be printed below.  This helps reproducibility.  */
1953   randomize ();
1954
1955   /* Print the options as passed.  */
1956   pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
1957                              _("options passed: "), "");
1958
1959   for (p = &save_argv[1]; *p != NULL; p++)
1960     if (**p == '-')
1961       {
1962         /* Ignore these.  */
1963         if (strcmp (*p, "-o") == 0)
1964           {
1965             if (p[1] != NULL)
1966               p++;
1967             continue;
1968           }
1969         if (strcmp (*p, "-quiet") == 0)
1970           continue;
1971         if (strcmp (*p, "-version") == 0)
1972           continue;
1973         if ((*p)[1] == 'd')
1974           continue;
1975
1976         pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
1977       }
1978   if (pos > 0)
1979     fprintf (file, "%s", term);
1980
1981   /* Print the -f and -m options that have been enabled.
1982      We don't handle language specific options but printing argv
1983      should suffice.  */
1984
1985   pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
1986                              _("options enabled: "), "");
1987
1988   for (j = 0; j < ARRAY_SIZE (f_options); j++)
1989     if (*f_options[j].variable == f_options[j].on_value)
1990       pos = print_single_switch (file, pos, max, indent, sep, term,
1991                                  "-f", f_options[j].string);
1992
1993   /* Print target specific options.  */
1994
1995   for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1996     if (target_switches[j].name[0] != '\0'
1997         && target_switches[j].value > 0
1998         && ((target_switches[j].value & target_flags)
1999             == target_switches[j].value))
2000       {
2001         pos = print_single_switch (file, pos, max, indent, sep, term,
2002                                    "-m", target_switches[j].name);
2003       }
2004
2005 #ifdef TARGET_OPTIONS
2006   for (j = 0; j < ARRAY_SIZE (target_options); j++)
2007     if (*target_options[j].variable != NULL)
2008       {
2009         char prefix[256];
2010         sprintf (prefix, "-m%s", target_options[j].prefix);
2011         pos = print_single_switch (file, pos, max, indent, sep, term,
2012                                    prefix, *target_options[j].variable);
2013       }
2014 #endif
2015
2016   fprintf (file, "%s", term);
2017 }
2018
2019 /* Open assembly code output file.  Do this even if -fsyntax-only is
2020    on, because then the driver will have provided the name of a
2021    temporary file or bit bucket for us.  NAME is the file specified on
2022    the command line, possibly NULL.  */
2023 static void
2024 init_asm_output (const char *name)
2025 {
2026   if (name == NULL && asm_file_name == 0)
2027     asm_out_file = stdout;
2028   else
2029     {
2030       if (asm_file_name == 0)
2031         {
2032           int len = strlen (dump_base_name);
2033           char *dumpname = xmalloc (len + 6);
2034           memcpy (dumpname, dump_base_name, len + 1);
2035           strip_off_ending (dumpname, len);
2036           strcat (dumpname, ".s");
2037           asm_file_name = dumpname;
2038         }
2039       if (!strcmp (asm_file_name, "-"))
2040         asm_out_file = stdout;
2041       else
2042         asm_out_file = fopen (asm_file_name, "w+");
2043       if (asm_out_file == 0)
2044         fatal_error ("can't open %s for writing: %m", asm_file_name);
2045     }
2046
2047 #ifdef IO_BUFFER_SIZE
2048   setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
2049            _IOFBF, IO_BUFFER_SIZE);
2050 #endif
2051
2052   if (!flag_syntax_only)
2053     {
2054       targetm.asm_out.file_start ();
2055
2056 #ifdef ASM_COMMENT_START
2057       if (flag_verbose_asm)
2058         {
2059           /* Print the list of options in effect.  */
2060           print_version (asm_out_file, ASM_COMMENT_START);
2061           print_switch_values (asm_out_file, 0, MAX_LINE,
2062                                ASM_COMMENT_START, " ", "\n");
2063           /* Add a blank line here so it appears in assembler output but not
2064              screen output.  */
2065           fprintf (asm_out_file, "\n");
2066         }
2067 #endif
2068     }
2069 }
2070
2071 /* Default version of get_pch_validity.
2072    By default, every flag difference is fatal; that will be mostly right for
2073    most targets, but completely right for very few.  */
2074
2075 void *
2076 default_get_pch_validity (size_t *len)
2077 {
2078 #ifdef TARGET_OPTIONS
2079   size_t i;
2080 #endif
2081   char *result, *r;
2082
2083   *len = sizeof (target_flags) + 2;
2084 #ifdef TARGET_OPTIONS
2085   for (i = 0; i < ARRAY_SIZE (target_options); i++)
2086     {
2087       *len += 1;
2088       if (*target_options[i].variable)
2089         *len += strlen (*target_options[i].variable);
2090     }
2091 #endif
2092
2093   result = r = xmalloc (*len);
2094   r[0] = flag_pic;
2095   r[1] = flag_pie;
2096   r += 2;
2097   memcpy (r, &target_flags, sizeof (target_flags));
2098   r += sizeof (target_flags);
2099
2100 #ifdef TARGET_OPTIONS
2101   for (i = 0; i < ARRAY_SIZE (target_options); i++)
2102     {
2103       const char *str = *target_options[i].variable;
2104       size_t l;
2105       if (! str)
2106         str = "";
2107       l = strlen (str) + 1;
2108       memcpy (r, str, l);
2109       r += l;
2110     }
2111 #endif
2112
2113   return result;
2114 }
2115
2116 /* Default version of pch_valid_p.  */
2117
2118 const char *
2119 default_pch_valid_p (const void *data_p, size_t len)
2120 {
2121   const char *data = (const char *)data_p;
2122   const char *flag_that_differs = NULL;
2123   size_t i;
2124
2125   /* -fpic and -fpie also usually make a PCH invalid.  */
2126   if (data[0] != flag_pic)
2127     return _("created and used with different settings of -fpic");
2128   if (data[1] != flag_pie)
2129     return _("created and used with different settings of -fpie");
2130   data += 2;
2131
2132   /* Check target_flags.  */
2133   if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
2134     {
2135       for (i = 0; i < ARRAY_SIZE (target_switches); i++)
2136         {
2137           int bits;
2138           int tf;
2139
2140           memcpy (&tf, data, sizeof (target_flags));
2141
2142           bits = target_switches[i].value;
2143           if (bits < 0)
2144             bits = -bits;
2145           if ((target_flags & bits) != (tf & bits))
2146             {
2147               flag_that_differs = target_switches[i].name;
2148               goto make_message;
2149             }
2150         }
2151       abort ();
2152     }
2153   data += sizeof (target_flags);
2154   len -= sizeof (target_flags);
2155
2156   /* Check string options.  */
2157 #ifdef TARGET_OPTIONS
2158   for (i = 0; i < ARRAY_SIZE (target_options); i++)
2159     {
2160       const char *str = *target_options[i].variable;
2161       size_t l;
2162       if (! str)
2163         str = "";
2164       l = strlen (str) + 1;
2165       if (len < l || memcmp (data, str, l) != 0)
2166         {
2167           flag_that_differs = target_options[i].prefix;
2168           goto make_message;
2169         }
2170       data += l;
2171       len -= l;
2172     }
2173 #endif
2174
2175   return NULL;
2176
2177  make_message:
2178   {
2179     char *r;
2180     asprintf (&r, _("created and used with differing settings of `-m%s'"),
2181                   flag_that_differs);
2182     if (r == NULL)
2183       return _("out of memory");
2184     return r;
2185   }
2186 }
2187
2188 /* Default tree printer.   Handles declarations only.  */
2189 static bool
2190 default_tree_printer (pretty_printer * pp, text_info *text)
2191 {
2192   switch (*text->format_spec)
2193     {
2194     case 'D':
2195     case 'F':
2196     case 'T':
2197       {
2198         tree t = va_arg (*text->args_ptr, tree);
2199         const char *n = DECL_NAME (t)
2200           ? lang_hooks.decl_printable_name (t, 2)
2201           : "<anonymous>";
2202         pp_string (pp, n);
2203       }
2204       return true;
2205
2206     default:
2207       return false;
2208     }
2209 }
2210
2211 /* Initialization of the front end environment, before command line
2212    options are parsed.  Signal handlers, internationalization etc.
2213    ARGV0 is main's argv[0].  */
2214 static void
2215 general_init (const char *argv0)
2216 {
2217   const char *p;
2218
2219   p = argv0 + strlen (argv0);
2220   while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
2221     --p;
2222   progname = p;
2223
2224   xmalloc_set_program_name (progname);
2225
2226   hex_init ();
2227
2228   gcc_init_libintl ();
2229
2230   /* Initialize the diagnostics reporting machinery, so option parsing
2231      can give warnings and errors.  */
2232   diagnostic_initialize (global_dc);
2233   /* Set a default printer.  Language specific initializations will
2234      override it later.  */
2235   pp_format_decoder (global_dc->printer) = &default_tree_printer;
2236
2237   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
2238 #ifdef SIGSEGV
2239   signal (SIGSEGV, crash_signal);
2240 #endif
2241 #ifdef SIGILL
2242   signal (SIGILL, crash_signal);
2243 #endif
2244 #ifdef SIGBUS
2245   signal (SIGBUS, crash_signal);
2246 #endif
2247 #ifdef SIGABRT
2248   signal (SIGABRT, crash_signal);
2249 #endif
2250 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
2251   signal (SIGIOT, crash_signal);
2252 #endif
2253 #ifdef SIGFPE
2254   signal (SIGFPE, crash_signal);
2255 #endif
2256
2257   /* Other host-specific signal setup.  */
2258   (*host_hooks.extra_signals)();
2259
2260   /* Initialize the garbage-collector, string pools and tree type hash
2261      table.  */
2262   init_ggc ();
2263   init_stringpool ();
2264   linemap_init (&line_table);
2265   init_ttree ();
2266
2267   /* Initialize register usage now so switches may override.  */
2268   init_reg_sets ();
2269
2270   /* Register the language-independent parameters.  */
2271   add_params (lang_independent_params, LAST_PARAM);
2272
2273   /* This must be done after add_params but before argument processing.  */
2274   init_ggc_heuristics();
2275   init_tree_optimization_passes ();
2276 }
2277
2278 /* Process the options that have been parsed.  */
2279 static void
2280 process_options (void)
2281 {
2282   /* Allow the front end to perform consistency checks and do further
2283      initialization based on the command line options.  This hook also
2284      sets the original filename if appropriate (e.g. foo.i -> foo.c)
2285      so we can correctly initialize debug output.  */
2286   no_backend = lang_hooks.post_options (&main_input_filename);
2287   input_filename = main_input_filename;
2288
2289 #ifdef OVERRIDE_OPTIONS
2290   /* Some machines may reject certain combinations of options.  */
2291   OVERRIDE_OPTIONS;
2292 #endif
2293
2294   if (flag_short_enums == 2)
2295     flag_short_enums = targetm.default_short_enums ();
2296
2297   /* Set aux_base_name if not already set.  */
2298   if (aux_base_name)
2299     ;
2300   else if (main_input_filename)
2301     {
2302       char *name = xstrdup (lbasename (main_input_filename));
2303
2304       strip_off_ending (name, strlen (name));
2305       aux_base_name = name;
2306     }
2307   else
2308     aux_base_name = "gccaux";
2309
2310   /* Set up the align_*_log variables, defaulting them to 1 if they
2311      were still unset.  */
2312   if (align_loops <= 0) align_loops = 1;
2313   if (align_loops_max_skip > align_loops || !align_loops)
2314     align_loops_max_skip = align_loops - 1;
2315   align_loops_log = floor_log2 (align_loops * 2 - 1);
2316   if (align_jumps <= 0) align_jumps = 1;
2317   if (align_jumps_max_skip > align_jumps || !align_jumps)
2318     align_jumps_max_skip = align_jumps - 1;
2319   align_jumps_log = floor_log2 (align_jumps * 2 - 1);
2320   if (align_labels <= 0) align_labels = 1;
2321   align_labels_log = floor_log2 (align_labels * 2 - 1);
2322   if (align_labels_max_skip > align_labels || !align_labels)
2323     align_labels_max_skip = align_labels - 1;
2324   if (align_functions <= 0) align_functions = 1;
2325   align_functions_log = floor_log2 (align_functions * 2 - 1);
2326
2327   /* Unrolling all loops implies that standard loop unrolling must also
2328      be done.  */
2329   if (flag_unroll_all_loops)
2330     flag_unroll_loops = 1;
2331
2332   if (flag_unroll_loops)
2333     {
2334       flag_old_unroll_loops = 0;
2335       flag_old_unroll_all_loops = 0;
2336     }
2337
2338   if (flag_old_unroll_all_loops)
2339     flag_old_unroll_loops = 1;
2340
2341   /* Old loop unrolling requires that strength_reduction be on also.  Silently
2342      turn on strength reduction here if it isn't already on.  Also, the loop
2343      unrolling code assumes that cse will be run after loop, so that must
2344      be turned on also.  */
2345   if (flag_old_unroll_loops)
2346     {
2347       flag_strength_reduce = 1;
2348       flag_rerun_cse_after_loop = 1;
2349     }
2350   if (flag_unroll_loops || flag_peel_loops)
2351     flag_rerun_cse_after_loop = 1;
2352
2353   if (flag_non_call_exceptions)
2354     flag_asynchronous_unwind_tables = 1;
2355   if (flag_asynchronous_unwind_tables)
2356     flag_unwind_tables = 1;
2357
2358   /* Disable unit-at-a-time mode for frontends not supporting callgraph
2359      interface.  */
2360   if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
2361     flag_unit_at_a_time = 0;
2362
2363   if (flag_value_profile_transformations)
2364     flag_profile_values = 1;
2365
2366   /* Warn about options that are not supported on this machine.  */
2367 #ifndef INSN_SCHEDULING
2368   if (flag_schedule_insns || flag_schedule_insns_after_reload)
2369     warning ("instruction scheduling not supported on this target machine");
2370 #endif
2371 #ifndef DELAY_SLOTS
2372   if (flag_delayed_branch)
2373     warning ("this target machine does not have delayed branches");
2374 #endif
2375
2376   if (flag_tree_based_profiling && flag_test_coverage)
2377     sorry ("test-coverage not yet implemented in trees.");
2378   if (flag_tree_based_profiling && flag_profile_values)
2379     sorry ("value-based profiling not yet implemented in trees.");
2380
2381   user_label_prefix = USER_LABEL_PREFIX;
2382   if (flag_leading_underscore != -1)
2383     {
2384       /* If the default prefix is more complicated than "" or "_",
2385          issue a warning and ignore this option.  */
2386       if (user_label_prefix[0] == 0 ||
2387           (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
2388         {
2389           user_label_prefix = flag_leading_underscore ? "_" : "";
2390         }
2391       else
2392         warning ("-f%sleading-underscore not supported on this target machine",
2393                  flag_leading_underscore ? "" : "no-");
2394     }
2395
2396   /* If we are in verbose mode, write out the version and maybe all the
2397      option flags in use.  */
2398   if (version_flag)
2399     {
2400       print_version (stderr, "");
2401       if (! quiet_flag)
2402         print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
2403     }
2404
2405   if (flag_syntax_only)
2406     {
2407       write_symbols = NO_DEBUG;
2408       profile_flag = 0;
2409     }
2410
2411   /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
2412      level is 0.  */
2413   if (debug_info_level == DINFO_LEVEL_NONE)
2414     write_symbols = NO_DEBUG;
2415
2416   /* Now we know write_symbols, set up the debug hooks based on it.
2417      By default we do nothing for debug output.  */
2418   if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
2419     default_debug_hooks = &do_nothing_debug_hooks;
2420 #if defined(DBX_DEBUGGING_INFO)
2421   else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
2422     default_debug_hooks = &dbx_debug_hooks;
2423 #endif
2424 #if defined(XCOFF_DEBUGGING_INFO)
2425   else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
2426     default_debug_hooks = &xcoff_debug_hooks;
2427 #endif
2428 #ifdef SDB_DEBUGGING_INFO
2429   else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
2430     default_debug_hooks = &sdb_debug_hooks;
2431 #endif
2432 #ifdef DWARF2_DEBUGGING_INFO
2433   else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
2434     default_debug_hooks = &dwarf2_debug_hooks;
2435 #endif
2436 #ifdef VMS_DEBUGGING_INFO
2437   else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
2438            || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
2439     default_debug_hooks = &vmsdbg_debug_hooks;
2440 #endif
2441
2442   if (write_symbols == NO_DEBUG)
2443     debug_hooks = &do_nothing_debug_hooks;
2444 #if defined(DBX_DEBUGGING_INFO)
2445   else if (write_symbols == DBX_DEBUG)
2446     debug_hooks = &dbx_debug_hooks;
2447 #endif
2448 #if defined(XCOFF_DEBUGGING_INFO)
2449   else if (write_symbols == XCOFF_DEBUG)
2450     debug_hooks = &xcoff_debug_hooks;
2451 #endif
2452 #ifdef SDB_DEBUGGING_INFO
2453   else if (write_symbols == SDB_DEBUG)
2454     debug_hooks = &sdb_debug_hooks;
2455 #endif
2456 #ifdef DWARF2_DEBUGGING_INFO
2457   else if (write_symbols == DWARF2_DEBUG)
2458     debug_hooks = &dwarf2_debug_hooks;
2459 #endif
2460 #ifdef VMS_DEBUGGING_INFO
2461   else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2462     debug_hooks = &vmsdbg_debug_hooks;
2463 #endif
2464   else
2465     error ("target system does not support the \"%s\" debug format",
2466            debug_type_names[write_symbols]);
2467
2468   /* Now we know which debug output will be used so we can set
2469      flag_var_tracking, flag_rename_registers and flag_web if the user has
2470      not specified them.  */
2471   if (debug_info_level < DINFO_LEVEL_NORMAL
2472       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
2473     {
2474       if (flag_var_tracking == 1)
2475         {
2476           if (debug_info_level < DINFO_LEVEL_NORMAL)
2477             warning ("variable tracking requested, but useless unless "
2478                      "producing debug info");
2479           else
2480             warning ("variable tracking requested, but not supported "
2481                      "by this debug format");
2482         }
2483       flag_var_tracking = 0;
2484     }
2485
2486   if (flag_rename_registers == AUTODETECT_FLAG_VAR_TRACKING)
2487     flag_rename_registers = default_debug_hooks->var_location
2488                             != do_nothing_debug_hooks.var_location;
2489
2490   if (flag_web == AUTODETECT_FLAG_VAR_TRACKING)
2491     flag_web = optimize >= 2 && (default_debug_hooks->var_location
2492                                  != do_nothing_debug_hooks.var_location);
2493
2494   if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
2495     flag_var_tracking = optimize >= 1;
2496
2497   /* If auxiliary info generation is desired, open the output file.
2498      This goes in the same directory as the source file--unlike
2499      all the other output files.  */
2500   if (flag_gen_aux_info)
2501     {
2502       aux_info_file = fopen (aux_info_file_name, "w");
2503       if (aux_info_file == 0)
2504         fatal_error ("can't open %s: %m", aux_info_file_name);
2505     }
2506
2507   if (! targetm.have_named_sections)
2508     {
2509       if (flag_function_sections)
2510         {
2511           warning ("-ffunction-sections not supported for this target");
2512           flag_function_sections = 0;
2513         }
2514       if (flag_data_sections)
2515         {
2516           warning ("-fdata-sections not supported for this target");
2517           flag_data_sections = 0;
2518         }
2519     }
2520
2521   if (flag_function_sections && profile_flag)
2522     {
2523       warning ("-ffunction-sections disabled; it makes profiling impossible");
2524       flag_function_sections = 0;
2525     }
2526
2527 #ifndef HAVE_prefetch
2528   if (flag_prefetch_loop_arrays)
2529     {
2530       warning ("-fprefetch-loop-arrays not supported for this target");
2531       flag_prefetch_loop_arrays = 0;
2532     }
2533 #else
2534   if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2535     {
2536       warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
2537       flag_prefetch_loop_arrays = 0;
2538     }
2539 #endif
2540
2541   /* This combination of options isn't handled for i386 targets and doesn't
2542      make much sense anyway, so don't allow it.  */
2543   if (flag_prefetch_loop_arrays && optimize_size)
2544     {
2545       warning ("-fprefetch-loop-arrays is not supported with -Os");
2546       flag_prefetch_loop_arrays = 0;
2547     }
2548
2549 #ifndef OBJECT_FORMAT_ELF
2550   if (flag_function_sections && write_symbols != NO_DEBUG)
2551     warning ("-ffunction-sections may affect debugging on some targets");
2552 #endif
2553
2554   /* The presence of IEEE signaling NaNs, implies all math can trap.  */
2555   if (flag_signaling_nans)
2556     flag_trapping_math = 1;
2557 }
2558
2559 /* Initialize the compiler back end.  */
2560 static void
2561 backend_init (void)
2562 {
2563   init_adjust_machine_modes ();
2564
2565   init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
2566                   || debug_info_level == DINFO_LEVEL_VERBOSE
2567 #ifdef VMS_DEBUGGING_INFO
2568                     /* Enable line number info for traceback.  */
2569                     || debug_info_level > DINFO_LEVEL_NONE
2570 #endif
2571                     || flag_test_coverage
2572                     || warn_notreached);
2573
2574   init_regs ();
2575   init_fake_stack_mems ();
2576   init_alias_once ();
2577   init_loop ();
2578   init_reload ();
2579   init_function_once ();
2580   init_varasm_once ();
2581
2582   /* The following initialization functions need to generate rtl, so
2583      provide a dummy function context for them.  */
2584   init_dummy_function_start ();
2585   init_expmed ();
2586   if (flag_caller_saves)
2587     init_caller_save ();
2588   expand_dummy_function_end ();
2589 }
2590
2591 /* Language-dependent initialization.  Returns nonzero on success.  */
2592 static int
2593 lang_dependent_init (const char *name)
2594 {
2595   if (dump_base_name == 0)
2596     dump_base_name = name ? name : "gccdump";
2597
2598   /* Other front-end initialization.  */
2599   if (lang_hooks.init () == 0)
2600     return 0;
2601
2602   init_asm_output (name);
2603
2604   /* These create various _DECL nodes, so need to be called after the
2605      front end is initialized.  */
2606   init_eh ();
2607   init_optabs ();
2608   init_optimization_passes ();
2609
2610   /* The following initialization functions need to generate rtl, so
2611      provide a dummy function context for them.  */
2612   init_dummy_function_start ();
2613   init_expr_once ();
2614   expand_dummy_function_end ();
2615
2616   /* If dbx symbol table desired, initialize writing it and output the
2617      predefined types.  */
2618   timevar_push (TV_SYMOUT);
2619
2620 #ifdef DWARF2_UNWIND_INFO
2621   if (dwarf2out_do_frame ())
2622     dwarf2out_frame_init ();
2623 #endif
2624
2625   /* Now we have the correct original filename, we can initialize
2626      debug output.  */
2627   (*debug_hooks->init) (name);
2628
2629   timevar_pop (TV_SYMOUT);
2630
2631   return 1;
2632 }
2633
2634 /* Clean up: close opened files, etc.  */
2635
2636 static void
2637 finalize (void)
2638 {
2639   /* Close the dump files.  */
2640   if (flag_gen_aux_info)
2641     {
2642       fclose (aux_info_file);
2643       if (errorcount)
2644         unlink (aux_info_file_name);
2645     }
2646
2647   /* Close non-debugging input and output files.  Take special care to note
2648      whether fclose returns an error, since the pages might still be on the
2649      buffer chain while the file is open.  */
2650
2651   if (asm_out_file)
2652     {
2653       if (ferror (asm_out_file) != 0)
2654         fatal_error ("error writing to %s: %m", asm_file_name);
2655       if (fclose (asm_out_file) != 0)
2656         fatal_error ("error closing %s: %m", asm_file_name);
2657     }
2658
2659   finish_optimization_passes ();
2660
2661   if (mem_report)
2662     {
2663       ggc_print_statistics ();
2664       stringpool_statistics ();
2665       dump_tree_statistics ();
2666       dump_rtx_statistics ();
2667       dump_varray_statistics ();
2668       dump_alloc_pool_statistics ();
2669       dump_ggc_loc_statistics ();
2670     }
2671
2672   /* Free up memory for the benefit of leak detectors.  */
2673   free_reg_info ();
2674
2675   /* Language-specific end of compilation actions.  */
2676   lang_hooks.finish ();
2677 }
2678
2679 /* Initialize the compiler, and compile the input file.  */
2680 static void
2681 do_compile (void)
2682 {
2683   /* Initialize timing first.  The C front ends read the main file in
2684      the post_options hook, and C++ does file timings.  */
2685   if (time_report || !quiet_flag  || flag_detailed_statistics)
2686     timevar_init ();
2687   timevar_start (TV_TOTAL);
2688
2689   process_options ();
2690
2691   /* Don't do any more if an error has already occurred.  */
2692   if (!errorcount)
2693     {
2694       /* Set up the back-end if requested.  */
2695       if (!no_backend)
2696         backend_init ();
2697
2698       /* Language-dependent initialization.  Returns true on success.  */
2699       if (lang_dependent_init (main_input_filename))
2700         compile_file ();
2701
2702       finalize ();
2703     }
2704
2705   /* Stop timing and print the times.  */
2706   timevar_stop (TV_TOTAL);
2707   timevar_print (stderr);
2708 }
2709
2710 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2711    Exit code is FATAL_EXIT_CODE if can't open files or if there were
2712    any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2713
2714    It is not safe to call this function more than once.  */
2715
2716 int
2717 toplev_main (unsigned int argc, const char **argv)
2718 {
2719   save_argv = argv;
2720
2721   /* Initialization of GCC's environment, and diagnostics.  */
2722   general_init (argv[0]);
2723
2724   /* Parse the options and do minimal processing; basically just
2725      enough to default flags appropriately.  */
2726   decode_options (argc, argv);
2727
2728   randomize ();
2729
2730   /* Exit early if we can (e.g. -help).  */
2731   if (!exit_after_options)
2732     do_compile ();
2733
2734   if (errorcount || sorrycount)
2735     return (FATAL_EXIT_CODE);
2736
2737   return (SUCCESS_EXIT_CODE);
2738 }