diff options
author | Chris Lattner <sabre@nondot.org> | 2009-08-23 07:19:13 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-08-23 07:19:13 +0000 |
commit | 103289e9383ad1eb66caf28c9b166aebce963a35 (patch) | |
tree | 610f140c3f32fdfab3f0ec1d59b6a28875577f9d /include/llvm/Support | |
parent | a36b81d64f90f7cc7c946080d317322c3f4e3a0f (diff) | |
download | external_llvm-103289e9383ad1eb66caf28c9b166aebce963a35.zip external_llvm-103289e9383ad1eb66caf28c9b166aebce963a35.tar.gz external_llvm-103289e9383ad1eb66caf28c9b166aebce963a35.tar.bz2 |
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')
-rw-r--r-- | include/llvm/Support/Casting.h | 4 | ||||
-rw-r--r-- | include/llvm/Support/GraphWriter.h | 64 |
2 files changed, 18 insertions, 50 deletions
diff --git a/include/llvm/Support/Casting.h b/include/llvm/Support/Casting.h index 48988f8..35fb29e 100644 --- a/include/llvm/Support/Casting.h +++ b/include/llvm/Support/Casting.h @@ -235,7 +235,7 @@ inline typename cast_retty<X, Y>::ret_type dyn_cast_or_null(const Y &Val) { #ifdef DEBUG_CAST_OPERATORS -#include "llvm/Support/Streams.h" +#include "llvm/Support/raw_ostream.h" struct bar { bar() {} @@ -251,7 +251,7 @@ struct foo { }; template <> inline bool isa_impl<foo,bar>(const bar &Val) { - cerr << "Classof: " << &Val << "\n"; + errs() << "Classof: " << &Val << "\n"; return true; } diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h index 0bb362f..f77b3db 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(); } |