Mercurial > hg > CbC > CbC_gcc
annotate gcc/opt-functions.awk @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
rev | line source |
---|---|
0 | 1 # Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. |
2 # Contributed by Kelley Cook, June 2004. | |
3 # Original code from Neil Booth, May 2003. | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify it | |
6 # under the terms of the GNU General Public License as published by the | |
7 # Free Software Foundation; either version 3, or (at your option) any | |
8 # later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; see the file COPYING3. If not see | |
17 # <http://www.gnu.org/licenses/>. | |
18 | |
19 # Some common subroutines for use by opt[ch]-gen.awk. | |
20 | |
21 # Return nonzero if FLAGS contains a flag matching REGEX. | |
22 function flag_set_p(regex, flags) | |
23 { | |
24 return (" " flags " ") ~ (" " regex " ") | |
25 } | |
26 | |
27 # Return STRING if FLAGS contains a flag matching regexp REGEX, | |
28 # otherwise return the empty string. | |
29 function test_flag(regex, flags, string) | |
30 { | |
31 if (flag_set_p(regex, flags)) | |
32 return string | |
33 return "" | |
34 } | |
35 | |
36 # If FLAGS contains a "NAME(...argument...)" flag, return the value | |
37 # of the argument. Return the empty string otherwise. | |
38 function opt_args(name, flags) | |
39 { | |
40 flags = " " flags | |
41 if (flags !~ " " name "\\(") | |
42 return "" | |
43 sub(".* " name "\\(", "", flags) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
44 if (flags ~ "^{") |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
45 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
46 sub ("^{", "", flags) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
47 sub("}\\).*", "", flags) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
48 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
49 else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
50 sub("\\).*", "", flags) |
0 | 51 |
52 return flags | |
53 } | |
54 | |
55 # Return the Nth comma-separated element of S. Return the empty string | |
56 # if S does not contain N elements. | |
57 function nth_arg(n, s) | |
58 { | |
59 while (n-- > 0) { | |
60 if (s !~ ",") | |
61 return "" | |
62 sub("[^,]*, *", "", s) | |
63 } | |
64 sub(",.*", "", s) | |
65 return s | |
66 } | |
67 | |
68 # Return a bitmask of CL_* values for option flags FLAGS. | |
69 function switch_flags (flags) | |
70 { | |
71 result = "0" | |
72 for (j = 0; j < n_langs; j++) { | |
73 regex = langs[j] | |
74 gsub ( "\\+", "\\+", regex ) | |
75 result = result test_flag(regex, flags, " | " macros[j]) | |
76 } | |
77 result = result \ | |
78 test_flag("Common", flags, " | CL_COMMON") \ | |
79 test_flag("Target", flags, " | CL_TARGET") \ | |
80 test_flag("Save", flags, " | CL_SAVE") \ | |
81 test_flag("Joined", flags, " | CL_JOINED") \ | |
82 test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \ | |
83 test_flag("Separate", flags, " | CL_SEPARATE") \ | |
84 test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \ | |
85 test_flag("UInteger", flags, " | CL_UINTEGER") \ | |
86 test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \ | |
87 test_flag("Warning", flags, " | CL_WARNING") \ | |
88 test_flag("Optimization", flags, " | CL_OPTIMIZATION") \ | |
89 test_flag("Report", flags, " | CL_REPORT") | |
90 sub( "^0 \\| ", "", result ) | |
91 return result | |
92 } | |
93 | |
94 # If FLAGS includes a Var flag, return the name of the variable it specifies. | |
95 # Return the empty string otherwise. | |
96 function var_name(flags) | |
97 { | |
98 return nth_arg(0, opt_args("Var", flags)) | |
99 } | |
100 | |
101 # Return true if the option described by FLAGS has a globally-visible state. | |
102 function global_state_p(flags) | |
103 { | |
104 return (var_name(flags) != "" \ | |
105 || opt_args("Mask", flags) != "" \ | |
106 || opt_args("InverseMask", flags) != "") | |
107 } | |
108 | |
109 # Return true if the option described by FLAGS must have some state | |
110 # associated with it. | |
111 function needs_state_p(flags) | |
112 { | |
113 return flag_set_p("Target", flags) | |
114 } | |
115 | |
116 # If FLAGS describes an option that needs a static state variable, | |
117 # return the name of that variable, otherwise return "". NAME is | |
118 # the name of the option. | |
119 function static_var(name, flags) | |
120 { | |
121 if (global_state_p(flags) || !needs_state_p(flags)) | |
122 return "" | |
123 gsub ("[^A-Za-z0-9]", "_", name) | |
124 return "VAR_" name | |
125 } | |
126 | |
127 # Return the type of variable that should be associated with the given flags. | |
128 function var_type(flags) | |
129 { | |
130 if (!flag_set_p("Joined.*", flags)) | |
131 return "int " | |
132 else if (flag_set_p("UInteger", flags)) | |
133 return "int " | |
134 else | |
135 return "const char *" | |
136 } | |
137 | |
138 # Return the type of variable that should be associated with the given flags | |
139 # for use within a structure. Simple variables are changed to unsigned char | |
140 # type instead of int to save space. | |
141 function var_type_struct(flags) | |
142 { | |
143 if (flag_set_p("UInteger", flags)) | |
144 return "int " | |
145 else if (!flag_set_p("Joined.*", flags)) { | |
146 if (flag_set_p(".*Mask.*", flags)) | |
147 return "int " | |
148 else | |
149 return "unsigned char " | |
150 } | |
151 else | |
152 return "const char *" | |
153 } | |
154 | |
155 # Given that an option has flags FLAGS, return an initializer for the | |
156 # "var_cond" and "var_value" fields of its cl_options[] entry. | |
157 function var_set(flags) | |
158 { | |
159 s = nth_arg(1, opt_args("Var", flags)) | |
160 if (s != "") | |
161 return "CLVC_EQUAL, " s | |
162 s = opt_args("Mask", flags); | |
163 if (s != "") { | |
164 vn = var_name(flags); | |
165 if (vn) | |
166 return "CLVC_BIT_SET, OPTION_MASK_" s | |
167 else | |
168 return "CLVC_BIT_SET, MASK_" s | |
169 } | |
170 s = nth_arg(0, opt_args("InverseMask", flags)); | |
171 if (s != "") { | |
172 vn = var_name(flags); | |
173 if (vn) | |
174 return "CLVC_BIT_CLEAR, OPTION_MASK_" s | |
175 else | |
176 return "CLVC_BIT_CLEAR, MASK_" s | |
177 } | |
178 if (var_type(flags) == "const char *") | |
179 return "CLVC_STRING, 0" | |
180 return "CLVC_BOOLEAN, 0" | |
181 } | |
182 | |
183 # Given that an option called NAME has flags FLAGS, return an initializer | |
184 # for the "flag_var" field of its cl_options[] entry. | |
185 function var_ref(name, flags) | |
186 { | |
187 name = var_name(flags) static_var(name, flags) | |
188 if (name != "") | |
189 return "&" name | |
190 if (opt_args("Mask", flags) != "") | |
191 return "&target_flags" | |
192 if (opt_args("InverseMask", flags) != "") | |
193 return "&target_flags" | |
194 return "0" | |
195 } |