diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:51:42 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:51:42 +0000 |
commit | 1d5ae1026e831016fc29fd927877c86af904481f (patch) | |
tree | 2cdfd12620fcfa5d9e4a0389f85368e8e36f63f9 /include/llvm/TextAPI | |
parent | e6d1592492a3a379186bfb02bd0f4eda0669c0d5 (diff) |
Notes
Diffstat (limited to 'include/llvm/TextAPI')
-rw-r--r-- | include/llvm/TextAPI/MachO/Architecture.h | 4 | ||||
-rw-r--r-- | include/llvm/TextAPI/MachO/ArchitectureSet.h | 4 | ||||
-rw-r--r-- | include/llvm/TextAPI/MachO/InterfaceFile.h | 240 | ||||
-rw-r--r-- | include/llvm/TextAPI/MachO/Platform.h | 45 | ||||
-rw-r--r-- | include/llvm/TextAPI/MachO/Symbol.h | 35 | ||||
-rw-r--r-- | include/llvm/TextAPI/MachO/Target.h | 68 | ||||
-rw-r--r-- | include/llvm/TextAPI/MachO/TextAPIReader.h | 5 |
7 files changed, 260 insertions, 141 deletions
diff --git a/include/llvm/TextAPI/MachO/Architecture.h b/include/llvm/TextAPI/MachO/Architecture.h index 055baeb0c0f0..3898cbada68f 100644 --- a/include/llvm/TextAPI/MachO/Architecture.h +++ b/include/llvm/TextAPI/MachO/Architecture.h @@ -14,6 +14,7 @@ #define LLVM_TEXTAPI_MACHO_ARCHITECTURE_H #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" #include "llvm/Support/raw_ostream.h" namespace llvm { @@ -39,6 +40,9 @@ StringRef getArchitectureName(Architecture Arch); /// Convert an architecture slice to a CPU Type and Subtype pair. std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch); +/// Convert a target to an architecture slice. +Architecture mapToArchitecture(const llvm::Triple &Target); + raw_ostream &operator<<(raw_ostream &OS, Architecture Arch); } // end namespace MachO. diff --git a/include/llvm/TextAPI/MachO/ArchitectureSet.h b/include/llvm/TextAPI/MachO/ArchitectureSet.h index d8dfc7f1af21..6e4ede6275b4 100644 --- a/include/llvm/TextAPI/MachO/ArchitectureSet.h +++ b/include/llvm/TextAPI/MachO/ArchitectureSet.h @@ -59,6 +59,10 @@ public: ArchSetType rawValue() const { return ArchSet; } + bool hasX86() const { + return has(AK_i386) || has(AK_x86_64) || has(AK_x86_64h); + } + template <typename Ty> class arch_iterator : public std::iterator<std::forward_iterator_tag, Architecture, size_t> { 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; }; diff --git a/include/llvm/TextAPI/MachO/Platform.h b/include/llvm/TextAPI/MachO/Platform.h new file mode 100644 index 000000000000..a22aae9b7dce --- /dev/null +++ b/include/llvm/TextAPI/MachO/Platform.h @@ -0,0 +1,45 @@ +//===- llvm/TextAPI/MachO/Platform.h - Platform -----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Defines the Platforms supported by Tapi and helpers. +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_TEXTAPI_MACHO_PLATFORM_H +#define LLVM_TEXTAPI_MACHO_PLATFORM_H + +#include "llvm/ADT/SmallSet.h" +#include "llvm/BinaryFormat/MachO.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, + 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); + +} // end namespace MachO. +} // end namespace llvm. + +#endif // LLVM_TEXTAPI_MACHO_PLATFORM_H
\ No newline at end of file diff --git a/include/llvm/TextAPI/MachO/Symbol.h b/include/llvm/TextAPI/MachO/Symbol.h index 3c7ff5e0f4ea..1b1632c599c4 100644 --- a/include/llvm/TextAPI/MachO/Symbol.h +++ b/include/llvm/TextAPI/MachO/Symbol.h @@ -14,6 +14,7 @@ #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TextAPI/MachO/ArchitectureSet.h" +#include "llvm/TextAPI/MachO/Target.h" namespace llvm { namespace MachO { @@ -37,7 +38,10 @@ enum class SymbolFlags : uint8_t { /// Undefined Undefined = 1U << 3, - LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Undefined), + /// Rexported + Rexported = 1U << 4, + + LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Rexported), }; // clang-format on @@ -49,16 +53,18 @@ enum class SymbolKind : uint8_t { ObjectiveCInstanceVariable, }; +using TargetList = SmallVector<Target, 5>; class Symbol { public: - constexpr Symbol(SymbolKind Kind, StringRef Name, - ArchitectureSet Architectures, SymbolFlags Flags) - : Name(Name), Architectures(Architectures), Kind(Kind), Flags(Flags) {} + Symbol(SymbolKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags) + : Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {} + void addTarget(Target target) { Targets.emplace_back(target); } SymbolKind getKind() const { return Kind; } StringRef getName() const { return Name; } - ArchitectureSet getArchitectures() const { return Architectures; } - void addArchitectures(ArchitectureSet Archs) { Architectures |= Archs; } + ArchitectureSet getArchitectures() const { + return mapToArchitectureSet(Targets); + } SymbolFlags getFlags() const { return Flags; } bool isWeakDefined() const { @@ -78,6 +84,21 @@ public: return (Flags & SymbolFlags::Undefined) == SymbolFlags::Undefined; } + bool isReexported() const { + return (Flags & SymbolFlags::Rexported) == SymbolFlags::Rexported; + } + + using const_target_iterator = TargetList::const_iterator; + using const_target_range = llvm::iterator_range<const_target_iterator>; + const_target_range targets() const { return {Targets}; } + + 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 architectures) const; + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void dump(raw_ostream &OS) const; void dump() const { dump(llvm::errs()); } @@ -85,7 +106,7 @@ public: private: StringRef Name; - ArchitectureSet Architectures; + TargetList Targets; SymbolKind Kind; SymbolFlags Flags; }; diff --git a/include/llvm/TextAPI/MachO/Target.h b/include/llvm/TextAPI/MachO/Target.h new file mode 100644 index 000000000000..5fe44cb7d366 --- /dev/null +++ b/include/llvm/TextAPI/MachO/Target.h @@ -0,0 +1,68 @@ +//===- llvm/TextAPI/Target.h - TAPI Target ----------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TEXTAPI_MACHO_TARGET_H +#define LLVM_TEXTAPI_MACHO_TARGET_H + +#include "llvm/ADT/Triple.h" +#include "llvm/Support/Error.h" +#include "llvm/TextAPI/MachO/Architecture.h" +#include "llvm/TextAPI/MachO/ArchitectureSet.h" +#include "llvm/TextAPI/MachO/Platform.h" + +namespace llvm { +namespace MachO { + +// This is similar to a llvm Triple, but the triple doesn't have all the +// information we need. For example there is no enum value for x86_64h. The +// only way to get that information is to parse the triple string. +class Target { +public: + Target() = default; + Target(Architecture Arch, PlatformKind Platform) + : Arch(Arch), Platform(Platform) {} + explicit Target(const llvm::Triple &Triple) + : Arch(mapToArchitecture(Triple)), Platform(mapToPlatformKind(Triple)) {} + + static llvm::Expected<Target> create(StringRef Target); + + operator std::string() const; + + Architecture Arch; + PlatformKind Platform; +}; + +inline bool operator==(const Target &LHS, const Target &RHS) { + return std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform); +} + +inline bool operator!=(const Target &LHS, const Target &RHS) { + return std::tie(LHS.Arch, LHS.Platform) != std::tie(RHS.Arch, RHS.Platform); +} + +inline bool operator<(const Target &LHS, const Target &RHS) { + return std::tie(LHS.Arch, LHS.Platform) < std::tie(RHS.Arch, RHS.Platform); +} + +inline bool operator==(const Target &LHS, const Architecture &RHS) { + return LHS.Arch == RHS; +} + +inline bool operator!=(const Target &LHS, const Architecture &RHS) { + return LHS.Arch != RHS; +} + +PlatformSet mapToPlatformSet(ArrayRef<Target> Targets); +ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets); + +raw_ostream &operator<<(raw_ostream &OS, const Target &Target); + +} // namespace MachO +} // namespace llvm + +#endif // LLVM_TEXTAPI_MACHO_TARGET_H diff --git a/include/llvm/TextAPI/MachO/TextAPIReader.h b/include/llvm/TextAPI/MachO/TextAPIReader.h index 6d9c09de5294..c551f0454e8e 100644 --- a/include/llvm/TextAPI/MachO/TextAPIReader.h +++ b/include/llvm/TextAPI/MachO/TextAPIReader.h @@ -20,10 +20,7 @@ class InterfaceFile; class TextAPIReader { public: static Expected<std::unique_ptr<InterfaceFile>> - get(std::unique_ptr<MemoryBuffer> InputBuffer); - - static Expected<std::unique_ptr<InterfaceFile>> - getUnmanaged(llvm::MemoryBuffer *InputBuffer); + get(MemoryBufferRef InputBuffer); TextAPIReader() = delete; }; |