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

1

2

3

4

5

6

7

8

9

10

11

12

16

17using namespace llvm;

19

23

26 if (InstallName.empty())

27 return;

28 auto Client = addEntry(AllowableClients, InstallName);

29 Client->addTarget(Target);

30}

31

34 if (InstallName.empty())

35 return;

36 auto Lib = addEntry(ReexportedLibraries, InstallName);

38}

39

41 if (Parent.empty())

42 return;

43 auto Iter = lower_bound(ParentUmbrellas, Target_,

44 [](const std::pair<Target, std::string> &LHS,

45 Target RHS) { return LHS.first < RHS; });

46

47 if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) {

48 Iter->second = std::string(Parent);

49 return;

50 }

51

52 ParentUmbrellas.emplace(Iter, Target_, std::string(Parent));

53}

54

56 if (RPath.empty())

57 return;

58 using RPathEntryT = const std::pair<Target, std::string>;

59 RPathEntryT Entry(InputTarget, RPath);

60

62 return;

63

64 RPaths.emplace_back(Entry);

65}

66

70

73 std::function<bool(const Target &)> fn = [Archs](const Target &Target_) {

74 return Archs.has(Target_.Arch);

75 };

77}

78

81 [](const std::shared_ptr &LHS,

82 const std::shared_ptr &RHS) {

83 return LHS->InstallName < RHS->InstallName;

84 });

85 assert((Pos == Documents.end() ||

86 (*Pos)->InstallName != Document->InstallName) &&

87 "Unexpected duplicate document added");

88 Document->Parent = this;

89 Documents.insert(Pos, Document);

90}

91

93 bool Overwrite) {

94 auto AddFwk = [&](std::shared_ptr &&Reexport) {

96 Documents, Reexport->getInstallName(),

97 [](std::shared_ptr &Lhs, const StringRef Rhs) {

98 return Lhs->getInstallName() < Rhs;

99 });

100

101 if (Overwrite && It != Documents.end() &&

102 Reexport->getInstallName() == (*It)->getInstallName()) {

103 llvm::replace(Documents, *It, std::move(Reexport));

104 return;

105 }

106

107 if ((It != Documents.end()) &&

108 !(Reexport->getInstallName() < (*It)->getInstallName()))

109 return;

110

111 Documents.emplace(It, std::move(Reexport));

112 };

113 for (auto Doc : Library->documents())

114 AddFwk(std::move(Doc));

115

116 Library->Documents.clear();

117 AddFwk(std::move(Library));

118}

119

122

126 }

127

131 }

132

136 }

137

142 }

143

147 }

148

151 "application extension safe flags do not match",

153 }

154

155 std::unique_ptr IF(new InterfaceFile());

156 IF->setFileType(std::max(getFileType(), O->getFileType()));

161

163 IF->setSwiftABIVersion(O->getSwiftABIVersion());

164 else

166

170

171 for (const auto &It : umbrellas()) {

172 if (!It.second.empty())

173 IF->addParentUmbrella(It.first, It.second);

174 }

175 for (const auto &It : O->umbrellas()) {

176 if (!It.second.empty())

177 IF->addParentUmbrella(It.first, It.second);

178 }

179 IF->addTargets(targets());

180 IF->addTargets(O->targets());

181

183 for (const auto &Target : Lib.targets())

184 IF->addAllowableClient(Lib.getInstallName(), Target);

185

186 for (const auto &Lib : O->allowableClients())

187 for (const auto &Target : Lib.targets())

188 IF->addAllowableClient(Lib.getInstallName(), Target);

189

191 for (const auto &Target : Lib.targets())

192 IF->addReexportedLibrary(Lib.getInstallName(), Target);

193

194 for (const auto &Lib : O->reexportedLibraries())

195 for (const auto &Target : Lib.targets())

196 IF->addReexportedLibrary(Lib.getInstallName(), Target);

197

199 IF->addRPath(Path, Target);

200 for (const auto &[Target, Path] : O->rpaths())

201 IF->addRPath(Path, Target);

202

203 for (const auto *Sym : symbols()) {

204 IF->addSymbol(Sym->getKind(), Sym->getName(), Sym->targets(),

205 Sym->getFlags());

206 }

207

208 for (const auto *Sym : O->symbols()) {

209 IF->addSymbol(Sym->getKind(), Sym->getName(), Sym->targets(),

210 Sym->getFlags());

211 }

212

213 return std::move(IF);

214}

215

222

224 bool Found = false;

225 for (auto &Doc : Documents) {

226 if (Doc->getArchitectures().has(Arch)) {

227 Found = true;

228 break;

229 }

230 }

231

232 if (!Found)

234 }

235

236

237

238 std::unique_ptr IF(new InterfaceFile());

249 for (const auto &It : umbrellas())

250 if (It.first.Arch != Arch)

251 IF->addParentUmbrella(It.first, It.second);

252

254 for (const auto &Target : Lib.targets())

256 IF->addAllowableClient(Lib.getInstallName(), Target);

257 }

258

260 for (const auto &Target : Lib.targets())

262 IF->addReexportedLibrary(Lib.getInstallName(), Target);

263 }

264

265 for (const auto *Sym : symbols()) {

266 auto Archs = Sym->getArchitectures();

267 Archs.clear(Arch);

268 if (Archs.empty())

269 continue;

270

271 IF->addSymbol(Sym->getKind(), Sym->getName(), Sym->targets(Archs),

272 Sym->getFlags());

273 }

274

275 for (auto &Doc : Documents) {

276

277

278 if (Doc->getArchitectures() == Arch)

279 continue;

280

281

282

283 if (!Doc->getArchitectures().has(Arch)) {

284 auto NewDoc = Doc;

285 IF->addDocument(std::move(NewDoc));

286 continue;

287 }

288

289 auto Result = Doc->remove(Arch);

290 if (!Result)

291 return Result;

292

293 IF->addDocument(std::move(Result.get()));

294 }

295

296 return std::move(IF);

297}

298

305 }

306

307 std::unique_ptr IF(new InterfaceFile());

310 IF->addTargets(targets(Arch));

318 for (const auto &It : umbrellas())

319 if (It.first.Arch == Arch)

320 IF->addParentUmbrella(It.first, It.second);

321

322 for (const auto &It : rpaths())

323 if (It.first.Arch == Arch)

324 IF->addRPath(It.second, It.first);

325

327 for (const auto &Target : Lib.targets())

329 IF->addAllowableClient(Lib.getInstallName(), Target);

330

332 for (const auto &Target : Lib.targets())

334 IF->addReexportedLibrary(Lib.getInstallName(), Target);

335

336 for (const auto *Sym : symbols()) {

337 if (Sym->hasArchitecture(Arch))

338 IF->addSymbol(Sym->getKind(), Sym->getName(), Sym->targets(Arch),

339 Sym->getFlags());

340 }

341

342 for (auto &Doc : Documents) {

343

344 if (!Doc->getArchitectures().has(Arch))

345 continue;

346

347 auto Result = Doc->extract(Arch);

348 if (!Result)

349 return Result;

350

351 IF->addDocument(std::move(Result.get()));

352 }

353

354 return std::move(IF);

355}

356

358 const Target &Targ) {

383}

384

388

390 if (Targets != O.Targets)

391 return false;

392 if (InstallName != O.InstallName)

393 return false;

394 if ((CurrentVersion != O.CurrentVersion) ||

395 (CompatibilityVersion != O.CompatibilityVersion))

396 return false;

397 if (SwiftABIVersion != O.SwiftABIVersion)

398 return false;

399 if (IsTwoLevelNamespace != O.IsTwoLevelNamespace)

400 return false;

401 if (IsAppExtensionSafe != O.IsAppExtensionSafe)

402 return false;

403 if (IsOSLibNotForSharedCache != O.IsOSLibNotForSharedCache)

404 return false;

405 if (HasSimSupport != O.HasSimSupport)

406 return false;

407 if (ParentUmbrellas != O.ParentUmbrellas)

408 return false;

409 if (AllowableClients != O.AllowableClients)

410 return false;

411 if (ReexportedLibraries != O.ReexportedLibraries)

412 return false;

413 if (*SymbolsSet != *O.SymbolsSet)

414 return false;

415

416

418 if (RPaths != O.RPaths)

419 return false;

421 return false;

422 }

423

425 [](const std::shared_ptr &LHS,

426 const std::shared_ptr &RHS) {

427 return *LHS == *RHS;

428 }))

429 return false;

430 return true;

431}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static bool isYAMLTextStub(const FileType &Kind)

Definition InterfaceFile.cpp:385

Implements the TAPI Record Collection Type.

Define TAPI specific error codes.

Tagged union holding either a T or a Error.

static ArchitectureSet All()

bool has(Architecture Arch) const

LLVM_ABI void addTarget(const Target &Target)

Definition InterfaceFile.cpp:20

LLVM_ABI void addDocument(std::shared_ptr< InterfaceFile > &&Document)

Add a library for inlining to top level library.

Definition InterfaceFile.cpp:79

StringRef getPath() const

Get the path from which this file was generated (if applicable).

LLVM_ABI void addReexportedLibrary(StringRef InstallName, const Target &Target)

Add a re-exported library.

Definition InterfaceFile.cpp:32

void setPath(StringRef Path_)

Set the path from which this file was generated (if applicable).

LLVM_ABI void setFromBinaryAttrs(const RecordsSlice::BinaryAttrs &BA, const Target &Targ)

Set InterfaceFile properties from pre-gathered binary attributes, if they are not set already.

Definition InterfaceFile.cpp:357

LLVM_ABI void addParentUmbrella(const Target &Target_, StringRef Parent)

Set the parent umbrella frameworks.

Definition InterfaceFile.cpp:40

const_target_range targets() const

void setOSLibNotForSharedCache(bool V=true)

Specify if the library is an OS library but not shared cache eligible.

llvm::iterator_range< const_filtered_target_iterator > const_filtered_target_range

bool isOSLibNotForSharedCache() const

Check if the library is an OS library that is not shared cache eligible.

LLVM_ABI llvm::Expected< std::unique_ptr< InterfaceFile > > remove(Architecture Arch) const

Remove architecture slice from Interface.

Definition InterfaceFile.cpp:217

bool isTwoLevelNamespace() const

Check if the library uses two-level namespace.

LLVM_ABI bool operator==(const InterfaceFile &O) const

The equality is determined by attributes that impact linking compatibilities.

Definition InterfaceFile.cpp:389

PackedVersion getCompatibilityVersion() const

Get the compatibility version of the library.

LLVM_ABI void addTarget(const Target &Target)

Set and add target.

Definition InterfaceFile.cpp:67

bool isApplicationExtensionSafe() const

Check if the library is application extension safe.

const std::vector< std::pair< Target, std::string > > & rpaths() const

Get the list of runpath search paths.

const std::vector< InterfaceFileRef > & allowableClients() const

Get the list of allowable clients.

void setInstallName(StringRef InstallName_)

Set the install name of the library.

const std::vector< std::pair< Target, std::string > > & umbrellas() const

Get the list of Parent Umbrella frameworks.

InterfaceFile(std::unique_ptr< SymbolSet > &&InputSymbols)

const std::vector< InterfaceFileRef > & reexportedLibraries() const

Get the list of re-exported libraries.

const_symbol_range symbols() const

void setFileType(FileType Kind)

Set the file type.

uint8_t getSwiftABIVersion() const

Get the Swift ABI version of the library.

PackedVersion getCurrentVersion() const

Get the current version of the library.

LLVM_ABI void addRPath(StringRef RPath, const Target &InputTarget)

Set the runpath search paths.

Definition InterfaceFile.cpp:55

void setCompatibilityVersion(PackedVersion Version)

Set the compatibility version of the library.

ArchitectureSet getArchitectures() const

Get the architectures.

StringRef getInstallName() const

Get the install name of the library.

LLVM_ABI llvm::Expected< std::unique_ptr< InterfaceFile > > merge(const InterfaceFile *O) const

Merge Interfaces for the same library.

Definition InterfaceFile.cpp:121

FileType getFileType() const

Get the file type.

void setApplicationExtensionSafe(bool V=true)

Specify if the library is application extension safe (or not).

LLVM_ABI void addAllowableClient(StringRef InstallName, const Target &Target)

Add an allowable client.

Definition InterfaceFile.cpp:24

LLVM_ABI void inlineLibrary(std::shared_ptr< InterfaceFile > Library, bool Overwrite=false)

Inline reexported library into Interface.

Definition InterfaceFile.cpp:92

void setSwiftABIVersion(uint8_t Version)

Set the Swift ABI version of the library.

void setCurrentVersion(PackedVersion Version)

Set the current version of the library.

LLVM_ABI llvm::Expected< std::unique_ptr< InterfaceFile > > extract(Architecture Arch) const

Extract architecture slice from Interface.

Definition InterfaceFile.cpp:300

void setTwoLevelNamespace(bool V=true)

Specify if the library uses two-level namespace (or flat namespace).

StringRef - Represent a constant reference to a string, i.e.

constexpr bool empty() const

empty - Check if the string is empty.

FileType

Defines the file type TextAPI files can represent.

@ TBD_V1

Text-based stub file (.tbd) version 1.0.

@ TBD_V5

Text-based stub file (.tbd) version 5.0.

LLVM_ABI StringRef getArchitectureName(Architecture Arch)

Convert an architecture slice to a string.

C::iterator addEntry(C &Container, StringRef InstallName)

Architecture

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

LLVM_ABI PlatformVersionSet mapToPlatformVersionSet(ArrayRef< Target > Targets)

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI std::error_code inconvertibleErrorCode()

The value returned by this function can be returned from convertToErrorCode for Error values where no...

iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)

Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...

Error make_error(ArgTs &&... Args)

Make a Error instance representing failure using the given error info type.

auto lower_bound(R &&Range, T &&Value)

Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...

void replace(R &&Range, const T &OldValue, const T &NewValue)

Provide wrappers to std::replace which take ranges instead of having to pass begin/end explicitly.

bool is_contained(R &&Range, const E &Element)

Returns true if Element is found in Range.

bool equal(L &&LRange, R &&RRange)

Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.

std::vector< StringRef > RexportedLibraries

std::vector< StringRef > AllowableClients

llvm::MachO::PackedVersion CompatVersion

llvm::MachO::PackedVersion CurrentVersion

bool OSLibNotForSharedCache