LLVM  14.0.0git
NativeTypeFunctionSig.cpp
Go to the documentation of this file.
1 //===- NativeTypeFunctionSig.cpp - info about function signature -*- 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 
10 
16 
17 using namespace llvm;
18 using namespace llvm::codeview;
19 using namespace llvm::pdb;
20 
21 namespace {
22 // This is kind of a silly class, hence why we keep it private to the file.
23 // It's only purpose is to wrap the real type record. I guess this is so that
24 // we can have the lexical parent point to the function instead of the global
25 // scope.
26 class NativeTypeFunctionArg : public NativeRawSymbol {
27 public:
28  NativeTypeFunctionArg(NativeSession &Session,
29  std::unique_ptr<PDBSymbol> RealType)
30  : NativeRawSymbol(Session, PDB_SymType::FunctionArg, 0),
31  RealType(std::move(RealType)) {}
32 
33  void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields,
34  PdbSymbolIdField RecurseIdFields) const override {
35  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
36 
37  dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
38  PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
39  }
40 
41  SymIndexId getTypeId() const override { return RealType->getSymIndexId(); }
42 
43  std::unique_ptr<PDBSymbol> RealType;
44 };
45 
46 class NativeEnumFunctionArgs : public IPDBEnumChildren<PDBSymbol> {
47 public:
48  NativeEnumFunctionArgs(NativeSession &Session,
49  std::unique_ptr<NativeEnumTypes> TypeEnumerator)
50  : Session(Session), TypeEnumerator(std::move(TypeEnumerator)) {}
51 
52  uint32_t getChildCount() const override {
53  return TypeEnumerator->getChildCount();
54  }
55  std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override {
56  return wrap(TypeEnumerator->getChildAtIndex(Index));
57  }
58  std::unique_ptr<PDBSymbol> getNext() override {
59  return wrap(TypeEnumerator->getNext());
60  }
61 
62  void reset() override { TypeEnumerator->reset(); }
63 
64 private:
65  std::unique_ptr<PDBSymbol> wrap(std::unique_ptr<PDBSymbol> S) const {
66  if (!S)
67  return nullptr;
68  auto NTFA = std::make_unique<NativeTypeFunctionArg>(Session, std::move(S));
69  return PDBSymbol::create(Session, std::move(NTFA));
70  }
71  NativeSession &Session;
72  std::unique_ptr<NativeEnumTypes> TypeEnumerator;
73 };
74 } // namespace
75 
76 NativeTypeFunctionSig::NativeTypeFunctionSig(NativeSession &Session,
77  SymIndexId Id,
81  Proc(std::move(Proc)), Index(Index), IsMemberFunction(false) {}
82 
87  MemberFunc(std::move(MemberFunc)), Index(Index), IsMemberFunction(true) {}
88 
90  if (IsMemberFunction) {
91  ClassParentId =
93  initializeArgList(MemberFunc.ArgumentList);
94  } else {
95  initializeArgList(Proc.ArgumentList);
96  }
97 }
98 
100 
101 void NativeTypeFunctionSig::initializeArgList(codeview::TypeIndex ArgListTI) {
103  CVType CVT = Tpi.typeCollection().getType(ArgListTI);
104 
105  cantFail(TypeDeserializer::deserializeAs<ArgListRecord>(CVT, ArgList));
106 }
107 
109  PdbSymbolIdField ShowIdFields,
110  PdbSymbolIdField RecurseIdFields) const {
111 
112  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
113 
114  dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
115  PdbSymbolIdField::LexicalParent, ShowIdFields,
116  RecurseIdFields);
117 
118  dumpSymbolField(OS, "callingConvention", getCallingConvention(), Indent);
119  dumpSymbolField(OS, "count", getCount(), Indent);
120  dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
121  PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
122  if (IsMemberFunction)
123  dumpSymbolField(OS, "thisAdjust", getThisAdjust(), Indent);
124  dumpSymbolField(OS, "constructor", hasConstructor(), Indent);
125  dumpSymbolField(OS, "constType", isConstType(), Indent);
126  dumpSymbolField(OS, "isConstructorVirtualBase", isConstructorVirtualBase(),
127  Indent);
128  dumpSymbolField(OS, "isCxxReturnUdt", isCxxReturnUdt(), Indent);
129  dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
130  dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
131 }
132 
133 std::unique_ptr<IPDBEnumSymbols>
136  return std::make_unique<NullEnumerator<PDBSymbol>>();
137 
138  auto NET = std::make_unique<NativeEnumTypes>(Session,
139  /* copy */ ArgList.ArgIndices);
140  return std::unique_ptr<IPDBEnumSymbols>(
141  new NativeEnumFunctionArgs(Session, std::move(NET)));
142 }
143 
145  if (!IsMemberFunction)
146  return 0;
147 
148  return ClassParentId;
149 }
150 
152  return IsMemberFunction ? MemberFunc.CallConv : Proc.CallConv;
153 }
154 
156  return IsMemberFunction ? (1 + MemberFunc.getParameterCount())
158 }
159 
161  TypeIndex ReturnTI =
162  IsMemberFunction ? MemberFunc.getReturnType() : Proc.getReturnType();
163 
165  return Result;
166 }
167 
169  return IsMemberFunction ? MemberFunc.getThisPointerAdjustment() : 0;
170 }
171 
173  if (!IsMemberFunction)
174  return false;
175 
176  return (MemberFunc.getOptions() & FunctionOptions::Constructor) !=
178 }
179 
180 bool NativeTypeFunctionSig::isConstType() const { return false; }
181 
183  if (!IsMemberFunction)
184  return false;
185 
186  return (MemberFunc.getOptions() &
187  FunctionOptions::ConstructorWithVirtualBases) !=
189 }
190 
193  IsMemberFunction ? MemberFunc.getOptions() : Proc.getOptions();
194  return (Options & FunctionOptions::CxxReturnUdt) != FunctionOptions::None;
195 }
196 
197 bool NativeTypeFunctionSig::isUnalignedType() const { return false; }
198 
199 bool NativeTypeFunctionSig::isVolatileType() const { return false; }
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::codeview::MemberFunctionRecord::CallConv
CallingConvention CallConv
Definition: TypeRecord.h:197
llvm::pdb::PDB_SymType::FunctionSig
@ FunctionSig
TpiStream.h
llvm::pdb::NativeTypeFunctionSig::NativeTypeFunctionSig
NativeTypeFunctionSig(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, codeview::ProcedureRecord Proc)
Definition: NativeTypeFunctionSig.cpp:76
llvm::codeview::FunctionOptions
FunctionOptions
Definition: CodeView.h:247
llvm::pdb::NativeTypeFunctionSig::isConstructorVirtualBase
bool isConstructorVirtualBase() const override
Definition: NativeTypeFunctionSig.cpp:182
llvm::pdb::NativeSession::getPDBFile
PDBFile & getPDBFile()
Definition: NativeSession.h:105
llvm::pdb::PdbSymbolIdField::Type
@ Type
llvm::pdb::NativeTypeFunctionSig::initialize
void initialize() override
Definition: NativeTypeFunctionSig.cpp:89
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::codeview::ProcedureRecord::getOptions
FunctionOptions getOptions() const
Definition: TypeRecord.h:158
llvm::pdb::NativeTypeFunctionSig::MemberFunc
codeview::MemberFunctionRecord MemberFunc
Definition: NativeTypeFunctionSig.h:60
llvm::dump
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Definition: SparseBitVector.h:876
llvm::pdb::NativeTypeFunctionSig::getCallingConvention
PDB_CallingConv getCallingConvention() const override
Definition: NativeTypeFunctionSig.cpp:151
llvm::pdb::PDB_SymType
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
llvm::codeview::ProcedureRecord::getReturnType
TypeIndex getReturnType() const
Definition: TypeRecord.h:156
llvm::pdb::NativeTypeFunctionSig::isUnalignedType
bool isUnalignedType() const override
Definition: NativeTypeFunctionSig.cpp:197
llvm::codeview::MemberFunctionRecord::getReturnType
TypeIndex getReturnType() const
Definition: TypeRecord.h:185
llvm::pdb::SymIndexId
uint32_t SymIndexId
Definition: PDBTypes.h:26
LazyRandomTypeCollection.h
llvm::pdb::NativeTypeFunctionSig::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeTypeFunctionSig.cpp:108
llvm::pdb::NativeTypeFunctionSig::getThisAdjust
int32_t getThisAdjust() const override
Definition: NativeTypeFunctionSig.cpp:168
llvm::pdb::PDB_SymType::FunctionArg
@ FunctionArg
llvm::pdb::PdbSymbolIdField::LexicalParent
@ LexicalParent
NativeTypeFunctionSig.h
llvm::codeview::MemberFunctionRecord::ClassType
TypeIndex ClassType
Definition: TypeRecord.h:195
false
Definition: StackSlotColoring.cpp:142
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::codeview::MemberFunctionRecord
Definition: TypeRecord.h:170
llvm::None
const NoneType None
Definition: None.h:23
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::NativeTypeFunctionSig::Proc
codeview::ProcedureRecord Proc
Definition: NativeTypeFunctionSig.h:61
llvm::pdb::NativeTypeFunctionSig::findChildren
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const override
Definition: NativeTypeFunctionSig.cpp:134
llvm::codeview::ProcedureRecord::ArgumentList
TypeIndex ArgumentList
Definition: TypeRecord.h:166
llvm::pdb::NativeTypeFunctionSig::hasConstructor
bool hasConstructor() const override
Definition: NativeTypeFunctionSig.cpp:172
llvm::codeview::MemberFunctionRecord::getThisPointerAdjustment
int32_t getThisPointerAdjustment() const
Definition: TypeRecord.h:192
llvm::pdb::NativeTypeFunctionSig::~NativeTypeFunctionSig
~NativeTypeFunctionSig() override
Definition: NativeTypeFunctionSig.cpp:99
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::pdb::dumpSymbolField
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:47
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::pdb::dumpSymbolIdField
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:202
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:109
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1609
llvm::codeview::ProcedureRecord::getParameterCount
uint16_t getParameterCount() const
Definition: TypeRecord.h:159
NativeEnumTypes.h
llvm::pdb::NativeTypeFunctionSig::isConstType
bool isConstType() const override
Definition: NativeTypeFunctionSig.cpp:180
llvm::codeview::ArgListRecord::ArgIndices
std::vector< TypeIndex > ArgIndices
Definition: TypeRecord.h:245
llvm::wrap
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:251
llvm::codeview::CVRecord< TypeLeafKind >
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:737
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::pdb::NativeTypeFunctionSig::isCxxReturnUdt
bool isCxxReturnUdt() const override
Definition: NativeTypeFunctionSig.cpp:191
llvm::codeview::ProcedureRecord
Definition: TypeRecord.h:145
llvm::pdb::PDBFile::getPDBTpiStream
Expected< TpiStream & > getPDBTpiStream()
Definition: PDBFile.cpp:302
llvm::pdb::NativeTypeFunctionSig::getCount
uint32_t getCount() const override
Definition: NativeTypeFunctionSig.cpp:155
llvm::pdb::SymbolCache::findSymbolByTypeIndex
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
Definition: SymbolCache.cpp:153
std
Definition: BitVector.h:838
llvm::codeview::MemberFunctionRecord::getParameterCount
uint16_t getParameterCount() const
Definition: TypeRecord.h:190
llvm::codeview::ProcedureRecord::CallConv
CallingConvention CallConv
Definition: TypeRecord.h:163
llvm::pdb::NativeTypeFunctionSig::getClassParentId
SymIndexId getClassParentId() const override
Definition: NativeTypeFunctionSig.cpp:144
llvm::pdb::NativeRawSymbol::dump
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Definition: NativeRawSymbol.cpp:22
llvm::pdb::NativeSession
Definition: NativeSession.h:28
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::PdbSymbolIdField
PdbSymbolIdField
Definition: IPDBRawSymbol.h:24
PDBFile.h
PDBExtras.h
llvm::pdb::TpiStream
Definition: TpiStream.h:33
llvm::codeview::CallingConvention
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition: CodeView.h:176
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:95
llvm::msgpack::Type
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
llvm::pdb::NativeTypeFunctionSig::isVolatileType
bool isVolatileType() const override
Definition: NativeTypeFunctionSig.cpp:199
llvm::pdb::NativeRawSymbol::Session
NativeSession & Session
Definition: NativeRawSymbol.h:232
llvm::pdb::IPDBEnumChildren
Definition: IPDBEnumChildren.h:19
llvm::codeview::LazyRandomTypeCollection::getType
CVType getType(TypeIndex Index) override
Definition: LazyRandomTypeCollection.cpp:90
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:228
llvm::codeview::MemberFunctionRecord::ArgumentList
TypeIndex ArgumentList
Definition: TypeRecord.h:200
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::pdb::TpiStream::typeCollection
codeview::LazyRandomTypeCollection & typeCollection()
Definition: TpiStream.h:58
llvm::pdb::NativeTypeFunctionSig::getTypeId
SymIndexId getTypeId() const override
Definition: NativeTypeFunctionSig.cpp:160
llvm::pdb::NativeRawSymbol
Definition: NativeRawSymbol.h:21
llvm::codeview::MemberFunctionRecord::getOptions
FunctionOptions getOptions() const
Definition: TypeRecord.h:189