mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
ADT/Triple: Generalize and simplify getDarwinNumber to just be getOSVersion.
llvm-svn: 129799
This commit is contained in:
parent
ce4e39d010
commit
e24d3d1bc5
@ -224,21 +224,31 @@ public:
|
|||||||
/// if the environment component is present).
|
/// if the environment component is present).
|
||||||
StringRef getOSAndEnvironmentName() const;
|
StringRef getOSAndEnvironmentName() const;
|
||||||
|
|
||||||
|
/// getOSNumber - Parse the version number from the OS name component of the
|
||||||
|
/// triple, if present.
|
||||||
|
///
|
||||||
|
/// For example, "fooos1.2.3" would return (1, 2, 3).
|
||||||
|
///
|
||||||
|
/// If an entry is not defined, it will be returned as 0.
|
||||||
|
void getOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const;
|
||||||
|
|
||||||
/// getDarwinNumber - Parse the 'darwin number' out of the specific target
|
/// getOSMajorVersion - Return just the major version number, this is
|
||||||
/// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
|
|
||||||
/// not defined, return 0's. This requires that the triple have an OSType of
|
|
||||||
/// darwin before it is called.
|
|
||||||
void getDarwinNumber(unsigned &Maj, unsigned &Min, unsigned &Revision) const;
|
|
||||||
|
|
||||||
/// getDarwinMajorNumber - Return just the major version number, this is
|
|
||||||
/// specialized because it is a common query.
|
/// specialized because it is a common query.
|
||||||
unsigned getDarwinMajorNumber() const {
|
unsigned getOSMajorVersion() const {
|
||||||
unsigned Maj, Min, Rev;
|
unsigned Maj, Min, Micro;
|
||||||
getDarwinNumber(Maj, Min, Rev);
|
getDarwinNumber(Maj, Min, Micro);
|
||||||
return Maj;
|
return Maj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getDarwinNumber(unsigned &Major, unsigned &Minor,
|
||||||
|
unsigned &Micro) const {
|
||||||
|
return getOSVersion(Major, Minor, Micro);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned getDarwinMajorNumber() const {
|
||||||
|
return getOSMajorVersion();
|
||||||
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Mutators
|
/// @name Mutators
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -532,67 +532,44 @@ StringRef Triple::getOSAndEnvironmentName() const {
|
|||||||
|
|
||||||
static unsigned EatNumber(StringRef &Str) {
|
static unsigned EatNumber(StringRef &Str) {
|
||||||
assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
|
assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
|
||||||
unsigned Result = Str[0]-'0';
|
unsigned Result = 0;
|
||||||
|
|
||||||
// Eat the digit.
|
do {
|
||||||
Str = Str.substr(1);
|
// Consume the leading digit.
|
||||||
|
|
||||||
// Handle "darwin11".
|
|
||||||
if (Result == 1 && !Str.empty() && Str[0] >= '0' && Str[0] <= '9') {
|
|
||||||
Result = Result*10 + (Str[0] - '0');
|
Result = Result*10 + (Str[0] - '0');
|
||||||
|
|
||||||
// Eat the digit.
|
// Eat the digit.
|
||||||
Str = Str.substr(1);
|
Str = Str.substr(1);
|
||||||
}
|
} while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getDarwinNumber - Parse the 'darwin number' out of the specific target
|
void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
|
||||||
/// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
|
unsigned &Micro) const {
|
||||||
/// not defined, return 0's. This requires that the triple have an OSType of
|
|
||||||
/// darwin before it is called.
|
|
||||||
void Triple::getDarwinNumber(unsigned &Maj, unsigned &Min,
|
|
||||||
unsigned &Revision) const {
|
|
||||||
assert(getOS() == Darwin && "Not a darwin target triple!");
|
|
||||||
StringRef OSName = getOSName();
|
StringRef OSName = getOSName();
|
||||||
assert(OSName.startswith("darwin") && "Unknown darwin target triple!");
|
|
||||||
|
|
||||||
// Strip off "darwin".
|
// Assume that the OS portion of the triple starts with the canonical name.
|
||||||
OSName = OSName.substr(6);
|
StringRef OSTypeName = getOSTypeName(getOS());
|
||||||
|
if (OSName.startswith(OSTypeName))
|
||||||
|
OSName = OSName.substr(OSTypeName.size());
|
||||||
|
|
||||||
Maj = Min = Revision = 0;
|
// Any unset version defaults to 0.
|
||||||
|
Major = Minor = Micro = 0;
|
||||||
|
|
||||||
if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
|
// Parse up to three components.
|
||||||
return;
|
unsigned *Components[3] = { &Major, &Minor, &Micro };
|
||||||
|
for (unsigned i = 0; i != 3; ++i) {
|
||||||
|
if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
|
||||||
|
break;
|
||||||
|
|
||||||
// The major version is the first digit.
|
// Consume the leading number.
|
||||||
Maj = EatNumber(OSName);
|
*Components[i] = EatNumber(OSName);
|
||||||
if (OSName.empty()) return;
|
|
||||||
|
|
||||||
// Handle minor version: 10.4.9 -> darwin8.9.
|
// Consume the separator, if present.
|
||||||
if (OSName[0] != '.')
|
if (OSName.startswith("."))
|
||||||
return;
|
OSName = OSName.substr(1);
|
||||||
|
}
|
||||||
// Eat the '.'.
|
|
||||||
OSName = OSName.substr(1);
|
|
||||||
|
|
||||||
if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
|
|
||||||
return;
|
|
||||||
|
|
||||||
Min = EatNumber(OSName);
|
|
||||||
if (OSName.empty()) return;
|
|
||||||
|
|
||||||
// Handle revision darwin8.9.1
|
|
||||||
if (OSName[0] != '.')
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Eat the '.'.
|
|
||||||
OSName = OSName.substr(1);
|
|
||||||
|
|
||||||
if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
|
|
||||||
return;
|
|
||||||
|
|
||||||
Revision = EatNumber(OSName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Triple::setTriple(const Twine &Str) {
|
void Triple::setTriple(const Twine &Str) {
|
||||||
|
Loading…
Reference in New Issue
Block a user