GCC Middle and Back End API Reference
toplev.c File Reference

Functions

static void general_init (const char *)
static void do_compile (void)
static void process_options (void)
static void backend_init (void)
static int lang_dependent_init (const char *)
static void init_asm_output (const char *)
static void finalize (bool)
static void crash_signal (int)
const char * get_src_pwd ()
void announce_function ()
static void init_local_tick ()
static void init_random_seed ()
HOST_WIDE_INT get_random_seed ()
const char * set_random_seed ()
static void crash_signal ()
void wrapup_global_declaration_1 ()
bool wrapup_global_declaration_2 ()
bool wrapup_global_declarations ()
void check_global_declaration_1 ()
void check_global_declarations ()
void emit_debug_global_declarations ()
static void compile_file ()
void print_version ()
static int print_to_asm_out_file ()
static int print_to_stderr ()
static int print_single_switch (print_switch_fn_type print_fn, int pos, print_switch_type type, const char *text)
static void print_switch_values ()
static void init_asm_output ()
static void * realloc_for_line_map ()
static void * alloc_for_identifier_to_locale ()
void output_stack_usage ()
static FILE * open_auxiliary_file ()
static void general_init ()
static bool target_supports_section_anchors_p ()
static void init_alignments ()
static void backend_init_target ()
static void init_excess_precision ()
static void lang_dependent_init_target ()
static int lang_dependent_init ()
void target_reinit ()
void dump_memory_report ()
static void finalize ()
int toplev_main ()

Function Documentation

static void* alloc_for_identifier_to_locale ( )
static
   A helper function: used as the allocator function for
   identifier_to_locale.  

References warning().

void announce_function ( )
   Called when the start of a function definition is parsed,
   this function prints on stderr the name of the function.  
static void backend_init ( )
static
   Initialize the compiler back end.  This function is called only once,
   when starting the compiler.  
     Initialize the target-specific back end pieces.  
static void backend_init_target ( )
static
   This function can be called multiple times to reinitialize the compiler
   back end when register classes or instruction sets have changed,
   before each function.  
     Initialize alignment variables.  
     This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
     to initialize reg_raw_mode[].  
     This invokes target hooks to set fixed_reg[] etc, which is
     mode-dependent.  
     This depends on stack_pointer_rtx.  
     Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
     mode-dependent.  
     Depends on HARD_FRAME_POINTER_REGNUM.  
     The following initialization functions need to generate rtl, so
     provide a dummy function context for them.  
     rtx_cost is mode-dependent, so cached values need to be recomputed
     on a mode change.  
     We may need to recompute regno_save_code[] and regno_restore_code[]
     after a mode change as well.  

References init_asm_output(), and open_auxiliary_file().

void check_global_declaration_1 ( )
   A subroutine of check_global_declarations.  Issue appropriate warnings
   for the global declaration DECL.  
     Warn about any function declared static but not defined.  We don't
     warn about variables, because many programs have static variables
     that exist only to get some text into the object file.  
         This symbol is effectively an "extern" declaration now.  
     Warn about static fns or vars defined but not used.  
          We don't warn about "static const" variables because the
          "rcs_id" idiom uses that construction.  
         The TREE_USED bit for file-scope decls is kept in the identifier,
         to handle multiple external decls in different scopes.  
         A volatile variable might be used in some non-obvious way.  
         Global register variables must be declared to reserve them.  
         Otherwise, ask the language.  
void check_global_declarations ( )
   Issue appropriate warnings for the global declarations in V (of
   which there are LEN).  
static void compile_file ( )
static
   Compile an entire translation unit.  Write a file of assembly
   output and various debugging dumps.  
     Call the parser, which parses the entire file (calling
     rest_of_compilation for each function).  
     Compilation is now finished except for writing
     what's left of the symbol table output.  
     This must also call finalize_compilation_unit.  
     Compilation unit is finalized.  When producing non-fat LTO object, we are
     basically finished.  
         File-scope initialization for AddressSanitizer.  
         Write out any pending weak symbol declarations.  
         This must be at the end before unwind and debug info.
         Some target ports emit PIC setup thunks here.  
         Do dbx symbols.  
         Output some stuff at end of file if nec.  
         Flush any pending external directives.  
     Emit LTO marker if LTO info has been previously emitted.  This is
     used by collect2 to determine whether an object file contains IL.
     We used to emit an undefined reference here, but this produces
     link errors if an object file with IL is stored into a shared
     library without invoking lto1.  
         Let linker plugin know that this is a slim object and must be LTOed
         even when user did not ask for it.  
     Attach a special .ident directive to the end of the file to identify
     the version of GCC which compiled this code.  The format of the .ident
     string is patterned after the ones produced by native SVR4 compilers.  
     Invoke registered plugin callbacks.  
     This must be at the end.  Some target ports emit end of file directives
     into the assembly file here, and hence we can not output anything to the
     assembly file after this point.  
