From 7e55e68852834a1b246116db3a90a793d26df703 Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Mon, 23 Oct 2017 21:51:50 +0000 Subject: [PATCH] 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 llvm-svn: 316380 --- llvm/include/llvm/ADT/Triple.h | 7 ++++++- llvm/lib/Support/Triple.cpp | 2 ++ llvm/unittests/ADT/TripleTest.cpp | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index f8fec5d..761e0ad9 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/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/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index 69c99ac..4f0a300 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/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/llvm/unittests/ADT/TripleTest.cpp b/llvm/unittests/ADT/TripleTest.cpp index b78aee4..ed4a8806 100644 --- a/llvm/unittests/ADT/TripleTest.cpp +++ b/llvm/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) { -- 2.7.4