1//===- llvm/TextAPI/InterfaceFile.h - TAPI Interface File -------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// A generic and abstract interface representation for linkable objects. This 10// could be an MachO executable, bundle, dylib, or text-based stub file. 12//===----------------------------------------------------------------------===// 14#ifndef LLVM_TEXTAPI_INTERFACEFILE_H 15#define LLVM_TEXTAPI_INTERFACEFILE_H 33/// Defines a list of Objective-C constraints. 41 /// Retain/Release for Simulator. 44 /// Retain/Release or Garbage Collection. 47 /// Garbage Collection. 51/// Reference to an interface file. 59 : InstallName(InstallName), Targets(
std::
move(Targets)) {}
64template <
typename RangeT>
voidaddTargets(RangeT &&Targets) {
65for (
constauto &
Target : Targets)
84return std::tie(InstallName, Targets) == std::tie(O.InstallName, O.Targets);
88return std::tie(InstallName, Targets) != std::tie(O.InstallName, O.Targets);
92return std::tie(InstallName, Targets) < std::tie(O.InstallName, O.Targets);
96 std::string InstallName;
100}
// end namespace MachO. 104/// Defines the interface file. 108 : SymbolsSet(
std::
move(InputSymbols)) {}
111 /// Set the path from which this file was generated (if applicable). 113 /// \param Path_ The path to the source file. 116 /// Get the path from which this file was generated (if applicable). 118 /// \return The path to the source file or empty. 121 /// Set the file type. 123 /// This is used by the YAML writer to identify the specification it should 124 /// use for writing the file. 126 /// \param Kind The file type. 129 /// Get the file type. 131 /// \return The file type. 134 /// Get the architectures. 136 /// \return The applicable architectures. 141 /// Get the platforms. 143 /// \return The applicable platforms. 146 /// Set and add target. 148 /// \param Target the target to add into. 151 /// Determine if target triple slice exists in file. 153 /// \param Targ the value to find. 158 /// Set and add targets. 160 /// Add the subset of llvm::triples that is supported by Tapi 162 /// \param Targets the collection of targets. 164for (
constauto &Target_ : Targets)
179 /// Set the install name of the library. 181 InstallName = std::string(InstallName_);
184 /// Get the install name of the library. 187 /// Set the current version of the library. 190 /// Get the current version of the library. 193 /// Set the compatibility version of the library. 198 /// Get the compatibility version of the library. 201 /// Set the Swift ABI version of the library. 204 /// Get the Swift ABI version of the library. 207 /// Specify if the library uses two-level namespace (or flat namespace). 210 /// Check if the library uses two-level namespace. 213 /// Specify if the library is an OS library but not shared cache eligible. 215 IsOSLibNotForSharedCache = V;
218 /// Check if the library is an OS library that is not shared cache eligible. 221 /// Specify if the library is application extension safe (or not). 224 /// Check if the library is application extension safe. 227 /// Check if the library has simulator support. 230 /// Specify if the library has simulator support. 233 /// Set the Objective-C constraint. 235 ObjcConstraint = Constraint;
238 /// Get the Objective-C constraint. 241 /// Set the parent umbrella frameworks. 242 /// \param Target_ The target applicable to Parent 243 /// \param Parent The name of Parent 246 /// Get the list of Parent Umbrella frameworks. 248 /// \return Returns a list of target information and install name of parent 250const std::vector<std::pair<Target, std::string>> &
umbrellas()
const{
251return ParentUmbrellas;
254 /// Add an allowable client. 256 /// Mach-O Dynamic libraries have the concept of allowable clients that are 257 /// checked during static link time. The name of the application or library 258 /// that is being generated needs to match one of the allowable clients or the 259 /// linker refuses to link this library. 261 /// \param InstallName The name of the client that is allowed to link this 263 /// \param Target The target triple for which this applies. 266 /// Get the list of allowable clients. 268 /// \return Returns a list of allowable clients. 270return AllowableClients;
273 /// Add a re-exported library. 275 /// \param InstallName The name of the library to re-export. 276 /// \param Target The target triple for which this applies. 279 /// Get the list of re-exported libraries. 281 /// \return Returns a list of re-exported libraries. 283return ReexportedLibraries;
286 /// Add a library for inlining to top level library. 288 ///\param Document The library to inline with top level library. 289voidaddDocument(std::shared_ptr<InterfaceFile> &&Document);
291 /// Returns the pointer to parent document if exists or nullptr otherwise. 294 /// Get the list of inlined libraries. 296 /// \return Returns a list of the inlined frameworks. 297const std::vector<std::shared_ptr<InterfaceFile>> &
documents()
const{
301 /// Set the runpath search paths. 302 /// \param RPath The name of runpath. 303 /// \param InputTarget The target applicable to runpath search path. 306 /// Get the list of runpath search paths. 308 /// \return Returns a list of the rpaths per target. 309const std::vector<std::pair<Target, std::string>> &
rpaths()
const{
313 /// Get symbol if exists in file. 315 /// \param Kind The kind of global symbol to record. 316 /// \param Name The name of the symbol. 317 /// \param ObjCIF The ObjCInterface symbol type, if applicable. 318 std::optional<const Symbol *>
321if (
auto *
Sym = SymbolsSet->findSymbol(Kind,
Name, ObjCIF))
326 /// Add a symbol to the symbols list or extend an existing one. 327template <
typename RangeT,
typename ElT = std::remove_reference_t<
328decltype(*std::begin(std::declval<RangeT>()))>>
331 SymbolsSet->addGlobal(Kind,
Name, Flags, Targets);
334 /// Add Symbol with multiple targets. 336 /// \param Kind The kind of global symbol to record. 337 /// \param Name The name of the symbol. 338 /// \param Targets The list of targets the symbol is defined in. 339 /// \param Flags The properties the symbol holds. 342 SymbolsSet->addGlobal(Kind,
Name, Flags, Targets);
345 /// Add Symbol with single target. 347 /// \param Kind The kind of global symbol to record. 348 /// \param Name The name of the symbol. 349 /// \param Target The target the symbol is defined in. 350 /// \param Flags The properties the symbol holds. 353 SymbolsSet->addGlobal(Kind,
Name, Flags,
Target);
356 /// Get size of symbol set. 357 /// \return The number of symbols the file holds. 366return SymbolsSet->reexports();
369return SymbolsSet->undefineds();
372 /// Extract architecture slice from Interface. 374 /// \param Arch architecture to extract from. 375 /// \return New InterfaceFile with extracted architecture slice. 379 /// Remove architecture slice from Interface. 381 /// \param Arch architecture to remove. 382 /// \return New Interface File with removed architecture slice. 386 /// Merge Interfaces for the same library. The following library attributes 388 /// * Install name, Current & Compatibility version, 389 /// * Two-level namespace enablement, and App extension enablement. 391 /// \param O The Interface to merge. 392 /// \return New Interface File that was merged. 396 /// Inline reexported library into Interface. 398 /// \param Library Interface of reexported library. 399 /// \param Overwrite Whether to overwrite preexisting inlined library. 401bool Overwrite =
false);
403 /// Set InterfaceFile properties from pre-gathered binary attributes, 404 /// if they are not set already. 406 /// \param BA Attributes typically represented in load commands. 407 /// \param Targ MachO Target slice to add attributes to. 411 /// The equality is determined by attributes that impact linking 412 /// compatibilities. Path, & FileKind are irrelevant since these by 413 /// itself should not impact linking. 414 /// This is an expensive operation. 433 std::string InstallName;
434 PackedVersion CurrentVersion;
435 PackedVersion CompatibilityVersion;
437bool IsTwoLevelNamespace{
false};
438bool IsOSLibNotForSharedCache{
false};
439bool IsAppExtensionSafe{
false};
440bool HasSimSupport{
false};
442 std::vector<std::pair<Target, std::string>> ParentUmbrellas;
443 std::vector<InterfaceFileRef> AllowableClients;
444 std::vector<InterfaceFileRef> ReexportedLibraries;
445 std::vector<std::shared_ptr<InterfaceFile>> Documents;
446 std::vector<std::pair<Target, std::string>> RPaths;
447 std::unique_ptr<SymbolSet> SymbolsSet;
451// Keep containers that hold InterfaceFileRefs in sorted order and uniqued. 455return O.getInstallName() < InstallName;
457if (
I != Container.end() &&
I->getInstallName() == InstallName)
460return Container.emplace(
I, InstallName);
463}
// end namespace MachO. 464}
// end namespace llvm. 466#endif// LLVM_TEXTAPI_INTERFACEFILE_H This file defines the BumpPtrAllocator interface.
Implements the TAPI Record Collection Type.
Allocate memory in an ever growing pool, as if by bump-pointer.
Tagged union holding either a T or a Error.
Reference to an interface file.
InterfaceFileRef(StringRef InstallName, const TargetList Targets)
bool hasTarget(Target &Targ) const
bool operator!=(const InterfaceFileRef &O) const
void addTargets(RangeT &&Targets)
PlatformSet getPlatforms() const
void addTarget(const Target &Target)
const_target_range targets() const
StringRef getInstallName() const
bool operator==(const InterfaceFileRef &O) const
ArchitectureSet getArchitectures() const
InterfaceFileRef(StringRef InstallName)
InterfaceFileRef()=default
bool operator<(const InterfaceFileRef &O) const
Defines the interface file.
std::optional< const Symbol * > getSymbol(EncodeKind Kind, StringRef Name, ObjCIFSymbolKind ObjCIF=ObjCIFSymbolKind::None) const
Get symbol if exists in file.
void addDocument(std::shared_ptr< InterfaceFile > &&Document)
Add a library for inlining to top level library.
StringRef getPath() const
Get the path from which this file was generated (if applicable).
void addReexportedLibrary(StringRef InstallName, const Target &Target)
Add a re-exported library.
void setPath(StringRef Path_)
Set the path from which this file was generated (if applicable).
void setFromBinaryAttrs(const RecordsSlice::BinaryAttrs &BA, const Target &Targ)
Set InterfaceFile properties from pre-gathered binary attributes, if they are not set already.
void addParentUmbrella(const Target &Target_, StringRef Parent)
Set the parent umbrella frameworks.
const_target_range targets() const
void setOSLibNotForSharedCache(bool V=true)
Specify if the library is an OS library but not shared cache eligible.
bool isOSLibNotForSharedCache() const
Check if the library is an OS library that is not shared cache eligible.
const_filtered_symbol_range reexports() const
llvm::Expected< std::unique_ptr< InterfaceFile > > remove(Architecture Arch) const
Remove architecture slice from Interface.
void setObjCConstraint(ObjCConstraintType Constraint)
Set the Objective-C constraint.
bool isTwoLevelNamespace() const
Check if the library uses two-level namespace.
PackedVersion getCompatibilityVersion() const
Get the compatibility version of the library.
size_t symbolsCount() const
Get size of symbol set.
bool operator!=(const InterfaceFile &O) const
void addTarget(const Target &Target)
Set and add target.
const_filtered_symbol_range exports() const
bool isApplicationExtensionSafe() const
Check if the library is application extension safe.
void addSymbol(EncodeKind Kind, StringRef Name, TargetList &&Targets, SymbolFlags Flags=SymbolFlags::None)
Add Symbol with multiple targets.
void setSimulatorSupport(bool V=true)
Specify if the library has simulator support.
PlatformSet getPlatforms() const
Get the platforms.
const std::vector< std::pair< Target, std::string > > & rpaths() const
Get the list of runpath search paths.
const std::vector< InterfaceFileRef > & allowableClients() const
Get the list of allowable clients.
void addSymbol(EncodeKind Kind, StringRef Name, RangeT &&Targets, SymbolFlags Flags=SymbolFlags::None)
Add a symbol to the symbols list or extend an existing one.
void setInstallName(StringRef InstallName_)
Set the install name of the library.
void addTargets(RangeT &&Targets)
Set and add targets.
const std::vector< std::shared_ptr< InterfaceFile > > & documents() const
Get the list of inlined libraries.
const std::vector< std::pair< Target, std::string > > & umbrellas() const
Get the list of Parent Umbrella frameworks.
InterfaceFile(std::unique_ptr< SymbolSet > &&InputSymbols)
const std::vector< InterfaceFileRef > & reexportedLibraries() const
Get the list of re-exported libraries.
InterfaceFile * getParent() const
Returns the pointer to parent document if exists or nullptr otherwise.
const_symbol_range symbols() const
void setFileType(FileType Kind)
Set the file type.
uint8_t getSwiftABIVersion() const
Get the Swift ABI version of the library.
PackedVersion getCurrentVersion() const
Get the current version of the library.
void addSymbol(EncodeKind Kind, StringRef Name, Target &Target, SymbolFlags Flags=SymbolFlags::None)
Add Symbol with single target.
void addRPath(StringRef RPath, const Target &InputTarget)
Set the runpath search paths.
const_filtered_symbol_range undefineds() const
void setCompatibilityVersion(PackedVersion Version)
Set the compatibility version of the library.
ArchitectureSet getArchitectures() const
Get the architectures.
StringRef getInstallName() const
Get the install name of the library.
llvm::Expected< std::unique_ptr< InterfaceFile > > merge(const InterfaceFile *O) const
Merge Interfaces for the same library.
ObjCConstraintType getObjCConstraint() const
Get the Objective-C constraint.
FileType getFileType() const
Get the file type.
void setApplicationExtensionSafe(bool V=true)
Specify if the library is application extension safe (or not).
void addAllowableClient(StringRef InstallName, const Target &Target)
Add an allowable client.
void inlineLibrary(std::shared_ptr< InterfaceFile > Library, bool Overwrite=false)
Inline reexported library into Interface.
bool hasTarget(const Target &Targ) const
Determine if target triple slice exists in file.
void setSwiftABIVersion(uint8_t Version)
Set the Swift ABI version of the library.
void setCurrentVersion(PackedVersion Version)
Set the current version of the library.
TargetList::const_iterator const_target_iterator
void setTwoLevelNamespace(bool V=true)
Specify if the library uses two-level namespace (or flat namespace).
bool hasSimulatorSupport() const
Check if the library has simulator support.
iterator_range< const_symbol_iterator > const_symbol_range
iterator_range< const_filtered_symbol_iterator > const_filtered_symbol_range
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
StringRef - Represent a constant reference to a string, i.e.
Specialization of filter_iterator_base for forward iteration only.
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
FileType
Defines the file type TextAPI files can represent.
@ Invalid
Invalid file type.
C::iterator addEntry(C &Container, StringRef InstallName)
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
ObjCConstraintType
Defines a list of Objective-C constraints.
@ Retain_Release_For_Simulator
Retain/Release for Simulator.
@ Retain_Release_Or_GC
Retain/Release or Garbage Collection.
@ Retain_Release
Retain/Release.
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
SmallVector< Target, 5 > TargetList
ObjCIFSymbolKind
ObjC Interface symbol mappings.
EncodeKind
Mapping of entry types in TextStubs.
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
This is an optimization pass for GlobalISel generic memory operations.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Implement std::hash so that hash_code can be used in STL containers.