Daily bump.
[official-gcc.git] / gcc / optc-save-gen.awk
blob4672228ff2036f1bd9d3f03840d2879dd57154ad
1 # Copyright (C) 2003-2013 Free Software Foundation, Inc.
2 # Contributed by Kelley Cook, June 2004.
3 # Original code from Neil Booth, May 2003.
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.
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/>.
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.
24 # This program uses functions from opt-functions.awk and code from
25 # opt-read.awk.
27 # Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-save-gen.awk \
28 # [-v header_name=header.h] < inputfile > options-save.c
30 # Dump that array of options into a C file.
31 END {
32 print "/* This file is auto-generated by optc-save-gen.awk. */"
33 print ""
34 n_headers = split(header_name, headers, " ")
35 for (i = 1; i <= n_headers; i++)
36 print "#include " quote headers[i] quote
37 print "#include " quote "opts.h" quote
38 print "#include " quote "intl.h" quote
39 print ""
40 print "#include " quote "flags.h" quote
41 print "#include " quote "target.h" quote
42 print ""
44 if (n_extra_c_includes > 0) {
45 for (i = 0; i < n_extra_c_includes; i++) {
46 print "#include " quote extra_c_includes[i] quote
48 print ""
51 have_save = 0;
52 if (n_extra_target_vars)
53 have_save = 1
55 for (i = 0; i < n_opts; i++) {
56 if (flag_set_p("Save", flags[i]))
57 have_save = 1;
60 print "/* Save optimization variables into a structure. */"
61 print "void";
62 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
63 print "{";
65 n_opt_char = 2;
66 n_opt_short = 0;
67 n_opt_int = 0;
68 n_opt_enum = 1;
69 n_opt_other = 0;
70 var_opt_char[0] = "optimize";
71 var_opt_char[1] = "optimize_size";
72 var_opt_range["optimize"] = "0, 255";
73 var_opt_range["optimize_size"] = "0, 255";
74 var_opt_enum[0] = "flag_fp_contract_mode";
76 # Sort by size to mimic how the structure is laid out to be friendlier to the
77 # cache.
79 for (i = 0; i < n_opts; i++) {
80 if (flag_set_p("Optimization", flags[i])) {
81 name = var_name(flags[i])
82 if(name == "")
83 continue;
85 if(name in var_opt_seen)
86 continue;
88 var_opt_seen[name]++;
89 otype = var_type_struct(flags[i]);
90 if (otype ~ "^((un)?signed +)?int *$")
91 var_opt_int[n_opt_int++] = name;
93 else if (otype ~ "^((un)?signed +)?short *$")
94 var_opt_short[n_opt_short++] = name;
96 else if (otype ~ ("^enum +[_" alnum "]+ *"))
97 var_opt_enum[n_opt_enum++] = name;
99 else if (otype ~ "^((un)?signed +)?char *$") {
100 var_opt_char[n_opt_char++] = name;
101 if (otype ~ "^unsigned +char *$")
102 var_opt_range[name] = "0, 255"
103 else if (otype ~ "^signed +char *$")
104 var_opt_range[name] = "-128, 127"
106 else
107 var_opt_other[n_opt_other++] = name;
111 for (i = 0; i < n_opt_char; i++) {
112 name = var_opt_char[i];
113 if (var_opt_range[name] != "")
114 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_opt_range[name] "));";
117 print "";
118 for (i = 0; i < n_opt_other; i++) {
119 print " ptr->x_" var_opt_other[i] " = opts->x_" var_opt_other[i] ";";
122 for (i = 0; i < n_opt_int; i++) {
123 print " ptr->x_" var_opt_int[i] " = opts->x_" var_opt_int[i] ";";
126 for (i = 0; i < n_opt_enum; i++) {
127 print " ptr->x_" var_opt_enum[i] " = opts->x_" var_opt_enum[i] ";";
130 for (i = 0; i < n_opt_short; i++) {
131 print " ptr->x_" var_opt_short[i] " = opts->x_" var_opt_short[i] ";";
134 for (i = 0; i < n_opt_char; i++) {
135 print " ptr->x_" var_opt_char[i] " = opts->x_" var_opt_char[i] ";";
138 print "}";
140 print "";
141 print "/* Restore optimization options from a structure. */";
142 print "void";
143 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
144 print "{";
146 for (i = 0; i < n_opt_other; i++) {
147 print " opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
150 for (i = 0; i < n_opt_int; i++) {
151 print " opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
154 for (i = 0; i < n_opt_enum; i++) {
155 print " opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
158 for (i = 0; i < n_opt_short; i++) {
159 print " opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
162 for (i = 0; i < n_opt_char; i++) {
163 print " opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
166 print " targetm.override_options_after_change ();";
167 print "}";
169 print "";
170 print "/* Print optimization options from a structure. */";
171 print "void";
172 print "cl_optimization_print (FILE *file,";
173 print " int indent_to,";
174 print " struct cl_optimization *ptr)";
175 print "{";
177 print " fputs (\"\\n\", file);";
178 for (i = 0; i < n_opt_other; i++) {
179 print " if (ptr->x_" var_opt_other[i] ")";
180 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
181 print " indent_to, \"\",";
182 print " \"" var_opt_other[i] "\",";
183 print " (unsigned long)ptr->x_" var_opt_other[i] ");";
184 print "";
187 for (i = 0; i < n_opt_int; i++) {
188 print " if (ptr->x_" var_opt_int[i] ")";
189 print " fprintf (file, \"%*s%s (%#x)\\n\",";
190 print " indent_to, \"\",";
191 print " \"" var_opt_int[i] "\",";
192 print " ptr->x_" var_opt_int[i] ");";
193 print "";
196 for (i = 0; i < n_opt_enum; i++) {
197 print " fprintf (file, \"%*s%s (%#x)\\n\",";
198 print " indent_to, \"\",";
199 print " \"" var_opt_enum[i] "\",";
200 print " (int) ptr->x_" var_opt_enum[i] ");";
201 print "";
204 for (i = 0; i < n_opt_short; i++) {
205 print " if (ptr->x_" var_opt_short[i] ")";
206 print " fprintf (file, \"%*s%s (%#x)\\n\",";
207 print " indent_to, \"\",";
208 print " \"" var_opt_short[i] "\",";
209 print " ptr->x_" var_opt_short[i] ");";
210 print "";
213 for (i = 0; i < n_opt_char; i++) {
214 print " if (ptr->x_" var_opt_char[i] ")";
215 print " fprintf (file, \"%*s%s (%#x)\\n\",";
216 print " indent_to, \"\",";
217 print " \"" var_opt_char[i] "\",";
218 print " ptr->x_" var_opt_char[i] ");";
219 print "";
222 print "}";
224 print "";
225 print "/* Save selected option variables into a structure. */"
226 print "void";
227 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
228 print "{";
230 n_target_char = 0;
231 n_target_short = 0;
232 n_target_int = 0;
233 n_target_enum = 0;
234 n_target_other = 0;
236 if (have_save) {
237 for (i = 0; i < n_opts; i++) {
238 if (flag_set_p("Save", flags[i])) {
239 name = var_name(flags[i])
240 if(name == "")
241 name = "target_flags";
243 if(name in var_save_seen)
244 continue;
246 var_save_seen[name]++;
247 otype = var_type_struct(flags[i])
248 if (otype ~ "^((un)?signed +)?int *$")
249 var_target_int[n_target_int++] = name;
251 else if (otype ~ "^((un)?signed +)?short *$")
252 var_target_short[n_target_short++] = name;
254 else if (otype ~ ("^enum +[_" alnum "]+ *$"))
255 var_target_enum[n_target_enum++] = name;
257 else if (otype ~ "^((un)?signed +)?char *$") {
258 var_target_char[n_target_char++] = name;
259 if (otype ~ "^unsigned +char *$")
260 var_target_range[name] = "0, 255"
261 else if (otype ~ "^signed +char *$")
262 var_target_range[name] = "-128, 127"
263 if (otype == var_type(flags[i]))
264 var_target_range[name] = ""
266 else
267 var_target_other[n_target_other++] = name;
270 } else {
271 var_target_int[n_target_int++] = "target_flags";
274 have_assert = 0;
275 for (i = 0; i < n_target_char; i++) {
276 name = var_target_char[i];
277 if (var_target_range[name] != "") {
278 have_assert = 1;
279 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
283 if (have_assert)
284 print "";
286 print " if (targetm.target_option.save)";
287 print " targetm.target_option.save (ptr);";
288 print "";
290 for (i = 0; i < n_extra_target_vars; i++) {
291 print " ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
294 for (i = 0; i < n_target_other; i++) {
295 print " ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
298 for (i = 0; i < n_target_enum; i++) {
299 print " ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
302 for (i = 0; i < n_target_int; i++) {
303 print " ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
306 for (i = 0; i < n_target_short; i++) {
307 print " ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
310 for (i = 0; i < n_target_char; i++) {
311 print " ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
314 print "}";
316 print "";
317 print "/* Restore selected current options from a structure. */";
318 print "void";
319 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
320 print "{";
322 for (i = 0; i < n_extra_target_vars; i++) {
323 print " opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
326 for (i = 0; i < n_target_other; i++) {
327 print " opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
330 for (i = 0; i < n_target_enum; i++) {
331 print " opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
334 for (i = 0; i < n_target_int; i++) {
335 print " opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
338 for (i = 0; i < n_target_short; i++) {
339 print " opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
342 for (i = 0; i < n_target_char; i++) {
343 print " opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
346 # This must occur after the normal variables in case the code depends on those
347 # variables.
348 print "";
349 print " if (targetm.target_option.restore)";
350 print " targetm.target_option.restore (ptr);";
352 print "}";
354 print "";
355 print "/* Print optimization options from a structure. */";
356 print "void";
357 print "cl_target_option_print (FILE *file,";
358 print " int indent,";
359 print " struct cl_target_option *ptr)";
360 print "{";
362 print " fputs (\"\\n\", file);";
363 for (i = 0; i < n_target_other; i++) {
364 print " if (ptr->x_" var_target_other[i] ")";
365 if (host_wide_int[var_target_other[i]] == "yes")
366 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
367 else
368 print " fprintf (file, \"%*s%s (%#x)\\n\",";
369 print " indent, \"\",";
370 print " \"" var_target_other[i] "\",";
371 if (host_wide_int[var_target_other[i]] == "yes")
372 print " ptr->x_" var_target_other[i] ");";
373 else
374 print " (unsigned long)ptr->x_" var_target_other[i] ");";
375 print "";
378 for (i = 0; i < n_target_enum; i++) {
379 print " if (ptr->x_" var_target_enum[i] ")";
380 print " fprintf (file, \"%*s%s (%#x)\\n\",";
381 print " indent, \"\",";
382 print " \"" var_target_enum[i] "\",";
383 print " ptr->x_" var_target_enum[i] ");";
384 print "";
387 for (i = 0; i < n_target_int; i++) {
388 print " if (ptr->x_" var_target_int[i] ")";
389 print " fprintf (file, \"%*s%s (%#x)\\n\",";
390 print " indent, \"\",";
391 print " \"" var_target_int[i] "\",";
392 print " ptr->x_" var_target_int[i] ");";
393 print "";
396 for (i = 0; i < n_target_short; i++) {
397 print " if (ptr->x_" var_target_short[i] ")";
398 print " fprintf (file, \"%*s%s (%#x)\\n\",";
399 print " indent, \"\",";
400 print " \"" var_target_short[i] "\",";
401 print " ptr->x_" var_target_short[i] ");";
402 print "";
405 for (i = 0; i < n_target_char; i++) {
406 print " if (ptr->x_" var_target_char[i] ")";
407 print " fprintf (file, \"%*s%s (%#x)\\n\",";
408 print " indent, \"\",";
409 print " \"" var_target_char[i] "\",";
410 print " ptr->x_" var_target_char[i] ");";
411 print "";
414 print "";
415 print " if (targetm.target_option.print)";
416 print " targetm.target_option.print (file, indent, ptr);";
418 print "}";