OSDN Git Service

* doc/options.texi (Enum, EnumValue): Document new record types.
[pf3gnuchains/gcc-fork.git] / gcc / optc-gen.awk
1 #  Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
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 # 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
29 BEGIN {
30         n_opts = 0
31         n_langs = 0
32         n_target_save = 0
33         n_extra_vars = 0
34         n_extra_target_vars = 0
35         n_extra_c_includes = 0
36         n_extra_h_includes = 0
37         n_enums = 0
38         quote = "\042"
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                 }
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                 }
56                 else if ($1 == "Variable") {
57                         extra_vars[n_extra_vars] = $2
58                         n_extra_vars++
59                 }
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                 }
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                 }
109                 else {
110                         name = opt_args("Mask", $1)
111                         if (name == "") {
112                                 opts[n_opts]  = $1
113                                 flags[n_opts] = $2
114                                 help[n_opts]  = $3
115                                 for (i = 4; i <= NF; i++)
116                                         help[n_opts] = help[n_opts] " " $i
117                                 n_opts++;
118                         }
119                 }
120         }
121
122 # Dump that array of options into a C file.
123 END {
124 print "/* This file is auto-generated by optc-gen.awk.  */"
125 print ""
126 n_headers = split(header_name, headers, " ")
127 for (i = 1; i <= n_headers; i++)
128         print "#include " quote headers[i] quote
129 print "#include " quote "opts.h" quote
130 print "#include " quote "intl.h" quote
131 print ""
132 print "#ifndef GCC_DRIVER"
133 print "#include " quote "flags.h" quote
134 print "#include " quote "target.h" quote
135 print "#endif /* GCC_DRIVER */"
136 print ""
137
138 if (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
145 for (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
168 print "const struct cl_enum cl_enums[] ="
169 print "{"
170 for (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 }
191 print "};"
192 print "const unsigned int cl_enums_count = " n_enums ";"
193 print ""
194
195 have_save = 0;
196 if (n_extra_target_vars)
197         have_save = 1
198
199 print "const struct gcc_options global_options_init =\n{"
200 for (i = 0; i < n_extra_vars; i++) {
201         var = extra_vars[i]
202         init = extra_vars[i]
203         if (var ~ "=" ) {
204                 sub(".*= *", "", init)
205                 sub(" *=.*", "", var)
206                 sub("^.*[ *]", "", var)
207                 sub("\\[.*\\]$", "", var)
208         } else {
209                 init = "0"
210         }
211         var_seen[var] = 1
212         print "  " init ", /* " var " */"
213 }
214 for (i = 0; i < n_opts; i++) {
215         if (flag_set_p("Save", flags[i]))
216                 have_save = 1;
217
218         name = var_name(flags[i]);
219         if (name == "")
220                 continue;
221
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
227         }
228 }
229 for (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"
241
242         print "  " init ", /* " name " */"
243
244         var_seen[name] = 1;
245 }
246 for (i = 0; i < n_opts; i++) {
247         name = static_var(opts[i], flags[i]);
248         if (name != "") {
249                 print "  0, /* " name " (private state) */"
250                 print "#undef x_" name
251         }
252 }
253 print "};"
254 print ""
255 print "struct gcc_options global_options;"
256 print "struct gcc_options global_options_set;"
257 print ""
258
259 print "const char * const lang_names[] =\n{"
260 for (i = 0; i < n_langs; i++) {
261         macros[i] = "CL_" langs[i]
262         gsub( "[^" alnum "_]", "X", macros[i] )
263         s = substr("         ", length (macros[i]))
264         print "  " quote langs[i] quote ","
265     }
266
267 print "  0\n};\n"
268 print "const unsigned int cl_options_count = N_OPTS;\n"
269 print "const unsigned int cl_lang_count = " n_langs ";\n"
270
271 print "const struct cl_option cl_options[] =\n{"
272
273 j = 0
274 for (i = 0; i < n_opts; i++) {
275         back_chain[i] = "N_OPTS";
276         indices[opts[i]] = j;
277         # Combine the flags of identical switches.  Switches
278         # appear many times if they are handled by many front
279         # ends, for example.
280         while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
281                 flags[i + 1] = flags[i] " " flags[i + 1];
282                 if (help[i + 1] == "")
283                         help[i + 1] = help[i]
284                 else if (help[i] != "" && help[i + 1] != help[i])
285                         print "warning: multiple different help strings for " \
286                                 opts[i] ":\n\t" help[i] "\n\t" help[i + 1] \
287                                 | "cat 1>&2"
288                 i++;
289                 back_chain[i] = "N_OPTS";
290                 indices[opts[i]] = j;
291         }
292         j++;
293 }
294
295 for (i = 0; i < n_opts; i++) {
296         # With identical flags, pick only the last one.  The
297         # earlier loop ensured that it has all flags merged,
298         # and a nonempty help text if one of the texts was nonempty.
299         while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
300                 i++;
301         }
302
303         len = length (opts[i]);
304         enum = opt_enum(opts[i])
305
306         # If this switch takes joined arguments, back-chain all
307         # subsequent switches to it for which it is a prefix.  If
308         # a later switch S is a longer prefix of a switch T, T
309         # will be back-chained to S in a later iteration of this
310         # for() loop, which is what we want.
311         if (flag_set_p("Joined.*", flags[i])) {
312                 for (j = i + 1; j < n_opts; j++) {
313                         if (substr (opts[j], 1, len) != opts[i])
314                                 break;
315                         back_chain[j] = enum;
316                 }
317         }
318
319         s = substr("                                  ", length (opts[i]))
320         if (i + 1 == n_opts)
321                 comma = ""
322
323         if (help[i] == "")
324                 hlp = "0"
325         else
326                 hlp = quote help[i] quote;
327
328         missing_arg_error = opt_args("MissingArgError", flags[i])
329         if (missing_arg_error == "")
330                 missing_arg_error = "0"
331         else
332                 missing_arg_error = quote missing_arg_error quote
333
334
335         warn_message = opt_args("Warn", flags[i])
336         if (warn_message == "")
337                 warn_message = "0"
338         else
339                 warn_message = quote warn_message quote
340
341         alias_arg = opt_args("Alias", flags[i])
342         if (alias_arg == "") {
343                 if (flag_set_p("Ignore", flags[i]))
344                         alias_data = "NULL, NULL, OPT_SPECIAL_ignore"
345                 else
346                         alias_data = "NULL, NULL, N_OPTS"
347         } else {
348                 alias_opt = nth_arg(0, alias_arg)
349                 alias_posarg = nth_arg(1, alias_arg)
350                 alias_negarg = nth_arg(2, alias_arg)
351
352                 if (var_ref(opts[i], flags[i]) != "-1")
353                         print "#error Alias setting variable"
354
355                 if (alias_posarg != "" && alias_negarg == "") {
356                         if (!flag_set_p("RejectNegative", flags[i]) \
357                             && opts[i] ~ "^[Wfm]")
358                                 print "#error Alias with single argument " \
359                                         "allowing negative form"
360                 }
361
362                 alias_opt = opt_enum(alias_opt)
363                 if (alias_posarg == "")
364                         alias_posarg = "NULL"
365                 else
366                         alias_posarg = quote alias_posarg quote
367                 if (alias_negarg == "")
368                         alias_negarg = "NULL"
369                 else
370                         alias_negarg = quote alias_negarg quote
371                 alias_data = alias_posarg ", " alias_negarg ", " alias_opt
372         }
373
374         neg = opt_args("Negative", flags[i]);
375         if (neg != "")
376                 idx = indices[neg]
377         else {
378                 if (flag_set_p("RejectNegative", flags[i]))
379                         idx = -1;
380                 else {
381                         if (opts[i] ~ "^[Wfm]")
382                                 idx = indices[opts[i]];
383                         else
384                                 idx = -1;
385                 }
386         }
387         # Split the printf after %u to work around an ia64-hp-hpux11.23
388         # awk bug.
389         printf("  { %c-%s%c,\n    %s,\n    %s,\n    %s,\n    %s, %s, %u,",
390                quote, opts[i], quote, hlp, missing_arg_error, warn_message,
391                alias_data, back_chain[i], len)
392         printf(" %d,\n", idx)
393         condition = opt_args("Condition", flags[i])
394         cl_flags = switch_flags(flags[i])
395         if (condition != "")
396                 printf("#if %s\n" \
397                        "    %s,\n" \
398                        "#else\n" \
399                        "    CL_DISABLED,\n" \
400                        "#endif\n",
401                        condition, cl_flags, cl_flags)
402         else
403                 printf("    %s,\n", cl_flags)
404         printf("    %s, %s }%s\n", var_ref(opts[i], flags[i]),
405                var_set(flags[i]), comma)
406 }
407
408 print "};"
409
410 print "";
411 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)"
412 print "";
413 print "/* Save optimization variables into a structure.  */"
414 print "void";
415 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
416 print "{";
417
418 n_opt_char = 2;
419 n_opt_short = 0;
420 n_opt_int = 0;
421 n_opt_enum = 1;
422 n_opt_other = 0;
423 var_opt_char[0] = "optimize";
424 var_opt_char[1] = "optimize_size";
425 var_opt_range["optimize"] = "0, 255";
426 var_opt_range["optimize_size"] = "0, 255";
427 var_opt_enum[0] = "flag_fp_contract_mode";
428
429 # Sort by size to mimic how the structure is laid out to be friendlier to the
430 # cache.
431
432 for (i = 0; i < n_opts; i++) {
433         if (flag_set_p("Optimization", flags[i])) {
434                 name = var_name(flags[i])
435                 if(name == "")
436                         continue;
437
438                 if(name in var_opt_seen)
439                         continue;
440
441                 var_opt_seen[name]++;
442                 otype = var_type_struct(flags[i]);
443                 if (otype ~ "^((un)?signed +)?int *$")
444                         var_opt_int[n_opt_int++] = name;
445
446                 else if (otype ~ "^((un)?signed +)?short *$")
447                         var_opt_short[n_opt_short++] = name;
448
449                 else if (otype ~ ("^enum +[_" alnum "]+ *"))
450                         var_opt_enum[n_opt_enum++] = name;
451
452                 else if (otype ~ "^((un)?signed +)?char *$") {
453                         var_opt_char[n_opt_char++] = name;
454                         if (otype ~ "^unsigned +char *$")
455                                 var_opt_range[name] = "0, 255"
456                         else if (otype ~ "^signed +char *$")
457                                 var_opt_range[name] = "-128, 127"
458                 }
459                 else
460                         var_opt_other[n_opt_other++] = name;
461         }
462 }
463
464 for (i = 0; i < n_opt_char; i++) {
465         name = var_opt_char[i];
466         if (var_opt_range[name] != "")
467                 print "  gcc_assert (IN_RANGE (opts->x_" name ", " var_opt_range[name] "));";
468 }
469
470 print "";
471 for (i = 0; i < n_opt_other; i++) {
472         print "  ptr->x_" var_opt_other[i] " = opts->x_" var_opt_other[i] ";";
473 }
474
475 for (i = 0; i < n_opt_int; i++) {
476         print "  ptr->x_" var_opt_int[i] " = opts->x_" var_opt_int[i] ";";
477 }
478
479 for (i = 0; i < n_opt_enum; i++) {
480         print "  ptr->x_" var_opt_enum[i] " = opts->x_" var_opt_enum[i] ";";
481 }
482
483 for (i = 0; i < n_opt_short; i++) {
484         print "  ptr->x_" var_opt_short[i] " = opts->x_" var_opt_short[i] ";";
485 }
486
487 for (i = 0; i < n_opt_char; i++) {
488         print "  ptr->x_" var_opt_char[i] " = opts->x_" var_opt_char[i] ";";
489 }
490
491 print "}";
492
493 print "";
494 print "/* Restore optimization options from a structure.  */";
495 print "void";
496 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
497 print "{";
498
499 for (i = 0; i < n_opt_other; i++) {
500         print "  opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
501 }
502
503 for (i = 0; i < n_opt_int; i++) {
504         print "  opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
505 }
506
507 for (i = 0; i < n_opt_enum; i++) {
508         print "  opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
509 }
510
511 for (i = 0; i < n_opt_short; i++) {
512         print "  opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
513 }
514
515 for (i = 0; i < n_opt_char; i++) {
516         print "  opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
517 }
518
519 print "  targetm.override_options_after_change ();";
520 print "}";
521
522 print "";
523 print "/* Print optimization options from a structure.  */";
524 print "void";
525 print "cl_optimization_print (FILE *file,";
526 print "                       int indent_to,";
527 print "                       struct cl_optimization *ptr)";
528 print "{";
529
530 print "  fputs (\"\\n\", file);";
531 for (i = 0; i < n_opt_other; i++) {
532         print "  if (ptr->x_" var_opt_other[i] ")";
533         print "    fprintf (file, \"%*s%s (%#lx)\\n\",";
534         print "             indent_to, \"\",";
535         print "             \"" var_opt_other[i] "\",";
536         print "             (unsigned long)ptr->x_" var_opt_other[i] ");";
537         print "";
538 }
539
540 for (i = 0; i < n_opt_int; i++) {
541         print "  if (ptr->x_" var_opt_int[i] ")";
542         print "    fprintf (file, \"%*s%s (%#x)\\n\",";
543         print "             indent_to, \"\",";
544         print "             \"" var_opt_int[i] "\",";
545         print "             ptr->x_" var_opt_int[i] ");";
546         print "";
547 }
548
549 for (i = 0; i < n_opt_enum; i++) {
550         print "  fprintf (file, \"%*s%s (%#x)\\n\",";
551         print "           indent_to, \"\",";
552         print "           \"" var_opt_enum[i] "\",";
553         print "           (int) ptr->x_" var_opt_enum[i] ");";
554         print "";
555 }
556
557 for (i = 0; i < n_opt_short; i++) {
558         print "  if (ptr->x_" var_opt_short[i] ")";
559         print "    fprintf (file, \"%*s%s (%#x)\\n\",";
560         print "             indent_to, \"\",";
561         print "             \"" var_opt_short[i] "\",";
562         print "             ptr->x_" var_opt_short[i] ");";
563         print "";
564 }
565
566 for (i = 0; i < n_opt_char; i++) {
567         print "  if (ptr->x_" var_opt_char[i] ")";
568         print "    fprintf (file, \"%*s%s (%#x)\\n\",";
569         print "             indent_to, \"\",";
570         print "             \"" var_opt_char[i] "\",";
571         print "             ptr->x_" var_opt_char[i] ");";
572         print "";
573 }
574
575 print "}";
576
577 print "";
578 print "/* Save selected option variables into a structure.  */"
579 print "void";
580 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
581 print "{";
582
583 n_target_char = 0;
584 n_target_short = 0;
585 n_target_int = 0;
586 n_target_enum = 0;
587 n_target_other = 0;
588
589 if (have_save) {
590         for (i = 0; i < n_opts; i++) {
591                 if (flag_set_p("Save", flags[i])) {
592                         name = var_name(flags[i])
593                         if(name == "")
594                                 name = "target_flags";
595
596                         if(name in var_save_seen)
597                                 continue;
598
599                         var_save_seen[name]++;
600                         otype = var_type_struct(flags[i])
601                         if (otype ~ "^((un)?signed +)?int *$")
602                                 var_target_int[n_target_int++] = name;
603
604                         else if (otype ~ "^((un)?signed +)?short *$")
605                                 var_target_short[n_target_short++] = name;
606
607                         else if (otype ~ ("^enum +[_" alnum "]+ *$"))
608                                 var_target_enum[n_target_enum++] = name;
609
610                         else if (otype ~ "^((un)?signed +)?char *$") {
611                                 var_target_char[n_target_char++] = name;
612                                 if (otype ~ "^unsigned +char *$")
613                                         var_target_range[name] = "0, 255"
614                                 else if (otype ~ "^signed +char *$")
615                                         var_target_range[name] = "-128, 127"
616                         }
617                         else
618                                 var_target_other[n_target_other++] = name;
619                 }
620         }
621 } else {
622         var_target_int[n_target_int++] = "target_flags";
623 }
624
625 have_assert = 0;
626 for (i = 0; i < n_target_char; i++) {
627         name = var_target_char[i];
628         if (var_target_range[name] != "") {
629                 have_assert = 1;
630                 print "  gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
631         }
632 }
633
634 if (have_assert)
635         print "";
636
637 print "  if (targetm.target_option.save)";
638 print "    targetm.target_option.save (ptr);";
639 print "";
640
641 for (i = 0; i < n_extra_target_vars; i++) {
642         print "  ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
643 }
644
645 for (i = 0; i < n_target_other; i++) {
646         print "  ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
647 }
648
649 for (i = 0; i < n_target_enum; i++) {
650         print "  ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
651 }
652
653 for (i = 0; i < n_target_int; i++) {
654         print "  ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
655 }
656
657 for (i = 0; i < n_target_short; i++) {
658         print "  ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
659 }
660
661 for (i = 0; i < n_target_char; i++) {
662         print "  ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
663 }
664
665 print "}";
666
667 print "";
668 print "/* Restore selected current options from a structure.  */";
669 print "void";
670 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
671 print "{";
672
673 for (i = 0; i < n_extra_target_vars; i++) {
674         print "  opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
675 }
676
677 for (i = 0; i < n_target_other; i++) {
678         print "  opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
679 }
680
681 for (i = 0; i < n_target_enum; i++) {
682         print "  opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
683 }
684
685 for (i = 0; i < n_target_int; i++) {
686         print "  opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
687 }
688
689 for (i = 0; i < n_target_short; i++) {
690         print "  opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
691 }
692
693 for (i = 0; i < n_target_char; i++) {
694         print "  opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
695 }
696
697 # This must occur after the normal variables in case the code depends on those
698 # variables.
699 print "";
700 print "  if (targetm.target_option.restore)";
701 print "    targetm.target_option.restore (ptr);";
702
703 print "}";
704
705 print "";
706 print "/* Print optimization options from a structure.  */";
707 print "void";
708 print "cl_target_option_print (FILE *file,";
709 print "                        int indent,";
710 print "                        struct cl_target_option *ptr)";
711 print "{";
712
713 print "  fputs (\"\\n\", file);";
714 for (i = 0; i < n_target_other; i++) {
715         print "  if (ptr->x_" var_target_other[i] ")";
716         print "    fprintf (file, \"%*s%s (%#lx)\\n\",";
717         print "             indent, \"\",";
718         print "             \"" var_target_other[i] "\",";
719         print "             (unsigned long)ptr->x_" var_target_other[i] ");";
720         print "";
721 }
722
723 for (i = 0; i < n_target_enum; i++) {
724         print "  if (ptr->x_" var_target_enum[i] ")";
725         print "    fprintf (file, \"%*s%s (%#x)\\n\",";
726         print "             indent, \"\",";
727         print "             \"" var_target_enum[i] "\",";
728         print "             ptr->x_" var_target_enum[i] ");";
729         print "";
730 }
731
732 for (i = 0; i < n_target_int; i++) {
733         print "  if (ptr->x_" var_target_int[i] ")";
734         print "    fprintf (file, \"%*s%s (%#x)\\n\",";
735         print "             indent, \"\",";
736         print "             \"" var_target_int[i] "\",";
737         print "             ptr->x_" var_target_int[i] ");";
738         print "";
739 }
740
741 for (i = 0; i < n_target_short; i++) {
742         print "  if (ptr->x_" var_target_short[i] ")";
743         print "    fprintf (file, \"%*s%s (%#x)\\n\",";
744         print "             indent, \"\",";
745         print "             \"" var_target_short[i] "\",";
746         print "             ptr->x_" var_target_short[i] ");";
747         print "";
748 }
749
750 for (i = 0; i < n_target_char; i++) {
751         print "  if (ptr->x_" var_target_char[i] ")";
752         print "    fprintf (file, \"%*s%s (%#x)\\n\",";
753         print "             indent, \"\",";
754         print "             \"" var_target_char[i] "\",";
755         print "             ptr->x_" var_target_char[i] ");";
756         print "";
757 }
758
759 print "";
760 print "  if (targetm.target_option.print)";
761 print "    targetm.target_option.print (file, indent, ptr);";
762
763 print "}";
764 print "#endif";
765
766 }