00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef LLVM_ANALYSIS_DOT_GRAPHTRAITS_PASS_H
00015 #define LLVM_ANALYSIS_DOT_GRAPHTRAITS_PASS_H
00016
00017 #include "llvm/Pass.h"
00018 #include "llvm/Analysis/CFGPrinter.h"
00019
00020 namespace llvm {
00021 template <class Analysis, bool Simple>
00022 struct DOTGraphTraitsViewer : public FunctionPass {
00023 std::string Name;
00024
00025 DOTGraphTraitsViewer(std::string GraphName, const void *ID) : FunctionPass(ID) {
00026 Name = GraphName;
00027 }
00028
00029 virtual bool runOnFunction(Function &F) {
00030 Analysis *Graph;
00031 std::string Title, GraphName;
00032 Graph = &getAnalysis<Analysis>();
00033 GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
00034 Title = GraphName + " for '" + F.getNameStr() + "' function";
00035 ViewGraph(Graph, Name, Simple, Title);
00036
00037 return false;
00038 }
00039
00040 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00041 AU.setPreservesAll();
00042 AU.addRequired<Analysis>();
00043 }
00044 };
00045
00046 template <class Analysis, bool Simple>
00047 struct DOTGraphTraitsPrinter : public FunctionPass {
00048
00049 std::string Name;
00050
00051 DOTGraphTraitsPrinter(std::string GraphName, const void *ID)
00052 : FunctionPass(ID) {
00053 Name = GraphName;
00054 }
00055
00056 virtual bool runOnFunction(Function &F) {
00057 Analysis *Graph;
00058 std::string Filename = Name + "." + F.getNameStr() + ".dot";
00059 errs() << "Writing '" << Filename << "'...";
00060
00061 std::string ErrorInfo;
00062 raw_fd_ostream File(Filename.c_str(), ErrorInfo);
00063 Graph = &getAnalysis<Analysis>();
00064
00065 std::string Title, GraphName;
00066 GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
00067 Title = GraphName + " for '" + F.getNameStr() + "' function";
00068
00069 if (ErrorInfo.empty())
00070 WriteGraph(File, Graph, Simple, Name, Title);
00071 else
00072 errs() << " error opening file for writing!";
00073 errs() << "\n";
00074 return false;
00075 }
00076
00077 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00078 AU.setPreservesAll();
00079 AU.addRequired<Analysis>();
00080 }
00081 };
00082 }
00083 #endif