WhirlIDMaps.h

Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/WhirlIDMaps.h,v 1.12 2005/05/16 15:17:39 eraxxon Exp $
00003 
00004 // * BeginCopyright *********************************************************
00005 // *********************************************************** EndCopyright *
00006 
00007 //***************************************************************************
00008 //
00009 // File:
00010 //   $Source: /Volumes/cvsrep/developer/OpenADFortTk/src/WhirlIDMaps.h,v $
00011 //
00012 // Purpose:
00013 //   [The purpose of this file]
00014 //
00015 // Description:
00016 //   [The set of functions, macros, etc. defined in the file]
00017 //
00018 //***************************************************************************
00019 
00020 #ifndef WhirlIDMaps_INCLUDED_h
00021 #define WhirlIDMaps_INCLUDED_h
00022 
00023 //************************* System Include Files ****************************
00024 
00025 #include <iostream>
00026 #include <map>  // STL
00027 #include <set>  // STL
00028 #include <list> // STL
00029 
00030 //************************** Open64 Include Files ***************************
00031 
00032 #include "Open64IRInterface/Open64BasicTypes.h"
00033 
00034 //*************************** User Include Files ****************************
00035 
00036 #include "BaseMap.h"
00037 #include "Diagnostics.h"
00038 
00039 //************************** Forward Declarations ***************************
00040 
00041 namespace fortTkSupport { 
00042 
00043 typedef UINT SymTabId;
00044 typedef UINT SymId;
00045 typedef UINT PUId;
00046 typedef UINT WNId;
00047 
00048 //***************************************************************************
00049 
00050 // A list of ids: Should only be used with scalar id types above
00051 template <class T>
00052 class IdList : public std::list<T> {
00053 public:
00054   IdList() { }
00055   ~IdList() { }
00056 
00057   // Returns 0 if not found
00058   T Find(T id) const
00059   {
00060     typename std::list<T>::iterator it;
00061     for (it = this->begin(); it != this->end(); ++it) {
00062       T val = *it;
00063       if (id == val) { return val; }
00064     }
00065     return 0;
00066   }
00067   
00068 };
00069 
00070 
00071 //***************************************************************************
00072 // ST_TAB <-> SymTabId maps (global/interprocedural)
00073 //***************************************************************************
00074 
00075 class SymTabToSymTabIdMap 
00076   : public BaseMap<ST_TAB*, SymTabId>
00077 {
00078 public:
00079   SymTabToSymTabIdMap() { }
00080   SymTabToSymTabIdMap(PU_Info* pu_forest) { Create(pu_forest); }
00081   virtual ~SymTabToSymTabIdMap() { }
00082   
00083   void Create(PU_Info* pu_forest);
00084 };
00085 
00086 
00087 // SymTabIdToSymTabMap: In WHIRL, all ST_TAB* are associated with a
00088 // specific PU_Info*, except the global ST_TAB*.  Because of the way
00089 // the symbol table is implemented, it is usually not easy to access the
00090 // symbol table with the ST_TAB*: one needs the corresponding
00091 // PU_Info*.  Consequently, we map a SymTabId to a pair.  When
00092 // entering the global the global ST_TAB* in the map, PU_Info* should
00093 // be NULL.
00094 class SymTabIdToSymTabMap 
00095   : public std::map<SymTabId, pair<ST_TAB*, PU_Info*> > {
00096 
00097 protected:
00098   typedef std::map<SymTabId, pair<ST_TAB*, PU_Info*> > BaseMap;
00099   
00100 public:
00101   SymTabIdToSymTabMap() { }
00102   SymTabIdToSymTabMap(PU_Info* pu_forest) { Create(pu_forest); }
00103   virtual ~SymTabIdToSymTabMap() { }
00104   
00105   pair<ST_TAB*, PU_Info*>
00106   Find(SymTabId id, bool mustFind = false) const
00107   {
00108     pair<ST_TAB*, PU_Info*> result(NULL, NULL);
00109     
00110     const_iterator it = this->find(id);
00111     if (it != this->end()) {
00112       result = (*it).second;
00113     } 
00114     else if (mustFind) {
00115       FORTTK_DIE("SymTabIdToSymTabMap: Could not find entry for key '" 
00116                  << id << "'");
00117     }
00118     
00119     return result;
00120   }
00121 
00122   void
00123   Insert(SymTabId id, ST_TAB* stab, PU_Info* pu)
00124   {
00125     this->insert(make_pair(id, make_pair(stab, pu))); // do not add duplicates!
00126   }
00127 
00128   void Create(PU_Info* pu_forest);
00129 };
00130 
00131 
00132 //***************************************************************************
00133 // ST <-> SymId maps (intra-procedural)
00134 //***************************************************************************
00135 
00136 // Note: Instead of creating ST* <-> to SymId maps, we currently use a
00137 // ST's index -- ST_index(ST*) -- in the symbol table as a persistent
00138 // id.  While this is correct, it would be nice to add an interface
00139 // map, even if the map is really only the identity function without
00140 // any state.
00141 
00142 
00143 //***************************************************************************
00144 // PU <-> PUId maps (global/interprocedural)
00145 //***************************************************************************
00146 
00147 class PUToPUIdMap 
00148   : public BaseMap<PU_Info*, PUId>
00149 {
00150 public:  
00151   PUToPUIdMap() { }
00152   PUToPUIdMap(PU_Info* pu_forest) { Create(pu_forest); }
00153   virtual ~PUToPUIdMap() { }
00154 
00155   void Create(PU_Info* pu_forest);
00156 };
00157 
00158 
00159 class PUIdToPUMap
00160   : public BaseMap<PUId, PU_Info*>
00161 {
00162 public:
00163   PUIdToPUMap() { }
00164   PUIdToPUMap(PU_Info* pu_forest) { Create(pu_forest); }
00165   virtual ~PUIdToPUMap() { }
00166   
00167   void Create(PU_Info* pu_forest);
00168 };
00169 
00170 
00171 //***************************************************************************
00172 // WNId <-> WN map
00173 //***************************************************************************
00174 
00175 class WNToWNIdMap 
00176   : public BaseMap<WN*, WNId>
00177 {
00178 public:  
00179   WNToWNIdMap() { }
00180   WNToWNIdMap(WN* wn) { Create(wn); }
00181   virtual ~WNToWNIdMap() { }
00182 
00183   void Create(WN* wn);
00184 };
00185 
00186 class WNIdToWNMap 
00187   : public BaseMap<WNId, WN*>
00188 {
00189 public:
00190   WNIdToWNMap() { }
00191   WNIdToWNMap(WN* wn) { Create(wn); }
00192   virtual ~WNIdToWNMap() { }
00193   
00194   void Create(WN* wn);
00195 };
00196 
00197 
00198 // ---------------------------------------------------------
00199 // 
00200 // ---------------------------------------------------------
00201 
00202 // Note: Assumes ownership of the tables it creates
00203 class WNToWNIdTabMap 
00204   : public BaseMap<PU_Info*, WNToWNIdMap*> {
00205   
00206 public:
00207   WNToWNIdTabMap() { }
00208   WNToWNIdTabMap(PU_Info* pu_forest) { Create(pu_forest); }
00209   virtual ~WNToWNIdTabMap();
00210   
00211   void Create(PU_Info* pu_forest);
00212   void Destroy();
00213 };
00214 
00215 class WNIdToWNTabMap 
00216   : public BaseMap<PU_Info*, WNIdToWNMap*> {
00217   
00218 public:
00219   WNIdToWNTabMap() { }
00220   WNIdToWNTabMap(PU_Info* pu_forest) { Create(pu_forest); }
00221   virtual ~WNIdToWNTabMap();
00222   
00223   void Create(PU_Info* pu_forest);
00224   void Destroy();
00225 };
00226 
00227 
00228 //***************************************************************************
00229 // Optional routines for map creation
00230 //***************************************************************************
00231 
00232 // CreateSymTabIdMaps: Given a PU forest, initialize the non-NULL
00233 // persistent ID <-> ST_TAB* maps.  STTABIds are guaranteed to be
00234 // unique within the PU forest 'pu_forest'. (The global symbol table
00235 // is included.)
00236 void
00237 CreateSymTabIdMaps(PU_Info* pu_forest, 
00238                    SymTabToSymTabIdMap* x, SymTabIdToSymTabMap* y);
00239 
00240 // CreatePUIdMaps: Given a PU forest, initialize the non-NULL
00241 // persistent ID <-> PU_Info* maps.  PUIds are guaranteed to be unique
00242 // within the PU forest 'pu_forest'.
00243 void
00244 CreatePUIdMaps(PU_Info* pu_forest, PUToPUIdMap* x, PUIdToPUMap* y);
00245 
00246 // CreateWhirlIDMaps: Given a WN*, initialize the non-NULL persistent
00247 // ID <-> WN* maps.  WNIds are guaranteed to be unique within the
00248 // WHIRL tree rooted at 'wn'. (Note that 'wn' is usually the result of
00249 // PU_Info_tree_ptr(PU_Info*).)
00250 void
00251 CreateWhirlIdMaps(WN* wn, WNToWNIdMap* x, WNIdToWNMap* y);
00252 
00253 
00254 //***************************************************************************
00255 
00256 }
00257 
00258 #endif /* WhirlIDMaps_INLUCDED_h */

Generated on Fri Jul 24 04:29:07 2009 for OpenADFortTk (extended to Open64) by  doxygen 1.5.7.1