LLVM  9.0.0svn
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 = llvm::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,
78  codeview::TypeIndex Index,
80  : NativeRawSymbol(Session, PDB_SymType::FunctionSig, Id),
81  Proc(std::move(Proc)), Index(Index), IsMemberFunction(false) {}
82 
86  : NativeRawSymbol(Session, PDB_SymType::FunctionSig, Id),
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>
135  if (Type != PDB_SymType::FunctionArg)
136  return llvm::make_unique<NullEnumerator<PDBSymbol>>();
137 
138  auto NET = llvm::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 
192  FunctionOptions Options =
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; }
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:703
int32_t getThisPointerAdjustment() const
Definition: TypeRecord.h:198
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
PDB_CallingConv getCallingConvention() const override
This class represents lattice values for constants.
Definition: AllocatorList.h:23
NativeTypeFunctionSig(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, codeview::ProcedureRecord Proc)
codeview::MemberFunctionRecord MemberFunc
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
codeview::LazyRandomTypeCollection & typeCollection()
Definition: TpiStream.h:58
static void dump(StringRef Title, SpillInfo const &Spills)
Definition: CoroFrame.cpp:298
block Block Frequency true
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
Expected< TpiStream & > getPDBTpiStream()
Definition: PDBFile.cpp:299
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const override
Definition: BitVector.h:937
A 32-bit type reference.
Definition: TypeIndex.h:95
TypeIndex getReturnType() const
Definition: TypeRecord.h:162
SymIndexId getTypeId() const override
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
Definition: PDBTypes.h:182
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
FunctionOptions getOptions() const
Definition: TypeRecord.h:195
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
std::vector< TypeIndex > ArgIndices
Definition: TypeRecord.h:251
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:48
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:185
SymIndexId getClassParentId() const override
CallingConvention CallConv
Definition: TypeRecord.h:169
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI)
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:189
SymbolCache & getSymbolCache()
FunctionOptions getOptions() const
Definition: TypeRecord.h:164
uint16_t getParameterCount() const
Definition: TypeRecord.h:165
Definition: JSON.cpp:597
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition: CodeView.h:173
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
bool isConstructorVirtualBase() const override