[llvm] r372618 - [TextAPI] Add New Supported Platforms
Cyndy Ishida via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 08:28:03 PDT 2019
Author: cishida
Date: Mon Sep 23 08:28:02 2019
New Revision: 372618
URL: http://llvm.org/viewvc/llvm-project?rev=372618&view=rev
Log:
[TextAPI] Add New Supported Platforms
Summary: This patch introduces simulators, as well was the restriced zippered and macCatalyst to supported platforms
Reviewers: ributzka, steven_wu
Reviewed By: ributzka
Subscribers: hiraditya, dexonsmith, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67528
Modified:
llvm/trunk/include/llvm/TextAPI/MachO/Platform.h
llvm/trunk/lib/TextAPI/MachO/Platform.cpp
llvm/trunk/lib/TextAPI/MachO/TextStub.cpp
llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp
llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp
llvm/trunk/unittests/TextAPI/TextStubV3Tests.cpp
Modified: llvm/trunk/include/llvm/TextAPI/MachO/Platform.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TextAPI/MachO/Platform.h?rev=372618&r1=372617&r2=372618&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TextAPI/MachO/Platform.h (original)
+++ llvm/trunk/include/llvm/TextAPI/MachO/Platform.h Mon Sep 23 08:28:02 2019
@@ -25,11 +25,16 @@ enum class PlatformKind : unsigned {
iOS = MachO::PLATFORM_IOS,
tvOS = MachO::PLATFORM_TVOS,
watchOS = MachO::PLATFORM_WATCHOS,
- bridgeOS = MachO::PLATFORM_BRIDGEOS
+ bridgeOS = MachO::PLATFORM_BRIDGEOS,
+ macCatalyst = MachO::PLATFORM_MACCATALYST,
+ iOSSimulator = MachO::PLATFORM_IOSSIMULATOR,
+ tvOSSimulator = MachO::PLATFORM_TVOSSIMULATOR,
+ watchOSSimulator = MachO::PLATFORM_WATCHOSSIMULATOR
};
using PlatformSet = SmallSet<PlatformKind, 3>;
+PlatformKind mapToPlatformKind(PlatformKind Platform, bool WantSim);
PlatformKind mapToPlatformKind(const Triple &Target);
PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
StringRef getPlatformName(PlatformKind Platform);
Modified: llvm/trunk/lib/TextAPI/MachO/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TextAPI/MachO/Platform.cpp?rev=372618&r1=372617&r2=372618&view=diff
==============================================================================
--- llvm/trunk/lib/TextAPI/MachO/Platform.cpp (original)
+++ llvm/trunk/lib/TextAPI/MachO/Platform.cpp Mon Sep 23 08:28:02 2019
@@ -17,6 +17,20 @@
namespace llvm {
namespace MachO {
+PlatformKind mapToPlatformKind(PlatformKind Platform, bool WantSim) {
+ switch (Platform) {
+ default:
+ return Platform;
+ case PlatformKind::iOS:
+ return WantSim ? PlatformKind::iOSSimulator : PlatformKind::iOS;
+ case PlatformKind::tvOS:
+ return WantSim ? PlatformKind::tvOSSimulator : PlatformKind::tvOS;
+ case PlatformKind::watchOS:
+ return WantSim ? PlatformKind::watchOSSimulator : PlatformKind::watchOS;
+ }
+ llvm_unreachable("Unknown llvm.MachO.PlatformKind enum");
+}
+
PlatformKind mapToPlatformKind(const Triple &Target) {
switch (Target.getOS()) {
default:
@@ -24,13 +38,20 @@ PlatformKind mapToPlatformKind(const Tri
case Triple::MacOSX:
return PlatformKind::macOS;
case Triple::IOS:
+ if (Target.isSimulatorEnvironment())
+ return PlatformKind::iOSSimulator;
+ if (Target.getEnvironment() == Triple::MacABI)
+ return PlatformKind::macCatalyst;
return PlatformKind::iOS;
case Triple::TvOS:
- return PlatformKind::tvOS;
+ return Target.isSimulatorEnvironment() ? PlatformKind::tvOSSimulator
+ : PlatformKind::tvOS;
case Triple::WatchOS:
- return PlatformKind::watchOS;
+ return Target.isSimulatorEnvironment() ? PlatformKind::watchOSSimulator
+ : PlatformKind::watchOS;
// TODO: add bridgeOS once in llvm::Triple
}
+ llvm_unreachable("Unknown Target Triple");
}
PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets) {
@@ -54,6 +75,14 @@ StringRef getPlatformName(PlatformKind P
return "watchOS";
case PlatformKind::bridgeOS:
return "bridgeOS";
+ case PlatformKind::macCatalyst:
+ return "macCatalyst";
+ case PlatformKind::iOSSimulator:
+ return "iOS Simulator";
+ case PlatformKind::tvOSSimulator:
+ return "tvOS Simulator";
+ case PlatformKind::watchOSSimulator:
+ return "watchOS Simulator";
}
llvm_unreachable("Unknown llvm.MachO.PlatformKind enum");
}
Modified: llvm/trunk/lib/TextAPI/MachO/TextStub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TextAPI/MachO/TextStub.cpp?rev=372618&r1=372617&r2=372618&view=diff
==============================================================================
--- llvm/trunk/lib/TextAPI/MachO/TextStub.cpp (original)
+++ llvm/trunk/lib/TextAPI/MachO/TextStub.cpp Mon Sep 23 08:28:02 2019
@@ -399,13 +399,25 @@ template <> struct MappingTraits<const I
}
}
+ // TBD v1 - TBD v3 files only support one platform and several
+ // architectures. It is possible to have more than one platform for TBD v3
+ // files, but the architectures don't apply to all
+ // platforms, specifically to filter out the i386 slice from
+ // platform macCatalyst.
TargetList synthesizeTargets(ArchitectureSet Architectures,
- const PlatformSet &Platforms) {
+ const PlatformSet &Platforms) {
TargetList Targets;
for (auto Platform : Platforms) {
- for (const auto &&Architecture : Architectures)
+ Platform = mapToPlatformKind(Platform, Architectures.hasX86());
+
+ for (const auto &&Architecture : Architectures) {
+ if ((Architecture == AK_i386) &&
+ (Platform == PlatformKind::macCatalyst))
+ continue;
+
Targets.emplace_back(Architecture, Platform);
+ }
}
return Targets;
}
Modified: llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp?rev=372618&r1=372617&r2=372618&view=diff
==============================================================================
--- llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp (original)
+++ llvm/trunk/lib/TextAPI/MachO/TextStubCommon.cpp Mon Sep 23 08:28:02 2019
@@ -43,6 +43,17 @@ void ScalarEnumerationTraits<ObjCConstra
void ScalarTraits<PlatformSet>::output(const PlatformSet &Values, void *IO,
raw_ostream &OS) {
+
+ const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
+ assert((!Ctx || Ctx && Ctx->FileKind != FileType::Invalid) &&
+ "File type is not set in context");
+
+ if ( Ctx && Ctx->FileKind == TBD_V3 && Values.count(PlatformKind::macOS) &&
+ Values.count(PlatformKind::macCatalyst) ) {
+ OS << "zippered";
+ return;
+ }
+
assert(Values.size() == 1U);
switch (*Values.begin()) {
default:
@@ -68,6 +79,19 @@ void ScalarTraits<PlatformSet>::output(c
StringRef ScalarTraits<PlatformSet>::input(StringRef Scalar, void *IO,
PlatformSet &Values) {
+ const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
+ assert((!Ctx || Ctx && Ctx->FileKind != FileType::Invalid) &&
+ "File type is not set in context");
+
+ if (Scalar == "zippered") {
+ if (Ctx && Ctx->FileKind == FileType::TBD_V3) {
+ Values.insert(PlatformKind::macOS);
+ Values.insert(PlatformKind::macCatalyst);
+ return {};
+ }
+ return "invalid platform";
+ }
+
auto Platform = StringSwitch<PlatformKind>(Scalar)
.Case("unknown", PlatformKind::unknown)
.Case("macosx", PlatformKind::macOS)
@@ -75,8 +99,13 @@ StringRef ScalarTraits<PlatformSet>::inp
.Case("watchos", PlatformKind::watchOS)
.Case("tvos", PlatformKind::tvOS)
.Case("bridgeos", PlatformKind::bridgeOS)
+ .Case("iosmac", PlatformKind::macCatalyst)
.Default(PlatformKind::unknown);
+ if (Platform == PlatformKind::macCatalyst)
+ if (Ctx && Ctx->FileKind != FileType::TBD_V3)
+ return "invalid platform";
+
if (Platform == PlatformKind::unknown)
return "unknown platform";
Modified: llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp?rev=372618&r1=372617&r2=372618&view=diff
==============================================================================
--- llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp (original)
+++ llvm/trunk/unittests/TextAPI/TextStubV2Tests.cpp Mon Sep 23 08:28:02 2019
@@ -457,6 +457,23 @@ TEST(TBDv2, UnknownPlatform) {
errorMessage);
}
+TEST(TBDv2, InvalidPlatform) {
+ static const char tbd_v2_file_invalid_platform[] =
+ "--- !tapi-tbd-v2\n"
+ "archs: [ i386 ]\n"
+ "platform: iosmac\n"
+ "install-name: Test.dylib\n"
+ "...\n";
+
+ auto Result = TextAPIReader::get(
+ MemoryBufferRef(tbd_v2_file_invalid_platform, "Test.tbd"));
+ EXPECT_FALSE(!!Result);
+ auto errorMessage = toString(Result.takeError());
+ EXPECT_EQ("malformed file\nTest.tbd:3:11: error: invalid platform\nplatform: "
+ "iosmac\n ^~~~~~\n",
+ errorMessage);
+}
+
TEST(TBDv2, MalformedFile1) {
static const char malformed_file1[] = "--- !tapi-tbd-v2\n"
"archs: [ arm64 ]\n"
Modified: llvm/trunk/unittests/TextAPI/TextStubV3Tests.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/TextAPI/TextStubV3Tests.cpp?rev=372618&r1=372617&r2=372618&view=diff
==============================================================================
--- llvm/trunk/unittests/TextAPI/TextStubV3Tests.cpp (original)
+++ llvm/trunk/unittests/TextAPI/TextStubV3Tests.cpp Mon Sep 23 08:28:02 2019
@@ -274,6 +274,43 @@ TEST(TBDv3, Platform_bridgeOS) {
EXPECT_EQ(Platform, *File->getPlatforms().begin());
}
+TEST(TBDv3, Platform_macCatalyst) {
+ static const char tbd_v1_platform_iosmac[] = "--- !tapi-tbd-v3\n"
+ "archs: [ armv7k ]\n"
+ "platform: iosmac\n"
+ "install-name: Test.dylib\n"
+ "...\n";
+
+ auto Result =
+ TextAPIReader::get(MemoryBufferRef(tbd_v1_platform_iosmac, "Test.tbd"));
+ EXPECT_TRUE(!!Result);
+ auto Platform = PlatformKind::macCatalyst;
+ auto File = std::move(Result.get());
+ EXPECT_EQ(FileType::TBD_V3, File->getFileType());
+ EXPECT_EQ(Platform, *File->getPlatforms().begin());
+}
+
+TEST(TBDv3, Platform_zippered) {
+ static const char tbd_v1_platform_zip[] = "--- !tapi-tbd-v3\n"
+ "archs: [ armv7k ]\n"
+ "platform: zippered\n"
+ "install-name: Test.dylib\n"
+ "...\n";
+
+ auto Result =
+ TextAPIReader::get(MemoryBufferRef(tbd_v1_platform_zip, "Test.tbd"));
+ EXPECT_TRUE(!!Result);
+ auto File = std::move(Result.get());
+ EXPECT_EQ(FileType::TBD_V3, File->getFileType());
+
+ PlatformSet Platforms;
+ Platforms.insert(PlatformKind::macOS);
+ Platforms.insert(PlatformKind::macCatalyst);
+ EXPECT_EQ(Platforms.size(), File->getPlatforms().size());
+ for (auto Platform : File->getPlatforms())
+ EXPECT_EQ(Platforms.count(Platform), 1U);
+}
+
TEST(TBDv3, Swift_1_0) {
static const char tbd_v1_swift_1_0[] = "--- !tapi-tbd-v3\n"
"archs: [ arm64 ]\n"
More information about the llvm-commits
mailing list