dwarf2out.c (mem_loc_descriptor): Recurse on LO_SUM.
[official-gcc.git] / gcc / opt-functions.awk
blob19bdf3afb06873cced64cae7b1089e1cc6741ae9
1 # Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
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
9 # later version.
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 # Some common subroutines for use by opt[ch]-gen.awk.
22 # Define some helpful character classes, for portability.
23 BEGIN {
24 lower = "abcdefghijklmnopqrstuvwxyz"
25 upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
26 digit = "0123456789"
27 alnum = lower "" upper "" digit
30 # Return nonzero if FLAGS contains a flag matching REGEX.
31 function flag_set_p(regex, flags)
33 return (" " flags " ") ~ (" " regex " ")
36 # Return STRING if FLAGS contains a flag matching regexp REGEX,
37 # otherwise return the empty string.
38 function test_flag(regex, flags, string)
40 if (flag_set_p(regex, flags))
41 return string
42 return ""
45 # Return a field initializer, with trailing comma, for a field that is
46 # 1 if FLAGS contains a flag matching REGEX and 0 otherwise.
47 function flag_init(regex, flags)
49 if (flag_set_p(regex, flags))
50 return "1 /* " regex " */, "
51 else
52 return "0, "
55 # If FLAGS contains a "NAME(...argument...)" flag, return the value
56 # of the argument. Return the empty string otherwise.
57 function opt_args(name, flags)
59 flags = " " flags
60 if (flags !~ " " name "\\(")
61 return ""
62 sub(".* " name "\\(", "", flags)
63 if (flags ~ "^{")
65 sub ("^{", "", flags)
66 sub("}\\).*", "", flags)
68 else
69 sub("\\).*", "", flags)
71 return flags
74 # Return the Nth comma-separated element of S. Return the empty string
75 # if S does not contain N elements.
76 function nth_arg(n, s)
78 while (n-- > 0) {
79 if (s !~ ",")
80 return ""
81 sub("[^,]*, *", "", s)
83 sub(",.*", "", s)
84 return s
87 # Return a bitmask of CL_* values for option flags FLAGS.
88 function switch_flags (flags)
90 result = "0"
91 for (j = 0; j < n_langs; j++) {
92 regex = langs[j]
93 gsub ( "\\+", "\\+", regex )
94 result = result test_flag(regex, flags, " | " macros[j])
96 result = result \
97 test_flag("Common", flags, " | CL_COMMON") \
98 test_flag("Target", flags, " | CL_TARGET") \
99 test_flag("Driver", flags, " | CL_DRIVER") \
100 test_flag("Joined", flags, " | CL_JOINED") \
101 test_flag("JoinedOrMissing", flags, " | CL_JOINED") \
102 test_flag("Separate", flags, " | CL_SEPARATE") \
103 test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \
104 test_flag("Warning", flags, " | CL_WARNING") \
105 test_flag("Optimization", flags, " | CL_OPTIMIZATION")
106 sub( "^0 \\| ", "", result )
107 return result
110 # Return bit-field initializers for option flags FLAGS.
111 function switch_bit_fields (flags)
113 result = ""
114 sep_args = opt_args("Args", flags)
115 if (sep_args == "")
116 sep_args = 0
117 else
118 sep_args--
119 result = result sep_args ", "
121 result = result \
122 flag_init("SeparateAlias", flags) \
123 flag_init("NegativeAlias", flags) \
124 flag_init("NoDriverArg", flags) \
125 flag_init("RejectDriver", flags) \
126 flag_init("RejectNegative", flags) \
127 flag_init("JoinedOrMissing", flags) \
128 flag_init("UInteger", flags) \
129 flag_init("Report", flags)
131 sub(", $", "", result)
132 return result
135 # If FLAGS includes a Var flag, return the name of the variable it specifies.
136 # Return the empty string otherwise.
137 function var_name(flags)
139 return nth_arg(0, opt_args("Var", flags))
142 # Return true if the option described by FLAGS has a globally-visible state.
143 function global_state_p(flags)
145 return (var_name(flags) != "" \
146 || opt_args("Mask", flags) != "" \
147 || opt_args("InverseMask", flags) != "")
150 # Return true if the option described by FLAGS must have some state
151 # associated with it.
152 function needs_state_p(flags)
154 return (flag_set_p("Target", flags) \
155 && !flag_set_p("Alias.*", flags) \
156 && !flag_set_p("Ignore", flags))
159 # If FLAGS describes an option that needs state without a public
160 # variable name, return the name of that field, minus the initial
161 # "x_", otherwise return "". NAME is the name of the option.
162 function static_var(name, flags)
164 if (global_state_p(flags) || !needs_state_p(flags))
165 return ""
166 gsub ("[^" alnum "]", "_", name)
167 return "VAR_" name
170 # Return the type of variable that should be associated with the given flags.
171 function var_type(flags)
173 if (flag_set_p("Defer", flags))
174 return "void *"
175 else if (flag_set_p("Enum.*", flags)) {
176 en = opt_args("Enum", flags);
177 return enum_type[en] " "
179 else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags))
180 return "int "
181 else if (flag_set_p("UInteger", flags))
182 return "int "
183 else
184 return "const char *"
187 # Return the type of variable that should be associated with the given flags
188 # for use within a structure. Simple variables are changed to signed char
189 # type instead of int to save space.
190 function var_type_struct(flags)
192 if (flag_set_p("UInteger", flags))
193 return "int "
194 else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) {
195 if (flag_set_p(".*Mask.*", flags))
196 return "int "
197 else
198 return "signed char "
200 else
201 return "const char *"
204 # Given that an option has flags FLAGS, return an initializer for the
205 # "var_enum", "var_type" and "var_value" fields of its cl_options[] entry.
206 function var_set(flags)
208 if (flag_set_p("Defer", flags))
209 return "0, CLVC_DEFER, 0"
210 s = nth_arg(1, opt_args("Var", flags))
211 if (s != "")
212 return "0, CLVC_EQUAL, " s
213 s = opt_args("Mask", flags);
214 if (s != "") {
215 vn = var_name(flags);
216 if (vn)
217 return "0, CLVC_BIT_SET, OPTION_MASK_" s
218 else
219 return "0, CLVC_BIT_SET, MASK_" s
221 s = nth_arg(0, opt_args("InverseMask", flags));
222 if (s != "") {
223 vn = var_name(flags);
224 if (vn)
225 return "0, CLVC_BIT_CLEAR, OPTION_MASK_" s
226 else
227 return "0, CLVC_BIT_CLEAR, MASK_" s
229 if (flag_set_p("Enum.*", flags)) {
230 en = opt_args("Enum", flags);
231 return enum_index[en] ", CLVC_ENUM, 0"
233 if (var_type(flags) == "const char *")
234 return "0, CLVC_STRING, 0"
235 return "0, CLVC_BOOLEAN, 0"
238 # Given that an option called NAME has flags FLAGS, return an initializer
239 # for the "flag_var" field of its cl_options[] entry.
240 function var_ref(name, flags)
242 name = var_name(flags) static_var(name, flags)
243 if (name != "")
244 return "offsetof (struct gcc_options, x_" name ")"
245 if (opt_args("Mask", flags) != "")
246 return "offsetof (struct gcc_options, x_target_flags)"
247 if (opt_args("InverseMask", flags) != "")
248 return "offsetof (struct gcc_options, x_target_flags)"
249 return "-1"
252 # Given the option called NAME return a sanitized version of its name.
253 function opt_sanitized_name(name)
255 gsub ("[^" alnum "]", "_", name)
256 return name
259 # Given the option called NAME return the appropriate enum for it.
260 function opt_enum(name)
262 return "OPT_" opt_sanitized_name(name)