diff --git a/src/base/acb/acbFunc.c b/src/base/acb/acbFunc.c index 3c0bb5f06..539b91abf 100644 --- a/src/base/acb/acbFunc.c +++ b/src/base/acb/acbFunc.c @@ -159,7 +159,7 @@ char * pLibStr2[25] = { }; void Acb_IntallLibrary( int f2Ins ) { - extern Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int fVerbose ); + extern Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int nFaninLimit, int fVerbose ); Mio_Library_t * pLib; int i; // create library string @@ -169,7 +169,7 @@ void Acb_IntallLibrary( int f2Ins ) Vec_StrAppend( vLibStr, ppLibStr[i] ); Vec_StrPush( vLibStr, '\0' ); // create library - pLib = Mio_LibraryReadBuffer( Vec_StrArray(vLibStr), 0, NULL, 0 ); + pLib = Mio_LibraryReadBuffer( Vec_StrArray(vLibStr), 0, NULL, 0, 0 ); Mio_LibrarySetName( pLib, Abc_UtilStrsav("iccad17.genlib") ); Mio_UpdateGenlib( pLib ); Vec_StrFree( vLibStr ); diff --git a/src/map/mapper/mapperSuper.c b/src/map/mapper/mapperSuper.c index 0c33d5800..049c7cc52 100644 --- a/src/map/mapper/mapperSuper.c +++ b/src/map/mapper/mapperSuper.c @@ -115,7 +115,7 @@ int Map_LibraryReadFile( Map_SuperLib_t * pLib, FILE * pFile ) fclose( pFileGen ); // read the genlib library - pLib->pGenlib = Mio_LibraryRead( pLibName, NULL, 0, 0 ); + pLib->pGenlib = Mio_LibraryRead( pLibName, NULL, 0, 0, 0 ); if ( pLib->pGenlib == NULL ) { printf( "Cannot read genlib file \"%s\".\n", pLibName ); diff --git a/src/map/mio/mio.c b/src/map/mio/mio.c index 9ca6767db..cfe5d3e8c 100644 --- a/src/map/mio/mio.c +++ b/src/map/mio/mio.c @@ -152,7 +152,7 @@ int Mio_UpdateGenlib2( Vec_Str_t * vStr, Vec_Str_t * vStr2, char * pFileName, in { Mio_Library_t * pLib; // set the new network - pLib = Mio_LibraryRead( pFileName, Vec_StrArray(vStr), NULL, fVerbose ); + pLib = Mio_LibraryRead( pFileName, Vec_StrArray(vStr), NULL, 0, fVerbose ); if ( pLib == NULL ) return 0; @@ -291,12 +291,13 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) char * pExcludeFile = NULL; double WireDelay = 0.0; int fShortNames = 0; + int nFaninLimit = 0; int c, fVerbose = 1; pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); Extra_UtilGetoptReset(); - while ( (c = Extra_UtilGetopt(argc, argv, "WEnvh")) != EOF ) + while ( (c = Extra_UtilGetopt(argc, argv, "WEKnvh")) != EOF ) { switch (c) { @@ -320,6 +321,15 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) pExcludeFile = argv[globalUtilOptind]; globalUtilOptind++; break; + case 'K': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-K\" should be followed by a file name.\n" ); + goto usage; + } + nFaninLimit = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + break; case 'n': fShortNames ^= 1; break; @@ -351,7 +361,7 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) fclose( pFile ); // set the new network - pLib = Mio_LibraryRead( pFileName, NULL, pExcludeFile, fVerbose ); + pLib = Mio_LibraryRead( pFileName, NULL, pExcludeFile, nFaninLimit, fVerbose ); if ( pLib == NULL ) { fprintf( pErr, "Reading genlib library has failed.\n" ); @@ -382,13 +392,14 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) return 0; usage: - fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-nvh]\n"); + fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-K num] [-nvh]\n"); fprintf( pErr, "\t read the library from a genlib file\n" ); fprintf( pErr, "\t (if the library contains more than one gate\n" ); fprintf( pErr, "\t with the same Boolean function, only the gate\n" ); fprintf( pErr, "\t with the smallest area will be used)\n" ); fprintf( pErr, "\t-W float : wire delay (added to pin-to-pin gate delays) [default = %g]\n", WireDelay ); - fprintf( pErr, "\t-E file : the file name with gates to be excluded [default = none]\n" ); + fprintf( pErr, "\t-E file : the file name with gates to be excluded [default = none]\n" ); + fprintf( pErr, "\t-K num : the max number of gate fanins (0 = no limit) [default = %d]\n", nFaninLimit ); fprintf( pErr, "\t-n : toggle replacing gate/pin names by short strings [default = %s]\n", fShortNames? "yes": "no" ); fprintf( pErr, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" ); fprintf( pErr, "\t-h : enable verbose output\n"); diff --git a/src/map/mio/mio.h b/src/map/mio/mio.h index 1a072a502..ce6f0aa9b 100644 --- a/src/map/mio/mio.h +++ b/src/map/mio/mio.h @@ -178,7 +178,7 @@ extern double Mio_PinReadDelayBlockMax ( Mio_Pin_t * pPin ); extern Mio_Pin_t * Mio_PinReadNext ( Mio_Pin_t * pPin ); /*=== mioRead.c =============================================================*/ extern char * Mio_ReadFile( char * FileName, int fAddEnd ); -extern Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * ExcludeFile, int fVerbose ); +extern Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * ExcludeFile, int nFaninLimit, int fVerbose ); extern int Mio_LibraryReadExclude( char * ExcludeFile, st__table * tExcludeGate ); /*=== mioFunc.c =============================================================*/ extern int Mio_LibraryParseFormulas( Mio_Library_t * pLib ); diff --git a/src/map/mio/mioRead.c b/src/map/mio/mioRead.c index c19c07d4d..79d5dc4ef 100644 --- a/src/map/mio/mioRead.c +++ b/src/map/mio/mioRead.c @@ -31,9 +31,9 @@ ABC_NAMESPACE_IMPL_START /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// -static Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st__table * tExcludeGate, int fVerbose ); - Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int fVerbose ); -static int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int fVerbose ); +static Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st__table * tExcludeGate, int nFaninLimit, int fVerbose ); + Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int nFaninLimit, int fVerbose ); +static int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int nFaninLimit, int fVerbose ); static Mio_Gate_t * Mio_LibraryReadGate( char ** ppToken, int fExtendedFormat ); static Mio_Pin_t * Mio_LibraryReadPin( char ** ppToken, int fExtendedFormat ); static char * chomp( char *s ); @@ -51,7 +51,7 @@ static void Io_ReadFileRemoveComments( char * pBuffer, int * pnDots, SeeAlso [] ***********************************************************************/ -Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * ExcludeFile, int fVerbose ) +Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * ExcludeFile, int nFaninLimit, int fVerbose ) { Mio_Library_t * pLib; int num; @@ -73,20 +73,20 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * Exclude pBufferCopy = Abc_UtilStrsav(pBuffer); if ( pBuffer == NULL ) - pLib = Mio_LibraryReadOne( FileName, 0, tExcludeGate, fVerbose ); // try normal format first .. + pLib = Mio_LibraryReadOne( FileName, 0, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first .. else { - pLib = Mio_LibraryReadBuffer( pBuffer, 0, tExcludeGate, fVerbose ); // try normal format first .. + pLib = Mio_LibraryReadBuffer( pBuffer, 0, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first .. if ( pLib ) pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") ); } if ( pLib == NULL ) { if ( pBuffer == NULL ) - pLib = Mio_LibraryReadOne( FileName, 1, tExcludeGate, fVerbose ); // try normal format first .. + pLib = Mio_LibraryReadOne( FileName, 1, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first .. else { - pLib = Mio_LibraryReadBuffer( pBufferCopy, 1, tExcludeGate, fVerbose ); // try normal format first .. + pLib = Mio_LibraryReadBuffer( pBufferCopy, 1, tExcludeGate, nFaninLimit, fVerbose ); // try normal format first .. if ( pLib ) pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") ); } @@ -152,7 +152,7 @@ char * Mio_ReadFile( char * FileName, int fAddEnd ) SeeAlso [] ***********************************************************************/ -Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int fVerbose ) +Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int nFaninLimit, int fVerbose ) { Mio_Library_t * pLib; @@ -165,7 +165,7 @@ Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__ Io_ReadFileRemoveComments( pBuffer, NULL, NULL ); // parse the contents of the file - if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, fVerbose ) ) + if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, nFaninLimit, fVerbose ) ) { Mio_LibraryDelete( pLib ); return NULL; @@ -196,7 +196,7 @@ Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st__ SeeAlso [] ***********************************************************************/ -Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st__table * tExcludeGate, int fVerbose ) +Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st__table * tExcludeGate, int nFaninLimit, int fVerbose ) { Mio_Library_t * pLib; char * pBuffer; @@ -207,7 +207,7 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st__ta pBuffer = Mio_ReadFile( FileName, 1 ); if ( pBuffer == NULL ) return NULL; - pLib = Mio_LibraryReadBuffer( pBuffer, fExtendedFormat, tExcludeGate, fVerbose ); + pLib = Mio_LibraryReadBuffer( pBuffer, fExtendedFormat, tExcludeGate, nFaninLimit, fVerbose ); ABC_FREE( pBuffer ); if ( pLib ) pLib->pName = Abc_UtilStrsav( FileName ); @@ -225,7 +225,7 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st__ta SeeAlso [] ***********************************************************************/ -int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int fVerbose ) +int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtendedFormat, st__table * tExcludeGate, int nFaninLimit, int fVerbose ) { Mio_Gate_t * pGate, ** ppGate; char * pToken; @@ -262,6 +262,19 @@ int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtended if ( pGate == NULL ) return 1; + // consider the fanin limit + if ( nFaninLimit ) + { + Mio_Pin_t * pPin; int nIns = 0; + for ( pPin = Mio_GateReadPins(pGate); pPin; pPin = Mio_PinReadNext(pPin) ) + nIns++; + if ( nIns > nFaninLimit ) + { + Mio_GateDelete( pGate ); + continue; + } + } + // skip the gate if its formula has problems if ( !Mio_ParseCheckFormula(pGate, pGate->pForm) ) { diff --git a/src/map/scl/sclLibUtil.c b/src/map/scl/sclLibUtil.c index 9624be93e..147c67f3e 100644 --- a/src/map/scl/sclLibUtil.c +++ b/src/map/scl/sclLibUtil.c @@ -846,7 +846,7 @@ Mio_Library_t * Abc_SclDeriveGenlibSimple( void * pScl ) { SC_Lib * p = (SC_Lib *)pScl; Vec_Str_t * vStr = Abc_SclProduceGenlibStrSimple( p ); - Mio_Library_t * pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 ); + Mio_Library_t * pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0, 0 ); Vec_StrFree( vStr ); if ( pLib ) printf( "Derived GENLIB library \"%s\" with %d gates.\n", p->pName, SC_LibCellNum(p) ); @@ -1029,7 +1029,7 @@ Mio_Library_t * Abc_SclDeriveGenlib( void * pScl, void * pMio, float SlewInit, f vStr = Abc_SclProduceGenlibStr( p, Slew, Gain, nGatesMin, &nCellCount ); else vStr = Abc_SclProduceGenlibStrProfile( p, (Mio_Library_t *)pMio, Slew, Gain, nGatesMin, &nCellCount ); - pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0 ); + pLib = Mio_LibraryRead( p->pFileName, Vec_StrArray(vStr), NULL, 0, 0 ); Vec_StrFree( vStr ); if ( !pLib ) printf( "Reading library has filed.\n" ); diff --git a/src/map/super/super.c b/src/map/super/super.c index 7868ba78e..21b193845 100644 --- a/src/map/super/super.c +++ b/src/map/super/super.c @@ -267,7 +267,7 @@ int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv ) fclose( pFile ); // set the new network - pLib = Mio_LibraryRead( FileName, NULL, ExcludeFile, fVerbose ); + pLib = Mio_LibraryRead( FileName, NULL, ExcludeFile, nVarsMax, fVerbose ); if ( pLib == NULL ) { fprintf( pErr, "Reading library has failed.\n" );