1 # Copyright (C) 2003,2004,2005,2006,2007,2008 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
23 # This program uses functions from opt-functions.awk
24 # Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h
36 # Collect the text and flags of each option into an array
38 if ($
1 ==
"Language") {
42 else if ($
1 ==
"TargetSave") {
43 # Make sure the declarations are put in source order
44 target_save_decl
[n_target_save
] = $
2
48 name = opt_args
("Mask", $
1)
56 extra_masks
[n_extra_masks
++] = name
61 # Dump out an enumeration into a .h file.
62 # Combine the flags of duplicate options.
64 print "/* This file is auto-generated by opth-gen.awk. */"
66 print "#ifndef OPTIONS_H"
67 print "#define OPTIONS_H"
69 print "extern int target_flags;"
70 print "extern int target_flags_explicit;"
75 for (i =
0; i
< n_opts
; i
++) {
76 if (flag_set_p
("Save", flags
[i
]))
79 name = var_name
(flags
[i
]);
87 print "extern " var_type
(flags
[i
]) name
";"
91 # All of the optimization switches gathered together so they can be saved and restored.
92 # This will allow attribute((cold)) to turn on space optimization.
94 # Change the type of normal switches from int to unsigned char to save space.
95 # Also, order the structure so that pointer fields occur first, then int
96 # fields, and then char fields to provide the best packing.
98 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)"
100 print "/* Structure to save/restore optimization and target specific options. */";
101 print "struct cl_optimization GTY(())";
108 var_opt_char
[0] =
"unsigned char optimize";
109 var_opt_char
[1] =
"unsigned char optimize_size";
111 for (i =
0; i
< n_opts
; i
++) {
112 if (flag_set_p
("Optimization", flags
[i
])) {
113 name = var_name
(flags
[i
])
117 if(name in var_opt_seen
)
120 var_opt_seen
[name
]++;
121 otype = var_type_struct
(flags
[i
]);
122 if (otype ~
"^((un)?signed +)?int *$")
123 var_opt_int
[n_opt_int
++] = otype name
;
125 else if (otype ~
"^((un)?signed +)?short *$")
126 var_opt_short
[n_opt_short
++] = otype name
;
128 else if (otype ~
"^((un)?signed +)?char *$")
129 var_opt_char
[n_opt_char
++] = otype name
;
132 var_opt_other
[n_opt_other
++] = otype name
;
136 for (i =
0; i
< n_opt_other
; i
++) {
137 print " " var_opt_other
[i
] ";";
140 for (i =
0; i
< n_opt_int
; i
++) {
141 print " " var_opt_int
[i
] ";";
144 for (i =
0; i
< n_opt_short
; i
++) {
145 print " " var_opt_short
[i
] ";";
148 for (i =
0; i
< n_opt_char
; i
++) {
149 print " " var_opt_char
[i
] ";";
155 # Target and optimization save/restore/print functions.
156 print "/* Structure to save/restore selected target specific options. */";
157 print "struct cl_target_option GTY(())";
165 for (i =
0; i
< n_target_save
; i
++) {
166 if (target_save_decl
[i
] ~
"^((un)?signed +)?int +[_a-zA-Z0-9]+$")
167 var_target_int
[n_target_int
++] = target_save_decl
[i
];
169 else if (target_save_decl
[i
] ~
"^((un)?signed +)?short +[_a-zA-Z0-9]+$")
170 var_target_short
[n_target_short
++] = target_save_decl
[i
];
172 else if (target_save_decl
[i
] ~
"^((un)?signed +)?char +[_a-zA-Z0-9]+$")
173 var_target_char
[n_target_char
++] = target_save_decl
[i
];
176 var_target_other
[n_target_other
++] = target_save_decl
[i
];
180 for (i =
0; i
< n_opts
; i
++) {
181 if (flag_set_p
("Save", flags
[i
])) {
182 name = var_name
(flags
[i
])
184 name =
"target_flags";
186 if(name in var_save_seen
)
189 var_save_seen
[name
]++;
190 otype = var_type_struct
(flags
[i
])
191 if (otype ~
"^((un)?signed +)?int *$")
192 var_target_int
[n_target_int
++] = otype name
;
194 else if (otype ~
"^((un)?signed +)?short *$")
195 var_target_short
[n_target_short
++] = otype name
;
197 else if (otype ~
"^((un)?signed +)?char *$")
198 var_target_char
[n_target_char
++] = otype name
;
201 var_target_other
[n_target_other
++] = otype name
;
205 var_target_int
[n_target_int
++] =
"int target_flags";
208 for (i =
0; i
< n_target_other
; i
++) {
209 print " " var_target_other
[i
] ";";
212 for (i =
0; i
< n_target_int
; i
++) {
213 print " " var_target_int
[i
] ";";
216 for (i =
0; i
< n_target_short
; i
++) {
217 print " " var_target_short
[i
] ";";
220 for (i =
0; i
< n_target_char
; i
++) {
221 print " " var_target_char
[i
] ";";
227 print "/* Save optimization variables into a structure. */"
228 print "extern void cl_optimization_save (struct cl_optimization *);";
230 print "/* Restore optimization variables from a structure. */";
231 print "extern void cl_optimization_restore (struct cl_optimization *);";
233 print "/* Print optimization variables from a structure. */";
234 print "extern void cl_optimization_print (FILE *, int, struct cl_optimization *);";
236 print "/* Save selected option variables into a structure. */"
237 print "extern void cl_target_option_save (struct cl_target_option *);";
239 print "/* Restore selected option variables from a structure. */"
240 print "extern void cl_target_option_restore (struct cl_target_option *);";
242 print "/* Print target option variables from a structure. */";
243 print "extern void cl_target_option_print (FILE *, int, struct cl_target_option *);";
247 for (i =
0; i
< n_opts
; i
++) {
248 name = opt_args
("Mask", flags
[i
])
249 vname = var_name
(flags
[i
])
252 mask =
"OPTION_MASK_"
254 if (name
!= "" && !flag_set_p
("MaskExists", flags
[i
]))
255 print "#define " mask name
" (1 << " masknum
[vname
]++ ")"
257 for (i =
0; i
< n_extra_masks
; i
++) {
258 print "#define MASK_" extra_masks
[i
] " (1 << " masknum
[""]++ ")"
261 for (var in masknum
) {
262 if (masknum
[var
] > 31) {
264 print "#error too many target masks"
266 print "#error too many masks for " var
271 for (i =
0; i
< n_opts
; i
++) {
272 name = opt_args
("Mask", flags
[i
])
273 vname = var_name
(flags
[i
])
275 mask =
"OPTION_MASK_"
277 vname =
"target_flags"
281 if (name
!= "" && !flag_set_p
("MaskExists", flags
[i
]))
282 print "#define " macro name \
283 " ((" vname
" & " mask name
") != 0)"
285 for (i =
0; i
< n_extra_masks
; i
++) {
286 print "#define TARGET_" extra_masks
[i
] \
287 " ((target_flags & MASK_" extra_masks
[i
] ") != 0)"
291 for (i =
0; i
< n_opts
; i
++) {
292 opt = opt_args
("InverseMask", flags
[i
])
294 vname = var_name
(flags
[i
])
296 mask =
"OPTION_MASK_"
298 vname =
"target_flags"
302 print "#define " macro nth_arg
(1, opt
) \
303 " ((" vname
" & " mask nth_arg
(0, opt
) ") == 0)"
308 for (i =
0; i
< n_langs
; i
++) {
309 macros
[i
] =
"CL_" langs
[i
]
310 gsub( "[^A-Za-z0-9_]", "X", macros
[i
] )
311 s =
substr(" ", length (macros
[i
]))
312 print "#define " macros
[i
] s
" (1 << " i
")"
314 print "#define CL_LANG_ALL ((1 << " n_langs
") - 1)"
317 print "enum opt_code"
320 for (i =
0; i
< n_opts
; i
++)
321 back_chain
[i
] =
"N_OPTS";
323 for (i =
0; i
< n_opts
; i
++) {
324 # Combine the flags of identical switches. Switches
325 # appear many times if they are handled by many front
327 while( i
+ 1 != n_opts
&& opts
[i
] == opts
[i
+ 1] ) {
328 flags
[i
+ 1] = flags
[i
] " " flags
[i
+ 1];
332 len =
length (opts
[i
]);
333 enum =
"OPT_" opts
[i
]
334 if (opts
[i
] ==
"finline-limit=" || opts
[i
] ==
"Wlarger-than=")
336 gsub ("[^A-Za-z0-9]", "_", enum
)
338 # If this switch takes joined arguments, back-chain all
339 # subsequent switches to it for which it is a prefix. If
340 # a later switch S is a longer prefix of a switch T, T
341 # will be back-chained to S in a later iteration of this
342 # for() loop, which is what we want.
343 if (flag_set_p
("Joined.*", flags
[i
])) {
344 for (j = i
+ 1; j
< n_opts
; j
++) {
345 if (substr (opts
[j
], 1, len
) != opts
[i
])
347 back_chain
[j
] = enum
;
351 s =
substr(" ", length (opts
[i
]))
358 hlp =
"N_(\"" help
[i
] "\")";
360 print " " enum
"," s
"/* -" opts
[i
] " */"
366 print "#endif /* OPTIONS_H */"