1 //===- InterfaceFile.cpp --------------------------------------------------===//
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 // Implements the Interface File.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/MachO/InterfaceFile.h"
21 typename
C::iterator
addEntry(C
&Container
, StringRef InstallName
) {
22 auto I
= partition_point(Container
, [=](const InterfaceFileRef
&O
) {
23 return O
.getInstallName() < InstallName
;
25 if (I
!= Container
.end() && I
->getInstallName() == InstallName
)
28 return Container
.emplace(I
, InstallName
);
32 typename
C::iterator
addEntry(C
&Container
, const Target
&Target_
) {
34 lower_bound(Container
, Target_
, [](const Target
&LHS
, const Target
&RHS
) {
37 if ((Iter
!= std::end(Container
)) && !(Target_
< *Iter
))
40 return Container
.insert(Iter
, Target_
);
42 } // end namespace detail.
44 void InterfaceFileRef::addTarget(const Target
&Target
) {
45 detail::addEntry(Targets
, Target
);
48 void InterfaceFile::addAllowableClient(StringRef InstallName
,
49 const Target
&Target
) {
50 auto Client
= detail::addEntry(AllowableClients
, InstallName
);
51 Client
->addTarget(Target
);
54 void InterfaceFile::addReexportedLibrary(StringRef InstallName
,
55 const Target
&Target
) {
56 auto Lib
= detail::addEntry(ReexportedLibraries
, InstallName
);
57 Lib
->addTarget(Target
);
60 void InterfaceFile::addParentUmbrella(const Target
&Target_
, StringRef Parent
) {
61 auto Iter
= lower_bound(ParentUmbrellas
, Target_
,
62 [](const std::pair
<Target
, std::string
> &LHS
,
63 Target RHS
) { return LHS
.first
< RHS
; });
65 if ((Iter
!= ParentUmbrellas
.end()) && !(Target_
< Iter
->first
)) {
66 Iter
->second
= Parent
;
70 ParentUmbrellas
.emplace(Iter
, Target_
, Parent
);
74 void InterfaceFile::addUUID(const Target
&Target_
, StringRef UUID
) {
75 auto Iter
= lower_bound(UUIDs
, Target_
,
76 [](const std::pair
<Target
, std::string
> &LHS
,
77 Target RHS
) { return LHS
.first
< RHS
; });
79 if ((Iter
!= UUIDs
.end()) && !(Target_
< Iter
->first
)) {
84 UUIDs
.emplace(Iter
, Target_
, UUID
);
88 void InterfaceFile::addUUID(const Target
&Target
, uint8_t UUID
[16]) {
89 std::stringstream Stream
;
90 for (unsigned i
= 0; i
< 16; ++i
) {
91 if (i
== 4 || i
== 6 || i
== 8 || i
== 10)
93 Stream
<< std::setfill('0') << std::setw(2) << std::uppercase
<< std::hex
94 << static_cast<int>(UUID
[i
]);
96 addUUID(Target
, Stream
.str());
99 void InterfaceFile::addTarget(const Target
&Target
) {
100 detail::addEntry(Targets
, Target
);
103 InterfaceFile::const_filtered_target_range
104 InterfaceFile::targets(ArchitectureSet Archs
) const {
105 std::function
<bool(const Target
&)> fn
= [Archs
](const Target
&Target_
) {
106 return Archs
.has(Target_
.Arch
);
108 return make_filter_range(Targets
, fn
);
111 void InterfaceFile::addSymbol(SymbolKind Kind
, StringRef Name
,
112 const TargetList
&Targets
, SymbolFlags Flags
) {
113 Name
= copyString(Name
);
114 auto result
= Symbols
.try_emplace(SymbolsMapKey
{Kind
, Name
}, nullptr);
116 result
.first
->second
= new (Allocator
) Symbol
{Kind
, Name
, Targets
, Flags
};
118 for (const auto &Target
: Targets
)
119 result
.first
->second
->addTarget(Target
);
122 } // end namespace MachO.
123 } // end namespace llvm.