static void crash_signal ( int  )
static
                       @verbatim 

Initialize src_pwd with the given string, and return true. If it was already initialized, return false. As a special case, it may be called with a NULL argument to test whether src_pwd has NOT been initialized yet.

References asm_out_file, current_function_decl, debug_hooks, default_target_flag_state, local_tick, save_decoded_options, save_decoded_options_count, stack_limit_rtx, this_target_flag_state, user_defined_section_attribute, and user_label_prefix.

static void crash_signal ( )
static
   Handler for fatal signals, such as SIGSEGV.  These are transformed
   into ICE messages, which is much more user friendly.  In case the
   error printer crashes, reset the signal to prevent infinite recursion.  
     If we crashed while processing an ASM statement, then be a little more
     graceful.  It's most likely the user's fault.  
static void do_compile ( )
static
   Initialize the compiler, and compile the input file.  
     Initialize timing first.  The C front ends read the main file in
     the post_options hook, and C++ does file timings.  
     Don't do any more if an error has already occurred.  
         This must be run always, because it is needed to compute the FP
         predefined macros, such as __LDBL_MAX__, for targets using non
         default FP formats.  
         Set up the back-end if requested.  
         Language-dependent initialization.  Returns true on success.  
             Initialize yet another pass.  
     Stop timing and print the times.  
void dump_memory_report ( )
void emit_debug_global_declarations ( )
   Emit debugging information for all global declarations in VEC.  
     Avoid confusing the debug information machinery when there are errors.  

References asan_finish_file(), finish_tm_clone_pairs(), output_object_blocks(), output_shared_constant_pool(), SANITIZE_ADDRESS, SANITIZE_THREAD, targetm, tsan_finish_file(), and weak_finish().

static void finalize ( bool  )
static
static void finalize ( )
static
   Clean up: close opened files, etc.  
     Close the dump files.  
     Close non-debugging input and output files.  Take special care to note
     whether fclose returns an error, since the pages might still be on the
     buffer chain while the file is open.  
     Language-specific end of compilation actions.  
static void general_init ( const char *  )
static
@verbatim 

Top level of GCC compilers (cc1, cc1plus, etc.) Copyright (C) 1987-2013 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.

   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.  
static void general_init ( )
static
   Initialization of the front end environment, before command line
   options are parsed.  Signal handlers, internationalization etc.
   ARGV0 is main's argv[0].  
     Unlock the stdio streams.  
     Initialize the diagnostics reporting machinery, so option parsing
     can give warnings and errors.  
     Set a default printer.  Language specific initializations will
     override it later.  
     FIXME: This should probably be moved to C-family
     language-specific initializations.  
     By default print macro expansion contexts in the diagnostic
     finalizer -- for tokens resulting from macro expansion.  
     Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  
     Other host-specific signal setup.  
     Initialize the garbage-collector, string pools and tree type hash
     table.  
     Initialize register usage now so switches may override.  
     Register the language-independent parameters.  
     This must be done after global_init_params but before argument
     processing.  
     Create the singleton holder for global state.
     Doing so also creates the pass manager and with it the passes.  
HOST_WIDE_INT get_random_seed ( )
   Obtain the random_seed.  Unless NOINIT, initialize it if
   it's not provided in the command line.  

References output_operand_lossage().

const char* get_src_pwd ( void  )
   Return the directory from which the translation unit was initiated,
   in case set_src_pwd() was not called before to assign it a
   different value.  

References global_dc.

static void init_alignments ( )
static
   Default the align_* variables to 1 if they're still unset, and
   set up the align_*_log variables.  
static void init_asm_output ( const char *  )
static

Referenced by backend_init_target().

static void init_asm_output ( )
static
   Open assembly code output file.  Do this even if -fsyntax-only is
   on, because then the driver will have provided the name of a
   temporary file or bit bucket for us.  NAME is the file specified on
   the command line, possibly NULL.  
                 Let the target know that we are about to start recording.  
                 Now record the switches.  
                 Let the target know that the recording is over.  
             Print the list of switches in effect
             into the assembler file as comments.  
static void init_excess_precision ( )
static
   Initialize excess precision settings.  
     Adjust excess precision handling based on the target options.  If
     the front end cannot handle it, flag_excess_precision_cmdline
     will already have been set accordingly in the post_options
     hook.  
             Either the target acts unpredictably (-1) or has all the
             operations required not to have excess precision (0).  
             In these cases, predictable excess precision makes
             sense.  
             Any other implementation-defined FLT_EVAL_METHOD values
             require the compiler to handle the associated excess
             precision rules in excess_precision_type.  
static void init_local_tick ( )
static
   Initialize local_tick with a random number or -1 if
   flag_random_seed is set.  
         Try urandom first. Time of day is too likely to collide. 
         In case of any error we just use the local tick. 
         Now get the tick anyways  
