+ std::string ErrorInfo;
+ raw_fd_ostream O(Filename.c_str(), ErrorInfo);
+
+ if (ErrorInfo.empty()) {
+ llvm::WriteGraph(O, G, ShortNames, Title);
+ errs() << " done. \n";
+ } else {
+ errs() << "error opening file '" << Filename.str() << "' for writing!\n";
+ Filename.clear();
+ }
+
+ return Filename;
+}
+
+/// ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file,
+/// then cleanup. For use from the debugger.
+///
+template<typename GraphType>
+void ViewGraph(const GraphType &G, const Twine &Name,
+ bool ShortNames = false, const Twine &Title = "",
+ GraphProgram::Name Program = GraphProgram::DOT) {
+ sys::Path Filename = llvm::WriteGraph(G, Name, ShortNames, Title);
+
+ if (Filename.isEmpty())
+ return;
+
+ DisplayGraph(Filename, true, Program);