LLVM  9.0.0svn
SymbolRecordHelpers.cpp
Go to the documentation of this file.
1 //===- SymbolRecordHelpers.cpp ----------------------------------*- 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 
11 #include "llvm/ADT/SmallVector.h"
13 
14 using namespace llvm;
15 using namespace llvm::codeview;
16 
17 template <typename RecordT> RecordT createRecord(const CVSymbol &sym) {
18  RecordT record(static_cast<SymbolRecordKind>(sym.kind()));
19  cantFail(SymbolDeserializer::deserializeAs<RecordT>(sym, record));
20  return record;
21 }
22 
25  switch (Sym.kind()) {
26  case SymbolKind::S_GPROC32:
27  case SymbolKind::S_LPROC32:
28  case SymbolKind::S_GPROC32_ID:
29  case SymbolKind::S_LPROC32_ID:
30  case SymbolKind::S_LPROC32_DPC:
31  case SymbolKind::S_LPROC32_DPC_ID: {
32  ProcSym Proc = createRecord<ProcSym>(Sym);
33  return Proc.End;
34  }
35  case SymbolKind::S_BLOCK32: {
36  BlockSym Block = createRecord<BlockSym>(Sym);
37  return Block.End;
38  }
39  case SymbolKind::S_THUNK32: {
40  Thunk32Sym Thunk = createRecord<Thunk32Sym>(Sym);
41  return Thunk.End;
42  }
43  case SymbolKind::S_INLINESITE: {
44  InlineSiteSym Site = createRecord<InlineSiteSym>(Sym);
45  return Site.End;
46  }
47  default:
48  assert(false && "Unknown record type");
49  return 0;
50  }
51 }
52 
56  switch (Sym.kind()) {
57  case SymbolKind::S_GPROC32:
58  case SymbolKind::S_LPROC32:
59  case SymbolKind::S_GPROC32_ID:
60  case SymbolKind::S_LPROC32_ID:
61  case SymbolKind::S_LPROC32_DPC:
62  case SymbolKind::S_LPROC32_DPC_ID: {
63  ProcSym Proc = createRecord<ProcSym>(Sym);
64  return Proc.Parent;
65  }
66  case SymbolKind::S_BLOCK32: {
67  BlockSym Block = createRecord<BlockSym>(Sym);
68  return Block.Parent;
69  }
70  case SymbolKind::S_THUNK32: {
71  Thunk32Sym Thunk = createRecord<Thunk32Sym>(Sym);
72  return Thunk.Parent;
73  }
74  case SymbolKind::S_INLINESITE: {
75  InlineSiteSym Site = createRecord<InlineSiteSym>(Sym);
76  return Site.Parent;
77  }
78  default:
79  assert(false && "Unknown record type");
80  return 0;
81  }
82 }
83 
86  uint32_t ScopeBegin) {
87  CVSymbol Opener = *Symbols.at(ScopeBegin);
88  assert(symbolOpensScope(Opener.kind()));
89  uint32_t EndOffset = getScopeEndOffset(Opener);
90  CVSymbol Closer = *Symbols.at(EndOffset);
91  EndOffset += Closer.RecordData.size();
92  return Symbols.substream(ScopeBegin, EndOffset);
93 }
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:703
Kind kind() const
Definition: CVRecord.h:36
This class represents lattice values for constants.
Definition: AllocatorList.h:23
uint32_t getScopeEndOffset(const CVSymbol &Symbol)
Given a symbol P for which symbolOpensScope(P) == true, return the corresponding end offset...
VarStreamArray< ValueType, Extractor > substream(uint32_t Begin, uint32_t End) const
bool symbolOpensScope(SymbolKind Kind)
Return true if this symbol opens a scope.
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
uint32_t getScopeParentOffset(const CVSymbol &Symbol)
RecordT createRecord(const CVSymbol &sym)
CVSymbolArray limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin)
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:48
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Iterator at(uint32_t Offset) const
given an offset into the array&#39;s underlying stream, return an iterator to the record at that offset...