1 //===--- DWARFVisitor.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 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_OBJECTYAML_DWARFVISITOR_H
13 #define LLVM_OBJECTYAML_DWARFVISITOR_H
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/BinaryFormat/Dwarf.h"
17 #include "llvm/Support/MemoryBuffer.h"
27 struct AttributeAbbrev;
29 /// \brief A class to visits DWARFYAML Compile Units and DIEs in preorder.
31 /// Extensions of this class can either maintain const or non-const references
32 /// to the DWARFYAML::Data object.
33 template <typename T> class VisitorImpl {
39 virtual void onStartCompileUnit(Unit &CU) {}
40 virtual void onEndCompileUnit(Unit &CU) {}
41 virtual void onStartDIE(Unit &CU, Entry &DIE) {}
42 virtual void onEndDIE(Unit &CU, Entry &DIE) {}
43 virtual void onForm(AttributeAbbrev &AttAbbrev, FormValue &Value) {}
46 /// Const Visitor Functions
48 virtual void onStartCompileUnit(const Unit &CU) {}
49 virtual void onEndCompileUnit(const Unit &CU) {}
50 virtual void onStartDIE(const Unit &CU, const Entry &DIE) {}
51 virtual void onEndDIE(const Unit &CU, const Entry &DIE) {}
52 virtual void onForm(const AttributeAbbrev &AttAbbrev,
53 const FormValue &Value) {}
58 virtual void onValue(const uint8_t U) {}
59 virtual void onValue(const uint16_t U) {}
60 virtual void onValue(const uint32_t U) {}
61 virtual void onValue(const uint64_t U, const bool LEB = false) {}
62 virtual void onValue(const int64_t S, const bool LEB = false) {}
63 virtual void onValue(const StringRef String) {}
64 virtual void onValue(const MemoryBufferRef MBR) {}
68 VisitorImpl(T &DI) : DebugInfo(DI) {}
70 virtual ~VisitorImpl() {}
72 void traverseDebugInfo();
75 void onVariableSizeValue(uint64_t U, unsigned Size);
78 // Making the visior instantiations extern and explicit in the cpp file. This
79 // prevents them from being instantiated in every compile unit that uses the
81 extern template class VisitorImpl<DWARFYAML::Data>;
82 extern template class VisitorImpl<const DWARFYAML::Data>;
84 class Visitor : public VisitorImpl<Data> {
86 Visitor(Data &DI) : VisitorImpl<Data>(DI) {}
89 class ConstVisitor : public VisitorImpl<const Data> {
91 ConstVisitor(const Data &DI) : VisitorImpl<const Data>(DI) {}
94 } // namespace DWARFYAML