1 //===-- TapiUniversal.h - Text-based Dynamic Library Stub -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares the TapiUniversal interface.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_OBJECT_TAPI_UNIVERSAL_H
14 #define LLVM_OBJECT_TAPI_UNIVERSAL_H
16 #include "llvm/Object/Binary.h"
17 #include "llvm/Object/TapiFile.h"
18 #include "llvm/Support/Error.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/TextAPI/MachO/Architecture.h"
21 #include "llvm/TextAPI/MachO/InterfaceFile.h"
26 class TapiUniversal : public Binary {
29 const TapiUniversal *Parent;
33 ObjectForArch(const TapiUniversal *Parent, int Index)
34 : Parent(Parent), Index(Index) {}
36 ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
38 bool operator==(const ObjectForArch &Other) const {
39 return (Parent == Other.Parent) && (Index == Other.Index);
42 uint32_t getCPUType() const {
44 MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
48 uint32_t getCPUSubType() const {
50 MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
54 StringRef getArchFlagName() const {
55 return MachO::getArchitectureName(Parent->Libraries[Index].Arch);
58 std::string getInstallName() const {
59 return std::string(Parent->Libraries[Index].InstallName);
62 bool isTopLevelLib() const {
63 return Parent->ParsedFile->getInstallName() == getInstallName();
66 Expected<std::unique_ptr<TapiFile>> getAsObjectFile() const;
69 class object_iterator {
73 object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
74 const ObjectForArch *operator->() const { return &Obj; }
75 const ObjectForArch &operator*() const { return Obj; }
77 bool operator==(const object_iterator &Other) const {
78 return Obj == Other.Obj;
80 bool operator!=(const object_iterator &Other) const {
81 return !(*this == Other);
84 object_iterator &operator++() { // Preincrement
90 TapiUniversal(MemoryBufferRef Source, Error &Err);
91 static Expected<std::unique_ptr<TapiUniversal>>
92 create(MemoryBufferRef Source);
93 ~TapiUniversal() override;
95 object_iterator begin_objects() const { return ObjectForArch(this, 0); }
96 object_iterator end_objects() const {
97 return ObjectForArch(this, Libraries.size());
100 iterator_range<object_iterator> objects() const {
101 return make_range(begin_objects(), end_objects());
104 uint32_t getNumberOfObjects() const { return Libraries.size(); }
106 static bool classof(const Binary *v) { return v->isTapiUniversal(); }
110 StringRef InstallName;
111 MachO::Architecture Arch;
114 std::unique_ptr<MachO::InterfaceFile> ParsedFile;
115 std::vector<Library> Libraries;
118 } // end namespace object.
119 } // end namespace llvm.
121 #endif // LLVM_OBJECT_TAPI_UNIVERSAL_H