LLVM  10.0.0svn
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_TAPI_UNIVERSAL_H
14 #define LLVM_OBJECT_TAPI_UNIVERSAL_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->Architectures[Index]);
45  return Result.first;
46  }
47 
49  auto Result =
50  MachO::getCPUTypeFromArchitecture(Parent->Architectures[Index]);
51  return Result.second;
52  }
53 
54  std::string getArchFlagName() const {
55  return MachO::getArchitectureName(Parent->Architectures[Index]);
56  }
57 
59  };
60 
62  ObjectForArch Obj;
63 
64  public:
65  object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
66  const ObjectForArch *operator->() const { return &Obj; }
67  const ObjectForArch &operator*() const { return Obj; }
68 
69  bool operator==(const object_iterator &Other) const {
70  return Obj == Other.Obj;
71  }
72  bool operator!=(const object_iterator &Other) const {
73  return !(*this == Other);
74  }
75 
76  object_iterator &operator++() { // Preincrement
77  Obj = Obj.getNext();
78  return *this;
79  }
80  };
81 
84  create(MemoryBufferRef Source);
85  ~TapiUniversal() override;
86 
87  object_iterator begin_objects() const { return ObjectForArch(this, 0); }
89  return ObjectForArch(this, Architectures.size());
90  }
91 
94  }
95 
96  uint32_t getNumberOfObjects() const { return Architectures.size(); }
97 
98  // Cast methods.
99  static bool classof(const Binary *v) { return v->isTapiUniversal(); }
100 
101 private:
102  std::unique_ptr<MachO::InterfaceFile> ParsedFile;
103  std::vector<MachO::Architecture> Architectures;
104 };
105 
106 } // end namespace object.
107 } // end namespace llvm.
108 
109 #endif // LLVM_OBJECT_TAPI_UNIVERSAL_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isTapiUniversal() const
Definition: Binary.h:116
const ObjectForArch & operator*() const
Definition: TapiUniversal.h:67
bool operator!=(const object_iterator &Other) const
Definition: TapiUniversal.h:72
static bool classof(const Binary *v)
Definition: TapiUniversal.h:99
iterator_range< object_iterator > objects() const
Definition: TapiUniversal.h:92
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
object_iterator(const ObjectForArch &Obj)
Definition: TapiUniversal.h:65
ObjectForArch(const TapiUniversal *Parent, int Index)
Definition: TapiUniversal.h:33
TapiUniversal(MemoryBufferRef Source, Error &Err)
bool operator==(const ObjectForArch &Other) const
Definition: TapiUniversal.h:38
object_iterator end_objects() const
Definition: TapiUniversal.h:88
Expected< std::unique_ptr< TapiFile > > getAsObjectFile() const
bool operator==(const object_iterator &Other) const
Definition: TapiUniversal.h:69
static Expected< std::unique_ptr< TapiUniversal > > create(MemoryBufferRef Source)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::pair< uint32_t, uint32_t > getCPUTypeFromArchitecture(Architecture Arch)
Convert an architecture slice to a CPU Type and Subtype pair.
A range adaptor for a pair of iterators.
uint32_t getNumberOfObjects() const
Definition: TapiUniversal.h:96
const ObjectForArch * operator->() const
Definition: TapiUniversal.h:66
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
object_iterator begin_objects() const
Definition: TapiUniversal.h:87