LLVM API Documentation

GraphWriter.cpp

Go to the documentation of this file.
00001 //===-- GraphWriter.cpp - Implements GraphWriter support routines ---------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements misc. GraphWriter support routines.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/System/Path.h"
00015 #include "llvm/System/Program.h"
00016 #include "llvm/Config/config.h"
00017 
00018 #include <iostream>
00019 
00020 using namespace llvm;
00021 
00022 namespace llvm {
00023 
00024 void DisplayGraph(const sys::Path& Filename)
00025 {
00026 #if HAVE_GRAPHVIZ
00027   sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
00028 
00029   std::vector<const char*> args;
00030   args.push_back(Graphviz.c_str());
00031   args.push_back(Filename.c_str());
00032   args.push_back(0);
00033   
00034   std::cerr << "Running 'Graphviz' program... " << std::flush;
00035   if (sys::Program::ExecuteAndWait(Graphviz, &args[0])) {
00036     std::cerr << "Error viewing graph: 'Graphviz' not in path?\n";
00037   }
00038 #elif (HAVE_GV && HAVE_DOT)
00039   sys::Path PSFilename = Filename;
00040   PSFilename.appendSuffix("ps");
00041   
00042   sys::Path dot(LLVM_PATH_DOT);
00043 
00044   std::vector<const char*> args;
00045   args.push_back(dot.c_str());
00046   args.push_back("-Tps");
00047   args.push_back("-Nfontname=Courier");
00048   args.push_back("-Gsize=7.5,10");
00049   args.push_back(Filename.c_str());
00050   args.push_back("-o");
00051   args.push_back(PSFilename.c_str());
00052   args.push_back(0);
00053   
00054   std::cerr << "Running 'dot' program... " << std::flush;
00055   if (sys::Program::ExecuteAndWait(dot, &args[0])) {
00056     std::cerr << "Error viewing graph: 'dot' not in path?\n";
00057   } else {
00058     std::cerr << " done. \n";
00059 
00060     sys::Path gv(LLVM_PATH_GV);
00061     args.clear();
00062     args.push_back(gv.c_str());
00063     args.push_back(PSFilename.c_str());
00064     args.push_back(0);
00065     
00066     sys::Program::ExecuteAndWait(gv, &args[0]);
00067   }
00068   PSFilename.eraseFromDisk();
00069 #elif HAVE_DOTTY
00070   sys::Path dotty(LLVM_PATH_DOTTY);
00071 
00072   std::vector<const char*> args;
00073   args.push_back(Filename.c_str());
00074   args.push_back(0);
00075   
00076   std::cerr << "Running 'dotty' program... " << std::flush;
00077   if (sys::Program::ExecuteAndWait(dotty, &args[0])) {
00078     std::cerr << "Error viewing graph: 'dotty' not in path?\n";
00079   } else {
00080 #ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns.
00081     return;
00082 #endif
00083   }
00084 #endif
00085   
00086   Filename.eraseFromDisk();
00087 }
00088 
00089 } // End llvm namespace