OSDN Git Service

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