[llvm] r371248 - [llvm-ifs] Improving detection of PlatformKind from triple for TBD generation.

Puyan Lotfi via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 13:00:00 PDT 2019


Author: zer0
Date: Fri Sep  6 12:59:59 2019
New Revision: 371248

URL: http://llvm.org/viewvc/llvm-project?rev=371248&view=rev
Log:
[llvm-ifs] Improving detection of PlatformKind from triple for TBD generation.

It was pointed out that I had hard-coded PlatformKind. This is rectifying that.

Differential Revision: https://reviews.llvm.org/D67255



Added:
    llvm/trunk/test/tools/llvm-ifs/ios-tbd.ifs
    llvm/trunk/test/tools/llvm-ifs/macos-tbd.ifs
    llvm/trunk/test/tools/llvm-ifs/tvos-tbd.ifs
    llvm/trunk/test/tools/llvm-ifs/watchos-tbd.ifs
Modified:
    llvm/trunk/tools/llvm-ifs/llvm-ifs.cpp

Added: llvm/trunk/test/tools/llvm-ifs/ios-tbd.ifs
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ifs/ios-tbd.ifs?rev=371248&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-ifs/ios-tbd.ifs (added)
+++ llvm/trunk/test/tools/llvm-ifs/ios-tbd.ifs Fri Sep  6 12:59:59 2019
@@ -0,0 +1,22 @@
+# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s
+
+# CHECK: --- !tapi-tbd-v3
+# CHECK-NEXT: archs:           [ arm64 ]
+# CHECK-NEXT: platform:        ios
+# CHECK-NEXT: flags:           [ flat_namespace, not_app_extension_safe ]
+# CHECK-NEXT: install-name:    ''
+# CHECK-NEXT: current-version: 0
+# CHECK-NEXT: compatibility-version: 0
+# CHECK-NEXT: objc-constraint: none
+# CHECK-NEXT: exports:
+# CHECK-NEXT:   - archs:           [ arm64 ]
+# CHECK-NEXT:     symbols:         [ __Z3fooi ]
+# CHECK-NEXT: ...
+
+--- !experimental-ifs-v1
+IfsVersion: 1.0
+Triple: arm64-apple-ios
+ObjectFileFormat: TBD
+Symbols:
+  __Z3fooi: { Type: Func }
+...

Added: llvm/trunk/test/tools/llvm-ifs/macos-tbd.ifs
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ifs/macos-tbd.ifs?rev=371248&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-ifs/macos-tbd.ifs (added)
+++ llvm/trunk/test/tools/llvm-ifs/macos-tbd.ifs Fri Sep  6 12:59:59 2019
@@ -0,0 +1,22 @@
+# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s
+
+# CHECK: --- !tapi-tbd-v3
+# CHECK-NEXT: archs:           [ arm64 ]
+# CHECK-NEXT: platform:        macosx
+# CHECK-NEXT: flags:           [ flat_namespace, not_app_extension_safe ]
+# CHECK-NEXT: install-name:    ''
+# CHECK-NEXT: current-version: 0
+# CHECK-NEXT: compatibility-version: 0
+# CHECK-NEXT: objc-constraint: none
+# CHECK-NEXT: exports:
+# CHECK-NEXT:   - archs:           [ arm64 ]
+# CHECK-NEXT:     symbols:         [ __Z3fooi ]
+# CHECK-NEXT: ...
+
+--- !experimental-ifs-v1
+IfsVersion: 1.0
+Triple: arm64-apple-macosx
+ObjectFileFormat: TBD
+Symbols:
+  __Z3fooi: { Type: Func }
+...

Added: llvm/trunk/test/tools/llvm-ifs/tvos-tbd.ifs
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ifs/tvos-tbd.ifs?rev=371248&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-ifs/tvos-tbd.ifs (added)
+++ llvm/trunk/test/tools/llvm-ifs/tvos-tbd.ifs Fri Sep  6 12:59:59 2019
@@ -0,0 +1,22 @@
+# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s
+
+# CHECK: --- !tapi-tbd-v3
+# CHECK-NEXT: archs:           [ arm64 ]
+# CHECK-NEXT: platform:        tvos
+# CHECK-NEXT: flags:           [ flat_namespace, not_app_extension_safe ]
+# CHECK-NEXT: install-name:    ''
+# CHECK-NEXT: current-version: 0
+# CHECK-NEXT: compatibility-version: 0
+# CHECK-NEXT: objc-constraint: none
+# CHECK-NEXT: exports:
+# CHECK-NEXT:   - archs:           [ arm64 ]
+# CHECK-NEXT:     symbols:         [ __Z3fooi ]
+# CHECK-NEXT: ...
+
+--- !experimental-ifs-v1
+IfsVersion: 1.0
+Triple: arm64-apple-tvos
+ObjectFileFormat: TBD
+Symbols:
+  __Z3fooi: { Type: Func }
+...

Added: llvm/trunk/test/tools/llvm-ifs/watchos-tbd.ifs
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ifs/watchos-tbd.ifs?rev=371248&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-ifs/watchos-tbd.ifs (added)
+++ llvm/trunk/test/tools/llvm-ifs/watchos-tbd.ifs Fri Sep  6 12:59:59 2019
@@ -0,0 +1,22 @@
+# RUN: llvm-ifs --action write-bin -o - %s | FileCheck %s
+
+# CHECK: --- !tapi-tbd-v3
+# CHECK-NEXT: archs:           [ arm64 ]
+# CHECK-NEXT: platform:        watchos
+# CHECK-NEXT: flags:           [ flat_namespace, not_app_extension_safe ]
+# CHECK-NEXT: install-name:    ''
+# CHECK-NEXT: current-version: 0
+# CHECK-NEXT: compatibility-version: 0
+# CHECK-NEXT: objc-constraint: none
+# CHECK-NEXT: exports:
+# CHECK-NEXT:   - archs:           [ arm64 ]
+# CHECK-NEXT:     symbols:         [ __Z3fooi ]
+# CHECK-NEXT: ...
+
+--- !experimental-ifs-v1
+IfsVersion: 1.0
+Triple: arm64-apple-watchos
+ObjectFileFormat: TBD
+Symbols:
+  __Z3fooi: { Type: Func }
+...

Modified: llvm/trunk/tools/llvm-ifs/llvm-ifs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ifs/llvm-ifs.cpp?rev=371248&r1=371247&r2=371248&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ifs/llvm-ifs.cpp (original)
+++ llvm/trunk/tools/llvm-ifs/llvm-ifs.cpp Fri Sep  6 12:59:59 2019
@@ -154,8 +154,8 @@ template <> struct CustomMappingTraits<s
       IO.mapRequired(Sym.Name.c_str(), const_cast<IFSSymbol &>(Sym));
   }
 };
-} // End yaml namespace
-} // End llvm namespace
+} // namespace yaml
+} // namespace llvm
 
 // A cumulative representation of ELF stubs.
 // Both textual and binary stubs will read into and write from this object.
@@ -196,8 +196,8 @@ template <> struct MappingTraits<IFSStub
     IO.mapRequired("Symbols", Stub.Symbols);
   }
 };
-} // End yaml namespace
-} // End llvm namespace
+} // namespace yaml
+} // namespace llvm
 
 static Expected<std::unique_ptr<IFSStub>> readInputFile(StringRef FilePath) {
   // Read in file.
@@ -224,7 +224,7 @@ int writeTbdStub(const llvm::Triple &T,
       [](const llvm::Triple &T) -> llvm::Expected<llvm::MachO::Architecture> {
     switch (T.getArch()) {
     default:
-      return createStringError(errc::not_supported, "Invalid Architecture.");
+      return createStringError(errc::not_supported, "Invalid Architecture.\n");
     case llvm::Triple::ArchType::x86:
       return AK_i386;
     case llvm::Triple::ArchType::x86_64:
@@ -236,15 +236,39 @@ int writeTbdStub(const llvm::Triple &T,
     }
   }(T);
 
+  auto PlatformKindOrError =
+      [](const llvm::Triple &T) -> llvm::Expected<llvm::MachO::PlatformKind> {
+    if (T.isMacOSX())
+      return llvm::MachO::PlatformKind::macOS;
+    if (T.isTvOS())
+      return llvm::MachO::PlatformKind::tvOS;
+    if (T.isWatchOS())
+      return llvm::MachO::PlatformKind::watchOS;
+    // Note: put isiOS last because tvOS and watchOS are also iOS according
+    // to the Triple.
+    if (T.isiOS())
+      return llvm::MachO::PlatformKind::iOS;
+
+    // TODO: Add an option for ForceTriple, but keep ForceFormat for now.
+    if (ForceFormat == "TBD")
+      return llvm::MachO::PlatformKind::macOS;
+
+    return createStringError(errc::not_supported, "Invalid Platform.\n");
+  }(T);
+
   if (!ArchOrError)
     return -1;
 
+  if (!PlatformKindOrError)
+    return -1;
+
   Architecture Arch = ArchOrError.get();
+  PlatformKind Plat = PlatformKindOrError.get();
 
   InterfaceFile File;
-  File.setFileType(FileType::TBD_V3);
+  File.setFileType(FileType::TBD_V3); // Only supporting v3 for now.
   File.setArchitectures(Arch);
-  File.setPlatform(PlatformKind::macOS);
+  File.setPlatform(Plat);
 
   for (const auto &Symbol : Symbols) {
     auto Name = Symbol.Name;




More information about the llvm-commits mailing list