ROSE  0.11.145.0
nodeConstAnalysis.h
1 #include <featureTests.h>
2 #ifdef ROSE_ENABLE_SOURCE_ANALYSIS
3 
4 #ifndef NODE_CONST_ANALYSIS_H
5 #define NODE_CONST_ANALYSIS_H
6 
7 #include "genericDataflowCommon.h"
8 #include "genUID.h"
9 #include "VirtualCFGIterator.h"
10 #include "cfgUtils.h"
11 #include "CallGraphTraverse.h"
12 #include "analysisCommon.h"
13 #include "analysis.h"
14 #include "dataflow.h"
15 #include "latticeFull.h"
16 #include "printAnalysisStates.h"
17 
18 #include <string>
19 #include <vector>
20 
21 extern int nodeConstAnalysisDebugLevel;
22 
23 // For each live variable records whether this variable has not been assigned, has one value or multiple values.
24 // There is one nodeConstAnalysisDebugLevel object for every variable
26 {
27  private:
28  // the unique ID of the value of the variable (if known)
29  unsigned long valID;
30 
31  public:
32  // The different levels of this lattice
33  // this object is uninitialized
34  static const int uninitialized=0;
35 
36  private:
37  // no information is known about the value of the variable
38  // (we haven't seen an assignment)
39  static const int bottom=1;
40  // the value of the variable is known
41  // (we've seen exactly one assignment)
42  static const int valKnown=2;
43  // this variable may have more than one value at the given CFGNode
44  static const int top=3;
45 
46  public:
47  // public names for the different levels that correspond to the final outcome of the analysis
48  static const int noAssign=bottom;
49  static const int constVal=valKnown;
50  static const int multVal=top;
51 
52  private:
53  // this object's current level in the lattice: (uninitialized, bottom, valKnown, top)
54  short level;
55 
56  public:
57 
59  {
60  valID=0;
61  level=uninitialized;
62  }
63 
65  {
66  this->valID = that.valID;
67  this->level = that.level;
68  }
69 
70  // initializes this Lattice to its default state, if it is not already initialized
71  void initialize()
72  {
73  if(level == uninitialized)
74  {
75  valID=0;
76  level=bottom;
77  }
78  }
79 
80  // returns a copy of this lattice
81  Lattice* copy() const;
82 
83  // overwrites the state of this Lattice with that of that Lattice
84  void copy(Lattice* that);
85 
86  // computes the meet of this and that and saves the result in this
87  // returns true if this causes this to change and false otherwise
88  bool meetUpdate(Lattice* that);
89 
90  // Computes the maximum of this node and that, which is just like meet
91  // except that different values get max-ed, rather than push the result to top
92  // returns true if this causes this to change and false otherwise
93  bool maxUpdate(nodeConstLattice& that);
94 
95  // If this lattice is at level valKnown, increments the value by the given amount
96  // returns true if this causes this to change and false otherwise
97  bool increment(int val=1);
98 
99  // computes the meet of this and that and returns the result
100  //Lattice* meet(Lattice* that) const;
101 
102  bool operator==(Lattice* that);
103 
104  /*private:
105  // returns this object's level
106  short getLevel() const;
107 
108  public:*/
109  // returns whether the variable is constant at the current node
110  short getValConst() const;
111 
112  // Sets the state of this lattice to bottom
113  // returns true if this causes the lattice's state to change, false otherwise
114  bool setToBottom();
115 
116  // Sets the state of this lattice to the given value.
117  // returns true if this causes the lattice's state to change, false otherwise
118  bool set(unsigned long valID);
119 
120  // Sets the state of this lattice to top
121  // returns true if this causes the lattice's state to change, false otherwise
122  bool setToTop();
123 
124  std::string str(std::string indent="");
125 };
126 
128 {
129  protected:
130  genUID uids;
131 
132  public:
134  { }
135 
136  /*// generates the initial variable-specific lattice state for a dataflow node
137  Lattice* genInitVarState(const Function& func, const DataflowNode& n, const NodeState& state);
138 
139  // generates the initial non-variable-specific lattice state for a dataflow node
140  Lattice* genInitNonVarState(const Function& func, const DataflowNode& n, const NodeState& state);*/
141 
142  // generates the initial lattice state for the given dataflow node, in the given function, with the given NodeState
143  //std::vector<Lattice*> genInitState(const Function& func, const DataflowNode& n, const NodeState& state);
144  void genInitState(const Function& func, const DataflowNode& n, const NodeState& state,
145  std::vector<Lattice*>& initLattices, std::vector<NodeFact*>& initFacts);
146 
147  bool transfer(const Function& func, const DataflowNode& n, NodeState& state, const std::vector<Lattice*>& dfInfo);
148 };
149 
150 // runs the nodeConstAnalysis on the project and returns the resulting nodeConstAnalysis object
151 nodeConstAnalysis* runNodeConstAnalysis();
152 
153 // prints the Lattices set by the given nodeConstAnalysis
154 void printNodeConstAnalysisStates(nodeConstAnalysis* da, std::string indent="");
155 
156 #endif
157 #endif
Definition: genUID.h:12