GCC Middle and Back End API Reference
opts-common.c File Reference

Data Structures

struct  option_map

Functions

static void prune_options (struct cl_decoded_option **, unsigned int *)
size_t find_opt ()
int integral_argument ()
static bool option_ok_for_language (const struct cl_option *option, unsigned int lang_mask)
static bool enum_arg_ok_for_language (const struct cl_enum_arg *enum_arg, unsigned int lang_mask)
static bool enum_arg_to_value (const struct cl_enum_arg *enum_args, const char *arg, int *value, unsigned int lang_mask)
bool opt_enum_arg_to_value (size_t opt_index, const char *arg, int *value, unsigned int lang_mask)
bool enum_value_to_arg (const struct cl_enum_arg *enum_args, const char **argp, int value, unsigned int lang_mask)
static void generate_canonical_option (size_t opt_index, const char *arg, int value, struct cl_decoded_option *decoded)
static unsigned int decode_cmdline_option (const char **argv, unsigned int lang_mask, struct cl_decoded_option *decoded)
char * opts_concat ()
void decode_cmdline_options_to_array (unsigned int argc, const char **argv, unsigned int lang_mask, struct cl_decoded_option **decoded_options, unsigned int *decoded_options_count)
static bool cancel_option ()
static bool handle_option (struct gcc_options *opts, struct gcc_options *opts_set, const struct cl_decoded_option *decoded, unsigned int lang_mask, int kind, location_t loc, const struct cl_option_handlers *handlers, bool generated_p, diagnostic_context *dc)
bool handle_generated_option (struct gcc_options *opts, struct gcc_options *opts_set, size_t opt_index, const char *arg, int value, unsigned int lang_mask, int kind, location_t loc, const struct cl_option_handlers *handlers, diagnostic_context *dc)
void generate_option (size_t opt_index, const char *arg, int value, unsigned int lang_mask, struct cl_decoded_option *decoded)
void generate_option_input_file (const char *file, struct cl_decoded_option *decoded)
void read_cmdline_option (struct gcc_options *opts, struct gcc_options *opts_set, struct cl_decoded_option *decoded, location_t loc, unsigned int lang_mask, const struct cl_option_handlers *handlers, diagnostic_context *dc)
void set_option (struct gcc_options *opts, struct gcc_options *opts_set, int opt_index, int value, const char *arg, int kind, location_t loc, diagnostic_context *dc)
void * option_flag_var ()
int option_enabled ()
bool get_option_state (struct gcc_options *opts, int option, struct cl_option_state *state)
void control_warning_option (unsigned int opt_index, int kind, bool imply, location_t loc, unsigned int lang_mask, const struct cl_option_handlers *handlers, struct gcc_options *opts, struct gcc_options *opts_set, diagnostic_context *dc)

Variables

static struct option_map option_map []
struct obstack opts_obstack

Function Documentation

static bool cancel_option ( )
static
Return true if NEXT_OPT_IDX cancels OPT_IDX.  Return false if the
   next one is the same as ORIG_NEXT_OPT_IDX.   

References cl_options.

Referenced by prune_options().

void control_warning_option ( unsigned int  opt_index,
int  kind,
bool  imply,
location_t  loc,
unsigned int  lang_mask,
const struct cl_option_handlers handlers,
struct gcc_options *  opts,
struct gcc_options *  opts_set,
diagnostic_context dc 
)
Set a warning option OPT_INDEX (language mask LANG_MASK, option
   handlers HANDLERS) to have diagnostic kind KIND for option
   structures OPTS and OPTS_SET and diagnostic context DC (possibly
   NULL), at location LOC (UNKNOWN_LOCATION for -Werror=).  If IMPLY,
   the warning option in question is implied at this point.  This is
   used by -Werror= and #pragma GCC diagnostic.   

References cl_option::alias_target, cl_options, CLVC_BOOLEAN, diagnostic_classify_diagnostic(), and handle_generated_option().

Referenced by common_handle_option(), and enable_warning_as_error().

void decode_cmdline_options_to_array ( unsigned int  argc,
const char **  argv,
unsigned int  lang_mask,
struct cl_decoded_option **  decoded_options,
unsigned int *  decoded_options_count 
)
Decode command-line options (ARGC and ARGV being the arguments of
   main) into an array, setting *DECODED_OPTIONS to a pointer to that
   array and *DECODED_OPTIONS_COUNT to the number of entries in the
   array.  The first entry in the array is always one for the program
   name (OPT_SPECIAL_program_name).  LANG_MASK indicates the language
   flags applicable for decoding (including CL_COMMON and CL_TARGET if
   those options should be considered applicable).  Do not produce any
   diagnostics or set state outside of these variables.   

