analyzer: fix feasibility false +ve on jumps through function ptrs [PR107582]
[platform/upstream/gcc.git] / gcc / optc-gen.awk
1 #  Copyright (C) 2003-2022 Free Software Foundation, Inc.
2 #  Contributed by Kelley Cook, June 2004.
3 #  Original code from Neil Booth, May 2003.
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; see the file COPYING3.  If not see
17 # <http://www.gnu.org/licenses/>.
18
19 # This Awk script reads in the option records generated from 
20 # opt-gather.awk, combines the flags of duplicate options and generates a
21 # C file.
22 #
23
24 # This program uses functions from opt-functions.awk and code from
25 # opt-read.awk.
26 #
27 # Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-gen.awk \
28 #            [-v header_name=header.h] < inputfile > options.cc
29
30 # Dump that array of options into a C file.
31 END {
32
33
34 # Combine the flags of identical switches.  Switches
35 # appear many times if they are handled by many front
36 # ends, for example.
37 for (i = 0; i < n_opts; i++) {
38     merged_flags[i] = flags[i]
39 }
40 for (i = 0; i < n_opts; i++) {
41     while(i + 1 != n_opts && opts[i] == opts[i + 1] ) {
42         merged_flags[i + 1] = merged_flags[i] " " merged_flags[i + 1];
43         i++;
44     }
45 }
46
47 # Record EnabledBy and LangEnabledBy uses.
48 n_enabledby = 0;
49 for (i = 0; i < n_langs; i++) {
50     n_enabledby_lang[i] = 0;
51 }
52 for (i = 0; i < n_opts; i++) {
53     enabledby_arg = opt_args("EnabledBy", flags[i]);
54     if (enabledby_arg != "") {
55         logical_and = index(enabledby_arg, " && ");
56         if (logical_and != 0) {
57             # EnabledBy(arg1 && arg2)
58             split_sep = " && ";
59         } else {
60             # EnabledBy(arg) or EnabledBy(arg1 || arg2 || arg3)
61             split_sep = " \\|\\| ";
62         }
63         n_enabledby_names = split(enabledby_arg, enabledby_names, split_sep);
64         if (logical_and != 0 && n_enabledby_names > 2) {
65             print "#error " opts[i] " EnabledBy(Wfoo && Wbar && Wbaz) currently not supported"
66         }
67         for (j = 1; j <= n_enabledby_names; j++) {
68             enabledby_name = enabledby_names[j];
69             enabledby_index = opt_numbers[enabledby_name];
70             if (enabledby_index == "") {
71                 print "#error " opts[i] " Enabledby(" enabledby_name "), unknown option '" enabledby_name "'"
72             } else if (!flag_set_p("Common", merged_flags[enabledby_index])) {
73                 print "#error " opts[i] " Enabledby(" enabledby_name "), '" \
74                     enabledby_name "' must have flag 'Common'"          \
75                     " to use Enabledby(), otherwise use LangEnabledBy()"
76             } else {
77                 condition = "";
78                 if (logical_and != 0) {
79                     opt_var_name_1 = search_var_name(enabledby_names[1], opt_numbers, opts, flags, n_opts);
80                     opt_var_name_2 = search_var_name(enabledby_names[2], opt_numbers, opts, flags, n_opts);
81                     if (opt_var_name_1 == "") {
82                         print "#error " enabledby_names[1] " does not have a Var() flag"
83                     }
84                     if (opt_var_name_2 == "") {
85                         print "#error " enabledby_names[2] " does not have a Var() flag"
86                     }
87                     condition = "opts->x_" opt_var_name_1 " && opts->x_" opt_var_name_2;
88                 }
89                 if (enables[enabledby_name] == "") {
90                     enabledby[n_enabledby] = enabledby_name;
91                     n_enabledby++;
92                 }
93                 enables[enabledby_name] = enables[enabledby_name] opts[i] ";";
94                 enablesif[enabledby_name] = enablesif[enabledby_name] condition ";";
95             }
96         }
97     }
98
99     enabledby_arg = opt_args("LangEnabledBy", flags[i]);
100     if (enabledby_arg != "") {
101         enabledby_n_args = n_args(enabledby_arg)
102         if (enabledby_n_args != 2 \
103             && enabledby_n_args != 4) {
104             print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify two or four arguments"
105         }
106
107         enabledby_langs = nth_arg(0, enabledby_arg);
108         if (enabledby_langs == "")
109             print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify LANGUAGE"
110         enabledby_opt = nth_arg(1, enabledby_arg);
111         if (enabledby_opt == "")
112             print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") must specify OPT"
113
114         enabledby_posarg_negarg = ""
115         if (enabledby_n_args == 4) {
116             enabledby_posarg = nth_arg(2, enabledby_arg);
117             enabledby_negarg = nth_arg(3, enabledby_arg);
118             if (enabledby_posarg == "" \
119                 || enabledby_negarg == "")
120                 print "#error " opts[i] " LangEnabledBy(" enabledby_arg ") with four arguments must specify POSARG and NEGARG"
121             else
122                 enabledby_posarg_negarg = "," enabledby_posarg "," enabledby_negarg
123         }
124
125         n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " ");
126         n_enabledby_array = split(enabledby_opt, enabledby_array, " \\|\\| ");
127         for (k = 1; k <= n_enabledby_array; k++) {
128             enabledby_index = opt_numbers[enabledby_array[k]];
129             if (enabledby_index == "") {
130                 print "#error " opts[i] " LangEnabledBy(" enabledby_arg "), unknown option '" enabledby_opt "'"
131                 continue
132             }
133
134             for (j = 1; j <= n_enabledby_arg_langs; j++) {
135                 lang_name = enabledby_arg_langs[j]
136                 lang_index = lang_numbers[lang_name];
137                 if (lang_index == "") {
138                     print "#error " opts[i] " LangEnabledBy(" enabledby_arg "), unknown language '" lang_name "'"
139                     continue
140                 }
141
142                 lang_name = lang_sanitized_name(lang_name);
143
144                 if (enables[lang_name,enabledby_array[k]] == "") {
145                     enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k];
146                     n_enabledby_lang[lang_index]++;
147                 }
148                 enables[lang_name,enabledby_array[k]] \
149                     = enables[lang_name,enabledby_array[k]] opts[i] enabledby_posarg_negarg ";";
150             }
151         }
152     }
153
154     if (flag_set_p("Param", flags[i]) && !(opts[i] ~ "^-param="))
155       print "#error Parameter option name '" opts[i] "' must start with '-param='"
156 }
157
158
159 print "/* This file is auto-generated by optc-gen.awk.  */"
160 print ""
161 n_headers = split(header_name, headers, " ")
162 for (i = 1; i <= n_headers; i++)
163         print "#include " quote headers[i] quote
164 print "#include " quote "opts.h" quote
165 print "#include " quote "intl.h" quote
166 print "#include " quote "insn-attr-common.h" quote
167 print ""
168
169 if (n_extra_c_includes > 0) {
170         for (i = 0; i < n_extra_c_includes; i++) {
171                 print "#include " quote extra_c_includes[i] quote
172         }
173         print ""
174 }
175
176 for (i = 0; i < n_enums; i++) {
177         name = enum_names[i]
178         type = enum_type[name]
179         print "static const struct cl_enum_arg cl_enum_" name \
180             "_data[] = "
181         print "{"
182         print enum_data[name] "  { NULL, 0, 0 }"
183         print "};"
184         print ""
185         print "static void"
186         print "cl_enum_" name "_set (void *var, int value)"
187         print "{"
188         print "  *((" type " *) var) = (" type ") value;"
189         print "}"
190         print ""
191         print "static int"
192         print "cl_enum_" name "_get (const void *var)"
193         print "{"
194         print "  return (int) *((const " type " *) var);"
195         print "}"
196         print ""
197 }
198
199 print "const struct cl_enum cl_enums[] ="
200 print "{"
201 for (i = 0; i < n_enums; i++) {
202         name = enum_names[i]
203         ehelp = enum_help[name]
204         if (ehelp == "")
205                 ehelp = "NULL"
206         else
207                 ehelp = quote ehelp quote
208         unknown_error = enum_unknown_error[name]
209         if (unknown_error == "")
210                 unknown_error = "NULL"
211         else
212                 unknown_error = quote unknown_error quote
213         print "  {"
214         print "    " ehelp ","
215         print "    " unknown_error ","
216         print "    cl_enum_" name "_data,"
217         print "    sizeof (" enum_type[name] "),"
218         print "    cl_enum_" name "_set,"
219         print "    cl_enum_" name "_get"
220         print "  },"
221 }
222 print "};"
223 print "const unsigned int cl_enums_count = " n_enums ";"
224 print ""
225
226 print "const struct gcc_options global_options_init =\n{"
227 for (i = 0; i < n_extra_vars; i++) {
228         var = extra_vars[i]
229         init = extra_vars[i]
230         if (var ~ "=" ) {
231                 sub(".*= *", "", init)
232         } else {
233                 init = "0"
234         }
235         sub(" *=.*", "", var)
236         name = var
237         sub("^.*[ *]", "", name)
238         sub("\\[.*\\]$", "", name)
239         var_seen[name] = 1
240         print "  " init ", /* " name " */"
241 }
242 for (i = 0; i < n_opts; i++) {
243         name = var_name(flags[i]);
244         init = opt_args("Init", flags[i])
245
246         if (name == "") {
247                 if (init != "")
248                     print "#error " opts[i] " must specify Var to use Init"
249                 continue;
250         }
251
252         if (init != "") {
253                 if (name in var_init && var_init[name] != init)
254                         print "#error multiple initializers for " name
255                 var_init[name] = init
256         }
257 }
258 for (i = 0; i < n_opts; i++) {
259         name = var_name(flags[i]);
260         if (name == "")
261                 continue;
262
263         if (name in var_seen)
264                 continue;
265
266         if (name in var_init)
267                 init = var_init[name]
268         else
269                 init = "0"
270
271         print "  " init ", /* " name " */"
272
273         var_seen[name] = 1;
274 }
275 for (i = 0; i < n_opts; i++) {
276         name = static_var(opts[i], flags[i]);
277         if (name != "") {
278                 print "  0, /* " name " (private state) */"
279                 print "#undef x_" name
280         }
281 }
282 for (i = 0; i < n_opts; i++) {
283         if (flag_set_p("SetByCombined", flags[i]))
284                 print "  false, /* frontend_set_" var_name(flags[i]) " */"
285 }
286 print "};"
287 print ""
288 print "struct gcc_options global_options;"
289 print "struct gcc_options global_options_set;"
290 print ""
291
292 print "const char * const lang_names[] =\n{"
293 for (i = 0; i < n_langs; i++) {
294         macros[i] = "CL_" lang_sanitized_name(langs[i])
295         s = substr("         ", length (macros[i]))
296         print "  " quote langs[i] quote ","
297     }
298
299 print "  0\n};\n"
300 print "const unsigned int cl_options_count = N_OPTS;\n"
301 print "#if (1U << " n_langs ") > CL_MIN_OPTION_CLASS"
302 print "  #error the number of languages exceeds the implementation limit"
303 print "#endif"
304 print "const unsigned int cl_lang_count = " n_langs ";\n"
305
306 print "const struct cl_option cl_options[] =\n{"
307
308 j = 0
309 for (i = 0; i < n_opts; i++) {
310         back_chain[i] = "N_OPTS";
311         indices[opts[i]] = j;
312         # Combine the flags of identical switches.  Switches
313         # appear many times if they are handled by many front
314         # ends, for example.
315         while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
316                 flags[i + 1] = flags[i] " " flags[i + 1];
317                 if (help[i + 1] == "")
318                         help[i + 1] = help[i]
319                 else if (help[i] != "" && help[i + 1] != help[i]) {
320                         print "#error Multiple different help strings for " \
321                                 opts[i] ":"
322                         print "#error   " help[i]
323                         print "#error   " help[i + 1]
324                 }
325                                 
326                 i++;
327                 back_chain[i] = "N_OPTS";
328                 indices[opts[i]] = j;
329         }
330         j++;
331 }
332
333 optindex = 0
334 for (i = 0; i < n_opts; i++) {
335         # With identical flags, pick only the last one.  The
336         # earlier loop ensured that it has all flags merged,
337         # and a nonempty help text if one of the texts was nonempty.
338         while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
339                 i++;
340         }
341
342         len = length (opts[i]);
343         enum = opt_enum(opts[i])
344
345         # Do not allow Joined and Separate properties if
346         # an options ends with '='.
347         if (flag_set_p("Joined", flags[i]) && flag_set_p("Separate", flags[i]) && opts[i] ~ "=$") {
348                 print "#error Option '" opts[i] "' ending with '=' cannot have " \
349                         "both Joined and Separate properties"
350         }
351
352         # If this switch takes joined arguments, back-chain all
353         # subsequent switches to it for which it is a prefix.  If
354         # a later switch S is a longer prefix of a switch T, T
355         # will be back-chained to S in a later iteration of this
356         # for() loop, which is what we want.
357         if (flag_set_p("Joined.*", flags[i])) {
358                 for (j = i + 1; j < n_opts; j++) {
359                         if (substr (opts[j], 1, len) != opts[i])
360                                 break;
361                         back_chain[j] = enum;
362                 }
363         }
364
365         s = substr("                                  ", length (opts[i]))
366         if (i + 1 == n_opts)
367                 comma = ""
368
369         if (help[i] == "")
370                 hlp = "NULL"
371         else
372                 hlp = quote help[i] quote;
373
374         missing_arg_error = opt_args("MissingArgError", flags[i])
375         if (missing_arg_error == "")
376                 missing_arg_error = "NULL"
377         else
378                 missing_arg_error = quote missing_arg_error quote
379
380
381         warn_message = opt_args("Warn", flags[i])
382         if (warn_message == "")
383                 warn_message = "NULL"
384         else
385                 warn_message = quote warn_message quote
386
387         alias_arg = opt_args("Alias", flags[i])
388         if (alias_arg == "") {
389                 if (flag_set_p("Ignore", flags[i])) {
390                           alias_data = "NULL, NULL, OPT_SPECIAL_ignore"
391         if (warn_message != "NULL")
392                                   print "#error Ignored option with Warn"
393         if (var_name(flags[i]) != "")
394                                   print "#error Ignored option with Var"
395       }
396     else if (flag_set_p("Deprecated", flags[i]))
397         print "#error Deprecated was replaced with WarnRemoved"
398     else if (flag_set_p("WarnRemoved", flags[i])) {
399                           alias_data = "NULL, NULL, OPT_SPECIAL_warn_removed"
400         if (warn_message != "NULL")
401                                   print "#error WarnRemoved option with Warn"
402       }
403                 else
404                         alias_data = "NULL, NULL, N_OPTS"
405                 if (flag_set_p("Enum.*", flags[i])) {
406                         if (!flag_set_p("RejectNegative", flags[i]) \
407                             && !flag_set_p("EnumSet", flags[i]) \
408                             && !flag_set_p("EnumBitSet", flags[i]) \
409                             && opts[i] ~ "^[Wfgm]")
410                                 print "#error Enum allowing negative form"
411                 }
412         } else {
413                 alias_opt = nth_arg(0, alias_arg)
414                 alias_posarg = nth_arg(1, alias_arg)
415                 alias_negarg = nth_arg(2, alias_arg)
416
417                 if (var_ref(opts[i], flags[i]) != "(unsigned short) -1")
418                         print "#error Alias setting variable"
419
420                 if (alias_posarg != "" && alias_negarg == "") {
421                         if (!flag_set_p("RejectNegative", flags[i]) \
422                             && opts[i] ~ "^[Wfm]")
423                                 print "#error Alias with single argument " \
424                                         "allowing negative form"
425                 }
426                 if (alias_posarg != "" \
427                     && flag_set_p("NegativeAlias", flags[i])) {
428                         print "#error Alias with multiple arguments " \
429                                 "used with NegativeAlias"
430                 }
431
432                 alias_opt = opt_enum(alias_opt)
433                 if (alias_posarg == "")
434                         alias_posarg = "NULL"
435                 else
436                         alias_posarg = quote alias_posarg quote
437                 if (alias_negarg == "")
438                         alias_negarg = "NULL"
439                 else
440                         alias_negarg = quote alias_negarg quote
441                 alias_data = alias_posarg ", " alias_negarg ", " alias_opt
442         }
443
444         neg = opt_args("Negative", flags[i]);
445         if (neg != "")
446                 idx = indices[neg]
447         else {
448                 if (flag_set_p("RejectNegative", flags[i]))
449                         idx = -1;
450                 else {
451                         if (opts[i] ~ "^[Wfgm]")
452                                 idx = indices[opts[i]];
453                         else
454                                 idx = -1;
455                 }
456         }
457         # Split the printf after %u to work around an ia64-hp-hpux11.23
458         # awk bug.
459         printf(" /* [%i] = */ {\n", optindex)
460         printf("    %c-%s%c,\n    %s,\n    %s,\n    %s,\n    %s, %s, %u,",
461                quote, opts[i], quote, hlp, missing_arg_error, warn_message,
462                alias_data, back_chain[i], len)
463         printf(" /* .neg_idx = */ %d,\n", idx)
464         condition = opt_args("Condition", flags[i])
465         cl_flags = switch_flags(flags[i])
466         cl_bit_fields = switch_bit_fields(flags[i])
467         cl_zero_bit_fields = switch_bit_fields("")
468         if (condition != "")
469                 printf("#if %s\n" \
470                        "    %s,\n" \
471                        "    0, %s,\n" \
472                        "#else\n" \
473                        "    0,\n" \
474                        "    1 /* Disabled.  */, %s,\n" \
475                        "#endif\n",
476                        condition, cl_flags, cl_bit_fields, cl_zero_bit_fields)
477         else
478                 printf("    %s,\n" \
479                        "    0, %s,\n",
480                        cl_flags, cl_bit_fields)
481         printf("    %s, %s, %s }%s\n", var_ref(opts[i], flags[i]),
482                var_set(flags[i]), integer_range_info(opt_args("IntegerRange", flags[i]),
483                     opt_args("Init", flags[i]), opts[i], flag_set_p("UInteger", flags[i])), comma)
484
485         # Bump up the informational option index.
486         ++optindex
487  }
488
489 print "};"
490
491 print "\n\n"
492 print "bool                                                                  "
493 print "common_handle_option_auto (struct gcc_options *opts,                  "
494 print "                           struct gcc_options *opts_set,              "
495 print "                           const struct cl_decoded_option *decoded,   "
496 print "                           unsigned int lang_mask, int kind,          "
497 print "                           location_t loc,                            "
498 print "                           const struct cl_option_handlers *handlers, "
499 print "                           diagnostic_context *dc)                    "
500 print "{                                                                     "
501 print "  size_t scode = decoded->opt_index;                                  "
502 print "  HOST_WIDE_INT value = decoded->value;                               "
503 print "  enum opt_code code = (enum opt_code) scode;                         "
504 print "                                                                      "
505 print "  gcc_assert (decoded->canonical_option_num_elements <= 2);           "
506 print "                                                                      "
507 print "  switch (code)                                                       "
508 print "    {                                                                 "
509 # Handle EnabledBy
510 for (i = 0; i < n_enabledby; i++) {
511     enabledby_name = enabledby[i];
512     print "    case " opt_enum(enabledby_name) ":"
513     n_enables = split(enables[enabledby_name], thisenable, ";");
514     n_enablesif = split(enablesif[enabledby_name], thisenableif, ";");
515     if (n_enables != n_enablesif) {
516         print "#error n_enables != n_enablesif: Something went wrong!"
517     }
518     for (j = 1; j < n_enables; j++) {
519         opt_var_name = var_name(flags[opt_numbers[thisenable[j]]]);
520         if (opt_var_name != "") {
521             condition = "!opts_set->x_" opt_var_name
522             if (thisenableif[j] != "") {
523                 value = "(" thisenableif[j] ")"
524             } else {
525                 value = "value"
526             }
527             print "      if (" condition ")"
528             print "        handle_generated_option (opts, opts_set,"
529             print "                                 " opt_enum(thisenable[j]) ", NULL, " value ","
530             print "                                 lang_mask, kind, loc, handlers, true, dc);"
531         } else {
532             print "#error " thisenable[j] " does not have a Var() flag"
533         }
534     }
535     print "      break;\n"
536 }
537 print "    default:    "
538 print "      break;    "
539 print "    }           "
540 print "  return true;  "
541 print "}               "
542
543 # Handle LangEnabledBy
544 for (i = 0; i < n_langs; i++) {
545     lang_name = lang_sanitized_name(langs[i]);
546     mark_unused = " ATTRIBUTE_UNUSED";
547
548     print "\n\n"
549     print "bool                                                                  "
550     print lang_name "_handle_option_auto (struct gcc_options *opts" mark_unused ",              "
551     print "                           struct gcc_options *opts_set" mark_unused ",              "
552     print "                           size_t scode" mark_unused ", const char *arg" mark_unused ", HOST_WIDE_INT value" mark_unused ",  "
553     print "                           unsigned int lang_mask" mark_unused ", int kind" mark_unused ",          "
554     print "                           location_t loc" mark_unused ",                            "
555     print "                           const struct cl_option_handlers *handlers" mark_unused ", "
556     print "                           diagnostic_context *dc" mark_unused ")                    "
557     print "{                                                                     "
558     print "  enum opt_code code = (enum opt_code) scode;                         "
559     print "                                                                      "
560     print "  switch (code)                                                       "
561     print "    {                                                                 "
562     
563     for (k = 0; k < n_enabledby_lang[i]; k++) {
564         enabledby_name = enabledby[lang_name,k];
565         print "    case " opt_enum(enabledby_name) ":"
566         n_thisenable = split(enables[lang_name,enabledby_name], thisenable, ";");
567         for (j = 1; j < n_thisenable; j++) {
568             n_thisenable_args = split(thisenable[j], thisenable_args, ",");
569             if (n_thisenable_args == 1) {
570                 thisenable_opt = thisenable[j];
571                 value = "value";
572             } else {
573                 thisenable_opt = thisenable_args[1];
574                 with_posarg = thisenable_args[2];
575                 with_negarg = thisenable_args[3];
576                 value = "value ? " with_posarg " : " with_negarg;
577             }
578             opt_var_name = var_name(flags[opt_numbers[thisenable_opt]]);
579             if (opt_var_name != "") {
580                 print "      if (!opts_set->x_" opt_var_name ")"
581                 print "        handle_generated_option (opts, opts_set,"
582                 print "                                 " opt_enum(thisenable_opt) ", NULL, " value ","
583                 print "                                 lang_mask, kind, loc, handlers, true, dc);"
584             } else {
585                 print "#error " thisenable_opt " does not have a Var() flag"
586             }
587         }
588         print "      break;\n"
589     }
590     print "    default:    "
591     print "      break;    "
592     print "    }           "
593     print "  return true;  "
594     print "}               "
595 }
596
597 #Handle CPP()
598 print "\n"
599 print "#include " quote "cpplib.h" quote;
600 print "void"
601 print "cpp_handle_option_auto (const struct gcc_options * opts,                   "
602 print "                        size_t scode, struct cpp_options * cpp_opts)"    
603 print "{                                                                     "
604 print "  enum opt_code code = (enum opt_code) scode;                         "
605 print "                                                                      "
606 print "  switch (code)                                                       "
607 print "    {                                                                 "
608 for (i = 0; i < n_opts; i++) {
609     # With identical flags, pick only the last one.  The
610     # earlier loop ensured that it has all flags merged,
611     # and a nonempty help text if one of the texts was nonempty.
612     while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
613         i++;
614     }
615
616     cpp_option = nth_arg(0, opt_args("CPP", flags[i]));
617     if (cpp_option != "") {
618         opt_var_name = var_name(flags[i]);
619         init = opt_args("Init", flags[i])
620         if (opt_var_name != "" && init != "") {
621             print "    case " opt_enum(opts[i]) ":"
622             print "      cpp_opts->" cpp_option " = opts->x_" opt_var_name ";"
623             print "      break;"
624         } else if (opt_var_name == "" && init == "") {
625             print "#error CPP() requires setting Init() and Var() for " opts[i]
626         } else if (opt_var_name != "") {
627             print "#error CPP() requires setting Init() for " opts[i]
628         } else {
629             print "#error CPP() requires setting Var() for " opts[i]
630         }
631     }
632 }
633 print "    default:    "
634 print "      break;    "
635 print "    }           "
636 print "}\n"
637 print "void"
638 print "init_global_opts_from_cpp(struct gcc_options * opts,                   "
639 print "                         const struct cpp_options * cpp_opts)"    
640 print "{                                                                     "
641 for (i = 0; i < n_opts; i++) {
642     # With identical flags, pick only the last one.  The
643     # earlier loop ensured that it has all flags merged,
644     # and a nonempty help text if one of the texts was nonempty.
645     while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
646         i++;
647     }
648     cpp_option = nth_arg(0, opt_args("CPP", flags[i]));
649     opt_var_name = var_name(flags[i]);
650     if (cpp_option != "" && opt_var_name != "") {
651         print "  opts->x_" opt_var_name " = cpp_opts->" cpp_option ";"
652     }
653 }
654 print "}               "
655
656 split("", var_seen, ":")
657 print "\n#if !defined(GENERATOR_FILE) && defined(ENABLE_PLUGIN)"
658 print "DEBUG_VARIABLE const struct cl_var cl_vars[] =\n{"
659
660 for (i = 0; i < n_opts; i++) {
661         name = var_name(flags[i]);
662         if (name == "")
663                 continue;
664         var_seen[name] = 1;
665 }
666
667 for (i = 0; i < n_extra_vars; i++) {
668         var = extra_vars[i]
669         sub(" *=.*", "", var)
670         name = var
671         sub("^.*[ *]", "", name)
672         sub("\\[.*\\]$", "", name)
673         if (name in var_seen)
674                 continue;
675         print "  { " quote name quote ", offsetof (struct gcc_options, x_" name ") },"
676         var_seen[name] = 1
677 }
678
679 print "  { NULL, (unsigned short) -1 }\n};\n#endif"
680
681 }