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,
{
// printf( "A simple supergate library is derived from gate library \"%s\".\n",
// 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
Map_SuperLibDeriveFromGenlib( pLib );
Map_SuperLibDeriveFromGenlib( pLib, fVerbose );
}
// return the library to normal
......@@ -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",
// 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
......
......@@ -201,7 +201,7 @@ int IoCommandRead( Abc_Frame_t * pAbc, int argc, char ** argv )
Command[0] = 0;
assert( strlen(pFileName) < 900 );
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" ) )
sprintf( Command, "read_liberty %s", pFileName );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "scl" ) )
......@@ -1298,6 +1298,7 @@ usage:
***********************************************************************/
int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv )
{
char Command[1000];
char * pFileName;
int c;
......@@ -1312,15 +1313,27 @@ int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv )
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 )
{
fprintf( pAbc->Out, "Empty network.\n" );
return 0;
}
if ( argc != globalUtilOptind + 1 )
goto usage;
// get the output file name
pFileName = argv[globalUtilOptind];
// call the corresponding file writer
Io_Write( pAbc->pNtkCur, pFileName, Io_ReadFileType(pFileName) );
return 0;
......
......@@ -76,9 +76,11 @@ extern void Amap_ManSetDefaultParams( Amap_Par_t * pPars );
/*=== amapLib.c ==========================================================*/
extern void Amap_LibFree( Amap_Lib_t * p );
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 ==========================================================*/
extern int Amap_LibertyParse( char * pFileName, int fVerbose );
extern Vec_Str_t * Amap_LibertyParseStr( char * pFileName, int fVerbose );
ABC_NAMESPACE_HEADER_END
......
......@@ -349,6 +349,7 @@ extern Vec_Ptr_t * Amap_ManProduceMapped( Amap_Man_t * p );
extern int Amap_LibParseEquations( Amap_Lib_t * p, int fVerbose );
/*=== amapPerm.c ==========================================================*/
/*=== amapRead.c ==========================================================*/
extern Amap_Lib_t * Amap_LibReadBuffer( char * pBuffer, int fVerbose );
extern Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose );
/*=== amapRule.c ==========================================================*/
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 )
ABC_FREE( p->pRules );
ABC_FREE( p->pRulesX );
ABC_FREE( p->pNodes );
ABC_FREE( p->pName );
ABC_FREE( p );
}
......@@ -325,11 +326,18 @@ void Amap_LibPrintSelectedGates( Amap_Lib_t * p, int fAllGates )
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;
clock_t clk = clock();
if ( pBuffer == NULL )
p = Amap_LibReadFile( pFileName, fVerbose );
else
{
p = Amap_LibReadBuffer( pBuffer, fVerbose );
if ( p )
p->pName = Abc_UtilStrsav( pFileName );
}
if ( fVerbose )
printf( "Read %d gates from file \"%s\".\n", Vec_PtrSize(p->vGates), pFileName );
if ( p == NULL )
......
......@@ -464,6 +464,101 @@ int Amap_LibertyPrintGenlib( Amap_Tree_t * p, char * pFileName, int fVerbose )
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*************************************************************
......@@ -950,6 +1045,55 @@ int Amap_LibertyParse( char * pFileName, int fVerbose )
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 ///
////////////////////////////////////////////////////////////////////////
......
......@@ -438,14 +438,10 @@ Amap_Lib_t * Amap_ParseTokens( Vec_Ptr_t * vTokens, int fVerbose )
SeeAlso []
***********************************************************************/
Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose )
Amap_Lib_t * Amap_LibReadBuffer( char * pBuffer, int fVerbose )
{
Amap_Lib_t * pLib;
Vec_Ptr_t * vTokens;
char * pBuffer;
pBuffer = Amap_LoadFile( pFileName );
if ( pBuffer == NULL )
return NULL;
Amap_RemoveComments( pBuffer, NULL, NULL );
vTokens = Amap_DeriveTokens( pBuffer );
pLib = Amap_ParseTokens( vTokens, fVerbose );
......@@ -454,8 +450,31 @@ Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose )
Vec_PtrFree( vTokens );
return NULL;
}
pLib->pName = Amap_ParseStrsav( pLib->pMemGates, pFileName );
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 );
return pLib;
}
......
......@@ -155,10 +155,8 @@ int Map_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
Abc_FrameSetLibSuper( pLib );
// replace the current genlib library
// if ( s_pLib ) Mio_LibraryDelete( s_pLib );
// s_pLib = s_pSuperLib->pGenlib;
Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
Abc_FrameSetLibGen( (Mio_Library_t *)pLib->pGenlib );
// Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
// Abc_FrameSetLibGen( (Mio_Library_t *)pLib->pGenlib );
return 0;
usage:
......
......@@ -165,7 +165,7 @@ extern void Map_CutCreateFromNode( Map_Man_t * p, Map_Super_t * pSupe
/*=== mapperCore.c =============================================================*/
extern int Map_Mapping( Map_Man_t * p );
/*=== 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 );
/*=== mapperMntk.c =============================================================*/
//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 )
// derive the supergate library
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;
}
......
/**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();
assert( p->nVarsMax > 0 );
// report the stats
if ( fVerbose ) {
if ( fVerbose )
{
printf( "Loaded %d unique %d-input supergates from \"%s\". ",
p->nSupersReal, p->nVarsMax, pFileName );
ABC_PRT( "Time", clock() - clk );
}
}
// assign the interver parameters
p->pGateInv = Mio_LibraryReadInv( p->pGenlib );
......@@ -149,8 +150,9 @@ void Map_SuperLibFree( Map_SuperLib_t * p )
if ( p->pGenlib )
{
assert( p->pGenlib == Abc_FrameReadLibGen() );
Mio_LibraryDelete( p->pGenlib );
Abc_FrameSetLibGen( NULL );
// Mio_LibraryDelete( p->pGenlib );
// Abc_FrameSetLibGen( NULL );
p->pGenlib = NULL;
}
if ( p->tTableC )
Map_SuperTableFree( p->tTableC );
......@@ -174,77 +176,22 @@ void Map_SuperLibFree( Map_SuperLib_t * p )
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();
char * pNameGeneric;
char * FileNameGenlib;
char * FileNameSuper;
char * CommandSuper;
char * CommandRead;
FILE * pFile;
char * pFileName;
if ( pLib == NULL )
return 0;
FileNameGenlib = ABC_ALLOC( char, 10000 );
FileNameSuper = ABC_ALLOC( char, 10000 );
CommandSuper = ABC_ALLOC( char, 10000 );
CommandRead = ABC_ALLOC( char, 10000 );
// 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 ) )
// 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");
if ( Cmd_CommandExecute( pAbc, pFileName ) )
{
//#ifdef WIN32
// _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 );
fprintf( stdout, "Cannot execute command \"read_super %s\".\n", pFileName );
return 0;
}
//#ifdef WIN32
// _unlink( FileNameSuper );
//#else
// unlink( FileNameSuper );
//#endif
ABC_FREE( FileNameGenlib );
ABC_FREE( FileNameSuper );
ABC_FREE( CommandSuper );
ABC_FREE( CommandRead );
return 1;
}
......
......@@ -115,7 +115,7 @@ int Map_LibraryReadFile( Map_SuperLib_t * pLib, FILE * pFile )
fclose( pFileGen );
// read the genlib library
pLib->pGenlib = Mio_LibraryRead( pLibName, 0, 0 );
pLib->pGenlib = Mio_LibraryRead( pLibName, NULL, 0, 0 );
if ( pLib->pGenlib == NULL )
{
printf( "Cannot read GENLIB file \"%s\".\n", pLibName );
......
......@@ -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 )
{
ProgressBar * pProgress;
char pBuffer[5000], pLibFile[5000];
FILE * pFileGen;
char pBuffer[5000];
Map_Super_t * pGate;
char * pTemp = 0, * pLibName;
int nCounter, k, i;
......@@ -126,57 +125,11 @@ int Map_LibraryReadFileTree( Map_SuperLib_t * pLib, FILE * pFile, char *pFileNam
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 );
{
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 )
pLib->pGenlib = Abc_FrameReadLibGen();
if ( pLib->pGenlib == NULL || strcmp( Mio_LibraryReadName(pLib->pGenlib), pLibName ) )
{
printf( "Cannot read GENLIB file \"%s\".\n", pLibFile );
printf( "Supergate library \"%s\" requires the use of Genlib library \"%s\".\n", pFileName, pLibName );
return 0;
}
......
......@@ -129,7 +129,7 @@ extern double Mio_PinReadDelayFanoutFall( Mio_Pin_t * pPin );
extern double Mio_PinReadDelayBlockMax ( Mio_Pin_t * pPin );
extern Mio_Pin_t * Mio_PinReadNext ( Mio_Pin_t * pPin );
/*=== mioRead.c =============================================================*/
extern 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 );
/*=== mioFunc.c =============================================================*/
extern int Mio_LibraryParseFormulas( Mio_Library_t * pLib );
......
......@@ -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_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 Mio_Gate_t * Mio_LibraryReadGate( 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,
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;
int num;
......@@ -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 );
}
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 )
{
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 )
printf ( "Warning: Read extended GENLIB format but ignoring extensions\n" );
}
......@@ -84,7 +99,7 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo
/**Function*************************************************************
Synopsis [Read the genlib type of library.]
Synopsis [Read contents of the file.]
Description []
......@@ -93,25 +108,9 @@ Mio_Library_t * Mio_LibraryRead( char * FileName, char * ExcludeFile, int fVerbo
SeeAlso []
***********************************************************************/
Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_table * tExcludeGate, int fVerbose )
char * Mio_ReadFile( char * FileName )
{
Mio_Library_t * pLib;
char * pBuffer = 0;
// allocate the genlib structure
pLib = ABC_ALLOC( Mio_Library_t, 1 );
memset( pLib, 0, sizeof(Mio_Library_t) );
pLib->pName = Mio_UtilStrsav( FileName );
pLib->tName2Gate = st_init_table(strcmp, st_strhash);
pLib->pMmFlex = Mem_FlexStart();
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
{
char * pBuffer;
FILE * pFile;
int nFileSize;
int RetValue;
......@@ -135,7 +134,30 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_tab
strcat( pBuffer, "\n.end\n" );
// close file
fclose( pFile );
}
return pBuffer;
}
/**Function*************************************************************
Synopsis [Read the genlib type of library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Mio_Library_t * Mio_LibraryReadBuffer( char * pBuffer, int fExtendedFormat, st_table * tExcludeGate, int fVerbose )
{
Mio_Library_t * pLib;
// allocate the genlib structure
pLib = ABC_ALLOC( Mio_Library_t, 1 );
memset( pLib, 0, sizeof(Mio_Library_t) );
pLib->tName2Gate = st_init_table(strcmp, st_strhash);
pLib->pMmFlex = Mem_FlexStart();
pLib->vCube = Vec_StrAlloc( 100 );
Io_ReadFileRemoveComments( pBuffer, NULL, NULL );
......@@ -143,10 +165,8 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_tab
if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, fVerbose ) )
{
Mio_LibraryDelete( pLib );
ABC_FREE( pBuffer );
return NULL;
}
ABC_FREE( pBuffer );
// derive the functinality of gates
if ( Mio_LibraryParseFormulas( pLib ) )
......@@ -173,6 +193,35 @@ Mio_Library_t * Mio_LibraryReadOne( char * FileName, int fExtendedFormat, st_tab
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 )
{
Mio_Gate_t * pGate, ** ppGate;
......@@ -248,12 +297,10 @@ int Mio_LibraryReadInternal( Mio_Library_t * pLib, char * pBuffer, int fExtended
}
pBase->pTwin = pGate;
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 )
{
......
......@@ -267,7 +267,7 @@ int Super_CommandSupergates( Abc_Frame_t * pAbc, int argc, char **argv )
fclose( pFile );
// set the new network
pLib = Mio_LibraryRead( FileName, ExcludeFile, fVerbose );
pLib = Mio_LibraryRead( FileName, NULL, ExcludeFile, fVerbose );
if ( pLib == NULL )
{
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