Commit 6095b151 by Alan Mishchenko

Added dumping original object names into a file.

parent 6e465e57
......@@ -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 );
......
......@@ -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 ///
////////////////////////////////////////////////////////////////////////
......
......@@ -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 );
......
......@@ -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) );
......
......@@ -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" );
......
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