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.
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
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
25 # This program uses functions from opt-functions.awk and code from
28 # Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-save-gen.awk \
29 # [-v header_name=header.h] < inputfile > options-save.c
31 # Dump that array of options into a C file.
33 print "/* This file is auto-generated by optc-save-gen.awk. */"
35 n_headers =
split(header_name
, headers
, " ")
36 for (i =
1; i
<= n_headers
; i
++)
37 print "#include " quote headers
[i
] quote
38 print "#include " quote
"opts.h" quote
39 print "#include " quote
"intl.h" quote
41 print "#include " quote
"flags.h" quote
42 print "#include " quote
"target.h" quote
45 if (n_extra_c_includes
> 0) {
46 for (i =
0; i
< n_extra_c_includes
; i
++) {
47 print "#include " quote extra_c_includes
[i
] quote
53 if (n_extra_target_vars
)
56 for (i =
0; i
< n_opts
; i
++) {
57 if (flag_set_p
("Save", flags
[i
]))
61 print "/* Save optimization variables into a structure. */"
63 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
71 var_opt_char
[0] =
"optimize";
72 var_opt_char
[1] =
"optimize_size";
73 var_opt_range
["optimize"] =
"0, 255";
74 var_opt_range
["optimize_size"] =
"0, 255";
75 var_opt_enum
[0] =
"flag_fp_contract_mode";
77 # Sort by size to mimic how the structure is laid out to be friendlier to the
80 for (i =
0; i
< n_opts
; i
++) {
81 if (flag_set_p
("Optimization", flags
[i
])) {
82 name = var_name
(flags
[i
])
86 if(name in var_opt_seen
)
90 otype = var_type_struct
(flags
[i
]);
91 if (otype ~
"^((un)?signed +)?int *$")
92 var_opt_int
[n_opt_int
++] = name
;
94 else if (otype ~
"^((un)?signed +)?short *$")
95 var_opt_short
[n_opt_short
++] = name
;
97 else if (otype ~
("^enum +[_" alnum
"]+ *"))
98 var_opt_enum
[n_opt_enum
++] = name
;
100 else if (otype ~
"^((un)?signed +)?char *$") {
101 var_opt_char
[n_opt_char
++] = name
;
102 if (otype ~
"^unsigned +char *$")
103 var_opt_range
[name
] =
"0, 255"
104 else if (otype ~
"^signed +char *$")
105 var_opt_range
[name
] =
"-128, 127"
108 var_opt_other
[n_opt_other
++] = name
;
112 for (i =
0; i
< n_opt_char
; i
++) {
113 name = var_opt_char
[i
];
114 if (var_opt_range
[name
] != "")
115 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_opt_range
[name
] "));";
119 for (i =
0; i
< n_opt_other
; i
++) {
120 print " ptr->x_" var_opt_other
[i
] " = opts->x_" var_opt_other
[i
] ";";
123 for (i =
0; i
< n_opt_int
; i
++) {
124 print " ptr->x_" var_opt_int
[i
] " = opts->x_" var_opt_int
[i
] ";";
127 for (i =
0; i
< n_opt_enum
; i
++) {
128 print " ptr->x_" var_opt_enum
[i
] " = opts->x_" var_opt_enum
[i
] ";";
131 for (i =
0; i
< n_opt_short
; i
++) {
132 print " ptr->x_" var_opt_short
[i
] " = opts->x_" var_opt_short
[i
] ";";
135 for (i =
0; i
< n_opt_char
; i
++) {
136 print " ptr->x_" var_opt_char
[i
] " = opts->x_" var_opt_char
[i
] ";";
142 print "/* Restore optimization options from a structure. */";
144 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
147 for (i =
0; i
< n_opt_other
; i
++) {
148 print " opts->x_" var_opt_other
[i
] " = ptr->x_" var_opt_other
[i
] ";";
151 for (i =
0; i
< n_opt_int
; i
++) {
152 print " opts->x_" var_opt_int
[i
] " = ptr->x_" var_opt_int
[i
] ";";
155 for (i =
0; i
< n_opt_enum
; i
++) {
156 print " opts->x_" var_opt_enum
[i
] " = ptr->x_" var_opt_enum
[i
] ";";
159 for (i =
0; i
< n_opt_short
; i
++) {
160 print " opts->x_" var_opt_short
[i
] " = ptr->x_" var_opt_short
[i
] ";";
163 for (i =
0; i
< n_opt_char
; i
++) {
164 print " opts->x_" var_opt_char
[i
] " = ptr->x_" var_opt_char
[i
] ";";
167 print " targetm.override_options_after_change ();";
171 print "/* Print optimization options from a structure. */";
173 print "cl_optimization_print (FILE *file,";
174 print " int indent_to,";
175 print " struct cl_optimization *ptr)";
178 print " fputs (\"\\n\", file);";
179 for (i =
0; i
< n_opt_other
; i
++) {
180 print " if (ptr->x_" var_opt_other
[i
] ")";
181 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
182 print " indent_to, \"\",";
183 print " \"" var_opt_other
[i
] "\",";
184 print " (unsigned long)ptr->x_" var_opt_other
[i
] ");";
188 for (i =
0; i
< n_opt_int
; i
++) {
189 print " if (ptr->x_" var_opt_int
[i
] ")";
190 print " fprintf (file, \"%*s%s (%#x)\\n\",";
191 print " indent_to, \"\",";
192 print " \"" var_opt_int
[i
] "\",";
193 print " ptr->x_" var_opt_int
[i
] ");";
197 for (i =
0; i
< n_opt_enum
; i
++) {
198 print " fprintf (file, \"%*s%s (%#x)\\n\",";
199 print " indent_to, \"\",";
200 print " \"" var_opt_enum
[i
] "\",";
201 print " (int) ptr->x_" var_opt_enum
[i
] ");";
205 for (i =
0; i
< n_opt_short
; i
++) {
206 print " if (ptr->x_" var_opt_short
[i
] ")";
207 print " fprintf (file, \"%*s%s (%#x)\\n\",";
208 print " indent_to, \"\",";
209 print " \"" var_opt_short
[i
] "\",";
210 print " ptr->x_" var_opt_short
[i
] ");";
214 for (i =
0; i
< n_opt_char
; i
++) {
215 print " if (ptr->x_" var_opt_char
[i
] ")";
216 print " fprintf (file, \"%*s%s (%#x)\\n\",";
217 print " indent_to, \"\",";
218 print " \"" var_opt_char
[i
] "\",";
219 print " ptr->x_" var_opt_char
[i
] ");";
226 print "/* Save selected option variables into a structure. */"
228 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
238 for (i =
0; i
< n_opts
; i
++) {
239 if (flag_set_p
("Save", flags
[i
])) {
240 name = var_name
(flags
[i
])
242 name =
"target_flags";
244 if(name in var_save_seen
)
247 var_save_seen
[name
]++;
248 otype = var_type_struct
(flags
[i
])
249 if (otype ~
"^((un)?signed +)?int *$")
250 var_target_int
[n_target_int
++] = name
;
252 else if (otype ~
"^((un)?signed +)?short *$")
253 var_target_short
[n_target_short
++] = name
;
255 else if (otype ~
("^enum +[_" alnum
"]+ *$"))
256 var_target_enum
[n_target_enum
++] = name
;
258 else if (otype ~
"^((un)?signed +)?char *$") {
259 var_target_char
[n_target_char
++] = name
;
260 if (otype ~
"^unsigned +char *$")
261 var_target_range
[name
] =
"0, 255"
262 else if (otype ~
"^signed +char *$")
263 var_target_range
[name
] =
"-128, 127"
264 if (otype == var_type
(flags
[i
]))
265 var_target_range
[name
] =
""
268 var_target_other
[n_target_other
++] = name
;
272 var_target_int
[n_target_int
++] =
"target_flags";
276 for (i =
0; i
< n_target_char
; i
++) {
277 name = var_target_char
[i
];
278 if (var_target_range
[name
] != "") {
280 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_target_range
[name
] "));";
287 print " if (targetm.target_option.save)";
288 print " targetm.target_option.save (ptr);";
291 for (i =
0; i
< n_extra_target_vars
; i
++) {
292 print " ptr->x_" extra_target_vars
[i
] " = opts->x_" extra_target_vars
[i
] ";";
295 for (i =
0; i
< n_target_other
; i
++) {
296 print " ptr->x_" var_target_other
[i
] " = opts->x_" var_target_other
[i
] ";";
299 for (i =
0; i
< n_target_enum
; i
++) {
300 print " ptr->x_" var_target_enum
[i
] " = opts->x_" var_target_enum
[i
] ";";
303 for (i =
0; i
< n_target_int
; i
++) {
304 print " ptr->x_" var_target_int
[i
] " = opts->x_" var_target_int
[i
] ";";
307 for (i =
0; i
< n_target_short
; i
++) {
308 print " ptr->x_" var_target_short
[i
] " = opts->x_" var_target_short
[i
] ";";
311 for (i =
0; i
< n_target_char
; i
++) {
312 print " ptr->x_" var_target_char
[i
] " = opts->x_" var_target_char
[i
] ";";
318 print "/* Restore selected current options from a structure. */";
320 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
323 for (i =
0; i
< n_extra_target_vars
; i
++) {
324 print " opts->x_" extra_target_vars
[i
] " = ptr->x_" extra_target_vars
[i
] ";";
327 for (i =
0; i
< n_target_other
; i
++) {
328 print " opts->x_" var_target_other
[i
] " = ptr->x_" var_target_other
[i
] ";";
331 for (i =
0; i
< n_target_enum
; i
++) {
332 print " opts->x_" var_target_enum
[i
] " = ptr->x_" var_target_enum
[i
] ";";
335 for (i =
0; i
< n_target_int
; i
++) {
336 print " opts->x_" var_target_int
[i
] " = ptr->x_" var_target_int
[i
] ";";
339 for (i =
0; i
< n_target_short
; i
++) {
340 print " opts->x_" var_target_short
[i
] " = ptr->x_" var_target_short
[i
] ";";
343 for (i =
0; i
< n_target_char
; i
++) {
344 print " opts->x_" var_target_char
[i
] " = ptr->x_" var_target_char
[i
] ";";
347 # This must occur after the normal variables in case the code depends on those
350 print " if (targetm.target_option.restore)";
351 print " targetm.target_option.restore (ptr);";
356 print "/* Print optimization options from a structure. */";
358 print "cl_target_option_print (FILE *file,";
359 print " int indent,";
360 print " struct cl_target_option *ptr)";
363 print " fputs (\"\\n\", file);";
364 for (i =
0; i
< n_target_other
; i
++) {
365 print " if (ptr->x_" var_target_other
[i
] ")";
366 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
367 print " indent, \"\",";
368 print " \"" var_target_other
[i
] "\",";
369 print " (unsigned long)ptr->x_" var_target_other
[i
] ");";
373 for (i =
0; i
< n_target_enum
; i
++) {
374 print " if (ptr->x_" var_target_enum
[i
] ")";
375 print " fprintf (file, \"%*s%s (%#x)\\n\",";
376 print " indent, \"\",";
377 print " \"" var_target_enum
[i
] "\",";
378 print " ptr->x_" var_target_enum
[i
] ");";
382 for (i =
0; i
< n_target_int
; i
++) {
383 print " if (ptr->x_" var_target_int
[i
] ")";
384 print " fprintf (file, \"%*s%s (%#x)\\n\",";
385 print " indent, \"\",";
386 print " \"" var_target_int
[i
] "\",";
387 print " ptr->x_" var_target_int
[i
] ");";
391 for (i =
0; i
< n_target_short
; i
++) {
392 print " if (ptr->x_" var_target_short
[i
] ")";
393 print " fprintf (file, \"%*s%s (%#x)\\n\",";
394 print " indent, \"\",";
395 print " \"" var_target_short
[i
] "\",";
396 print " ptr->x_" var_target_short
[i
] ");";
400 for (i =
0; i
< n_target_char
; i
++) {
401 print " if (ptr->x_" var_target_char
[i
] ")";
402 print " fprintf (file, \"%*s%s (%#x)\\n\",";
403 print " indent, \"\",";
404 print " \"" var_target_char
[i
] "\",";
405 print " ptr->x_" var_target_char
[i
] ");";
410 print " if (targetm.target_option.print)";
411 print " targetm.target_option.print (file, indent, ptr);";