Mercurial > hg > CbC > CbC_gcc
comparison gcc/opt-functions.awk @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 # Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010 | 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 |
28 } | 27 } |
29 | 28 |
30 # Return nonzero if FLAGS contains a flag matching REGEX. | 29 # Return nonzero if FLAGS contains a flag matching REGEX. |
31 function flag_set_p(regex, flags) | 30 function flag_set_p(regex, flags) |
32 { | 31 { |
33 return (" " flags " ") ~ (" " regex " ") | 32 # Ignore the arguments of flags with arguments. |
33 gsub ("\\([^)]+\\)", "", flags); | |
34 return (" " flags " ") ~ (" " regex " ") | |
34 } | 35 } |
35 | 36 |
36 # Return STRING if FLAGS contains a flag matching regexp REGEX, | 37 # Return STRING if FLAGS contains a flag matching regexp REGEX, |
37 # otherwise return the empty string. | 38 # otherwise return the empty string. |
38 function test_flag(regex, flags, string) | 39 function test_flag(regex, flags, string) |
39 { | 40 { |
40 if (flag_set_p(regex, flags)) | 41 if (flag_set_p(regex, flags)) |
41 return string | 42 return string |
42 return "" | 43 return "" |
44 } | |
45 | |
46 # Return a field initializer, with trailing comma, for a field that is | |
47 # 1 if FLAGS contains a flag matching REGEX and 0 otherwise. | |
48 function flag_init(regex, flags) | |
49 { | |
50 if (flag_set_p(regex, flags)) | |
51 return "1 /* " regex " */, " | |
52 else | |
53 return "0, " | |
43 } | 54 } |
44 | 55 |
45 # If FLAGS contains a "NAME(...argument...)" flag, return the value | 56 # If FLAGS contains a "NAME(...argument...)" flag, return the value |
46 # of the argument. Return the empty string otherwise. | 57 # of the argument. Return the empty string otherwise. |
47 function opt_args(name, flags) | 58 function opt_args(name, flags) |
48 { | 59 { |
49 flags = " " flags | 60 flags = " " flags |
50 if (flags !~ " " name "\\(") | 61 if (flags !~ " " name "\\(") |
51 return "" | 62 return "" |
52 sub(".* " name "\\(", "", flags) | 63 sub(".* " name "\\(", "", flags) |
53 if (flags ~ "^{") | 64 if (flags ~ "^[{]") |
54 { | 65 { |
55 sub ("^{", "", flags) | 66 sub ("^[{]", "", flags) |
56 sub("}\\).*", "", flags) | 67 sub ("}\\).*", "", flags) |
57 } | 68 } |
58 else | 69 else |
59 sub("\\).*", "", flags) | 70 sub("\\).*", "", flags) |
60 | 71 |
61 return flags | 72 return flags |
84 result = result test_flag(regex, flags, " | " macros[j]) | 95 result = result test_flag(regex, flags, " | " macros[j]) |
85 } | 96 } |
86 result = result \ | 97 result = result \ |
87 test_flag("Common", flags, " | CL_COMMON") \ | 98 test_flag("Common", flags, " | CL_COMMON") \ |
88 test_flag("Target", flags, " | CL_TARGET") \ | 99 test_flag("Target", flags, " | CL_TARGET") \ |
100 test_flag("PchIgnore", flags, " | CL_PCH_IGNORE") \ | |
89 test_flag("Driver", flags, " | CL_DRIVER") \ | 101 test_flag("Driver", flags, " | CL_DRIVER") \ |
90 test_flag("RejectDriver", flags, " | CL_REJECT_DRIVER") \ | |
91 test_flag("NoDriverArg", flags, " | CL_NO_DRIVER_ARG") \ | |
92 test_flag("SeparateAlias", flags, " | CL_SEPARATE_ALIAS") \ | |
93 test_flag("Save", flags, " | CL_SAVE") \ | |
94 test_flag("Joined", flags, " | CL_JOINED") \ | 102 test_flag("Joined", flags, " | CL_JOINED") \ |
95 test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \ | 103 test_flag("JoinedOrMissing", flags, " | CL_JOINED") \ |
96 test_flag("Separate", flags, " | CL_SEPARATE") \ | 104 test_flag("Separate", flags, " | CL_SEPARATE") \ |
97 test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \ | |
98 test_flag("UInteger", flags, " | CL_UINTEGER") \ | |
99 test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \ | 105 test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \ |
106 test_flag("NoDWARFRecord", flags, " | CL_NO_DWARF_RECORD") \ | |
100 test_flag("Warning", flags, " | CL_WARNING") \ | 107 test_flag("Warning", flags, " | CL_WARNING") \ |
101 test_flag("Optimization", flags, " | CL_OPTIMIZATION") \ | 108 test_flag("(Optimization|PerFunction)", flags, " | CL_OPTIMIZATION") |
102 test_flag("Report", flags, " | CL_REPORT") | 109 sub( "^0 \\| ", "", result ) |
110 return result | |
111 } | |
112 | |
113 # Return bit-field initializers for option flags FLAGS. | |
114 function switch_bit_fields (flags) | |
115 { | |
116 vn = var_name(flags); | |
117 if (host_wide_int[vn] == "yes") | |
118 hwi = "Host_Wide_Int" | |
119 else | |
120 hwi = "" | |
121 result = "" | |
103 sep_args = opt_args("Args", flags) | 122 sep_args = opt_args("Args", flags) |
104 if (sep_args != "") { | 123 if (sep_args == "") |
124 sep_args = 0 | |
125 else | |
105 sep_args-- | 126 sep_args-- |
106 result = result " | (" sep_args \ | 127 result = result sep_args ", " |
107 " << CL_SEPARATE_NARGS_SHIFT)" | 128 |
108 } | 129 result = result \ |
109 sub( "^0 \\| ", "", result ) | 130 flag_init("SeparateAlias", flags) \ |
131 flag_init("NegativeAlias", flags) \ | |
132 flag_init("NoDriverArg", flags) \ | |
133 flag_init("RejectDriver", flags) \ | |
134 flag_init("RejectNegative", flags) \ | |
135 flag_init("JoinedOrMissing", flags) \ | |
136 flag_init("UInteger", flags) \ | |
137 flag_init("Host_Wide_Int", hwi) \ | |
138 flag_init("ToLower", flags) \ | |
139 flag_init("Report", flags) | |
140 | |
141 sub(", $", "", result) | |
110 return result | 142 return result |
111 } | 143 } |
112 | 144 |
113 # If FLAGS includes a Var flag, return the name of the variable it specifies. | 145 # If FLAGS includes a Var flag, return the name of the variable it specifies. |
114 # Return the empty string otherwise. | 146 # Return the empty string otherwise. |
115 function var_name(flags) | 147 function var_name(flags) |
116 { | 148 { |
117 return nth_arg(0, opt_args("Var", flags)) | 149 return nth_arg(0, opt_args("Var", flags)) |
150 } | |
151 | |
152 # Return the name of the variable if FLAGS has a HOST_WIDE_INT variable. | |
153 # Return the empty string otherwise. | |
154 function host_wide_int_var_name(flags) | |
155 { | |
156 split (flags, array, "[ \t]+") | |
157 if (array[1] == "HOST_WIDE_INT") | |
158 return array[2] | |
159 else | |
160 return "" | |
118 } | 161 } |
119 | 162 |
120 # Return true if the option described by FLAGS has a globally-visible state. | 163 # Return true if the option described by FLAGS has a globally-visible state. |
121 function global_state_p(flags) | 164 function global_state_p(flags) |
122 { | 165 { |
167 # type instead of int to save space. | 210 # type instead of int to save space. |
168 function var_type_struct(flags) | 211 function var_type_struct(flags) |
169 { | 212 { |
170 if (flag_set_p("UInteger", flags)) | 213 if (flag_set_p("UInteger", flags)) |
171 return "int " | 214 return "int " |
215 else if (flag_set_p("Enum.*", flags)) { | |
216 en = opt_args("Enum", flags); | |
217 return enum_type[en] " " | |
218 } | |
172 else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) { | 219 else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) { |
173 if (flag_set_p(".*Mask.*", flags)) | 220 if (flag_set_p(".*Mask.*", flags)) { |
174 return "int " | 221 if (host_wide_int[var_name(flags)] == "yes") |
222 return "HOST_WIDE_INT " | |
223 else | |
224 return "int " | |
225 } | |
175 else | 226 else |
176 return "signed char " | 227 return "signed char " |
177 } | 228 } |
178 else | 229 else |
179 return "const char *" | 230 return "const char *" |
222 return "offsetof (struct gcc_options, x_" name ")" | 273 return "offsetof (struct gcc_options, x_" name ")" |
223 if (opt_args("Mask", flags) != "") | 274 if (opt_args("Mask", flags) != "") |
224 return "offsetof (struct gcc_options, x_target_flags)" | 275 return "offsetof (struct gcc_options, x_target_flags)" |
225 if (opt_args("InverseMask", flags) != "") | 276 if (opt_args("InverseMask", flags) != "") |
226 return "offsetof (struct gcc_options, x_target_flags)" | 277 return "offsetof (struct gcc_options, x_target_flags)" |
227 return "-1" | 278 return "(unsigned short) -1" |
228 } | 279 } |
229 | 280 |
230 # Given the option called NAME return a sanitized version of its name. | 281 # Given the option called NAME return a sanitized version of its name. |
231 function opt_sanitized_name(name) | 282 function opt_sanitized_name(name) |
232 { | 283 { |
237 # Given the option called NAME return the appropriate enum for it. | 288 # Given the option called NAME return the appropriate enum for it. |
238 function opt_enum(name) | 289 function opt_enum(name) |
239 { | 290 { |
240 return "OPT_" opt_sanitized_name(name) | 291 return "OPT_" opt_sanitized_name(name) |
241 } | 292 } |
293 | |
294 # Given the language called NAME return a sanitized version of its name. | |
295 function lang_sanitized_name(name) | |
296 { | |
297 gsub( "[^" alnum "_]", "X", name ) | |
298 return name | |
299 } | |
300 | |
301 # Search for a valid var_name among all OPTS equal to option NAME. | |
302 # If not found, return "". | |
303 function search_var_name(name, opt_numbers, opts, flags, n_opts) | |
304 { | |
305 opt_var_name = var_name(flags[opt_numbers[name]]); | |
306 if (opt_var_name != "") { | |
307 return opt_var_name; | |
308 } | |
309 for (k = 0; k < n_opts; k++) { | |
310 if (opts[k] == name && var_name(flags[k]) != "") { | |
311 return var_name(flags[k]); | |
312 } | |
313 } | |
314 return "" | |
315 } | |
316 | |
317 function integer_range_info(range_option, init, option) | |
318 { | |
319 if (range_option != "") { | |
320 start = nth_arg(0, range_option); | |
321 end = nth_arg(1, range_option); | |
322 if (init != "" && init != "-1" && (init < start || init > end)) | |
323 print "#error initial value " init " of '" option "' must be in range [" start "," end "]" | |
324 return start ", " end | |
325 } | |
326 else | |
327 return "-1, -1" | |
328 } | |
329 | |
330 # Handle LangEnabledBy(ENABLED_BY_LANGS, ENABLEDBY_NAME, ENABLEDBY_POSARG, | |
331 # ENABLEDBY_NEGARG). This function does not return anything. | |
332 function lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg) | |
333 { | |
334 n_enabledby_arg_langs = split(enabledby_langs, enabledby_arg_langs, " "); | |
335 if (enabledby_posarg != "" && enabledby_negarg != "") { | |
336 with_args = "," enabledby_posarg "," enabledby_negarg | |
337 } else if (enabledby_posarg == "" && enabledby_negarg == "") { | |
338 with_args = "" | |
339 } else { | |
340 print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \ | |
341 enabledby_posarg", " enabledby_negargs \ | |
342 ") with three arguments, it should have either 2 or 4" | |
343 } | |
344 | |
345 n_enabledby_array = split(enabledby_name, enabledby_array, " \\|\\| "); | |
346 for (k = 1; k <= n_enabledby_array; k++) { | |
347 enabledby_index = opt_numbers[enabledby_array[k]]; | |
348 if (enabledby_index == "") { | |
349 print "#error " opts[i] " LangEnabledBy("enabledby_langs","enabledby_name", " \ | |
350 enabledby_posarg", " enabledby_negargs"), unknown option '" enabledby_name "'" | |
351 } else { | |
352 for (j = 1; j <= n_enabledby_arg_langs; j++) { | |
353 lang_name = lang_sanitized_name(enabledby_arg_langs[j]); | |
354 lang_index = lang_numbers[enabledby_arg_langs[j]]; | |
355 if (enables[lang_name,enabledby_array[k]] == "") { | |
356 enabledby[lang_name,n_enabledby_lang[lang_index]] = enabledby_array[k]; | |
357 n_enabledby_lang[lang_index]++; | |
358 } | |
359 enables[lang_name,enabledby_array[k]] \ | |
360 = enables[lang_name,enabledby_array[k]] opts[i] with_args ";"; | |
361 } | |
362 } | |
363 } | |
364 } |