static void init_random_seed ( )
static
   Set up a default flag_random_seed and local_tick, unless the user
   already specified one.  Must be called after init_local_tick.  
         When the driver passed in a hex number don't crc it again 
static int lang_dependent_init ( const char *  )
static
static int lang_dependent_init ( )
static
   Language-dependent initialization.  Returns nonzero on success.  
     Other front-end initialization.  
         If stack usage information is desired, open the output file.  
     This creates various _DECL nodes, so needs to be called after the
     front end is initialized.  
     Do the target-specific parts of the initialization.  
         If dbx symbol table desired, initialize writing it and output the
         predefined types.  
         Now we have the correct original filename, we can initialize
         debug output.  
static void lang_dependent_init_target ( )
static
   Initialize things that are both lang-dependent and target-dependent.
   This function can be called more than once if target parameters change.  
     This determines excess precision settings.  
     This creates various _DECL nodes, so needs to be called after the
     front end is initialized.  It also depends on the HAVE_xxx macros
     generated from the target machine description.  
     The following initialization functions need to generate rtl, so
     provide a dummy function context for them.  
     Do the target-specific parts of expr initialization.  
     Although the actions of these functions are language-independent,
     they use optabs, so we cannot call them from backend_init.  

References gcc::pass_manager::finish_optimization_passes(), g, gcc::context::get_passes(), ira_finish_once(), and statistics_fini().

static FILE* open_auxiliary_file ( )
static
   Open an auxiliary output file.  

Referenced by backend_init_target().

void output_stack_usage ( void  )
   Output stack usage information.  
     Add the maximum amount of space pushed onto the stack.  
     Now on to the tricky part: dynamic stack allocation.  
         Add the size even in the unbounded case, this can't hurt.  
         We don't want to print the full qualified name because it can be long,
         so we strip the scope prefix, but we may need to deal with the suffix
         created by the compiler.  
static int print_single_switch ( print_switch_fn_type  print_fn,
int  pos,
print_switch_type  type,
const char *  text 
)
static
   Print an option value and return the adjusted position in the line.
   ??? print_fn doesn't handle errors, eg disk full; presumably other
   code will catch a disk full though.  
     The ultrix fprintf returns 0 on success, so compute the result
     we want here since we need it for the following test.  The +1
     is for the separator character that will probably be emitted.  
static void print_switch_values ( )
static
   Print active target switches using PRINT_FN.
   POS is the current cursor position and MAX is the size of a "line".
   Each line begins with INDENT and ends with TERM.
   Each switch is separated from the next by SEP.  
     Fill in the -frandom-seed option, if the user didn't pass it, so
     that it can be printed below.  This helps reproducibility.  
     Print the options as passed.  
             Ignore these.  
     Print the -f and -m options that have been enabled.
     We don't handle language specific options but printing argv
     should suffice.  
static int print_to_asm_out_file ( )
static
         Drop through.  
         No need to return the length here as
         print_single_switch has already done it.  

References len, strlen(), SWITCH_TYPE_LINE_END, and SWITCH_TYPE_LINE_START.

static int print_to_stderr ( )
static
         Drop through.  
         No need to return the length here as
         print_single_switch has already done it.  
void print_version ( void  )
   Print version information to FILE.
   Each line begins with INDENT (for the case where FILE is the
   assembler output file).  
     We need to stringify the GMP macro values.  Ugh, gmp_version has
     two string formats, "i.j.k" and "i.j" when k is zero.  As of
     gmp-4.3.0, GMP always uses the 3 number format.  

References strlen(), SWITCH_TYPE_DESCRIPTIVE, SWITCH_TYPE_ENABLED, SWITCH_TYPE_LINE_END, SWITCH_TYPE_LINE_START, and SWITCH_TYPE_PASSED.

