src/map/mapper/mapperTree.c File Reference

#include "mapperInt.h"
Include dependency graph for mapperTree.c:

Go to the source code of this file.

Functions

static int Map_LibraryReadFileTree (Map_SuperLib_t *pLib, FILE *pFile, char *pFileName)
static Map_Super_tMap_LibraryReadGateTree (Map_SuperLib_t *pLib, char *pBuffer, int Number, int nVars)
static int Map_LibraryDeriveGateInfo (Map_SuperLib_t *pLib, st_table *tExcludeGate)
static void Map_LibraryAddFaninDelays (Map_SuperLib_t *pLib, Map_Super_t *pGate, Map_Super_t *pFanin, Mio_Pin_t *pPin)
static int Map_LibraryGetMaxSuperPi_rec (Map_Super_t *pGate)
static unsigned Map_LibraryGetGateSupp_rec (Map_Super_t *pGate)
int Map_LibraryReadTree (Map_SuperLib_t *pLib, char *pFileName, char *pExcludeFile)
unsigned Map_CalculatePhase (unsigned uTruths[][2], int nVars, unsigned uTruth, unsigned uPhase)
void Map_CalculatePhase6 (unsigned uTruths[][2], int nVars, unsigned uTruth[], unsigned uPhase, unsigned uTruthRes[])
void Map_LibraryPrintTree (Map_SuperLib_t *pLib)

Variables

const int s_MapFanoutLimits [10] = { 1, 10, 5, 2, 1, 1, 1 }

Function Documentation

unsigned Map_CalculatePhase ( unsigned  uTruths[][2],
int  nVars,
unsigned  uTruth,
unsigned  uPhase 
)

Function*************************************************************

Synopsis [Performs phase transformation for one function.]

Description []

SideEffects []

SeeAlso []

Definition at line 696 of file mapperTree.c.

00697 {
00698     int v, Shift;
00699     for ( v = 0, Shift = 1; v < nVars; v++, Shift <<= 1 )
00700         if ( uPhase & Shift )
00701             uTruth = (((uTruth & ~uTruths[v][0]) << Shift) | ((uTruth & uTruths[v][0]) >> Shift));
00702     return uTruth;
00703 }

void Map_CalculatePhase6 ( unsigned  uTruths[][2],
int  nVars,
unsigned  uTruth[],
unsigned  uPhase,
unsigned  uTruthRes[] 
)

Function*************************************************************

Synopsis [Performs phase transformation for one function.]

Description []

SideEffects []

SeeAlso []

Definition at line 716 of file mapperTree.c.

00717 {
00718     unsigned uTemp;
00719     int v, Shift;
00720 
00721     // initialize the result
00722     uTruthRes[0] = uTruth[0];
00723     uTruthRes[1] = uTruth[1];
00724     if ( uPhase == 0 )
00725         return;
00726     // compute the phase 
00727     for ( v = 0, Shift = 1; v < nVars; v++, Shift <<= 1 )
00728         if ( uPhase & Shift )
00729         {
00730             if ( Shift < 32 )
00731             {
00732                 uTruthRes[0] = (((uTruthRes[0] & ~uTruths[v][0]) << Shift) | ((uTruthRes[0] & uTruths[v][0]) >> Shift));
00733                 uTruthRes[1] = (((uTruthRes[1] & ~uTruths[v][1]) << Shift) | ((uTruthRes[1] & uTruths[v][1]) >> Shift));
00734             }
00735             else
00736             {
00737                 uTemp        = uTruthRes[0];
00738                 uTruthRes[0] = uTruthRes[1];
00739                 uTruthRes[1] = uTemp;
00740             }
00741         }
00742 }

void Map_LibraryAddFaninDelays ( Map_SuperLib_t pLib,
Map_Super_t pGate,
Map_Super_t pFanin,
Mio_Pin_t pPin 
) [static]

Function*************************************************************

