diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-10-11 19:27:55 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-10-11 19:27:55 +0000 |
commit | 2492c89882b5c5ce03afb4704fee67b7eff8f5ee (patch) | |
tree | 6a06e7bfe07b7541005dc02a9b1d591c4451ce09 /lib/Serialization/ModuleManager.cpp | |
parent | 92d6d404833468120f9a86fb360691ac60585551 (diff) |
Add support for viewing the module graph via Graphviz, for debugging
purposes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141697 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ModuleManager.cpp')
-rw-r--r-- | lib/Serialization/ModuleManager.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/Serialization/ModuleManager.cpp b/lib/Serialization/ModuleManager.cpp index a9fe64d42b..c4b1f7199b 100644 --- a/lib/Serialization/ModuleManager.cpp +++ b/lib/Serialization/ModuleManager.cpp @@ -16,6 +16,10 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/system_error.h" +#ifndef NDEBUG +#include "llvm/Support/GraphWriter.h" +#endif + using namespace clang; using namespace serialization; @@ -202,3 +206,48 @@ void ModuleManager::visitDepthFirst(bool (*Visitor)(Module &M, bool Preorder, return; } } + +#ifndef NDEBUG +namespace llvm { + template<> + struct GraphTraits<ModuleManager> { + typedef Module NodeType; + typedef llvm::SetVector<Module *>::const_iterator ChildIteratorType; + typedef ModuleManager::ModuleConstIterator nodes_iterator; + + static ChildIteratorType child_begin(NodeType *Node) { + return Node->Imports.begin(); + } + + static ChildIteratorType child_end(NodeType *Node) { + return Node->Imports.end(); + } + + static nodes_iterator nodes_begin(const ModuleManager &Manager) { + return Manager.begin(); + } + + static nodes_iterator nodes_end(const ModuleManager &Manager) { + return Manager.end(); + } + }; + + template<> + struct DOTGraphTraits<ModuleManager> : public DefaultDOTGraphTraits { + explicit DOTGraphTraits(bool IsSimple = false) + : DefaultDOTGraphTraits(IsSimple) { } + + static bool renderGraphFromBottomUp() { + return true; + } + + std::string getNodeLabel(Module *M, const ModuleManager&) { + return llvm::sys::path::stem(M->FileName); + } + }; +} + +void ModuleManager::viewGraph() { + llvm::ViewGraph(*this, "Modules"); +} +#endif |