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/Object/MachOFormat.h"
28 class MachOUniversalBinary : public Binary {
29 virtual void anchor();
31 uint32_t NumberOfObjects;
34 const MachOUniversalBinary *Parent;
35 /// \brief Index of object in the universal binary.
37 /// \brief Descriptor of the object.
38 macho::FatArchHeader Header;
41 ObjectForArch(const MachOUniversalBinary *Parent, uint32_t Index);
48 bool operator==(const ObjectForArch &Other) const {
49 return (Parent == Other.Parent) && (Index == Other.Index);
52 ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
53 uint32_t getCPUType() const { return Header.CPUType; }
55 error_code getAsObjectFile(OwningPtr<ObjectFile> &Result) const;
58 class object_iterator {
61 object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
62 const ObjectForArch* operator->() const {
66 bool operator==(const object_iterator &Other) const {
67 return Obj == Other.Obj;
69 bool operator!=(const object_iterator &Other) const {
70 return !(*this == Other);
73 object_iterator& operator++() { // Preincrement
79 MachOUniversalBinary(MemoryBuffer *Source, error_code &ec);
81 object_iterator begin_objects() const {
82 return ObjectForArch(this, 0);
84 object_iterator end_objects() const {
85 return ObjectForArch(0, 0);
88 uint32_t getNumberOfObjects() const { return NumberOfObjects; }
91 static inline bool classof(Binary const *V) {
92 return V->isMachOUniversalBinary();
95 error_code getObjectForArch(Triple::ArchType Arch,
96 OwningPtr<ObjectFile> &Result) const;