| 1 |
# Copyright (C) 2003-2025 Free Software Foundation, Inc. |
| 2 |
# Contributed by Kelley Cook, June 2004. |
| 3 |
# Original code from Neil Booth, May 2003. |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by the |
| 7 |
# Free Software Foundation; either version 3, or (at your option) any |
| 8 |
# later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; see the file COPYING3. If not see |
| 17 |
# <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
# This Awk script reads in the option records generated from |
| 20 |
# opt-gather.awk, combines the flags of duplicate options and generates a |
| 21 |
# C file. |
| 22 |
# |
| 23 |
|
| 24 |
# This program uses functions from opt-functions.awk and code from |
| 25 |
# opt-read.awk. |
| 26 |
# |
| 27 |
# Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-gen.awk \ |
| 28 |
# [-v header_name=header.h] < inputfile > options.cc |
| 29 |
|
| 30 |
# Dump that array of options into a C file. |
| 31 |
END { |
| 32 |
|
| 33 |
|
| 34 |
# Combine the flags of identical switches. Switches |
| 35 |
# appear many times if they are handled by many front |
| 36 |
# ends, for example. |
| 37 |
for (i = 0; i < n_opts; i++) { |
| 38 |
merged_flags[i] = flags[i] |
| 39 |
} |
| 40 |
for (i = 0; i < n_opts; i++) { |
| 41 |
while(i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
| 42 |
merged_flags[i + 1] = merged_flags[i] " " merged_flags[i + 1]; |
| 43 |
i++; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
# Record EnabledBy and LangEnabledBy uses. |
| 48 |
n_enabledby = 0; |
| 49 |
for (i = 0; i < n_langs; i++) { |
| 50 |
n_enabledby_lang[i] = 0; |
| 51 |
} |
| 52 |
for (i = 0; i < n_opts; i++) { |
| 53 |
enabledby_arg = opt_args("EnabledBy", flags[i]); |
| 54 |
if (enabledby_arg != "") { |
| 55 |
logical_and = index(enabledby_arg, " && "); |
| 56 |
if (logical_and != 0) { |
| 57 |
# EnabledBy(arg1 && arg2) |
| 58 |
split_sep = " && "; |
| 59 |
} else { |
| 60 |
# EnabledBy(arg) or EnabledBy(arg1 || arg2 || arg3) |
| 61 |
split_sep = " \\|\\| "; |
| 62 |
} |
| 63 |
n_enabledby_names = split(enabledby_arg, enabledby_names, split_sep); |
| 64 |
if (logical_and != 0 && n_enabledby_names > 2) { |
| 65 |
print "#error " opts[i] " EnabledBy(Wfoo && Wbar && Wbaz) currently not supported" |
| 66 |
} |
| 67 |
for (j = 1; j <= n_enabledby_names; j++) { |
| 68 |
enabledby_name = enabledby_names[j]; |
| 69 |
enabledby_index = opt_numbers[enabledby_name]; |
| 70 |
if (enabledby_index == "") { |
| 71 |
print "#error " opts[i] " Enabledby(" enabledby_name "), unknown option '" enabledby_name "'" |
| 72 |
} else if (!flag_set_p("Common", merged_flags[enabledby_index])) { |
| 73 |
print "#error " opts[i] " Enabledby(" enabledby_name "), '" \ |
| 74 |
enabledby_name "' must have flag 'Common'" \ |
| 75 |
" to use Enabledby(), otherwise use LangEnabledBy()" |
| 76 |
} else { |
| 77 |
condition = ""; |
| 78 |
if (logical_and != 0) { |
| 79 |
opt_var_name_1 = search_var_name(enabledby_names[1], opt_numbers, opts, flags, n_opts); |
| 80 |
opt_var_name_2 = search_var_name(enabledby_names[2], opt_numbers, opts, flags, n_opts); |
| 81 |
if (opt_var_name_1 == "") { |
| 82 |
print "#error " enabledby_names[1] " does not have a Var() flag" |
| 83 |
} |
| 84 |
if (opt_var_name_2 == "") { |
| 85 |
print "#error " enabledby_names[2] " does not have a Var() flag" |
| 86 |
} |
| 87 |
condition = "opts->x_" opt_var_name_1 " && opts->x_" opt_var_name_2; |
| 88 |
} |
| 89 |
if (enables[enabledby_name] == "") { |
| 90 |
enabledby[n_enabledby] = enabledby_name; |
| 91 |
n_enabledby++; |
| 92 |
} |
| 93 |
enables[enabledby_name] = enables[enabledby_name] opts[i] ";"; |
| 94 |
enablesif[enabledby_name] = enablesif[enabledby_name] condition ";"; |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
enabledby_arg = opt_args("LangEnabledBy", flags[i]); |
| 100 |
if (enabledby_arg != "") { |
| 101 |
enabledby_n_args = n_args(enabledby_arg) |
| 102 |
if (enabledby_n_args != 2 \ |
| 103 |
&& enabledby_n_args != 4) { |
| 104 |
print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify two or four arguments" |
| 105 |
} |
| 106 |
|
| 107 |
enabledby_langs = nth_arg(0, enabledby_arg); |
| 108 |
if (enabledby_langs == "") |
| 109 |
print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify LANGUAGE" |
| 110 |
enabledby_opt = nth_arg(1, enabledby_arg); |
| 111 |
if (enabledby_opt == "") |
| 112 |
print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify OPT" |
| 113 |
|
| 114 |
enabledby_posarg_negarg = "" |
| 115 |
if (enabledby_n_args == 4) { |
| 116 |
enabledby_posarg = nth_arg(2, enabledby_arg); |
| 117 |
enabledby_negarg = nth_arg(3, enabledby_arg); |
| 118 |
if (enabledby_posarg == "" \ |
| 119 |
|| enabledby_negarg == "") |
| 120 |
print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") with four arguments must specify POSARG and NEGARG" |
| 121 |
else |
| 122 |
enabledby_posarg_negarg = "," enabledby_posarg "," enabledby_negarg |
| 123 |
} |
| 124 |
|
| 125 |
n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " "); |
| 126 |
n_enabledby_array = split(enabledby_opt, enabledby_array, " \\|\\| "); |
| 127 |
for (k = 1; k <= n_enabledby_array; k++) { |
| 128 |
enabledby_index = opt_numbers[enabledby_array[k]]; |
| 129 |
if (enabledby_index == "") { |
| 130 |
print "#error " opts[i] " LangEnabledBy(" enabledby_arg "), unknown option '" enabledby_opt "'" |
| 131 |
continue |
| 132 |
} |
| 133 |
|
| 134 |
for (j = 1; j <= n_enabledby_arg_langs; j++) { |
| 135 |
lang_name = enabledby_arg_langs[j] |
| 136 |
lang_index = lang_numbers[lang_name]; |
| 137 |
if (lang_index == "") { |
| 138 |
print "#error " opts[i] " LangEnabledBy(" enabledby_arg "), unknown language '" lang_name "'" |
| 139 |
continue |
| 140 |
} |
| 141 |
|
| 142 |
lang_name = lang_sanitized_name(lang_name); |
| 143 |
|
| 144 |
if (enables[lang_name,enabledby_array[k]] == "") { |
| 145 |
enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k]; |
| 146 |
n_enabledby_lang[lang_index]++; |
| 147 |
} |
| 148 |
enables[lang_name,enabledby_array[k]] \ |
| 149 |
= enables[lang_name,enabledby_array[k]] opts[i] enabledby_posarg_negarg ";"; |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
if (flag_set_p("Param", flags[i]) && !(opts[i] ~ "^-param=")) |
| 155 |
print "#error Parameter option name '" opts[i] "' must start with '-param='" |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
print "/* This file is auto-generated by optc-gen.awk. */" |
| 160 |
print "" |
| 161 |
print "#define INCLUDE_MEMORY" |
| 162 |
n_headers = split(header_name, headers, " ") |
| 163 |
for (i = 1; i <= n_headers; i++) |
| 164 |
print "#include " quote headers[i] quote |
| 165 |
print "#include " quote "opts.h" quote |
| 166 |
print "#include " quote "intl.h" quote |
| 167 |
print "#include " quote "insn-attr-common.h" quote |
| 168 |
print "" |
| 169 |
|
| 170 |
if (n_extra_c_includes > 0) { |
| 171 |
for (i = 0; i < n_extra_c_includes; i++) { |
| 172 |
print "#include " quote extra_c_includes[i] quote |
| 173 |
} |
| 174 |
print "" |
| 175 |
} |
| 176 |
|
| 177 |
for (i = 0; i < n_enums; i++) { |
| 178 |
name = enum_names[i] |
| 179 |
type = enum_type[name] |
| 180 |
print "static const struct cl_enum_arg cl_enum_" name \ |
| 181 |
"_data[] = " |
| 182 |
print "{" |
| 183 |
print enum_data[name] " { NULL, 0, 0 }" |
| 184 |
print "};" |
| 185 |
print "" |
| 186 |
print "static void" |
| 187 |
print "cl_enum_" name "_set (void *var, int value)" |
| 188 |
print "{" |
| 189 |
print " *((" type " *) var) = (" type ") value;" |
| 190 |
print "}" |
| 191 |
print "" |
| 192 |
print "static int" |
| 193 |
print "cl_enum_" name "_get (const void *var)" |
| 194 |
print "{" |
| 195 |
print " return (int) *((const " type " *) var);" |
| 196 |
print "}" |
| 197 |
print "" |
| 198 |
} |
| 199 |
|
| 200 |
print "const struct cl_enum cl_enums[] =" |
| 201 |
print "{" |
| 202 |
for (i = 0; i < n_enums; i++) { |
| 203 |
name = enum_names[i] |
| 204 |
ehelp = enum_help[name] |
| 205 |
if (ehelp == "") |
| 206 |
ehelp = "NULL" |
| 207 |
else |
| 208 |
ehelp = quote ehelp quote |
| 209 |
unknown_error = enum_unknown_error[name] |
| 210 |
if (unknown_error == "") |
| 211 |
unknown_error = "NULL" |
| 212 |
else |
| 213 |
unknown_error = quote unknown_error quote |
| 214 |
print " {" |
| 215 |
print " " ehelp "," |
| 216 |
print " " unknown_error "," |
| 217 |
print " cl_enum_" name "_data," |
| 218 |
print " sizeof (" enum_type[name] ")," |
| 219 |
print " cl_enum_" name "_set," |
| 220 |
print " cl_enum_" name "_get" |
| 221 |
print " }," |
| 222 |
} |
| 223 |
print "};" |
| 224 |
print "const unsigned int cl_enums_count = " n_enums ";" |
| 225 |
print "" |
| 226 |
|
| 227 |
print "const struct gcc_options global_options_init =\n{" |
| 228 |
for (i = 0; i < n_extra_vars; i++) { |
| 229 |
var = extra_vars[i] |
| 230 |
init = extra_vars[i] |
| 231 |
if (var ~ "=" ) { |
| 232 |
sub(".*= *", "", init) |
| 233 |
} else { |
| 234 |
init = "0" |
| 235 |
} |
| 236 |
sub(" *=.*", "", var) |
| 237 |
name = var |
| 238 |
sub("^.*[ *]", "", name) |
| 239 |
sub("\\[.*\\]$", "", name) |
| 240 |
var_seen[name] = 1 |
| 241 |
print " " init ", /* " name " */" |
| 242 |
} |
| 243 |
for (i = 0; i < n_opts; i++) { |
| 244 |
name = var_name(flags[i]); |
| 245 |
init = opt_args("Init", flags[i]) |
| 246 |
|
| 247 |
if (name == "") { |
| 248 |
if (init != "") |
| 249 |
print "#error " opts[i] " must specify Var to use Init" |
| 250 |
continue; |
| 251 |
} |
| 252 |
|
| 253 |
if (init != "") { |
| 254 |
if (name in var_init && var_init[name] != init) |
| 255 |
print "#error multiple initializers for " name |
| 256 |
var_init[name] = init |
| 257 |
} |
| 258 |
} |
| 259 |
for (i = 0; i < n_opts; i++) { |
| 260 |
name = var_name(flags[i]); |
| 261 |
if (name == "") |
| 262 |
continue; |
| 263 |
|
| 264 |
if (name in var_seen) |
| 265 |
continue; |
| 266 |
|
| 267 |
if (name in var_init) |
| 268 |
init = var_init[name] |
| 269 |
else |
| 270 |
init = "0" |
| 271 |
|
| 272 |
print " " init ", /* " name " */" |
| 273 |
|
| 274 |
var_seen[name] = 1; |
| 275 |
} |
| 276 |
for (i = 0; i < n_opts; i++) { |
| 277 |
name = static_var(opts[i], flags[i]); |
| 278 |
if (name != "") { |
| 279 |
print " 0, /* " name " (private state) */" |
| 280 |
print "#undef x_" name |
| 281 |
} |
| 282 |
} |
| 283 |
for (i = 0; i < n_opts; i++) { |
| 284 |
if (flag_set_p("SetByCombined", flags[i])) |
| 285 |
print " false, /* frontend_set_" var_name(flags[i]) " */" |
| 286 |
} |
| 287 |
print "};" |
| 288 |
print "" |
| 289 |
print "struct gcc_options global_options;" |
| 290 |
print "struct gcc_options global_options_set;" |
| 291 |
print "" |
| 292 |
|
| 293 |
print "const char * const lang_names[] =\n{" |
| 294 |
for (i = 0; i < n_langs; i++) { |
| 295 |
macros[i] = "CL_" lang_sanitized_name(langs[i]) |
| 296 |
s = substr(" ", length (macros[i])) |
| 297 |
print " " quote langs[i] quote "," |
| 298 |
} |
| 299 |
|
| 300 |
print " 0\n};\n" |
| 301 |
print "const unsigned int cl_options_count = N_OPTS;\n" |
| 302 |
print "#if (1U << " n_langs ") > CL_MIN_OPTION_CLASS" |
| 303 |
print " #error the number of languages exceeds the implementation limit" |
| 304 |
print "#endif" |
| 305 |
print "const unsigned int cl_lang_count = " n_langs ";\n" |
| 306 |
|
| 307 |
print "const struct cl_option cl_options[] =\n{" |
| 308 |
|
| 309 |
j = 0 |
| 310 |
for (i = 0; i < n_opts; i++) { |
| 311 |
back_chain[i] = "N_OPTS"; |
| 312 |
indices[opts[i]] = j; |
| 313 |
# Combine the flags of identical switches. Switches |
| 314 |
# appear many times if they are handled by many front |
| 315 |
# ends, for example. |
| 316 |
while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
| 317 |
flags[i + 1] = flags[i] " " flags[i + 1]; |
| 318 |
if (help[i + 1] == "") |
| 319 |
help[i + 1] = help[i] |
| 320 |
else if (help[i] != "" && help[i + 1] != help[i]) { |
| 321 |
print "#error Multiple different help strings for " \ |
| 322 |
opts[i] ":" |
| 323 |
print "#error " help[i] |
| 324 |
print "#error " help[i + 1] |
| 325 |
} |
| 326 |
|
| 327 |
i++; |
| 328 |
back_chain[i] = "N_OPTS"; |
| 329 |
indices[opts[i]] = j; |
| 330 |
} |
| 331 |
j++; |
| 332 |
} |
| 333 |
|
| 334 |
optindex = 0 |
| 335 |
for (i = 0; i < n_opts; i++) { |
| 336 |
# With identical flags, pick only the last one. The |
| 337 |
# earlier loop ensured that it has all flags merged, |
| 338 |
# and a nonempty help text if one of the texts was nonempty. |
| 339 |
while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
| 340 |
i++; |
| 341 |
} |
| 342 |
|
| 343 |
len = length (opts[i]); |
| 344 |
enum = opt_enum(opts[i]) |
| 345 |
|
| 346 |
# Do not allow Joined and Separate properties if |
| 347 |
# an options ends with '='. |
| 348 |
if (flag_set_p("Joined", flags[i]) && flag_set_p("Separate", flags[i]) && opts[i] ~ "=$") { |
| 349 |
print "#error Option '" opts[i] "' ending with '=' cannot have " \ |
| 350 |
"both Joined and Separate properties" |
| 351 |
} |
| 352 |
|
| 353 |
# If this switch takes joined arguments, back-chain all |
| 354 |
# subsequent switches to it for which it is a prefix. If |
| 355 |
# a later switch S is a longer prefix of a switch T, T |
| 356 |
# will be back-chained to S in a later iteration of this |
| 357 |
# for() loop, which is what we want. |
| 358 |
if (flag_set_p("Joined.*", flags[i])) { |
| 359 |
for (j = i + 1; j < n_opts; j++) { |
| 360 |
if (substr (opts[j], 1, len) != opts[i]) |
| 361 |
break; |
| 362 |
back_chain[j] = enum; |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
s = substr(" ", length (opts[i])) |
| 367 |
if (i + 1 == n_opts) |
| 368 |
comma = "" |
| 369 |
|
| 370 |
if (help[i] == "") |
| 371 |
hlp = "NULL" |
| 372 |
else |
| 373 |
hlp = quote help[i] quote; |
| 374 |
|
| 375 |
missing_arg_error = opt_args("MissingArgError", flags[i]) |
| 376 |
if (missing_arg_error == "") |
| 377 |
missing_arg_error = "NULL" |
| 378 |
else |
| 379 |
missing_arg_error = quote missing_arg_error quote |
| 380 |
|
| 381 |
|
| 382 |
warn_message = opt_args("Warn", flags[i]) |
| 383 |
if (warn_message == "") |
| 384 |
warn_message = "NULL" |
| 385 |
else |
| 386 |
warn_message = quote warn_message quote |
| 387 |
|
| 388 |
alias_arg = opt_args("Alias", flags[i]) |
| 389 |
if (alias_arg == "") { |
| 390 |
if (flag_set_p("Ignore", flags[i])) { |
| 391 |
alias_data = "NULL, NULL, OPT_SPECIAL_ignore" |
| 392 |
if (warn_message != "NULL") |
| 393 |
print "#error Ignored option with Warn" |
| 394 |
if (var_name(flags[i]) != "") |
| 395 |
print "#error Ignored option with Var" |
| 396 |
} |
| 397 |
else if (flag_set_p("Deprecated", flags[i])) |
| 398 |
print "#error Deprecated was replaced with WarnRemoved" |
| 399 |
else if (flag_set_p("WarnRemoved", flags[i])) { |
| 400 |
alias_data = "NULL, NULL, OPT_SPECIAL_warn_removed" |
| 401 |
if (warn_message != "NULL") |
| 402 |
print "#error WarnRemoved option with Warn" |
| 403 |
} |
| 404 |
else |
| 405 |
alias_data = "NULL, NULL, N_OPTS" |
| 406 |
if (flag_set_p("Enum.*", flags[i])) { |
| 407 |
if (!flag_set_p("RejectNegative", flags[i]) \ |
| 408 |
&& !flag_set_p("EnumSet", flags[i]) \ |
| 409 |
&& !flag_set_p("EnumBitSet", flags[i]) \ |
| 410 |
&& opts[i] ~ "^[Wfgm]") |
| 411 |
print "#error Enum allowing negative form" |
| 412 |
} |
| 413 |
} else { |
| 414 |
alias_opt = nth_arg(0, alias_arg) |
| 415 |
alias_posarg = nth_arg(1, alias_arg) |
| 416 |
alias_negarg = nth_arg(2, alias_arg) |
| 417 |
|
| 418 |
if (var_ref(opts[i], flags[i]) != "(unsigned short) -1") |
| 419 |
print "#error Alias setting variable" |
| 420 |
|
| 421 |
if (alias_posarg != "" && alias_negarg == "") { |
| 422 |
if (!flag_set_p("RejectNegative", flags[i]) \ |
| 423 |
&& opts[i] ~ "^[Wfm]") |
| 424 |
print "#error Alias with single argument " \ |
| 425 |
"allowing negative form" |
| 426 |
} |
| 427 |
if (alias_posarg != "" \ |
| 428 |
&& flag_set_p("NegativeAlias", flags[i])) { |
| 429 |
print "#error Alias with multiple arguments " \ |
| 430 |
"used with NegativeAlias" |
| 431 |
} |
| 432 |
|
| 433 |
alias_opt = opt_enum(alias_opt) |
| 434 |
if (alias_posarg == "") |
| 435 |
alias_posarg = "NULL" |
| 436 |
else |
| 437 |
alias_posarg = quote alias_posarg quote |
| 438 |
if (alias_negarg == "") |
| 439 |
alias_negarg = "NULL" |
| 440 |
else |
| 441 |
alias_negarg = quote alias_negarg quote |
| 442 |
alias_data = alias_posarg ", " alias_negarg ", " alias_opt |
| 443 |
} |
| 444 |
|
| 445 |
neg = opt_args("Negative", flags[i]); |
| 446 |
if (neg != "") |
| 447 |
idx = indices[neg] |
| 448 |
else { |
| 449 |
if (flag_set_p("RejectNegative", flags[i])) |
| 450 |
idx = -1; |
| 451 |
else { |
| 452 |
if (opts[i] ~ "^[Wfgm]") |
| 453 |
idx = indices[opts[i]]; |
| 454 |
else |
| 455 |
idx = -1; |
| 456 |
} |
| 457 |
} |
| 458 |
# Split the printf after %u to work around an ia64-hp-hpux11.23 |
| 459 |
# awk bug. |
| 460 |
printf(" /* [%i] = */ {\n", optindex) |
| 461 |
printf(" %c-%s%c,\n %s,\n %s,\n %s,\n %s, %s, %u,", |
| 462 |
quote, opts[i], quote, hlp, missing_arg_error, warn_message, |
| 463 |
alias_data, back_chain[i], len) |
| 464 |
printf(" /* .neg_idx = */ %d,\n", idx) |
| 465 |
condition = opt_args("Condition", flags[i]) |
| 466 |
cl_flags = switch_flags(flags[i]) |
| 467 |
cl_bit_fields = switch_bit_fields(flags[i]) |
| 468 |
cl_zero_bit_fields = switch_bit_fields("") |
| 469 |
if (condition != "") |
| 470 |
printf("#if %s\n" \ |
| 471 |
" %s,\n" \ |
| 472 |
" 0, %s,\n" \ |
| 473 |
"#else\n" \ |
| 474 |
" 0,\n" \ |
| 475 |
" 1 /* Disabled. */, %s,\n" \ |
| 476 |
"#endif\n", |
| 477 |
condition, cl_flags, cl_bit_fields, cl_zero_bit_fields) |
| 478 |
else |
| 479 |
printf(" %s,\n" \ |
| 480 |
" 0, %s,\n", |
| 481 |
cl_flags, cl_bit_fields) |
| 482 |
printf(" %s, %s, %s }%s\n", var_ref(opts[i], flags[i]), |
| 483 |
var_set(flags[i]), integer_range_info(opt_args("IntegerRange", flags[i]), |
| 484 |
opt_args("Init", flags[i]), opts[i], flag_set_p("UInteger", flags[i])), comma) |
| 485 |
|
| 486 |
# Bump up the informational option index. |
| 487 |
++optindex |
| 488 |
} |
| 489 |
|
| 490 |
print "};" |
| 491 |
|
| 492 |
print "\n\n" |
| 493 |
print "bool " |
| 494 |
print "common_handle_option_auto (struct gcc_options *opts, " |
| 495 |
print " struct gcc_options *opts_set, " |
| 496 |
print " const struct cl_decoded_option *decoded, " |
| 497 |
print " unsigned int lang_mask, int kind, " |
| 498 |
print " location_t loc, " |
| 499 |
print " const struct cl_option_handlers *handlers, " |
| 500 |
print " diagnostic_context *dc) " |
| 501 |
print "{ " |
| 502 |
print " size_t scode = decoded->opt_index; " |
| 503 |
print " HOST_WIDE_INT value = decoded->value; " |
| 504 |
print " enum opt_code code = (enum opt_code) scode; " |
| 505 |
print " " |
| 506 |
print " gcc_assert (decoded->canonical_option_num_elements <= 2); " |
| 507 |
print " " |
| 508 |
print " switch (code) " |
| 509 |
print " { " |
| 510 |
# Handle EnabledBy |
| 511 |
for (i = 0; i < n_enabledby; i++) { |
| 512 |
enabledby_name = enabledby[i]; |
| 513 |
print " case " opt_enum(enabledby_name) ":" |
| 514 |
n_enables = split(enables[enabledby_name], thisenable, ";"); |
| 515 |
n_enablesif = split(enablesif[enabledby_name], thisenableif, ";"); |
| 516 |
if (n_enables != n_enablesif) { |
| 517 |
print "#error n_enables != n_enablesif: Something went wrong!" |
| 518 |
} |
| 519 |
for (j = 1; j < n_enables; j++) { |
| 520 |
opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]); |
| 521 |
if (opt_var_name != "") { |
| 522 |
condition = "!opts_set->x_" opt_var_name |
| 523 |
if (thisenableif[j] != "") { |
| 524 |
value = "(" thisenableif[j] ")" |
| 525 |
} else { |
| 526 |
value = "value" |
| 527 |
} |
| 528 |
print " if (" condition ")" |
| 529 |
print " handle_generated_option (opts, opts_set," |
| 530 |
print " " opt_enum(thisenable[j]) ", NULL, " value "," |
| 531 |
print " lang_mask, kind, loc, handlers, true, dc);" |
| 532 |
} else { |
| 533 |
print "#error " thisenable[j] " does not have a Var() flag" |
| 534 |
} |
| 535 |
} |
| 536 |
print " break;\n" |
| 537 |
} |
| 538 |
print " default: " |
| 539 |
print " break; " |
| 540 |
print " } " |
| 541 |
print " return true; " |
| 542 |
print "} " |
| 543 |
|
| 544 |
# Handle LangEnabledBy |
| 545 |
for (i = 0; i < n_langs; i++) { |
| 546 |
lang_name = lang_sanitized_name(langs[i]); |
| 547 |
mark_unused = " ATTRIBUTE_UNUSED"; |
| 548 |
|
| 549 |
print "\n\n" |
| 550 |
print "bool " |
| 551 |
print lang_name "_handle_option_auto (struct gcc_options *opts" mark_unused ", " |
| 552 |
print " struct gcc_options *opts_set" mark_unused ", " |
| 553 |
print " size_t scode" mark_unused ", const char *arg" mark_unused ", HOST_WIDE_INT value" mark_unused ", " |
| 554 |
print " unsigned int lang_mask" mark_unused ", int kind" mark_unused ", " |
| 555 |
print " location_t loc" mark_unused ", " |
| 556 |
print " const struct cl_option_handlers *handlers" mark_unused ", " |
| 557 |
print " diagnostic_context *dc" mark_unused ") " |
| 558 |
print "{ " |
| 559 |
print " enum opt_code code = (enum opt_code) scode; " |
| 560 |
print " " |
| 561 |
print " switch (code) " |
| 562 |
print " { " |
| 563 |
|
| 564 |
for (k = 0; k < n_enabledby_lang[i]; k++) { |
| 565 |
enabledby_name = enabledby[lang_name,k]; |
| 566 |
print " case " opt_enum(enabledby_name) ":" |
| 567 |
n_thisenable = split(enables[lang_name,enabledby_name], thisenable, ";"); |
| 568 |
for (j = 1; j < n_thisenable; j++) { |
| 569 |
n_thisenable_args = split(thisenable[j], thisenable_args, ","); |
| 570 |
if (n_thisenable_args == 1) { |
| 571 |
thisenable_opt = thisenable[j]; |
| 572 |
value = "value"; |
| 573 |
} else { |
| 574 |
thisenable_opt = thisenable_args[1]; |
| 575 |
with_posarg = thisenable_args[2]; |
| 576 |
with_negarg = thisenable_args[3]; |
| 577 |
value = "value ? " with_posarg " : " with_negarg; |
| 578 |
} |
| 579 |
opt_var_name = var_name(flags[opt_numbers[thisenable_opt]]); |
| 580 |
if (opt_var_name != "") { |
| 581 |
print " if (!opts_set->x_" opt_var_name ")" |
| 582 |
print " handle_generated_option (opts, opts_set," |
| 583 |
print " " opt_enum(thisenable_opt) ", NULL, " value "," |
| 584 |
print " lang_mask, kind, loc, handlers, true, dc);" |
| 585 |
} else { |
| 586 |
print "#error " thisenable_opt " does not have a Var() flag" |
| 587 |
} |
| 588 |
} |
| 589 |
print " break;\n" |
| 590 |
} |
| 591 |
print " default: " |
| 592 |
print " break; " |
| 593 |
print " } " |
| 594 |
print " return true; " |
| 595 |
print "} " |
| 596 |
} |
| 597 |
|
| 598 |
#Handle CPP() |
| 599 |
print "\n" |
| 600 |
print "#include " quote "cpplib.h" quote; |
| 601 |
print "void" |
| 602 |
print "cpp_handle_option_auto (const struct gcc_options * opts, " |
| 603 |
print " size_t scode, struct cpp_options * cpp_opts)" |
| 604 |
print "{ " |
| 605 |
print " enum opt_code code = (enum opt_code) scode; " |
| 606 |
print " " |
| 607 |
print " switch (code) " |
| 608 |
print " { " |
| 609 |
for (i = 0; i < n_opts; i++) { |
| 610 |
# With identical flags, pick only the last one. The |
| 611 |
# earlier loop ensured that it has all flags merged, |
| 612 |
# and a nonempty help text if one of the texts was nonempty. |
| 613 |
while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
| 614 |
i++; |
| 615 |
} |
| 616 |
|
| 617 |
cpp_option = nth_arg(0, opt_args("CPP", flags[i])); |
| 618 |
if (cpp_option != "") { |
| 619 |
opt_var_name = var_name(flags[i]); |
| 620 |
init = opt_args("Init", flags[i]) |
| 621 |
if (opt_var_name != "" && init != "") { |
| 622 |
print " case " opt_enum(opts[i]) ":" |
| 623 |
print " cpp_opts->" cpp_option " = opts->x_" opt_var_name ";" |
| 624 |
print " break;" |
| 625 |
} else if (opt_var_name == "" && init == "") { |
| 626 |
print "#error CPP() requires setting Init() and Var() for " opts[i] |
| 627 |
} else if (opt_var_name != "") { |
| 628 |
print "#error CPP() requires setting Init() for " opts[i] |
| 629 |
} else { |
| 630 |
print "#error CPP() requires setting Var() for " opts[i] |
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
print " default: " |
| 635 |
print " break; " |
| 636 |
print " } " |
| 637 |
print "}\n" |
| 638 |
print "void" |
| 639 |
print "init_global_opts_from_cpp(struct gcc_options * opts, " |
| 640 |
print " const struct cpp_options * cpp_opts)" |
| 641 |
print "{ " |
| 642 |
for (i = 0; i < n_opts; i++) { |
| 643 |
# With identical flags, pick only the last one. The |
| 644 |
# earlier loop ensured that it has all flags merged, |
| 645 |
# and a nonempty help text if one of the texts was nonempty. |
| 646 |
while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
| 647 |
i++; |
| 648 |
} |
| 649 |
cpp_option = nth_arg(0, opt_args("CPP", flags[i])); |
| 650 |
opt_var_name = var_name(flags[i]); |
| 651 |
if (cpp_option != "" && opt_var_name != "") { |
| 652 |
print " opts->x_" opt_var_name " = cpp_opts->" cpp_option ";" |
| 653 |
} |
| 654 |
} |
| 655 |
print "} " |
| 656 |
|
| 657 |
split("", var_seen, ":") |
| 658 |
print "\n#if !defined(GENERATOR_FILE) && defined(ENABLE_PLUGIN)" |
| 659 |
print "DEBUG_VARIABLE const struct cl_var cl_vars[] =\n{" |
| 660 |
|
| 661 |
for (i = 0; i < n_opts; i++) { |
| 662 |
name = var_name(flags[i]); |
| 663 |
if (name == "") |
| 664 |
continue; |
| 665 |
var_seen[name] = 1; |
| 666 |
} |
| 667 |
|
| 668 |
for (i = 0; i < n_extra_vars; i++) { |
| 669 |
var = extra_vars[i] |
| 670 |
sub(" *=.*", "", var) |
| 671 |
name = var |
| 672 |
sub("^.*[ *]", "", name) |
| 673 |
sub("\\[.*\\]$", "", name) |
| 674 |
if (name in var_seen) |
| 675 |
continue; |
| 676 |
print " { " quote name quote ", offsetof (struct gcc_options, x_" name ") }," |
| 677 |
var_seen[name] = 1 |
| 678 |
} |
| 679 |
|
| 680 |
print " { NULL, (unsigned short) -1 }\n};\n#endif" |
| 681 |
|
| 682 |
} |