LLVM: lib/TextAPI/TextStub.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

28#include

29#include

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204using namespace llvm;

207

208namespace {

209struct ExportSection {

210 std::vector Architectures;

211 std::vector AllowableClients;

212 std::vector ReexportedLibraries;

213 std::vector Symbols;

214 std::vector Classes;

215 std::vector ClassEHs;

216 std::vector IVars;

217 std::vector WeakDefSymbols;

218 std::vector TLVSymbols;

219};

220

221struct UndefinedSection {

222 std::vector Architectures;

223 std::vector Symbols;

224 std::vector Classes;

225 std::vector ClassEHs;

226 std::vector IVars;

227 std::vector WeakRefSymbols;

228};

229

230

231struct SymbolSection {

233 std::vector Symbols;

234 std::vector Classes;

235 std::vector ClassEHs;

236 std::vector Ivars;

237 std::vector WeakSymbols;

238 std::vector TlvSymbols;

239};

240

241struct MetadataSection {

242 enum Option { Clients, Libraries };

243 std::vector Targets;

244 std::vector Values;

245};

246

247struct UmbrellaSection {

248 std::vector Targets;

249 std::string Umbrella;

250};

251

252

253struct UUIDv4 {

255 std::string Value;

256

257 UUIDv4() = default;

258 UUIDv4(const Target &TargetID, const std::string &Value)

259 : TargetID(TargetID), Value(Value) {}

260};

261}

262

266

272

273namespace llvm {

274namespace yaml {

275

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

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

315 static void mapping(IO &IO, SymbolSection &Section) {

316 IO.mapRequired("targets", Section.Targets);

317 IO.mapOptional("symbols", Section.Symbols);

318 IO.mapOptional("objc-classes", Section.Classes);

319 IO.mapOptional("objc-eh-types", Section.ClassEHs);

320 IO.mapOptional("objc-ivars", Section.Ivars);

321 IO.mapOptional("weak-symbols", Section.WeakSymbols);

322 IO.mapOptional("thread-local-symbols", Section.TlvSymbols);

323 }

324};

325

327 static void mapping(IO &IO, UmbrellaSection &Section) {

328 IO.mapRequired("targets", Section.Targets);

329 IO.mapRequired("umbrella", Section.Umbrella);

330 }

331};

332

335 IO.mapRequired("target", UUID.TargetID);

336 IO.mapRequired("value", UUID.Value);

337 }

338};

339

340template <>

341struct MappingContextTraits<MetadataSection, MetadataSection::Option> {

342 static void mapping(IO &IO, MetadataSection &Section,

343 MetadataSection::Option &OptionKind) {

344 IO.mapRequired("targets", Section.Targets);

345 switch (OptionKind) {

346 case MetadataSection::Option::Clients:

347 IO.mapRequired("clients", Section.Values);

348 return;

349 case MetadataSection::Option::Libraries:

350 IO.mapRequired("libraries", Section.Values);

351 return;

352 }

354 }

355};

356

357template <> struct ScalarBitSetTraits<TBDFlags> {

359 IO.bitSetCase(Flags, "flat_namespace", TBDFlags::FlatNamespace);

360 IO.bitSetCase(Flags, "not_app_extension_safe",

361 TBDFlags::NotApplicationExtensionSafe);

362 IO.bitSetCase(Flags, "installapi", TBDFlags::InstallAPI);

363 IO.bitSetCase(Flags, "not_for_dyld_shared_cache",

364 TBDFlags::OSLibNotForSharedCache);

365 }

366};

367

368template <> struct ScalarTraits<Target> {

371 switch (Value.Platform) {

372#define PLATFORM(platform, id, name, build_name, target, tapi_target, \

373 marketing) \

374 case PLATFORM_##platform: \

375 OS << #tapi_target; \

376 break;

377#include "llvm/BinaryFormat/MachO.def"

378 }

379 }

380

383 if (!Result) {

385 return "unparsable target";

386 }

387

390 return "unknown architecture";

391 if (Value.Platform == PLATFORM_UNKNOWN)

392 return "unknown platform";

393

394 return {};

395 }

396

398};

399

