-write-graph now can be used with -o.

Makes it possible to set the output file name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67835 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/CompilerDriver/CompilationGraph.h b/include/llvm/CompilerDriver/CompilationGraph.h
index 6bb649b..825d4c4 100644
--- a/include/llvm/CompilerDriver/CompilationGraph.h
+++ b/include/llvm/CompilerDriver/CompilationGraph.h
@@ -157,8 +157,8 @@
     /// in your path.
     void viewGraph();
 
-    /// writeGraph - Write a compilation-graph.dot file.
-    void writeGraph();
+    /// writeGraph - Write Graphviz .dot source file to the current direcotry.
+    void writeGraph(const std::string& OutputFilename);
 
     // GraphTraits support.
     friend NodesIterator GraphBegin(CompilationGraph*);
diff --git a/include/llvm/CompilerDriver/Main.inc b/include/llvm/CompilerDriver/Main.inc
index 0e4480b..2d50c95 100644
--- a/include/llvm/CompilerDriver/Main.inc
+++ b/include/llvm/CompilerDriver/Main.inc
@@ -98,7 +98,11 @@
     Plugins.PopulateCompilationGraph(graph);
 
     if (CheckGraph) {
-      return graph.Check();
+      int ret = graph.Check();
+      if (!ret)
+        std::cerr << "check-graph: no errors found.\n";
+
+      return ret;
     }
 
     if (ViewGraph) {
@@ -108,7 +112,9 @@
     }
 
     if (WriteGraph) {
-      graph.writeGraph();
+      graph.writeGraph(OutputFilename.empty()
+                       ? std::string("compilation-graph.dot")
+                       : OutputFilename);
       return 0;
     }
 
diff --git a/lib/CompilerDriver/CompilationGraph.cpp b/lib/CompilerDriver/CompilationGraph.cpp
index 6112cfe..dece4e8 100644
--- a/lib/CompilerDriver/CompilationGraph.cpp
+++ b/lib/CompilerDriver/CompilationGraph.cpp
@@ -465,9 +465,6 @@
   // Check for cycles.
   ret += this->CheckCycles();
 
-  if (!ret)
-    std::cerr << "check-graph: no errors found.\n";
-
   return ret;
 }
 
@@ -519,18 +516,18 @@
 
 }
 
-void CompilationGraph::writeGraph() {
-  std::ofstream O("compilation-graph.dot");
+void CompilationGraph::writeGraph(const std::string& OutputFilename) {
+  std::ofstream O(OutputFilename.c_str());
 
   if (O.good()) {
-    std::cerr << "Writing 'compilation-graph.dot' file...";
+    std::cerr << "Writing '"<< OutputFilename << "' file...";
     llvm::WriteGraph(O, this);
     std::cerr << "done.\n";
     O.close();
   }
   else {
-    throw std::runtime_error("Error opening file 'compilation-graph.dot'"
-                             " for writing!");
+    throw std::runtime_error("Error opening file '" + OutputFilename
+                             + "' for writing!");
   }
 }