* config/rs6000/aix61.h (PROCESSOR_DEFAULT): Change to
[official-gcc.git] / gcc / opth-gen.awk
blobc3f6c04ebfb46a08d6b62e453db8586f67ee3537
1 # Copyright (C) 2003,2004,2005,2006,2007,2008, 2010, 2011
2 # Free Software Foundation, Inc.
3 # Contributed by Kelley Cook, June 2004.
4 # Original code from Neil Booth, May 2003.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 3, or (at your option) any
9 # later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; see the file COPYING3. If not see
18 # <http://www.gnu.org/licenses/>.
20 # This Awk script reads in the option records generated from
21 # opt-gather.awk, combines the flags of duplicate options and generates a
22 # C header file.
24 # This program uses functions from opt-functions.awk
25 # Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h
27 BEGIN {
28 n_opts = 0
29 n_langs = 0
30 n_target_save = 0
31 n_extra_vars = 0
32 n_extra_target_vars = 0
33 n_extra_masks = 0
34 n_extra_c_includes = 0
35 n_extra_h_includes = 0
36 have_save = 0;
37 quote = "\042"
38 FS=SUBSEP
41 # Collect the text and flags of each option into an array
43 if ($1 == "Language") {
44 langs[n_langs] = $2
45 n_langs++;
47 else if ($1 == "TargetSave") {
48 # Make sure the declarations are put in source order
49 target_save_decl[n_target_save] = $2
50 n_target_save++
52 else if ($1 == "Variable") {
53 extra_vars[n_extra_vars] = $2
54 n_extra_vars++
56 else if ($1 == "TargetVariable") {
57 # Combination of TargetSave and Variable
58 extra_vars[n_extra_vars] = $2
59 n_extra_vars++
61 var = $2
62 sub(" *=.*", "", var)
63 orig_var = var
64 name = var
65 type = var
66 sub("^.*[ *]", "", name)
67 sub(" *" name "$", "", type)
68 target_save_decl[n_target_save] = type " x_" name
69 n_target_save++
71 extra_target_vars[n_extra_target_vars] = name
72 n_extra_target_vars++
74 else if ($1 == "HeaderInclude") {
75 extra_h_includes[n_extra_h_includes++] = $2;
77 else if ($1 == "SourceInclude") {
78 extra_c_includes[n_extra_c_includes++] = $2;
80 else if ($1 == "Enum") {
81 props = $2
82 name = opt_args("Name", props)
83 type = opt_args("Type", props)
84 unknown_error = opt_args("UnknownError", props)
85 enum_names[n_enums] = name
86 enum_type[name] = type
87 enum_index[name] = n_enums
88 enum_unknown_error[name] = unknown_error
89 enum_help[name] = $3
90 n_enums++
92 else if ($1 == "EnumValue") {
93 props = $2
94 enum_name = opt_args("Enum", props)
95 string = opt_args("String", props)
96 value = opt_args("Value", props)
97 val_flags = "0"
98 val_flags = val_flags \
99 test_flag("Canonical", props, "| CL_ENUM_CANONICAL") \
100 test_flag("DriverOnly", props, "| CL_ENUM_DRIVER_ONLY")
101 enum_data[enum_name] = enum_data[enum_name] \
102 " { " quote string quote ", " value ", " val_flags \
103 " },\n"
105 else {
106 name = opt_args("Mask", $1)
107 if (name == "") {
108 opts[n_opts] = $1
109 flags[n_opts] = $2
110 help[n_opts] = $3
111 n_opts++;
113 else {
114 extra_masks[n_extra_masks++] = name
119 # Dump out an enumeration into a .h file.
120 # Combine the flags of duplicate options.
121 END {
122 print "/* This file is auto-generated by opth-gen.awk. */"
123 print ""
124 print "#ifndef OPTIONS_H"
125 print "#define OPTIONS_H"
126 print ""
127 print "#include \"flag-types.h\""
128 print ""
130 if (n_extra_h_includes > 0) {
131 for (i = 0; i < n_extra_h_includes; i++) {
132 print "#include " quote extra_h_includes[i] quote
134 print ""
137 print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)"
138 print "#ifndef GENERATOR_FILE"
139 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)"
140 print "struct GTY(()) gcc_options"
141 print "#else"
142 print "struct gcc_options"
143 print "#endif"
144 print "{"
145 print "#endif"
147 for (i = 0; i < n_extra_vars; i++) {
148 var = extra_vars[i]
149 sub(" *=.*", "", var)
150 orig_var = var
151 name = var
152 type = var
153 type_after = var
154 sub("^.*[ *]", "", name)
155 sub("\\[.*\\]$", "", name)
156 sub("\\[.*\\]$", "", type)
157 sub(" *" name "$", "", type)
158 sub("^.*" name, "", type_after)
159 var_seen[name] = 1
160 print "#ifdef GENERATOR_FILE"
161 print "extern " orig_var ";"
162 print "#else"
163 print " " type " x_" name type_after ";"
164 print "#define " name " global_options.x_" name
165 print "#endif"
168 for (i = 0; i < n_opts; i++) {
169 if (flag_set_p("Save", flags[i]))
170 have_save = 1;
172 name = var_name(flags[i]);
173 if (name == "")
174 continue;
176 if (name in var_seen)
177 continue;
179 var_seen[name] = 1;
180 print "#ifdef GENERATOR_FILE"
181 print "extern " var_type(flags[i]) name ";"
182 print "#else"
183 print " " var_type(flags[i]) "x_" name ";"
184 print "#define " name " global_options.x_" name
185 print "#endif"
187 for (i = 0; i < n_opts; i++) {
188 name = static_var(opts[i], flags[i]);
189 if (name != "") {
190 print "#ifndef GENERATOR_FILE"
191 print " " var_type(flags[i]) "x_" name ";"
192 print "#define x_" name " do_not_use"
193 print "#endif"
196 for (i = 0; i < n_opts; i++) {
197 if (flag_set_p("SetByCombined", flags[i])) {
198 print "#ifndef GENERATOR_FILE"
199 print " bool frontend_set_" var_name(flags[i]) ";"
200 print "#endif"
203 print "#ifndef GENERATOR_FILE"
204 print "};"
205 print "extern struct gcc_options global_options;"
206 print "extern const struct gcc_options global_options_init;"
207 print "extern struct gcc_options global_options_set;"
208 print "#define target_flags_explicit global_options_set.x_target_flags"
209 print "#endif"
210 print "#endif"
211 print ""
213 # All of the optimization switches gathered together so they can be saved and restored.
214 # This will allow attribute((cold)) to turn on space optimization.
216 # Change the type of normal switches from int to unsigned char to save space.
217 # Also, order the structure so that pointer fields occur first, then int
218 # fields, and then char fields to provide the best packing.
220 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)"
221 print ""
222 print "/* Structure to save/restore optimization and target specific options. */";
223 print "struct GTY(()) cl_optimization";
224 print "{";
226 n_opt_char = 2;
227 n_opt_short = 0;
228 n_opt_int = 0;
229 n_opt_enum = 1;
230 n_opt_other = 0;
231 var_opt_char[0] = "unsigned char x_optimize";
232 var_opt_char[1] = "unsigned char x_optimize_size";
233 var_opt_enum[0] = "enum fp_contract_mode x_flag_fp_contract_mode";
235 for (i = 0; i < n_opts; i++) {
236 if (flag_set_p("Optimization", flags[i])) {
237 name = var_name(flags[i])
238 if(name == "")
239 continue;
241 if(name in var_opt_seen)
242 continue;
244 var_opt_seen[name]++;
245 otype = var_type_struct(flags[i]);
246 if (otype ~ "^((un)?signed +)?int *$")
247 var_opt_int[n_opt_int++] = otype "x_" name;
249 else if (otype ~ "^((un)?signed +)?short *$")
250 var_opt_short[n_opt_short++] = otype "x_" name;
252 else if (otype ~ "^((un)?signed +)?char *$")
253 var_opt_char[n_opt_char++] = otype "x_" name;
255 else if (otype ~ ("^enum +[_" alnum "]+ *$"))
256 var_opt_enum[n_opt_enum++] = otype "x_" name;
258 else
259 var_opt_other[n_opt_other++] = otype "x_" name;
263 for (i = 0; i < n_opt_other; i++) {
264 print " " var_opt_other[i] ";";
267 for (i = 0; i < n_opt_int; i++) {
268 print " " var_opt_int[i] ";";
271 for (i = 0; i < n_opt_enum; i++) {
272 print " " var_opt_enum[i] ";";
275 for (i = 0; i < n_opt_short; i++) {
276 print " " var_opt_short[i] ";";
279 for (i = 0; i < n_opt_char; i++) {
280 print " " var_opt_char[i] ";";
283 print "};";
284 print "";
286 # Target and optimization save/restore/print functions.
287 print "/* Structure to save/restore selected target specific options. */";
288 print "struct GTY(()) cl_target_option";
289 print "{";
291 n_target_char = 0;
292 n_target_short = 0;
293 n_target_int = 0;
294 n_target_enum = 0;
295 n_target_other = 0;
297 for (i = 0; i < n_target_save; i++) {
298 if (target_save_decl[i] ~ "^((un)?signed +)?int +[_" alnum "]+$")
299 var_target_int[n_target_int++] = target_save_decl[i];
301 else if (target_save_decl[i] ~ "^((un)?signed +)?short +[_" alnum "]+$")
302 var_target_short[n_target_short++] = target_save_decl[i];
304 else if (target_save_decl[i] ~ "^((un)?signed +)?char +[_ " alnum "]+$")
305 var_target_char[n_target_char++] = target_save_decl[i];
307 else if (target_save_decl[i] ~ ("^enum +[_" alnum "]+ +[_" alnum "]+$")) {
308 var_target_enum[n_target_enum++] = target_save_decl[i];
310 else
311 var_target_other[n_target_other++] = target_save_decl[i];
314 if (have_save) {
315 for (i = 0; i < n_opts; i++) {
316 if (flag_set_p("Save", flags[i])) {
317 name = var_name(flags[i])
318 if(name == "")
319 name = "target_flags";
321 if(name in var_save_seen)
322 continue;
324 var_save_seen[name]++;
325 otype = var_type_struct(flags[i])
326 if (otype ~ "^((un)?signed +)?int *$")
327 var_target_int[n_target_int++] = otype "x_" name;
329 else if (otype ~ "^((un)?signed +)?short *$")
330 var_target_short[n_target_short++] = otype "x_" name;
332 else if (otype ~ "^((un)?signed +)?char *$")
333 var_target_char[n_target_char++] = otype "x_" name;
335 else if (otype ~ ("^enum +[_" alnum "]+ +[_" alnum "]+"))
336 var_target_enum[n_target_enum++] = otype "x_" name;
338 else
339 var_target_other[n_target_other++] = otype "x_" name;
342 } else {
343 var_target_int[n_target_int++] = "int x_target_flags";
346 for (i = 0; i < n_target_other; i++) {
347 print " " var_target_other[i] ";";
350 for (i = 0; i < n_target_enum; i++) {
351 print " " var_target_enum[i] ";";
354 for (i = 0; i < n_target_int; i++) {
355 print " " var_target_int[i] ";";
358 for (i = 0; i < n_target_short; i++) {
359 print " " var_target_short[i] ";";
362 for (i = 0; i < n_target_char; i++) {
363 print " " var_target_char[i] ";";
366 print "};";
367 print "";
368 print "";
369 print "/* Save optimization variables into a structure. */"
370 print "extern void cl_optimization_save (struct cl_optimization *, struct gcc_options *);";
371 print "";
372 print "/* Restore optimization variables from a structure. */";
373 print "extern void cl_optimization_restore (struct gcc_options *, struct cl_optimization *);";
374 print "";
375 print "/* Print optimization variables from a structure. */";
376 print "extern void cl_optimization_print (FILE *, int, struct cl_optimization *);";
377 print "";
378 print "/* Save selected option variables into a structure. */"
379 print "extern void cl_target_option_save (struct cl_target_option *, struct gcc_options *);";
380 print "";
381 print "/* Restore selected option variables from a structure. */"
382 print "extern void cl_target_option_restore (struct gcc_options *, struct cl_target_option *);";
383 print "";
384 print "/* Print target option variables from a structure. */";
385 print "extern void cl_target_option_print (FILE *, int, struct cl_target_option *);";
386 print "#endif";
387 print "";
389 for (i = 0; i < n_opts; i++) {
390 name = opt_args("Mask", flags[i])
391 vname = var_name(flags[i])
392 mask = "MASK_"
393 if (vname != "") {
394 mask = "OPTION_MASK_"
396 if (name != "" && !flag_set_p("MaskExists", flags[i]))
397 print "#define " mask name " (1 << " masknum[vname]++ ")"
399 for (i = 0; i < n_extra_masks; i++) {
400 print "#define MASK_" extra_masks[i] " (1 << " masknum[""]++ ")"
403 for (var in masknum) {
404 if (masknum[var] > 31) {
405 if (var == "")
406 print "#error too many target masks"
407 else
408 print "#error too many masks for " var
411 print ""
413 for (i = 0; i < n_opts; i++) {
414 name = opt_args("Mask", flags[i])
415 vname = var_name(flags[i])
416 macro = "OPTION_"
417 mask = "OPTION_MASK_"
418 if (vname == "") {
419 vname = "target_flags"
420 macro = "TARGET_"
421 mask = "MASK_"
423 if (name != "" && !flag_set_p("MaskExists", flags[i]))
424 print "#define " macro name \
425 " ((" vname " & " mask name ") != 0)"
427 for (i = 0; i < n_extra_masks; i++) {
428 print "#define TARGET_" extra_masks[i] \
429 " ((target_flags & MASK_" extra_masks[i] ") != 0)"
431 print ""
433 for (i = 0; i < n_opts; i++) {
434 opt = opt_args("InverseMask", flags[i])
435 if (opt ~ ",") {
436 vname = var_name(flags[i])
437 macro = "OPTION_"
438 mask = "OPTION_MASK_"
439 if (vname == "") {
440 vname = "target_flags"
441 macro = "TARGET_"
442 mask = "MASK_"
444 print "#define " macro nth_arg(1, opt) \
445 " ((" vname " & " mask nth_arg(0, opt) ") == 0)"
448 print ""
450 for (i = 0; i < n_langs; i++) {
451 macros[i] = "CL_" langs[i]
452 gsub( "[^" alnum "_]", "X", macros[i] )
453 s = substr(" ", length (macros[i]))
454 print "#define " macros[i] s " (1 << " i ")"
456 print "#define CL_LANG_ALL ((1 << " n_langs ") - 1)"
458 print ""
459 print "enum opt_code"
460 print "{"
462 for (i = 0; i < n_opts; i++)
463 back_chain[i] = "N_OPTS";
465 enum_value = 0
466 for (i = 0; i < n_opts; i++) {
467 # Combine the flags of identical switches. Switches
468 # appear many times if they are handled by many front
469 # ends, for example.
470 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
471 flags[i + 1] = flags[i] " " flags[i + 1];
472 i++;
475 len = length (opts[i]);
476 enum = opt_enum(opts[i])
477 enum_string = enum " = " enum_value ","
479 # Aliases do not get enumeration names.
480 if ((flag_set_p("Alias.*", flags[i]) \
481 && !flag_set_p("SeparateAlias", flags[i])) \
482 || flag_set_p("Ignore", flags[i])) {
483 enum_string = "/* " enum_string " */"
486 # If this switch takes joined arguments, back-chain all
487 # subsequent switches to it for which it is a prefix. If
488 # a later switch S is a longer prefix of a switch T, T
489 # will be back-chained to S in a later iteration of this
490 # for() loop, which is what we want.
491 if (flag_set_p("Joined.*", flags[i])) {
492 for (j = i + 1; j < n_opts; j++) {
493 if (substr (opts[j], 1, len) != opts[i])
494 break;
495 back_chain[j] = enum;
499 s = substr(" ",
500 length (enum_string))
502 if (help[i] == "")
503 hlp = "0"
504 else
505 hlp = "N_(\"" help[i] "\")";
507 print " " enum_string s "/* -" opts[i] " */"
508 enum_value++
511 print " N_OPTS,"
512 print " OPT_SPECIAL_unknown,"
513 print " OPT_SPECIAL_ignore,"
514 print " OPT_SPECIAL_program_name,"
515 print " OPT_SPECIAL_input_file"
516 print "};"
517 print ""
518 print "#endif /* OPTIONS_H */"