summaryrefslogtreecommitdiff
path: root/lib/ObjectYAML/DWARFVisitor.h
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2017-03-06 20:52:12 +0000
committerChris Bieneman <beanz@apple.com>2017-03-06 20:52:12 +0000
commit5cd1dc4987d2558d2060dab26e31958b09e7fc26 (patch)
tree14b53b573d753caca37e394767ec06bf828e8da7 /lib/ObjectYAML/DWARFVisitor.h
parent0f756c78047735bc69ba249a9e6ed516fb4db0b6 (diff)
[ObjectYAML] NFC. Refactor DWARFYAML CompileUnit dump code
Summary: This patch refactors the DWARFYAML code for dumping compile units to use a visitor pattern. Using this design will, in the future, enable the DWARF YAML code to perform analysis and mutations of the DWARF DIEs. An example of such mutations would be calculating the length of a compile unit and updating the CU's Length field before writing the DIE. This support will make it easier to craft or modify DWARF tests by hand. Reviewers: lhames Subscribers: mgorny, fhahn, jgosnell, aprantl, llvm-commits Differential Revision: https://reviews.llvm.org/D30357 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297067 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ObjectYAML/DWARFVisitor.h')
-rw-r--r--lib/ObjectYAML/DWARFVisitor.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/ObjectYAML/DWARFVisitor.h b/lib/ObjectYAML/DWARFVisitor.h
new file mode 100644
index 00000000000..263e36220a0
--- /dev/null
+++ b/lib/ObjectYAML/DWARFVisitor.h
@@ -0,0 +1,97 @@
+//===--- DWARFVisitor.h -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_OBJECTYAML_DWARFVISITOR_H
+#define LLVM_OBJECTYAML_DWARFVISITOR_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Dwarf.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace llvm {
+
+namespace DWARFYAML {
+
+struct Data;
+struct Unit;
+struct Entry;
+struct FormValue;
+struct AttributeAbbrev;
+
+/// \brief A class to visits DWARFYAML Compile Units and DIEs in preorder.
+///
+/// Extensions of this class can either maintain const or non-const references
+/// to the DWARFYAML::Data object.
+template <typename T> class VisitorImpl {
+protected:
+ T &DebugInfo;
+
+ /// Visitor Functions
+ /// @{
+ virtual void onStartCompileUnit(Unit &CU) {}
+ virtual void onEndCompileUnit(Unit &CU) {}
+ virtual void onStartDIE(Unit &CU, Entry &DIE) {}
+ virtual void onEndDIE(Unit &CU, Entry &DIE) {}
+ virtual void onForm(AttributeAbbrev &AttAbbrev, FormValue &Value) {}
+ /// @}
+
+ /// Const Visitor Functions
+ /// @{
+ virtual void onStartCompileUnit(const Unit &CU) {}
+ virtual void onEndCompileUnit(const Unit &CU) {}
+ virtual void onStartDIE(const Unit &CU, const Entry &DIE) {}
+ virtual void onEndDIE(const Unit &CU, const Entry &DIE) {}
+ virtual void onForm(const AttributeAbbrev &AttAbbrev,
+ const FormValue &Value) {}
+ /// @}
+
+ /// Value visitors
+ /// @{
+ virtual void onValue(const uint8_t U) {}
+ virtual void onValue(const uint16_t U) {}
+ virtual void onValue(const uint32_t U) {}
+ virtual void onValue(const uint64_t U, const bool LEB = false) {}
+ virtual void onValue(const int64_t S, const bool LEB = false) {}
+ virtual void onValue(const StringRef String) {}
+ virtual void onValue(const MemoryBufferRef MBR) {}
+ /// @}
+
+public:
+ VisitorImpl(T &DI) : DebugInfo(DI) {}
+
+ virtual ~VisitorImpl() {}
+
+ void traverseDebugInfo();
+
+private:
+ void onVariableSizeValue(uint64_t U, unsigned Size);
+};
+
+// Making the visior instantiations extern and explicit in the cpp file. This
+// prevents them from being instantiated in every compile unit that uses the
+// visitors.
+extern template class VisitorImpl<DWARFYAML::Data>;
+extern template class VisitorImpl<const DWARFYAML::Data>;
+
+class Visitor : public VisitorImpl<Data> {
+public:
+ Visitor(Data &DI) : VisitorImpl<Data>(DI) {}
+};
+
+class ConstVisitor : public VisitorImpl<const Data> {
+public:
+ ConstVisitor(const Data &DI) : VisitorImpl<const Data>(DI) {}
+};
+
+} // namespace DWARFYAML
+} // namespace llvm
+
+#endif