Synopsis [Derives the pin-to-pin delay constraints for the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 552 of file mapperTree.c.

00553 {
00554     Mio_PinPhase_t PinPhase;
00555     float tDelayBlockRise, tDelayBlockFall, tDelayPin;
00556     bool fMaxDelay = 0;
00557     int i;
00558 
00559     // use this node to enable max-delay model
00560     if ( fMaxDelay )
00561     {
00562         float tDelayBlockMax;
00563         // get the maximum delay
00564         tDelayBlockMax = (float)Mio_PinReadDelayBlockMax(pPin);
00565         // go through the supergate inputs
00566         for ( i = 0; i < pLib->nVarsMax; i++ )
00567         {
00568             if ( pFanin->tDelaysR[i].Rise < 0 )
00569                 continue;
00570             tDelayPin = pFanin->tDelaysR[i].Rise + tDelayBlockMax;
00571             if ( pGate->tDelaysR[i].Rise < tDelayPin )
00572                 pGate->tDelaysR[i].Rise = tDelayPin;
00573         }
00574         // go through the supergate inputs
00575         for ( i = 0; i < pLib->nVarsMax; i++ )
00576         {
00577             if ( pFanin->tDelaysF[i].Fall < 0 )
00578                 continue;
00579             tDelayPin = pFanin->tDelaysF[i].Fall + tDelayBlockMax;
00580             if ( pGate->tDelaysF[i].Fall < tDelayPin )
00581                 pGate->tDelaysF[i].Fall = tDelayPin;
00582         }
00583         return;
00584     }
00585 
00586     // get the interesting parameters of this pin
00587     PinPhase = Mio_PinReadPhase(pPin);
00588     tDelayBlockRise = (float)Mio_PinReadDelayBlockRise( pPin );  
00589     tDelayBlockFall = (float)Mio_PinReadDelayBlockFall( pPin );  
00590 
00591     // update the rise and fall of the output depending on the phase of the pin 
00592     if ( PinPhase != MIO_PHASE_INV )  // NONINV phase is present
00593     {
00594         // the rise of the gate is determined by the rise of the fanin
00595         // the fall of the gate is determined by the fall of the fanin
00596         for ( i = 0; i < pLib->nVarsMax; i++ )
00597         {
00599             // consider the rise of the gate
00601             // check two types of constraints on the rise of the fanin:
00602             // (1) the constraints related to the rise of the PIs
00603             // (2) the constraints related to the fall of the PIs
00604             if ( pFanin->tDelaysR[i].Rise >= 0 ) // case (1)
00605             { // fanin's rise depends on the rise of i-th PI
00606                 // update the rise of the gate's output
00607                 if ( pGate->tDelaysR[i].Rise < pFanin->tDelaysR[i].Rise + tDelayBlockRise )
00608                     pGate->tDelaysR[i].Rise = pFanin->tDelaysR[i].Rise + tDelayBlockRise;
00609             }
00610             if ( pFanin->tDelaysR[i].Fall >= 0 ) // case (2)
00611             { // fanin's rise depends on the fall of i-th PI
00612                 // update the rise of the gate's output
00613                 if ( pGate->tDelaysR[i].Fall < pFanin->tDelaysR[i].Fall + tDelayBlockRise )
00614                     pGate->tDelaysR[i].Fall = pFanin->tDelaysR[i].Fall + tDelayBlockRise;
00615             }
00617 
00619             // consider the fall of the gate (similar)
00621             // check two types of constraints on the fall of the fanin:
00622             // (1) the constraints related to the rise of the PIs
00623             // (2) the constraints related to the fall of the PIs
00624             if ( pFanin->tDelaysF[i].Rise >= 0 ) // case (1) 
00625             { 
00626                 if ( pGate->tDelaysF[i].Rise < pFanin->tDelaysF[i].Rise + tDelayBlockFall )
00627                     pGate->tDelaysF[i].Rise = pFanin->tDelaysF[i].Rise + tDelayBlockFall;
00628             }
00629             if ( pFanin->tDelaysF[i].Fall >= 0 ) // case (2) 
00630             { 
00631                 if ( pGate->tDelaysF[i].Fall < pFanin->tDelaysF[i].Fall + tDelayBlockFall )
00632                     pGate->tDelaysF[i].Fall = pFanin->tDelaysF[i].Fall + tDelayBlockFall;
00633             }
00635         }
00636     }
00637     if ( PinPhase != MIO_PHASE_NONINV )  // INV phase is present
00638     {
00639         // the rise of the gate is determined by the fall of the fanin
00640         // the fall of the gate is determined by the rise of the fanin
00641         for ( i = 0; i < pLib->nVarsMax; i++ )
00642         {
00644             // consider the rise of the gate's output
00646             // check two types of constraints on the fall of the fanin:
00647             // (1) the constraints related to the rise of the PIs
00648             // (2) the constraints related to the fall of the PIs
00649             if ( pFanin->tDelaysF[i].Rise >= 0 ) // case (1)
00650             { // fanin's rise depends on the rise of i-th PI
00651                 // update the rise of the gate
00652                 if ( pGate->tDelaysR[i].Rise < pFanin->tDelaysF[i].Rise + tDelayBlockRise )
00653                     pGate->tDelaysR[i].Rise = pFanin->tDelaysF[i].Rise + tDelayBlockRise;
00654             }
00655             if ( pFanin->tDelaysF[i].Fall >= 0 ) // case (2)
00656             { // fanin's rise depends on the fall of i-th PI
00657                 // update the rise of the gate
00658                 if ( pGate->tDelaysR[i].Fall < pFanin->tDelaysF[i].Fall + tDelayBlockRise )
00659                     pGate->tDelaysR[i].Fall = pFanin->tDelaysF[i].Fall + tDelayBlockRise;
00660             }
00662 
00664             // consider the fall of the gate (similar)
00666             // check two types of constraints on the rise of the fanin:
00667             // (1) the constraints related to the rise of the PIs
00668             // (2) the constraints related to the fall of the PIs
00669             if ( pFanin->tDelaysR[i].Rise >= 0 ) // case (1) 
00670             { 
00671                 if ( pGate->tDelaysF[i].Rise < pFanin->tDelaysR[i].Rise + tDelayBlockFall )
00672                     pGate->tDelaysF[i].Rise = pFanin->tDelaysR[i].Rise + tDelayBlockFall;
00673             }
00674             if ( pFanin->tDelaysR[i].Fall >= 0 ) // case (2) 
00675             { 
00676                 if ( pGate->tDelaysF[i].Fall < pFanin->tDelaysR[i].Fall + tDelayBlockFall )
00677                     pGate->tDelaysF[i].Fall = pFanin->tDelaysR[i].Fall + tDelayBlockFall;
00678             }
00680         }
00681     }
00682 }

int Map_LibraryDeriveGateInfo ( Map_SuperLib_t pLib,
st_table tExcludeGate 
) [static]

Function*************************************************************

Synopsis [Derives information about the library.]

Description []

SideEffects []

SeeAlso []

Definition at line 364 of file mapperTree.c.

00365 {
00366     Map_Super_t * pGate, * pFanin;
00367     Mio_Pin_t * pPin;
00368     unsigned uCanon[2];
00369     unsigned uTruths[6][2];
00370     int i, k, nRealVars;
00371 
00372     // set all the derivable info related to the supergates
00373     for ( i = pLib->nVarsMax; i < (int)pLib->nLines; i++ )
00374     {
00375         pGate = pLib->ppSupers[i];
00376 
00377         if ( tExcludeGate )
00378         {
00379             if ( st_is_member( tExcludeGate, Mio_GateReadName( pGate->pRoot ) ) )
00380                 pGate->fExclude = 1;
00381             for ( k = 0; k < (int)pGate->nFanins; k++ )
00382             {
00383                 pFanin = pGate->pFanins[k];
00384                 if ( pFanin->fExclude )
00385                 {
00386                     pGate->fExclude = 1;
00387                     continue;
00388                 }
00389             }
00390         }
00391         
00392         // collect the truth tables of the fanins
00393         for ( k = 0; k < (int)pGate->nFanins; k++ )
00394         {
00395             pFanin = pGate->pFanins[k];
00396             uTruths[k][0] = pFanin->uTruth[0];
00397             uTruths[k][1] = pFanin->uTruth[1];
00398         }
00399         // derive the new truth table
00400         Mio_DeriveTruthTable( pGate->pRoot, uTruths, pGate->nFanins, 6, pGate->uTruth );
00401 
00402         // set the initial delays of the supergate
00403         for ( k = 0; k < pLib->nVarsMax; k++ )
00404         {
00405             pGate->tDelaysR[k].Rise = pGate->tDelaysR[k].Fall = MAP_NO_VAR;
00406             pGate->tDelaysF[k].Rise = pGate->tDelaysF[k].Fall = MAP_NO_VAR;
00407         }
00408         // get the linked list of pins for the given root gate
00409         pPin = Mio_GateReadPins( pGate->pRoot );
00410         // update the initial delay of the supergate using info from the corresponding pin
00411         for ( k = 0; k < (int)pGate->nFanins; k++, pPin = Mio_PinReadNext(pPin) )
00412         {
00413             // if there is no corresponding pin, this is a bug, return fail
00414             if ( pPin == NULL )
00415             {
00416                 printf( "There are less pins than gate inputs.\n" );
00417                 return 0;
00418             }
00419             // update the delay information of k-th fanins info from the corresponding pin
00420             Map_LibraryAddFaninDelays( pLib, pGate, pGate->pFanins[k], pPin );
00421         }
00422         // if there are some pins left, this is a bug, return fail
00423         if ( pPin != NULL )
00424         {
00425             printf( "There are more pins than gate inputs.\n" );
00426             return 0;
00427         }
00428         // find the max delay
00429         pGate->tDelayMax.Rise = pGate->tDelayMax.Fall = MAP_NO_VAR;
00430         for ( k = 0; k < pLib->nVarsMax; k++ )
00431         {
00432             // the rise of the output depends on the rise and fall of the output
00433             if ( pGate->tDelayMax.Rise < pGate->tDelaysR[k].Rise )
00434                 pGate->tDelayMax.Rise = pGate->tDelaysR[k].Rise;
00435             if ( pGate->tDelayMax.Rise < pGate->tDelaysR[k].Fall )
00436                 pGate->tDelayMax.Rise = pGate->tDelaysR[k].Fall;
00437             // the fall of the output depends on the rise and fall of the output
00438             if ( pGate->tDelayMax.Fall < pGate->tDelaysF[k].Rise )
00439                 pGate->tDelayMax.Fall = pGate->tDelaysF[k].Rise;
00440             if ( pGate->tDelayMax.Fall < pGate->tDelaysF[k].Fall )
00441                 pGate->tDelayMax.Fall = pGate->tDelaysF[k].Fall;
00442 
00443             pGate->tDelaysF[k].Worst = MAP_MAX( pGate->tDelaysF[k].Fall, pGate->tDelaysF[k].Rise );
00444             pGate->tDelaysR[k].Worst = MAP_MAX( pGate->tDelaysR[k].Fall, pGate->tDelaysR[k].Rise );
00445         }
00446 
00447         // count gates and area of the supergate
00448         pGate->nGates = 1;
00449         pGate->Area   = (float)Mio_GateReadArea(pGate->pRoot);
00450         for ( k = 0; k < (int)pGate->nFanins; k++ )
00451         {
00452             pGate->nGates += pGate->pFanins[k]->nGates;
00453             pGate->Area   += pGate->pFanins[k]->Area;
00454         }
00455         // do not add the gate to the table, if this gate is an internal gate
00456         // of some supegate and does not correspond to a supergate output
00457         if ( ( !pGate->fSuper ) || pGate->fExclude )
00458             continue;
00459 
00460         // find the maximum index of a variable in the support of the supergates
00461         // this is important for two reasons:
00462         // (1) to limit the number of permutations considered for canonicization
00463         // (2) to get rid of equivalence phases to speed-up matching
00464         nRealVars = Map_LibraryGetMaxSuperPi_rec( pGate ) + 1;
00465         assert( nRealVars > 0 && nRealVars <= pLib->nVarsMax );
00466         // if there are some problems with this code, try this instead
00467 //        nRealVars = pLib->nVarsMax;
00468 
00469         // find the N-canonical form of this supergate
00470         pGate->nPhases = Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, nRealVars, pGate->uTruth, pGate->uPhases, uCanon );
00471         // add the supergate into the table by its N-canonical table
00472         Map_SuperTableInsertC( pLib->tTableC, uCanon, pGate );
00473 /*
00474         {
00475             int uCanon1, uCanon2;
00476             uCanon1 = uCanon[0];
00477             pGate->uTruth[0] = ~pGate->uTruth[0];
00478             pGate->uTruth[1] = ~pGate->uTruth[1];
00479             Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, nRealVars, pGate->uTruth, pGate->uPhases, uCanon );
00480             uCanon2 = uCanon[0];
00481 Rwt_Man5ExploreCount( uCanon1 < uCanon2 ? uCanon1 : uCanon2 );
00482         }
00483 */
00484     }
00485     // sort the gates in each line
00486     Map_SuperTableSortSupergatesByDelay( pLib->tTableC, pLib->nSupersAll );
00487 
00488     // let the glory be manifest
00489 //    Map_LibraryPrintTree( pLib );
00490     return 1;
00491 }

