Skip to content

Commit

Permalink
Adding visualization of global BDDs in 'show_bdd'.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanminko committed Sep 27, 2018
1 parent 563f4a8 commit 5528d1b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 9 deletions.
52 changes: 52 additions & 0 deletions src/base/abc/abcShow.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,61 @@ void Abc_NodeShowBdd( Abc_Obj_t * pNode )
// visualize the file
Abc_ShowFile( FileNameDot );
}
void Abc_NtkShowBdd( Abc_Ntk_t * pNtk )
{
char FileNameDot[200];
char ** ppNamesIn, ** ppNamesOut;
DdManager * dd; DdNode * bFunc;
Vec_Ptr_t * vFuncsGlob;
Abc_Obj_t * pObj; int i;
FILE * pFile;

assert( Abc_NtkIsStrash(pNtk) );
dd = (DdManager *)Abc_NtkBuildGlobalBdds( pNtk, 10000000, 1, 1, 0, 0 );
if ( dd == NULL )
{
printf( "Construction of global BDDs has failed.\n" );
return;
}
//printf( "Shared BDD size = %6d nodes.\n", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );

// complement the global functions
vFuncsGlob = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) );
Abc_NtkForEachCo( pNtk, pObj, i )
Vec_PtrPush( vFuncsGlob, Abc_ObjGlobalBdd(pObj) );

// create the file name
Abc_ShowGetFileName( pNtk->pName, FileNameDot );
// check that the file can be opened
if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
{
fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
return;
}

// set the node names
ppNamesIn = Abc_NtkCollectCioNames( pNtk, 0 );
ppNamesOut = Abc_NtkCollectCioNames( pNtk, 1 );
Cudd_DumpDot( dd, Abc_NtkCoNum(pNtk), (DdNode **)Vec_PtrArray(vFuncsGlob), ppNamesIn, ppNamesOut, pFile );
ABC_FREE( ppNamesIn );
ABC_FREE( ppNamesOut );
fclose( pFile );

// cleanup
Abc_NtkFreeGlobalBdds( pNtk, 0 );
Vec_PtrForEachEntry( DdNode *, vFuncsGlob, bFunc, i )
Cudd_RecursiveDeref( dd, bFunc );
Vec_PtrFree( vFuncsGlob );
Extra_StopManager( dd );
Abc_NtkCleanCopy( pNtk );

// visualize the file
Abc_ShowFile( FileNameDot );
}

#else
void Abc_NodeShowBdd( Abc_Obj_t * pNode ) {}
void Abc_NtkShowBdd( Abc_Ntk_t * pNtk ) {}
#endif

/**Function*************************************************************
Expand Down
38 changes: 29 additions & 9 deletions src/base/abci/abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3061,15 +3061,19 @@ int Abc_CommandShowBdd( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
Abc_Obj_t * pNode;
int c;
int c, fGlobal = 0;
extern void Abc_NodeShowBdd( Abc_Obj_t * pNode );
extern void Abc_NtkShowBdd( Abc_Ntk_t * pNtk );

// set defaults
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "gh" ) ) != EOF )
{
switch ( c )
{
case 'g':
fGlobal ^= 1;
break;
case 'h':
goto usage;
default:
Expand All @@ -3083,10 +3087,21 @@ int Abc_CommandShowBdd( Abc_Frame_t * pAbc, int argc, char ** argv )
return 1;
}

if ( !Abc_NtkIsBddLogic(pNtk) )
if ( fGlobal )
{
Abc_Print( -1, "Visualizing BDDs can only be done for logic BDD networks (run \"bdd\").\n" );
return 1;
if ( !Abc_NtkIsStrash(pNtk) )
{
Abc_Print( -1, "Visualizing BDDs can only be done for AIGs (run \"strash\").\n" );
return 1;
}
}
else
{
if ( !Abc_NtkIsBddLogic(pNtk) )
{
Abc_Print( -1, "Visualizing BDDs can only be done for logic BDD networks (run \"bdd\").\n" );
return 1;
}
}

if ( argc > globalUtilOptind + 1 )
Expand All @@ -3112,17 +3127,22 @@ int Abc_CommandShowBdd( Abc_Frame_t * pAbc, int argc, char ** argv )
return 1;
}
}
Abc_NodeShowBdd( pNode );
if ( fGlobal )
Abc_NtkShowBdd( pNtk );
else
Abc_NodeShowBdd( pNode );
return 0;

usage:
Abc_Print( -2, "usage: show_bdd [-h] <node>\n" );
Abc_Print( -2, " visualizes the BDD of a node using DOT and GSVIEW\n" );
Abc_Print( -2, "usage: show_bdd [-gh] <node>\n" );
Abc_Print( -2, " uses DOT and GSVIEW to visualize the global BDDs of primary outputs\n" );
Abc_Print( -2, " in terms of primary inputs or the local BDD of a node in terms of its fanins\n" );
#ifdef WIN32
Abc_Print( -2, " \"dot.exe\" and \"gsview32.exe\" should be set in the paths\n" );
Abc_Print( -2, " (\"gsview32.exe\" may be in \"C:\\Program Files\\Ghostgum\\gsview\\\")\n" );
#endif
Abc_Print( -2, "\t<node>: the node to consider [default = the driver of the first PO]\n");
Abc_Print( -2, "\t<node>: (optional) the node to consider [default = the driver of the first PO]\n");
Abc_Print( -2, "\t-g : toggle visualizing the global BDDs of primary outputs [default = %s].\n", fGlobal? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
Expand Down

0 comments on commit 5528d1b

Please sign in to comment.