2010-01-16 10:56:41 +00:00
|
|
|
//===-- DOTGraphTraitsPass.h - Print/View dotty graphs-----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Templates to create dotty viewer and printer passes for GraphTraits graphs.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
|
|
|
|
#define LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
|
2010-01-16 10:56:41 +00:00
|
|
|
|
|
|
|
#include "llvm/Analysis/CFGPrinter.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Pass.h"
|
2010-01-16 10:56:41 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2013-01-11 17:28:14 +00:00
|
|
|
template <class Analysis, bool Simple>
|
|
|
|
class DOTGraphTraitsViewer : public FunctionPass {
|
|
|
|
public:
|
2013-01-13 16:01:15 +00:00
|
|
|
DOTGraphTraitsViewer(StringRef GraphName, char &ID)
|
2013-01-11 17:28:14 +00:00
|
|
|
: FunctionPass(ID), Name(GraphName) {}
|
2010-01-16 10:56:41 +00:00
|
|
|
|
|
|
|
virtual bool runOnFunction(Function &F) {
|
2013-01-11 17:28:14 +00:00
|
|
|
Analysis *Graph = &getAnalysis<Analysis>();
|
|
|
|
std::string GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
|
|
|
|
std::string Title = GraphName + " for '" + F.getName().str() + "' function";
|
|
|
|
|
2010-01-16 10:56:41 +00:00
|
|
|
ViewGraph(Graph, Name, Simple, Title);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<Analysis>();
|
|
|
|
}
|
2013-01-11 17:28:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string Name;
|
2010-01-16 10:56:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class Analysis, bool Simple>
|
2013-01-11 17:28:14 +00:00
|
|
|
class DOTGraphTraitsPrinter : public FunctionPass {
|
|
|
|
public:
|
2013-01-13 16:01:15 +00:00
|
|
|
DOTGraphTraitsPrinter(StringRef GraphName, char &ID)
|
2013-01-11 17:28:14 +00:00
|
|
|
: FunctionPass(ID), Name(GraphName) {}
|
|
|
|
|
|
|
|
virtual bool runOnFunction(Function &F) {
|
|
|
|
Analysis *Graph = &getAnalysis<Analysis>();
|
|
|
|
std::string Filename = Name + "." + F.getName().str() + ".dot";
|
|
|
|
std::string ErrorInfo;
|
|
|
|
|
|
|
|
errs() << "Writing '" << Filename << "'...";
|
|
|
|
|
|
|
|
raw_fd_ostream File(Filename.c_str(), ErrorInfo);
|
|
|
|
std::string GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
|
|
|
|
std::string Title = GraphName + " for '" + F.getName().str() + "' function";
|
|
|
|
|
|
|
|
if (ErrorInfo.empty())
|
|
|
|
WriteGraph(File, Graph, Simple, Title);
|
|
|
|
else
|
|
|
|
errs() << " error opening file for writing!";
|
|
|
|
errs() << "\n";
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<Analysis>();
|
|
|
|
}
|
2010-01-16 10:56:41 +00:00
|
|
|
|
2013-01-11 17:28:14 +00:00
|
|
|
private:
|
2010-01-16 10:56:41 +00:00
|
|
|
std::string Name;
|
2013-01-11 17:28:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class Analysis, bool Simple>
|
|
|
|
class DOTGraphTraitsModuleViewer : public ModulePass {
|
|
|
|
public:
|
2013-01-13 16:01:15 +00:00
|
|
|
DOTGraphTraitsModuleViewer(StringRef GraphName, char &ID)
|
2013-01-11 17:28:14 +00:00
|
|
|
: ModulePass(ID), Name(GraphName) {}
|
|
|
|
|
|
|
|
virtual bool runOnModule(Module &M) {
|
|
|
|
Analysis *Graph = &getAnalysis<Analysis>();
|
|
|
|
std::string Title = DOTGraphTraits<Analysis*>::getGraphName(Graph);
|
2010-01-16 10:56:41 +00:00
|
|
|
|
2013-01-11 17:28:14 +00:00
|
|
|
ViewGraph(Graph, Name, Simple, Title);
|
|
|
|
|
|
|
|
return false;
|
2010-01-16 10:56:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 17:28:14 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<Analysis>();
|
|
|
|
}
|
2010-01-16 10:56:41 +00:00
|
|
|
|
2013-01-11 17:28:14 +00:00
|
|
|
private:
|
|
|
|
std::string Name;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Analysis, bool Simple>
|
|
|
|
class DOTGraphTraitsModulePrinter : public ModulePass {
|
|
|
|
public:
|
2013-01-13 16:01:15 +00:00
|
|
|
DOTGraphTraitsModulePrinter(StringRef GraphName, char &ID)
|
2013-01-11 17:28:14 +00:00
|
|
|
: ModulePass(ID), Name(GraphName) {}
|
|
|
|
|
|
|
|
virtual bool runOnModule(Module &M) {
|
|
|
|
Analysis *Graph = &getAnalysis<Analysis>();
|
|
|
|
std::string Filename = Name + ".dot";
|
2010-01-16 10:56:41 +00:00
|
|
|
std::string ErrorInfo;
|
|
|
|
|
2013-01-11 17:28:14 +00:00
|
|
|
errs() << "Writing '" << Filename << "'...";
|
|
|
|
|
|
|
|
raw_fd_ostream File(Filename.c_str(), ErrorInfo);
|
|
|
|
std::string Title = DOTGraphTraits<Analysis*>::getGraphName(Graph);
|
2010-01-16 10:56:41 +00:00
|
|
|
|
|
|
|
if (ErrorInfo.empty())
|
2010-09-27 15:34:19 +00:00
|
|
|
WriteGraph(File, Graph, Simple, Title);
|
2010-01-16 10:56:41 +00:00
|
|
|
else
|
|
|
|
errs() << " error opening file for writing!";
|
|
|
|
errs() << "\n";
|
2013-01-11 17:28:14 +00:00
|
|
|
|
2010-01-16 10:56:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<Analysis>();
|
|
|
|
}
|
2013-01-11 17:28:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string Name;
|
2010-01-16 10:56:41 +00:00
|
|
|
};
|
2013-01-11 17:28:14 +00:00
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2010-01-16 10:56:41 +00:00
|
|
|
#endif
|