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 #include "netlist.h"
00036 #include "basepacking.h"
00037 #include "parsers.h"
00038
00039 #include <iostream>
00040 #include <fstream>
00041 #include <float.h>
00042 #include <algorithm>
00043 using namespace std;
00044 using namespace parse_utils;
00045 using namespace basepacking_h;
00046
00047
00048 double NetType::getHPWL(const OrientedPacking& pk) const
00049 {
00050 double minX = Dimension::INFTY;
00051 double maxX = -1 * Dimension::INFTY;
00052 double minY = Dimension::INFTY;
00053 double maxY = -1 * Dimension::INFTY;
00054
00055 for (unsigned int i = 0; i < in_pads.size(); i++)
00056 {
00057 double xloc = in_pads[i].xloc;
00058 double yloc = in_pads[i].yloc;
00059
00060 minX = min(minX, xloc);
00061 maxX = max(maxX, xloc);
00062 minY = min(minY, yloc);
00063 maxY = max(maxY, yloc);
00064
00065 }
00066
00067 for (unsigned int i = 0; i < in_pins.size(); i++)
00068 {
00069 double orig_x_offset = in_pins[i].x_offset;
00070 double orig_y_offset = in_pins[i].y_offset;
00071
00072 int blk_index = in_pins[i].block;
00073 OrientedPacking::ORIENT blk_orient = pk.orient[blk_index];
00074
00075 double x_length = (blk_orient % 2 == 0)?
00076 pk.width[blk_index] : pk.height[blk_index];
00077 double y_length = (blk_orient % 2 == 0)?
00078 pk.height[blk_index] : pk.width[blk_index];
00079
00080 double x_offset = -1;
00081 double y_offset = -1;
00082 getOffsets(orig_x_offset, orig_y_offset, blk_orient,
00083 x_offset, y_offset);
00084
00085 double xloc = pk.xloc[blk_index] + (x_length / 2) + x_offset;
00086 double yloc = pk.yloc[blk_index] + (y_length / 2) + y_offset;
00087
00088 minX = min(minX, xloc);
00089 maxX = max(maxX, xloc);
00090 minY = min(minY, yloc);
00091 maxY = max(maxY, yloc);
00092
00093
00094
00095 }
00096
00097
00098
00099 return ((maxX - minX) + (maxY - minY));
00100 }
00101
00102 void NetListType::ParsePl(ifstream& infile,
00103 const HardBlockInfoType& blockinfo)
00104 {
00105 in_all_pads.clear();
00106
00107 ofstream outfile;
00108 outfile.open("dummy_pl");
00109
00110 string line;
00111 int objCount = 0;
00112 for (int lineCount = 0;
00113 getline(infile, line); lineCount++)
00114 {
00115 char name[100];
00116 double xloc, yloc;
00117
00118 outfile << line << endl;
00119 if (sscanf(line.c_str(), "%s %lf %lf",
00120 name, &xloc, &yloc) == 3)
00121 {
00122 if (objCount >= blockinfo.blocknum())
00123 {
00124 PadInfoType temp_pad;
00125 temp_pad.pad_name = name;
00126 temp_pad.xloc = xloc;
00127 temp_pad.yloc = yloc;
00128
00129 in_all_pads.push_back(temp_pad);
00130 }
00131 objCount++;
00132 }
00133 }
00134 }
00135
00136 void NetListType::ParseNets(ifstream& infile,
00137 const HardBlockInfoType& blockinfo)
00138 {
00139 string line;
00140 int numNets = -1;
00141 int numPins = -1;
00142 if(!infile.good())
00143 {
00144 cout << "ERROR: .nets file could not be opened successfully" << endl;
00145 exit(1);
00146 }
00147
00148
00149 getline(infile, line);
00150 while(getline(infile, line))
00151 {
00152 char first_word[100];
00153 char ch;
00154
00155 if ((sscanf(line.c_str(), "%s %c %d",
00156 first_word, &ch, &numNets) == 3) &&
00157 !strcmp(first_word, "NumNets"))
00158 break;
00159
00160 }
00161
00162 if (!infile.good())
00163 {
00164 cout << "ERROR in reading .net file (# nets)." << endl;
00165 exit(1);
00166 }
00167
00168
00169 while(getline(infile, line))
00170 {
00171 char first_word[100];
00172 char ch;
00173
00174 if ((sscanf(line.c_str(), "%s %c %d",
00175 first_word, &ch, &numPins) == 3) &&
00176 !strcmp(first_word, "NumPins"))
00177 break;
00178 }
00179
00180 if (!infile.good())
00181 {
00182 cout << "ERROR in reading .net file (# pins)." << endl;
00183 exit(1);
00184 }
00185
00186
00187
00188 int netDegree = -1;
00189 int degreeCount = 0;
00190 int pinCount = 0;
00191 vector<NetType::PadType> netPads;
00192 vector<NetType::PinType> netPins;
00193 for (int lineCount = 0; infile.good(); lineCount++)
00194 {
00195 char dummy_word[1000];
00196 char block_name[1000];
00197 char dummy_chars[100];
00198 int number;
00199 double x_percent, y_percent;
00200
00201 getline(infile, line);
00202 if (sscanf(line.c_str(), "%s", dummy_word) < 1)
00203 {
00204
00205 if (infile.eof())
00206 {
00207
00208 int degreeCount = netPins.size() + netPads.size();
00209 if (degreeCount == netDegree)
00210 {
00211 NetType temp(netPins, netPads);
00212 in_nets.push_back(temp);
00213
00214 degreeCount = 0;
00215 netPins.clear();
00216 netPads.clear();
00217 }
00218 else
00219 {
00220 printf("ERROR: netDegree in net %d does not tally\n",
00221 in_nets.size());
00222 exit(1);
00223 }
00224 }
00225 }
00226 else if ((sscanf(line.c_str(), "%c", dummy_chars+0) == 1) &&
00227 dummy_chars[0] == '#')
00228 { }
00229 else if (sscanf(line.c_str(), "%s %c %c %c%lf %c%lf",
00230 block_name, dummy_chars+0, dummy_chars+1,
00231 dummy_chars+2, &x_percent,
00232 dummy_chars+3, &y_percent) == 7)
00233 {
00234
00235 int index = get_index(string(block_name), blockinfo);
00236 if (index == -1)
00237 {
00238 printf("ERROR: Unrecognized block \"%s\"\n", block_name);
00239 exit(1);
00240 }
00241 else
00242 {
00243 x_percent /= 100;
00244 y_percent /= 100;
00245
00246 NetType::PinType temp;
00247 temp.block = index;
00248 temp.x_offset = (blockinfo[index].width[0] * x_percent) / 2;
00249 temp.y_offset = (blockinfo[index].height[0] * y_percent) / 2;
00250
00251
00252
00253 netPins.push_back(temp);
00254 degreeCount++;
00255 pinCount++;
00256 }
00257 }
00258 else if (sscanf(line.c_str(), "%s %c %d",
00259 dummy_word, dummy_chars+0, &number) == 3)
00260 {
00261 if (!strcmp(dummy_word, "NetDegree"))
00262 {
00263
00264 if (netDegree == -1)
00265 netDegree = number;
00266 else if (degreeCount == netDegree)
00267 {
00268 NetType temp(netPins, netPads);
00269 in_nets.push_back(NetType(netPins, netPads));
00270
00271 netDegree = number;
00272 degreeCount = 0;
00273 netPins.clear();
00274 netPads.clear();
00275 }
00276 else
00277 {
00278 printf("ERROR: netDegree in net %d does not tally (%d vs. %d).\n",
00279 in_nets.size(), degreeCount, netDegree);
00280 exit(1);
00281 }
00282 }
00283 else
00284 {
00285 printf("ERROR in parsing .net file (line %d after NumPins).\n",
00286 lineCount+1);
00287 printf("line: %s\n", line.c_str());
00288 exit(1);
00289 }
00290 }
00291 else if (sscanf(line.c_str(), "%s %c",
00292 block_name, dummy_chars+0) == 2)
00293 {
00294
00295 vector<int> indices;
00296 get_index(string(block_name), indices);
00297 if (indices.empty())
00298 {
00299 printf("ERROR: unrecognized pad \"%s\"\n", block_name);
00300 exit(1);
00301 }
00302 else
00303 {
00304 for (unsigned int i = 0; i < indices.size(); i++)
00305 {
00306 NetType::PadType temp;
00307 temp.xloc = in_all_pads[indices[i]].xloc;
00308 temp.yloc = in_all_pads[indices[i]].yloc;
00309 netPads.push_back(temp);
00310 pinCount++;
00311 }
00312 degreeCount++;
00313 }
00314
00315 }
00316 else
00317 {
00318 printf("ERROR in parsing .net file (line %d after NumPins).\n",
00319 lineCount+1);
00320 printf("line: %s\n", line.c_str());
00321 exit(1);
00322 }
00323 }
00324
00325 if (pinCount != numPins)
00326 {
00327 printf("ERROR: # pins does not tally (%d vs. %d).",
00328 pinCount, numPins);
00329 exit(1);
00330 }
00331 else if (int(in_nets.size()) != numNets)
00332 {
00333 printf("ERROR: # nets does not tally (%d vz. %d).",
00334 in_nets.size(), numNets);
00335 exit(1);
00336 }
00337 infile.close();
00338 }
00339
00340
00341
00342