1
//===-- DOTGraphTraitsPass.h - Print/View dotty graphs-----------*- C++ -*-===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
// Templates to create dotty viewer and printer passes for GraphTraits graphs.
12
//===----------------------------------------------------------------------===//
14
#ifndef LLVM_ANALYSIS_DOT_GRAPHTRAITS_PASS_H
15
#define LLVM_ANALYSIS_DOT_GRAPHTRAITS_PASS_H
17
#include "llvm/Pass.h"
18
#include "llvm/Analysis/CFGPrinter.h"
21
template <class Analysis, bool Simple>
22
struct DOTGraphTraitsViewer : public FunctionPass {
25
DOTGraphTraitsViewer(std::string GraphName, char &ID) : FunctionPass(ID) {
29
virtual bool runOnFunction(Function &F) {
31
std::string Title, GraphName;
32
Graph = &getAnalysis<Analysis>();
33
GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
34
Title = GraphName + " for '" + F.getNameStr() + "' function";
35
ViewGraph(Graph, Name, Simple, Title);
40
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
42
AU.addRequired<Analysis>();
46
template <class Analysis, bool Simple>
47
struct DOTGraphTraitsPrinter : public FunctionPass {
51
DOTGraphTraitsPrinter(std::string GraphName, char &ID)
56
virtual bool runOnFunction(Function &F) {
58
std::string Filename = Name + "." + F.getNameStr() + ".dot";
59
errs() << "Writing '" << Filename << "'...";
61
std::string ErrorInfo;
62
raw_fd_ostream File(Filename.c_str(), ErrorInfo);
63
Graph = &getAnalysis<Analysis>();
65
std::string Title, GraphName;
66
GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
67
Title = GraphName + " for '" + F.getNameStr() + "' function";
69
if (ErrorInfo.empty())
70
WriteGraph(File, Graph, Simple, Name, Title);
72
errs() << " error opening file for writing!";
77
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
79
AU.addRequired<Analysis>();