1 //===- MachOUniversal.h - Mach-O universal binaries -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares Mach-O fat/universal binaries.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECT_MACHOUNIVERSAL_H
15 #define LLVM_OBJECT_MACHOUNIVERSAL_H
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Object/Binary.h"
21 #include "llvm/Support/ErrorOr.h"
22 #include "llvm/Support/MachO.h"
29 class MachOUniversalBinary : public Binary {
30 virtual void anchor();
32 uint32_t NumberOfObjects;
35 const MachOUniversalBinary *Parent;
36 /// \brief Index of object in the universal binary.
38 /// \brief Descriptor of the object.
39 MachO::fat_arch Header;
42 ObjectForArch(const MachOUniversalBinary *Parent, uint32_t Index);
49 bool operator==(const ObjectForArch &Other) const {
50 return (Parent == Other.Parent) && (Index == Other.Index);
53 ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
54 uint32_t getCPUType() const { return Header.cputype; }
56 error_code getAsObjectFile(OwningPtr<ObjectFile> &Result) const;
59 class object_iterator {
62 object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
63 const ObjectForArch* operator->() const {
67 bool operator==(const object_iterator &Other) const {
68 return Obj == Other.Obj;
70 bool operator!=(const object_iterator &Other) const {
71 return !(*this == Other);
74 object_iterator& operator++() { // Preincrement
80 MachOUniversalBinary(MemoryBuffer *Source, error_code &ec);
81 static ErrorOr<MachOUniversalBinary*> create(MemoryBuffer *Source);
83 object_iterator begin_objects() const {
84 return ObjectForArch(this, 0);
86 object_iterator end_objects() const {
87 return ObjectForArch(0, 0);
90 uint32_t getNumberOfObjects() const { return NumberOfObjects; }
93 static inline bool classof(Binary const *V) {
94 return V->isMachOUniversalBinary();
97 error_code getObjectForArch(Triple::ArchType Arch,
98 OwningPtr<ObjectFile> &Result) const;