]> git.ipfire.org Git - people/ms/gcc.git/blame - gcc/optc-gen.awk
c++: namespace-scoped friend in local class [PR69410]
[people/ms/gcc.git] / gcc / optc-gen.awk
CommitLineData
aeee4812 1# Copyright (C) 2003-2023 Free Software Foundation, Inc.
776dc15d
KC
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
9dcd6f09 7# Free Software Foundation; either version 3, or (at your option) any
776dc15d
KC
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
9dcd6f09
NC
16# along with this program; see the file COPYING3. If not see
17# <http://www.gnu.org/licenses/>.
776dc15d
KC
18
19# This Awk script reads in the option records generated from
fc54bc84 20# opt-gather.awk, combines the flags of duplicate options and generates a
776dc15d
KC
21# C file.
22#
86fa5de4
JM
23
24# This program uses functions from opt-functions.awk and code from
25# opt-read.awk.
776dc15d 26#
86fa5de4 27# Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-gen.awk \
e53b6e56 28# [-v header_name=header.h] < inputfile > options.cc
776dc15d 29
776dc15d
KC
30# Dump that array of options into a C file.
31END {
f2bc201f 32
c2d89095
MLI
33
34# Combine the flags of identical switches. Switches
35# appear many times if they are handled by many front
36# ends, for example.
37for (i = 0; i < n_opts; i++) {
38 merged_flags[i] = flags[i]
39}
40for (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.
f2bc201f
MLI
48n_enabledby = 0;
49for (i = 0; i < n_langs; i++) {
50 n_enabledby_lang[i] = 0;
51}
52for (i = 0; i < n_opts; i++) {
53 enabledby_arg = opt_args("EnabledBy", flags[i]);
54 if (enabledby_arg != "") {
27e51192
TB
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) {
c2d89095 65 print "#error " opts[i] " EnabledBy(Wfoo && Wbar && Wbaz) currently not supported"
d919140b
MLI
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 == "") {
c2d89095
MLI
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 = "";
27e51192 78 if (logical_and != 0) {
d919140b
MLI
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 ";";
f2bc201f 95 }
f2bc201f
MLI
96 }
97 }
98
99 enabledby_arg = opt_args("LangEnabledBy", flags[i]);
100 if (enabledby_arg != "") {
d8e91994
TS
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 }
f2bc201f 152 }
bafcf452
ML
153
154 if (flag_set_p("Param", flags[i]) && !(opts[i] ~ "^-param="))
155 print "#error Parameter option name '" opts[i] "' must start with '-param='"
f2bc201f
MLI
156}
157
158
af47e6ac 159print "/* This file is auto-generated by optc-gen.awk. */"
776dc15d 160print ""
aeb70e78
RS
161n_headers = split(header_name, headers, " ")
162for (i = 1; i <= n_headers; i++)
163 print "#include " quote headers[i] quote
776dc15d 164print "#include " quote "opts.h" quote
fb664b5a 165print "#include " quote "intl.h" quote
c344a866 166print "#include " quote "insn-attr-common.h" quote
776dc15d
KC
167print ""
168
fd438373
MM
169if (n_extra_c_includes > 0) {
170 for (i = 0; i < n_extra_c_includes; i++) {
171 print "#include " quote extra_c_includes[i] quote
172 }
173 print ""
174}
175
e6d4b984
JM
176for (i = 0; i < n_enums; i++) {
177 name = enum_names[i]
178 type = enum_type[name]
179 print "static const struct cl_enum_arg cl_enum_" name \
180 "_data[] = "
181 print "{"
182 print enum_data[name] " { NULL, 0, 0 }"
183 print "};"
184 print ""
185 print "static void"
186 print "cl_enum_" name "_set (void *var, int value)"
187 print "{"
188 print " *((" type " *) var) = (" type ") value;"
189 print "}"
190 print ""
191 print "static int"
192 print "cl_enum_" name "_get (const void *var)"
193 print "{"
194 print " return (int) *((const " type " *) var);"
195 print "}"
196 print ""
197}
198
199print "const struct cl_enum cl_enums[] ="
200print "{"
201for (i = 0; i < n_enums; i++) {
202 name = enum_names[i]
203 ehelp = enum_help[name]
204 if (ehelp == "")
205 ehelp = "NULL"
206 else
207 ehelp = quote ehelp quote
208 unknown_error = enum_unknown_error[name]
209 if (unknown_error == "")
210 unknown_error = "NULL"
211 else
212 unknown_error = quote unknown_error quote
213 print " {"
214 print " " ehelp ","
215 print " " unknown_error ","
216 print " cl_enum_" name "_data,"
217 print " sizeof (" enum_type[name] "),"
218 print " cl_enum_" name "_set,"
219 print " cl_enum_" name "_get"
220 print " },"
221}
222print "};"
223print "const unsigned int cl_enums_count = " n_enums ";"
224print ""
225
a75bfaa6 226print "const struct gcc_options global_options_init =\n{"
e90afde6 227for (i = 0; i < n_extra_vars; i++) {
e3339d0f
JM
228 var = extra_vars[i]
229 init = extra_vars[i]
230 if (var ~ "=" ) {
231 sub(".*= *", "", init)
e3339d0f
JM
232 } else {
233 init = "0"
234 }
24f48c2f
JM
235 sub(" *=.*", "", var)
236 name = var
237 sub("^.*[ *]", "", name)
238 sub("\\[.*\\]$", "", name)
239 var_seen[name] = 1
240 print " " init ", /* " name " */"
e90afde6 241}
776dc15d
KC
242for (i = 0; i < n_opts; i++) {
243 name = var_name(flags[i]);
c5230519
TS
244 init = opt_args("Init", flags[i])
245
246 if (name == "") {
247 if (init != "")
248 print "#error " opts[i] " must specify Var to use Init"
776dc15d 249 continue;
c5230519 250 }
776dc15d 251
e3339d0f
JM
252 if (init != "") {
253 if (name in var_init && var_init[name] != init)
254 print "#error multiple initializers for " name
255 var_init[name] = init
14c7833c 256 }
e3339d0f
JM
257}
258for (i = 0; i < n_opts; i++) {
259 name = var_name(flags[i]);
260 if (name == "")
261 continue;
262
263 if (name in var_seen)
264 continue;
265
266 if (name in var_init)
267 init = var_init[name]
268 else
269 init = "0"
a56a0779 270
e3339d0f 271 print " " init ", /* " name " */"
f7f655c7
DD
272
273 var_seen[name] = 1;
a56a0779 274}
ee133b69
RS
275for (i = 0; i < n_opts; i++) {
276 name = static_var(opts[i], flags[i]);
46625112
JM
277 if (name != "") {
278 print " 0, /* " name " (private state) */"
279 print "#undef x_" name
280 }
ee133b69 281}
5e46b0c6
ILT
282for (i = 0; i < n_opts; i++) {
283 if (flag_set_p("SetByCombined", flags[i]))
284 print " false, /* frontend_set_" var_name(flags[i]) " */"
285}
46625112 286print "};"
ee133b69 287print ""
a75bfaa6 288print "struct gcc_options global_options;"
d4d24ba4
JM
289print "struct gcc_options global_options_set;"
290print ""
776dc15d
KC
291
292print "const char * const lang_names[] =\n{"
293for (i = 0; i < n_langs; i++) {
f2bc201f 294 macros[i] = "CL_" lang_sanitized_name(langs[i])
776dc15d
KC
295 s = substr(" ", length (macros[i]))
296 print " " quote langs[i] quote ","
297 }
298
299print " 0\n};\n"
300print "const unsigned int cl_options_count = N_OPTS;\n"
58265ea6
GF
301print "#if (1U << " n_langs ") > CL_MIN_OPTION_CLASS"
302print " #error the number of languages exceeds the implementation limit"
303print "#endif"
c662432e 304print "const unsigned int cl_lang_count = " n_langs ";\n"
776dc15d
KC
305
306print "const struct cl_option cl_options[] =\n{"
307
14c7833c
L
308j = 0
309for (i = 0; i < n_opts; i++) {
776dc15d 310 back_chain[i] = "N_OPTS";
14c7833c
L
311 indices[opts[i]] = j;
312 # Combine the flags of identical switches. Switches
313 # appear many times if they are handled by many front
314 # ends, for example.
315 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
316 flags[i + 1] = flags[i] " " flags[i + 1];
a16d1645
RW
317 if (help[i + 1] == "")
318 help[i + 1] = help[i]
6c0e2645 319 else if (help[i] != "" && help[i + 1] != help[i]) {
71caddc5 320 print "#error Multiple different help strings for " \
6c0e2645
TS
321 opts[i] ":"
322 print "#error " help[i]
323 print "#error " help[i + 1]
324 }
71caddc5 325
14c7833c
L
326 i++;
327 back_chain[i] = "N_OPTS";
328 indices[opts[i]] = j;
329 }
330 j++;
331}
776dc15d 332
00abf86c 333optindex = 0
b167666c 334for (i = 0; i < n_opts; i++) {
a16d1645
RW
335 # With identical flags, pick only the last one. The
336 # earlier loop ensured that it has all flags merged,
337 # and a nonempty help text if one of the texts was nonempty.
b167666c 338 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
b167666c
RS
339 i++;
340 }
776dc15d 341
b167666c 342 len = length (opts[i]);
9db94baa 343 enum = opt_enum(opts[i])
b167666c 344
9e1e962e
ML
345 # Do not allow Joined and Separate properties if
346 # an options ends with '='.
347 if (flag_set_p("Joined", flags[i]) && flag_set_p("Separate", flags[i]) && opts[i] ~ "=$") {
348 print "#error Option '" opts[i] "' ending with '=' cannot have " \
349 "both Joined and Separate properties"
350 }
351
b167666c
RS
352 # If this switch takes joined arguments, back-chain all
353 # subsequent switches to it for which it is a prefix. If
354 # a later switch S is a longer prefix of a switch T, T
355 # will be back-chained to S in a later iteration of this
356 # for() loop, which is what we want.
357 if (flag_set_p("Joined.*", flags[i])) {
358 for (j = i + 1; j < n_opts; j++) {
359 if (substr (opts[j], 1, len) != opts[i])
360 break;
361 back_chain[j] = enum;
776dc15d 362 }
b167666c 363 }
776dc15d 364
b167666c
RS
365 s = substr(" ", length (opts[i]))
366 if (i + 1 == n_opts)
367 comma = ""
776dc15d 368
b167666c 369 if (help[i] == "")
00abf86c 370 hlp = "NULL"
b167666c
RS
371 else
372 hlp = quote help[i] quote;
776dc15d 373
61ff2bdc
JM
374 missing_arg_error = opt_args("MissingArgError", flags[i])
375 if (missing_arg_error == "")
00abf86c 376 missing_arg_error = "NULL"
61ff2bdc
JM
377 else
378 missing_arg_error = quote missing_arg_error quote
379
2d2bd949
JM
380
381 warn_message = opt_args("Warn", flags[i])
382 if (warn_message == "")
00abf86c 383 warn_message = "NULL"
2d2bd949
JM
384 else
385 warn_message = quote warn_message quote
386
5de8299c
JM
387 alias_arg = opt_args("Alias", flags[i])
388 if (alias_arg == "") {
c0c12356
ML
389 if (flag_set_p("Ignore", flags[i])) {
390 alias_data = "NULL, NULL, OPT_SPECIAL_ignore"
391 if (warn_message != "NULL")
392 print "#error Ignored option with Warn"
393 if (var_name(flags[i]) != "")
394 print "#error Ignored option with Var"
c0c12356 395 }
68a57628
ML
396 else if (flag_set_p("Deprecated", flags[i]))
397 print "#error Deprecated was replaced with WarnRemoved"
398 else if (flag_set_p("WarnRemoved", flags[i])) {
399 alias_data = "NULL, NULL, OPT_SPECIAL_warn_removed"
c0c12356 400 if (warn_message != "NULL")
68a57628 401 print "#error WarnRemoved option with Warn"
c0c12356 402 }
2d2bd949
JM
403 else
404 alias_data = "NULL, NULL, N_OPTS"
742b1804
JJ
405 if (flag_set_p("Enum.*", flags[i])) {
406 if (!flag_set_p("RejectNegative", flags[i]) \
385196ad 407 && !flag_set_p("EnumSet", flags[i]) \
0ebb09f5 408 && !flag_set_p("EnumBitSet", flags[i]) \
9ed32e27 409 && opts[i] ~ "^[Wfgm]")
742b1804
JJ
410 print "#error Enum allowing negative form"
411 }
5de8299c
JM
412 } else {
413 alias_opt = nth_arg(0, alias_arg)
414 alias_posarg = nth_arg(1, alias_arg)
415 alias_negarg = nth_arg(2, alias_arg)
416
f6b3ca5a 417 if (var_ref(opts[i], flags[i]) != "(unsigned short) -1")
5de8299c
JM
418 print "#error Alias setting variable"
419
420 if (alias_posarg != "" && alias_negarg == "") {
421 if (!flag_set_p("RejectNegative", flags[i]) \
422 && opts[i] ~ "^[Wfm]")
423 print "#error Alias with single argument " \
424 "allowing negative form"
425 }
666a21a2
JM
426 if (alias_posarg != "" \
427 && flag_set_p("NegativeAlias", flags[i])) {
428 print "#error Alias with multiple arguments " \
429 "used with NegativeAlias"
430 }
5de8299c
JM
431
432 alias_opt = opt_enum(alias_opt)
433 if (alias_posarg == "")
434 alias_posarg = "NULL"
435 else
436 alias_posarg = quote alias_posarg quote
437 if (alias_negarg == "")
438 alias_negarg = "NULL"
439 else
440 alias_negarg = quote alias_negarg quote
441 alias_data = alias_posarg ", " alias_negarg ", " alias_opt
442 }
443
14c7833c
L
444 neg = opt_args("Negative", flags[i]);
445 if (neg != "")
446 idx = indices[neg]
447 else {
448 if (flag_set_p("RejectNegative", flags[i]))
449 idx = -1;
450 else {
9ed32e27 451 if (opts[i] ~ "^[Wfgm]")
14c7833c
L
452 idx = indices[opts[i]];
453 else
454 idx = -1;
455 }
456 }
b1c61c7e
RW
457 # Split the printf after %u to work around an ia64-hp-hpux11.23
458 # awk bug.
00abf86c
MS
459 printf(" /* [%i] = */ {\n", optindex)
460 printf(" %c-%s%c,\n %s,\n %s,\n %s,\n %s, %s, %u,",
2d2bd949 461 quote, opts[i], quote, hlp, missing_arg_error, warn_message,
5de8299c 462 alias_data, back_chain[i], len)
00abf86c 463 printf(" /* .neg_idx = */ %d,\n", idx)
aeb70e78
RS
464 condition = opt_args("Condition", flags[i])
465 cl_flags = switch_flags(flags[i])
300d83d9
JM
466 cl_bit_fields = switch_bit_fields(flags[i])
467 cl_zero_bit_fields = switch_bit_fields("")
aeb70e78
RS
468 if (condition != "")
469 printf("#if %s\n" \
470 " %s,\n" \
300d83d9 471 " 0, %s,\n" \
aeb70e78 472 "#else\n" \
300d83d9
JM
473 " 0,\n" \
474 " 1 /* Disabled. */, %s,\n" \
aeb70e78 475 "#endif\n",
300d83d9 476 condition, cl_flags, cl_bit_fields, cl_zero_bit_fields)
aeb70e78 477 else
300d83d9
JM
478 printf(" %s,\n" \
479 " 0, %s,\n",
480 cl_flags, cl_bit_fields)
63010089 481 printf(" %s, %s, %s }%s\n", var_ref(opts[i], flags[i]),
e88a9384 482 var_set(flags[i]), integer_range_info(opt_args("IntegerRange", flags[i]),
679652a7 483 opt_args("Init", flags[i]), opts[i], flag_set_p("UInteger", flags[i])), comma)
00abf86c
MS
484
485 # Bump up the informational option index.
486 ++optindex
487 }
776dc15d
KC
488
489print "};"
ab442df7 490
7d5a5747
MLI
491print "\n\n"
492print "bool "
493print "common_handle_option_auto (struct gcc_options *opts, "
494print " struct gcc_options *opts_set, "
495print " const struct cl_decoded_option *decoded, "
496print " unsigned int lang_mask, int kind, "
497print " location_t loc, "
498print " const struct cl_option_handlers *handlers, "
499print " diagnostic_context *dc) "
500print "{ "
501print " size_t scode = decoded->opt_index; "
00abf86c 502print " HOST_WIDE_INT value = decoded->value; "
7d5a5747
MLI
503print " enum opt_code code = (enum opt_code) scode; "
504print " "
505print " gcc_assert (decoded->canonical_option_num_elements <= 2); "
506print " "
507print " switch (code) "
508print " { "
d919140b 509# Handle EnabledBy
7d5a5747
MLI
510for (i = 0; i < n_enabledby; i++) {
511 enabledby_name = enabledby[i];
512 print " case " opt_enum(enabledby_name) ":"
65d4f2cd 513 n_enables = split(enables[enabledby_name], thisenable, ";");
d919140b
MLI
514 n_enablesif = split(enablesif[enabledby_name], thisenableif, ";");
515 if (n_enables != n_enablesif) {
516 print "#error n_enables != n_enablesif: Something went wrong!"
517 }
7d5a5747
MLI
518 for (j = 1; j < n_enables; j++) {
519 opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]);
9b095bf1 520 if (opt_var_name != "") {
d919140b
MLI
521 condition = "!opts_set->x_" opt_var_name
522 if (thisenableif[j] != "") {
a82122df
MK
523 value = "(" thisenableif[j] ")"
524 } else {
525 value = "value"
d919140b
MLI
526 }
527 print " if (" condition ")"
9b095bf1 528 print " handle_generated_option (opts, opts_set,"
a82122df 529 print " " opt_enum(thisenable[j]) ", NULL, " value ","
b9822443 530 print " lang_mask, kind, loc, handlers, true, dc);"
9b095bf1
MLI
531 } else {
532 print "#error " thisenable[j] " does not have a Var() flag"
533 }
7d5a5747
MLI
534 }
535 print " break;\n"
7d5a5747
MLI
536}
537print " default: "
538print " break; "
539print " } "
540print " return true; "
541print "} "
542
f2bc201f
MLI
543# Handle LangEnabledBy
544for (i = 0; i < n_langs; i++) {
545 lang_name = lang_sanitized_name(langs[i]);
546 mark_unused = " ATTRIBUTE_UNUSED";
547
548 print "\n\n"
549 print "bool "
550 print lang_name "_handle_option_auto (struct gcc_options *opts" mark_unused ", "
551 print " struct gcc_options *opts_set" mark_unused ", "
00abf86c 552 print " size_t scode" mark_unused ", const char *arg" mark_unused ", HOST_WIDE_INT value" mark_unused ", "
f2bc201f
MLI
553 print " unsigned int lang_mask" mark_unused ", int kind" mark_unused ", "
554 print " location_t loc" mark_unused ", "
555 print " const struct cl_option_handlers *handlers" mark_unused ", "
556 print " diagnostic_context *dc" mark_unused ") "
557 print "{ "
558 print " enum opt_code code = (enum opt_code) scode; "
559 print " "
560 print " switch (code) "
561 print " { "
562
563 for (k = 0; k < n_enabledby_lang[i]; k++) {
564 enabledby_name = enabledby[lang_name,k];
565 print " case " opt_enum(enabledby_name) ":"
65d4f2cd
MLI
566 n_thisenable = split(enables[lang_name,enabledby_name], thisenable, ";");
567 for (j = 1; j < n_thisenable; j++) {
568 n_thisenable_args = split(thisenable[j], thisenable_args, ",");
569 if (n_thisenable_args == 1) {
570 thisenable_opt = thisenable[j];
571 value = "value";
572 } else {
573 thisenable_opt = thisenable_args[1];
574 with_posarg = thisenable_args[2];
575 with_negarg = thisenable_args[3];
576 value = "value ? " with_posarg " : " with_negarg;
577 }
578 opt_var_name = var_name(flags[opt_numbers[thisenable_opt]]);
9b095bf1
MLI
579 if (opt_var_name != "") {
580 print " if (!opts_set->x_" opt_var_name ")"
581 print " handle_generated_option (opts, opts_set,"
65d4f2cd 582 print " " opt_enum(thisenable_opt) ", NULL, " value ","
b9822443 583 print " lang_mask, kind, loc, handlers, true, dc);"
9b095bf1 584 } else {
65d4f2cd 585 print "#error " thisenable_opt " does not have a Var() flag"
9b095bf1 586 }
f2bc201f
MLI
587 }
588 print " break;\n"
589 }
590 print " default: "
591 print " break; "
592 print " } "
593 print " return true; "
594 print "} "
595}
596
43f9a13c
MLI
597#Handle CPP()
598print "\n"
599print "#include " quote "cpplib.h" quote;
600print "void"
601print "cpp_handle_option_auto (const struct gcc_options * opts, "
602print " size_t scode, struct cpp_options * cpp_opts)"
603print "{ "
604print " enum opt_code code = (enum opt_code) scode; "
605print " "
606print " switch (code) "
607print " { "
608for (i = 0; i < n_opts; i++) {
609 # With identical flags, pick only the last one. The
610 # earlier loop ensured that it has all flags merged,
611 # and a nonempty help text if one of the texts was nonempty.
612 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
613 i++;
614 }
615
616 cpp_option = nth_arg(0, opt_args("CPP", flags[i]));
2b71f4a4
MLI
617 if (cpp_option != "") {
618 opt_var_name = var_name(flags[i]);
619 init = opt_args("Init", flags[i])
620 if (opt_var_name != "" && init != "") {
621 print " case " opt_enum(opts[i]) ":"
622 print " cpp_opts->" cpp_option " = opts->x_" opt_var_name ";"
623 print " break;"
624 } else if (opt_var_name == "" && init == "") {
625 print "#error CPP() requires setting Init() and Var() for " opts[i]
626 } else if (opt_var_name != "") {
627 print "#error CPP() requires setting Init() for " opts[i]
628 } else {
629 print "#error CPP() requires setting Var() for " opts[i]
630 }
43f9a13c 631 }
776dc15d 632}
43f9a13c
MLI
633print " default: "
634print " break; "
635print " } "
636print "}\n"
637print "void"
638print "init_global_opts_from_cpp(struct gcc_options * opts, "
639print " const struct cpp_options * cpp_opts)"
640print "{ "
641for (i = 0; i < n_opts; i++) {
642 # With identical flags, pick only the last one. The
643 # earlier loop ensured that it has all flags merged,
644 # and a nonempty help text if one of the texts was nonempty.
645 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
646 i++;
647 }
648 cpp_option = nth_arg(0, opt_args("CPP", flags[i]));
649 opt_var_name = var_name(flags[i]);
650 if (cpp_option != "" && opt_var_name != "") {
651 print " opts->x_" opt_var_name " = cpp_opts->" cpp_option ";"
652 }
653}
654print "} "
655
84e0549c
JJ
656split("", var_seen, ":")
657print "\n#if !defined(GENERATOR_FILE) && defined(ENABLE_PLUGIN)"
658print "DEBUG_VARIABLE const struct cl_var cl_vars[] =\n{"
659
660for (i = 0; i < n_opts; i++) {
661 name = var_name(flags[i]);
662 if (name == "")
663 continue;
664 var_seen[name] = 1;
43f9a13c
MLI
665}
666
84e0549c
JJ
667for (i = 0; i < n_extra_vars; i++) {
668 var = extra_vars[i]
669 sub(" *=.*", "", var)
670 name = var
671 sub("^.*[ *]", "", name)
672 sub("\\[.*\\]$", "", name)
673 if (name in var_seen)
674 continue;
675 print " { " quote name quote ", offsetof (struct gcc_options, x_" name ") },"
676 var_seen[name] = 1
677}
678
679print " { NULL, (unsigned short) -1 }\n};\n#endif"
680
681}