1 //===--- DWARFVisitor.h -----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
11 #ifndef LLVM_OBJECTYAML_DWARFVISITOR_H
12 #define LLVM_OBJECTYAML_DWARFVISITOR_H
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/BinaryFormat/Dwarf.h"
16 #include "llvm/Support/MemoryBuffer.h"
26 struct AttributeAbbrev
;
28 /// A class to visits DWARFYAML Compile Units and DIEs in preorder.
30 /// Extensions of this class can either maintain const or non-const references
31 /// to the DWARFYAML::Data object.
32 template <typename T
> class VisitorImpl
{
38 virtual void onStartCompileUnit(Unit
&CU
) {}
39 virtual void onEndCompileUnit(Unit
&CU
) {}
40 virtual void onStartDIE(Unit
&CU
, Entry
&DIE
) {}
41 virtual void onEndDIE(Unit
&CU
, Entry
&DIE
) {}
42 virtual void onForm(AttributeAbbrev
&AttAbbrev
, FormValue
&Value
) {}
45 /// Const Visitor Functions
47 virtual void onStartCompileUnit(const Unit
&CU
) {}
48 virtual void onEndCompileUnit(const Unit
&CU
) {}
49 virtual void onStartDIE(const Unit
&CU
, const Entry
&DIE
) {}
50 virtual void onEndDIE(const Unit
&CU
, const Entry
&DIE
) {}
51 virtual void onForm(const AttributeAbbrev
&AttAbbrev
,
52 const FormValue
&Value
) {}
57 virtual void onValue(const uint8_t U
) {}
58 virtual void onValue(const uint16_t U
) {}
59 virtual void onValue(const uint32_t U
) {}
60 virtual void onValue(const uint64_t U
, const bool LEB
= false) {}
61 virtual void onValue(const int64_t S
, const bool LEB
= false) {}
62 virtual void onValue(const StringRef String
) {}
63 virtual void onValue(const MemoryBufferRef MBR
) {}
67 VisitorImpl(T
&DI
) : DebugInfo(DI
) {}
69 virtual ~VisitorImpl() {}
71 void traverseDebugInfo();
74 void onVariableSizeValue(uint64_t U
, unsigned Size
);
77 // Making the visior instantiations extern and explicit in the cpp file. This
78 // prevents them from being instantiated in every compile unit that uses the
80 extern template class VisitorImpl
<DWARFYAML::Data
>;
81 extern template class VisitorImpl
<const DWARFYAML::Data
>;
83 class Visitor
: public VisitorImpl
<Data
> {
85 Visitor(Data
&DI
) : VisitorImpl
<Data
>(DI
) {}
88 class ConstVisitor
: public VisitorImpl
<const Data
> {
90 ConstVisitor(const Data
&DI
) : VisitorImpl
<const Data
>(DI
) {}
93 } // namespace DWARFYAML