LLVM 19.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
20#include "llvm/TextAPI/Record.h"
22
23namespace llvm {
24namespace MachO {
25
26// Define collection of records for a library that are tied to a darwin target
27// triple.
29public:
30 RecordsSlice(const llvm::Triple &T) : TargetTriple(T), TAPITarget(T) {}
31 /// Get target triple.
32 const llvm::Triple &getTriple() const { return TargetTriple; }
33 /// Get TAPI converted target.
34 const Target &getTarget() const { return TAPITarget; }
35
36 /// Add unspecified record to slice.
37 ///
38 /// Assign specific record type based on properties and symbol name.
39 ///
40 /// \param Name The name of symbol.
41 /// \param Flags The flags that describe attributes of the symbol.
42 /// \param GV The kind of global, if this represents a non obj-c global
43 /// symbol.
44 /// \param Linkage The linkage of symbol.
45 /// \return The non-owning pointer to added record in slice.
49
50 /// Add non-ObjC global record.
51 ///
52 /// \param Name The name of symbol.
53 /// \param Linkage The linkage of symbol.
54 /// \param GV The kind of global.
55 /// \param Flags The flags that describe attributes of the symbol.
56 /// \param Inlined Whether declaration is inlined, only applicable to
57 /// functions.
58 /// \return The non-owning pointer to added record in slice.
62 bool Inlined = false);
63
64 /// Add ObjC Class record.
65 ///
66 /// \param Name The name of class, not symbol.
67 /// \param Linkage The linkage of symbol.
68 /// \param SymType The symbols this class represents.
69 /// \return The non-owning pointer to added record in slice.
71 ObjCIFSymbolKind SymType);
72
73 /// Add ObjC IVar record.
74 ///
75 /// \param Container Owning pointer for instance variable.
76 /// \param Name The name of ivar, not symbol.
77 /// \param Linkage The linkage of symbol.
78 /// \return The non-owning pointer to added record in slice.
80 RecordLinkage Linkage);
81
82 /// Add ObjC Category record.
83 ///
84 /// \param ClassToExtend The name of class that is being extended by the
85 /// category, not symbol.
86 /// \param Category The name of category.
87 /// \return The non-owning pointer to added record in slice.
89 StringRef Category);
90
91 /// Find ObjC Class.
92 ///
93 /// \param Name name of class, not full symbol name.
94 /// \return The non-owning pointer to record in slice.
96
97 /// Find ObjC Category.
98 ///
99 /// \param ClassToExtend The name of class, not full symbol name.
100 /// \param Category The name of category.
101 /// \return The non-owning pointer to record in slice.
103 StringRef Category) const;
104
105 /// Find ObjC Container. This is commonly used for assigning for looking up
106 /// instance variables that are assigned to either a category or class.
107 ///
108 /// \param IsIVar If true, the name is the name of the IVar, otherwise it will
109 /// be looked up as the name of the container.
110 /// \param Name Either the name of ivar or name of container.
111 /// \return The non-owning pointer to record in
112 /// slice.
113 ObjCContainerRecord *findContainer(bool IsIVar, StringRef Name) const;
114
115 /// Find ObjC instance variable.
116 ///
117 /// \param IsScopedName This is used to determine how to parse the name.
118 /// \param Name Either the full name of the symbol or just the ivar.
119 /// \return The non-owning pointer to record in slice.
120 ObjCIVarRecord *findObjCIVar(bool IsScopedName, StringRef Name) const;
121
122 /// Find non-objc global.
123 ///
124 /// \param Name The name of symbol.
125 /// \param GV The Kind of global to find.
126 /// \return The non-owning pointer to record in slice.
130
131 // Determine if library attributes were assigned.
132 bool hasBinaryAttrs() const { return BA.get(); }
133
134 // Determine if record slice is unassigned.
135 bool empty() const {
136 return !hasBinaryAttrs() && Globals.empty() && Classes.empty() &&
137 Categories.empty();
138 }
139
140 // Visit all records known to RecordsSlice.
141 void visit(RecordVisitor &V) const;
142
143 struct BinaryAttrs {
144 std::vector<StringRef> AllowableClients;
145 std::vector<StringRef> RexportedLibraries;
146 std::vector<StringRef> RPaths;
154 uint8_t SwiftABI = 0;
155 bool TwoLevelNamespace = false;
156 bool AppExtensionSafe = false;
158 };
159
160 /// Return reference to BinaryAttrs.
162
163 /// Store any strings owned by RecordSlice into allocator and return back
164 /// reference to that.
166
167private:
168 const llvm::Triple TargetTriple;
169 // Hold tapi converted triple to avoid unecessary casts.
170 const Target TAPITarget;
171
172 /// BumpPtrAllocator to store generated/copied strings.
173 llvm::BumpPtrAllocator StringAllocator;
174
175 /// Promote linkage of requested record. It is no-op if linkage type is lower
176 /// than the current assignment.
177 ///
178 /// \param R The record to update.
179 /// \param L Linkage type to update to.
180 void updateLinkage(Record *R, RecordLinkage L) {
181 R->Linkage = std::max(R->Linkage, L);
182 }
183
184 /// Update set flags of requested record.
185 ///
186 /// \param R The record to update.
187 /// \param F Flags to update to.
188 void updateFlags(Record *R, SymbolFlags F) { R->Flags |= F; }
189
190 RecordMap<GlobalRecord> Globals;
191 RecordMap<ObjCInterfaceRecord> Classes;
192 RecordMap<ObjCCategoryRecord, std::pair<StringRef, StringRef>> Categories;
193
194 std::unique_ptr<BinaryAttrs> BA{nullptr};
195};
196
198class InterfaceFile;
199std::unique_ptr<InterfaceFile> convertToInterfaceFile(const Records &Slices);
200
201} // namespace MachO
202} // namespace llvm
203#endif // LLVM_TEXTAPI_RECORDSLICE_H
This file defines the BumpPtrAllocator interface.
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:66
Defines the interface file.
Base class for any usage of traversing over collected Records.
Definition: RecordVisitor.h:23
Define Record.
Definition: Record.h:67
StringRef copyString(StringRef String)
Store any strings owned by RecordSlice into allocator and return back reference to that.
ObjCIVarRecord * findObjCIVar(bool IsScopedName, StringRef Name) const
Find ObjC instance variable.
ObjCCategoryRecord * addObjCCategory(StringRef ClassToExtend, StringRef Category)
Add ObjC Category record.
ObjCInterfaceRecord * addObjCInterface(StringRef Name, RecordLinkage Linkage, ObjCIFSymbolKind SymType)
Add ObjC Class record.
RecordsSlice(const llvm::Triple &T)
Definition: RecordsSlice.h:30
ObjCContainerRecord * findContainer(bool IsIVar, StringRef Name) const
Find ObjC Container.
ObjCIVarRecord * addObjCIVar(ObjCContainerRecord *Container, StringRef Name, RecordLinkage Linkage)
Add ObjC IVar record.
GlobalRecord * addGlobal(StringRef Name, RecordLinkage Linkage, GlobalRecord::Kind GV, SymbolFlags Flags=SymbolFlags::None, bool Inlined=false)
Add non-ObjC global record.
GlobalRecord * findGlobal(StringRef Name, GlobalRecord::Kind GV=GlobalRecord::Kind::Unknown) const
Find non-objc global.
ObjCCategoryRecord * findObjCCategory(StringRef ClassToExtend, StringRef Category) const
Find ObjC Category.
BinaryAttrs & getBinaryAttrs()
Return reference to BinaryAttrs.
const Target & getTarget() const
Get TAPI converted target.
Definition: RecordsSlice.h:34
const llvm::Triple & getTriple() const
Get target triple.
Definition: RecordsSlice.h:32
ObjCInterfaceRecord * findObjCInterface(StringRef Name) const
Find ObjC Class.
Record * addRecord(StringRef Name, SymbolFlags Flags, GlobalRecord::Kind GV=GlobalRecord::Kind::Unknown, RecordLinkage Linkage=RecordLinkage::Unknown)
Add unspecified record to slice.
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:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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:48
std::unique_ptr< InterfaceFile > convertToInterfaceFile(const Records &Slices)
ObjCIFSymbolKind
ObjC Interface symbol mappings.
Definition: Symbol.h:69
SymbolFlags
Symbol flags.
Definition: Symbol.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::vector< StringRef > RPaths
Definition: RecordsSlice.h:146
std::vector< StringRef > RexportedLibraries
Definition: RecordsSlice.h:145
std::vector< StringRef > AllowableClients
Definition: RecordsSlice.h:144
llvm::MachO::PackedVersion CompatVersion
Definition: RecordsSlice.h:153
llvm::MachO::PackedVersion CurrentVersion
Definition: RecordsSlice.h:152