LLVM  3.7.0
MachOUniversal.h
Go to the documentation of this file.
1 //===- MachOUniversal.h - Mach-O universal binaries -------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares Mach-O fat/universal binaries.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_OBJECT_MACHOUNIVERSAL_H
15 #define LLVM_OBJECT_MACHOUNIVERSAL_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/Triple.h"
20 #include "llvm/Object/Archive.h"
21 #include "llvm/Object/Binary.h"
22 #include "llvm/Object/MachO.h"
23 #include "llvm/Support/ErrorOr.h"
24 #include "llvm/Support/MachO.h"
25 
26 namespace llvm {
27 namespace object {
28 
29 class MachOUniversalBinary : public Binary {
30  virtual void anchor();
31 
32  uint32_t NumberOfObjects;
33 public:
34  class ObjectForArch {
35  const MachOUniversalBinary *Parent;
36  /// \brief Index of object in the universal binary.
37  uint32_t Index;
38  /// \brief Descriptor of the object.
39  MachO::fat_arch Header;
40 
41  public:
42  ObjectForArch(const MachOUniversalBinary *Parent, uint32_t Index);
43 
44  void clear() {
45  Parent = nullptr;
46  Index = 0;
47  }
48 
49  bool operator==(const ObjectForArch &Other) const {
50  return (Parent == Other.Parent) && (Index == Other.Index);
51  }
52 
53  ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
54  uint32_t getCPUType() const { return Header.cputype; }
55  uint32_t getCPUSubType() const { return Header.cpusubtype; }
56  uint32_t getOffset() const { return Header.offset; }
57  uint32_t getSize() const { return Header.size; }
58  uint32_t getAlign() const { return Header.align; }
59  std::string getArchTypeName() const {
61  return T.getArchName();
62  }
63 
65 
67  };
68 
70  ObjectForArch Obj;
71  public:
72  object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
73  const ObjectForArch *operator->() const { return &Obj; }
74  const ObjectForArch &operator*() const { return Obj; }
75 
76  bool operator==(const object_iterator &Other) const {
77  return Obj == Other.Obj;
78  }
79  bool operator!=(const object_iterator &Other) const {
80  return !(*this == Other);
81  }
82 
83  object_iterator& operator++() { // Preincrement
84  Obj = Obj.getNext();
85  return *this;
86  }
87  };
88 
89  MachOUniversalBinary(MemoryBufferRef Souce, std::error_code &EC);
92 
94  return ObjectForArch(this, 0);
95  }
97  return ObjectForArch(nullptr, 0);
98  }
99 
101  return make_range(begin_objects(), end_objects());
102  }
103 
104  uint32_t getNumberOfObjects() const { return NumberOfObjects; }
105 
106  // Cast methods.
107  static inline bool classof(Binary const *V) {
108  return V->isMachOUniversalBinary();
109  }
110 
112  getObjectForArch(StringRef ArchName) const;
113 };
114 
115 }
116 }
117 
118 #endif
ErrorOr< std::unique_ptr< Archive > > getAsArchive() const
Represents either an error or a value T.
Definition: ErrorOr.h:82
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
ObjectForArch(const MachOUniversalBinary *Parent, uint32_t Index)
bool operator==(const object_iterator &Other) const
bool operator==(const ObjectForArch &Other) const
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:591
iterator_range< object_iterator > objects() const
unsigned getArch() const override
ErrorOr< std::unique_ptr< MachOObjectFile > > getAsObjectFile() const
ErrorOr< std::unique_ptr< MachOObjectFile > > getObjectForArch(StringRef ArchName) const
bool operator!=(const object_iterator &Other) const
static ErrorOr< std::unique_ptr< MachOUniversalBinary > > create(MemoryBufferRef Source)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
object_iterator end_objects() const
A range adaptor for a pair of iterators.
StringRef getArchName() const
getArchName - Get the architecture (first) component of the triple.
Definition: Triple.cpp:783
MachOUniversalBinary(MemoryBufferRef Souce, std::error_code &EC)
object_iterator begin_objects() const
static bool classof(Binary const *V)
Provides ErrorOr<T> smart pointer.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
bool isMachOUniversalBinary() const
Definition: Binary.h:100