diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-13 17:20:48 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-13 17:20:48 +0000 |
commit | ce61b1e5b11f6164864ed1c29a5186fdf6850173 (patch) | |
tree | 08d0dcafd902cbb49c4177cfcadfef79f772ded5 /llvm/lib/Support/GraphWriter.cpp | |
parent | 230ecb24222a13f8801867da857c8e925cbb3d31 (diff) | |
download | bcm5719-llvm-ce61b1e5b11f6164864ed1c29a5186fdf6850173.tar.gz bcm5719-llvm-ce61b1e5b11f6164864ed1c29a5186fdf6850173.zip |
Reduce usage of sys::Path in the graph writer.
Now PathV1.h is not needed in GraphWriter.h.
llvm-svn: 183919
Diffstat (limited to 'llvm/lib/Support/GraphWriter.cpp')
-rw-r--r-- | llvm/lib/Support/GraphWriter.cpp | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp index 41af06c2392..3a305d851ed 100644 --- a/llvm/lib/Support/GraphWriter.cpp +++ b/llvm/lib/Support/GraphWriter.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/GraphWriter.h" #include "llvm/Config/config.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" using namespace llvm; @@ -64,26 +65,42 @@ StringRef llvm::DOT::getColorString(unsigned ColorNumber) { return Colors[ColorNumber % NumColors]; } +std::string llvm::createGraphFilename(const Twine &Name) { + std::string ErrMsg; + sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg); + if (Filename.isEmpty()) { + errs() << "Error: " << ErrMsg << "\n"; + return ""; + } + Filename.appendComponent((Name + ".dot").str()); + if (Filename.makeUnique(true,&ErrMsg)) { + errs() << "Error: " << ErrMsg << "\n"; + return ""; + } + return Filename.str(); +} + // Execute the graph viewer. Return true if successful. static bool LLVM_ATTRIBUTE_UNUSED -ExecGraphViewer(const sys::Path &ExecPath, std::vector<const char*> &args, - const sys::Path &Filename, bool wait, std::string &ErrMsg) { +ExecGraphViewer(StringRef ExecPath, std::vector<const char*> &args, + StringRef Filename, bool wait, std::string &ErrMsg) { if (wait) { - if (sys::ExecuteAndWait(ExecPath, &args[0],0,0,0,0,&ErrMsg)) { + if (sys::ExecuteAndWait(sys::Path(ExecPath), &args[0],0,0,0,0,&ErrMsg)) { errs() << "Error: " << ErrMsg << "\n"; return false; } - Filename.eraseFromDisk(); + bool Existed; + sys::fs::remove(Filename, Existed); errs() << " done. \n"; } else { - sys::ExecuteNoWait(ExecPath, &args[0],0,0,0,&ErrMsg); + sys::ExecuteNoWait(sys::Path(ExecPath), &args[0],0,0,0,&ErrMsg); errs() << "Remember to erase graph file: " << Filename.str() << "\n"; } return true; } -void llvm::DisplayGraph(const sys::Path &Filename, bool wait, +void llvm::DisplayGraph(StringRef Filename, bool wait, GraphProgram::Name program) { wait &= !ViewBackground; std::string ErrMsg; @@ -120,66 +137,67 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait, #elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \ HAVE_TWOPI || HAVE_CIRCO)) - sys::Path PSFilename = Filename; + sys::Path PSFilename = sys::Path(Filename); PSFilename.appendSuffix("ps"); - sys::Path prog; + std::string prog; // Set default grapher #if HAVE_CIRCO - prog = sys::Path(LLVM_PATH_CIRCO); + prog = LLVM_PATH_CIRCO; #endif #if HAVE_TWOPI - prog = sys::Path(LLVM_PATH_TWOPI); + prog = LLVM_PATH_TWOPI; #endif #if HAVE_NEATO - prog = sys::Path(LLVM_PATH_NEATO); + prog = LLVM_PATH_NEATO; #endif #if HAVE_FDP - prog = sys::Path(LLVM_PATH_FDP); + prog = LLVM_PATH_FDP; #endif #if HAVE_DOT - prog = sys::Path(LLVM_PATH_DOT); + prog = LLVM_PATH_DOT; #endif // Find which program the user wants #if HAVE_DOT if (program == GraphProgram::DOT) - prog = sys::Path(LLVM_PATH_DOT); + prog = LLVM_PATH_DOT; #endif #if (HAVE_FDP) if (program == GraphProgram::FDP) - prog = sys::Path(LLVM_PATH_FDP); + prog = LLVM_PATH_FDP; #endif #if (HAVE_NEATO) if (program == GraphProgram::NEATO) - prog = sys::Path(LLVM_PATH_NEATO); + prog = LLVM_PATH_NEATO; #endif #if (HAVE_TWOPI) if (program == GraphProgram::TWOPI) - prog = sys::Path(LLVM_PATH_TWOPI); + prog = LLVM_PATH_TWOPI; #endif #if (HAVE_CIRCO) if (program == GraphProgram::CIRCO) - prog = sys::Path(LLVM_PATH_CIRCO); + prog = LLVM_PATH_CIRCO; #endif std::vector<const char*> args; + std::string FilenameStr = Filename; args.push_back(prog.c_str()); args.push_back("-Tps"); args.push_back("-Nfontname=Courier"); args.push_back("-Gsize=7.5,10"); - args.push_back(Filename.c_str()); + args.push_back(FilenameStr.c_str()); args.push_back("-o"); args.push_back(PSFilename.c_str()); args.push_back(0); - errs() << "Running '" << prog.str() << "' program... "; + errs() << "Running '" << prog << "' program... "; if (!ExecGraphViewer(prog, args, Filename, wait, ErrMsg)) return; - sys::Path gv(LLVM_PATH_GV); + std::string gv(LLVM_PATH_GV); args.clear(); args.push_back(gv.c_str()); args.push_back(PSFilename.c_str()); @@ -187,7 +205,7 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait, args.push_back(0); ErrMsg.clear(); - if (!ExecGraphViewer(gv, args, PSFilename, wait, ErrMsg)) + if (!ExecGraphViewer(gv, args, PSFilename.str(), wait, ErrMsg)) return; #elif HAVE_DOTTY |