1 //===--- DWARFVisitor.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 //===----------------------------------------------------------------------===// 11 12 #ifndef LLVM_OBJECTYAML_DWARFVISITOR_H 13 #define LLVM_OBJECTYAML_DWARFVISITOR_H 14 15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/BinaryFormat/Dwarf.h" 17 #include "llvm/Support/MemoryBuffer.h" 18 19 namespace llvm { 20 21 namespace DWARFYAML { 22 23 struct Data; 24 struct Unit; 25 struct Entry; 26 struct FormValue; 27 struct AttributeAbbrev; 28 29 /// A class to visits DWARFYAML Compile Units and DIEs in preorder. 30 /// 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 { 34 protected: 35 T &DebugInfo; 36 37 /// Visitor Functions 38 /// @{ onStartCompileUnit(Unit & CU)39 virtual void onStartCompileUnit(Unit &CU) {} onEndCompileUnit(Unit & CU)40 virtual void onEndCompileUnit(Unit &CU) {} onStartDIE(Unit & CU,Entry & DIE)41 virtual void onStartDIE(Unit &CU, Entry &DIE) {} onEndDIE(Unit & CU,Entry & DIE)42 virtual void onEndDIE(Unit &CU, Entry &DIE) {} onForm(AttributeAbbrev & AttAbbrev,FormValue & Value)43 virtual void onForm(AttributeAbbrev &AttAbbrev, FormValue &Value) {} 44 /// @} 45 46 /// Const Visitor Functions 47 /// @{ onStartCompileUnit(const Unit & CU)48 virtual void onStartCompileUnit(const Unit &CU) {} onEndCompileUnit(const Unit & CU)49 virtual void onEndCompileUnit(const Unit &CU) {} onStartDIE(const Unit & CU,const Entry & DIE)50 virtual void onStartDIE(const Unit &CU, const Entry &DIE) {} onEndDIE(const Unit & CU,const Entry & DIE)51 virtual void onEndDIE(const Unit &CU, const Entry &DIE) {} onForm(const AttributeAbbrev & AttAbbrev,const FormValue & Value)52 virtual void onForm(const AttributeAbbrev &AttAbbrev, 53 const FormValue &Value) {} 54 /// @} 55 56 /// Value visitors 57 /// @{ onValue(const uint8_t U)58 virtual void onValue(const uint8_t U) {} onValue(const uint16_t U)59 virtual void onValue(const uint16_t U) {} onValue(const uint32_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) {} onValue(const StringRef String)63 virtual void onValue(const StringRef String) {} onValue(const MemoryBufferRef MBR)64 virtual void onValue(const MemoryBufferRef MBR) {} 65 /// @} 66 67 public: VisitorImpl(T & DI)68 VisitorImpl(T &DI) : DebugInfo(DI) {} 69 ~VisitorImpl()70 virtual ~VisitorImpl() {} 71 72 void traverseDebugInfo(); 73 74 private: 75 void onVariableSizeValue(uint64_t U, unsigned Size); 76 }; 77 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 80 // visitors. 81 extern template class VisitorImpl<DWARFYAML::Data>; 82 extern template class VisitorImpl<const DWARFYAML::Data>; 83 84 class Visitor : public VisitorImpl<Data> { 85 public: Visitor(Data & DI)86 Visitor(Data &DI) : VisitorImpl<Data>(DI) {} 87 }; 88 89 class ConstVisitor : public VisitorImpl<const Data> { 90 public: ConstVisitor(const Data & DI)91 ConstVisitor(const Data &DI) : VisitorImpl<const Data>(DI) {} 92 }; 93 94 } // namespace DWARFYAML 95 } // namespace llvm 96 97 #endif 98