LLVM 22.0.0git
TapiUniversal.h
Go to the documentation of this file.
1//===-- TapiUniversal.h - Text-based Dynamic Library Stub -------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the TapiUniversal interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_OBJECT_TAPIUNIVERSAL_H
14#define LLVM_OBJECT_TAPIUNIVERSAL_H
15
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Object/Binary.h"
19#include "llvm/Support/Error.h"
23
24namespace llvm {
25namespace object {
26
27class TapiFile;
28
30public:
32 const TapiUniversal *Parent;
33 int Index;
34
35 public:
36 ObjectForArch(const TapiUniversal *Parent, int Index)
37 : Parent(Parent), Index(Index) {}
38
39 ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
40
41 bool operator==(const ObjectForArch &Other) const {
42 return (Parent == Other.Parent) && (Index == Other.Index);
43 }
44
46 auto Result =
47 MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
48 return Result.first;
49 }
50
52 auto Result =
53 MachO::getCPUTypeFromArchitecture(Parent->Libraries[Index].Arch);
54 return Result.second;
55 }
56
58 return MachO::getArchitectureName(Parent->Libraries[Index].Arch);
59 }
60
61 std::string getInstallName() const {
62 return std::string(Parent->Libraries[Index].InstallName);
63 }
64
65 bool isTopLevelLib() const {
66 return Parent->ParsedFile->getInstallName() == getInstallName();
67 }
68
69 LLVM_ABI Expected<std::unique_ptr<TapiFile>> getAsObjectFile() const;
70 };
71
73 ObjectForArch Obj;
74
75 public:
76 object_iterator(const ObjectForArch &Obj) : Obj(Obj) {}
77 const ObjectForArch *operator->() const { return &Obj; }
78 const ObjectForArch &operator*() const { return Obj; }
79
80 bool operator==(const object_iterator &Other) const {
81 return Obj == Other.Obj;
82 }
83 bool operator!=(const object_iterator &Other) const {
84 return !(*this == Other);
85 }
86
87 object_iterator &operator++() { // Preincrement
88 Obj = Obj.getNext();
89 return *this;
90 }
91 };
92
95 create(MemoryBufferRef Source);
96 ~TapiUniversal() override;
97
98 object_iterator begin_objects() const { return ObjectForArch(this, 0); }
100 return ObjectForArch(this, Libraries.size());
101 }
102
104 return make_range(begin_objects(), end_objects());
105 }
106
107 const MachO::InterfaceFile &getInterfaceFile() { return *ParsedFile; }
108
109 uint32_t getNumberOfObjects() const { return Libraries.size(); }
110
111 static bool classof(const Binary *v) { return v->isTapiUniversal(); }
112
113private:
114 /// Attributes of a library that is inlined into a single TBD file.
115 struct Library {
116 const StringRef InstallName;
117 const MachO::Architecture Arch;
118 const std::optional<size_t> DocumentIdx;
119 };
120
121 std::unique_ptr<MachO::InterfaceFile> ParsedFile;
122 std::vector<Library> Libraries;
123};
124
125} // end namespace object.
126} // end namespace llvm.
127
128#endif // LLVM_OBJECT_TAPIUNIVERSAL_H
#define LLVM_ABI
Definition: Compiler.h:213
uint32_t Index
std::optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1328
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
Defines the interface file.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
A range adaptor for a pair of iterators.
ObjectForArch(const TapiUniversal *Parent, int Index)
Definition: TapiUniversal.h:36
bool operator==(const ObjectForArch &Other) const
Definition: TapiUniversal.h:41
object_iterator(const ObjectForArch &Obj)
Definition: TapiUniversal.h:76
const ObjectForArch & operator*() const
Definition: TapiUniversal.h:78
bool operator==(const object_iterator &Other) const
Definition: TapiUniversal.h:80
bool operator!=(const object_iterator &Other) const
Definition: TapiUniversal.h:83
const ObjectForArch * operator->() const
Definition: TapiUniversal.h:77
iterator_range< object_iterator > objects() const
uint32_t getNumberOfObjects() const
object_iterator end_objects() const
Definition: TapiUniversal.h:99
static bool classof(const Binary *v)
const MachO::InterfaceFile & getInterfaceFile()
object_iterator begin_objects() const
Definition: TapiUniversal.h:98
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:28
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.