mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-03 01:12:53 +00:00
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372618 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6d98e4c3cc
commit
a6305400b9
@ -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);
|
||||
|
@ -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 Triple &Target) {
|
||||
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 Platform) {
|
||||
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");
|
||||
}
|
||||
|
@ -399,13 +399,25 @@ template <> struct MappingTraits<const InterfaceFile *> {
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
@ -43,6 +43,17 @@ void ScalarEnumerationTraits<ObjCConstraintType>::enumeration(
|
||||
|
||||
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(const PlatformSet &Values, void *IO,
|
||||
|
||||
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>::input(StringRef Scalar, void *IO,
|
||||
.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";
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user