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
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
25 # This program uses functions from opt-functions.awk and code from
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.
33 print "/* This file is auto-generated by optc-gen.awk. */"
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
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
49 for (i =
0; i
< n_enums
; i
++) {
51 type = enum_type
[name
]
52 print "static const struct cl_enum_arg cl_enum_" name \
55 print enum_data
[name
] " { NULL, 0, 0 }"
59 print "cl_enum_" name
"_set (void *var, int value)"
61 print " *((" type
" *) var) = (" type
") value;"
65 print "cl_enum_" name
"_get (const void *var)"
67 print " return (int) *((const " type
" *) var);"
72 print "const struct cl_enum cl_enums[] ="
74 for (i =
0; i
< n_enums
; i
++) {
76 ehelp = enum_help
[name
]
80 ehelp = quote ehelp quote
81 unknown_error = enum_unknown_error
[name
]
82 if (unknown_error ==
"")
83 unknown_error =
"NULL"
85 unknown_error = quote unknown_error quote
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"
96 print "const unsigned int cl_enums_count = " n_enums
";"
99 print "const struct gcc_options global_options_init =\n{"
100 for (i =
0; i
< n_extra_vars
; i
++) {
104 sub(".*= *", "", init
)
108 sub(" *=.*", "", var
)
110 sub("^.*[ *]", "", name
)
111 sub("\\[.*\\]$", "", name
)
113 print " " init
", /* " name
" */"
115 for (i =
0; i
< n_opts
; i
++) {
116 name = var_name
(flags
[i
]);
120 init = opt_args
("Init", flags
[i
])
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
]);
132 if (name in var_seen
)
135 if (name in var_init
)
136 init = var_init
[name
]
140 print " " init
", /* " name
" */"
144 for (i =
0; i
< n_opts
; i
++) {
145 name = static_var
(opts
[i
], flags
[i
]);
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
]) " */"
157 print "struct gcc_options global_options;"
158 print "struct gcc_options global_options_set;"
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
","
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{"
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
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] \
191 back_chain
[i
] =
"N_OPTS";
192 indices
[opts
[i
]] = 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] ) {
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
])
217 back_chain
[j
] = enum
;
221 s =
substr(" ", length (opts
[i
]))
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"
234 missing_arg_error = quote missing_arg_error quote
237 warn_message = opt_args
("Warn", flags
[i
])
238 if (warn_message ==
"")
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"
248 alias_data =
"NULL, NULL, N_OPTS"
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"
273 alias_posarg = quote alias_posarg quote
274 if (alias_negarg ==
"")
275 alias_negarg =
"NULL"
277 alias_negarg = quote alias_negarg quote
278 alias_data = alias_posarg
", " alias_negarg
", " alias_opt
281 neg = opt_args
("Negative", flags
[i
]);
285 if (flag_set_p
("RejectNegative", flags
[i
]))
288 if (opts
[i
] ~
"^[Wfm]")
289 idx = indices
[opts
[i
]];
294 # Split the printf after %u to work around an ia64-hp-hpux11.23
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
("")
310 " 1 /* Disabled. */, %s,\n" \
312 condition
, cl_flags
, cl_bit_fields
, cl_zero_bit_fields
)
316 cl_flags
, cl_bit_fields
)
317 printf(" %s, %s }%s\n", var_ref
(opts
[i
], flags
[i
]),
318 var_set
(flags
[i
]), comma
)