LLVM  5.0.0
SymbolDeserializer.h
Go to the documentation of this file.
1 //===- SymbolDeserializer.h -------------------------------------*- 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 
10 #ifndef LLVM_DEBUGINFO_CODEVIEW_SYMBOLDESERIALIZER_H
11 #define LLVM_DEBUGINFO_CODEVIEW_SYMBOLDESERIALIZER_H
12 
13 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/Support/Error.h"
21 
22 namespace llvm {
23 namespace codeview {
24 class SymbolVisitorDelegate;
26  struct MappingInfo {
27  MappingInfo(ArrayRef<uint8_t> RecordData, CodeViewContainer Container)
28  : Stream(RecordData, llvm::support::little), Reader(Stream),
29  Mapping(Reader, Container) {}
30 
31  BinaryByteStream Stream;
32  BinaryStreamReader Reader;
33  SymbolRecordMapping Mapping;
34  };
35 
36 public:
37  template <typename T> static Error deserializeAs(CVSymbol Symbol, T &Record) {
38  // If we're just deserializing one record, then don't worry about alignment
39  // as there's nothing that comes after.
41  if (auto EC = S.visitSymbolBegin(Symbol))
42  return EC;
43  if (auto EC = S.visitKnownRecord(Symbol, Record))
44  return EC;
45  if (auto EC = S.visitSymbolEnd(Symbol))
46  return EC;
47  return Error::success();
48  }
49 
51  CodeViewContainer Container)
52  : Delegate(Delegate), Container(Container) {}
53 
55  return visitSymbolBegin(Record);
56  }
57 
59  assert(!Mapping && "Already in a symbol mapping!");
60  Mapping = llvm::make_unique<MappingInfo>(Record.content(), Container);
61  return Mapping->Mapping.visitSymbolBegin(Record);
62  }
64  assert(Mapping && "Not in a symbol mapping!");
65  auto EC = Mapping->Mapping.visitSymbolEnd(Record);
66  Mapping.reset();
67  return EC;
68  }
69 
70 #define SYMBOL_RECORD(EnumName, EnumVal, Name) \
71  Error visitKnownRecord(CVSymbol &CVR, Name &Record) override { \
72  return visitKnownRecordImpl(CVR, Record); \
73  }
74 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
75 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
76 
77 private:
78  template <typename T> Error visitKnownRecordImpl(CVSymbol &CVR, T &Record) {
79 
80  Record.RecordOffset =
81  Delegate ? Delegate->getRecordOffset(Mapping->Reader) : 0;
82  if (auto EC = Mapping->Mapping.visitKnownRecord(CVR, Record))
83  return EC;
84  return Error::success();
85  }
86 
87  SymbolVisitorDelegate *Delegate;
88  CodeViewContainer Container;
89  std::unique_ptr<MappingInfo> Mapping;
90 };
91 }
92 }
93 
94 #endif
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
virtual uint32_t getRecordOffset(BinaryStreamReader Reader)=0
CVRecord< SymbolKind > CVSymbol
Definition: SymbolRecord.h:945
SymbolDeserializer(SymbolVisitorDelegate *Delegate, CodeViewContainer Container)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
ArrayRef< uint8_t > content() const
Definition: CVRecord.h:44
Error visitSymbolEnd(CVSymbol &Record) override
Error visitSymbolBegin(CVSymbol &Record, uint32_t Offset) override
Paired begin/end actions for all symbols.
Error visitSymbolBegin(CVSymbol &Record) override
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Provides read only access to a subclass of BinaryStream.
static Error deserializeAs(CVSymbol Symbol, T &Record)