WhirlIDMaps.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "Open64IRInterface/Open64IRInterface.hpp"
00025 #include "WhirlIDMaps.h"
00026
00027
00028
00029 namespace fortTkSupport {
00030
00031
00032
00033
00034
00035 void
00036 SymTabToSymTabIdMap::Create(PU_Info* pu_forest)
00037 {
00038 CreateSymTabIdMaps(pu_forest, this, NULL);
00039 }
00040
00041 void
00042 SymTabIdToSymTabMap::Create(PU_Info* pu_forest)
00043 {
00044 CreateSymTabIdMaps(pu_forest, NULL, this);
00045 }
00046
00047
00048
00049
00050
00051 void
00052 PUToPUIdMap::Create(PU_Info* pu_forest)
00053 {
00054 CreatePUIdMaps(pu_forest, this, NULL);
00055 }
00056
00057 void
00058 PUIdToPUMap::Create(PU_Info* pu_forest)
00059 {
00060 CreatePUIdMaps(pu_forest, NULL, this);
00061 }
00062
00063
00064
00065
00066
00067 void
00068 WNToWNIdMap::Create(WN* wn)
00069 {
00070 CreateWhirlIdMaps(wn, this, NULL);
00071 }
00072
00073 void
00074 WNIdToWNMap::Create(WN* wn)
00075 {
00076 CreateWhirlIdMaps(wn, NULL, this);
00077 }
00078
00079
00080 WNToWNIdTabMap::~WNToWNIdTabMap()
00081 {
00082 Destroy();
00083 }
00084
00085 void
00086 WNToWNIdTabMap::Create(PU_Info* pu_forest)
00087 {
00088 Open64IRProcIterator procIt(pu_forest);
00089 for ( ; procIt.isValid(); ++procIt) {
00090 PU_Info* pu = (PU_Info*)procIt.current().hval();
00091 WN* wn_pu = PU_Info_tree_ptr(pu);
00092 WNToWNIdMap* tab = new WNToWNIdMap(wn_pu);
00093 #if 0
00094 ST* pu_st = ST_ptr(PU_Info_proc_sym(pu));
00095 const char* pu_name = ST_name(pu_st);
00096 std::cout << "JU: WNToWNIdTabMap::Create (" << tab << ") for " << pu_name << std::endl;
00097 #endif
00098 Insert(pu, tab);
00099 }
00100 }
00101
00102 void
00103 WNToWNIdTabMap::Destroy()
00104 {
00105 for (iterator it = begin(); it != end(); ++it) {
00106 delete (*it).second;
00107 }
00108 clear();
00109 }
00110
00111
00112 WNIdToWNTabMap::~WNIdToWNTabMap()
00113 {
00114 Destroy();
00115 }
00116
00117 void
00118 WNIdToWNTabMap::Create(PU_Info* pu_forest)
00119 {
00120 Open64IRProcIterator procIt(pu_forest);
00121 for ( ; procIt.isValid(); ++procIt) {
00122 PU_Info* pu = (PU_Info*)procIt.current().hval();
00123 WN* wn_pu = PU_Info_tree_ptr(pu);
00124 WNIdToWNMap* tab = new WNIdToWNMap(wn_pu);
00125 #if 0
00126 ST* pu_st = ST_ptr(PU_Info_proc_sym(pu));
00127 const char* pu_name = ST_name(pu_st);
00128 std::cout << "JU: WNIdToWNTabMap::Create (" << tab << ") for " << pu_name << std::endl;
00129 #endif
00130 Insert(pu, tab);
00131 }
00132 }
00133
00134 void
00135 WNIdToWNTabMap::Destroy()
00136 {
00137 for (iterator it = begin(); it != end(); ++it) {
00138 delete (*it).second;
00139 }
00140 clear();
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150 void
00151 CreateSymTabIdMaps(PU_Info* pu_forest,
00152 SymTabToSymTabIdMap* x, SymTabIdToSymTabMap* y)
00153 {
00154 static UINT nextId = 0;
00155
00156
00157 ++nextId;
00158 if (x) {
00159 x->Insert(Scope_tab[GLOBAL_SYMTAB].st_tab, nextId);
00160 }
00161 if (y) {
00162 y->Insert(nextId, Scope_tab[GLOBAL_SYMTAB].st_tab, NULL);
00163 }
00164
00165
00166 Open64IRProcIterator procIt(pu_forest);
00167 for ( ; procIt.isValid(); ++procIt) {
00168 PU_Info* pu = (PU_Info*)procIt.current().hval();
00169
00170 ++nextId;
00171 if (x) {
00172 x->Insert(Scope_tab[CURRENT_SYMTAB].st_tab, nextId);
00173 }
00174 if (y) {
00175 y->Insert(nextId, Scope_tab[GLOBAL_SYMTAB].st_tab, pu);
00176 }
00177 }
00178 }
00179
00180
00181
00182 void
00183 CreatePUIdMaps(PU_Info* pu_forest, PUToPUIdMap* x, PUIdToPUMap* y)
00184 {
00185 static UINT nextId = 0;
00186
00187
00188 Open64IRProcIterator procIt(pu_forest);
00189 for ( ; procIt.isValid(); ++procIt) {
00190 PU_Info* pu = (PU_Info*)procIt.current().hval();
00191
00192 ++nextId;
00193 if (x) {
00194 x->Insert(pu, nextId);
00195 }
00196 if (y) {
00197 y->Insert(nextId, pu);
00198 }
00199 }
00200 }
00201
00202
00203 void
00204 CreateWhirlIdMaps(WN* wn, WNToWNIdMap* x, WNIdToWNMap* y)
00205 {
00206
00207
00208
00209 UINT nextId = 0;
00210
00211
00212 WN_TREE_CONTAINER<PRE_ORDER> wtree(wn);
00213 WN_TREE_CONTAINER<PRE_ORDER>::iterator it;
00214
00215 for (it = wtree.begin(); it != wtree.end(); ++it) {
00216 WN* curWN = it.Wn();
00217 UINT curId = ++nextId;
00218
00219 if (x) {
00220 x->Insert(curWN, curId);
00221 #if 0
00222 std::cout << " JU: CreateWhirlIdMaps (" << x <<"): " << curWN << "(";
00223 Open64IRInterface::DumpWN(curWN,std::cout);
00224 std::cout << ")->" << curId << std::endl;
00225 #endif
00226 }
00227 if (y) {
00228 y->Insert(curId, curWN);
00229 #if 0
00230 std::cout << " JU: CreateWhirlIdMaps (" << y <<"): " << curId << "->" << curWN << "(";
00231 Open64IRInterface::DumpWN(curWN,std::cout);
00232 std::cout << ")" << std::endl;
00233 #endif
00234 }
00235 }
00236 }
00237
00238
00239
00240 }