DebugInfo: Include lexical scopes in inlined subroutines.
[oota-llvm.git] / include / llvm / Object / MachOUniversal.h
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"
19 #include "llvm/Object/Binary.h"
20 #include "llvm/Support/ErrorOr.h"
21 #include "llvm/Support/MachO.h"
22
23 namespace llvm {
24 namespace object {
25
26 class ObjectFile;
27
28 class MachOUniversalBinary : public Binary {
29   virtual void anchor();
30
31   uint32_t NumberOfObjects;
32 public:
33   class ObjectForArch {
34     const MachOUniversalBinary *Parent;
35     /// \brief Index of object in the universal binary.
36     uint32_t Index;
37     /// \brief Descriptor of the object.
38     MachO::fat_arch Header;
39
40   public:
41     ObjectForArch(const MachOUniversalBinary *Parent, uint32_t Index);
42
43     void clear() {
44       Parent = nullptr;
45       Index = 0;
46     }
47
48     bool operator==(const ObjectForArch &Other) const {
49       return (Parent == Other.Parent) && (Index == Other.Index);
50     }
51
52     ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
53     uint32_t getCPUType() const { return Header.cputype; }
54
55     error_code getAsObjectFile(std::unique_ptr<ObjectFile> &Result) const;
56   };
57
58   class object_iterator {
59     ObjectForArch Obj;
60   public:
61     object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
62     const ObjectForArch* operator->() const {
63       return &Obj;
64     }
65
66     bool operator==(const object_iterator &Other) const {
67       return Obj == Other.Obj;
68     }
69     bool operator!=(const object_iterator &Other) const {
70       return !(*this == Other);
71     }
72
73     object_iterator& operator++() {  // Preincrement
74       Obj = Obj.getNext();
75       return *this;
76     }
77   };
78
79   MachOUniversalBinary(MemoryBuffer *Source, error_code &ec);
80   static ErrorOr<MachOUniversalBinary*> create(MemoryBuffer *Source);
81
82   object_iterator begin_objects() const {
83     return ObjectForArch(this, 0);
84   }
85   object_iterator end_objects() const {
86     return ObjectForArch(nullptr, 0);
87   }
88
89   uint32_t getNumberOfObjects() const { return NumberOfObjects; }
90
91   // Cast methods.
92   static inline bool classof(Binary const *V) {
93     return V->isMachOUniversalBinary();
94   }
95
96   error_code getObjectForArch(Triple::ArchType Arch,
97                               std::unique_ptr<ObjectFile> &Result) const;
98 };
99
100 }
101 }
102
103 #endif