00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef CBZ_IPCONSTANTS_H
00038 #define CBZ_IPCONSTANTS_H
00039
00040 #include "pointers.h"
00041 #include "ipanalysis.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 class ipConstant : public analysisVal
00053 {
00054 friend class ipConstantPropagation;
00055 friend class ipConstantsChanger;
00056
00057 private:
00058
00059 constant _value;
00060 bool _top;
00061 bool _internal;
00062
00063 ipConstant(constant & value);
00064 ipConstant();
00065 ipConstant(const ipConstant & other);
00066 virtual ~ipConstant();
00067
00068
00069
00070 void to_bottom();
00071 bool is_top() const;
00072 bool is_bottom() const;
00073
00074 inline const constant & value() const { return _value; }
00075 inline constant & value() { return _value; }
00076
00077 public:
00078
00079 inline void intern() { _internal = true; }
00080
00081 void assign(const ipConstant * other);
00082
00083
00084
00085 virtual bool diff(analysisVal * other) const;
00086
00087
00088
00089
00090
00091
00092
00093 virtual void meet_with(const analysisVal * other);
00094
00095
00096
00097 virtual void binary_operator(const Operator * op,
00098 const analysisVal * right_operand);
00099
00100 virtual void unary_operator(const Operator * op);
00101
00102 virtual void cast_operator(const typeNode * type);
00103
00104
00105
00106 void print(ostream & o);
00107
00108 };
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 typedef map< memoryDef *, ipConstant * > const_variables_map;
00119 typedef const_variables_map::iterator const_variables_map_p;
00120
00121 typedef map< constNode * , ipConstant * > constants_map;
00122 typedef constants_map::iterator constants_map_p;
00123
00124 typedef map< declNode * , ipConstant * > enums_map;
00125 typedef enums_map::iterator enums_map_p;
00126
00127 typedef set< ipConstant * > ipconstant_set;
00128 typedef ipconstant_set::iterator ipconstant_set_p;
00129
00130 #include "path.h"
00131
00132 class ipConstantPropagation : public analysisProblem
00133 {
00134 private:
00135
00136 const_variables_map _values;
00137 constants_map _constants;
00138 enums_map _enums;
00139 ipConstant * _top;
00140 ipConstant * _bottom;
00141 bool _debug;
00142
00143 ipconstant_set _deleted;
00144 int _count;
00145
00146 public:
00147
00148 ipConstantPropagation(bool debug = false)
00149 : _values(),
00150 _constants(),
00151 _top(new ipConstant()),
00152 _bottom(new ipConstant()),
00153 _debug(debug),
00154 _deleted(),
00155 _count(0)
00156 {
00157 _bottom->to_bottom();
00158 }
00159
00160
00161
00162
00163 virtual bool assignment(const Path * where,
00164 memoryDef * left_hand_side,
00165 analysisVal * right_hand_side,
00166 bool is_strong_update);
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 virtual analysisVal * lookup(memoryBlock * block, memoryUse * use);
00178 virtual analysisVal * lookup(constNode * con);
00179 virtual analysisVal * lookup(const string & field_name);
00180
00181
00182
00183 virtual void free(analysisVal * to_free);
00184
00185
00186
00187
00188 virtual analysisVal * top();
00189
00190
00191
00192
00193 virtual analysisVal * bottom();
00194
00195
00196
00197
00198
00199
00200
00201 virtual analysisVal * binary_operator(const Operator * op,
00202 const analysisVal * left_operand,
00203 const analysisVal * right_operand);
00204
00205 virtual analysisVal * unary_operator(const Operator * op,
00206 const analysisVal * operand);
00207
00208 virtual analysisVal * cast_operator(const typeNode * type,
00209 const analysisVal * operand);
00210
00211
00212
00213 void stats();
00214
00215 private:
00216
00217 void allocate(ipConstant * ic) {
00218 _count++;
00219
00220
00221
00222
00223
00224 }
00225
00226 ipConstant * clone(analysisVal * to_clone);
00227 };
00228
00229
00230 #endif // CBZ_IPCONSTANTS_H