Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

mixedpacking.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00037 #include "mixedpacking.h"
00038 #include "basepacking.h"
00039 #include "parsers.h"
00040 
00041 #include <fstream>
00042 #include <cmath>
00043 using namespace std;
00044 using namespace parse_utils;
00045 using namespace basepacking_h;
00046 
00047 const int MixedBlockInfoType::ORIENT_NUM = HardBlockInfoType::ORIENT_NUM;
00048 // --------------------------------------------------------
00049 MixedBlockInfoType::MixedBlockInfoType(const string& blocksfilename,
00050                                        const string& format)
00051    : currDimensions(_currDimensions),
00052      blockARinfo(_blockARinfo),
00053      _currDimensions(0)
00054 {
00055    ifstream infile;
00056    infile.open(blocksfilename.c_str());
00057    if (!infile.good())
00058    {
00059       cout << "ERROR: cannot open file " << blocksfilename << endl;
00060       exit(1);
00061    }
00062   
00063    if (format == "txt")
00064    {
00065       cout << "Sorry, .txt format isn't supported now." << endl;
00066       exit(0);
00067    }
00068    else if (format == "blocks")
00069       ParseBlocks(infile);
00070 }
00071 // --------------------------------------------------------
00072 void MixedBlockInfoType::ParseBlocks(ifstream& input)
00073 {
00074    char block_name[1024];
00075    char block_type[1024];
00076    char tempWord1[1024];
00077     
00078    vector<Point> vertices;
00079    int numVertices;
00080    bool success; 
00081    double width, height;
00082    
00083    double area,minAr,maxAr;
00084    int numSoftBl=0;
00085    int numHardBl=0;
00086    int numBl = numSoftBl + numHardBl;
00087    int numTerm=0;
00088    
00089    int indexBlock=0;
00090    int indexTerm=0;
00091    
00092    if(!input)
00093    {
00094       cout<<"ERROR: .blocks file could not be opened successfully"<<endl;
00095       exit(0);
00096    }
00097 
00098    while(!input.eof())
00099    {
00100       input>>tempWord1;
00101       if(!(strcmp(tempWord1,"NumSoftRectangularBlocks")))
00102          break;
00103    }
00104    input>>tempWord1;
00105    input>>numSoftBl;
00106 
00107    while(!input.eof())
00108    {
00109       input>>tempWord1;
00110       if(!(strcmp(tempWord1,"NumHardRectilinearBlocks")))
00111          break;
00112    }
00113    input>>tempWord1;
00114    input>>numHardBl;
00115     
00116    while(!input.eof())
00117    {
00118       input>>tempWord1;
00119       if(!(strcmp(tempWord1,"NumTerminals")))
00120          break;
00121    }
00122    input>>tempWord1;
00123    input>>numTerm;
00124 
00125    numBl = numHardBl + numSoftBl;
00126    _currDimensions.in_blocks.resize(numBl+2);
00127    _currDimensions.in_block_names.resize(numBl+2);
00128    _blockARinfo.resize(numHardBl+numSoftBl+2);
00129    while(!input.eof())
00130    {
00131       block_type[0] = '\0';
00132       eatblank(input);
00133       if(input.eof())
00134          break;
00135       if(input.peek()=='#')
00136          eathash(input);
00137       else
00138       {
00139          eatblank(input);
00140          if(input.peek() == '\n' || input.peek() == '\r')
00141          {
00142             input.get();
00143             continue;
00144          }
00145          
00146          input >> block_name;
00147          input >> block_type ;
00148          
00149          if(!strcmp(block_type,"softrectangular")) 
00150          {
00151             input >> area;
00152             input >> minAr;
00153             input >> maxAr;
00154 
00155             width = sqrt(area);
00156             height = sqrt(area);
00157 
00158 //             printf("[%d]: area: %.2lf minAR: %.2lf maxAR: %.2lf width: %.2lf height: %.2lf\n",
00159 //                    indexBlock, area, minAr, maxAr, width, height);
00160             _currDimensions.set_dimensions(indexBlock, width, height);
00161             if (indexBlock >= int(_currDimensions.block_names.size()))
00162             {
00163                cout << "ERROR: too many hard block specified." << endl;
00164                exit(1);
00165             }                 
00166             _currDimensions.in_block_names[indexBlock] = block_name;
00167 
00168             _blockARinfo[indexBlock].area = area;
00169             set_blockARinfo_AR(indexBlock, min(minAr, maxAr), max(minAr, maxAr));
00170             _blockARinfo[indexBlock].isSoft = true;
00171             
00172             ++indexBlock;
00173             //cout<<block_name<<" "<<area<<endl;
00174          }
00175          else if(!strcmp(block_type,"hardrectilinear"))
00176          {
00177             input >> numVertices; //maybe need voltage here 
00178             input >> numVertices;
00179             Point tempPoint;
00180             success = 1;
00181             if(numVertices > 4)
00182                cout<<"ERROR in parsing .blocks file. rectilinear blocks can be only rectangles for now\n";
00183             for(int i=0; i<numVertices; ++i)
00184             {
00185                success &= needCaseChar(input, '(');  input.get();
00186                input >> tempPoint.x;
00187                success &= needCaseChar(input, ',');  input.get();
00188                input >> tempPoint.y;
00189                success &= needCaseChar(input, ')');  input.get();
00190                vertices.push_back(tempPoint);
00191             }
00192             if(!success)
00193                cout<<"ERROR in parsing .blocks file while processing hardrectilinear blocks"<<endl;
00194             
00195             width = vertices[2].x - vertices[0].x;
00196             height = vertices[2].y - vertices[0].y;
00197             area = width*height;
00198             minAr = width/height;
00199             maxAr = minAr;
00200 
00201             _currDimensions.set_dimensions(indexBlock, width, height);
00202             if (indexBlock >= int(_currDimensions.block_names.size()))
00203             {
00204                cout << "ERROR: too many hard block specified." << endl;
00205                exit(1);
00206             }                 
00207             _currDimensions.in_block_names[indexBlock] = block_name;
00208             
00209             _blockARinfo[indexBlock].area = area;
00210             set_blockARinfo_AR(indexBlock, min(minAr, maxAr), max(minAr, maxAr));
00211             _blockARinfo[indexBlock].isSoft = false;
00212 
00213             ++indexBlock;
00214             vertices.clear();
00215             //cout<<block_name<<" "<<area<<endl;
00216          }
00217          else if(!strcmp(block_type,"terminal"))
00218          {
00219             ++indexTerm;
00220             //cout<<indexTerm<<"  "<<block_name<<endl;
00221          }
00222          /*
00223            else
00224            cout<<"ERROR in parsing .blocks file"<<endl;
00225          */
00226       }  
00227    }
00228    input.close();
00229    
00230    if(numSoftBl+numHardBl != indexBlock)
00231       cout << "ERROR in parsing .blocks file. No: of blocks do not tally "
00232            << (indexBlock+indexTerm) << " vs " << (numSoftBl+numHardBl+numTerm)
00233            << endl;
00234 
00235    _currDimensions.set_dimensions(numBl, 0, Dimension::INFTY);
00236    _currDimensions.in_block_names[numBl] = "LEFT";
00237    _blockARinfo[numBl].area = 0;
00238    _blockARinfo[numBl].minAR.resize(ORIENT_NUM, 0);
00239    _blockARinfo[numBl].maxAR.resize(ORIENT_NUM, 0);
00240    _blockARinfo[numBl].isSoft = false;
00241 
00242    _currDimensions.set_dimensions(numBl+1, Dimension::INFTY, 0);
00243    _currDimensions.in_block_names[numBl+1] = "BOTTOM";
00244    _blockARinfo[numBl+1].area = 0;
00245    _blockARinfo[numBl+1].minAR.resize(ORIENT_NUM, Dimension::INFTY);
00246    _blockARinfo[numBl+1].maxAR.resize(ORIENT_NUM, Dimension::INFTY);
00247    _blockARinfo[numBl+1].isSoft = false;
00248 }
00249 // --------------------------------------------------------
00250       

Generated on Mon Apr 25 01:09:24 2005 for Parquete by doxygen 1.3.2