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
00038 #ifndef CBZ_IPCONSTANTS_H
00039 #define CBZ_IPCONSTANTS_H
00040
00041 #include "pointers.h"
00042 #include "ipanalysis.h"
00043
00044
00045
00046
00047
00055 class ipConstant : public analysisVal
00056 {
00057 friend class ipConstantPropagation;
00058 friend class ipConstantsChanger;
00059
00060 private:
00061
00062 constant _value;
00063 bool _top;
00064 bool _internal;
00065
00066 ipConstant(constant & value);
00067 ipConstant();
00068 ipConstant(const ipConstant & other);
00069 virtual ~ipConstant();
00070
00075
00076 void to_bottom();
00077 bool is_top() const;
00078 bool is_bottom() const;
00079
00080 inline const constant & value() const { return _value; }
00081 inline constant & value() { return _value; }
00082
00085 public:
00086
00087 inline void intern() { _internal = true; }
00088
00089 void assign(const ipConstant * other);
00090
00092 virtual bool diff(analysisVal * other) const;
00093
00094
00102 virtual void meet_with(const analysisVal * other);
00103
00108 virtual void binary_operator(const Operator * op,
00109 const analysisVal * right_operand);
00110
00111 virtual void unary_operator(const Operator * op);
00112
00113 virtual void cast_operator(const typeNode * type);
00116
00117 void print(ostream & o);
00118
00119 };
00120
00121
00122
00123
00124
00125 typedef map< memoryDef *, ipConstant * > const_variables_map;
00126 typedef const_variables_map::iterator const_variables_map_p;
00127
00128 typedef map< constNode * , ipConstant * > constants_map;
00129 typedef constants_map::iterator constants_map_p;
00130
00131 typedef map< declNode * , ipConstant * > enums_map;
00132 typedef enums_map::iterator enums_map_p;
00133
00134 typedef set< ipConstant * > ipconstant_set;
00135 typedef ipconstant_set::iterator ipconstant_set_p;
00136
00137 #include "path.h"
00138
00145 class ipConstantPropagation : public analysisProblem
00146 {
00147 private:
00148
00149 const_variables_map _values;
00150 constants_map _constants;
00151 enums_map _enums;
00152 ipConstant * _top;
00153 ipConstant * _bottom;
00154 bool _debug;
00155
00156 ipconstant_set _deleted;
00157 int _count;
00158
00159 public:
00160
00161 ipConstantPropagation(bool debug = false)
00162 : _values(),
00163 _constants(),
00164 _top(new ipConstant()),
00165 _bottom(new ipConstant()),
00166 _debug(debug),
00167 _deleted(),
00168 _count(0)
00169 {
00170 _bottom->to_bottom();
00171 }
00172
00174 virtual bool assignment(const Path * where,
00175 memoryDef * left_hand_side,
00176 analysisVal * right_hand_side,
00177 bool is_strong_update);
00178
00188 virtual analysisVal * lookup(memoryBlock * block, memoryUse * use);
00189 virtual analysisVal * lookup(constNode * con);
00190 virtual analysisVal * lookup(const string & field_name);
00193
00194 virtual void free(analysisVal * to_free);
00195
00200 virtual analysisVal * top();
00201
00206 virtual analysisVal * bottom();
00207
00218 virtual analysisVal * binary_operator(const Operator * op,
00219 const analysisVal * left_operand,
00220 const analysisVal * right_operand);
00221
00222 virtual analysisVal * unary_operator(const Operator * op,
00223 const analysisVal * operand);
00224
00225 virtual analysisVal * cast_operator(const typeNode * type,
00226 const analysisVal * operand);
00227
00230
00231 void stats();
00232
00233 private:
00234
00235 void allocate(ipConstant * ic) {
00236 _count++;
00237
00238
00239
00240
00241
00242 }
00243
00244 ipConstant * clone(analysisVal * to_clone);
00245 };
00246
00247
00248 #endif // CBZ_IPCONSTANTS_H