From 5528d1b17c358d8535ee2e6450a4fd4404bb54b5 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Thu, 27 Sep 2018 14:11:31 -0700 Subject: Adding visualization of global BDDs in 'show_bdd'. --- src/base/abc/abcShow.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/base/abci/abc.c | 38 +++++++++++++++++++++++++++--------- 2 files changed, 81 insertions(+), 9 deletions(-) (limited to 'src/base') diff --git a/src/base/abc/abcShow.c b/src/base/abc/abcShow.c index 13dd9346..e7badb12 100644 --- a/src/base/abc/abcShow.c +++ b/src/base/abc/abcShow.c @@ -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************************************************************* diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 1484d5cc..069f771a 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -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: @@ -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 ) @@ -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] \n" ); - Abc_Print( -2, " visualizes the BDD of a node using DOT and GSVIEW\n" ); + Abc_Print( -2, "usage: show_bdd [-gh] \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: the node to consider [default = the driver of the first PO]\n"); + Abc_Print( -2, "\t: (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; } -- cgit v1.2.3