46625112d2
* opt-functions.awk (static_var): Update comment. (var_ref): Return offsetof expression or -1, not variable address. * optc-gen.awk: Generate structure field initializers instead of static variables. Expect -1 for missing variables instead of null pointer. Add gcc_options parameters to generated functions. * opth-gen.awk: Generate structure fields for static variables. Add gcc_options parameters to generated functions. * common.opt (optimize, optimize_size): Add variables. * config/i386/i386-c.c (ix86_pragma_target_parse): Pass &global_options to cl_target_option_restore. * config/i386/i386.c (ix86_valid_target_attribute_p): Pass &global_options to cl_optimization_restore, cl_target_option_save and cl_target_option_restore. (ix86_set_current_function): Pass &global_options to cl_target_option_restore. * config/pdp11/pdp11.h (optimize): Remove. * config/rs6000/rs6000.h (optimize): Remove. * config/sh/sh.h (optimize): Remove. * config/xtensa/xtensa.h (optimize): Remove. * coretypes.h (struct gcc_options): Declare. * diagnostic.c (diagnostic_initialize): Initialize context->option_state. (diagnostic_report_diagnostic): Pass option_state to option_enabled hook. * diagnostic.h (diagnostic_context.option_enabled): Add void * parameter. (diagnostic_context.option_state): New field. * final.c (final_start_function, final, final_scan_insn): Rename optimize parameter to optimize_p. * flags.h (optimize, optimize_size): Remove. * function.c (invoke_set_current_function_hook): Pass &global_options to cl_optimization_restore. * gcc.c (driver_handle_option): Take gcc_options parameter. Assert that it is &global_options. (process_command): Pass &global_options to read_cmdline_option. * ipa-pure-const.c (suggest_attribute): Pass &global_options to option_enabled. * lto-opts.c (lto_reissue_options): Use option_flag_var. Pass &global_options to set_option. * opts-common.c (handle_option, handle_generated_option, read_cmdline_option, set_option): Take explicit gcc_options parameters. Use option_flag_var. (option_flag_var): New. * opts.c (common_handle_option, lang_handle_option, target_handle_option): Take gcc_options parameter. Assert that it is &global_options. (read_cmdline_options): Pass &global_options to read_cmdline_option. (print_filtered_help): Use option_flag_var. Pass &global_options to option_enabled. (common_handle_option): Use option_flag_var. (option_enabled): Take opts parameter. Use option_flag_var. (get_option_state): Take gcc_options parameter. Use option_flag_var. Pass gcc_options parameter to option_enabled. (enable_warning_as_error): Pass &global_options to handle_generated_option. * opts.h (struct cl_option): Change flag_var to flag_var_offset. (cl_option_handler_func.handler): Take gcc_options parameter. (option_enabled, get_option_state, set_option, handle_option, handle_generated_option, read_cmdline_option): Take gcc_options parameters. * toplev.c (optimize, optimize_size): Remove. (print_switch_values): Pass &global_options to option_enabled. (option_affects_pch_p): Use option_flag_var. Pass &global_options to get_option_state. (general_init): Initialize global_dc->option_state. * tree.c (build_optimization_node): Pass &global_options to cl_optimization_save. (build_target_option_node): Pass &global_options to cl_target_option_save. c-family: * c-common.c (handle_optimize_attribute): Pass &global_options to cl_optimization_save and cl_optimization_restore. * c-opts.c (c_common_handle_option): Pass &global_options to handle_generated_option. * c-pragma.c (handle_pragma_diagnostic): Use option_flag_var. (handle_pragma_pop_options, handle_pragma_reset_options): Pass &global_options to cl_optimization_restore. From-SVN: r164751
218 lines
6.2 KiB
Awk
218 lines
6.2 KiB
Awk
# Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
|
|
# Free Software Foundation, Inc.
|
|
# Contributed by Kelley Cook, June 2004.
|
|
# Original code from Neil Booth, May 2003.
|
|
#
|
|
# This program 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.
|
|
#
|
|
# This program 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 this program; see the file COPYING3. If not see
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
# Some common subroutines for use by opt[ch]-gen.awk.
|
|
|
|
# Return nonzero if FLAGS contains a flag matching REGEX.
|
|
function flag_set_p(regex, flags)
|
|
{
|
|
return (" " flags " ") ~ (" " regex " ")
|
|
}
|
|
|
|
# Return STRING if FLAGS contains a flag matching regexp REGEX,
|
|
# otherwise return the empty string.
|
|
function test_flag(regex, flags, string)
|
|
{
|
|
if (flag_set_p(regex, flags))
|
|
return string
|
|
return ""
|
|
}
|
|
|
|
# If FLAGS contains a "NAME(...argument...)" flag, return the value
|
|
# of the argument. Return the empty string otherwise.
|
|
function opt_args(name, flags)
|
|
{
|
|
flags = " " flags
|
|
if (flags !~ " " name "\\(")
|
|
return ""
|
|
sub(".* " name "\\(", "", flags)
|
|
if (flags ~ "^{")
|
|
{
|
|
sub ("^{", "", flags)
|
|
sub("}\\).*", "", flags)
|
|
}
|
|
else
|
|
sub("\\).*", "", flags)
|
|
|
|
return flags
|
|
}
|
|
|
|
# Return the Nth comma-separated element of S. Return the empty string
|
|
# if S does not contain N elements.
|
|
function nth_arg(n, s)
|
|
{
|
|
while (n-- > 0) {
|
|
if (s !~ ",")
|
|
return ""
|
|
sub("[^,]*, *", "", s)
|
|
}
|
|
sub(",.*", "", s)
|
|
return s
|
|
}
|
|
|
|
# Return a bitmask of CL_* values for option flags FLAGS.
|
|
function switch_flags (flags)
|
|
{
|
|
result = "0"
|
|
for (j = 0; j < n_langs; j++) {
|
|
regex = langs[j]
|
|
gsub ( "\\+", "\\+", regex )
|
|
result = result test_flag(regex, flags, " | " macros[j])
|
|
}
|
|
result = result \
|
|
test_flag("Common", flags, " | CL_COMMON") \
|
|
test_flag("Target", flags, " | CL_TARGET") \
|
|
test_flag("Driver", flags, " | CL_DRIVER") \
|
|
test_flag("RejectDriver", flags, " | CL_REJECT_DRIVER") \
|
|
test_flag("NoDriverArg", flags, " | CL_NO_DRIVER_ARG") \
|
|
test_flag("SeparateAlias", flags, " | CL_SEPARATE_ALIAS") \
|
|
test_flag("Save", flags, " | CL_SAVE") \
|
|
test_flag("Joined", flags, " | CL_JOINED") \
|
|
test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
|
|
test_flag("Separate", flags, " | CL_SEPARATE") \
|
|
test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \
|
|
test_flag("UInteger", flags, " | CL_UINTEGER") \
|
|
test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \
|
|
test_flag("Warning", flags, " | CL_WARNING") \
|
|
test_flag("Optimization", flags, " | CL_OPTIMIZATION") \
|
|
test_flag("Report", flags, " | CL_REPORT")
|
|
sub( "^0 \\| ", "", result )
|
|
return result
|
|
}
|
|
|
|
# If FLAGS includes a Var flag, return the name of the variable it specifies.
|
|
# Return the empty string otherwise.
|
|
function var_name(flags)
|
|
{
|
|
return nth_arg(0, opt_args("Var", flags))
|
|
}
|
|
|
|
# Return true if the option described by FLAGS has a globally-visible state.
|
|
function global_state_p(flags)
|
|
{
|
|
return (var_name(flags) != "" \
|
|
|| opt_args("Mask", flags) != "" \
|
|
|| opt_args("InverseMask", flags) != "")
|
|
}
|
|
|
|
# Return true if the option described by FLAGS must have some state
|
|
# associated with it.
|
|
function needs_state_p(flags)
|
|
{
|
|
return (flag_set_p("Target", flags) \
|
|
&& !flag_set_p("Alias.*", flags) \
|
|
&& !flag_set_p("Ignore", flags))
|
|
}
|
|
|
|
# If FLAGS describes an option that needs state without a public
|
|
# variable name, return the name of that field, minus the initial
|
|
# "x_", otherwise return "". NAME is the name of the option.
|
|
function static_var(name, flags)
|
|
{
|
|
if (global_state_p(flags) || !needs_state_p(flags))
|
|
return ""
|
|
gsub ("[^A-Za-z0-9]", "_", name)
|
|
return "VAR_" name
|
|
}
|
|
|
|
# Return the type of variable that should be associated with the given flags.
|
|
function var_type(flags)
|
|
{
|
|
if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags))
|
|
return "int "
|
|
else if (flag_set_p("UInteger", flags))
|
|
return "int "
|
|
else
|
|
return "const char *"
|
|
}
|
|
|
|
# Return the type of variable that should be associated with the given flags
|
|
# for use within a structure. Simple variables are changed to signed char
|
|
# type instead of int to save space.
|
|
function var_type_struct(flags)
|
|
{
|
|
if (flag_set_p("UInteger", flags))
|
|
return "int "
|
|
else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) {
|
|
if (flag_set_p(".*Mask.*", flags))
|
|
return "int "
|
|
else
|
|
return "signed char "
|
|
}
|
|
else
|
|
return "const char *"
|
|
}
|
|
|
|
# Given that an option has flags FLAGS, return an initializer for the
|
|
# "var_cond" and "var_value" fields of its cl_options[] entry.
|
|
function var_set(flags)
|
|
{
|
|
s = nth_arg(1, opt_args("Var", flags))
|
|
if (s != "")
|
|
return "CLVC_EQUAL, " s
|
|
s = opt_args("Mask", flags);
|
|
if (s != "") {
|
|
vn = var_name(flags);
|
|
if (vn)
|
|
return "CLVC_BIT_SET, OPTION_MASK_" s
|
|
else
|
|
return "CLVC_BIT_SET, MASK_" s
|
|
}
|
|
s = nth_arg(0, opt_args("InverseMask", flags));
|
|
if (s != "") {
|
|
vn = var_name(flags);
|
|
if (vn)
|
|
return "CLVC_BIT_CLEAR, OPTION_MASK_" s
|
|
else
|
|
return "CLVC_BIT_CLEAR, MASK_" s
|
|
}
|
|
if (var_type(flags) == "const char *")
|
|
return "CLVC_STRING, 0"
|
|
return "CLVC_BOOLEAN, 0"
|
|
}
|
|
|
|
# Given that an option called NAME has flags FLAGS, return an initializer
|
|
# for the "flag_var" field of its cl_options[] entry.
|
|
function var_ref(name, flags)
|
|
{
|
|
name = var_name(flags) static_var(name, flags)
|
|
if (name != "")
|
|
return "offsetof (struct gcc_options, x_" name ")"
|
|
if (opt_args("Mask", flags) != "")
|
|
return "offsetof (struct gcc_options, x_target_flags)"
|
|
if (opt_args("InverseMask", flags) != "")
|
|
return "offsetof (struct gcc_options, x_target_flags)"
|
|
return "-1"
|
|
}
|
|
|
|
# Given the option called NAME return a sanitized version of its name.
|
|
function opt_sanitized_name(name)
|
|
{
|
|
if (name == "gdwarf+")
|
|
name = "gdwarfplus"
|
|
gsub ("[^A-Za-z0-9]", "_", name)
|
|
return name
|
|
}
|
|
|
|
# Given the option called NAME return the appropriate enum for it.
|
|
function opt_enum(name)
|
|
{
|
|
return "OPT_" opt_sanitized_name(name)
|
|
}
|