References cl_decoded_option::arg, cl_decoded_option::canonical_option, cl_decoded_option::canonical_option_num_elements, decode_cmdline_option(), cl_decoded_option::errors, generate_option_input_file(), cl_decoded_option::opt_index, cl_decoded_option::orig_option_with_args_text, prune_options(), cl_decoded_option::value, and cl_decoded_option::warn_message.

Referenced by decode_cmdline_options_to_array_default_mask(), do_self_spec(), get_options_from_collect_gcc_options(), and main().

static bool enum_arg_ok_for_language ( const struct cl_enum_arg enum_arg,
unsigned int  lang_mask 
)
static
Return whether ENUM_ARG is OK for the language given by
   LANG_MASK.   

References cl_enum_arg::flags.

Referenced by enum_arg_to_value(), and enum_value_to_arg().

static bool enum_arg_to_value ( const struct cl_enum_arg enum_args,
const char *  arg,
int *  value,
unsigned int  lang_mask 
)
static
Look up ARG in ENUM_ARGS for language LANG_MASK, returning true and
   storing the value in *VALUE if found, and returning false without
   modifying *VALUE if not found.   

References cl_enum_arg::arg, enum_arg_ok_for_language(), and cl_enum_arg::value.

Referenced by decode_cmdline_option(), and opt_enum_arg_to_value().

bool enum_value_to_arg ( const struct cl_enum_arg enum_args,
const char **  argp,
int  value,
unsigned int  lang_mask 
)
Look of VALUE in ENUM_ARGS for language LANG_MASK and store the
   corresponding string in *ARGP, returning true if the found string
   was marked as canonical, false otherwise.  If VALUE is not found
   (which may be the case for uninitialized values if the relevant
   option has not been passed), set *ARGP to NULL and return
   false.   

References cl_enum_arg::arg, enum_arg_ok_for_language(), and cl_option::flags.

Referenced by decode_cmdline_option(), and print_filtered_help().

size_t find_opt ( )
Perform a binary search to find which option the command-line INPUT
   matches.  Returns its index in the option array, and
   OPT_SPECIAL_unknown on failure.

   This routine is quite subtle.  A normal binary search is not good
   enough because some options can be suffixed with an argument, and
   multiple sub-matches can occur, e.g. input of "-pedantic" matching
   the initial substring of "-pedantic-errors".

   A more complicated example is -gstabs.  It should match "-g" with
   an argument of "stabs".  Suppose, however, that the number and list
   of switches are such that the binary search tests "-gen-decls"
   before having tested "-g".  This doesn't match, and as "-gen-decls"
   is less than "-gstabs", it will become the lower bound of the
   binary search range, and "-g" will never be seen.  To resolve this
   issue, 'optc-gen.awk' makes "-gen-decls" point, via the back_chain member,
   to "-g" so that failed searches that end between "-gen-decls" and
   the lexicographically subsequent switch know to go back and see if
   "-g" causes a match (which it does in this example).

   This search is done in such a way that the longest match for the
   front end in question wins.  If there is no match for the current
   front end, the longest match for a different front end is returned
   (or N_OPTS if none) and the caller emits an error message.   

References cl_option::back_chain, cl_options, cl_options_count, comp, cl_option::flags, cl_option::opt_len, cl_option::opt_text, and strlen().

Referenced by decode_cmdline_option(), and enable_warning_as_error().

static void generate_canonical_option ( size_t  opt_index,
const char *  arg,
int  value,
struct cl_decoded_option decoded 
)
static
void generate_option ( size_t  opt_index,
const char *  arg,
int  value,
unsigned int  lang_mask,
struct cl_decoded_option decoded 
)
bool get_option_state ( struct gcc_options *  opts,
int  option,
struct cl_option_state state 
)
bool handle_generated_option ( struct gcc_options *  opts,
struct gcc_options *  opts_set,
size_t  opt_index,
const char *  arg,
int  value,
unsigned int  lang_mask,
int  kind,
location_t  loc,
const struct cl_option_handlers handlers,
diagnostic_context dc 
)
Like handle_option, but OPT_INDEX, ARG and VALUE describe the
   option instead of DECODED.  This is used for callbacks when one
   option implies another instead of an option being decoded from the
   command line.   

References generate_option(), and handle_option().

Referenced by control_warning_option(), and maybe_default_option().

static bool handle_option ( struct gcc_options *  opts,
struct gcc_options *  opts_set,
const struct cl_decoded_option decoded,
unsigned int  lang_mask,
int  kind,
location_t  loc,
const struct cl_option_handlers handlers,
bool  generated_p,
diagnostic_context dc 
)
static
Handle option DECODED for the language indicated by LANG_MASK,
   using the handlers in HANDLERS and setting fields in OPTS and
   OPTS_SET.  KIND is the diagnostic_t if this is a diagnostics
   option, DK_UNSPECIFIED otherwise, and LOC is the location of the
   option for options from the source file, UNKNOWN_LOCATION
   otherwise.  GENERATED_P is true for an option generated as part of
   processing another option or otherwise generated internally, false
   for one explicitly passed by the user.  Returns false if the switch
   was invalid.  DC is the diagnostic context for options affecting
   diagnostics state, or NULL.   

