diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 3a09e7b0585..a31ace76e15 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -36,9 +36,8 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Support/CFG.h" -#include "llvm/Support/Streams.h" +#include "llvm/Support/raw_ostream.h" #include -#include namespace llvm { diff --git a/include/llvm/Support/Casting.h b/include/llvm/Support/Casting.h index 48988f8a6bb..35fb29ec6cb 100644 --- a/include/llvm/Support/Casting.h +++ b/include/llvm/Support/Casting.h @@ -235,7 +235,7 @@ inline typename cast_retty::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(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 0bb362f8673..f77b3db673c 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 #include #include 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 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 -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 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(); } diff --git a/lib/Analysis/CFGPrinter.cpp b/lib/Analysis/CFGPrinter.cpp index f6ecfc596f5..4ac6b8d8e5d 100644 --- a/lib/Analysis/CFGPrinter.cpp +++ b/lib/Analysis/CFGPrinter.cpp @@ -25,7 +25,6 @@ #include "llvm/Support/CFG.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/GraphWriter.h" -#include "llvm/Config/config.h" using namespace llvm; namespace llvm { @@ -136,14 +135,16 @@ namespace { virtual bool runOnFunction(Function &F) { std::string Filename = "cfg." + F.getNameStr() + ".dot"; - cerr << "Writing '" << Filename << "'..."; - std::ofstream File(Filename.c_str()); + errs() << "Writing '" << Filename << "'..."; + + std::string ErrorInfo; + raw_fd_ostream File(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force); - if (File.good()) + if (ErrorInfo.empty()) WriteGraph(File, (const Function*)&F); else - cerr << " error opening file for writing!"; - cerr << "\n"; + errs() << " error opening file for writing!"; + errs() << "\n"; return false; } @@ -166,14 +167,16 @@ namespace { explicit CFGOnlyPrinter(void *pid) : FunctionPass(pid) {} virtual bool runOnFunction(Function &F) { std::string Filename = "cfg." + F.getNameStr() + ".dot"; - cerr << "Writing '" << Filename << "'..."; - std::ofstream File(Filename.c_str()); + errs() << "Writing '" << Filename << "'..."; - if (File.good()) + std::string ErrorInfo; + raw_fd_ostream File(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force); + + if (ErrorInfo.empty()) WriteGraph(File, (const Function*)&F, true); else - cerr << " error opening file for writing!"; - cerr << "\n"; + errs() << " error opening file for writing!"; + errs() << "\n"; return false; } void print(raw_ostream &OS, const Module* = 0) const {} diff --git a/lib/Analysis/LoopPass.cpp b/lib/Analysis/LoopPass.cpp index ee03556f274..0007aded2b5 100644 --- a/lib/Analysis/LoopPass.cpp +++ b/lib/Analysis/LoopPass.cpp @@ -272,7 +272,7 @@ bool LPPassManager::runOnFunction(Function &F) { /// Print passes managed by this manager void LPPassManager::dumpPassStructure(unsigned Offset) { - llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n"; + errs().indent(Offset*2) << "Loop Pass Manager\n"; for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { Pass *P = getContainedPass(Index); P->dumpPassStructure(Offset + 1); diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index c3175dd6750..c8099c8b188 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1724,7 +1724,7 @@ GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) { return GMP; } - cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n"; + errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n"; llvm_unreachable(0); } diff --git a/lib/CodeGen/PostRASchedulerList.cpp b/lib/CodeGen/PostRASchedulerList.cpp index 320e6b4eec1..5042415c2cf 100644 --- a/lib/CodeGen/PostRASchedulerList.cpp +++ b/lib/CodeGen/PostRASchedulerList.cpp @@ -765,9 +765,9 @@ void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) { #ifndef NDEBUG if (SuccSU->NumPredsLeft < 0) { - cerr << "*** Scheduling failed! ***\n"; + errs() << "*** Scheduling failed! ***\n"; SuccSU->dump(this); - cerr << " has been released too many times!\n"; + errs() << " has been released too many times!\n"; llvm_unreachable(0); } #endif diff --git a/lib/CompilerDriver/CompilationGraph.cpp b/lib/CompilerDriver/CompilationGraph.cpp index f3039433b03..bb0eb7bcf19 100644 --- a/lib/CompilerDriver/CompilationGraph.cpp +++ b/lib/CompilerDriver/CompilationGraph.cpp @@ -514,13 +514,13 @@ namespace llvm { } void CompilationGraph::writeGraph(const std::string& OutputFilename) { - std::ofstream O(OutputFilename.c_str()); + std::string ErrorInfo; + raw_fd_ostream O(OutputFilename.c_str(), ErrorInfo); - if (O.good()) { + if (ErrorInfo.empty()) { errs() << "Writing '"<< OutputFilename << "' file..."; llvm::WriteGraph(O, this); errs() << "done.\n"; - O.close(); } else { throw std::runtime_error("Error opening file '" + OutputFilename diff --git a/lib/Support/GraphWriter.cpp b/lib/Support/GraphWriter.cpp index 4ec0bf86e56..9d72db1bd2d 100644 --- a/lib/Support/GraphWriter.cpp +++ b/lib/Support/GraphWriter.cpp @@ -12,12 +12,45 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/GraphWriter.h" -#include "llvm/Support/Streams.h" #include "llvm/System/Path.h" #include "llvm/System/Program.h" #include "llvm/Config/config.h" using namespace llvm; +std::string llvm::DOT::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; +} + + + void llvm::DisplayGraph(const sys::Path &Filename, bool wait, GraphProgram::Name program) { std::string ErrMsg; @@ -29,13 +62,11 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait, args.push_back(Filename.c_str()); args.push_back(0); - cerr << "Running 'Graphviz' program... "; - if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) { - cerr << "Error viewing graph " << Filename << ": " << ErrMsg << "\n"; - } - else { + errs() << "Running 'Graphviz' program... "; + if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) + errs() << "Error viewing graph " << Filename << ": " << ErrMsg << "\n"; + else Filename.eraseFromDisk(); - } #elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \ HAVE_TWOPI || HAVE_CIRCO)) @@ -98,12 +129,12 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait, args.push_back(PSFilename.c_str()); args.push_back(0); - cerr << "Running '" << prog << "' program... "; + errs() << "Running '" << prog << "' program... "; if (sys::Program::ExecuteAndWait(prog, &args[0],0,0,0,0,&ErrMsg)) { - cerr << "Error viewing graph " << Filename << ": '" << ErrMsg << "\n"; + errs() << "Error viewing graph " << Filename << ": '" << ErrMsg << "\n"; } else { - cerr << " done. \n"; + errs() << " done. \n"; sys::Path gv(LLVM_PATH_GV); args.clear(); @@ -114,15 +145,15 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait, ErrMsg.clear(); if (wait) { - if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) { - cerr << "Error viewing graph: " << ErrMsg << "\n"; - } + if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) + errs() << "Error viewing graph: " << ErrMsg << "\n"; Filename.eraseFromDisk(); PSFilename.eraseFromDisk(); } else { sys::Program::ExecuteNoWait(gv, &args[0],0,0,0,&ErrMsg); - cerr << "Remember to erase graph files: " << Filename << " " << PSFilename << "\n"; + errs() << "Remember to erase graph files: " << Filename << " " + << PSFilename << "\n"; } } #elif HAVE_DOTTY @@ -133,9 +164,9 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait, args.push_back(Filename.c_str()); args.push_back(0); - cerr << "Running 'dotty' program... "; + errs() << "Running 'dotty' program... "; if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) { - cerr << "Error viewing graph " << Filename << ": " << ErrMsg << "\n"; + errs() << "Error viewing graph " << Filename << ": " << ErrMsg << "\n"; } else { #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns return; diff --git a/lib/Transforms/IPO/LoopExtractor.cpp b/lib/Transforms/IPO/LoopExtractor.cpp index 0c654438d50..4b0988441d9 100644 --- a/lib/Transforms/IPO/LoopExtractor.cpp +++ b/lib/Transforms/IPO/LoopExtractor.cpp @@ -193,8 +193,8 @@ void BlockExtractorPass::LoadFile(const char *Filename) { // Load the BlockFile... std::ifstream In(Filename); if (!In.good()) { - cerr << "WARNING: BlockExtractor couldn't load file '" << Filename - << "'!\n"; + errs() << "WARNING: BlockExtractor couldn't load file '" << Filename + << "'!\n"; return; } while (In) {