toplev.c

来自「GCC编译器源代码」· C语言 代码 · 共 2,599 行 · 第 1/5 页

C
2,599
字号
/* Top level of GNU C compiler   Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.  *//* This is the top level of cc1/c++.   It parses command args, opens files, invokes the various passes   in the proper order, and counts the time used by each.   Error messages and low-level interface to malloc also handled here.  */#include "config.h"#ifdef __STDC__#include <stdarg.h>#else#include <varargs.h>#endif#include <stdio.h>#include <signal.h>#include <setjmp.h>#include <sys/types.h>#include <ctype.h>#include <sys/stat.h>#undef FLOAT#ifdef HAVE_SYS_PARAM_H#include <sys/param.h>#endif#undef FLOAT /* This is for hpux. They should change hpux.  */#undef FFS  /* Some systems define this in param.h.  */#ifdef TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H# include <sys/time.h># else#  include <time.h>#endif#endif#ifdef HAVE_SYS_RESOURCE_H# include <sys/resource.h>#endif#ifdef HAVE_SYS_TIMES_H# include <sys/times.h>#endif#include "input.h"#include "tree.h"#include "rtl.h"#include "flags.h"#include "insn-attr.h"#include "defaults.h"#include "output.h"#include "bytecode.h"#include "bc-emit.h"#include "except.h"#ifdef XCOFF_DEBUGGING_INFO#include "xcoffout.h"#endif#ifdef VMS/* The extra parameters substantially improve the I/O performance.  */static FILE *vms_fopen (fname, type)     char * fname;     char * type;{  /* The <stdio.h> in the gcc-vms-1.42 distribution prototypes fopen with two     fixed arguments, which matches ANSI's specification but not VAXCRTL's     pre-ANSI implementation.  This hack circumvents the mismatch problem.  */  FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen;  if (*type == 'w')    return (*vmslib_fopen) (fname, type, "mbc=32",			    "deq=64", "fop=tef", "shr=nil");  else    return (*vmslib_fopen) (fname, type, "mbc=32");}#define fopen vms_fopen#endif	/* VMS */#ifndef DEFAULT_GDB_EXTENSIONS#define DEFAULT_GDB_EXTENSIONS 1#endif/* If more than one debugging type is supported, you must define   PREFERRED_DEBUGGING_TYPE to choose a format in a system-dependent way.    This is one long line cause VAXC can't handle a \-newline.  */#if 1 < (defined (DBX_DEBUGGING_INFO) + defined (SDB_DEBUGGING_INFO) + defined (DWARF_DEBUGGING_INFO) + defined (DWARF2_DEBUGGING_INFO) + defined (XCOFF_DEBUGGING_INFO))#ifndef PREFERRED_DEBUGGING_TYPEYou Lose!  You must define PREFERRED_DEBUGGING_TYPE!#endif /* no PREFERRED_DEBUGGING_TYPE */#else /* Only one debugging format supported.  Define PREFERRED_DEBUGGING_TYPE	 so the following code needn't care.  */#ifdef DBX_DEBUGGING_INFO#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG#endif#ifdef SDB_DEBUGGING_INFO#define PREFERRED_DEBUGGING_TYPE SDB_DEBUG#endif#ifdef DWARF_DEBUGGING_INFO#define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG#endif#ifdef DWARF2_DEBUGGING_INFO#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG#endif#ifdef XCOFF_DEBUGGING_INFO#define PREFERRED_DEBUGGING_TYPE XCOFF_DEBUG#endif#endif /* More than one debugger format enabled.  *//* If still not defined, must have been because no debugging formats   are supported.  */#ifndef PREFERRED_DEBUGGING_TYPE#define PREFERRED_DEBUGGING_TYPE NO_DEBUG#endifextern int rtx_equal_function_value_matters;#if ! (defined (VMS) || defined (OS2))extern char **environ;#endifextern char *version_string, *language_string;/* Carry information from ASM_DECLARE_OBJECT_NAME   to ASM_FINISH_DECLARE_OBJECT.  */extern int size_directive_output;extern tree last_assemble_variable_decl;extern void init_lex ();extern void init_decl_processing ();extern void init_obstacks ();extern void init_tree_codes ();extern void init_rtl ();extern void init_regs ();extern void init_optabs ();extern void init_stmt ();extern void init_reg_sets ();extern void dump_flow_info ();extern void dump_sched_info ();extern void dump_local_alloc ();extern void regset_release_memory ();void rest_of_decl_compilation ();void error_with_file_and_line PVPROTO((char *file, int line, char *s, ...));void error_with_decl PVPROTO((tree decl, char *s, ...));void error_for_asm PVPROTO((rtx insn, char *s, ...));void error PVPROTO((char *s, ...));void fatal PVPROTO((char *s, ...));void warning_with_file_and_line PVPROTO((char *file, int line, char *s, ...));void warning_with_decl PVPROTO((tree decl, char *s, ...));void warning_for_asm PVPROTO((rtx insn, char *s, ...));void warning PVPROTO((char *s, ...));void pedwarn PVPROTO((char *s, ...));void pedwarn_with_decl PVPROTO((tree decl, char *s, ...));void pedwarn_with_file_and_line PVPROTO((char *file, int line, char *s, ...));void sorry PVPROTO((char *s, ...));void really_sorry PVPROTO((char *s, ...));void fancy_abort ();#ifndef abortvoid abort ();#endifvoid set_target_switch ();static char *decl_name ();void print_version ();int print_single_switch ();void print_switch_values ();/* Length of line when printing switch values.  */#define MAX_LINE 75#ifdef __alphaextern char *sbrk ();#endif/* Name of program invoked, sans directories.  */char *progname;/* Copy of arguments to main.  */int save_argc;char **save_argv;/* Name of current original source file (what was input to cpp).   This comes from each #-command in the actual input.  */char *input_filename;/* Name of top-level original source file (what was input to cpp).   This comes from the #-command at the beginning of the actual input.   If there isn't any there, then this is the cc1 input file name.  */char *main_input_filename;#if !USE_CPPLIB/* Stream for reading from the input file.  */FILE *finput;#endif/* Current line number in real source file.  */int lineno;/* Stack of currently pending input files.  */struct file_stack *input_file_stack;/* Incremented on each change to input_file_stack.  */int input_file_stack_tick;/* FUNCTION_DECL for function now being parsed or compiled.  */extern tree current_function_decl;/* Name to use as base of names for dump output files.  */char *dump_base_name;/* Bit flags that specify the machine subtype we are compiling for.   Bits are tested using macros TARGET_... defined in the tm.h file   and set by `-m...' switches.  Must be defined in rtlanal.c.  */extern int target_flags;/* Flags saying which kinds of debugging dump have been requested.  */int rtl_dump = 0;int rtl_dump_and_exit = 0;int jump_opt_dump = 0;int addressof_dump = 0;int cse_dump = 0;int loop_dump = 0;int cse2_dump = 0;int branch_prob_dump = 0;int flow_dump = 0;int combine_dump = 0;int sched_dump = 0;int local_reg_dump = 0;int global_reg_dump = 0;int sched2_dump = 0;int jump2_opt_dump = 0;int dbr_sched_dump = 0;int flag_print_asm_name = 0;int stack_reg_dump = 0;/* Name for output file of assembly code, specified with -o.  */char *asm_file_name;/* Value of the -G xx switch, and whether it was passed or not.  */int g_switch_value;int g_switch_set;/* Type(s) of debugging information we are producing (if any).   See flags.h for the definitions of the different possible   types of debugging information.  */enum debug_info_type write_symbols = NO_DEBUG;/* Level of debugging information we are producing.  See flags.h   for the definitions of the different possible levels.  */enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;/* Nonzero means use GNU-only extensions in the generated symbolic   debugging information.  *//* Currently, this only has an effect when write_symbols is set to   DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG.  */int use_gnu_debug_info_extensions = 0;/* Nonzero means do optimizations.  -O.   Particular numeric values stand for particular amounts of optimization;   thus, -O2 stores 2 here.  However, the optimizations beyond the basic   ones are not controlled directly by this variable.  Instead, they are   controlled by individual `flag_...' variables that are defaulted   based on this variable.  */int optimize = 0;/* Number of error messages and warning messages so far.  */int errorcount = 0;int warningcount = 0;int sorrycount = 0;/* Flag to output bytecode instead of native assembler */int output_bytecode = 0;/* Pointer to function to compute the name to use to print a declaration.   DECL is the declaration in question.   VERBOSITY determines what information will be printed:     0: DECL_NAME, demangled as necessary.     1: and scope information.     2: and any other information that might be interesting, such as function        parameter types in C++.  */char *(*decl_printable_name) (/* tree decl, int verbosity */);/* Pointer to function to compute rtl for a language-specific tree code.  */struct rtx_def *(*lang_expand_expr) ();/* Pointer to function to finish handling an incomplete decl at the   end of compilation.  */void (*incomplete_decl_finalize_hook) () = 0;/* Highest label number used at the end of reload.  */int max_label_num_after_reload;/* Nonzero if generating code to do profiling.  */int profile_flag = 0;/* Nonzero if generating code to do profiling on a line-by-line basis.  */int profile_block_flag;/* Nonzero if generating code to profile program flow graph arcs.  */int profile_arc_flag = 0;/* Nonzero if generating info for gcov to calculate line test coverage.  */int flag_test_coverage = 0;/* Nonzero indicates that branch taken probabilities should be calculated.  */int flag_branch_probabilities = 0;/* Nonzero for -pedantic switch: warn about anything   that standard spec forbids.  */int pedantic = 0;/* Temporarily suppress certain warnings.   This is set while reading code from a system header file.  */int in_system_header = 0;/* Nonzero means do stupid register allocation.   Currently, this is 1 if `optimize' is 0.  */int obey_regdecls = 0;/* Don't print functions as they are compiled and don't print   times taken by the various passes.  -quiet.  */int quiet_flag = 0;/* -f flags.  *//* Nonzero means `char' should be signed.  */int flag_signed_char;/* Nonzero means give an enum type only as many bytes as it needs.  */int flag_short_enums;/* Nonzero for -fcaller-saves: allocate values in regs that need to   be saved across function calls, if that produces overall better code.   Optional now, so people can test it.  */#ifdef DEFAULT_CALLER_SAVESint flag_caller_saves = 1;#elseint flag_caller_saves = 0;#endif/* Nonzero if structures and unions should be returned in memory.   This should only be defined if compatibility with another compiler or   with an ABI is needed, because it results in slower code.  */#ifndef DEFAULT_PCC_STRUCT_RETURN#define DEFAULT_PCC_STRUCT_RETURN 1#endif/* Nonzero for -fpcc-struct-return: return values the same way PCC does.  */int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;/* Nonzero for -fforce-mem: load memory value into a register   before arithmetic on it.  This makes better cse but slower compilation.  */int flag_force_mem = 0;/* Nonzero for -fforce-addr: load memory address into a register before   reference to memory.  This makes better cse but slower compilation.  */int flag_force_addr = 0;/* Nonzero for -fdefer-pop: don't pop args after each function call;   instead save them up to pop many calls' args with one insns.  */int flag_defer_pop = 0;/* Nonzero for -ffloat-store: don't allocate floats and doubles   in extended-precision registers.  */int flag_float_store = 0;/* Nonzero for -fcse-follow-jumps:   have cse follow jumps to do a more extensive job.  */int flag_cse_follow_jumps;/* Nonzero for -fcse-skip-blocks:   have cse follow a branch around a block.  */int flag_cse_skip_blocks;/* Nonzero for -fexpensive-optimizations:   perform miscellaneous relatively-expensive optimizations.  */int flag_expensive_optimizations;/* Nonzero for -fthread-jumps:   have jump optimize output of loop.  */int flag_thread_jumps;/* Nonzero enables strength-reduction in loop.c.  */int flag_strength_reduce = 0;/* Nonzero enables loop unrolling in unroll.c.  Only loops for which the   number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,   UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are   unrolled.  */int flag_unroll_loops;/* Nonzero enables loop unrolling in unroll.c.  All loops are unrolled.   This is generally not a win.  */int flag_unroll_all_loops;/* Nonzero for -fwritable-strings:   store string constants in data segment and don't uniquize them.  */int flag_writable_strings = 0;/* Nonzero means don't put addresses of constant functions in registers.   Used for compiling the Unix kernel, where strange substitutions are   done on the assembly output.  */int flag_no_function_cse = 0;/* Nonzero for -fomit-frame-pointer:   don't make a frame pointer in simple functions that don't require one.  */int flag_omit_frame_pointer = 0;/* Nonzero means place each function into its own section on those platforms   which support arbitrary section names and unlimited numbers of sections.  */int flag_function_sections = 0;/* Nonzero to inhibit use of define_optimization peephole opts.  */int flag_no_peephole = 0;/* Nonzero allows GCC to violate some IEEE or ANSI rules regarding math   operations in the interest of optimization.  For example it allows   GCC to assume arguments to sqrt are nonnegative numbers, allowing   faster code for sqrt to be generated.  */int flag_fast_math = 0;/* Nonzero means all references through pointers are volatile.  */int flag_volatile;/* Nonzero means treat all global and extern variables as global.  */int flag_volatile_global;/* Nonzero means just do syntax checking; don't output anything.  */int flag_syntax_only = 0;/* Nonzero means to rerun cse after loop optimization.  This increases   compilation time about 20% and picks up a few more common expressions.  */static int flag_rerun_cse_after_loop;/* Nonzero for -finline-functions: ok to inline functions that look like   good inline candidates.  */int flag_inline_functions;/* Nonzero for -fkeep-inline-functions: even if we make a function   go inline everywhere, keep its definition around for debugging   purposes.  */int flag_keep_inline_functions;/* Nonzero means that functions will not be inlined.  */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?