1 # Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011, 2012
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.
34 # Record first EnabledBy and LangEnabledBy uses.
36 for (i =
0; i
< n_langs
; i
++) {
37 n_enabledby_lang
[i
] =
0;
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
47 if (enables
[enabledby_name
] ==
"") {
48 enabledby
[n_enabledby
] = enabledby_name
;
51 enables
[enabledby_name
] = enables
[enabledby_name
] opts
[i
] ",";
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
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
]++;
70 enables
[lang_name
,enabledby_name
] = enables
[lang_name
,enabledby_name
] opts
[i
] ",";
77 print "/* This file is auto-generated by optc-gen.awk. */"
79 n_headers =
split(header_name
, headers
, " ")
80 for (i =
1; i
<= n_headers
; i
++)
81 print "#include " quote headers
[i
] quote
82 print "#include " quote
"opts.h" quote
83 print "#include " quote
"intl.h" quote
84 print "#include " quote
"insn-attr-common.h" quote
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
94 for (i =
0; i
< n_enums
; i
++) {
96 type = enum_type
[name
]
97 print "static const struct cl_enum_arg cl_enum_" name \
100 print enum_data
[name
] " { NULL, 0, 0 }"
104 print "cl_enum_" name
"_set (void *var, int value)"
106 print " *((" type
" *) var) = (" type
") value;"
110 print "cl_enum_" name
"_get (const void *var)"
112 print " return (int) *((const " type
" *) var);"
117 print "const struct cl_enum cl_enums[] ="
119 for (i =
0; i
< n_enums
; i
++) {
121 ehelp = enum_help
[name
]
125 ehelp = quote ehelp quote
126 unknown_error = enum_unknown_error
[name
]
127 if (unknown_error ==
"")
128 unknown_error =
"NULL"
130 unknown_error = quote unknown_error quote
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"
141 print "const unsigned int cl_enums_count = " n_enums
";"
144 print "const struct gcc_options global_options_init =\n{"
145 for (i =
0; i
< n_extra_vars
; i
++) {
149 sub(".*= *", "", init
)
153 sub(" *=.*", "", var
)
155 sub("^.*[ *]", "", name
)
156 sub("\\[.*\\]$", "", name
)
158 print " " init
", /* " name
" */"
160 for (i =
0; i
< n_opts
; i
++) {
161 name = var_name
(flags
[i
]);
165 init = opt_args
("Init", flags
[i
])
167 if (name in var_init
&& var_init
[name
] != init
)
168 print "#error multiple initializers for " name
169 var_init
[name
] = init
172 for (i =
0; i
< n_opts
; i
++) {
173 name = var_name
(flags
[i
]);
177 if (name in var_seen
)
180 if (name in var_init
)
181 init = var_init
[name
]
185 print " " init
", /* " name
" */"
189 for (i =
0; i
< n_opts
; i
++) {
190 name = static_var
(opts
[i
], flags
[i
]);
192 print " 0, /* " name
" (private state) */"
193 print "#undef x_" name
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
]) " */"
202 print "struct gcc_options global_options;"
203 print "struct gcc_options global_options_set;"
206 print "const char * const lang_names[] =\n{"
207 for (i =
0; i
< n_langs
; i
++) {
208 macros
[i
] =
"CL_" lang_sanitized_name
(langs
[i
])
209 s =
substr(" ", length (macros
[i
]))
210 print " " quote langs
[i
] quote
","
214 print "const unsigned int cl_options_count = N_OPTS;\n"
215 print "#if (1U << " n_langs
") > CL_MIN_OPTION_CLASS"
216 print " #error the number of languages exceeds the implementation limit"
218 print "const unsigned int cl_lang_count = " n_langs
";\n"
220 print "const struct cl_option cl_options[] =\n{"
223 for (i =
0; i
< n_opts
; i
++) {
224 back_chain
[i
] =
"N_OPTS";
225 indices
[opts
[i
]] = j
;
226 # Combine the flags of identical switches. Switches
227 # appear many times if they are handled by many front
229 while( i
+ 1 != n_opts
&& opts
[i
] == opts
[i
+ 1] ) {
230 flags
[i
+ 1] = flags
[i
] " " flags
[i
+ 1];
231 if (help
[i
+ 1] ==
"")
232 help
[i
+ 1] = help
[i
]
233 else if (help
[i
] != "" && help
[i
+ 1] != help
[i
])
234 print "#error Multiple different help strings for " \
235 opts
[i
] ":\n\t" help
[i
] "\n\t" help
[i
+ 1]
238 back_chain
[i
] =
"N_OPTS";
239 indices
[opts
[i
]] = j
;
244 for (i =
0; i
< n_opts
; i
++) {
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.
248 while( i
+ 1 != n_opts
&& opts
[i
] == opts
[i
+ 1] ) {
252 len =
length (opts
[i
]);
253 enum = opt_enum
(opts
[i
])
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
])
264 back_chain
[j
] = enum
;
268 s =
substr(" ", length (opts
[i
]))
275 hlp = quote help
[i
] quote
;
277 missing_arg_error = opt_args
("MissingArgError", flags
[i
])
278 if (missing_arg_error ==
"")
279 missing_arg_error =
"0"
281 missing_arg_error = quote missing_arg_error quote
284 warn_message = opt_args
("Warn", flags
[i
])
285 if (warn_message ==
"")
288 warn_message = quote warn_message quote
290 alias_arg = opt_args
("Alias", flags
[i
])
291 if (alias_arg ==
"") {
292 if (flag_set_p
("Ignore", flags
[i
]))
293 alias_data =
"NULL, NULL, OPT_SPECIAL_ignore"
295 alias_data =
"NULL, NULL, N_OPTS"
297 alias_opt = nth_arg
(0, alias_arg
)
298 alias_posarg = nth_arg
(1, alias_arg
)
299 alias_negarg = nth_arg
(2, alias_arg
)
301 if (var_ref
(opts
[i
], flags
[i
]) != "-1")
302 print "#error Alias setting variable"
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"
310 if (alias_posarg
!= "" \
311 && flag_set_p
("NegativeAlias", flags
[i
])) {
312 print "#error Alias with multiple arguments " \
313 "used with NegativeAlias"
316 alias_opt = opt_enum
(alias_opt
)
317 if (alias_posarg ==
"")
318 alias_posarg =
"NULL"
320 alias_posarg = quote alias_posarg quote
321 if (alias_negarg ==
"")
322 alias_negarg =
"NULL"
324 alias_negarg = quote alias_negarg quote
325 alias_data = alias_posarg
", " alias_negarg
", " alias_opt
328 neg = opt_args
("Negative", flags
[i
]);
332 if (flag_set_p
("RejectNegative", flags
[i
]))
335 if (opts
[i
] ~
"^[Wfm]")
336 idx = indices
[opts
[i
]];
341 # Split the printf after %u to work around an ia64-hp-hpux11.23
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
,
345 alias_data
, back_chain
[i
], len
)
346 printf(" %d,\n", idx
)
347 condition = opt_args
("Condition", flags
[i
])
348 cl_flags = switch_flags
(flags
[i
])
349 cl_bit_fields = switch_bit_fields
(flags
[i
])
350 cl_zero_bit_fields = switch_bit_fields
("")
357 " 1 /* Disabled. */, %s,\n" \
359 condition
, cl_flags
, cl_bit_fields
, cl_zero_bit_fields
)
363 cl_flags
, cl_bit_fields
)
364 printf(" %s, %s }%s\n", var_ref
(opts
[i
], flags
[i
]),
365 var_set
(flags
[i
]), comma
)
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) "
380 print " size_t scode = decoded->opt_index; "
381 print " int value = decoded->value; "
382 print " enum opt_code code = (enum opt_code) scode; "
384 print " gcc_assert (decoded->canonical_option_num_elements <= 2); "
386 print " switch (code) "
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
]]]);
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);"
400 print "#error " thisenable
[j
] " does not have a Var() flag"
408 print " return true; "
411 # Handle LangEnabledBy
412 for (i =
0; i
< n_langs
; i
++) {
413 lang_name = lang_sanitized_name
(langs
[i
]);
414 mark_unused =
" ATTRIBUTE_UNUSED";
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
") "
426 print " enum opt_code code = (enum opt_code) scode; "
428 print " switch (code) "
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
]]]);
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);"
443 print "#error " thisenable
[j
] " does not have a Var() flag"
451 print " return true; "