LLVM  9.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 using namespace llvm::MachO;
18 
19 namespace llvm {
20 namespace MachO {
21 namespace detail {
22 template <typename C>
23 typename C::iterator addEntry(C &Container, StringRef InstallName) {
24  auto I =
25  std::lower_bound(std::begin(Container), std::end(Container), InstallName,
26  [](const InterfaceFileRef &LHS, const StringRef &RHS) {
27  return LHS.getInstallName() < RHS;
28  });
29  if ((I != std::end(Container)) && !(InstallName < I->getInstallName()))
30  return I;
31 
32  return Container.emplace(I, InstallName);
33 }
34 } // end namespace detail.
35 
37  ArchitectureSet Architectures) {
38  auto Client = detail::addEntry(AllowableClients, Name);
39  Client->addArchitectures(Architectures);
40 }
41 
43  ArchitectureSet Architectures) {
44  auto Lib = detail::addEntry(ReexportedLibraries, InstallName);
45  Lib->addArchitectures(Architectures);
46 }
47 
49  auto I = std::lower_bound(UUIDs.begin(), UUIDs.end(), Arch,
50  [](const std::pair<Architecture, std::string> &LHS,
51  Architecture RHS) { return LHS.first < RHS; });
52 
53  if ((I != UUIDs.end()) && !(Arch < I->first)) {
54  I->second = UUID;
55  return;
56  }
57 
58  UUIDs.emplace(I, Arch, UUID);
59  return;
60 }
61 
62 void InterfaceFile::addUUID(Architecture Arch, uint8_t UUID[16]) {
63  std::stringstream Stream;
64  for (unsigned i = 0; i < 16; ++i) {
65  if (i == 4 || i == 6 || i == 8 || i == 10)
66  Stream << '-';
67  Stream << std::setfill('0') << std::setw(2) << std::uppercase << std::hex
68  << static_cast<int>(UUID[i]);
69  }
70  addUUID(Arch, Stream.str());
71 }
72 
74  ArchitectureSet Archs, SymbolFlags Flags) {
75  Name = copyString(Name);
76  auto result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
77  if (result.second)
78  result.first->second = new (Allocator) Symbol{Kind, Name, Archs, Flags};
79  else
80  result.first->second->addArchitectures(Archs);
81 }
82 
83 } // end namespace MachO.
84 } // 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:1281
uint64_t CallInst * C
void addAllowableClient(StringRef Name, ArchitectureSet Architectures)
Add an allowable client.
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void addSymbol(SymbolKind Kind, StringRef Name, ArchitectureSet Architectures, SymbolFlags Flags=SymbolFlags::None)
Add a symbol to the symbols list or extend an existing one.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Reference to an interface file.
Definition: InterfaceFile.h:86
void addUUID(Architecture Arch, StringRef UUID)
Add an architecture/UUID pair.
C::iterator addEntry(C &Container, StringRef InstallName)
void addReexportedLibrary(StringRef InstallName, ArchitectureSet Architectures)
Add a re-exported library.
StringRef getInstallName() const
Definition: InterfaceFile.h:95
SymbolFlags
Symbol flags.
Definition: Symbol.h:24
std::pair< llvm::MachO::Architecture, std::string > UUID
unsigned first
Basic Register Allocator
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:23
#define I(x, y, z)
Definition: MD5.cpp:58
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48