|
OpenADFortTk (basic)
|
00001 // -*-Mode: C++;-*- 00002 // Description: 00003 // 00004 // A WHIRL PU -- program unit, representing a procedure or function 00005 // -- is not a self-contained encapsulation. For example, it does 00006 // not own its own scoped symbol table; instead, the latter resides 00007 // in a *global* variable named Scope_tab[]. When working at the 00008 // intra-procedural level this is not a problem, but when performing 00009 // inter-procedural tasks it is a great inconvenience. This is 00010 // because nodes in the WHIRL tree contain symbol table indices, not 00011 // pointers. If the tables in the global Scope_tab[] do not 00012 // correspond to the current PU, then the WHIRL for that PU contains 00013 // bogus symbol table indices. Thus, when writing inter-procedural 00014 // routines, the global symbol table variables must be *manually 00015 // set* to point to the correct tables. The following scheme models 00016 // that used in Open64's inter-procedural analysis. The main 00017 // difference and advantage is that it is *separate* from the IPA 00018 // and can thus be used any time one wishes to work with multiple 00019 // PUs. 00020 // 00021 // The basic scheme is to create a scoped symbol table for each PU 00022 // and store this in a PU->scope_symbol_table map. This map is 00023 // automatically populated by the WHIRL reader. Although the map 00024 // can be queried, users will most often prepare the global state 00025 // for a given pu by calling PU_SetGlobalState(pu). 00026 // 00027 // (Note: It would be preferable to have a PU_Info* store its own 00028 // lexical scope table. This would require moderate revisions of 00029 // Open64, would would clean up some exceedingly ugly code.) 00030 // 00031 //*************************************************************************** 00032 00033 #ifndef WhirlGlobalStateUtils_INCLUDED_h 00034 #define WhirlGlobalStateUtils_INCLUDED_h 00035 00036 //************************* System Include Files **************************** 00037 00038 #include <iostream> 00039 #include <map> // STL 00040 00041 //************************** Open64 Include Files *************************** 00042 00043 #include "Open64BasicTypes.h" 00044 00045 //*************************** User Include Files **************************** 00046 00047 //************************** Forward Declarations *************************** 00048 00049 class PUToScopedSymTabMap; 00050 00051 // The global map of PU_Info* to lexical scope tables (SCOPE*). It 00052 // assumes ownership of all scope tables inserted into it. 00053 extern PUToScopedSymTabMap PUToScopeTabMap; 00054 00055 //*************************************************************************** 00056 00057 // PU_SetGlobalState: Restores all global state for 'pu'. This 00058 // function may be called as many times as neceessary. 00059 // - Current_Map_Tab 00060 // - Current_pu 00061 // - Current_PU_Info 00062 // - CURRENT_SYMTAB == Current_scope 00063 // - Scope_tab 00064 void 00065 PU_SetGlobalState(PU_Info* pu); 00066 00067 00068 // PU_AllocBEGlobalSymtab, PU_FreeBEGlobalSymtab: Allocate and free 00069 // the back end *global* symbol tables. These routines *must* be paired. 00070 void 00071 PU_AllocBEGlobalSymtab(); 00072 void 00073 PU_FreeBEGlobalSymtab(); 00074 00075 // PU_AllocBELocalSymtab, PU_FreeBELocalSymtab: Allocate and free 00076 // the back end *local* symbol tables for the pu and all of its 00077 // children. For a given PU, these routines *must* be paired. 00078 void 00079 PU_AllocBELocalSymtab(PU_Info* pu); 00080 void 00081 PU_FreeBELocalSymtab(PU_Info* pu); 00082 00083 //*************************************************************************** 00084 00085 namespace WhirlGlobalStateUtils_hidden { 00086 00087 typedef std::map<PU_Info*, SCOPE*> PUToScopedSymTabBaseMap; 00088 00089 00090 // Save global state so that it can be restored with 00091 // PU_SetGlobalState(). Assumes that all global state for 'pu' 00092 // is correctly set. This should only be called *once* for each PU. 00093 void 00094 PU_SaveGlobalState(PU_Info* pu); 00095 00096 }; /* namespace WhirlGlobalStateUtils_hidden */ 00097 00098 00099 class PUToScopedSymTabMap 00100 : public WhirlGlobalStateUtils_hidden::PUToScopedSymTabBaseMap { 00101 00102 public: 00103 00104 PUToScopedSymTabMap(); 00105 ~PUToScopedSymTabMap(); 00106 00107 SCOPE* 00108 Find(PU_Info* pu) 00109 { 00110 using namespace WhirlGlobalStateUtils_hidden; 00111 00112 SCOPE* result = 0; 00113 00114 PUToScopedSymTabBaseMap::iterator it = this->find(pu); 00115 if (it != this->end()) { 00116 result = (*it).second; 00117 } 00118 00119 return result; 00120 } 00121 00122 void 00123 Insert(PU_Info* pu, SCOPE* symtab) 00124 { 00125 this->insert(make_pair(pu, symtab)); // do not add duplicates! 00126 } 00127 00128 }; 00129 00130 //*************************************************************************** 00131 00132 #endif /* WhirlGlobalStateUtils_INCLUDED_h */