00001
00021 #include "mainInt.h"
00022 #include "abc.h"
00023 #include "dec.h"
00024
00028
00029 static Abc_Frame_t * s_GlobalFrame = NULL;
00030
00034
00046 Vec_Ptr_t * Abc_FrameReadStore() { return s_GlobalFrame->vStore; }
00047 int Abc_FrameReadStoreSize() { return Vec_PtrSize(s_GlobalFrame->vStore); }
00048 void * Abc_FrameReadLibLut() { return s_GlobalFrame->pLibLut; }
00049 void * Abc_FrameReadLibGen() { return s_GlobalFrame->pLibGen; }
00050 void * Abc_FrameReadLibSuper() { return s_GlobalFrame->pLibSuper; }
00051 void * Abc_FrameReadLibVer() { return s_GlobalFrame->pLibVer; }
00052 void * Abc_FrameReadManDd() { if ( s_GlobalFrame->dd == NULL ) s_GlobalFrame->dd = Cudd_Init( 0, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 ); return s_GlobalFrame->dd; }
00053 void * Abc_FrameReadManDec() { if ( s_GlobalFrame->pManDec == NULL ) s_GlobalFrame->pManDec = Dec_ManStart(); return s_GlobalFrame->pManDec; }
00054 char * Abc_FrameReadFlag( char * pFlag ) { return Cmd_FlagReadByName( s_GlobalFrame, pFlag ); }
00055
00056 void Abc_FrameSetLibLut( void * pLib ) { s_GlobalFrame->pLibLut = pLib; }
00057 void Abc_FrameSetLibGen( void * pLib ) { s_GlobalFrame->pLibGen = pLib; }
00058 void Abc_FrameSetLibSuper( void * pLib ) { s_GlobalFrame->pLibSuper = pLib; }
00059 void Abc_FrameSetLibVer( void * pLib ) { s_GlobalFrame->pLibVer = pLib; }
00060 void Abc_FrameSetFlag( char * pFlag, char * pValue ) { Cmd_FlagUpdateValue( s_GlobalFrame, pFlag, pValue ); }
00061
00073 bool Abc_FrameIsFlagEnabled( char * pFlag )
00074 {
00075 char * pValue;
00076
00077 pValue = Abc_FrameReadFlag( pFlag );
00078 if ( pValue == NULL )
00079 return 0;
00080
00081 if ( strcmp(pValue, "") && strcmp(pValue, "1") )
00082 return 0;
00083 return 1;
00084 }
00085
00097 Abc_Frame_t * Abc_FrameAllocate()
00098 {
00099 Abc_Frame_t * p;
00100 extern void define_cube_size( int n );
00101 extern void set_espresso_flags();
00102
00103 p = ALLOC( Abc_Frame_t, 1 );
00104 memset( p, 0, sizeof(Abc_Frame_t) );
00105
00106 p->sVersion = Abc_UtilsGetVersion( p );
00107
00108 p->Err = stderr;
00109 p->Out = stdout;
00110 p->Hst = NULL;
00111
00112 p->nSteps = 1;
00113 p->fBatchMode = 0;
00114
00115 p->vStore = Vec_PtrAlloc( 16 );
00116
00117 define_cube_size(20);
00118 set_espresso_flags();
00119
00120
00121 return p;
00122 }
00123
00124
00136 void Abc_FrameDeallocate( Abc_Frame_t * p )
00137 {
00138 extern void Rwt_ManGlobalStop();
00139 extern void undefine_cube_size();
00140
00141
00142 undefine_cube_size();
00143 Rwt_ManGlobalStop();
00144
00145 if ( p->pLibVer ) Abc_LibFree( p->pLibVer, NULL );
00146 if ( p->pManDec ) Dec_ManStop( p->pManDec );
00147 if ( p->dd ) Extra_StopManager( p->dd );
00148 if ( p->vStore ) Vec_PtrFree( p->vStore );
00149 Abc_FrameDeleteAllNetworks( p );
00150 free( p );
00151 s_GlobalFrame = NULL;
00152 }
00153
00165 void Abc_FrameRestart( Abc_Frame_t * p )
00166 {
00167 }
00168
00180 bool Abc_FrameShowProgress( Abc_Frame_t * p )
00181 {
00182 return Abc_FrameIsFlagEnabled( "progressbar" );
00183 }
00184
00185
00197 Abc_Ntk_t * Abc_FrameReadNtk( Abc_Frame_t * p )
00198 {
00199 return p->pNtkCur;
00200 }
00201
00213 FILE * Abc_FrameReadOut( Abc_Frame_t * p )
00214 {
00215 return p->Out;
00216 }
00217
00229 FILE * Abc_FrameReadErr( Abc_Frame_t * p )
00230 {
00231 return p->Err;
00232 }
00233
00245 int Abc_FrameReadMode( Abc_Frame_t * p )
00246 {
00247 int fShortNames;
00248 char * pValue;
00249 pValue = Cmd_FlagReadByName( p, "namemode" );
00250 if ( pValue == NULL )
00251 fShortNames = 0;
00252 else
00253 fShortNames = atoi(pValue);
00254 return fShortNames;
00255 }
00256
00268 bool Abc_FrameSetMode( Abc_Frame_t * p, bool fNameMode )
00269 {
00270 char Buffer[2];
00271 bool fNameModeOld;
00272 fNameModeOld = Abc_FrameReadMode( p );
00273 Buffer[0] = '0' + fNameMode;
00274 Buffer[1] = 0;
00275 Cmd_FlagUpdateValue( p, "namemode", (char *)Buffer );
00276 return fNameModeOld;
00277 }
00278
00279
00295 void Abc_FrameSetCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNtkNew )
00296 {
00297 Abc_Ntk_t * pNtk, * pNtk2, * pNtk3;
00298 int nNetsPresent;
00299 int nNetsToSave;
00300 char * pValue;
00301
00302
00303 Abc_NtkSetBackup( pNtkNew, p->pNtkCur );
00304
00305 Abc_NtkSetStep( pNtkNew, ++p->nSteps );
00306
00307 p->pNtkCur = pNtkNew;
00308
00309
00310 pValue = Cmd_FlagReadByName( p, "savesteps" );
00311
00312 if ( pValue == NULL )
00313 nNetsToSave = 1;
00314 else
00315 nNetsToSave = atoi(pValue);
00316
00317
00318 nNetsPresent = 0;
00319 pNtk2 = pNtk3 = NULL;
00320 for ( pNtk = p->pNtkCur; pNtk; pNtk = Abc_NtkBackup(pNtk2) )
00321 {
00322 nNetsPresent++;
00323 pNtk3 = pNtk2;
00324 pNtk2 = pNtk;
00325 }
00326
00327
00328 if ( nNetsPresent - 1 > nNetsToSave )
00329 {
00330 Abc_NtkDelete( pNtk2 );
00331
00332 Abc_NtkSetBackup( pNtk3, NULL );
00333 }
00334 }
00335
00347 void Abc_FrameSwapCurrentAndBackup( Abc_Frame_t * p )
00348 {
00349 Abc_Ntk_t * pNtkCur, * pNtkBack, * pNtkBack2;
00350 int iStepCur, iStepBack;
00351
00352 pNtkCur = p->pNtkCur;
00353 pNtkBack = Abc_NtkBackup( pNtkCur );
00354 iStepCur = Abc_NtkStep ( pNtkCur );
00355
00356
00357 if ( pNtkBack == NULL )
00358 return;
00359
00360
00361 pNtkBack2 = Abc_NtkBackup( pNtkBack );
00362 iStepBack = Abc_NtkStep ( pNtkBack );
00363
00364
00365 Abc_NtkSetBackup( pNtkCur, pNtkBack2 );
00366 Abc_NtkSetStep ( pNtkCur, iStepBack );
00367
00368
00369 Abc_NtkSetBackup( pNtkBack, pNtkCur );
00370 Abc_NtkSetStep ( pNtkBack, iStepCur );
00371
00372
00373 p->pNtkCur = pNtkBack;
00374 }
00375
00376
00389 void Abc_FrameReplaceCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNtk )
00390 {
00391 if ( pNtk == NULL )
00392 return;
00393
00394
00395 if ( p->pNtkCur && Abc_FrameIsFlagEnabled( "backup" ) )
00396 {
00397 Abc_NtkSetBackup( pNtk, Abc_NtkBackup(p->pNtkCur) );
00398 Abc_NtkSetStep( pNtk, Abc_NtkStep(p->pNtkCur) );
00399
00400 Abc_NtkDelete( p->pNtkCur );
00401 }
00402 else
00403 {
00404 Abc_NtkSetBackup( pNtk, NULL );
00405 Abc_NtkSetStep( pNtk, ++p->nSteps );
00406
00407 if ( p->pNtkCur )
00408 Abc_NtkDelete( p->pNtkCur );
00409 }
00410
00411 p->pNtkCur = pNtk;
00412 }
00413
00425 void Abc_FrameUnmapAllNetworks( Abc_Frame_t * p )
00426 {
00427 Abc_Ntk_t * pNtk;
00428 for ( pNtk = p->pNtkCur; pNtk; pNtk = Abc_NtkBackup(pNtk) )
00429 if ( Abc_NtkHasMapping(pNtk) )
00430 Abc_NtkMapToSop( pNtk );
00431 }
00432
00444 void Abc_FrameDeleteAllNetworks( Abc_Frame_t * p )
00445 {
00446 Abc_Ntk_t * pNtk, * pNtk2;
00447
00448 for ( pNtk = p->pNtkCur,
00449 pNtk2 = pNtk? Abc_NtkBackup(pNtk): NULL;
00450 pNtk;
00451 pNtk = pNtk2,
00452 pNtk2 = pNtk? Abc_NtkBackup(pNtk): NULL )
00453 Abc_NtkDelete( pNtk );
00454
00455 p->pNtkCur = NULL;
00456
00457 }
00458
00470 void Abc_FrameSetGlobalFrame( Abc_Frame_t * p )
00471 {
00472 s_GlobalFrame = p;
00473 }
00474
00486 Abc_Frame_t * Abc_FrameGetGlobalFrame()
00487 {
00488 if ( s_GlobalFrame == 0 )
00489 {
00490
00491 s_GlobalFrame = Abc_FrameAllocate();
00492
00493 Abc_FrameInit( s_GlobalFrame );
00494 }
00495 return s_GlobalFrame;
00496 }
00497
00498
00502
00503