GCC Middle and Back End API Reference
driver Class Reference

#include <gcc.h>

Collaboration diagram for driver:

Public Member Functions

 driver (bool can_finalize, bool debug)
 
 ~driver ()
 
int main (int argc, char **argv)
 
void finalize ()
 

Private Member Functions

void set_progname (const char *argv0) const
 
void expand_at_files (int *argc, char ***argv) const
 
void decode_argv (int argc, const char **argv)
 
void global_initializations ()
 
void build_multilib_strings () const
 
void set_up_specs () const
 
void putenv_COLLECT_GCC (const char *argv0) const
 
void maybe_putenv_COLLECT_LTO_WRAPPER () const
 
void maybe_putenv_OFFLOAD_TARGETS () const
 
void handle_unrecognized_options ()
 
int maybe_print_and_exit () const
 
bool prepare_infiles ()
 
void do_spec_on_infiles () const
 
void maybe_run_linker (const char *argv0) const
 
void final_actions () const
 
void detect_jobserver () const
 
int get_exit_code () const
 

Private Attributes

char * explicit_link_files
 
struct cl_decoded_optiondecoded_options
 
unsigned int decoded_options_count
 
option_proposer m_option_proposer
 

Detailed Description

Header file for modules that link with gcc.cc
   Copyright (C) 1999-2024 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/>.   
The top-level "main" within the driver would be ~1000 lines long.
This class breaks it up into smaller functions and contains some
state shared by them.   

Constructor & Destructor Documentation

◆ driver()

driver::driver ( bool can_finalize,
bool debug )

References debug, env, and env_manager::init().

◆ ~driver()

driver::~driver ( )

Member Function Documentation

◆ build_multilib_strings()

void driver::build_multilib_strings ( ) const
private
Build multilib_select, et. al from the separate lines that make up each
multilib selection.   

References i, multilib_defaults, multilib_defaults_raw, multilib_exclusions, multilib_matches, multilib_obstack, multilib_reuse, and multilib_select.

Referenced by main().

◆ decode_argv()

void driver::decode_argv ( int argc,
const char ** argv )
private
Decode the command-line arguments from argc/argv into the
decoded_options array.   

References CL_DRIVER, decode_cmdline_options_to_array(), decoded_options, decoded_options_count, global_options, global_options_set, init_options_struct(), and init_opts_obstack().

Referenced by main().

◆ detect_jobserver()

void driver::detect_jobserver ( ) const
private
Detect whether jobserver is active and working.  If not drop
--jobserver-auth from MAKEFLAGS.   

References jobserver_info::is_active, jobserver_info::skipped_makeflags, and xputenv().

Referenced by maybe_run_linker().

◆ do_spec_on_infiles()

◆ expand_at_files()

void driver::expand_at_files ( int * argc,
char *** argv ) const
private
Expand any @ files within the command-line args,
setting at_file_supplied if any were expanded.   

References at_file_supplied.

Referenced by main().

◆ final_actions()

void driver::final_actions ( ) const
private
The end of "main".   

References delete_failure_queue(), delete_temp_files(), NULL, print_help_list, seen_error(), and totruncate_file.

Referenced by main().

◆ finalize()

void driver::finalize ( )
Restore all state within gcc.cc to the initial state, so that the driver
code can be safely re-run in-process.

Many const char * variables are referenced by static specs (see
INIT_STATIC_SPEC above).  These variables are restored to their default
values by a simple loop over the static specs.

For other variables, we directly restore them all to their initial
values (often implicitly 0).

Free the various obstacks in this file, along with "opts_obstack"
from opts.cc.

This function also restores any environment variables that were changed.   

