OSDN Git Service

* opts.h (struct cl_option): Add warn_message field.
[pf3gnuchains/gcc-fork.git] / gcc / opt-functions.awk
1 #  Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
2 #  Free Software Foundation, Inc.
3 #  Contributed by Kelley Cook, June 2004.
4 #  Original code from Neil Booth, May 2003.
5 #
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.
10
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.
15
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/>.
19
20 # Some common subroutines for use by opt[ch]-gen.awk.
21
22 # Return nonzero if FLAGS contains a flag matching REGEX.
23 function flag_set_p(regex, flags)
24 {
25         return (" " flags " ") ~ (" " regex " ")
26 }
27
28 # Return STRING if FLAGS contains a flag matching regexp REGEX,
29 # otherwise return the empty string.
30 function test_flag(regex, flags, string)
31 {
32         if (flag_set_p(regex, flags))
33                 return string
34         return ""
35 }
36
37 # If FLAGS contains a "NAME(...argument...)" flag, return the value
38 # of the argument.  Return the empty string otherwise.
39 function opt_args(name, flags)
40 {
41         flags = " " flags
42         if (flags !~ " " name "\\(")
43                 return ""
44         sub(".* " name "\\(", "", flags)
45         if (flags ~ "^{")
46         {
47                 sub ("^{", "", flags)
48                 sub("}\\).*", "", flags)
49         }
50         else
51                 sub("\\).*", "", flags)
52
53         return flags
54 }
55
56 # Return the Nth comma-separated element of S.  Return the empty string
57 # if S does not contain N elements.
58 function nth_arg(n, s)
59 {
60         while (n-- > 0) {
61                 if (s !~ ",")
62                         return ""
63                 sub("[^,]*, *", "", s)
64         }
65         sub(",.*", "", s)
66         return s
67 }
68
69 # Return a bitmask of CL_* values for option flags FLAGS.
70 function switch_flags (flags)
71 {
72         result = "0"
73         for (j = 0; j < n_langs; j++) {
74                 regex = langs[j]
75                 gsub ( "\\+", "\\+", regex )
76                 result = result test_flag(regex, flags, " | " macros[j])
77         }
78         result = result \
79           test_flag("Common", flags, " | CL_COMMON") \
80           test_flag("Target", flags, " | CL_TARGET") \
81           test_flag("Driver", flags, " | CL_DRIVER") \
82           test_flag("RejectDriver", flags, " | CL_REJECT_DRIVER") \
83           test_flag("NoDriverArg", flags, " | CL_NO_DRIVER_ARG") \
84           test_flag("Save", flags, " | CL_SAVE") \
85           test_flag("Joined", flags, " | CL_JOINED") \
86           test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
87           test_flag("Separate", flags, " | CL_SEPARATE") \
88           test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \
89           test_flag("UInteger", flags, " | CL_UINTEGER") \
90           test_flag("Undocumented", flags,  " | CL_UNDOCUMENTED") \
91           test_flag("Warning", flags,  " | CL_WARNING") \
92           test_flag("Optimization", flags,  " | CL_OPTIMIZATION") \
93           test_flag("Report", flags, " | CL_REPORT")
94         sub( "^0 \\| ", "", result )
95         return result
96 }
97
98 # If FLAGS includes a Var flag, return the name of the variable it specifies.
99 # Return the empty string otherwise.
100 function var_name(flags)
101 {
102         return nth_arg(0, opt_args("Var", flags))
103 }
104
105 # Return true if the option described by FLAGS has a globally-visible state.
106 function global_state_p(flags)
107 {
108         return (var_name(flags) != "" \
109                 || opt_args("Mask", flags) != "" \
110                 || opt_args("InverseMask", flags) != "")
111 }
112
113 # Return true if the option described by FLAGS must have some state
114 # associated with it.
115 function needs_state_p(flags)
116 {
117         return (flag_set_p("Target", flags) \
118                 && !flag_set_p("Alias.*", flags) \
119                 && !flag_set_p("Ignore", flags))
120 }
121
122 # If FLAGS describes an option that needs a static state variable,
123 # return the name of that variable, otherwise return "".  NAME is
124 # the name of the option.
125 function static_var(name, flags)
126 {
127         if (global_state_p(flags) || !needs_state_p(flags))
128                 return ""
129         gsub ("[^A-Za-z0-9]", "_", name)
130         return "VAR_" name
131 }
132
133 # Return the type of variable that should be associated with the given flags.
134 function var_type(flags)
135 {
136         if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags))
137                 return "int "
138         else if (flag_set_p("UInteger", flags))
139                 return "int "
140         else
141                 return "const char *"
142 }
143
144 # Return the type of variable that should be associated with the given flags
145 # for use within a structure.  Simple variables are changed to signed char
146 # type instead of int to save space.
147 function var_type_struct(flags)
148 {
149         if (flag_set_p("UInteger", flags))
150                 return "int "
151         else if (!flag_set_p("Joined.*", flags) && !flag_set_p("Separate", flags)) {
152                 if (flag_set_p(".*Mask.*", flags))
153                         return "int "
154                 else
155                         return "signed char "
156         }
157         else
158                 return "const char *"
159 }
160
161 # Given that an option has flags FLAGS, return an initializer for the
162 # "var_cond" and "var_value" fields of its cl_options[] entry.
163 function var_set(flags)
164 {
165         s = nth_arg(1, opt_args("Var", flags))
166         if (s != "")
167                 return "CLVC_EQUAL, " s
168         s = opt_args("Mask", flags);
169         if (s != "") {
170                 vn = var_name(flags);
171                 if (vn)
172                         return "CLVC_BIT_SET, OPTION_MASK_" s
173                 else
174                         return "CLVC_BIT_SET, MASK_" s
175         }
176         s = nth_arg(0, opt_args("InverseMask", flags));
177         if (s != "") {
178                 vn = var_name(flags);
179                 if (vn)
180                         return "CLVC_BIT_CLEAR, OPTION_MASK_" s
181                 else
182                         return "CLVC_BIT_CLEAR, MASK_" s
183         }
184         if (var_type(flags) == "const char *")
185                 return "CLVC_STRING, 0"
186         return "CLVC_BOOLEAN, 0"
187 }
188
189 # Given that an option called NAME has flags FLAGS, return an initializer
190 # for the "flag_var" field of its cl_options[] entry.
191 function var_ref(name, flags)
192 {
193         name = var_name(flags) static_var(name, flags)
194         if (name != "")
195                 return "&" name
196         if (opt_args("Mask", flags) != "")
197                 return "&target_flags"
198         if (opt_args("InverseMask", flags) != "")
199                 return "&target_flags"
200         return "0"
201 }
202
203 # Given the option called NAME return a sanitized version of its name.
204 function opt_sanitized_name(name)
205 {
206         if (name == "gdwarf+")
207                 name = "gdwarfplus"
208         gsub ("[^A-Za-z0-9]", "_", name)
209         return name
210 }
211
212 # Given the option called NAME return the appropriate enum for it.
213 function opt_enum(name)
214 {
215         return "OPT_" opt_sanitized_name(name)
216 }