Improve Selection DAG printer portability. Patch by Owen Anderson!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24425 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2005-11-19 07:44:09 +00:00
parent 65303d6bd7
commit 3aa2c74e19

View File

@@ -18,6 +18,7 @@
#include "llvm/Target/MRegisterInfo.h" #include "llvm/Target/MRegisterInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Support/GraphWriter.h" #include "llvm/Support/GraphWriter.h"
#include "llvm/System/Path.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h" #include "llvm/Config/config.h"
#include <fstream> #include <fstream>
@@ -108,7 +109,8 @@ std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
void SelectionDAG::viewGraph() { void SelectionDAG::viewGraph() {
// This code is only for debugging! // This code is only for debugging!
#ifndef NDEBUG #ifndef NDEBUG
std::string Filename = "/tmp/dag." + std::string TempDir = sys::Path::GetTemporaryDirectory().toString();
std::string Filename = TempDir + "dag." +
getMachineFunction().getFunction()->getName() + ".dot"; getMachineFunction().getFunction()->getName() + ".dot";
std::cerr << "Writing '" << Filename << "'... "; std::cerr << "Writing '" << Filename << "'... ";
std::ofstream F(Filename.c_str()); std::ofstream F(Filename.c_str());
@@ -135,13 +137,13 @@ void SelectionDAG::viewGraph() {
#ifdef HAVE_GV #ifdef HAVE_GV
std::cerr << "Running 'dot' program... " << std::flush; std::cerr << "Running 'dot' program... " << std::flush;
if (system(("dot -Tps -Nfontname=Courier -Gsize=7.5,10 " + Filename if (system(("dot -Tps -Nfontname=Courier -Gsize=7.5,10 " + Filename
+ " > /tmp/dag.tempgraph.ps").c_str())) { + " > " + TempDir +"dag.tempgraph.ps").c_str())) {
std::cerr << "Error viewing graph: 'dot' not in path?\n"; std::cerr << "Error viewing graph: 'dot' not in path?\n";
} else { } else {
std::cerr << "\n"; std::cerr << "\n";
system(LLVM_PATH_GV " /tmp/dag.tempgraph.ps"); system(LLVM_PATH_GV " " + TempDir + "dag.tempgraph.ps");
} }
system(("rm " + Filename + " /tmp/dag.tempgraph.ps").c_str()); system(("rm " + Filename + " "+ TempDir + "dag.tempgraph.ps").c_str());
return; return;
#endif // HAVE_GV #endif // HAVE_GV
#endif // NDEBUG #endif // NDEBUG