401 struct NormalizedTBD {

404 Architectures = File->getArchitectures();

405 Platforms = File->getPlatforms();

406 InstallName = File->getInstallName();

407 CurrentVersion = PackedVersion(File->getCurrentVersion());

408 CompatibilityVersion = PackedVersion(File->getCompatibilityVersion());

409 SwiftABIVersion = File->getSwiftABIVersion();

410 ObjCConstraint = File->getObjCConstraint();

411

412 Flags = TBDFlags::None;

413 if (!File->isApplicationExtensionSafe())

414 Flags |= TBDFlags::NotApplicationExtensionSafe;

415

416 if (!File->isTwoLevelNamespace())

417 Flags |= TBDFlags::FlatNamespace;

418

419 if (!File->umbrellas().empty())

420 ParentUmbrella = File->umbrellas().begin()->second;

421

422 std::set ArchSet;

423 for (const auto &Library : File->allowableClients())

424 ArchSet.insert(Library.getArchitectures());

425

426 for (const auto &Library : File->reexportedLibraries())

427 ArchSet.insert(Library.getArchitectures());

428

429 std::map<const Symbol *, ArchitectureSet> SymbolToArchSet;

430 for (const auto *Symbol : File->symbols()) {

432 SymbolToArchSet[Symbol] = Architectures;

433 ArchSet.insert(Architectures);

434 }

435

436 for (auto Architectures : ArchSet) {

437 ExportSection Section;

438 Section.Architectures = Architectures;

439

440 for (const auto &Library : File->allowableClients())

441 if (Library.getArchitectures() == Architectures)

442 Section.AllowableClients.emplace_back(Library.getInstallName());

443

444 for (const auto &Library : File->reexportedLibraries())

445 if (Library.getArchitectures() == Architectures)

446 Section.ReexportedLibraries.emplace_back(Library.getInstallName());

447

448 for (const auto &SymArch : SymbolToArchSet) {

449 if (SymArch.second != Architectures)

450 continue;

451

452 const auto *Symbol = SymArch.first;

454 case EncodeKind::GlobalSymbol:

456 Section.WeakDefSymbols.emplace_back(Symbol->getName());

458 Section.TLVSymbols.emplace_back(Symbol->getName());

459 else

461 break;

462 case EncodeKind::ObjectiveCClass:

463 if (File->getFileType() != FileType::TBD_V3)

464 Section.Classes.emplace_back(

466 else

468 break;

469 case EncodeKind::ObjectiveCClassEHType:

470 if (File->getFileType() != FileType::TBD_V3)

471 Section.Symbols.emplace_back(

473 else

474 Section.ClassEHs.emplace_back(Symbol->getName());

475 break;

476 case EncodeKind::ObjectiveCInstanceVariable:

477 if (File->getFileType() != FileType::TBD_V3)

478 Section.IVars.emplace_back(

480 else

482 break;

483 }

484 }

491 Exports.emplace_back(std::move(Section));

492 }

493

494 ArchSet.clear();

495 SymbolToArchSet.clear();

496

497 for (const auto *Symbol : File->undefineds()) {

499 SymbolToArchSet[Symbol] = Architectures;

500 ArchSet.insert(Architectures);

501 }

502

503 for (auto Architectures : ArchSet) {

504 UndefinedSection Section;

505 Section.Architectures = Architectures;

506

507 for (const auto &SymArch : SymbolToArchSet) {

508 if (SymArch.second != Architectures)

509 continue;

510

511 const auto *Symbol = SymArch.first;

513 case EncodeKind::GlobalSymbol:

515 Section.WeakRefSymbols.emplace_back(Symbol->getName());

516 else

518 break;

519 case EncodeKind::ObjectiveCClass:

520 if (File->getFileType() != FileType::TBD_V3)

521 Section.Classes.emplace_back(

523 else

525 break;

526 case EncodeKind::ObjectiveCClassEHType:

527 if (File->getFileType() != FileType::TBD_V3)

528 Section.Symbols.emplace_back(

530 else

531 Section.ClassEHs.emplace_back(Symbol->getName());

532 break;

533 case EncodeKind::ObjectiveCInstanceVariable:

534 if (File->getFileType() != FileType::TBD_V3)

535 Section.IVars.emplace_back(

537 else

539 break;

540 }

541 }

547 Undefineds.emplace_back(std::move(Section));

548 }

549 }

550

551

552

553

554

555

559

560 for (auto Platform : Platforms) {

562

563 for (const auto &&Architecture : Architectures) {

564 if ((Architecture == AK_i386) && (Platform == PLATFORM_MACCATALYST))

565 continue;

566

568 }

569 }

570 return Targets;

571 }

572

574 auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());

576

578 File->setPath(Ctx->Path);

579 File->setFileType(Ctx->FileKind);

580 File->addTargets(synthesizeTargets(Architectures, Platforms));

581 File->setInstallName(InstallName);

582 File->setCurrentVersion(CurrentVersion);

583 File->setCompatibilityVersion(CompatibilityVersion);

584 File->setSwiftABIVersion(SwiftABIVersion);

585 File->setObjCConstraint(ObjCConstraint);

586 for (const auto &Target : File->targets())

587 File->addParentUmbrella(Target, ParentUmbrella);

588

589 if (Ctx->FileKind == FileType::TBD_V1) {

590 File->setTwoLevelNamespace();

591 File->setApplicationExtensionSafe();

592 } else {

593 File->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));

594 File->setApplicationExtensionSafe(

595 !(Flags & TBDFlags::NotApplicationExtensionSafe));

596 }

