llvm.org GIT mirror llvm / 087d6a5
ADT/Triple: Generalize and simplify getDarwinNumber to just be getOSVersion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129799 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 9 years ago
2 changed file(s) with 51 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
223223 /// if the environment component is present).
224224 StringRef getOSAndEnvironmentName() const;
225225
226
227 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
228 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
229 /// not defined, return 0's. This requires that the triple have an OSType of
230 /// darwin before it is called.
231 void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
232
233 /// getDarwinMajorNumber - Return just the major version number, this is
226 /// getOSNumber - Parse the version number from the OS name component of the
227 /// triple, if present.
228 ///
229 /// For example, "fooos1.2.3" would return (1, 2, 3).
230 ///
231 /// If an entry is not defined, it will be returned as 0.
232 void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
233
234 /// getOSMajorVersion - Return just the major version number, this is
234235 /// specialized because it is a common query.
236 unsigned getOSMajorVersion() const {
237 unsigned Maj, Min, Micro;
238 getDarwinNumber(Maj, Min, Micro);
239 return Maj;
240 }
241
242 void getDarwinNumber(unsigned &Major, unsigned &Minor,
243 unsigned &Micro) const {
244 return getOSVersion(Major, Minor, Micro);
245 }
246
235247 unsigned getDarwinMajorNumber() const {
236 unsigned Maj, Min, Rev;
237 getDarwinNumber(Maj, Min, Rev);
238 return Maj;
248 return getOSMajorVersion();
239249 }
240250
241251 /// @}
531531
532532 static unsigned EatNumber(StringRef &Str) {
533533 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
534 unsigned Result = Str[0]-'0';
535
536 // Eat the digit.
537 Str = Str.substr(1);
538
539 // Handle "darwin11".
540 if (Result == 1 && !Str.empty() && Str[0] >= '0' && Str[0] <= '9') {
534 unsigned Result = 0;
535
536 do {
537 // Consume the leading digit.
541538 Result = Result*10 + (Str[0] - '0');
539
542540 // Eat the digit.
543541 Str = Str.substr(1);
544 }
542 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
545543
546544 return Result;
547545 }
548546
549 /// getDarwinNumber - Parse the 'darwin number' out of the specific target
550 /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
551 /// not defined, return 0's. This requires that the triple have an OSType of
552 /// darwin before it is called.
553 void Triple::getDarwinNumber(unsigned &Maj, unsigned &Min,
554 unsigned &Revision) const {
555 assert(getOS() == Darwin && "Not a darwin target triple!");
547 void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
548 unsigned &Micro) const {
556549 StringRef OSName = getOSName();
557 assert(OSName.startswith("darwin") && "Unknown darwin target triple!");
558
559 // Strip off "darwin".
560 OSName = OSName.substr(6);
561
562 Maj = Min = Revision = 0;
563
564 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
565 return;
566
567 // The major version is the first digit.
568 Maj = EatNumber(OSName);
569 if (OSName.empty()) return;
570
571 // Handle minor version: 10.4.9 -> darwin8.9.
572 if (OSName[0] != '.')
573 return;
574
575 // Eat the '.'.
576 OSName = OSName.substr(1);
577
578 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
579 return;
580
581 Min = EatNumber(OSName);
582 if (OSName.empty()) return;
583
584 // Handle revision darwin8.9.1
585 if (OSName[0] != '.')
586 return;
587
588 // Eat the '.'.
589 OSName = OSName.substr(1);
590
591 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
592 return;
593
594 Revision = EatNumber(OSName);
550
551 // Assume that the OS portion of the triple starts with the canonical name.
552 StringRef OSTypeName = getOSTypeName(getOS());
553 if (OSName.startswith(OSTypeName))
554 OSName = OSName.substr(OSTypeName.size());
555
556 // Any unset version defaults to 0.
557 Major = Minor = Micro = 0;
558
559 // Parse up to three components.
560 unsigned *Components[3] = { &Major, &Minor, &Micro };
561 for (unsigned i = 0; i != 3; ++i) {
562 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
563 break;
564
565 // Consume the leading number.
566 *Components[i] = EatNumber(OSName);
567
568 // Consume the separator, if present.
569 if (OSName.startswith("."))
570 OSName = OSName.substr(1);
571 }
595572 }
596573
597574 void Triple::setTriple(const Twine &Str) {