LLVM 23.0.0git
TextStub.cpp
Go to the documentation of this file.
1//===- TextStub.cpp -------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implements the text stub file reader/writer.
10//
11//===----------------------------------------------------------------------===//
12
13#include "TextAPIContext.h"
14#include "TextStubCommon.h"
16#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/StringRef.h"
29#include <set>
30
31// clang-format off
32/*
33
34 YAML Format specification.
35
36 The TBD v1 format only support two level address libraries and is per
37 definition application extension safe.
38
39--- # the tag !tapi-tbd-v1 is optional and
40 # shouldn't be emitted to support older linker.
41archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
42 # supported by this file.
43platform: ios # Specifies the platform (macosx, ios, etc)
44install-name: /u/l/libfoo.dylib #
45current-version: 1.2.3 # Optional: defaults to 1.0
46compatibility-version: 1.0 # Optional: defaults to 1.0
47swift-version: 0 # Optional: defaults to 0
48objc-constraint: none # Optional: defaults to none
49exports: # List of export sections
50...
51
52Each export section is defined as following:
53
54 - archs: [ arm64 ] # the list of architecture slices
55 allowed-clients: [ client ] # Optional: List of clients
56 re-exports: [ ] # Optional: List of re-exports
57 symbols: [ _sym ] # Optional: List of symbols
58 objc-classes: [] # Optional: List of Objective-C classes
59 objc-ivars: [] # Optional: List of Objective C Instance
60 # Variables
61 weak-def-symbols: [] # Optional: List of weak defined symbols
62 thread-local-symbols: [] # Optional: List of thread local symbols
63*/
64
65/*
66
67 YAML Format specification.
68
69--- !tapi-tbd-v2
70archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
71 # supported by this file.
72uuids: [ armv7:... ] # Optional: List of architecture and UUID pairs.
73platform: ios # Specifies the platform (macosx, ios, etc)
74flags: [] # Optional:
75install-name: /u/l/libfoo.dylib #
76current-version: 1.2.3 # Optional: defaults to 1.0
77compatibility-version: 1.0 # Optional: defaults to 1.0
78swift-version: 0 # Optional: defaults to 0
79objc-constraint: retain_release # Optional: defaults to retain_release
80parent-umbrella: # Optional:
81exports: # List of export sections
82...
83undefineds: # List of undefineds sections
84...
85
86Each export section is defined as following:
87
88- archs: [ arm64 ] # the list of architecture slices
89 allowed-clients: [ client ] # Optional: List of clients
90 re-exports: [ ] # Optional: List of re-exports
91 symbols: [ _sym ] # Optional: List of symbols
92 objc-classes: [] # Optional: List of Objective-C classes
93 objc-ivars: [] # Optional: List of Objective C Instance
94 # Variables
95 weak-def-symbols: [] # Optional: List of weak defined symbols
96 thread-local-symbols: [] # Optional: List of thread local symbols
97
98Each undefineds section is defined as following:
99- archs: [ arm64 ] # the list of architecture slices
100 symbols: [ _sym ] # Optional: List of symbols
101 objc-classes: [] # Optional: List of Objective-C classes
102 objc-ivars: [] # Optional: List of Objective C Instance Variables
103 weak-ref-symbols: [] # Optional: List of weak defined symbols
104*/
105
106/*
107
108 YAML Format specification.
109
110--- !tapi-tbd-v3
111archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
112 # supported by this file.
113uuids: [ armv7:... ] # Optional: List of architecture and UUID pairs.
114platform: ios # Specifies the platform (macosx, ios, etc)
115flags: [] # Optional:
116install-name: /u/l/libfoo.dylib #
117current-version: 1.2.3 # Optional: defaults to 1.0
118compatibility-version: 1.0 # Optional: defaults to 1.0
119swift-abi-version: 0 # Optional: defaults to 0
120objc-constraint: retain_release # Optional: defaults to retain_release
121parent-umbrella: # Optional:
122exports: # List of export sections
123...
124undefineds: # List of undefineds sections
125...
126
127Each export section is defined as following:
128
129- archs: [ arm64 ] # the list of architecture slices
130 allowed-clients: [ client ] # Optional: List of clients
131 re-exports: [ ] # Optional: List of re-exports
132 symbols: [ _sym ] # Optional: List of symbols
133 objc-classes: [] # Optional: List of Objective-C classes
134 objc-eh-types: [] # Optional: List of Objective-C classes
135 # with EH
136 objc-ivars: [] # Optional: List of Objective C Instance
137 # Variables
138 weak-def-symbols: [] # Optional: List of weak defined symbols
139 thread-local-symbols: [] # Optional: List of thread local symbols
140
141Each undefineds section is defined as following:
142- archs: [ arm64 ] # the list of architecture slices
143 symbols: [ _sym ] # Optional: List of symbols
144 objc-classes: [] # Optional: List of Objective-C classes
145 objc-eh-types: [] # Optional: List of Objective-C classes
146 # with EH
147 objc-ivars: [] # Optional: List of Objective C Instance Variables
148 weak-ref-symbols: [] # Optional: List of weak defined symbols
149*/
150
151/*
152
153 YAML Format specification.
154
155--- !tapi-tbd
156tbd-version: 4 # The tbd version for format
157targets: [ armv7-ios, x86_64-maccatalyst ] # The list of applicable tapi supported target triples
158uuids: # Optional: List of target and UUID pairs.
159 - target: armv7-ios
160 value: ...
161 - target: x86_64-maccatalyst
162 value: ...
163flags: [] # Optional:
164install-name: /u/l/libfoo.dylib #
165current-version: 1.2.3 # Optional: defaults to 1.0
166compatibility-version: 1.0 # Optional: defaults to 1.0
167swift-abi-version: 0 # Optional: defaults to 0
168parent-umbrella: # Optional:
169allowable-clients:
170 - targets: [ armv7-ios ] # Optional:
171 clients: [ clientA ]
172exports: # List of export sections
173...
174re-exports: # List of reexport sections
175...
176undefineds: # List of undefineds sections
177...
178
179Each export and reexport section is defined as following:
180
181- targets: [ arm64-macos ] # The list of target triples associated with symbols
182 symbols: [ _symA ] # Optional: List of symbols
183 objc-classes: [] # Optional: List of Objective-C classes
184 objc-eh-types: [] # Optional: List of Objective-C classes
185 # with EH
186 objc-ivars: [] # Optional: List of Objective C Instance
187 # Variables
188 weak-symbols: [] # Optional: List of weak defined symbols
189 thread-local-symbols: [] # Optional: List of thread local symbols
190- targets: [ arm64-macos, x86_64-maccatalyst ] # Optional: Targets for applicable additional symbols
191 symbols: [ _symB ] # Optional: List of symbols
192
193Each undefineds section is defined as following:
194- targets: [ arm64-macos ] # The list of target triples associated with symbols
195 symbols: [ _symC ] # Optional: List of symbols
196 objc-classes: [] # Optional: List of Objective-C classes
197 objc-eh-types: [] # Optional: List of Objective-C classes
198 # with EH
199 objc-ivars: [] # Optional: List of Objective C Instance Variables
200 weak-symbols: [] # Optional: List of weak defined symbols
201*/
202// clang-format on
203
204using namespace llvm;
205using namespace llvm::yaml;
206using namespace llvm::MachO;
207
208namespace {
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;
219};
220
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;
228};
229
230// Sections for direct target mapping in TBDv4
231struct SymbolSection {
232 TargetList Targets;
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;
239};
240
241struct MetadataSection {
242 enum Option { Clients, Libraries };
243 std::vector<Target> Targets;
244 std::vector<FlowStringRef> Values;
245};
246
247struct UmbrellaSection {
248 std::vector<Target> Targets;
249 std::string Umbrella;
250};
251
252// UUID's for TBDv4 are mapped to target not arch
253struct UUIDv4 {
254 Target TargetID;
255 std::string Value;
256
257 UUIDv4() = default;
258 UUIDv4(const Target &TargetID, const std::string &Value)
259 : TargetID(TargetID), Value(Value) {}
260};
261} // end anonymous namespace.
262
264LLVM_YAML_IS_SEQUENCE_VECTOR(ExportSection)
265LLVM_YAML_IS_SEQUENCE_VECTOR(UndefinedSection)
266// Specific to TBDv4
267LLVM_YAML_IS_SEQUENCE_VECTOR(SymbolSection)
268LLVM_YAML_IS_SEQUENCE_VECTOR(MetadataSection)
269LLVM_YAML_IS_SEQUENCE_VECTOR(UmbrellaSection)
272
273namespace llvm {
274namespace yaml {
275
276template <> struct MappingTraits<ExportSection> {
277 static void mapping(IO &IO, ExportSection &Section) {
278 const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
279 assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
280 "File type is not set in YAML context");
281
282 IO.mapRequired("archs", Section.Architectures);
283 if (Ctx->FileKind == FileType::TBD_V1)
284 IO.mapOptional("allowed-clients", Section.AllowableClients);
285 else
286 IO.mapOptional("allowable-clients", Section.AllowableClients);
287 IO.mapOptional("re-exports", Section.ReexportedLibraries);
288 IO.mapOptional("symbols", Section.Symbols);
289 IO.mapOptional("objc-classes", Section.Classes);
290 if (Ctx->FileKind == FileType::TBD_V3)
291 IO.mapOptional("objc-eh-types", Section.ClassEHs);
292 IO.mapOptional("objc-ivars", Section.IVars);
293 IO.mapOptional("weak-def-symbols", Section.WeakDefSymbols);
294 IO.mapOptional("thread-local-symbols", Section.TLVSymbols);
295 }
296};
297
298template <> struct MappingTraits<UndefinedSection> {
299 static void mapping(IO &IO, UndefinedSection &Section) {
300 const auto *Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
301 assert((!Ctx || Ctx->FileKind != FileType::Invalid) &&
302 "File type is not set in YAML context");
303
304 IO.mapRequired("archs", Section.Architectures);
305 IO.mapOptional("symbols", Section.Symbols);
306 IO.mapOptional("objc-classes", Section.Classes);
307 if (Ctx->FileKind == FileType::TBD_V3)
308 IO.mapOptional("objc-eh-types", Section.ClassEHs);
309 IO.mapOptional("objc-ivars", Section.IVars);
310 IO.mapOptional("weak-ref-symbols", Section.WeakRefSymbols);
311 }
312};
313
314template <> struct MappingTraits<SymbolSection> {
315 static void mapping(IO &IO, SymbolSection &Section) {
316 IO.mapRequired("targets", Section.Targets);
317 // With SkipUnknownTriples, ScalarTraits of Target accepts unknown
318 // arch/platform scalars without erroring, leaving invalid Targets in the
319 // vector. Drop them so downstream code only sees valid Targets.
320 if (!IO.outputting())
321 llvm::erase_if(Section.Targets,
322 [](const Target &T) { return !T.isValid(); });
323 IO.mapOptional("symbols", Section.Symbols);
324 IO.mapOptional("objc-classes", Section.Classes);
325 IO.mapOptional("objc-eh-types", Section.ClassEHs);
326 IO.mapOptional("objc-ivars", Section.Ivars);
327 IO.mapOptional("weak-symbols", Section.WeakSymbols);
328 IO.mapOptional("thread-local-symbols", Section.TlvSymbols);
329 }
330};
331
332template <> struct MappingTraits<UmbrellaSection> {
333 static void mapping(IO &IO, UmbrellaSection &Section) {
334 IO.mapRequired("targets", Section.Targets);
335 if (!IO.outputting())
336 llvm::erase_if(Section.Targets,
337 [](const Target &T) { return !T.isValid(); });
338 IO.mapRequired("umbrella", Section.Umbrella);
339 }
340};
341
342template <> struct MappingTraits<UUIDv4> {
343 static void mapping(IO &IO, UUIDv4 &UUID) {
344 IO.mapRequired("target", UUID.TargetID);
345 IO.mapRequired("value", UUID.Value);
346 }
347};
348
349template <>
350struct MappingContextTraits<MetadataSection, MetadataSection::Option> {
351 static void mapping(IO &IO, MetadataSection &Section,
352 MetadataSection::Option &OptionKind) {
353 IO.mapRequired("targets", Section.Targets);
354 if (!IO.outputting())
355 llvm::erase_if(Section.Targets,
356 [](const Target &T) { return !T.isValid(); });
357 switch (OptionKind) {
358 case MetadataSection::Option::Clients:
359 IO.mapRequired("clients", Section.Values);
360 return;
361 case MetadataSection::Option::Libraries:
362 IO.mapRequired("libraries", Section.Values);
363 return;
364 }
365 llvm_unreachable("unexpected option for metadata");
366 }
367};
368
369template <> struct ScalarBitSetTraits<TBDFlags> {
370 static void bitset(IO &IO, TBDFlags &Flags) {
371 IO.bitSetCase(Flags, "flat_namespace", TBDFlags::FlatNamespace);
372 IO.bitSetCase(Flags, "not_app_extension_safe",
374 IO.bitSetCase(Flags, "installapi", TBDFlags::InstallAPI);
375 IO.bitSetCase(Flags, "not_for_dyld_shared_cache",
377 }
378};
379
380template <> struct ScalarTraits<Target> {
381 static void output(const Target &Value, void *, raw_ostream &OS) {
382 OS << Value.Arch << "-";
383 switch (Value.Platform) {
384#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
385 marketing) \
386 case PLATFORM_##platform: \
387 OS << #tapi_target; \
388 break;
389#include "llvm/BinaryFormat/MachO.def"
390 }
391 }
392
394 auto Result = Target::create(Scalar);
395 if (!Result) {
396 consumeError(Result.takeError());
397 return "unparsable target";
398 }
399
400 Value = *Result;
401
402 const bool SkipUnknownTriples =
403 reinterpret_cast<TextAPIContext *>(Ctx)->SkipUnknownTriples;
404 if (!Value.isValid() && !SkipUnknownTriples)
405 return "unknown target";
406
407 return {};
408 }
409
411};
412
413template <> struct MappingTraits<const InterfaceFile *> {
415 explicit NormalizedTBD(IO &IO) {}
417 Architectures = File->getArchitectures();
418 Platforms = File->getPlatforms();
419 InstallName = File->getInstallName();
420 CurrentVersion = PackedVersion(File->getCurrentVersion());
421 CompatibilityVersion = PackedVersion(File->getCompatibilityVersion());
422 SwiftABIVersion = File->getSwiftABIVersion();
423 ObjCConstraint = File->getObjCConstraint();
424
426 if (!File->isApplicationExtensionSafe())
428
429 if (!File->isTwoLevelNamespace())
431
432 if (!File->umbrellas().empty())
433 ParentUmbrella = File->umbrellas().begin()->second;
434
435 std::set<ArchitectureSet> ArchSet;
436 for (const auto &Library : File->allowableClients())
437 ArchSet.insert(Library.getArchitectures());
438
439 for (const auto &Library : File->reexportedLibraries())
440 ArchSet.insert(Library.getArchitectures());
441
442 std::map<const Symbol *, ArchitectureSet> SymbolToArchSet;
443 for (const auto *Symbol : File->symbols()) {
445 SymbolToArchSet[Symbol] = Architectures;
446 ArchSet.insert(Architectures);
447 }
448
449 for (auto Architectures : ArchSet) {
450 ExportSection Section;
451 Section.Architectures = Architectures;
452
453 for (const auto &Library : File->allowableClients())
454 if (Library.getArchitectures() == Architectures)
455 Section.AllowableClients.emplace_back(Library.getInstallName());
456
457 for (const auto &Library : File->reexportedLibraries())
458 if (Library.getArchitectures() == Architectures)
459 Section.ReexportedLibraries.emplace_back(Library.getInstallName());
460
461 for (const auto &SymArch : SymbolToArchSet) {
462 if (SymArch.second != Architectures)
463 continue;
464
465 const auto *Symbol = SymArch.first;
466 switch (Symbol->getKind()) {
468 if (Symbol->isWeakDefined())
469 Section.WeakDefSymbols.emplace_back(Symbol->getName());
470 else if (Symbol->isThreadLocalValue())
471 Section.TLVSymbols.emplace_back(Symbol->getName());
472 else
473 Section.Symbols.emplace_back(Symbol->getName());
474 break;
476 if (File->getFileType() != FileType::TBD_V3)
477 Section.Classes.emplace_back(
478 copyString("_" + Symbol->getName().str()));
479 else
480 Section.Classes.emplace_back(Symbol->getName());
481 break;
483 if (File->getFileType() != FileType::TBD_V3)
484 Section.Symbols.emplace_back(
485 copyString("_OBJC_EHTYPE_$_" + Symbol->getName().str()));
486 else
487 Section.ClassEHs.emplace_back(Symbol->getName());
488 break;
490 if (File->getFileType() != FileType::TBD_V3)
491 Section.IVars.emplace_back(
492 copyString("_" + Symbol->getName().str()));
493 else
494 Section.IVars.emplace_back(Symbol->getName());
495 break;
496 }
497 }
498 llvm::sort(Section.Symbols);
499 llvm::sort(Section.Classes);
500 llvm::sort(Section.ClassEHs);
501 llvm::sort(Section.IVars);
502 llvm::sort(Section.WeakDefSymbols);
503 llvm::sort(Section.TLVSymbols);
504 Exports.emplace_back(std::move(Section));
505 }
506
507 ArchSet.clear();
508 SymbolToArchSet.clear();
509
510 for (const auto *Symbol : File->undefineds()) {
512 SymbolToArchSet[Symbol] = Architectures;
513 ArchSet.insert(Architectures);
514 }
515
516 for (auto Architectures : ArchSet) {
517 UndefinedSection Section;
518 Section.Architectures = Architectures;
519
520 for (const auto &SymArch : SymbolToArchSet) {
521 if (SymArch.second != Architectures)
522 continue;
523
524 const auto *Symbol = SymArch.first;
525 switch (Symbol->getKind()) {
528 Section.WeakRefSymbols.emplace_back(Symbol->getName());
529 else
530 Section.Symbols.emplace_back(Symbol->getName());
531 break;
533 if (File->getFileType() != FileType::TBD_V3)
534 Section.Classes.emplace_back(
535 copyString("_" + Symbol->getName().str()));
536 else
537 Section.Classes.emplace_back(Symbol->getName());
538 break;
540 if (File->getFileType() != FileType::TBD_V3)
541 Section.Symbols.emplace_back(
542 copyString("_OBJC_EHTYPE_$_" + Symbol->getName().str()));
543 else
544 Section.ClassEHs.emplace_back(Symbol->getName());
545 break;
547 if (File->getFileType() != FileType::TBD_V3)
548 Section.IVars.emplace_back(
549 copyString("_" + Symbol->getName().str()));
550 else
551 Section.IVars.emplace_back(Symbol->getName());
552 break;
553 }
554 }
555 llvm::sort(Section.Symbols);
556 llvm::sort(Section.Classes);
557 llvm::sort(Section.ClassEHs);
558 llvm::sort(Section.IVars);
559 llvm::sort(Section.WeakRefSymbols);
560 Undefineds.emplace_back(std::move(Section));
561 }
562 }
563
564 // TBD v1 - TBD v3 files only support one platform and several
565 // architectures. It is possible to have more than one platform for TBD v3
566 // files, but the architectures don't apply to all
567 // platforms, specifically to filter out the i386 slice from
568 // platform macCatalyst.
570 const PlatformSet &Platforms) {
571 TargetList Targets;
572
573 for (auto Platform : Platforms) {
574 Platform = mapToPlatformType(Platform, Architectures.hasX86());
575
576 for (const auto &&Architecture : Architectures) {
577 if ((Architecture == AK_i386) && (Platform == PLATFORM_MACCATALYST))
578 continue;
579
580 Target T(Architecture, Platform);
581 if (!T.isValid())
582 continue;
583 Targets.push_back(T);
584 }
585 }
586 return Targets;
587 }
588
590 auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
591 assert(Ctx);
592
593 auto *File = new InterfaceFile;
594 File->setPath(Ctx->Path);
595 File->setFileType(Ctx->FileKind);
596 File->addTargets(synthesizeTargets(Architectures, Platforms));
597 File->setInstallName(InstallName);
598 File->setCurrentVersion(CurrentVersion);
599 File->setCompatibilityVersion(CompatibilityVersion);
600 File->setSwiftABIVersion(SwiftABIVersion);
601 File->setObjCConstraint(ObjCConstraint);
602 for (const auto &Target : File->targets())
603 File->addParentUmbrella(Target, ParentUmbrella);
604
605 if (Ctx->FileKind == FileType::TBD_V1) {
606 File->setTwoLevelNamespace();
607 File->setApplicationExtensionSafe();
608 } else {
609 File->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
610 File->setApplicationExtensionSafe(
612 }
613
614 // For older file formats, the segment where the symbol
615 // comes from is unknown, treat all symbols as Data
616 // in these cases.
617 const auto Flags = SymbolFlags::Data;
618
619 for (const auto &Section : Exports) {
620 const auto Targets =
621 synthesizeTargets(Section.Architectures, Platforms);
622 if (Targets.empty())
623 continue;
624
625 for (const auto &Lib : Section.AllowableClients)
626 for (const auto &Target : Targets)
627 File->addAllowableClient(Lib, Target);
628
629 for (const auto &Lib : Section.ReexportedLibraries)
630 for (const auto &Target : Targets)
631 File->addReexportedLibrary(Lib, Target);
632
633 for (const auto &Symbol : Section.Symbols) {
634 if (Ctx->FileKind != FileType::TBD_V3 &&
635 Symbol.value.starts_with(ObjC2EHTypePrefix))
636 File->addSymbol(EncodeKind::ObjectiveCClassEHType,
637 Symbol.value.drop_front(15), Targets, Flags);
638 else
639 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets, Flags);
640 }
641 for (auto &Symbol : Section.Classes) {
642 auto Name = Symbol.value;
643 if (Ctx->FileKind != FileType::TBD_V3)
644 Name = Name.drop_front();
645 File->addSymbol(EncodeKind::ObjectiveCClass, Name, Targets, Flags);
646 }
647 for (auto &Symbol : Section.ClassEHs)
648 File->addSymbol(EncodeKind::ObjectiveCClassEHType, Symbol, Targets,
649 Flags);
650 for (auto &Symbol : Section.IVars) {
651 auto Name = Symbol.value;
652 if (Ctx->FileKind != FileType::TBD_V3)
653 Name = Name.drop_front();
654 File->addSymbol(EncodeKind::ObjectiveCInstanceVariable, Name, Targets,
655 Flags);
656 }
657 for (auto &Symbol : Section.WeakDefSymbols)
658 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,
660 for (auto &Symbol : Section.TLVSymbols)
661 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,
663 }
664
665 for (const auto &Section : Undefineds) {
666 const auto Targets =
667 synthesizeTargets(Section.Architectures, Platforms);
668 if (Targets.empty())
669 continue;
670 for (auto &Symbol : Section.Symbols) {
671 if (Ctx->FileKind != FileType::TBD_V3 &&
672 Symbol.value.starts_with(ObjC2EHTypePrefix))
673 File->addSymbol(EncodeKind::ObjectiveCClassEHType,
674 Symbol.value.drop_front(15), Targets,
676 else
677 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,
679 }
680 for (auto &Symbol : Section.Classes) {
681 auto Name = Symbol.value;
682 if (Ctx->FileKind != FileType::TBD_V3)
683 Name = Name.drop_front();
684 File->addSymbol(EncodeKind::ObjectiveCClass, Name, Targets,
686 }
687 for (auto &Symbol : Section.ClassEHs)
688 File->addSymbol(EncodeKind::ObjectiveCClassEHType, Symbol, Targets,
690 for (auto &Symbol : Section.IVars) {
691 auto Name = Symbol.value;
692 if (Ctx->FileKind != FileType::TBD_V3)
693 Name = Name.drop_front();
694 File->addSymbol(EncodeKind::ObjectiveCInstanceVariable, Name, Targets,
696 }
697 for (auto &Symbol : Section.WeakRefSymbols)
698 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,
700 Flags);
701 }
702
703 return File;
704 }
705
708 if (String.empty())
709 return {};
710
711 void *Ptr = Allocator.Allocate(String.size(), 1);
712 memcpy(Ptr, String.data(), String.size());
713 return StringRef(reinterpret_cast<const char *>(Ptr), String.size());
714 }
715
716 std::vector<Architecture> Architectures;
717 std::vector<UUID> UUIDs;
722 SwiftVersion SwiftABIVersion{0};
726 std::vector<ExportSection> Exports;
727 std::vector<UndefinedSection> Undefineds;
728 };
729
731 if (IO.mapTag("!tapi-tbd", false))
732 Ctx->FileKind = FileType::TBD_V4;
733 else if (IO.mapTag("!tapi-tbd-v3", false))
734 Ctx->FileKind = FileType::TBD_V3;
735 else if (IO.mapTag("!tapi-tbd-v2", false))
736 Ctx->FileKind = FileType::TBD_V2;
737 else if (IO.mapTag("!tapi-tbd-v1", false) ||
738 IO.mapTag("tag:yaml.org,2002:map", false))
739 Ctx->FileKind = FileType::TBD_V1;
740 else {
741 Ctx->FileKind = FileType::Invalid;
742 return;
743 }
744 }
745
746 static void mapping(IO &IO, const InterfaceFile *&File) {
747 auto *Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
748 assert((!Ctx || !IO.outputting() ||
749 (Ctx && Ctx->FileKind != FileType::Invalid)) &&
750 "File type is not set in YAML context");
751
752 if (!IO.outputting()) {
754 switch (Ctx->FileKind) {
755 default:
756 break;
757 case FileType::TBD_V4:
758 mapKeysToValuesV4(IO, File);
759 return;
761 IO.setError("unsupported file type");
762 return;
763 }
764 } else {
765 // Set file type when writing.
766 switch (Ctx->FileKind) {
767 default:
768 llvm_unreachable("unexpected file type");
769 case FileType::TBD_V4:
770 mapKeysToValuesV4(IO, File);
771 return;
772 case FileType::TBD_V3:
773 IO.mapTag("!tapi-tbd-v3", true);
774 break;
775 case FileType::TBD_V2:
776 IO.mapTag("!tapi-tbd-v2", true);
777 break;
778 case FileType::TBD_V1:
779 // Don't write the tag into the .tbd file for TBD v1
780 break;
781 }
782 }
783 mapKeysToValues(Ctx->FileKind, IO, File);
784 }
785
786 using SectionList = std::vector<SymbolSection>;
788 explicit NormalizedTBD_V4(IO &IO) {}
790 auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
791 assert(Ctx);
792 TBDVersion = Ctx->FileKind >> 4;
793 for (auto &T : File->targets())
794 if (T.isValid())
795 Targets.push_back(T);
796 InstallName = File->getInstallName();
797 CurrentVersion = File->getCurrentVersion();
798 CompatibilityVersion = File->getCompatibilityVersion();
799 SwiftABIVersion = File->getSwiftABIVersion();
800
802 if (!File->isApplicationExtensionSafe())
804
805 if (!File->isTwoLevelNamespace())
807
808 if (File->isOSLibNotForSharedCache())
810
811 {
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);
816
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;
822 ParentUmbrellas.emplace_back(std::move(CurrentSection));
823 }
824 }
825
826 assignTargetsToLibrary(File->allowableClients(), AllowableClients);
827 assignTargetsToLibrary(File->reexportedLibraries(), ReexportedLibraries);
828
829 auto handleSymbols =
830 [](SectionList &CurrentSections,
832 std::set<TargetList> TargetSet;
833 std::map<const Symbol *, TargetList> SymbolToTargetList;
834 for (const auto *Symbol : Symbols) {
836 for (auto &T : Symbol->targets())
837 if (T.isValid())
838 Targets.push_back(T);
839
840 SymbolToTargetList[Symbol] = Targets;
841 TargetSet.emplace(std::move(Targets));
842 }
843 for (const auto &TargetIDs : TargetSet) {
844 SymbolSection CurrentSection;
845 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
846 TargetIDs.begin(), TargetIDs.end());
847
848 for (const auto &IT : SymbolToTargetList) {
849 if (IT.second != TargetIDs)
850 continue;
851
852 const auto *Symbol = IT.first;
853 switch (Symbol->getKind()) {
855 if (Symbol->isWeakDefined())
856 CurrentSection.WeakSymbols.emplace_back(Symbol->getName());
857 else if (Symbol->isThreadLocalValue())
858 CurrentSection.TlvSymbols.emplace_back(Symbol->getName());
859 else
860 CurrentSection.Symbols.emplace_back(Symbol->getName());
861 break;
863 CurrentSection.Classes.emplace_back(Symbol->getName());
864 break;
866 CurrentSection.ClassEHs.emplace_back(Symbol->getName());
867 break;
869 CurrentSection.Ivars.emplace_back(Symbol->getName());
870 break;
871 }
872 }
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));
880 }
881 };
882
883 handleSymbols(Exports, File->exports());
884 handleSymbols(Reexports, File->reexports());
885 handleSymbols(Undefineds, File->undefineds());
886 }
887
889 auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());
890 assert(Ctx);
891
892 auto *File = new InterfaceFile;
893 File->setPath(Ctx->Path);
894 File->setFileType(Ctx->FileKind);
895 File->addTargets(Targets);
896 File->setInstallName(InstallName);
897 File->setCurrentVersion(CurrentVersion);
898 File->setCompatibilityVersion(CompatibilityVersion);
899 File->setSwiftABIVersion(SwiftABIVersion);
900 for (const auto &CurrentSection : ParentUmbrellas)
901 for (const auto &target : CurrentSection.Targets)
902 File->addParentUmbrella(target, CurrentSection.Umbrella);
903 File->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
904 File->setApplicationExtensionSafe(
906 File->setOSLibNotForSharedCache(
908
909 for (const auto &CurrentSection : AllowableClients) {
910 for (const auto &lib : CurrentSection.Values)
911 for (const auto &Target : CurrentSection.Targets)
912 File->addAllowableClient(lib, Target);
913 }
914
915 for (const auto &CurrentSection : ReexportedLibraries) {
916 for (const auto &Lib : CurrentSection.Values)
917 for (const auto &Target : CurrentSection.Targets)
918 File->addReexportedLibrary(Lib, Target);
919 }
920
921 auto handleSymbols = [File](const SectionList &CurrentSections,
922 SymbolFlags InputFlag = SymbolFlags::None) {
923 // For older file formats, the segment where the symbol
924 // comes from is unknown, treat all symbols as Data
925 // in these cases.
926 const SymbolFlags Flag = InputFlag | SymbolFlags::Data;
927
928 for (const auto &CurrentSection : CurrentSections) {
929 if (CurrentSection.Targets.empty())
930 continue;
931
932 for (auto &sym : CurrentSection.Symbols)
933 File->addSymbol(EncodeKind::GlobalSymbol, sym,
934 CurrentSection.Targets, Flag);
935
936 for (auto &sym : CurrentSection.Classes)
937 File->addSymbol(EncodeKind::ObjectiveCClass, sym,
938 CurrentSection.Targets, Flag);
939
940 for (auto &sym : CurrentSection.ClassEHs)
941 File->addSymbol(EncodeKind::ObjectiveCClassEHType, sym,
942 CurrentSection.Targets, Flag);
943
944 for (auto &sym : CurrentSection.Ivars)
945 File->addSymbol(EncodeKind::ObjectiveCInstanceVariable, sym,
946 CurrentSection.Targets, Flag);
947
948 SymbolFlags SymFlag =
952 for (auto &sym : CurrentSection.WeakSymbols) {
953 File->addSymbol(EncodeKind::GlobalSymbol, sym,
954 CurrentSection.Targets, Flag | SymFlag);
955 }
956
957 for (auto &sym : CurrentSection.TlvSymbols)
958 File->addSymbol(EncodeKind::GlobalSymbol, sym,
959 CurrentSection.Targets,
961 }
962 };
963
964 handleSymbols(Exports);
965 handleSymbols(Reexports, SymbolFlags::Rexported);
966 handleSymbols(Undefineds, SymbolFlags::Undefined);
967
968 return File;
969 }
970
971 unsigned TBDVersion;
972 std::vector<UUIDv4> UUIDs;
977 SwiftVersion SwiftABIVersion{0};
978 std::vector<MetadataSection> AllowableClients;
979 std::vector<MetadataSection> ReexportedLibraries;
981 std::vector<UmbrellaSection> ParentUmbrellas;
985
986 private:
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) {
992 TargetList targets(library.targets());
993 valueToTargetList[&library] = targets;
994 targetSet.emplace(std::move(targets));
995 }
996
997 for (const auto &targets : targetSet) {
998 MetadataSection CurrentSection;
999 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),
1000 targets.begin(), targets.end());
1001
1002 for (const auto &it : valueToTargetList) {
1003 if (it.second != targets)
1004 continue;
1005
1006 CurrentSection.Values.emplace_back(it.first->getInstallName());
1007 }
1008 llvm::sort(CurrentSection.Values);
1009 Section.emplace_back(std::move(CurrentSection));
1010 }
1011 }
1012 };
1013
1014 static void mapKeysToValues(FileType FileKind, IO &IO,
1015 const InterfaceFile *&File) {
1017 std::vector<UUID> EmptyUUID;
1018 IO.mapRequired("archs", Keys->Architectures);
1019 if (FileKind != FileType::TBD_V1)
1020 IO.mapOptional("uuids", EmptyUUID);
1021 IO.mapRequired("platform", Keys->Platforms);
1022 if (FileKind != FileType::TBD_V1)
1023 IO.mapOptional("flags", Keys->Flags, TBDFlags::None);
1024 IO.mapRequired("install-name", Keys->InstallName);
1025 IO.mapOptional("current-version", Keys->CurrentVersion,
1026 PackedVersion(1, 0, 0));
1027 IO.mapOptional("compatibility-version", Keys->CompatibilityVersion,
1028 PackedVersion(1, 0, 0));
1029 if (FileKind != FileType::TBD_V3)
1030 IO.mapOptional("swift-version", Keys->SwiftABIVersion, SwiftVersion(0));
1031 else
1032 IO.mapOptional("swift-abi-version", Keys->SwiftABIVersion,
1033 SwiftVersion(0));
1034 IO.mapOptional("objc-constraint", Keys->ObjCConstraint,
1035 (FileKind == FileType::TBD_V1)
1038 if (FileKind != FileType::TBD_V1)
1039 IO.mapOptional("parent-umbrella", Keys->ParentUmbrella, StringRef());
1040 IO.mapOptional("exports", Keys->Exports);
1041 if (FileKind != FileType::TBD_V1)
1042 IO.mapOptional("undefineds", Keys->Undefineds);
1043 }
1044
1045 static void mapKeysToValuesV4(IO &IO, const InterfaceFile *&File) {
1047 File);
1048 std::vector<UUIDv4> EmptyUUID;
1049 IO.mapTag("!tapi-tbd", true);
1050 IO.mapRequired("tbd-version", Keys->TBDVersion);
1051 IO.mapRequired("targets", Keys->Targets);
1052 if (!IO.outputting())
1053 llvm::erase_if(Keys->Targets,
1054 [](const Target &T) { return !T.isValid(); });
1055 IO.mapOptional("uuids", EmptyUUID);
1056 IO.mapOptional("flags", Keys->Flags, TBDFlags::None);
1057 IO.mapRequired("install-name", Keys->InstallName);
1058 IO.mapOptional("current-version", Keys->CurrentVersion,
1059 PackedVersion(1, 0, 0));
1060 IO.mapOptional("compatibility-version", Keys->CompatibilityVersion,
1061 PackedVersion(1, 0, 0));
1062 IO.mapOptional("swift-abi-version", Keys->SwiftABIVersion, SwiftVersion(0));
1063 IO.mapOptional("parent-umbrella", Keys->ParentUmbrellas);
1064 auto OptionKind = MetadataSection::Option::Clients;
1065 IO.mapOptionalWithContext("allowable-clients", Keys->AllowableClients,
1066 OptionKind);
1067 OptionKind = MetadataSection::Option::Libraries;
1068 IO.mapOptionalWithContext("reexported-libraries", Keys->ReexportedLibraries,
1069 OptionKind);
1070 IO.mapOptional("exports", Keys->Exports);
1071 IO.mapOptional("reexports", Keys->Reexports);
1072 IO.mapOptional("undefineds", Keys->Undefineds);
1073 }
1074};
1075
1076template <>
1077struct DocumentListTraits<std::vector<const MachO::InterfaceFile *>> {
1078 static size_t size(IO &IO, std::vector<const MachO::InterfaceFile *> &Seq) {
1079 return Seq.size();
1080 }
1081 static const InterfaceFile *&
1082 element(IO &IO, std::vector<const InterfaceFile *> &Seq, size_t Index) {
1083 if (Index >= Seq.size())
1084 Seq.resize(Index + 1);
1085 return Seq[Index];
1086 }
1087};
1088
1089} // end namespace yaml.
1090} // namespace llvm
1091
1092static void DiagHandler(const SMDiagnostic &Diag, void *Context) {
1093 auto *File = static_cast<TextAPIContext *>(Context);
1094 SmallString<1024> Message;
1095 raw_svector_ostream S(Message);
1096
1097 SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(), File->Path,
1098 Diag.getLineNo(), Diag.getColumnNo(), Diag.getKind(),
1099 Diag.getMessage(), Diag.getLineContents(),
1100 Diag.getRanges(), Diag.getFixIts());
1101
1102 NewDiag.print(nullptr, S);
1103 File->ErrorMessage = ("malformed file\n" + Message).str();
1104}
1105
1107 auto TAPIFile = InputBuffer.getBuffer().trim();
1108 if (TAPIFile.starts_with("{") && TAPIFile.ends_with("}"))
1109 return FileType::TBD_V5;
1110
1111 if (!TAPIFile.ends_with("..."))
1112 return createStringError(std::errc::not_supported, "unsupported file type");
1113
1114 if (TAPIFile.starts_with("--- !tapi-tbd"))
1115 return FileType::TBD_V4;
1116
1117 if (TAPIFile.starts_with("--- !tapi-tbd-v3"))
1118 return FileType::TBD_V3;
1119
1120 if (TAPIFile.starts_with("--- !tapi-tbd-v2"))
1121 return FileType::TBD_V2;
1122
1123 if (TAPIFile.starts_with("--- !tapi-tbd-v1") ||
1124 TAPIFile.starts_with("---\narchs:"))
1125 return FileType::TBD_V1;
1126
1127 return createStringError(std::errc::not_supported, "unsupported file type");
1128}
1129
1131TextAPIReader::get(MemoryBufferRef InputBuffer, bool SkipUnknownTriples) {
1132 TextAPIContext Ctx;
1133
1134 Ctx.SkipUnknownTriples = SkipUnknownTriples;
1135 Ctx.Path = std::string(InputBuffer.getBufferIdentifier());
1136 if (auto FTOrErr = canRead(InputBuffer))
1137 Ctx.FileKind = *FTOrErr;
1138 else
1139 return FTOrErr.takeError();
1140
1141 // Handle JSON Format.
1142 if (Ctx.FileKind >= FileType::TBD_V5) {
1143 auto FileOrErr = getInterfaceFileFromJSON(InputBuffer.getBuffer());
1144 if (!FileOrErr)
1145 return FileOrErr.takeError();
1146
1147 (*FileOrErr)->setPath(Ctx.Path);
1148 return std::move(*FileOrErr);
1149 }
1150 yaml::Input YAMLIn(InputBuffer.getBuffer(), &Ctx, DiagHandler, &Ctx);
1151
1152 // Fill vector with interface file objects created by parsing the YAML file.
1153 std::vector<const InterfaceFile *> Files;
1154 YAMLIn >> Files;
1155
1156 // YAMLIn dynamically allocates for Interface file and in case of error,
1157 // memory leak will occur unless wrapped around unique_ptr
1158 auto File = std::unique_ptr<InterfaceFile>(
1159 const_cast<InterfaceFile *>(Files.front()));
1160
1161 for (const InterfaceFile *FI : llvm::drop_begin(Files))
1162 File->addDocument(
1163 std::shared_ptr<InterfaceFile>(const_cast<InterfaceFile *>(FI)));
1164
1165 if (YAMLIn.error())
1166 return make_error<StringError>(Ctx.ErrorMessage, YAMLIn.error());
1167
1168 return std::move(File);
1169}
1170
1172 const FileType FileKind, bool Compact) {
1173 TextAPIContext Ctx;
1174 Ctx.Path = std::string(File.getPath());
1175
1176 // Prefer parameter for format if passed, otherwise fallback to the File
1177 // FileType.
1178 Ctx.FileKind =
1179 (FileKind == FileType::Invalid) ? File.getFileType() : FileKind;
1180
1181 // Write out in JSON format.
1182 if (Ctx.FileKind >= FileType::TBD_V5) {
1183 return serializeInterfaceFileToJSON(OS, File, Ctx.FileKind, Compact);
1184 }
1185
1186 llvm::yaml::Output YAMLOut(OS, &Ctx, /*WrapColumn=*/80);
1187
1188 std::vector<const InterfaceFile *> Files;
1189 Files.emplace_back(&File);
1190
1191 for (const auto &Document : File.documents())
1192 Files.emplace_back(Document.get());
1193
1194 // Stream out yaml.
1195 YAMLOut << Files;
1196
1197 return Error::success();
1198}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
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.
#define T
Replace intrinsics with calls to vector library
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallString class.
std::pair< llvm::MachO::Target, std::string > UUID
@ NotApplicationExtensionSafe
@ InstallAPI
@ FlatNamespace
@ None
@ OSLibNotForSharedCache
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.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Defines the interface file.
SymbolSet::const_filtered_symbol_range const_filtered_symbol_range
bool isWeakDefined() const
Definition Symbol.h:110
const_target_range targets() const
Definition Symbol.h:149
bool isThreadLocalValue() const
Definition Symbol.h:118
ArchitectureSet getArchitectures() const
Definition Symbol.h:105
StringRef getName() const
Definition Symbol.h:104
EncodeKind getKind() const
Definition Symbol.h:103
bool isWeakReferenced() const
Definition Symbol.h:114
static LLVM_ABI llvm::Expected< Target > create(StringRef Target)
Definition Target.cpp:17
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...
Definition SourceMgr.h:303
LLVM_ABI void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
SourceMgr::DiagKind getKind() const
Definition SourceMgr.h:333
int getLineNo() const
Definition SourceMgr.h:331
StringRef getLineContents() const
Definition SourceMgr.h:335
SMLoc getLoc() const
Definition SourceMgr.h:329
StringRef getMessage() const
Definition SourceMgr.h:334
ArrayRef< SMFixIt > getFixIts() const
Definition SourceMgr.h:340
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
Definition SourceMgr.h:336
const SourceMgr * getSourceMgr() const
Definition SourceMgr.h:328
int getColumnNo() const
Definition SourceMgr.h:332
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
Definition StringRef.h:844
Target - Wrapper for Target specific information.
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
A YAML Stream is a sequence of Documents.
Definition YAMLParser.h:538
void bitSetCase(T &Val, StringRef Str, const T ConstVal)
Definition YAMLTraits.h:760
virtual bool outputting() const =0
virtual bool mapTag(StringRef Tag, bool Default=false)=0
void mapOptionalWithContext(StringRef Key, T &Val, Context &Ctx)
Definition YAMLTraits.h:812
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:800
virtual void setError(const Twine &)=0
void * getContext() const
void mapRequired(StringRef Key, T &Val)
Definition YAMLTraits.h:790
The Input class is used to parse a yaml document into in-memory structs and vectors.
std::error_code error() override
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.
Definition FileTypes.h:15
@ Invalid
Invalid file type.
Definition FileTypes.h:17
@ TBD_V1
Text-based stub file (.tbd) version 1.0.
Definition FileTypes.h:29
@ TBD_V3
Text-based stub file (.tbd) version 3.0.
Definition FileTypes.h:35
@ TBD_V5
Text-based stub file (.tbd) version 5.0.
Definition FileTypes.h:41
@ TBD_V4
Text-based stub file (.tbd) version 4.0.
Definition FileTypes.h:38
@ TBD_V2
Text-based stub file (.tbd) version 2.0.
Definition FileTypes.h:32
Error serializeInterfaceFileToJSON(raw_ostream &OS, const InterfaceFile &File, const FileType FileKind, bool Compact)
SmallSet< PlatformType, 3 > PlatformSet
Definition Platform.h:23
ObjCConstraintType
Defines a list of Objective-C constraints.
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
LLVM_ABI PlatformType mapToPlatformType(PlatformType Platform, bool WantSim)
Definition Platform.cpp:21
Expected< std::unique_ptr< InterfaceFile > > getInterfaceFileFromJSON(StringRef JSON)
SymbolFlags
Symbol flags.
Definition Symbol.h:25
@ ThreadLocalValue
Thread-local value symbol.
Definition Symbol.h:30
@ Rexported
Rexported.
Definition Symbol.h:42
@ WeakReferenced
Weak referenced symbol.
Definition Symbol.h:36
@ WeakDefined
Weak defined symbol.
Definition Symbol.h:33
@ Undefined
Undefined.
Definition Symbol.h:39
@ Data
Data Segment.
Definition Symbol.h:45
SmallVector< Target, 5 > TargetList
Definition Symbol.h:82
constexpr StringLiteral ObjC2EHTypePrefix
Definition Symbol.h:66
QuotingType
Describe which type of quotes should be used when quoting is necessary.
Definition YAMLTraits.h:132
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.
Definition STLExtras.h:315
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1635
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition STLExtras.h:2191
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874
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...
Definition YAMLTraits.h:265
static void mapping(IO &IO, MetadataSection &Section, MetadataSection::Option &OptionKind)
Definition TextStub.cpp:351
This class is similar to MappingTraits<T> but allows you to pass in additional context for each map o...
Definition YAMLTraits.h:86
static void mapping(IO &IO, ExportSection &Section)
Definition TextStub.cpp:277
static void mapping(IO &IO, SymbolSection &Section)
Definition TextStub.cpp:315
static void mapping(IO &IO, UUIDv4 &UUID)
Definition TextStub.cpp:343
static void mapping(IO &IO, UmbrellaSection &Section)
Definition TextStub.cpp:333
static void mapping(IO &IO, UndefinedSection &Section)
Definition TextStub.cpp:299
TargetList synthesizeTargets(ArchitectureSet Architectures, const PlatformSet &Platforms)
Definition TextStub.cpp:569
static void mapKeysToValuesV4(IO &IO, const InterfaceFile *&File)
static void setFileTypeForInput(TextAPIContext *Ctx, IO &IO)
Definition TextStub.cpp:730
static void mapping(IO &IO, const InterfaceFile *&File)
Definition TextStub.cpp:746
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.
Definition YAMLTraits.h:63
static void bitset(IO &IO, TBDFlags &Flags)
Definition TextStub.cpp:370
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
Definition YAMLTraits.h:124
static StringRef input(StringRef Scalar, void *Ctx, Target &Value)
Definition TextStub.cpp:393
static void output(const Target &Value, void *, raw_ostream &OS)
Definition TextStub.cpp:381
static QuotingType mustQuote(StringRef)
Definition TextStub.cpp:410
This class should be specialized by type that requires custom conversion to/from a yaml scalar.
Definition YAMLTraits.h:150