summaryrefslogtreecommitdiffstats
path: root/src/map/amap
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/amap')
-rw-r--r--src/map/amap/amap.h4
-rw-r--r--src/map/amap/amapInt.h1
-rw-r--r--src/map/amap/amapLib.c12
-rw-r--r--src/map/amap/amapLiberty.c144
-rw-r--r--src/map/amap/amapRead.c31
5 files changed, 183 insertions, 9 deletions
diff --git a/src/map/amap/amap.h b/src/map/amap/amap.h
index b4c8b574..03e9ce44 100644
--- a/src/map/amap/amap.h
+++ b/src/map/amap/amap.h
@@ -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
diff --git a/src/map/amap/amapInt.h b/src/map/amap/amapInt.h
index 7a9bef7a..b28ea7e7 100644
--- a/src/map/amap/amapInt.h
+++ b/src/map/amap/amapInt.h
@@ -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 );
diff --git a/src/map/amap/amapLib.c b/src/map/amap/amapLib.c
index 002386ad..de02c872 100644
--- a/src/map/amap/amapLib.c
+++ b/src/map/amap/amapLib.c
@@ -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();
- 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 )
printf( "Read %d gates from file \"%s\".\n", Vec_PtrSize(p->vGates), pFileName );
if ( p == NULL )
diff --git a/src/map/amap/amapLiberty.c b/src/map/amap/amapLiberty.c
index 20624882..941abe50 100644
--- a/src/map/amap/amapLiberty.c
+++ b/src/map/amap/amapLiberty.c
@@ -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 ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/map/amap/amapRead.c b/src/map/amap/amapRead.c
index e8206e31..8ea3c9c0 100644
--- a/src/map/amap/amapRead.c
+++ b/src/map/amap/amapRead.c
@@ -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;
}