LLVM 22.0.0git
RecordsSlice.h
Go to the documentation of this file.
1//===- llvm/TextAPI/RecordSlice.h - TAPI RecordSlice ------------*- 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/// \file
10/// \brief Implements the TAPI Record Collection Type.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TEXTAPI_RECORDSLICE_H
15#define LLVM_TEXTAPI_RECORDSLICE_H
16
21#include "llvm/TextAPI/Record.h"
23
24namespace llvm {
25namespace MachO {
26
27// Define collection of records for a library that are tied to a darwin target
28// triple.
30public:
31 RecordsSlice(const llvm::Triple &T) : TargetTriple(T), TAPITarget(T) {}
32 /// Get target triple.
33 const llvm::Triple &getTriple() const { return TargetTriple; }
34 /// Get TAPI converted target.
35 const Target &getTarget() const { return TAPITarget; }
36
37 /// Add unspecified record to slice.
38 ///
39 /// Assign specific record type based on properties and symbol name.
40 ///
41 /// \param Name The name of symbol.
42 /// \param Flags The flags that describe attributes of the symbol.
43 /// \param GV The kind of global, if this represents a non obj-c global
44 /// symbol.
45 /// \param Linkage The linkage of symbol.
46 /// \return The non-owning pointer to added record in slice.
51
52 /// Add non-ObjC global record.
53 ///
54 /// \param Name The name of symbol.
55 /// \param Linkage The linkage of symbol.
56 /// \param GV The kind of global.
57 /// \param Flags The flags that describe attributes of the symbol.
58 /// \param Inlined Whether declaration is inlined, only applicable to
59 /// functions.
60 /// \return The non-owning pointer to added record in slice.
64 bool Inlined = false);
65
66 /// Add ObjC Class record.
67 ///
68 /// \param Name The name of class, not symbol.
69 /// \param Linkage The linkage of symbol.
70 /// \param SymType The symbols this class represents.
71 /// \return The non-owning pointer to added record in slice.
74 ObjCIFSymbolKind SymType);
75
76 /// Add ObjC IVar record.
77 ///
78 /// \param Container Owning pointer for instance variable.
79 /// \param Name The name of ivar, not symbol.
80 /// \param Linkage The linkage of symbol.
81 /// \return The non-owning pointer to added record in slice.
84
85 /// Add ObjC Category record.
86 ///
87 /// \param ClassToExtend The name of class that is being extended by the
88 /// category, not symbol.
89 /// \param Category The name of category.
90 /// \return The non-owning pointer to added record in slice.
92 StringRef Category);
93
94 /// Find ObjC Class.
95 ///
96 /// \param Name name of class, not full symbol name.
97 /// \return The non-owning pointer to record in slice.
99
100 /// Find ObjC Category.
101 ///
102 /// \param ClassToExtend The name of class, not full symbol name.
103 /// \param Category The name of category.
104 /// \return The non-owning pointer to record in slice.
106 StringRef Category) const;
107
108 /// Find ObjC Container. This is commonly used for assigning for looking up
109 /// instance variables that are assigned to either a category or class.
110 ///
111 /// \param IsIVar If true, the name is the name of the IVar, otherwise it will
112 /// be looked up as the name of the container.
113 /// \param Name Either the name of ivar or name of container.
114 /// \return The non-owning pointer to record in
115 /// slice.
117 StringRef Name) const;
118
119 /// Find ObjC instance variable.
120 ///
121 /// \param IsScopedName This is used to determine how to parse the name.
122 /// \param Name Either the full name of the symbol or just the ivar.
123 /// \return The non-owning pointer to record in slice.
124 LLVM_ABI ObjCIVarRecord *findObjCIVar(bool IsScopedName,
125 StringRef Name) const;
126
127 /// Find non-objc global.
128 ///
129 /// \param Name The name of symbol.
130 /// \param GV The Kind of global to find.
131 /// \return The non-owning pointer to record in slice.
135
136 // Determine if library attributes were assigned.
137 bool hasBinaryAttrs() const { return BA.get(); }
138
139 // Determine if record slice is unassigned.
140 bool empty() const {
141 return !hasBinaryAttrs() && Globals.empty() && Classes.empty() &&
142 Categories.empty();
143 }
144
145 // Visit all records known to RecordsSlice.
146 LLVM_ABI void visit(RecordVisitor &V) const;
147
148 struct BinaryAttrs {
149 std::vector<StringRef> AllowableClients;
150 std::vector<StringRef> RexportedLibraries;
151 std::vector<StringRef> RPaths;
160 bool TwoLevelNamespace = false;
161 bool AppExtensionSafe = false;
163 };
164
165 /// Return reference to BinaryAttrs.
167
168 /// Store any strings owned by RecordSlice into allocator and return back
169 /// reference to that.
171
172private:
173 const llvm::Triple TargetTriple;
174 // Hold tapi converted triple to avoid unecessary casts.
175 const Target TAPITarget;
176
177 /// BumpPtrAllocator to store generated/copied strings.
178 llvm::BumpPtrAllocator StringAllocator;
179
180 /// Promote linkage of requested record. It is no-op if linkage type is lower
181 /// than the current assignment.
182 ///
183 /// \param R The record to update.
184 /// \param L Linkage type to update to.
185 void updateLinkage(Record *R, RecordLinkage L) {
186 R->Linkage = std::max(R->Linkage, L);
187 }
188
189 /// Update set flags of requested record.
190 ///
191 /// \param R The record to update.
192 /// \param F Flags to update to.
193 void updateFlags(Record *R, SymbolFlags F) { R->Flags |= F; }
194
195 RecordMap<GlobalRecord> Globals;
196 RecordMap<ObjCInterfaceRecord> Classes;
197 RecordMap<ObjCCategoryRecord, std::pair<StringRef, StringRef>> Categories;
198
199 std::unique_ptr<BinaryAttrs> BA{nullptr};
200};
201
203class InterfaceFile;
204LLVM_ABI std::unique_ptr<InterfaceFile>
205convertToInterfaceFile(const Records &Slices);
206
207} // namespace MachO
208} // namespace llvm
209#endif // LLVM_TEXTAPI_RECORDSLICE_H
This file defines the BumpPtrAllocator interface.
#define LLVM_ABI
Definition: Compiler.h:213
DXIL Finalize Linkage
std::string Name
#define F(x, y, z)
Definition: MD5.cpp:55
Implements the TAPI Record Types.
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
Defines the interface file.
Base class for any usage of traversing over collected Records.
Definition: RecordVisitor.h:24
Define Record.
Definition: Record.h:68
LLVM_ABI StringRef copyString(StringRef String)
Store any strings owned by RecordSlice into allocator and return back reference to that.
LLVM_ABI ObjCIVarRecord * findObjCIVar(bool IsScopedName, StringRef Name) const
Find ObjC instance variable.
LLVM_ABI ObjCCategoryRecord * addObjCCategory(StringRef ClassToExtend, StringRef Category)
Add ObjC Category record.
LLVM_ABI ObjCInterfaceRecord * addObjCInterface(StringRef Name, RecordLinkage Linkage, ObjCIFSymbolKind SymType)
Add ObjC Class record.
RecordsSlice(const llvm::Triple &T)
Definition: RecordsSlice.h:31
LLVM_ABI ObjCContainerRecord * findContainer(bool IsIVar, StringRef Name) const
Find ObjC Container.
LLVM_ABI ObjCIVarRecord * addObjCIVar(ObjCContainerRecord *Container, StringRef Name, RecordLinkage Linkage)
Add ObjC IVar record.
LLVM_ABI GlobalRecord * addGlobal(StringRef Name, RecordLinkage Linkage, GlobalRecord::Kind GV, SymbolFlags Flags=SymbolFlags::None, bool Inlined=false)
Add non-ObjC global record.
LLVM_ABI GlobalRecord * findGlobal(StringRef Name, GlobalRecord::Kind GV=GlobalRecord::Kind::Unknown) const
Find non-objc global.
LLVM_ABI ObjCCategoryRecord * findObjCCategory(StringRef ClassToExtend, StringRef Category) const
Find ObjC Category.
LLVM_ABI BinaryAttrs & getBinaryAttrs()
Return reference to BinaryAttrs.
const Target & getTarget() const
Get TAPI converted target.
Definition: RecordsSlice.h:35
const llvm::Triple & getTriple() const
Get target triple.
Definition: RecordsSlice.h:33
LLVM_ABI ObjCInterfaceRecord * findObjCInterface(StringRef Name) const
Find ObjC Class.
LLVM_ABI Record * addRecord(StringRef Name, SymbolFlags Flags, GlobalRecord::Kind GV=GlobalRecord::Kind::Unknown, RecordLinkage Linkage=RecordLinkage::Unknown)
Add unspecified record to slice.
LLVM_ABI void visit(RecordVisitor &V) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
FileType
Defines the file type TextAPI files can represent.
Definition: FileTypes.h:15
@ Invalid
Invalid file type.
Definition: FileTypes.h:17
RecordLinkage
Definition: Record.h:49
LLVM_ABI std::unique_ptr< InterfaceFile > convertToInterfaceFile(const Records &Slices)
ObjCIFSymbolKind
ObjC Interface symbol mappings.
Definition: Symbol.h:70
SymbolFlags
Symbol flags.
Definition: Symbol.h:25
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::vector< StringRef > RPaths
Definition: RecordsSlice.h:151
std::vector< StringRef > RexportedLibraries
Definition: RecordsSlice.h:150
std::vector< StringRef > AllowableClients
Definition: RecordsSlice.h:149
llvm::MachO::PackedVersion CompatVersion
Definition: RecordsSlice.h:158
llvm::MachO::PackedVersion CurrentVersion
Definition: RecordsSlice.h:157