summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/ModuleManager.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-10-11 19:27:55 +0000
committerDouglas Gregor <dgregor@apple.com>2011-10-11 19:27:55 +0000
commit9d7c1a2a180ab153a54809133fa7080f8213b44a (patch)
tree10c0e392ba228460a08167b84e95bc6817f8263d /clang/lib/Serialization/ModuleManager.cpp
parent7148bce86e3207c60f45d083f372ed97fe5c1943 (diff)
downloadbcm5719-llvm-9d7c1a2a180ab153a54809133fa7080f8213b44a.tar.gz
bcm5719-llvm-9d7c1a2a180ab153a54809133fa7080f8213b44a.zip
Add support for viewing the module graph via Graphviz, for debugging
purposes. llvm-svn: 141697
Diffstat (limited to 'clang/lib/Serialization/ModuleManager.cpp')
-rw-r--r--clang/lib/Serialization/ModuleManager.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index a9fe64d42bd..c4b1f7199be 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud