208struct ExportSection {
209 std::vector<Architecture> Architectures;
210 std::vector<FlowStringRef> AllowableClients;
211 std::vector<FlowStringRef> ReexportedLibraries;
212 std::vector<FlowStringRef> Symbols;
213 std::vector<FlowStringRef> Classes;
214 std::vector<FlowStringRef> ClassEHs;
215 std::vector<FlowStringRef> IVars;
216 std::vector<FlowStringRef> WeakDefSymbols;
217 std::vector<FlowStringRef> TLVSymbols;
220struct UndefinedSection {
221 std::vector<Architecture> Architectures;
222 std::vector<FlowStringRef> Symbols;
223 std::vector<FlowStringRef> Classes;
224 std::vector<FlowStringRef> ClassEHs;
225 std::vector<FlowStringRef> IVars;
226 std::vector<FlowStringRef> WeakRefSymbols;
230struct SymbolSection {
232 std::vector<FlowStringRef> Symbols;
233 std::vector<FlowStringRef> Classes;
234 std::vector<FlowStringRef> ClassEHs;
235 std::vector<FlowStringRef> Ivars;
236 std::vector<FlowStringRef> WeakSymbols;
237 std::vector<FlowStringRef> TlvSymbols;
240struct MetadataSection {
241 enum Option { Clients, Libraries };
242 std::vector<Target> Targets;
243 std::vector<FlowStringRef> Values;
246struct UmbrellaSection {
247 std::vector<Target> Targets;
248 std::string Umbrella;
257 UUIDv4(
const Target &TargetID,
const std::string &Value)
258 : TargetID(TargetID), Value(Value) {}
279 "File type is not set in YAML context");
285 IO.
mapOptional(
"allowable-clients", Section.AllowableClients);
301 "File type is not set in YAML context");
342 MetadataSection::Option &OptionKind) {
344 switch (OptionKind) {
345 case MetadataSection::Option::Clients:
348 case MetadataSection::Option::Libraries:
369 OS <<
Value.Arch <<
"-";
370 switch (
Value.Platform) {
371#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
373 case PLATFORM_##platform: \
374 OS << #tapi_target; \
376#include "llvm/BinaryFormat/MachO.def"
384 return "unparsable target";
389 return "unknown architecture";
390 if (
Value.Platform == PLATFORM_UNKNOWN)
391 return "unknown platform";
412 if (!File->isApplicationExtensionSafe())
415 if (!File->isTwoLevelNamespace())
418 if (!File->umbrellas().empty())
421 std::set<ArchitectureSet> ArchSet;
422 for (
const auto &Library : File->allowableClients())
423 ArchSet.insert(Library.getArchitectures());
425 for (
const auto &Library : File->reexportedLibraries())
426 ArchSet.insert(Library.getArchitectures());
428 std::map<const Symbol *, ArchitectureSet> SymbolToArchSet;
429 for (
const auto *
Symbol : File->symbols()) {
436 ExportSection Section;
439 for (
const auto &Library : File->allowableClients())
441 Section.AllowableClients.emplace_back(Library.getInstallName());
443 for (
const auto &Library : File->reexportedLibraries())
445 Section.ReexportedLibraries.emplace_back(Library.getInstallName());
447 for (
const auto &SymArch : SymbolToArchSet) {
451 const auto *
Symbol = SymArch.first;
463 Section.Classes.emplace_back(
470 Section.Symbols.emplace_back(
477 Section.IVars.emplace_back(
490 Exports.emplace_back(std::move(Section));
494 SymbolToArchSet.clear();
496 for (
const auto *
Symbol : File->undefineds()) {
503 UndefinedSection Section;
506 for (
const auto &SymArch : SymbolToArchSet) {
510 const auto *
Symbol = SymArch.first;
520 Section.Classes.emplace_back(
527 Section.Symbols.emplace_back(
534 Section.IVars.emplace_back(
563 if ((
Architecture == AK_i386) && (Platform == PLATFORM_MACCATALYST))
577 File->setPath(Ctx->Path);
578 File->setFileType(Ctx->FileKind);
585 for (
const auto &
Target : File->targets())
589 File->setTwoLevelNamespace();
590 File->setApplicationExtensionSafe();
593 File->setApplicationExtensionSafe(
602 for (
const auto &Section :
Exports) {
606 for (
const auto &
Lib : Section.AllowableClients)
607 for (
const auto &
Target : Targets)
610 for (
const auto &
Lib : Section.ReexportedLibraries)
611 for (
const auto &
Target : Targets)
614 for (
const auto &
Symbol : Section.Symbols) {
622 for (
auto &
Symbol : Section.Classes) {
625 Name = Name.drop_front();
628 for (
auto &
Symbol : Section.ClassEHs)
631 for (
auto &
Symbol : Section.IVars) {
634 Name = Name.drop_front();
638 for (
auto &
Symbol : Section.WeakDefSymbols)
641 for (
auto &
Symbol : Section.TLVSymbols)
649 for (
auto &
Symbol : Section.Symbols) {
653 Symbol.value.drop_front(15), Targets,
659 for (
auto &
Symbol : Section.Classes) {
662 Name = Name.drop_front();
666 for (
auto &
Symbol : Section.ClassEHs)
669 for (
auto &
Symbol : Section.IVars) {
672 Name = Name.drop_front();
676 for (
auto &
Symbol : Section.WeakRefSymbols)
712 else if (
IO.
mapTag(
"!tapi-tbd-v3",
false))
714 else if (
IO.
mapTag(
"!tapi-tbd-v2",
false))
716 else if (
IO.
mapTag(
"!tapi-tbd-v1",
false) ||
717 IO.
mapTag(
"tag:yaml.org,2002:map",
false))
729 "File type is not set in YAML context");
733 switch (Ctx->FileKind) {
745 switch (Ctx->FileKind) {
773 File->targets().end());
780 if (!File->isApplicationExtensionSafe())
783 if (!File->isTwoLevelNamespace())
786 if (File->isOSLibNotForSharedCache())
790 std::map<std::string, TargetList> valueToTargetList;
791 for (
const auto &it : File->umbrellas())
792 valueToTargetList[it.second].emplace_back(it.first);
794 for (
const auto &it : valueToTargetList) {
795 UmbrellaSection CurrentSection;
796 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
797 it.second.begin(), it.second.end());
798 CurrentSection.Umbrella = it.first;
809 std::set<TargetList> TargetSet;
810 std::map<const Symbol *, TargetList> SymbolToTargetList;
811 for (
const auto *
Symbol : Symbols) {
814 TargetSet.emplace(std::move(
Targets));
816 for (
const auto &TargetIDs : TargetSet) {
817 SymbolSection CurrentSection;
818 CurrentSection.Targets.
insert(CurrentSection.Targets.
begin(),
819 TargetIDs.begin(), TargetIDs.end());
821 for (
const auto &
IT : SymbolToTargetList) {
822 if (
IT.second != TargetIDs)
846 sort(CurrentSection.Symbols);
847 sort(CurrentSection.Classes);
848 sort(CurrentSection.ClassEHs);
849 sort(CurrentSection.Ivars);
850 sort(CurrentSection.WeakSymbols);
851 sort(CurrentSection.TlvSymbols);
852 CurrentSections.emplace_back(std::move(CurrentSection));
856 handleSymbols(
Exports, File->exports());
857 handleSymbols(
Reexports, File->reexports());
858 handleSymbols(
Undefineds, File->undefineds());
866 File->setPath(Ctx->Path);
867 File->setFileType(Ctx->FileKind);
874 for (
const auto &target : CurrentSection.Targets)
875 File->addParentUmbrella(target, CurrentSection.Umbrella);
877 File->setApplicationExtensionSafe(
879 File->setOSLibNotForSharedCache(
883 for (
const auto &lib : CurrentSection.Values)
884 for (
const auto &
Target : CurrentSection.Targets)
885 File->addAllowableClient(lib,
Target);
889 for (
const auto &
Lib : CurrentSection.Values)
890 for (
const auto &
Target : CurrentSection.Targets)
894 auto handleSymbols = [File](
const SectionList &CurrentSections,
901 for (
const auto &CurrentSection : CurrentSections) {
902 for (
auto &sym : CurrentSection.Symbols)
904 CurrentSection.Targets, Flag);
906 for (
auto &sym : CurrentSection.Classes)
908 CurrentSection.Targets, Flag);
910 for (
auto &sym : CurrentSection.ClassEHs)
912 CurrentSection.Targets, Flag);
914 for (
auto &sym : CurrentSection.Ivars)
916 CurrentSection.Targets, Flag);
922 for (
auto &sym : CurrentSection.WeakSymbols) {
924 CurrentSection.Targets, Flag | SymFlag);
927 for (
auto &sym : CurrentSection.TlvSymbols)
929 CurrentSection.Targets,
957 void assignTargetsToLibrary(
const std::vector<InterfaceFileRef> &Libraries,
958 std::vector<MetadataSection> &Section) {
959 std::set<TargetList> targetSet;
960 std::map<const InterfaceFileRef *, TargetList> valueToTargetList;
961 for (
const auto &
library : Libraries) {
963 valueToTargetList[&
library] = targets;
964 targetSet.emplace(std::move(targets));
967 for (
const auto &targets : targetSet) {
968 MetadataSection CurrentSection;
969 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
970 targets.begin(), targets.end());
972 for (
const auto &it : valueToTargetList) {
973 if (it.second != targets)
976 CurrentSection.Values.emplace_back(it.first->getInstallName());
979 Section.emplace_back(std::move(CurrentSection));
987 std::vector<UUID> EmptyUUID;
997 IO.
mapOptional(
"compatibility-version", Keys->CompatibilityVersion,
1000 IO.
mapOptional(
"swift-version", Keys->SwiftABIVersion, SwiftVersion(0));
1018 std::vector<UUIDv4> EmptyUUID;
1027 IO.
mapOptional(
"compatibility-version", Keys->CompatibilityVersion,
1029 IO.
mapOptional(
"swift-abi-version", Keys->SwiftABIVersion, SwiftVersion(0));
1031 auto OptionKind = MetadataSection::Option::Clients;
1034 OptionKind = MetadataSection::Option::Libraries;
1045 static size_t size(
IO &
IO, std::vector<const MachO::InterfaceFile *> &Seq) {
1049 element(
IO &
IO, std::vector<const InterfaceFile *> &Seq,
size_t Index) {
1050 if (Index >= Seq.size())
1051 Seq.resize(Index + 1);
1069 NewDiag.
print(
nullptr, S);
1070 File->ErrorMessage = (
"malformed file\n" + Message).str();
1075 if (TAPIFile.starts_with(
"{") && TAPIFile.ends_with(
"}"))
1078 if (!TAPIFile.ends_with(
"..."))
1081 if (TAPIFile.starts_with(
"--- !tapi-tbd"))
1084 if (TAPIFile.starts_with(
"--- !tapi-tbd-v3"))
1087 if (TAPIFile.starts_with(
"--- !tapi-tbd-v2"))
1090 if (TAPIFile.starts_with(
"--- !tapi-tbd-v1") ||
1091 TAPIFile.starts_with(
"---\narchs:"))
1101 if (
auto FTOrErr =
canRead(InputBuffer))
1102 Ctx.FileKind = *FTOrErr;
1104 return FTOrErr.takeError();
1110 return FileOrErr.takeError();
1112 (*FileOrErr)->setPath(Ctx.Path);
1113 return std::move(*FileOrErr);
1118 std::vector<const InterfaceFile *> Files;
1123 auto File = std::unique_ptr<InterfaceFile>(
1128 std::shared_ptr<InterfaceFile>(
const_cast<InterfaceFile *
>(FI)));
1133 return std::move(File);
1137 const FileType FileKind,
bool Compact) {
1139 Ctx.
Path = std::string(File.getPath());
1153 std::vector<const InterfaceFile *> Files;
1154 Files.emplace_back(&File);
1156 for (
const auto &
Document : File.documents())
1157 Files.emplace_back(
Document.get());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
This file defines the BumpPtrAllocator interface.
Replace intrinsics with calls to vector library
This file defines the SmallString class.
std::pair< llvm::MachO::Target, std::string > UUID
@ NotApplicationExtensionSafe
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML flow sequen...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Defines the interface file.
SymbolSet::const_filtered_symbol_range const_filtered_symbol_range
bool isWeakDefined() const
const_target_range targets() const
bool isThreadLocalValue() const
ArchitectureSet getArchitectures() const
StringRef getName() const
EncodeKind getKind() const
bool isWeakReferenced() const
static LLVM_ABI llvm::Expected< Target > create(StringRef Target)
static LLVM_ABI Expected< FileType > canRead(MemoryBufferRef InputBuffer)
Determine whether input can be interpreted as TAPI text file.
static LLVM_ABI Expected< std::unique_ptr< InterfaceFile > > get(MemoryBufferRef InputBuffer)
Parse and get an InterfaceFile that represents the full library.
static LLVM_ABI Error writeToStream(raw_ostream &OS, const InterfaceFile &File, const FileType FileKind=FileType::Invalid, bool Compact=false)
Write TAPI text file contents into stream.
StringRef getBufferIdentifier() const
StringRef getBuffer() const
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
LLVM_ABI void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
SourceMgr::DiagKind getKind() const
StringRef getLineContents() const
StringRef getMessage() const
ArrayRef< SMFixIt > getFixIts() const
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
const SourceMgr * getSourceMgr() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
reference emplace_back(ArgTypes &&... Args)
iterator insert(iterator I, T &&Elt)
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
Target - Wrapper for Target specific information.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
A YAML Stream is a sequence of Documents.
void mapOptional(const char *Key, T &Val)
void bitSetCase(T &Val, const char *Str, const T ConstVal)
virtual bool outputting() const =0
virtual bool mapTag(StringRef Tag, bool Default=false)=0
void mapRequired(const char *Key, T &Val)
virtual void setError(const Twine &)=0
void * getContext() const
void mapOptionalWithContext(const char *Key, T &Val, Context &Ctx)
The Output class is used to generate a yaml document from in-memory structs and vectors.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
FileType
Defines the file type TextAPI files can represent.
@ Invalid
Invalid file type.
@ TBD_V1
Text-based stub file (.tbd) version 1.0.
@ TBD_V3
Text-based stub file (.tbd) version 3.0.
@ TBD_V5
Text-based stub file (.tbd) version 5.0.
@ TBD_V4
Text-based stub file (.tbd) version 4.0.
@ TBD_V2
Text-based stub file (.tbd) version 2.0.
Error serializeInterfaceFileToJSON(raw_ostream &OS, const InterfaceFile &File, const FileType FileKind, bool Compact)
SmallSet< PlatformType, 3 > PlatformSet
ObjCConstraintType
Defines a list of Objective-C constraints.
@ Retain_Release
Retain/Release.
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
LLVM_ABI PlatformType mapToPlatformType(PlatformType Platform, bool WantSim)
Expected< std::unique_ptr< InterfaceFile > > getInterfaceFileFromJSON(StringRef JSON)
@ ObjectiveCInstanceVariable
@ ThreadLocalValue
Thread-local value symbol.
@ WeakReferenced
Weak referenced symbol.
@ WeakDefined
Weak defined symbol.
SmallVector< Target, 5 > TargetList
constexpr StringLiteral ObjC2EHTypePrefix
QuotingType
Describe which type of quotes should be used when quoting is necessary.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void sort(IteratorTy Start, IteratorTy End)
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
static const InterfaceFile *& element(IO &IO, std::vector< const InterfaceFile * > &Seq, size_t Index)
static size_t size(IO &IO, std::vector< const MachO::InterfaceFile * > &Seq)
This class should be specialized by any type that needs to be converted to/from a list of YAML docume...
static void mapping(IO &IO, MetadataSection &Section, MetadataSection::Option &OptionKind)
This class is similar to MappingTraits<T> but allows you to pass in additional context for each map o...
static void mapping(IO &IO, ExportSection &Section)
static void mapping(IO &IO, SymbolSection &Section)
static void mapping(IO &IO, UUIDv4 &UUID)
static void mapping(IO &IO, UmbrellaSection &Section)
static void mapping(IO &IO, UndefinedSection &Section)
std::vector< UmbrellaSection > ParentUmbrellas
PackedVersion CurrentVersion
std::vector< UUIDv4 > UUIDs
std::vector< MetadataSection > AllowableClients
PackedVersion CompatibilityVersion
SwiftVersion SwiftABIVersion
std::vector< MetadataSection > ReexportedLibraries
const InterfaceFile * denormalize(IO &IO)
NormalizedTBD_V4(IO &IO, const InterfaceFile *&File)
std::vector< UndefinedSection > Undefineds
NormalizedTBD(IO &IO, const InterfaceFile *&File)
StringRef copyString(StringRef String)
TargetList synthesizeTargets(ArchitectureSet Architectures, const PlatformSet &Platforms)
std::vector< UUID > UUIDs
const InterfaceFile * denormalize(IO &IO)
SwiftVersion SwiftABIVersion
std::vector< Architecture > Architectures
ObjCConstraintType ObjCConstraint
llvm::BumpPtrAllocator Allocator
PackedVersion CurrentVersion
std::vector< ExportSection > Exports
PackedVersion CompatibilityVersion
static void mapKeysToValuesV4(IO &IO, const InterfaceFile *&File)
static void setFileTypeForInput(TextAPIContext *Ctx, IO &IO)
std::vector< SymbolSection > SectionList
static void mapping(IO &IO, const InterfaceFile *&File)
static void mapKeysToValues(FileType FileKind, IO &IO, const InterfaceFile *&File)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
static void bitset(IO &IO, TBDFlags &Flags)
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
static StringRef input(StringRef Scalar, void *, Target &Value)
static void output(const Target &Value, void *, raw_ostream &OS)
static QuotingType mustQuote(StringRef)
This class should be specialized by type that requires custom conversion to/from a yaml scalar.