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 | 4883d90396c210a95bb70409c0d4e712c2a79744 (patch) | |
tree | 9c09f657b0740b9ecbf8f2b27e4170b984c60028 /llvm/lib | |
parent | 7e3cfe35ff03fed7bea78ab408962a46ca774466 (diff) | |
download | bcm5719-llvm-4883d90396c210a95bb70409c0d4e712c2a79744.tar.gz bcm5719-llvm-4883d90396c210a95bb70409c0d4e712c2a79744.zip |
convert LoopInfo.h and GraphWriter.h to use raw_ostream
llvm-svn: 79836
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/CFGPrinter.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/Analysis/LoopPass.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/PostRASchedulerList.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CompilerDriver/CompilationGraph.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Support/GraphWriter.cpp | 63 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/LoopExtractor.cpp | 4 |
7 files changed, 70 insertions, 36 deletions
diff --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp index f6ecfc596f5..4ac6b8d8e5d 100644 --- a/llvm/lib/Analysis/CFGPrinter.cpp +++ b/llvm/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/llvm/lib/Analysis/LoopPass.cpp b/llvm/lib/Analysis/LoopPass.cpp index ee03556f274..0007aded2b5 100644 --- a/llvm/lib/Analysis/LoopPass.cpp +++ b/llvm/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/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index c3175dd6750..c8099c8b188 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/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/llvm/lib/CodeGen/PostRASchedulerList.cpp b/llvm/lib/CodeGen/PostRASchedulerList.cpp index 320e6b4eec1..5042415c2cf 100644 --- a/llvm/lib/CodeGen/PostRASchedulerList.cpp +++ b/llvm/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/llvm/lib/CompilerDriver/CompilationGraph.cpp b/llvm/lib/CompilerDriver/CompilationGraph.cpp index f3039433b03..bb0eb7bcf19 100644 --- a/llvm/lib/CompilerDriver/CompilationGraph.cpp +++ b/llvm/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/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp index 4ec0bf86e56..9d72db1bd2d 100644 --- a/llvm/lib/Support/GraphWriter.cpp +++ b/llvm/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/llvm/lib/Transforms/IPO/LoopExtractor.cpp b/llvm/lib/Transforms/IPO/LoopExtractor.cpp index 0c654438d50..4b0988441d9 100644 --- a/llvm/lib/Transforms/IPO/LoopExtractor.cpp +++ b/llvm/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) { |