597

598

599

600

601 const auto Flags = SymbolFlags::Data;

602

603 for (const auto &Section : Exports) {

604 const auto Targets =

605 synthesizeTargets(Section.Architectures, Platforms);

606

607 for (const auto &Lib : Section.AllowableClients)

608 for (const auto &Target : Targets)

609 File->addAllowableClient(Lib, Target);

610

611 for (const auto &Lib : Section.ReexportedLibraries)

612 for (const auto &Target : Targets)

613 File->addReexportedLibrary(Lib, Target);

614

615 for (const auto &Symbol : Section.Symbols) {

616 if (Ctx->FileKind != FileType::TBD_V3 &&

618 File->addSymbol(EncodeKind::ObjectiveCClassEHType,

619 Symbol.value.drop_front(15), Targets, Flags);

620 else

621 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets, Flags);

622 }

623 for (auto &Symbol : Section.Classes) {

625 if (Ctx->FileKind != FileType::TBD_V3)

627 File->addSymbol(EncodeKind::ObjectiveCClass, Name, Targets, Flags);

628 }

629 for (auto &Symbol : Section.ClassEHs)

630 File->addSymbol(EncodeKind::ObjectiveCClassEHType, Symbol, Targets,

631 Flags);

632 for (auto &Symbol : Section.IVars) {

634 if (Ctx->FileKind != FileType::TBD_V3)

636 File->addSymbol(EncodeKind::ObjectiveCInstanceVariable, Name, Targets,

637 Flags);

638 }

639 for (auto &Symbol : Section.WeakDefSymbols)

640 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,

641 SymbolFlags::WeakDefined | Flags);

642 for (auto &Symbol : Section.TLVSymbols)

643 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,

644 SymbolFlags::ThreadLocalValue | Flags);

645 }

646

647 for (const auto &Section : Undefineds) {

648 const auto Targets =

649 synthesizeTargets(Section.Architectures, Platforms);

650 for (auto &Symbol : Section.Symbols) {

651 if (Ctx->FileKind != FileType::TBD_V3 &&

653 File->addSymbol(EncodeKind::ObjectiveCClassEHType,

654 Symbol.value.drop_front(15), Targets,

655 SymbolFlags::Undefined | Flags);

656 else

657 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,

658 SymbolFlags::Undefined | Flags);

659 }

660 for (auto &Symbol : Section.Classes) {

662 if (Ctx->FileKind != FileType::TBD_V3)

664 File->addSymbol(EncodeKind::ObjectiveCClass, Name, Targets,

665 SymbolFlags::Undefined | Flags);

666 }

667 for (auto &Symbol : Section.ClassEHs)

668 File->addSymbol(EncodeKind::ObjectiveCClassEHType, Symbol, Targets,

669 SymbolFlags::Undefined | Flags);

670 for (auto &Symbol : Section.IVars) {

672 if (Ctx->FileKind != FileType::TBD_V3)

674 File->addSymbol(EncodeKind::ObjectiveCInstanceVariable, Name, Targets,

675 SymbolFlags::Undefined | Flags);

676 }

677 for (auto &Symbol : Section.WeakRefSymbols)

678 File->addSymbol(EncodeKind::GlobalSymbol, Symbol, Targets,

679 SymbolFlags::Undefined | SymbolFlags::WeakReferenced |

680 Flags);

681 }

682

683 return File;

684 }

685

689 return {};

690

693 return StringRef(reinterpret_cast<const char *>(Ptr), String.size());

694 }

695

702 SwiftVersion SwiftABIVersion{0};

708 };

709

711 if (IO.mapTag("!tapi-tbd", false))

712 Ctx->FileKind = FileType::TBD_V4;

713 else if (IO.mapTag("!tapi-tbd-v3", false))

714 Ctx->FileKind = FileType::TBD_V3;

715 else if (IO.mapTag("!tapi-tbd-v2", false))

716 Ctx->FileKind = FileType::TBD_V2;

717 else if (IO.mapTag("!tapi-tbd-v1", false) ||

718 IO.mapTag("tag:yaml.org,2002:map", false))

719 Ctx->FileKind = FileType::TBD_V1;

720 else {

721 Ctx->FileKind = FileType::Invalid;

722 return;

723 }

724 }

725

727 auto *Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());

728 assert((!Ctx || !IO.outputting() ||

729 (Ctx && Ctx->FileKind != FileType::Invalid)) &&

730 "File type is not set in YAML context");

731

732 if (!IO.outputting()) {

733 setFileTypeForInput(Ctx, IO);

734 switch (Ctx->FileKind) {

735 default:

736 break;

737 case FileType::TBD_V4:

738 mapKeysToValuesV4(IO, File);

739 return;

740 case FileType::Invalid:

741 IO.setError("unsupported file type");

742 return;

743 }

744 } else {

745

746 switch (Ctx->FileKind) {

747 default:

749 case FileType::TBD_V4:

750 mapKeysToValuesV4(IO, File);

751 return;

752 case FileType::TBD_V3:

753 IO.mapTag("!tapi-tbd-v3", true);

754 break;

755 case FileType::TBD_V2:

756 IO.mapTag("!tapi-tbd-v2", true);

757 break;

758 case FileType::TBD_V1:

759

760 break;

761 }

762 }

763 mapKeysToValues(Ctx->FileKind, IO, File);

764 }

765

767 struct NormalizedTBD_V4 {

770 auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());

772 TBDVersion = Ctx->FileKind >> 4;

773 Targets.insert(Targets.begin(), File->targets().begin(),

774 File->targets().end());

775 InstallName = File->getInstallName();

776 CurrentVersion = File->getCurrentVersion();

777 CompatibilityVersion = File->getCompatibilityVersion();

778 SwiftABIVersion = File->getSwiftABIVersion();

779

780 Flags = TBDFlags::None;

781 if (!File->isApplicationExtensionSafe())

782 Flags |= TBDFlags::NotApplicationExtensionSafe;

783

784 if (!File->isTwoLevelNamespace())

785 Flags |= TBDFlags::FlatNamespace;

786

787 if (File->isOSLibNotForSharedCache())

788 Flags |= TBDFlags::OSLibNotForSharedCache;

789

790 {

791 std::map<std::string, TargetList> valueToTargetList;

792 for (const auto &it : File->umbrellas())

793 valueToTargetList[it.second].emplace_back(it.first);

794

795 for (const auto &it : valueToTargetList) {

796 UmbrellaSection CurrentSection;

797 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),

798 it.second.begin(), it.second.end());

799 CurrentSection.Umbrella = it.first;

800 ParentUmbrellas.emplace_back(std::move(CurrentSection));

801 }

802 }

803

804 assignTargetsToLibrary(File->allowableClients(), AllowableClients);

805 assignTargetsToLibrary(File->reexportedLibraries(), ReexportedLibraries);

806

807 auto handleSymbols =

810 std::set TargetSet;

811 std::map<const Symbol *, TargetList> SymbolToTargetList;

812 for (const auto *Symbol : Symbols) {

814 SymbolToTargetList[Symbol] = Targets;

815 TargetSet.emplace(std::move(Targets));

816 }

817 for (const auto &TargetIDs : TargetSet) {

818 SymbolSection CurrentSection;

819 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),

820 TargetIDs.begin(), TargetIDs.end());

821

822 for (const auto &IT : SymbolToTargetList) {

823 if (IT.second != TargetIDs)

824 continue;

825

826 const auto *Symbol = IT.first;

828 case EncodeKind::GlobalSymbol:

830 CurrentSection.WeakSymbols.emplace_back(Symbol->getName());

832 CurrentSection.TlvSymbols.emplace_back(Symbol->getName());

833 else

834 CurrentSection.Symbols.emplace_back(Symbol->getName());

835 break;

836 case EncodeKind::ObjectiveCClass:

837 CurrentSection.Classes.emplace_back(Symbol->getName());

838 break;

839 case EncodeKind::ObjectiveCClassEHType:

840 CurrentSection.ClassEHs.emplace_back(Symbol->getName());

841 break;

842 case EncodeKind::ObjectiveCInstanceVariable:

843 CurrentSection.Ivars.emplace_back(Symbol->getName());

844 break;

845 }

846 }

847 sort(CurrentSection.Symbols);

848 sort(CurrentSection.Classes);

849 sort(CurrentSection.ClassEHs);

850 sort(CurrentSection.Ivars);

851 sort(CurrentSection.WeakSymbols);

852 sort(CurrentSection.TlvSymbols);

853 CurrentSections.emplace_back(std::move(CurrentSection));

854 }

855 };

856

857 handleSymbols(Exports, File->exports());

858 handleSymbols(Reexports, File->reexports());

859 handleSymbols(Undefineds, File->undefineds());

860 }

861

863 auto Ctx = reinterpret_cast<TextAPIContext *>(IO.getContext());

865

867 File->setPath(Ctx->Path);

868 File->setFileType(Ctx->FileKind);

869 File->addTargets(Targets);

870 File->setInstallName(InstallName);

871 File->setCurrentVersion(CurrentVersion);

872 File->setCompatibilityVersion(CompatibilityVersion);

873 File->setSwiftABIVersion(SwiftABIVersion);

874 for (const auto &CurrentSection : ParentUmbrellas)

875 for (const auto &target : CurrentSection.Targets)

876 File->addParentUmbrella(target, CurrentSection.Umbrella);

877 File->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));

878 File->setApplicationExtensionSafe(

879 !(Flags & TBDFlags::NotApplicationExtensionSafe));

880 File->setOSLibNotForSharedCache(

881 (Flags & TBDFlags::OSLibNotForSharedCache));

882

883 for (const auto &CurrentSection : AllowableClients) {

884 for (const auto &lib : CurrentSection.Values)

885 for (const auto &Target : CurrentSection.Targets)

886 File->addAllowableClient(lib, Target);

887 }

888

889 for (const auto &CurrentSection : ReexportedLibraries) {

890 for (const auto &Lib : CurrentSection.Values)

891 for (const auto &Target : CurrentSection.Targets)

892 File->addReexportedLibrary(Lib, Target);

893 }

894

895 auto handleSymbols = [File](const SectionList &CurrentSections,

896 SymbolFlags InputFlag = SymbolFlags::None) {

897

898

899

900 const SymbolFlags Flag = InputFlag | SymbolFlags::Data;

901

902 for (const auto &CurrentSection : CurrentSections) {

903 for (auto &sym : CurrentSection.Symbols)

904 File->addSymbol(EncodeKind::GlobalSymbol, sym,

905 CurrentSection.Targets, Flag);

906

907 for (auto &sym : CurrentSection.Classes)

908 File->addSymbol(EncodeKind::ObjectiveCClass, sym,

909 CurrentSection.Targets, Flag);

910

911 for (auto &sym : CurrentSection.ClassEHs)

912 File->addSymbol(EncodeKind::ObjectiveCClassEHType, sym,

913 CurrentSection.Targets, Flag);

914

915 for (auto &sym : CurrentSection.Ivars)

916 File->addSymbol(EncodeKind::ObjectiveCInstanceVariable, sym,

917 CurrentSection.Targets, Flag);

918

920 ((Flag & SymbolFlags::Undefined) == SymbolFlags::Undefined)

921 ? SymbolFlags::WeakReferenced

922 : SymbolFlags::WeakDefined;

923 for (auto &sym : CurrentSection.WeakSymbols) {

924 File->addSymbol(EncodeKind::GlobalSymbol, sym,

925 CurrentSection.Targets, Flag | SymFlag);

926 }

927

928 for (auto &sym : CurrentSection.TlvSymbols)

929 File->addSymbol(EncodeKind::GlobalSymbol, sym,

930 CurrentSection.Targets,

931 Flag | SymbolFlags::ThreadLocalValue);

932 }

933 };

934

935 handleSymbols(Exports);

936 handleSymbols(Reexports, SymbolFlags::Rexported);

937 handleSymbols(Undefineds, SymbolFlags::Undefined);

938

939 return File;

940 }

941

948 SwiftVersion SwiftABIVersion{0};

956

957 private:

958 void assignTargetsToLibrary(const std::vector &Libraries,

959 std::vector &Section) {

960 std::set targetSet;

961 std::map<const InterfaceFileRef *, TargetList> valueToTargetList;

962 for (const auto &library : Libraries) {

964 valueToTargetList[&library] = targets;

965 targetSet.emplace(std::move(targets));

966 }

967

968 for (const auto &targets : targetSet) {

969 MetadataSection CurrentSection;

970 CurrentSection.Targets.insert(CurrentSection.Targets.begin(),

971 targets.begin(), targets.end());

972

973 for (const auto &it : valueToTargetList) {

974 if (it.second != targets)

975 continue;

976

977 CurrentSection.Values.emplace_back(it.first->getInstallName());

978 }

980 Section.emplace_back(std::move(CurrentSection));

981 }

982 }

983 };

984

987 MappingNormalization<NormalizedTBD, const InterfaceFile *> Keys(IO, File);

988 std::vector EmptyUUID;

989 IO.mapRequired("archs", Keys->Architectures);

990 if (FileKind != FileType::TBD_V1)

991 IO.mapOptional("uuids", EmptyUUID);

992 IO.mapRequired("platform", Keys->Platforms);

993 if (FileKind != FileType::TBD_V1)

994 IO.mapOptional("flags", Keys->Flags, TBDFlags::None);

995 IO.mapRequired("install-name", Keys->InstallName);

996 IO.mapOptional("current-version", Keys->CurrentVersion,

998 IO.mapOptional("compatibility-version", Keys->CompatibilityVersion,

1000 if (FileKind != FileType::TBD_V3)

1001 IO.mapOptional("swift-version", Keys->SwiftABIVersion, SwiftVersion(0));

1002 else

1003 IO.mapOptional("swift-abi-version", Keys->SwiftABIVersion,

1004 SwiftVersion(0));

1005 IO.mapOptional("objc-constraint", Keys->ObjCConstraint,

1006 (FileKind == FileType::TBD_V1)

1007 ? ObjCConstraintType::None

1008 : ObjCConstraintType::Retain_Release);

1009 if (FileKind != FileType::TBD_V1)

1010 IO.mapOptional("parent-umbrella", Keys->ParentUmbrella, StringRef());

1011 IO.mapOptional("exports", Keys->Exports);

1012 if (FileKind != FileType::TBD_V1)

1013 IO.mapOptional("undefineds", Keys->Undefineds);

1014 }

1015

1017 MappingNormalization<NormalizedTBD_V4, const InterfaceFile *> Keys(IO,

1018 File);

1019 std::vector EmptyUUID;

1020 IO.mapTag("!tapi-tbd", true);

1021 IO.mapRequired("tbd-version", Keys->TBDVersion);

1022 IO.mapRequired("targets", Keys->Targets);

1023 IO.mapOptional("uuids", EmptyUUID);

1024 IO.mapOptional("flags", Keys->Flags, TBDFlags::None);

1025 IO.mapRequired("install-name", Keys->InstallName);

1026 IO.mapOptional("current-version", Keys->CurrentVersion,

1028 IO.mapOptional("compatibility-version", Keys->CompatibilityVersion,

1030 IO.mapOptional("swift-abi-version", Keys->SwiftABIVersion, SwiftVersion(0));

1031 IO.mapOptional("parent-umbrella", Keys->ParentUmbrellas);

1032 auto OptionKind = MetadataSection::Option::Clients;

1033 IO.mapOptionalWithContext("allowable-clients", Keys->AllowableClients,

1034 OptionKind);

1035 OptionKind = MetadataSection::Option::Libraries;

1036 IO.mapOptionalWithContext("reexported-libraries", Keys->ReexportedLibraries,

1037 OptionKind);

1038 IO.mapOptional("exports", Keys->Exports);

1039 IO.mapOptional("reexports", Keys->Reexports);

1040 IO.mapOptional("undefineds", Keys->Undefineds);

1041 }

1042};

1043

1044template <>

1045struct DocumentListTraits<std::vector<const MachO::InterfaceFile *>> {

1046 static size_t size(IO &IO, std::vector<const MachO::InterfaceFile *> &Seq) {

1047 return Seq.size();

1048 }

1050 element(IO &IO, std::vector<const InterfaceFile *> &Seq, size_t Index) {

1051 if (Index >= Seq.size())

1052 Seq.resize(Index + 1);

1053 return Seq[Index];

1054 }

1055};

1056

1057}

