aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm14/lib/TextAPI
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
committervitalyisaev <vitalyisaev@yandex-team.com>2023-06-29 10:00:50 +0300
commit6ffe9e53658409f212834330e13564e4952558f6 (patch)
tree85b1e00183517648b228aafa7c8fb07f5276f419 /contrib/libs/llvm14/lib/TextAPI
parent726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff)
downloadydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'contrib/libs/llvm14/lib/TextAPI')
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/Architecture.cpp98
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/ArchitectureSet.cpp70
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/InterfaceFile.cpp163
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/PackedVersion.cpp112
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/Platform.cpp136
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/Symbol.cpp58
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/Target.cpp79
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/TextAPIContext.h32
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/TextStub.cpp1149
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/TextStubCommon.cpp237
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/TextStubCommon.h85
-rw-r--r--contrib/libs/llvm14/lib/TextAPI/ya.make35
12 files changed, 2254 insertions, 0 deletions
diff --git a/contrib/libs/llvm14/lib/TextAPI/Architecture.cpp b/contrib/libs/llvm14/lib/TextAPI/Architecture.cpp
new file mode 100644
index 00000000000..bb349b21774
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/Architecture.cpp
@@ -0,0 +1,98 @@
+//===- Architecture.cpp ---------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the architecture helper functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/Architecture.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/BinaryFormat/MachO.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ErrorHandling.h"
+
+namespace llvm {
+namespace MachO {
+
+Architecture getArchitectureFromCpuType(uint32_t CPUType, uint32_t CPUSubType) {
+#define ARCHINFO(Arch, Type, Subtype, NumBits) \
+ if (CPUType == (Type) && \
+ (CPUSubType & ~MachO::CPU_SUBTYPE_MASK) == (Subtype)) \
+ return AK_##Arch;
+#include "llvm/TextAPI/Architecture.def"
+#undef ARCHINFO
+
+ return AK_unknown;
+}
+
+Architecture getArchitectureFromName(StringRef Name) {
+ return StringSwitch<Architecture>(Name)
+#define ARCHINFO(Arch, Type, Subtype, NumBits) .Case(#Arch, AK_##Arch)
+#include "llvm/TextAPI/Architecture.def"
+#undef ARCHINFO
+ .Default(AK_unknown);
+}
+
+StringRef getArchitectureName(Architecture Arch) {
+ switch (Arch) {
+#define ARCHINFO(Arch, Type, Subtype, NumBits) \
+ case AK_##Arch: \
+ return #Arch;
+#include "llvm/TextAPI/Architecture.def"
+#undef ARCHINFO
+ case AK_unknown:
+ return "unknown";
+ }
+
+ // Appease some compilers that cannot figure out that this is a fully covered
+ // switch statement.
+ return "unknown";
+}
+
+std::pair<uint32_t, uint32_t> getCPUTypeFromArchitecture(Architecture Arch) {
+ switch (Arch) {
+#define ARCHINFO(Arch, Type, Subtype, NumBits) \
+ case AK_##Arch: \
+ return std::make_pair(Type, Subtype);
+#include "llvm/TextAPI/Architecture.def"
+#undef ARCHINFO
+ case AK_unknown:
+ return std::make_pair(0, 0);
+ }
+
+ // Appease some compilers that cannot figure out that this is a fully covered
+ // switch statement.
+ return std::make_pair(0, 0);
+}
+
+Architecture mapToArchitecture(const Triple &Target) {
+ return getArchitectureFromName(Target.getArchName());
+}
+
+bool is64Bit(Architecture Arch) {
+ switch (Arch) {
+#define ARCHINFO(Arch, Type, Subtype, NumBits) \
+ case AK_##Arch: \
+ return NumBits == 64;
+#include "llvm/TextAPI/Architecture.def"
+#undef ARCHINFO
+ case AK_unknown:
+ return false;
+ }
+
+ llvm_unreachable("Fully handled switch case above.");
+}
+
+raw_ostream &operator<<(raw_ostream &OS, Architecture Arch) {
+ OS << getArchitectureName(Arch);
+ return OS;
+}
+
+} // end namespace MachO.
+} // end namespace llvm.
diff --git a/contrib/libs/llvm14/lib/TextAPI/ArchitectureSet.cpp b/contrib/libs/llvm14/lib/TextAPI/ArchitectureSet.cpp
new file mode 100644
index 00000000000..0fc2ede37ac
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/ArchitectureSet.cpp
@@ -0,0 +1,70 @@
+//===- ArchitectureSet.cpp ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the architecture set.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/ArchitectureSet.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+namespace MachO {
+
+ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs)
+ : ArchitectureSet() {
+ for (auto Arch : Archs) {
+ if (Arch == AK_unknown)
+ continue;
+ set(Arch);
+ }
+}
+
+size_t ArchitectureSet::count() const {
+ // popcnt
+ size_t Cnt = 0;
+ for (unsigned i = 0; i < sizeof(ArchSetType) * 8; ++i)
+ if (ArchSet & (1U << i))
+ ++Cnt;
+ return Cnt;
+}
+
+ArchitectureSet::operator std::string() const {
+ if (empty())
+ return "[(empty)]";
+
+ std::string result;
+ auto size = count();
+ for (auto arch : *this) {
+ result.append(std::string(getArchitectureName(arch)));
+ size -= 1;
+ if (size)
+ result.append(" ");
+ }
+ return result;
+}
+
+ArchitectureSet::operator std::vector<Architecture>() const {
+ std::vector<Architecture> archs;
+ for (auto arch : *this) {
+ if (arch == AK_unknown)
+ continue;
+ archs.emplace_back(arch);
+ }
+ return archs;
+}
+
+void ArchitectureSet::print(raw_ostream &os) const { os << std::string(*this); }
+
+raw_ostream &operator<<(raw_ostream &os, ArchitectureSet set) {
+ set.print(os);
+ return os;
+}
+
+} // end namespace MachO.
+} // end namespace llvm.
diff --git a/contrib/libs/llvm14/lib/TextAPI/InterfaceFile.cpp b/contrib/libs/llvm14/lib/TextAPI/InterfaceFile.cpp
new file mode 100644
index 00000000000..1156a39228e
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/InterfaceFile.cpp
@@ -0,0 +1,163 @@
+//===- InterfaceFile.cpp --------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the Interface File.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/InterfaceFile.h"
+#include <iomanip>
+#include <sstream>
+
+using namespace llvm;
+using namespace llvm::MachO;
+
+namespace {
+template <typename C>
+typename C::iterator addEntry(C &Container, StringRef InstallName) {
+ auto I = partition_point(Container, [=](const InterfaceFileRef &O) {
+ return O.getInstallName() < InstallName;
+ });
+ if (I != Container.end() && I->getInstallName() == InstallName)
+ return I;
+
+ return Container.emplace(I, InstallName);
+}
+
+template <typename C>
+typename C::iterator addEntry(C &Container, const Target &Target_) {
+ auto Iter =
+ lower_bound(Container, Target_, [](const Target &LHS, const Target &RHS) {
+ return LHS < RHS;
+ });
+ if ((Iter != std::end(Container)) && !(Target_ < *Iter))
+ return Iter;
+
+ return Container.insert(Iter, Target_);
+}
+} // end namespace
+
+void InterfaceFileRef::addTarget(const Target &Target) {
+ addEntry(Targets, Target);
+}
+
+void InterfaceFile::addAllowableClient(StringRef InstallName,
+ const Target &Target) {
+ auto Client = addEntry(AllowableClients, InstallName);
+ Client->addTarget(Target);
+}
+
+void InterfaceFile::addReexportedLibrary(StringRef InstallName,
+ const Target &Target) {
+ auto Lib = addEntry(ReexportedLibraries, InstallName);
+ Lib->addTarget(Target);
+}
+
+void InterfaceFile::addParentUmbrella(const Target &Target_, StringRef Parent) {
+ auto Iter = lower_bound(ParentUmbrellas, Target_,
+ [](const std::pair<Target, std::string> &LHS,
+ Target RHS) { return LHS.first < RHS; });
+
+ if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) {
+ Iter->second = std::string(Parent);
+ return;
+ }
+
+ ParentUmbrellas.emplace(Iter, Target_, std::string(Parent));
+}
+
+void InterfaceFile::addUUID(const Target &Target_, StringRef UUID) {
+ auto Iter = lower_bound(UUIDs, Target_,
+ [](const std::pair<Target, std::string> &LHS,
+ Target RHS) { return LHS.first < RHS; });
+
+ if ((Iter != UUIDs.end()) && !(Target_ < Iter->first)) {
+ Iter->second = std::string(UUID);
+ return;
+ }
+
+ UUIDs.emplace(Iter, Target_, std::string(UUID));
+}
+
+void InterfaceFile::addUUID(const Target &Target, uint8_t UUID[16]) {
+ std::stringstream Stream;
+ for (unsigned i = 0; i < 16; ++i) {
+ if (i == 4 || i == 6 || i == 8 || i == 10)
+ Stream << '-';
+ Stream << std::setfill('0') << std::setw(2) << std::uppercase << std::hex
+ << static_cast<int>(UUID[i]);
+ }
+ addUUID(Target, Stream.str());
+}
+
+void InterfaceFile::addTarget(const Target &Target) {
+ addEntry(Targets, Target);
+}
+
+InterfaceFile::const_filtered_target_range
+InterfaceFile::targets(ArchitectureSet Archs) const {
+ std::function<bool(const Target &)> fn = [Archs](const Target &Target_) {
+ return Archs.has(Target_.Arch);
+ };
+ return make_filter_range(Targets, fn);
+}
+
+void InterfaceFile::addSymbol(SymbolKind Kind, StringRef Name,
+ const TargetList &Targets, SymbolFlags Flags) {
+ Name = copyString(Name);
+ auto result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
+ if (result.second)
+ result.first->second = new (Allocator) Symbol{Kind, Name, Targets, Flags};
+ else
+ for (const auto &Target : Targets)
+ result.first->second->addTarget(Target);
+}
+
+void InterfaceFile::addDocument(std::shared_ptr<InterfaceFile> &&Document) {
+ auto Pos = llvm::lower_bound(Documents, Document,
+ [](const std::shared_ptr<InterfaceFile> &LHS,
+ const std::shared_ptr<InterfaceFile> &RHS) {
+ return LHS->InstallName < RHS->InstallName;
+ });
+ Document->Parent = this;
+ Documents.insert(Pos, Document);
+}
+
+bool InterfaceFile::operator==(const InterfaceFile &O) const {
+ if (Targets != O.Targets)
+ return false;
+ if (InstallName != O.InstallName)
+ return false;
+ if ((CurrentVersion != O.CurrentVersion) ||
+ (CompatibilityVersion != O.CompatibilityVersion))
+ return false;
+ if (SwiftABIVersion != O.SwiftABIVersion)
+ return false;
+ if (IsTwoLevelNamespace != O.IsTwoLevelNamespace)
+ return false;
+ if (IsAppExtensionSafe != O.IsAppExtensionSafe)
+ return false;
+ if (IsInstallAPI != O.IsInstallAPI)
+ return false;
+ if (ParentUmbrellas != O.ParentUmbrellas)
+ return false;
+ if (AllowableClients != O.AllowableClients)
+ return false;
+ if (ReexportedLibraries != O.ReexportedLibraries)
+ return false;
+ if (Symbols != O.Symbols)
+ return false;
+ if (!std::equal(Documents.begin(), Documents.end(), O.Documents.begin(),
+ O.Documents.end(),
+ [](const std::shared_ptr<InterfaceFile> LHS,
+ const std::shared_ptr<InterfaceFile> RHS) {
+ return *LHS == *RHS;
+ }))
+ return false;
+ return true;
+}
diff --git a/contrib/libs/llvm14/lib/TextAPI/PackedVersion.cpp b/contrib/libs/llvm14/lib/TextAPI/PackedVersion.cpp
new file mode 100644
index 00000000000..67fb30aeb12
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/PackedVersion.cpp
@@ -0,0 +1,112 @@
+//===- PackedVersion.cpp --------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the Mach-O packed version.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/PackedVersion.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+namespace MachO {
+
+bool PackedVersion::parse32(StringRef Str) {
+ Version = 0;
+
+ if (Str.empty())
+ return false;
+
+ SmallVector<StringRef, 3> Parts;
+ SplitString(Str, Parts, ".");
+
+ if (Parts.size() > 3)
+ return false;
+
+ unsigned long long Num;
+ if (getAsUnsignedInteger(Parts[0], 10, Num))
+ return false;
+
+ if (Num > UINT16_MAX)
+ return false;
+
+ Version = Num << 16;
+
+ for (unsigned i = 1, ShiftNum = 8; i < Parts.size(); ++i, ShiftNum -= 8) {
+ if (getAsUnsignedInteger(Parts[i], 10, Num))
+ return false;
+
+ if (Num > UINT8_MAX)
+ return false;
+
+ Version |= (Num << ShiftNum);
+ }
+
+ return true;
+}
+
+std::pair<bool, bool> PackedVersion::parse64(StringRef Str) {
+ bool Truncated = false;
+ Version = 0;
+
+ if (Str.empty())
+ return std::make_pair(false, Truncated);
+
+ SmallVector<StringRef, 5> Parts;
+ SplitString(Str, Parts, ".");
+
+ if (Parts.size() > 5)
+ return std::make_pair(false, Truncated);
+
+ unsigned long long Num;
+ if (getAsUnsignedInteger(Parts[0], 10, Num))
+ return std::make_pair(false, Truncated);
+
+ if (Num > 0xFFFFFFULL)
+ return std::make_pair(false, Truncated);
+
+ if (Num > 0xFFFFULL) {
+ Num = 0xFFFFULL;
+ Truncated = true;
+ }
+ Version = Num << 16;
+
+ for (unsigned i = 1, ShiftNum = 8; i < Parts.size() && i < 3;
+ ++i, ShiftNum -= 8) {
+ if (getAsUnsignedInteger(Parts[i], 10, Num))
+ return std::make_pair(false, Truncated);
+
+ if (Num > 0x3FFULL)
+ return std::make_pair(false, Truncated);
+
+ if (Num > 0xFFULL) {
+ Num = 0xFFULL;
+ Truncated = true;
+ }
+ Version |= (Num << ShiftNum);
+ }
+
+ if (Parts.size() > 3)
+ Truncated = true;
+
+ return std::make_pair(true, Truncated);
+}
+
+void PackedVersion::print(raw_ostream &OS) const {
+ OS << format("%d", getMajor());
+ if (getMinor() || getSubminor())
+ OS << format(".%d", getMinor());
+ if (getSubminor())
+ OS << format(".%d", getSubminor());
+}
+
+} // end namespace MachO.
+} // end namespace llvm.
diff --git a/contrib/libs/llvm14/lib/TextAPI/Platform.cpp b/contrib/libs/llvm14/lib/TextAPI/Platform.cpp
new file mode 100644
index 00000000000..c3c74252301
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/Platform.cpp
@@ -0,0 +1,136 @@
+//===- llvm/TextAPI/Platform.cpp - Platform ---------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementations of Platform Helper functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/Platform.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
+
+namespace llvm {
+namespace MachO {
+
+PlatformType mapToPlatformType(PlatformType Platform, bool WantSim) {
+ switch (Platform) {
+ default:
+ return Platform;
+ case PLATFORM_IOS:
+ return WantSim ? PLATFORM_IOSSIMULATOR : PLATFORM_IOS;
+ case PLATFORM_TVOS:
+ return WantSim ? PLATFORM_TVOSSIMULATOR : PLATFORM_TVOS;
+ case PLATFORM_WATCHOS:
+ return WantSim ? PLATFORM_WATCHOSSIMULATOR : PLATFORM_WATCHOS;
+ }
+}
+
+PlatformType mapToPlatformType(const Triple &Target) {
+ switch (Target.getOS()) {
+ default:
+ return PLATFORM_UNKNOWN;
+ case Triple::MacOSX:
+ return PLATFORM_MACOS;
+ case Triple::IOS:
+ if (Target.isSimulatorEnvironment())
+ return PLATFORM_IOSSIMULATOR;
+ if (Target.getEnvironment() == Triple::MacABI)
+ return PLATFORM_MACCATALYST;
+ return PLATFORM_IOS;
+ case Triple::TvOS:
+ return Target.isSimulatorEnvironment() ? PLATFORM_TVOSSIMULATOR
+ : PLATFORM_TVOS;
+ case Triple::WatchOS:
+ return Target.isSimulatorEnvironment() ? PLATFORM_WATCHOSSIMULATOR
+ : PLATFORM_WATCHOS;
+ // TODO: add bridgeOS & driverKit once in llvm::Triple
+ }
+}
+
+PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets) {
+ PlatformSet Result;
+ for (const auto &Target : Targets)
+ Result.insert(mapToPlatformType(Target));
+ return Result;
+}
+
+StringRef getPlatformName(PlatformType Platform) {
+ switch (Platform) {
+ case PLATFORM_UNKNOWN:
+ return "unknown";
+ case PLATFORM_MACOS:
+ return "macOS";
+ case PLATFORM_IOS:
+ return "iOS";
+ case PLATFORM_TVOS:
+ return "tvOS";
+ case PLATFORM_WATCHOS:
+ return "watchOS";
+ case PLATFORM_BRIDGEOS:
+ return "bridgeOS";
+ case PLATFORM_MACCATALYST:
+ return "macCatalyst";
+ case PLATFORM_IOSSIMULATOR:
+ return "iOS Simulator";
+ case PLATFORM_TVOSSIMULATOR:
+ return "tvOS Simulator";
+ case PLATFORM_WATCHOSSIMULATOR:
+ return "watchOS Simulator";
+ case PLATFORM_DRIVERKIT:
+ return "DriverKit";
+ }
+ llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
+}
+
+PlatformType getPlatformFromName(StringRef Name) {
+ return StringSwitch<PlatformType>(Name)
+ .Case("macos", PLATFORM_MACOS)
+ .Case("ios", PLATFORM_IOS)
+ .Case("tvos", PLATFORM_TVOS)
+ .Case("watchos", PLATFORM_WATCHOS)
+ .Case("bridgeos", PLATFORM_BRIDGEOS)
+ .Case("ios-macabi", PLATFORM_MACCATALYST)
+ .Case("ios-simulator", PLATFORM_IOSSIMULATOR)
+ .Case("tvos-simulator", PLATFORM_TVOSSIMULATOR)
+ .Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR)
+ .Case("driverkit", PLATFORM_DRIVERKIT)
+ .Default(PLATFORM_UNKNOWN);
+}
+
+std::string getOSAndEnvironmentName(PlatformType Platform,
+ std::string Version) {
+ switch (Platform) {
+ case PLATFORM_UNKNOWN:
+ return "darwin" + Version;
+ case PLATFORM_MACOS:
+ return "macos" + Version;
+ case PLATFORM_IOS:
+ return "ios" + Version;
+ case PLATFORM_TVOS:
+ return "tvos" + Version;
+ case PLATFORM_WATCHOS:
+ return "watchos" + Version;
+ case PLATFORM_BRIDGEOS:
+ return "bridgeos" + Version;
+ case PLATFORM_MACCATALYST:
+ return "ios" + Version + "-macabi";
+ case PLATFORM_IOSSIMULATOR:
+ return "ios" + Version + "-simulator";
+ case PLATFORM_TVOSSIMULATOR:
+ return "tvos" + Version + "-simulator";
+ case PLATFORM_WATCHOSSIMULATOR:
+ return "watchos" + Version + "-simulator";
+ case PLATFORM_DRIVERKIT:
+ return "driverkit" + Version;
+ }
+ llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
+}
+
+} // end namespace MachO.
+} // end namespace llvm.
diff --git a/contrib/libs/llvm14/lib/TextAPI/Symbol.cpp b/contrib/libs/llvm14/lib/TextAPI/Symbol.cpp
new file mode 100644
index 00000000000..041f553c66f
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/Symbol.cpp
@@ -0,0 +1,58 @@
+//===- Symbol.cpp ---------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the Symbol.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/Symbol.h"
+#include <string>
+
+namespace llvm {
+namespace MachO {
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void Symbol::dump(raw_ostream &OS) const {
+ std::string Result;
+ if (isUndefined())
+ Result += "(undef) ";
+ if (isWeakDefined())
+ Result += "(weak-def) ";
+ if (isWeakReferenced())
+ Result += "(weak-ref) ";
+ if (isThreadLocalValue())
+ Result += "(tlv) ";
+ switch (Kind) {
+ case SymbolKind::GlobalSymbol:
+ Result += Name.str();
+ break;
+ case SymbolKind::ObjectiveCClass:
+ Result += "(ObjC Class) " + Name.str();
+ break;
+ case SymbolKind::ObjectiveCClassEHType:
+ Result += "(ObjC Class EH) " + Name.str();
+ break;
+ case SymbolKind::ObjectiveCInstanceVariable:
+ Result += "(ObjC IVar) " + Name.str();
+ break;
+ }
+ OS << Result;
+}
+#endif
+
+Symbol::const_filtered_target_range
+Symbol::targets(ArchitectureSet Architectures) const {
+ std::function<bool(const Target &)> FN =
+ [Architectures](const Target &Target) {
+ return Architectures.has(Target.Arch);
+ };
+ return make_filter_range(Targets, FN);
+}
+
+} // end namespace MachO.
+} // end namespace llvm.
diff --git a/contrib/libs/llvm14/lib/TextAPI/Target.cpp b/contrib/libs/llvm14/lib/TextAPI/Target.cpp
new file mode 100644
index 00000000000..c54c3bd66b9
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/Target.cpp
@@ -0,0 +1,79 @@
+//===- Target.cpp -----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/Target.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+namespace MachO {
+
+Expected<Target> Target::create(StringRef TargetValue) {
+ auto Result = TargetValue.split('-');
+ auto ArchitectureStr = Result.first;
+ auto Architecture = getArchitectureFromName(ArchitectureStr);
+ auto PlatformStr = Result.second;
+ PlatformType Platform;
+ Platform = StringSwitch<PlatformType>(PlatformStr)
+ .Case("macos", PLATFORM_MACOS)
+ .Case("ios", PLATFORM_IOS)
+ .Case("tvos", PLATFORM_TVOS)
+ .Case("watchos", PLATFORM_WATCHOS)
+ .Case("bridgeos", PLATFORM_BRIDGEOS)
+ .Case("maccatalyst", PLATFORM_MACCATALYST)
+ .Case("ios-simulator", PLATFORM_IOSSIMULATOR)
+ .Case("tvos-simulator", PLATFORM_TVOSSIMULATOR)
+ .Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR)
+ .Case("driverkit", PLATFORM_DRIVERKIT)
+ .Default(PLATFORM_UNKNOWN);
+
+ if (Platform == PLATFORM_UNKNOWN) {
+ if (PlatformStr.startswith("<") && PlatformStr.endswith(">")) {
+ PlatformStr = PlatformStr.drop_front().drop_back();
+ unsigned long long RawValue;
+ if (!PlatformStr.getAsInteger(10, RawValue))
+ Platform = (PlatformType)RawValue;
+ }
+ }
+
+ return Target{Architecture, Platform};
+}
+
+Target::operator std::string() const {
+ return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) + ")")
+ .str();
+}
+
+raw_ostream &operator<<(raw_ostream &OS, const Target &Target) {
+ OS << std::string(Target);
+ return OS;
+}
+
+PlatformSet mapToPlatformSet(ArrayRef<Target> Targets) {
+ PlatformSet Result;
+ for (const auto &Target : Targets)
+ Result.insert(Target.Platform);
+ return Result;
+}
+
+ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets) {
+ ArchitectureSet Result;
+ for (const auto &Target : Targets)
+ Result.set(Target.Arch);
+ return Result;
+}
+
+std::string getTargetTripleName(const Target &Targ) {
+ return (getArchitectureName(Targ.Arch) + "-apple-" +
+ getOSAndEnvironmentName(Targ.Platform))
+ .str();
+}
+
+} // end namespace MachO.
+} // end namespace llvm.
diff --git a/contrib/libs/llvm14/lib/TextAPI/TextAPIContext.h b/contrib/libs/llvm14/lib/TextAPI/TextAPIContext.h
new file mode 100644
index 00000000000..217d1f5400e
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/TextAPIContext.h
@@ -0,0 +1,32 @@
+//===- TextAPIContext.h ---------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines the YAML Context for the TextAPI Reader/Writer.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TEXTAPI_MACHO_CONTEXT_H
+#define LLVM_TEXTAPI_MACHO_CONTEXT_H
+
+#include <string>
+
+namespace llvm {
+namespace MachO {
+
+enum FileType : unsigned;
+
+struct TextAPIContext {
+ std::string ErrorMessage;
+ std::string Path;
+ FileType FileKind;
+};
+
+} // end namespace MachO.
+} // end namespace llvm.
+
+#endif // LLVM_TEXTAPI_MACHO_CONTEXT_H
diff --git a/contrib/libs/llvm14/lib/TextAPI/TextStub.cpp b/contrib/libs/llvm14/lib/TextAPI/TextStub.cpp
new file mode 100644
index 00000000000..ff93e43356f
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/TextStub.cpp
@@ -0,0 +1,1149 @@
+//===- TextStub.cpp -------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the text stub file reader/writer.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TextAPIContext.h"
+#include "TextStubCommon.h"
+#include "llvm/ADT/BitmaskEnum.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/TextAPI/Architecture.h"
+#include "llvm/TextAPI/ArchitectureSet.h"
+#include "llvm/TextAPI/InterfaceFile.h"
+#include "llvm/TextAPI/PackedVersion.h"
+#include "llvm/TextAPI/TextAPIReader.h"
+#include "llvm/TextAPI/TextAPIWriter.h"
+#include <algorithm>
+#include <set>
+
+// clang-format off
+/*
+
+ YAML Format specification.
+
+ The TBD v1 format only support two level address libraries and is per
+ definition application extension safe.
+
+--- # the tag !tapi-tbd-v1 is optional and
+ # shouldn't be emitted to support older linker.
+archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
+ # supported by this file.
+platform: ios # Specifies the platform (macosx, ios, etc)
+install-name: /u/l/libfoo.dylib #
+current-version: 1.2.3 # Optional: defaults to 1.0
+compatibility-version: 1.0 # Optional: defaults to 1.0
+swift-version: 0 # Optional: defaults to 0
+objc-constraint: none # Optional: defaults to none
+exports: # List of export sections
+...
+
+Each export section is defined as following:
+
+ - archs: [ arm64 ] # the list of architecture slices
+ allowed-clients: [ client ] # Optional: List of clients
+ re-exports: [ ] # Optional: List of re-exports
+ symbols: [ _sym ] # Optional: List of symbols
+ objc-classes: [] # Optional: List of Objective-C classes
+ objc-ivars: [] # Optional: List of Objective C Instance
+ # Variables
+ weak-def-symbols: [] # Optional: List of weak defined symbols
+ thread-local-symbols: [] # Optional: List of thread local symbols
+*/
+
+/*
+
+ YAML Format specification.
+
+--- !tapi-tbd-v2
+archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
+ # supported by this file.
+uuids: [ armv7:... ] # Optional: List of architecture and UUID pairs.
+platform: ios # Specifies the platform (macosx, ios, etc)
+flags: [] # Optional:
+install-name: /u/l/libfoo.dylib #
+current-version: 1.2.3 # Optional: defaults to 1.0
+compatibility-version: 1.0 # Optional: defaults to 1.0
+swift-version: 0 # Optional: defaults to 0
+objc-constraint: retain_release # Optional: defaults to retain_release
+parent-umbrella: # Optional:
+exports: # List of export sections
+...
+undefineds: # List of undefineds sections
+...
+
+Each export section is defined as following:
+
+- archs: [ arm64 ] # the list of architecture slices
+ allowed-clients: [ client ] # Optional: List of clients
+ re-exports: [ ] # Optional: List of re-exports
+ symbols: [ _sym ] # Optional: List of symbols
+ objc-classes: [] # Optional: List of Objective-C classes
+ objc-ivars: [] # Optional: List of Objective C Instance
+ # Variables
+ weak-def-symbols: [] # Optional: List of weak defined symbols
+ thread-local-symbols: [] # Optional: List of thread local symbols
+
+Each undefineds section is defined as following:
+- archs: [ arm64 ] # the list of architecture slices
+ symbols: [ _sym ] # Optional: List of symbols
+ objc-classes: [] # Optional: List of Objective-C classes
+ objc-ivars: [] # Optional: List of Objective C Instance Variables
+ weak-ref-symbols: [] # Optional: List of weak defined symbols
+*/
+
+/*
+
+ YAML Format specification.
+
+--- !tapi-tbd-v3
+archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
+ # supported by this file.
+uuids: [ armv7:... ] # Optional: List of architecture and UUID pairs.
+platform: ios # Specifies the platform (macosx, ios, etc)
+flags: [] # Optional:
+install-name: /u/l/libfoo.dylib #
+current-version: 1.2.3 # Optional: defaults to 1.0
+compatibility-version: 1.0 # Optional: defaults to 1.0
+swift-abi-version: 0 # Optional: defaults to 0
+objc-constraint: retain_release # Optional: defaults to retain_release
+parent-umbrella: # Optional:
+exports: # List of export sections
+...
+undefineds: # List of undefineds sections
+...
+
+Each export section is defined as following:
+
+- archs: [ arm64 ] # the list of architecture slices
+ allowed-clients: [ client ] # Optional: List of clients
+ re-exports: [ ] # Optional: List of re-exports
+ symbols: [ _sym ] # Optional: List of symbols
+ objc-classes: [] # Optional: List of Objective-C classes
+ objc-eh-types: [] # Optional: List of Objective-C classes
+ # with EH
+ objc-ivars: [] # Optional: List of Objective C Instance
+ # Variables
+ weak-def-symbols: [] # Optional: List of weak defined symbols
+ thread-local-symbols: [] # Optional: List of thread local symbols
+
+Each undefineds section is defined as following:
+- archs: [ arm64 ] # the list of architecture slices
+ symbols: [ _sym ] # Optional: List of symbols
+ objc-classes: [] # Optional: List of Objective-C classes
+ objc-eh-types: [] # Optional: List of Objective-C classes
+ # with EH
+ objc-ivars: [] # Optional: List of Objective C Instance Variables
+ weak-ref-symbols: [] # Optional: List of weak defined symbols
+*/
+
+/*
+
+ YAML Format specification.
+
+--- !tapi-tbd
+tbd-version: 4 # The tbd version for format
+targets: [ armv7-ios, x86_64-maccatalyst ] # The list of applicable tapi supported target triples
+uuids: # Optional: List of target and UUID pairs.
+ - target: armv7-ios
+ value: ...
+ - target: x86_64-maccatalyst
+ value: ...
+flags: [] # Optional:
+install-name: /u/l/libfoo.dylib #
+current-version: 1.2.3 # Optional: defaults to 1.0
+compatibility-version: 1.0 # Optional: defaults to 1.0
+swift-abi-version: 0 # Optional: defaults to 0
+parent-umbrella: # Optional:
+allowable-clients:
+ - targets: [ armv7-ios ] # Optional:
+ clients: [ clientA ]
+exports: # List of export sections
+...
+re-exports: # List of reexport sections
+...
+undefineds: # List of undefineds sections
+...
+
+Each export and reexport section is defined as following:
+
+- targets: [ arm64-macos ] # The list of target triples associated with symbols
+ symbols: [ _symA ] # Optional: List of symbols
+ objc-classes: [] # Optional: List of Objective-C classes
+ objc-eh-types: [] # Optional: List of Objective-C classes
+ # with EH
+ objc-ivars: [] # Optional: List of Objective C Instance
+ # Variables
+ weak-symbols: [] # Optional: List of weak defined symbols
+ thread-local-symbols: [] # Optional: List of thread local symbols
+- targets: [ arm64-macos, x86_64-maccatalyst ] # Optional: Targets for applicable additional symbols
+ symbols: [ _symB ] # Optional: List of symbols
+
+Each undefineds section is defined as following:
+- targets: [ arm64-macos ] # The list of target triples associated with symbols
+ symbols: [ _symC ] # Optional: List of symbols
+ objc-classes: [] # Optional: List of Objective-C classes
+ objc-eh-types: [] # Optional: List of Objective-C classes
+ # with EH
+ objc-ivars: [] # Optional: List of Objective C Instance Variables
+ weak-symbols: [] # Optional: List of weak defined symbols
+*/
+// clang-format on
+
+using namespace llvm;
+using namespace llvm::yaml;
+using namespace llvm::MachO;
+
+namespace {
+struct ExportSection {
+ std::vector<Architecture> Architectures;
+ std::vector<FlowStringRef> AllowableClients;
+ std::vector<FlowStringRef> ReexportedLibraries;
+ std::vector<FlowStringRef> Symbols;
+ std::vector<FlowStringRef> Classes;
+ std::vector<FlowStringRef> ClassEHs;
+ std::vector<FlowStringRef> IVars;
+ std::vector<FlowStringRef> WeakDefSymbols;
+ std::vector<FlowStringRef> TLVSymbols;
+};
+
+struct UndefinedSection {
+ std::vector<Architecture> Architectures;
+ std::vector<FlowStringRef> Symbols;
+ std::vector<FlowStringRef> Classes;
+ std::vector<FlowStringRef> ClassEHs;
+ std::vector<FlowStringRef> IVars;
+ std::vector<FlowStringRef> WeakRefSymbols;
+};
+
+// Sections for direct target mapping in TBDv4
+struct SymbolSection {
+ TargetList Targets;
+ std::vector<FlowStringRef> Symbols;
+ std::vector<FlowStringRef> Classes;
+ std::vector<FlowStringRef> ClassEHs;
+ std::vector<FlowStringRef> Ivars;
+ std::vector<FlowStringRef> WeakSymbols;
+ std::vector<FlowStringRef> TlvSymbols;
+};
+
+struct MetadataSection {
+ enum Option { Clients, Libraries };
+ std::vector<Target> Targets;
+ std::vector<FlowStringRef> Values;
+};
+
+struct UmbrellaSection {
+ std::vector<Target> Targets;
+ std::string Umbrella;
+};
+
+// UUID's for TBDv4 are mapped to target not arch
+struct UUIDv4 {
+ Target TargetID;
+ std::string Value;
+
+ UUIDv4() = default;
+ UUIDv4(const Target &TargetID, const std::string &Value)
+ : TargetID(TargetID), Value(Value) {}
+};
+
+// clang-format off
+enum TBDFlags : unsigned {
+ None = 0U,
+ FlatNamespace = 1U << 0,
+ NotApplicationExtensionSafe = 1U << 1,
+ InstallAPI = 1U << 2,
+ LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/InstallAPI),
+};
+// clang-format on
+} // end anonymous namespace.
+
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(Architecture)
+LLVM_YAML_IS_SEQUENCE_VECTOR(ExportSection)
+LLVM_YAML_IS_SEQUENCE_VECTOR(UndefinedSection)
+// Specific to TBDv4
+LLVM_YAML_IS_SEQUENCE_VECTOR(SymbolSection)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MetadataSection)
+LLVM_YAML_IS_SEQUENCE_VECTOR(UmbrellaSection)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(Target)
+LLVM_YAML_IS_SEQUENCE_VECTOR(UUIDv4)
+
+namespace llvm {
+namespace yaml {
+
+template <> struct MappingTraits<ExportSection> {
+ static void mapping(IO &IO, ExportSection &Section) {
+ const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
+ assert((!Ctx || (Ctx && Ctx->FileKind != FileType::Invalid)) &&
+ "File type is not set in YAML context");
+
+ IO.mapRequired("archs", Section.Architectures);
+ if (Ctx->FileKind == FileType::TBD_V1)
+ IO.mapOptional("allowed-clients", Section.AllowableClients);
+ else
+ IO.mapOptional("allowable-clients", Section.AllowableClients);
+ IO.mapOptional("re-exports", Section.ReexportedLibraries);
+ IO.mapOptional("symbols", Section.Symbols);
+ IO.mapOptional("objc-classes", Section.Classes);
+ if (Ctx->FileKind == FileType::TBD_V3)
+ IO.mapOptional("objc-eh-types", Section.ClassEHs);
+ IO.mapOptional("objc-ivars", Section.IVars);
+ IO.mapOptional("weak-def-symbols", Section.WeakDefSymbols);
+ IO.mapOptional("thread-local-symbols", Section.TLVSymbols);
+ }
+};
+
+template <> struct MappingTraits<UndefinedSection> {
+ static void mapping(IO &IO, UndefinedSection &Section) {
+ const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
+ assert((!Ctx || (Ctx && Ctx->FileKind != FileType::Invalid)) &&
+ "File type is not set in YAML context");
+
+ IO.mapRequired("archs", Section.Architectures);
+ IO.mapOptional("symbols", Section.Symbols);
+ IO.mapOptional("objc-classes", Section.Classes);
+ if (Ctx->FileKind == FileType::TBD_V3)
+ IO.mapOptional("objc-eh-types", Section.ClassEHs);
+ IO.mapOptional("objc-ivars", Section.IVars);
+ IO.mapOptional("weak-ref-symbols", Section.WeakRefSymbols);
+ }
+};
+
+template <> struct MappingTraits<SymbolSection> {
+ static void mapping(IO &IO, SymbolSection &Section) {
+ IO.mapRequired("targets", Section.Targets);
+ IO.mapOptional("symbols", Section.Symbols);
+ IO.mapOptional("objc-classes", Section.Classes);
+ IO.mapOptional("objc-eh-types", Section.ClassEHs);
+ IO.mapOptional("objc-ivars", Section.Ivars);
+ IO.mapOptional("weak-symbols", Section.WeakSymbols);
+ IO.mapOptional("thread-local-symbols", Section.TlvSymbols);
+ }
+};
+
+template <> struct MappingTraits<UmbrellaSection> {
+ static void mapping(IO &IO, UmbrellaSection &Section) {
+ IO.mapRequired("targets", Section.Targets);
+ IO.mapRequired("umbrella", Section.Umbrella);
+ }
+};
+
+template <> struct MappingTraits<UUIDv4> {
+ static void mapping(IO &IO, UUIDv4 &UUID) {
+ IO.mapRequired("target", UUID.TargetID);
+ IO.mapRequired("value", UUID.Value);
+ }
+};
+
+template <>
+struct MappingContextTraits<MetadataSection, MetadataSection::Option> {
+ static void mapping(IO &IO, MetadataSection &Section,
+ MetadataSection::Option &OptionKind) {
+ IO.mapRequired("targets", Section.Targets);
+ switch (OptionKind) {
+ case MetadataSection::Option::Clients:
+ IO.mapRequired("clients", Section.Values);
+ return;
+ case MetadataSection::Option::Libraries:
+ IO.mapRequired("libraries", Section.Values);
+ return;
+ }
+ llvm_unreachable("unexpected option for metadata");
+ }
+};
+
+template <> struct ScalarBitSetTraits<TBDFlags> {
+ static void bitset(IO &IO, TBDFlags &Flags) {
+ IO.bitSetCase(Flags, "flat_namespace", TBDFlags::FlatNamespace);
+ IO.bitSetCase(Flags, "not_app_extension_safe",
+ TBDFlags::NotApplicationExtensionSafe);
+ IO.bitSetCase(Flags, "installapi", TBDFlags::InstallAPI);
+ }
+};
+
+template <> struct ScalarTraits<Target> {
+ static void output(const Target &Value, void *, raw_ostream &OS) {
+ OS << Value.Arch << "-";
+ switch (Value.Platform) {
+ default:
+ OS << "unknown";
+ break;
+ case PLATFORM_MACOS:
+ OS << "macos";
+ break;
+ case PLATFORM_IOS:
+ OS << "ios";
+ break;
+ case PLATFORM_TVOS:
+ OS << "tvos";
+ break;
+ case PLATFORM_WATCHOS:
+ OS << "watchos";
+ break;
+ case PLATFORM_BRIDGEOS:
+ OS << "bridgeos";
+ break;
+ case PLATFORM_MACCATALYST:
+ OS << "maccatalyst";
+ break;
+ case PLATFORM_IOSSIMULATOR:
+ OS << "ios-simulator";
+ break;
+ case PLATFORM_TVOSSIMULATOR:
+ OS << "tvos-simulator";
+ break;
+ case PLATFORM_WATCHOSSIMULATOR:
+ OS << "watchos-simulator";
+ break;
+ case PLATFORM_DRIVERKIT:
+ OS << "driverkit";
+ break;
+ }
+ }
+
+ static StringRef input(StringRef Scalar, void *, Target &Value) {
+ auto Result = Target::create(Scalar);
+ if (!Result) {
+ consumeError(Result.takeError());
+ return "unparsable target";
+ }
+
+ Value = *Result;
+ if (Value.Arch == AK_unknown)
+ return "unknown architecture";
+ if (Value.Platform == PLATFORM_UNKNOWN)
+ return "unknown platform";
+
+ return {};
+ }
+
+ static QuotingType mustQuote(StringRef) { return QuotingType::None; }
+};
+
+template <> struct MappingTraits<const InterfaceFile *> {
+ struct NormalizedTBD {
+ explicit NormalizedTBD(IO &IO) {}
+ NormalizedTBD(IO &IO, const InterfaceFile *&File) {
+ Architectures = File->getArchitectures();
+ UUIDs = File->uuids();
+ Platforms = File->getPlatforms();
+ InstallName = File->getInstallName();
+ CurrentVersion = PackedVersion(File->getCurrentVersion());
+ CompatibilityVersion = PackedVersion(File->getCompatibilityVersion());
+ SwiftABIVersion = File->getSwiftABIVersion();
+ ObjCConstraint = File->getObjCConstraint();
+
+ Flags = TBDFlags::None;
+ if (!File->isApplicationExtensionSafe())
+ Flags |= TBDFlags::NotApplicationExtensionSafe;
+
+ if (!File->isTwoLevelNamespace())
+ Flags |= TBDFlags::FlatNamespace;
+
+ if (File->isInstallAPI())
+ Flags |= TBDFlags::InstallAPI;
+
+ if (!File->umbrellas().empty())
+ ParentUmbrella = File->umbrellas().begin()->second;
+
+ std::set<ArchitectureSet> ArchSet;
+ for (const auto &Library : File->allowableClients())
+ ArchSet.insert(Library.getArchitectures());
+
+ for (const auto &Library : File->reexportedLibraries())
+ ArchSet.insert(Library.getArchitectures());
+
+ std::map<const Symbol *, ArchitectureSet> SymbolToArchSet;
+ for (const auto *Symbol : File->exports()) {
+ auto Architectures = Symbol->getArchitectures();
+ SymbolToArchSet[Symbol] = Architectures;
+ ArchSet.insert(Architectures);
+ }
+
+ for (auto Architectures : ArchSet) {
+ ExportSection Section;
+ Section.Architectures = Architectures;
+
+ for (const auto &Library : File->allowableClients())
+ if (Library.getArchitectures() == Architectures)
+ Section.AllowableClients.emplace_back(Library.getInstallName());
+
+ for (const auto &Library : File->reexportedLibraries())
+ if (Library.getArchitectures() == Architectures)
+ Section.ReexportedLibraries.emplace_back(Library.getInstallName());
+
+ for (const auto &SymArch : SymbolToArchSet) {
+ if (SymArch.second != Architectures)
+ continue;
+
+ const auto *Symbol = SymArch.first;
+ switch (Symbol->getKind()) {
+ case SymbolKind::GlobalSymbol:
+ if (Symbol->isWeakDefined())
+ Section.WeakDefSymbols.emplace_back(Symbol->getName());
+ else if (Symbol->isThreadLocalValue())
+ Section.TLVSymbols.emplace_back(Symbol->getName());
+ else
+ Section.Symbols.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCClass:
+ if (File->getFileType() != FileType::TBD_V3)
+ Section.Classes.emplace_back(
+ copyString("_" + Symbol->getName().str()));
+ else
+ Section.Classes.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCClassEHType:
+ if (File->getFileType() != FileType::TBD_V3)
+ Section.Symbols.emplace_back(
+ copyString("_OBJC_EHTYPE_$_" + Symbol->getName().str()));
+ else
+ Section.ClassEHs.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCInstanceVariable:
+ if (File->getFileType() != FileType::TBD_V3)
+ Section.IVars.emplace_back(
+ copyString("_" + Symbol->getName().str()));
+ else
+ Section.IVars.emplace_back(Symbol->getName());
+ break;
+ }
+ }
+ llvm::sort(Section.Symbols);
+ llvm::sort(Section.Classes);
+ llvm::sort(Section.ClassEHs);
+ llvm::sort(Section.IVars);
+ llvm::sort(Section.WeakDefSymbols);
+ llvm::sort(Section.TLVSymbols);
+ Exports.emplace_back(std::move(Section));
+ }
+
+ ArchSet.clear();
+ SymbolToArchSet.clear();
+
+ for (const auto *Symbol : File->undefineds()) {
+ auto Architectures = Symbol->getArchitectures();
+ SymbolToArchSet[Symbol] = Architectures;
+ ArchSet.insert(Architectures);
+ }
+
+ for (auto Architectures : ArchSet) {
+ UndefinedSection Section;
+ Section.Architectures = Architectures;
+
+ for (const auto &SymArch : SymbolToArchSet) {
+ if (SymArch.second != Architectures)
+ continue;
+
+ const auto *Symbol = SymArch.first;
+ switch (Symbol->getKind()) {
+ case SymbolKind::GlobalSymbol:
+ if (Symbol->isWeakReferenced())
+ Section.WeakRefSymbols.emplace_back(Symbol->getName());
+ else
+ Section.Symbols.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCClass:
+ if (File->getFileType() != FileType::TBD_V3)
+ Section.Classes.emplace_back(
+ copyString("_" + Symbol->getName().str()));
+ else
+ Section.Classes.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCClassEHType:
+ if (File->getFileType() != FileType::TBD_V3)
+ Section.Symbols.emplace_back(
+ copyString("_OBJC_EHTYPE_$_" + Symbol->getName().str()));
+ else
+ Section.ClassEHs.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCInstanceVariable:
+ if (File->getFileType() != FileType::TBD_V3)
+ Section.IVars.emplace_back(
+ copyString("_" + Symbol->getName().str()));
+ else
+ Section.IVars.emplace_back(Symbol->getName());
+ break;
+ }
+ }
+ llvm::sort(Section.Symbols);
+ llvm::sort(Section.Classes);
+ llvm::sort(Section.ClassEHs);
+ llvm::sort(Section.IVars);
+ llvm::sort(Section.WeakRefSymbols);
+ Undefineds.emplace_back(std::move(Section));
+ }
+ }
+
+ // TBD v1 - TBD v3 files only support one platform and several
+ // architectures. It is possible to have more than one platform for TBD v3
+ // files, but the architectures don't apply to all
+ // platforms, specifically to filter out the i386 slice from
+ // platform macCatalyst.
+ TargetList synthesizeTargets(ArchitectureSet Architectures,
+ const PlatformSet &Platforms) {
+ TargetList Targets;
+
+ for (auto Platform : Platforms) {
+ Platform = mapToPlatformType(Platform, Architectures.hasX86());
+
+ for (const auto &&Architecture : Architectures) {
+ if ((Architecture == AK_i386) && (Platform == PLATFORM_MACCATALYST))
+ continue;
+
+ Targets.emplace_back(Architecture, Platform);
+ }
+ }
+ return Targets;
+ }
+
+ const InterfaceFile *denormalize(IO &IO) {
+ auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
+ assert(Ctx);
+
+ auto *File = new InterfaceFile;
+ File->setPath(Ctx->Path);
+ File->setFileType(Ctx->FileKind);
+ File->addTargets(synthesizeTargets(Architectures, Platforms));
+ for (auto &ID : UUIDs)
+ File->addUUID(ID.first, ID.second);
+ File->setInstallName(InstallName);
+ File->setCurrentVersion(CurrentVersion);
+ File->setCompatibilityVersion(CompatibilityVersion);
+ File->setSwiftABIVersion(SwiftABIVersion);
+ File->setObjCConstraint(ObjCConstraint);
+ for (const auto &Target : File->targets())
+ File->addParentUmbrella(Target, ParentUmbrella);
+
+ if (Ctx->FileKind == FileType::TBD_V1) {
+ File->setTwoLevelNamespace();
+ File->setApplicationExtensionSafe();
+ } else {
+ File->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
+ File->setApplicationExtensionSafe(
+ !(Flags & TBDFlags::NotApplicationExtensionSafe));
+ File->setInstallAPI(Flags & TBDFlags::InstallAPI);
+ }
+
+ for (const auto &Section : Exports) {
+ const auto Targets =
+ synthesizeTargets(Section.Architectures, Platforms);
+
+ for (const auto &Lib : Section.AllowableClients)
+ for (const auto &Target : Targets)
+ File->addAllowableClient(Lib, Target);
+
+ for (const auto &Lib : Section.ReexportedLibraries)
+ for (const auto &Target : Targets)
+ File->addReexportedLibrary(Lib, Target);
+
+ for (const auto &Symbol : Section.Symbols) {
+ if (Ctx->FileKind != FileType::TBD_V3 &&
+ Symbol.value.startswith("_OBJC_EHTYPE_$_"))
+ File->addSymbol(SymbolKind::ObjectiveCClassEHType,
+ Symbol.value.drop_front(15), Targets);
+ else
+ File->addSymbol(SymbolKind::GlobalSymbol, Symbol, Targets);
+ }
+ for (auto &Symbol : Section.Classes) {
+ auto Name = Symbol.value;
+ if (Ctx->FileKind != FileType::TBD_V3)
+ Name = Name.drop_front();
+ File->addSymbol(SymbolKind::ObjectiveCClass, Name, Targets);
+ }
+ for (auto &Symbol : Section.ClassEHs)
+ File->addSymbol(SymbolKind::ObjectiveCClassEHType, Symbol, Targets);
+ for (auto &Symbol : Section.IVars) {
+ auto Name = Symbol.value;
+ if (Ctx->FileKind != FileType::TBD_V3)
+ Name = Name.drop_front();
+ File->addSymbol(SymbolKind::ObjectiveCInstanceVariable, Name,
+ Targets);
+ }
+ for (auto &Symbol : Section.WeakDefSymbols)
+ File->addSymbol(SymbolKind::GlobalSymbol, Symbol, Targets,
+ SymbolFlags::WeakDefined);
+ for (auto &Symbol : Section.TLVSymbols)
+ File->addSymbol(SymbolKind::GlobalSymbol, Symbol, Targets,
+ SymbolFlags::ThreadLocalValue);
+ }
+
+ for (const auto &Section : Undefineds) {
+ const auto Targets =
+ synthesizeTargets(Section.Architectures, Platforms);
+ for (auto &Symbol : Section.Symbols) {
+ if (Ctx->FileKind != FileType::TBD_V3 &&
+ Symbol.value.startswith("_OBJC_EHTYPE_$_"))
+ File->addSymbol(SymbolKind::ObjectiveCClassEHType,
+ Symbol.value.drop_front(15), Targets,
+ SymbolFlags::Undefined);
+ else
+ File->addSymbol(SymbolKind::GlobalSymbol, Symbol, Targets,
+ SymbolFlags::Undefined);
+ }
+ for (auto &Symbol : Section.Classes) {
+ auto Name = Symbol.value;
+ if (Ctx->FileKind != FileType::TBD_V3)
+ Name = Name.drop_front();
+ File->addSymbol(SymbolKind::ObjectiveCClass, Name, Targets,
+ SymbolFlags::Undefined);
+ }
+ for (auto &Symbol : Section.ClassEHs)
+ File->addSymbol(SymbolKind::ObjectiveCClassEHType, Symbol, Targets,
+ SymbolFlags::Undefined);
+ for (auto &Symbol : Section.IVars) {
+ auto Name = Symbol.value;
+ if (Ctx->FileKind != FileType::TBD_V3)
+ Name = Name.drop_front();
+ File->addSymbol(SymbolKind::ObjectiveCInstanceVariable, Name, Targets,
+ SymbolFlags::Undefined);
+ }
+ for (auto &Symbol : Section.WeakRefSymbols)
+ File->addSymbol(SymbolKind::GlobalSymbol, Symbol, Targets,
+ SymbolFlags::Undefined | SymbolFlags::WeakReferenced);
+ }
+
+ return File;
+ }
+
+ llvm::BumpPtrAllocator Allocator;
+ StringRef copyString(StringRef String) {
+ if (String.empty())
+ return {};
+
+ void *Ptr = Allocator.Allocate(String.size(), 1);
+ memcpy(Ptr, String.data(), String.size());
+ return StringRef(reinterpret_cast<const char *>(Ptr), String.size());
+ }
+
+ std::vector<Architecture> Architectures;
+ std::vector<UUID> UUIDs;
+ PlatformSet Platforms;
+ StringRef InstallName;
+ PackedVersion CurrentVersion;
+ PackedVersion CompatibilityVersion;
+ SwiftVersion SwiftABIVersion{0};
+ ObjCConstraintType ObjCConstraint{ObjCConstraintType::None};
+ TBDFlags Flags{TBDFlags::None};
+ StringRef ParentUmbrella;
+ std::vector<ExportSection> Exports;
+ std::vector<UndefinedSection> Undefineds;
+ };
+
+ static void setFileTypeForInput(TextAPIContext *Ctx, IO &IO) {
+ if (IO.mapTag("!tapi-tbd", false))
+ Ctx->FileKind = FileType::TBD_V4;
+ else if (IO.mapTag("!tapi-tbd-v3", false))
+ Ctx->FileKind = FileType::TBD_V3;
+ else if (IO.mapTag("!tapi-tbd-v2", false))
+ Ctx->FileKind = FileType::TBD_V2;
+ else if (IO.mapTag("!tapi-tbd-v1", false) ||
+ IO.mapTag("tag:yaml.org,2002:map", false))
+ Ctx->FileKind = FileType::TBD_V1;
+ else {
+ Ctx->FileKind = FileType::Invalid;
+ return;
+ }
+ }
+
+ static void mapping(IO &IO, const InterfaceFile *&File) {
+ auto *Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
+ assert((!Ctx || !IO.outputting() ||
+ (Ctx && Ctx->FileKind != FileType::Invalid)) &&
+ "File type is not set in YAML context");
+
+ if (!IO.outputting()) {
+ setFileTypeForInput(Ctx, IO);
+ switch (Ctx->FileKind) {
+ default:
+ break;
+ case FileType::TBD_V4:
+ mapKeysToValuesV4(IO, File);
+ return;
+ case FileType::Invalid:
+ IO.setError("unsupported file type");
+ return;
+ }
+ } else {
+ // Set file type when writing.
+ switch (Ctx->FileKind) {
+ default:
+ llvm_unreachable("unexpected file type");
+ case FileType::TBD_V4:
+ mapKeysToValuesV4(IO, File);
+ return;
+ case FileType::TBD_V3:
+ IO.mapTag("!tapi-tbd-v3", true);
+ break;
+ case FileType::TBD_V2:
+ IO.mapTag("!tapi-tbd-v2", true);
+ break;
+ case FileType::TBD_V1:
+ // Don't write the tag into the .tbd file for TBD v1
+ break;
+ }
+ }
+ mapKeysToValues(Ctx->FileKind, IO, File);
+ }
+
+ using SectionList = std::vector<SymbolSection>;
+ struct NormalizedTBD_V4 {
+ explicit NormalizedTBD_V4(IO &IO) {}
+ NormalizedTBD_V4(IO &IO, const InterfaceFile *&File) {
+ auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
+ assert(Ctx);
+ TBDVersion = Ctx->FileKind >> 1;
+ Targets.insert(Targets.begin(), File->targets().begin(),
+ File->targets().end());
+ for (const auto &IT : File->uuids())
+ UUIDs.emplace_back(IT.first, IT.second);
+ InstallName = File->getInstallName();
+ CurrentVersion = File->getCurrentVersion();
+ CompatibilityVersion = File->getCompatibilityVersion();
+ SwiftABIVersion = File->getSwiftABIVersion();
+
+ Flags = TBDFlags::None;
+ if (!File->isApplicationExtensionSafe())
+ Flags |= TBDFlags::NotApplicationExtensionSafe;
+
+ if (!File->isTwoLevelNamespace())
+ Flags |= TBDFlags::FlatNamespace;
+
+ if (File->isInstallAPI())
+ Flags |= TBDFlags::InstallAPI;
+
+ {
+ std::map<std::string, TargetList> valueToTargetList;
+ for (const auto &it : File->umbrellas())
+ valueToTargetList[it.second].emplace_back(it.first);
+
+ for (const auto &it : valueToTargetList) {
+ UmbrellaSection CurrentSection;
+ CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
+ it.second.begin(), it.second.end());
+ CurrentSection.Umbrella = it.first;
+ ParentUmbrellas.emplace_back(std::move(CurrentSection));
+ }
+ }
+
+ assignTargetsToLibrary(File->allowableClients(), AllowableClients);
+ assignTargetsToLibrary(File->reexportedLibraries(), ReexportedLibraries);
+
+ auto handleSymbols =
+ [](SectionList &CurrentSections,
+ InterfaceFile::const_filtered_symbol_range Symbols,
+ std::function<bool(const Symbol *)> Pred) {
+ std::set<TargetList> TargetSet;
+ std::map<const Symbol *, TargetList> SymbolToTargetList;
+ for (const auto *Symbol : Symbols) {
+ if (!Pred(Symbol))
+ continue;
+ TargetList Targets(Symbol->targets());
+ SymbolToTargetList[Symbol] = Targets;
+ TargetSet.emplace(std::move(Targets));
+ }
+ for (const auto &TargetIDs : TargetSet) {
+ SymbolSection CurrentSection;
+ CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
+ TargetIDs.begin(), TargetIDs.end());
+
+ for (const auto &IT : SymbolToTargetList) {
+ if (IT.second != TargetIDs)
+ continue;
+
+ const auto *Symbol = IT.first;
+ switch (Symbol->getKind()) {
+ case SymbolKind::GlobalSymbol:
+ if (Symbol->isWeakDefined())
+ CurrentSection.WeakSymbols.emplace_back(Symbol->getName());
+ else if (Symbol->isThreadLocalValue())
+ CurrentSection.TlvSymbols.emplace_back(Symbol->getName());
+ else
+ CurrentSection.Symbols.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCClass:
+ CurrentSection.Classes.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCClassEHType:
+ CurrentSection.ClassEHs.emplace_back(Symbol->getName());
+ break;
+ case SymbolKind::ObjectiveCInstanceVariable:
+ CurrentSection.Ivars.emplace_back(Symbol->getName());
+ break;
+ }
+ }
+ sort(CurrentSection.Symbols);
+ sort(CurrentSection.Classes);
+ sort(CurrentSection.ClassEHs);
+ sort(CurrentSection.Ivars);
+ sort(CurrentSection.WeakSymbols);
+ sort(CurrentSection.TlvSymbols);
+ CurrentSections.emplace_back(std::move(CurrentSection));
+ }
+ };
+
+ handleSymbols(Exports, File->exports(), [](const Symbol *Symbol) {
+ return !Symbol->isReexported();
+ });
+ handleSymbols(Reexports, File->exports(), [](const Symbol *Symbol) {
+ return Symbol->isReexported();
+ });
+ handleSymbols(Undefineds, File->undefineds(),
+ [](const Symbol *Symbol) { return true; });
+ }
+
+ const InterfaceFile *denormalize(IO &IO) {
+ auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
+ assert(Ctx);
+
+ auto *File = new InterfaceFile;
+ File->setPath(Ctx->Path);
+ File->setFileType(Ctx->FileKind);
+ for (auto &id : UUIDs)
+ File->addUUID(id.TargetID, id.Value);
+ File->addTargets(Targets);
+ File->setInstallName(InstallName);
+ File->setCurrentVersion(CurrentVersion);
+ File->setCompatibilityVersion(CompatibilityVersion);
+ File->setSwiftABIVersion(SwiftABIVersion);
+ for (const auto &CurrentSection : ParentUmbrellas)
+ for (const auto &target : CurrentSection.Targets)
+ File->addParentUmbrella(target, CurrentSection.Umbrella);
+ File->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
+ File->setApplicationExtensionSafe(
+ !(Flags & TBDFlags::NotApplicationExtensionSafe));
+ File->setInstallAPI(Flags & TBDFlags::InstallAPI);
+
+ for (const auto &CurrentSection : AllowableClients) {
+ for (const auto &lib : CurrentSection.Values)
+ for (const auto &Target : CurrentSection.Targets)
+ File->addAllowableClient(lib, Target);
+ }
+
+ for (const auto &CurrentSection : ReexportedLibraries) {
+ for (const auto &Lib : CurrentSection.Values)
+ for (const auto &Target : CurrentSection.Targets)
+ File->addReexportedLibrary(Lib, Target);
+ }
+
+ auto handleSymbols = [File](const SectionList &CurrentSections,
+ SymbolFlags Flag = SymbolFlags::None) {
+ for (const auto &CurrentSection : CurrentSections) {
+ for (auto &sym : CurrentSection.Symbols)
+ File->addSymbol(SymbolKind::GlobalSymbol, sym,
+ CurrentSection.Targets, Flag);
+
+ for (auto &sym : CurrentSection.Classes)
+ File->addSymbol(SymbolKind::ObjectiveCClass, sym,
+ CurrentSection.Targets);
+
+ for (auto &sym : CurrentSection.ClassEHs)
+ File->addSymbol(SymbolKind::ObjectiveCClassEHType, sym,
+ CurrentSection.Targets);
+
+ for (auto &sym : CurrentSection.Ivars)
+ File->addSymbol(SymbolKind::ObjectiveCInstanceVariable, sym,
+ CurrentSection.Targets);
+
+ for (auto &sym : CurrentSection.WeakSymbols)
+ File->addSymbol(SymbolKind::GlobalSymbol, sym,
+ CurrentSection.Targets, SymbolFlags::WeakDefined);
+
+ for (auto &sym : CurrentSection.TlvSymbols)
+ File->addSymbol(SymbolKind::GlobalSymbol, sym,
+ CurrentSection.Targets,
+ SymbolFlags::ThreadLocalValue);
+ }
+ };
+
+ handleSymbols(Exports);
+ handleSymbols(Reexports, SymbolFlags::Rexported);
+ handleSymbols(Undefineds, SymbolFlags::Undefined);
+
+ return File;
+ }
+
+ unsigned TBDVersion;
+ std::vector<UUIDv4> UUIDs;
+ TargetList Targets;
+ StringRef InstallName;
+ PackedVersion CurrentVersion;
+ PackedVersion CompatibilityVersion;
+ SwiftVersion SwiftABIVersion{0};
+ std::vector<MetadataSection> AllowableClients;
+ std::vector<MetadataSection> ReexportedLibraries;
+ TBDFlags Flags{TBDFlags::None};
+ std::vector<UmbrellaSection> ParentUmbrellas;
+ SectionList Exports;
+ SectionList Reexports;
+ SectionList Undefineds;
+
+ private:
+ void assignTargetsToLibrary(const std::vector<InterfaceFileRef> &Libraries,
+ std::vector<MetadataSection> &Section) {
+ std::set<TargetList> targetSet;
+ std::map<const InterfaceFileRef *, TargetList> valueToTargetList;
+ for (const auto &library : Libraries) {
+ TargetList targets(library.targets());
+ valueToTargetList[&library] = targets;
+ targetSet.emplace(std::move(targets));
+ }
+
+ for (const auto &targets : targetSet) {
+ MetadataSection CurrentSection;
+ CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
+ targets.begin(), targets.end());
+
+ for (const auto &it : valueToTargetList) {
+ if (it.second != targets)
+ continue;
+
+ CurrentSection.Values.emplace_back(it.first->getInstallName());
+ }
+ llvm::sort(CurrentSection.Values);
+ Section.emplace_back(std::move(CurrentSection));
+ }
+ }
+ };
+
+ static void mapKeysToValues(FileType FileKind, IO &IO,
+ const InterfaceFile *&File) {
+ MappingNormalization<NormalizedTBD, const InterfaceFile *> Keys(IO, File);
+ IO.mapRequired("archs", Keys->Architectures);
+ if (FileKind != FileType::TBD_V1)
+ IO.mapOptional("uuids", Keys->UUIDs);
+ IO.mapRequired("platform", Keys->Platforms);
+ if (FileKind != FileType::TBD_V1)
+ IO.mapOptional("flags", Keys->Flags, TBDFlags::None);
+ IO.mapRequired("install-name", Keys->InstallName);
+ IO.mapOptional("current-version", Keys->CurrentVersion,
+ PackedVersion(1, 0, 0));
+ IO.mapOptional("compatibility-version", Keys->CompatibilityVersion,
+ PackedVersion(1, 0, 0));
+ if (FileKind != FileType::TBD_V3)
+ IO.mapOptional("swift-version", Keys->SwiftABIVersion, SwiftVersion(0));
+ else
+ IO.mapOptional("swift-abi-version", Keys->SwiftABIVersion,
+ SwiftVersion(0));
+ IO.mapOptional("objc-constraint", Keys->ObjCConstraint,
+ (FileKind == FileType::TBD_V1)
+ ? ObjCConstraintType::None
+ : ObjCConstraintType::Retain_Release);
+ if (FileKind != FileType::TBD_V1)
+ IO.mapOptional("parent-umbrella", Keys->ParentUmbrella, StringRef());
+ IO.mapOptional("exports", Keys->Exports);
+ if (FileKind != FileType::TBD_V1)
+ IO.mapOptional("undefineds", Keys->Undefineds);
+ }
+
+ static void mapKeysToValuesV4(IO &IO, const InterfaceFile *&File) {
+ MappingNormalization<NormalizedTBD_V4, const InterfaceFile *> Keys(IO,
+ File);
+ IO.mapTag("!tapi-tbd", true);
+ IO.mapRequired("tbd-version", Keys->TBDVersion);
+ IO.mapRequired("targets", Keys->Targets);
+ IO.mapOptional("uuids", Keys->UUIDs);
+ IO.mapOptional("flags", Keys->Flags, TBDFlags::None);
+ IO.mapRequired("install-name", Keys->InstallName);
+ IO.mapOptional("current-version", Keys->CurrentVersion,
+ PackedVersion(1, 0, 0));
+ IO.mapOptional("compatibility-version", Keys->CompatibilityVersion,
+ PackedVersion(1, 0, 0));
+ IO.mapOptional("swift-abi-version", Keys->SwiftABIVersion, SwiftVersion(0));
+ IO.mapOptional("parent-umbrella", Keys->ParentUmbrellas);
+ auto OptionKind = MetadataSection::Option::Clients;
+ IO.mapOptionalWithContext("allowable-clients", Keys->AllowableClients,
+ OptionKind);
+ OptionKind = MetadataSection::Option::Libraries;
+ IO.mapOptionalWithContext("reexported-libraries", Keys->ReexportedLibraries,
+ OptionKind);
+ IO.mapOptional("exports", Keys->Exports);
+ IO.mapOptional("reexports", Keys->Reexports);
+ IO.mapOptional("undefineds", Keys->Undefineds);
+ }
+};
+
+template <>
+struct DocumentListTraits<std::vector<const MachO::InterfaceFile *>> {
+ static size_t size(IO &IO, std::vector<const MachO::InterfaceFile *> &Seq) {
+ return Seq.size();
+ }
+ static const InterfaceFile *&
+ element(IO &IO, std::vector<const InterfaceFile *> &Seq, size_t Index) {
+ if (Index >= Seq.size())
+ Seq.resize(Index + 1);
+ return Seq[Index];
+ }
+};
+
+} // end namespace yaml.
+} // namespace llvm
+
+static void DiagHandler(const SMDiagnostic &Diag, void *Context) {
+ auto *File = static_cast<TextAPIContext *>(Context);
+ SmallString<1024> Message;
+ raw_svector_ostream S(Message);
+
+ SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(), File->Path,
+ Diag.getLineNo(), Diag.getColumnNo(), Diag.getKind(),
+ Diag.getMessage(), Diag.getLineContents(),
+ Diag.getRanges(), Diag.getFixIts());
+
+ NewDiag.print(nullptr, S);
+ File->ErrorMessage = ("malformed file\n" + Message).str();
+}
+
+Expected<std::unique_ptr<InterfaceFile>>
+TextAPIReader::get(MemoryBufferRef InputBuffer) {
+ TextAPIContext Ctx;
+ Ctx.Path = std::string(InputBuffer.getBufferIdentifier());
+ yaml::Input YAMLIn(InputBuffer.getBuffer(), &Ctx, DiagHandler, &Ctx);
+
+ // Fill vector with interface file objects created by parsing the YAML file.
+ std::vector<const InterfaceFile *> Files;
+ YAMLIn >> Files;
+
+ // YAMLIn dynamically allocates for Interface file and in case of error,
+ // memory leak will occur unless wrapped around unique_ptr
+ auto File = std::unique_ptr<InterfaceFile>(
+ const_cast<InterfaceFile *>(Files.front()));
+
+ for (const InterfaceFile *FI : llvm::drop_begin(Files))
+ File->addDocument(
+ std::shared_ptr<InterfaceFile>(const_cast<InterfaceFile *>(FI)));
+
+ if (YAMLIn.error())
+ return make_error<StringError>(Ctx.ErrorMessage, YAMLIn.error());
+
+ return std::move(File);
+}
+
+Error TextAPIWriter::writeToStream(raw_ostream &OS, const InterfaceFile &File) {
+ TextAPIContext Ctx;
+ Ctx.Path = std::string(File.getPath());
+ Ctx.FileKind = File.getFileType();
+ llvm::yaml::Output YAMLOut(OS, &Ctx, /*WrapColumn=*/80);
+
+ std::vector<const InterfaceFile *> Files;
+ Files.emplace_back(&File);
+
+ for (auto Document : File.documents())
+ Files.emplace_back(Document.get());
+
+ // Stream out yaml.
+ YAMLOut << Files;
+
+ return Error::success();
+}
diff --git a/contrib/libs/llvm14/lib/TextAPI/TextStubCommon.cpp b/contrib/libs/llvm14/lib/TextAPI/TextStubCommon.cpp
new file mode 100644
index 00000000000..29b74f981a9
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/TextStubCommon.cpp
@@ -0,0 +1,237 @@
+//===- TextStubCommon.cpp -------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implememts common Text Stub YAML mappings.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TextStubCommon.h"
+#include "TextAPIContext.h"
+#include "llvm/ADT/StringSwitch.h"
+
+using namespace llvm::MachO;
+
+namespace llvm {
+namespace yaml {
+
+void ScalarTraits<FlowStringRef>::output(const FlowStringRef &Value, void *Ctx,
+ raw_ostream &OS) {
+ ScalarTraits<StringRef>::output(Value, Ctx, OS);
+}
+StringRef ScalarTraits<FlowStringRef>::input(StringRef Value, void *Ctx,
+ FlowStringRef &Out) {
+ return ScalarTraits<StringRef>::input(Value, Ctx, Out.value);
+}
+QuotingType ScalarTraits<FlowStringRef>::mustQuote(StringRef Name) {
+ return ScalarTraits<StringRef>::mustQuote(Name);
+}
+
+void ScalarEnumerationTraits<ObjCConstraintType>::enumeration(
+ IO &IO, ObjCConstraintType &Constraint) {
+ IO.enumCase(Constraint, "none", ObjCConstraintType::None);
+ IO.enumCase(Constraint, "retain_release", ObjCConstraintType::Retain_Release);
+ IO.enumCase(Constraint, "retain_release_for_simulator",
+ ObjCConstraintType::Retain_Release_For_Simulator);
+ IO.enumCase(Constraint, "retain_release_or_gc",
+ ObjCConstraintType::Retain_Release_Or_GC);
+ IO.enumCase(Constraint, "gc", ObjCConstraintType::GC);
+}
+
+void ScalarTraits<PlatformSet>::output(const PlatformSet &Values, void *IO,
+ raw_ostream &OS) {
+
+ const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
+ assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
+ "File type is not set in context");
+
+ if (Ctx && Ctx->FileKind == TBD_V3 && Values.count(PLATFORM_MACOS) &&
+ Values.count(PLATFORM_MACCATALYST)) {
+ OS << "zippered";
+ return;
+ }
+
+ assert(Values.size() == 1U);
+ switch (*Values.begin()) {
+ default:
+ llvm_unreachable("unexpected platform");
+ break;
+ case PLATFORM_MACOS:
+ OS << "macosx";
+ break;
+ case PLATFORM_IOSSIMULATOR:
+ LLVM_FALLTHROUGH;
+ case PLATFORM_IOS:
+ OS << "ios";
+ break;
+ case PLATFORM_WATCHOSSIMULATOR:
+ LLVM_FALLTHROUGH;
+ case PLATFORM_WATCHOS:
+ OS << "watchos";
+ break;
+ case PLATFORM_TVOSSIMULATOR:
+ LLVM_FALLTHROUGH;
+ case PLATFORM_TVOS:
+ OS << "tvos";
+ break;
+ case PLATFORM_BRIDGEOS:
+ OS << "bridgeos";
+ break;
+ case PLATFORM_MACCATALYST:
+ OS << "iosmac";
+ break;
+ case PLATFORM_DRIVERKIT:
+ OS << "driverkit";
+ break;
+ }
+}
+
+StringRef ScalarTraits<PlatformSet>::input(StringRef Scalar, void *IO,
+ PlatformSet &Values) {
+ const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
+ assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
+ "File type is not set in context");
+
+ if (Scalar == "zippered") {
+ if (Ctx && Ctx->FileKind == FileType::TBD_V3) {
+ Values.insert(PLATFORM_MACOS);
+ Values.insert(PLATFORM_MACCATALYST);
+ return {};
+ }
+ return "invalid platform";
+ }
+
+ auto Platform = StringSwitch<PlatformType>(Scalar)
+ .Case("macosx", PLATFORM_MACOS)
+ .Case("ios", PLATFORM_IOS)
+ .Case("watchos", PLATFORM_WATCHOS)
+ .Case("tvos", PLATFORM_TVOS)
+ .Case("bridgeos", PLATFORM_BRIDGEOS)
+ .Case("iosmac", PLATFORM_MACCATALYST)
+ .Default(PLATFORM_UNKNOWN);
+
+ if (Platform == PLATFORM_MACCATALYST)
+ if (Ctx && Ctx->FileKind != FileType::TBD_V3)
+ return "invalid platform";
+
+ if (Platform == PLATFORM_UNKNOWN)
+ return "unknown platform";
+
+ Values.insert(Platform);
+ return {};
+}
+
+QuotingType ScalarTraits<PlatformSet>::mustQuote(StringRef) {
+ return QuotingType::None;
+}
+
+void ScalarBitSetTraits<ArchitectureSet>::bitset(IO &IO,
+ ArchitectureSet &Archs) {
+#define ARCHINFO(arch, type, subtype, numbits) \
+ IO.bitSetCase(Archs, #arch, 1U << static_cast<int>(AK_##arch));
+#include "llvm/TextAPI/Architecture.def"
+#undef ARCHINFO
+}
+
+void ScalarTraits<Architecture>::output(const Architecture &Value, void *,
+ raw_ostream &OS) {
+ OS << Value;
+}
+StringRef ScalarTraits<Architecture>::input(StringRef Scalar, void *,
+ Architecture &Value) {
+ Value = getArchitectureFromName(Scalar);
+ return {};
+}
+QuotingType ScalarTraits<Architecture>::mustQuote(StringRef) {
+ return QuotingType::None;
+}
+
+void ScalarTraits<PackedVersion>::output(const PackedVersion &Value, void *,
+ raw_ostream &OS) {
+ OS << Value;
+}
+StringRef ScalarTraits<PackedVersion>::input(StringRef Scalar, void *,
+ PackedVersion &Value) {
+ if (!Value.parse32(Scalar))
+ return "invalid packed version string.";
+ return {};
+}
+QuotingType ScalarTraits<PackedVersion>::mustQuote(StringRef) {
+ return QuotingType::None;
+}
+
+void ScalarTraits<SwiftVersion>::output(const SwiftVersion &Value, void *,
+ raw_ostream &OS) {
+ switch (Value) {
+ case 1:
+ OS << "1.0";
+ break;
+ case 2:
+ OS << "1.1";
+ break;
+ case 3:
+ OS << "2.0";
+ break;
+ case 4:
+ OS << "3.0";
+ break;
+ default:
+ OS << (unsigned)Value;
+ break;
+ }
+}
+StringRef ScalarTraits<SwiftVersion>::input(StringRef Scalar, void *IO,
+ SwiftVersion &Value) {
+ const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO);
+ assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
+ "File type is not set in context");
+
+ if (Ctx->FileKind == FileType::TBD_V4) {
+ if (Scalar.getAsInteger(10, Value))
+ return "invalid Swift ABI version.";
+ return {};
+ } else {
+ Value = StringSwitch<SwiftVersion>(Scalar)
+ .Case("1.0", 1)
+ .Case("1.1", 2)
+ .Case("2.0", 3)
+ .Case("3.0", 4)
+ .Default(0);
+ }
+
+ if (Value != SwiftVersion(0))
+ return {};
+
+ if (Scalar.getAsInteger(10, Value))
+ return "invalid Swift ABI version.";
+
+ return StringRef();
+}
+QuotingType ScalarTraits<SwiftVersion>::mustQuote(StringRef) {
+ return QuotingType::None;
+}
+
+void ScalarTraits<UUID>::output(const UUID &Value, void *, raw_ostream &OS) {
+ OS << Value.first << ": " << Value.second;
+}
+StringRef ScalarTraits<UUID>::input(StringRef Scalar, void *, UUID &Value) {
+ auto Split = Scalar.split(':');
+ auto Arch = Split.first.trim();
+ auto UUID = Split.second.trim();
+ if (UUID.empty())
+ return "invalid uuid string pair";
+ Value.second = std::string(UUID);
+ Value.first = Target{getArchitectureFromName(Arch), PLATFORM_UNKNOWN};
+ return {};
+}
+
+QuotingType ScalarTraits<UUID>::mustQuote(StringRef) {
+ return QuotingType::Single;
+}
+
+} // end namespace yaml.
+} // end namespace llvm.
diff --git a/contrib/libs/llvm14/lib/TextAPI/TextStubCommon.h b/contrib/libs/llvm14/lib/TextAPI/TextStubCommon.h
new file mode 100644
index 00000000000..aac27221b5f
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/TextStubCommon.h
@@ -0,0 +1,85 @@
+//===- TextStubCommon.h ---------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines common Text Stub YAML mappings.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TEXTAPI_TEXT_STUB_COMMON_H
+#define LLVM_TEXTAPI_TEXT_STUB_COMMON_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/TextAPI/Architecture.h"
+#include "llvm/TextAPI/InterfaceFile.h"
+#include "llvm/TextAPI/Platform.h"
+#include "llvm/TextAPI/Target.h"
+
+using UUID = std::pair<llvm::MachO::Target, std::string>;
+
+LLVM_YAML_STRONG_TYPEDEF(llvm::StringRef, FlowStringRef)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, SwiftVersion)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(UUID)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FlowStringRef)
+
+namespace llvm {
+
+namespace MachO {
+ class ArchitectureSet;
+ class PackedVersion;
+}
+namespace yaml {
+
+template <> struct ScalarTraits<FlowStringRef> {
+ static void output(const FlowStringRef &, void *, raw_ostream &);
+ static StringRef input(StringRef, void *, FlowStringRef &);
+ static QuotingType mustQuote(StringRef);
+};
+
+template <> struct ScalarEnumerationTraits<MachO::ObjCConstraintType> {
+ static void enumeration(IO &, MachO::ObjCConstraintType &);
+};
+
+template <> struct ScalarTraits<MachO::PlatformSet> {
+ static void output(const MachO::PlatformSet &, void *, raw_ostream &);
+ static StringRef input(StringRef, void *, MachO::PlatformSet &);
+ static QuotingType mustQuote(StringRef);
+};
+
+template <> struct ScalarBitSetTraits<MachO::ArchitectureSet> {
+ static void bitset(IO &, MachO::ArchitectureSet &);
+};
+
+template <> struct ScalarTraits<MachO::Architecture> {
+ static void output(const MachO::Architecture &, void *, raw_ostream &);
+ static StringRef input(StringRef, void *, MachO::Architecture &);
+ static QuotingType mustQuote(StringRef);
+};
+
+template <> struct ScalarTraits<MachO::PackedVersion> {
+ static void output(const MachO::PackedVersion &, void *, raw_ostream &);
+ static StringRef input(StringRef, void *, MachO::PackedVersion &);
+ static QuotingType mustQuote(StringRef);
+};
+
+template <> struct ScalarTraits<SwiftVersion> {
+ static void output(const SwiftVersion &, void *, raw_ostream &);
+ static StringRef input(StringRef, void *, SwiftVersion &);
+ static QuotingType mustQuote(StringRef);
+};
+
+template <> struct ScalarTraits<UUID> {
+ static void output(const UUID &, void *, raw_ostream &);
+ static StringRef input(StringRef, void *, UUID &);
+ static QuotingType mustQuote(StringRef);
+};
+
+} // end namespace yaml.
+} // end namespace llvm.
+
+#endif // LLVM_TEXTAPI_TEXT_STUB_COMMON_H
diff --git a/contrib/libs/llvm14/lib/TextAPI/ya.make b/contrib/libs/llvm14/lib/TextAPI/ya.make
new file mode 100644
index 00000000000..d22e2d66867
--- /dev/null
+++ b/contrib/libs/llvm14/lib/TextAPI/ya.make
@@ -0,0 +1,35 @@
+# Generated by devtools/yamaker.
+
+LIBRARY()
+
+LICENSE(Apache-2.0 WITH LLVM-exception)
+
+LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
+
+PEERDIR(
+ contrib/libs/llvm14
+ contrib/libs/llvm14/lib/BinaryFormat
+ contrib/libs/llvm14/lib/Support
+)
+
+ADDINCL(
+ contrib/libs/llvm14/lib/TextAPI
+)
+
+NO_COMPILER_WARNINGS()
+
+NO_UTIL()
+
+SRCS(
+ Architecture.cpp
+ ArchitectureSet.cpp
+ InterfaceFile.cpp
+ PackedVersion.cpp
+ Platform.cpp
+ Symbol.cpp
+ Target.cpp
+ TextStub.cpp
+ TextStubCommon.cpp
+)
+
+END()