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);
30 } // end namespace detail.
32 void InterfaceFile::addAllowableClient(StringRef Name,
33 ArchitectureSet Architectures) {
34 auto Client = detail::addEntry(AllowableClients, Name);
35 Client->addArchitectures(Architectures);
38 void InterfaceFile::addReexportedLibrary(StringRef InstallName,
39 ArchitectureSet Architectures) {
40 auto Lib = detail::addEntry(ReexportedLibraries, InstallName);
41 Lib->addArchitectures(Architectures);
44 void InterfaceFile::addUUID(Architecture Arch, StringRef UUID) {
45 auto I = partition_point(UUIDs,
46 [=](const std::pair<Architecture, std::string> &O) {
47 return O.first < Arch;
50 if (I != UUIDs.end() && Arch == I->first) {
55 UUIDs.emplace(I, Arch, UUID);
59 void InterfaceFile::addUUID(Architecture Arch, uint8_t UUID[16]) {
60 std::stringstream Stream;
61 for (unsigned i = 0; i < 16; ++i) {
62 if (i == 4 || i == 6 || i == 8 || i == 10)
64 Stream << std::setfill('0') << std::setw(2) << std::uppercase << std::hex
65 << static_cast<int>(UUID[i]);
67 addUUID(Arch, Stream.str());
70 void InterfaceFile::addSymbol(SymbolKind Kind, StringRef Name,
71 ArchitectureSet Archs, SymbolFlags Flags) {
72 Name = copyString(Name);
73 auto result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
75 result.first->second = new (Allocator) Symbol{Kind, Name, Archs, Flags};
77 result.first->second->addArchitectures(Archs);
80 } // end namespace MachO.
81 } // end namespace llvm.