[llvm] c4ed142 - [llvm][TextAPI] add mapping from OS string to Platform

Cyndy Ishida via llvm-commits llvm-commits at lists.llvm.org
Thu May 6 16:26:13 PDT 2021


Author: Cyndy Ishida
Date: 2021-05-06T16:25:56-07:00
New Revision: c4ed142e695f14ba5675ec6d12226ee706329a0f

URL: https://github.com/llvm/llvm-project/commit/c4ed142e695f14ba5675ec6d12226ee706329a0f
DIFF: https://github.com/llvm/llvm-project/commit/c4ed142e695f14ba5675ec6d12226ee706329a0f.diff

LOG: [llvm][TextAPI] add mapping from OS string to Platform

* add utility for matching target triple OS value strings  to PlatformKind

This was reviewed offline by ributzka, steven_wu

Added: 
    

Modified: 
    llvm/include/llvm/TextAPI/Platform.h
    llvm/lib/TextAPI/Platform.cpp
    llvm/unittests/TextAPI/TextStubV4Tests.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/TextAPI/Platform.h b/llvm/include/llvm/TextAPI/Platform.h
index 7a81b496cf84..0879039f994d 100644
--- a/llvm/include/llvm/TextAPI/Platform.h
+++ b/llvm/include/llvm/TextAPI/Platform.h
@@ -39,6 +39,7 @@ PlatformKind mapToPlatformKind(PlatformKind Platform, bool WantSim);
 PlatformKind mapToPlatformKind(const Triple &Target);
 PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets);
 StringRef getPlatformName(PlatformKind Platform);
+PlatformKind getPlatformFromName(StringRef Name);
 
 } // end namespace MachO.
 } // end namespace llvm.

diff  --git a/llvm/lib/TextAPI/Platform.cpp b/llvm/lib/TextAPI/Platform.cpp
index d68a0dd483ef..2e6b8852cd6f 100644
--- a/llvm/lib/TextAPI/Platform.cpp
+++ b/llvm/lib/TextAPI/Platform.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/TextAPI/Platform.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 
 namespace llvm {
@@ -89,5 +90,20 @@ StringRef getPlatformName(PlatformKind Platform) {
   llvm_unreachable("Unknown llvm.MachO.PlatformKind enum");
 }
 
+PlatformKind getPlatformFromName(StringRef Name) {
+  return StringSwitch<PlatformKind>(Name)
+      .Case("macos", PlatformKind::macOS)
+      .Case("ios", PlatformKind::iOS)
+      .Case("tvos", PlatformKind::tvOS)
+      .Case("watchos", PlatformKind::watchOS)
+      .Case("bridgeos", PlatformKind::macOS)
+      .Case("ios-macabi", PlatformKind::macCatalyst)
+      .Case("ios-simulator", PlatformKind::iOSSimulator)
+      .Case("tvos-simulator", PlatformKind::tvOSSimulator)
+      .Case("watchos-simulator", PlatformKind::watchOSSimulator)
+      .Case("driverkit", PlatformKind::driverKit)
+      .Default(PlatformKind::unknown);
+}
+
 } // end namespace MachO.
 } // end namespace llvm.

diff  --git a/llvm/unittests/TextAPI/TextStubV4Tests.cpp b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
index 620363cae819..1fe5081894fa 100644
--- a/llvm/unittests/TextAPI/TextStubV4Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
@@ -82,8 +82,8 @@ TEST(TBDv4, ReadFile) {
   TBDFile File = std::move(Result.get());
   EXPECT_EQ(FileType::TBD_V4, File->getFileType());
   PlatformSet Platforms;
-  Platforms.insert(PlatformKind::macOS);
-  Platforms.insert(PlatformKind::iOS);
+  Platforms.insert(getPlatformFromName("macos"));
+  Platforms.insert(getPlatformFromName("ios"));
   auto Archs = AK_i386 | AK_x86_64;
   TargetList Targets = {
       Target(AK_i386, PlatformKind::macOS),


        


More information about the llvm-commits mailing list