]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/optc-gen.awk
cfghooks.c (tidy_fallthru_edges): Add ??? comment.
[thirdparty/gcc.git] / gcc / optc-gen.awk
CommitLineData
5e46b0c6 1# Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
c75c517d 2# Free Software Foundation, Inc.
776dc15d
KC
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
9dcd6f09 8# Free Software Foundation; either version 3, or (at your option) any
776dc15d
KC
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
9dcd6f09
NC
17# along with this program; see the file COPYING3. If not see
18# <http://www.gnu.org/licenses/>.
776dc15d
KC
19
20# This Awk script reads in the option records generated from
fc54bc84 21# opt-gather.awk, combines the flags of duplicate options and generates a
776dc15d
KC
22# C file.
23#
24# This program uses functions from opt-functions.awk
25#
26# Usage: awk -f opt-functions.awk -f optc-gen.awk \
27# [-v header_name=header.h] < inputfile > options.c
28
29BEGIN {
30 n_opts = 0
31 n_langs = 0
ab442df7 32 n_target_save = 0
e90afde6 33 n_extra_vars = 0
fd438373
MM
34 n_extra_target_vars = 0
35 n_extra_c_includes = 0
36 n_extra_h_includes = 0
e6d4b984 37 n_enums = 0
fd438373 38 quote = "\042"
776dc15d
KC
39 comma = ","
40 FS=SUBSEP
41 # Default the name of header created from opth-gen.awk to options.h
42 if (header_name == "") header_name="options.h"
43}
44
45# Collect the text and flags of each option into an array
46 {
47 if ($1 == "Language") {
48 langs[n_langs] = $2
49 n_langs++;
50 }
ab442df7
MM
51 else if ($1 == "TargetSave") {
52 # Make sure the declarations are put in source order
53 target_save_decl[n_target_save] = $2
54 n_target_save++
55 }
e90afde6
JM
56 else if ($1 == "Variable") {
57 extra_vars[n_extra_vars] = $2
58 n_extra_vars++
59 }
fd438373
MM
60 else if ($1 == "TargetVariable") {
61 # Combination of TargetSave and Variable
62 extra_vars[n_extra_vars] = $2
63 n_extra_vars++
64
65 var = $2
66 sub(" *=.*", "", var)
67 orig_var = var
68 name = var
69 type = var
70 sub("^.*[ *]", "", name)
71 sub(" *" name "$", "", type)
72 target_save_decl[n_target_save] = type " x_" name
73 n_target_save++
74
75 extra_target_vars[n_extra_target_vars] = name
76 n_extra_target_vars++;
77 }
78 else if ($1 == "HeaderInclude") {
79 extra_h_includes[n_extra_h_includes++] = $2;
80 }
81 else if ($1 == "SourceInclude") {
82 extra_c_includes[n_extra_c_includes++] = $2;
83 }
e6d4b984
JM
84 else if ($1 == "Enum") {
85 props = $2
86 name = opt_args("Name", props)
87 type = opt_args("Type", props)
88 unknown_error = opt_args("UnknownError", props)
89 enum_names[n_enums] = name
90 enum_type[name] = type
91 enum_index[name] = n_enums
92 enum_unknown_error[name] = unknown_error
93 enum_help[name] = $3
94 n_enums++
95 }
96 else if ($1 == "EnumValue") {
97 props = $2
98 enum_name = opt_args("Enum", props)
99 string = opt_args("String", props)
100 value = opt_args("Value", props)
101 val_flags = "0"
102 val_flags = val_flags \
103 test_flag("Canonical", props, "| CL_ENUM_CANONICAL") \
104 test_flag("DriverOnly", props, "| CL_ENUM_DRIVER_ONLY")
105 enum_data[enum_name] = enum_data[enum_name] \
106 " { " quote string quote ", " value ", " val_flags \
107 " },\n"
108 }
776dc15d 109 else {
fe609b0f
EB
110 name = opt_args("Mask", $1)
111 if (name == "") {
112 opts[n_opts] = $1
113 flags[n_opts] = $2
114 help[n_opts] = $3
4d077054
RW
115 for (i = 4; i <= NF; i++)
116 help[n_opts] = help[n_opts] " " $i
fe609b0f
EB
117 n_opts++;
118 }
776dc15d
KC
119 }
120 }
121
122# Dump that array of options into a C file.
123END {
af47e6ac 124print "/* This file is auto-generated by optc-gen.awk. */"
776dc15d 125print ""
aeb70e78
RS
126n_headers = split(header_name, headers, " ")
127for (i = 1; i <= n_headers; i++)
128 print "#include " quote headers[i] quote
776dc15d 129print "#include " quote "opts.h" quote
fb664b5a 130print "#include " quote "intl.h" quote
776dc15d 131print ""
d4d24ba4 132print "#ifndef GCC_DRIVER"
ab442df7
MM
133print "#include " quote "flags.h" quote
134print "#include " quote "target.h" quote
8dc3f290 135print "#endif /* GCC_DRIVER */"
14c7833c 136print ""
776dc15d 137
fd438373
MM
138if (n_extra_c_includes > 0) {
139 for (i = 0; i < n_extra_c_includes; i++) {
140 print "#include " quote extra_c_includes[i] quote
141 }
142 print ""
143}
144
e6d4b984
JM
145for (i = 0; i < n_enums; i++) {
146 name = enum_names[i]
147 type = enum_type[name]
148 print "static const struct cl_enum_arg cl_enum_" name \
149 "_data[] = "
150 print "{"
151 print enum_data[name] " { NULL, 0, 0 }"
152 print "};"
153 print ""
154 print "static void"
155 print "cl_enum_" name "_set (void *var, int value)"
156 print "{"
157 print " *((" type " *) var) = (" type ") value;"
158 print "}"
159 print ""
160 print "static int"
161 print "cl_enum_" name "_get (const void *var)"
162 print "{"
163 print " return (int) *((const " type " *) var);"
164 print "}"
165 print ""
166}
167
168print "const struct cl_enum cl_enums[] ="
169print "{"
170for (i = 0; i < n_enums; i++) {
171 name = enum_names[i]
172 ehelp = enum_help[name]
173 if (ehelp == "")
174 ehelp = "NULL"
175 else
176 ehelp = quote ehelp quote
177 unknown_error = enum_unknown_error[name]
178 if (unknown_error == "")
179 unknown_error = "NULL"
180 else
181 unknown_error = quote unknown_error quote
182 print " {"
183 print " " ehelp ","
184 print " " unknown_error ","
185 print " cl_enum_" name "_data,"
186 print " sizeof (" enum_type[name] "),"
187 print " cl_enum_" name "_set,"
188 print " cl_enum_" name "_get"
189 print " },"
190}
191print "};"
192print "const unsigned int cl_enums_count = " n_enums ";"
193print ""
194
ab442df7 195have_save = 0;
fd438373
MM
196if (n_extra_target_vars)
197 have_save = 1
198
a75bfaa6 199print "const struct gcc_options global_options_init =\n{"
e90afde6 200for (i = 0; i < n_extra_vars; i++) {
e3339d0f
JM
201 var = extra_vars[i]
202 init = extra_vars[i]
203 if (var ~ "=" ) {
204 sub(".*= *", "", init)
205 sub(" *=.*", "", var)
206 sub("^.*[ *]", "", var)
69ccdddb 207 sub("\\[.*\\]$", "", var)
e3339d0f
JM
208 } else {
209 init = "0"
210 }
211 var_seen[var] = 1
212 print " " init ", /* " var " */"
e90afde6 213}
776dc15d 214for (i = 0; i < n_opts; i++) {
ab442df7
MM
215 if (flag_set_p("Save", flags[i]))
216 have_save = 1;
217
776dc15d
KC
218 name = var_name(flags[i]);
219 if (name == "")
220 continue;
221
e3339d0f
JM
222 init = opt_args("Init", flags[i])
223 if (init != "") {
224 if (name in var_init && var_init[name] != init)
225 print "#error multiple initializers for " name
226 var_init[name] = init
14c7833c 227 }
e3339d0f
JM
228}
229for (i = 0; i < n_opts; i++) {
230 name = var_name(flags[i]);
231 if (name == "")
232 continue;
233
234 if (name in var_seen)
235 continue;
236
237 if (name in var_init)
238 init = var_init[name]
239 else
240 init = "0"
a56a0779 241
e3339d0f 242 print " " init ", /* " name " */"
f7f655c7
DD
243
244 var_seen[name] = 1;
a56a0779 245}
ee133b69
RS
246for (i = 0; i < n_opts; i++) {
247 name = static_var(opts[i], flags[i]);
46625112
JM
248 if (name != "") {
249 print " 0, /* " name " (private state) */"
250 print "#undef x_" name
251 }
ee133b69 252}
5e46b0c6
ILT
253for (i = 0; i < n_opts; i++) {
254 if (flag_set_p("SetByCombined", flags[i]))
255 print " false, /* frontend_set_" var_name(flags[i]) " */"
256}
46625112 257print "};"
ee133b69 258print ""
a75bfaa6 259print "struct gcc_options global_options;"
d4d24ba4
JM
260print "struct gcc_options global_options_set;"
261print ""
776dc15d
KC
262
263print "const char * const lang_names[] =\n{"
264for (i = 0; i < n_langs; i++) {
265 macros[i] = "CL_" langs[i]
e4590d63 266 gsub( "[^" alnum "_]", "X", macros[i] )
776dc15d
KC
267 s = substr(" ", length (macros[i]))
268 print " " quote langs[i] quote ","
269 }
270
271print " 0\n};\n"
272print "const unsigned int cl_options_count = N_OPTS;\n"
c662432e 273print "const unsigned int cl_lang_count = " n_langs ";\n"
776dc15d
KC
274
275print "const struct cl_option cl_options[] =\n{"
276
14c7833c
L
277j = 0
278for (i = 0; i < n_opts; i++) {
776dc15d 279 back_chain[i] = "N_OPTS";
14c7833c
L
280 indices[opts[i]] = j;
281 # Combine the flags of identical switches. Switches
282 # appear many times if they are handled by many front
283 # ends, for example.
284 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
285 flags[i + 1] = flags[i] " " flags[i + 1];
a16d1645
RW
286 if (help[i + 1] == "")
287 help[i + 1] = help[i]
40a1cfba
RW
288 else if (help[i] != "" && help[i + 1] != help[i])
289 print "warning: multiple different help strings for " \
290 opts[i] ":\n\t" help[i] "\n\t" help[i + 1] \
291 | "cat 1>&2"
14c7833c
L
292 i++;
293 back_chain[i] = "N_OPTS";
294 indices[opts[i]] = j;
295 }
296 j++;
297}
776dc15d 298
b167666c 299for (i = 0; i < n_opts; i++) {
a16d1645
RW
300 # With identical flags, pick only the last one. The
301 # earlier loop ensured that it has all flags merged,
302 # and a nonempty help text if one of the texts was nonempty.
b167666c 303 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
b167666c
RS
304 i++;
305 }
776dc15d 306
b167666c 307 len = length (opts[i]);
9db94baa 308 enum = opt_enum(opts[i])
b167666c
RS
309
310 # If this switch takes joined arguments, back-chain all
311 # subsequent switches to it for which it is a prefix. If
312 # a later switch S is a longer prefix of a switch T, T
313 # will be back-chained to S in a later iteration of this
314 # for() loop, which is what we want.
315 if (flag_set_p("Joined.*", flags[i])) {
316 for (j = i + 1; j < n_opts; j++) {
317 if (substr (opts[j], 1, len) != opts[i])
318 break;
319 back_chain[j] = enum;
776dc15d 320 }
b167666c 321 }
776dc15d 322
b167666c
RS
323 s = substr(" ", length (opts[i]))
324 if (i + 1 == n_opts)
325 comma = ""
776dc15d 326
b167666c
RS
327 if (help[i] == "")
328 hlp = "0"
329 else
330 hlp = quote help[i] quote;
776dc15d 331
61ff2bdc
JM
332 missing_arg_error = opt_args("MissingArgError", flags[i])
333 if (missing_arg_error == "")
334 missing_arg_error = "0"
335 else
336 missing_arg_error = quote missing_arg_error quote
337
2d2bd949
JM
338
339 warn_message = opt_args("Warn", flags[i])
340 if (warn_message == "")
341 warn_message = "0"
342 else
343 warn_message = quote warn_message quote
344
5de8299c
JM
345 alias_arg = opt_args("Alias", flags[i])
346 if (alias_arg == "") {
2d2bd949
JM
347 if (flag_set_p("Ignore", flags[i]))
348 alias_data = "NULL, NULL, OPT_SPECIAL_ignore"
349 else
350 alias_data = "NULL, NULL, N_OPTS"
5de8299c
JM
351 } else {
352 alias_opt = nth_arg(0, alias_arg)
353 alias_posarg = nth_arg(1, alias_arg)
354 alias_negarg = nth_arg(2, alias_arg)
355
46625112 356 if (var_ref(opts[i], flags[i]) != "-1")
5de8299c
JM
357 print "#error Alias setting variable"
358
359 if (alias_posarg != "" && alias_negarg == "") {
360 if (!flag_set_p("RejectNegative", flags[i]) \
361 && opts[i] ~ "^[Wfm]")
362 print "#error Alias with single argument " \
363 "allowing negative form"
364 }
666a21a2
JM
365 if (alias_posarg != "" \
366 && flag_set_p("NegativeAlias", flags[i])) {
367 print "#error Alias with multiple arguments " \
368 "used with NegativeAlias"
369 }
5de8299c
JM
370
371 alias_opt = opt_enum(alias_opt)
372 if (alias_posarg == "")
373 alias_posarg = "NULL"
374 else
375 alias_posarg = quote alias_posarg quote
376 if (alias_negarg == "")
377 alias_negarg = "NULL"
378 else
379 alias_negarg = quote alias_negarg quote
380 alias_data = alias_posarg ", " alias_negarg ", " alias_opt
381 }
382
14c7833c
L
383 neg = opt_args("Negative", flags[i]);
384 if (neg != "")
385 idx = indices[neg]
386 else {
387 if (flag_set_p("RejectNegative", flags[i]))
388 idx = -1;
389 else {
390 if (opts[i] ~ "^[Wfm]")
391 idx = indices[opts[i]];
392 else
393 idx = -1;
394 }
395 }
b1c61c7e
RW
396 # Split the printf after %u to work around an ia64-hp-hpux11.23
397 # awk bug.
2d2bd949
JM
398 printf(" { %c-%s%c,\n %s,\n %s,\n %s,\n %s, %s, %u,",
399 quote, opts[i], quote, hlp, missing_arg_error, warn_message,
5de8299c 400 alias_data, back_chain[i], len)
b1c61c7e 401 printf(" %d,\n", idx)
aeb70e78
RS
402 condition = opt_args("Condition", flags[i])
403 cl_flags = switch_flags(flags[i])
300d83d9
JM
404 cl_bit_fields = switch_bit_fields(flags[i])
405 cl_zero_bit_fields = switch_bit_fields("")
aeb70e78
RS
406 if (condition != "")
407 printf("#if %s\n" \
408 " %s,\n" \
300d83d9 409 " 0, %s,\n" \
aeb70e78 410 "#else\n" \
300d83d9
JM
411 " 0,\n" \
412 " 1 /* Disabled. */, %s,\n" \
aeb70e78 413 "#endif\n",
300d83d9 414 condition, cl_flags, cl_bit_fields, cl_zero_bit_fields)
aeb70e78 415 else
300d83d9
JM
416 printf(" %s,\n" \
417 " 0, %s,\n",
418 cl_flags, cl_bit_fields)
ee133b69
RS
419 printf(" %s, %s }%s\n", var_ref(opts[i], flags[i]),
420 var_set(flags[i]), comma)
776dc15d
KC
421}
422
423print "};"
ab442df7
MM
424
425print "";
e62fe68a 426print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)"
ab442df7
MM
427print "";
428print "/* Save optimization variables into a structure. */"
429print "void";
46625112 430print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
ab442df7
MM
431print "{";
432
433n_opt_char = 2;
434n_opt_short = 0;
435n_opt_int = 0;
fd438373 436n_opt_enum = 1;
ab442df7
MM
437n_opt_other = 0;
438var_opt_char[0] = "optimize";
439var_opt_char[1] = "optimize_size";
440var_opt_range["optimize"] = "0, 255";
441var_opt_range["optimize_size"] = "0, 255";
fd438373 442var_opt_enum[0] = "flag_fp_contract_mode";
ab442df7
MM
443
444# Sort by size to mimic how the structure is laid out to be friendlier to the
445# cache.
446
447for (i = 0; i < n_opts; i++) {
448 if (flag_set_p("Optimization", flags[i])) {
449 name = var_name(flags[i])
450 if(name == "")
451 continue;
452
453 if(name in var_opt_seen)
454 continue;
455
456 var_opt_seen[name]++;
457 otype = var_type_struct(flags[i]);
458 if (otype ~ "^((un)?signed +)?int *$")
459 var_opt_int[n_opt_int++] = name;
460
461 else if (otype ~ "^((un)?signed +)?short *$")
462 var_opt_short[n_opt_short++] = name;
463
fd438373
MM
464 else if (otype ~ ("^enum +[_" alnum "]+ *"))
465 var_opt_enum[n_opt_enum++] = name;
466
ab442df7
MM
467 else if (otype ~ "^((un)?signed +)?char *$") {
468 var_opt_char[n_opt_char++] = name;
469 if (otype ~ "^unsigned +char *$")
470 var_opt_range[name] = "0, 255"
471 else if (otype ~ "^signed +char *$")
472 var_opt_range[name] = "-128, 127"
473 }
474 else
475 var_opt_other[n_opt_other++] = name;
476 }
477}
478
479for (i = 0; i < n_opt_char; i++) {
480 name = var_opt_char[i];
481 if (var_opt_range[name] != "")
46625112 482 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_opt_range[name] "));";
ab442df7
MM
483}
484
485print "";
486for (i = 0; i < n_opt_other; i++) {
46625112 487 print " ptr->x_" var_opt_other[i] " = opts->x_" var_opt_other[i] ";";
ab442df7
MM
488}
489
490for (i = 0; i < n_opt_int; i++) {
46625112 491 print " ptr->x_" var_opt_int[i] " = opts->x_" var_opt_int[i] ";";
ab442df7
MM
492}
493
fd438373
MM
494for (i = 0; i < n_opt_enum; i++) {
495 print " ptr->x_" var_opt_enum[i] " = opts->x_" var_opt_enum[i] ";";
496}
497
ab442df7 498for (i = 0; i < n_opt_short; i++) {
46625112 499 print " ptr->x_" var_opt_short[i] " = opts->x_" var_opt_short[i] ";";
ab442df7
MM
500}
501
502for (i = 0; i < n_opt_char; i++) {
46625112 503 print " ptr->x_" var_opt_char[i] " = opts->x_" var_opt_char[i] ";";
ab442df7
MM
504}
505
506print "}";
507
508print "";
509print "/* Restore optimization options from a structure. */";
510print "void";
46625112 511print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
ab442df7
MM
512print "{";
513
514for (i = 0; i < n_opt_other; i++) {
46625112 515 print " opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
ab442df7
MM
516}
517
518for (i = 0; i < n_opt_int; i++) {
46625112 519 print " opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
ab442df7
MM
520}
521
fd438373
MM
522for (i = 0; i < n_opt_enum; i++) {
523 print " opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
524}
525
ab442df7 526for (i = 0; i < n_opt_short; i++) {
46625112 527 print " opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
ab442df7
MM
528}
529
530for (i = 0; i < n_opt_char; i++) {
46625112 531 print " opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
ab442df7
MM
532}
533
2b7e2984 534print " targetm.override_options_after_change ();";
ab442df7
MM
535print "}";
536
537print "";
538print "/* Print optimization options from a structure. */";
539print "void";
540print "cl_optimization_print (FILE *file,";
541print " int indent_to,";
542print " struct cl_optimization *ptr)";
543print "{";
544
545print " fputs (\"\\n\", file);";
546for (i = 0; i < n_opt_other; i++) {
e3339d0f 547 print " if (ptr->x_" var_opt_other[i] ")";
35c59d9c 548 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
ab442df7
MM
549 print " indent_to, \"\",";
550 print " \"" var_opt_other[i] "\",";
e3339d0f 551 print " (unsigned long)ptr->x_" var_opt_other[i] ");";
ab442df7
MM
552 print "";
553}
554
555for (i = 0; i < n_opt_int; i++) {
e3339d0f 556 print " if (ptr->x_" var_opt_int[i] ")";
35c59d9c 557 print " fprintf (file, \"%*s%s (%#x)\\n\",";
ab442df7
MM
558 print " indent_to, \"\",";
559 print " \"" var_opt_int[i] "\",";
e3339d0f 560 print " ptr->x_" var_opt_int[i] ");";
ab442df7
MM
561 print "";
562}
563
fd438373
MM
564for (i = 0; i < n_opt_enum; i++) {
565 print " fprintf (file, \"%*s%s (%#x)\\n\",";
566 print " indent_to, \"\",";
567 print " \"" var_opt_enum[i] "\",";
568 print " (int) ptr->x_" var_opt_enum[i] ");";
569 print "";
570}
571
ab442df7 572for (i = 0; i < n_opt_short; i++) {
e3339d0f 573 print " if (ptr->x_" var_opt_short[i] ")";
35c59d9c 574 print " fprintf (file, \"%*s%s (%#x)\\n\",";
ab442df7
MM
575 print " indent_to, \"\",";
576 print " \"" var_opt_short[i] "\",";
e3339d0f 577 print " ptr->x_" var_opt_short[i] ");";
ab442df7
MM
578 print "";
579}
580
581for (i = 0; i < n_opt_char; i++) {
e3339d0f 582 print " if (ptr->x_" var_opt_char[i] ")";
35c59d9c 583 print " fprintf (file, \"%*s%s (%#x)\\n\",";
ab442df7
MM
584 print " indent_to, \"\",";
585 print " \"" var_opt_char[i] "\",";
e3339d0f 586 print " ptr->x_" var_opt_char[i] ");";
ab442df7
MM
587 print "";
588}
589
590print "}";
591
592print "";
593print "/* Save selected option variables into a structure. */"
594print "void";
46625112 595print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
ab442df7
MM
596print "{";
597
598n_target_char = 0;
599n_target_short = 0;
600n_target_int = 0;
fd438373 601n_target_enum = 0;
ab442df7
MM
602n_target_other = 0;
603
604if (have_save) {
605 for (i = 0; i < n_opts; i++) {
606 if (flag_set_p("Save", flags[i])) {
607 name = var_name(flags[i])
608 if(name == "")
609 name = "target_flags";
610
611 if(name in var_save_seen)
612 continue;
613
614 var_save_seen[name]++;
615 otype = var_type_struct(flags[i])
616 if (otype ~ "^((un)?signed +)?int *$")
617 var_target_int[n_target_int++] = name;
618
619 else if (otype ~ "^((un)?signed +)?short *$")
620 var_target_short[n_target_short++] = name;
621
fd438373
MM
622 else if (otype ~ ("^enum +[_" alnum "]+ *$"))
623 var_target_enum[n_target_enum++] = name;
624
ab442df7
MM
625 else if (otype ~ "^((un)?signed +)?char *$") {
626 var_target_char[n_target_char++] = name;
627 if (otype ~ "^unsigned +char *$")
628 var_target_range[name] = "0, 255"
629 else if (otype ~ "^signed +char *$")
630 var_target_range[name] = "-128, 127"
631 }
632 else
633 var_target_other[n_target_other++] = name;
634 }
635 }
636} else {
637 var_target_int[n_target_int++] = "target_flags";
638}
639
640have_assert = 0;
641for (i = 0; i < n_target_char; i++) {
642 name = var_target_char[i];
643 if (var_target_range[name] != "") {
644 have_assert = 1;
46625112 645 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
ab442df7
MM
646 }
647}
648
649if (have_assert)
650 print "";
651
652print " if (targetm.target_option.save)";
653print " targetm.target_option.save (ptr);";
654print "";
655
fd438373
MM
656for (i = 0; i < n_extra_target_vars; i++) {
657 print " ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
658}
659
ab442df7 660for (i = 0; i < n_target_other; i++) {
46625112 661 print " ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
ab442df7
MM
662}
663
fd438373
MM
664for (i = 0; i < n_target_enum; i++) {
665 print " ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
666}
667
ab442df7 668for (i = 0; i < n_target_int; i++) {
46625112 669 print " ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
ab442df7
MM
670}
671
672for (i = 0; i < n_target_short; i++) {
46625112 673 print " ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
ab442df7
MM
674}
675
676for (i = 0; i < n_target_char; i++) {
46625112 677 print " ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
ab442df7
MM
678}
679
680print "}";
681
682print "";
683print "/* Restore selected current options from a structure. */";
684print "void";
46625112 685print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
ab442df7
MM
686print "{";
687
fd438373
MM
688for (i = 0; i < n_extra_target_vars; i++) {
689 print " opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
690}
691
ab442df7 692for (i = 0; i < n_target_other; i++) {
46625112 693 print " opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
ab442df7
MM
694}
695
fd438373
MM
696for (i = 0; i < n_target_enum; i++) {
697 print " opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
698}
699
ab442df7 700for (i = 0; i < n_target_int; i++) {
46625112 701 print " opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
ab442df7
MM
702}
703
704for (i = 0; i < n_target_short; i++) {
46625112 705 print " opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
ab442df7
MM
706}
707
708for (i = 0; i < n_target_char; i++) {
46625112 709 print " opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
ab442df7
MM
710}
711
712# This must occur after the normal variables in case the code depends on those
713# variables.
714print "";
715print " if (targetm.target_option.restore)";
716print " targetm.target_option.restore (ptr);";
717
718print "}";
719
720print "";
721print "/* Print optimization options from a structure. */";
722print "void";
723print "cl_target_option_print (FILE *file,";
724print " int indent,";
725print " struct cl_target_option *ptr)";
726print "{";
727
728print " fputs (\"\\n\", file);";
729for (i = 0; i < n_target_other; i++) {
e3339d0f 730 print " if (ptr->x_" var_target_other[i] ")";
35c59d9c 731 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
ab442df7
MM
732 print " indent, \"\",";
733 print " \"" var_target_other[i] "\",";
e3339d0f 734 print " (unsigned long)ptr->x_" var_target_other[i] ");";
ab442df7 735 print "";
fd438373
MM
736}
737
738for (i = 0; i < n_target_enum; i++) {
739 print " if (ptr->x_" var_target_enum[i] ")";
740 print " fprintf (file, \"%*s%s (%#x)\\n\",";
741 print " indent, \"\",";
742 print " \"" var_target_enum[i] "\",";
743 print " ptr->x_" var_target_enum[i] ");";
744 print "";
ab442df7
MM
745}
746
747for (i = 0; i < n_target_int; i++) {
e3339d0f 748 print " if (ptr->x_" var_target_int[i] ")";
35c59d9c 749 print " fprintf (file, \"%*s%s (%#x)\\n\",";
ab442df7
MM
750 print " indent, \"\",";
751 print " \"" var_target_int[i] "\",";
e3339d0f 752 print " ptr->x_" var_target_int[i] ");";
ab442df7
MM
753 print "";
754}
755
756for (i = 0; i < n_target_short; i++) {
e3339d0f 757 print " if (ptr->x_" var_target_short[i] ")";
35c59d9c 758 print " fprintf (file, \"%*s%s (%#x)\\n\",";
ab442df7
MM
759 print " indent, \"\",";
760 print " \"" var_target_short[i] "\",";
e3339d0f 761 print " ptr->x_" var_target_short[i] ");";
ab442df7
MM
762 print "";
763}
764
765for (i = 0; i < n_target_char; i++) {
e3339d0f 766 print " if (ptr->x_" var_target_char[i] ")";
35c59d9c 767 print " fprintf (file, \"%*s%s (%#x)\\n\",";
ab442df7
MM
768 print " indent, \"\",";
769 print " \"" var_target_char[i] "\",";
e3339d0f 770 print " ptr->x_" var_target_char[i] ");";
ab442df7
MM
771 print "";
772}
773
774print "";
775print " if (targetm.target_option.print)";
776print " targetm.target_option.print (file, indent, ptr);";
777
778print "}";
779print "#endif";
780
776dc15d 781}