diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2015-06-01 23:38:09 +0000 | 
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2015-06-01 23:38:09 +0000 | 
| commit | aac4ea01236e74a54e5119cd06a72816540422e7 (patch) | |
| tree | f278e43b95a7dc9071cd986dd8e06ead439c7085 /llvm | |
| parent | e20dc1cd3ac696805b7e57402d5d8d7129873cde (diff) | |
| download | bcm5719-llvm-aac4ea01236e74a54e5119cd06a72816540422e7.tar.gz bcm5719-llvm-aac4ea01236e74a54e5119cd06a72816540422e7.zip  | |
[ADT] Add Triple::getEnvironmentVersion
This allows us to extract version numbers from the environment.
getOSVersion is currently overloaded for that purpose, this allows us to
clean it up.
llvm-svn: 238796
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/ADT/Triple.h | 9 | ||||
| -rw-r--r-- | llvm/lib/Support/Triple.cpp | 56 | 
2 files changed, 49 insertions, 16 deletions
diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index 2416ce342c9..9315d6b6b93 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -255,6 +255,15 @@ public:    /// getEnvironment - Get the parsed environment type of this triple.    EnvironmentType getEnvironment() const { return Environment; } +  /// \brief 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 getEnvironmentVersion(unsigned &Major, unsigned &Minor, +                             unsigned &Micro) const; +    /// getFormat - Get the object format for this triple.    ObjectFormatType getObjectFormat() const { return ObjectFormat; } diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index a1ee18809ca..6c6b87ea5fb 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -702,6 +702,16 @@ std::string Triple::normalize(StringRef Str) {    // Special case logic goes here.  At this point Arch, Vendor and OS have the    // correct values for the computed components. +  std::string NormalizedEnvironment; +  if (Environment == Triple::Android && Components[3].startswith("androideabi")) { +    StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi")); +    if (AndroidVersion.empty()) { +      Components[3] = "android"; +    } else { +      NormalizedEnvironment = Twine("android", AndroidVersion).str(); +      Components[3] = NormalizedEnvironment; +    } +  }    if (OS == Triple::Win32) {      Components.resize(4); @@ -779,6 +789,35 @@ static unsigned EatNumber(StringRef &Str) {    return Result;  } +static void parseVersionFromName(StringRef Name, unsigned &Major, +                                 unsigned &Minor, unsigned &Micro) { +  // Any unset version defaults to 0. +  Major = Minor = Micro = 0; + +  // Parse up to three components. +  unsigned *Components[3] = {&Major, &Minor, &Micro}; +  for (unsigned i = 0; i != 3; ++i) { +    if (Name.empty() || Name[0] < '0' || Name[0] > '9') +      break; + +    // Consume the leading number. +    *Components[i] = EatNumber(Name); + +    // Consume the separator, if present. +    if (Name.startswith(".")) +      Name = Name.substr(1); +  } +} + +void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor, +                                   unsigned &Micro) const { +  StringRef EnvironmentName = getEnvironmentName(); +  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment()); +  if (EnvironmentName.startswith(EnvironmentTypeName)) +    EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size()); +  parseVersionFromName(EnvironmentName, Major, Minor, Micro); +} +  void Triple::getOSVersion(unsigned &Major, unsigned &Minor,                            unsigned &Micro) const {    StringRef OSName = getOSName(); @@ -796,22 +835,7 @@ void Triple::getOSVersion(unsigned &Major, unsigned &Minor,    if (OSName.startswith(OSTypeName))      OSName = OSName.substr(OSTypeName.size()); -  // Any unset version defaults to 0. -  Major = Minor = Micro = 0; - -  // Parse up to three components. -  unsigned *Components[3] = { &Major, &Minor, &Micro }; -  for (unsigned i = 0; i != 3; ++i) { -    if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9') -      break; - -    // Consume the leading number. -    *Components[i] = EatNumber(OSName); - -    // Consume the separator, if present. -    if (OSName.startswith(".")) -      OSName = OSName.substr(1); -  } +  parseVersionFromName(OSName, Major, Minor, Micro);  }  bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,  | 

