Chris Bieneman | 8f471f7 | 2017-03-06 20:52:12 +0000 | [diff] [blame] | 1 | //===--- DWARFVisitor.h -----------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Chris Bieneman | 8f471f7 | 2017-03-06 20:52:12 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef LLVM_OBJECTYAML_DWARFVISITOR_H |
| 12 | #define LLVM_OBJECTYAML_DWARFVISITOR_H |
| 13 | |
| 14 | #include "llvm/ADT/StringRef.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 15 | #include "llvm/BinaryFormat/Dwarf.h" |
Chris Bieneman | 8f471f7 | 2017-03-06 20:52:12 +0000 | [diff] [blame] | 16 | #include "llvm/Support/MemoryBuffer.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | |
| 20 | namespace DWARFYAML { |
| 21 | |
| 22 | struct Data; |
| 23 | struct Unit; |
| 24 | struct Entry; |
| 25 | struct FormValue; |
| 26 | struct AttributeAbbrev; |
| 27 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 28 | /// A class to visits DWARFYAML Compile Units and DIEs in preorder. |
Chris Bieneman | 8f471f7 | 2017-03-06 20:52:12 +0000 | [diff] [blame] | 29 | /// |
| 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 { |
| 33 | protected: |
| 34 | T &DebugInfo; |
| 35 | |
| 36 | /// Visitor Functions |
| 37 | /// @{ |
| 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) {} |
| 43 | /// @} |
| 44 | |
| 45 | /// Const Visitor Functions |
| 46 | /// @{ |
| 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) {} |
| 53 | /// @} |
| 54 | |
| 55 | /// Value visitors |
| 56 | /// @{ |
| 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) {} |
| 64 | /// @} |
| 65 | |
| 66 | public: |
| 67 | VisitorImpl(T &DI) : DebugInfo(DI) {} |
| 68 | |
| 69 | virtual ~VisitorImpl() {} |
| 70 | |
| 71 | void traverseDebugInfo(); |
| 72 | |
| 73 | private: |
| 74 | void onVariableSizeValue(uint64_t U, unsigned Size); |
| 75 | }; |
| 76 | |
| 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 |
| 79 | // visitors. |
| 80 | extern template class VisitorImpl<DWARFYAML::Data>; |
| 81 | extern template class VisitorImpl<const DWARFYAML::Data>; |
| 82 | |
| 83 | class Visitor : public VisitorImpl<Data> { |
| 84 | public: |
| 85 | Visitor(Data &DI) : VisitorImpl<Data>(DI) {} |
| 86 | }; |
| 87 | |
| 88 | class ConstVisitor : public VisitorImpl<const Data> { |
| 89 | public: |
| 90 | ConstVisitor(const Data &DI) : VisitorImpl<const Data>(DI) {} |
| 91 | }; |
| 92 | |
| 93 | } // namespace DWARFYAML |
| 94 | } // namespace llvm |
| 95 | |
| 96 | #endif |