1 //===-- TapiUniversal.h - Text-based Dynamic Library Stub -------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares the TapiUniversal interface.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_OBJECT_TAPI_UNIVERSAL_H
14 #define LLVM_OBJECT_TAPI_UNIVERSAL_H
16 #include "llvm/Object/Binary.h"
17 #include "llvm/Object/TapiFile.h"
18 #include "llvm/Support/Error.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/TextAPI/MachO/Architecture.h"
21 #include "llvm/TextAPI/MachO/InterfaceFile.h"
26 class TapiUniversal
: public Binary
{
29 const TapiUniversal
*Parent
;
33 ObjectForArch(const TapiUniversal
*Parent
, int Index
)
34 : Parent(Parent
), Index(Index
) {}
36 ObjectForArch
getNext() const { return ObjectForArch(Parent
, Index
+ 1); }
38 bool operator==(const ObjectForArch
&Other
) const {
39 return (Parent
== Other
.Parent
) && (Index
== Other
.Index
);
42 uint32_t getCPUType() const {
44 MachO::getCPUTypeFromArchitecture(Parent
->Architectures
[Index
]);
48 uint32_t getCPUSubType() const {
50 MachO::getCPUTypeFromArchitecture(Parent
->Architectures
[Index
]);
54 std::string
getArchFlagName() const {
55 return MachO::getArchitectureName(Parent
->Architectures
[Index
]);
58 Expected
<std::unique_ptr
<TapiFile
>> getAsObjectFile() const;
61 class object_iterator
{
65 object_iterator(const ObjectForArch
&Obj
) : Obj(Obj
) {}
66 const ObjectForArch
*operator->() const { return &Obj
; }
67 const ObjectForArch
&operator*() const { return Obj
; }
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 TapiUniversal(MemoryBufferRef Source
, Error
&Err
);
83 static Expected
<std::unique_ptr
<TapiUniversal
>>
84 create(MemoryBufferRef Source
);
85 ~TapiUniversal() override
;
87 object_iterator
begin_objects() const { return ObjectForArch(this, 0); }
88 object_iterator
end_objects() const {
89 return ObjectForArch(this, Architectures
.size());
92 iterator_range
<object_iterator
> objects() const {
93 return make_range(begin_objects(), end_objects());
96 uint32_t getNumberOfObjects() const { return Architectures
.size(); }
99 static bool classof(const Binary
*v
) { return v
->isTapiUniversal(); }
102 std::unique_ptr
<MachO::InterfaceFile
> ParsedFile
;
103 std::vector
<MachO::Architecture
> Architectures
;
106 } // end namespace object.
107 } // end namespace llvm.
109 #endif // LLVM_OBJECT_TAPI_UNIVERSAL_H