summaryrefslogtreecommitdiffstats
path: root/src/map/mapper
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/mapper')
-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
5 files changed, 414 insertions, 108 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.]