Commit 20a2b0a0 by Alan Mishchenko

Added switch 'read_genlib -n' to anonymize Genlib library.

parent fa111ff8
......@@ -286,18 +286,14 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
Amap_Lib_t * pLib2;
char * pFileName;
char * pExcludeFile = NULL;
int fVerbose;
double WireDelay;
int c;
double WireDelay = 0.0;
int fShortNames = 0;
int c, fVerbose = 1;
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
// set the defaults
WireDelay = 0.0;
fVerbose = 1;
Extra_UtilGetoptReset();
while ( (c = Extra_UtilGetopt(argc, argv, "WEvh")) != EOF )
while ( (c = Extra_UtilGetopt(argc, argv, "WEnvh")) != EOF )
{
switch (c)
{
......@@ -321,6 +317,9 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
pExcludeFile = argv[globalUtilOptind];
globalUtilOptind++;
break;
case 'n':
fShortNames ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
......@@ -358,6 +357,10 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
if ( fVerbose )
printf( "Entered genlib library with %d gates from file \"%s\".\n", Mio_LibraryReadGateNum(pLib), pFileName );
// convert the library if needed
if ( fShortNames )
Mio_LibraryShortNames( pLib );
// add the fixed number (wire delay) to all delays in the library
if ( WireDelay != 0.0 )
Mio_LibraryShiftDelay( pLib, WireDelay );
......@@ -376,13 +379,14 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
return 0;
usage:
fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-vh]\n");
fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-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-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");
return 1;
......
......@@ -213,6 +213,7 @@ extern void Mio_LibraryTransferProfile( Mio_Library_t * pLibDst, Mi
extern void Mio_LibraryTransferProfile2( Mio_Library_t * pLibDst, Mio_Library_t * pLibSrc );
extern int Mio_LibraryHasProfile( Mio_Library_t * pLib );
extern void Mio_LibraryCleanProfile2( Mio_Library_t * pLib );
extern void Mio_LibraryShortNames( Mio_Library_t * pLib );
/*=== sclUtil.c =========================================================*/
extern Mio_Library_t * Abc_SclDeriveGenlibSimple( void * pScl );
......
......@@ -1465,6 +1465,131 @@ void Mio_LibraryCleanProfile2( Mio_Library_t * pLib )
Mio_GateSetProfile2( pGate, 0 );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Mio_LibraryHashGates( Mio_Library_t * pLib )
{
Mio_Gate_t * pGate;
Mio_LibraryForEachGate( pLib, pGate )
if ( pGate->pTwin )
{
printf( "Gates with multiple outputs are not supported.\n" );
return;
}
if ( pLib->tName2Gate )
st__free_table( pLib->tName2Gate );
pLib->tName2Gate = st__init_table(strcmp, st__strhash);
Mio_LibraryForEachGate( pLib, pGate )
st__insert( pLib->tName2Gate, pGate->pName, (char *)pGate );
}
/**Function*************************************************************
Synopsis []
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 Mio_LibraryShortFormula( Mio_Gate_t * pCell, char * pForm, char * pBuffer )
{
Mio_Pin_t * pPin;
char * pTemp, * pLimit; int i;
if ( !strncmp(pForm, "CONST", 5) )
{
sprintf( pBuffer, "%s", pForm );
return;
}
for ( pTemp = pForm; *pTemp; )
{
if ( !Abc_SclIsChar(*pTemp) )
{
*pBuffer++ = *pTemp++;
continue;
}
pLimit = Abc_SclFindLimit( pTemp );
i = 0;
Mio_GateForEachPin( pCell, pPin )
{
if ( Abc_SclAreEqual( pPin->pName, pTemp, pLimit ) )
{
*pBuffer++ = 'a' + i;
break;
}
i++;
}
pTemp = pLimit;
}
*pBuffer++ = 0;
}
void Mio_LibraryShortNames( Mio_Library_t * pLib )
{
char Buffer[10000];
Mio_Gate_t * pGate; Mio_Pin_t * pPin;
int c = 0, i, nDigits = Abc_Base10Log( Mio_LibraryReadGateNum(pLib) );
// itereate through classes
Mio_LibraryForEachGate( pLib, pGate )
{
ABC_FREE( pGate->pName );
sprintf( Buffer, "g%0*d", nDigits, ++c );
pGate->pName = Abc_UtilStrsav( Buffer );
// update formula
Mio_LibraryShortFormula( pGate, pGate->pForm, Buffer );
ABC_FREE( pGate->pForm );
pGate->pForm = Abc_UtilStrsav( Buffer );
// pin names
i = 0;
Mio_GateForEachPin( pGate, pPin )
{
ABC_FREE( pPin->pName );
sprintf( Buffer, "%c", 'a'+i );
pPin->pName = Abc_UtilStrsav( Buffer );
i++;
}
// output pin
ABC_FREE( pGate->pOutName );
sprintf( Buffer, "z" );
pGate->pOutName = Abc_UtilStrsav( Buffer );
}
Mio_LibraryHashGates( pLib );
// update library name
printf( "Renaming library \"%s\" into \"%s%d\".\n", pLib->pName, "lib", Mio_LibraryReadGateNum(pLib) );
ABC_FREE( pLib->pName );
sprintf( Buffer, "lib%d", Mio_LibraryReadGateNum(pLib) );
pLib->pName = Abc_UtilStrsav( Buffer );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment