]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/optc-gen.awk
PR middle-end/50260
[thirdparty/gcc.git] / gcc / optc-gen.awk
CommitLineData
ecee1b29 1# Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
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.
32END {
30b0f428 33print "/* This file is auto-generated by optc-gen.awk. */"
e8b212b8 34print ""
5c5ccba2 35n_headers = split(header_name, headers, " ")
36for (i = 1; i <= n_headers; i++)
37 print "#include " quote headers[i] quote
e8b212b8 38print "#include " quote "opts.h" quote
6ce616df 39print "#include " quote "intl.h" quote
19c83f00 40print "#include " quote "insn-attr-common.h" quote
e8b212b8 41print ""
42
755fa783 43if (n_extra_c_includes > 0) {
44 for (i = 0; i < n_extra_c_includes; i++) {
45 print "#include " quote extra_c_includes[i] quote
46 }
47 print ""
48}
49
d62a5950 50for (i = 0; i < n_enums; i++) {
51 name = enum_names[i]
52 type = enum_type[name]
53 print "static const struct cl_enum_arg cl_enum_" name \
54 "_data[] = "
55 print "{"
56 print enum_data[name] " { NULL, 0, 0 }"
57 print "};"
58 print ""
59 print "static void"
60 print "cl_enum_" name "_set (void *var, int value)"
61 print "{"
62 print " *((" type " *) var) = (" type ") value;"
63 print "}"
64 print ""
65 print "static int"
66 print "cl_enum_" name "_get (const void *var)"
67 print "{"
68 print " return (int) *((const " type " *) var);"
69 print "}"
70 print ""
71}
72
73print "const struct cl_enum cl_enums[] ="
74print "{"
75for (i = 0; i < n_enums; i++) {
76 name = enum_names[i]
77 ehelp = enum_help[name]
78 if (ehelp == "")
79 ehelp = "NULL"
80 else
81 ehelp = quote ehelp quote
82 unknown_error = enum_unknown_error[name]
83 if (unknown_error == "")
84 unknown_error = "NULL"
85 else
86 unknown_error = quote unknown_error quote
87 print " {"
88 print " " ehelp ","
89 print " " unknown_error ","
90 print " cl_enum_" name "_data,"
91 print " sizeof (" enum_type[name] "),"
92 print " cl_enum_" name "_set,"
93 print " cl_enum_" name "_get"
94 print " },"
95}
96print "};"
97print "const unsigned int cl_enums_count = " n_enums ";"
98print ""
99
f3f006ad 100print "const struct gcc_options global_options_init =\n{"
0f8defe5 101for (i = 0; i < n_extra_vars; i++) {
5ae82d58 102 var = extra_vars[i]
103 init = extra_vars[i]
104 if (var ~ "=" ) {
105 sub(".*= *", "", init)
5ae82d58 106 } else {
107 init = "0"
108 }
c3be4b75 109 sub(" *=.*", "", var)
110 name = var
111 sub("^.*[ *]", "", name)
112 sub("\\[.*\\]$", "", name)
113 var_seen[name] = 1
114 print " " init ", /* " name " */"
0f8defe5 115}
e8b212b8 116for (i = 0; i < n_opts; i++) {
117 name = var_name(flags[i]);
118 if (name == "")
119 continue;
120
5ae82d58 121 init = opt_args("Init", flags[i])
122 if (init != "") {
123 if (name in var_init && var_init[name] != init)
124 print "#error multiple initializers for " name
125 var_init[name] = init
a1baa5f1 126 }
5ae82d58 127}
128for (i = 0; i < n_opts; i++) {
129 name = var_name(flags[i]);
130 if (name == "")
131 continue;
132
133 if (name in var_seen)
134 continue;
135
136 if (name in var_init)
137 init = var_init[name]
138 else
139 init = "0"
a150399d 140
5ae82d58 141 print " " init ", /* " name " */"
c5e839cb 142
143 var_seen[name] = 1;
a150399d 144}
d6907cfa 145for (i = 0; i < n_opts; i++) {
146 name = static_var(opts[i], flags[i]);
2c5d2e39 147 if (name != "") {
148 print " 0, /* " name " (private state) */"
149 print "#undef x_" name
150 }
d6907cfa 151}
ecee1b29 152for (i = 0; i < n_opts; i++) {
153 if (flag_set_p("SetByCombined", flags[i]))
154 print " false, /* frontend_set_" var_name(flags[i]) " */"
155}
2c5d2e39 156print "};"
d6907cfa 157print ""
f3f006ad 158print "struct gcc_options global_options;"
f83b64ca 159print "struct gcc_options global_options_set;"
160print ""
e8b212b8 161
162print "const char * const lang_names[] =\n{"
163for (i = 0; i < n_langs; i++) {
164 macros[i] = "CL_" langs[i]
ca40ed4b 165 gsub( "[^" alnum "_]", "X", macros[i] )
e8b212b8 166 s = substr(" ", length (macros[i]))
167 print " " quote langs[i] quote ","
168 }
169
170print " 0\n};\n"
171print "const unsigned int cl_options_count = N_OPTS;\n"
87c75316 172print "const unsigned int cl_lang_count = " n_langs ";\n"
e8b212b8 173
174print "const struct cl_option cl_options[] =\n{"
175
a1baa5f1 176j = 0
177for (i = 0; i < n_opts; i++) {
e8b212b8 178 back_chain[i] = "N_OPTS";
a1baa5f1 179 indices[opts[i]] = j;
180 # Combine the flags of identical switches. Switches
181 # appear many times if they are handled by many front
182 # ends, for example.
183 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
184 flags[i + 1] = flags[i] " " flags[i + 1];
e6a03973 185 if (help[i + 1] == "")
186 help[i + 1] = help[i]
0863a8f4 187 else if (help[i] != "" && help[i + 1] != help[i])
188 print "warning: multiple different help strings for " \
189 opts[i] ":\n\t" help[i] "\n\t" help[i + 1] \
190 | "cat 1>&2"
a1baa5f1 191 i++;
192 back_chain[i] = "N_OPTS";
193 indices[opts[i]] = j;
194 }
195 j++;
196}
e8b212b8 197
d39ef3aa 198for (i = 0; i < n_opts; i++) {
e6a03973 199 # With identical flags, pick only the last one. The
200 # earlier loop ensured that it has all flags merged,
201 # and a nonempty help text if one of the texts was nonempty.
d39ef3aa 202 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
d39ef3aa 203 i++;
204 }
e8b212b8 205
d39ef3aa 206 len = length (opts[i]);
d4c7816a 207 enum = opt_enum(opts[i])
d39ef3aa 208
209 # If this switch takes joined arguments, back-chain all
210 # subsequent switches to it for which it is a prefix. If
211 # a later switch S is a longer prefix of a switch T, T
212 # will be back-chained to S in a later iteration of this
213 # for() loop, which is what we want.
214 if (flag_set_p("Joined.*", flags[i])) {
215 for (j = i + 1; j < n_opts; j++) {
216 if (substr (opts[j], 1, len) != opts[i])
217 break;
218 back_chain[j] = enum;
e8b212b8 219 }
d39ef3aa 220 }
e8b212b8 221
d39ef3aa 222 s = substr(" ", length (opts[i]))
223 if (i + 1 == n_opts)
224 comma = ""
e8b212b8 225
d39ef3aa 226 if (help[i] == "")
227 hlp = "0"
228 else
229 hlp = quote help[i] quote;
e8b212b8 230
fecf9011 231 missing_arg_error = opt_args("MissingArgError", flags[i])
232 if (missing_arg_error == "")
233 missing_arg_error = "0"
234 else
235 missing_arg_error = quote missing_arg_error quote
236
3b0273a1 237
238 warn_message = opt_args("Warn", flags[i])
239 if (warn_message == "")
240 warn_message = "0"
241 else
242 warn_message = quote warn_message quote
243
67089c6b 244 alias_arg = opt_args("Alias", flags[i])
245 if (alias_arg == "") {
3b0273a1 246 if (flag_set_p("Ignore", flags[i]))
247 alias_data = "NULL, NULL, OPT_SPECIAL_ignore"
248 else
249 alias_data = "NULL, NULL, N_OPTS"
67089c6b 250 } else {
251 alias_opt = nth_arg(0, alias_arg)
252 alias_posarg = nth_arg(1, alias_arg)
253 alias_negarg = nth_arg(2, alias_arg)
254
2c5d2e39 255 if (var_ref(opts[i], flags[i]) != "-1")
67089c6b 256 print "#error Alias setting variable"
257
258 if (alias_posarg != "" && alias_negarg == "") {
259 if (!flag_set_p("RejectNegative", flags[i]) \
260 && opts[i] ~ "^[Wfm]")
261 print "#error Alias with single argument " \
262 "allowing negative form"
263 }
4e775b8e 264 if (alias_posarg != "" \
265 && flag_set_p("NegativeAlias", flags[i])) {
266 print "#error Alias with multiple arguments " \
267 "used with NegativeAlias"
268 }
67089c6b 269
270 alias_opt = opt_enum(alias_opt)
271 if (alias_posarg == "")
272 alias_posarg = "NULL"
273 else
274 alias_posarg = quote alias_posarg quote
275 if (alias_negarg == "")
276 alias_negarg = "NULL"
277 else
278 alias_negarg = quote alias_negarg quote
279 alias_data = alias_posarg ", " alias_negarg ", " alias_opt
280 }
281
a1baa5f1 282 neg = opt_args("Negative", flags[i]);
283 if (neg != "")
284 idx = indices[neg]
285 else {
286 if (flag_set_p("RejectNegative", flags[i]))
287 idx = -1;
288 else {
289 if (opts[i] ~ "^[Wfm]")
290 idx = indices[opts[i]];
291 else
292 idx = -1;
293 }
294 }
13c2c394 295 # Split the printf after %u to work around an ia64-hp-hpux11.23
296 # awk bug.
3b0273a1 297 printf(" { %c-%s%c,\n %s,\n %s,\n %s,\n %s, %s, %u,",
298 quote, opts[i], quote, hlp, missing_arg_error, warn_message,
67089c6b 299 alias_data, back_chain[i], len)
13c2c394 300 printf(" %d,\n", idx)
5c5ccba2 301 condition = opt_args("Condition", flags[i])
302 cl_flags = switch_flags(flags[i])
ec840af4 303 cl_bit_fields = switch_bit_fields(flags[i])
304 cl_zero_bit_fields = switch_bit_fields("")
5c5ccba2 305 if (condition != "")
306 printf("#if %s\n" \
307 " %s,\n" \
ec840af4 308 " 0, %s,\n" \
5c5ccba2 309 "#else\n" \
ec840af4 310 " 0,\n" \
311 " 1 /* Disabled. */, %s,\n" \
5c5ccba2 312 "#endif\n",
ec840af4 313 condition, cl_flags, cl_bit_fields, cl_zero_bit_fields)
5c5ccba2 314 else
ec840af4 315 printf(" %s,\n" \
316 " 0, %s,\n",
317 cl_flags, cl_bit_fields)
d6907cfa 318 printf(" %s, %s }%s\n", var_ref(opts[i], flags[i]),
319 var_set(flags[i]), comma)
e8b212b8 320}
321
322print "};"
46f8e3b0 323
e8b212b8 324}