1 # Copyright (C) 2003,2004,2005,2006,2007,2008, 2010
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
24 # This program uses functions from opt-functions.awk
25 # Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h
37 # Collect the text and flags of each option into an array
39 if ($
1 ==
"Language") {
43 else if ($
1 ==
"TargetSave") {
44 # Make sure the declarations are put in source order
45 target_save_decl
[n_target_save
] = $
2
49 name = opt_args
("Mask", $
1)
57 extra_masks
[n_extra_masks
++] = name
62 # Dump out an enumeration into a .h file.
63 # Combine the flags of duplicate options.
65 print "/* This file is auto-generated by opth-gen.awk. */"
67 print "#ifndef OPTIONS_H"
68 print "#define OPTIONS_H"
70 print "extern int target_flags;"
71 print "extern int target_flags_explicit;"
76 for (i =
0; i
< n_opts
; i
++) {
77 if (flag_set_p
("Save", flags
[i
]))
80 name = var_name
(flags
[i
]);
88 print "extern " var_type
(flags
[i
]) name
";"
92 # All of the optimization switches gathered together so they can be saved and restored.
93 # This will allow attribute((cold)) to turn on space optimization.
95 # Change the type of normal switches from int to unsigned char to save space.
96 # Also, order the structure so that pointer fields occur first, then int
97 # fields, and then char fields to provide the best packing.
99 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)"
101 print "/* Structure to save/restore optimization and target specific options. */";
102 print "struct GTY(()) cl_optimization";
109 var_opt_char
[0] =
"unsigned char optimize";
110 var_opt_char
[1] =
"unsigned char optimize_size";
112 for (i =
0; i
< n_opts
; i
++) {
113 if (flag_set_p
("Optimization", flags
[i
])) {
114 name = var_name
(flags
[i
])
118 if(name in var_opt_seen
)
121 var_opt_seen
[name
]++;
122 otype = var_type_struct
(flags
[i
]);
123 if (otype ~
"^((un)?signed +)?int *$")
124 var_opt_int
[n_opt_int
++] = otype name
;
126 else if (otype ~
"^((un)?signed +)?short *$")
127 var_opt_short
[n_opt_short
++] = otype name
;
129 else if (otype ~
"^((un)?signed +)?char *$")
130 var_opt_char
[n_opt_char
++] = otype name
;
133 var_opt_other
[n_opt_other
++] = otype name
;
137 for (i =
0; i
< n_opt_other
; i
++) {
138 print " " var_opt_other
[i
] ";";
141 for (i =
0; i
< n_opt_int
; i
++) {
142 print " " var_opt_int
[i
] ";";
145 for (i =
0; i
< n_opt_short
; i
++) {
146 print " " var_opt_short
[i
] ";";
149 for (i =
0; i
< n_opt_char
; i
++) {
150 print " " var_opt_char
[i
] ";";
156 # Target and optimization save/restore/print functions.
157 print "/* Structure to save/restore selected target specific options. */";
158 print "struct GTY(()) cl_target_option";
166 for (i =
0; i
< n_target_save
; i
++) {
167 if (target_save_decl
[i
] ~
"^((un)?signed +)?int +[_a-zA-Z0-9]+$")
168 var_target_int
[n_target_int
++] = target_save_decl
[i
];
170 else if (target_save_decl
[i
] ~
"^((un)?signed +)?short +[_a-zA-Z0-9]+$")
171 var_target_short
[n_target_short
++] = target_save_decl
[i
];
173 else if (target_save_decl
[i
] ~
"^((un)?signed +)?char +[_a-zA-Z0-9]+$")
174 var_target_char
[n_target_char
++] = target_save_decl
[i
];
177 var_target_other
[n_target_other
++] = target_save_decl
[i
];
181 for (i =
0; i
< n_opts
; i
++) {
182 if (flag_set_p
("Save", flags
[i
])) {
183 name = var_name
(flags
[i
])
185 name =
"target_flags";
187 if(name in var_save_seen
)
190 var_save_seen
[name
]++;
191 otype = var_type_struct
(flags
[i
])
192 if (otype ~
"^((un)?signed +)?int *$")
193 var_target_int
[n_target_int
++] = otype name
;
195 else if (otype ~
"^((un)?signed +)?short *$")
196 var_target_short
[n_target_short
++] = otype name
;
198 else if (otype ~
"^((un)?signed +)?char *$")
199 var_target_char
[n_target_char
++] = otype name
;
202 var_target_other
[n_target_other
++] = otype name
;
206 var_target_int
[n_target_int
++] =
"int target_flags";
209 for (i =
0; i
< n_target_other
; i
++) {
210 print " " var_target_other
[i
] ";";
213 for (i =
0; i
< n_target_int
; i
++) {
214 print " " var_target_int
[i
] ";";
217 for (i =
0; i
< n_target_short
; i
++) {
218 print " " var_target_short
[i
] ";";
221 for (i =
0; i
< n_target_char
; i
++) {
222 print " " var_target_char
[i
] ";";
228 print "/* Save optimization variables into a structure. */"
229 print "extern void cl_optimization_save (struct cl_optimization *);";
231 print "/* Restore optimization variables from a structure. */";
232 print "extern void cl_optimization_restore (struct cl_optimization *);";
234 print "/* Print optimization variables from a structure. */";
235 print "extern void cl_optimization_print (FILE *, int, struct cl_optimization *);";
237 print "/* Save selected option variables into a structure. */"
238 print "extern void cl_target_option_save (struct cl_target_option *);";
240 print "/* Restore selected option variables from a structure. */"
241 print "extern void cl_target_option_restore (struct cl_target_option *);";
243 print "/* Print target option variables from a structure. */";
244 print "extern void cl_target_option_print (FILE *, int, struct cl_target_option *);";
248 for (i =
0; i
< n_opts
; i
++) {
249 name = opt_args
("Mask", flags
[i
])
250 vname = var_name
(flags
[i
])
253 mask =
"OPTION_MASK_"
255 if (name
!= "" && !flag_set_p
("MaskExists", flags
[i
]))
256 print "#define " mask name
" (1 << " masknum
[vname
]++ ")"
258 for (i =
0; i
< n_extra_masks
; i
++) {
259 print "#define MASK_" extra_masks
[i
] " (1 << " masknum
[""]++ ")"
262 for (var in masknum
) {
263 if (masknum
[var
] > 31) {
265 print "#error too many target masks"
267 print "#error too many masks for " var
272 for (i =
0; i
< n_opts
; i
++) {
273 name = opt_args
("Mask", flags
[i
])
274 vname = var_name
(flags
[i
])
276 mask =
"OPTION_MASK_"
278 vname =
"target_flags"
282 if (name
!= "" && !flag_set_p
("MaskExists", flags
[i
]))
283 print "#define " macro name \
284 " ((" vname
" & " mask name
") != 0)"
286 for (i =
0; i
< n_extra_masks
; i
++) {
287 print "#define TARGET_" extra_masks
[i
] \
288 " ((target_flags & MASK_" extra_masks
[i
] ") != 0)"
292 for (i =
0; i
< n_opts
; i
++) {
293 opt = opt_args
("InverseMask", flags
[i
])
295 vname = var_name
(flags
[i
])
297 mask =
"OPTION_MASK_"
299 vname =
"target_flags"
303 print "#define " macro nth_arg
(1, opt
) \
304 " ((" vname
" & " mask nth_arg
(0, opt
) ") == 0)"
309 for (i =
0; i
< n_langs
; i
++) {
310 macros
[i
] =
"CL_" langs
[i
]
311 gsub( "[^A-Za-z0-9_]", "X", macros
[i
] )
312 s =
substr(" ", length (macros
[i
]))
313 print "#define " macros
[i
] s
" (1 << " i
")"
315 print "#define CL_LANG_ALL ((1 << " n_langs
") - 1)"
318 print "enum opt_code"
321 for (i =
0; i
< n_opts
; i
++)
322 back_chain
[i
] =
"N_OPTS";
324 for (i =
0; i
< n_opts
; i
++) {
325 # Combine the flags of identical switches. Switches
326 # appear many times if they are handled by many front
328 while( i
+ 1 != n_opts
&& opts
[i
] == opts
[i
+ 1] ) {
329 flags
[i
+ 1] = flags
[i
] " " flags
[i
+ 1];
333 len =
length (opts
[i
]);
334 enum =
"OPT_" opts
[i
]
335 if (opts
[i
] ==
"finline-limit=" || opts
[i
] ==
"Wlarger-than=" \
336 || opts
[i
] ==
"ftemplate-depth=")
338 if (opts
[i
] ==
"gdwarf+")
339 enum =
"OPT_gdwarfplus"
340 gsub ("[^A-Za-z0-9]", "_", enum
)
342 # If this switch takes joined arguments, back-chain all
343 # subsequent switches to it for which it is a prefix. If
344 # a later switch S is a longer prefix of a switch T, T
345 # will be back-chained to S in a later iteration of this
346 # for() loop, which is what we want.
347 if (flag_set_p
("Joined.*", flags
[i
])) {
348 for (j = i
+ 1; j
< n_opts
; j
++) {
349 if (substr (opts
[j
], 1, len
) != opts
[i
])
351 back_chain
[j
] = enum
;
355 s =
substr(" ", length (enum
))
362 hlp =
"N_(\"" help
[i
] "\")";
364 print " " enum
"," s
"/* -" opts
[i
] " */"
370 print "#endif /* OPTIONS_H */"