📄 toplev.c
字号:
/* Top level of GNU C compiler Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 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>#ifndef _WIN32#ifdef USG#undef FLOAT#include <sys/param.h>/* This is for hpux. It is a real screw. They should change hpux. */#undef FLOAT#include <sys/times.h>#include <time.h> /* Correct for hpux at least. Is it good on other USG? */#undef FFS /* Some systems define this in param.h. */#else#ifndef VMS#include <sys/time.h>#include <sys/resource.h>#endif#endif#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"#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#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 ();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 void print_switch_values ();static char *decl_name ();#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;/* Stream for reading from the input file. */FILE *finput;/* 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 cse_dump = 0;int loop_dump = 0;int cse2_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. */char *(*decl_printable_name) ();/* 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;/* Pointer to function for interim exception handling implementation. This interface will change, and it is only here until a better interface replaces it. */void (*interim_eh_hook) PROTO((tree));/* 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 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 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. */int flag_no_inline;/* Nonzero means we should be saving declaration info into a .X file. */int flag_gen_aux_info = 0;/* Specified name of aux-info file. */static char *aux_info_file_name;/* Nonzero means make the text shared if supported. */int flag_shared_data;/* Nonzero means schedule into delayed branch slots if supported. */int flag_delayed_branch;/* Nonzero means to run cleanups after CALL_EXPRs. */int flag_short_temps;/* Nonzero if we are compiling pure (sharable) code. Value is 1 if we are doing reasonable (i.e. simple offset into offset table) pic. Value is 2 if we can only perform register offsets. */int flag_pic;/* Nonzero means place uninitialized global data in the bss section. */int flag_no_common;/* Nonzero means pretend it is OK to examine bits of target floats, even if that isn't true. The resulting code will have incorrect constants, but the same series of instructions that the native compiler would make. */int flag_pretend_float;/* Nonzero means change certain warnings into errors. Usually these are warnings about failure to conform to some standard. */int flag_pedantic_errors = 0;/* flag_schedule_insns means schedule insns within basic blocks (before local_alloc). flag_schedule_insns_after_reload means schedule insns after global_alloc. */int flag_schedule_insns = 0;int flag_schedule_insns_after_reload = 0;/* -finhibit-size-directive inhibits output of .size for ELF. This is used only for compiling crtstuff.c, and it may be extended to other effects needed for crtstuff.c on other systems. */int flag_inhibit_size_directive = 0;/* -fverbose-asm causes extra commentary information to be produced in the generated assembly code (to make it more readable). This option is generally only of use to those who actually need to read the generated assembly code (perhaps while debugging the compiler itself). */int flag_verbose_asm = 0;/* -fgnu-linker specifies use of the GNU linker for initializations. (Or, more generally, a linker that handles initializations.) -fno-gnu-linker says that collect2 will be used. */#ifdef USE_COLLECT2int flag_gnu_linker = 0;#elseint flag_gnu_linker = 1;#endif/* Tag all structures with __attribute__(packed) */int flag_pack_struct = 0;/* Table of language-independent -f options.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -