2626#include " llvm/TextAPI/MachO/Architecture.h"
2727#include " llvm/TextAPI/MachO/ArchitectureSet.h"
2828#include " llvm/TextAPI/MachO/PackedVersion.h"
29+ #include " llvm/TextAPI/MachO/Platform.h"
2930#include " llvm/TextAPI/MachO/Symbol.h"
31+ #include " llvm/TextAPI/MachO/Target.h"
3032
3133namespace llvm {
3234namespace MachO {
3335
34- // / Defines the list of MachO platforms.
35- enum class PlatformKind : unsigned {
36- unknown,
37- macOS = MachO::PLATFORM_MACOS,
38- iOS = MachO::PLATFORM_IOS,
39- tvOS = MachO::PLATFORM_TVOS,
40- watchOS = MachO::PLATFORM_WATCHOS,
41- bridgeOS = MachO::PLATFORM_BRIDGEOS,
42- };
43-
4436// / Defines a list of Objective-C constraints.
4537enum class ObjCConstraintType : unsigned {
4638 // / No constraint.
@@ -89,29 +81,42 @@ class InterfaceFileRef {
8981
9082 InterfaceFileRef (StringRef InstallName) : InstallName(InstallName) {}
9183
92- InterfaceFileRef (StringRef InstallName, ArchitectureSet Archs )
93- : InstallName(InstallName), Architectures(Archs ) {}
84+ InterfaceFileRef (StringRef InstallName, const TargetList Targets )
85+ : InstallName(InstallName), Targets(std::move(Targets) ) {}
9486
9587 StringRef getInstallName () const { return InstallName; };
96- void addArchitectures (ArchitectureSet Archs) { Architectures |= Archs; }
97- ArchitectureSet getArchitectures () const { return Architectures; }
98- bool hasArchitecture (Architecture Arch) const {
99- return Architectures.has (Arch);
88+
89+ void addTarget (const Target &Target);
90+ template <typename RangeT> void addTargets (RangeT &&Targets) {
91+ for (const auto &Target : Targets)
92+ addTarget (Target (Target));
10093 }
10194
95+ using const_target_iterator = TargetList::const_iterator;
96+ using const_target_range = llvm::iterator_range<const_target_iterator>;
97+ const_target_range targets () const { return {Targets}; }
98+
99+ ArchitectureSet getArchitectures () const {
100+ return mapToArchitectureSet (Targets);
101+ }
102+
103+ PlatformSet getPlatforms () const { return mapToPlatformSet (Targets); }
104+
102105 bool operator ==(const InterfaceFileRef &O) const {
103- return std::tie (InstallName, Architectures) ==
104- std::tie (O.InstallName , O.Architectures );
106+ return std::tie (InstallName, Targets) == std::tie (O.InstallName , O.Targets );
107+ }
108+
109+ bool operator !=(const InterfaceFileRef &O) const {
110+ return std::tie (InstallName, Targets) != std::tie (O.InstallName , O.Targets );
105111 }
106112
107113 bool operator <(const InterfaceFileRef &O) const {
108- return std::tie (InstallName, Architectures) <
109- std::tie (O.InstallName , O.Architectures );
114+ return std::tie (InstallName, Targets) < std::tie (O.InstallName , O.Targets );
110115 }
111116
112117private:
113118 std::string InstallName;
114- ArchitectureSet Architectures ;
119+ TargetList Targets ;
115120};
116121
117122} // end namespace MachO.
@@ -170,27 +175,43 @@ class InterfaceFile {
170175 // / \return The file type.
171176 FileType getFileType () const { return FileKind; }
172177
173- // / Set the platform.
174- void setPlatform (PlatformKind Platform_) { Platform = Platform_; }
178+ // / Get the architectures.
179+ // /
180+ // / \return The applicable architectures.
181+ ArchitectureSet getArchitectures () const {
182+ return mapToArchitectureSet (Targets);
183+ }
175184
176- // / Get the platform.
177- PlatformKind getPlatform () const { return Platform; }
185+ // / Get the platforms.
186+ // /
187+ // / \return The applicable platforms.
188+ PlatformSet getPlatforms () const { return mapToPlatformSet (Targets); }
178189
179- // / Specify the set of supported architectures by this file .
180- void setArchitectures (ArchitectureSet Architectures_) {
181- Architectures = Architectures_;
182- }
190+ // / Set and add target .
191+ // /
192+ // / \param Target the target to add into.
193+ void addTarget ( const Target &Target);
183194
184- // / Add the set of supported architectures by this file.
185- void addArchitectures (ArchitectureSet Architectures_) {
186- Architectures |= Architectures_;
195+ // / Set and add targets.
196+ // /
197+ // / Add the subset of llvm::triples that is supported by Tapi
198+ // /
199+ // / \param Targets the collection of targets.
200+ template <typename RangeT> void addTargets (RangeT &&Targets) {
201+ for (const auto &Target_ : Targets)
202+ addTarget (Target (Target_));
187203 }
188204
189- // / Add supported architecture by this file..
190- void addArch (Architecture Arch) { Architectures.set (Arch); }
205+ using const_target_iterator = TargetList::const_iterator;
206+ using const_target_range = llvm::iterator_range<const_target_iterator>;
207+ const_target_range targets () const { return {Targets}; }
191208
192- // / Get the set of supported architectures.
193- ArchitectureSet getArchitectures () const { return Architectures; }
209+ using const_filtered_target_iterator =
210+ llvm::filter_iterator<const_target_iterator,
211+ std::function<bool (const Target &)>>;
212+ using const_filtered_target_range =
213+ llvm::iterator_range<const_filtered_target_iterator>;
214+ const_filtered_target_range targets (ArchitectureSet Archs) const ;
194215
195216 // / Set the install name of the library.
196217 void setInstallName (StringRef InstallName_) { InstallName = InstallName_; }
@@ -244,11 +265,18 @@ class InterfaceFile {
244265 // / Check if this file was generated during InstallAPI.
245266 bool isInstallAPI () const { return IsInstallAPI; }
246267
247- // / Set the parent umbrella framework.
248- void setParentUmbrella (StringRef Parent) { ParentUmbrella = Parent; }
268+ // / Set the parent umbrella frameworks.
269+ // / \param Target_ The target applicable to Parent
270+ // / \param Parent The name of Parent
271+ void addParentUmbrella (const Target &Target_, StringRef Parent);
272+ const std::vector<std::pair<Target, std::string>> &umbrellas () const {
273+ return ParentUmbrellas;
274+ }
249275
250276 // / Get the parent umbrella framework.
251- StringRef getParentUmbrella () const { return ParentUmbrella; }
277+ const std::vector<std::pair<Target, std::string>> getParentUmbrellas () const {
278+ return ParentUmbrellas;
279+ }
252280
253281 // / Add an allowable client.
254282 // /
@@ -258,8 +286,8 @@ class InterfaceFile {
258286 // / linker refuses to link this library.
259287 // /
260288 // / \param Name The name of the client that is allowed to link this library.
261- // / \param Architectures The set of architecture for which this applies.
262- void addAllowableClient (StringRef Name, ArchitectureSet Architectures );
289+ // / \param Target The target triple for which this applies.
290+ void addAllowableClient (StringRef InstallName, const Target &Target );
263291
264292 // / Get the list of allowable clients.
265293 // /
@@ -271,9 +299,8 @@ class InterfaceFile {
271299 // / Add a re-exported library.
272300 // /
273301 // / \param InstallName The name of the library to re-export.
274- // / \param Architectures The set of architecture for which this applies.
275- void addReexportedLibrary (StringRef InstallName,
276- ArchitectureSet Architectures);
302+ // / \param Target The target triple for which this applies.
303+ void addReexportedLibrary (StringRef InstallName, const Target &Target);
277304
278305 // / Get the list of re-exported libraries.
279306 // /
@@ -282,27 +309,27 @@ class InterfaceFile {
282309 return ReexportedLibraries;
283310 }
284311
285- // / Add an architecture /UUID pair.
312+ // / Add an Target /UUID pair.
286313 // /
287- // / \param Arch The architecture for which this applies.
314+ // / \param Target The target triple for which this applies.
288315 // / \param UUID The UUID of the library for the specified architecture.
289- void addUUID (Architecture Arch , StringRef UUID);
316+ void addUUID (const Target &Target , StringRef UUID);
290317
291- // / Add an architecture /UUID pair.
318+ // / Add an Target /UUID pair.
292319 // /
293- // / \param Arch The architecture for which this applies.
320+ // / \param Target The target triple for which this applies.
294321 // / \param UUID The UUID of the library for the specified architecture.
295- void addUUID (Architecture Arch , uint8_t UUID[16 ]);
322+ void addUUID (const Target &Target , uint8_t UUID[16 ]);
296323
297- // / Get the list of architecture /UUID pairs.
324+ // / Get the list of Target /UUID pairs.
298325 // /
299- // / \return Returns a list of architecture /UUID pairs.
300- const std::vector<std::pair<Architecture , std::string>> &uuids () const {
326+ // / \return Returns a list of Target /UUID pairs.
327+ const std::vector<std::pair<Target , std::string>> &uuids () const {
301328 return UUIDs;
302329 }
303330
304331 // / Add a symbol to the symbols list or extend an existing one.
305- void addSymbol (SymbolKind Kind, StringRef Name, ArchitectureSet Architectures ,
332+ void addSymbol (SymbolKind Kind, StringRef Name, const TargetList &Targets ,
306333 SymbolFlags Flags = SymbolFlags::None);
307334
308335 using SymbolMapType = DenseMap<SymbolsMapKey, Symbol *>;
@@ -411,10 +438,9 @@ class InterfaceFile {
411438 return StringRef (reinterpret_cast <const char *>(Ptr), String.size ());
412439 }
413440
441+ TargetList Targets;
414442 std::string Path;
415443 FileType FileKind;
416- PlatformKind Platform;
417- ArchitectureSet Architectures;
418444 std::string InstallName;
419445 PackedVersion CurrentVersion;
420446 PackedVersion CompatibilityVersion;
@@ -423,10 +449,10 @@ class InterfaceFile {
423449 bool IsAppExtensionSafe{false };
424450 bool IsInstallAPI{false };
425451 ObjCConstraintType ObjcConstraint = ObjCConstraintType::None;
426- std::string ParentUmbrella ;
452+ std::vector<std::pair<Target, std:: string>> ParentUmbrellas ;
427453 std::vector<InterfaceFileRef> AllowableClients;
428454 std::vector<InterfaceFileRef> ReexportedLibraries;
429- std::vector<std::pair<Architecture , std::string>> UUIDs;
455+ std::vector<std::pair<Target , std::string>> UUIDs;
430456 SymbolMapType Symbols;
431457};
432458
0 commit comments