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