C-Breeze
C Compiler Infrastructure

[ Project home page]

memorymodel.h

Go to the documentation of this file.
00001 // $Id: memorymodel.h,v 1.20 2003/08/08 15:16:29 toktb Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2000 University of Texas at Austin
00008 // 
00009 //  Samuel Z. Guyer
00010 //  Daniel A. Jimenez
00011 //  Calvin Lin
00012 // 
00013 //  Permission is hereby granted, free of charge, to any person
00014 //  obtaining a copy of this software and associated documentation
00015 //  files (the "Software"), to deal in the Software without
00016 //  restriction, including without limitation the rights to use, copy,
00017 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00018 //  of the Software, and to permit persons to whom the Software is
00019 //  furnished to do so, subject to the following conditions:
00020 //  
00021 //  The above copyright notice and this permission notice shall be
00022 //  included in all copies or substantial portions of the Software.
00023 //  
00024 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00028 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00029 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00030 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00031 //  THE SOFTWARE.
00032 //
00033 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00034 //  Computer Science for inspiring parts of the C-Breeze design.
00035 //
00036 // ----------------------------------------------------------------------
00037 
00038 #ifndef CBZ_MEMORYMODEL_H
00039 #define CBZ_MEMORYMODEL_H
00040 
00041 #include "pointeroptions.h"
00042 #include "location.h"
00043 #include "unification.h" // TB_unify
00044 
00045 class memoryBlock;
00046 
00047 class memoryModel
00048 {
00049 public:
00050 
00051   typedef pair< Location *, declNode * > memorymodel_key;
00052 
00053   typedef map< memorymodel_key , memoryBlock *> memorymodel_map;
00054   typedef memorymodel_map::iterator memorymodel_map_p;
00055   typedef memorymodel_map::const_iterator memorymodel_map_cp;
00056 
00057   typedef map< procNode *, memorymodel_map > proc_memorymodel_map;
00058   typedef proc_memorymodel_map::iterator proc_memorymodel_map_p;
00059   typedef proc_memorymodel_map::const_iterator proc_memorymodel_map_cp;
00060 
00061   typedef pair< stmtNode *, declNode * > ci_memorymodel_key;
00062 
00063   typedef map< ci_memorymodel_key , memoryBlock *> ci_memorymodel_map;
00064   typedef ci_memorymodel_map::iterator ci_memorymodel_map_p;
00065   typedef ci_memorymodel_map::const_iterator ci_memorymodel_map_cp;
00066 
00067 
00068   typedef map< constNode *, memoryBlock *> string_constant_map;
00069   typedef string_constant_map::iterator string_constant_map_p;
00070 
00071 private:
00072 
00080   TREE proc_memorymodel_map _memory_blocks;
00081 
00088   TREE ci_memorymodel_map _ci_memory_blocks;
00089 
00095   string_constant_map _string_constants;
00096 
00099   int Counter;
00100 
00103   memoryBlock * Null;
00104 
00110   memoryBlock * _string_constant;
00111 
00113   UnificationBasedPtr *_unification_based; // TB_unify
00114 
00116   map<declNode*,declNode*> _copy_decl; // TB_unify
00117   
00118 public:
00119 
00123   memoryModel();
00124 
00130   ~memoryModel();
00131 
00136   void clear();
00137 
00140   int size();
00141 
00144   // const memorymodel_map & memory_blocks() const { return _memory_blocks; }
00145 
00148   memoryBlock * null() const { return Null; }
00149  // TB_unify
00151 
00152   inline UnificationBasedPtr *unification() const { return _unification_based; }
00153 
00156   inline void unification(UnificationBasedPtr *u) { _unification_based=u; }
00157 
00162   static bool is_in_non_unify_list(UnifyTypes & non_unify_types,
00163                                    UnifyType *obj);
00164 
00165 
00170   memoryBlock * lookup(Location * location, declNode * decl);
00171 
00176   memoryBlock * lookup(stmtNode * location, declNode * decl);
00177 
00184   memoryBlock * lookup_variable(Location * location,
00185                                 declNode * decl,
00186                                 procNode * local_to);
00187 
00194   memoryBlock * lookup_heap_object(const string & name,
00195                                    stmtLocation * allocation_site,
00196                                    stmtNode * allocation_stmt,
00197                                    declNode * decl,
00198                                    bool synthetic_decl);
00199 
00204   memoryBlock * lookup_string_constant(constNode * the_string);
00205 
00216   memoryBlock * generate_su_field(const string & field_name,
00217                                   declNode * field_decl,
00218                                   memoryBlock * container);
00219 
00225   void update_def_use_chains();
00226 
00231   int counter() { Counter++; return Counter; }
00232 
00235   void stats(ostream & out);
00236 
00237   void print(ostream & o) const;
00238 
00239 private:
00240 
00257   memoryBlock * create_memory_object(Location * location,
00258                                      declNode * decl,
00259                                      bool synthetic_decl,
00260                                      memoryBlock * container,
00261                                      procNode * local_to,
00262                                      declNode * org_field_decl = 0,
00263                                      bool is_alloc = false,
00264                                      bool is_array_elt = false);
00265 
00270   memoryBlock * create_memory_object(stmtNode * location,
00271                                      declNode * decl,
00272                                      bool synthetic_decl,
00273                                      memoryBlock * container,
00274                                      procNode * local_to,
00275                                      bool is_alloc = false);
00276 
00294   void generate_array_elements_for(memoryBlock * array_object);
00295 
00296 
00301   void initialize_struct(memoryBlock * struct_object,
00302                          sueNode * sue_type,
00303                          expr_list & inits);
00304 };
00305 
00306 #endif // 

Generated on February 1, 2006
Back to the C-Breeze home page