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_MEMORYBLOCK_H
00038 #define CBZ_MEMORYBLOCK_H
00039
00040 #include "pointers_common.h"
00041 #include "location.h"
00042 #include "memoryaccess.h"
00043
00044 #include <set>
00045
00046
00047
00048
00049
00050
00051
00052 class memoryBlock;
00053
00054 typedef list< memoryBlock * > memoryblock_list;
00055 typedef memoryblock_list::iterator memoryblock_list_p;
00056
00057 typedef map< int, memoryBlock *, less< int > > component_map;
00058 typedef component_map::iterator component_map_p;
00059 typedef component_map::const_iterator component_map_cp;
00060
00061 class memoryBlock : public PerClassHeap< PointersHeap >
00062 {
00063 private:
00064
00067 REF const memoryBlock * _container;
00068
00076
00077 TREE orderedDefs Defs;
00078 TREE orderedUses Uses;
00079
00081
00088 REF memoryUse * _current_use;
00089
00099 REF memoryDef * _current_def;
00100
00103 component_map _components;
00104
00110 declNode * _decl;
00111
00118 bool _synthetic_decl;
00119
00126 procNode * _local_to;
00127
00134 bool _multiplicity;
00135
00141 bool _write_protected;
00142
00147 bool _is_array;
00148
00156 memoryDef * _initializer_def;
00157
00158 private:
00159
00160 friend class memoryModel;
00161
00168 memoryBlock(declNode * decl, bool synthetic,
00169 memoryBlock * container,
00170 procNode * local_to = 0);
00171
00177 ~memoryBlock();
00178
00179 public:
00180
00185 void clear();
00186
00187
00188
00189 declNode * decl() const { return _decl; }
00190 procNode * local_to() const { return _local_to; }
00191
00192 bool multiplicity() const { return _multiplicity; }
00193 void set_multiplicity() { _multiplicity = true; }
00194
00195 bool write_protected() const { return _write_protected; }
00196 void set_write_protected() { _write_protected = true; }
00197
00198 memoryUse * current_use() const { return _current_use; }
00199 memoryDef * current_def() const { return _current_def; }
00200
00201 void reset_current_def_use(Location * unused);
00202 void set_current_def_use(Location * where);
00203
00204
00205
00206 memoryDef * def_at(Location * where, bool & is_new);
00207 memoryDef * nearest_def_at(Location * where);
00208 memoryUse * use_at(Location * where);
00209 memoryDef * last_def_at(basicblockLocation * block);
00210 memoryDef * find_def_at(Location * where);
00211
00212 void set_current_to_nearest_def_at(Location * where);
00213
00214 void setup_merge_uses_at(basicblockLocation * merge_location,
00215 memoryDef * reaching_def,
00216 basicblock_set & predecessors);
00217
00218 void merge_uses_at(basicblockLocation * where,
00219 memoryuse_list & uses,
00220 bool computePointers);
00221
00222
00223
00224 void reachable_blocks(Location * where,
00225 memoryblock_list & worklist,
00226 memoryblock_set & already_seen,
00227 memoryBlock * null);
00228
00229
00230
00231 void prune_defs_uses();
00232
00233
00234
00235 void dot(const string & field_name,
00236 declNode * field_decl,
00237 memoryModel & Memory,
00238 memoryblock_set & results);
00239
00240
00241
00242 bool is_array() const { return _is_array; }
00243
00244 void set_array_element(memoryBlock * element);
00245
00246 memoryBlock * get_array_element();
00247
00248 memoryDef * setup_array_def();
00249
00250
00251
00252 bool in_scope(basicblockLocation * where) const;
00253
00254
00255
00256 friend ostream& operator<<(ostream & o, const memoryBlock & mb) {
00257
00258 return o;
00259 }
00260
00261
00262
00263
00264 typedef enum { NAME_ONLY, CURRENT_VALUE, AFTER_ASSIGNMENT, ALL_VALUES } Output_mode;
00265
00266 void print(ostream & o, Location * path, Output_mode mode = CURRENT_VALUE) const;
00267 string name() const;
00268
00269 void print_def_use(ostream & o) const;
00270
00271
00272
00273
00274 void update_def_use_chains();
00275
00276
00277
00278 static void stats();
00279 int num_defs() const { return Defs.size(); }
00280
00281 private:
00282
00283
00284
00285
00286
00287
00288 class FieldNameDB
00289 {
00290 private:
00291
00292 typedef map< string, int, less< string > > field_name_map;
00293 typedef field_name_map::iterator field_name_map_p;
00294
00295 field_name_map _fields;
00296 int _count;
00297
00298 public:
00299
00300 static int ArrayField;
00301
00302 FieldNameDB()
00303 : _fields(),
00304 _count(0)
00305 {}
00306
00307
00308
00309 int get_field(const string & name);
00310
00311
00312
00313 string field_name(int index);
00314 };
00315
00316 static FieldNameDB FieldNames;
00317 };
00318
00319
00320 #endif // CBZ_MEMORYBLOCK_H