1 //===- CVSymbolVisitor.cpp --------------------------------------*- 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 #include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
12 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
13 #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
16 using namespace llvm::codeview
;
18 CVSymbolVisitor::CVSymbolVisitor(SymbolVisitorCallbacks
&Callbacks
)
19 : Callbacks(Callbacks
) {}
22 static Error
visitKnownRecord(CVSymbol
&Record
,
23 SymbolVisitorCallbacks
&Callbacks
) {
24 SymbolRecordKind RK
= static_cast<SymbolRecordKind
>(Record
.Type
);
26 if (auto EC
= Callbacks
.visitKnownRecord(Record
, KnownRecord
))
28 return Error::success();
31 static Error
finishVisitation(CVSymbol
&Record
,
32 SymbolVisitorCallbacks
&Callbacks
) {
33 switch (Record
.Type
) {
35 if (auto EC
= Callbacks
.visitUnknownSymbol(Record
))
38 #define SYMBOL_RECORD(EnumName, EnumVal, Name) \
40 if (auto EC = visitKnownRecord<Name>(Record, Callbacks)) \
44 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) \
45 SYMBOL_RECORD(EnumVal, EnumVal, AliasName)
46 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
49 if (auto EC
= Callbacks
.visitSymbolEnd(Record
))
52 return Error::success();
55 Error
CVSymbolVisitor::visitSymbolRecord(CVSymbol
&Record
) {
56 if (auto EC
= Callbacks
.visitSymbolBegin(Record
))
58 return finishVisitation(Record
, Callbacks
);
61 Error
CVSymbolVisitor::visitSymbolRecord(CVSymbol
&Record
, uint32_t Offset
) {
62 if (auto EC
= Callbacks
.visitSymbolBegin(Record
, Offset
))
64 return finishVisitation(Record
, Callbacks
);
67 Error
CVSymbolVisitor::visitSymbolStream(const CVSymbolArray
&Symbols
) {
68 for (auto I
: Symbols
) {
69 if (auto EC
= visitSymbolRecord(I
))
72 return Error::success();
75 Error
CVSymbolVisitor::visitSymbolStream(const CVSymbolArray
&Symbols
,
76 uint32_t InitialOffset
) {
77 for (auto I
: Symbols
) {
78 if (auto EC
= visitSymbolRecord(I
, InitialOffset
))
80 InitialOffset
+= I
.length();
82 return Error::success();