20090811-1.c: Skip for incompatible options, do not override other options.
[official-gcc.git] / gcc / optc-gen.awk
blob519b1e9306c4c290c42b8abb9b33da328138c23f
1 # Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3 # Contributed by Kelley Cook, June 2004.
4 # Original code from Neil Booth, May 2003.
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
8 # Free Software Foundation; either version 3, or (at your option) any
9 # later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; see the file COPYING3. If not see
18 # <http://www.gnu.org/licenses/>.
20 # This Awk script reads in the option records generated from
21 # opt-gather.awk, combines the flags of duplicate options and generates a
22 # C file.
25 # This program uses functions from opt-functions.awk and code from
26 # opt-read.awk.
28 # Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-gen.awk \
29 # [-v header_name=header.h] < inputfile > options.c
31 # Dump that array of options into a C file.
32 END {
33 print "/* This file is auto-generated by optc-gen.awk. */"
34 print ""
35 n_headers = split(header_name, headers, " ")
36 for (i = 1; i <= n_headers; i++)
37 print "#include " quote headers[i] quote
38 print "#include " quote "opts.h" quote
39 print "#include " quote "intl.h" quote
40 print ""
42 if (n_extra_c_includes > 0) {
43 for (i = 0; i < n_extra_c_includes; i++) {
44 print "#include " quote extra_c_includes[i] quote
46 print ""
49 for (i = 0; i < n_enums; i++) {
50 name = enum_names[i]
51 type = enum_type[name]
52 print "static const struct cl_enum_arg cl_enum_" name \
53 "_data[] = "
54 print "{"
55 print enum_data[name] " { NULL, 0, 0 }"
56 print "};"
57 print ""
58 print "static void"
59 print "cl_enum_" name "_set (void *var, int value)"
60 print "{"
61 print " *((" type " *) var) = (" type ") value;"
62 print "}"
63 print ""
64 print "static int"
65 print "cl_enum_" name "_get (const void *var)"
66 print "{"
67 print " return (int) *((const " type " *) var);"
68 print "}"
69 print ""
72 print "const struct cl_enum cl_enums[] ="
73 print "{"
74 for (i = 0; i < n_enums; i++) {
75 name = enum_names[i]
76 ehelp = enum_help[name]
77 if (ehelp == "")
78 ehelp = "NULL"
79 else
80 ehelp = quote ehelp quote
81 unknown_error = enum_unknown_error[name]
82 if (unknown_error == "")
83 unknown_error = "NULL"
84 else
85 unknown_error = quote unknown_error quote
86 print " {"
87 print " " ehelp ","
88 print " " unknown_error ","
89 print " cl_enum_" name "_data,"
90 print " sizeof (" enum_type[name] "),"
91 print " cl_enum_" name "_set,"
92 print " cl_enum_" name "_get"
93 print " },"
95 print "};"
96 print "const unsigned int cl_enums_count = " n_enums ";"
97 print ""
99 print "const struct gcc_options global_options_init =\n{"
100 for (i = 0; i < n_extra_vars; i++) {
101 var = extra_vars[i]
102 init = extra_vars[i]
103 if (var ~ "=" ) {
104 sub(".*= *", "", init)
105 } else {
106 init = "0"
108 sub(" *=.*", "", var)
109 name = var
110 sub("^.*[ *]", "", name)
111 sub("\\[.*\\]$", "", name)
112 var_seen[name] = 1
113 print " " init ", /* " name " */"
115 for (i = 0; i < n_opts; i++) {
116 name = var_name(flags[i]);
117 if (name == "")
118 continue;
120 init = opt_args("Init", flags[i])
121 if (init != "") {
122 if (name in var_init && var_init[name] != init)
123 print "#error multiple initializers for " name
124 var_init[name] = init
127 for (i = 0; i < n_opts; i++) {
128 name = var_name(flags[i]);
129 if (name == "")
130 continue;
132 if (name in var_seen)
133 continue;
135 if (name in var_init)
136 init = var_init[name]
137 else
138 init = "0"
140 print " " init ", /* " name " */"
142 var_seen[name] = 1;
144 for (i = 0; i < n_opts; i++) {
145 name = static_var(opts[i], flags[i]);
146 if (name != "") {
147 print " 0, /* " name " (private state) */"
148 print "#undef x_" name
151 for (i = 0; i < n_opts; i++) {
152 if (flag_set_p("SetByCombined", flags[i]))
153 print " false, /* frontend_set_" var_name(flags[i]) " */"
155 print "};"
156 print ""
157 print "struct gcc_options global_options;"
158 print "struct gcc_options global_options_set;"
159 print ""
161 print "const char * const lang_names[] =\n{"
162 for (i = 0; i < n_langs; i++) {
163 macros[i] = "CL_" langs[i]
164 gsub( "[^" alnum "_]", "X", macros[i] )
165 s = substr(" ", length (macros[i]))
166 print " " quote langs[i] quote ","
169 print " 0\n};\n"
170 print "const unsigned int cl_options_count = N_OPTS;\n"
171 print "const unsigned int cl_lang_count = " n_langs ";\n"
173 print "const struct cl_option cl_options[] =\n{"
175 j = 0
176 for (i = 0; i < n_opts; i++) {
177 back_chain[i] = "N_OPTS";
178 indices[opts[i]] = j;
179 # Combine the flags of identical switches. Switches
180 # appear many times if they are handled by many front
181 # ends, for example.
182 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
183 flags[i + 1] = flags[i] " " flags[i + 1];
184 if (help[i + 1] == "")
185 help[i + 1] = help[i]
186 else if (help[i] != "" && help[i + 1] != help[i])
187 print "warning: multiple different help strings for " \
188 opts[i] ":\n\t" help[i] "\n\t" help[i + 1] \
189 | "cat 1>&2"
190 i++;
191 back_chain[i] = "N_OPTS";
192 indices[opts[i]] = j;
194 j++;
197 for (i = 0; i < n_opts; i++) {
198 # With identical flags, pick only the last one. The
199 # earlier loop ensured that it has all flags merged,
200 # and a nonempty help text if one of the texts was nonempty.
201 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
202 i++;
205 len = length (opts[i]);
206 enum = opt_enum(opts[i])
208 # If this switch takes joined arguments, back-chain all
209 # subsequent switches to it for which it is a prefix. If
210 # a later switch S is a longer prefix of a switch T, T
211 # will be back-chained to S in a later iteration of this
212 # for() loop, which is what we want.
213 if (flag_set_p("Joined.*", flags[i])) {
214 for (j = i + 1; j < n_opts; j++) {
215 if (substr (opts[j], 1, len) != opts[i])
216 break;
217 back_chain[j] = enum;
221 s = substr(" ", length (opts[i]))
222 if (i + 1 == n_opts)
223 comma = ""
225 if (help[i] == "")
226 hlp = "0"
227 else
228 hlp = quote help[i] quote;
230 missing_arg_error = opt_args("MissingArgError", flags[i])
231 if (missing_arg_error == "")
232 missing_arg_error = "0"
233 else
234 missing_arg_error = quote missing_arg_error quote
237 warn_message = opt_args("Warn", flags[i])
238 if (warn_message == "")
239 warn_message = "0"
240 else
241 warn_message = quote warn_message quote
243 alias_arg = opt_args("Alias", flags[i])
244 if (alias_arg == "") {
245 if (flag_set_p("Ignore", flags[i]))
246 alias_data = "NULL, NULL, OPT_SPECIAL_ignore"
247 else
248 alias_data = "NULL, NULL, N_OPTS"
249 } else {
250 alias_opt = nth_arg(0, alias_arg)
251 alias_posarg = nth_arg(1, alias_arg)
252 alias_negarg = nth_arg(2, alias_arg)
254 if (var_ref(opts[i], flags[i]) != "-1")
255 print "#error Alias setting variable"
257 if (alias_posarg != "" && alias_negarg == "") {
258 if (!flag_set_p("RejectNegative", flags[i]) \
259 && opts[i] ~ "^[Wfm]")
260 print "#error Alias with single argument " \
261 "allowing negative form"
263 if (alias_posarg != "" \
264 && flag_set_p("NegativeAlias", flags[i])) {
265 print "#error Alias with multiple arguments " \
266 "used with NegativeAlias"
269 alias_opt = opt_enum(alias_opt)
270 if (alias_posarg == "")
271 alias_posarg = "NULL"
272 else
273 alias_posarg = quote alias_posarg quote
274 if (alias_negarg == "")
275 alias_negarg = "NULL"
276 else
277 alias_negarg = quote alias_negarg quote
278 alias_data = alias_posarg ", " alias_negarg ", " alias_opt
281 neg = opt_args("Negative", flags[i]);
282 if (neg != "")
283 idx = indices[neg]
284 else {
285 if (flag_set_p("RejectNegative", flags[i]))
286 idx = -1;
287 else {
288 if (opts[i] ~ "^[Wfm]")
289 idx = indices[opts[i]];
290 else
291 idx = -1;
294 # Split the printf after %u to work around an ia64-hp-hpux11.23
295 # awk bug.
296 printf(" { %c-%s%c,\n %s,\n %s,\n %s,\n %s, %s, %u,",
297 quote, opts[i], quote, hlp, missing_arg_error, warn_message,
298 alias_data, back_chain[i], len)
299 printf(" %d,\n", idx)
300 condition = opt_args("Condition", flags[i])
301 cl_flags = switch_flags(flags[i])
302 cl_bit_fields = switch_bit_fields(flags[i])
303 cl_zero_bit_fields = switch_bit_fields("")
304 if (condition != "")
305 printf("#if %s\n" \
306 " %s,\n" \
307 " 0, %s,\n" \
308 "#else\n" \
309 " 0,\n" \
310 " 1 /* Disabled. */, %s,\n" \
311 "#endif\n",
312 condition, cl_flags, cl_bit_fields, cl_zero_bit_fields)
313 else
314 printf(" %s,\n" \
315 " 0, %s,\n",
316 cl_flags, cl_bit_fields)
317 printf(" %s, %s }%s\n", var_ref(opts[i], flags[i]),
318 var_set(flags[i]), comma)
321 print "};"