Reduce usage of sys::Path in the graph writer.

Now PathV1.h is not needed in GraphWriter.h.

llvm-svn: 183919
This commit is contained in:
Rafael Espindola 2013-06-13 17:20:48 +00:00
parent 230ecb2422
commit ce61b1e5b1
2 changed files with 52 additions and 49 deletions

View File

@ -26,7 +26,6 @@
#include "llvm/ADT/GraphTraits.h"
#include "llvm/Support/DOTGraphTraits.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PathV1.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <vector>
@ -51,13 +50,8 @@ namespace GraphProgram {
};
}
void DisplayGraph(const sys::Path& Filename, bool wait=true, GraphProgram::Name program = GraphProgram::DOT);
inline void DisplayGraph(StringRef Filename, bool wait = true,
GraphProgram::Name program = GraphProgram::DOT) {
sys::Path P(Filename);
DisplayGraph(P, wait, program);
}
void DisplayGraph(StringRef Filename, bool wait = true,
GraphProgram::Name program = GraphProgram::DOT);
template<typename GraphType>
class GraphWriter {
@ -325,22 +319,13 @@ raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G,
return O;
}
template<typename GraphType>
sys::Path WriteGraph(const GraphType &G, const Twine &Name,
bool ShortNames = false, const Twine &Title = "") {
std::string ErrMsg;
sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
if (Filename.isEmpty()) {
errs() << "Error: " << ErrMsg << "\n";
return Filename;
}
Filename.appendComponent((Name + ".dot").str());
if (Filename.makeUnique(true,&ErrMsg)) {
errs() << "Error: " << ErrMsg << "\n";
return sys::Path();
}
std::string createGraphFilename(const Twine &Name);
errs() << "Writing '" << Filename.str() << "'... ";
template <typename GraphType>
std::string WriteGraph(const GraphType &G, const Twine &Name,
bool ShortNames = false, const Twine &Title = "") {
std::string Filename = createGraphFilename(Name);
errs() << "Writing '" << Filename << "'... ";
std::string ErrorInfo;
raw_fd_ostream O(Filename.c_str(), ErrorInfo);
@ -349,8 +334,8 @@ sys::Path WriteGraph(const GraphType &G, const Twine &Name,
llvm::WriteGraph(O, G, ShortNames, Title);
errs() << " done. \n";
} else {
errs() << "error opening file '" << Filename.str() << "' for writing!\n";
Filename.clear();
errs() << "error opening file '" << Filename << "' for writing!\n";
return "";
}
return Filename;
@ -363,9 +348,9 @@ template<typename GraphType>
void ViewGraph(const GraphType &G, const Twine &Name,
bool ShortNames = false, const Twine &Title = "",
GraphProgram::Name Program = GraphProgram::DOT) {
sys::Path Filename = llvm::WriteGraph(G, Name, ShortNames, Title);
std::string Filename = llvm::WriteGraph(G, Name, ShortNames, Title);
if (Filename.isEmpty())
if (Filename.empty())
return;
DisplayGraph(Filename, true, Program);

View File

@ -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