mainFrame.c 25.1 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**CFile****************************************************************

  FileName    [mainFrame.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [The main package.]

  Synopsis    [The global framework resides in this file.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: mainFrame.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

21
#include "base/abc/abc.h"
22
#include "mainInt.h"
23
#include "bool/dec/dec.h"
24
#include "map/if/if.h"
25
#include "aig/miniaig/ndr.h"
Alan Mishchenko committed
26

27
#ifdef ABC_USE_CUDD
28
#include "bdd/extrab/extraBdd.h"
29
#endif
30 31 32 33

ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
34 35 36 37
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
38
static Abc_Frame_t * s_GlobalFrame = NULL;
Alan Mishchenko committed
39 40

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
41
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
42 43 44 45
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

Alan Mishchenko committed
46 47 48 49 50 51 52 53 54
  Synopsis    [APIs to access parameters in the flobal frame.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
55 56 57
Vec_Ptr_t * Abc_FrameReadStore()                             { return s_GlobalFrame->vStore;       } 
int         Abc_FrameReadStoreSize()                         { return Vec_PtrSize(s_GlobalFrame->vStore); }
void *      Abc_FrameReadLibLut()                            { return s_GlobalFrame->pLibLut;      } 
Alan Mishchenko committed
58
void *      Abc_FrameReadLibBox()                            { return s_GlobalFrame->pLibBox;      } 
59 60 61
void *      Abc_FrameReadLibGen()                            { return s_GlobalFrame->pLibGen;      } 
void *      Abc_FrameReadLibGen2()                           { return s_GlobalFrame->pLibGen2;     } 
void *      Abc_FrameReadLibSuper()                          { return s_GlobalFrame->pLibSuper;    } 
62
void *      Abc_FrameReadLibScl()                            { return s_GlobalFrame->pLibScl;      } 
63
#ifdef ABC_USE_CUDD
64
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;      } 
65
#endif
66
void *      Abc_FrameReadManDec()                            { if ( s_GlobalFrame->pManDec == NULL ) s_GlobalFrame->pManDec = Dec_ManStart();                                        return s_GlobalFrame->pManDec; } 
67
void *      Abc_FrameReadManDsd()                            { return s_GlobalFrame->pManDsd;      } 
Alan Mishchenko committed
68 69
void *      Abc_FrameReadManDsd2()                           { return s_GlobalFrame->pManDsd2;     }
char *      Abc_FrameReadFlag( char * pFlag )                { return Cmd_FlagReadByName( s_GlobalFrame, pFlag );   }
70
Vec_Ptr_t * Abc_FrameReadSignalNames()                       { return s_GlobalFrame->vSignalNames; }
71
char *      Abc_FrameReadSpecName()                          { return s_GlobalFrame->pSpecName;    }
72 73 74

int         Abc_FrameReadBmcFrames( Abc_Frame_t * p )        { return s_GlobalFrame->nFrames;      }               
int         Abc_FrameReadProbStatus( Abc_Frame_t * p )       { return s_GlobalFrame->Status;       }               
75
void *      Abc_FrameReadCex( Abc_Frame_t * p )              { return s_GlobalFrame->pCex;         }        
76
Vec_Ptr_t * Abc_FrameReadCexVec( Abc_Frame_t * p )           { return s_GlobalFrame->vCexVec;      }        
77
Vec_Int_t * Abc_FrameReadStatusVec( Abc_Frame_t * p )        { return s_GlobalFrame->vStatuses;    }        
78
Vec_Ptr_t * Abc_FrameReadPoEquivs( Abc_Frame_t * p )         { return s_GlobalFrame->vPoEquivs;    }        
79
Vec_Int_t * Abc_FrameReadPoStatuses( Abc_Frame_t * p )       { return s_GlobalFrame->vStatuses;    }        
80
Vec_Int_t * Abc_FrameReadObjIds( Abc_Frame_t * p )           { return s_GlobalFrame->vAbcObjIds;   }        
81 82
Abc_Nam_t * Abc_FrameReadJsonStrs( Abc_Frame_t * p )         { return s_GlobalFrame->pJsonStrs;    }     
Vec_Wec_t * Abc_FrameReadJsonObjs( Abc_Frame_t * p )         { return s_GlobalFrame->vJsonObjs;    }   
83
       
84 85 86 87
int         Abc_FrameReadCexPiNum( Abc_Frame_t * p )         { return s_GlobalFrame->pCex->nPis;   }               
int         Abc_FrameReadCexRegNum( Abc_Frame_t * p )        { return s_GlobalFrame->pCex->nRegs;  }               
int         Abc_FrameReadCexPo( Abc_Frame_t * p )            { return s_GlobalFrame->pCex->iPo;    }               
int         Abc_FrameReadCexFrame( Abc_Frame_t * p )         { return s_GlobalFrame->pCex->iFrame; }               
88

89 90 91 92
void        Abc_FrameInputNdr( Abc_Frame_t * pAbc, void * pData ) { Ndr_Delete(s_GlobalFrame->pNdr); s_GlobalFrame->pNdr = pData;                        }
void *      Abc_FrameOutputNdr( Abc_Frame_t * pAbc )         { void * pData = s_GlobalFrame->pNdr; s_GlobalFrame->pNdr = NULL; return pData;             }  
int *       Abc_FrameOutputNdrArray( Abc_Frame_t * pAbc )    { int * pArray = s_GlobalFrame->pNdrArray; s_GlobalFrame->pNdrArray = NULL; return pArray;  }

93
void        Abc_FrameSetLibLut( void * pLib )                { s_GlobalFrame->pLibLut   = pLib;    } 
Alan Mishchenko committed
94
void        Abc_FrameSetLibBox( void * pLib )                { s_GlobalFrame->pLibBox   = pLib;    } 
95 96 97
void        Abc_FrameSetLibGen( void * pLib )                { s_GlobalFrame->pLibGen   = pLib;    } 
void        Abc_FrameSetLibGen2( void * pLib )               { s_GlobalFrame->pLibGen2  = pLib;    } 
void        Abc_FrameSetLibSuper( void * pLib )              { s_GlobalFrame->pLibSuper = pLib;    } 
98 99 100
void        Abc_FrameSetFlag( char * pFlag, char * pValue )  { Cmd_FlagUpdateValue( s_GlobalFrame, pFlag, pValue );               } 
void        Abc_FrameSetCex( Abc_Cex_t * pCex )              { ABC_FREE( s_GlobalFrame->pCex ); s_GlobalFrame->pCex = pCex;       }
void        Abc_FrameSetNFrames( int nFrames )               { ABC_FREE( s_GlobalFrame->pCex ); s_GlobalFrame->nFrames = nFrames; }
101
void        Abc_FrameSetStatus( int Status )                 { ABC_FREE( s_GlobalFrame->pCex ); s_GlobalFrame->Status = Status;   }
102 103
void        Abc_FrameSetManDsd( void * pMan )                { if (s_GlobalFrame->pManDsd  && s_GlobalFrame->pManDsd  != pMan) If_DsdManFree((If_DsdMan_t *)s_GlobalFrame->pManDsd,  0); s_GlobalFrame->pManDsd = pMan;  }
void        Abc_FrameSetManDsd2( void * pMan )               { if (s_GlobalFrame->pManDsd2 && s_GlobalFrame->pManDsd2 != pMan) If_DsdManFree((If_DsdMan_t *)s_GlobalFrame->pManDsd2, 0); s_GlobalFrame->pManDsd2 = pMan; }
Alan Mishchenko committed
104
void        Abc_FrameSetInv( Vec_Int_t * vInv )              { Vec_IntFreeP(&s_GlobalFrame->pAbcWlcInv); s_GlobalFrame->pAbcWlcInv = vInv; }
105 106
void        Abc_FrameSetJsonStrs( Abc_Nam_t * pStrs )        { Abc_NamDeref( s_GlobalFrame->pJsonStrs ); s_GlobalFrame->pJsonStrs = pStrs; }
void        Abc_FrameSetJsonObjs( Vec_Wec_t * vObjs )        { Vec_WecFreeP(&s_GlobalFrame->vJsonObjs ); s_GlobalFrame->vJsonObjs = vObjs; }
107
void        Abc_FrameSetSignalNames( Vec_Ptr_t * vNames )    { if ( s_GlobalFrame->vSignalNames ) Vec_PtrFreeFree( s_GlobalFrame->vSignalNames ); s_GlobalFrame->vSignalNames = vNames; }
108
void        Abc_FrameSetSpecName( char * pFileName )         { ABC_FREE( s_GlobalFrame->pSpecName ); s_GlobalFrame->pSpecName = pFileName; }
Alan Mishchenko committed
109

110
int         Abc_FrameIsBatchMode()                           { return s_GlobalFrame ? s_GlobalFrame->fBatchMode : 0;              } 
111
void        Abc_FrameSetBatchMode( int Mode )                { if ( s_GlobalFrame ) s_GlobalFrame->fBatchMode = Mode;             } 
112

113 114
int         Abc_FrameIsBridgeMode()                          { return s_GlobalFrame ? s_GlobalFrame->fBridgeMode : 0;             } 
void        Abc_FrameSetBridgeMode()                         { if ( s_GlobalFrame ) s_GlobalFrame->fBridgeMode = 1;               } 
115

116 117 118
char *      Abc_FrameReadDrivingCell()                       { return s_GlobalFrame->pDrivingCell;    }              
float       Abc_FrameReadMaxLoad()                           { return s_GlobalFrame->MaxLoad;         }      
void        Abc_FrameSetDrivingCell( char * pName )          { ABC_FREE(s_GlobalFrame->pDrivingCell); s_GlobalFrame->pDrivingCell   = pName; }      
119 120 121 122
void        Abc_FrameSetMaxLoad( float Load )                { s_GlobalFrame->MaxLoad = Load;         }      

int *       Abc_FrameReadArrayMapping( Abc_Frame_t * pAbc )  { return pAbc->pArray;                                            }
void        Abc_FrameSetArrayMapping( int * p )              { ABC_FREE( s_GlobalFrame->pArray ); s_GlobalFrame->pArray = p;   }      
123

124 125 126
int *       Abc_FrameReadBoxes( Abc_Frame_t * pAbc )         { return pAbc->pBoxes;                                            }
void        Abc_FrameSetBoxes( int * p )                     { ABC_FREE( s_GlobalFrame->pBoxes ); s_GlobalFrame->pBoxes = p;   }      

Alan Mishchenko committed
127 128 129 130 131 132 133 134 135 136 137
/**Function*************************************************************

  Synopsis    [Returns 1 if the flag is enabled without value or with value 1.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
138
int Abc_FrameIsFlagEnabled( char * pFlag )
Alan Mishchenko committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152
{
    char * pValue;
    // if flag is not defined, it is not enabled
    pValue = Abc_FrameReadFlag( pFlag );
    if ( pValue == NULL )
        return 0;
    // if flag is defined but value is not empty (no parameter) or "1", it is not enabled
    if ( strcmp(pValue, "") && strcmp(pValue, "1") )
        return 0;
    return 1;
}

/**Function*************************************************************

Alan Mishchenko committed
153 154 155 156 157 158 159 160 161 162 163 164
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Frame_t * Abc_FrameAllocate()
{
    Abc_Frame_t * p;
Alan Mishchenko committed
165 166
    extern void define_cube_size( int n );
    extern void set_espresso_flags();
Alan Mishchenko committed
167
    // allocate and clean
168
    p = ABC_CALLOC( Abc_Frame_t, 1 );
Alan Mishchenko committed
169 170 171 172 173 174
    // get version
    p->sVersion = Abc_UtilsGetVersion( p );
    // set streams
    p->Err = stderr;
    p->Out = stdout;
    p->Hst = NULL;
175 176
    p->Status     = -1;
    p->nFrames    = -1;
Alan Mishchenko committed
177
    // set the starting step
178 179
    p->nSteps     =  1;
    p->fBatchMode =  0;
Alan Mishchenko committed
180 181
    // networks to be used by choice
    p->vStore = Vec_PtrAlloc( 16 );
182
    p->vAbcObjIds = Vec_IntAlloc( 0 );
Alan Mishchenko committed
183
    // initialize decomposition manager
Alan Mishchenko committed
184 185
//    define_cube_size(20);
//    set_espresso_flags();
Alan Mishchenko committed
186 187
    // initialize the trace manager
//    Abc_HManStart();
188
    p->vPlugInComBinPairs = Vec_PtrAlloc( 100 );
Alan Mishchenko committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    return p;
}


/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameDeallocate( Abc_Frame_t * p )
{
Alan Mishchenko committed
206 207 208 209
    extern void Rwt_ManGlobalStop();
    extern void undefine_cube_size();
//    extern void Ivy_TruthManStop();
//    Abc_HManStop();
Alan Mishchenko committed
210
//    undefine_cube_size();
Alan Mishchenko committed
211 212
    Rwt_ManGlobalStop();
//    Ivy_TruthManStop();
213
    if ( p->vAbcObjIds)  Vec_IntFree( p->vAbcObjIds );
214 215
    if ( p->vCexVec   )  Vec_PtrFreeFree( p->vCexVec );
    if ( p->vPoEquivs )  Vec_VecFree( (Vec_Vec_t *)p->vPoEquivs );
216
    if ( p->vStatuses )  Vec_IntFree( p->vStatuses );
217
    if ( p->pManDec   )  Dec_ManStop( (Dec_Man_t *)p->pManDec );
218
#ifdef ABC_USE_CUDD
219
    if ( p->dd        )  Extra_StopManager( p->dd );
220
#endif
221 222 223 224 225
    if ( p->vStore    )  Vec_PtrFree( p->vStore );
    if ( p->pSave1    )  Aig_ManStop( (Aig_Man_t *)p->pSave1 );
    if ( p->pSave2    )  Aig_ManStop( (Aig_Man_t *)p->pSave2 );
    if ( p->pSave3    )  Aig_ManStop( (Aig_Man_t *)p->pSave3 );
    if ( p->pSave4    )  Aig_ManStop( (Aig_Man_t *)p->pSave4 );
226
    if ( p->pManDsd   )  If_DsdManFree( (If_DsdMan_t *)p->pManDsd, 0 );
227
    if ( p->pManDsd2  )  If_DsdManFree( (If_DsdMan_t *)p->pManDsd2, 0 );
228
    if ( p->pNtkBackup)  Abc_NtkDelete( p->pNtkBackup );
229 230 231 232 233 234 235 236
    if ( p->vPlugInComBinPairs ) 
    {
        char * pTemp;
        int i;
        Vec_PtrForEachEntry( char *, p->vPlugInComBinPairs, pTemp, i )
            ABC_FREE( pTemp );
        Vec_PtrFree( p->vPlugInComBinPairs );
    }
237
    Vec_IntFreeP( &p->vIndFlops );
238
    Vec_PtrFreeP( &p->vLTLProperties_global );
239 240
    if ( p->vSignalNames )
    Vec_PtrFreeFree( p->vSignalNames );
241
    ABC_FREE( p->pSpecName );
Alan Mishchenko committed
242
    Abc_FrameDeleteAllNetworks( p );
243
    ABC_FREE( p->pDrivingCell );
244
    ABC_FREE( p->pCex2 );
245
    ABC_FREE( p->pCex );
Alan Mishchenko committed
246
    Vec_IntFreeP( &p->pAbcWlcInv );
247
    Abc_NamDeref( s_GlobalFrame->pJsonStrs );
248 249 250
    Vec_WecFreeP( &s_GlobalFrame->vJsonObjs );  
    Ndr_Delete( s_GlobalFrame->pNdr );
    ABC_FREE( s_GlobalFrame->pNdrArray );
251 252 253 254 255

    Gia_ManStopP( &p->pGiaMiniAig );
    Gia_ManStopP( &p->pGiaMiniLut );
    Vec_IntFreeP( &p->vCopyMiniAig );
    Vec_IntFreeP( &p->vCopyMiniLut );
256
    ABC_FREE( p->pArray );
257
    ABC_FREE( p->pBoxes );
258
    
259

Alan Mishchenko committed
260
    ABC_FREE( p );
Alan Mishchenko committed
261
    s_GlobalFrame = NULL;
Alan Mishchenko committed
262 263
}

Alan Mishchenko committed
264

Alan Mishchenko committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameRestart( Abc_Frame_t * p )
{
}

Alan Mishchenko committed
280 281 282 283 284 285 286 287 288 289 290
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
void Abc_FrameClearVerifStatus( Abc_Frame_t * p )
{
    p->nFrames = -1;
    p->Status  = -1;
    ABC_FREE( p->pCex );
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_FrameShowProgress( Abc_Frame_t * p )
Alan Mishchenko committed
310 311 312 313
{
    return Abc_FrameIsFlagEnabled( "progressbar" );
}

Alan Mishchenko committed
314 315 316 317 318 319 320 321 322 323 324 325

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
326
Abc_Ntk_t * Abc_FrameReadNtk( Abc_Frame_t * p )
Alan Mishchenko committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
{
    return p->pNtkCur;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
Gia_Man_t * Abc_FrameReadGia( Abc_Frame_t * p )
{
    return p->pGia;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
FILE * Abc_FrameReadOut( Abc_Frame_t * p )
{
    return p->Out;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
FILE * Abc_FrameReadErr( Abc_Frame_t * p )
{
    return p->Err;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_FrameReadMode( Abc_Frame_t * p )
{
    int fShortNames;
    char * pValue;
    pValue = Cmd_FlagReadByName( p, "namemode" );
    if ( pValue == NULL )
        fShortNames = 0;
    else 
        fShortNames = atoi(pValue);
    return fShortNames;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
413
int Abc_FrameSetMode( Abc_Frame_t * p, int fNameMode )
Alan Mishchenko committed
414 415
{
    char Buffer[2];
416
    int fNameModeOld;
Alan Mishchenko committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
    fNameModeOld = Abc_FrameReadMode( p );
    Buffer[0] = '0' + fNameMode;
    Buffer[1] = 0;
    Cmd_FlagUpdateValue( p, "namemode", (char *)Buffer );
    return fNameModeOld;
}


/**Function*************************************************************

  Synopsis    [Sets the given network to be the current one.]

  Description [Takes the network and makes it the current network.
  The previous current network is attached to the given network as 
  a backup copy. In the stack of backup networks contains too many
  networks (defined by the paramater "savesteps"), the bottom
  most network is deleted.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
440
void Abc_FrameSetCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNtkNew )
Alan Mishchenko committed
441
{
Alan Mishchenko committed
442
    Abc_Ntk_t * pNtk, * pNtk2, * pNtk3;
Alan Mishchenko committed
443 444 445 446
    int nNetsPresent;
    int nNetsToSave;
    char * pValue;

Alan Mishchenko committed
447 448 449
    if ( p->pNtkCur == pNtkNew )
        return;

Alan Mishchenko committed
450
    // link it to the previous network
Alan Mishchenko committed
451
    Abc_NtkSetBackup( pNtkNew, p->pNtkCur );
Alan Mishchenko committed
452
    // set the step of this network
Alan Mishchenko committed
453
    Abc_NtkSetStep( pNtkNew, ++p->nSteps );
Alan Mishchenko committed
454
    // set this network to be the current network
Alan Mishchenko committed
455
    p->pNtkCur = pNtkNew;
Alan Mishchenko committed
456 457 458 459 460 461 462 463 464 465 466

    // remove any extra network that may happen to be in the stack
    pValue = Cmd_FlagReadByName( p, "savesteps" );
    // if the value of steps to save is not set, assume 1-level undo
    if ( pValue == NULL )
        nNetsToSave = 1;
    else 
        nNetsToSave = atoi(pValue);
    
    // count the network, remember the last one, and the one before the last one
    nNetsPresent = 0;
Alan Mishchenko committed
467 468
    pNtk2 = pNtk3 = NULL;
    for ( pNtk = p->pNtkCur; pNtk; pNtk = Abc_NtkBackup(pNtk2) )
Alan Mishchenko committed
469 470
    {
        nNetsPresent++;
Alan Mishchenko committed
471 472
        pNtk3 = pNtk2;
        pNtk2 = pNtk;
Alan Mishchenko committed
473 474 475 476 477
    }

    // remove the earliest backup network if it is more steps away than we store
    if ( nNetsPresent - 1 > nNetsToSave )
    { // delete the last network
Alan Mishchenko committed
478
        Abc_NtkDelete( pNtk2 );
Alan Mishchenko committed
479
        // clean the pointer of the network before the last one
Alan Mishchenko committed
480
        Abc_NtkSetBackup( pNtk3, NULL );
Alan Mishchenko committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
    }
}

/**Function*************************************************************

  Synopsis    [This procedure swaps the current and the backup network.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameSwapCurrentAndBackup( Abc_Frame_t * p )
{
Alan Mishchenko committed
497
    Abc_Ntk_t * pNtkCur, * pNtkBack, * pNtkBack2;
Alan Mishchenko committed
498 499 500
    int iStepCur, iStepBack;

    pNtkCur  = p->pNtkCur;
Alan Mishchenko committed
501
    pNtkBack = Abc_NtkBackup( pNtkCur );
Alan Mishchenko committed
502 503 504
    iStepCur = Abc_NtkStep  ( pNtkCur );

    // if there is no backup nothing to reset
Alan Mishchenko committed
505
    if ( pNtkBack == NULL )
Alan Mishchenko committed
506 507 508
        return;

    // remember the backup of the backup
Alan Mishchenko committed
509 510
    pNtkBack2 = Abc_NtkBackup( pNtkBack );
    iStepBack = Abc_NtkStep  ( pNtkBack );
Alan Mishchenko committed
511 512

    // set pNtkCur to be the next after the backup's backup
Alan Mishchenko committed
513
    Abc_NtkSetBackup( pNtkCur, pNtkBack2 );
Alan Mishchenko committed
514 515 516
    Abc_NtkSetStep  ( pNtkCur, iStepBack );

    // set pNtkCur to be the next after the backup
Alan Mishchenko committed
517 518
    Abc_NtkSetBackup( pNtkBack, pNtkCur );
    Abc_NtkSetStep  ( pNtkBack, iStepCur );
Alan Mishchenko committed
519 520

    // set the current network
Alan Mishchenko committed
521
    p->pNtkCur = pNtkBack;
Alan Mishchenko committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
}


/**Function*************************************************************

  Synopsis    [Replaces the current network by the given one.]

  Description [This procedure does not modify the stack of saved
  networks.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
537
void Abc_FrameReplaceCurrentNetwork( Abc_Frame_t * p, Abc_Ntk_t * pNtk )
Alan Mishchenko committed
538
{
Alan Mishchenko committed
539
    if ( pNtk == NULL )
Alan Mishchenko committed
540 541
        return;

542 543 544
    if ( Abc_NtkPoNum(pNtk) == 0 )
        Abc_Print( 0, "The current network has no primary outputs. Some commands may not work correctly.\n" );

Alan Mishchenko committed
545
    // transfer the parameters to the new network
Alan Mishchenko committed
546
    if ( p->pNtkCur && Abc_FrameIsFlagEnabled( "backup" ) )
Alan Mishchenko committed
547
    {
Alan Mishchenko committed
548 549
        Abc_NtkSetBackup( pNtk, Abc_NtkBackup(p->pNtkCur) );
        Abc_NtkSetStep( pNtk, Abc_NtkStep(p->pNtkCur) );
Alan Mishchenko committed
550 551 552 553 554
        // delete the current network
        Abc_NtkDelete( p->pNtkCur );
    }
    else
    {
Alan Mishchenko committed
555 556
        Abc_NtkSetBackup( pNtk, NULL );
        Abc_NtkSetStep( pNtk, ++p->nSteps );
Alan Mishchenko committed
557 558 559
        // delete the current network if present but backup is disabled
        if ( p->pNtkCur )
            Abc_NtkDelete( p->pNtkCur );
Alan Mishchenko committed
560 561
    }
    // set the new current network
Alan Mishchenko committed
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
    p->pNtkCur = pNtk;
}

/**Function*************************************************************

  Synopsis    [Removes library binding of all currently stored networks.]

  Description [This procedure is called when the library is freed.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameUnmapAllNetworks( Abc_Frame_t * p )
{
    Abc_Ntk_t * pNtk;
    for ( pNtk = p->pNtkCur; pNtk; pNtk = Abc_NtkBackup(pNtk) )
Alan Mishchenko committed
580
        if ( Abc_NtkHasMapping(pNtk) )
Alan Mishchenko committed
581
            Abc_NtkMapToSop( pNtk );
Alan Mishchenko committed
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameDeleteAllNetworks( Abc_Frame_t * p )
{
Alan Mishchenko committed
597
    Abc_Ntk_t * pNtk, * pNtk2;
Alan Mishchenko committed
598
    // delete all the currently saved networks
Alan Mishchenko committed
599 600 601 602 603 604
    for ( pNtk  = p->pNtkCur, 
          pNtk2 = pNtk? Abc_NtkBackup(pNtk): NULL; 
          pNtk; 
          pNtk  = pNtk2, 
          pNtk2 = pNtk? Abc_NtkBackup(pNtk): NULL )
        Abc_NtkDelete( pNtk );
Alan Mishchenko committed
605 606
    // set the current network empty
    p->pNtkCur = NULL;
Alan Mishchenko committed
607
//    fprintf( p->Out, "All networks have been deleted.\n" );
608 609 610
    Gia_ManStopP( &p->pGia );
    Gia_ManStopP( &p->pGia2 );
    Gia_ManStopP( &p->pGiaBest );
611 612
    Gia_ManStopP( &p->pGiaBest2 );
    Gia_ManStopP( &p->pGiaSaved );
Alan Mishchenko committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameSetGlobalFrame( Abc_Frame_t * p )
{
Alan Mishchenko committed
628
    s_GlobalFrame = p;
Alan Mishchenko committed
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Frame_t * Abc_FrameGetGlobalFrame()
{
Alan Mishchenko committed
644
    if ( s_GlobalFrame == 0 )
Alan Mishchenko committed
645 646
    {
        // start the framework
Alan Mishchenko committed
647
        s_GlobalFrame = Abc_FrameAllocate();
Alan Mishchenko committed
648
        // perform initializations
Alan Mishchenko committed
649
        Abc_FrameInit( s_GlobalFrame );
Alan Mishchenko committed
650
    }
Alan Mishchenko committed
651
    return s_GlobalFrame;
Alan Mishchenko committed
652 653
}

Alan Mishchenko committed
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Frame_t * Abc_FrameReadGlobalFrame()
{
    return s_GlobalFrame;
}
Alan Mishchenko committed
669

Alan Mishchenko committed
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameSetSave1( void * pAig )
{
    Abc_Frame_t * pFrame = Abc_FrameGetGlobalFrame();
    if ( pFrame->pSave1 )
685
        Aig_ManStop( (Aig_Man_t *)pFrame->pSave1 );
Alan Mishchenko committed
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
    pFrame->pSave1 = pAig;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_FrameSetSave2( void * pAig )
{
    Abc_Frame_t * pFrame = Abc_FrameGetGlobalFrame();
    if ( pFrame->pSave2 )
704
        Aig_ManStop( (Aig_Man_t *)pFrame->pSave2 );
Alan Mishchenko committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
    pFrame->pSave2 = pAig;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void * Abc_FrameReadSave1()  { void * pAig = Abc_FrameGetGlobalFrame()->pSave1; Abc_FrameGetGlobalFrame()->pSave1 = NULL; return pAig; }
void * Abc_FrameReadSave2()  { void * pAig = Abc_FrameGetGlobalFrame()->pSave2; Abc_FrameGetGlobalFrame()->pSave2 = NULL; return pAig; }

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
/**Function*************************************************************

  Synopsis    [Returns 0/1 if pNtkCur is an AIG and PO is 0/1; -1 otherwise.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_FrameCheckPoConst( Abc_Frame_t * p, int iPoNum )
{
    Abc_Obj_t * pObj;
    if ( p->pNtkCur == NULL )
        return -1;
    if ( !Abc_NtkIsStrash(p->pNtkCur) )
        return -1;
    if ( iPoNum < 0 || iPoNum >= Abc_NtkPoNum(p->pNtkCur) )
        return -1;
    pObj = Abc_NtkPo( p->pNtkCur, iPoNum );
    if ( !Abc_AigNodeIsConst(Abc_ObjFanin0(pObj)) )
        return -1;
    return !Abc_ObjFaninC0(pObj);
}
void Abc_FrameCheckPoConstTest( Abc_Frame_t * p )
{
    Abc_Obj_t * pObj;
    int i;
    Abc_NtkForEachPo( p->pNtkCur, pObj, i )
        printf( "%d = %d\n", i, Abc_FrameCheckPoConst(p, i) );
}


Alan Mishchenko committed
756 757 758 759 760
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


761 762
ABC_NAMESPACE_IMPL_END