1 # Copyright (C) 2003-2014 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
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
24 # This program uses functions from opt-functions.awk and code from
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.
32 print "/* This file is auto-generated by optc-save-gen.awk. */"
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
40 print "#include " quote
"flags.h" quote
41 print "#include " quote
"target.h" quote
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
52 if (n_extra_target_vars
)
55 for (i =
0; i
< n_opts
; i
++) {
56 if (flag_set_p
("Save", flags
[i
]))
60 print "/* Save optimization variables into a structure. */"
62 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
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
79 for (i =
0; i
< n_opts
; i
++) {
80 if (flag_set_p
("Optimization", flags
[i
])) {
81 name = var_name
(flags
[i
])
85 if(name in var_opt_seen
)
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"
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
] "));";
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
] ";";
141 print "/* Restore optimization options from a structure. */";
143 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
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 ();";
170 print "/* Print optimization options from a structure. */";
172 print "cl_optimization_print (FILE *file,";
173 print " int indent_to,";
174 print " struct cl_optimization *ptr)";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
225 print "/* Save selected option variables into a structure. */"
227 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
237 for (i =
0; i
< n_opts
; i
++) {
238 if (flag_set_p
("Save", flags
[i
])) {
239 name = var_name
(flags
[i
])
241 name =
"target_flags";
243 if(name in var_save_seen
)
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
] =
""
267 var_target_other
[n_target_other
++] = name
;
271 var_target_int
[n_target_int
++] =
"target_flags";
275 for (i =
0; i
< n_target_char
; i
++) {
276 name = var_target_char
[i
];
277 if (var_target_range
[name
] != "") {
279 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_target_range
[name
] "));";
286 print " if (targetm.target_option.save)";
287 print " targetm.target_option.save (ptr, opts);";
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
] ";";
317 print "/* Restore selected current options from a structure. */";
319 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
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
349 print " if (targetm.target_option.restore)";
350 print " targetm.target_option.restore (opts, ptr);";
355 print "/* Print optimization options from a structure. */";
357 print "cl_target_option_print (FILE *file,";
358 print " int indent,";
359 print " struct cl_target_option *ptr)";
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\",";
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
] ");";
374 print " (unsigned long)ptr->x_" var_target_other
[i
] ");";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
415 print " if (targetm.target_option.print)";
416 print " targetm.target_option.print (file, indent, ptr);";