LLVM  15.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/ADT/StringRef.h"
17 #include "llvm/Object/Binary.h"
18 #include "llvm/Support/Error.h"
22 
23 namespace llvm {
24 namespace object {
25 
26 class TapiFile;
27 
28 class TapiUniversal : public Binary {
29 public:
30  class ObjectForArch {
31  const TapiUniversal *Parent;
32  int Index;
33 
34  public:
35  ObjectForArch(const TapiUniversal *Parent, int Index)
36  : Parent(Parent), Index(Index) {}
37 
38  ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
39 
40  bool operator==(const ObjectForArch &Other) const {
41  return (Parent == Other.Parent) && (Index == Other.Index);
42  }
43 
44  uint32_t getCPUType() const {
45  auto Result =
46  MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
47  return Result.first;
48  }
49 
51  auto Result =
52  MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
53  return Result.second;
54  }
55 
57  return MachO::getArchitectureName(Parent->Libraries[Index].Arch);
58  }
59 
60  std::string getInstallName() const {
61  return std::string(Parent->Libraries[Index].InstallName);
62  }
63 
64  bool isTopLevelLib() const {
65  return Parent->ParsedFile->getInstallName() == getInstallName();
66  }
67 
69  };
70 
72  ObjectForArch Obj;
73 
74  public:
75  object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
76  const ObjectForArch *operator->() const { return &Obj; }
77  const ObjectForArch &operator*() const { return Obj; }
78 
79  bool operator==(const object_iterator &Other) const {
80  return Obj == Other.Obj;
81  }
82  bool operator!=(const object_iterator &Other) const {
83  return !(*this == Other);
84  }
85 
86  object_iterator &operator++() { // Preincrement
87  Obj = Obj.getNext();
88  return *this;
89  }
90  };
91 
95  ~TapiUniversal() override;
96 
97  object_iterator begin_objects() const { return ObjectForArch(this, 0); }
99  return ObjectForArch(this, Libraries.size());
100  }
101 
103  return make_range(begin_objects(), end_objects());
104  }
105 
106  const MachO::InterfaceFile &getInterfaceFile() { return *ParsedFile; }
107 
108  uint32_t getNumberOfObjects() const { return Libraries.size(); }
109 
110  static bool classof(const Binary *v) { return v->isTapiUniversal(); }
111 
112 private:
113  struct Library {
114  StringRef InstallName;
115  MachO::Architecture Arch;
116  };
117 
118  std::unique_ptr<MachO::InterfaceFile> ParsedFile;
119  std::vector<Library> Libraries;
120 };
121 
122 } // end namespace object.
123 } // end namespace llvm.
124 
125 #endif // LLVM_OBJECT_TAPIUNIVERSAL_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
StringRef.h
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:77
Architecture.h
MemoryBufferRef.h
llvm::object::TapiUniversal::ObjectForArch::getCPUSubType
uint32_t getCPUSubType() const
Definition: TapiUniversal.h:50
llvm::object::TapiUniversal::ObjectForArch::getCPUType
uint32_t getCPUType() const
Definition: TapiUniversal.h:44
llvm::object::TapiUniversal::ObjectForArch::ObjectForArch
ObjectForArch(const TapiUniversal *Parent, int Index)
Definition: TapiUniversal.h:35
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::object::TapiUniversal::object_iterator::operator==
bool operator==(const object_iterator &Other) const
Definition: TapiUniversal.h:79
llvm::object::TapiUniversal::ObjectForArch::getAsObjectFile
Expected< std::unique_ptr< TapiFile > > getAsObjectFile() const
Definition: TapiUniversal.cpp:49
llvm::object::TapiUniversal::end_objects
object_iterator end_objects() const
Definition: TapiUniversal.h:98
llvm::object::TapiUniversal::ObjectForArch::getNext
ObjectForArch getNext() const
Definition: TapiUniversal.h:38
llvm::object::TapiUniversal::TapiUniversal
TapiUniversal(MemoryBufferRef Source, Error &Err)
Definition: TapiUniversal.cpp:24
llvm::object::Binary::isTapiUniversal
bool isTapiUniversal() const
Definition: Binary.h:118
llvm::object::TapiUniversal::ObjectForArch::getInstallName
std::string getInstallName() const
Definition: TapiUniversal.h:60
llvm::object::TapiUniversal::getInterfaceFile
const MachO::InterfaceFile & getInterfaceFile()
Definition: TapiUniversal.h:106
llvm::object::TapiUniversal::objects
iterator_range< object_iterator > objects() const
Definition: TapiUniversal.h:102
llvm::object::TapiUniversal::classof
static bool classof(const Binary *v)
Definition: TapiUniversal.h:110
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:108
llvm::object::TapiUniversal::create
static Expected< std::unique_ptr< TapiUniversal > > create(MemoryBufferRef Source)
Definition: TapiUniversal.cpp:56
llvm::object::TapiUniversal::ObjectForArch::isTopLevelLib
bool isTopLevelLib() const
Definition: TapiUniversal.h:64
llvm::object::TapiUniversal::object_iterator::operator++
object_iterator & operator++()
Definition: TapiUniversal.h:86
llvm::MachO::InterfaceFile
Defines the interface file.
Definition: InterfaceFile.h:152
llvm::object::TapiUniversal::ObjectForArch
Definition: TapiUniversal.h:30
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:99
llvm::object::TapiUniversal
Definition: TapiUniversal.h:28
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::Binary
Definition: Binary.h:32
uint32_t
llvm::object::TapiUniversal::object_iterator::operator->
const ObjectForArch * operator->() const
Definition: TapiUniversal.h:76
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::object::TapiUniversal::object_iterator
Definition: TapiUniversal.h:71
Binary.h
llvm::object::TapiUniversal::ObjectForArch::operator==
bool operator==(const ObjectForArch &Other) const
Definition: TapiUniversal.h:40
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:97
llvm::object::TapiUniversal::object_iterator::object_iterator
object_iterator(const ObjectForArch &Obj)
Definition: TapiUniversal.h:75
InterfaceFile.h
llvm::object::TapiUniversal::object_iterator::operator!=
bool operator!=(const object_iterator &Other) const
Definition: TapiUniversal.h:82
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1225
llvm::object::TapiUniversal::ObjectForArch::getArchFlagName
StringRef getArchFlagName() const
Definition: TapiUniversal.h:56