LLVM  14.0.0git
TapiUniversal.h
Go to the documentation of this file.
1 //===-- TapiUniversal.h - Text-based Dynamic Library Stub -------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the TapiUniversal interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_OBJECT_TAPIUNIVERSAL_H
14 #define LLVM_OBJECT_TAPIUNIVERSAL_H
15 
16 #include "llvm/Object/Binary.h"
17 #include "llvm/Object/TapiFile.h"
18 #include "llvm/Support/Error.h"
22 
23 namespace llvm {
24 namespace object {
25 
26 class TapiUniversal : public Binary {
27 public:
28  class ObjectForArch {
29  const TapiUniversal *Parent;
30  int Index;
31 
32  public:
33  ObjectForArch(const TapiUniversal *Parent, int Index)
34  : Parent(Parent), Index(Index) {}
35 
36  ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
37 
38  bool operator==(const ObjectForArch &Other) const {
39  return (Parent == Other.Parent) && (Index == Other.Index);
40  }
41 
42  uint32_t getCPUType() const {
43  auto Result =
44  MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
45  return Result.first;
46  }
47 
49  auto Result =
50  MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
51  return Result.second;
52  }
53 
55  return MachO::getArchitectureName(Parent->Libraries[Index].Arch);
56  }
57 
58  std::string getInstallName() const {
59  return std::string(Parent->Libraries[Index].InstallName);
60  }
61 
62  bool isTopLevelLib() const {
63  return Parent->ParsedFile->getInstallName() == getInstallName();
64  }
65 
67  };
68 
70  ObjectForArch Obj;
71 
72  public:
73  object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
74  const ObjectForArch *operator->() const { return &Obj; }
75  const ObjectForArch &operator*() const { return Obj; }
76 
77  bool operator==(const object_iterator &Other) const {
78  return Obj == Other.Obj;
79  }
80  bool operator!=(const object_iterator &Other) const {
81  return !(*this == Other);
82  }
83 
84  object_iterator &operator++() { // Preincrement
85  Obj = Obj.getNext();
86  return *this;
87  }
88  };
89 
93  ~TapiUniversal() override;
94 
95  object_iterator begin_objects() const { return ObjectForArch(this, 0); }
97  return ObjectForArch(this, Libraries.size());
98  }
99 
101  return make_range(begin_objects(), end_objects());
102  }
103 
104  const MachO::InterfaceFile &getInterfaceFile() { return *ParsedFile; }
105 
106  uint32_t getNumberOfObjects() const { return Libraries.size(); }
107 
108  static bool classof(const Binary *v) { return v->isTapiUniversal(); }
109 
110 private:
111  struct Library {
112  StringRef InstallName;
113  MachO::Architecture Arch;
114  };
115 
116  std::unique_ptr<MachO::InterfaceFile> ParsedFile;
117  std::vector<Library> Libraries;
118 };
119 
120 } // end namespace object.
121 } // end namespace llvm.
122 
123 #endif // LLVM_OBJECT_TAPIUNIVERSAL_H
MemoryBuffer.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::object::TapiUniversal::~TapiUniversal
~TapiUniversal() override
Error.h
Library
Itanium Name Demangler Library
Definition: README.txt:2
llvm::object::TapiUniversal::object_iterator::operator*
const ObjectForArch & operator*() const
Definition: TapiUniversal.h:75
Architecture.h
llvm::object::TapiUniversal::ObjectForArch::getCPUSubType
uint32_t getCPUSubType() const
Definition: TapiUniversal.h:48
llvm::object::TapiUniversal::ObjectForArch::getCPUType
uint32_t getCPUType() const
Definition: TapiUniversal.h:42
llvm::object::TapiUniversal::ObjectForArch::ObjectForArch
ObjectForArch(const TapiUniversal *Parent, int Index)
Definition: TapiUniversal.h:33
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::object::TapiUniversal::object_iterator::operator==
bool operator==(const object_iterator &Other) const
Definition: TapiUniversal.h:77
TapiFile.h
llvm::object::TapiUniversal::ObjectForArch::getAsObjectFile
Expected< std::unique_ptr< TapiFile > > getAsObjectFile() const
Definition: TapiUniversal.cpp:48
llvm::object::TapiUniversal::end_objects
object_iterator end_objects() const
Definition: TapiUniversal.h:96
llvm::object::TapiUniversal::ObjectForArch::getNext
ObjectForArch getNext() const
Definition: TapiUniversal.h:36
llvm::object::TapiUniversal::TapiUniversal
TapiUniversal(MemoryBufferRef Source, Error &Err)
Definition: TapiUniversal.cpp:23
llvm::object::Binary::isTapiUniversal
bool isTapiUniversal() const
Definition: Binary.h:118
llvm::object::TapiUniversal::ObjectForArch::getInstallName
std::string getInstallName() const
Definition: TapiUniversal.h:58
llvm::object::TapiUniversal::getInterfaceFile
const MachO::InterfaceFile & getInterfaceFile()
Definition: TapiUniversal.h:104
llvm::object::TapiUniversal::objects
iterator_range< object_iterator > objects() const
Definition: TapiUniversal.h:100
llvm::object::TapiUniversal::classof
static bool classof(const Binary *v)
Definition: TapiUniversal.h:108
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::MachO::Architecture
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
llvm::object::TapiUniversal::getNumberOfObjects
uint32_t getNumberOfObjects() const
Definition: TapiUniversal.h:106
llvm::object::TapiUniversal::create
static Expected< std::unique_ptr< TapiUniversal > > create(MemoryBufferRef Source)
Definition: TapiUniversal.cpp:55
llvm::object::TapiUniversal::ObjectForArch::isTopLevelLib
bool isTopLevelLib() const
Definition: TapiUniversal.h:62
llvm::object::TapiUniversal::object_iterator::operator++
object_iterator & operator++()
Definition: TapiUniversal.h:84
llvm::MachO::InterfaceFile
Defines the interface file.
Definition: InterfaceFile.h:156
llvm::object::TapiUniversal::ObjectForArch
Definition: TapiUniversal.h:28
llvm::MachO::getCPUTypeFromArchitecture
std::pair< uint32_t, uint32_t > getCPUTypeFromArchitecture(Architecture Arch)
Convert an architecture slice to a CPU Type and Subtype pair.
Definition: Architecture.cpp:58
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:100
llvm::object::TapiUniversal
Definition: TapiUniversal.h:26
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::object::Binary
Definition: Binary.h:32
uint32_t
llvm::object::TapiUniversal::object_iterator::operator->
const ObjectForArch * operator->() const
Definition: TapiUniversal.h:74
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::object::TapiUniversal::object_iterator
Definition: TapiUniversal.h:69
Binary.h
llvm::object::TapiUniversal::ObjectForArch::operator==
bool operator==(const ObjectForArch &Other) const
Definition: TapiUniversal.h:38
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::MachO::getArchitectureName
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
Definition: Architecture.cpp:42
llvm::object::TapiUniversal::begin_objects
object_iterator begin_objects() const
Definition: TapiUniversal.h:95
llvm::object::TapiUniversal::object_iterator::object_iterator
object_iterator(const ObjectForArch &Obj)
Definition: TapiUniversal.h:73
InterfaceFile.h
llvm::object::TapiUniversal::object_iterator::operator!=
bool operator!=(const object_iterator &Other) const
Definition: TapiUniversal.h:80
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1195
llvm::object::TapiUniversal::ObjectForArch::getArchFlagName
StringRef getArchFlagName() const
Definition: TapiUniversal.h:54