diff options
Diffstat (limited to 'src/base/io')
-rw-r--r-- | src/base/io/io.c | 25 | ||||
-rw-r--r-- | src/base/io/io.h | 2 | ||||
-rw-r--r-- | src/base/io/ioReadBlifMv.c | 99 | ||||
-rw-r--r-- | src/base/io/ioReadPla.c | 30 | ||||
-rw-r--r-- | src/base/io/ioUtil.c | 2 |
5 files changed, 145 insertions, 13 deletions
diff --git a/src/base/io/io.c b/src/base/io/io.c index fe88a285..628ef2b9 100644 --- a/src/base/io/io.c +++ b/src/base/io/io.c @@ -722,14 +722,19 @@ int IoCommandReadPla( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Ntk_t * pNtk; char * pFileName; int fCheck; + int fZeros; int c; + fZeros = 0; fCheck = 1; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "zch" ) ) != EOF ) { switch ( c ) { + case 'z': + fZeros ^= 1; + break; case 'c': fCheck ^= 1; break; @@ -744,7 +749,20 @@ int IoCommandReadPla( Abc_Frame_t * pAbc, int argc, char ** argv ) // get the input file name pFileName = argv[globalUtilOptind]; // read the file using the corresponding file reader - pNtk = Io_Read( pFileName, IO_FILE_PLA, fCheck ); + if ( fZeros ) + { + Abc_Ntk_t * pTemp; + pNtk = Io_ReadPla( pFileName, fZeros, fCheck ); + if ( pNtk == NULL ) + { + printf( "Reading PLA file has failed.\n" ); + return 1; + } + pNtk = Abc_NtkToLogic( pTemp = pNtk ); + Abc_NtkDelete( pTemp ); + } + else + pNtk = Io_Read( pFileName, IO_FILE_PLA, fCheck ); if ( pNtk == NULL ) return 1; // replace the current network @@ -752,8 +770,9 @@ int IoCommandReadPla( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; usage: - fprintf( pAbc->Err, "usage: read_pla [-ch] <file>\n" ); + fprintf( pAbc->Err, "usage: read_pla [-zch] <file>\n" ); fprintf( pAbc->Err, "\t read the network in PLA\n" ); + fprintf( pAbc->Err, "\t-z : toggle reading on-set and off-set [default = %s]\n", fZeros? "off-set":"on-set" ); fprintf( pAbc->Err, "\t-c : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" ); fprintf( pAbc->Err, "\t-h : prints the command summary\n" ); fprintf( pAbc->Err, "\tfile : the name of a file to read\n" ); diff --git a/src/base/io/io.h b/src/base/io/io.h index 126de332..eea76efe 100644 --- a/src/base/io/io.h +++ b/src/base/io/io.h @@ -83,7 +83,7 @@ extern Abc_Ntk_t * Io_ReadEdif( char * pFileName, int fCheck ); /*=== abcReadEqn.c ============================================================*/ extern Abc_Ntk_t * Io_ReadEqn( char * pFileName, int fCheck ); /*=== abcReadPla.c ============================================================*/ -extern Abc_Ntk_t * Io_ReadPla( char * pFileName, int fCheck ); +extern Abc_Ntk_t * Io_ReadPla( char * pFileName, int fZeros, int fCheck ); /*=== abcReadVerilog.c ========================================================*/ extern Abc_Ntk_t * Io_ReadVerilog( char * pFileName, int fCheck ); /*=== abcWriteAiger.c =========================================================*/ diff --git a/src/base/io/ioReadBlifMv.c b/src/base/io/ioReadBlifMv.c index 8a1fe309..84378024 100644 --- a/src/base/io/ioReadBlifMv.c +++ b/src/base/io/ioReadBlifMv.c @@ -49,6 +49,7 @@ struct Io_MvMod_t_ Vec_Ptr_t * vResets; // .reset lines Vec_Ptr_t * vNames; // .names lines Vec_Ptr_t * vSubckts; // .subckt lines + Vec_Ptr_t * vOnehots; // .onehot lines Vec_Ptr_t * vMvs; // .mv lines int fBlackBox; // indicates blackbox model // the resulting network @@ -97,6 +98,7 @@ static int Io_MvParseLineInputs( Io_MvMod_t * p, char * pLine ); static int Io_MvParseLineOutputs( Io_MvMod_t * p, char * pLine ); static int Io_MvParseLineLatch( Io_MvMod_t * p, char * pLine ); static int Io_MvParseLineSubckt( Io_MvMod_t * p, char * pLine ); +static Vec_Int_t * Io_MvParseLineOnehot( Io_MvMod_t * p, char * pLine ); static int Io_MvParseLineMv( Io_MvMod_t * p, char * pLine ); static int Io_MvParseLineNamesMv( Io_MvMod_t * p, char * pLine, int fReset ); static int Io_MvParseLineNamesBlif( Io_MvMod_t * p, char * pLine ); @@ -295,6 +297,7 @@ static Io_MvMod_t * Io_MvModAlloc() p->vResets = Vec_PtrAlloc( 512 ); p->vNames = Vec_PtrAlloc( 512 ); p->vSubckts = Vec_PtrAlloc( 512 ); + p->vOnehots = Vec_PtrAlloc( 512 ); p->vMvs = Vec_PtrAlloc( 512 ); return p; } @@ -320,6 +323,7 @@ static void Io_MvModFree( Io_MvMod_t * p ) Vec_PtrFree( p->vResets ); Vec_PtrFree( p->vNames ); Vec_PtrFree( p->vSubckts ); + Vec_PtrFree( p->vOnehots ); Vec_PtrFree( p->vMvs ); free( p ); } @@ -597,6 +601,8 @@ static void Io_MvReadPreparse( Io_MvMan_t * p ) Vec_PtrPush( p->pLatest->vOutputs, pCur ); else if ( !strncmp(pCur, "subckt", 6) ) Vec_PtrPush( p->pLatest->vSubckts, pCur ); + else if ( !strncmp(pCur, "onehot", 6) ) + Vec_PtrPush( p->pLatest->vOnehots, pCur ); else if ( p->fBlifMv && !strncmp(pCur, "mv", 2) ) Vec_PtrPush( p->pLatest->vMvs, pCur ); else if ( !strncmp(pCur, "blackbox", 8) ) @@ -743,6 +749,42 @@ static Abc_Lib_t * Io_MvParse( Io_MvMan_t * p ) return NULL; // finalize the network Abc_NtkFinalizeRead( pMod->pNtk ); + // read the one-hotness lines + if ( Vec_PtrSize(pMod->vOnehots) > 0 ) + { + Vec_Int_t * vLine; + Abc_Obj_t * pObj; + // set register numbers + Abc_NtkForEachLatch( pMod->pNtk, pObj, k ) + pObj->pNext = (Abc_Obj_t *)k; + // derive register + pMod->pNtk->vOnehots = Vec_PtrAlloc( Vec_PtrSize(pMod->vOnehots) ); + Vec_PtrForEachEntry( pMod->vOnehots, pLine, k ) + { + vLine = Io_MvParseLineOnehot( pMod, pLine ); + if ( vLine == NULL ) + return NULL; + Vec_PtrPush( pMod->pNtk->vOnehots, vLine ); +// printf( "Parsed %d one-hot registers.\n", Vec_IntSize(vLine) ); + } + // reset register numbers + Abc_NtkForEachLatch( pMod->pNtk, pObj, k ) + pObj->pNext = NULL; + // print the result + printf( "Parsed %d groups of 1-hot registers: { ", Vec_PtrSize(pMod->pNtk->vOnehots) ); + Vec_PtrForEachEntry( pMod->pNtk->vOnehots, vLine, k ) + printf( "%d ", Vec_IntSize(vLine) ); + printf( "}\n" ); + printf( "The total number of 1-hot registers = %d. (%.2f %%)\n", + Vec_VecSizeSize( (Vec_Vec_t *)pMod->pNtk->vOnehots ), + 100.0 * Vec_VecSizeSize( (Vec_Vec_t *)pMod->pNtk->vOnehots ) / Abc_NtkLatchNum(pMod->pNtk) ); + { + extern void Abc_GenOneHotIntervals( char * pFileName, int nPis, int nRegs, Vec_Ptr_t * vOnehots ); + char * pFileName = Extra_FileNameGenericAppend( pMod->pMan->pFileName, "_1h.blif" ); + Abc_GenOneHotIntervals( pFileName, Abc_NtkPiNum(pMod->pNtk), Abc_NtkLatchNum(pMod->pNtk), pMod->pNtk->vOnehots ); + printf( "One-hotness condition is written into file \"%s\".\n", pFileName ); + } + } } if ( p->nNDnodes ) // printf( "Warning: The parser added %d PIs to replace non-deterministic nodes.\n", p->nNDnodes ); @@ -995,6 +1037,63 @@ static int Io_MvParseLineSubckt( Io_MvMod_t * p, char * pLine ) return 1; } +/**Function************************************************************* + + Synopsis [Parses the subckt line.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static Vec_Int_t * Io_MvParseLineOnehot( Io_MvMod_t * p, char * pLine ) +{ + Vec_Ptr_t * vTokens = p->pMan->vTokens; +// Vec_Ptr_t * vResult; + Vec_Int_t * vResult; + Abc_Obj_t * pNet, * pTerm; + char * pToken; + int nEquals, i; + + // split the line into tokens + nEquals = Io_MvCountChars( pLine, '=' ); + Io_MvSplitIntoTokensAndClear( vTokens, pLine, '\0', '=' ); + pToken = Vec_PtrEntry(vTokens,0); + assert( !strcmp(pToken, "onehot") ); + + // iterate through the register names +// vResult = Vec_PtrAlloc( Vec_PtrSize(vTokens) ); + vResult = Vec_IntAlloc( Vec_PtrSize(vTokens) ); + Vec_PtrForEachEntryStart( vTokens, pToken, i, 1 ) + { + // check if this register exists + pNet = Abc_NtkFindNet( p->pNtk, pToken ); + if ( pNet == NULL ) + { + sprintf( p->pMan->sError, "Line %d: Signal with name \"%s\" does not exist in the model \"%s\".", + Io_MvGetLine(p->pMan, pToken), pToken, Abc_NtkName(p->pNtk) ); + return NULL; + } + // check if this is register output net + pTerm = Abc_ObjFanin0( pNet ); + if ( pTerm == NULL || Abc_ObjFanin0(pTerm) == NULL || !Abc_ObjIsLatch(Abc_ObjFanin0(pTerm)) ) + { + sprintf( p->pMan->sError, "Line %d: Signal with name \"%s\" is not a register in the model \"%s\".", + Io_MvGetLine(p->pMan, pToken), pToken, Abc_NtkName(p->pNtk) ); + return NULL; + } + // save register name +// Vec_PtrPush( vResult, Abc_ObjName(pNet) ); + Vec_IntPush( vResult, (int)Abc_ObjFanin0(pTerm)->pNext ); +// printf( "%d(%d) ", (int)Abc_ObjFanin0(pTerm)->pNext, ((int)Abc_ObjFanin0(pTerm)->pData) -1 ); + printf( "%d", ((int)Abc_ObjFanin0(pTerm)->pData)-1 ); + } + printf( "\n" ); + return vResult; +} + /**Function************************************************************* diff --git a/src/base/io/ioReadPla.c b/src/base/io/ioReadPla.c index fdfdb4f6..288c3704 100644 --- a/src/base/io/ioReadPla.c +++ b/src/base/io/ioReadPla.c @@ -24,7 +24,7 @@ /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -static Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p ); +static Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p, int fZeros ); //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// @@ -41,7 +41,7 @@ static Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p ); SeeAlso [] ***********************************************************************/ -Abc_Ntk_t * Io_ReadPla( char * pFileName, int fCheck ) +Abc_Ntk_t * Io_ReadPla( char * pFileName, int fZeros, int fCheck ) { Extra_FileReader_t * p; Abc_Ntk_t * pNtk; @@ -52,7 +52,7 @@ Abc_Ntk_t * Io_ReadPla( char * pFileName, int fCheck ) return NULL; // read the network - pNtk = Io_ReadPlaNetwork( p ); + pNtk = Io_ReadPlaNetwork( p, fZeros ); Extra_FileReaderFree( p ); if ( pNtk == NULL ) return NULL; @@ -77,7 +77,7 @@ Abc_Ntk_t * Io_ReadPla( char * pFileName, int fCheck ) SeeAlso [] ***********************************************************************/ -Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p ) +Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p, int fZeros ) { ProgressBar * pProgress; Vec_Ptr_t * vTokens; @@ -205,12 +205,26 @@ Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p ) Abc_NtkDelete( pNtk ); return NULL; } - for ( i = 0; i < nOutputs; i++ ) + if ( fZeros ) { - if ( pCubeOut[i] == '1' ) + for ( i = 0; i < nOutputs; i++ ) + { + if ( pCubeOut[i] == '0' ) + { + Vec_StrAppend( ppSops[i], pCubeIn ); + Vec_StrAppend( ppSops[i], " 1\n" ); + } + } + } + else + { + for ( i = 0; i < nOutputs; i++ ) { - Vec_StrAppend( ppSops[i], pCubeIn ); - Vec_StrAppend( ppSops[i], " 1\n" ); + if ( pCubeOut[i] == '1' ) + { + Vec_StrAppend( ppSops[i], pCubeIn ); + Vec_StrAppend( ppSops[i], " 1\n" ); + } } } nCubes++; diff --git a/src/base/io/ioUtil.c b/src/base/io/ioUtil.c index 4f9f2e9f..51a00274 100644 --- a/src/base/io/ioUtil.c +++ b/src/base/io/ioUtil.c @@ -134,7 +134,7 @@ Abc_Ntk_t * Io_ReadNetlist( char * pFileName, Io_FileType_t FileType, int fCheck else if ( FileType == IO_FILE_EQN ) pNtk = Io_ReadEqn( pFileName, fCheck ); else if ( FileType == IO_FILE_PLA ) - pNtk = Io_ReadPla( pFileName, fCheck ); + pNtk = Io_ReadPla( pFileName, 0, fCheck ); else if ( FileType == IO_FILE_VERILOG ) pNtk = Io_ReadVerilog( pFileName, fCheck ); else |