]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303571, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / DebugInfo / CodeView / SymbolDeserializer.h
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"
14 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
15 #include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h"
16 #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
17 #include "llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h"
18 #include "llvm/Support/BinaryByteStream.h"
19 #include "llvm/Support/BinaryStreamReader.h"
20 #include "llvm/Support/Error.h"
21
22 namespace llvm {
23 namespace codeview {
24 class SymbolVisitorDelegate;
25 class SymbolDeserializer : public SymbolVisitorCallbacks {
26   struct MappingInfo {
27     explicit MappingInfo(ArrayRef<uint8_t> RecordData)
28         : Stream(RecordData, llvm::support::little), Reader(Stream),
29           Mapping(Reader) {}
30
31     BinaryByteStream Stream;
32     BinaryStreamReader Reader;
33     SymbolRecordMapping Mapping;
34   };
35
36 public:
37   explicit SymbolDeserializer(SymbolVisitorDelegate *Delegate)
38       : Delegate(Delegate) {}
39
40   Error visitSymbolBegin(CVSymbol &Record) override {
41     assert(!Mapping && "Already in a symbol mapping!");
42     Mapping = llvm::make_unique<MappingInfo>(Record.content());
43     return Mapping->Mapping.visitSymbolBegin(Record);
44   }
45   Error visitSymbolEnd(CVSymbol &Record) override {
46     assert(Mapping && "Not in a symbol mapping!");
47     auto EC = Mapping->Mapping.visitSymbolEnd(Record);
48     Mapping.reset();
49     return EC;
50   }
51
52 #define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
53   Error visitKnownRecord(CVSymbol &CVR, Name &Record) override {               \
54     return visitKnownRecordImpl(CVR, Record);                                  \
55   }
56 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
57 #include "CVSymbolTypes.def"
58
59 private:
60   template <typename T> Error visitKnownRecordImpl(CVSymbol &CVR, T &Record) {
61
62     Record.RecordOffset =
63         Delegate ? Delegate->getRecordOffset(Mapping->Reader) : 0;
64     if (auto EC = Mapping->Mapping.visitKnownRecord(CVR, Record))
65       return EC;
66     return Error::success();
67   }
68
69   SymbolVisitorDelegate *Delegate;
70   std::unique_ptr<MappingInfo> Mapping;
71 };
72 }
73 }
74
75 #endif