[cfe-commits] r141697 - in /cfe/trunk: include/clang/Serialization/ModuleManager.h lib/Serialization/ModuleManager.cpp

Douglas Gregor dgregor at apple.com
Tue Oct 11 12:27:55 PDT 2011


Author: dgregor
Date: Tue Oct 11 14:27:55 2011
New Revision: 141697

URL: http://llvm.org/viewvc/llvm-project?rev=141697&view=rev
Log:
Add support for viewing the module graph via Graphviz, for debugging
purposes.

Modified:
    cfe/trunk/include/clang/Serialization/ModuleManager.h
    cfe/trunk/lib/Serialization/ModuleManager.cpp

Modified: cfe/trunk/include/clang/Serialization/ModuleManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ModuleManager.h?rev=141697&r1=141696&r2=141697&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ModuleManager.h (original)
+++ cfe/trunk/include/clang/Serialization/ModuleManager.h Tue Oct 11 14:27:55 2011
@@ -146,6 +146,9 @@
   void visitDepthFirst(bool (*Visitor)(Module &M, bool Preorder, 
                                        void *UserData), 
                        void *UserData);
+  
+  /// \brief View the graphviz representation of the module graph.
+  void viewGraph();
 };
 
 } } // end namespace clang::serialization

Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=141697&r1=141696&r2=141697&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Tue Oct 11 14:27:55 2011
@@ -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 @@
       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





More information about the cfe-commits mailing list