]>
Commit | Line | Data |
---|---|---|
3aea1f79 | 1 | # Copyright (C) 2003-2014 Free Software Foundation, Inc. |
e8b212b8 | 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 | |
8c4c00c1 | 7 | # Free Software Foundation; either version 3, or (at your option) any |
e8b212b8 | 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 | |
8c4c00c1 | 16 | # along with this program; see the file COPYING3. If not see |
17 | # <http://www.gnu.org/licenses/>. | |
e8b212b8 | 18 | |
19 | # This Awk script reads in the option records generated from | |
63433b97 | 20 | # opt-gather.awk, combines the flags of duplicate options and generates a |
e8b212b8 | 21 | # C file. |
22 | # | |
1e127302 | 23 | |
24 | # This program uses functions from opt-functions.awk and code from | |
25 | # opt-read.awk. | |
e8b212b8 | 26 | # |
1e127302 | 27 | # Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-gen.awk \ |
e8b212b8 | 28 | # [-v header_name=header.h] < inputfile > options.c |
29 | ||
e8b212b8 | 30 | # Dump that array of options into a C file. |
31 | END { | |
d3b7ee7c | 32 | |
33 | # Record first EnabledBy and LangEnabledBy uses. | |
34 | n_enabledby = 0; | |
35 | for (i = 0; i < n_langs; i++) { | |
36 | n_enabledby_lang[i] = 0; | |
37 | } | |
38 | for (i = 0; i < n_opts; i++) { | |
39 | enabledby_arg = opt_args("EnabledBy", flags[i]); | |
40 | if (enabledby_arg != "") { | |
1090f26f | 41 | n_enabledby_names = split(enabledby_arg, enabledby_names, " && "); |
42 | if (n_enabledby_names > 2) { | |
43 | print "#error EnabledBy (Wfoo && Wbar && Wbaz) not currently supported" | |
44 | } | |
45 | for (j = 1; j <= n_enabledby_names; j++) { | |
46 | enabledby_name = enabledby_names[j]; | |
47 | enabledby_index = opt_numbers[enabledby_name]; | |
48 | if (enabledby_index == "") { | |
49 | print "#error Enabledby: " enabledby_name | |
50 | } else { | |
51 | condition = ""; | |
52 | if (n_enabledby_names == 2) { | |
53 | opt_var_name_1 = search_var_name(enabledby_names[1], opt_numbers, opts, flags, n_opts); | |
54 | opt_var_name_2 = search_var_name(enabledby_names[2], opt_numbers, opts, flags, n_opts); | |
55 | if (opt_var_name_1 == "") { | |
56 | print "#error " enabledby_names[1] " does not have a Var() flag" | |
57 | } | |
58 | if (opt_var_name_2 == "") { | |
59 | print "#error " enabledby_names[2] " does not have a Var() flag" | |
60 | } | |
61 | condition = "opts->x_" opt_var_name_1 " && opts->x_" opt_var_name_2; | |
62 | } | |
63 | if (enables[enabledby_name] == "") { | |
64 | enabledby[n_enabledby] = enabledby_name; | |
65 | n_enabledby++; | |
66 | } | |
67 | enables[enabledby_name] = enables[enabledby_name] opts[i] ";"; | |
68 | enablesif[enabledby_name] = enablesif[enabledby_name] condition ";"; | |
d3b7ee7c | 69 | } |
d3b7ee7c | 70 | } |
71 | } | |
72 | ||
73 | enabledby_arg = opt_args("LangEnabledBy", flags[i]); | |
74 | if (enabledby_arg != "") { | |
5493f55e | 75 | enabledby_langs = nth_arg(0, enabledby_arg); |
d3b7ee7c | 76 | enabledby_name = nth_arg(1, enabledby_arg); |
5493f55e | 77 | enabledby_posarg = nth_arg(2, enabledby_arg); |
78 | enabledby_negarg = nth_arg(3, enabledby_arg); | |
79 | lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg); | |
d3b7ee7c | 80 | } |
81 | } | |
82 | ||
83 | ||
30b0f428 | 84 | print "/* This file is auto-generated by optc-gen.awk. */" |
e8b212b8 | 85 | print "" |
5c5ccba2 | 86 | n_headers = split(header_name, headers, " ") |
87 | for (i = 1; i <= n_headers; i++) | |
88 | print "#include " quote headers[i] quote | |
e8b212b8 | 89 | print "#include " quote "opts.h" quote |
6ce616df | 90 | print "#include " quote "intl.h" quote |
19c83f00 | 91 | print "#include " quote "insn-attr-common.h" quote |
e8b212b8 | 92 | print "" |
93 | ||
755fa783 | 94 | if (n_extra_c_includes > 0) { |
95 | for (i = 0; i < n_extra_c_includes; i++) { | |
96 | print "#include " quote extra_c_includes[i] quote | |
97 | } | |
98 | print "" | |
99 | } | |
100 | ||
d62a5950 | 101 | for (i = 0; i < n_enums; i++) { |
102 | name = enum_names[i] | |
103 | type = enum_type[name] | |
104 | print "static const struct cl_enum_arg cl_enum_" name \ | |
105 | "_data[] = " | |
106 | print "{" | |
107 | print enum_data[name] " { NULL, 0, 0 }" | |
108 | print "};" | |
109 | print "" | |
110 | print "static void" | |
111 | print "cl_enum_" name "_set (void *var, int value)" | |
112 | print "{" | |
113 | print " *((" type " *) var) = (" type ") value;" | |
114 | print "}" | |
115 | print "" | |
116 | print "static int" | |
117 | print "cl_enum_" name "_get (const void *var)" | |
118 | print "{" | |
119 | print " return (int) *((const " type " *) var);" | |
120 | print "}" | |
121 | print "" | |
122 | } | |
123 | ||
124 | print "const struct cl_enum cl_enums[] =" | |
125 | print "{" | |
126 | for (i = 0; i < n_enums; i++) { | |
127 | name = enum_names[i] | |
128 | ehelp = enum_help[name] | |
129 | if (ehelp == "") | |
130 | ehelp = "NULL" | |
131 | else | |
132 | ehelp = quote ehelp quote | |
133 | unknown_error = enum_unknown_error[name] | |
134 | if (unknown_error == "") | |
135 | unknown_error = "NULL" | |
136 | else | |
137 | unknown_error = quote unknown_error quote | |
138 | print " {" | |
139 | print " " ehelp "," | |
140 | print " " unknown_error "," | |
141 | print " cl_enum_" name "_data," | |
142 | print " sizeof (" enum_type[name] ")," | |
143 | print " cl_enum_" name "_set," | |
144 | print " cl_enum_" name "_get" | |
145 | print " }," | |
146 | } | |
147 | print "};" | |
148 | print "const unsigned int cl_enums_count = " n_enums ";" | |
149 | print "" | |
150 | ||
f3f006ad | 151 | print "const struct gcc_options global_options_init =\n{" |
0f8defe5 | 152 | for (i = 0; i < n_extra_vars; i++) { |
5ae82d58 | 153 | var = extra_vars[i] |
154 | init = extra_vars[i] | |
155 | if (var ~ "=" ) { | |
156 | sub(".*= *", "", init) | |
5ae82d58 | 157 | } else { |
158 | init = "0" | |
159 | } | |
c3be4b75 | 160 | sub(" *=.*", "", var) |
161 | name = var | |
162 | sub("^.*[ *]", "", name) | |
163 | sub("\\[.*\\]$", "", name) | |
164 | var_seen[name] = 1 | |
165 | print " " init ", /* " name " */" | |
0f8defe5 | 166 | } |
e8b212b8 | 167 | for (i = 0; i < n_opts; i++) { |
168 | name = var_name(flags[i]); | |
169 | if (name == "") | |
170 | continue; | |
171 | ||
5ae82d58 | 172 | init = opt_args("Init", flags[i]) |
173 | if (init != "") { | |
174 | if (name in var_init && var_init[name] != init) | |
175 | print "#error multiple initializers for " name | |
176 | var_init[name] = init | |
a1baa5f1 | 177 | } |
5ae82d58 | 178 | } |
179 | for (i = 0; i < n_opts; i++) { | |
180 | name = var_name(flags[i]); | |
181 | if (name == "") | |
182 | continue; | |
183 | ||
184 | if (name in var_seen) | |
185 | continue; | |
186 | ||
187 | if (name in var_init) | |
188 | init = var_init[name] | |
189 | else | |
190 | init = "0" | |
a150399d | 191 | |
5ae82d58 | 192 | print " " init ", /* " name " */" |
c5e839cb | 193 | |
194 | var_seen[name] = 1; | |
a150399d | 195 | } |
d6907cfa | 196 | for (i = 0; i < n_opts; i++) { |
197 | name = static_var(opts[i], flags[i]); | |
2c5d2e39 | 198 | if (name != "") { |
199 | print " 0, /* " name " (private state) */" | |
200 | print "#undef x_" name | |
201 | } | |
d6907cfa | 202 | } |
ecee1b29 | 203 | for (i = 0; i < n_opts; i++) { |
204 | if (flag_set_p("SetByCombined", flags[i])) | |
205 | print " false, /* frontend_set_" var_name(flags[i]) " */" | |
206 | } | |
2c5d2e39 | 207 | print "};" |
d6907cfa | 208 | print "" |
f3f006ad | 209 | print "struct gcc_options global_options;" |
f83b64ca | 210 | print "struct gcc_options global_options_set;" |
211 | print "" | |
e8b212b8 | 212 | |
213 | print "const char * const lang_names[] =\n{" | |
214 | for (i = 0; i < n_langs; i++) { | |
d3b7ee7c | 215 | macros[i] = "CL_" lang_sanitized_name(langs[i]) |
e8b212b8 | 216 | s = substr(" ", length (macros[i])) |
217 | print " " quote langs[i] quote "," | |
218 | } | |
219 | ||
220 | print " 0\n};\n" | |
221 | print "const unsigned int cl_options_count = N_OPTS;\n" | |
634b1f85 | 222 | print "#if (1U << " n_langs ") > CL_MIN_OPTION_CLASS" |
223 | print " #error the number of languages exceeds the implementation limit" | |
224 | print "#endif" | |
87c75316 | 225 | print "const unsigned int cl_lang_count = " n_langs ";\n" |
e8b212b8 | 226 | |
227 | print "const struct cl_option cl_options[] =\n{" | |
228 | ||
a1baa5f1 | 229 | j = 0 |
230 | for (i = 0; i < n_opts; i++) { | |
e8b212b8 | 231 | back_chain[i] = "N_OPTS"; |
a1baa5f1 | 232 | indices[opts[i]] = j; |
233 | # Combine the flags of identical switches. Switches | |
234 | # appear many times if they are handled by many front | |
235 | # ends, for example. | |
236 | while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { | |
237 | flags[i + 1] = flags[i] " " flags[i + 1]; | |
e6a03973 | 238 | if (help[i + 1] == "") |
239 | help[i + 1] = help[i] | |
0863a8f4 | 240 | else if (help[i] != "" && help[i + 1] != help[i]) |
4584d89f | 241 | print "#error Multiple different help strings for " \ |
242 | opts[i] ":\n\t" help[i] "\n\t" help[i + 1] | |
243 | ||
a1baa5f1 | 244 | i++; |
245 | back_chain[i] = "N_OPTS"; | |
246 | indices[opts[i]] = j; | |
247 | } | |
248 | j++; | |
249 | } | |
e8b212b8 | 250 | |
d39ef3aa | 251 | for (i = 0; i < n_opts; i++) { |
e6a03973 | 252 | # With identical flags, pick only the last one. The |
253 | # earlier loop ensured that it has all flags merged, | |
254 | # and a nonempty help text if one of the texts was nonempty. | |
d39ef3aa | 255 | while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
d39ef3aa | 256 | i++; |
257 | } | |
e8b212b8 | 258 | |
d39ef3aa | 259 | len = length (opts[i]); |
d4c7816a | 260 | enum = opt_enum(opts[i]) |
d39ef3aa | 261 | |
262 | # If this switch takes joined arguments, back-chain all | |
263 | # subsequent switches to it for which it is a prefix. If | |
264 | # a later switch S is a longer prefix of a switch T, T | |
265 | # will be back-chained to S in a later iteration of this | |
266 | # for() loop, which is what we want. | |
267 | if (flag_set_p("Joined.*", flags[i])) { | |
268 | for (j = i + 1; j < n_opts; j++) { | |
269 | if (substr (opts[j], 1, len) != opts[i]) | |
270 | break; | |
271 | back_chain[j] = enum; | |
e8b212b8 | 272 | } |
d39ef3aa | 273 | } |
e8b212b8 | 274 | |
d39ef3aa | 275 | s = substr(" ", length (opts[i])) |
276 | if (i + 1 == n_opts) | |
277 | comma = "" | |
e8b212b8 | 278 | |
d39ef3aa | 279 | if (help[i] == "") |
280 | hlp = "0" | |
281 | else | |
282 | hlp = quote help[i] quote; | |
e8b212b8 | 283 | |
fecf9011 | 284 | missing_arg_error = opt_args("MissingArgError", flags[i]) |
285 | if (missing_arg_error == "") | |
286 | missing_arg_error = "0" | |
287 | else | |
288 | missing_arg_error = quote missing_arg_error quote | |
289 | ||
3b0273a1 | 290 | |
291 | warn_message = opt_args("Warn", flags[i]) | |
292 | if (warn_message == "") | |
293 | warn_message = "0" | |
294 | else | |
295 | warn_message = quote warn_message quote | |
296 | ||
67089c6b | 297 | alias_arg = opt_args("Alias", flags[i]) |
298 | if (alias_arg == "") { | |
3b0273a1 | 299 | if (flag_set_p("Ignore", flags[i])) |
300 | alias_data = "NULL, NULL, OPT_SPECIAL_ignore" | |
301 | else | |
302 | alias_data = "NULL, NULL, N_OPTS" | |
67089c6b | 303 | } else { |
304 | alias_opt = nth_arg(0, alias_arg) | |
305 | alias_posarg = nth_arg(1, alias_arg) | |
306 | alias_negarg = nth_arg(2, alias_arg) | |
307 | ||
2c5d2e39 | 308 | if (var_ref(opts[i], flags[i]) != "-1") |
67089c6b | 309 | print "#error Alias setting variable" |
310 | ||
311 | if (alias_posarg != "" && alias_negarg == "") { | |
312 | if (!flag_set_p("RejectNegative", flags[i]) \ | |
313 | && opts[i] ~ "^[Wfm]") | |
314 | print "#error Alias with single argument " \ | |
315 | "allowing negative form" | |
316 | } | |
4e775b8e | 317 | if (alias_posarg != "" \ |
318 | && flag_set_p("NegativeAlias", flags[i])) { | |
319 | print "#error Alias with multiple arguments " \ | |
320 | "used with NegativeAlias" | |
321 | } | |
67089c6b | 322 | |
323 | alias_opt = opt_enum(alias_opt) | |
324 | if (alias_posarg == "") | |
325 | alias_posarg = "NULL" | |
326 | else | |
327 | alias_posarg = quote alias_posarg quote | |
328 | if (alias_negarg == "") | |
329 | alias_negarg = "NULL" | |
330 | else | |
331 | alias_negarg = quote alias_negarg quote | |
332 | alias_data = alias_posarg ", " alias_negarg ", " alias_opt | |
333 | } | |
334 | ||
a1baa5f1 | 335 | neg = opt_args("Negative", flags[i]); |
336 | if (neg != "") | |
337 | idx = indices[neg] | |
338 | else { | |
339 | if (flag_set_p("RejectNegative", flags[i])) | |
340 | idx = -1; | |
341 | else { | |
342 | if (opts[i] ~ "^[Wfm]") | |
343 | idx = indices[opts[i]]; | |
344 | else | |
345 | idx = -1; | |
346 | } | |
347 | } | |
13c2c394 | 348 | # Split the printf after %u to work around an ia64-hp-hpux11.23 |
349 | # awk bug. | |
3b0273a1 | 350 | printf(" { %c-%s%c,\n %s,\n %s,\n %s,\n %s, %s, %u,", |
351 | quote, opts[i], quote, hlp, missing_arg_error, warn_message, | |
67089c6b | 352 | alias_data, back_chain[i], len) |
13c2c394 | 353 | printf(" %d,\n", idx) |
5c5ccba2 | 354 | condition = opt_args("Condition", flags[i]) |
355 | cl_flags = switch_flags(flags[i]) | |
ec840af4 | 356 | cl_bit_fields = switch_bit_fields(flags[i]) |
357 | cl_zero_bit_fields = switch_bit_fields("") | |
5c5ccba2 | 358 | if (condition != "") |
359 | printf("#if %s\n" \ | |
360 | " %s,\n" \ | |
ec840af4 | 361 | " 0, %s,\n" \ |
5c5ccba2 | 362 | "#else\n" \ |
ec840af4 | 363 | " 0,\n" \ |
364 | " 1 /* Disabled. */, %s,\n" \ | |
5c5ccba2 | 365 | "#endif\n", |
ec840af4 | 366 | condition, cl_flags, cl_bit_fields, cl_zero_bit_fields) |
5c5ccba2 | 367 | else |
ec840af4 | 368 | printf(" %s,\n" \ |
369 | " 0, %s,\n", | |
370 | cl_flags, cl_bit_fields) | |
d6907cfa | 371 | printf(" %s, %s }%s\n", var_ref(opts[i], flags[i]), |
372 | var_set(flags[i]), comma) | |
e8b212b8 | 373 | } |
374 | ||
375 | print "};" | |
46f8e3b0 | 376 | |
fbb6fbd8 | 377 | print "\n\n" |
378 | print "bool " | |
379 | print "common_handle_option_auto (struct gcc_options *opts, " | |
380 | print " struct gcc_options *opts_set, " | |
381 | print " const struct cl_decoded_option *decoded, " | |
382 | print " unsigned int lang_mask, int kind, " | |
383 | print " location_t loc, " | |
384 | print " const struct cl_option_handlers *handlers, " | |
385 | print " diagnostic_context *dc) " | |
386 | print "{ " | |
387 | print " size_t scode = decoded->opt_index; " | |
388 | print " int value = decoded->value; " | |
389 | print " enum opt_code code = (enum opt_code) scode; " | |
390 | print " " | |
391 | print " gcc_assert (decoded->canonical_option_num_elements <= 2); " | |
392 | print " " | |
393 | print " switch (code) " | |
394 | print " { " | |
1090f26f | 395 | # Handle EnabledBy |
fbb6fbd8 | 396 | for (i = 0; i < n_enabledby; i++) { |
397 | enabledby_name = enabledby[i]; | |
398 | print " case " opt_enum(enabledby_name) ":" | |
77b27208 | 399 | n_enables = split(enables[enabledby_name], thisenable, ";"); |
1090f26f | 400 | n_enablesif = split(enablesif[enabledby_name], thisenableif, ";"); |
401 | if (n_enables != n_enablesif) { | |
402 | print "#error n_enables != n_enablesif: Something went wrong!" | |
403 | } | |
fbb6fbd8 | 404 | for (j = 1; j < n_enables; j++) { |
405 | opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]); | |
db490cb6 | 406 | if (opt_var_name != "") { |
1090f26f | 407 | condition = "!opts_set->x_" opt_var_name |
408 | if (thisenableif[j] != "") { | |
409 | condition = condition " && (" thisenableif[j] ")" | |
410 | } | |
411 | print " if (" condition ")" | |
db490cb6 | 412 | print " handle_generated_option (opts, opts_set," |
413 | print " " opt_enum(thisenable[j]) ", NULL, value," | |
414 | print " lang_mask, kind, loc, handlers, dc);" | |
415 | } else { | |
416 | print "#error " thisenable[j] " does not have a Var() flag" | |
417 | } | |
fbb6fbd8 | 418 | } |
419 | print " break;\n" | |
fbb6fbd8 | 420 | } |
421 | print " default: " | |
422 | print " break; " | |
423 | print " } " | |
424 | print " return true; " | |
425 | print "} " | |
426 | ||
d3b7ee7c | 427 | # Handle LangEnabledBy |
428 | for (i = 0; i < n_langs; i++) { | |
429 | lang_name = lang_sanitized_name(langs[i]); | |
430 | mark_unused = " ATTRIBUTE_UNUSED"; | |
431 | ||
432 | print "\n\n" | |
433 | print "bool " | |
434 | print lang_name "_handle_option_auto (struct gcc_options *opts" mark_unused ", " | |
435 | print " struct gcc_options *opts_set" mark_unused ", " | |
436 | print " size_t scode" mark_unused ", const char *arg" mark_unused ", int value" mark_unused ", " | |
437 | print " unsigned int lang_mask" mark_unused ", int kind" mark_unused ", " | |
438 | print " location_t loc" mark_unused ", " | |
439 | print " const struct cl_option_handlers *handlers" mark_unused ", " | |
440 | print " diagnostic_context *dc" mark_unused ") " | |
441 | print "{ " | |
442 | print " enum opt_code code = (enum opt_code) scode; " | |
443 | print " " | |
444 | print " switch (code) " | |
445 | print " { " | |
446 | ||
447 | for (k = 0; k < n_enabledby_lang[i]; k++) { | |
448 | enabledby_name = enabledby[lang_name,k]; | |
449 | print " case " opt_enum(enabledby_name) ":" | |
77b27208 | 450 | n_thisenable = split(enables[lang_name,enabledby_name], thisenable, ";"); |
451 | for (j = 1; j < n_thisenable; j++) { | |
452 | n_thisenable_args = split(thisenable[j], thisenable_args, ","); | |
453 | if (n_thisenable_args == 1) { | |
454 | thisenable_opt = thisenable[j]; | |
455 | value = "value"; | |
456 | } else { | |
457 | thisenable_opt = thisenable_args[1]; | |
458 | with_posarg = thisenable_args[2]; | |
459 | with_negarg = thisenable_args[3]; | |
460 | value = "value ? " with_posarg " : " with_negarg; | |
461 | } | |
462 | opt_var_name = var_name(flags[opt_numbers[thisenable_opt]]); | |
db490cb6 | 463 | if (opt_var_name != "") { |
464 | print " if (!opts_set->x_" opt_var_name ")" | |
465 | print " handle_generated_option (opts, opts_set," | |
77b27208 | 466 | print " " opt_enum(thisenable_opt) ", NULL, " value "," |
db490cb6 | 467 | print " lang_mask, kind, loc, handlers, dc);" |
468 | } else { | |
77b27208 | 469 | print "#error " thisenable_opt " does not have a Var() flag" |
db490cb6 | 470 | } |
d3b7ee7c | 471 | } |
472 | print " break;\n" | |
473 | } | |
474 | print " default: " | |
475 | print " break; " | |
476 | print " } " | |
477 | print " return true; " | |
478 | print "} " | |
479 | } | |
480 | ||
e8b212b8 | 481 | } |