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/StringRef.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Object/Binary.h"
20 #include "llvm/Object/Archive.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 std::error_code getAsObjectFile(std::unique_ptr<ObjectFile> &Result) const;
58 std::error_code getAsArchive(std::unique_ptr<Archive> &Result) const;
61 class object_iterator {
64 object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
65 const ObjectForArch* operator->() const {
69 bool operator==(const object_iterator &Other) const {
70 return Obj == Other.Obj;
72 bool operator!=(const object_iterator &Other) const {
73 return !(*this == Other);
76 object_iterator& operator++() { // Preincrement
82 MachOUniversalBinary(MemoryBuffer *Source, std::error_code &ec);
83 static ErrorOr<MachOUniversalBinary*> create(MemoryBuffer *Source);
85 object_iterator begin_objects() const {
86 return ObjectForArch(this, 0);
88 object_iterator end_objects() const {
89 return ObjectForArch(nullptr, 0);
92 uint32_t getNumberOfObjects() const { return NumberOfObjects; }
95 static inline bool classof(Binary const *V) {
96 return V->isMachOUniversalBinary();
99 std::error_code getObjectForArch(Triple::ArchType Arch,
100 std::unique_ptr<ObjectFile> &Result) const;