static void process_options ( )
static
   Process the options that have been parsed.  
     Just in case lang_hooks.post_options ends up calling a debug_hook.
     This can happen with incorrect pre-processed input. 
     Default to -fdiagnostics-color=auto if GCC_COLORS is in the environment,
     otherwise default to -fdiagnostics-color=never.  
     Allow the front end to perform consistency checks and do further
     initialization based on the command line options.  This hook also
     sets the original filename if appropriate (e.g. foo.i -> foo.c)
     so we can correctly initialize debug output.  
     Some machines may reject certain combinations of options.  
     Avoid any informative notes in the second run of -fcompare-debug.  
     Set aux_base_name if not already set.  
     One region RA really helps to decrease the code size.  
     Unrolling all loops implies that standard loop unrolling must also
     be done.  
     web and rename-registers help when run after loop unrolling.  
     Warn about options that are not supported on this machine.  
         If the default prefix is more complicated than "" or "_",
         issue a warning and ignore this option.  
     If we are in verbose mode, write out the version and maybe all the
     option flags in use.  
     A lot of code assumes write_symbols == NO_DEBUG if the debugging
     level is 0.  
     We know which debug output will be used so we can set flag_var_tracking
     and flag_var_tracking_uninit if the user has not specified them.  
     The debug hooks are used to implement -fdump-go-spec because it
     gives a simple and stable API for all the information we need to
     dump.  
     If the user specifically requested variable tracking with tagging
     uninitialized variables, we need to turn on variable tracking.
     (We already determined above that variable tracking is feasible.)  
     If auxiliary info generation is desired, open the output file.
     This goes in the same directory as the source file--unlike
     all the other output files.  
     This combination of options isn't handled for i386 targets and doesn't
     make much sense anyway, so don't allow it.  
     The presence of IEEE signaling NaNs, implies all math can trap.  
     We cannot reassociate if we want traps or signed zeros.  
     With -fcx-limited-range, we do cheap and quick complex arithmetic.  
     With -fcx-fortran-rules, we do something in-between cheap and C99.  
     Targets must be able to place spill slots at lower addresses.  If the
     target already uses a soft frame pointer, the transition is trivial.  
     Address Sanitizer needs porting to each target architecture.  
     Enable -Werror=coverage-mismatch when -Werror and -Wno-error
     have not been set.  
     Save the current optimization options.  
static void* realloc_for_line_map ( )
static
   A helper function; used as the reallocator function for cpp's line
   table.  
const char* set_random_seed ( )
   Modify the random_seed string to VAL.  Return its previous
   value.  
void target_reinit ( void  )
   Reinitialize everything when target parameters, such as register usage,
   have changed.  
     Save *crtl and regno_reg_rtx around the reinitialization
     to allow target_reinit being called even after prepare_function_start.  
     Reinitialize RTL backend.  
     Reinitialize lang-dependent parts.  
     And restore it at the end, as free_after_compilation from
     expand_dummy_function_end clears it.  

Referenced by save_target_globals().

static bool target_supports_section_anchors_p ( )
static
   Return true if the current target supports -fsection-anchors.  
int toplev_main ( )
   Entry point of cc1, cc1plus, jc1, f771, etc.
   Exit code is FATAL_EXIT_CODE if can't open files or if there were
   any errors, or SUCCESS_EXIT_CODE if compilation succeeded.

   It is not safe to call this function more than once.  
     Parsing and gimplification sometimes need quite large stack.
     Increase stack size limits if possible.  
     Initialization of GCC's environment, and diagnostics.  
     One-off initialization of options that does not need to be
     repeated when options are added for particular functions.  
     Initialize global options structures; this must be repeated for
     each structure used for parsing options.  
     Convert the options to an array.  
     Perform language-specific options initialization.  
     Parse the options and do minimal processing; basically just
     enough to default flags appropriately.  
     Exit early if we can (e.g. -help).  
     Invoke registered plugin callbacks if any.  
void wrapup_global_declaration_1 ( )
   A subroutine of wrapup_global_declarations.  We've come to the end of
   the compilation unit.  All deferred variables should be undeferred,
   and all incomplete decls should be finalized.  
     We're not deferring this any longer.  Assignment is conditional to
     avoid needlessly dirtying PCH pages.  
bool wrapup_global_declaration_2 ( )
   A subroutine of wrapup_global_declarations.  Decide whether or not DECL
   needs to be output.  Return true if it is output.  
     Don't write out static consts, unless we still need them.

     We also keep static consts if not optimizing (for debugging),
     unless the user specified -fno-keep-static-consts.
     ??? They might be better written into the debug information.
     This is possible when using DWARF.

     A language processor that wants static constants to be always
     written out (even if it is not used) is responsible for
     calling rest_of_decl_compilation itself.  E.g. the C front-end
     calls rest_of_decl_compilation from finish_decl.
     One motivation for this is that is conventional in some
     environments to write things like:
     static const char rcsid[] = "... version string ...";
     intending to force the string to be in the executable.

     A language processor that would prefer to have unneeded
     static constants "optimized away" would just defer writing
     them out until here.  E.g. C++ does this, because static
     constants are often defined in header files.

     ??? A tempting alternative (for both C and C++) would be
     to force a constant to be written if and only if it is
     defined in a main file, as opposed to an include file.  
           needed 
           needed 
bool wrapup_global_declarations ( )
   Do any final processing required for the declarations in VEC, of
   which there are LEN.  We write out inline functions and variables
   that have been deferred until this point, but which are required.
   Returns nonzero if anything was put out.  
     Now emit any global variables or functions that we have been
     putting off.  We need to loop in case one of the things emitted
     here references another one which comes earlier in the list.  

References input_location, pedwarn(), and warning().