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