aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/TextAPI/MachO/InterfaceFile.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:51:42 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:51:42 +0000
commit1d5ae1026e831016fc29fd927877c86af904481f (patch)
tree2cdfd12620fcfa5d9e4a0389f85368e8e36f63f9 /include/llvm/TextAPI/MachO/InterfaceFile.h
parente6d1592492a3a379186bfb02bd0f4eda0669c0d5 (diff)
Notes
Diffstat (limited to 'include/llvm/TextAPI/MachO/InterfaceFile.h')
-rw-r--r--include/llvm/TextAPI/MachO/InterfaceFile.h240
1 files changed, 110 insertions, 130 deletions
diff --git a/include/llvm/TextAPI/MachO/InterfaceFile.h b/include/llvm/TextAPI/MachO/InterfaceFile.h
index e722449d52f1..bd434e04b693 100644
--- a/include/llvm/TextAPI/MachO/InterfaceFile.h
+++ b/include/llvm/TextAPI/MachO/InterfaceFile.h
@@ -26,21 +26,13 @@
#include "llvm/TextAPI/MachO/Architecture.h"
#include "llvm/TextAPI/MachO/ArchitectureSet.h"
#include "llvm/TextAPI/MachO/PackedVersion.h"
+#include "llvm/TextAPI/MachO/Platform.h"
#include "llvm/TextAPI/MachO/Symbol.h"
+#include "llvm/TextAPI/MachO/Target.h"
namespace llvm {
namespace MachO {
-/// Defines the list of MachO platforms.
-enum class PlatformKind : unsigned {
- unknown,
- macOS = MachO::PLATFORM_MACOS,
- iOS = MachO::PLATFORM_IOS,
- tvOS = MachO::PLATFORM_TVOS,
- watchOS = MachO::PLATFORM_WATCHOS,
- bridgeOS = MachO::PLATFORM_BRIDGEOS,
-};
-
/// Defines a list of Objective-C constraints.
enum class ObjCConstraintType : unsigned {
/// No constraint.
@@ -75,6 +67,9 @@ enum FileType : unsigned {
/// Text-based stub file (.tbd) version 3.0
TBD_V3 = 1U << 2,
+ /// Text-based stub file (.tbd) version 4.0
+ TBD_V4 = 1U << 3,
+
All = ~0U,
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/All),
@@ -89,29 +84,42 @@ public:
InterfaceFileRef(StringRef InstallName) : InstallName(InstallName) {}
- InterfaceFileRef(StringRef InstallName, ArchitectureSet Archs)
- : InstallName(InstallName), Architectures(Archs) {}
+ InterfaceFileRef(StringRef InstallName, const TargetList Targets)
+ : InstallName(InstallName), Targets(std::move(Targets)) {}
StringRef getInstallName() const { return InstallName; };
- void addArchitectures(ArchitectureSet Archs) { Architectures |= Archs; }
- ArchitectureSet getArchitectures() const { return Architectures; }
- bool hasArchitecture(Architecture Arch) const {
- return Architectures.has(Arch);
+
+ void addTarget(const Target &Target);
+ template <typename RangeT> void addTargets(RangeT &&Targets) {
+ for (const auto &Target : Targets)
+ addTarget(Target(Target));
}
+ using const_target_iterator = TargetList::const_iterator;
+ using const_target_range = llvm::iterator_range<const_target_iterator>;
+ const_target_range targets() const { return {Targets}; }
+
+ ArchitectureSet getArchitectures() const {
+ return mapToArchitectureSet(Targets);
+ }
+
+ PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); }
+
bool operator==(const InterfaceFileRef &O) const {
- return std::tie(InstallName, Architectures) ==
- std::tie(O.InstallName, O.Architectures);
+ return std::tie(InstallName, Targets) == std::tie(O.InstallName, O.Targets);
+ }
+
+ bool operator!=(const InterfaceFileRef &O) const {
+ return std::tie(InstallName, Targets) != std::tie(O.InstallName, O.Targets);
}
bool operator<(const InterfaceFileRef &O) const {
- return std::tie(InstallName, Architectures) <
- std::tie(O.InstallName, O.Architectures);
+ return std::tie(InstallName, Targets) < std::tie(O.InstallName, O.Targets);
}
private:
std::string InstallName;
- ArchitectureSet Architectures;
+ TargetList Targets;
};
} // end namespace MachO.
@@ -170,27 +178,43 @@ public:
/// \return The file type.
FileType getFileType() const { return FileKind; }
- /// Set the platform.
- void setPlatform(PlatformKind Platform_) { Platform = Platform_; }
+ /// Get the architectures.
+ ///
+ /// \return The applicable architectures.
+ ArchitectureSet getArchitectures() const {
+ return mapToArchitectureSet(Targets);
+ }
- /// Get the platform.
- PlatformKind getPlatform() const { return Platform; }
+ /// Get the platforms.
+ ///
+ /// \return The applicable platforms.
+ PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); }
- /// Specify the set of supported architectures by this file.
- void setArchitectures(ArchitectureSet Architectures_) {
- Architectures = Architectures_;
- }
+ /// Set and add target.
+ ///
+ /// \param Target the target to add into.
+ void addTarget(const Target &Target);
- /// Add the set of supported architectures by this file.
- void addArchitectures(ArchitectureSet Architectures_) {
- Architectures |= Architectures_;
+ /// Set and add targets.
+ ///
+ /// Add the subset of llvm::triples that is supported by Tapi
+ ///
+ /// \param Targets the collection of targets.
+ template <typename RangeT> void addTargets(RangeT &&Targets) {
+ for (const auto &Target_ : Targets)
+ addTarget(Target(Target_));
}
- /// Add supported architecture by this file..
- void addArch(Architecture Arch) { Architectures.set(Arch); }
+ using const_target_iterator = TargetList::const_iterator;
+ using const_target_range = llvm::iterator_range<const_target_iterator>;
+ const_target_range targets() const { return {Targets}; }
- /// Get the set of supported architectures.
- ArchitectureSet getArchitectures() const { return Architectures; }
+ using const_filtered_target_iterator =
+ llvm::filter_iterator<const_target_iterator,
+ std::function<bool(const Target &)>>;
+ using const_filtered_target_range =
+ llvm::iterator_range<const_filtered_target_iterator>;
+ const_filtered_target_range targets(ArchitectureSet Archs) const;
/// Set the install name of the library.
void setInstallName(StringRef InstallName_) { InstallName = InstallName_; }
@@ -244,11 +268,18 @@ public:
/// Check if this file was generated during InstallAPI.
bool isInstallAPI() const { return IsInstallAPI; }
- /// Set the parent umbrella framework.
- void setParentUmbrella(StringRef Parent) { ParentUmbrella = Parent; }
+ /// Set the parent umbrella frameworks.
+ /// \param Target_ The target applicable to Parent
+ /// \param Parent The name of Parent
+ void addParentUmbrella(const Target &Target_, StringRef Parent);
+ const std::vector<std::pair<Target, std::string>> &umbrellas() const {
+ return ParentUmbrellas;
+ }
/// Get the parent umbrella framework.
- StringRef getParentUmbrella() const { return ParentUmbrella; }
+ const std::vector<std::pair<Target, std::string>> getParentUmbrellas() const {
+ return ParentUmbrellas;
+ }
/// Add an allowable client.
///
@@ -257,9 +288,9 @@ public:
/// that is being generated needs to match one of the allowable clients or the
/// linker refuses to link this library.
///
- /// \param Name The name of the client that is allowed to link this library.
- /// \param Architectures The set of architecture for which this applies.
- void addAllowableClient(StringRef Name, ArchitectureSet Architectures);
+ /// \param InstallName The name of the client that is allowed to link this library.
+ /// \param Target The target triple for which this applies.
+ void addAllowableClient(StringRef InstallName, const Target &Target);
/// Get the list of allowable clients.
///
@@ -271,9 +302,8 @@ public:
/// Add a re-exported library.
///
/// \param InstallName The name of the library to re-export.
- /// \param Architectures The set of architecture for which this applies.
- void addReexportedLibrary(StringRef InstallName,
- ArchitectureSet Architectures);
+ /// \param Target The target triple for which this applies.
+ void addReexportedLibrary(StringRef InstallName, const Target &Target);
/// Get the list of re-exported libraries.
///
@@ -282,27 +312,27 @@ public:
return ReexportedLibraries;
}
- /// Add an architecture/UUID pair.
+ /// Add an Target/UUID pair.
///
- /// \param Arch The architecture for which this applies.
+ /// \param Target The target triple for which this applies.
/// \param UUID The UUID of the library for the specified architecture.
- void addUUID(Architecture Arch, StringRef UUID);
+ void addUUID(const Target &Target, StringRef UUID);
- /// Add an architecture/UUID pair.
+ /// Add an Target/UUID pair.
///
- /// \param Arch The architecture for which this applies.
+ /// \param Target The target triple for which this applies.
/// \param UUID The UUID of the library for the specified architecture.
- void addUUID(Architecture Arch, uint8_t UUID[16]);
+ void addUUID(const Target &Target, uint8_t UUID[16]);
- /// Get the list of architecture/UUID pairs.
+ /// Get the list of Target/UUID pairs.
///
- /// \return Returns a list of architecture/UUID pairs.
- const std::vector<std::pair<Architecture, std::string>> &uuids() const {
+ /// \return Returns a list of Target/UUID pairs.
+ const std::vector<std::pair<Target, std::string>> &uuids() const {
return UUIDs;
}
/// Add a symbol to the symbols list or extend an existing one.
- void addSymbol(SymbolKind Kind, StringRef Name, ArchitectureSet Architectures,
+ void addSymbol(SymbolKind Kind, StringRef Name, const TargetList &Targets,
SymbolFlags Flags = SymbolFlags::None);
using SymbolMapType = DenseMap<SymbolsMapKey, Symbol *>;
@@ -320,84 +350,35 @@ public:
reference operator*() const { return I->second; }
pointer operator->() const { return I->second; }
};
- using const_symbol_range = iterator_range<const_symbol_iterator>;
-
- // Custom iterator to return only exported symbols.
- struct const_export_iterator
- : public iterator_adaptor_base<
- const_export_iterator, const_symbol_iterator,
- std::forward_iterator_tag, const Symbol *> {
- const_symbol_iterator _end;
-
- void skipToNextSymbol() {
- while (I != _end && I->isUndefined())
- ++I;
- }
-
- const_export_iterator() = default;
- template <typename U>
- const_export_iterator(U &&it, U &&end)
- : iterator_adaptor_base(std::forward<U &&>(it)),
- _end(std::forward<U &&>(end)) {
- skipToNextSymbol();
- }
-
- const_export_iterator &operator++() {
- ++I;
- skipToNextSymbol();
- return *this;
- }
-
- const_export_iterator operator++(int) {
- const_export_iterator tmp(*this);
- ++(*this);
- return tmp;
- }
- };
- using const_export_range = llvm::iterator_range<const_export_iterator>;
-
- // Custom iterator to return only undefined symbols.
- struct const_undefined_iterator
- : public iterator_adaptor_base<
- const_undefined_iterator, const_symbol_iterator,
- std::forward_iterator_tag, const Symbol *> {
- const_symbol_iterator _end;
- void skipToNextSymbol() {
- while (I != _end && !I->isUndefined())
- ++I;
- }
+ using const_symbol_range = iterator_range<const_symbol_iterator>;
- const_undefined_iterator() = default;
- template <typename U>
- const_undefined_iterator(U &&it, U &&end)
- : iterator_adaptor_base(std::forward<U &&>(it)),
- _end(std::forward<U &&>(end)) {
- skipToNextSymbol();
- }
-
- const_undefined_iterator &operator++() {
- ++I;
- skipToNextSymbol();
- return *this;
- }
-
- const_undefined_iterator operator++(int) {
- const_undefined_iterator tmp(*this);
- ++(*this);
- return tmp;
- }
- };
- using const_undefined_range = llvm::iterator_range<const_undefined_iterator>;
+ using const_filtered_symbol_iterator =
+ filter_iterator<const_symbol_iterator,
+ std::function<bool(const Symbol *)>>;
+ using const_filtered_symbol_range =
+ iterator_range<const_filtered_symbol_iterator>;
const_symbol_range symbols() const {
return {Symbols.begin(), Symbols.end()};
}
- const_export_range exports() const {
- return {{Symbols.begin(), Symbols.end()}, {Symbols.end(), Symbols.end()}};
+
+ const_filtered_symbol_range exports() const {
+ std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) {
+ return !Symbol->isUndefined();
+ };
+ return make_filter_range(
+ make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}),
+ fn);
}
- const_undefined_range undefineds() const {
- return {{Symbols.begin(), Symbols.end()}, {Symbols.end(), Symbols.end()}};
+
+ const_filtered_symbol_range undefineds() const {
+ std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) {
+ return Symbol->isUndefined();
+ };
+ return make_filter_range(
+ make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}),
+ fn);
}
private:
@@ -411,10 +392,9 @@ private:
return StringRef(reinterpret_cast<const char *>(Ptr), String.size());
}
+ TargetList Targets;
std::string Path;
FileType FileKind;
- PlatformKind Platform;
- ArchitectureSet Architectures;
std::string InstallName;
PackedVersion CurrentVersion;
PackedVersion CompatibilityVersion;
@@ -423,10 +403,10 @@ private:
bool IsAppExtensionSafe{false};
bool IsInstallAPI{false};
ObjCConstraintType ObjcConstraint = ObjCConstraintType::None;
- std::string ParentUmbrella;
+ std::vector<std::pair<Target, std::string>> ParentUmbrellas;
std::vector<InterfaceFileRef> AllowableClients;
std::vector<InterfaceFileRef> ReexportedLibraries;
- std::vector<std::pair<Architecture, std::string>> UUIDs;
+ std::vector<std::pair<Target, std::string>> UUIDs;
SymbolMapType Symbols;
};