summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/map/mapper/mapper.c4
-rw-r--r--src/map/mapper/mapperInt.h4
-rw-r--r--src/map/mapper/mapperLib.c66
-rw-r--r--src/map/mapper/mapperSuper.c6
-rw-r--r--src/map/mapper/mapperTree.c442
-rw-r--r--src/map/mio/mio.c10
-rw-r--r--src/map/mio/mio.h1
-rw-r--r--src/map/mio/mioRead.c15
-rw-r--r--src/map/super/super.c7
-rw-r--r--src/map/super/super.h12
-rw-r--r--src/map/super/superGate.c365
-rw-r--r--src/map/super/superInt.h6
12 files changed, 669 insertions, 269 deletions
diff --git a/src/map/mapper/mapper.c b/src/map/mapper/mapper.c
index db06f1fd..17102cec 100644
--- a/src/map/mapper/mapper.c
+++ b/src/map/mapper/mapper.c
@@ -143,11 +143,11 @@ int Map_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
fclose( pFile );
// set the new network
- pLib = Map_SuperLibCreate( FileName, ExcludeFile, fAlgorithm, fVerbose );
+ pLib = Map_SuperLibCreate( NULL, FileName, ExcludeFile, fAlgorithm, fVerbose );
if ( pLib == NULL )
{
fprintf( pErr, "Reading supergate library has failed.\n" );
- goto usage;
+ return 1;
}
// replace the current library
// Map_SuperLibFree( s_pSuperLib );
diff --git a/src/map/mapper/mapperInt.h b/src/map/mapper/mapperInt.h
index 5afbcca7..1740d4e9 100644
--- a/src/map/mapper/mapperInt.h
+++ b/src/map/mapper/mapperInt.h
@@ -378,7 +378,7 @@ extern void Map_NodeAddFaninFanout( Map_Node_t * pFanin, Map_Node_t
extern void Map_NodeRemoveFaninFanout( Map_Node_t * pFanin, Map_Node_t * pFanoutToRemove );
extern int Map_NodeGetFanoutNum( Map_Node_t * pNode );
/*=== mapperLib.c ============================================================*/
-extern Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose );
+extern Map_SuperLib_t * Map_SuperLibCreate( Vec_Str_t * vStr, char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose );
extern void Map_SuperLibFree( Map_SuperLib_t * p );
/*=== mapperMatch.c ===============================================================*/
extern int Map_MappingMatches( Map_Man_t * p );
@@ -405,6 +405,8 @@ extern float Map_MappingGetArea( Map_Man_t * pMan, Map_NodeVec_t * v
/*=== mapperShow.c =============================================================*/
extern void Map_MappingShow( Map_Man_t * pMan, char * pFileName );
/*=== mapperTree.c ===============================================================*/
+extern int Map_LibraryDeriveGateInfo( Map_SuperLib_t * pLib, st_table * tExcludeGate );
+extern int Map_LibraryReadFileTreeStr( Map_SuperLib_t * pLib, Vec_Str_t * vStr, char * pFileName );
extern int Map_LibraryReadTree( Map_SuperLib_t * pLib, char * pFileName, char * pExcludeFile );
extern void Map_LibraryPrintTree( Map_SuperLib_t * pLib );
/*=== mapperSuper.c ===============================================================*/
diff --git a/src/map/mapper/mapperLib.c b/src/map/mapper/mapperLib.c
index b1436d19..91ba6dcc 100644
--- a/src/map/mapper/mapperLib.c
+++ b/src/map/mapper/mapperLib.c
@@ -22,6 +22,8 @@
#endif
#include "mapperInt.h"
+#include "map/super/super.h"
+#include "map/mapper/mapperInt.h"
ABC_NAMESPACE_IMPL_START
@@ -53,7 +55,7 @@ ABC_NAMESPACE_IMPL_START
SeeAlso []
***********************************************************************/
-Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose )
+Map_SuperLib_t * Map_SuperLibCreate( Vec_Str_t * vStr, char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose )
{
Map_SuperLib_t * p;
clock_t clk;
@@ -61,7 +63,7 @@ Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, int
// start the supergate library
p = ABC_ALLOC( Map_SuperLib_t, 1 );
memset( p, 0, sizeof(Map_SuperLib_t) );
- p->pName = pFileName;
+ p->pName = Abc_UtilStrsav(pFileName);
p->fVerbose = fVerbose;
p->mmSupers = Extra_MmFixedStart( sizeof(Map_Super_t) );
p->mmEntries = Extra_MmFixedStart( sizeof(Map_HashEntry_t) );
@@ -74,7 +76,25 @@ Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, int
// read the supergate library from file
clk = clock();
- if ( fAlgorithm )
+ if ( vStr != NULL )
+ {
+ // read the supergate library from file
+ int Status = Map_LibraryReadFileTreeStr( p, vStr, pFileName );
+ if ( Status == 0 )
+ {
+ Map_SuperLibFree( p );
+ return NULL;
+ }
+ // prepare the info about the library
+ Status = Map_LibraryDeriveGateInfo( p, NULL );
+ if ( Status == 0 )
+ {
+ Map_SuperLibFree( p );
+ return NULL;
+ }
+ assert( p->nVarsMax > 0 );
+ }
+ else if ( fAlgorithm )
{
if ( !Map_LibraryReadTree( p, pFileName, pExcludeFile ) )
{
@@ -162,6 +182,7 @@ void Map_SuperLibFree( Map_SuperLib_t * p )
Extra_MmFixedStop( p->mmEntries );
Extra_MmFlexStop( p->mmForms );
ABC_FREE( p->ppSupers );
+ ABC_FREE( p->pName );
ABC_FREE( p );
}
@@ -178,15 +199,47 @@ void Map_SuperLibFree( Map_SuperLib_t * p )
***********************************************************************/
int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib, int fVerbose )
{
- extern void Super_Precompute( Mio_Library_t * pLibGen, int nInputs, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fWriteOldFormat, int fVerbose );
+ Map_SuperLib_t * pLibSuper;
+ Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
+ Vec_Str_t * vStr;
+ char * pFileName;
+ if ( pLib == NULL )
+ return 0;
+ // compute supergates
+ vStr = Super_PrecomputeStr( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0 );
+ if ( vStr == NULL )
+ return 0;
+ // create supergate library
+ pFileName = Extra_FileNameGenericAppend( Mio_LibraryReadName(pLib), ".super" );
+ pLibSuper = Map_SuperLibCreate( vStr, pFileName, NULL, 1, 0 );
+ Vec_StrFree( vStr );
+ // replace the library
+ Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
+ Abc_FrameSetLibSuper( pLibSuper );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Derives the library from the genlib library.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Map_SuperLibDeriveFromGenlib2( Mio_Library_t * pLib, int fVerbose )
+{
Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
char * pFileName;
if ( pLib == NULL )
return 0;
// compute supergates
- Super_Precompute( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0, 0 );
- // assuming that it terminated successfully
pFileName = Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super");
+ Super_Precompute( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0, pFileName );
+ // assuming that it terminated successfully
if ( Cmd_CommandExecute( pAbc, pFileName ) )
{
fprintf( stdout, "Cannot execute command \"read_super %s\".\n", pFileName );
@@ -195,7 +248,6 @@ int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib, int fVerbose )
return 1;
}
-
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/map/mapper/mapperSuper.c b/src/map/mapper/mapperSuper.c
index c945ebdb..a8682a1b 100644
--- a/src/map/mapper/mapperSuper.c
+++ b/src/map/mapper/mapperSuper.c
@@ -103,13 +103,13 @@ int Map_LibraryReadFile( Map_SuperLib_t * pLib, FILE * pFile )
pLibName = strtok( pTemp, " \t\r\n" );
if ( strcmp( pLibName, "GATE" ) == 0 )
{
- printf( "The input file \"%s\" looks like a GENLIB file and not a supergate library file.\n", pLib->pName );
+ printf( "The input file \"%s\" looks like a genlib file and not a supergate library file.\n", pLib->pName );
return 0;
}
pFileGen = fopen( pLibName, "r" );
if ( pFileGen == NULL )
{
- printf( "Cannot open the GENLIB file \"%s\".\n", pLibName );
+ printf( "Cannot open the genlib file \"%s\".\n", pLibName );
return 0;
}
fclose( pFileGen );
@@ -118,7 +118,7 @@ int Map_LibraryReadFile( Map_SuperLib_t * pLib, FILE * pFile )
pLib->pGenlib = Mio_LibraryRead( pLibName, NULL, 0, 0 );
if ( pLib->pGenlib == NULL )
{
- printf( "Cannot read GENLIB file \"%s\".\n", pLibName );
+ printf( "Cannot read genlib file \"%s\".\n", pLibName );
return 0;
}
diff --git a/src/map/mapper/mapperTree.c b/src/map/mapper/mapperTree.c
index 6d240c56..62d11c53 100644
--- a/src/map/mapper/mapperTree.c
+++ b/src/map/mapper/mapperTree.c
@@ -29,12 +29,9 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
-static int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileName );
-static Map_Super_t * Map_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 );
+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 );
// fanout limits
static const int s_MapFanoutLimits[10] = { 1/*0*/, 10/*1*/, 5/*2*/, 2/*3*/, 1/*4*/, 1/*5*/, 1/*6*/ };
@@ -45,7 +42,7 @@ static const int s_MapFanoutLimits[10] = { 1/*0*/, 10/*1*/, 5/*2*/, 2/*3*/, 1/*4
/**Function*************************************************************
- Synopsis [Reads the supergate library from file.]
+ Synopsis [Reads one gate.]
Description []
@@ -54,50 +51,89 @@ static const int s_MapFanoutLimits[10] = { 1/*0*/, 10/*1*/, 5/*2*/, 2/*3*/, 1/*4
SeeAlso []
***********************************************************************/
-int Map_LibraryReadTree( Map_SuperLib_t * pLib, char * pFileName, char * pExcludeFile )
+Map_Super_t * Map_LibraryReadGateTree( Map_SuperLib_t * pLib, char * pBuffer, int Number, int nVarsMax )
{
- FILE * pFile;
- int Status, num;
- Abc_Frame_t * pAbc;
- st_table * tExcludeGate = 0;
+ Map_Super_t * pGate;
+ char * pTemp;
+ int i, Num;
- // read the beginning of the file
- assert( pLib->pGenlib == NULL );
- pFile = Io_FileOpen( pFileName, "open_path", "r", 1 );
-// pFile = fopen( pFileName, "r" );
- if ( pFile == NULL )
+ // start and clean the gate
+ pGate = (Map_Super_t *)Extra_MmFixedEntryFetch( pLib->mmSupers );
+ memset( pGate, 0, sizeof(Map_Super_t) );
+
+ // set the gate number
+ pGate->Num = Number;
+
+ // read the mark
+ pTemp = strtok( pBuffer, " " );
+ if ( pTemp[0] == '*' )
{
- printf( "Cannot open input file \"%s\".\n", pFileName );
- return 0;
+ pGate->fSuper = 1;
+ pTemp = strtok( NULL, " " );
}
- if ( pExcludeFile )
+ // read the root gate
+ pGate->pRoot = Mio_LibraryReadGateByName( pLib->pGenlib, pTemp, NULL );
+ if ( pGate->pRoot == NULL )
{
- pAbc = Abc_FrameGetGlobalFrame();
-
- tExcludeGate = st_init_table(strcmp, st_strhash);
- if ( (num = Mio_LibraryReadExclude( pExcludeFile, tExcludeGate )) == -1 )
+ printf( "Cannot read the root gate names %s.\n", pTemp );
+ return NULL;
+ }
+ // set the max number of fanouts
+ pGate->nFanLimit = s_MapFanoutLimits[ Mio_GateReadPinNum(pGate->pRoot) ];
+
+ // read the pin-to-pin delay
+ for ( i = 0; ( pTemp = strtok( NULL, " \n\0" ) ); i++ )
+ {
+ if ( pTemp[0] == '#' )
+ break;
+ if ( i == nVarsMax )
{
- st_free_table( tExcludeGate );
- tExcludeGate = 0;
- return 0;
+ printf( "There are too many entries on the line.\n" );
+ return NULL;
}
+ Num = atoi(pTemp);
+ if ( Num < 0 )
+ {
+ printf( "The number of a child supergate is negative.\n" );
+ return NULL;
+ }
+ if ( Num > pLib->nLines )
+ {
+ printf( "The number of a child supergate (%d) exceeded the number of lines (%d).\n",
+ Num, pLib->nLines );
+ return NULL;
+ }
+ pGate->pFanins[i] = pLib->ppSupers[Num];
+ }
+ pGate->nFanins = i;
+ if ( pGate->nFanins != (unsigned)Mio_GateReadPinNum(pGate->pRoot) )
+ {
+ printf( "The number of fanins of a root gate is wrong.\n" );
+ return NULL;
+ }
- fprintf ( Abc_FrameReadOut( pAbc ), "Read %d gates from exclude file\n", num );
+ // save the gate name, just in case
+ if ( pTemp && pTemp[0] == '#' )
+ {
+ if ( pTemp[1] == 0 )
+ pTemp = strtok( NULL, " \n\0" );
+ else // skip spaces
+ for ( pTemp++; *pTemp == ' '; pTemp++ );
+ // save the formula
+ pGate->pFormula = Extra_MmFlexEntryFetch( pLib->mmForms, strlen(pTemp)+1 );
+ strcpy( pGate->pFormula, pTemp );
}
-
- Status = Map_LibraryReadFileTree( pLib, pFile, pFileName );
- fclose( pFile );
- if ( Status == 0 )
- return 0;
- // prepare the info about the library
- return Map_LibraryDeriveGateInfo( pLib, tExcludeGate );
+ // check the rest of the string
+ pTemp = strtok( NULL, " \n\0" );
+ if ( pTemp != NULL )
+ printf( "The following trailing symbols found \"%s\".\n", pTemp );
+ return pGate;
}
-
/**Function*************************************************************
- Synopsis [Reads the library file.]
+ Synopsis [Reads the supergate library from file.]
Description []
@@ -129,7 +165,7 @@ int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileNam
pLib->pGenlib = Abc_FrameReadLibGen();
if ( pLib->pGenlib == NULL || strcmp( Mio_LibraryReadName(pLib->pGenlib), pLibName ) )
{
- printf( "Supergate library \"%s\" requires the use of Genlib library \"%s\".\n", pFileName, pLibName );
+ printf( "Supergate library \"%s\" requires the use of genlib library \"%s\".\n", pFileName, pLibName );
return 0;
}
@@ -224,10 +260,49 @@ int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileNam
pLib->nSupersReal = nCounter;
return 1;
}
+int Map_LibraryReadTree2( Map_SuperLib_t * pLib, char * pFileName, char * pExcludeFile )
+{
+ FILE * pFile;
+ int Status, num;
+ Abc_Frame_t * pAbc;
+ st_table * tExcludeGate = 0;
+
+ // read the beginning of the file
+ assert( pLib->pGenlib == NULL );
+ pFile = Io_FileOpen( pFileName, "open_path", "r", 1 );
+// pFile = fopen( pFileName, "r" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open input file \"%s\".\n", pFileName );
+ return 0;
+ }
+
+ if ( pExcludeFile )
+ {
+ pAbc = Abc_FrameGetGlobalFrame();
+
+ tExcludeGate = st_init_table(strcmp, st_strhash);
+ if ( (num = Mio_LibraryReadExclude( pExcludeFile, tExcludeGate )) == -1 )
+ {
+ st_free_table( tExcludeGate );
+ tExcludeGate = 0;
+ return 0;
+ }
+
+ fprintf ( Abc_FrameReadOut( pAbc ), "Read %d gates from exclude file\n", num );
+ }
+
+ Status = Map_LibraryReadFileTree( pLib, pFile, pFileName );
+ fclose( pFile );
+ if ( Status == 0 )
+ return 0;
+ // prepare the info about the library
+ return Map_LibraryDeriveGateInfo( pLib, tExcludeGate );
+}
/**Function*************************************************************
- Synopsis [Reads one gate.]
+ Synopsis [Similar to fgets.]
Description []
@@ -236,87 +311,264 @@ int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileNam
SeeAlso []
***********************************************************************/
-Map_Super_t * Map_LibraryReadGateTree( Map_SuperLib_t * pLib, char * pBuffer, int Number, int nVarsMax )
+int Vec_StrGets( char * pBuffer, int nBufferSize, Vec_Str_t * vStr, int * pPos )
{
+ char * pCur;
+ char * pBeg = Vec_StrArray(vStr) + *pPos;
+ char * pEnd = Vec_StrArray(vStr) + Vec_StrSize(vStr);
+ assert( nBufferSize > 1 );
+ if ( pBeg == pEnd )
+ {
+ *pBuffer = 0;
+ return 0;
+ }
+ assert( pBeg < pEnd );
+ for ( pCur = pBeg; pCur < pEnd; pCur++ )
+ {
+ *pBuffer++ = *pCur;
+ if ( *pCur == 0 )
+ {
+ *pPos += pCur - pBeg;
+ return 0;
+ }
+ if ( *pCur == '\n' )
+ {
+ *pPos += pCur - pBeg + 1;
+ *pBuffer = 0;
+ return 1;
+ }
+ if ( pCur - pBeg == nBufferSize-1 )
+ {
+ *pPos += pCur - pBeg + 1;
+ *pBuffer = 0;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Map_LibraryCompareLibNames( char * pName1, char * pName2 )
+{
+ char * p1 = Abc_UtilStrsav( pName1 );
+ char * p2 = Abc_UtilStrsav( pName2 );
+ int i, RetValue;
+ for ( i = 0; p1[i]; i++ )
+ if ( p1[i] == '>' || p1[i] == '\\' || p1[i] == '/' )
+ p1[i] = '/';
+ for ( i = 0; p2[i]; i++ )
+ if ( p2[i] == '>' || p2[i] == '\\' || p2[i] == '/' )
+ p2[i] = '/';
+ RetValue = strcmp( p1, p2 );
+ ABC_FREE( p1 );
+ ABC_FREE( p2 );
+ return RetValue;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Reads the supergate library from file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Map_LibraryReadFileTreeStr( Map_SuperLib_t * pLib, Vec_Str_t * vStr, char * pFileName )
+{
+ ProgressBar * pProgress;
+ char pBuffer[5000];
Map_Super_t * pGate;
- char * pTemp;
- int i, Num;
+ char * pTemp = 0, * pLibName;
+ int nCounter, k, i;
+ int RetValue, nPos = 0;
- // start and clean the gate
- pGate = (Map_Super_t *)Extra_MmFixedEntryFetch( pLib->mmSupers );
- memset( pGate, 0, sizeof(Map_Super_t) );
+ // skip empty and comment lines
+// while ( fgets( pBuffer, 5000, pFile ) != NULL )
+ while ( 1 )
+ {
+ RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
+ if ( RetValue == 0 )
+ return 0;
+ // skip leading spaces
+ for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
+ // skip comment lines and empty lines
+ if ( *pTemp != 0 && *pTemp != '#' )
+ break;
+ }
- // set the gate number
- pGate->Num = Number;
+ pLibName = strtok( pTemp, " \t\r\n" );
+ pLib->pGenlib = Abc_FrameReadLibGen();
+// if ( pLib->pGenlib == NULL || strcmp( , pLibName ) )
+ if ( pLib->pGenlib == NULL || Map_LibraryCompareLibNames(Mio_LibraryReadName(pLib->pGenlib), pLibName) )
+ {
+ printf( "Supergate library \"%s\" requires the use of genlib library \"%s\".\n", pFileName, pLibName );
+ return 0;
+ }
- // read the mark
- pTemp = strtok( pBuffer, " " );
- if ( pTemp[0] == '*' )
+ // read the number of variables
+ RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
+ if ( RetValue == 0 )
+ return 0;
+ RetValue = sscanf( pBuffer, "%d\n", &pLib->nVarsMax );
+ if ( pLib->nVarsMax < 2 || pLib->nVarsMax > 10 )
{
- pGate->fSuper = 1;
- pTemp = strtok( NULL, " " );
+ printf( "Suspicious number of variables (%d).\n", pLib->nVarsMax );
+ return 0;
}
- // read the root gate
- pGate->pRoot = Mio_LibraryReadGateByName( pLib->pGenlib, pTemp, NULL );
- if ( pGate->pRoot == NULL )
+ // read the number of gates
+ RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
+ if ( RetValue == 0 )
+ return 0;
+ RetValue = sscanf( pBuffer, "%d\n", &pLib->nSupersReal );
+ if ( pLib->nSupersReal < 1 || pLib->nSupersReal > 10000000 )
{
- printf( "Cannot read the root gate names %s.\n", pTemp );
- return NULL;
+ printf( "Suspicious number of gates (%d).\n", pLib->nSupersReal );
+ return 0;
}
- // set the max number of fanouts
- pGate->nFanLimit = s_MapFanoutLimits[ Mio_GateReadPinNum(pGate->pRoot) ];
- // read the pin-to-pin delay
- for ( i = 0; ( pTemp = strtok( NULL, " \n\0" ) ); i++ )
+ // read the number of lines
+ RetValue = Vec_StrGets( pBuffer, 5000, vStr, &nPos );
+ if ( RetValue == 0 )
+ return 0;
+ RetValue = sscanf( pBuffer, "%d\n", &pLib->nLines );
+ if ( pLib->nLines < 1 || pLib->nLines > 10000000 )
{
- if ( pTemp[0] == '#' )
- break;
- if ( i == nVarsMax )
- {
- printf( "There are too many entries on the line.\n" );
- return NULL;
- }
- Num = atoi(pTemp);
- if ( Num < 0 )
+ printf( "Suspicious number of lines (%d).\n", pLib->nLines );
+ return 0;
+ }
+
+ // allocate room for supergate pointers
+ pLib->ppSupers = ABC_ALLOC( Map_Super_t *, pLib->nLines + 10000 );
+
+ // create the elementary supergates
+ for ( i = 0; i < pLib->nVarsMax; i++ )
+ {
+ // get a new gate
+ pGate = (Map_Super_t *)Extra_MmFixedEntryFetch( pLib->mmSupers );
+ memset( pGate, 0, sizeof(Map_Super_t) );
+ // assign the elementary variable, the truth table, and the delays
+ pGate->Num = i;
+ // set the truth table
+ pGate->uTruth[0] = pLib->uTruths[i][0];
+ pGate->uTruth[1] = pLib->uTruths[i][1];
+ // set the arrival times of all input to non-existent delay
+ for ( k = 0; k < pLib->nVarsMax; k++ )
{
- printf( "The number of a child supergate is negative.\n" );
- return NULL;
+ pGate->tDelaysR[k].Rise = pGate->tDelaysR[k].Fall = MAP_NO_VAR;
+ pGate->tDelaysF[k].Rise = pGate->tDelaysF[k].Fall = MAP_NO_VAR;
}
- if ( Num > pLib->nLines )
+ // set an existent arrival time for rise and fall
+ pGate->tDelaysR[i].Rise = 0.0;
+ pGate->tDelaysF[i].Fall = 0.0;
+ // set the gate
+ pLib->ppSupers[i] = pGate;
+ }
+
+ // read the lines
+ nCounter = pLib->nVarsMax;
+ pProgress = Extra_ProgressBarStart( stdout, pLib->nLines );
+// while ( fgets( pBuffer, 5000, pFile ) != NULL )
+ while ( Vec_StrGets( pBuffer, 5000, vStr, &nPos ) )
+ {
+ for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
+ if ( pTemp[0] == '\0' )
+ continue;
+// if ( pTemp[0] == 'a' || pTemp[2] == 'a' )
+// {
+// pLib->nLines--;
+// continue;
+// }
+
+ // get the gate
+ pGate = Map_LibraryReadGateTree( pLib, pTemp, nCounter, pLib->nVarsMax );
+ if ( pGate == NULL )
{
- printf( "The number of a child supergate (%d) exceeded the number of lines (%d).\n",
- Num, pLib->nLines );
- return NULL;
+ Extra_ProgressBarStop( pProgress );
+ return 0;
}
- pGate->pFanins[i] = pLib->ppSupers[Num];
+ pLib->ppSupers[nCounter++] = pGate;
+ // later we will derive: truth table, delays, area, number of component gates, etc
+
+ // update the progress bar
+ Extra_ProgressBarUpdate( pProgress, nCounter, NULL );
}
- pGate->nFanins = i;
- if ( pGate->nFanins != (unsigned)Mio_GateReadPinNum(pGate->pRoot) )
+ Extra_ProgressBarStop( pProgress );
+ if ( nCounter != pLib->nLines )
+ printf( "The number of lines read (%d) is different from what the file says (%d).\n", nCounter, pLib->nLines );
+ pLib->nSupersAll = nCounter;
+ // count the number of real supergates
+ nCounter = 0;
+ for ( k = 0; k < pLib->nLines; k++ )
+ nCounter += pLib->ppSupers[k]->fSuper;
+ if ( nCounter != pLib->nSupersReal )
+ printf( "The number of gates read (%d) is different what the file says (%d).\n", nCounter, pLib->nSupersReal );
+ pLib->nSupersReal = nCounter;
+ return 1;
+}
+int Map_LibraryReadTree( Map_SuperLib_t * pLib, char * pFileName, char * pExcludeFile )
+{
+ char * pBuffer;
+ Vec_Str_t * vStr;
+ int Status, num;
+ Abc_Frame_t * pAbc;
+ st_table * tExcludeGate = 0;
+
+ // read the beginning of the file
+ assert( pLib->pGenlib == NULL );
+// pFile = Io_FileOpen( pFileName, "open_path", "r", 1 );
+ pBuffer = Mio_ReadFile( pFileName, 0 );
+ if ( pBuffer == NULL )
{
- printf( "The number of fanins of a root gate is wrong.\n" );
- return NULL;
+ printf( "Cannot open input file \"%s\".\n", pFileName );
+ return 0;
}
+ vStr = Vec_StrAllocArray( pBuffer, strlen(pBuffer) );
- // save the gate name, just in case
- if ( pTemp && pTemp[0] == '#' )
+ if ( pExcludeFile )
{
- if ( pTemp[1] == 0 )
- pTemp = strtok( NULL, " \n\0" );
- else // skip spaces
- for ( pTemp++; *pTemp == ' '; pTemp++ );
- // save the formula
- pGate->pFormula = Extra_MmFlexEntryFetch( pLib->mmForms, strlen(pTemp)+1 );
- strcpy( pGate->pFormula, pTemp );
+ pAbc = Abc_FrameGetGlobalFrame();
+
+ tExcludeGate = st_init_table(strcmp, st_strhash);
+ if ( (num = Mio_LibraryReadExclude( pExcludeFile, tExcludeGate )) == -1 )
+ {
+ st_free_table( tExcludeGate );
+ tExcludeGate = 0;
+ Vec_StrFree( vStr );
+ return 0;
+ }
+
+ fprintf ( Abc_FrameReadOut( pAbc ), "Read %d gates from exclude file\n", num );
}
- // check the rest of the string
- pTemp = strtok( NULL, " \n\0" );
- if ( pTemp != NULL )
- printf( "The following trailing symbols found \"%s\".\n", pTemp );
- return pGate;
+
+ Status = Map_LibraryReadFileTreeStr( pLib, vStr, pFileName );
+ Vec_StrFree( vStr );
+ if ( Status == 0 )
+ return 0;
+ // prepare the info about the library
+ return Map_LibraryDeriveGateInfo( pLib, tExcludeGate );
}
+
+
+
+
+
+
/**Function*************************************************************
Synopsis [Derives information about the library.]
diff --git a/src/map/mio/mio.c b/src/map/mio/mio.c
index 791a7ac0..14878f94 100644
--- a/src/map/mio/mio.c
+++ b/src/map/mio/mio.c
@@ -40,7 +40,7 @@ static int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
/*
-// internal version of GENLIB library
+// internal version of genlib library
static char * pMcncGenlib[25] = {
"GATE inv1 1 O=!a; PIN * INV 1 999 0.9 0.0 0.9 0.0\n",
"GATE inv2 2 O=!a; PIN * INV 2 999 1.0 0.0 1.0 0.0\n",
@@ -320,7 +320,7 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
pLib = Mio_LibraryRead( pFileName, NULL, pExcludeFile, fVerbose );
if ( pLib == NULL )
{
- fprintf( pErr, "Reading GENLIB library has failed.\n" );
+ fprintf( pErr, "Reading genlib library has failed.\n" );
return 1;
}
// add the fixed number (wire delay) to all delays in the library
@@ -342,14 +342,14 @@ int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, NULL, 0, 0 );
if ( pLib == NULL )
{
- fprintf( pErr, "Reading GENLIB library has failed.\n" );
+ fprintf( pErr, "Reading genlib library has failed.\n" );
return 1;
}
// replace the current library
Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
Abc_FrameSetLibGen2( pLib );
if ( fVerbose )
- printf( "Entered GENLIB library with %d gates from file \"%s\".\n", Mio_LibraryReadGateNum(pLib), pFileName );
+ printf( "Entered genlib library with %d gates from file \"%s\".\n", Mio_LibraryReadGateNum(pLib), pFileName );
return 0;
usage:
@@ -425,7 +425,7 @@ int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
}
Mio_WriteLibrary( pFile, (Mio_Library_t *)Abc_FrameReadLibGen(), 0 );
fclose( pFile );
- printf( "The current GENLIB library is written into file \"%s\".\n", pFileName );
+ printf( "The current genlib library is written into file \"%s\".\n", pFileName );
return 0;
usage:
diff --git a/src/map/mio/mio.h b/src/map/mio/mio.h
index f2899654..3b9990a1 100644
--- a/src/map/mio/mio.h
+++ b/src/map/mio/mio.h
@@ -129,6 +129,7 @@ extern double Mio_PinReadDelayFanoutFall( Mio_Pin_t * pPin );
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 int Mio_LibraryReadExclude( char * ExcludeFile, st_table * tExcludeGate );
/*=== mioFunc.c =============================================================*/
diff --git a/src/map/mio/mioRead.c b/src/map/mio/mioRead.c
index aa92c9cd..19c68899 100644
--- a/src/map/mio/mioRead.c
+++ b/src/map/mio/mioRead.c
@@ -89,7 +89,7 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * Exclude
pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") );
}
if ( pLib != NULL )
- printf ( "Warning: Read extended GENLIB format but ignoring extensions\n" );
+ printf ( "Warning: Read extended genlib format but ignoring extensions\n" );
}
if ( tExcludeGate )
st_free_table( tExcludeGate );
@@ -108,7 +108,7 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * Exclude
SeeAlso []
***********************************************************************/
-char * Mio_ReadFile( char * FileName )
+char * Mio_ReadFile( char * FileName, int fAddEnd )
{
char * pBuffer;
FILE * pFile;
@@ -131,7 +131,8 @@ char * Mio_ReadFile( char * FileName )
RetValue = fread( pBuffer, nFileSize, 1, pFile );
// terminate the string with '\0'
pBuffer[ nFileSize ] = '\0';
- strcat( pBuffer, "\n.end\n" );
+ if ( fAddEnd )
+ strcat( pBuffer, "\n.end\n" );
// close file
fclose( pFile );
return pBuffer;
@@ -201,7 +202,7 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_tab
// pBuffer = Io_ReadFileFileContents( FileName, NULL );
// we don't use above function but actually do the same thing explicitly
// to handle open_path expansion correctly
- pBuffer = Mio_ReadFile( FileName );
+ pBuffer = Mio_ReadFile( FileName, 1 );
if ( pBuffer == NULL )
return NULL;
pLib = Mio_LibraryReadBuffer( pBuffer, fExtendedFormat, tExcludeGate, fVerbose );
@@ -617,7 +618,7 @@ void Mio_LibraryDetectSpecialGates( Mio_Library_t * pLib )
pLib->pGateBuf = Mio_GateCompare( pLib->pGateBuf, pGate, uFuncBuf );
if ( pLib->pGateBuf == NULL )
{
- printf( "Warnings: GENLIB library reader cannot detect the buffer gate.\n" );
+ printf( "Warnings: genlib library reader cannot detect the buffer gate.\n" );
printf( "Some parts of the supergate-based technology mapper may not work correctly.\n" );
}
@@ -626,7 +627,7 @@ void Mio_LibraryDetectSpecialGates( Mio_Library_t * pLib )
pLib->pGateInv = Mio_GateCompare( pLib->pGateInv, pGate, uFuncInv );
if ( pLib->pGateInv == NULL )
{
- printf( "Warnings: GENLIB library reader cannot detect the invertor gate.\n" );
+ printf( "Warnings: genlib library reader cannot detect the invertor gate.\n" );
printf( "Some parts of the supergate-based technology mapper may not work correctly.\n" );
}
@@ -637,7 +638,7 @@ void Mio_LibraryDetectSpecialGates( Mio_Library_t * pLib )
pLib->pGateAnd2 = Mio_GateCompare( pLib->pGateAnd2, pGate, uFuncAnd2 );
if ( pLib->pGateAnd2 == NULL && pLib->pGateNand2 == NULL )
{
- printf( "Warnings: GENLIB library reader cannot detect the AND2 or NAND2 gate.\n" );
+ printf( "Warnings: genlib library reader cannot detect the AND2 or NAND2 gate.\n" );
printf( "Some parts of the supergate-based technology mapper may not work correctly.\n" );
}
}
diff --git a/src/map/super/super.c b/src/map/super/super.c
index f188472e..4786b5ce 100644
--- a/src/map/super/super.c
+++ b/src/map/super/super.c
@@ -243,7 +243,7 @@ int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
if ( argc != globalUtilOptind + 1 )
{
- fprintf( pErr, "The GENLIB library file should be given on the command line.\n" );
+ fprintf( pErr, "The genlib library file should be given on the command line.\n" );
goto usage;
}
@@ -275,7 +275,8 @@ int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
}
// compute the gates
- Super_Precompute( pLib, nVarsMax, nLevels, nGatesMax, DelayLimit, AreaLimit, TimeLimit, fSkipInvs, fWriteOldFormat, fVerbose );
+ FileName = Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super");
+ Super_Precompute( pLib, nVarsMax, nLevels, nGatesMax, DelayLimit, AreaLimit, TimeLimit, fSkipInvs, fVerbose, FileName );
// delete the library
Mio_LibraryDelete( pLib );
@@ -283,7 +284,7 @@ int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
usage:
fprintf( pErr, "usage: super [-ILNT num] [-DA float] [-E file] [-sovh] <genlib_file>\n");
- fprintf( pErr, "\t precomputes the supergates for the given GENLIB library\n" );
+ fprintf( pErr, "\t precomputes the supergates for the given genlib library\n" );
fprintf( pErr, "\t-I num : the max number of supergate inputs [default = %d]\n", nVarsMax );
fprintf( pErr, "\t-L num : the max number of levels of gates [default = %d]\n", nLevels );
fprintf( pErr, "\t-N num : the limit on the number of considered supergates [default = %d]\n", nGatesMax );
diff --git a/src/map/super/super.h b/src/map/super/super.h
index e2af9a85..1e8808f6 100644
--- a/src/map/super/super.h
+++ b/src/map/super/super.h
@@ -28,11 +28,8 @@
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
-
-
ABC_NAMESPACE_HEADER_START
-
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
@@ -49,14 +46,15 @@ ABC_NAMESPACE_HEADER_START
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
-/*=== superCore.c =============================================================*/
-
+/*=== superAnd.c =============================================================*/
+extern void Super2_Precompute( int nInputs, int nLevels, int fVerbose );
+/*=== superGate.c =============================================================*/
+extern Vec_Str_t * Super_PrecomputeStr( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose );
+extern void Super_Precompute( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose, char * pFileName );
ABC_NAMESPACE_HEADER_END
-
-
#endif
////////////////////////////////////////////////////////////////////////
diff --git a/src/map/super/superGate.c b/src/map/super/superGate.c
index 2fa71481..8c22920e 100644
--- a/src/map/super/superGate.c
+++ b/src/map/super/superGate.c
@@ -113,17 +113,14 @@ static int Super_AreaCompare( Super_Gate_t ** ppG1, Super_Gate_t ** p
static void Super_TranferGatesToArray( Super_Man_t * pMan );
static int Super_CheckTimeout( ProgressBar * pPro, Super_Man_t * pMan );
-static void Super_Write( Super_Man_t * pMan );
+static Vec_Str_t * Super_Write( Super_Man_t * pMan );
static int Super_WriteCompare( Super_Gate_t ** ppG1, Super_Gate_t ** ppG2 );
static void Super_WriteFileHeader( Super_Man_t * pMan, FILE * pFile );
static void Super_WriteLibrary( Super_Man_t * pMan );
-static void Super_WriteLibraryGate( FILE * pFile, Super_Man_t * pMan, Super_Gate_t * pGate, int Num );
-static char * Super_WriteLibraryGateName( Super_Gate_t * pGate );
-static void Super_WriteLibraryGateName_rec( Super_Gate_t * pGate, char * pBuffer );
-static void Super_WriteLibraryTree( Super_Man_t * pMan );
-static void Super_WriteLibraryTree_rec( FILE * pFile, Super_Man_t * pMan, Super_Gate_t * pSuper, int * pCounter );
+static void Super_WriteLibraryTreeFile( Super_Man_t * pMan );
+static Vec_Str_t * Super_WriteLibraryTreeStr( Super_Man_t * pMan );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
@@ -140,8 +137,41 @@ static void Super_WriteLibraryTree_rec( FILE * pFile, Super_Man_t * pM
SeeAlso []
***********************************************************************/
-void Super_Precompute( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fWriteOldFormat, int fVerbose )
+void Super_Precompute( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose, char * pFileName )
{
+ Vec_Str_t * vStr;
+ FILE * pFile = fopen( pFileName, "wb" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open output file \"%s\".\n", pFileName );
+ return;
+ }
+ vStr = Super_PrecomputeStr( pLibGen, nVarsMax, nLevels, nGatesMax, tDelayMax, tAreaMax, TimeLimit, fSkipInv, fVerbose );
+ fwrite( Vec_StrArray(vStr), 1, Vec_StrSize(vStr), pFile );
+ fclose( pFile );
+ Vec_StrFree( vStr );
+ // report the result of writing
+ if ( fVerbose )
+ {
+ printf( "The supergates are written using new format \"%s\" ", pFileName );
+ printf( "(%0.3f MB).\n", ((double)Extra_FileSize(pFileName))/(1<<20) );
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Precomputes the library of supergates.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Vec_Str_t * Super_PrecomputeStr( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose )
+{
+ Vec_Str_t * vStr;
Super_Man_t * pMan;
Mio_Gate_t ** ppGates;
int nGates, Level;
@@ -152,7 +182,7 @@ void Super_Precompute( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int n
{
fprintf( stderr, "Erro! The number of supergates requested (%d) in less than the number of variables (%d).\n", nGatesMax, nVarsMax );
fprintf( stderr, "The library cannot be computed.\n" );
- return;
+ return NULL;
}
// get the root gates
@@ -173,7 +203,6 @@ void Super_Precompute( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int n
pMan->TimeLimit = TimeLimit; // in seconds
pMan->TimeStop = TimeLimit * CLOCKS_PER_SEC + clock(); // in CPU ticks
pMan->fVerbose = fVerbose;
- pMan->fWriteOldFormat = fWriteOldFormat;
if ( nGates == 0 )
{
@@ -185,7 +214,7 @@ void Super_Precompute( Mio_Library_t * pLibGen, int nVarsMax, int nLevels, int n
Super_ManStop( pMan );
ABC_FREE( ppGates );
- return;
+ return NULL;
}
// get the starting supergates
@@ -224,11 +253,12 @@ printf( "Writing the output file...\n" );
fflush( stdout );
}
// write them into a file
- Super_Write( pMan );
+ vStr = Super_Write( pMan );
// stop the manager
Super_ManStop( pMan );
ABC_FREE( ppGates );
+ return vStr;
}
@@ -299,7 +329,7 @@ void Super_First( Super_Man_t * pMan, int nVarsMax )
Synopsis [Precomputes one level of supergates.]
Description [This procedure computes the set of supergates that can be
- derived from the given set of root gates (from GENLIB library) by composing
+ derived from the given set of root gates (from genlib library) by composing
the root gates with the currently available supergates. This procedure is
smart in the sense that it tries to avoid useless emuration by imposing
tight bounds by area and delay. Only the supergates and are guaranteed to
@@ -946,8 +976,9 @@ void Super_ManStop( Super_Man_t * pMan )
SeeAlso []
***********************************************************************/
-void Super_Write( Super_Man_t * pMan )
+Vec_Str_t * Super_Write( Super_Man_t * pMan )
{
+ Vec_Str_t * vStr;
Super_Gate_t * pGateRoot, * pGate;
stmm_generator * gen;
int fZeroFound, v;
@@ -957,7 +988,7 @@ void Super_Write( Super_Man_t * pMan )
if ( pMan->nGates < 1 )
{
printf( "The generated library is empty. No output file written.\n" );
- return;
+ return NULL;
}
// Filters the supergates by removing those that have fewer inputs than
@@ -1010,11 +1041,12 @@ ABC_PRT( "Writing old format", clock() - clk );
// write the tree-like structure of supergates
clk = clock();
- Super_WriteLibraryTree( pMan );
+ vStr = Super_WriteLibraryTreeStr( pMan );
if ( pMan->fVerbose )
{
ABC_PRT( "Writing new format", clock() - clk );
}
+ return vStr;
}
@@ -1054,10 +1086,57 @@ void Super_WriteFileHeader( Super_Man_t * pMan, FILE * pFile )
fprintf( pFile, "%d\n", pMan->nVarsMax );
fprintf( pFile, "%d\n", pMan->nGates );
}
+void Super_WriteFileHeaderStr( Super_Man_t * pMan, Vec_Str_t * vStr )
+{
+ char pBuffer[1000];
+ sprintf( pBuffer, "#\n" );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# Supergate library derived for \"%s\" on %s.\n", pMan->pName, Extra_TimeStamp() );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "#\n" );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# Command line: \"super -I %d -L %d -N %d -T %d -D %.2f -A %.2f %s %s\".\n",
+ pMan->nVarsMax, pMan->nLevels, pMan->nGatesMax, pMan->TimeLimit, pMan->tDelayMax, pMan->tAreaMax, (pMan->fSkipInv? "" : "-s"), pMan->pName );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "#\n" );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The number of inputs = %10d.\n", pMan->nVarsMax );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The number of levels = %10d.\n", pMan->nLevels );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The maximum delay = %10.2f.\n", pMan->tDelayMax );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The maximum area = %10.2f.\n", pMan->tAreaMax );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The maximum runtime (sec) = %10d.\n", pMan->TimeLimit );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "#\n" );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The number of attempts = %10d.\n", pMan->nTried );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The number of supergates = %10d.\n", pMan->nGates );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The number of functions = %10d.\n", pMan->nUnique );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# The total functions = %.0f (2^%d).\n", pow((double)2,pMan->nMints), pMan->nMints );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "#\n" );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "# Generation time = %10.2f sec.\n", (float)(pMan->Time)/(float)(CLOCKS_PER_SEC) );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "#\n" );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "%s\n", pMan->pName );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "%d\n", pMan->nVarsMax );
+ Vec_StrPrintStr( vStr, pBuffer );
+ sprintf( pBuffer, "%d\n", pMan->nGates );
+ Vec_StrPrintStr( vStr, pBuffer );
+}
/**Function*************************************************************
- Synopsis [Compares the truth tables of two gates.]
+ Synopsis [Compares two gates.]
Description []
@@ -1080,18 +1159,6 @@ int Super_WriteCompare( Super_Gate_t ** ppG1, Super_Gate_t ** ppG2 )
return 1;
return 0;
}
-
-/**Function*************************************************************
-
- Synopsis [Compares the max delay of two gates.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
int Super_DelayCompare( Super_Gate_t ** ppG1, Super_Gate_t ** ppG2 )
{
if ( (*ppG1)->tDelayMax < (*ppG2)->tDelayMax )
@@ -1100,18 +1167,6 @@ int Super_DelayCompare( Super_Gate_t ** ppG1, Super_Gate_t ** ppG2 )
return 1;
return 0;
}
-
-/**Function*************************************************************
-
- Synopsis [Compares the area of two gates.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
int Super_AreaCompare( Super_Gate_t ** ppG1, Super_Gate_t ** ppG2 )
{
if ( (*ppG1)->Area < (*ppG2)->Area )
@@ -1137,6 +1192,48 @@ int Super_AreaCompare( Super_Gate_t ** ppG1, Super_Gate_t ** ppG2 )
SeeAlso []
***********************************************************************/
+void Super_WriteLibraryGateName_rec( Super_Gate_t * pGate, char * pBuffer )
+{
+ char Buffer[10];
+ int i;
+
+ if ( pGate->pRoot == NULL )
+ {
+ sprintf( Buffer, "%c", 'a' + pGate->Number );
+ strcat( pBuffer, Buffer );
+ return;
+ }
+ strcat( pBuffer, Mio_GateReadName(pGate->pRoot) );
+ strcat( pBuffer, "(" );
+ for ( i = 0; i < (int)pGate->nFanins; i++ )
+ {
+ if ( i )
+ strcat( pBuffer, "," );
+ Super_WriteLibraryGateName_rec( pGate->pFanins[i], pBuffer );
+ }
+ strcat( pBuffer, ")" );
+}
+char * Super_WriteLibraryGateName( Super_Gate_t * pGate )
+{
+ static char Buffer[2000];
+ Buffer[0] = 0;
+ Super_WriteLibraryGateName_rec( pGate, Buffer );
+ return Buffer;
+}
+void Super_WriteLibraryGate( FILE * pFile, Super_Man_t * pMan, Super_Gate_t * pGate, int Num )
+{
+ int i;
+ fprintf( pFile, "%04d ", Num ); // the number
+ Extra_PrintBinary( pFile, pGate->uTruth, pMan->nMints ); // the truth table
+ fprintf( pFile, " %5.2f", pGate->tDelayMax ); // the max delay
+ fprintf( pFile, " " );
+ for ( i = 0; i < pMan->nVarsMax; i++ ) // the pin-to-pin delays
+ fprintf( pFile, " %5.2f", pGate->ptDelays[i]==SUPER_NO_VAR? 0.0 : pGate->ptDelays[i] );
+ fprintf( pFile, " %5.2f", pGate->Area ); // the area
+ fprintf( pFile, " " );
+ fprintf( pFile, "%s", Super_WriteLibraryGateName(pGate) ); // the symbolic expression
+ fprintf( pFile, "\n" );
+}
void Super_WriteLibrary( Super_Man_t * pMan )
{
Super_Gate_t * pGate, * pGateNext;
@@ -1183,63 +1280,21 @@ void Super_WriteLibrary( Super_Man_t * pMan )
assert( Counter == pMan->nGates );
fclose( pFile );
-if ( pMan->fVerbose )
-{
- printf( "The supergates are written using old format \"%s\" ", FileName );
- printf( "(%0.3f MB).\n", ((double)Extra_FileSize(FileName))/(1<<20) );
-}
+ if ( pMan->fVerbose )
+ {
+ printf( "The supergates are written using old format \"%s\" ", FileName );
+ printf( "(%0.3f MB).\n", ((double)Extra_FileSize(FileName))/(1<<20) );
+ }
ABC_FREE( FileName );
}
-/**Function*************************************************************
-
- Synopsis [Writes the supergate into the file.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-void Super_WriteLibraryGate( FILE * pFile, Super_Man_t * pMan, Super_Gate_t * pGate, int Num )
-{
- int i;
- fprintf( pFile, "%04d ", Num ); // the number
- Extra_PrintBinary( pFile, pGate->uTruth, pMan->nMints ); // the truth table
- fprintf( pFile, " %5.2f", pGate->tDelayMax ); // the max delay
- fprintf( pFile, " " );
- for ( i = 0; i < pMan->nVarsMax; i++ ) // the pin-to-pin delays
- fprintf( pFile, " %5.2f", pGate->ptDelays[i]==SUPER_NO_VAR? 0.0 : pGate->ptDelays[i] );
- fprintf( pFile, " %5.2f", pGate->Area ); // the area
- fprintf( pFile, " " );
- fprintf( pFile, "%s", Super_WriteLibraryGateName(pGate) ); // the symbolic expression
- fprintf( pFile, "\n" );
-}
-
-/**Function*************************************************************
-
- Synopsis [Recursively generates symbolic name of the supergate.]
-
- Description []
-
- SideEffects []
- SeeAlso []
-***********************************************************************/
-char * Super_WriteLibraryGateName( Super_Gate_t * pGate )
-{
- static char Buffer[2000];
- Buffer[0] = 0;
- Super_WriteLibraryGateName_rec( pGate, Buffer );
- return Buffer;
-}
/**Function*************************************************************
- Synopsis [Recursively generates symbolic name of the supergate.]
+ Synopsis [Recursively writes the gates.]
Description []
@@ -1248,44 +1303,30 @@ char * Super_WriteLibraryGateName( Super_Gate_t * pGate )
SeeAlso []
***********************************************************************/
-void Super_WriteLibraryGateName_rec( Super_Gate_t * pGate, char * pBuffer )
+void Super_WriteLibraryTreeFile_rec( FILE * pFile, Super_Man_t * pMan, Super_Gate_t * pSuper, int * pCounter )
{
- char Buffer[10];
- int i;
-
- if ( pGate->pRoot == NULL )
- {
- sprintf( Buffer, "%c", 'a' + pGate->Number );
- strcat( pBuffer, Buffer );
+ int nFanins, i;
+ // skip an elementary variable and a gate that was already written
+ if ( pSuper->fVar || pSuper->Number > 0 )
return;
- }
- strcat( pBuffer, Mio_GateReadName(pGate->pRoot) );
- strcat( pBuffer, "(" );
- for ( i = 0; i < (int)pGate->nFanins; i++ )
- {
- if ( i )
- strcat( pBuffer, "," );
- Super_WriteLibraryGateName_rec( pGate->pFanins[i], pBuffer );
- }
- strcat( pBuffer, ")" );
+ // write the fanins
+ nFanins = Mio_GateReadPinNum(pSuper->pRoot);
+ for ( i = 0; i < nFanins; i++ )
+ Super_WriteLibraryTreeFile_rec( pFile, pMan, pSuper->pFanins[i], pCounter );
+ // finally write the gate
+ pSuper->Number = (*pCounter)++;
+ fprintf( pFile, "%s", pSuper->fSuper? "* " : "" );
+ fprintf( pFile, "%s", Mio_GateReadName(pSuper->pRoot) );
+ for ( i = 0; i < nFanins; i++ )
+ fprintf( pFile, " %d", pSuper->pFanins[i]->Number );
+ // write the formula
+ // this step is optional, the resulting library will work in any case
+ // however, it may be helpful to for debugging to compare the same library
+ // written in the old format and written in the new format with formulas
+// fprintf( pFile, " # %s", Super_WriteLibraryGateName( pSuper ) );
+ fprintf( pFile, "\n" );
}
-
-
-
-
-
-/**Function*************************************************************
-
- Synopsis [Recursively writes the gates.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-void Super_WriteLibraryTree( Super_Man_t * pMan )
+void Super_WriteLibraryTreeFile( Super_Man_t * pMan )
{
Super_Gate_t * pSuper;
FILE * pFile;
@@ -1302,7 +1343,7 @@ void Super_WriteLibraryTree( Super_Man_t * pMan )
ABC_FREE( pNameGeneric );
// write the elementary variables
- pFile = fopen( FileName, "w" );
+ pFile = fopen( FileName, "wb" );
Super_WriteFileHeader( pMan, pFile );
// write the place holder for the number of lines
posStart = ftell( pFile );
@@ -1313,7 +1354,7 @@ void Super_WriteLibraryTree( Super_Man_t * pMan )
// write the supergates
Counter = pMan->nVarsMax;
Super_ManForEachGate( pMan->pGates, pMan->nGates, i, pSuper )
- Super_WriteLibraryTree_rec( pFile, pMan, pSuper, &Counter );
+ Super_WriteLibraryTreeFile_rec( pFile, pMan, pSuper, &Counter );
fclose( pFile );
// write the number of lines
pFile = fopen( FileName, "rb+" );
@@ -1330,9 +1371,10 @@ if ( pMan->fVerbose )
ABC_FREE( FileName );
}
+
/**Function*************************************************************
- Synopsis [Recursively writes the gate.]
+ Synopsis [Recursively writes the gates.]
Description []
@@ -1341,7 +1383,7 @@ if ( pMan->fVerbose )
SeeAlso []
***********************************************************************/
-void Super_WriteLibraryTree_rec( FILE * pFile, Super_Man_t * pMan, Super_Gate_t * pSuper, int * pCounter )
+void Super_WriteLibraryTreeStr_rec( Vec_Str_t * vStr, Super_Man_t * pMan, Super_Gate_t * pSuper, int * pCounter )
{
int nFanins, i;
// skip an elementary variable and a gate that was already written
@@ -1350,21 +1392,78 @@ void Super_WriteLibraryTree_rec( FILE * pFile, Super_Man_t * pMan, Super_Gate_t
// write the fanins
nFanins = Mio_GateReadPinNum(pSuper->pRoot);
for ( i = 0; i < nFanins; i++ )
- Super_WriteLibraryTree_rec( pFile, pMan, pSuper->pFanins[i], pCounter );
+ Super_WriteLibraryTreeStr_rec( vStr, pMan, pSuper->pFanins[i], pCounter );
// finally write the gate
pSuper->Number = (*pCounter)++;
- fprintf( pFile, "%s", pSuper->fSuper? "* " : "" );
- fprintf( pFile, "%s", Mio_GateReadName(pSuper->pRoot) );
+// fprintf( pFile, "%s", pSuper->fSuper? "* " : "" );
+// fprintf( pFile, "%s", Mio_GateReadName(pSuper->pRoot) );
+// for ( i = 0; i < nFanins; i++ )
+// fprintf( pFile, " %d", pSuper->pFanins[i]->Number );
+ Vec_StrPrintStr( vStr, pSuper->fSuper? "* " : "" );
+ Vec_StrPrintStr( vStr, Mio_GateReadName(pSuper->pRoot) );
for ( i = 0; i < nFanins; i++ )
- fprintf( pFile, " %d", pSuper->pFanins[i]->Number );
+ {
+ Vec_StrPrintStr( vStr, " " );
+ Vec_StrPrintNum( vStr, pSuper->pFanins[i]->Number );
+ }
// write the formula
// this step is optional, the resulting library will work in any case
// however, it may be helpful to for debugging to compare the same library
// written in the old format and written in the new format with formulas
// fprintf( pFile, " # %s", Super_WriteLibraryGateName( pSuper ) );
- fprintf( pFile, "\n" );
+// fprintf( pFile, "\n" );
+ Vec_StrPrintStr( vStr, "\n" );
+}
+Vec_Str_t * Super_WriteLibraryTreeStr( Super_Man_t * pMan )
+{
+ char pInsert[16];
+ Vec_Str_t * vStr;
+ Super_Gate_t * pSuper;
+ int i, Counter;
+ int posStart;
+ // write the elementary variables
+ vStr = Vec_StrAlloc( 1000 );
+ Super_WriteFileHeaderStr( pMan, vStr );
+ // write the place holder for the number of lines
+ posStart = Vec_StrSize( vStr );
+ for ( i = 0; i < 9; i++ )
+ Vec_StrPush( vStr, ' ' );
+ Vec_StrPush( vStr, '\n' );
+ // mark the real supergates
+ Super_ManForEachGate( pMan->pGates, pMan->nGates, i, pSuper )
+ pSuper->fSuper = 1;
+ // write the supergates
+ Counter = pMan->nVarsMax;
+ Super_ManForEachGate( pMan->pGates, pMan->nGates, i, pSuper )
+ Super_WriteLibraryTreeStr_rec( vStr, pMan, pSuper, &Counter );
+ Vec_StrPush( vStr, 0 );
+ // write the number of lines
+ sprintf( pInsert, "%d", Counter );
+ for ( i = 0; i < (int)strlen(pInsert); i++ )
+ Vec_StrWriteEntry( vStr, posStart + i, pInsert[i] );
+ return vStr;
+}
+void Super_WriteLibraryTree( Super_Man_t * pMan )
+{
+ Vec_Str_t * vStr;
+ char * pFileName = Extra_FileNameGenericAppend( pMan->pName, ".super" );
+ FILE * pFile = fopen( pFileName, "wb" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open output file \"%s\".\n", pFileName );
+ return;
+ }
+ vStr = Super_WriteLibraryTreeStr( pMan );
+ fwrite( Vec_StrArray(vStr), 1, Vec_StrSize(vStr), pFile );
+ fclose( pFile );
+ Vec_StrFree( vStr );
+ // report the result of writing
+ if ( pMan->fVerbose )
+ {
+ printf( "The supergates are written using new format \"%s\" ", pFileName );
+ printf( "(%0.3f MB).\n", ((double)Extra_FileSize(pFileName))/(1<<20) );
+ }
}
-
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
diff --git a/src/map/super/superInt.h b/src/map/super/superInt.h
index a808eb64..ab35c796 100644
--- a/src/map/super/superInt.h
+++ b/src/map/super/superInt.h
@@ -54,12 +54,6 @@ ABC_NAMESPACE_HEADER_START
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
-/*=== superAnd.c =============================================================*/
-extern void Super2_Precompute( int nInputs, int nLevels, int fVerbose );
-/*=== superGate.c =============================================================*/
-extern void Super_Precompute( Mio_Library_t * pLibGen, int nInputs, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fWriteOldFormat, int fVerbose );
-
-
ABC_NAMESPACE_HEADER_END