LLVM  8.0.1
NativeEnumGlobals.cpp
Go to the documentation of this file.
1 //==- NativeEnumGlobals.cpp - Native Global Enumerator impl ------*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
19 
20 using namespace llvm;
21 using namespace llvm::codeview;
22 using namespace llvm::pdb;
23 
24 NativeEnumGlobals::NativeEnumGlobals(NativeSession &PDBSession,
25  std::vector<codeview::SymbolKind> Kinds)
26  : Index(0), Session(PDBSession) {
29  for (uint32_t Off : GS.getGlobalsTable()) {
30  CVSymbol S = SS.readRecord(Off);
31  if (!llvm::is_contained(Kinds, S.kind()))
32  continue;
33  MatchOffsets.push_back(Off);
34  }
35 }
36 
38  return static_cast<uint32_t>(MatchOffsets.size());
39 }
40 
41 std::unique_ptr<PDBSymbol>
43  if (N >= MatchOffsets.size())
44  return nullptr;
45 
46  SymIndexId Id =
47  Session.getSymbolCache().getOrCreateGlobalSymbolByOffset(MatchOffsets[N]);
48  return Session.getSymbolCache().getSymbolById(Id);
49 }
50 
51 std::unique_ptr<PDBSymbol> NativeEnumGlobals::getNext() {
52  return getChildAtIndex(Index++);
53 }
54 
55 void NativeEnumGlobals::reset() { Index = 0; }
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:704
Kind kind() const
Definition: CVRecord.h:37
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Expected< GlobalsStream & > getPDBGlobalsStream()
Definition: PDBFile.cpp:256
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
uint32_t getChildCount() const override
std::unique_ptr< PDBSymbol > getChildAtIndex(uint32_t Index) const override
Expected< SymbolStream & > getPDBSymbolStream()
Definition: PDBFile.cpp:347
std::unique_ptr< PDBSymbol > getNext() override
SymIndexId getOrCreateGlobalSymbolByOffset(uint32_t Offset)
#define N
const GSIHashTable & getGlobalsTable() const
Definition: GlobalsStream.h:75
SymbolCache & getSymbolCache()
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1245