Mercurial > hg > CbC > CbC_gcc
comparison gcc/opth-gen.awk @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
65:65488c3d617d | 67:f6334be47118 |
---|---|
1 # Copyright (C) 2003,2004,2005,2006,2007,2008, 2010 | 1 # Copyright (C) 2003,2004,2005,2006,2007,2008, 2010, 2011 |
2 # Free Software Foundation, Inc. | 2 # Free Software Foundation, Inc. |
3 # Contributed by Kelley Cook, June 2004. | 3 # Contributed by Kelley Cook, June 2004. |
4 # Original code from Neil Booth, May 2003. | 4 # Original code from Neil Booth, May 2003. |
5 # | 5 # |
6 # This program is free software; you can redistribute it and/or modify it | 6 # This program is free software; you can redistribute it and/or modify it |
26 | 26 |
27 BEGIN { | 27 BEGIN { |
28 n_opts = 0 | 28 n_opts = 0 |
29 n_langs = 0 | 29 n_langs = 0 |
30 n_target_save = 0 | 30 n_target_save = 0 |
31 n_extra_vars = 0 | |
32 n_extra_target_vars = 0 | |
31 n_extra_masks = 0 | 33 n_extra_masks = 0 |
34 n_extra_c_includes = 0 | |
35 n_extra_h_includes = 0 | |
36 have_save = 0; | |
32 quote = "\042" | 37 quote = "\042" |
33 comma = "," | |
34 FS=SUBSEP | 38 FS=SUBSEP |
35 } | 39 } |
36 | 40 |
37 # Collect the text and flags of each option into an array | 41 # Collect the text and flags of each option into an array |
38 { | 42 { |
42 } | 46 } |
43 else if ($1 == "TargetSave") { | 47 else if ($1 == "TargetSave") { |
44 # Make sure the declarations are put in source order | 48 # Make sure the declarations are put in source order |
45 target_save_decl[n_target_save] = $2 | 49 target_save_decl[n_target_save] = $2 |
46 n_target_save++ | 50 n_target_save++ |
51 } | |
52 else if ($1 == "Variable") { | |
53 extra_vars[n_extra_vars] = $2 | |
54 n_extra_vars++ | |
55 } | |
56 else if ($1 == "TargetVariable") { | |
57 # Combination of TargetSave and Variable | |
58 extra_vars[n_extra_vars] = $2 | |
59 n_extra_vars++ | |
60 | |
61 var = $2 | |
62 sub(" *=.*", "", var) | |
63 orig_var = var | |
64 name = var | |
65 type = var | |
66 sub("^.*[ *]", "", name) | |
67 sub(" *" name "$", "", type) | |
68 target_save_decl[n_target_save] = type " x_" name | |
69 n_target_save++ | |
70 | |
71 extra_target_vars[n_extra_target_vars] = name | |
72 n_extra_target_vars++ | |
73 } | |
74 else if ($1 == "HeaderInclude") { | |
75 extra_h_includes[n_extra_h_includes++] = $2; | |
76 } | |
77 else if ($1 == "SourceInclude") { | |
78 extra_c_includes[n_extra_c_includes++] = $2; | |
79 } | |
80 else if ($1 == "Enum") { | |
81 props = $2 | |
82 name = opt_args("Name", props) | |
83 type = opt_args("Type", props) | |
84 unknown_error = opt_args("UnknownError", props) | |
85 enum_names[n_enums] = name | |
86 enum_type[name] = type | |
87 enum_index[name] = n_enums | |
88 enum_unknown_error[name] = unknown_error | |
89 enum_help[name] = $3 | |
90 n_enums++ | |
91 } | |
92 else if ($1 == "EnumValue") { | |
93 props = $2 | |
94 enum_name = opt_args("Enum", props) | |
95 string = opt_args("String", props) | |
96 value = opt_args("Value", props) | |
97 val_flags = "0" | |
98 val_flags = val_flags \ | |
99 test_flag("Canonical", props, "| CL_ENUM_CANONICAL") \ | |
100 test_flag("DriverOnly", props, "| CL_ENUM_DRIVER_ONLY") | |
101 enum_data[enum_name] = enum_data[enum_name] \ | |
102 " { " quote string quote ", " value ", " val_flags \ | |
103 " },\n" | |
47 } | 104 } |
48 else { | 105 else { |
49 name = opt_args("Mask", $1) | 106 name = opt_args("Mask", $1) |
50 if (name == "") { | 107 if (name == "") { |
51 opts[n_opts] = $1 | 108 opts[n_opts] = $1 |
65 print "/* This file is auto-generated by opth-gen.awk. */" | 122 print "/* This file is auto-generated by opth-gen.awk. */" |
66 print "" | 123 print "" |
67 print "#ifndef OPTIONS_H" | 124 print "#ifndef OPTIONS_H" |
68 print "#define OPTIONS_H" | 125 print "#define OPTIONS_H" |
69 print "" | 126 print "" |
70 print "extern int target_flags;" | 127 print "#include \"flag-types.h\"" |
71 print "extern int target_flags_explicit;" | 128 print "" |
72 print "" | 129 |
73 | 130 if (n_extra_h_includes > 0) { |
74 have_save = 0; | 131 for (i = 0; i < n_extra_h_includes; i++) { |
132 print "#include " quote extra_h_includes[i] quote | |
133 } | |
134 print "" | |
135 } | |
136 | |
137 print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)" | |
138 print "#ifndef GENERATOR_FILE" | |
139 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)" | |
140 print "struct GTY(()) gcc_options" | |
141 print "#else" | |
142 print "struct gcc_options" | |
143 print "#endif" | |
144 print "{" | |
145 print "#endif" | |
146 | |
147 for (i = 0; i < n_extra_vars; i++) { | |
148 var = extra_vars[i] | |
149 sub(" *=.*", "", var) | |
150 orig_var = var | |
151 name = var | |
152 type = var | |
153 type_after = var | |
154 sub("^.*[ *]", "", name) | |
155 sub("\\[.*\\]$", "", name) | |
156 sub("\\[.*\\]$", "", type) | |
157 sub(" *" name "$", "", type) | |
158 sub("^.*" name, "", type_after) | |
159 var_seen[name] = 1 | |
160 print "#ifdef GENERATOR_FILE" | |
161 print "extern " orig_var ";" | |
162 print "#else" | |
163 print " " type " x_" name type_after ";" | |
164 print "#define " name " global_options.x_" name | |
165 print "#endif" | |
166 } | |
75 | 167 |
76 for (i = 0; i < n_opts; i++) { | 168 for (i = 0; i < n_opts; i++) { |
77 if (flag_set_p("Save", flags[i])) | 169 if (flag_set_p("Save", flags[i])) |
78 have_save = 1; | 170 have_save = 1; |
79 | 171 |
83 | 175 |
84 if (name in var_seen) | 176 if (name in var_seen) |
85 continue; | 177 continue; |
86 | 178 |
87 var_seen[name] = 1; | 179 var_seen[name] = 1; |
180 print "#ifdef GENERATOR_FILE" | |
88 print "extern " var_type(flags[i]) name ";" | 181 print "extern " var_type(flags[i]) name ";" |
89 } | 182 print "#else" |
183 print " " var_type(flags[i]) "x_" name ";" | |
184 print "#define " name " global_options.x_" name | |
185 print "#endif" | |
186 } | |
187 for (i = 0; i < n_opts; i++) { | |
188 name = static_var(opts[i], flags[i]); | |
189 if (name != "") { | |
190 print "#ifndef GENERATOR_FILE" | |
191 print " " var_type(flags[i]) "x_" name ";" | |
192 print "#define x_" name " do_not_use" | |
193 print "#endif" | |
194 } | |
195 } | |
196 for (i = 0; i < n_opts; i++) { | |
197 if (flag_set_p("SetByCombined", flags[i])) { | |
198 print "#ifndef GENERATOR_FILE" | |
199 print " bool frontend_set_" var_name(flags[i]) ";" | |
200 print "#endif" | |
201 } | |
202 } | |
203 print "#ifndef GENERATOR_FILE" | |
204 print "};" | |
205 print "extern struct gcc_options global_options;" | |
206 print "extern const struct gcc_options global_options_init;" | |
207 print "extern struct gcc_options global_options_set;" | |
208 print "#define target_flags_explicit global_options_set.x_target_flags" | |
209 print "#endif" | |
210 print "#endif" | |
90 print "" | 211 print "" |
91 | 212 |
92 # All of the optimization switches gathered together so they can be saved and restored. | 213 # 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. | 214 # This will allow attribute((cold)) to turn on space optimization. |
94 | 215 |
103 print "{"; | 224 print "{"; |
104 | 225 |
105 n_opt_char = 2; | 226 n_opt_char = 2; |
106 n_opt_short = 0; | 227 n_opt_short = 0; |
107 n_opt_int = 0; | 228 n_opt_int = 0; |
229 n_opt_enum = 1; | |
108 n_opt_other = 0; | 230 n_opt_other = 0; |
109 var_opt_char[0] = "unsigned char optimize"; | 231 var_opt_char[0] = "unsigned char x_optimize"; |
110 var_opt_char[1] = "unsigned char optimize_size"; | 232 var_opt_char[1] = "unsigned char x_optimize_size"; |
233 var_opt_enum[0] = "enum fp_contract_mode x_flag_fp_contract_mode"; | |
111 | 234 |
112 for (i = 0; i < n_opts; i++) { | 235 for (i = 0; i < n_opts; i++) { |
113 if (flag_set_p("Optimization", flags[i])) { | 236 if (flag_set_p("Optimization", flags[i])) { |
114 name = var_name(flags[i]) | 237 name = var_name(flags[i]) |
115 if(name == "") | 238 if(name == "") |
119 continue; | 242 continue; |
120 | 243 |
121 var_opt_seen[name]++; | 244 var_opt_seen[name]++; |
122 otype = var_type_struct(flags[i]); | 245 otype = var_type_struct(flags[i]); |
123 if (otype ~ "^((un)?signed +)?int *$") | 246 if (otype ~ "^((un)?signed +)?int *$") |
124 var_opt_int[n_opt_int++] = otype name; | 247 var_opt_int[n_opt_int++] = otype "x_" name; |
125 | 248 |
126 else if (otype ~ "^((un)?signed +)?short *$") | 249 else if (otype ~ "^((un)?signed +)?short *$") |
127 var_opt_short[n_opt_short++] = otype name; | 250 var_opt_short[n_opt_short++] = otype "x_" name; |
128 | 251 |
129 else if (otype ~ "^((un)?signed +)?char *$") | 252 else if (otype ~ "^((un)?signed +)?char *$") |
130 var_opt_char[n_opt_char++] = otype name; | 253 var_opt_char[n_opt_char++] = otype "x_" name; |
254 | |
255 else if (otype ~ ("^enum +[_" alnum "]+ *$")) | |
256 var_opt_enum[n_opt_enum++] = otype "x_" name; | |
131 | 257 |
132 else | 258 else |
133 var_opt_other[n_opt_other++] = otype name; | 259 var_opt_other[n_opt_other++] = otype "x_" name; |
134 } | 260 } |
135 } | 261 } |
136 | 262 |
137 for (i = 0; i < n_opt_other; i++) { | 263 for (i = 0; i < n_opt_other; i++) { |
138 print " " var_opt_other[i] ";"; | 264 print " " var_opt_other[i] ";"; |
139 } | 265 } |
140 | 266 |
141 for (i = 0; i < n_opt_int; i++) { | 267 for (i = 0; i < n_opt_int; i++) { |
142 print " " var_opt_int[i] ";"; | 268 print " " var_opt_int[i] ";"; |
269 } | |
270 | |
271 for (i = 0; i < n_opt_enum; i++) { | |
272 print " " var_opt_enum[i] ";"; | |
143 } | 273 } |
144 | 274 |
145 for (i = 0; i < n_opt_short; i++) { | 275 for (i = 0; i < n_opt_short; i++) { |
146 print " " var_opt_short[i] ";"; | 276 print " " var_opt_short[i] ";"; |
147 } | 277 } |
159 print "{"; | 289 print "{"; |
160 | 290 |
161 n_target_char = 0; | 291 n_target_char = 0; |
162 n_target_short = 0; | 292 n_target_short = 0; |
163 n_target_int = 0; | 293 n_target_int = 0; |
294 n_target_enum = 0; | |
164 n_target_other = 0; | 295 n_target_other = 0; |
165 | 296 |
166 for (i = 0; i < n_target_save; i++) { | 297 for (i = 0; i < n_target_save; i++) { |
167 if (target_save_decl[i] ~ "^((un)?signed +)?int +[_a-zA-Z0-9]+$") | 298 if (target_save_decl[i] ~ "^((un)?signed +)?int +[_" alnum "]+$") |
168 var_target_int[n_target_int++] = target_save_decl[i]; | 299 var_target_int[n_target_int++] = target_save_decl[i]; |
169 | 300 |
170 else if (target_save_decl[i] ~ "^((un)?signed +)?short +[_a-zA-Z0-9]+$") | 301 else if (target_save_decl[i] ~ "^((un)?signed +)?short +[_" alnum "]+$") |
171 var_target_short[n_target_short++] = target_save_decl[i]; | 302 var_target_short[n_target_short++] = target_save_decl[i]; |
172 | 303 |
173 else if (target_save_decl[i] ~ "^((un)?signed +)?char +[_a-zA-Z0-9]+$") | 304 else if (target_save_decl[i] ~ "^((un)?signed +)?char +[_ " alnum "]+$") |
174 var_target_char[n_target_char++] = target_save_decl[i]; | 305 var_target_char[n_target_char++] = target_save_decl[i]; |
175 | 306 |
307 else if (target_save_decl[i] ~ ("^enum +[_" alnum "]+ +[_" alnum "]+$")) { | |
308 var_target_enum[n_target_enum++] = target_save_decl[i]; | |
309 } | |
176 else | 310 else |
177 var_target_other[n_target_other++] = target_save_decl[i]; | 311 var_target_other[n_target_other++] = target_save_decl[i]; |
178 } | 312 } |
179 | 313 |
180 if (have_save) { | 314 if (have_save) { |
188 continue; | 322 continue; |
189 | 323 |
190 var_save_seen[name]++; | 324 var_save_seen[name]++; |
191 otype = var_type_struct(flags[i]) | 325 otype = var_type_struct(flags[i]) |
192 if (otype ~ "^((un)?signed +)?int *$") | 326 if (otype ~ "^((un)?signed +)?int *$") |
193 var_target_int[n_target_int++] = otype name; | 327 var_target_int[n_target_int++] = otype "x_" name; |
194 | 328 |
195 else if (otype ~ "^((un)?signed +)?short *$") | 329 else if (otype ~ "^((un)?signed +)?short *$") |
196 var_target_short[n_target_short++] = otype name; | 330 var_target_short[n_target_short++] = otype "x_" name; |
197 | 331 |
198 else if (otype ~ "^((un)?signed +)?char *$") | 332 else if (otype ~ "^((un)?signed +)?char *$") |
199 var_target_char[n_target_char++] = otype name; | 333 var_target_char[n_target_char++] = otype "x_" name; |
334 | |
335 else if (otype ~ ("^enum +[_" alnum "]+ +[_" alnum "]+")) | |
336 var_target_enum[n_target_enum++] = otype "x_" name; | |
200 | 337 |
201 else | 338 else |
202 var_target_other[n_target_other++] = otype name; | 339 var_target_other[n_target_other++] = otype "x_" name; |
203 } | 340 } |
204 } | 341 } |
205 } else { | 342 } else { |
206 var_target_int[n_target_int++] = "int target_flags"; | 343 var_target_int[n_target_int++] = "int x_target_flags"; |
207 } | 344 } |
208 | 345 |
209 for (i = 0; i < n_target_other; i++) { | 346 for (i = 0; i < n_target_other; i++) { |
210 print " " var_target_other[i] ";"; | 347 print " " var_target_other[i] ";"; |
211 } | 348 } |
212 | 349 |
350 for (i = 0; i < n_target_enum; i++) { | |
351 print " " var_target_enum[i] ";"; | |
352 } | |
353 | |
213 for (i = 0; i < n_target_int; i++) { | 354 for (i = 0; i < n_target_int; i++) { |
214 print " " var_target_int[i] ";"; | 355 print " " var_target_int[i] ";"; |
215 } | 356 } |
216 | 357 |
217 for (i = 0; i < n_target_short; i++) { | 358 for (i = 0; i < n_target_short; i++) { |
224 | 365 |
225 print "};"; | 366 print "};"; |
226 print ""; | 367 print ""; |
227 print ""; | 368 print ""; |
228 print "/* Save optimization variables into a structure. */" | 369 print "/* Save optimization variables into a structure. */" |
229 print "extern void cl_optimization_save (struct cl_optimization *);"; | 370 print "extern void cl_optimization_save (struct cl_optimization *, struct gcc_options *);"; |
230 print ""; | 371 print ""; |
231 print "/* Restore optimization variables from a structure. */"; | 372 print "/* Restore optimization variables from a structure. */"; |
232 print "extern void cl_optimization_restore (struct cl_optimization *);"; | 373 print "extern void cl_optimization_restore (struct gcc_options *, struct cl_optimization *);"; |
233 print ""; | 374 print ""; |
234 print "/* Print optimization variables from a structure. */"; | 375 print "/* Print optimization variables from a structure. */"; |
235 print "extern void cl_optimization_print (FILE *, int, struct cl_optimization *);"; | 376 print "extern void cl_optimization_print (FILE *, int, struct cl_optimization *);"; |
236 print ""; | 377 print ""; |
237 print "/* Save selected option variables into a structure. */" | 378 print "/* Save selected option variables into a structure. */" |
238 print "extern void cl_target_option_save (struct cl_target_option *);"; | 379 print "extern void cl_target_option_save (struct cl_target_option *, struct gcc_options *);"; |
239 print ""; | 380 print ""; |
240 print "/* Restore selected option variables from a structure. */" | 381 print "/* Restore selected option variables from a structure. */" |
241 print "extern void cl_target_option_restore (struct cl_target_option *);"; | 382 print "extern void cl_target_option_restore (struct gcc_options *, struct cl_target_option *);"; |
242 print ""; | 383 print ""; |
243 print "/* Print target option variables from a structure. */"; | 384 print "/* Print target option variables from a structure. */"; |
244 print "extern void cl_target_option_print (FILE *, int, struct cl_target_option *);"; | 385 print "extern void cl_target_option_print (FILE *, int, struct cl_target_option *);"; |
245 print "#endif"; | 386 print "#endif"; |
246 print ""; | 387 print ""; |
306 } | 447 } |
307 print "" | 448 print "" |
308 | 449 |
309 for (i = 0; i < n_langs; i++) { | 450 for (i = 0; i < n_langs; i++) { |
310 macros[i] = "CL_" langs[i] | 451 macros[i] = "CL_" langs[i] |
311 gsub( "[^A-Za-z0-9_]", "X", macros[i] ) | 452 gsub( "[^" alnum "_]", "X", macros[i] ) |
312 s = substr(" ", length (macros[i])) | 453 s = substr(" ", length (macros[i])) |
313 print "#define " macros[i] s " (1 << " i ")" | 454 print "#define " macros[i] s " (1 << " i ")" |
314 } | 455 } |
315 print "#define CL_LANG_ALL ((1 << " n_langs ") - 1)" | 456 print "#define CL_LANG_ALL ((1 << " n_langs ") - 1)" |
316 | 457 |
319 print "{" | 460 print "{" |
320 | 461 |
321 for (i = 0; i < n_opts; i++) | 462 for (i = 0; i < n_opts; i++) |
322 back_chain[i] = "N_OPTS"; | 463 back_chain[i] = "N_OPTS"; |
323 | 464 |
465 enum_value = 0 | |
324 for (i = 0; i < n_opts; i++) { | 466 for (i = 0; i < n_opts; i++) { |
325 # Combine the flags of identical switches. Switches | 467 # Combine the flags of identical switches. Switches |
326 # appear many times if they are handled by many front | 468 # appear many times if they are handled by many front |
327 # ends, for example. | 469 # ends, for example. |
328 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { | 470 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
330 i++; | 472 i++; |
331 } | 473 } |
332 | 474 |
333 len = length (opts[i]); | 475 len = length (opts[i]); |
334 enum = opt_enum(opts[i]) | 476 enum = opt_enum(opts[i]) |
477 enum_string = enum " = " enum_value "," | |
478 | |
479 # Aliases do not get enumeration names. | |
480 if ((flag_set_p("Alias.*", flags[i]) \ | |
481 && !flag_set_p("SeparateAlias", flags[i])) \ | |
482 || flag_set_p("Ignore", flags[i])) { | |
483 enum_string = "/* " enum_string " */" | |
484 } | |
335 | 485 |
336 # If this switch takes joined arguments, back-chain all | 486 # If this switch takes joined arguments, back-chain all |
337 # subsequent switches to it for which it is a prefix. If | 487 # subsequent switches to it for which it is a prefix. If |
338 # a later switch S is a longer prefix of a switch T, T | 488 # a later switch S is a longer prefix of a switch T, T |
339 # will be back-chained to S in a later iteration of this | 489 # will be back-chained to S in a later iteration of this |
344 break; | 494 break; |
345 back_chain[j] = enum; | 495 back_chain[j] = enum; |
346 } | 496 } |
347 } | 497 } |
348 | 498 |
349 s = substr(" ", length (enum)) | 499 s = substr(" ", |
350 if (i + 1 == n_opts) | 500 length (enum_string)) |
351 comma = "" | |
352 | 501 |
353 if (help[i] == "") | 502 if (help[i] == "") |
354 hlp = "0" | 503 hlp = "0" |
355 else | 504 else |
356 hlp = "N_(\"" help[i] "\")"; | 505 hlp = "N_(\"" help[i] "\")"; |
357 | 506 |
358 print " " enum "," s "/* -" opts[i] " */" | 507 print " " enum_string s "/* -" opts[i] " */" |
359 } | 508 enum_value++ |
360 | 509 } |
361 print " N_OPTS" | 510 |
511 print " N_OPTS," | |
512 print " OPT_SPECIAL_unknown," | |
513 print " OPT_SPECIAL_ignore," | |
514 print " OPT_SPECIAL_program_name," | |
515 print " OPT_SPECIAL_input_file" | |
362 print "};" | 516 print "};" |
363 print "" | 517 print "" |
364 print "#endif /* OPTIONS_H */" | 518 print "#endif /* OPTIONS_H */" |
365 } | 519 } |