1132734Skan/* Top level of GCC compilers (cc1, cc1plus, etc.) 272566Sobrien Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3169699Skan 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 4169699Skan Free Software Foundation, Inc. 518334Speter 690282SobrienThis file is part of GCC. 718334Speter 890282SobrienGCC is free software; you can redistribute it and/or modify it under 990282Sobrienthe terms of the GNU General Public License as published by the Free 1090282SobrienSoftware Foundation; either version 2, or (at your option) any later 1190282Sobrienversion. 1218334Speter 1390282SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1490282SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1590282SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1690282Sobrienfor more details. 1718334Speter 1818334SpeterYou should have received a copy of the GNU General Public License 1990282Sobrienalong with GCC; see the file COPYING. If not, write to the Free 20169699SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 21169699Skan02110-1301, USA. */ 2218334Speter 2352558Sobrien/* $FreeBSD$ */ 2452558Sobrien 2518334Speter/* This is the top level of cc1/c++. 2618334Speter It parses command args, opens files, invokes the various passes 2718334Speter in the proper order, and counts the time used by each. 2818334Speter Error messages and low-level interface to malloc also handled here. */ 2918334Speter 3018334Speter#include "config.h" 3150615Sobrien#undef FLOAT /* This is for hpux. They should change hpux. */ 3250615Sobrien#undef FFS /* Some systems define this in param.h. */ 3350615Sobrien#include "system.h" 34132734Skan#include "coretypes.h" 35132734Skan#include "tm.h" 3618334Speter#include <signal.h> 3718334Speter 3850615Sobrien#ifdef HAVE_SYS_RESOURCE_H 3950615Sobrien# include <sys/resource.h> 4018334Speter#endif 4150615Sobrien 4250615Sobrien#ifdef HAVE_SYS_TIMES_H 4350615Sobrien# include <sys/times.h> 4418334Speter#endif 4518334Speter 46169699Skan#include "line-map.h" 4718334Speter#include "input.h" 4818334Speter#include "tree.h" 49169699Skan#include "version.h" 5018334Speter#include "rtl.h" 5190282Sobrien#include "tm_p.h" 5218334Speter#include "flags.h" 5318334Speter#include "insn-attr.h" 5450615Sobrien#include "insn-config.h" 5590282Sobrien#include "insn-flags.h" 5690282Sobrien#include "hard-reg-set.h" 5750615Sobrien#include "recog.h" 5818334Speter#include "output.h" 5950615Sobrien#include "except.h" 6090282Sobrien#include "function.h" 6150615Sobrien#include "toplev.h" 6252558Sobrien#include "expr.h" 6352558Sobrien#include "basic-block.h" 6452558Sobrien#include "intl.h" 6590282Sobrien#include "ggc.h" 6690282Sobrien#include "graph.h" 6790282Sobrien#include "regs.h" 6890282Sobrien#include "timevar.h" 6990282Sobrien#include "diagnostic.h" 7090282Sobrien#include "params.h" 7190282Sobrien#include "reload.h" 7290282Sobrien#include "dwarf2asm.h" 7390282Sobrien#include "integrate.h" 74117414Skan#include "real.h" 7590282Sobrien#include "debug.h" 7690282Sobrien#include "target.h" 7790282Sobrien#include "langhooks.h" 78117414Skan#include "cfglayout.h" 79132734Skan#include "cfgloop.h" 80132734Skan#include "hosthooks.h" 81132734Skan#include "cgraph.h" 82132734Skan#include "opts.h" 83132734Skan#include "coverage.h" 84132734Skan#include "value-prof.h" 85132734Skan#include "alloc-pool.h" 86169699Skan#include "tree-mudflap.h" 8718334Speter 8850615Sobrien#if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO) 8950615Sobrien#include "dwarf2out.h" 9050615Sobrien#endif 9150615Sobrien 9250615Sobrien#if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) 9350615Sobrien#include "dbxout.h" 9450615Sobrien#endif 9550615Sobrien 9650615Sobrien#ifdef SDB_DEBUGGING_INFO 9750615Sobrien#include "sdbout.h" 9850615Sobrien#endif 9950615Sobrien 10018334Speter#ifdef XCOFF_DEBUGGING_INFO 10190282Sobrien#include "xcoffout.h" /* Needed for external data 10290282Sobrien declarations for e.g. AIX 4.x. */ 10318334Speter#endif 104132734Skan 105132734Skanstatic void general_init (const char *); 106132734Skanstatic void do_compile (void); 107132734Skanstatic void process_options (void); 108132734Skanstatic void backend_init (void); 109132734Skanstatic int lang_dependent_init (const char *); 110132734Skanstatic void init_asm_output (const char *); 111132734Skanstatic void finalize (void); 11218334Speter 113132734Skanstatic void crash_signal (int) ATTRIBUTE_NORETURN; 114132734Skanstatic void setup_core_dumping (void); 115132734Skanstatic void compile_file (void); 11650615Sobrien 117132734Skanstatic int print_single_switch (FILE *, int, int, const char *, 118132734Skan const char *, const char *, 119132734Skan const char *, const char *); 120132734Skanstatic void print_switch_values (FILE *, int, int, const char *, 121132734Skan const char *, const char *); 12218334Speter 123117414Skan/* Nonzero to dump debug info whilst parsing (-dy option). */ 124117414Skanstatic int set_yydebug; 125117414Skan 126132734Skan/* True if we don't need a backend (e.g. preprocessing only). */ 127132734Skanstatic bool no_backend; 128132734Skan 12950615Sobrien/* Length of line when printing switch values. */ 13050615Sobrien#define MAX_LINE 75 13118334Speter 13218334Speter/* Name of program invoked, sans directories. */ 13318334Speter 13490282Sobrienconst char *progname; 13518334Speter 136132734Skan/* Copy of argument vector to toplev_main. */ 137132734Skanstatic const char **save_argv; 13818334Speter 13918334Speter/* Name of top-level original source file (what was input to cpp). 14018334Speter This comes from the #-command at the beginning of the actual input. 14118334Speter If there isn't any there, then this is the cc1 input file name. */ 14218334Speter 14390282Sobrienconst char *main_input_filename; 14418334Speter 145169699Skan#ifndef USE_MAPPED_LOCATION 146169699Skanlocation_t unknown_location = { NULL, 0 }; 147169699Skan#endif 148169699Skan 149169699Skan/* Used to enable -fvar-tracking, -fweb and -frename-registers according 150169699Skan to optimize and default_debug_hooks in process_options (). */ 151169699Skan#define AUTODETECT_VALUE 2 152169699Skan 153132734Skan/* Current position in real source file. */ 15418334Speter 155132734Skanlocation_t input_location; 15618334Speter 157169699Skanstruct line_maps line_table; 158169699Skan 15952558Sobrien/* Nonzero if it is unsafe to create any new pseudo registers. */ 16052558Sobrienint no_new_pseudos; 16152558Sobrien 16218334Speter/* Stack of currently pending input files. */ 16318334Speter 16418334Speterstruct file_stack *input_file_stack; 16518334Speter 16618334Speter/* Incremented on each change to input_file_stack. */ 16718334Speterint input_file_stack_tick; 16818334Speter 169169699Skan/* Record of input_file_stack at each tick. */ 170169699Skantypedef struct file_stack *fs_p; 171169699SkanDEF_VEC_P(fs_p); 172169699SkanDEF_VEC_ALLOC_P(fs_p,heap); 173169699Skanstatic VEC(fs_p,heap) *input_file_stack_history; 174169699Skan 175169699Skan/* Whether input_file_stack has been restored to a previous state (in 176169699Skan which case there should be no more pushing). */ 177169699Skanstatic bool input_file_stack_restored; 178169699Skan 17918334Speter/* Name to use as base of names for dump output files. */ 18018334Speter 18152558Sobrienconst char *dump_base_name; 18218334Speter 183117414Skan/* Name to use as a base for auxiliary output files. */ 184117414Skan 185117414Skanconst char *aux_base_name; 186117414Skan 18718334Speter/* Bit flags that specify the machine subtype we are compiling for. 18818334Speter Bits are tested using macros TARGET_... defined in the tm.h file 18918334Speter and set by `-m...' switches. Must be defined in rtlanal.c. */ 19018334Speter 19118334Speterextern int target_flags; 19218334Speter 193117414Skan/* A mask of target_flags that includes bit X if X was set or cleared 194117414Skan on the command line. */ 195117414Skan 196117414Skanint target_flags_explicit; 197117414Skan 19890282Sobrien/* Debug hooks - dependent upon command line options. */ 19918334Speter 200132734Skanconst struct gcc_debug_hooks *debug_hooks; 20190282Sobrien 202169699Skan/* Debug hooks - target default. */ 20390282Sobrien 204169699Skanstatic const struct gcc_debug_hooks *default_debug_hooks; 20590282Sobrien 20690282Sobrien/* Other flags saying which kinds of debugging dump have been requested. */ 20790282Sobrien 20890282Sobrienint rtl_dump_and_exit; 20990282Sobrienint flag_print_asm_name; 21052558Sobrienenum graph_dump_types graph_dump_format; 21118334Speter 21218334Speter/* Name for output file of assembly code, specified with -o. */ 21318334Speter 214132734Skanconst char *asm_file_name; 21518334Speter 21618334Speter/* Nonzero means do optimizations. -O. 21718334Speter Particular numeric values stand for particular amounts of optimization; 21818334Speter thus, -O2 stores 2 here. However, the optimizations beyond the basic 21918334Speter ones are not controlled directly by this variable. Instead, they are 22018334Speter controlled by individual `flag_...' variables that are defaulted 22118334Speter based on this variable. */ 22218334Speter 22318334Speterint optimize = 0; 22418334Speter 22550615Sobrien/* Nonzero means optimize for size. -Os. 226117414Skan The only valid values are zero and nonzero. When optimize_size is 227117414Skan nonzero, optimize defaults to 2, but certain individual code 22850615Sobrien bloating optimizations are disabled. */ 22950615Sobrien 23050615Sobrienint optimize_size = 0; 23150615Sobrien 23290282Sobrien/* The FUNCTION_DECL for the function currently being compiled, 23390282Sobrien or 0 if between functions. */ 23490282Sobrientree current_function_decl; 23518334Speter 236169699Skan/* Set to the FUNC_BEGIN label of the current function, or NULL 23790282Sobrien if none. */ 238169699Skanconst char * current_function_func_begin_label; 23990282Sobrien 24018334Speter/* Temporarily suppress certain warnings. 24118334Speter This is set while reading code from a system header file. */ 24218334Speter 24318334Speterint in_system_header = 0; 24418334Speter 245132734Skan/* Nonzero means to collect statistics which might be expensive 24690282Sobrien and to print them when we are done. */ 24790282Sobrienint flag_detailed_statistics = 0; 24890282Sobrien 249132734Skan/* A random sequence of characters, unless overridden by user. */ 250132734Skanconst char *flag_random_seed; 251132734Skan 252132734Skan/* A local time stamp derived from the time of compilation. It will be 253132734Skan zero if the system cannot provide a time. It will be -1u, if the 254132734Skan user has specified a particular random seed. */ 255132734Skanunsigned local_tick; 256132734Skan 25718334Speter/* -f flags. */ 25818334Speter 25918334Speter/* Nonzero means `char' should be signed. */ 26018334Speter 26118334Speterint flag_signed_char; 26218334Speter 263169699Skan/* Nonzero means give an enum type only as many bytes as it needs. A value 264169699Skan of 2 means it has not yet been initialized. */ 26518334Speter 26618334Speterint flag_short_enums; 26718334Speter 26818334Speter/* Nonzero if structures and unions should be returned in memory. 26918334Speter 27018334Speter This should only be defined if compatibility with another compiler or 27118334Speter with an ABI is needed, because it results in slower code. */ 27218334Speter 27318334Speter#ifndef DEFAULT_PCC_STRUCT_RETURN 27418334Speter#define DEFAULT_PCC_STRUCT_RETURN 1 27518334Speter#endif 27618334Speter 27718334Speter/* Nonzero for -fpcc-struct-return: return values the same way PCC does. */ 27818334Speter 27918334Speterint flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN; 28018334Speter 28152558Sobrien/* 0 means straightforward implementation of complex divide acceptable. 28252558Sobrien 1 means wide ranges of inputs must work for complex divide. 283169699Skan 2 means C99-like requirements for complex multiply and divide. */ 28452558Sobrien 285169699Skanint flag_complex_method = 1; 28652558Sobrien 28796289Sobrien/* Nonzero means that we don't want inlining by virtue of -fno-inline, 28896289Sobrien not just because the tree inliner turned us off. */ 28996289Sobrien 29096289Sobrienint flag_really_no_inline = 2; 29196289Sobrien 29218334Speter/* Nonzero means we should be saving declaration info into a .X file. */ 29318334Speter 29418334Speterint flag_gen_aux_info = 0; 29518334Speter 29618334Speter/* Specified name of aux-info file. */ 29718334Speter 298132734Skanconst char *aux_info_file_name; 29918334Speter 300132734Skan/* Nonzero if we are compiling code for a shared library, zero for 301132734Skan executable. */ 302132734Skan 303132734Skanint flag_shlib; 304132734Skan 305169699Skan/* Generate code for GNU or NeXT Objective-C runtime environment. */ 306169699Skan 307169699Skan#ifdef NEXT_OBJC_RUNTIME 308169699Skanint flag_next_runtime = 1; 309169699Skan#else 310169699Skanint flag_next_runtime = 0; 311169699Skan#endif 312169699Skan 313117414Skan/* Set to the default thread-local storage (tls) model to use. */ 314117414Skan 315117414Skanenum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC; 316117414Skan 31718334Speter/* Nonzero means change certain warnings into errors. 31818334Speter Usually these are warnings about failure to conform to some standard. */ 31918334Speter 32018334Speterint flag_pedantic_errors = 0; 32118334Speter 32250615Sobrien/* -dA causes debug commentary information to be produced in 32350615Sobrien the generated assembly code (to make it more readable). This option 32450615Sobrien is generally only of use to those who actually need to read the 32550615Sobrien generated assembly code (perhaps while debugging the compiler itself). 32650615Sobrien Currently, this switch is only used by dwarfout.c; however, it is intended 32750615Sobrien to be a catchall for printing debug information in the assembler file. */ 32850615Sobrien 32950615Sobrienint flag_debug_asm = 0; 33050615Sobrien 33190282Sobrien/* -dP causes the rtl to be emitted as a comment in assembly. */ 33290282Sobrien 33390282Sobrienint flag_dump_rtl_in_asm = 0; 33490282Sobrien 33590282Sobrien/* When non-NULL, indicates that whenever space is allocated on the 33690282Sobrien stack, the resulting stack pointer must not pass this 33790282Sobrien address---that is, for stacks that grow downward, the stack pointer 33890282Sobrien must always be greater than or equal to this address; for stacks 33990282Sobrien that grow upward, the stack pointer must be less than this address. 34090282Sobrien At present, the rtx may be either a REG or a SYMBOL_REF, although 34190282Sobrien the support provided depends on the backend. */ 34290282Sobrienrtx stack_limit_rtx; 34350615Sobrien 34490282Sobrien/* If one, renumber instruction UIDs to reduce the number of 34590282Sobrien unused UIDs if there are a lot of instructions. If greater than 34690282Sobrien one, unconditionally renumber instruction UIDs. */ 34790282Sobrienint flag_renumber_insns = 1; 34890282Sobrien 349169699Skan/* Nonzero if we should track variables. When 350169699Skan flag_var_tracking == AUTODETECT_VALUE it will be set according 351169699Skan to optimize, debug_info_level and debug_hooks in process_options (). */ 352169699Skanint flag_var_tracking = AUTODETECT_VALUE; 353117414Skan 354169699Skan/* True if the user has tagged the function with the 'section' 355169699Skan attribute. */ 356117414Skan 357169699Skanbool user_defined_section_attribute = false; 358117414Skan 35990282Sobrien/* Values of the -falign-* flags: how much to align labels in code. 36090282Sobrien 0 means `use default', 1 means `don't align'. 36190282Sobrien For each variable, there is an _log variant which is the power 36290282Sobrien of two not less than the variable, for .align output. */ 36390282Sobrien 36490282Sobrienint align_loops_log; 36590282Sobrienint align_loops_max_skip; 36690282Sobrienint align_jumps_log; 36790282Sobrienint align_jumps_max_skip; 36890282Sobrienint align_labels_log; 36990282Sobrienint align_labels_max_skip; 37090282Sobrienint align_functions_log; 37190282Sobrien 37250615Sobrientypedef struct 37350615Sobrien{ 37490282Sobrien const char *const string; 37590282Sobrien int *const variable; 37690282Sobrien const int on_value; 37750615Sobrien} 37850615Sobrienlang_independent_options; 37950615Sobrien 380132734Skan/* Nonzero if subexpressions must be evaluated from left-to-right. */ 381132734Skanint flag_evaluation_order = 0; 382132734Skan 38352558Sobrien/* The user symbol prefix after having resolved same. */ 38452558Sobrienconst char *user_label_prefix; 38552558Sobrien 38690282Sobrienstatic const param_info lang_independent_params[] = { 387169699Skan#define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \ 388169699Skan { OPTION, DEFAULT, MIN, MAX, HELP }, 38990282Sobrien#include "params.def" 39090282Sobrien#undef DEFPARAM 391169699Skan { NULL, 0, 0, 0, NULL } 39290282Sobrien}; 39390282Sobrien 394132734Skan/* Output files for assembler code (real compiler output) 395132734Skan and debugging dumps. */ 39618334Speter 397132734SkanFILE *asm_out_file; 398132734SkanFILE *aux_info_file; 399169699SkanFILE *dump_file = NULL; 400169699Skanconst char *dump_file_name; 40118334Speter 402132734Skan/* The current working directory of a translation. It's generally the 403132734Skan directory from which compilation was initiated, but a preprocessed 404132734Skan file may specify the original directory in which it was 405132734Skan created. */ 40690282Sobrien 407132734Skanstatic const char *src_pwd; 40818334Speter 409132734Skan/* Initialize src_pwd with the given string, and return true. If it 410132734Skan was already initialized, return false. As a special case, it may 411132734Skan be called with a NULL argument to test whether src_pwd has NOT been 412132734Skan initialized yet. */ 41318334Speter 414132734Skanbool 415132734Skanset_src_pwd (const char *pwd) 416132734Skan{ 417132734Skan if (src_pwd) 418169699Skan { 419169699Skan if (strcmp (src_pwd, pwd) == 0) 420169699Skan return true; 421169699Skan else 422169699Skan return false; 423169699Skan } 42418334Speter 425132734Skan src_pwd = xstrdup (pwd); 426132734Skan return true; 427132734Skan} 42818334Speter 429132734Skan/* Return the directory from which the translation unit was initiated, 430132734Skan in case set_src_pwd() was not called before to assign it a 431132734Skan different value. */ 43218334Speter 433132734Skanconst char * 434132734Skanget_src_pwd (void) 435132734Skan{ 436132734Skan if (! src_pwd) 437169699Skan { 438169699Skan src_pwd = getpwd (); 439169699Skan if (!src_pwd) 440169699Skan src_pwd = "."; 441169699Skan } 44290282Sobrien 443132734Skan return src_pwd; 444132734Skan} 44590282Sobrien 446132734Skan/* Called when the start of a function definition is parsed, 447132734Skan this function prints on stderr the name of the function. */ 44890282Sobrienvoid 449132734Skanannounce_function (tree decl) 45090282Sobrien{ 451132734Skan if (!quiet_flag) 452132734Skan { 453132734Skan if (rtl_dump_and_exit) 454169699Skan fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl))); 455132734Skan else 456169699Skan fprintf (stderr, " %s", lang_hooks.decl_printable_name (decl, 2)); 457132734Skan fflush (stderr); 458132734Skan pp_needs_newline (global_dc->printer) = true; 459132734Skan diagnostic_set_last_function (global_dc); 460132734Skan } 46190282Sobrien} 46290282Sobrien 463132734Skan/* Set up a default flag_random_seed and local_tick, unless the user 464132734Skan already specified one. */ 46590282Sobrien 466132734Skanstatic void 467132734Skanrandomize (void) 46890282Sobrien{ 469132734Skan if (!flag_random_seed) 470132734Skan { 471132734Skan unsigned HOST_WIDE_INT value; 472132734Skan static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; 47390282Sobrien 474132734Skan /* Get some more or less random data. */ 475132734Skan#ifdef HAVE_GETTIMEOFDAY 476132734Skan { 477132734Skan struct timeval tv; 478132734Skan 479132734Skan gettimeofday (&tv, NULL); 480132734Skan local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000; 481132734Skan } 482132734Skan#else 483132734Skan { 484132734Skan time_t now = time (NULL); 485132734Skan 486132734Skan if (now != (time_t)-1) 487132734Skan local_tick = (unsigned) now; 488132734Skan } 489132734Skan#endif 490132734Skan value = local_tick ^ getpid (); 491132734Skan 492132734Skan sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); 493132734Skan flag_random_seed = random_seed; 494132734Skan } 495132734Skan else if (!local_tick) 496132734Skan local_tick = -1; 49790282Sobrien} 49890282Sobrien 49918334Speter 50052558Sobrien/* Decode the string P as an integral parameter. 50152558Sobrien If the string is indeed an integer return its numeric value else 50252558Sobrien issue an Invalid Option error for the option PNAME and return DEFVAL. 50390282Sobrien If PNAME is zero just return DEFVAL, do not call error. */ 50490282Sobrien 50552558Sobrienint 506132734Skanread_integral_parameter (const char *p, const char *pname, const int defval) 50752558Sobrien{ 50852558Sobrien const char *endp = p; 50952558Sobrien 51052558Sobrien while (*endp) 51152558Sobrien { 51290282Sobrien if (ISDIGIT (*endp)) 51352558Sobrien endp++; 51452558Sobrien else 51552558Sobrien break; 51652558Sobrien } 51752558Sobrien 51852558Sobrien if (*endp != 0) 51952558Sobrien { 52052558Sobrien if (pname != 0) 521169699Skan error ("invalid option argument %qs", pname); 52252558Sobrien return defval; 52352558Sobrien } 52452558Sobrien 52552558Sobrien return atoi (p); 52652558Sobrien} 52718334Speter 528169699Skan/* When compiling with a recent enough GCC, we use the GNU C "extern inline" 529169699Skan for floor_log2 and exact_log2; see toplev.h. That construct, however, 530169699Skan conflicts with the ISO C++ One Definition Rule. */ 53118334Speter 532169699Skan#if GCC_VERSION < 3004 || !defined (__cplusplus) 53318334Speter 534169699Skan/* Given X, an unsigned number, return the largest int Y such that 2**Y <= X. 535169699Skan If X is 0, return -1. */ 536169699Skan 53718334Speterint 538169699Skanfloor_log2 (unsigned HOST_WIDE_INT x) 53918334Speter{ 540169699Skan int t = 0; 541169699Skan 542169699Skan if (x == 0) 54318334Speter return -1; 544169699Skan 545169699Skan#ifdef CLZ_HWI 546169699Skan t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x); 547169699Skan#else 548169699Skan if (HOST_BITS_PER_WIDE_INT > 64) 549169699Skan if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64)) 550169699Skan t += 64; 551169699Skan if (HOST_BITS_PER_WIDE_INT > 32) 552169699Skan if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32)) 553169699Skan t += 32; 554169699Skan if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16)) 555169699Skan t += 16; 556169699Skan if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8)) 557169699Skan t += 8; 558169699Skan if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4)) 559169699Skan t += 4; 560169699Skan if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2)) 561169699Skan t += 2; 562169699Skan if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1)) 563169699Skan t += 1; 564169699Skan#endif 565169699Skan 566169699Skan return t; 56718334Speter} 56818334Speter 569169699Skan/* Return the logarithm of X, base 2, considering X unsigned, 570169699Skan if X is a power of 2. Otherwise, returns -1. */ 57118334Speter 57218334Speterint 573169699Skanexact_log2 (unsigned HOST_WIDE_INT x) 57418334Speter{ 575169699Skan if (x != (x & -x)) 576169699Skan return -1; 577169699Skan#ifdef CTZ_HWI 578169699Skan return x ? CTZ_HWI (x) : -1; 579169699Skan#else 580169699Skan return floor_log2 (x); 581169699Skan#endif 58218334Speter} 58318334Speter 584169699Skan#endif /* GCC_VERSION < 3004 || !defined (__cplusplus) */ 585169699Skan 58690282Sobrien/* Handler for fatal signals, such as SIGSEGV. These are transformed 587132734Skan into ICE messages, which is much more user friendly. In case the 588132734Skan error printer crashes, reset the signal to prevent infinite recursion. */ 58918334Speter 59018334Speterstatic void 591132734Skancrash_signal (int signo) 59218334Speter{ 593132734Skan signal (signo, SIG_DFL); 594169699Skan 595169699Skan /* If we crashed while processing an ASM statement, then be a little more 596169699Skan graceful. It's most likely the user's fault. */ 597169699Skan if (this_is_asm_operands) 598169699Skan { 599169699Skan output_operand_lossage ("unrecoverable error"); 600169699Skan exit (FATAL_EXIT_CODE); 601169699Skan } 602169699Skan 603117414Skan internal_error ("%s", strsignal (signo)); 60418334Speter} 60518334Speter 606132734Skan/* Arrange to dump core on error. (The regular error message is still 607132734Skan printed first, except in the case of abort().) */ 608132734Skan 609132734Skanstatic void 610132734Skansetup_core_dumping (void) 611132734Skan{ 612132734Skan#ifdef SIGABRT 613132734Skan signal (SIGABRT, SIG_DFL); 614132734Skan#endif 615132734Skan#if defined(HAVE_SETRLIMIT) 616132734Skan { 617132734Skan struct rlimit rlim; 618132734Skan if (getrlimit (RLIMIT_CORE, &rlim) != 0) 619132734Skan fatal_error ("getting core file size maximum limit: %m"); 620132734Skan rlim.rlim_cur = rlim.rlim_max; 621132734Skan if (setrlimit (RLIMIT_CORE, &rlim) != 0) 622132734Skan fatal_error ("setting core file size limit to maximum: %m"); 623132734Skan } 624132734Skan#endif 625132734Skan diagnostic_abort_on_error (global_dc); 626132734Skan} 627132734Skan 628132734Skan 62918334Speter/* Strip off a legitimate source ending from the input string NAME of 63018334Speter length LEN. Rather than having to know the names used by all of 63150615Sobrien our front ends, we strip off an ending of a period followed by 63290282Sobrien up to five characters. (Java uses ".class".) */ 63318334Speter 63418334Spetervoid 635132734Skanstrip_off_ending (char *name, int len) 63618334Speter{ 63750615Sobrien int i; 638117414Skan for (i = 2; i < 6 && len > i; i++) 63950615Sobrien { 64050615Sobrien if (name[len - i] == '.') 64150615Sobrien { 64250615Sobrien name[len - i] = '\0'; 64350615Sobrien break; 64450615Sobrien } 64550615Sobrien } 64618334Speter} 64718334Speter 64818334Speter/* Output a quoted string. */ 64950615Sobrien 65018334Spetervoid 651132734Skanoutput_quoted_string (FILE *asm_file, const char *string) 65218334Speter{ 65350615Sobrien#ifdef OUTPUT_QUOTED_STRING 65450615Sobrien OUTPUT_QUOTED_STRING (asm_file, string); 65550615Sobrien#else 65618334Speter char c; 65718334Speter 65818334Speter putc ('\"', asm_file); 65918334Speter while ((c = *string++) != 0) 66018334Speter { 66196289Sobrien if (ISPRINT (c)) 66296289Sobrien { 66396289Sobrien if (c == '\"' || c == '\\') 66496289Sobrien putc ('\\', asm_file); 66596289Sobrien putc (c, asm_file); 66696289Sobrien } 66796289Sobrien else 668117414Skan fprintf (asm_file, "\\%03o", (unsigned char) c); 66918334Speter } 67018334Speter putc ('\"', asm_file); 67150615Sobrien#endif 67218334Speter} 67318334Speter 674132734Skan/* Output a file name in the form wanted by System V. */ 675132734Skan 676117414Skanvoid 677132734Skanoutput_file_directive (FILE *asm_file, const char *input_name) 678117414Skan{ 679132734Skan int len; 680132734Skan const char *na; 681117414Skan 682132734Skan if (input_name == NULL) 683132734Skan input_name = "<stdin>"; 684117414Skan 685132734Skan len = strlen (input_name); 686132734Skan na = input_name + len; 687117414Skan 68818334Speter /* NA gets INPUT_NAME sans directory names. */ 68918334Speter while (na > input_name) 69018334Speter { 69190282Sobrien if (IS_DIR_SEPARATOR (na[-1])) 692117414Skan break; 69318334Speter na--; 69418334Speter } 69518334Speter 69618334Speter#ifdef ASM_OUTPUT_SOURCE_FILENAME 69718334Speter ASM_OUTPUT_SOURCE_FILENAME (asm_file, na); 69818334Speter#else 69918334Speter fprintf (asm_file, "\t.file\t"); 70018334Speter output_quoted_string (asm_file, na); 70118334Speter fputc ('\n', asm_file); 70218334Speter#endif 70318334Speter} 704132734Skan 705169699Skan/* A subroutine of wrapup_global_declarations. We've come to the end of 706169699Skan the compilation unit. All deferred variables should be undeferred, 707169699Skan and all incomplete decls should be finalized. */ 70818334Speter 709169699Skanvoid 710169699Skanwrapup_global_declaration_1 (tree decl) 71118334Speter{ 712169699Skan /* We're not deferring this any longer. Assignment is conditional to 713169699Skan avoid needlessly dirtying PCH pages. */ 714169699Skan if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS) 715169699Skan && DECL_DEFER_OUTPUT (decl) != 0) 716169699Skan DECL_DEFER_OUTPUT (decl) = 0; 71718334Speter 718169699Skan if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0) 719169699Skan lang_hooks.finish_incomplete_decl (decl); 720169699Skan} 72150615Sobrien 722169699Skan/* A subroutine of wrapup_global_declarations. Decide whether or not DECL 723169699Skan needs to be output. Return true if it is output. */ 72450615Sobrien 725169699Skanbool 726169699Skanwrapup_global_declaration_2 (tree decl) 727169699Skan{ 728169699Skan if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl)) 729169699Skan return false; 73050615Sobrien 731169699Skan /* Don't write out static consts, unless we still need them. 73250615Sobrien 733169699Skan We also keep static consts if not optimizing (for debugging), 734169699Skan unless the user specified -fno-keep-static-consts. 735169699Skan ??? They might be better written into the debug information. 736169699Skan This is possible when using DWARF. 73750615Sobrien 738169699Skan A language processor that wants static constants to be always 739169699Skan written out (even if it is not used) is responsible for 740169699Skan calling rest_of_decl_compilation itself. E.g. the C front-end 741169699Skan calls rest_of_decl_compilation from finish_decl. 742169699Skan One motivation for this is that is conventional in some 743169699Skan environments to write things like: 744169699Skan static const char rcsid[] = "... version string ..."; 745169699Skan intending to force the string to be in the executable. 74690282Sobrien 747169699Skan A language processor that would prefer to have unneeded 748169699Skan static constants "optimized away" would just defer writing 749169699Skan them out until here. E.g. C++ does this, because static 750169699Skan constants are often defined in header files. 75190282Sobrien 752169699Skan ??? A tempting alternative (for both C and C++) would be 753169699Skan to force a constant to be written if and only if it is 754169699Skan defined in a main file, as opposed to an include file. */ 75590282Sobrien 756169699Skan if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)) 757169699Skan { 758169699Skan struct cgraph_varpool_node *node; 759169699Skan bool needed = true; 760169699Skan node = cgraph_varpool_node (decl); 76150615Sobrien 762169699Skan if (node->finalized) 763169699Skan needed = false; 764169699Skan else if (node->alias) 765169699Skan needed = false; 766169699Skan else if (!cgraph_global_info_ready 767169699Skan && (TREE_USED (decl) 768169699Skan || TREE_USED (DECL_ASSEMBLER_NAME (decl)))) 769169699Skan /* needed */; 770169699Skan else if (node->needed) 771169699Skan /* needed */; 772169699Skan else if (DECL_COMDAT (decl)) 773169699Skan needed = false; 774169699Skan else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl) 775169699Skan && (optimize || !flag_keep_static_consts 776169699Skan || DECL_ARTIFICIAL (decl))) 777169699Skan needed = false; 77890282Sobrien 779169699Skan if (needed) 780169699Skan { 781169699Skan rest_of_decl_compilation (decl, 1, 1); 782169699Skan return true; 783169699Skan } 78490282Sobrien } 78550615Sobrien 786169699Skan return false; 78718334Speter} 78818334Speter 78952558Sobrien/* Do any final processing required for the declarations in VEC, of 79052558Sobrien which there are LEN. We write out inline functions and variables 79152558Sobrien that have been deferred until this point, but which are required. 792117414Skan Returns nonzero if anything was put out. */ 79390282Sobrien 794169699Skanbool 795132734Skanwrapup_global_declarations (tree *vec, int len) 79652558Sobrien{ 797169699Skan bool reconsider, output_something = false; 79852558Sobrien int i; 79950615Sobrien 80052558Sobrien for (i = 0; i < len; i++) 801169699Skan wrapup_global_declaration_1 (vec[i]); 80290282Sobrien 80352558Sobrien /* Now emit any global variables or functions that we have been 80452558Sobrien putting off. We need to loop in case one of the things emitted 80552558Sobrien here references another one which comes earlier in the list. */ 80652558Sobrien do 80752558Sobrien { 808169699Skan reconsider = false; 80952558Sobrien for (i = 0; i < len; i++) 810169699Skan reconsider |= wrapup_global_declaration_2 (vec[i]); 81152558Sobrien if (reconsider) 812169699Skan output_something = true; 81352558Sobrien } 81452558Sobrien while (reconsider); 81552558Sobrien 81652558Sobrien return output_something; 81752558Sobrien} 81852558Sobrien 819169699Skan/* A subroutine of check_global_declarations. Issue appropriate warnings 820169699Skan for the global declaration DECL. */ 821169699Skan 822169699Skanvoid 823169699Skancheck_global_declaration_1 (tree decl) 824169699Skan{ 825169699Skan /* Warn about any function declared static but not defined. We don't 826169699Skan warn about variables, because many programs have static variables 827169699Skan that exist only to get some text into the object file. */ 828169699Skan if (TREE_CODE (decl) == FUNCTION_DECL 829169699Skan && DECL_INITIAL (decl) == 0 830169699Skan && DECL_EXTERNAL (decl) 831169699Skan && ! DECL_ARTIFICIAL (decl) 832169699Skan && ! TREE_NO_WARNING (decl) 833169699Skan && ! TREE_PUBLIC (decl) 834169699Skan && (warn_unused_function 835169699Skan || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))) 836169699Skan { 837169699Skan if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))) 838169699Skan pedwarn ("%q+F used but never defined", decl); 839169699Skan else 840169699Skan warning (0, "%q+F declared %<static%> but never defined", decl); 841169699Skan /* This symbol is effectively an "extern" declaration now. */ 842169699Skan TREE_PUBLIC (decl) = 1; 843169699Skan assemble_external (decl); 844169699Skan } 845169699Skan 846169699Skan /* Warn about static fns or vars defined but not used. */ 847169699Skan if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL) 848169699Skan /* We don't warn about "static const" variables because the 849169699Skan "rcs_id" idiom uses that construction. */ 850169699Skan || (warn_unused_variable 851169699Skan && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl))) 852169699Skan && ! DECL_IN_SYSTEM_HEADER (decl) 853169699Skan && ! TREE_USED (decl) 854169699Skan /* The TREE_USED bit for file-scope decls is kept in the identifier, 855169699Skan to handle multiple external decls in different scopes. */ 856169699Skan && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl))) 857169699Skan && ! DECL_EXTERNAL (decl) 858169699Skan && ! TREE_PUBLIC (decl) 859169699Skan /* A volatile variable might be used in some non-obvious way. */ 860169699Skan && ! TREE_THIS_VOLATILE (decl) 861169699Skan /* Global register variables must be declared to reserve them. */ 862169699Skan && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)) 863169699Skan /* Otherwise, ask the language. */ 864169699Skan && lang_hooks.decls.warn_unused_global (decl)) 865169699Skan warning (0, "%q+D defined but not used", decl); 866169699Skan} 867169699Skan 86852558Sobrien/* Issue appropriate warnings for the global declarations in VEC (of 869169699Skan which there are LEN). */ 87090282Sobrien 87152558Sobrienvoid 872132734Skancheck_global_declarations (tree *vec, int len) 87352558Sobrien{ 87452558Sobrien int i; 87552558Sobrien 87652558Sobrien for (i = 0; i < len; i++) 877169699Skan check_global_declaration_1 (vec[i]); 878169699Skan} 87952558Sobrien 880169699Skan/* Emit debugging information for all global declarations in VEC. */ 88152558Sobrien 882169699Skanvoid 883169699Skanemit_debug_global_declarations (tree *vec, int len) 884169699Skan{ 885169699Skan int i; 88652558Sobrien 887169699Skan /* Avoid confusing the debug information machinery when there are errors. */ 888169699Skan if (errorcount != 0 || sorrycount != 0) 889169699Skan return; 89052558Sobrien 891169699Skan timevar_push (TV_SYMOUT); 892169699Skan for (i = 0; i < len; i++) 893169699Skan debug_hooks->global_decl (vec[i]); 894169699Skan timevar_pop (TV_SYMOUT); 89552558Sobrien} 89652558Sobrien 897132734Skan/* Warn about a use of an identifier which was marked deprecated. */ 898132734Skanvoid 899132734Skanwarn_deprecated_use (tree node) 900132734Skan{ 901132734Skan if (node == 0 || !warn_deprecated_decl) 902132734Skan return; 903132734Skan 904132734Skan if (DECL_P (node)) 905169699Skan { 906169699Skan expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node)); 907169699Skan warning (OPT_Wdeprecated_declarations, 908169699Skan "%qs is deprecated (declared at %s:%d)", 909169699Skan IDENTIFIER_POINTER (DECL_NAME (node)), 910169699Skan xloc.file, xloc.line); 911169699Skan } 912132734Skan else if (TYPE_P (node)) 913132734Skan { 914132734Skan const char *what = NULL; 915132734Skan tree decl = TYPE_STUB_DECL (node); 916132734Skan 917169699Skan if (TYPE_NAME (node)) 918169699Skan { 919169699Skan if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE) 920169699Skan what = IDENTIFIER_POINTER (TYPE_NAME (node)); 921169699Skan else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL 922169699Skan && DECL_NAME (TYPE_NAME (node))) 923169699Skan what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))); 924169699Skan } 925132734Skan 926169699Skan if (decl) 927132734Skan { 928169699Skan expanded_location xloc 929169699Skan = expand_location (DECL_SOURCE_LOCATION (decl)); 930169699Skan if (what) 931169699Skan warning (OPT_Wdeprecated_declarations, 932169699Skan "%qs is deprecated (declared at %s:%d)", what, 933169699Skan xloc.file, xloc.line); 934132734Skan else 935169699Skan warning (OPT_Wdeprecated_declarations, 936169699Skan "type is deprecated (declared at %s:%d)", 937169699Skan xloc.file, xloc.line); 938132734Skan } 939132734Skan else 940169699Skan { 941169699Skan if (what) 942169699Skan warning (OPT_Wdeprecated_declarations, "%qs is deprecated", what); 943169699Skan else 944169699Skan warning (OPT_Wdeprecated_declarations, "type is deprecated"); 945169699Skan } 946132734Skan } 947132734Skan} 948132734Skan 949260919Spfg/* APPLE LOCAL begin "unavailable" attribute (radar 2809697) --ilr */ 950260919Spfg/* Warn about a use of an identifier which was marked deprecated. */ 951260919Spfgvoid 952260919Spfgerror_unavailable_use (tree node) 953260919Spfg{ 954260919Spfg if (node == 0) 955260919Spfg return; 956260919Spfg 957260919Spfg if (DECL_P (node)) 958260919Spfg error ("%qs is unavailable (declared at %s:%d)", 959260919Spfg IDENTIFIER_POINTER (DECL_NAME (node)), 960260919Spfg DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node)); 961260919Spfg else if (TYPE_P (node)) 962260919Spfg { 963260919Spfg const char *what = NULL; 964260919Spfg tree decl = TYPE_STUB_DECL (node); 965260919Spfg 966260919Spfg if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE) 967260919Spfg what = IDENTIFIER_POINTER (TYPE_NAME (node)); 968260919Spfg else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL 969260919Spfg && DECL_NAME (TYPE_NAME (node))) 970260919Spfg what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))); 971260919Spfg 972260919Spfg if (what) 973260919Spfg { 974260919Spfg if (decl) 975260919Spfg error ("%qs is unavailable (declared at %s:%d)", what, 976260919Spfg DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); 977260919Spfg else 978260919Spfg error ("%qs is unavailable", what); 979260919Spfg } 980260919Spfg else if (decl) 981260919Spfg error ("type is unavailable (declared at %s:%d)", 982260919Spfg DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); 983260919Spfg else 984260919Spfg error ("type is unavailable"); 985260919Spfg } 986260919Spfg} 987260919Spfg/* APPLE LOCAL end "unavailable" attribute (radar 2809697) --ilr */ 988260919Spfg 989132734Skan/* Save the current INPUT_LOCATION on the top entry in the 99090282Sobrien INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the 991132734Skan INPUT_LOCATION accordingly. */ 99218334Speter 99390282Sobrienvoid 994169699Skan#ifdef USE_MAPPED_LOCATION 995169699Skanpush_srcloc (location_t fline) 996169699Skan#else 997132734Skanpush_srcloc (const char *file, int line) 998169699Skan#endif 99918334Speter{ 100090282Sobrien struct file_stack *fs; 100118334Speter 1002169699Skan gcc_assert (!input_file_stack_restored); 1003169699Skan if (input_file_stack_tick == (int) ((1U << INPUT_FILE_STACK_BITS) - 1)) 1004169699Skan sorry ("GCC supports only %d input file changes", input_file_stack_tick); 1005169699Skan 1006169699Skan fs = XNEW (struct file_stack); 1007132734Skan fs->location = input_location; 100890282Sobrien fs->next = input_file_stack; 1009169699Skan#ifdef USE_MAPPED_LOCATION 1010169699Skan input_location = fline; 1011169699Skan#else 1012132734Skan input_filename = file; 1013132734Skan input_line = line; 1014169699Skan#endif 101590282Sobrien input_file_stack = fs; 101690282Sobrien input_file_stack_tick++; 1017169699Skan VEC_safe_push (fs_p, heap, input_file_stack_history, input_file_stack); 101890282Sobrien} 101918334Speter 102090282Sobrien/* Pop the top entry off the stack of presently open source files. 1021132734Skan Restore the INPUT_LOCATION from the new topmost entry on the 1022132734Skan stack. */ 102318334Speter 102490282Sobrienvoid 1025132734Skanpop_srcloc (void) 102690282Sobrien{ 102790282Sobrien struct file_stack *fs; 102818334Speter 1029169699Skan gcc_assert (!input_file_stack_restored); 1030169699Skan if (input_file_stack_tick == (int) ((1U << INPUT_FILE_STACK_BITS) - 1)) 1031169699Skan sorry ("GCC supports only %d input file changes", input_file_stack_tick); 1032169699Skan 103390282Sobrien fs = input_file_stack; 1034132734Skan input_location = fs->location; 103590282Sobrien input_file_stack = fs->next; 103690282Sobrien input_file_stack_tick++; 1037169699Skan VEC_safe_push (fs_p, heap, input_file_stack_history, input_file_stack); 103890282Sobrien} 103918334Speter 1040169699Skan/* Restore the input file stack to its state as of TICK, for the sake 1041169699Skan of diagnostics after processing the whole input. Once this has 1042169699Skan been called, push_srcloc and pop_srcloc may no longer be 1043169699Skan called. */ 1044169699Skanvoid 1045169699Skanrestore_input_file_stack (int tick) 1046169699Skan{ 1047169699Skan if (tick == 0) 1048169699Skan input_file_stack = NULL; 1049169699Skan else 1050169699Skan input_file_stack = VEC_index (fs_p, input_file_stack_history, tick - 1); 1051169699Skan input_file_stack_tick = tick; 1052169699Skan input_file_stack_restored = true; 1053169699Skan} 1054169699Skan 105590282Sobrien/* Compile an entire translation unit. Write a file of assembly 105690282Sobrien output and various debugging dumps. */ 105718334Speter 105890282Sobrienstatic void 1059132734Skancompile_file (void) 106090282Sobrien{ 106118334Speter /* Initialize yet another pass. */ 106218334Speter 1063169699Skan init_cgraph (); 106450615Sobrien init_final (main_input_filename); 1065132734Skan coverage_init (aux_base_name); 106618334Speter 106790282Sobrien timevar_push (TV_PARSE); 106818334Speter 1069117414Skan /* Call the parser, which parses the entire file (calling 1070117414Skan rest_of_compilation for each function). */ 1071169699Skan lang_hooks.parse_file (set_yydebug); 107218334Speter 107390282Sobrien /* In case there were missing block closers, 107490282Sobrien get us back to the global binding level. */ 1075169699Skan lang_hooks.clear_binding_stack (); 107618334Speter 107718334Speter /* Compilation is now finished except for writing 107818334Speter what's left of the symbol table output. */ 107990282Sobrien timevar_pop (TV_PARSE); 108018334Speter 1081169699Skan if (flag_syntax_only || errorcount || sorrycount) 108290282Sobrien return; 108352558Sobrien 1084169699Skan lang_hooks.decls.final_write_globals (); 1085132734Skan cgraph_varpool_assemble_pending_decls (); 1086169699Skan finish_aliases_2 (); 108718334Speter 1088132734Skan /* This must occur after the loop to output deferred functions. 1089132734Skan Else the coverage initializer would not be emitted if all the 1090132734Skan functions in this compilation unit were deferred. */ 1091132734Skan coverage_finish (); 109218334Speter 1093169699Skan /* Likewise for mudflap static object registrations. */ 1094169699Skan if (flag_mudflap) 1095169699Skan mudflap_finish_file (); 1096169699Skan 1097169699Skan output_shared_constant_pool (); 1098169699Skan output_object_blocks (); 1099169699Skan 110018334Speter /* Write out any pending weak symbol declarations. */ 110118334Speter 110218334Speter weak_finish (); 110318334Speter 110490282Sobrien /* Do dbx symbols. */ 110590282Sobrien timevar_push (TV_SYMOUT); 110618334Speter 1107169699Skan#if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO 110850615Sobrien if (dwarf2out_do_frame ()) 110950615Sobrien dwarf2out_frame_finish (); 111050615Sobrien#endif 111150615Sobrien 111290282Sobrien (*debug_hooks->finish) (main_input_filename); 111390282Sobrien timevar_pop (TV_SYMOUT); 111450615Sobrien 111518334Speter /* Output some stuff at end of file if nec. */ 111618334Speter 111790282Sobrien dw2_output_indirect_constants (); 111890282Sobrien 1119215840Sdim /* Flush any pending external directives. */ 1120169699Skan process_pending_assemble_externals (); 1121146908Skan 112290282Sobrien /* Attach a special .ident directive to the end of the file to identify 112390282Sobrien the version of GCC which compiled this code. The format of the .ident 112490282Sobrien string is patterned after the ones produced by native SVR4 compilers. */ 112590282Sobrien#ifdef IDENT_ASM_OP 112690282Sobrien if (!flag_no_ident) 112790282Sobrien fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n", 112890282Sobrien IDENT_ASM_OP, version_string); 112952558Sobrien#endif 113052558Sobrien 1131169699Skan /* This must be at the end. Some target ports emit end of file directives 1132169699Skan into the assembly file here, and hence we can not output anything to the 1133169699Skan assembly file after this point. */ 1134169699Skan targetm.asm_out.file_end (); 113518334Speter} 1136132734Skan 113790282Sobrien/* Parse a -d... command line switch. */ 113850615Sobrien 1139132734Skanvoid 1140132734Skandecode_d_option (const char *arg) 114190282Sobrien{ 1142169699Skan int c; 114350615Sobrien 114490282Sobrien while (*arg) 114590282Sobrien switch (c = *arg++) 114690282Sobrien { 114790282Sobrien case 'A': 114890282Sobrien flag_debug_asm = 1; 114990282Sobrien break; 115090282Sobrien case 'p': 115190282Sobrien flag_print_asm_name = 1; 115290282Sobrien break; 115390282Sobrien case 'P': 1154117414Skan flag_dump_rtl_in_asm = 1; 1155117414Skan flag_print_asm_name = 1; 1156117414Skan break; 115790282Sobrien case 'v': 115890282Sobrien graph_dump_format = vcg; 115990282Sobrien break; 116090282Sobrien case 'x': 116190282Sobrien rtl_dump_and_exit = 1; 116290282Sobrien break; 116390282Sobrien case 'y': 1164117414Skan set_yydebug = 1; 116590282Sobrien break; 116690282Sobrien case 'D': /* These are handled by the preprocessor. */ 116790282Sobrien case 'I': 116890282Sobrien break; 1169132734Skan case 'H': 1170132734Skan setup_core_dumping(); 1171132734Skan break; 117290282Sobrien 1173169699Skan case 'a': 117490282Sobrien default: 1175169699Skan if (!enable_rtl_dump_file (c)) 1176169699Skan warning (0, "unrecognized gcc debugging option: %c", c); 117790282Sobrien break; 117890282Sobrien } 117990282Sobrien} 118090282Sobrien 1181132734Skan/* Indexed by enum debug_info_type. */ 1182132734Skanconst char *const debug_type_names[] = 118350615Sobrien{ 1184169699Skan "none", "stabs", "coff", "dwarf-2", "xcoff", "vms" 1185132734Skan}; 118650615Sobrien 118750615Sobrien/* Print version information to FILE. 118850615Sobrien Each line begins with INDENT (for the case where FILE is the 118950615Sobrien assembler output file). */ 119018334Speter 1191132734Skanvoid 1192132734Skanprint_version (FILE *file, const char *indent) 119350615Sobrien{ 1194169699Skan static const char fmt1[] = 1195169699Skan#ifdef __GNUC__ 1196169699Skan N_("%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n") 1197169699Skan#else 1198169699Skan N_("%s%s%s version %s (%s) compiled by CC.\n") 1199169699Skan#endif 1200169699Skan ; 1201169699Skan static const char fmt2[] = 1202169699Skan N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n"); 120350615Sobrien#ifndef __VERSION__ 120452558Sobrien#define __VERSION__ "[?]" 120550615Sobrien#endif 1206169699Skan fprintf (file, 1207169699Skan file == stderr ? _(fmt1) : fmt1, 1208169699Skan indent, *indent != 0 ? " " : "", 120990282Sobrien lang_hooks.name, version_string, TARGET_NAME, 121090282Sobrien indent, __VERSION__); 1211169699Skan fprintf (file, 1212169699Skan file == stderr ? _(fmt2) : fmt2, 1213117414Skan indent, *indent != 0 ? " " : "", 1214117414Skan PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE)); 121550615Sobrien} 121618334Speter 121750615Sobrien/* Print an option value and return the adjusted position in the line. 121850615Sobrien ??? We don't handle error returns from fprintf (disk full); presumably 121950615Sobrien other code will catch a disk full though. */ 122018334Speter 122152558Sobrienstatic int 1222132734Skanprint_single_switch (FILE *file, int pos, int max, 1223132734Skan const char *indent, const char *sep, const char *term, 1224132734Skan const char *type, const char *name) 122518334Speter{ 122650615Sobrien /* The ultrix fprintf returns 0 on success, so compute the result we want 122750615Sobrien here since we need it for the following test. */ 122850615Sobrien int len = strlen (sep) + strlen (type) + strlen (name); 122918334Speter 123050615Sobrien if (pos != 0 123150615Sobrien && pos + len > max) 123218334Speter { 123350615Sobrien fprintf (file, "%s", term); 123450615Sobrien pos = 0; 123518334Speter } 123650615Sobrien if (pos == 0) 123750615Sobrien { 123850615Sobrien fprintf (file, "%s", indent); 123950615Sobrien pos = strlen (indent); 124050615Sobrien } 124150615Sobrien fprintf (file, "%s%s%s", sep, type, name); 124250615Sobrien pos += len; 124350615Sobrien return pos; 124418334Speter} 124590282Sobrien 124650615Sobrien/* Print active target switches to FILE. 124750615Sobrien POS is the current cursor position and MAX is the size of a "line". 124850615Sobrien Each line begins with INDENT and ends with TERM. 124950615Sobrien Each switch is separated from the next by SEP. */ 125018334Speter 125152558Sobrienstatic void 1252132734Skanprint_switch_values (FILE *file, int pos, int max, 1253132734Skan const char *indent, const char *sep, const char *term) 125418334Speter{ 125550615Sobrien size_t j; 1256132734Skan const char **p; 125718334Speter 1258117414Skan /* Fill in the -frandom-seed option, if the user didn't pass it, so 1259132734Skan that it can be printed below. This helps reproducibility. */ 1260132734Skan randomize (); 1261117414Skan 126250615Sobrien /* Print the options as passed. */ 126350615Sobrien pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term, 126452558Sobrien _("options passed: "), ""); 126550615Sobrien 126650615Sobrien for (p = &save_argv[1]; *p != NULL; p++) 126750615Sobrien if (**p == '-') 126850615Sobrien { 126950615Sobrien /* Ignore these. */ 127050615Sobrien if (strcmp (*p, "-o") == 0) 127150615Sobrien { 127250615Sobrien if (p[1] != NULL) 127350615Sobrien p++; 127450615Sobrien continue; 127550615Sobrien } 127650615Sobrien if (strcmp (*p, "-quiet") == 0) 127750615Sobrien continue; 127850615Sobrien if (strcmp (*p, "-version") == 0) 127950615Sobrien continue; 128050615Sobrien if ((*p)[1] == 'd') 128150615Sobrien continue; 128250615Sobrien 128350615Sobrien pos = print_single_switch (file, pos, max, indent, sep, term, *p, ""); 128450615Sobrien } 128550615Sobrien if (pos > 0) 128650615Sobrien fprintf (file, "%s", term); 128750615Sobrien 128850615Sobrien /* Print the -f and -m options that have been enabled. 128950615Sobrien We don't handle language specific options but printing argv 129050615Sobrien should suffice. */ 129150615Sobrien 129250615Sobrien pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term, 129352558Sobrien _("options enabled: "), ""); 129450615Sobrien 1295169699Skan for (j = 0; j < cl_options_count; j++) 1296169699Skan if ((cl_options[j].flags & CL_REPORT) 1297169699Skan && option_enabled (j) > 0) 129850615Sobrien pos = print_single_switch (file, pos, max, indent, sep, term, 1299169699Skan "", cl_options[j].opt_text); 130018334Speter 130150615Sobrien fprintf (file, "%s", term); 130218334Speter} 1303132734Skan 130490282Sobrien/* Open assembly code output file. Do this even if -fsyntax-only is 130590282Sobrien on, because then the driver will have provided the name of a 130690282Sobrien temporary file or bit bucket for us. NAME is the file specified on 130790282Sobrien the command line, possibly NULL. */ 130890282Sobrienstatic void 1309132734Skaninit_asm_output (const char *name) 131090282Sobrien{ 131190282Sobrien if (name == NULL && asm_file_name == 0) 131290282Sobrien asm_out_file = stdout; 131390282Sobrien else 131490282Sobrien { 131590282Sobrien if (asm_file_name == 0) 1316117414Skan { 1317117414Skan int len = strlen (dump_base_name); 1318169699Skan char *dumpname = XNEWVEC (char, len + 6); 1319117414Skan memcpy (dumpname, dump_base_name, len + 1); 1320117414Skan strip_off_ending (dumpname, len); 1321117414Skan strcat (dumpname, ".s"); 1322117414Skan asm_file_name = dumpname; 1323117414Skan } 132490282Sobrien if (!strcmp (asm_file_name, "-")) 1325117414Skan asm_out_file = stdout; 132690282Sobrien else 1327169699Skan asm_out_file = fopen (asm_file_name, "w+b"); 132890282Sobrien if (asm_out_file == 0) 1329169699Skan fatal_error ("can%'t open %s for writing: %m", asm_file_name); 133090282Sobrien } 133150615Sobrien 133290282Sobrien if (!flag_syntax_only) 133390282Sobrien { 1334132734Skan targetm.asm_out.file_start (); 133590282Sobrien 133690282Sobrien#ifdef ASM_COMMENT_START 133790282Sobrien if (flag_verbose_asm) 133890282Sobrien { 133990282Sobrien /* Print the list of options in effect. */ 134090282Sobrien print_version (asm_out_file, ASM_COMMENT_START); 134190282Sobrien print_switch_values (asm_out_file, 0, MAX_LINE, 134290282Sobrien ASM_COMMENT_START, " ", "\n"); 134390282Sobrien /* Add a blank line here so it appears in assembler output but not 134490282Sobrien screen output. */ 134590282Sobrien fprintf (asm_out_file, "\n"); 134690282Sobrien } 134790282Sobrien#endif 134890282Sobrien } 134990282Sobrien} 1350132734Skan 1351169699Skan/* Return true if the state of option OPTION should be stored in PCH files 1352169699Skan and checked by default_pch_valid_p. Store the option's current state 1353169699Skan in STATE if so. */ 1354169699Skan 1355169699Skanstatic inline bool 1356169699Skanoption_affects_pch_p (int option, struct cl_option_state *state) 1357169699Skan{ 1358169699Skan if ((cl_options[option].flags & CL_TARGET) == 0) 1359169699Skan return false; 1360169699Skan if (cl_options[option].flag_var == &target_flags) 1361169699Skan if (targetm.check_pch_target_flags) 1362169699Skan return false; 1363169699Skan return get_option_state (option, state); 1364169699Skan} 1365169699Skan 1366132734Skan/* Default version of get_pch_validity. 1367132734Skan By default, every flag difference is fatal; that will be mostly right for 1368132734Skan most targets, but completely right for very few. */ 1369132734Skan 1370132734Skanvoid * 1371132734Skandefault_get_pch_validity (size_t *len) 1372132734Skan{ 1373169699Skan struct cl_option_state state; 1374132734Skan size_t i; 1375132734Skan char *result, *r; 1376132734Skan 1377169699Skan *len = 2; 1378169699Skan if (targetm.check_pch_target_flags) 1379169699Skan *len += sizeof (target_flags); 1380169699Skan for (i = 0; i < cl_options_count; i++) 1381169699Skan if (option_affects_pch_p (i, &state)) 1382169699Skan *len += state.size; 1383132734Skan 1384169699Skan result = r = XNEWVEC (char, *len); 1385132734Skan r[0] = flag_pic; 1386132734Skan r[1] = flag_pie; 1387132734Skan r += 2; 1388169699Skan if (targetm.check_pch_target_flags) 1389132734Skan { 1390169699Skan memcpy (r, &target_flags, sizeof (target_flags)); 1391169699Skan r += sizeof (target_flags); 1392132734Skan } 1393132734Skan 1394169699Skan for (i = 0; i < cl_options_count; i++) 1395169699Skan if (option_affects_pch_p (i, &state)) 1396169699Skan { 1397169699Skan memcpy (r, state.data, state.size); 1398169699Skan r += state.size; 1399169699Skan } 1400169699Skan 1401132734Skan return result; 1402132734Skan} 1403132734Skan 1404169699Skan/* Return a message which says that a PCH file was created with a different 1405169699Skan setting of OPTION. */ 1406169699Skan 1407169699Skanstatic const char * 1408169699Skanpch_option_mismatch (const char *option) 1409169699Skan{ 1410169699Skan char *r; 1411169699Skan 1412169699Skan asprintf (&r, _("created and used with differing settings of '%s'"), option); 1413169699Skan if (r == NULL) 1414169699Skan return _("out of memory"); 1415169699Skan return r; 1416169699Skan} 1417169699Skan 1418132734Skan/* Default version of pch_valid_p. */ 1419132734Skan 1420132734Skanconst char * 1421132734Skandefault_pch_valid_p (const void *data_p, size_t len) 1422132734Skan{ 1423169699Skan struct cl_option_state state; 1424132734Skan const char *data = (const char *)data_p; 1425132734Skan size_t i; 1426132734Skan 1427132734Skan /* -fpic and -fpie also usually make a PCH invalid. */ 1428132734Skan if (data[0] != flag_pic) 1429132734Skan return _("created and used with different settings of -fpic"); 1430132734Skan if (data[1] != flag_pie) 1431132734Skan return _("created and used with different settings of -fpie"); 1432132734Skan data += 2; 1433132734Skan 1434132734Skan /* Check target_flags. */ 1435169699Skan if (targetm.check_pch_target_flags) 1436132734Skan { 1437169699Skan int tf; 1438169699Skan const char *r; 1439132734Skan 1440169699Skan memcpy (&tf, data, sizeof (target_flags)); 1441169699Skan data += sizeof (target_flags); 1442169699Skan len -= sizeof (target_flags); 1443169699Skan r = targetm.check_pch_target_flags (tf); 1444169699Skan if (r != NULL) 1445169699Skan return r; 1446132734Skan } 1447132734Skan 1448169699Skan for (i = 0; i < cl_options_count; i++) 1449169699Skan if (option_affects_pch_p (i, &state)) 1450169699Skan { 1451169699Skan if (memcmp (data, state.data, state.size) != 0) 1452169699Skan return pch_option_mismatch (cl_options[i].opt_text); 1453169699Skan data += state.size; 1454169699Skan len -= state.size; 1455169699Skan } 1456132734Skan 1457132734Skan return NULL; 1458132734Skan} 1459132734Skan 1460132734Skan/* Default tree printer. Handles declarations only. */ 1461132734Skanstatic bool 1462169699Skandefault_tree_printer (pretty_printer * pp, text_info *text, const char *spec, 1463169699Skan int precision, bool wide, bool set_locus, bool hash) 1464132734Skan{ 1465169699Skan tree t; 1466169699Skan 1467169699Skan /* FUTURE: %+x should set the locus. */ 1468169699Skan if (precision != 0 || wide || hash) 1469169699Skan return false; 1470169699Skan 1471169699Skan switch (*spec) 1472132734Skan { 1473132734Skan case 'D': 1474169699Skan t = va_arg (*text->args_ptr, tree); 1475169699Skan if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t)) 1476169699Skan t = DECL_DEBUG_EXPR (t); 1477169699Skan break; 1478169699Skan 1479132734Skan case 'F': 1480132734Skan case 'T': 1481169699Skan t = va_arg (*text->args_ptr, tree); 1482169699Skan break; 1483132734Skan 1484132734Skan default: 1485132734Skan return false; 1486132734Skan } 1487169699Skan 1488169699Skan if (set_locus && text->locus) 1489169699Skan *text->locus = DECL_SOURCE_LOCATION (t); 1490169699Skan 1491169699Skan if (DECL_P (t)) 1492169699Skan { 1493169699Skan const char *n = DECL_NAME (t) 1494169699Skan ? lang_hooks.decl_printable_name (t, 2) 1495169699Skan : "<anonymous>"; 1496169699Skan pp_string (pp, n); 1497169699Skan } 1498169699Skan else 1499169699Skan dump_generic_node (pp, t, 0, 0, 0); 1500169699Skan 1501169699Skan return true; 1502132734Skan} 1503132734Skan 150490282Sobrien/* Initialization of the front end environment, before command line 150590282Sobrien options are parsed. Signal handlers, internationalization etc. 150690282Sobrien ARGV0 is main's argv[0]. */ 150790282Sobrienstatic void 1508132734Skangeneral_init (const char *argv0) 150950615Sobrien{ 1510132734Skan const char *p; 151190282Sobrien 151290282Sobrien p = argv0 + strlen (argv0); 151390282Sobrien while (p != argv0 && !IS_DIR_SEPARATOR (p[-1])) 151490282Sobrien --p; 151590282Sobrien progname = p; 151690282Sobrien 151790282Sobrien xmalloc_set_program_name (progname); 151890282Sobrien 1519117414Skan hex_init (); 1520117414Skan 1521169699Skan /* Unlock the stdio streams. */ 1522169699Skan unlock_std_streams (); 1523169699Skan 152490282Sobrien gcc_init_libintl (); 152590282Sobrien 1526132734Skan /* Initialize the diagnostics reporting machinery, so option parsing 1527132734Skan can give warnings and errors. */ 1528132734Skan diagnostic_initialize (global_dc); 1529132734Skan /* Set a default printer. Language specific initializations will 1530132734Skan override it later. */ 1531132734Skan pp_format_decoder (global_dc->printer) = &default_tree_printer; 1532132734Skan 153390282Sobrien /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */ 153490282Sobrien#ifdef SIGSEGV 153590282Sobrien signal (SIGSEGV, crash_signal); 153650615Sobrien#endif 153790282Sobrien#ifdef SIGILL 153890282Sobrien signal (SIGILL, crash_signal); 153950615Sobrien#endif 154090282Sobrien#ifdef SIGBUS 154190282Sobrien signal (SIGBUS, crash_signal); 154290282Sobrien#endif 154390282Sobrien#ifdef SIGABRT 154490282Sobrien signal (SIGABRT, crash_signal); 154590282Sobrien#endif 154690282Sobrien#if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT) 154790282Sobrien signal (SIGIOT, crash_signal); 154890282Sobrien#endif 1549117414Skan#ifdef SIGFPE 1550117414Skan signal (SIGFPE, crash_signal); 1551117414Skan#endif 155290282Sobrien 1553132734Skan /* Other host-specific signal setup. */ 1554132734Skan (*host_hooks.extra_signals)(); 1555117414Skan 1556117414Skan /* Initialize the garbage-collector, string pools and tree type hash 1557117414Skan table. */ 1558117414Skan init_ggc (); 1559117414Skan init_stringpool (); 1560169699Skan linemap_init (&line_table); 1561117414Skan init_ttree (); 1562117414Skan 156390282Sobrien /* Initialize register usage now so switches may override. */ 156490282Sobrien init_reg_sets (); 156590282Sobrien 156690282Sobrien /* Register the language-independent parameters. */ 156790282Sobrien add_params (lang_independent_params, LAST_PARAM); 156890282Sobrien 1569117414Skan /* This must be done after add_params but before argument processing. */ 1570117414Skan init_ggc_heuristics(); 1571169699Skan init_optimization_passes (); 1572132734Skan} 1573117414Skan 1574169699Skan/* Return true if the current target supports -fsection-anchors. */ 1575169699Skan 1576169699Skanstatic bool 1577169699Skantarget_supports_section_anchors_p (void) 1578169699Skan{ 1579169699Skan if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0) 1580169699Skan return false; 1581169699Skan 1582169699Skan if (targetm.asm_out.output_anchor == NULL) 1583169699Skan return false; 1584169699Skan 1585169699Skan return true; 1586169699Skan} 1587169699Skan 1588132734Skan/* Process the options that have been parsed. */ 1589132734Skanstatic void 1590132734Skanprocess_options (void) 1591132734Skan{ 1592161660Skan /* Just in case lang_hooks.post_options ends up calling a debug_hook. 1593161660Skan This can happen with incorrect pre-processed input. */ 1594161660Skan debug_hooks = &do_nothing_debug_hooks; 1595161660Skan 1596132734Skan /* Allow the front end to perform consistency checks and do further 1597132734Skan initialization based on the command line options. This hook also 1598132734Skan sets the original filename if appropriate (e.g. foo.i -> foo.c) 1599132734Skan so we can correctly initialize debug output. */ 1600169699Skan no_backend = lang_hooks.post_options (&main_input_filename); 1601169699Skan#ifndef USE_MAPPED_LOCATION 1602132734Skan input_filename = main_input_filename; 1603169699Skan#endif 160490282Sobrien 1605132734Skan#ifdef OVERRIDE_OPTIONS 1606132734Skan /* Some machines may reject certain combinations of options. */ 1607132734Skan OVERRIDE_OPTIONS; 160890282Sobrien#endif 160990282Sobrien 1610169699Skan if (flag_section_anchors && !target_supports_section_anchors_p ()) 1611169699Skan { 1612169699Skan warning (OPT_fsection_anchors, 1613169699Skan "this target does not support %qs", "-fsection-anchors"); 1614169699Skan flag_section_anchors = 0; 1615169699Skan } 1616169699Skan 1617169699Skan if (flag_short_enums == 2) 1618169699Skan flag_short_enums = targetm.default_short_enums (); 1619169699Skan 1620132734Skan /* Set aux_base_name if not already set. */ 1621132734Skan if (aux_base_name) 1622132734Skan ; 1623132734Skan else if (main_input_filename) 162490282Sobrien { 1625132734Skan char *name = xstrdup (lbasename (main_input_filename)); 162690282Sobrien 1627132734Skan strip_off_ending (name, strlen (name)); 1628132734Skan aux_base_name = name; 162990282Sobrien } 163096289Sobrien else 1631132734Skan aux_base_name = "gccaux"; 163296289Sobrien 163390282Sobrien /* Set up the align_*_log variables, defaulting them to 1 if they 163490282Sobrien were still unset. */ 163590282Sobrien if (align_loops <= 0) align_loops = 1; 163690282Sobrien if (align_loops_max_skip > align_loops || !align_loops) 163790282Sobrien align_loops_max_skip = align_loops - 1; 163890282Sobrien align_loops_log = floor_log2 (align_loops * 2 - 1); 163990282Sobrien if (align_jumps <= 0) align_jumps = 1; 164090282Sobrien if (align_jumps_max_skip > align_jumps || !align_jumps) 164190282Sobrien align_jumps_max_skip = align_jumps - 1; 164290282Sobrien align_jumps_log = floor_log2 (align_jumps * 2 - 1); 164390282Sobrien if (align_labels <= 0) align_labels = 1; 164490282Sobrien align_labels_log = floor_log2 (align_labels * 2 - 1); 164590282Sobrien if (align_labels_max_skip > align_labels || !align_labels) 164690282Sobrien align_labels_max_skip = align_labels - 1; 164790282Sobrien if (align_functions <= 0) align_functions = 1; 164890282Sobrien align_functions_log = floor_log2 (align_functions * 2 - 1); 164990282Sobrien 165090282Sobrien /* Unrolling all loops implies that standard loop unrolling must also 165190282Sobrien be done. */ 165290282Sobrien if (flag_unroll_all_loops) 165390282Sobrien flag_unroll_loops = 1; 1654132734Skan 1655169699Skan /* The loop unrolling code assumes that cse will be run after loop. 1656169699Skan web and rename-registers also help when run after loop unrolling. */ 1657132734Skan 1658169699Skan if (flag_rerun_cse_after_loop == AUTODETECT_VALUE) 1659169699Skan flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops; 1660169699Skan if (flag_web == AUTODETECT_VALUE) 1661169699Skan flag_web = flag_unroll_loops || flag_peel_loops; 1662169699Skan if (flag_rename_registers == AUTODETECT_VALUE) 1663169699Skan flag_rename_registers = flag_unroll_loops || flag_peel_loops; 1664132734Skan 166590282Sobrien if (flag_non_call_exceptions) 166690282Sobrien flag_asynchronous_unwind_tables = 1; 166790282Sobrien if (flag_asynchronous_unwind_tables) 166890282Sobrien flag_unwind_tables = 1; 166990282Sobrien 1670132734Skan /* Disable unit-at-a-time mode for frontends not supporting callgraph 1671132734Skan interface. */ 1672132734Skan if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function) 1673132734Skan flag_unit_at_a_time = 0; 1674132734Skan 1675169699Skan if (!flag_unit_at_a_time) 1676169699Skan flag_section_anchors = 0; 1677169699Skan 1678132734Skan if (flag_value_profile_transformations) 1679132734Skan flag_profile_values = 1; 1680132734Skan 168190282Sobrien /* Warn about options that are not supported on this machine. */ 168290282Sobrien#ifndef INSN_SCHEDULING 168390282Sobrien if (flag_schedule_insns || flag_schedule_insns_after_reload) 1684169699Skan warning (0, "instruction scheduling not supported on this target machine"); 168590282Sobrien#endif 168690282Sobrien#ifndef DELAY_SLOTS 168790282Sobrien if (flag_delayed_branch) 1688169699Skan warning (0, "this target machine does not have delayed branches"); 168990282Sobrien#endif 169090282Sobrien 169190282Sobrien user_label_prefix = USER_LABEL_PREFIX; 169290282Sobrien if (flag_leading_underscore != -1) 169390282Sobrien { 169490282Sobrien /* If the default prefix is more complicated than "" or "_", 169590282Sobrien issue a warning and ignore this option. */ 169690282Sobrien if (user_label_prefix[0] == 0 || 169790282Sobrien (user_label_prefix[0] == '_' && user_label_prefix[1] == 0)) 169890282Sobrien { 169990282Sobrien user_label_prefix = flag_leading_underscore ? "_" : ""; 170090282Sobrien } 170190282Sobrien else 1702169699Skan warning (0, "-f%sleading-underscore not supported on this target machine", 170390282Sobrien flag_leading_underscore ? "" : "no-"); 170490282Sobrien } 170590282Sobrien 170690282Sobrien /* If we are in verbose mode, write out the version and maybe all the 170790282Sobrien option flags in use. */ 170890282Sobrien if (version_flag) 170990282Sobrien { 171090282Sobrien print_version (stderr, ""); 171190282Sobrien if (! quiet_flag) 171290282Sobrien print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n"); 171390282Sobrien } 171490282Sobrien 171590282Sobrien if (flag_syntax_only) 171690282Sobrien { 171790282Sobrien write_symbols = NO_DEBUG; 171890282Sobrien profile_flag = 0; 171990282Sobrien } 172090282Sobrien 1721132734Skan /* A lot of code assumes write_symbols == NO_DEBUG if the debugging 1722132734Skan level is 0. */ 1723132734Skan if (debug_info_level == DINFO_LEVEL_NONE) 1724132734Skan write_symbols = NO_DEBUG; 1725132734Skan 172690282Sobrien /* Now we know write_symbols, set up the debug hooks based on it. 172790282Sobrien By default we do nothing for debug output. */ 1728169699Skan if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG) 1729169699Skan default_debug_hooks = &do_nothing_debug_hooks; 1730169699Skan#if defined(DBX_DEBUGGING_INFO) 1731169699Skan else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG) 1732169699Skan default_debug_hooks = &dbx_debug_hooks; 1733169699Skan#endif 1734169699Skan#if defined(XCOFF_DEBUGGING_INFO) 1735169699Skan else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG) 1736169699Skan default_debug_hooks = &xcoff_debug_hooks; 1737169699Skan#endif 1738169699Skan#ifdef SDB_DEBUGGING_INFO 1739169699Skan else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG) 1740169699Skan default_debug_hooks = &sdb_debug_hooks; 1741169699Skan#endif 1742169699Skan#ifdef DWARF2_DEBUGGING_INFO 1743169699Skan else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG) 1744169699Skan default_debug_hooks = &dwarf2_debug_hooks; 1745169699Skan#endif 1746169699Skan#ifdef VMS_DEBUGGING_INFO 1747169699Skan else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG 1748169699Skan || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG) 1749169699Skan default_debug_hooks = &vmsdbg_debug_hooks; 1750169699Skan#endif 1751169699Skan 1752132734Skan if (write_symbols == NO_DEBUG) 1753161660Skan ; 175490282Sobrien#if defined(DBX_DEBUGGING_INFO) 1755132734Skan else if (write_symbols == DBX_DEBUG) 175690282Sobrien debug_hooks = &dbx_debug_hooks; 175750615Sobrien#endif 175890282Sobrien#if defined(XCOFF_DEBUGGING_INFO) 1759132734Skan else if (write_symbols == XCOFF_DEBUG) 176090282Sobrien debug_hooks = &xcoff_debug_hooks; 176190282Sobrien#endif 176250615Sobrien#ifdef SDB_DEBUGGING_INFO 1763132734Skan else if (write_symbols == SDB_DEBUG) 176490282Sobrien debug_hooks = &sdb_debug_hooks; 176550615Sobrien#endif 176690282Sobrien#ifdef DWARF2_DEBUGGING_INFO 1767132734Skan else if (write_symbols == DWARF2_DEBUG) 176890282Sobrien debug_hooks = &dwarf2_debug_hooks; 176990282Sobrien#endif 177090282Sobrien#ifdef VMS_DEBUGGING_INFO 1771132734Skan else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) 177290282Sobrien debug_hooks = &vmsdbg_debug_hooks; 177390282Sobrien#endif 1774132734Skan else 1775132734Skan error ("target system does not support the \"%s\" debug format", 1776132734Skan debug_type_names[write_symbols]); 177790282Sobrien 1778169699Skan /* Now we know which debug output will be used so we can set 1779169699Skan flag_var_tracking, flag_rename_registers if the user has 1780169699Skan not specified them. */ 1781169699Skan if (debug_info_level < DINFO_LEVEL_NORMAL 1782169699Skan || debug_hooks->var_location == do_nothing_debug_hooks.var_location) 1783169699Skan { 1784169699Skan if (flag_var_tracking == 1) 1785169699Skan { 1786169699Skan if (debug_info_level < DINFO_LEVEL_NORMAL) 1787169699Skan warning (0, "variable tracking requested, but useless unless " 1788169699Skan "producing debug info"); 1789169699Skan else 1790169699Skan warning (0, "variable tracking requested, but not supported " 1791169699Skan "by this debug format"); 1792169699Skan } 1793169699Skan flag_var_tracking = 0; 1794169699Skan } 1795169699Skan 1796169699Skan if (flag_rename_registers == AUTODETECT_VALUE) 1797169699Skan flag_rename_registers = default_debug_hooks->var_location 1798169699Skan != do_nothing_debug_hooks.var_location; 1799169699Skan 1800169699Skan if (flag_var_tracking == AUTODETECT_VALUE) 1801169699Skan flag_var_tracking = optimize >= 1; 1802169699Skan 180390282Sobrien /* If auxiliary info generation is desired, open the output file. 180490282Sobrien This goes in the same directory as the source file--unlike 180590282Sobrien all the other output files. */ 180690282Sobrien if (flag_gen_aux_info) 180790282Sobrien { 180890282Sobrien aux_info_file = fopen (aux_info_file_name, "w"); 180990282Sobrien if (aux_info_file == 0) 1810169699Skan fatal_error ("can%'t open %s: %m", aux_info_file_name); 181190282Sobrien } 181290282Sobrien 181390282Sobrien if (! targetm.have_named_sections) 181490282Sobrien { 181590282Sobrien if (flag_function_sections) 181690282Sobrien { 1817169699Skan warning (0, "-ffunction-sections not supported for this target"); 181890282Sobrien flag_function_sections = 0; 181990282Sobrien } 182090282Sobrien if (flag_data_sections) 182190282Sobrien { 1822169699Skan warning (0, "-fdata-sections not supported for this target"); 182390282Sobrien flag_data_sections = 0; 182490282Sobrien } 182590282Sobrien } 182690282Sobrien 182790282Sobrien if (flag_function_sections && profile_flag) 182890282Sobrien { 1829169699Skan warning (0, "-ffunction-sections disabled; it makes profiling impossible"); 183090282Sobrien flag_function_sections = 0; 183190282Sobrien } 183290282Sobrien 183390282Sobrien#ifndef HAVE_prefetch 183490282Sobrien if (flag_prefetch_loop_arrays) 183590282Sobrien { 1836169699Skan warning (0, "-fprefetch-loop-arrays not supported for this target"); 183790282Sobrien flag_prefetch_loop_arrays = 0; 183890282Sobrien } 183990282Sobrien#else 184090282Sobrien if (flag_prefetch_loop_arrays && !HAVE_prefetch) 184190282Sobrien { 1842169699Skan warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)"); 184390282Sobrien flag_prefetch_loop_arrays = 0; 184490282Sobrien } 184590282Sobrien#endif 184690282Sobrien 184790282Sobrien /* This combination of options isn't handled for i386 targets and doesn't 184890282Sobrien make much sense anyway, so don't allow it. */ 184990282Sobrien if (flag_prefetch_loop_arrays && optimize_size) 185090282Sobrien { 1851169699Skan warning (0, "-fprefetch-loop-arrays is not supported with -Os"); 185290282Sobrien flag_prefetch_loop_arrays = 0; 185390282Sobrien } 185490282Sobrien 185590282Sobrien#ifndef OBJECT_FORMAT_ELF 1856169699Skan#ifndef OBJECT_FORMAT_MACHO 185790282Sobrien if (flag_function_sections && write_symbols != NO_DEBUG) 1858169699Skan warning (0, "-ffunction-sections may affect debugging on some targets"); 185990282Sobrien#endif 1860169699Skan#endif 1861117414Skan 1862169699Skan /* The presence of IEEE signaling NaNs, implies all math can trap. */ 1863169699Skan if (flag_signaling_nans) 1864169699Skan flag_trapping_math = 1; 1865169699Skan 1866169699Skan /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */ 1867169699Skan if (flag_cx_limited_range) 1868169699Skan flag_complex_method = 0; 1869169699Skan 1870169699Skan /* Targets must be able to place spill slots at lower addresses. If the 1871169699Skan target already uses a soft frame pointer, the transition is trivial. */ 1872169699Skan if (!FRAME_GROWS_DOWNWARD && flag_stack_protect) 1873169699Skan { 1874169699Skan warning (0, "-fstack-protector not supported for this target"); 1875169699Skan flag_stack_protect = 0; 1876169699Skan } 1877169699Skan if (!flag_stack_protect) 1878169699Skan warn_stack_protect = 0; 1879169699Skan 1880169699Skan /* ??? Unwind info is not correct around the CFG unless either a frame 1881169699Skan pointer is present or A_O_A is set. Fixing this requires rewriting 1882169699Skan unwind info generation to be aware of the CFG and propagating states 1883169699Skan around edges. */ 1884169699Skan if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS 1885169699Skan && flag_omit_frame_pointer) 1886169699Skan { 1887169699Skan warning (0, "unwind tables currently requires a frame pointer " 1888169699Skan "for correctness"); 1889169699Skan flag_omit_frame_pointer = 0; 1890169699Skan } 189150615Sobrien} 1892132734Skan 1893117414Skan/* Initialize the compiler back end. */ 189490282Sobrienstatic void 1895132734Skanbackend_init (void) 189690282Sobrien{ 189790282Sobrien init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL 189890282Sobrien || debug_info_level == DINFO_LEVEL_VERBOSE 189990282Sobrien#ifdef VMS_DEBUGGING_INFO 1900132734Skan /* Enable line number info for traceback. */ 190190282Sobrien || debug_info_level > DINFO_LEVEL_NONE 190290282Sobrien#endif 1903169699Skan || flag_test_coverage); 1904132734Skan 1905169699Skan init_rtlanal (); 1906132734Skan init_regs (); 1907117414Skan init_fake_stack_mems (); 190890282Sobrien init_alias_once (); 190990282Sobrien init_reload (); 191090282Sobrien init_varasm_once (); 191190282Sobrien 191290282Sobrien /* The following initialization functions need to generate rtl, so 191390282Sobrien provide a dummy function context for them. */ 191490282Sobrien init_dummy_function_start (); 191590282Sobrien init_expmed (); 191690282Sobrien if (flag_caller_saves) 191790282Sobrien init_caller_save (); 191890282Sobrien expand_dummy_function_end (); 191990282Sobrien} 1920132734Skan 1921117414Skan/* Language-dependent initialization. Returns nonzero on success. */ 192290282Sobrienstatic int 1923132734Skanlang_dependent_init (const char *name) 192450615Sobrien{ 1925169699Skan location_t save_loc = input_location; 192690282Sobrien if (dump_base_name == 0) 1927169699Skan dump_base_name = name && name[0] ? name : "gccdump"; 1928132734Skan 1929132734Skan /* Other front-end initialization. */ 1930169699Skan#ifdef USE_MAPPED_LOCATION 1931169699Skan input_location = BUILTINS_LOCATION; 1932169699Skan#else 1933169699Skan input_filename = "<built-in>"; 1934169699Skan input_line = 0; 1935169699Skan#endif 1936169699Skan if (lang_hooks.init () == 0) 193790282Sobrien return 0; 1938169699Skan input_location = save_loc; 193990282Sobrien 194090282Sobrien init_asm_output (name); 194190282Sobrien 194290282Sobrien /* These create various _DECL nodes, so need to be called after the 194390282Sobrien front end is initialized. */ 194490282Sobrien init_eh (); 194590282Sobrien init_optabs (); 194690282Sobrien 1947117414Skan /* The following initialization functions need to generate rtl, so 1948117414Skan provide a dummy function context for them. */ 1949117414Skan init_dummy_function_start (); 1950117414Skan init_expr_once (); 1951117414Skan expand_dummy_function_end (); 1952117414Skan 195390282Sobrien /* If dbx symbol table desired, initialize writing it and output the 195490282Sobrien predefined types. */ 195590282Sobrien timevar_push (TV_SYMOUT); 195690282Sobrien 1957169699Skan#if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO 195890282Sobrien if (dwarf2out_do_frame ()) 195990282Sobrien dwarf2out_frame_init (); 196090282Sobrien#endif 196190282Sobrien 196290282Sobrien /* Now we have the correct original filename, we can initialize 196390282Sobrien debug output. */ 196490282Sobrien (*debug_hooks->init) (name); 196590282Sobrien 196690282Sobrien timevar_pop (TV_SYMOUT); 196790282Sobrien 196890282Sobrien return 1; 196950615Sobrien} 1970132734Skan 197190282Sobrien/* Clean up: close opened files, etc. */ 197250615Sobrien 197390282Sobrienstatic void 1974132734Skanfinalize (void) 197590282Sobrien{ 197690282Sobrien /* Close the dump files. */ 197790282Sobrien if (flag_gen_aux_info) 197890282Sobrien { 197990282Sobrien fclose (aux_info_file); 198090282Sobrien if (errorcount) 198190282Sobrien unlink (aux_info_file_name); 198290282Sobrien } 198350615Sobrien 198490282Sobrien /* Close non-debugging input and output files. Take special care to note 198590282Sobrien whether fclose returns an error, since the pages might still be on the 198690282Sobrien buffer chain while the file is open. */ 198790282Sobrien 198890282Sobrien if (asm_out_file) 198990282Sobrien { 199090282Sobrien if (ferror (asm_out_file) != 0) 1991132734Skan fatal_error ("error writing to %s: %m", asm_file_name); 199290282Sobrien if (fclose (asm_out_file) != 0) 1993132734Skan fatal_error ("error closing %s: %m", asm_file_name); 199490282Sobrien } 199590282Sobrien 1996169699Skan finish_optimization_passes (); 199790282Sobrien 199890282Sobrien if (mem_report) 199990282Sobrien { 200090282Sobrien ggc_print_statistics (); 200190282Sobrien stringpool_statistics (); 200290282Sobrien dump_tree_statistics (); 2003132734Skan dump_rtx_statistics (); 2004132734Skan dump_varray_statistics (); 2005132734Skan dump_alloc_pool_statistics (); 2006169699Skan dump_ggc_loc_statistics (); 200790282Sobrien } 200890282Sobrien 200990282Sobrien /* Free up memory for the benefit of leak detectors. */ 201090282Sobrien free_reg_info (); 201190282Sobrien 201290282Sobrien /* Language-specific end of compilation actions. */ 2013169699Skan lang_hooks.finish (); 201490282Sobrien} 2015132734Skan 201690282Sobrien/* Initialize the compiler, and compile the input file. */ 201790282Sobrienstatic void 2018132734Skando_compile (void) 201950615Sobrien{ 2020132734Skan /* Initialize timing first. The C front ends read the main file in 2021132734Skan the post_options hook, and C++ does file timings. */ 2022132734Skan if (time_report || !quiet_flag || flag_detailed_statistics) 2023132734Skan timevar_init (); 2024132734Skan timevar_start (TV_TOTAL); 2025117414Skan 202690282Sobrien process_options (); 202790282Sobrien 2028132734Skan /* Don't do any more if an error has already occurred. */ 2029132734Skan if (!errorcount) 2030117414Skan { 2031146908Skan /* This must be run always, because it is needed to compute the FP 2032146908Skan predefined macros, such as __LDBL_MAX__, for targets using non 2033146908Skan default FP formats. */ 2034146908Skan init_adjust_machine_modes (); 2035146908Skan 2036132734Skan /* Set up the back-end if requested. */ 2037132734Skan if (!no_backend) 2038132734Skan backend_init (); 2039117414Skan 2040132734Skan /* Language-dependent initialization. Returns true on success. */ 2041132734Skan if (lang_dependent_init (main_input_filename)) 2042169699Skan compile_file (); 204390282Sobrien 2044132734Skan finalize (); 2045132734Skan } 204690282Sobrien 204790282Sobrien /* Stop timing and print the times. */ 204890282Sobrien timevar_stop (TV_TOTAL); 204990282Sobrien timevar_print (stderr); 205050615Sobrien} 2051132734Skan 205290282Sobrien/* Entry point of cc1, cc1plus, jc1, f771, etc. 205390282Sobrien Exit code is FATAL_EXIT_CODE if can't open files or if there were 205490282Sobrien any errors, or SUCCESS_EXIT_CODE if compilation succeeded. 205590282Sobrien 205690282Sobrien It is not safe to call this function more than once. */ 205790282Sobrien 205890282Sobrienint 2059132734Skantoplev_main (unsigned int argc, const char **argv) 206090282Sobrien{ 2061132734Skan save_argv = argv; 2062132734Skan 206390282Sobrien /* Initialization of GCC's environment, and diagnostics. */ 2064117414Skan general_init (argv[0]); 206590282Sobrien 206690282Sobrien /* Parse the options and do minimal processing; basically just 206790282Sobrien enough to default flags appropriately. */ 2068132734Skan decode_options (argc, argv); 206990282Sobrien 2070132734Skan randomize (); 2071132734Skan 207290282Sobrien /* Exit early if we can (e.g. -help). */ 2073117414Skan if (!exit_after_options) 207490282Sobrien do_compile (); 207590282Sobrien 207690282Sobrien if (errorcount || sorrycount) 207790282Sobrien return (FATAL_EXIT_CODE); 207890282Sobrien 207990282Sobrien return (SUCCESS_EXIT_CODE); 208090282Sobrien} 2081