diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-20 18:21:51 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-20 18:21:51 +0000 |
commit | fc6a89964badf45cbe8e907cd1e1ea1765f5357b (patch) | |
tree | 806a0a4c1127e855509de6d09c844b8a26d800da /lib/Driver/HostInfo.cpp | |
parent | 600cfab4743c9a842c50453ca4e873e2aa8fbf1f (diff) |
Driver: Parse Darwin version out of target triple.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67388 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/HostInfo.cpp')
-rw-r--r-- | lib/Driver/HostInfo.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index 5f2460f209..39a688a4f5 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -11,6 +11,8 @@ #include "clang/Driver/Arg.h" #include "clang/Driver/ArgList.h" +#include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Option.h" #include "clang/Driver/Options.h" @@ -59,6 +61,37 @@ public: const char *ArchName) const; }; +/// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and +/// return the grouped values as integers. Numbers which are not +/// provided are set to 0. +/// +/// \return True if the entire string was parsed (9.2), or all groups +/// were parsed (10.3.5extrastuff). +static bool GetReleaseVersion(const char *Str, unsigned &Major, + unsigned &Minor, unsigned &Micro) { + Major = Minor = Micro = 0; + if (*Str == '\0') + return true; + + char *End; + Major = (unsigned) strtol(Str, &End, 10); + if (*Str != '\0' && *End == '\0') + return true; + if (*End != '.') + return false; + + Str = End+1; + Minor = (unsigned) strtol(Str, &End, 10); + if (*Str != '\0' && *End == '\0') + return true; + if (*End != '.') + return false; + + Str = End+1; + Micro = (unsigned) strtol(Str, &End, 10); + return true; +} + DarwinHostInfo::DarwinHostInfo(const Driver &D, const char *_Arch, const char *_Platform, const char *_OS) : HostInfo(D, _Arch, _Platform, _OS) { @@ -67,7 +100,14 @@ DarwinHostInfo::DarwinHostInfo(const Driver &D, const char *_Arch, getArchName() == "ppc" || getArchName() == "ppc64") && "Unknown Darwin arch."); - // FIXME: How to deal with errors? + assert(memcmp(&getOSName()[0], "darwin", 6) == 0 && + "Unknown Darwin platform."); + const char *Release = &getOSName()[6]; + if (!GetReleaseVersion(Release, DarwinVersion[0], DarwinVersion[1], + DarwinVersion[2])) { + D.Diag(clang::diag::err_drv_invalid_darwin_version) + << Release; + } // We can only call 4.2.1 for now. GCCVersion[0] = 4; |