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
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include <map>
00049 #include "FPcommon.h"
00050 #include "Nets.h"
00051 #include "Nodes.h"
00052 using namespace parquetfp;
00053
00054 Nets::Nets(char* baseName)
00055 {
00056 char basefile[1024];
00057 strcpy(basefile,baseName);
00058 char fname[1024];
00059 strcpy(fname,basefile);
00060 strcat(fname,".nets");
00061 parseNets(fname);
00062 initName2IdxMap();
00063 strcpy(fname,basefile);
00064 strcat(fname,".wts");
00065 parseWts(fname);
00066 }
00067
00068 void Nets::parseNets(char* fnameNets)
00069 {
00070 char block_name[1024];
00071 ifstream nets(fnameNets);
00072 char tempWord1[1024];
00073 char netName[1024];
00074 double poffsetX;
00075 double poffsetY;
00076 int netIndex = 0;
00077 int numNets = 0;
00078 int numPins;
00079 unsigned netDegree=0;
00080 unsigned netCtr=0;
00081 Net tempEdge;
00082
00083 if(!nets)
00084 {
00085 cout<<"ERROR: .nets file could not be opened successfully"<<endl;
00086 return;
00087 }
00088 skiptoeol(nets);
00089 while(!nets.eof())
00090 {
00091 nets>>tempWord1;
00092 if(!(strcmp(tempWord1,"NumNets")))
00093 break;
00094 }
00095 nets>>tempWord1;
00096 nets>>numNets;
00097 while(!nets.eof())
00098 {
00099 nets>>tempWord1;
00100 if(!(strcmp(tempWord1,"NumPins")))
00101 break;
00102 }
00103 nets>>tempWord1;
00104 nets>>numPins;
00105
00106 if(numNets > 0)
00107 {
00108 while(!nets.eof())
00109 {
00110 nets>>tempWord1;
00111 if(!(strcmp(tempWord1,"NetDegree")))
00112 break;
00113 }
00114 nets>>tempWord1;
00115 nets>>netDegree;
00116
00117 eatblank(nets);
00118 if(nets.peek() == '\n' || nets.peek() == '\r')
00119 {
00120 sprintf(netName,"N%d",netIndex);
00121 }
00122 else
00123 {
00124 nets>>netName;
00125 }
00126 skiptoeol(nets);
00127 tempEdge.putName(netName);
00128 }
00129
00130 eatblank(nets);
00131 if(nets.peek() == EOF)
00132 nets.get();
00133
00134 while(!nets.eof())
00135 {
00136 eatblank(nets);
00137 if(nets.eof())
00138 break;
00139 if(nets.peek()=='#')
00140 eathash(nets);
00141 else
00142 {
00143 eatblank(nets);
00144 if(nets.peek() == '\n' || nets.peek() == '\r' || nets.peek() == EOF)
00145 {
00146 nets.get();
00147 continue;
00148 }
00149
00150 nets>>block_name;
00151 nets>>tempWord1;
00152
00153 if(!strcmp(tempWord1,"B") || !strcmp(tempWord1,"O") ||
00154 !strcmp(tempWord1,"I"))
00155 {
00156 eatblank(nets);
00157
00158 if(nets.peek()=='\n' || nets.peek()=='\r' || nets.eof())
00159 {
00160 nets.get();
00161
00162 pin tempPin(block_name,true,0,0,netIndex);
00163 tempEdge.addNode(tempPin);
00164
00165 ++netCtr;
00166 continue;
00167 }
00168 else
00169 {
00170 nets>>tempWord1;
00171 if(!strcmp(tempWord1,":"))
00172 {
00173 eatblank(nets);
00174 }
00175 else
00176 cout << "error in parsing"<<endl;
00177
00178 if(nets.peek()!='%')
00179 {cout<<"expecting %"<<endl;}
00180 else
00181 {
00182 nets.get();
00183 nets>>poffsetX;
00184 eatblank(nets);
00185 nets.get();
00186 nets>>poffsetY;
00187 nets.get();
00188
00189 poffsetX /= 100;
00190 poffsetY /= 100;
00191
00192 pin tempPin(block_name,false,poffsetX,poffsetY,netIndex);
00193 tempEdge.addNode(tempPin);
00194
00195 ++netCtr;
00196 }
00197 }
00198 }
00199
00200 else if(!strcmp(block_name,"NetDegree"))
00201 {
00202 tempEdge.putIndex(netIndex);
00203 _nets.push_back(tempEdge);
00204
00205 if(netCtr != netDegree)
00206 {
00207 cout<<"ERROR in parsing .nets file. For net "<<tempEdge.getName()<<" netDegree do not match with no: of pins. "<<netCtr<<" vs "<<netDegree<<"\n"<<endl;
00208 }
00209 netCtr = 0;
00210 tempEdge.clean();
00211 netIndex++;
00212
00213 nets>>netDegree;
00214 eatblank(nets);
00215 if(nets.peek() == '\n' || nets.peek() == '\r')
00216 {
00217 sprintf(netName,"N%d",netIndex);
00218 }
00219 else
00220 {
00221 nets>>netName;
00222 }
00223 skiptoeol(nets);
00224 tempEdge.putName(netName);
00225 }
00226 }
00227 }
00228 nets.close();
00229
00230 if(numNets > 0)
00231 {
00232
00233 tempEdge.putIndex(netIndex);
00234 _nets.push_back(tempEdge);
00235 ++netIndex;
00236 }
00237
00238 if(netIndex != numNets)
00239 cout<<"Error in parsing .nets file. Number of nets do not tally "<<netIndex<<" vs "<<numNets<<endl;
00240
00241
00242 int actNumPins = getNumPins();
00243 if(numPins != actNumPins)
00244 {
00245 cout<<"Error in parsing .nets file. Number of pins do not tally "<<actNumPins<<" vs "<<numPins<<endl;
00246 }
00247 }
00248
00249
00250 void Nets::parseWts(char* fnameWts)
00251 {
00252 ifstream wts(fnameWts);
00253
00254 char netName[1024];
00255 double netWeight=1;
00256
00257 if(!wts)
00258 {
00259 cout<<"WARNING: .wts file could not be opened successfully"<<endl;
00260 return;
00261 }
00262
00263 skiptoeol(wts);
00264
00265 while(!wts.eof())
00266 {
00267 eatblank(wts);
00268 if(wts.eof())
00269 break;
00270 if(wts.peek()=='#')
00271 eathash(wts);
00272 else
00273 {
00274 eatblank(wts);
00275 if(wts.peek() == '\n' || wts.peek() == '\r' || wts.peek() == EOF)
00276 {
00277 wts.get();
00278 continue;
00279 }
00280 wts>>netName;
00281 wts>>netWeight;
00282 if(_name2IdxMap.find(netName) != _name2IdxMap.end())
00283 {
00284 unsigned idx = getIdxFrmName(netName);
00285 Net& net = getNet(idx);
00286 net.putWeight(netWeight);
00287 }
00288 else
00289 {
00290 cout<<"ERROR in parsing .wts file. Net "<<netName<<" has weight, but is not defined in .nets file"<<endl;
00291 }
00292
00293 }
00294 }
00295 wts.close();
00296 }
00297
00298 void Nets::updateNodeInfo(Nodes& nodes)
00299 {
00300 itNet net;
00301 itPin pin;
00302 itNode node;
00303
00304 map<const char*, int, ltstr> index;
00305 map<const char*, bool, ltstr> type;
00306
00307 for(node = nodes.nodesBegin(); node != nodes.nodesEnd(); node++)
00308 {
00309 index[node->getName()] = node->getIndex();
00310 type[node->getName()] = 0;
00311 }
00312 for(node = nodes.terminalsBegin(); node != nodes.terminalsEnd(); node++)
00313 {
00314 index[node->getName()] = node->getIndex();
00315 type[node->getName()] = 1;
00316 }
00317
00318 for(net = _nets.begin(); net != _nets.end(); net++)
00319 {
00320 for(pin = net->pinsBegin(); pin != net->pinsEnd(); pin++)
00321 {
00322 int thisIndex = index[pin->getName()];
00323 bool thisType = type[pin->getName()];
00324 pin->putNodeIndex(thisIndex);
00325 pin->putType(thisType);
00326
00327
00328 }
00329 }
00330 }
00331
00332 int Nets::getNumPins(void)
00333 {
00334 itNet net;
00335 int numPins = 0;
00336 for(net = netsBegin(); net != netsEnd(); ++net)
00337 {
00338 numPins += net->_pins.size();
00339 }
00340 return numPins;
00341 }
00342
00343 void Nets::putName2IdxEntry(const char* netName, int idx)
00344 {
00345 _name2IdxMap[netName] = idx;
00346 }
00347
00348 int Nets::getIdxFrmName(const char* netName)
00349 {
00350 return _name2IdxMap[netName];
00351 }
00352
00353 void Nets::initName2IdxMap(void)
00354 {
00355 unsigned netCtr=0;
00356 for(itNet net=netsBegin(); net != netsEnd(); ++net)
00357 {
00358 putName2IdxEntry(net->getName(), netCtr);
00359 ++netCtr;
00360 }
00361 }
00362