From 0871bffae307e0553e0c5186336189e8b55cf6a6 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Sun, 15 Feb 2009 08:01:00 -0800 Subject: Version abc90215 --- src/map/mio/mio.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/map/mio/mio.h | 8 ++--- src/map/mio/mioFunc.c | 8 +++-- src/map/mio/mioRead.c | 22 +++++++------- src/map/mio/mioUtils.c | 34 ++++++++++----------- 5 files changed, 118 insertions(+), 35 deletions(-) (limited to 'src/map/mio') diff --git a/src/map/mio/mio.c b/src/map/mio/mio.c index 1326dbbf..b7dd2895 100644 --- a/src/map/mio/mio.c +++ b/src/map/mio/mio.c @@ -27,6 +27,7 @@ #include "mainInt.h" #include "mioInt.h" #include "mapper.h" +#include "amap.h" extern void Amap_LibFree( void * p ); extern void Amap_LibPrintSelectedGates( void * p, int fAllGates ); @@ -36,6 +37,8 @@ extern void * Amap_LibReadAndPrepare( char * pFileName, int fVerbose, int fVeryV /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// +static int Mio_CommandReadLiberty( 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 ); @@ -106,6 +109,8 @@ void Mio_Init( Abc_Frame_t * pAbc ) unlink( pFileTemp ); #endif + 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", "print_library", Mio_CommandPrintLibrary, 0 ); @@ -132,6 +137,82 @@ void Mio_End() } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv ) +{ + FILE * pFile; + FILE * pOut, * pErr; + Abc_Ntk_t * pNet; + char * FileName; + int fVerbose; + int c; + + pNet = Abc_FrameReadNtk(pAbc); + pOut = Abc_FrameReadOut(pAbc); + pErr = Abc_FrameReadErr(pAbc); + + // set the defaults + fVerbose = 1; + Extra_UtilGetoptReset(); + while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF ) + { + switch (c) + { + case 'v': + fVerbose ^= 1; + break; + case 'h': + goto usage; + break; + default: + goto usage; + } + } + + + if ( argc != globalUtilOptind + 1 ) + { + goto usage; + } + + // get the input file name + FileName = argv[globalUtilOptind]; + if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL ) + { + fprintf( pErr, "Cannot open input file \"%s\". ", FileName ); + if ( (FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) ) + fprintf( pErr, "Did you mean \"%s\"?", FileName ); + fprintf( pErr, "\n" ); + return 1; + } + fclose( pFile ); + + if ( !Amap_LibertyParse( FileName, "temp.genlib", fVerbose ) ) + return 0; + Cmd_CommandExecute( pAbc, "read_library temp.genlib" ); + return 0; + +usage: + fprintf( pErr, "usage: read_liberty [-vh]\n"); + fprintf( pErr, "\t read standard cell library in Liberty format\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-h : enable verbose output\n"); + return 1; /* error exit */ +} + /**Function************************************************************* Synopsis [] diff --git a/src/map/mio/mio.h b/src/map/mio/mio.h index 0e5a39d3..66fea292 100644 --- a/src/map/mio/mio.h +++ b/src/map/mio/mio.h @@ -19,10 +19,6 @@ #ifndef __MIO_H__ #define __MIO_H__ -#ifdef __cplusplus -extern "C" { -#endif - //////////////////////////////////////////////////////////////////////// /// INCLUDES /// //////////////////////////////////////////////////////////////////////// @@ -31,6 +27,10 @@ extern "C" { /// PARAMETERS /// //////////////////////////////////////////////////////////////////////// +#ifdef __cplusplus +extern "C" { +#endif + //////////////////////////////////////////////////////////////////////// /// STRUCTURE DEFINITIONS /// //////////////////////////////////////////////////////////////////////// diff --git a/src/map/mio/mioFunc.c b/src/map/mio/mioFunc.c index 1fca5764..a06151f0 100644 --- a/src/map/mio/mioFunc.c +++ b/src/map/mio/mioFunc.c @@ -144,7 +144,7 @@ int Mio_GateParseFormula( Mio_Gate_t * pGate ) { // get the topmost (generic) pin pPin = pGate->pPins; - FREE( pPin->pName ); + ABC_FREE( pPin->pName ); // create individual pins from the generic pin ppPin = &pPin->pNext; @@ -173,10 +173,10 @@ int Mio_GateParseFormula( Mio_Gate_t * pGate ) { if ( pPinNames[i] && strcmp( pPinNames[i], pPin->pName ) == 0 ) { - // free pPinNames[i] because it is already available as pPin->pName + // ABC_FREE pPinNames[i] because it is already available as pPin->pName // setting pPinNames[i] to NULL is useful to make sure that // this name is not assigned to two pins in the list - FREE( pPinNames[i] ); + ABC_FREE( pPinNames[i] ); pPinNamesCopy[iPin++] = pPin->pName; break; } @@ -212,6 +212,8 @@ int Mio_GateParseFormula( Mio_Gate_t * pGate ) // derive the formula as the BDD pGate->bFunc = Parse_FormulaParser( stdout, pGate->pForm, nPins, 0, pPinNames, dd, dd->vars ); + if ( pGate->bFunc == NULL ) + return 1; Cudd_Ref( pGate->bFunc ); // derive the cover (SOP) diff --git a/src/map/mio/mioRead.c b/src/map/mio/mioRead.c index ae33c942..fdb340aa 100644 --- a/src/map/mio/mioRead.c +++ b/src/map/mio/mioRead.c @@ -94,7 +94,7 @@ Mio_Library_t * Mio_LibraryReadOne( Abc_Frame_t * pAbc, char * FileName, bool fE char * pBuffer = 0; // allocate the genlib structure - pLib = ALLOC( Mio_Library_t, 1 ); + pLib = ABC_ALLOC( Mio_Library_t, 1 ); memset( pLib, 0, sizeof(Mio_Library_t) ); pLib->pName = Extra_UtilStrsav( FileName ); pLib->tName2Gate = st_init_table(strcmp, st_strhash); @@ -122,7 +122,7 @@ Mio_Library_t * Mio_LibraryReadOne( Abc_Frame_t * pAbc, char * FileName, bool fE // move the file current reading position to the beginning rewind( pFile ); // load the contents of the file into memory - pBuffer = ALLOC( char, nFileSize + 10 ); + pBuffer = ABC_ALLOC( char, nFileSize + 10 ); fread( pBuffer, nFileSize, 1, pFile ); // terminate the string with '\0' pBuffer[ nFileSize ] = '\0'; @@ -137,10 +137,10 @@ Mio_Library_t * Mio_LibraryReadOne( Abc_Frame_t * pAbc, char * FileName, bool fE if ( Mio_LibraryReadInternal( pLib, pBuffer, fExtendedFormat, tExcludeGate, fVerbose ) ) { Mio_LibraryDelete( pLib ); - free( pBuffer ); + ABC_FREE( pBuffer ); return NULL; } - free( pBuffer ); + ABC_FREE( pBuffer ); // derive the functinality of gates if ( Mio_LibraryParseFormulas( pLib ) ) @@ -243,7 +243,7 @@ Mio_Gate_t * Mio_LibraryReadGate( char ** ppToken, bool fExtendedFormat ) char * pToken = *ppToken; // allocate the gate structure - pGate = ALLOC( Mio_Gate_t, 1 ); + pGate = ABC_ALLOC( Mio_Gate_t, 1 ); memset( pGate, 0, sizeof(Mio_Gate_t) ); // read the name @@ -311,7 +311,7 @@ Mio_Pin_t * Mio_LibraryReadPin( char ** ppToken, bool fExtendedFormat ) char * pToken = *ppToken; // allocate the gate structure - pPin = ALLOC( Mio_Pin_t, 1 ); + pPin = ABC_ALLOC( Mio_Pin_t, 1 ); memset( pPin, 0, sizeof(Mio_Pin_t) ); // read the name @@ -397,7 +397,7 @@ char * chomp( char *s ) if ( !isspace(*b) ) break; // strsav the string - a = strcpy( ALLOC(char, strlen(b)+1), b ); + a = strcpy( ABC_ALLOC(char, strlen(b)+1), b ); // remove trailing spaces for ( c = a+strlen(a); c > a; c-- ) if ( *c == 0 || isspace(*c) ) @@ -464,12 +464,12 @@ void Mio_LibrarySortGates( Mio_Library_t * pLib ) { Mio_Gate_t ** ppGates, * pGate; int i = 0; - ppGates = ALLOC( Mio_Gate_t *, pLib->nGates ); + ppGates = ABC_ALLOC( Mio_Gate_t *, pLib->nGates ); Mio_LibraryForEachGate( pLib, pGate ) ppGates[i++] = pGate; assert( i == pLib->nGates ); // sort gates by area - pLib->ppGates0 = ALLOC( Mio_Gate_t *, pLib->nGates ); + pLib->ppGates0 = ABC_ALLOC( Mio_Gate_t *, pLib->nGates ); for ( i = 0; i < pLib->nGates; i++ ) pLib->ppGates0[i] = ppGates[i]; qsort( (void *)ppGates, pLib->nGates, sizeof(void *), @@ -477,9 +477,9 @@ void Mio_LibrarySortGates( Mio_Library_t * pLib ) for ( i = 0; i < pLib->nGates; i++ ) ppGates[i]->pNext = (i < pLib->nGates-1)? ppGates[i+1] : NULL; pLib->pGates = ppGates[0]; - free( ppGates ); + ABC_FREE( ppGates ); // sort gates by name - pLib->ppGatesName = ALLOC( Mio_Gate_t *, pLib->nGates ); + pLib->ppGatesName = ABC_ALLOC( Mio_Gate_t *, pLib->nGates ); for ( i = 0; i < pLib->nGates; i++ ) pLib->ppGatesName[i] = pLib->ppGates0[i]; qsort( (void *)pLib->ppGatesName, pLib->nGates, sizeof(void *), diff --git a/src/map/mio/mioUtils.c b/src/map/mio/mioUtils.c index 2a1d1f30..3f42d2bb 100644 --- a/src/map/mio/mioUtils.c +++ b/src/map/mio/mioUtils.c @@ -47,10 +47,10 @@ void Mio_LibraryDelete( Mio_Library_t * pLib ) Mio_Gate_t * pGate, * pGate2; if ( pLib == NULL ) return; - // free the bindings of nodes to gates from this library for all networks + // ABC_FREE the bindings of nodes to gates from this library for all networks Abc_FrameUnmapAllNetworks( Abc_FrameGetGlobalFrame() ); - // free the library - FREE( pLib->pName ); + // ABC_FREE the library + ABC_FREE( pLib->pName ); Mio_LibraryForEachGateSafe( pLib, pGate, pGate2 ) Mio_GateDelete( pGate ); Extra_MmFlexStop( pLib->pMmFlex ); @@ -59,9 +59,9 @@ void Mio_LibraryDelete( Mio_Library_t * pLib ) st_free_table( pLib->tName2Gate ); if ( pLib->dd ) Cudd_Quit( pLib->dd ); - FREE( pLib->ppGates0 ); - FREE( pLib->ppGatesName ); - free( pLib ); + ABC_FREE( pLib->ppGates0 ); + ABC_FREE( pLib->ppGatesName ); + ABC_FREE( pLib ); } /**Function************************************************************* @@ -78,14 +78,14 @@ void Mio_LibraryDelete( Mio_Library_t * pLib ) void Mio_GateDelete( Mio_Gate_t * pGate ) { Mio_Pin_t * pPin, * pPin2; - FREE( pGate->pOutName ); - FREE( pGate->pName ); - FREE( pGate->pForm ); + ABC_FREE( pGate->pOutName ); + ABC_FREE( pGate->pName ); + ABC_FREE( pGate->pForm ); if ( pGate->bFunc ) Cudd_RecursiveDeref( pGate->pLib->dd, pGate->bFunc ); Mio_GateForEachPinSafe( pGate, pPin, pPin2 ) Mio_PinDelete( pPin ); - free( pGate ); + ABC_FREE( pGate ); } /**Function************************************************************* @@ -101,8 +101,8 @@ void Mio_GateDelete( Mio_Gate_t * pGate ) ***********************************************************************/ void Mio_PinDelete( Mio_Pin_t * pPin ) { - FREE( pPin->pName ); - free( pPin ); + ABC_FREE( pPin->pName ); + ABC_FREE( pPin ); } /**Function************************************************************* @@ -120,7 +120,7 @@ Mio_Pin_t * Mio_PinDup( Mio_Pin_t * pPin ) { Mio_Pin_t * pPinNew; - pPinNew = ALLOC( Mio_Pin_t, 1 ); + pPinNew = ABC_ALLOC( Mio_Pin_t, 1 ); *pPinNew = *pPin; pPinNew->pName = (pPinNew->pName ? Extra_UtilStrsav(pPinNew->pName) : NULL); pPinNew->pNext = NULL; @@ -256,7 +256,7 @@ Mio_Gate_t ** Mio_CollectRoots( Mio_Library_t * pLib, int nInputs, float tDelay, } // collect the gates into the array - ppGates = ALLOC( Mio_Gate_t *, nGates ); + ppGates = ABC_ALLOC( Mio_Gate_t *, nGates ); iGate = 0; st_foreach_item( tFuncs, gen, (char **)&bFunc, (char **)&pGate ) ppGates[ iGate++ ] = pGate; @@ -265,7 +265,7 @@ Mio_Gate_t ** Mio_CollectRoots( Mio_Library_t * pLib, int nInputs, float tDelay, */ - ppGates = ALLOC( Mio_Gate_t *, nGates ); + ppGates = ABC_ALLOC( Mio_Gate_t *, nGates ); iGate = 0; Mio_LibraryForEachGate( pLib, pGate ) { @@ -515,13 +515,13 @@ Mio_Gate_t * Mio_GateCreatePseudo( int nInputs ) Mio_Pin_t * pPin; int i; // allocate the gate structure - pGate = ALLOC( Mio_Gate_t, 1 ); + pGate = ABC_ALLOC( Mio_Gate_t, 1 ); memset( pGate, 0, sizeof(Mio_Gate_t) ); pGate->nInputs = nInputs; // create pins for ( i = 0; i < nInputs; i++ ) { - pPin = ALLOC( Mio_Pin_t, 1 ); + pPin = ABC_ALLOC( Mio_Pin_t, 1 ); memset( pPin, 0, sizeof(Mio_Pin_t) ); pPin->pNext = pGate->pPins; pGate->pPins = pPin; -- cgit v1.2.3