diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2014-04-26 23:47:54 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2014-04-26 23:47:54 -0700 |
commit | 6095b1517488139c4d6b94507bc230cf4588ffd3 (patch) | |
tree | de04e416f7287a2e97e0597761d0f589e0741e2d /src | |
parent | 6e465e57fe8fb098b8a0fc6286d45a444655775f (diff) | |
download | abc-6095b1517488139c4d6b94507bc230cf4588ffd3.tar.gz abc-6095b1517488139c4d6b94507bc230cf4588ffd3.tar.bz2 abc-6095b1517488139c4d6b94507bc230cf4588ffd3.zip |
Added dumping original object names into a file.
Diffstat (limited to 'src')
-rw-r--r-- | src/base/abc/abc.h | 5 | ||||
-rw-r--r-- | src/base/abc/abcNames.c | 134 | ||||
-rw-r--r-- | src/base/abc/abcNtk.c | 1 | ||||
-rw-r--r-- | src/base/abci/abcStrash.c | 8 | ||||
-rw-r--r-- | src/base/io/io.c | 14 |
5 files changed, 159 insertions, 3 deletions
diff --git a/src/base/abc/abc.h b/src/base/abc/abc.h index 762136ba..12a2024a 100644 --- a/src/base/abc/abc.h +++ b/src/base/abc/abc.h @@ -210,8 +210,8 @@ struct Abc_Ntk_t_ Vec_Ptr_t * vOnehots; // names of one-hot-encoded registers Vec_Int_t * vObjPerm; // permutation saved Vec_Int_t * vTopo; - // node attributes Vec_Ptr_t * vAttrs; // managers of various node attributes (node functionality, global BDDs, etc) + Vec_Int_t * vNameIds; // name IDs }; struct Abc_Des_t_ @@ -717,6 +717,9 @@ extern ABC_DLL void Abc_NtkAddDummyPiNames( Abc_Ntk_t * pNtk ); extern ABC_DLL void Abc_NtkAddDummyPoNames( Abc_Ntk_t * pNtk ); extern ABC_DLL void Abc_NtkAddDummyBoxNames( Abc_Ntk_t * pNtk ); extern ABC_DLL void Abc_NtkShortNames( Abc_Ntk_t * pNtk ); +extern ABC_DLL void Abc_NtkStartNameIds( Abc_Ntk_t * p ); +extern ABC_DLL void Abc_NtkTransferNameIds( Abc_Ntk_t * p, Abc_Ntk_t * pNew ); +extern ABC_DLL void Abc_NtkUpdateNameIds( Abc_Ntk_t * p ); /*=== abcNetlist.c ==========================================================*/ extern ABC_DLL Abc_Ntk_t * Abc_NtkToLogic( Abc_Ntk_t * pNtk ); extern ABC_DLL Abc_Ntk_t * Abc_NtkToNetlist( Abc_Ntk_t * pNtk ); diff --git a/src/base/abc/abcNames.c b/src/base/abc/abcNames.c index ab33c91a..87ae3717 100644 --- a/src/base/abc/abcNames.c +++ b/src/base/abc/abcNames.c @@ -496,6 +496,140 @@ void Abc_NtkShortNames( Abc_Ntk_t * pNtk ) Abc_NtkAddDummyBoxNames( pNtk ); } + +/**Function************************************************************* + + Synopsis [Saves name IDs into a file.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_NtkStartNameIds( Abc_Ntk_t * p ) +{ + char pFileName[1000]; + FILE * pFile; + Abc_Obj_t * pObj, * pFanin; + Vec_Ptr_t * vNodes; + int i, Counter = 1; + assert( Abc_NtkIsNetlist(p) ); + assert( p->vNameIds == NULL ); + assert( strlen(p->pSpec) < 1000 ); + sprintf( pFileName, "%s_%s_names.txt", Extra_FileNameGenericAppend(p->pSpec,""), Extra_FileNameExtension(p->pSpec) ); + pFile = fopen( pFileName, "wb" ); + p->vNameIds = Vec_IntStart( Abc_NtkObjNumMax(p) ); + // add inputs + Abc_NtkForEachCi( p, pObj, i ) + fprintf( pFile, "%s \n", Abc_ObjName(Abc_ObjFanout0(pObj)) ), Vec_IntWriteEntry(p->vNameIds, Abc_ObjId(pObj), 2*Counter++); + // add outputs + Abc_NtkForEachCo( p, pObj, i ) + { + pFanin = Abc_ObjFanin0(Abc_ObjFanin0(pObj)); + if ( !Vec_IntEntry(p->vNameIds, Abc_ObjId(pFanin)) ) + fprintf( pFile, "%s \n", Abc_ObjName(Abc_ObjFanout0(pFanin)) ), Vec_IntWriteEntry(p->vNameIds, Abc_ObjId(pFanin), 2*Counter++); + } + // add nodes in a topo order + vNodes = Abc_NtkDfs( p, 1 ); + Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i ) + if ( !Vec_IntEntry(p->vNameIds, Abc_ObjId(pObj)) ) + fprintf( pFile, "%s \n", Abc_ObjName(Abc_ObjFanout0(pObj)) ), Vec_IntWriteEntry(p->vNameIds, Abc_ObjId(pObj), 2*Counter++); + Vec_PtrFree( vNodes ); + fclose( pFile ); + // transfer driver node names to COs + Abc_NtkForEachCo( p, pObj, i ) + { + pFanin = Abc_ObjFanin0(Abc_ObjFanin0(pObj)); + Vec_IntWriteEntry( p->vNameIds, Abc_ObjId(pObj), Vec_IntEntry(p->vNameIds, Abc_ObjId(pFanin)) ); + Vec_IntWriteEntry( p->vNameIds, Abc_ObjId(pFanin), 0 ); + } +} + +/**Function************************************************************* + + Synopsis [Remaps the AIG from the old manager into the new manager.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_NtkTransferNameIds( Abc_Ntk_t * p, Abc_Ntk_t * pNew ) +{ + Abc_Obj_t * pObj, * pObjNew; + int i; + assert( p->vNameIds != NULL ); + assert( pNew->vNameIds == NULL ); + pNew->vNameIds = Vec_IntStart( Abc_NtkObjNumMax(pNew) ); +// Abc_NtkForEachCi( p, pObj, i ) +// printf( "%d ", Vec_IntEntry(p->vNameIds, Abc_ObjId(pObj)) ); +// printf( "\n" ); + Abc_NtkForEachObj( p, pObj, i ) + if ( pObj->pCopy && Vec_IntEntry(p->vNameIds, i) ) + { + pObjNew = Abc_ObjRegular(pObj->pCopy); + assert( Abc_ObjNtk(pObjNew) == pNew ); + if ( Abc_ObjIsCi(pObjNew) && !Abc_ObjIsCi(pObj) ) // do not overwrite CI name by internal node name + continue; + Vec_IntWriteEntry( pNew->vNameIds, Abc_ObjId(pObjNew), Vec_IntEntry(p->vNameIds, i) ^ Abc_ObjIsComplement(pObj->pCopy) ); + } +} + +/**Function************************************************************* + + Synopsis [Updates file with name IDs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_NtkUpdateNameIds( Abc_Ntk_t * p ) +{ + char pFileName[1000]; + Vec_Int_t * vStarts; + Abc_Obj_t * pObj; + FILE * pFile; + int i, c, iVar, fCompl, fSeenSpace, Counter = 0; + assert( !Abc_NtkIsNetlist(p) ); + assert( strlen(p->pSpec) < 1000 ); + assert( p->vNameIds != NULL ); + sprintf( pFileName, "%s_%s_names.txt", Extra_FileNameGenericAppend(p->pSpec,""), Extra_FileNameExtension(p->pSpec) ); + pFile = fopen( pFileName, "r+" ); + // collect info about lines + fSeenSpace = 0; + vStarts = Vec_IntAlloc( 1000 ); + Vec_IntPush( vStarts, -1 ); + while ( (c = fgetc(pFile)) != EOF && ++Counter ) + if ( c == ' ' && !fSeenSpace ) + Vec_IntPush(vStarts, Counter), fSeenSpace = 1; + else if ( c == '\n' ) + fSeenSpace = 0; + // add info about names + Abc_NtkForEachObj( p, pObj, i ) + { + if ( !Vec_IntEntry(p->vNameIds, i) ) + continue; + iVar = Abc_Lit2Var( Vec_IntEntry(p->vNameIds, i) ); + fCompl = Abc_LitIsCompl( Vec_IntEntry(p->vNameIds, i) ); + assert( iVar < Vec_IntSize(vStarts) ); + fseek( pFile, Vec_IntEntry(vStarts, iVar), SEEK_SET ); + fprintf( pFile, "%s%d", fCompl? "-":"", i ); + } + printf( "Saved %d names into file \"%s\".\n", Vec_IntSize(vStarts)-1, pFileName ); + fclose( pFile ); + Vec_IntFree( vStarts ); + Vec_IntFreeP( &p->vNameIds ); +// Abc_NtkForEachObj( p, pObj, i ) +// Abc_ObjPrint( stdout, pObj ); +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/abc/abcNtk.c b/src/base/abc/abcNtk.c index 8012d3a7..fb3b179b 100644 --- a/src/base/abc/abcNtk.c +++ b/src/base/abc/abcNtk.c @@ -1331,6 +1331,7 @@ void Abc_NtkDelete( Abc_Ntk_t * pNtk ) assert( pNtk->pSCLib == NULL ); Vec_IntFreeP( &pNtk->vGates ); Vec_PtrFree( pNtk->vAttrs ); + Vec_IntFreeP( &pNtk->vNameIds ); ABC_FREE( pNtk->pWLoadUsed ); ABC_FREE( pNtk->pName ); ABC_FREE( pNtk->pSpec ); diff --git a/src/base/abci/abcStrash.c b/src/base/abci/abcStrash.c index d428af38..a3d87323 100644 --- a/src/base/abci/abcStrash.c +++ b/src/base/abci/abcStrash.c @@ -232,6 +232,11 @@ Abc_Ntk_t * Abc_NtkRestrashZero( Abc_Ntk_t * pNtk, int fCleanup ) // duplicate EXDC if ( pNtk->pExdc ) pNtkAig->pExdc = Abc_NtkDup( pNtk->pExdc ); + // transfer name IDs + if ( pNtk->vNameIds ) + Abc_NtkTransferNameIds( pNtk, pNtkAig ); + if ( pNtk->vNameIds ) + Abc_NtkUpdateNameIds( pNtkAig ); // make sure everything is okay if ( !Abc_NtkCheck( pNtkAig ) ) { @@ -276,6 +281,9 @@ Abc_Ntk_t * Abc_NtkStrash( Abc_Ntk_t * pNtk, int fAllNodes, int fCleanup, int fR pNtkAig = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG ); Abc_NtkStrashPerform( pNtk, pNtkAig, fAllNodes, fRecord ); Abc_NtkFinalize( pNtk, pNtkAig ); + // transfer name IDs + if ( pNtk->vNameIds ) + Abc_NtkTransferNameIds( pNtk, pNtkAig ); // print warning about self-feed latches // if ( Abc_NtkCountSelfFeedLatches(pNtkAig) ) // printf( "Warning: The network has %d self-feeding latches.\n", Abc_NtkCountSelfFeedLatches(pNtkAig) ); diff --git a/src/base/io/io.c b/src/base/io/io.c index 68a4ade1..4308b243 100644 --- a/src/base/io/io.c +++ b/src/base/io/io.c @@ -440,20 +440,25 @@ int IoCommandReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv ) int fReadAsAig; int fCheck; int fUseNewParser; + int fSaveNames; int c; extern Abc_Ntk_t * Io_ReadBlifAsAig( char * pFileName, int fCheck ); fCheck = 1; fReadAsAig = 0; fUseNewParser = 1; + fSaveNames = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "nach" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "nmach" ) ) != EOF ) { switch ( c ) { case 'n': fUseNewParser ^= 1; break; + case 'm': + fSaveNames ^= 1; + break; case 'a': fReadAsAig ^= 1; break; @@ -481,7 +486,11 @@ int IoCommandReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv ) pNtk = Io_ReadBlif( pFileName, fCheck ); if ( pNtk == NULL ) return 1; + if ( fSaveNames ) + Abc_NtkStartNameIds( pNtk ); pNtk = Abc_NtkToLogic( pTemp = pNtk ); + if ( fSaveNames ) + Abc_NtkTransferNameIds( pTemp, pNtk ); Abc_NtkDelete( pTemp ); } @@ -493,10 +502,11 @@ int IoCommandReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; usage: - fprintf( pAbc->Err, "usage: read_blif [-nach] <file>\n" ); + fprintf( pAbc->Err, "usage: read_blif [-nmach] <file>\n" ); fprintf( pAbc->Err, "\t reads the network in binary BLIF format\n" ); fprintf( pAbc->Err, "\t (if this command does not work, try \"read\")\n" ); fprintf( pAbc->Err, "\t-n : toggle using old BLIF parser without hierarchy support [default = %s]\n", !fUseNewParser? "yes":"no" ); + fprintf( pAbc->Err, "\t-m : toggle saving original circuit names into a file [default = %s]\n", fSaveNames? "yes":"no" ); fprintf( pAbc->Err, "\t-a : toggle creating AIG while reading the file [default = %s]\n", fReadAsAig? "yes":"no" ); 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" ); |