diff options
author | Bob Wilson <bob.wilson@apple.com> | 2017-10-23 21:51:50 +0000 |
---|---|---|
committer | Bob Wilson <bob.wilson@apple.com> | 2017-10-23 21:51:50 +0000 |
commit | 4f08478711d7b40c8eee1dbb274b28f220321ae1 (patch) | |
tree | db9d8b5896edf2e03624da6c973c3357edf1ecea | |
parent | 6d8b51f8988d868eb924954897e3148c2f91569c (diff) |
Add a new Simulator entry for the target triple environment.
Apple's iOS, tvOS and watchOS simulator platforms have never been clearly
distinguished in the target triples. Even though they are intended to
behave similarly to the corresponding device platforms, they have separate
SDKs and are really separate platforms from the compiler's perspective.
Clang now defines a macro when building for one of these simulator platforms
(r297866) but that relies on the very indirect mechanism of checking to see
which option was used to specify the minimum deployment target. That is not
so great. Swift would also like to distinguish these simulator platforms in
a similar way, but unlike Clang, Swift does not use a separate option to
specify the minimum deployment target -- it uses a -target option to
specify the target triple directly, including the OS version number.
Using a different target triple for the simulator platforms is a much
more direct and obvious way to specify this. Putting the "simulator" in
the environment component of the triple means the OS values can stay the
same and existing code the looks at the OS field will not be affected.
https://reviews.llvm.org/D39143
rdar://problem/34729432
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316380 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/Triple.h | 7 | ||||
-rw-r--r-- | lib/Support/Triple.cpp | 2 | ||||
-rw-r--r-- | unittests/ADT/TripleTest.cpp | 9 |
3 files changed, 17 insertions, 1 deletions
diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h index f8fec5d0da7..761e0ad98db 100644 --- a/include/llvm/ADT/Triple.h +++ b/include/llvm/ADT/Triple.h @@ -205,7 +205,8 @@ public: AMDOpenCL, CoreCLR, OpenCL, - LastEnvironmentType = OpenCL + Simulator, // Simulator variants of other systems, e.g., Apple's iOS + LastEnvironmentType = Simulator }; enum ObjectFormatType { UnknownObjectFormat, @@ -470,6 +471,10 @@ public: return isMacOSX() || isiOS() || isWatchOS(); } + bool isSimulatorEnvironment() const { + return getEnvironment() == Triple::Simulator; + } + bool isOSNetBSD() const { return getOS() == Triple::NetBSD; } diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index 69c99ac907a..4f0a30042b7 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -235,6 +235,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) { case AMDOpenCL: return "amdopencl"; case CoreCLR: return "coreclr"; case OpenCL: return "opencl"; + case Simulator: return "simulator"; } llvm_unreachable("Invalid EnvironmentType!"); @@ -525,6 +526,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) { .StartsWith("amdopencl", Triple::AMDOpenCL) .StartsWith("coreclr", Triple::CoreCLR) .StartsWith("opencl", Triple::OpenCL) + .StartsWith("simulator", Triple::Simulator) .Default(Triple::UnknownEnvironment); } diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index b78aee4f33d..ed4a88067b1 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -1000,6 +1000,15 @@ TEST(TripleTest, getOSVersion) { EXPECT_EQ((unsigned)7, Major); EXPECT_EQ((unsigned)0, Minor); EXPECT_EQ((unsigned)0, Micro); + EXPECT_FALSE(T.isSimulatorEnvironment()); + + T = Triple("x86_64-apple-ios10.3-simulator"); + EXPECT_TRUE(T.isiOS()); + T.getiOSVersion(Major, Minor, Micro); + EXPECT_EQ((unsigned)10, Major); + EXPECT_EQ((unsigned)3, Minor); + EXPECT_EQ((unsigned)0, Micro); + EXPECT_TRUE(T.isSimulatorEnvironment()); } TEST(TripleTest, FileFormat) { |