References added_libraries, always_delete_queue, arg_going, assembler_options, at_file_supplied, basename_length, clear_args(), collect_obstack, combine_inputs, compare_debug, compare_debug_opt, compare_debug_second, compilers, debug_check_temp_file, spec_list::default_ptr, DEFAULT_TARGET_SYSTEM_ROOT, delete_this_arg, diagnostic_finish(), dumpbase, dumpbase_ext, dumpdir, dumpdir_length, dumpdir_trailing_dash_added, env, exec_prefixes, execution_count, failure_delete_queue, used_arg_t::finalize(), free(), gcc_exec_prefix, gcc_input_filename, gcc_libexec_prefix, global_dc, greatest_status, have_c, have_o, i, include_prefixes, infiles, input_basename, input_file_compiler, input_file_number, input_filename_length, input_from_pipe, input_stat_set, input_suffix, is_cpp_driver, just_machine_suffix, last_language_n_infiles, LINK_COMMAND_SPEC, link_command_spec, linker_options, machine_suffix, MD_EXEC_PREFIX, md_exec_prefix, MD_STARTFILE_PREFIX, md_startfile_prefix, MD_STARTFILE_PREFIX_1, md_startfile_prefix_1, mdswitches, multiarch_dir, multilib_dir, multilib_obstack, multilib_os_dir, n_compilers, n_default_compilers, n_infiles, n_infiles_alloc, n_mdswitches, n_switches, n_switches_alloc, n_switches_alloc_debug_check, n_switches_debug_check, spec_list::name, spec_list::next, NULL, obstack, opts_obstack, outbase, outbase_length, outfiles, path_prefix_reset(), preprocessor_options, print_help_list, print_subprocess_help, print_version, processing_spec_function, report_times_to_file, env_manager::restore(), save_temps_flag, SAVE_TEMPS_NONE, save_temps_overrides_dumpdir, set_static_spec_shared(), signal_count, sl, spec_lang, spec_machine, specs, startfile_prefixes, static_specs, suffix_subst, suffixed_basename_length, switches, switches_debug_check, target_sysroot_hdrs_suffix, target_sysroot_suffix, target_system_root, target_system_root_changed, temp_filename, temp_filename_length, temp_names, this_is_library_file, this_is_linker_script, this_is_output_file, use_ld, used_arg, user_specs_head, user_specs_tail, and verbose_only_flag.

◆ get_exit_code()

int driver::get_exit_code ( ) const
private
Determine what the exit code of the driver should be.   

References greatest_status, seen_error(), and signal_count.

Referenced by main().

◆ global_initializations()

◆ handle_unrecognized_options()

void driver::handle_unrecognized_options ( )
private
Reject switches that no pass was interested in.   

References error(), i, m_option_proposer, n_switches, option_proposer::suggest_option(), and switches.

Referenced by main().

◆ main()

◆ maybe_print_and_exit()

◆ maybe_putenv_COLLECT_LTO_WRAPPER()

void driver::maybe_putenv_COLLECT_LTO_WRAPPER ( ) const
private
Set up to remember the pathname of the lto wrapper.  

References collect_obstack, convert_white_space(), find_a_program(), have_c, lto_wrapper_spec, NULL, set_static_spec_owned(), and xputenv().

Referenced by main().

◆ maybe_putenv_OFFLOAD_TARGETS()

void driver::maybe_putenv_OFFLOAD_TARGETS ( ) const
private
Set up to remember the names of offload targets.   

References collect_obstack, free(), NULL, offload_targets, and xputenv().

Referenced by main().

◆ maybe_run_linker()

◆ prepare_infiles()

bool driver::prepare_infiles ( )
private

◆ putenv_COLLECT_GCC()

void driver::putenv_COLLECT_GCC ( const char * argv0) const
private
Set up to remember the pathname of gcc and any options
needed for collect.  We use argv[0] instead of progname because
we need the complete pathname.   

References collect_obstack, and xputenv().

Referenced by main().

◆ set_progname()

void driver::set_progname ( const char * argv0) const
private
Locate the final component of argv[0] after any leading path, and set
the program name accordingly.   

References progname.

Referenced by main().

◆ set_up_specs()

Field Documentation

◆ decoded_options

struct cl_decoded_option* driver::decoded_options
private

Referenced by decode_argv(), set_up_specs(), and ~driver().

◆ decoded_options_count

unsigned int driver::decoded_options_count
private

Referenced by decode_argv(), and set_up_specs().

◆ explicit_link_files

char* driver::explicit_link_files
private

◆ m_option_proposer

option_proposer driver::m_option_proposer
private

The documentation for this class was generated from the following files: