LLVM  10.0.0svn
InterfaceFile.cpp
Go to the documentation of this file.
1 //===- InterfaceFile.cpp --------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implements the Interface File.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include <iomanip>
15 #include <sstream>
16 
17 namespace llvm {
18 namespace MachO {
19 namespace detail {
20 template <typename C>
21 typename C::iterator addEntry(C &Container, StringRef InstallName) {
22  auto I = partition_point(Container, [=](const InterfaceFileRef &O) {
23  return O.getInstallName() < InstallName;
24  });
25  if (I != Container.end() && I->getInstallName() == InstallName)
26  return I;
27 
28  return Container.emplace(I, InstallName);
29 }
30 
31 template <typename C>
32 typename C::iterator addEntry(C &Container, const Target &Target_) {
33  auto Iter =
34  lower_bound(Container, Target_, [](const Target &LHS, const Target &RHS) {
35  return LHS < RHS;
36  });
37  if ((Iter != std::end(Container)) && !(Target_ < *Iter))
38  return Iter;
39 
40  return Container.insert(Iter, Target_);
41 }
42 } // end namespace detail.
43 
45  detail::addEntry(Targets, Target);
46 }
47 
49  const Target &Target) {
50  auto Client = detail::addEntry(AllowableClients, InstallName);
51  Client->addTarget(Target);
52 }
53 
55  const Target &Target) {
56  auto Lib = detail::addEntry(ReexportedLibraries, InstallName);
57  Lib->addTarget(Target);
58 }
59 
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; });
64 
65  if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) {
66  Iter->second = Parent;
67  return;
68  }
69 
70  ParentUmbrellas.emplace(Iter, Target_, Parent);
71  return;
72 }
73 
75  auto Iter = lower_bound(UUIDs, Target_,
76  [](const std::pair<Target, std::string> &LHS,
77  Target RHS) { return LHS.first < RHS; });
78 
79  if ((Iter != UUIDs.end()) && !(Target_ < Iter->first)) {
80  Iter->second = UUID;
81  return;
82  }
83 
84  UUIDs.emplace(Iter, Target_, UUID);
85  return;
86 }
87 
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)
92  Stream << '-';
93  Stream << std::setfill('0') << std::setw(2) << std::uppercase << std::hex
94  << static_cast<int>(UUID[i]);
95  }
96  addUUID(Target, Stream.str());
97 }
98 
100  detail::addEntry(Targets, Target);
101 }
102 
105  std::function<bool(const Target &)> fn = [Archs](const Target &Target_) {
106  return Archs.has(Target_.Arch);
107  };
108  return make_filter_range(Targets, fn);
109 }
110 
112  const TargetList &Targets, SymbolFlags Flags) {
113  Name = copyString(Name);
114  auto result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
115  if (result.second)
116  result.first->second = new (Allocator) Symbol{Kind, Name, Targets, Flags};
117  else
118  for (const auto &Target : Targets)
119  result.first->second->addTarget(Target);
120 }
121 
122 } // end namespace MachO.
123 } // end namespace llvm.
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1261
uint64_t CallInst * C
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
bool has(Architecture Arch) const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void addSymbol(SymbolKind Kind, StringRef Name, const TargetList &Targets, SymbolFlags Flags=SymbolFlags::None)
Add a symbol to the symbols list or extend an existing one.
void addUUID(const Target &Target, StringRef UUID)
Add an Target/UUID pair.
Reference to an interface file.
Definition: InterfaceFile.h:81
C::iterator addEntry(C &Container, StringRef InstallName)
void addParentUmbrella(const Target &Target_, StringRef Parent)
Set the parent umbrella frameworks.
void addReexportedLibrary(StringRef InstallName, const Target &Target)
Add a re-exported library.
StringRef getInstallName() const
Definition: InterfaceFile.h:90
SymbolFlags
Symbol flags.
Definition: Symbol.h:25
void addAllowableClient(StringRef InstallName, const Target &Target)
Add an allowable client.
auto partition_point(R &&Range, Predicate P) -> decltype(adl_begin(Range))
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:1302
unsigned first
Basic Register Allocator
const_target_range targets() const
std::pair< llvm::MachO::Target, std::string > UUID
void addTarget(const Target &Target)
A range adaptor for a pair of iterators.
#define I(x, y, z)
Definition: MD5.cpp:58
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...
Definition: STLExtras.h:422
void addTarget(const Target &Target)
Set and add target.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48