From 5bf0f864505d97ea7d6a349f100dd1849f74b7a6 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Mon, 24 Aug 2015 17:40:20 -0700 Subject: New switch in 'read_lib' to replace gate/pin names by short strings. --- src/map/scl/scl.c | 12 +++++-- src/map/scl/sclLib.h | 1 + src/map/scl/sclLibUtil.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) (limited to 'src/map') diff --git a/src/map/scl/scl.c b/src/map/scl/scl.c index 53672073..bd917ca3 100644 --- a/src/map/scl/scl.c +++ b/src/map/scl/scl.c @@ -139,11 +139,12 @@ int Scl_CommandReadLib( Abc_Frame_t * pAbc, int argc, char ** argv ) float Slew = 0; float Gain = 0; int nGatesMin = 0; + int fShortNames = 0; int fVerbose = 1; int fVeryVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "SGMdvwh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "SGMdnvwh" ) ) != EOF ) { switch ( c ) { @@ -183,6 +184,9 @@ int Scl_CommandReadLib( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'd': fDump ^= 1; break; + case 'n': + fShortNames ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -219,6 +223,9 @@ int Scl_CommandReadLib( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; } Abc_SclLoad( pLib, (SC_Lib **)&pAbc->pLibScl ); + // convert the library if needed + if ( fShortNames ) + Abc_SclShortNames( pLib ); // dump the resulting library if ( fDump && pAbc->pLibScl ) Abc_SclWriteLiberty( Extra_FileNameGenericAppend(pFileName, "_temp.lib"), (SC_Lib *)pAbc->pLibScl ); @@ -228,12 +235,13 @@ int Scl_CommandReadLib( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; usage: - fprintf( pAbc->Err, "usage: read_lib [-SG float] [-M num] [-dvwh] \n" ); + fprintf( pAbc->Err, "usage: read_lib [-SG float] [-M num] [-dnvwh] \n" ); fprintf( pAbc->Err, "\t reads Liberty library from file\n" ); fprintf( pAbc->Err, "\t-S float : the slew parameter used to generate the library [default = %.2f]\n", Slew ); fprintf( pAbc->Err, "\t-G float : the gain parameter used to generate the library [default = %.2f]\n", Gain ); fprintf( pAbc->Err, "\t-M num : skip gate classes whose size is less than this [default = %d]\n", nGatesMin ); fprintf( pAbc->Err, "\t-d : toggle dumping the parsed library into file \"*_temp.lib\" [default = %s]\n", fDump? "yes": "no" ); + fprintf( pAbc->Err, "\t-n : toggle replacing gate/pin names by short strings [default = %s]\n", fShortNames? "yes": "no" ); fprintf( pAbc->Err, "\t-v : toggle writing verbose information [default = %s]\n", fVerbose? "yes": "no" ); fprintf( pAbc->Err, "\t-v : toggle writing information about skipped gates [default = %s]\n", fVeryVerbose? "yes": "no" ); fprintf( pAbc->Err, "\t-h : prints the command summary\n" ); diff --git a/src/map/scl/sclLib.h b/src/map/scl/sclLib.h index 44cff1ce..4dc80758 100644 --- a/src/map/scl/sclLib.h +++ b/src/map/scl/sclLib.h @@ -615,6 +615,7 @@ extern void Abc_SclWriteLiberty( char * pFileName, SC_Lib * p ); extern void Abc_SclHashCells( SC_Lib * p ); extern int Abc_SclCellFind( SC_Lib * p, char * pName ); extern int Abc_SclClassCellNum( SC_Cell * pClass ); +extern void Abc_SclShortNames( SC_Lib * p ); extern int Abc_SclLibClassNum( SC_Lib * pLib ); extern void Abc_SclLinkCells( SC_Lib * p ); extern void Abc_SclPrintCells( SC_Lib * p, float Slew, float Gain, int fInvOnly, int fShort ); diff --git a/src/map/scl/sclLibUtil.c b/src/map/scl/sclLibUtil.c index bb70ee9b..b5ccacdf 100644 --- a/src/map/scl/sclLibUtil.c +++ b/src/map/scl/sclLibUtil.c @@ -99,6 +99,100 @@ int Abc_SclLibClassNum( SC_Lib * pLib ) return Count; } +/**Function************************************************************* + + Synopsis [Change cell names and pin names.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Abc_SclIsChar( char c ) +{ + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; +} +static inline int Abc_SclIsName( char c ) +{ + return Abc_SclIsChar(c) || (c >= '0' && c <= '9'); +} +static inline char * Abc_SclFindLimit( char * pName ) +{ + assert( Abc_SclIsChar(*pName) ); + while ( Abc_SclIsName(*pName) ) + pName++; + return pName; +} +static inline int Abc_SclAreEqual( char * pBase, char * pName, char * pLimit ) +{ + return !strncmp( pBase, pName, pLimit - pName ); +} +void Abc_SclShortFormula( SC_Cell * pCell, char * pForm, char * pBuffer ) +{ + SC_Pin * pPin; int i; + char * pTemp, * pLimit; + for ( pTemp = pForm; *pTemp; ) + { + if ( !Abc_SclIsChar(*pTemp) ) + { + *pBuffer++ = *pTemp++; + continue; + } + pLimit = Abc_SclFindLimit( pTemp ); + SC_CellForEachPinIn( pCell, pPin, i ) + if ( Abc_SclAreEqual( pPin->pName, pTemp, pLimit ) ) + { + *pBuffer++ = 'a' + i; + break; + } + assert( i < pCell->n_inputs ); + pTemp = pLimit; + } + *pBuffer++ = 0; +} +void Abc_SclShortNames( SC_Lib * p ) +{ + char Buffer[10000]; + SC_Cell * pClass, * pCell; SC_Pin * pPin; + int i, k, n, nClasses = Abc_SclLibClassNum(p); + int nDigits = Abc_Base10Log( nClasses ); + // itereate through classes + SC_LibForEachCellClass( p, pClass, i ) + { + int nDigits2 = Abc_Base10Log( Abc_SclClassCellNum(pClass) ); + SC_RingForEachCell( pClass, pCell, k ) + { + ABC_FREE( pCell->pName ); + sprintf( Buffer, "g%0*d_%0*d", nDigits, i, nDigits2, k ); + pCell->pName = Abc_UtilStrsav( Buffer ); + // formula + SC_CellForEachPinOut( pCell, pPin, n ) + { + Abc_SclShortFormula( pCell, pPin->func_text, Buffer ); + ABC_FREE( pPin->func_text ); + pPin->func_text = Abc_UtilStrsav( Buffer ); + } + // pin names + SC_CellForEachPinIn( pCell, pPin, n ) + { + ABC_FREE( pPin->pName ); + sprintf( Buffer, "%c", 'a'+n ); + pPin->pName = Abc_UtilStrsav( Buffer ); + } + SC_CellForEachPinOut( pCell, pPin, n ) + { + ABC_FREE( pPin->pName ); + sprintf( Buffer, "%c", 'z'-n+pCell->n_inputs ); + pPin->pName = Abc_UtilStrsav( Buffer ); + } + } + } + p->nBins = 0; + ABC_FREE( p->pBins ); + Abc_SclHashCells( p ); +} /**Function************************************************************* Synopsis [Links equal gates into rings while sorting them by area.] -- cgit v1.2.3