Implement bswap
[llvm/msp430.git] / lib / Support / GraphWriter.cpp
blobc359dfb82ea7b618454f9ed9500d75926221591a
1 //===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements misc. GraphWriter support routines.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/GraphWriter.h"
15 #include "llvm/Support/Streams.h"
16 #include "llvm/System/Path.h"
17 #include "llvm/System/Program.h"
18 #include "llvm/Config/config.h"
19 using namespace llvm;
21 void llvm::DisplayGraph(const sys::Path &Filename) {
22 std::string ErrMsg;
23 #if HAVE_GRAPHVIZ
24 sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
26 std::vector<const char*> args;
27 args.push_back(Graphviz.c_str());
28 args.push_back(Filename.c_str());
29 args.push_back(0);
31 cerr << "Running 'Graphviz' program... " << std::flush;
32 if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) {
33 cerr << "Error viewing graph: " << ErrMsg << "\n";
35 #elif (HAVE_GV && HAVE_DOT)
36 sys::Path PSFilename = Filename;
37 PSFilename.appendSuffix("ps");
39 sys::Path dot(LLVM_PATH_DOT);
41 std::vector<const char*> args;
42 args.push_back(dot.c_str());
43 args.push_back("-Tps");
44 args.push_back("-Nfontname=Courier");
45 args.push_back("-Gsize=7.5,10");
46 args.push_back(Filename.c_str());
47 args.push_back("-o");
48 args.push_back(PSFilename.c_str());
49 args.push_back(0);
51 cerr << "Running 'dot' program... " << std::flush;
52 if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,0,&ErrMsg)) {
53 cerr << "Error viewing graph: '" << ErrMsg << "\n";
54 } else {
55 cerr << " done. \n";
57 sys::Path gv(LLVM_PATH_GV);
58 args.clear();
59 args.push_back(gv.c_str());
60 args.push_back(PSFilename.c_str());
61 args.push_back("-spartan");
62 args.push_back(0);
64 ErrMsg.clear();
65 if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) {
66 cerr << "Error viewing graph: " << ErrMsg << "\n";
69 PSFilename.eraseFromDisk();
70 #elif HAVE_DOTTY
71 sys::Path dotty(LLVM_PATH_DOTTY);
73 std::vector<const char*> args;
74 args.push_back(dotty.c_str());
75 args.push_back(Filename.c_str());
76 args.push_back(0);
78 cerr << "Running 'dotty' program... " << std::flush;
79 if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) {
80 cerr << "Error viewing graph: " << ErrMsg << "\n";
81 } else {
82 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns
83 return;
84 #endif
86 #endif
88 Filename.eraseFromDisk();