References cl_decoded_option::arg, cl_options, cl_option::flags, cl_option_handler_func::handler, cl_option_handlers::handlers, cl_option_handler_func::mask, cl_option_handlers::num_handlers, cl_decoded_option::opt_index, option(), option_flag_var(), set_option(), and cl_decoded_option::value.

Referenced by handle_generated_option(), and read_cmdline_option().

int integral_argument ( )
If ARG is a non-negative integer made up solely of digits, return its
   value, otherwise return -1.   

Referenced by decode_cmdline_option(), default_options_optimization(), handle_param(), and set_debug_level().

bool opt_enum_arg_to_value ( size_t  opt_index,
const char *  arg,
int *  value,
unsigned int  lang_mask 
)
Look up ARG in the enum used by option OPT_INDEX for language
   LANG_MASK, returning true and storing the value in *VALUE if found,
   and returning false without modifying *VALUE if not found.   

References cl_enums, cl_options, CLVC_ENUM, enum_arg_to_value(), option(), cl_enum::values, cl_option::var_enum, and cl_option::var_type.

int option_enabled ( )
void* option_flag_var ( )
Return the address of the flag variable for option OPT_INDEX in
   options structure OPTS, or NULL if there is no flag variable.   

References cl_options, cl_option::flag_var_offset, and option().

Referenced by common_handle_option(), get_option_state(), handle_option(), option_affects_pch_p(), option_enabled(), print_filtered_help(), and set_option().

static bool option_ok_for_language ( const struct cl_option option,
unsigned int  lang_mask 
)
static
Return whether OPTION is OK for the language given by
   LANG_MASK.   

References cl_option::flags.

Referenced by decode_cmdline_option(), and generate_option().

char* opts_concat ( )
Like libiberty concat, but allocate using opts_obstack.   

References memcpy(), opts_obstack, and strlen().

Referenced by finish_options(), generate_canonical_option(), and generate_option().

static void prune_options ( struct cl_decoded_option **  decoded_options,
unsigned int *  decoded_options_count 
)
static
@verbatim Command line option handling.

Copyright (C) 2006-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/.

Filter out options canceled by the ones after them.   

References cancel_option(), cl_options, cl_options_count, cl_option::flags, free(), cl_option::neg_index, cl_decoded_option::opt_index, and option().

Referenced by decode_cmdline_options_to_array().

void read_cmdline_option ( struct gcc_options *  opts,
struct gcc_options *  opts_set,
struct cl_decoded_option decoded,
location_t  loc,
unsigned int  lang_mask,
const struct cl_option_handlers handlers,
diagnostic_context dc 
)
void set_option ( struct gcc_options *  opts,
struct gcc_options *  opts_set,
int  opt_index,
int  value,
const char *  arg,
int  kind,
location_t  loc,
diagnostic_context dc 
)
Set any field in OPTS, and OPTS_SET if not NULL, for option
   OPT_INDEX according to VALUE and ARG, diagnostic kind KIND,
   location LOC, using diagnostic context DC if not NULL for
   diagnostic classification.   

References cl_enums, cl_option::cl_host_wide_int, cl_options, CLVC_BIT_CLEAR, CLVC_BIT_SET, CLVC_BOOLEAN, CLVC_DEFER, CLVC_ENUM, CLVC_EQUAL, CLVC_STRING, diagnostic_classify_diagnostic(), HOST_WIDE_INT, option(), option_flag_var(), cl_enum::set, cl_option::var_enum, cl_option::var_type, and cl_option::var_value.

Referenced by handle_option().


Variable Documentation

struct option_map option_map[]
static
Initial value:
{
{ "-Wno-", NULL, "-W", false, true },
{ "-fno-", NULL, "-f", false, true },
{ "-mno-", NULL, "-m", false, true },
{ "--debug=", NULL, "-g", false, false },
{ "--machine-", NULL, "-m", true, false },
{ "--machine-no-", NULL, "-m", false, true },
{ "--machine=", NULL, "-m", false, false },
{ "--machine=no-", NULL, "-m", false, true },
{ "--machine", "", "-m", false, false },
{ "--machine", "no-", "-m", false, true },
{ "--optimize=", NULL, "-O", false, false },
{ "--std=", NULL, "-std=", false, false },
{ "--std", "", "-std=", false, false },
{ "--warn-", NULL, "-W", true, false },
{ "--warn-no-", NULL, "-W", false, true },
{ "--", NULL, "-f", true, false },
{ "--no-", NULL, "-f", false, true }
}
struct obstack opts_obstack