Commit aed3b3a1 by Alan Mishchenko

Cleaned up interfaces of genlib/liberty/supergate reading/writing.

parent d0197d83
...@@ -93,8 +93,11 @@ Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, ...@@ -93,8 +93,11 @@ Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti,
{ {
// printf( "A simple supergate library is derived from gate library \"%s\".\n", // printf( "A simple supergate library is derived from gate library \"%s\".\n",
// Mio_LibraryReadName((Mio_Library_t *)Abc_FrameReadLibGen()) ); // Mio_LibraryReadName((Mio_Library_t *)Abc_FrameReadLibGen()) );
if ( fVerbose )
printf( "Converting \"%s\" into supergate library \"%s\".\n",
Mio_LibraryReadName(pLib), Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super") );
// compute supergate library to be used for mapping // compute supergate library to be used for mapping
Map_SuperLibDeriveFromGenlib( pLib ); Map_SuperLibDeriveFromGenlib( pLib, fVerbose );
} }
// return the library to normal // return the library to normal
...@@ -455,7 +458,7 @@ Abc_Ntk_t * Abc_NtkSuperChoice( Abc_Ntk_t * pNtk ) ...@@ -455,7 +458,7 @@ Abc_Ntk_t * Abc_NtkSuperChoice( Abc_Ntk_t * pNtk )
{ {
// printf( "A simple supergate library is derived from gate library \"%s\".\n", // printf( "A simple supergate library is derived from gate library \"%s\".\n",
// Mio_LibraryReadName((Mio_Library_t *)Abc_FrameReadLibGen()) ); // Mio_LibraryReadName((Mio_Library_t *)Abc_FrameReadLibGen()) );
Map_SuperLibDeriveFromGenlib( (Mio_Library_t *)Abc_FrameReadLibGen() ); Map_SuperLibDeriveFromGenlib( (Mio_Library_t *)Abc_FrameReadLibGen(), 0 );
} }
// print a warning about choice nodes // print a warning about choice nodes
......
...@@ -201,7 +201,7 @@ int IoCommandRead( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -201,7 +201,7 @@ int IoCommandRead( Abc_Frame_t * pAbc, int argc, char ** argv )
Command[0] = 0; Command[0] = 0;
assert( strlen(pFileName) < 900 ); assert( strlen(pFileName) < 900 );
if ( !strcmp( Extra_FileNameExtension(pFileName), "genlib" ) ) if ( !strcmp( Extra_FileNameExtension(pFileName), "genlib" ) )
sprintf( Command, "read_library %s", pFileName ); sprintf( Command, "read_genlib %s", pFileName );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "lib" ) ) else if ( !strcmp( Extra_FileNameExtension(pFileName), "lib" ) )
sprintf( Command, "read_liberty %s", pFileName ); sprintf( Command, "read_liberty %s", pFileName );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "scl" ) ) else if ( !strcmp( Extra_FileNameExtension(pFileName), "scl" ) )
...@@ -1298,6 +1298,7 @@ usage: ...@@ -1298,6 +1298,7 @@ usage:
***********************************************************************/ ***********************************************************************/
int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv ) int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv )
{ {
char Command[1000];
char * pFileName; char * pFileName;
int c; int c;
...@@ -1312,15 +1313,27 @@ int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -1312,15 +1313,27 @@ int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv )
goto usage; goto usage;
} }
} }
if ( argc != globalUtilOptind + 1 )
goto usage;
// get the output file name
pFileName = argv[globalUtilOptind];
// write libraries
Command[0] = 0;
assert( strlen(pFileName) < 900 );
if ( !strcmp( Extra_FileNameExtension(pFileName), "genlib" ) )
sprintf( Command, "write_genlib %s", pFileName );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "lib" ) )
sprintf( Command, "write_liberty %s", pFileName );
if ( Command[0] )
{
Cmd_CommandExecute( pAbc, Command );
return 0;
}
if ( pAbc->pNtkCur == NULL ) if ( pAbc->pNtkCur == NULL )
{ {
fprintf( pAbc->Out, "Empty network.\n" ); fprintf( pAbc->Out, "Empty network.\n" );
return 0; return 0;
} }
if ( argc != globalUtilOptind + 1 )
goto usage;
// get the output file name
pFileName = argv[globalUtilOptind];
// call the corresponding file writer // call the corresponding file writer
Io_Write( pAbc->pNtkCur, pFileName, Io_ReadFileType(pFileName) ); Io_Write( pAbc->pNtkCur, pFileName, Io_ReadFileType(pFileName) );
return 0; return 0;
......
...@@ -76,9 +76,11 @@ extern void Amap_ManSetDefaultParams( Amap_Par_t * pPars ); ...@@ -76,9 +76,11 @@ extern void Amap_ManSetDefaultParams( Amap_Par_t * pPars );
/*=== amapLib.c ==========================================================*/ /*=== amapLib.c ==========================================================*/
extern void Amap_LibFree( Amap_Lib_t * p ); extern void Amap_LibFree( Amap_Lib_t * p );
extern void Amap_LibPrintSelectedGates( Amap_Lib_t * p, int fAllGates ); extern void Amap_LibPrintSelectedGates( Amap_Lib_t * p, int fAllGates );
extern Amap_Lib_t * Amap_LibReadAndPrepare( char * pFileName, int fVerbose, int fVeryVerbose ); extern Amap_Lib_t * Amap_LibReadAndPrepare( char * pFileName, char * pBuffer, int fVerbose, int fVeryVerbose );
/*=== amapLiberty.c ==========================================================*/ /*=== amapLiberty.c ==========================================================*/
extern int Amap_LibertyParse( char * pFileName, int fVerbose ); extern int Amap_LibertyParse( char * pFileName, int fVerbose );
extern Vec_Str_t * Amap_LibertyParseStr( char * pFileName, int fVerbose );
ABC_NAMESPACE_HEADER_END ABC_NAMESPACE_HEADER_END
......
...@@ -349,6 +349,7 @@ extern Vec_Ptr_t * Amap_ManProduceMapped( Amap_Man_t * p ); ...@@ -349,6 +349,7 @@ extern Vec_Ptr_t * Amap_ManProduceMapped( Amap_Man_t * p );
extern int Amap_LibParseEquations( Amap_Lib_t * p, int fVerbose ); extern int Amap_LibParseEquations( Amap_Lib_t * p, int fVerbose );
/*=== amapPerm.c ==========================================================*/ /*=== amapPerm.c ==========================================================*/
/*=== amapRead.c ==========================================================*/ /*=== amapRead.c ==========================================================*/
extern Amap_Lib_t * Amap_LibReadBuffer( char * pBuffer, int fVerbose );
extern Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose ); extern Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose );
/*=== amapRule.c ==========================================================*/ /*=== amapRule.c ==========================================================*/
extern short * Amap_LibTableFindNode( Amap_Lib_t * p, int iFan0, int iFan1, int fXor ); extern short * Amap_LibTableFindNode( Amap_Lib_t * p, int iFan0, int iFan1, int fXor );
......
...@@ -85,6 +85,7 @@ void Amap_LibFree( Amap_Lib_t * p ) ...@@ -85,6 +85,7 @@ void Amap_LibFree( Amap_Lib_t * p )
ABC_FREE( p->pRules ); ABC_FREE( p->pRules );
ABC_FREE( p->pRulesX ); ABC_FREE( p->pRulesX );
ABC_FREE( p->pNodes ); ABC_FREE( p->pNodes );
ABC_FREE( p->pName );
ABC_FREE( p ); ABC_FREE( p );
} }
...@@ -325,11 +326,18 @@ void Amap_LibPrintSelectedGates( Amap_Lib_t * p, int fAllGates ) ...@@ -325,11 +326,18 @@ void Amap_LibPrintSelectedGates( Amap_Lib_t * p, int fAllGates )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Amap_Lib_t * Amap_LibReadAndPrepare( char * pFileName, int fVerbose, int fVeryVerbose ) Amap_Lib_t * Amap_LibReadAndPrepare( char * pFileName, char * pBuffer, int fVerbose, int fVeryVerbose )
{ {
Amap_Lib_t * p; Amap_Lib_t * p;
clock_t clk = clock(); clock_t clk = clock();
p = Amap_LibReadFile( pFileName, fVerbose ); if ( pBuffer == NULL )
p = Amap_LibReadFile( pFileName, fVerbose );
else
{
p = Amap_LibReadBuffer( pBuffer, fVerbose );
if ( p )
p->pName = Abc_UtilStrsav( pFileName );
}
if ( fVerbose ) if ( fVerbose )
printf( "Read %d gates from file \"%s\".\n", Vec_PtrSize(p->vGates), pFileName ); printf( "Read %d gates from file \"%s\".\n", Vec_PtrSize(p->vGates), pFileName );
if ( p == NULL ) if ( p == NULL )
......
...@@ -464,6 +464,101 @@ int Amap_LibertyPrintGenlib( Amap_Tree_t * p, char * pFileName, int fVerbose ) ...@@ -464,6 +464,101 @@ int Amap_LibertyPrintGenlib( Amap_Tree_t * p, char * pFileName, int fVerbose )
return 1; return 1;
} }
/**Function*************************************************************
Synopsis [Prints parse tree in Genlib format.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Str_t * Amap_LibertyPrintGenlibStr( Amap_Tree_t * p, int fVerbose )
{
Vec_Str_t * vStr;
char Buffer[100];
Vec_Ptr_t * vOutputs;
Amap_Item_t * pCell, * pArea, * pFunc, * pPin, * pOutput;
int i, Counter;
char * pForm;
vStr = Vec_StrAlloc( 1000 );
Vec_StrPrintStr( vStr, "GATE _const0_ 0.000000 z=CONST0;\n" );
Vec_StrPrintStr( vStr, "GATE _const1_ 0.000000 z=CONST1;\n" );
Amap_ItemForEachChild( p, Amap_LibertyRoot(p), pCell )
{
if ( Amap_LibertyCompare(p, pCell->Key, "cell") )
continue;
if ( Amap_LibertyCellIsFlop(p, pCell) )
{
if ( fVerbose )
printf( "Amap_LibertyPrintGenlib() skipped sequential cell \"%s\".\n", Amap_LibertyGetString(p, pCell->Head) );
continue;
}
Counter = Amap_LibertyCellCountOutputs( p, pCell );
if ( Counter == 0 )
{
if ( fVerbose )
printf( "Amap_LibertyPrintGenlib() skipped cell \"%s\" without logic function.\n", Amap_LibertyGetString(p, pCell->Head) );
continue;
}
pArea = Amap_LibertyCellArea( p, pCell );
if ( pArea == NULL )
{
if ( fVerbose )
printf( "Amap_LibertyPrintGenlib() skipped cell \"%s\" with unspecified area.\n", Amap_LibertyGetString(p, pCell->Head) );
continue;
}
vOutputs = Amap_LibertyCellOutputs( p, pCell );
Vec_PtrForEachEntry( Amap_Item_t *, vOutputs, pOutput, i )
{
pFunc = Amap_LibertyPinFunction( p, pOutput );
pForm = Amap_LibertyGetStringFormula( p, pFunc->Head );
if ( !strcmp(pForm, "0") || !strcmp(pForm, "1") )
{
if ( fVerbose )
printf( "Amap_LibertyPrintGenlib() skipped cell \"%s\" with constant formula \"%s\".\n", Amap_LibertyGetString(p, pCell->Head), pForm );
continue;
}
/*
fprintf( pFile, "GATE " );
fprintf( pFile, "%16s ", Amap_LibertyGetString(p, pCell->Head) );
fprintf( pFile, "%f ", atof(Amap_LibertyGetString(p, pArea->Head)) );
fprintf( pFile, "%s=", Amap_LibertyGetString(p, pOutput->Head) );
fprintf( pFile, "%s;\n", Amap_LibertyGetStringFormula(p, pFunc->Head) );
Amap_ItemForEachChild( p, pCell, pPin )
if ( Vec_PtrFind(vOutputs, pPin) == -1 && !Amap_LibertyCompare(p, pPin->Key, "pin") )
fprintf( pFile, " PIN %13s UNKNOWN 1 999 1.00 0.00 1.00 0.00\n", Amap_LibertyGetString(p, pPin->Head) );
*/
Vec_StrPrintStr( vStr, "GATE " );
Vec_StrPrintStr( vStr, Amap_LibertyGetString(p, pCell->Head) );
Vec_StrPrintStr( vStr, " " );
sprintf( Buffer, "%f", atof(Amap_LibertyGetString(p, pArea->Head)) );
Vec_StrPrintStr( vStr, Buffer );
Vec_StrPrintStr( vStr, " " );
Vec_StrPrintStr( vStr, Amap_LibertyGetString(p, pOutput->Head) );
Vec_StrPrintStr( vStr, "=" );
Vec_StrPrintStr( vStr, Amap_LibertyGetStringFormula(p, pFunc->Head) );
Vec_StrPrintStr( vStr, ";\n" );
Amap_ItemForEachChild( p, pCell, pPin )
if ( Vec_PtrFind(vOutputs, pPin) == -1 && !Amap_LibertyCompare(p, pPin->Key, "pin") )
{
Vec_StrPrintStr( vStr, " PIN " );
Vec_StrPrintStr( vStr, Amap_LibertyGetString(p, pPin->Head) );
Vec_StrPrintStr( vStr, " UNKNOWN 1 999 1.00 0.00 1.00 0.00\n" );
}
}
Vec_PtrFree( vOutputs );
}
Vec_StrPrintStr( vStr, "\n.end\n" );
Vec_StrPush( vStr, '\0' );
// printf( "%s", Vec_StrArray(vStr) );
return vStr;
}
/**Function************************************************************* /**Function*************************************************************
...@@ -950,6 +1045,55 @@ int Amap_LibertyParse( char * pFileName, int fVerbose ) ...@@ -950,6 +1045,55 @@ int Amap_LibertyParse( char * pFileName, int fVerbose )
return RetValue; return RetValue;
} }
/**Function*************************************************************
Synopsis [Parses the standard cell library in Liberty format.]
Description [Writes the resulting file in Genlib format.]
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Str_t * Amap_LibertyParseStr( char * pFileName, int fVerbose )
{
Amap_Tree_t * p;
Vec_Str_t * vStr = NULL;
char * pPos;
clock_t clk = clock();
int RetValue;
p = Amap_LibertyStart( pFileName );
if ( p == NULL )
return 0;
pPos = p->pContents;
Amap_LibertyWipeOutComments( p->pContents, p->pContents+p->nContents );
if ( Amap_LibertyBuildItem( p, &pPos, p->pContents + p->nContents ) == 0 )
{
if ( fVerbose )
printf( "Parsing finished successfully.\n" );
// Amap_LibertyPrintLiberty( p, "temp_.lib" );
vStr = Amap_LibertyPrintGenlibStr( p, fVerbose );
RetValue = 1;
}
else
{
if ( p->pError )
printf( "%s", p->pError );
if ( fVerbose )
printf( "Parsing failed.\n" );
RetValue = 0;
}
if ( fVerbose )
{
printf( "Memory = %7.2f MB. ", 1.0*(p->nContents+p->nItermAlloc*sizeof(Amap_Item_t))/(1<<20) );
ABC_PRT( "Time", clock() - clk );
}
Amap_LibertyStop( p );
return vStr;
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// END OF FILE /// /// END OF FILE ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
...@@ -438,14 +438,10 @@ Amap_Lib_t * Amap_ParseTokens( Vec_Ptr_t * vTokens, int fVerbose ) ...@@ -438,14 +438,10 @@ Amap_Lib_t * Amap_ParseTokens( Vec_Ptr_t * vTokens, int fVerbose )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose ) Amap_Lib_t * Amap_LibReadBuffer( char * pBuffer, int fVerbose )
{ {
Amap_Lib_t * pLib; Amap_Lib_t * pLib;
Vec_Ptr_t * vTokens; Vec_Ptr_t * vTokens;
char * pBuffer;
pBuffer = Amap_LoadFile( pFileName );
if ( pBuffer == NULL )
return NULL;
Amap_RemoveComments( pBuffer, NULL, NULL ); Amap_RemoveComments( pBuffer, NULL, NULL );
vTokens = Amap_DeriveTokens( pBuffer ); vTokens = Amap_DeriveTokens( pBuffer );
pLib = Amap_ParseTokens( vTokens, fVerbose ); pLib = Amap_ParseTokens( vTokens, fVerbose );
...@@ -454,8 +450,31 @@ Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose ) ...@@ -454,8 +450,31 @@ Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose )
Vec_PtrFree( vTokens ); Vec_PtrFree( vTokens );
return NULL; return NULL;
} }
pLib->pName = Amap_ParseStrsav( pLib->pMemGates, pFileName );
Vec_PtrFree( vTokens ); Vec_PtrFree( vTokens );
return pLib;
}
/**Function*************************************************************
Synopsis [Reads the library from the input file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose )
{
Amap_Lib_t * pLib;
char * pBuffer;
pBuffer = Amap_LoadFile( pFileName );
if ( pBuffer == NULL )
return NULL;
pLib = Amap_LibReadBuffer( pBuffer, fVerbose );
if ( pLib )
pLib->pName = Abc_UtilStrsav( pFileName );
ABC_FREE( pBuffer ); ABC_FREE( pBuffer );
return pLib; return pLib;
} }
......
...@@ -155,10 +155,8 @@ int Map_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -155,10 +155,8 @@ int Map_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() ); Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
Abc_FrameSetLibSuper( pLib ); Abc_FrameSetLibSuper( pLib );
// replace the current genlib library // replace the current genlib library
// if ( s_pLib ) Mio_LibraryDelete( s_pLib ); // Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
// s_pLib = s_pSuperLib->pGenlib; // Abc_FrameSetLibGen( (Mio_Library_t *)pLib->pGenlib );
Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
Abc_FrameSetLibGen( (Mio_Library_t *)pLib->pGenlib );
return 0; return 0;
usage: usage:
......
...@@ -165,7 +165,7 @@ extern void Map_CutCreateFromNode( Map_Man_t * p, Map_Super_t * pSupe ...@@ -165,7 +165,7 @@ extern void Map_CutCreateFromNode( Map_Man_t * p, Map_Super_t * pSupe
/*=== mapperCore.c =============================================================*/ /*=== mapperCore.c =============================================================*/
extern int Map_Mapping( Map_Man_t * p ); extern int Map_Mapping( Map_Man_t * p );
/*=== mapperLib.c =============================================================*/ /*=== mapperLib.c =============================================================*/
extern int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib ); extern int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib, int fVerbose );
extern void Map_SuperLibFree( Map_SuperLib_t * p ); extern void Map_SuperLibFree( Map_SuperLib_t * p );
/*=== mapperMntk.c =============================================================*/ /*=== mapperMntk.c =============================================================*/
//extern Mntk_Man_t * Map_ConvertMappingToMntk( Map_Man_t * pMan ); //extern Mntk_Man_t * Map_ConvertMappingToMntk( Map_Man_t * pMan );
......
...@@ -186,7 +186,7 @@ Map_Man_t * Map_ManCreate( int nInputs, int nOutputs, int fVerbose ) ...@@ -186,7 +186,7 @@ Map_Man_t * Map_ManCreate( int nInputs, int nOutputs, int fVerbose )
// derive the supergate library // derive the supergate library
if ( Abc_FrameReadLibSuper() == NULL ) if ( Abc_FrameReadLibSuper() == NULL )
{ {
printf( "The supergate library is not specified. Use \"read_library\" or \"read_super\".\n" ); printf( "The supergate library is not specified. Use \"read_super\".\n" );
return NULL; return NULL;
} }
......
/**CFile****************************************************************
FileName [mapper__.c]
PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
Synopsis [Generic technology mapping engine.]
Author [MVSIS Group]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 8, 2003.]
Revision [$Id: mapper__.h,v 1.0 2003/09/08 00:00:00 alanmi Exp $]
***********************************************************************/
#include "mapperInt.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
...@@ -99,11 +99,12 @@ clk = clock(); ...@@ -99,11 +99,12 @@ clk = clock();
assert( p->nVarsMax > 0 ); assert( p->nVarsMax > 0 );
// report the stats // report the stats
if ( fVerbose ) { if ( fVerbose )
printf( "Loaded %d unique %d-input supergates from \"%s\". ", {
p->nSupersReal, p->nVarsMax, pFileName ); printf( "Loaded %d unique %d-input supergates from \"%s\". ",
ABC_PRT( "Time", clock() - clk ); p->nSupersReal, p->nVarsMax, pFileName );
} ABC_PRT( "Time", clock() - clk );
}
// assign the interver parameters // assign the interver parameters
p->pGateInv = Mio_LibraryReadInv( p->pGenlib ); p->pGateInv = Mio_LibraryReadInv( p->pGenlib );
...@@ -149,8 +150,9 @@ void Map_SuperLibFree( Map_SuperLib_t * p ) ...@@ -149,8 +150,9 @@ void Map_SuperLibFree( Map_SuperLib_t * p )
if ( p->pGenlib ) if ( p->pGenlib )
{ {
assert( p->pGenlib == Abc_FrameReadLibGen() ); assert( p->pGenlib == Abc_FrameReadLibGen() );
Mio_LibraryDelete( p->pGenlib ); // Mio_LibraryDelete( p->pGenlib );
Abc_FrameSetLibGen( NULL ); // Abc_FrameSetLibGen( NULL );
p->pGenlib = NULL;
} }
if ( p->tTableC ) if ( p->tTableC )
Map_SuperTableFree( p->tTableC ); Map_SuperTableFree( p->tTableC );
...@@ -174,77 +176,22 @@ void Map_SuperLibFree( Map_SuperLib_t * p ) ...@@ -174,77 +176,22 @@ void Map_SuperLibFree( Map_SuperLib_t * p )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib ) 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 );
Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame(); Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
char * pNameGeneric; char * pFileName;
char * FileNameGenlib;
char * FileNameSuper;
char * CommandSuper;
char * CommandRead;
FILE * pFile;
if ( pLib == NULL ) if ( pLib == NULL )
return 0; return 0;
// compute supergates
FileNameGenlib = ABC_ALLOC( char, 10000 ); Super_Precompute( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0, 0 );
FileNameSuper = ABC_ALLOC( char, 10000 ); // assuming that it terminated successfully
CommandSuper = ABC_ALLOC( char, 10000 ); pFileName = Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super");
CommandRead = ABC_ALLOC( char, 10000 ); if ( Cmd_CommandExecute( pAbc, pFileName ) )
// write the current library into the file
sprintf( FileNameGenlib, "%s_temp", Mio_LibraryReadName(pLib) );
pFile = fopen( FileNameGenlib, "w" );
Mio_WriteLibrary( pFile, pLib, 0 );
fclose( pFile );
// get the file name with the library
pNameGeneric = Extra_FileNameGeneric( Mio_LibraryReadName(pLib) );
sprintf( FileNameSuper, "%s.super", pNameGeneric );
ABC_FREE( pNameGeneric );
sprintf( CommandSuper, "super -L 1 -I 5 -D 10000000 -A 10000000 -T 100 %s", FileNameGenlib );
if ( Cmd_CommandExecute( pAbc, CommandSuper ) )
{
ABC_FREE( FileNameGenlib );
ABC_FREE( FileNameSuper );
ABC_FREE( CommandSuper );
ABC_FREE( CommandRead );
fprintf( stdout, "Cannot execute command \"%s\".\n", CommandSuper );
return 0;
}
//#ifdef WIN32
// _unlink( FileNameGenlib );
//#else
// unlink( FileNameGenlib );
//#endif
printf( "A simple supergate library is derived from gate library \"%s\".\n", Mio_LibraryReadName(pLib) );
fflush( stdout );
sprintf( CommandRead, "read_super %s", FileNameSuper );
if ( Cmd_CommandExecute( pAbc, CommandRead ) )
{ {
//#ifdef WIN32 fprintf( stdout, "Cannot execute command \"read_super %s\".\n", pFileName );
// _unlink( FileNameSuper );
//#else
// unlink( FileNameSuper );
//#endif
fprintf( stdout, "Cannot execute command \"%s\".\n", CommandRead );
ABC_FREE( FileNameGenlib );
ABC_FREE( FileNameSuper );
ABC_FREE( CommandSuper );
ABC_FREE( CommandRead );
return 0; return 0;
} }
//#ifdef WIN32
// _unlink( FileNameSuper );
//#else
// unlink( FileNameSuper );
//#endif
ABC_FREE( FileNameGenlib );
ABC_FREE( FileNameSuper );
ABC_FREE( CommandSuper );
ABC_FREE( CommandRead );
return 1; return 1;
} }
......
...@@ -115,7 +115,7 @@ int Map_LibraryReadFile( Map_SuperLib_t * pLib, FILE * pFile ) ...@@ -115,7 +115,7 @@ int Map_LibraryReadFile( Map_SuperLib_t * pLib, FILE * pFile )
fclose( pFileGen ); fclose( pFileGen );
// read the genlib library // read the genlib library
pLib->pGenlib = Mio_LibraryRead( pLibName, 0, 0 ); pLib->pGenlib = Mio_LibraryRead( pLibName, NULL, 0, 0 );
if ( pLib->pGenlib == NULL ) if ( pLib->pGenlib == NULL )
{ {
printf( "Cannot read GENLIB file \"%s\".\n", pLibName ); printf( "Cannot read GENLIB file \"%s\".\n", pLibName );
......
...@@ -109,8 +109,7 @@ int Map_LibraryReadTree( Map_SuperLib_t * pLib, char * pFileName, char * pExclud ...@@ -109,8 +109,7 @@ int Map_LibraryReadTree( Map_SuperLib_t * pLib, char * pFileName, char * pExclud
int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileName ) int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileName )
{ {
ProgressBar * pProgress; ProgressBar * pProgress;
char pBuffer[5000], pLibFile[5000]; char pBuffer[5000];
FILE * pFileGen;
Map_Super_t * pGate; Map_Super_t * pGate;
char * pTemp = 0, * pLibName; char * pTemp = 0, * pLibName;
int nCounter, k, i; int nCounter, k, i;
...@@ -125,58 +124,12 @@ int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileNam ...@@ -125,58 +124,12 @@ int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileNam
if ( *pTemp != 0 && *pTemp != '#' ) if ( *pTemp != 0 && *pTemp != '#' )
break; break;
} }
// get the genlib file name (base)
pLibName = strtok( pTemp, " \t\r\n" );
#ifdef __linux__
if( strchr( pLibName, '/' ) != NULL )
pLibName = strrchr( pLibName, '/' ) + 1;
#else
if( strchr( pLibName, '\\' ) != NULL )
pLibName = strrchr( pLibName, '\\' ) + 1;
#endif
if ( strcmp( pLibName, "GATE" ) == 0 )
{
printf( "The input file \"%s\" looks like a GENLIB file and not a supergate library file.\n", pLib->pName );
return 0;
}
// now figure out the directory if any in the pFileName
#ifdef __linux__
snprintf( pLibFile, 5000, "%s/%s", dirname(strdup(pFileName)), pLibName );
#else
// strcpy( pLibFile, pFileName );
pLibName = strtok( pTemp, " \t\r\n" );
pLib->pGenlib = Abc_FrameReadLibGen();
if ( pLib->pGenlib == NULL || strcmp( Mio_LibraryReadName(pLib->pGenlib), pLibName ) )
{ {
char * pStr; printf( "Supergate library \"%s\" requires the use of Genlib library \"%s\".\n", pFileName, pLibName );
strcpy( pLibFile, pFileName );
pStr = pLibFile + strlen(pBuffer) - 1;
while ( pStr > pLibFile && *pStr != '\\' && *pStr != '/' )
pStr--;
if ( pStr == pLibFile )
strcpy( pLibFile, pLibName );
else
sprintf( pStr, "\\%s", pLibName );
}
#endif
pFileGen = Io_FileOpen( pLibFile, "open_path", "r", 1 );
// pFileGen = fopen( pLibFile, "r" );
if ( pFileGen == NULL )
{
printf( "Cannot open the GENLIB file \"%s\".\n", pLibFile );
return 0;
}
fclose( pFileGen );
// read the genlib library
pLib->pGenlib = Mio_LibraryRead( pLibFile, 0, 0 );
if ( pLib->pGenlib == NULL )
{
printf( "Cannot read GENLIB file \"%s\".\n", pLibFile );
return 0; return 0;
} }
......
/**CFile****************************************************************
FileName [mapperTree.c]
PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
Synopsis [Generic technology mapping engine.]
Author [MVSIS Group]
Affiliation [UC Berkeley]
Date [Ver. 2.0. Started - June 1, 2004.]
Revision [$Id: mapperTree.c,v 1.9 2005/01/23 06:59:45 alanmi Exp $]
***********************************************************************/
#ifdef __linux__
#include <libgen.h>
#endif
#include "mapperInt.h"
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 );
// fanout limits
extern const int s_MapFanoutLimits[10] = { 1/*0*/, 10/*1*/, 5/*2*/, 2/*3*/, 1/*4*/, 1/*5*/, 1/*6*/ };
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Reads the supergate library from file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Map_LibraryReadTree( 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( pAbc, 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 the library file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileName )
{
ProgressBar * pProgress;
char pBuffer[5000], pLibFile[5000];
FILE * pFileGen;
Map_Super_t * pGate;
char * pTemp = 0, * pLibName;
int nCounter, k, i;
// skip empty and comment lines
while ( fgets( pBuffer, 5000, pFile ) != NULL )
{
// skip leading spaces
for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
// skip comment lines and empty lines
if ( *pTemp != 0 && *pTemp != '#' )
break;
}
// get the genlib file name (base)
pLibName = strtok( pTemp, " \t\r\n" );
#ifdef __linux__
pLibName = strrchr( pLibName, '/' )+1;
#else
pLibName = strrchr( pLibName, '\\' )+1;
#endif
if ( strcmp( pLibName, "GATE" ) == 0 )
{
printf( "The input file \"%s\" looks like a GENLIB file and not a supergate library file.\n", pLib->pName );
return 0;
}
// now figure out the directory if any in the pFileName
#ifdef __linux__
snprintf( pLibFile, 5000, "%s/%s", dirname(strdup(pFileName)), pLibName );
#else
{
char * pStr;
strcpy( pLibFile, pFileName );
pStr = pLibFile + strlen(pBuffer) - 1;
while ( pStr > pLibFile && *pStr != '\\' && *pStr != '/' )
pStr--;
if ( pStr == pLibFile )
strcpy( pLibFile, pLibName );
else
sprintf( pStr, "\\%s", pLibName );
}
#endif
pFileGen = Io_FileOpen( pLibFile, "open_path", "r", 1 );
// pFileGen = fopen( pLibFile, "r" );
if ( pFileGen == NULL )
{
printf( "Cannot open the GENLIB file \"%s\".\n", pLibFile );
return 0;
}
fclose( pFileGen );
// read the genlib library
pLib->pGenlib = Mio_LibraryRead( pLibFile, 0, 0 );
if ( pLib->pGenlib == NULL )
{
printf( "Cannot read GENLIB file \"%s\".\n", pLibFile );
return 0;
}
// read the number of variables
fscanf( pFile, "%d\n", &pLib->nVarsMax );
if ( pLib->nVarsMax < 2 || pLib->nVarsMax > 10 )
{
printf( "Suspicious number of variables (%d).\n", pLib->nVarsMax );
return 0;
}
// read the number of gates
fscanf( pFile, "%d\n", &pLib->nSupersReal );
if ( pLib->nSupersReal < 1 || pLib->nSupersReal > 10000000 )
{
printf( "Suspicious number of gates (%d).\n", pLib->nSupersReal );
return 0;
}
// read the number of lines
fscanf( pFile, "%d\n", &pLib->nLines );
if ( pLib->nLines < 1 || pLib->nLines > 10000000 )
{
printf( "Suspicious number of lines (%d).\n", pLib->nLines );
return 0;
}
// allocate room for supergate pointers
pLib->ppSupers = 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++ )
{
pGate->tDelaysR[k].Rise = pGate->tDelaysR[k].Fall = MAP_NO_VAR;
pGate->tDelaysF[k].Rise = pGate->tDelaysF[k].Fall = MAP_NO_VAR;
}
// 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 )
{
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 )
{
Extra_ProgressBarStop( pProgress );
return 0;
}
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 );
}
Extra_ProgressBarStop( pProgress );
if ( nCounter != pLib->nLines )
printf( "The number of lines read (%d) is different 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;
}
/**Function*************************************************************
Synopsis [Reads one gate.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Map_Super_t * Map_LibraryReadGateTree( Map_SuperLib_t * pLib, char * pBuffer, int Number, int nVarsMax )
{
Map_Super_t * pGate;
char * pTemp;
int i, Num;
// 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] == '*' )
{
pGate->fSuper = 1;
pTemp = strtok( NULL, " " );
}
// read the root gate
pGate->pRoot = Mio_LibraryReadGateByName( pLib->pGenlib, pTemp, NULL );
if ( pGate->pRoot == NULL )
{
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 )
{
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;
}
// 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 );
}
// 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 [Derives information about the library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Map_LibraryDeriveGateInfo( Map_SuperLib_t * pLib, st_table * tExcludeGate )
{
Map_Super_t * pGate, * pFanin;
Mio_Pin_t * pPin;
unsigned uCanon[2];
unsigned uTruths[6][2];
int i, k, nRealVars;
// set all the derivable info related to the supergates
for ( i = pLib->nVarsMax; i < (int)pLib->nLines; i++ )
{
pGate = pLib->ppSupers[i];
if ( tExcludeGate )
{
if ( st_is_member( tExcludeGate, Mio_GateReadName( pGate->pRoot ) ) )
pGate->fExclude = 1;
for ( k = 0; k < (int)pGate->nFanins; k++ )
{
pFanin = pGate->pFanins[k];
if ( pFanin->fExclude )
{
pGate->fExclude = 1;
continue;
}
}
}
// collect the truth tables of the fanins
for ( k = 0; k < (int)pGate->nFanins; k++ )
{
pFanin = pGate->pFanins[k];
uTruths[k][0] = pFanin->uTruth[0];
uTruths[k][1] = pFanin->uTruth[1];
}
// derive the new truth table
Mio_DeriveTruthTable( pGate->pRoot, uTruths, pGate->nFanins, 6, pGate->uTruth );
// set the initial delays of the supergate
for ( k = 0; k < pLib->nVarsMax; k++ )
{
pGate->tDelaysR[k].Rise = pGate->tDelaysR[k].Fall = MAP_NO_VAR;
pGate->tDelaysF[k].Rise = pGate->tDelaysF[k].Fall = MAP_NO_VAR;
}
// get the linked list of pins for the given root gate
pPin = Mio_GateReadPins( pGate->pRoot );
// update the initial delay of the supergate using info from the corresponding pin
for ( k = 0; k < (int)pGate->nFanins; k++, pPin = Mio_PinReadNext(pPin) )
{
// if there is no corresponding pin, this is a bug, return fail
if ( pPin == NULL )
{
printf( "There are less pins than gate inputs.\n" );
return 0;
}
// update the delay information of k-th fanins info from the corresponding pin
Map_LibraryAddFaninDelays( pLib, pGate, pGate->pFanins[k], pPin );
}
// if there are some pins left, this is a bug, return fail
if ( pPin != NULL )
{
printf( "There are more pins than gate inputs.\n" );
return 0;
}
// find the max delay
pGate->tDelayMax.Rise = pGate->tDelayMax.Fall = MAP_NO_VAR;
for ( k = 0; k < pLib->nVarsMax; k++ )
{
// the rise of the output depends on the rise and fall of the output
if ( pGate->tDelayMax.Rise < pGate->tDelaysR[k].Rise )
pGate->tDelayMax.Rise = pGate->tDelaysR[k].Rise;
if ( pGate->tDelayMax.Rise < pGate->tDelaysR[k].Fall )
pGate->tDelayMax.Rise = pGate->tDelaysR[k].Fall;
// the fall of the output depends on the rise and fall of the output
if ( pGate->tDelayMax.Fall < pGate->tDelaysF[k].Rise )
pGate->tDelayMax.Fall = pGate->tDelaysF[k].Rise;
if ( pGate->tDelayMax.Fall < pGate->tDelaysF[k].Fall )
pGate->tDelayMax.Fall = pGate->tDelaysF[k].Fall;
pGate->tDelaysF[k].Worst = MAP_MAX( pGate->tDelaysF[k].Fall, pGate->tDelaysF[k].Rise );
pGate->tDelaysR[k].Worst = MAP_MAX( pGate->tDelaysR[k].Fall, pGate->tDelaysR[k].Rise );
}
// count gates and area of the supergate
pGate->nGates = 1;
pGate->Area = (float)Mio_GateReadArea(pGate->pRoot);
for ( k = 0; k < (int)pGate->nFanins; k++ )
{
pGate->nGates += pGate->pFanins[k]->nGates;
pGate->Area += pGate->pFanins[k]->Area;
}
// do not add the gate to the table, if this gate is an internal gate
// of some supegate and does not correspond to a supergate output
if ( ( !pGate->fSuper ) || pGate->fExclude )
continue;
// find the maximum index of a variable in the support of the supergates
// this is important for two reasons:
// (1) to limit the number of permutations considered for canonicization
// (2) to get rid of equivalence phases to speed-up matching
nRealVars = Map_LibraryGetMaxSuperPi_rec( pGate ) + 1;
assert( nRealVars > 0 && nRealVars <= pLib->nVarsMax );
// if there are some problems with this code, try this instead
// nRealVars = pLib->nVarsMax;
// find the N-canonical form of this supergate
pGate->nPhases = Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, nRealVars, pGate->uTruth, pGate->uPhases, uCanon );
// add the supergate into the table by its N-canonical table
Map_SuperTableInsertC( pLib->tTableC, uCanon, pGate );
/*
{
int uCanon1, uCanon2;
uCanon1 = uCanon[0];
pGate->uTruth[0] = ~pGate->uTruth[0];
pGate->uTruth[1] = ~pGate->uTruth[1];
Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, nRealVars, pGate->uTruth, pGate->uPhases, uCanon );
uCanon2 = uCanon[0];
Rwt_Man5ExploreCount( uCanon1 < uCanon2 ? uCanon1 : uCanon2 );
}
*/
}
// sort the gates in each line
Map_SuperTableSortSupergatesByDelay( pLib->tTableC, pLib->nSupersAll );
// let the glory be manifest
// Map_LibraryPrintTree( pLib );
return 1;
}
/**Function*************************************************************
Synopsis [Finds the largest PI number in the support of the supergate.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Map_LibraryGetMaxSuperPi_rec( Map_Super_t * pGate )
{
int i, VarCur, VarMax = 0;
if ( pGate->pRoot == NULL )
return pGate->Num;
for ( i = 0; i < (int)pGate->nFanins; i++ )
{
VarCur = Map_LibraryGetMaxSuperPi_rec( pGate->pFanins[i] );
if ( VarMax < VarCur )
VarMax = VarCur;
}
return VarMax;
}
/**Function*************************************************************
Synopsis [Finds the largest PI number in the support of the supergate.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
unsigned Map_LibraryGetGateSupp_rec( Map_Super_t * pGate )
{
unsigned uSupport;
int i;
if ( pGate->pRoot == NULL )
return (unsigned)(1 << (pGate->Num));
uSupport = 0;
for ( i = 0; i < (int)pGate->nFanins; i++ )
uSupport |= Map_LibraryGetGateSupp_rec( pGate->pFanins[i] );
return uSupport;
}
/**Function*************************************************************
Synopsis [Derives the pin-to-pin delay constraints for the supergate.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Map_LibraryAddFaninDelays( Map_SuperLib_t * pLib, Map_Super_t * pGate, Map_Super_t * pFanin, Mio_Pin_t * pPin )
{
Mio_PinPhase_t PinPhase;
float tDelayBlockRise, tDelayBlockFall, tDelayPin;
int fMaxDelay = 0;
int i;
// use this node to enable max-delay model
if ( fMaxDelay )
{
float tDelayBlockMax;
// get the maximum delay
tDelayBlockMax = (float)Mio_PinReadDelayBlockMax(pPin);
// go through the supergate inputs
for ( i = 0; i < pLib->nVarsMax; i++ )
{
if ( pFanin->tDelaysR[i].Rise < 0 )
continue;
tDelayPin = pFanin->tDelaysR[i].Rise + tDelayBlockMax;
if ( pGate->tDelaysR[i].Rise < tDelayPin )
pGate->tDelaysR[i].Rise = tDelayPin;
}
// go through the supergate inputs
for ( i = 0; i < pLib->nVarsMax; i++ )
{
if ( pFanin->tDelaysF[i].Fall < 0 )
continue;
tDelayPin = pFanin->tDelaysF[i].Fall + tDelayBlockMax;
if ( pGate->tDelaysF[i].Fall < tDelayPin )
pGate->tDelaysF[i].Fall = tDelayPin;
}
return;
}
// get the interesting parameters of this pin
PinPhase = Mio_PinReadPhase(pPin);
tDelayBlockRise = (float)Mio_PinReadDelayBlockRise( pPin );
tDelayBlockFall = (float)Mio_PinReadDelayBlockFall( pPin );
// update the rise and fall of the output depending on the phase of the pin
if ( PinPhase != MIO_PHASE_INV ) // NONINV phase is present
{
// the rise of the gate is determined by the rise of the fanin
// the fall of the gate is determined by the fall of the fanin
for ( i = 0; i < pLib->nVarsMax; i++ )
{
////////////////////////////////////////////////////////
// consider the rise of the gate
////////////////////////////////////////////////////////
// check two types of constraints on the rise of the fanin:
// (1) the constraints related to the rise of the PIs
// (2) the constraints related to the fall of the PIs
if ( pFanin->tDelaysR[i].Rise >= 0 ) // case (1)
{ // fanin's rise depends on the rise of i-th PI
// update the rise of the gate's output
if ( pGate->tDelaysR[i].Rise < pFanin->tDelaysR[i].Rise + tDelayBlockRise )
pGate->tDelaysR[i].Rise = pFanin->tDelaysR[i].Rise + tDelayBlockRise;
}
if ( pFanin->tDelaysR[i].Fall >= 0 ) // case (2)
{ // fanin's rise depends on the fall of i-th PI
// update the rise of the gate's output
if ( pGate->tDelaysR[i].Fall < pFanin->tDelaysR[i].Fall + tDelayBlockRise )
pGate->tDelaysR[i].Fall = pFanin->tDelaysR[i].Fall + tDelayBlockRise;
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// consider the fall of the gate (similar)
////////////////////////////////////////////////////////
// check two types of constraints on the fall of the fanin:
// (1) the constraints related to the rise of the PIs
// (2) the constraints related to the fall of the PIs
if ( pFanin->tDelaysF[i].Rise >= 0 ) // case (1)
{
if ( pGate->tDelaysF[i].Rise < pFanin->tDelaysF[i].Rise + tDelayBlockFall )
pGate->tDelaysF[i].Rise = pFanin->tDelaysF[i].Rise + tDelayBlockFall;
}
if ( pFanin->tDelaysF[i].Fall >= 0 ) // case (2)
{
if ( pGate->tDelaysF[i].Fall < pFanin->tDelaysF[i].Fall + tDelayBlockFall )
pGate->tDelaysF[i].Fall = pFanin->tDelaysF[i].Fall + tDelayBlockFall;
}
////////////////////////////////////////////////////////
}
}
if ( PinPhase != MIO_PHASE_NONINV ) // INV phase is present
{
// the rise of the gate is determined by the fall of the fanin
// the fall of the gate is determined by the rise of the fanin
for ( i = 0; i < pLib->nVarsMax; i++ )
{
////////////////////////////////////////////////////////
// consider the rise of the gate's output
////////////////////////////////////////////////////////
// check two types of constraints on the fall of the fanin:
// (1) the constraints related to the rise of the PIs
// (2) the constraints related to the fall of the PIs
if ( pFanin->tDelaysF[i].Rise >= 0 ) // case (1)
{ // fanin's rise depends on the rise of i-th PI
// update the rise of the gate
if ( pGate->tDelaysR[i].Rise < pFanin->tDelaysF[i].Rise + tDelayBlockRise )
pGate->tDelaysR[i].Rise = pFanin->tDelaysF[i].Rise + tDelayBlockRise;
}
if ( pFanin->tDelaysF[i].Fall >= 0 ) // case (2)
{ // fanin's rise depends on the fall of i-th PI
// update the rise of the gate
if ( pGate->tDelaysR[i].Fall < pFanin->tDelaysF[i].Fall + tDelayBlockRise )
pGate->tDelaysR[i].Fall = pFanin->tDelaysF[i].Fall + tDelayBlockRise;
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// consider the fall of the gate (similar)
////////////////////////////////////////////////////////
// check two types of constraints on the rise of the fanin:
// (1) the constraints related to the rise of the PIs
// (2) the constraints related to the fall of the PIs
if ( pFanin->tDelaysR[i].Rise >= 0 ) // case (1)
{
if ( pGate->tDelaysF[i].Rise < pFanin->tDelaysR[i].Rise + tDelayBlockFall )
pGate->tDelaysF[i].Rise = pFanin->tDelaysR[i].Rise + tDelayBlockFall;
}
if ( pFanin->tDelaysR[i].Fall >= 0 ) // case (2)
{
if ( pGate->tDelaysF[i].Fall < pFanin->tDelaysR[i].Fall + tDelayBlockFall )
pGate->tDelaysF[i].Fall = pFanin->tDelaysR[i].Fall + tDelayBlockFall;
}
////////////////////////////////////////////////////////
}
}
}
/**Function*************************************************************
Synopsis [Performs phase transformation for one function.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
unsigned Map_CalculatePhase( unsigned uTruths[][2], int nVars, unsigned uTruth, unsigned uPhase )
{
int v, Shift;
for ( v = 0, Shift = 1; v < nVars; v++, Shift <<= 1 )
if ( uPhase & Shift )
uTruth = (((uTruth & ~uTruths[v][0]) << Shift) | ((uTruth & uTruths[v][0]) >> Shift));
return uTruth;
}
/**Function*************************************************************
Synopsis [Performs phase transformation for one function.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Map_CalculatePhase6( unsigned uTruths[][2], int nVars, unsigned uTruth[], unsigned uPhase, unsigned uTruthRes[] )
{
unsigned uTemp;
int v, Shift;
// initialize the result
uTruthRes[0] = uTruth[0];
uTruthRes[1] = uTruth[1];
if ( uPhase == 0 )
return;
// compute the phase
for ( v = 0, Shift = 1; v < nVars; v++, Shift <<= 1 )
if ( uPhase & Shift )
{
if ( Shift < 32 )
{
uTruthRes[0] = (((uTruthRes[0] & ~uTruths[v][0]) << Shift) | ((uTruthRes[0] & uTruths[v][0]) >> Shift));
uTruthRes[1] = (((uTruthRes[1] & ~uTruths[v][1]) << Shift) | ((uTruthRes[1] & uTruths[v][1]) >> Shift));
}
else
{
uTemp = uTruthRes[0];
uTruthRes[0] = uTruthRes[1];
uTruthRes[1] = uTemp;
}
}
}
/**Function*************************************************************
Synopsis [Prints the supergate library after deriving parameters.]
Description [This procedure is very useful to see the library after
it has been read into the mapper by "read_super" and all the information
about the supergates derived.]
SideEffects []
SeeAlso []
***********************************************************************/
void Map_LibraryPrintTree( Map_SuperLib_t * pLib )
{
Map_Super_t * pGate;
int i, k;
// print all the info related to the supergates
// for ( i = pLib->nVarsMax; i < (int)pLib->nLines; i++ )
for ( i = pLib->nVarsMax; i < 20; i++ )
{
pGate = pLib->ppSupers[i];
// write the gate's fanin info and formula
printf( "%6d ", pGate->Num );
printf( "%c ", pGate->fSuper? '*' : ' ' );
printf( "%6s", Mio_GateReadName(pGate->pRoot) );
for ( k = 0; k < (int)pGate->nFanins; k++ )
printf( " %6d", pGate->pFanins[k]->Num );
printf( " %s", pGate->pFormula );
printf( "\n" );
// write the gate's derived info
Extra_PrintBinary( stdout, pGate->uTruth, 64 );
printf( " %3d", pGate->nGates );
printf( " %6.2f", pGate->Area );
printf( " (%4.2f, %4.2f)", pGate->tDelayMax.Rise, pGate->tDelayMax.Fall );
printf( "\n" );
for ( k = 0; k < pLib->nVarsMax; k++ )
{
// print the constraint on the rise of the gate in the form (D1, D2),
// where D1 is the constraint related to the rise of the k-th PI
// where D2 is the constraint related to the fall of the k-th PI
if ( pGate->tDelaysR[k].Rise < 0 && pGate->tDelaysR[k].Fall < 0 )
printf( " (----, ----)" );
else if ( pGate->tDelaysR[k].Fall < 0 )
printf( " (%4.2f, ----)", pGate->tDelaysR[k].Rise );
else if ( pGate->tDelaysR[k].Rise < 0 )
printf( " (----, %4.2f)", pGate->tDelaysR[k].Fall );
else
printf( " (%4.2f, %4.2f)", pGate->tDelaysR[k].Rise, pGate->tDelaysR[k].Fall );
// print the constraint on the fall of the gate in the form (D1, D2),
// where D1 is the constraint related to the rise of the k-th PI
// where D2 is the constraint related to the fall of the k-th PI
if ( pGate->tDelaysF[k].Rise < 0 && pGate->tDelaysF[k].Fall < 0 )
printf( " (----, ----)" );
else if ( pGate->tDelaysF[k].Fall < 0 )
printf( " (%4.2f, ----)", pGate->tDelaysF[k].Rise );
else if ( pGate->tDelaysF[k].Rise < 0 )
printf( " (----, %4.2f)", pGate->tDelaysF[k].Fall );
else
printf( " (%4.2f, %4.2f)", pGate->tDelaysF[k].Rise, pGate->tDelaysF[k].Fall );
printf( "\n" );
}
printf( "\n" );
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
...@@ -35,12 +35,10 @@ ABC_NAMESPACE_IMPL_START ...@@ -35,12 +35,10 @@ ABC_NAMESPACE_IMPL_START
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
static int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv ); static int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandReadLibrary2( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintLibrary2( Abc_Frame_t * pAbc, int argc, char **argv );
/* /*
// internal version of GENLIB library // internal version of GENLIB library
static char * pMcncGenlib[25] = { static char * pMcncGenlib[25] = {
...@@ -84,37 +82,15 @@ static char * pMcncGenlib[25] = { ...@@ -84,37 +82,15 @@ static char * pMcncGenlib[25] = {
***********************************************************************/ ***********************************************************************/
void Mio_Init( Abc_Frame_t * pAbc ) void Mio_Init( Abc_Frame_t * pAbc )
{ {
/*
char * pFileTemp = "mcnc_temp.genlib";
void * pLibGen;
FILE * pFile;
int i;
// write genlib into file
pFile = fopen( pFileTemp, "w" );
for ( i = 0; pMcncGenlib[i]; i++ )
fputs( pMcncGenlib[i], pFile );
fclose( pFile );
// read genlib from file
pLibGen = Mio_LibraryRead( pAbc, pFileTemp, NULL, 0 );
Abc_FrameSetLibGen( pLibGen );
pLibGen = Amap_LibReadAndPrepare( pFileTemp, 0, 0 );
Abc_FrameSetLibGen2( pLibGen );
#ifdef WIN32
_unlink( pFileTemp );
#else
unlink( pFileTemp );
#endif
*/
Cmd_CommandAdd( pAbc, "SC mapping", "read_liberty", Mio_CommandReadLiberty, 0 ); Cmd_CommandAdd( pAbc, "SC mapping", "read_liberty", Mio_CommandReadLiberty, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "read_library", Mio_CommandReadLibrary, 0 ); Cmd_CommandAdd( pAbc, "SC mapping", "read_genlib", Mio_CommandReadGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "print_library", Mio_CommandPrintLibrary, 0 ); Cmd_CommandAdd( pAbc, "SC mapping", "write_genlib", Mio_CommandWriteGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "print_genlib", Mio_CommandPrintGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "read_library2", Mio_CommandReadLibrary2, 0 ); Cmd_CommandAdd( pAbc, "SC mapping", "read_library", Mio_CommandReadGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "print_library2", Mio_CommandPrintLibrary2, 0 ); Cmd_CommandAdd( pAbc, "SC mapping", "write_library", Mio_CommandWriteGenlib, 0 );
Cmd_CommandAdd( pAbc, "SC mapping", "print_library", Mio_CommandPrintGenlib, 0 );
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -130,7 +106,6 @@ void Mio_Init( Abc_Frame_t * pAbc ) ...@@ -130,7 +106,6 @@ void Mio_Init( Abc_Frame_t * pAbc )
***********************************************************************/ ***********************************************************************/
void Mio_End( Abc_Frame_t * pAbc ) void Mio_End( Abc_Frame_t * pAbc )
{ {
// Mio_LibraryDelete( s_pLib );
Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() ); Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() ); Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
} }
...@@ -149,6 +124,7 @@ void Mio_End( Abc_Frame_t * pAbc ) ...@@ -149,6 +124,7 @@ void Mio_End( Abc_Frame_t * pAbc )
***********************************************************************/ ***********************************************************************/
int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv ) int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv )
{ {
int fUseFileInterface = 0;
char Command[1000]; char Command[1000];
FILE * pFile; FILE * pFile;
FILE * pOut, * pErr; FILE * pOut, * pErr;
...@@ -197,11 +173,54 @@ int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -197,11 +173,54 @@ int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv )
} }
fclose( pFile ); fclose( pFile );
if ( !Amap_LibertyParse( pFileName, fVerbose ) ) if ( fUseFileInterface )
return 0; {
assert( strlen(pFileName) < 900 ); if ( !Amap_LibertyParse( pFileName, fVerbose ) )
sprintf( Command, "read_library %s", Extra_FileNameGenericAppend(pFileName, ".genlib") ); return 0;
Cmd_CommandExecute( pAbc, Command ); assert( strlen(pFileName) < 900 );
sprintf( Command, "read_genlib %s", Extra_FileNameGenericAppend(pFileName, ".genlib") );
Cmd_CommandExecute( pAbc, Command );
}
else
{
Mio_Library_t * pLib;
Vec_Str_t * vStr, * vStr2;
vStr = Amap_LibertyParseStr( pFileName, fVerbose );
if ( vStr == NULL )
return 0;
vStr2 = Vec_StrDup( vStr );
// set the new network
pLib = Mio_LibraryRead( pFileName, Vec_StrArray(vStr), NULL, fVerbose );
Vec_StrFree( vStr );
if ( pLib == NULL )
{
Vec_StrFree( vStr2 );
return 0;
}
// free the current superlib because it depends on the old Mio library
if ( Abc_FrameReadLibSuper() )
{
Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
Abc_FrameSetLibSuper( NULL );
}
// replace the current library
Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
Abc_FrameSetLibGen( pLib );
// set the new network
pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, Vec_StrArray(vStr2), 0, 0 );
Vec_StrFree( vStr2 );
if ( pLib == NULL )
return 0;
// replace the current library
Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
Abc_FrameSetLibGen2( pLib );
}
return 0; return 0;
usage: usage:
...@@ -212,7 +231,7 @@ usage: ...@@ -212,7 +231,7 @@ usage:
fprintf( pErr, "\t with the smallest area will be used)\n" ); fprintf( pErr, "\t with the smallest area will be used)\n" );
fprintf( pErr, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" ); fprintf( pErr, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
fprintf( pErr, "\t-h : enable verbose output\n"); fprintf( pErr, "\t-h : enable verbose output\n");
return 1; /* error exit */ return 1;
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -226,7 +245,7 @@ usage: ...@@ -226,7 +245,7 @@ usage:
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
{ {
FILE * pFile; FILE * pFile;
FILE * pOut, * pErr; FILE * pOut, * pErr;
...@@ -298,7 +317,7 @@ int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -298,7 +317,7 @@ int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
fclose( pFile ); fclose( pFile );
// set the new network // set the new network
pLib = Mio_LibraryRead( pFileName, pExcludeFile, fVerbose ); pLib = Mio_LibraryRead( pFileName, NULL, pExcludeFile, fVerbose );
if ( pLib == NULL ) if ( pLib == NULL )
{ {
fprintf( pErr, "Reading GENLIB library has failed.\n" ); fprintf( pErr, "Reading GENLIB library has failed.\n" );
...@@ -320,7 +339,7 @@ int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -320,7 +339,7 @@ int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
Abc_FrameSetLibGen( pLib ); Abc_FrameSetLibGen( pLib );
// set the new network // set the new network
pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, 0, 0 ); pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, NULL, 0, 0 );
if ( pLib == NULL ) if ( pLib == NULL )
{ {
fprintf( pErr, "Reading GENLIB library has failed.\n" ); fprintf( pErr, "Reading GENLIB library has failed.\n" );
...@@ -329,10 +348,12 @@ int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -329,10 +348,12 @@ int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
// replace the current library // replace the current library
Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() ); Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
Abc_FrameSetLibGen2( pLib ); Abc_FrameSetLibGen2( pLib );
if ( fVerbose )
printf( "Entered GENLIB library with %d gates from file \"%s\".\n", Mio_LibraryReadGateNum(pLib), pFileName );
return 0; return 0;
usage: usage:
fprintf( pErr, "usage: read_library [-W float] [-E filename] [-vh]\n"); fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-vh]\n");
fprintf( pErr, "\t read the library from a genlib file\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 (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 same Boolean function, only the gate\n" );
...@@ -341,101 +362,9 @@ usage: ...@@ -341,101 +362,9 @@ usage:
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-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" ); fprintf( pErr, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
fprintf( pErr, "\t-h : enable verbose output\n"); fprintf( pErr, "\t-h : enable verbose output\n");
return 1; /* error exit */ return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Mio_CommandReadLibrary2( Abc_Frame_t * pAbc, int argc, char **argv )
{
FILE * pFile;
FILE * pOut, * pErr;
Mio_Library_t * pLib;
Abc_Ntk_t * pNet;
char * pFileName;
int fVerbose;
int fVeryVerbose;
int c;
pNet = Abc_FrameReadNtk(pAbc);
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
// set the defaults
fVerbose = 1;
fVeryVerbose = 0;
Extra_UtilGetoptReset();
while ( (c = Extra_UtilGetopt(argc, argv, "vwh")) != EOF )
{
switch (c)
{
case 'v':
fVerbose ^= 1;
break;
case 'w':
fVeryVerbose ^= 1;
break;
case 'h':
goto usage;
break;
default:
goto usage;
}
}
if ( argc != globalUtilOptind + 1 )
{
goto usage;
}
// get the input file name
pFileName = argv[globalUtilOptind];
if ( (pFile = Io_FileOpen( pFileName, "open_path", "r", 0 )) == NULL )
{
fprintf( pErr, "Cannot open input file \"%s\". ", pFileName );
if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".genlib", ".lib", ".gen", ".g", NULL )) )
fprintf( pErr, "Did you mean \"%s\"?", pFileName );
fprintf( pErr, "\n" );
return 1;
}
fclose( pFile );
// set the new network
pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, fVerbose, fVeryVerbose );
if ( pLib == NULL )
{
fprintf( pErr, "Reading GENLIB library has failed.\n" );
return 1;
}
// replace the current library
Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
Abc_FrameSetLibGen2( pLib );
return 0;
usage:
fprintf( pErr, "usage: read_library2 [-vh]\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-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
fprintf( pErr, "\t-w : toggle detailed printout [default = %s]\n", fVeryVerbose? "yes": "no" );
fprintf( pErr, "\t-h : enable verbose output\n");
return 1; /* error exit */
} }
/**Function************************************************************* /**Function*************************************************************
Synopsis [Command procedure to read LUT libraries.] Synopsis [Command procedure to read LUT libraries.]
...@@ -447,7 +376,7 @@ usage: ...@@ -447,7 +376,7 @@ usage:
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Mio_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
{ {
FILE * pOut, * pErr, * pFile; FILE * pOut, * pErr, * pFile;
Abc_Ntk_t * pNet; Abc_Ntk_t * pNet;
...@@ -481,35 +410,33 @@ int Mio_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -481,35 +410,33 @@ int Mio_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
printf( "Library is not available.\n" ); printf( "Library is not available.\n" );
return 1; return 1;
} }
if ( argc != globalUtilOptind + 1 )
{
printf( "The file name is not given.\n" );
return 1;
}
pFileName = argv[globalUtilOptind]; pFileName = argv[globalUtilOptind];
if ( argc == globalUtilOptind + 1 ) pFile = fopen( pFileName, "w" );
if ( pFile == NULL )
{ {
pFile = fopen( pFileName, "w" ); printf( "Error! Cannot open file \"%s\" for writing the library.\n", pFileName );
if ( pFile == NULL ) return 1;
{
printf( "Error! Cannot open file \"%s\" for writing the library.\n", pFileName );
return 1;
}
Mio_WriteLibrary( pFile, (Mio_Library_t *)Abc_FrameReadLibGen(), 0 );
fclose( pFile );
printf( "The current GENLIB library is written into file \"%s\".\n", pFileName );
} }
else if ( argc == globalUtilOptind ) Mio_WriteLibrary( pFile, (Mio_Library_t *)Abc_FrameReadLibGen(), 0 );
Mio_WriteLibrary( stdout, (Mio_Library_t *)Abc_FrameReadLibGen(), 0 ); fclose( pFile );
else printf( "The current GENLIB library is written into file \"%s\".\n", pFileName );
goto usage;
return 0; return 0;
usage: usage:
fprintf( pErr, "\nusage: print_library [-vh] <file>\n"); fprintf( pErr, "\nusage: write_genlib [-vh] <file>\n");
fprintf( pErr, "\t print the current genlib library\n" ); fprintf( pErr, "\t writes the current genlib library into a file\n" );
fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", fVerbose? "yes" : "no" ); fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", fVerbose? "yes" : "no" );
fprintf( pErr, "\t-h : print the command usage\n"); fprintf( pErr, "\t-h : print the command usage\n");
fprintf( pErr, "\t<file> : optional file name to write the library\n"); fprintf( pErr, "\t<file> : optional file name to write the library\n");
return 1; /* error exit */ return 1;
} }
/**Function************************************************************* /**Function*************************************************************
Synopsis [Command procedure to read LUT libraries.] Synopsis [Command procedure to read LUT libraries.]
...@@ -521,11 +448,10 @@ usage: ...@@ -521,11 +448,10 @@ usage:
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Mio_CommandPrintLibrary2( Abc_Frame_t * pAbc, int argc, char **argv ) int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
{ {
FILE * pOut, * pErr; FILE * pOut, * pErr;
Abc_Ntk_t * pNet; Abc_Ntk_t * pNet;
int fPrintAll;
int fVerbose; int fVerbose;
int c; int c;
...@@ -534,16 +460,12 @@ int Mio_CommandPrintLibrary2( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -534,16 +460,12 @@ int Mio_CommandPrintLibrary2( Abc_Frame_t * pAbc, int argc, char **argv )
pErr = Abc_FrameReadErr(pAbc); pErr = Abc_FrameReadErr(pAbc);
// set the defaults // set the defaults
fPrintAll = 0;
fVerbose = 1; fVerbose = 1;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( (c = Extra_UtilGetopt(argc, argv, "avh")) != EOF ) while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
{ {
switch (c) switch (c)
{ {
case 'a':
fPrintAll ^= 1;
break;
case 'v': case 'v':
fVerbose ^= 1; fVerbose ^= 1;
break; break;
...@@ -554,24 +476,20 @@ int Mio_CommandPrintLibrary2( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -554,24 +476,20 @@ int Mio_CommandPrintLibrary2( Abc_Frame_t * pAbc, int argc, char **argv )
goto usage; goto usage;
} }
} }
if ( Abc_FrameReadLibGen() == NULL )
if ( argc != globalUtilOptind )
{ {
goto usage; printf( "Library is not available.\n" );
return 1;
} }
Mio_WriteLibrary( stdout, (Mio_Library_t *)Abc_FrameReadLibGen(), 0 );
// set the new network
Amap_LibPrintSelectedGates( (Amap_Lib_t *)Abc_FrameReadLibGen2(), fPrintAll );
return 0; return 0;
usage: usage:
fprintf( pErr, "\nusage: print_library2 [-avh]\n"); fprintf( pErr, "\nusage: print_genlib [-vh]\n");
fprintf( pErr, "\t print gates used for area-oriented tech-mapping\n" ); fprintf( pErr, "\t print the current genlib library\n" );
fprintf( pErr, "\t-a : toggles printing all gates [default = %s]\n", (fPrintAll? "yes" : "no") ); fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", fVerbose? "yes" : "no" );
fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
fprintf( pErr, "\t-h : print the command usage\n"); fprintf( pErr, "\t-h : print the command usage\n");
return 1; /* error exit */ return 1;
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
......
...@@ -129,7 +129,7 @@ extern double Mio_PinReadDelayFanoutFall( Mio_Pin_t * pPin ); ...@@ -129,7 +129,7 @@ extern double Mio_PinReadDelayFanoutFall( Mio_Pin_t * pPin );
extern double Mio_PinReadDelayBlockMax ( Mio_Pin_t * pPin ); extern double Mio_PinReadDelayBlockMax ( Mio_Pin_t * pPin );
extern Mio_Pin_t * Mio_PinReadNext ( Mio_Pin_t * pPin ); extern Mio_Pin_t * Mio_PinReadNext ( Mio_Pin_t * pPin );
/*=== mioRead.c =============================================================*/ /*=== mioRead.c =============================================================*/
extern Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbose ); extern Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * ExcludeFile, int fVerbose );
extern int Mio_LibraryReadExclude( char * ExcludeFile, st_table * tExcludeGate ); extern int Mio_LibraryReadExclude( char * ExcludeFile, st_table * tExcludeGate );
/*=== mioFunc.c =============================================================*/ /*=== mioFunc.c =============================================================*/
extern int Mio_LibraryParseFormulas( Mio_Library_t * pLib ); extern int Mio_LibraryParseFormulas( Mio_Library_t * pLib );
......
...@@ -32,6 +32,7 @@ ABC_NAMESPACE_IMPL_START ...@@ -32,6 +32,7 @@ ABC_NAMESPACE_IMPL_START
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
static Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_table * tExcludeGate, int fVerbose ); static Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_table * tExcludeGate, int fVerbose );
static 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 int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtendedFormat, st_table * tExcludeGate, int fVerbose );
static Mio_Gate_t * Mio_LibraryReadGate( char ** ppToken, int fExtendedFormat ); static Mio_Gate_t * Mio_LibraryReadGate( char ** ppToken, int fExtendedFormat );
static Mio_Pin_t * Mio_LibraryReadPin( char ** ppToken, int fExtendedFormat ); static Mio_Pin_t * Mio_LibraryReadPin( char ** ppToken, int fExtendedFormat );
...@@ -50,7 +51,7 @@ static void Io_ReadFileRemoveComments( char * pBuffer, int * pnDots, ...@@ -50,7 +51,7 @@ static void Io_ReadFileRemoveComments( char * pBuffer, int * pnDots,
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbose ) Mio_Library_t * Mio_LibraryRead( char * FileName, char * pBuffer, char * ExcludeFile, int fVerbose )
{ {
Mio_Library_t * pLib; Mio_Library_t * pLib;
int num; int num;
...@@ -69,10 +70,24 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo ...@@ -69,10 +70,24 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo
fprintf ( stdout, "Read %d gates from exclude file\n", num ); fprintf ( stdout, "Read %d gates from exclude file\n", num );
} }
pLib = Mio_LibraryReadOne( FileName, 0, tExcludeGate, fVerbose ); // try normal format first .. if ( pBuffer == NULL )
pLib = Mio_LibraryReadOne( FileName, 0, tExcludeGate, fVerbose ); // try normal format first ..
else
{
pLib = Mio_LibraryReadBuffer( pBuffer, 0, tExcludeGate, fVerbose ); // try normal format first ..
if ( pLib )
pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") );
}
if ( pLib == NULL ) if ( pLib == NULL )
{ {
pLib = Mio_LibraryReadOne( FileName, 1, tExcludeGate, fVerbose ); // .. otherwise try extended format if ( pBuffer == NULL )
pLib = Mio_LibraryReadOne( FileName, 1, tExcludeGate, fVerbose ); // try normal format first ..
else
{
pLib = Mio_LibraryReadBuffer( pBuffer, 1, tExcludeGate, fVerbose ); // try normal format first ..
if ( pLib )
pLib->pName = Abc_UtilStrsav( Extra_FileNameGenericAppend(FileName, ".genlib") );
}
if ( pLib != NULL ) if ( pLib != NULL )
printf ( "Warning: Read extended GENLIB format but ignoring extensions\n" ); printf ( "Warning: Read extended GENLIB format but ignoring extensions\n" );
} }
...@@ -84,6 +99,46 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo ...@@ -84,6 +99,46 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo
/**Function************************************************************* /**Function*************************************************************
Synopsis [Read contents of the file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
char * Mio_ReadFile( char * FileName )
{
char * pBuffer;
FILE * pFile;
int nFileSize;
int RetValue;
// open the BLIF file for binary reading
pFile = Io_FileOpen( FileName, "open_path", "rb", 1 );
// pFile = fopen( FileName, "rb" );
// if we got this far, file should be okay otherwise would
// have been detected by caller
assert ( pFile != NULL );
// get the file size, in bytes
fseek( pFile, 0, SEEK_END );
nFileSize = ftell( pFile );
// move the file current reading position to the beginning
rewind( pFile );
// load the contents of the file into memory
pBuffer = ABC_ALLOC( char, nFileSize + 10 );
RetValue = fread( pBuffer, nFileSize, 1, pFile );
// terminate the string with '\0'
pBuffer[ nFileSize ] = '\0';
strcat( pBuffer, "\n.end\n" );
// close file
fclose( pFile );
return pBuffer;
}
/**Function*************************************************************
Synopsis [Read the genlib type of library.] Synopsis [Read the genlib type of library.]
Description [] Description []
...@@ -93,60 +148,25 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo ...@@ -93,60 +148,25 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
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 )
{ {
Mio_Library_t * pLib; Mio_Library_t * pLib;
char * pBuffer = 0;
// allocate the genlib structure // allocate the genlib structure
pLib = ABC_ALLOC( Mio_Library_t, 1 ); pLib = ABC_ALLOC( Mio_Library_t, 1 );
memset( pLib, 0, sizeof(Mio_Library_t) ); memset( pLib, 0, sizeof(Mio_Library_t) );
pLib->pName = Mio_UtilStrsav( FileName );
pLib->tName2Gate = st_init_table(strcmp, st_strhash); pLib->tName2Gate = st_init_table(strcmp, st_strhash);
pLib->pMmFlex = Mem_FlexStart(); pLib->pMmFlex = Mem_FlexStart();
pLib->vCube = Vec_StrAlloc( 100 ); pLib->vCube = Vec_StrAlloc( 100 );
// read the file and clean comments
// pBuffer = Io_ReadFileFileContents( FileName, NULL );
// we don't use above function but actually do the same thing explicitly
// to handle open_path expansion correctly
{
FILE * pFile;
int nFileSize;
int RetValue;
// open the BLIF file for binary reading
pFile = Io_FileOpen( FileName, "open_path", "rb", 1 );
// pFile = fopen( FileName, "rb" );
// if we got this far, file should be okay otherwise would
// have been detected by caller
assert ( pFile != NULL );
// get the file size, in bytes
fseek( pFile, 0, SEEK_END );
nFileSize = ftell( pFile );
// move the file current reading position to the beginning
rewind( pFile );
// load the contents of the file into memory
pBuffer = ABC_ALLOC( char, nFileSize + 10 );
RetValue = fread( pBuffer, nFileSize, 1, pFile );
// terminate the string with '\0'
pBuffer[ nFileSize ] = '\0';
strcat( pBuffer, "\n.end\n" );
// close file
fclose( pFile );
}
Io_ReadFileRemoveComments( pBuffer, NULL, NULL ); Io_ReadFileRemoveComments( pBuffer, NULL, NULL );
// parse the contents of the file // parse the contents of the file
if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, fVerbose ) ) if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, fVerbose ) )
{ {
Mio_LibraryDelete( pLib ); Mio_LibraryDelete( pLib );
ABC_FREE( pBuffer );
return NULL; return NULL;
} }
ABC_FREE( pBuffer );
// derive the functinality of gates // derive the functinality of gates
if ( Mio_LibraryParseFormulas( pLib ) ) if ( Mio_LibraryParseFormulas( pLib ) )
...@@ -173,6 +193,35 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_tab ...@@ -173,6 +193,35 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_tab
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_table * tExcludeGate, int fVerbose )
{
Mio_Library_t * pLib;
char * pBuffer;
// read the file and clean comments
// 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 );
if ( pBuffer == NULL )
return NULL;
pLib = Mio_LibraryReadBuffer( pBuffer, fExtendedFormat, tExcludeGate, fVerbose );
ABC_FREE( pBuffer );
if ( pLib )
pLib->pName = Mio_UtilStrsav( FileName );
return pLib;
}
/**Function*************************************************************
Synopsis [Read the genlib type of library.]
Description []
SideEffects []
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 fVerbose )
{ {
Mio_Gate_t * pGate, ** ppGate; Mio_Gate_t * pGate, ** ppGate;
...@@ -248,12 +297,10 @@ int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtended ...@@ -248,12 +297,10 @@ int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtended
} }
pBase->pTwin = pGate; pBase->pTwin = pGate;
pGate->pTwin = pBase; pGate->pTwin = pBase;
printf( "Gate \"%s\" appears two times. Creating a 2-output gate.\n", pGate->pName ); // printf( "Gate \"%s\" appears two times. Creating a 2-output gate.\n", pGate->pName );
} }
} }
} }
if ( fVerbose )
printf( "Entered GENLIB library with %d gates from file \"%s\".\n", nGates, pLib->pName );
if ( nGates == 0 ) if ( nGates == 0 )
{ {
......
...@@ -267,7 +267,7 @@ int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -267,7 +267,7 @@ int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
fclose( pFile ); fclose( pFile );
// set the new network // set the new network
pLib = Mio_LibraryRead( FileName, ExcludeFile, fVerbose ); pLib = Mio_LibraryRead( FileName, NULL, ExcludeFile, fVerbose );
if ( pLib == NULL ) if ( pLib == NULL )
{ {
fprintf( pErr, "Reading library has failed.\n" ); fprintf( pErr, "Reading library has failed.\n" );
......
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