ROSE  0.9.9.109
analysis.h
1 #ifndef ANALYSIS_H
2 #define ANALYSIS_H
3 
4 #include "VirtualCFGIterator.h"
5 #include "cfgUtils.h"
6 #include "CallGraphTraverse.h"
7 #include "analysisCommon.h"
8 
9 class Analysis;
10 
11 #include "lattice.h"
12 #include "nodeState.h"
13 #include "variables.h"
14 #include "varSets.h"
15 #include <vector>
16 #include <set>
17 #include <map>
18 
19 extern int analysisDebugLevel;
20 
21 class Analysis
22 {
23  public:
24  // a filter function to decide which raw CFG node to show (if return true) or hide (otherwise)
25  // This is required to support custom filters of virtual CFG
26  // Custom filter is set inside the intra-procedural analysis.
27  // Inter-procedural analysis will copy the filter from its intra-procedural analysis during the call to its constructor.
28  bool (*filter) (CFGNode cfgn);
29  Analysis(bool (*f)(CFGNode) = defaultFilter):filter(f) {}
30 };
31 
33 
34 class IntraProceduralAnalysis : virtual public Analysis
35 {
36  protected:
37  InterProceduralAnalysis* interAnalysis;
38 
39  public:
40  void setInterAnalysis(InterProceduralAnalysis* interAnalysis)
41  { this->interAnalysis = interAnalysis; }
42 
43  // runs the intra-procedural analysis on the given function, returns true if
44  // the function's NodeState gets modified as a result and false otherwise
45  // state - the function's NodeState
46  virtual bool runAnalysis(const Function& func, NodeState* state)=0;
47 
48  virtual ~IntraProceduralAnalysis();
49 };
50 
51 class InterProceduralAnalysis : virtual public Analysis
52 {
53  protected:
54  IntraProceduralAnalysis* intraAnalysis;
55 
57  {
58  this->intraAnalysis = intraAnalysis;
59  // inform the intra-procedural analysis that this inter-procedural analysis will be running it
60  intraAnalysis->setInterAnalysis(this);
61  }
62 
63  virtual void runAnalysis()=0;
64 
65  virtual ~InterProceduralAnalysis();
66 };
67 
68 /********************************
69  *** UnstructuredPassAnalyses ***
70  ********************************/
71 
72 // A driver class which simply iterates through all CFG nodes of a specified function
74 {
75  public:
76  // runs the intra-procedural analysis on the given function, returns true if
77  // the function's NodeState gets modified as a result and false otherwise
78  // state - the function's NodeState
79  bool runAnalysis(const Function& func, NodeState* state);
80 
81  virtual void visit(const Function& func, const DataflowNode& n, NodeState& state)=0;
82 };
83 // A driver class which simply iterates all function definitions one by one and call intra-procedural analysis on each of them.
85 {
86  public:
88  { }
89 
90  void runAnalysis();
91 };
92 
93 #endif
A node in the control flow graph.
Definition: virtualCFG.h:67