209struct ExportSection {
210 std::vector<Architecture> Architectures;
211 std::vector<FlowStringRef> AllowableClients;
212 std::vector<FlowStringRef> ReexportedLibraries;
213 std::vector<FlowStringRef> Symbols;
214 std::vector<FlowStringRef> Classes;
215 std::vector<FlowStringRef> ClassEHs;
216 std::vector<FlowStringRef> IVars;
217 std::vector<FlowStringRef> WeakDefSymbols;
218 std::vector<FlowStringRef> TLVSymbols;
221struct UndefinedSection {
222 std::vector<Architecture> Architectures;
223 std::vector<FlowStringRef> Symbols;
224 std::vector<FlowStringRef> Classes;
225 std::vector<FlowStringRef> ClassEHs;
226 std::vector<FlowStringRef> IVars;
227 std::vector<FlowStringRef> WeakRefSymbols;
231struct SymbolSection {
233 std::vector<FlowStringRef> Symbols;
234 std::vector<FlowStringRef> Classes;
235 std::vector<FlowStringRef> ClassEHs;
236 std::vector<FlowStringRef> Ivars;
237 std::vector<FlowStringRef> WeakSymbols;
238 std::vector<FlowStringRef> TlvSymbols;
241struct MetadataSection {
242 enum Option { Clients, Libraries };
243 std::vector<Target> Targets;
244 std::vector<FlowStringRef> Values;
247struct UmbrellaSection {
248 std::vector<Target> Targets;
249 std::string Umbrella;
258 UUIDv4(
const Target &TargetID,
const std::string &Value)
259 : TargetID(TargetID), Value(Value) {}
280 "File type is not set in YAML context");
286 IO.
mapOptional(
"allowable-clients", Section.AllowableClients);
302 "File type is not set in YAML context");
322 [](
const Target &
T) { return !T.isValid(); });
337 [](
const Target &
T) { return !T.isValid(); });
352 MetadataSection::Option &OptionKind) {
356 [](
const Target &
T) { return !T.isValid(); });
357 switch (OptionKind) {
358 case MetadataSection::Option::Clients:
361 case MetadataSection::Option::Libraries:
382 OS <<
Value.Arch <<
"-";
383 switch (
Value.Platform) {
384#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
386 case PLATFORM_##platform: \
387 OS << #tapi_target; \
389#include "llvm/BinaryFormat/MachO.def"
397 return "unparsable target";
402 const bool SkipUnknownTriples =
404 if (!
Value.isValid() && !SkipUnknownTriples)
405 return "unknown target";
426 if (!File->isApplicationExtensionSafe())
429 if (!File->isTwoLevelNamespace())
432 if (!File->umbrellas().empty())
435 std::set<ArchitectureSet> ArchSet;
436 for (
const auto &Library : File->allowableClients())
437 ArchSet.insert(Library.getArchitectures());
439 for (
const auto &Library : File->reexportedLibraries())
440 ArchSet.insert(Library.getArchitectures());
442 std::map<const Symbol *, ArchitectureSet> SymbolToArchSet;
443 for (
const auto *
Symbol : File->symbols()) {
450 ExportSection Section;
453 for (
const auto &Library : File->allowableClients())
455 Section.AllowableClients.emplace_back(Library.getInstallName());
457 for (
const auto &Library : File->reexportedLibraries())
459 Section.ReexportedLibraries.emplace_back(Library.getInstallName());
461 for (
const auto &SymArch : SymbolToArchSet) {
465 const auto *
Symbol = SymArch.first;
477 Section.Classes.emplace_back(
484 Section.Symbols.emplace_back(
491 Section.IVars.emplace_back(
504 Exports.emplace_back(std::move(Section));
508 SymbolToArchSet.clear();
510 for (
const auto *
Symbol : File->undefineds()) {
517 UndefinedSection Section;
520 for (
const auto &SymArch : SymbolToArchSet) {
524 const auto *
Symbol = SymArch.first;
534 Section.Classes.emplace_back(
541 Section.Symbols.emplace_back(
548 Section.IVars.emplace_back(
577 if ((
Architecture == AK_i386) && (Platform == PLATFORM_MACCATALYST))
594 File->setPath(Ctx->Path);
595 File->setFileType(Ctx->FileKind);
602 for (
const auto &
Target : File->targets())
606 File->setTwoLevelNamespace();
607 File->setApplicationExtensionSafe();
610 File->setApplicationExtensionSafe(
619 for (
const auto &Section :
Exports) {
625 for (
const auto &
Lib : Section.AllowableClients)
626 for (
const auto &
Target : Targets)
629 for (
const auto &
Lib : Section.ReexportedLibraries)
630 for (
const auto &
Target : Targets)
633 for (
const auto &
Symbol : Section.Symbols) {
641 for (
auto &
Symbol : Section.Classes) {
644 Name = Name.drop_front();
647 for (
auto &
Symbol : Section.ClassEHs)
650 for (
auto &
Symbol : Section.IVars) {
653 Name = Name.drop_front();
657 for (
auto &
Symbol : Section.WeakDefSymbols)
660 for (
auto &
Symbol : Section.TLVSymbols)
670 for (
auto &
Symbol : Section.Symbols) {
674 Symbol.value.drop_front(15), Targets,
680 for (
auto &
Symbol : Section.Classes) {
683 Name = Name.drop_front();
687 for (
auto &
Symbol : Section.ClassEHs)
690 for (
auto &
Symbol : Section.IVars) {
693 Name = Name.drop_front();
697 for (
auto &
Symbol : Section.WeakRefSymbols)
733 else if (
IO.
mapTag(
"!tapi-tbd-v3",
false))
735 else if (
IO.
mapTag(
"!tapi-tbd-v2",
false))
737 else if (
IO.
mapTag(
"!tapi-tbd-v1",
false) ||
738 IO.
mapTag(
"tag:yaml.org,2002:map",
false))
750 "File type is not set in YAML context");
754 switch (Ctx->FileKind) {
766 switch (Ctx->FileKind) {
793 for (
auto &
T : File->targets())
802 if (!File->isApplicationExtensionSafe())
805 if (!File->isTwoLevelNamespace())
808 if (File->isOSLibNotForSharedCache())
812 std::map<std::string, TargetList> valueToTargetList;
813 for (
const auto &it : File->umbrellas())
814 if (it.first.isValid())
815 valueToTargetList[it.second].emplace_back(it.first);
817 for (
const auto &it : valueToTargetList) {
818 UmbrellaSection CurrentSection;
819 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
820 it.second.begin(), it.second.end());
821 CurrentSection.Umbrella = it.first;
832 std::set<TargetList> TargetSet;
833 std::map<const Symbol *, TargetList> SymbolToTargetList;
834 for (
const auto *
Symbol : Symbols) {
841 TargetSet.emplace(std::move(
Targets));
843 for (
const auto &TargetIDs : TargetSet) {
844 SymbolSection CurrentSection;
845 CurrentSection.Targets.
insert(CurrentSection.Targets.
begin(),
846 TargetIDs.begin(), TargetIDs.end());
848 for (
const auto &
IT : SymbolToTargetList) {
849 if (
IT.second != TargetIDs)
873 sort(CurrentSection.Symbols);
874 sort(CurrentSection.Classes);
875 sort(CurrentSection.ClassEHs);
876 sort(CurrentSection.Ivars);
877 sort(CurrentSection.WeakSymbols);
878 sort(CurrentSection.TlvSymbols);
879 CurrentSections.emplace_back(std::move(CurrentSection));
883 handleSymbols(
Exports, File->exports());
884 handleSymbols(
Reexports, File->reexports());
885 handleSymbols(
Undefineds, File->undefineds());
893 File->setPath(Ctx->Path);
894 File->setFileType(Ctx->FileKind);
901 for (
const auto &target : CurrentSection.Targets)
902 File->addParentUmbrella(target, CurrentSection.Umbrella);
904 File->setApplicationExtensionSafe(
906 File->setOSLibNotForSharedCache(
910 for (
const auto &lib : CurrentSection.Values)
911 for (
const auto &
Target : CurrentSection.Targets)
912 File->addAllowableClient(lib,
Target);
916 for (
const auto &
Lib : CurrentSection.Values)
917 for (
const auto &
Target : CurrentSection.Targets)
921 auto handleSymbols = [File](
const SectionList &CurrentSections,
928 for (
const auto &CurrentSection : CurrentSections) {
929 if (CurrentSection.Targets.empty())
932 for (
auto &sym : CurrentSection.Symbols)
934 CurrentSection.Targets, Flag);
936 for (
auto &sym : CurrentSection.Classes)
938 CurrentSection.Targets, Flag);
940 for (
auto &sym : CurrentSection.ClassEHs)
942 CurrentSection.Targets, Flag);
944 for (
auto &sym : CurrentSection.Ivars)
946 CurrentSection.Targets, Flag);
952 for (
auto &sym : CurrentSection.WeakSymbols) {
954 CurrentSection.Targets, Flag | SymFlag);
957 for (
auto &sym : CurrentSection.TlvSymbols)
959 CurrentSection.Targets,
987 void assignTargetsToLibrary(
const std::vector<InterfaceFileRef> &Libraries,
988 std::vector<MetadataSection> &Section) {
989 std::set<TargetList> targetSet;
990 std::map<const InterfaceFileRef *, TargetList> valueToTargetList;
991 for (
const auto &
library : Libraries) {
993 valueToTargetList[&
library] = targets;
994 targetSet.emplace(std::move(targets));
997 for (
const auto &targets : targetSet) {
998 MetadataSection CurrentSection;
999 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
1000 targets.begin(), targets.end());
1002 for (
const auto &it : valueToTargetList) {
1003 if (it.second != targets)
1006 CurrentSection.Values.emplace_back(it.first->getInstallName());
1009 Section.emplace_back(std::move(CurrentSection));
1017 std::vector<UUID> EmptyUUID;
1027 IO.
mapOptional(
"compatibility-version", Keys->CompatibilityVersion,
1030 IO.
mapOptional(
"swift-version", Keys->SwiftABIVersion, SwiftVersion(0));
1048 std::vector<UUIDv4> EmptyUUID;
1054 [](
const Target &
T) { return !T.isValid(); });
1060 IO.
mapOptional(
"compatibility-version", Keys->CompatibilityVersion,
1062 IO.
mapOptional(
"swift-abi-version", Keys->SwiftABIVersion, SwiftVersion(0));
1064 auto OptionKind = MetadataSection::Option::Clients;
1067 OptionKind = MetadataSection::Option::Libraries;
1078 static size_t size(
IO &
IO, std::vector<const MachO::InterfaceFile *> &Seq) {
1082 element(
IO &
IO, std::vector<const InterfaceFile *> &Seq,
size_t Index) {
1083 if (Index >= Seq.size())
1084 Seq.resize(Index + 1);
1102 NewDiag.
print(
nullptr, S);
1103 File->ErrorMessage = (
"malformed file\n" + Message).str();
1108 if (TAPIFile.starts_with(
"{") && TAPIFile.ends_with(
"}"))
1111 if (!TAPIFile.ends_with(
"..."))
1114 if (TAPIFile.starts_with(
"--- !tapi-tbd"))
1117 if (TAPIFile.starts_with(
"--- !tapi-tbd-v3"))
1120 if (TAPIFile.starts_with(
"--- !tapi-tbd-v2"))
1123 if (TAPIFile.starts_with(
"--- !tapi-tbd-v1") ||
1124 TAPIFile.starts_with(
"---\narchs:"))
1136 if (
auto FTOrErr =
canRead(InputBuffer))
1137 Ctx.FileKind = *FTOrErr;
1139 return FTOrErr.takeError();
1145 return FileOrErr.takeError();
1147 (*FileOrErr)->setPath(Ctx.Path);
1148 return std::move(*FileOrErr);
1153 std::vector<const InterfaceFile *> Files;
1158 auto File = std::unique_ptr<InterfaceFile>(
1163 std::shared_ptr<InterfaceFile>(
const_cast<InterfaceFile *
>(FI)));
1168 return std::move(File);
1172 const FileType FileKind,
bool Compact) {
1174 Ctx.
Path = std::string(File.getPath());
1188 std::vector<const InterfaceFile *> Files;
1189 Files.emplace_back(&File);
1191 for (
const auto &
Document : File.documents())
1192 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< std::unique_ptr< InterfaceFile > > get(MemoryBufferRef InputBuffer, bool SkipUnknownTriples=false)
Parse and get an InterfaceFile that represents the full library.
static LLVM_ABI Expected< FileType > canRead(MemoryBufferRef InputBuffer)
Determine whether input can be interpreted as TAPI text file.
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...
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
std::string str() const
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 bitSetCase(T &Val, StringRef Str, const T ConstVal)
virtual bool outputting() const =0
virtual bool mapTag(StringRef Tag, bool Default=false)=0
void mapOptionalWithContext(StringRef Key, T &Val, Context &Ctx)
void mapOptional(StringRef Key, T &Val)
virtual void setError(const Twine &)=0
void * getContext() const
void mapRequired(StringRef Key, T &Val)
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)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
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 *Ctx, 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.