summaryrefslogtreecommitdiff
path: root/include/llvm/Support/GraphWriter.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-23 07:19:13 +0000
committerChris Lattner <sabre@nondot.org>2009-08-23 07:19:13 +0000
commit103289e9383ad1eb66caf28c9b166aebce963a35 (patch)
tree610f140c3f32fdfab3f0ec1d59b6a28875577f9d /include/llvm/Support/GraphWriter.h
parenta36b81d64f90f7cc7c946080d317322c3f4e3a0f (diff)
downloadllvm-103289e9383ad1eb66caf28c9b166aebce963a35.tar.gz
llvm-103289e9383ad1eb66caf28c9b166aebce963a35.tar.bz2
llvm-103289e9383ad1eb66caf28c9b166aebce963a35.tar.xz
convert LoopInfo.h and GraphWriter.h to use raw_ostream
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79836 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/GraphWriter.h')
-rw-r--r--include/llvm/Support/GraphWriter.h64
1 files changed, 16 insertions, 48 deletions
diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h
index 0bb362f867..f77b3db673 100644
--- a/include/llvm/Support/GraphWriter.h
+++ b/include/llvm/Support/GraphWriter.h
@@ -24,47 +24,16 @@
#define LLVM_SUPPORT_GRAPHWRITER_H
#include "llvm/Support/DOTGraphTraits.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/GraphTraits.h"
#include "llvm/System/Path.h"
-#include <fstream>
#include <vector>
#include <cassert>
namespace llvm {
namespace DOT { // Private functions...
- inline std::string EscapeString(const std::string &Label) {
- std::string Str(Label);
- for (unsigned i = 0; i != Str.length(); ++i)
- switch (Str[i]) {
- case '\n':
- Str.insert(Str.begin()+i, '\\'); // Escape character...
- ++i;
- Str[i] = 'n';
- break;
- case '\t':
- Str.insert(Str.begin()+i, ' '); // Convert to two spaces
- ++i;
- Str[i] = ' ';
- break;
- case '\\':
- 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 '"':
- Str.insert(Str.begin()+i, '\\'); // Escape character...
- ++i; // don't infinite loop
- break;
- }
- return Str;
- }
+ std::string EscapeString(const std::string &Label);
}
namespace GraphProgram {
@@ -81,7 +50,7 @@ void DisplayGraph(const sys::Path& Filename, bool wait=true, GraphProgram::Name
template<typename GraphType>
class GraphWriter {
- std::ostream &O;
+ raw_ostream &O;
const GraphType &G;
bool ShortNames;
@@ -91,7 +60,7 @@ class GraphWriter {
typedef typename GTraits::nodes_iterator node_iterator;
typedef typename GTraits::ChildIteratorType child_iterator;
public:
- GraphWriter(std::ostream &o, const GraphType &g, bool SN) :
+ GraphWriter(raw_ostream &o, const GraphType &g, bool SN) :
O(o), G(g), ShortNames(SN) {}
void writeHeader(const std::string &Name) {
@@ -266,10 +235,10 @@ public:
};
template<typename GraphType>
-std::ostream &WriteGraph(std::ostream &O, const GraphType &G,
- bool ShortNames = false,
- const std::string &Name = "",
- const std::string &Title = "") {
+raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G,
+ bool ShortNames = false,
+ const std::string &Name = "",
+ const std::string &Title = "") {
// Start the graph emission process...
GraphWriter<GraphType> W(O, G, ShortNames);
@@ -295,26 +264,25 @@ sys::Path WriteGraph(const GraphType &G,
std::string ErrMsg;
sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
if (Filename.isEmpty()) {
- cerr << "Error: " << ErrMsg << "\n";
+ errs() << "Error: " << ErrMsg << "\n";
return Filename;
}
Filename.appendComponent(Name + ".dot");
if (Filename.makeUnique(true,&ErrMsg)) {
- cerr << "Error: " << ErrMsg << "\n";
+ errs() << "Error: " << ErrMsg << "\n";
return sys::Path();
}
- cerr << "Writing '" << Filename << "'... ";
+ errs() << "Writing '" << Filename << "'... ";
- std::ofstream O(Filename.c_str());
+ std::string ErrorInfo;
+ raw_fd_ostream O(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force);
- if (O.good()) {
+ if (ErrorInfo.empty()) {
WriteGraph(O, G, ShortNames, Name, Title);
- cerr << " done. \n";
-
- O.close();
+ errs() << " done. \n";
} else {
- cerr << "error opening file for writing!\n";
+ errs() << "error opening file '" << Filename << "' for writing!\n";
Filename.clear();
}