OSDN Git Service

Remove changelog entry accidentally committed in r175057
[pf3gnuchains/gcc-fork.git] / gcc / optc-gen.awk
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.
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
8 # Free Software Foundation; either version 3, or (at your option) any
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
17 # along with this program; see the file COPYING3.  If not see
18 # <http://www.gnu.org/licenses/>.
19
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.
23 #
24
25 # This program uses functions from opt-functions.awk and code from
26 # opt-read.awk.
27 #
28 # Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-gen.awk \
29 #            [-v header_name=header.h] < inputfile > options.c
30
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 "#include " quote "insn-attr-common.h" quote
41 print ""
42
43 if (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
50 for (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
73 print "const struct cl_enum cl_enums[] ="
74 print "{"
75 for (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 }
96 print "};"
97 print "const unsigned int cl_enums_count = " n_enums ";"
98 print ""
99
100 print "const struct gcc_options global_options_init =\n{"
101 for (i = 0; i < n_extra_vars; i++) {
102         var = extra_vars[i]
103         init = extra_vars[i]
104         if (var ~ "=" ) {
105                 sub(".*= *", "", init)
106         } else {
107                 init = "0"
108         }
109         sub(" *=.*", "", var)
110         name = var
111         sub("^.*[ *]", "", name)
112         sub("\\[.*\\]$", "", name)
113         var_seen[name] = 1
114         print "  " init ", /* " name " */"
115 }
116 for (i = 0; i < n_opts; i++) {
117         name = var_name(flags[i]);
118         if (name == "")
119                 continue;
120
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
126         }
127 }
128 for (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"
140
141         print "  " init ", /* " name " */"
142
143         var_seen[name] = 1;
144 }
145 for (i = 0; i < n_opts; i++) {
146         name = static_var(opts[i], flags[i]);
147         if (name != "") {
148                 print "  0, /* " name " (private state) */"
149                 print "#undef x_" name
150         }
151 }
152 for (i = 0; i < n_opts; i++) {
153         if (flag_set_p("SetByCombined", flags[i]))
154                 print "  false, /* frontend_set_" var_name(flags[i]) " */"
155 }
156 print "};"
157 print ""
158 print "struct gcc_options global_options;"
159 print "struct gcc_options global_options_set;"
160 print ""
161
162 print "const char * const lang_names[] =\n{"
163 for (i = 0; i < n_langs; i++) {
164         macros[i] = "CL_" langs[i]
165         gsub( "[^" alnum "_]", "X", macros[i] )
166         s = substr("         ", length (macros[i]))
167         print "  " quote langs[i] quote ","
168     }
169
170 print "  0\n};\n"
171 print "const unsigned int cl_options_count = N_OPTS;\n"
172 print "const unsigned int cl_lang_count = " n_langs ";\n"
173
174 print "const struct cl_option cl_options[] =\n{"
175
176 j = 0
177 for (i = 0; i < n_opts; i++) {
178         back_chain[i] = "N_OPTS";
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];
185                 if (help[i + 1] == "")
186                         help[i + 1] = help[i]
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"
191                 i++;
192                 back_chain[i] = "N_OPTS";
193                 indices[opts[i]] = j;
194         }
195         j++;
196 }
197
198 for (i = 0; i < n_opts; i++) {
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.
202         while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
203                 i++;
204         }
205
206         len = length (opts[i]);
207         enum = opt_enum(opts[i])
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;
219                 }
220         }
221
222         s = substr("                                  ", length (opts[i]))
223         if (i + 1 == n_opts)
224                 comma = ""
225
226         if (help[i] == "")
227                 hlp = "0"
228         else
229                 hlp = quote help[i] quote;
230
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
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
244         alias_arg = opt_args("Alias", flags[i])
245         if (alias_arg == "") {
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"
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
255                 if (var_ref(opts[i], flags[i]) != "-1")
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                 }
264                 if (alias_posarg != "" \
265                     && flag_set_p("NegativeAlias", flags[i])) {
266                         print "#error Alias with multiple arguments " \
267                                 "used with NegativeAlias"
268                 }
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
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         }
295         # Split the printf after %u to work around an ia64-hp-hpux11.23
296         # awk bug.
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,
299                alias_data, back_chain[i], len)
300         printf(" %d,\n", idx)
301         condition = opt_args("Condition", flags[i])
302         cl_flags = switch_flags(flags[i])
303         cl_bit_fields = switch_bit_fields(flags[i])
304         cl_zero_bit_fields = switch_bit_fields("")
305         if (condition != "")
306                 printf("#if %s\n" \
307                        "    %s,\n" \
308                        "    0, %s,\n" \
309                        "#else\n" \
310                        "    0,\n" \
311                        "    1 /* Disabled.  */, %s,\n" \
312                        "#endif\n",
313                        condition, cl_flags, cl_bit_fields, cl_zero_bit_fields)
314         else
315                 printf("    %s,\n" \
316                        "    0, %s,\n",
317                        cl_flags, cl_bit_fields)
318         printf("    %s, %s }%s\n", var_ref(opts[i], flags[i]),
319                var_set(flags[i]), comma)
320 }
321
322 print "};"
323
324 }