Use MachineBasicBlock::transferSuccessors.
[oota-llvm.git] / include / llvm / Support / GraphWriter.h
index 9f96a7723806548c3c4ebbeef11cfd87e572d645..cb9199162ed3ac9506d4af5a1743ff3bb3f51945 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #ifndef LLVM_SUPPORT_GRAPHWRITER_H
 #define LLVM_SUPPORT_GRAPHWRITER_H
 
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/DOTGraphTraits.h"
 #include "llvm/ADT/GraphTraits.h"
 #include "llvm/System/Path.h"
-#include <vector>
-#include <iostream>
 #include <fstream>
+#include <vector>
 
 namespace llvm {
 
@@ -48,11 +48,16 @@ namespace DOT {  // Private functions...
         Str[i] = ' ';
         break;
       case '\\':
-        if (i+1 != Str.length() && Str[i+1] == 'l')
-          break;  // don't disturb \l
+        if (i+1 != Str.length())
+          switch (Str[i+1]) {
+            case 'l': continue; // don't disturb \l
+            case '|': case '{': case '}':
+               Str.erase(Str.begin()+i); continue;
+            default: break;
+          }
       case '{': case '}':
       case '<': case '>':
-      case '"':
+      case '|': case '"':
         Str.insert(Str.begin()+i, '\\');  // Escape character...
         ++i;  // don't infinite loop
         break;
@@ -101,7 +106,11 @@ public:
     // Loop over the graph, printing it out...
     for (node_iterator I = GTraits::nodes_begin(G), E = GTraits::nodes_end(G);
          I != E; ++I)
-      writeNode(&*I);
+      writeNode(*I);
+  }
+  
+  void writeNode(NodeType& Node) {
+    writeNode(&Node);
   }
 
   void writeNode(NodeType *const *Node) {
@@ -109,7 +118,7 @@ public:
   }
 
   void writeNode(NodeType *Node) {
-    std::string NodeAttributes = DOTTraits::getNodeAttributes(Node);
+    std::string NodeAttributes = DOTTraits::getNodeAttributes(Node, G);
 
     O << "\tNode" << reinterpret_cast<const void*>(Node) << " [shape=record,";
     if (!NodeAttributes.empty()) O << NodeAttributes << ",";
@@ -166,8 +175,8 @@ public:
         child_iterator TargetIt = DOTTraits::getEdgeTarget(Node, EI);
 
         // Figure out which edge this targets...
-        unsigned Offset = std::distance(GTraits::child_begin(TargetNode),
-                                        TargetIt);
+        unsigned Offset =
+          (unsigned)std::distance(GTraits::child_begin(TargetNode), TargetIt);
         DestPort = static_cast<int>(Offset);
       }
 
@@ -244,10 +253,19 @@ template<typename GraphType>
 sys::Path WriteGraph(const GraphType &G,
                      const std::string& Name, 
                      const std::string& Title = "") {
-  sys::Path Filename = sys::Path::GetTemporaryDirectory();;  
+  std::string ErrMsg;
+  sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
+  if (Filename.isEmpty()) {
+    cerr << "Error: " << ErrMsg << "\n";
+    return Filename;
+  }
   Filename.appendComponent(Name + ".dot");
-  Filename.makeUnique();
-  std::cerr << "Writing '" << Filename << "'... ";
+  if (Filename.makeUnique(true,&ErrMsg)) {
+    cerr << "Error: " << ErrMsg << "\n";
+    return sys::Path();
+  }
+
+  cerr << "Writing '" << Filename << "'... ";
   
   std::ofstream O(Filename.c_str());
 
@@ -266,12 +284,12 @@ sys::Path WriteGraph(const GraphType &G,
 
     // Output the end of the graph
     W.writeFooter();
-    std::cerr << " done. \n";
+    cerr << " done. \n";
 
     O.close();
     
   } else {
-    std::cerr << "error opening file for writing!\n";
+    cerr << "error opening file for writing!\n";
     Filename.clear();
   }