[llvm] 27459a3 - [TextAPI] Update missing enum cases & utility functions

Cyndy Ishida via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 08:28:47 PDT 2023


Author: Cyndy Ishida
Date: 2023-07-27T08:24:42-07:00
New Revision: 27459a3a2ba1b6fe906a125f80eaa8ea657eacc0

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

LOG: [TextAPI] Update missing enum cases & utility functions

* Expand understood `FileType`s that InterfaceFile class can represent.
* Add `hasTarget` function.
* Cleanup symbol `<` comparator to account for SymbolSet operations.

Added: 
    

Modified: 
    llvm/include/llvm/TextAPI/InterfaceFile.h
    llvm/include/llvm/TextAPI/Symbol.h
    llvm/lib/TextAPI/TextStub.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/TextAPI/InterfaceFile.h b/llvm/include/llvm/TextAPI/InterfaceFile.h
index 7966ec8e70cdff..6b46ad993aa97a 100644
--- a/llvm/include/llvm/TextAPI/InterfaceFile.h
+++ b/llvm/include/llvm/TextAPI/InterfaceFile.h
@@ -55,22 +55,31 @@ enum FileType : unsigned {
   /// Invalid file type.
   Invalid = 0U,
 
+  /// \brief MachO Dynamic Library file.
+  MachO_DynamicLibrary      = 1U <<  0,
+
+  /// \brief MachO Dynamic Library Stub file.
+  MachO_DynamicLibrary_Stub = 1U <<  1,
+
+  /// \brief MachO Bundle file.
+  MachO_Bundle              = 1U <<  2,
+
   /// Text-based stub file (.tbd) version 1.0
-  TBD_V1  = 1U <<  0,
+  TBD_V1                    = 1U <<  3,
 
   /// Text-based stub file (.tbd) version 2.0
-  TBD_V2  = 1U <<  1,
+  TBD_V2                    = 1U <<  4,
 
   /// Text-based stub file (.tbd) version 3.0
-  TBD_V3  = 1U <<  2,
+  TBD_V3                    = 1U <<  5,
 
   /// Text-based stub file (.tbd) version 4.0
-  TBD_V4  = 1U <<  3,
+  TBD_V4                    = 1U <<  6,
 
   /// Text-based stub file (.tbd) version 5.0
-  TBD_V5  = 1U <<  4,
+  TBD_V5                    = 1U <<  7,
 
-  All     = ~0U,
+  All                       = ~0U,
 
   LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/All),
 };
@@ -95,6 +104,10 @@ class InterfaceFileRef {
       addTarget(Target(Target));
   }
 
+  bool hasTarget(Target &Targ) const {
+    return llvm::is_contained(Targets, Targ);
+  }
+
   using const_target_iterator = TargetList::const_iterator;
   using const_target_range = llvm::iterator_range<const_target_iterator>;
   const_target_range targets() const { return {Targets}; }
@@ -173,6 +186,13 @@ class InterfaceFile {
   /// \param Target the target to add into.
   void addTarget(const Target &Target);
 
+  /// Determine if target triple slice exists in file.
+  ///
+  /// \param Target the value to find.
+  bool hasTarget(const Target &Targ) const {
+    return llvm::is_contained(Targets, Targ);
+  }
+
   /// Set and add targets.
   ///
   /// Add the subset of llvm::triples that is supported by Tapi

diff  --git a/llvm/include/llvm/TextAPI/Symbol.h b/llvm/include/llvm/TextAPI/Symbol.h
index 63c21c50e9c39c..35d9a64dee1c19 100644
--- a/llvm/include/llvm/TextAPI/Symbol.h
+++ b/llvm/include/llvm/TextAPI/Symbol.h
@@ -125,6 +125,10 @@ class Symbol {
     return mapToArchitectureSet(Targets).contains(Arch);
   }
 
+  bool hasTarget(const Target &Targ) const {
+    return llvm::is_contained(Targets, Targ);
+  }
+
   using const_target_iterator = TargetList::const_iterator;
   using const_target_range = llvm::iterator_range<const_target_iterator>;
   const_target_range targets() const { return {Targets}; }
@@ -146,8 +150,7 @@ class Symbol {
   bool operator!=(const Symbol &O) const { return !(*this == O); }
 
   bool operator<(const Symbol &O) const {
-    return std::tie(Name, Kind, Targets, Flags) <
-           std::tie(O.Name, O.Kind, O.Targets, O.Flags);
+    return std::tie(Kind, Name) < std::tie(O.Kind, O.Name);
   }
 
 private:

diff  --git a/llvm/lib/TextAPI/TextStub.cpp b/llvm/lib/TextAPI/TextStub.cpp
index 78de3ebf3f3a59..e6dc0a4f79aca6 100644
--- a/llvm/lib/TextAPI/TextStub.cpp
+++ b/llvm/lib/TextAPI/TextStub.cpp
@@ -787,7 +787,7 @@ template <> struct MappingTraits<const InterfaceFile *> {
     NormalizedTBD_V4(IO &IO, const InterfaceFile *&File) {
       auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
       assert(Ctx);
-      TBDVersion = Ctx->FileKind >> 1;
+      TBDVersion = Ctx->FileKind >> 4;
       Targets.insert(Targets.begin(), File->targets().begin(),
                      File->targets().end());
       InstallName = File->getInstallName();


        


More information about the llvm-commits mailing list