comparison gcc/opth-gen.awk @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 # Copyright (C) 2003,2004,2005,2006,2007,2008, 2010, 2011 1 # Copyright (C) 2003-2017 Free Software Foundation, Inc.
2 # Free Software Foundation, Inc.
3 # Contributed by Kelley Cook, June 2004. 2 # Contributed by Kelley Cook, June 2004.
4 # Original code from Neil Booth, May 2003. 3 # Original code from Neil Booth, May 2003.
5 # 4 #
6 # This program is free software; you can redistribute it and/or modify it 5 # 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 6 # under the terms of the GNU General Public License as published by the
19 18
20 # This Awk script reads in the option records generated from 19 # This Awk script reads in the option records generated from
21 # opt-gather.awk, combines the flags of duplicate options and generates a 20 # opt-gather.awk, combines the flags of duplicate options and generates a
22 # C header file. 21 # C header file.
23 # 22 #
24 # This program uses functions from opt-functions.awk 23 # This program uses functions from opt-functions.awk and code from
25 # Usage: awk -f opt-functions.awk -f opth-gen.awk < inputfile > options.h 24 # opt-read.awk.
26 25 # Usage: awk -f opt-functions.awk -f opt-read.awk -f opth-gen.awk \
27 BEGIN { 26 # < inputfile > options.h
28 n_opts = 0
29 n_langs = 0
30 n_target_save = 0
31 n_extra_vars = 0
32 n_extra_target_vars = 0
33 n_extra_masks = 0
34 n_extra_c_includes = 0
35 n_extra_h_includes = 0
36 have_save = 0;
37 quote = "\042"
38 FS=SUBSEP
39 }
40
41 # Collect the text and flags of each option into an array
42 {
43 if ($1 == "Language") {
44 langs[n_langs] = $2
45 n_langs++;
46 }
47 else if ($1 == "TargetSave") {
48 # Make sure the declarations are put in source order
49 target_save_decl[n_target_save] = $2
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"
104 }
105 else {
106 name = opt_args("Mask", $1)
107 if (name == "") {
108 opts[n_opts] = $1
109 flags[n_opts] = $2
110 help[n_opts] = $3
111 n_opts++;
112 }
113 else {
114 extra_masks[n_extra_masks++] = name
115 }
116 }
117 }
118 27
119 # Dump out an enumeration into a .h file. 28 # Dump out an enumeration into a .h file.
120 # Combine the flags of duplicate options. 29 # Combine the flags of duplicate options.
121 END { 30 END {
122 print "/* This file is auto-generated by opth-gen.awk. */" 31 print "/* This file is auto-generated by opth-gen.awk. */"
134 print "" 43 print ""
135 } 44 }
136 45
137 print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)" 46 print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)"
138 print "#ifndef GENERATOR_FILE" 47 print "#ifndef GENERATOR_FILE"
139 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)" 48 print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)"
140 print "struct GTY(()) gcc_options" 49 print "struct GTY(()) gcc_options"
141 print "#else" 50 print "#else"
142 print "struct gcc_options" 51 print "struct gcc_options"
143 print "#endif" 52 print "#endif"
144 print "{" 53 print "{"
215 124
216 # Change the type of normal switches from int to unsigned char to save space. 125 # Change the type of normal switches from int to unsigned char to save space.
217 # Also, order the structure so that pointer fields occur first, then int 126 # Also, order the structure so that pointer fields occur first, then int
218 # fields, and then char fields to provide the best packing. 127 # fields, and then char fields to provide the best packing.
219 128
220 print "#if !defined(GCC_DRIVER) && !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS)" 129 print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)"
221 print "" 130 print ""
222 print "/* Structure to save/restore optimization and target specific options. */"; 131 print "/* Structure to save/restore optimization and target specific options. */";
223 print "struct GTY(()) cl_optimization"; 132 print "struct GTY(()) cl_optimization";
224 print "{"; 133 print "{";
225 134
226 n_opt_char = 2; 135 n_opt_char = 3;
227 n_opt_short = 0; 136 n_opt_short = 0;
228 n_opt_int = 0; 137 n_opt_int = 0;
229 n_opt_enum = 1; 138 n_opt_enum = 0;
230 n_opt_other = 0; 139 n_opt_other = 0;
231 var_opt_char[0] = "unsigned char x_optimize"; 140 var_opt_char[0] = "unsigned char x_optimize";
232 var_opt_char[1] = "unsigned char x_optimize_size"; 141 var_opt_char[1] = "unsigned char x_optimize_size";
233 var_opt_enum[0] = "enum fp_contract_mode x_flag_fp_contract_mode"; 142 var_opt_char[2] = "unsigned char x_optimize_debug";
234 143
235 for (i = 0; i < n_opts; i++) { 144 for (i = 0; i < n_opts; i++) {
236 if (flag_set_p("Optimization", flags[i])) { 145 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
237 name = var_name(flags[i]) 146 name = var_name(flags[i])
238 if(name == "") 147 if(name == "")
239 continue; 148 continue;
240 149
241 if(name in var_opt_seen) 150 if(name in var_opt_seen)
373 print "extern void cl_optimization_restore (struct gcc_options *, struct cl_optimization *);"; 282 print "extern void cl_optimization_restore (struct gcc_options *, struct cl_optimization *);";
374 print ""; 283 print "";
375 print "/* Print optimization variables from a structure. */"; 284 print "/* Print optimization variables from a structure. */";
376 print "extern void cl_optimization_print (FILE *, int, struct cl_optimization *);"; 285 print "extern void cl_optimization_print (FILE *, int, struct cl_optimization *);";
377 print ""; 286 print "";
287 print "/* Print different optimization variables from structures provided as arguments. */";
288 print "extern void cl_optimization_print_diff (FILE *, int, cl_optimization *ptr1, cl_optimization *ptr2);";
289 print "";
378 print "/* Save selected option variables into a structure. */" 290 print "/* Save selected option variables into a structure. */"
379 print "extern void cl_target_option_save (struct cl_target_option *, struct gcc_options *);"; 291 print "extern void cl_target_option_save (struct cl_target_option *, struct gcc_options *);";
380 print ""; 292 print "";
381 print "/* Restore selected option variables from a structure. */" 293 print "/* Restore selected option variables from a structure. */"
382 print "extern void cl_target_option_restore (struct gcc_options *, struct cl_target_option *);"; 294 print "extern void cl_target_option_restore (struct gcc_options *, struct cl_target_option *);";
383 print ""; 295 print "";
384 print "/* Print target option variables from a structure. */"; 296 print "/* Print target option variables from a structure. */";
385 print "extern void cl_target_option_print (FILE *, int, struct cl_target_option *);"; 297 print "extern void cl_target_option_print (FILE *, int, struct cl_target_option *);";
298 print "";
299 print "/* Print different target option variables from structures provided as arguments. */";
300 print "extern void cl_target_option_print_diff (FILE *, int, cl_target_option *ptr1, cl_target_option *ptr2);";
301 print "";
302 print "/* Compare two target option variables from a structure. */";
303 print "extern bool cl_target_option_eq (const struct cl_target_option *, const struct cl_target_option *);";
304 print "";
305 print "/* Hash option variables from a structure. */";
306 print "extern hashval_t cl_target_option_hash (const struct cl_target_option *);";
307 print "";
308 print "/* Hash optimization from a structure. */";
309 print "extern hashval_t cl_optimization_hash (const struct cl_optimization *);";
310 print "";
311 print "/* Generator files may not have access to location_t, and don't need these. */"
312 print "#if defined(UNKNOWN_LOCATION)"
313 print "bool "
314 print "common_handle_option_auto (struct gcc_options *opts, "
315 print " struct gcc_options *opts_set, "
316 print " const struct cl_decoded_option *decoded, "
317 print " unsigned int lang_mask, int kind, "
318 print " location_t loc, "
319 print " const struct cl_option_handlers *handlers, "
320 print " diagnostic_context *dc); "
321 for (i = 0; i < n_langs; i++) {
322 lang_name = lang_sanitized_name(langs[i]);
323 print "bool "
324 print lang_name "_handle_option_auto (struct gcc_options *opts, "
325 print " struct gcc_options *opts_set, "
326 print " size_t scode, const char *arg, int value, "
327 print " unsigned int lang_mask, int kind, "
328 print " location_t loc, "
329 print " const struct cl_option_handlers *handlers, "
330 print " diagnostic_context *dc); "
331 }
332 print "void cpp_handle_option_auto (const struct gcc_options * opts, size_t scode,"
333 print " struct cpp_options * cpp_opts);"
334 print "void init_global_opts_from_cpp(struct gcc_options * opts, "
335 print " const struct cpp_options * cpp_opts);"
386 print "#endif"; 336 print "#endif";
337 print "#endif";
387 print ""; 338 print "";
388 339
389 for (i = 0; i < n_opts; i++) { 340 for (i = 0; i < n_opts; i++) {
390 name = opt_args("Mask", flags[i]) 341 name = opt_args("Mask", flags[i])
391 vname = var_name(flags[i]) 342 if (name == "") {
392 mask = "MASK_" 343 opt = opt_args("InverseMask", flags[i])
393 if (vname != "") { 344 if (opt ~ ",")
394 mask = "OPTION_MASK_" 345 name = nth_arg(0, opt)
395 } 346 else
396 if (name != "" && !flag_set_p("MaskExists", flags[i])) 347 name = opt
397 print "#define " mask name " (1 << " masknum[vname]++ ")" 348 }
349 if (name != "" && mask_bits[name] == 0) {
350 mask_bits[name] = 1
351 vname = var_name(flags[i])
352 mask = "MASK_"
353 mask_1 = "1U"
354 if (vname != "") {
355 mask = "OPTION_MASK_"
356 if (host_wide_int[vname] == "yes")
357 mask_1 = "HOST_WIDE_INT_1U"
358 } else
359 extra_mask_bits[name] = 1
360 print "#define " mask name " (" mask_1 " << " masknum[vname]++ ")"
361 }
398 } 362 }
399 for (i = 0; i < n_extra_masks; i++) { 363 for (i = 0; i < n_extra_masks; i++) {
400 print "#define MASK_" extra_masks[i] " (1 << " masknum[""]++ ")" 364 if (extra_mask_bits[extra_masks[i]] == 0)
365 print "#define MASK_" extra_masks[i] " (1U << " masknum[""]++ ")"
401 } 366 }
402 367
403 for (var in masknum) { 368 for (var in masknum) {
404 if (masknum[var] > 31) { 369 if (var != "" && host_wide_int[var] == "yes") {
370 print "#if defined(HOST_BITS_PER_WIDE_INT) && " masknum[var] " > HOST_BITS_PER_WIDE_INT"
371 print "#error too many masks for " var
372 print "#endif"
373 }
374 else if (masknum[var] > 32) {
405 if (var == "") 375 if (var == "")
406 print "#error too many target masks" 376 print "#error too many target masks"
407 else 377 else
408 print "#error too many masks for " var 378 print "#error too many masks for " var
409 } 379 }
410 } 380 }
411 print "" 381 print ""
412 382
413 for (i = 0; i < n_opts; i++) { 383 for (i = 0; i < n_opts; i++) {
414 name = opt_args("Mask", flags[i]) 384 name = opt_args("Mask", flags[i])
415 vname = var_name(flags[i]) 385 if (name == "") {
416 macro = "OPTION_" 386 opt = opt_args("InverseMask", flags[i])
417 mask = "OPTION_MASK_" 387 if (opt ~ ",")
418 if (vname == "") { 388 name = nth_arg(0, opt)
419 vname = "target_flags" 389 else
420 macro = "TARGET_" 390 name = opt
421 mask = "MASK_" 391 }
422 } 392 if (name != "" && mask_macros[name] == 0) {
423 if (name != "" && !flag_set_p("MaskExists", flags[i])) 393 mask_macros[name] = 1
424 print "#define " macro name \ 394 vname = var_name(flags[i])
395 mask = "OPTION_MASK_"
396 if (vname == "") {
397 vname = "target_flags"
398 mask = "MASK_"
399 extra_mask_macros[name] = 1
400 }
401 print "#define TARGET_" name \
425 " ((" vname " & " mask name ") != 0)" 402 " ((" vname " & " mask name ") != 0)"
403 print "#define TARGET_" name "_P(" vname ")" \
404 " (((" vname ") & " mask name ") != 0)"
405 }
426 } 406 }
427 for (i = 0; i < n_extra_masks; i++) { 407 for (i = 0; i < n_extra_masks; i++) {
428 print "#define TARGET_" extra_masks[i] \ 408 if (extra_mask_macros[extra_masks[i]] == 0)
429 " ((target_flags & MASK_" extra_masks[i] ") != 0)" 409 print "#define TARGET_" extra_masks[i] \
410 " ((target_flags & MASK_" extra_masks[i] ") != 0)"
430 } 411 }
431 print "" 412 print ""
432 413
433 for (i = 0; i < n_opts; i++) { 414 for (i = 0; i < n_opts; i++) {
434 opt = opt_args("InverseMask", flags[i]) 415 opt = opt_args("InverseMask", flags[i])
435 if (opt ~ ",") { 416 if (opt ~ ",") {
436 vname = var_name(flags[i]) 417 vname = var_name(flags[i])
437 macro = "OPTION_"
438 mask = "OPTION_MASK_" 418 mask = "OPTION_MASK_"
439 if (vname == "") { 419 if (vname == "") {
440 vname = "target_flags" 420 vname = "target_flags"
441 macro = "TARGET_"
442 mask = "MASK_" 421 mask = "MASK_"
443 } 422 }
444 print "#define " macro nth_arg(1, opt) \ 423 print "#define TARGET_" nth_arg(1, opt) \
445 " ((" vname " & " mask nth_arg(0, opt) ") == 0)" 424 " ((" vname " & " mask nth_arg(0, opt) ") == 0)"
446 } 425 }
447 } 426 }
448 print "" 427 print ""
449 428
450 for (i = 0; i < n_langs; i++) { 429 for (i = 0; i < n_langs; i++) {
451 macros[i] = "CL_" langs[i] 430 macros[i] = "CL_" lang_sanitized_name(langs[i])
452 gsub( "[^" alnum "_]", "X", macros[i] )
453 s = substr(" ", length (macros[i])) 431 s = substr(" ", length (macros[i]))
454 print "#define " macros[i] s " (1 << " i ")" 432 print "#define " macros[i] s " (1U << " i ")"
455 } 433 }
456 print "#define CL_LANG_ALL ((1 << " n_langs ") - 1)" 434 print "#define CL_LANG_ALL ((1U << " n_langs ") - 1)"
457 435
458 print "" 436 print ""
459 print "enum opt_code" 437 print "enum opt_code"
460 print "{" 438 print "{"
461 439
513 print " OPT_SPECIAL_ignore," 491 print " OPT_SPECIAL_ignore,"
514 print " OPT_SPECIAL_program_name," 492 print " OPT_SPECIAL_program_name,"
515 print " OPT_SPECIAL_input_file" 493 print " OPT_SPECIAL_input_file"
516 print "};" 494 print "};"
517 print "" 495 print ""
496 print "#ifdef GCC_C_COMMON_C"
497 print "/* Mapping from cpp message reasons to the options that enable them. */"
498 print "#include <cpplib.h>"
499 print "struct cpp_reason_option_codes_t"
500 print "{"
501 print " const int reason; /* cpplib message reason. */"
502 print " const int option_code; /* gcc option that controls this message. */"
503 print "};"
504 print ""
505 print "static const struct cpp_reason_option_codes_t cpp_reason_option_codes[] = {"
506 for (i = 0; i < n_opts; i++) {
507 # With identical flags, pick only the last one. The
508 # earlier loop ensured that it has all flags merged,
509 # and a nonempty help text if one of the texts was nonempty.
510 while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
511 i++;
512 }
513 cpp_reason = nth_arg(0, opt_args("CppReason", flags[i]));
514 if (cpp_reason != "") {
515 cpp_reason = cpp_reason ",";
516 printf(" {%-40s %s},\n", cpp_reason, opt_enum(opts[i]))
517 }
518 }
519 printf(" {%-40s 0},\n", "CPP_W_NONE,")
520 print "};"
521 print "#endif"
522 print ""
518 print "#endif /* OPTIONS_H */" 523 print "#endif /* OPTIONS_H */"
519 } 524 }