llvm.org GIT mirror llvm / dfc17f7
add a couple of helpers to the Triple class for decoding the darwin version string. This should help consolidate the variety of weird functions we have scattered around the codebase that do stuff like this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78792 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 80 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
157157 /// if the environment component is present).
158158 StringRef getOSAndEnvironmentName() const;
159159
160
161 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
162 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
163 /// not defined, return 0's. This requires that the triple have an OSType of
164 /// darwin before it is called.
165 void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
166
167 /// getDarwinMajorNumber - Return just the major version number, this is
168 /// specialized because it is a common query.
169 unsigned getDarwinMajorNumber() const {
170 unsigned Maj, Min, Rev;
171 getDarwinNumber(Maj, Min, Rev);
172 return Maj;
173 }
174
160175 /// @}
161176 /// @name Mutators
162177 /// @{
208208 return Tmp.split('-').second; // Strip second component
209209 }
210210
211 static unsigned EatNumber(StringRef &Str) {
212 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
213 unsigned Result = Str[0]-'0';
214
215 // Eat the digit.
216 Str = Str.substr(1);
217
218 // Handle "darwin11".
219 if (Result == 1 && !Str.empty() && Str[0] >= '0' && Str[0] <= '9') {
220 Result = Result*10 + (Str[0] - '0');
221 // Eat the digit.
222 Str = Str.substr(1);
223 }
224
225 return Result;
226 }
227
228 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
229 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
230 /// not defined, return 0's. This requires that the triple have an OSType of
231 /// darwin before it is called.
232 void Triple::getDarwinNumber(unsigned &Maj, unsigned &Min,
233 unsigned &Revision) const {
234 assert(getOS() == Darwin && "Not a darwin target triple!");
235 StringRef OSName = getOSName();
236 assert(OSName.startswith("darwin") && "Unknown darwin target triple!");
237
238 // Strip off "darwin".
239 OSName = OSName.substr(6);
240
241 Maj = Min = Revision = 0;
242
243 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
244 return;
245
246 // The major version is the first digit.
247 Maj = EatNumber(OSName);
248 if (OSName.empty()) return;
249
250 // Handle minor version: 10.4.9 -> darwin8.9.
251 if (OSName[0] != '.')
252 return;
253
254 // Eat the '.'.
255 OSName = OSName.substr(1);
256
257 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
258 return;
259
260 Min = EatNumber(OSName);
261 if (OSName.empty()) return;
262
263 // Handle revision darwin8.9.1
264 if (OSName[0] != '.')
265 return;
266
267 // Eat the '.'.
268 OSName = OSName.substr(1);
269
270 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
271 return;
272
273 Revision = EatNumber(OSName);
274 }
275
211276 void Triple::setTriple(const Twine &Str) {
212277 Data = Str.str();
213278 Arch = InvalidArch;