]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h
MFV r314910: 7843 get_clones_stat() is suboptimal for lots of clones
[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/DebugInfo/MSF/ByteStream.h"
19 #include "llvm/DebugInfo/MSF/StreamReader.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), Reader(Stream), Mapping(Reader) {}
29
30     msf::ByteStream Stream;
31     msf::StreamReader Reader;
32     SymbolRecordMapping Mapping;
33   };
34
35 public:
36   explicit SymbolDeserializer(SymbolVisitorDelegate *Delegate)
37       : Delegate(Delegate) {}
38
39   Error visitSymbolBegin(CVSymbol &Record) override {
40     assert(!Mapping && "Already in a symbol mapping!");
41     Mapping = llvm::make_unique<MappingInfo>(Record.content());
42     return Mapping->Mapping.visitSymbolBegin(Record);
43   }
44   Error visitSymbolEnd(CVSymbol &Record) override {
45     assert(Mapping && "Not in a symbol mapping!");
46     auto EC = Mapping->Mapping.visitSymbolEnd(Record);
47     Mapping.reset();
48     return EC;
49   }
50
51 #define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
52   Error visitKnownRecord(CVSymbol &CVR, Name &Record) override {               \
53     return visitKnownRecordImpl(CVR, Record);                                  \
54   }
55 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
56 #include "CVSymbolTypes.def"
57
58 private:
59   template <typename T> Error visitKnownRecordImpl(CVSymbol &CVR, T &Record) {
60
61     Record.RecordOffset =
62         Delegate ? Delegate->getRecordOffset(Mapping->Reader) : 0;
63     if (auto EC = Mapping->Mapping.visitKnownRecord(CVR, Record))
64       return EC;
65     return Error::success();
66   }
67
68   SymbolVisitorDelegate *Delegate;
69   std::unique_ptr<MappingInfo> Mapping;
70 };
71 }
72 }
73
74 #endif