LLVM: lib/TextAPI/InterfaceFile.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
16#include
17#include
18
19using namespace llvm;
21
24}
25
28 if (InstallName.empty())
29 return;
30 auto Client = addEntry(AllowableClients, InstallName);
31 Client->addTarget(Target);
32}
33
36 if (InstallName.empty())
37 return;
38 auto Lib = addEntry(ReexportedLibraries, InstallName);
40}
41
43 if (Parent.empty())
44 return;
45 auto Iter = lower_bound(ParentUmbrellas, Target_,
46 [](const std::pair<Target, std::string> &LHS,
48
49 if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) {
50 Iter->second = std::string(Parent);
51 return;
52 }
53
54 ParentUmbrellas.emplace(Iter, Target_, std::string(Parent));
55}
56
58 if (RPath.empty())
59 return;
60 using RPathEntryT = const std::pair<Target, std::string>;
61 RPathEntryT Entry(InputTarget, RPath);
62 auto Iter =
64 [](RPathEntryT &LHS, RPathEntryT &RHS) { return LHS < RHS; });
65
66 if ((Iter != RPaths.end()) && (*Iter == Entry))
67 return;
68
69 RPaths.emplace(Iter, Entry);
70}
71
74}
75
78 std::function<bool(const Target &)> fn = [Archs](const Target &Target_) {
79 return Archs.has(Target_.Arch);
80 };
82}
83
86 [](const std::shared_ptr &LHS,
87 const std::shared_ptr &RHS) {
88 return LHS->InstallName < RHS->InstallName;
89 });
90 assert((Pos == Documents.end() ||
91 (*Pos)->InstallName != Document->InstallName) &&
92 "Unexpected duplicate document added");
93 Document->Parent = this;
94 Documents.insert(Pos, Document);
95}
96
98 bool Overwrite) {
99 auto AddFwk = [&](std::shared_ptr &&Reexport) {
101 Documents, Reexport->getInstallName(),
102 [](std::shared_ptr &Lhs, const StringRef Rhs) {
103 return Lhs->getInstallName() < Rhs;
104 });
105
106 if (Overwrite && It != Documents.end() &&
107 Reexport->getInstallName() == (*It)->getInstallName()) {
108 std::replace(Documents.begin(), Documents.end(), *It,
109 std::move(Reexport));
110 return;
111 }
112
113 if ((It != Documents.end()) &&
114 !(Reexport->getInstallName() < (*It)->getInstallName()))
115 return;
116
117 Documents.emplace(It, std::move(Reexport));
118 };
119 for (auto Doc : Library->documents())
120 AddFwk(std::move(Doc));
121
122 Library->Documents.clear();
123 AddFwk(std::move(Library));
124}
125
128
130 return make_error("install names do not match",
132 }
133
135 return make_error("current versions do not match",
137 }
138
140 return make_error("compatibility versions do not match",
142 }
143
146 return make_error("swift ABI versions do not match",
148 }
149
151 return make_error("two level namespace flags do not match",
153 }
154
156 return make_error(
157 "application extension safe flags do not match",
159 }
160
161 std::unique_ptr IF(new InterfaceFile());
162 IF->setFileType(std::max(getFileType(), O->getFileType()));
167
169 IF->setSwiftABIVersion(O->getSwiftABIVersion());
170 else
172
176
177 for (const auto &It : umbrellas()) {
178 if (!It.second.empty())
179 IF->addParentUmbrella(It.first, It.second);
180 }
181 for (const auto &It : O->umbrellas()) {
182 if (!It.second.empty())
183 IF->addParentUmbrella(It.first, It.second);
184 }
185 IF->addTargets(targets());
186 IF->addTargets(O->targets());
187
189 for (const auto &Target : Lib.targets())
190 IF->addAllowableClient(Lib.getInstallName(), Target);
191
192 for (const auto &Lib : O->allowableClients())
193 for (const auto &Target : Lib.targets())
194 IF->addAllowableClient(Lib.getInstallName(), Target);
195
197 for (const auto &Target : Lib.targets())
198 IF->addReexportedLibrary(Lib.getInstallName(), Target);
199
200 for (const auto &Lib : O->reexportedLibraries())
201 for (const auto &Target : Lib.targets())
202 IF->addReexportedLibrary(Lib.getInstallName(), Target);
203
205 IF->addRPath(Path, Target);
206 for (const auto &[Target, Path] : O->rpaths())
207 IF->addRPath(Path, Target);
208
212 }
213
214 for (const auto *Sym : O->symbols()) {
217 }
218
219 return std::move(IF);
220}
221
225 return make_error("cannot remove last architecture slice '" +
228
230 bool Found = false;
231 for (auto &Doc : Documents) {
232 if (Doc->getArchitectures().has(Arch)) {
233 Found = true;
234 break;
235 }
236 }
237
238 if (!Found)
240 }
241
242
243
244 std::unique_ptr IF(new InterfaceFile());
255 for (const auto &It : umbrellas())
256 if (It.first.Arch != Arch)
257 IF->addParentUmbrella(It.first, It.second);
258
260 for (const auto &Target : Lib.targets())
262 IF->addAllowableClient(Lib.getInstallName(), Target);
263 }
264
266 for (const auto &Target : Lib.targets())
268 IF->addReexportedLibrary(Lib.getInstallName(), Target);
269 }
270
273 Archs.clear(Arch);
274 if (Archs.empty())
275 continue;
276
279 }
280
281 for (auto &Doc : Documents) {
282
283
284 if (Doc->getArchitectures() == Arch)
285 continue;
286
287
288
289 if (!Doc->getArchitectures().has(Arch)) {
290 auto NewDoc = Doc;
291 IF->addDocument(std::move(NewDoc));
292 continue;
293 }
294
295 auto Result = Doc->remove(Arch);
296 if (!Result)
297 return Result;
298
299 IF->addDocument(std::move(Result.get()));
300 }
301
302 return std::move(IF);
303}
304
308 return make_error("file doesn't have architecture '" +
311 }
312
313 std::unique_ptr IF(new InterfaceFile());
316 IF->addTargets(targets(Arch));
324 for (const auto &It : umbrellas())
325 if (It.first.Arch == Arch)
326 IF->addParentUmbrella(It.first, It.second);
327
328 for (const auto &It : rpaths())
329 if (It.first.Arch == Arch)
330 IF->addRPath(It.second, It.first);
331
333 for (const auto &Target : Lib.targets())
335 IF->addAllowableClient(Lib.getInstallName(), Target);
336
338 for (const auto &Target : Lib.targets())
340 IF->addReexportedLibrary(Lib.getInstallName(), Target);
341
346 }
347
348 for (auto &Doc : Documents) {
349
350 if (!Doc->getArchitectures().has(Arch))
351 continue;
352
353 auto Result = Doc->extract(Arch);
354 if (!Result)
355 return Result;
356
357 IF->addDocument(std::move(Result.get()));
358 }
359
360 return std::move(IF);
361}
362
364 const Target &Targ) {
389}
390
393}
394
396 if (Targets != O.Targets)
397 return false;
398 if (InstallName != O.InstallName)
399 return false;
400 if ((CurrentVersion != O.CurrentVersion) ||
401 (CompatibilityVersion != O.CompatibilityVersion))
402 return false;
403 if (SwiftABIVersion != O.SwiftABIVersion)
404 return false;
405 if (IsTwoLevelNamespace != O.IsTwoLevelNamespace)
406 return false;
407 if (IsAppExtensionSafe != O.IsAppExtensionSafe)
408 return false;
409 if (IsOSLibNotForSharedCache != O.IsOSLibNotForSharedCache)
410 return false;
411 if (HasSimSupport != O.HasSimSupport)
412 return false;
413 if (ParentUmbrellas != O.ParentUmbrellas)
414 return false;
415 if (AllowableClients != O.AllowableClients)
416 return false;
417 if (ReexportedLibraries != O.ReexportedLibraries)
418 return false;
419 if (*SymbolsSet != *O.SymbolsSet)
420 return false;
421
422
424 if (RPaths != O.RPaths)
425 return false;
427 return false;
428 }
429
430 if (!std::equal(Documents.begin(), Documents.end(), O.Documents.begin(),
431 O.Documents.end(),
432 [](const std::shared_ptr LHS,
433 const std::shared_ptr RHS) {
434 return *LHS == *RHS;
435 }))
436 return false;
437 return true;
438}
static bool isYAMLTextStub(const FileType &Kind)
Implements the TAPI Record Collection Type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Define TAPI specific error codes.
Tagged union holding either a T or a Error.
static ArchitectureSet All()
ArchitectureSet clear(Architecture Arch)
bool has(Architecture Arch) const
void addTarget(const Target &Target)
Defines the interface 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.
llvm::Expected< std::unique_ptr< InterfaceFile > > remove(Architecture Arch) const
Remove architecture slice from Interface.
bool isTwoLevelNamespace() const
Check if the library uses two-level namespace.
bool operator==(const InterfaceFile &O) const
The equality is determined by attributes that impact linking compatibilities.
PackedVersion getCompatibilityVersion() const
Get the compatibility version of the library.
void addTarget(const Target &Target)
Set and add target.
bool isApplicationExtensionSafe() const
Check if the library is application extension safe.
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 setInstallName(StringRef InstallName_)
Set the install name of the library.
const std::vector< std::pair< Target, std::string > > & umbrellas() const
Get the list of Parent Umbrella frameworks.
const std::vector< InterfaceFileRef > & reexportedLibraries() const
Get the list of re-exported libraries.
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 addRPath(StringRef RPath, const Target &InputTarget)
Set the runpath search paths.
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.
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.
void setSwiftABIVersion(uint8_t Version)
Set the Swift ABI version of the library.
void setCurrentVersion(PackedVersion Version)
Set the current version of the library.
llvm::Expected< std::unique_ptr< InterfaceFile > > extract(Architecture Arch) const
Extract architecture slice from Interface.
void setTwoLevelNamespace(bool V=true)
Specify if the library uses two-level namespace (or flat namespace).
SymbolFlags getFlags() const
bool hasArchitecture(Architecture Arch) const
const_target_range targets() const
ArchitectureSet getArchitectures() const
StringRef getName() const
EncodeKind getKind() const
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
A range adaptor for a pair of iterators.
FileType
Defines the file type TextAPI files can represent.
@ TBD_V1
Text-based stub file (.tbd) version 1.0.
@ TBD_V5
Text-based stub file (.tbd) version 5.0.
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
C::iterator addEntry(C &Container, StringRef InstallName)
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
PlatformVersionSet mapToPlatformVersionSet(ArrayRef< Target > Targets)
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
std::vector< StringRef > RexportedLibraries
std::vector< StringRef > AllowableClients
llvm::MachO::PackedVersion CompatVersion
llvm::MachO::PackedVersion CurrentVersion
bool OSLibNotForSharedCache