GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "intl.h"
#include "coretypes.h"
#include "opts.h"
#include "flags.h"
#include "diagnostic.h"
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 |
|
static |
Return true if NEXT_OPT_IDX cancels OPT_IDX. Return false if the next one is the same as ORIG_NEXT_OPT_IDX.
An option can be canceled by the same option or an option with Negative.
References CL_ERR_WRONG_LANG, cl_options, cl_options_count, cl_option::flags, cl_option::neg_index, and cl_decoded_option::opt_index.
Referenced by decode_cmdline_options_to_array().
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.
-Werror=foo implies -Wfoo.
|
static |
Decode the switch beginning at ARGV for the language indicated by LANG_MASK (including CL_COMMON and CL_TARGET if applicable), into the structure *DECODED. Returns the number of switches consumed.
Reject negative form of switches that don't take negatives as unrecognized.
Check to see if the option is disabled for this configuration.
Determine whether there may be a separate argument based on whether this option is being processed for the driver, and, if so, how many such arguments.
Sort out any argument the switch takes.
Have arg point to the original switch. This is because some code, such as disable_builtin_function, expects its argument to be persistent until the program exits.
Missing argument.
Is this option an alias (or an ignored option, marked as an alias of OPT_SPECIAL_ignore)?
The new option must not be an alias itself.
Recompute what arguments are allowed.
Recheck for warnings and disabled options.
Check if this is a switch for a different front end.
Convert the argument to lowercase if appropriate.
If the switch takes an integer, convert it.
If the switch takes an enumerated argument, convert it.
If the argument is an empty string, we will print it as "" in orig_option_with_args_text.
Print the empty string verbally.
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.
Interpret "-" or a non-switch as a file name.
References cancel_option(), and cl_options.
Referenced by init_options_once().
|
static |
Return whether ENUM_ARG is OK for the language given by LANG_MASK.
References cl_enum_arg::value.
Referenced by opt_enum_arg_to_value().
|
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_enums, cl_options, CLVC_ENUM, gcc_assert, option(), cl_enum::values, cl_option::var_enum, and cl_option::var_type.
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.
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.
Find mn such this lexicographical inequality holds: cl_options[mn] <= input < cl_options[mn + 1].
This is the switch that is the best match but for a different front end, or OPT_SPECIAL_unknown if there is no match at all.
Backtrace the chain of possible matches, returning the longest one, if any, that fits best. With current GCC switches, this loop executes at most twice.
Is the input either an exact match or a prefix that takes a joined argument?
If language is OK, return it.
If we haven't remembered a prior match, remember this one. Any prior match is necessarily better.
Try the next possibility. This is cl_options_count if there are no more.
Long options, starting "--", may be abbreviated if the abbreviation is unambiguous. This only applies to options not taking a joined argument, and abbreviations of "--option" are permitted even if there is a variant "--option=".
Option matching this abbreviation. OK if it is the first match and that does not take a joined argument, or the second match, taking a joined argument and with only '=' added to the first match; otherwise considered ambiguous.
Return the best wrong match, or OPT_SPECIAL_unknown if none.
References cl_options, cl_options_count, and cl_option::opt_len.
|
static |
Fill in the canonical option part of *DECODED with an option described by OPT_INDEX, ARG and VALUE.
References cl_decoded_option::canonical_option, cl_decoded_option::canonical_option_num_elements, CL_SEPARATE, cl_option::cl_separate_alias, cl_option::flags, gcc_assert, NULL, cl_option::opt_text, and opts_concat().
Referenced by handle_option().
void generate_option | ( | size_t | opt_index, |
const char * | arg, | ||
int | value, | ||
unsigned int | lang_mask, | ||
struct cl_decoded_option * | decoded | ||
) |
Fill in *DECODED with an option described by OPT_INDEX, ARG and VALUE for a front end using LANG_MASK. This is used when the compiler generates options internally.
References cl_decoded_option::arg, CL_ERR_DISABLED, cl_options, error_at(), cl_decoded_option::errors, cl_option::missing_argument_error, cl_decoded_option::opt_index, option(), cl_decoded_option::orig_option_with_args_text, cl_option_handlers::unknown_option_callback, cl_decoded_option::warn_message, and warning_at().
void generate_option_input_file | ( | const char * | file, |
struct cl_decoded_option * | decoded | ||
) |
Fill in *DECODED with an option for input file FILE.
bool get_option_state | ( | struct gcc_options * | opts, |
int | option, | ||
struct cl_option_state * | state | ||
) |
Fill STATE with the current state of option OPTION in OPTS. Return true if there is some state to store.
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.
|
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_decoded_option::canonical_option, cl_decoded_option::canonical_option_num_elements, CL_ERR_WRONG_LANG, cl_options, cl_decoded_option::errors, gcc_unreachable, generate_canonical_option(), NULL, cl_decoded_option::opt_index, option_ok_for_language(), opts_concat(), cl_decoded_option::orig_option_with_args_text, cl_decoded_option::value, and cl_decoded_option::warn_message.
int integral_argument | ( | ) |
If ARG is a non-negative integer made up solely of digits, return its value, otherwise return -1.
References CL_COMMON, CL_DRIVER, CL_TARGET, and cl_option::flags.
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_enum_arg::arg, CL_ENUM_CANONICAL, enum_arg_ok_for_language(), cl_option::flags, and NULL.
int option_enabled | ( | ) |
Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled, or -1 if it isn't a simple on-off switch.
References cl_enums, and cl_options.
Referenced by function_always_visible_to_compiler_p().
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_option::cl_host_wide_int, cl_options, CLVC_BIT_CLEAR, CLVC_BIT_SET, CLVC_BOOLEAN, CLVC_EQUAL, cl_option_state::data, HOST_WIDE_INT, option(), and cl_option_state::size.
|
static |
Return whether OPTION is OK for the language given by LANG_MASK.
Complain for target flag language mismatches if any languages are specified.
References CL_DRIVER, CL_ENUM_DRIVER_ONLY, and cl_enum_arg::flags.
Referenced by handle_option().
char* opts_concat | ( | ) |
Like libiberty concat, but allocate using opts_obstack.
First compute the size of the result and get sufficient memory.
Now copy the individual pieces to the result string.
Referenced by generate_canonical_option(), and handle_option().
|
static |
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.
Remove arguments which are negated by others after them.
Skip joined switches.
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 | ||
) |
Handle the switch DECODED (location LOC) for the language indicated by LANG_MASK, using the handlers in *HANDLERS and setting fields in OPTS and OPTS_SET and using diagnostic context DC (if not NULL) for diagnostic options.
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_enum::set, and cl_option::var_enum.
|
static |
struct obstack opts_obstack |
Obstack for option strings.