1 //===- SymbolDeserializer.h -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_CODEVIEW_SYMBOLDESERIALIZER_H
11 #define LLVM_DEBUGINFO_CODEVIEW_SYMBOLDESERIALIZER_H
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"
24 class SymbolVisitorDelegate;
25 class SymbolDeserializer : public SymbolVisitorCallbacks {
27 explicit MappingInfo(ArrayRef<uint8_t> RecordData)
28 : Stream(RecordData, llvm::support::little), Reader(Stream),
31 BinaryByteStream Stream;
32 BinaryStreamReader Reader;
33 SymbolRecordMapping Mapping;
37 template <typename T> static Error deserializeAs(CVSymbol Symbol, T &Record) {
38 SymbolDeserializer S(nullptr);
39 if (auto EC = S.visitSymbolBegin(Symbol))
41 if (auto EC = S.visitKnownRecord(Symbol, Record))
43 if (auto EC = S.visitSymbolEnd(Symbol))
45 return Error::success();
48 explicit SymbolDeserializer(SymbolVisitorDelegate *Delegate)
49 : Delegate(Delegate) {}
51 Error visitSymbolBegin(CVSymbol &Record) override {
52 assert(!Mapping && "Already in a symbol mapping!");
53 Mapping = llvm::make_unique<MappingInfo>(Record.content());
54 return Mapping->Mapping.visitSymbolBegin(Record);
56 Error visitSymbolEnd(CVSymbol &Record) override {
57 assert(Mapping && "Not in a symbol mapping!");
58 auto EC = Mapping->Mapping.visitSymbolEnd(Record);
63 #define SYMBOL_RECORD(EnumName, EnumVal, Name) \
64 Error visitKnownRecord(CVSymbol &CVR, Name &Record) override { \
65 return visitKnownRecordImpl(CVR, Record); \
67 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
68 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
71 template <typename T> Error visitKnownRecordImpl(CVSymbol &CVR, T &Record) {
74 Delegate ? Delegate->getRecordOffset(Mapping->Reader) : 0;
75 if (auto EC = Mapping->Mapping.visitKnownRecord(CVR, Record))
77 return Error::success();
80 SymbolVisitorDelegate *Delegate;
81 std::unique_ptr<MappingInfo> Mapping;