File indexing completed on 2026-05-10 08:44:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_OBJECT_TAPIUNIVERSAL_H
0014 #define LLVM_OBJECT_TAPIUNIVERSAL_H
0015
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/Object/Binary.h"
0018 #include "llvm/Support/Error.h"
0019 #include "llvm/Support/MemoryBufferRef.h"
0020 #include "llvm/TextAPI/Architecture.h"
0021 #include "llvm/TextAPI/InterfaceFile.h"
0022
0023 namespace llvm {
0024 namespace object {
0025
0026 class TapiFile;
0027
0028 class TapiUniversal : public Binary {
0029 public:
0030 class ObjectForArch {
0031 const TapiUniversal *Parent;
0032 int Index;
0033
0034 public:
0035 ObjectForArch(const TapiUniversal *Parent, int Index)
0036 : Parent(Parent), Index(Index) {}
0037
0038 ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
0039
0040 bool operator==(const ObjectForArch &Other) const {
0041 return (Parent == Other.Parent) && (Index == Other.Index);
0042 }
0043
0044 uint32_t getCPUType() const {
0045 auto Result =
0046 MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
0047 return Result.first;
0048 }
0049
0050 uint32_t getCPUSubType() const {
0051 auto Result =
0052 MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
0053 return Result.second;
0054 }
0055
0056 StringRef getArchFlagName() const {
0057 return MachO::getArchitectureName(Parent->Libraries[Index].Arch);
0058 }
0059
0060 std::string getInstallName() const {
0061 return std::string(Parent->Libraries[Index].InstallName);
0062 }
0063
0064 bool isTopLevelLib() const {
0065 return Parent->ParsedFile->getInstallName() == getInstallName();
0066 }
0067
0068 Expected<std::unique_ptr<TapiFile>> getAsObjectFile() const;
0069 };
0070
0071 class object_iterator {
0072 ObjectForArch Obj;
0073
0074 public:
0075 object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
0076 const ObjectForArch *operator->() const { return &Obj; }
0077 const ObjectForArch &operator*() const { return Obj; }
0078
0079 bool operator==(const object_iterator &Other) const {
0080 return Obj == Other.Obj;
0081 }
0082 bool operator!=(const object_iterator &Other) const {
0083 return !(*this == Other);
0084 }
0085
0086 object_iterator &operator++() {
0087 Obj = Obj.getNext();
0088 return *this;
0089 }
0090 };
0091
0092 TapiUniversal(MemoryBufferRef Source, Error &Err);
0093 static Expected<std::unique_ptr<TapiUniversal>>
0094 create(MemoryBufferRef Source);
0095 ~TapiUniversal() override;
0096
0097 object_iterator begin_objects() const { return ObjectForArch(this, 0); }
0098 object_iterator end_objects() const {
0099 return ObjectForArch(this, Libraries.size());
0100 }
0101
0102 iterator_range<object_iterator> objects() const {
0103 return make_range(begin_objects(), end_objects());
0104 }
0105
0106 const MachO::InterfaceFile &getInterfaceFile() { return *ParsedFile; }
0107
0108 uint32_t getNumberOfObjects() const { return Libraries.size(); }
0109
0110 static bool classof(const Binary *v) { return v->isTapiUniversal(); }
0111
0112 private:
0113 struct Library {
0114 StringRef InstallName;
0115 MachO::Architecture Arch;
0116 };
0117
0118 std::unique_ptr<MachO::InterfaceFile> ParsedFile;
0119 std::vector<Library> Libraries;
0120 };
0121
0122 }
0123 }
0124
0125 #endif