1058}

1059

1061 auto *File = static_cast<TextAPIContext *>(Context);

1064

1069

1070 NewDiag.print(nullptr, S);

1071 File->ErrorMessage = ("malformed file\n" + Message).str();

1072}

1073

1076 if (TAPIFile.starts_with("{") && TAPIFile.ends_with("}"))

1078

1079 if (!TAPIFile.ends_with("..."))

1080 return createStringError(std::errc::not_supported, "unsupported file type");

1081

1082 if (TAPIFile.starts_with("--- !tapi-tbd"))

1084

1085 if (TAPIFile.starts_with("--- !tapi-tbd-v3"))

1087

1088 if (TAPIFile.starts_with("--- !tapi-tbd-v2"))

1090

1091 if (TAPIFile.starts_with("--- !tapi-tbd-v1") ||

1092 TAPIFile.starts_with("---\narchs:"))

1094

1095 return createStringError(std::errc::not_supported, "unsupported file type");

1096}

1097

1102 if (auto FTOrErr = canRead(InputBuffer))

1104 else

1105 return FTOrErr.takeError();

1106

1107

1110 if (!FileOrErr)

1111 return FileOrErr.takeError();

1112

1113 (*FileOrErr)->setPath(Ctx.Path);

1114 return std::move(*FileOrErr);

1115 }

1117

1118

1119 std::vector<const InterfaceFile *> Files;

1120 YAMLIn >> Files;

1121

1122

1123

1124 auto File = std::unique_ptr(

1126

1128 File->addDocument(

1129 std::shared_ptr(const_cast<InterfaceFile *>(FI)));

1130

1131 if (YAMLIn.error())

1132 return make_error(Ctx.ErrorMessage, YAMLIn.error());

1133

1134 return std::move(File);

1135}

1136

1138 const FileType FileKind, bool Compact) {

1140 Ctx.Path = std::string(File.getPath());

1141

1142

1143

1145 (FileKind == FileType::Invalid) ? File.getFileType() : FileKind;

1146

1147

1150 }

1151

1152 llvm::yaml::Output YAMLOut(OS, &Ctx, 80);

1153

1154 std::vector<const InterfaceFile *> Files;

1155 Files.emplace_back(&File);

1156

1157 for (const auto &Document : File.documents())

1158 Files.emplace_back(Document.get());

1159

1160

1161 YAMLOut << Files;

1162

1164}

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

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file defines the SmallString class.

std::pair< llvm::MachO::Target, std::string > UUID

static void DiagHandler(const SMDiagnostic &Diag, void *Context)

#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)

#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type)

Allocate memory in an ever growing pool, as if by bump-pointer.

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.

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::Expected< Target > create(StringRef Target)

static Expected< FileType > canRead(MemoryBufferRef InputBuffer)

Determine whether input can be interpreted as TAPI text file.

static Expected< std::unique_ptr< InterfaceFile > > get(MemoryBufferRef InputBuffer)

Parse and get an InterfaceFile that represents the full library.

static 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...

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

SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...

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.

A range adaptor for a pair of iterators.

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.

#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)

ObjCConstraintType

Defines a list of Objective-C constraints.

Architecture

Defines the architecture slices that are supported by Text-based Stub files.

PlatformType mapToPlatformType(PlatformType Platform, bool WantSim)

Expected< std::unique_ptr< InterfaceFile > > getInterfaceFileFromJSON(StringRef JSON)

constexpr StringLiteral ObjC2EHTypePrefix

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)

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)

static void mapping(IO &IO, MetadataSection &Section, MetadataSection::Option &OptionKind)

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

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)

std::vector< Architecture > Architectures

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)

static void bitset(IO &IO, TBDFlags &Flags)

static StringRef input(StringRef Scalar, void *, Target &Value)

static void output(const Target &Value, void *, raw_ostream &OS)

static QuotingType mustQuote(StringRef)