unsigned Map_LibraryGetGateSupp_rec ( Map_Super_t pGate  )  [static]

Function*************************************************************

Synopsis [Finds the largest PI number in the support of the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 529 of file mapperTree.c.

00530 {
00531     unsigned uSupport;
00532     int i;
00533     if ( pGate->pRoot == NULL )
00534         return (unsigned)(1 << (pGate->Num));
00535     uSupport = 0;
00536     for ( i = 0; i < (int)pGate->nFanins; i++ )
00537         uSupport |= Map_LibraryGetGateSupp_rec( pGate->pFanins[i] );
00538     return uSupport;
00539 }

int Map_LibraryGetMaxSuperPi_rec ( Map_Super_t pGate  )  [static]

Function*************************************************************

Synopsis [Finds the largest PI number in the support of the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 504 of file mapperTree.c.

00505 {
00506     int i, VarCur, VarMax = 0;
00507     if ( pGate->pRoot == NULL )
00508         return pGate->Num;
00509     for ( i = 0; i < (int)pGate->nFanins; i++ )
00510     {
00511         VarCur = Map_LibraryGetMaxSuperPi_rec( pGate->pFanins[i] );
00512         if ( VarMax < VarCur )
00513             VarMax = VarCur;
00514     }
00515     return VarMax;
00516 }

void Map_LibraryPrintTree ( Map_SuperLib_t pLib  ) 

Function*************************************************************

Synopsis [Prints the supergate library after deriving parameters.]

Description [This procedure is very useful to see the library after it has been read into the mapper by "read_super" and all the information about the supergates derived.]

SideEffects []

SeeAlso []

Definition at line 757 of file mapperTree.c.

00758 {
00759     Map_Super_t * pGate;
00760     int i, k;
00761 
00762     // print all the info related to the supergates
00763 //    for ( i = pLib->nVarsMax; i < (int)pLib->nLines; i++ )
00764     for ( i = pLib->nVarsMax; i < 20; i++ )
00765     {
00766         pGate = pLib->ppSupers[i];
00767 
00768         // write the gate's fanin info and formula
00769         printf( "%6d  ", pGate->Num );
00770         printf( "%c ", pGate->fSuper? '*' : ' ' );
00771         printf( "%6s", Mio_GateReadName(pGate->pRoot) );
00772         for ( k = 0; k < (int)pGate->nFanins; k++ )
00773             printf( " %6d", pGate->pFanins[k]->Num );
00774         printf( "  %s", pGate->pFormula );
00775         printf( "\n" );
00776 
00777         // write the gate's derived info
00778         Extra_PrintBinary( stdout, pGate->uTruth, 64 );
00779         printf( "  %3d",   pGate->nGates );
00780         printf( "  %6.2f", pGate->Area );
00781         printf( "  (%4.2f, %4.2f)", pGate->tDelayMax.Rise, pGate->tDelayMax.Fall );
00782         printf( "\n" );
00783         for ( k = 0; k < pLib->nVarsMax; k++ )
00784         {
00785             // print the constraint on the rise of the gate in the form (D1, D2), 
00786             // where D1 is the constraint related to the rise of the k-th PI
00787             // where D2 is the constraint related to the fall of the k-th PI
00788             if ( pGate->tDelaysR[k].Rise < 0 && pGate->tDelaysR[k].Fall < 0 )
00789                 printf( " (----, ----)" );
00790             else if ( pGate->tDelaysR[k].Fall < 0 )
00791                 printf( " (%4.2f, ----)", pGate->tDelaysR[k].Rise );
00792             else if ( pGate->tDelaysR[k].Rise < 0 )
00793                 printf( " (----, %4.2f)", pGate->tDelaysR[k].Fall );
00794             else
00795                 printf( " (%4.2f, %4.2f)", pGate->tDelaysR[k].Rise, pGate->tDelaysR[k].Fall );
00796 
00797             // print the constraint on the fall of the gate in the form (D1, D2), 
00798             // where D1 is the constraint related to the rise of the k-th PI
00799             // where D2 is the constraint related to the fall of the k-th PI
00800             if ( pGate->tDelaysF[k].Rise < 0 && pGate->tDelaysF[k].Fall < 0 )
00801                 printf( " (----, ----)" );
00802             else if ( pGate->tDelaysF[k].Fall < 0 )
00803                 printf( " (%4.2f, ----)", pGate->tDelaysF[k].Rise );
00804             else if ( pGate->tDelaysF[k].Rise < 0 )
00805                 printf( " (----, %4.2f)", pGate->tDelaysF[k].Fall );
00806             else
00807                 printf( " (%4.2f, %4.2f)", pGate->tDelaysF[k].Rise, pGate->tDelaysF[k].Fall );
00808             printf( "\n" );
00809         }
00810         printf( "\n" );
00811     }
00812 }

int Map_LibraryReadFileTree ( Map_SuperLib_t pLib,
FILE *  pFile,
char *  pFileName 
) [static]

CFile****************************************************************

FileName [mapperTree.c]

PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

Synopsis [Generic technology mapping engine.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - June 1, 2004.]

Revision [

Id
mapperTree.c,v 1.9 2005/01/23 06:59:45 alanmi Exp

] DECLARATIONS ///

Function*************************************************************

Synopsis [Reads the library file.]

Description []

SideEffects []

SeeAlso []

Definition at line 106 of file mapperTree.c.

00107 {
00108     ProgressBar * pProgress;
00109     char pBuffer[5000], pLibFile[5000];
00110     FILE * pFileGen;
00111     Map_Super_t * pGate;
00112     char * pTemp = 0, * pLibName;
00113     int nCounter, k, i;
00114 
00115     // skip empty and comment lines
00116     while ( fgets( pBuffer, 5000, pFile ) != NULL )
00117     {
00118         // skip leading spaces
00119         for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
00120         // skip comment lines and empty lines
00121         if ( *pTemp != 0 && *pTemp != '#' )
00122             break;
00123     }
00124     
00125     // get the genlib file name (base)
00126     pLibName = strtok( pTemp, " \t\r\n" );
00127     
00128     if ( strcmp( pLibName, "GATE" ) == 0 )
00129     {
00130         printf( "The input file \"%s\" looks like a GENLIB file and not a supergate library file.\n", pLib->pName );
00131         return 0;
00132     }
00133     
00134 
00135     // now figure out the directory if any in the pFileName
00136 #ifdef __linux__
00137     snprintf( pLibFile, 5000, "%s/%s", dirname(strdup(pFileName)), pLibName ); 
00138 #else
00139     {
00140         char * pStr;
00141         strcpy( pLibFile, pFileName );
00142         pStr = pLibFile + strlen(pBuffer) - 1;
00143         while ( pStr > pLibFile && *pStr != '\\' && *pStr != '/' )
00144             pStr--;
00145         if ( pStr == pLibFile )
00146             strcpy( pLibFile, pLibName );
00147         else
00148             sprintf( pStr, "/%s", pLibName );
00149     }
00150 #endif
00151     
00152     pFileGen = Io_FileOpen( pLibFile, "open_path", "r", 1 );
00153 //    pFileGen = fopen( pLibFile, "r" ); 
00154     if ( pFileGen == NULL )
00155     {
00156         printf( "Cannot open the GENLIB file \"%s\".\n", pLibFile );
00157         return 0;
00158     }
00159     fclose( pFileGen );
00160 
00161     // read the genlib library
00162     pLib->pGenlib = Mio_LibraryRead( Abc_FrameGetGlobalFrame(), pLibFile, 0, 0 );
00163     if ( pLib->pGenlib == NULL )
00164     {
00165         printf( "Cannot read GENLIB file \"%s\".\n", pLibFile );
00166         return 0;
00167     }
00168 
00169     // read the number of variables
00170     fscanf( pFile, "%d\n", &pLib->nVarsMax );
00171     if ( pLib->nVarsMax < 2 || pLib->nVarsMax > 10 )
00172     {
00173         printf( "Suspicious number of variables (%d).\n", pLib->nVarsMax );
00174         return 0;
00175     }
00176 
00177     // read the number of gates
00178     fscanf( pFile, "%d\n", &pLib->nSupersReal );
00179     if ( pLib->nSupersReal < 1 || pLib->nSupersReal > 10000000 )
00180     {
00181         printf( "Suspicious number of gates (%d).\n", pLib->nSupersReal );
00182         return 0;
00183     }
00184 
00185     // read the number of lines
00186     fscanf( pFile, "%d\n", &pLib->nLines );
00187     if ( pLib->nLines < 1 || pLib->nLines > 10000000 )
00188     {
00189         printf( "Suspicious number of lines (%d).\n", pLib->nLines );
00190         return 0;
00191     }
00192 
00193     // allocate room for supergate pointers
00194     pLib->ppSupers = ALLOC( Map_Super_t *, pLib->nLines + 10000 );
00195 
00196     // create the elementary supergates
00197     for ( i = 0; i < pLib->nVarsMax; i++ )
00198     {
00199         // get a new gate
00200         pGate = (Map_Super_t *)Extra_MmFixedEntryFetch( pLib->mmSupers );
00201         memset( pGate, 0, sizeof(Map_Super_t) );
00202         // assign the elementary variable, the truth table, and the delays
00203         pGate->Num = i;
00204         // set the truth table
00205         pGate->uTruth[0] = pLib->uTruths[i][0];
00206         pGate->uTruth[1] = pLib->uTruths[i][1];
00207         // set the arrival times of all input to non-existent delay
00208         for ( k = 0; k < pLib->nVarsMax; k++ )
00209         {
00210             pGate->tDelaysR[k].Rise = pGate->tDelaysR[k].Fall = MAP_NO_VAR;
00211             pGate->tDelaysF[k].Rise = pGate->tDelaysF[k].Fall = MAP_NO_VAR;
00212         }
00213         // set an existent arrival time for rise and fall
00214         pGate->tDelaysR[i].Rise = 0.0;
00215         pGate->tDelaysF[i].Fall = 0.0;
00216         // set the gate
00217         pLib->ppSupers[i] = pGate;
00218     }
00219 
00220     // read the lines
00221     nCounter = pLib->nVarsMax;
00222     pProgress = Extra_ProgressBarStart( stdout, pLib->nLines );
00223     while ( fgets( pBuffer, 5000, pFile ) != NULL )
00224     {
00225         for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
00226         if ( pTemp[0] == '\0' )
00227             continue;
00228 //        if ( pTemp[0] == 'a' || pTemp[2] == 'a' )
00229 //        {
00230 //            pLib->nLines--;
00231 //            continue;
00232 //        }
00233 
00234         // get the gate
00235         pGate = Map_LibraryReadGateTree( pLib, pTemp, nCounter, pLib->nVarsMax );
00236         if ( pGate == NULL )
00237         {
00238             Extra_ProgressBarStop( pProgress );
00239             return 0;
00240         }
00241         pLib->ppSupers[nCounter++] = pGate;
00242         // later we will derive: truth table, delays, area, number of component gates, etc
00243 
00244         // update the progress bar
00245         Extra_ProgressBarUpdate( pProgress, nCounter, NULL );
00246     }
00247     Extra_ProgressBarStop( pProgress );
00248     if ( nCounter != pLib->nLines )
00249         printf( "The number of lines read (%d) is different what the file says (%d).\n", nCounter, pLib->nLines );
00250     pLib->nSupersAll = nCounter;
00251     // count the number of real supergates
00252     nCounter = 0;
00253     for ( k = 0; k < pLib->nLines; k++ )
00254         nCounter += pLib->ppSupers[k]->fSuper;
00255     if ( nCounter != pLib->nSupersReal )
00256         printf( "The number of gates read (%d) is different what the file says (%d).\n", nCounter, pLib->nSupersReal );
00257     pLib->nSupersReal = nCounter;
00258     return 1;
00259 }

Map_Super_t * Map_LibraryReadGateTree ( Map_SuperLib_t pLib,
char *  pBuffer,
int  Number,
int  nVarsMax 
) [static]

Function*************************************************************

Synopsis [Reads one gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 272 of file mapperTree.c.

00273 {
00274     Map_Super_t * pGate;
00275     char * pTemp;
00276     int i, Num;
00277 
00278     // start and clean the gate
00279     pGate = (Map_Super_t *)Extra_MmFixedEntryFetch( pLib->mmSupers );
00280     memset( pGate, 0, sizeof(Map_Super_t) );
00281 
00282     // set the gate number
00283     pGate->Num = Number;
00284 
00285     // read the mark
00286     pTemp = strtok( pBuffer, " " );
00287     if ( pTemp[0] == '*' )
00288     {
00289         pGate->fSuper = 1;
00290         pTemp = strtok( NULL, " " );
00291     }
00292 
00293     // read the root gate
00294     pGate->pRoot = Mio_LibraryReadGateByName( pLib->pGenlib, pTemp );
00295     if ( pGate->pRoot == NULL )
00296     {
00297         printf( "Cannot read the root gate names %s.\n", pTemp );
00298         return NULL;
00299     }
00300     // set the max number of fanouts
00301     pGate->nFanLimit = s_MapFanoutLimits[ Mio_GateReadInputs(pGate->pRoot) ];
00302 
00303     // read the pin-to-pin delay
00304     for ( i = 0; ( pTemp = strtok( NULL, " \n\0" ) ); i++ )
00305     {
00306         if ( pTemp[0] == '#' )
00307             break;
00308         if ( i == nVarsMax )
00309         {
00310             printf( "There are too many entries on the line.\n" );
00311             return NULL;
00312         }
00313         Num = atoi(pTemp);
00314         if ( Num < 0 )
00315         {
00316             printf( "The number of a child supergate is negative.\n" );
00317             return NULL;
00318         }
00319         if ( Num > pLib->nLines )
00320         {
00321             printf( "The number of a child supergate (%d) exceeded the number of lines (%d).\n", 
00322                 Num, pLib->nLines );
00323             return NULL;
00324         }
00325         pGate->pFanins[i] = pLib->ppSupers[Num];
00326     }
00327     pGate->nFanins = i;
00328     if ( pGate->nFanins != (unsigned)Mio_GateReadInputs(pGate->pRoot) )
00329     {
00330         printf( "The number of fanins of a root gate is wrong.\n" );
00331         return NULL;
00332     }
00333 
00334     // save the gate name, just in case
00335     if ( pTemp && pTemp[0] == '#' )
00336     {
00337         if ( pTemp[1] == 0 )
00338             pTemp = strtok( NULL, " \n\0" );
00339         else // skip spaces
00340             for ( pTemp++; *pTemp == ' '; pTemp++ );
00341         // save the formula
00342         pGate->pFormula = Extra_MmFlexEntryFetch( pLib->mmForms, strlen(pTemp)+1 );
00343         strcpy( pGate->pFormula, pTemp );
00344     }
00345     // check the rest of the string
00346     pTemp = strtok( NULL, " \n\0" );
00347     if ( pTemp != NULL )
00348         printf( "The following trailing symbols found \"%s\".\n", pTemp );
00349     return pGate;
00350 }

int Map_LibraryReadTree ( Map_SuperLib_t pLib,
char *  pFileName,
char *  pExcludeFile 
)

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Reads the supergate library from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 54 of file mapperTree.c.

00055 {
00056     FILE * pFile;
00057     int Status, num;
00058     Abc_Frame_t * pAbc;
00059     st_table * tExcludeGate = 0;
00060 
00061     // read the beginning of the file
00062     assert( pLib->pGenlib == NULL );
00063     pFile = Io_FileOpen( pFileName, "open_path", "r", 1 );
00064 //    pFile = fopen( pFileName, "r" ); 
00065     if ( pFile == NULL )
00066     {
00067         printf( "Cannot open input file \"%s\".\n", pFileName );
00068         return 0;
00069     }
00070 
00071     if ( pExcludeFile )
00072     {
00073         pAbc = Abc_FrameGetGlobalFrame();
00074         
00075         tExcludeGate = st_init_table(strcmp, st_strhash);
00076         if ( (num = Mio_LibraryReadExclude( pAbc, pExcludeFile, tExcludeGate )) == -1 )
00077         {
00078             st_free_table( tExcludeGate );
00079             tExcludeGate = 0;
00080             return 0;
00081         }
00082 
00083         fprintf ( Abc_FrameReadOut( pAbc ), "Read %d gates from exclude file\n", num );
00084     }
00085     
00086     Status = Map_LibraryReadFileTree( pLib, pFile, pFileName );
00087     fclose( pFile );
00088     if ( Status == 0 )
00089         return 0;
00090     // prepare the info about the library
00091     return Map_LibraryDeriveGateInfo( pLib, tExcludeGate );
00092 }


Variable Documentation

const int s_MapFanoutLimits[10] = { 1, 10, 5, 2, 1, 1, 1 }

Generated on Tue Jan 5 12:19:06 2010 for abc70930 by  doxygen 1.6.1