abcDar.c 155 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    [abcDar.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [DAG-aware rewriting.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

21 22 23 24 25 26 27 28 29 30 31
#include "base/abc/abc.h"
#include "base/main/main.h"
#include "aig/gia/giaAig.h"
#include "opt/dar/dar.h"
#include "sat/cnf/cnf.h"
#include "proof/fra/fra.h"
#include "proof/fraig/fraig.h"
#include "proof/int/int.h"
#include "proof/dch/dch.h"
#include "proof/ssw/ssw.h"
#include "opt/cgt/cgt.h"
32
#include "bdd/bbr/bbr.h"
33 34 35 36
#include "aig/gia/gia.h"
#include "proof/cec/cec.h"
#include "opt/csw/csw.h"
#include "proof/pdr/pdr.h"
37
#include "sat/bmc/bmc.h"
38
#include "map/mio/mio.h"
Alan Mishchenko committed
39

40 41
ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
42 43 44 45 46 47 48 49 50 51
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_ObjCompareById( Abc_Obj_t ** pp1, Abc_Obj_t ** pp2 )
{
    return Abc_ObjId(Abc_ObjRegular(*pp1)) - Abc_ObjId(Abc_ObjRegular(*pp2));
}

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

  Synopsis    [Collects the supergate.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_CollectTopOr_rec( Abc_Obj_t * pObj, Vec_Ptr_t * vSuper )
{
    if ( Abc_ObjIsComplement(pObj) || !Abc_ObjIsNode(pObj) )
    {
        Vec_PtrPush( vSuper, pObj );
        return;
    }
    // go through the branches
    Abc_CollectTopOr_rec( Abc_ObjChild0(pObj), vSuper );
    Abc_CollectTopOr_rec( Abc_ObjChild1(pObj), vSuper );
}
void Abc_CollectTopOr( Abc_Obj_t * pObj, Vec_Ptr_t * vSuper )
{
    Vec_PtrClear( vSuper );
    if ( Abc_ObjIsComplement(pObj) )
    {
        Abc_CollectTopOr_rec( Abc_ObjNot(pObj), vSuper );
        Vec_PtrUniqify( vSuper, (int (*)())Abc_ObjCompareById );
    }
    else
        Vec_PtrPush( vSuper, Abc_ObjNot(pObj) );
}

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

  Synopsis    [Converts the network from the AIG manager into ABC.]

  Description [The returned map maps new PO IDs into old ones.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Abc_NtkToDarBmc( Abc_Ntk_t * pNtk, Vec_Int_t ** pvMap )
{
    Aig_Man_t * pMan;
    Abc_Obj_t * pObj, * pTemp;
    Vec_Ptr_t * vDrivers;
    Vec_Ptr_t * vSuper;
    int i, k, nDontCares;

    // print warning about initial values
    nDontCares = 0;
    Abc_NtkForEachLatch( pNtk, pObj, i )
        if ( Abc_LatchIsInitDc(pObj) )
        {
            Abc_LatchSetInit0(pObj);
            nDontCares++;
        }
    if ( nDontCares )
    {
129 130 131 132
        Abc_Print( 1, "Warning: %d registers in this network have don't-care init values.\n", nDontCares );
        Abc_Print( 1, "The don't-care are assumed to be 0. The result may not verify.\n" );
        Abc_Print( 1, "Use command \"print_latch\" to see the init values of registers.\n" );
        Abc_Print( 1, "Use command \"zero\" to convert or \"init\" to change the values.\n" );
133 134 135 136 137
    }

    // collect the drivers
    vSuper   = Vec_PtrAlloc( 100 );
    vDrivers = Vec_PtrAlloc( 100 );
138
    if ( pvMap ) 
139 140 141
    *pvMap   = Vec_IntAlloc( 100 );
    Abc_NtkForEachPo( pNtk, pObj, i )
    {
142 143 144 145 146 147 148
        if ( pNtk->nConstrs && i >= pNtk->nConstrs )
        {
            Vec_PtrPush( vDrivers, Abc_ObjNot(Abc_ObjChild0(pObj)) );
            if ( pvMap )
            Vec_IntPush( *pvMap, i );
            continue;
        }
149 150 151 152 153 154 155 156 157 158 159 160 161
        Abc_CollectTopOr( Abc_ObjChild0(pObj), vSuper );
        Vec_PtrForEachEntry( Abc_Obj_t *, vSuper, pTemp, k )
        {
            Vec_PtrPush( vDrivers, pTemp );
            if ( pvMap )
            Vec_IntPush( *pvMap, i );
        }       
    }
    Vec_PtrFree( vSuper );

    // create network
    pMan = Aig_ManStart( Abc_NtkNodeNum(pNtk) + 100 );
    pMan->nConstrs = pNtk->nConstrs;
162
    pMan->nBarBufs = pNtk->nBarBufs;
163
    pMan->pName = Extra_UtilStrsav( pNtk->pName );
164
    pMan->pSpec = Extra_UtilStrsav( pNtk->pSpec );
165 166 167
    // transfer the pointers to the basic nodes
    Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)Aig_ManConst1(pMan);
    Abc_NtkForEachCi( pNtk, pObj, i )
168
        pObj->pCopy = (Abc_Obj_t *)Aig_ObjCreateCi(pMan);
169 170 171 172 173 174 175 176
    // create flops
    Abc_NtkForEachLatch( pNtk, pObj, i )
        Abc_ObjFanout0(pObj)->pCopy = Abc_ObjNotCond( Abc_ObjFanout0(pObj)->pCopy, Abc_LatchIsInit1(pObj) );
    // copy internal nodes
    Abc_NtkForEachNode( pNtk, pObj, i )
        pObj->pCopy = (Abc_Obj_t *)Aig_And( pMan, (Aig_Obj_t *)Abc_ObjChild0Copy(pObj), (Aig_Obj_t *)Abc_ObjChild1Copy(pObj) );
    // create the POs
    Vec_PtrForEachEntry( Abc_Obj_t *, vDrivers, pTemp, k )
177
        Aig_ObjCreateCo( pMan, (Aig_Obj_t *)Abc_ObjNotCond(Abc_ObjRegular(pTemp)->pCopy, !Abc_ObjIsComplement(pTemp)) );
178 179 180
    Vec_PtrFree( vDrivers );
    // create flops
    Abc_NtkForEachLatchInput( pNtk, pObj, i )
181
        Aig_ObjCreateCo( pMan, (Aig_Obj_t *)Abc_ObjNotCond(Abc_ObjChild0Copy(pObj), Abc_LatchIsInit1(Abc_ObjFanout0(pObj))) );
182 183 184 185 186 187

    // remove dangling nodes
    Aig_ManSetRegNum( pMan, Abc_NtkLatchNum(pNtk) );
    Aig_ManCleanup( pMan );
    if ( !Aig_ManCheck( pMan ) )
    {
188
        Abc_Print( 1, "Abc_NtkToDarBmc: AIG check has failed.\n" );
189 190 191 192 193 194 195 196 197
        Aig_ManStop( pMan );
        return NULL;
    }
    return pMan;
}


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

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
  Synopsis    [Collects information about what flops have unknown values.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Abc_NtkFindDcLatches( Abc_Ntk_t * pNtk )
{
    Vec_Int_t * vUnknown;
    Abc_Obj_t * pObj;
    int i;
    vUnknown = Vec_IntStart( Abc_NtkLatchNum(pNtk) );
    Abc_NtkForEachLatch( pNtk, pObj, i )
        if ( Abc_LatchIsInitDc(pObj) )
215
        {
216
            Vec_IntWriteEntry( vUnknown, i, 1 );
217 218
            Abc_LatchSetInit0(pObj);
        }
219 220 221 222 223
    return vUnknown;
}

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

Alan Mishchenko committed
224 225
  Synopsis    [Converts the network from the AIG manager into ABC.]

Alan Mishchenko committed
226
  Description [Assumes that registers are ordered after PIs/POs.]
Alan Mishchenko committed
227 228 229 230 231 232
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
233
Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters )
Alan Mishchenko committed
234
{
235
    Vec_Ptr_t * vNodes;
Alan Mishchenko committed
236
    Aig_Man_t * pMan;
Alan Mishchenko committed
237
    Aig_Obj_t * pObjNew;
Alan Mishchenko committed
238
    Abc_Obj_t * pObj;
Alan Mishchenko committed
239
    int i, nNodes, nDontCares;
Alan Mishchenko committed
240
    // make sure the latches follow PIs/POs
Alan Mishchenko committed
241 242
    if ( fRegisters ) 
    { 
Alan Mishchenko committed
243 244 245 246 247 248
        assert( Abc_NtkBoxNum(pNtk) == Abc_NtkLatchNum(pNtk) );
        Abc_NtkForEachCi( pNtk, pObj, i )
            if ( i < Abc_NtkPiNum(pNtk) )
            {
                assert( Abc_ObjIsPi(pObj) );
                if ( !Abc_ObjIsPi(pObj) )
249
                    Abc_Print( 1, "Abc_NtkToDar(): Temporary bug: The PI ordering is wrong!\n" );
Alan Mishchenko committed
250 251 252 253 254 255 256 257
            }
            else
                assert( Abc_ObjIsBo(pObj) );
        Abc_NtkForEachCo( pNtk, pObj, i )
            if ( i < Abc_NtkPoNum(pNtk) )
            {
                assert( Abc_ObjIsPo(pObj) );
                if ( !Abc_ObjIsPo(pObj) )
258
                    Abc_Print( 1, "Abc_NtkToDar(): Temporary bug: The PO ordering is wrong!\n" );
Alan Mishchenko committed
259 260 261
            }
            else
                assert( Abc_ObjIsBi(pObj) );
Alan Mishchenko committed
262 263 264 265 266 267 268 269 270 271
        // print warning about initial values
        nDontCares = 0;
        Abc_NtkForEachLatch( pNtk, pObj, i )
            if ( Abc_LatchIsInitDc(pObj) )
            {
                Abc_LatchSetInit0(pObj);
                nDontCares++;
            }
        if ( nDontCares )
        {
272 273 274 275
            Abc_Print( 1, "Warning: %d registers in this network have don't-care init values.\n", nDontCares );
            Abc_Print( 1, "The don't-care are assumed to be 0. The result may not verify.\n" );
            Abc_Print( 1, "Use command \"print_latch\" to see the init values of registers.\n" );
            Abc_Print( 1, "Use command \"zero\" to convert or \"init\" to change the values.\n" );
Alan Mishchenko committed
276
        }
Alan Mishchenko committed
277
    }
Alan Mishchenko committed
278
    // create the manager
Alan Mishchenko committed
279
    pMan = Aig_ManStart( Abc_NtkNodeNum(pNtk) + 100 );
Alan Mishchenko committed
280
    pMan->fCatchExor = fExors;
281
    pMan->nConstrs = pNtk->nConstrs;
282
    pMan->nBarBufs = pNtk->nBarBufs;
Alan Mishchenko committed
283
    pMan->pName = Extra_UtilStrsav( pNtk->pName );
284
    pMan->pSpec = Extra_UtilStrsav( pNtk->pSpec );
Alan Mishchenko committed
285
    // transfer the pointers to the basic nodes
Alan Mishchenko committed
286
    Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)Aig_ManConst1(pMan);
Alan Mishchenko committed
287
    Abc_NtkForEachCi( pNtk, pObj, i )
288
    {
289
        pObj->pCopy = (Abc_Obj_t *)Aig_ObjCreateCi(pMan);
290 291 292
        // initialize logic level of the CIs
        ((Aig_Obj_t *)pObj->pCopy)->Level = pObj->Level;
    }
293

Alan Mishchenko committed
294
    // complement the 1-values registers
Alan Mishchenko committed
295
    if ( fRegisters ) {
Alan Mishchenko committed
296 297 298
        Abc_NtkForEachLatch( pNtk, pObj, i )
            if ( Abc_LatchIsInit1(pObj) )
                Abc_ObjFanout0(pObj)->pCopy = Abc_ObjNot(Abc_ObjFanout0(pObj)->pCopy);
Alan Mishchenko committed
299
    }
Alan Mishchenko committed
300
    // perform the conversion of the internal nodes (assumes DFS ordering)
Alan Mishchenko committed
301
//    pMan->fAddStrash = 1;
302 303 304
    vNodes = Abc_NtkDfs( pNtk, 0 );
    Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
//    Abc_NtkForEachNode( pNtk, pObj, i )
Alan Mishchenko committed
305
    {
Alan Mishchenko committed
306
        pObj->pCopy = (Abc_Obj_t *)Aig_And( pMan, (Aig_Obj_t *)Abc_ObjChild0Copy(pObj), (Aig_Obj_t *)Abc_ObjChild1Copy(pObj) );
307
//        Abc_Print( 1, "%d->%d ", pObj->Id, ((Aig_Obj_t *)pObj->pCopy)->Id );
Alan Mishchenko committed
308
    }
309
    Vec_PtrFree( vNodes );
Alan Mishchenko committed
310
    pMan->fAddStrash = 0;
Alan Mishchenko committed
311 312
    // create the POs
    Abc_NtkForEachCo( pNtk, pObj, i )
313
        Aig_ObjCreateCo( pMan, (Aig_Obj_t *)Abc_ObjChild0Copy(pObj) );
Alan Mishchenko committed
314
    // complement the 1-valued registers
Alan Mishchenko committed
315
    Aig_ManSetRegNum( pMan, Abc_NtkLatchNum(pNtk) );
Alan Mishchenko committed
316 317
    if ( fRegisters )
        Aig_ManForEachLiSeq( pMan, pObjNew, i )
Alan Mishchenko committed
318
            if ( Abc_LatchIsInit1(Abc_ObjFanout0(Abc_NtkCo(pNtk,i))) )
Alan Mishchenko committed
319 320
                pObjNew->pFanin0 = Aig_Not(pObjNew->pFanin0);
    // remove dangling nodes
Alan Mishchenko committed
321
    nNodes = (Abc_NtkGetChoiceNum(pNtk) == 0)? Aig_ManCleanup( pMan ) : 0;
Alan Mishchenko committed
322
    if ( !fExors && nNodes )
323
        Abc_Print( 1, "Abc_NtkToDar(): Unexpected %d dangling nodes when converting to AIG!\n", nNodes );
Alan Mishchenko committed
324
//Aig_ManDumpVerilog( pMan, "test.v" );
Alan Mishchenko committed
325 326 327 328 329 330 331 332 333 334
    // save the number of registers
    if ( fRegisters )
    {
        Aig_ManSetRegNum( pMan, Abc_NtkLatchNum(pNtk) );
        pMan->vFlopNums = Vec_IntStartNatural( pMan->nRegs );
//        pMan->vFlopNums = NULL;
//        pMan->vOnehots = Abc_NtkConverLatchNamesIntoNumbers( pNtk );
        if ( pNtk->vOnehots )
            pMan->vOnehots = (Vec_Ptr_t *)Vec_VecDupInt( (Vec_Vec_t *)pNtk->vOnehots );
    }
Alan Mishchenko committed
335 336
    if ( !Aig_ManCheck( pMan ) )
    {
337
        Abc_Print( 1, "Abc_NtkToDar: AIG check has failed.\n" );
Alan Mishchenko committed
338 339 340
        Aig_ManStop( pMan );
        return NULL;
    }
Alan Mishchenko committed
341 342 343 344 345 346 347
    return pMan;
}

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

  Synopsis    [Converts the network from the AIG manager into ABC.]

Alan Mishchenko committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
  Description [Assumes that registers are ordered after PIs/POs.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Abc_NtkToDarChoices( Abc_Ntk_t * pNtk )
{
    Aig_Man_t * pMan;
    Abc_Obj_t * pObj, * pPrev, * pFanin;
    Vec_Ptr_t * vNodes;
    int i;
    vNodes = Abc_AigDfs( pNtk, 0, 0 );
    // create the manager
    pMan = Aig_ManStart( Abc_NtkNodeNum(pNtk) + 100 );
364
    pMan->nConstrs = pNtk->nConstrs;
365
    pMan->nBarBufs = pNtk->nBarBufs;
366 367
    pMan->pName = Extra_UtilStrsav( pNtk->pName );
    pMan->pSpec = Extra_UtilStrsav( pNtk->pSpec );
Alan Mishchenko committed
368 369
    if ( Abc_NtkGetChoiceNum(pNtk) )
    {
Alan Mishchenko committed
370
        pMan->pEquivs = ABC_ALLOC( Aig_Obj_t *, Abc_NtkObjNum(pNtk) );
Alan Mishchenko committed
371 372 373 374 375
        memset( pMan->pEquivs, 0, sizeof(Aig_Obj_t *) * Abc_NtkObjNum(pNtk) );
    }
    // transfer the pointers to the basic nodes
    Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)Aig_ManConst1(pMan);
    Abc_NtkForEachCi( pNtk, pObj, i )
376
        pObj->pCopy = (Abc_Obj_t *)Aig_ObjCreateCi(pMan);
Alan Mishchenko committed
377
    // perform the conversion of the internal nodes (assumes DFS ordering)
378
    Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
379 380
    {
        pObj->pCopy = (Abc_Obj_t *)Aig_And( pMan, (Aig_Obj_t *)Abc_ObjChild0Copy(pObj), (Aig_Obj_t *)Abc_ObjChild1Copy(pObj) );
381
//        Abc_Print( 1, "%d->%d ", pObj->Id, ((Aig_Obj_t *)pObj->pCopy)->Id );
Alan Mishchenko committed
382 383
        if ( Abc_AigNodeIsChoice( pObj ) )
        {
384
            for ( pPrev = pObj, pFanin = (Abc_Obj_t *)pObj->pData; pFanin; pPrev = pFanin, pFanin = (Abc_Obj_t *)pFanin->pData )
Alan Mishchenko committed
385 386 387 388 389 390 391
                Aig_ObjSetEquiv( pMan, (Aig_Obj_t *)pPrev->pCopy, (Aig_Obj_t *)pFanin->pCopy );
//            Aig_ManCreateChoice( pIfMan, (Aig_Obj_t *)pNode->pCopy );
        }
    }
    Vec_PtrFree( vNodes );
    // create the POs
    Abc_NtkForEachCo( pNtk, pObj, i )
392
        Aig_ObjCreateCo( pMan, (Aig_Obj_t *)Abc_ObjChild0Copy(pObj) );
Alan Mishchenko committed
393 394 395 396
    // complement the 1-valued registers
    Aig_ManSetRegNum( pMan, 0 );
    if ( !Aig_ManCheck( pMan ) )
    {
397
        Abc_Print( 1, "Abc_NtkToDar: AIG check has failed.\n" );
Alan Mishchenko committed
398 399 400 401 402 403 404 405 406 407
        Aig_ManStop( pMan );
        return NULL;
    }
    return pMan;
}

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

  Synopsis    [Converts the network from the AIG manager into ABC.]

Alan Mishchenko committed
408 409 410 411 412 413 414
  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
415
Abc_Ntk_t * Abc_NtkFromDar( Abc_Ntk_t * pNtkOld, Aig_Man_t * pMan )
Alan Mishchenko committed
416 417 418
{
    Vec_Ptr_t * vNodes;
    Abc_Ntk_t * pNtkNew;
Alan Mishchenko committed
419
    Aig_Obj_t * pObj;
Alan Mishchenko committed
420
    int i;
Alan Mishchenko committed
421
    assert( pMan->nAsserts == 0 );
Alan Mishchenko committed
422
//    assert( Aig_ManRegNum(pMan) == Abc_NtkLatchNum(pNtkOld) );
Alan Mishchenko committed
423
    // perform strashing
Alan Mishchenko committed
424
    pNtkNew = Abc_NtkStartFrom( pNtkOld, ABC_NTK_STRASH, ABC_FUNC_AIG );
425
    pNtkNew->nConstrs = pMan->nConstrs;
426
    pNtkNew->nBarBufs = pNtkOld->nBarBufs;
Alan Mishchenko committed
427
    // transfer the pointers to the basic nodes
Alan Mishchenko committed
428
    Aig_ManConst1(pMan)->pData = Abc_AigConst1(pNtkNew);
429
    Aig_ManForEachCi( pMan, pObj, i )
430
    {
Alan Mishchenko committed
431
        pObj->pData = Abc_NtkCi(pNtkNew, i);
432 433 434
        // initialize logic level of the CIs
        ((Abc_Obj_t *)pObj->pData)->Level = pObj->Level;
    }
Alan Mishchenko committed
435
    // rebuild the AIG
Alan Mishchenko committed
436
    vNodes = Aig_ManDfs( pMan, 1 );
437
    Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
438 439
        if ( Aig_ObjIsBuf(pObj) )
            pObj->pData = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
Alan Mishchenko committed
440
        else
441
            pObj->pData = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, (Abc_Obj_t *)Aig_ObjChild0Copy(pObj), (Abc_Obj_t *)Aig_ObjChild1Copy(pObj) );
Alan Mishchenko committed
442 443
    Vec_PtrFree( vNodes );
    // connect the PO nodes
444
    Aig_ManForEachCo( pMan, pObj, i )
Alan Mishchenko committed
445
    {
446
        if ( pMan->nAsserts && i == Aig_ManCoNum(pMan) - pMan->nAsserts )
Alan Mishchenko committed
447
            break;
Alan Mishchenko committed
448
        Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), (Abc_Obj_t *)Aig_ObjChild0Copy(pObj) );
Alan Mishchenko committed
449 450
    }
    // if there are assertions, add them
Alan Mishchenko committed
451
    if ( !Abc_NtkCheck( pNtkNew ) )
452
        Abc_Print( 1, "Abc_NtkFromDar(): Network check has failed.\n" );
453
//Abc_NtkPrintCiLevels( pNtkNew );
Alan Mishchenko committed
454 455 456
    return pNtkNew;
}

Alan Mishchenko committed
457 458 459 460
/**Function*************************************************************

  Synopsis    [Converts the network from the AIG manager into ABC.]

Alan Mishchenko committed
461 462 463 464 465 466 467 468 469 470
  Description [This procedure should be called after seq sweeping, 
  which changes the number of registers.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkFromDarSeqSweep( Abc_Ntk_t * pNtkOld, Aig_Man_t * pMan )
{
Alan Mishchenko committed
471
    Vec_Ptr_t * vNodes; 
Alan Mishchenko committed
472 473
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pObjNew, * pLatch;
Alan Mishchenko committed
474
    Aig_Obj_t * pObj, * pObjLo, * pObjLi;
Alan Mishchenko committed
475 476
    int i, iNodeId, nDigits; 
    assert( pMan->nAsserts == 0 );
477
    assert( pNtkOld->nBarBufs == 0 );
Alan Mishchenko committed
478 479 480
//    assert( Aig_ManRegNum(pMan) != Abc_NtkLatchNum(pNtkOld) );
    // perform strashing
    pNtkNew = Abc_NtkStartFromNoLatches( pNtkOld, ABC_NTK_STRASH, ABC_FUNC_AIG );
481
    pNtkNew->nConstrs = pMan->nConstrs;
482
    pNtkNew->nBarBufs = pMan->nBarBufs;
Alan Mishchenko committed
483
    // consider the case of target enlargement
484
    if ( Abc_NtkCiNum(pNtkNew) < Aig_ManCiNum(pMan) - Aig_ManRegNum(pMan) )
Alan Mishchenko committed
485
    {
486
        for ( i = Aig_ManCiNum(pMan) - Aig_ManRegNum(pMan) - Abc_NtkCiNum(pNtkNew); i > 0; i-- )
Alan Mishchenko committed
487 488 489 490 491
        {
            pObjNew = Abc_NtkCreatePi( pNtkNew );
            Abc_ObjAssignName( pObjNew, Abc_ObjName(pObjNew), NULL );
        }
        Abc_NtkOrderCisCos( pNtkNew );
Alan Mishchenko committed
492
    }
493 494
    assert( Abc_NtkCiNum(pNtkNew) == Aig_ManCiNum(pMan) - Aig_ManRegNum(pMan) );
    assert( Abc_NtkCoNum(pNtkNew) == Aig_ManCoNum(pMan) - Aig_ManRegNum(pMan) );
Alan Mishchenko committed
495 496 497 498 499
    // transfer the pointers to the basic nodes
    Aig_ManConst1(pMan)->pData = Abc_AigConst1(pNtkNew);
    Aig_ManForEachPiSeq( pMan, pObj, i )
        pObj->pData = Abc_NtkCi(pNtkNew, i);
    // create as many latches as there are registers in the manager
Alan Mishchenko committed
500 501 502
    Aig_ManForEachLiLoSeq( pMan, pObjLi, pObjLo, i )
    {
        pObjNew = Abc_NtkCreateLatch( pNtkNew );
Alan Mishchenko committed
503 504
        pObjLi->pData = Abc_NtkCreateBi( pNtkNew );
        pObjLo->pData = Abc_NtkCreateBo( pNtkNew );
505 506
        Abc_ObjAddFanin( pObjNew, (Abc_Obj_t *)pObjLi->pData );
        Abc_ObjAddFanin( (Abc_Obj_t *)pObjLo->pData, pObjNew );
Alan Mishchenko committed
507 508 509
        Abc_LatchSetInit0( pObjNew );
    }
    // rebuild the AIG
Alan Mishchenko committed
510
    vNodes = Aig_ManDfs( pMan, 1 );
511
    Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
512 513 514
        if ( Aig_ObjIsBuf(pObj) )
            pObj->pData = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
        else
515
            pObj->pData = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, (Abc_Obj_t *)Aig_ObjChild0Copy(pObj), (Abc_Obj_t *)Aig_ObjChild1Copy(pObj) );
Alan Mishchenko committed
516 517
    Vec_PtrFree( vNodes );
    // connect the PO nodes
518
    Aig_ManForEachCo( pMan, pObj, i )
Alan Mishchenko committed
519
    {
520
//        if ( pMan->nAsserts && i == Aig_ManCoNum(pMan) - pMan->nAsserts )
Alan Mishchenko committed
521
//            break;
Alan Mishchenko committed
522 523 524 525 526
        iNodeId = Nm_ManFindIdByNameTwoTypes( pNtkNew->pManName, Abc_ObjName(Abc_NtkCo(pNtkNew, i)), ABC_OBJ_PI, ABC_OBJ_BO );
        if ( iNodeId >= 0 )
            pObjNew = Abc_NtkObj( pNtkNew, iNodeId );
        else
            pObjNew = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
Alan Mishchenko committed
527
        Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), pObjNew );
Alan Mishchenko committed
528
    }
Alan Mishchenko committed
529 530 531 532
    if ( pMan->vFlopNums == NULL )
        Abc_NtkAddDummyBoxNames( pNtkNew );
    else
    {
Alan Mishchenko committed
533
/*
Alan Mishchenko committed
534 535 536 537
        {
            int i, k, iFlop, Counter = 0;
            FILE * pFile;
            pFile = fopen( "out.txt", "w" );
538
            fAbc_Print( 1, pFile, "The total of %d registers were removed (out of %d):\n", 
Alan Mishchenko committed
539 540 541 542 543 544 545 546 547
                Abc_NtkLatchNum(pNtkOld)-Vec_IntSize(pMan->vFlopNums), Abc_NtkLatchNum(pNtkOld) );
            for ( i = 0; i < Abc_NtkLatchNum(pNtkOld); i++ )
            {
                Vec_IntForEachEntry( pMan->vFlopNums, iFlop, k )
                {
                    if ( i == iFlop )
                        break;
                }
                if ( k == Vec_IntSize(pMan->vFlopNums) )
548
                    fAbc_Print( 1, pFile, "%6d (%6d)  :  %s\n", ++Counter, i, Abc_ObjName( Abc_ObjFanout0(Abc_NtkBox(pNtkOld, i)) ) );
Alan Mishchenko committed
549 550
            }
            fclose( pFile );
551
            //Abc_Print( 1, "\n" );
Alan Mishchenko committed
552
        }
Alan Mishchenko committed
553
*/
Alan Mishchenko committed
554
        assert( Abc_NtkBoxNum(pNtkOld) == Abc_NtkLatchNum(pNtkOld) );
555
        nDigits = Abc_Base10Log( Abc_NtkLatchNum(pNtkNew) );
Alan Mishchenko committed
556 557 558 559 560 561 562 563 564
        Abc_NtkForEachLatch( pNtkNew, pObjNew, i )
        {
            pLatch = Abc_NtkBox( pNtkOld, Vec_IntEntry( pMan->vFlopNums, i ) );
            iNodeId = Nm_ManFindIdByName( pNtkNew->pManName, Abc_ObjName(Abc_ObjFanout0(pLatch)), ABC_OBJ_PO );
            if ( iNodeId >= 0 )
            {
                Abc_ObjAssignName( pObjNew, Abc_ObjNameDummy("l", i, nDigits), NULL );
                Abc_ObjAssignName( Abc_ObjFanin0(pObjNew), Abc_ObjNameDummy("li", i, nDigits), NULL );
                Abc_ObjAssignName( Abc_ObjFanout0(pObjNew), Abc_ObjNameDummy("lo", i, nDigits), NULL );
565
//Abc_Print( 1, "happening   %s -> %s\n", Abc_ObjName(Abc_ObjFanin0(pObjNew)), Abc_ObjName(Abc_ObjFanout0(pObjNew)) );
Alan Mishchenko committed
566 567 568 569 570 571 572
                continue;
            }
            Abc_ObjAssignName( pObjNew, Abc_ObjName(pLatch), NULL );
            Abc_ObjAssignName( Abc_ObjFanin0(pObjNew),  Abc_ObjName(Abc_ObjFanin0(pLatch)), NULL );
            Abc_ObjAssignName( Abc_ObjFanout0(pObjNew), Abc_ObjName(Abc_ObjFanout0(pLatch)), NULL );
        }
    }
Alan Mishchenko committed
573
    // if there are assertions, add them
Alan Mishchenko committed
574
    if ( !Abc_NtkCheck( pNtkNew ) )
575
        Abc_Print( 1, "Abc_NtkFromDar(): Network check has failed.\n" );
Alan Mishchenko committed
576 577 578 579 580 581 582
    return pNtkNew;
}

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

  Synopsis    [Converts the network from the AIG manager into ABC.]

Alan Mishchenko committed
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
  Description [This procedure should be called after seq sweeping, 
  which changes the number of registers.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan )
{
    Vec_Ptr_t * vNodes; 
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pObjNew;
    Aig_Obj_t * pObj, * pObjLo, * pObjLi;
    int i; 
    assert( pMan->nAsserts == 0 );
    // perform strashing
    pNtkNew = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
601
    pNtkNew->nConstrs = pMan->nConstrs;
602
    pNtkNew->nBarBufs = pMan->nBarBufs;
Alan Mishchenko committed
603 604 605
    // duplicate the name and the spec
//    pNtkNew->pName = Extra_UtilStrsav(pMan->pName);
//    pNtkNew->pSpec = Extra_UtilStrsav(pMan->pSpec);
Alan Mishchenko committed
606 607 608 609 610
    Aig_ManConst1(pMan)->pData = Abc_AigConst1(pNtkNew);
    // create PIs
    Aig_ManForEachPiSeq( pMan, pObj, i )
    {
        pObjNew = Abc_NtkCreatePi( pNtkNew );
611
//        Abc_ObjAssignName( pObjNew, Abc_ObjName(pObjNew), NULL );
Alan Mishchenko committed
612 613 614 615 616 617
        pObj->pData = pObjNew;
    }
    // create POs
    Aig_ManForEachPoSeq( pMan, pObj, i )
    {
        pObjNew = Abc_NtkCreatePo( pNtkNew );
618
//        Abc_ObjAssignName( pObjNew, Abc_ObjName(pObjNew), NULL );
Alan Mishchenko committed
619 620
        pObj->pData = pObjNew;
    }
621 622
    assert( Abc_NtkCiNum(pNtkNew) == Aig_ManCiNum(pMan) - Aig_ManRegNum(pMan) );
    assert( Abc_NtkCoNum(pNtkNew) == Aig_ManCoNum(pMan) - Aig_ManRegNum(pMan) );
Alan Mishchenko committed
623 624 625 626 627 628
    // create as many latches as there are registers in the manager
    Aig_ManForEachLiLoSeq( pMan, pObjLi, pObjLo, i )
    {
        pObjNew = Abc_NtkCreateLatch( pNtkNew );
        pObjLi->pData = Abc_NtkCreateBi( pNtkNew );
        pObjLo->pData = Abc_NtkCreateBo( pNtkNew );
629 630
        Abc_ObjAddFanin( pObjNew, (Abc_Obj_t *)pObjLi->pData );
        Abc_ObjAddFanin( (Abc_Obj_t *)pObjLo->pData, pObjNew );
Alan Mishchenko committed
631
        Abc_LatchSetInit0( pObjNew );
632 633
//        Abc_ObjAssignName( (Abc_Obj_t *)pObjLi->pData, Abc_ObjName((Abc_Obj_t *)pObjLi->pData), NULL );
//        Abc_ObjAssignName( (Abc_Obj_t *)pObjLo->pData, Abc_ObjName((Abc_Obj_t *)pObjLo->pData), NULL );
Alan Mishchenko committed
634 635 636
    }
    // rebuild the AIG
    vNodes = Aig_ManDfs( pMan, 1 );
637
    Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
638 639 640
        if ( Aig_ObjIsBuf(pObj) )
            pObj->pData = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
        else
641
            pObj->pData = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, (Abc_Obj_t *)Aig_ObjChild0Copy(pObj), (Abc_Obj_t *)Aig_ObjChild1Copy(pObj) );
Alan Mishchenko committed
642 643
    Vec_PtrFree( vNodes );
    // connect the PO nodes
644
    Aig_ManForEachCo( pMan, pObj, i )
Alan Mishchenko committed
645 646 647 648
    {
        pObjNew = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
        Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), pObjNew );
    }
649 650 651 652 653

    Abc_NtkAddDummyPiNames( pNtkNew );
    Abc_NtkAddDummyPoNames( pNtkNew );
    Abc_NtkAddDummyBoxNames( pNtkNew );

Alan Mishchenko committed
654 655
    // check the resulting AIG
    if ( !Abc_NtkCheck( pNtkNew ) )
656
        Abc_Print( 1, "Abc_NtkFromAigPhase(): Network check has failed.\n" );
Alan Mishchenko committed
657 658 659
    return pNtkNew;
}

660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723


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

  Synopsis    [Creates local function of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Hop_Obj_t * Abc_ObjHopFromGia_rec( Hop_Man_t * pHopMan, Gia_Man_t * p, int Id, Vec_Ptr_t * vCopies )
{
    Gia_Obj_t * pObj;
    Hop_Obj_t * gFunc, * gFunc0, * gFunc1;
    if ( Gia_ObjIsTravIdCurrentId(p, Id) )
        return (Hop_Obj_t *)Vec_PtrEntry( vCopies, Id );
    Gia_ObjSetTravIdCurrentId(p, Id);
    pObj = Gia_ManObj(p, Id);
    assert( Gia_ObjIsAnd(pObj) );
    // compute the functions of the children
    gFunc0 = Abc_ObjHopFromGia_rec( pHopMan, p, Gia_ObjFaninId0(pObj, Id), vCopies );
    gFunc1 = Abc_ObjHopFromGia_rec( pHopMan, p, Gia_ObjFaninId1(pObj, Id), vCopies );
    // get the function of the cut
    gFunc  = Hop_And( pHopMan, Hop_NotCond(gFunc0, Gia_ObjFaninC0(pObj)), Hop_NotCond(gFunc1, Gia_ObjFaninC1(pObj)) );  
    Vec_PtrWriteEntry( vCopies, Id, gFunc );
    return gFunc;
}
Hop_Obj_t * Abc_ObjHopFromGia( Hop_Man_t * pHopMan, Gia_Man_t * p, int GiaId, Vec_Ptr_t * vCopies )
{
    int k, iFan;
    assert( Gia_ObjIsLut(p, GiaId) );
    assert( Gia_ObjLutSize(p, GiaId) > 0 );
    Gia_ManIncrementTravId( p );
    Gia_LutForEachFanin( p, GiaId, iFan, k )
    {
        Gia_ObjSetTravIdCurrentId(p, iFan);
        Vec_PtrWriteEntry( vCopies, iFan, Hop_IthVar(pHopMan, k) );
    }
    return Abc_ObjHopFromGia_rec( pHopMan, p, GiaId, vCopies );
}

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

  Synopsis    [Converts the network from the mapped GIA manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkFromMappedGia( Gia_Man_t * p )
{
    int fVerbose = 0;
    int fDuplicate = 0;
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pObjNew, * pObjNewLi, * pObjNewLo, * pConst0 = NULL;
    Gia_Obj_t * pObj, * pObjLi, * pObjLo;
    Vec_Ptr_t * vReflect;
    int i, k, iFan, nDupGates; 
724 725
    assert( Gia_ManHasMapping(p) || p->pMuxes );
    pNtkNew = Abc_NtkAlloc( ABC_NTK_LOGIC, Gia_ManHasMapping(p) ? ABC_FUNC_AIG : ABC_FUNC_SOP, 1 );
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
    // duplicate the name and the spec
    pNtkNew->pName = Extra_UtilStrsav(p->pName);
    pNtkNew->pSpec = Extra_UtilStrsav(p->pSpec);
    Gia_ManFillValue( p );
    // create constant
    pConst0 = Abc_NtkCreateNodeConst0( pNtkNew );
    Gia_ManConst0(p)->Value = Abc_ObjId(pConst0);
    // create PIs
    Gia_ManForEachPi( p, pObj, i )
        pObj->Value = Abc_ObjId( Abc_NtkCreatePi( pNtkNew ) );
    // create POs
    Gia_ManForEachPo( p, pObj, i )
        pObj->Value = Abc_ObjId( Abc_NtkCreatePo( pNtkNew ) );
    // create as many latches as there are registers in the manager
    Gia_ManForEachRiRo( p, pObjLi, pObjLo, i )
    {
        pObjNew = Abc_NtkCreateLatch( pNtkNew );
        pObjNewLi = Abc_NtkCreateBi( pNtkNew );
        pObjNewLo = Abc_NtkCreateBo( pNtkNew );
        Abc_ObjAddFanin( pObjNew, pObjNewLi );
        Abc_ObjAddFanin( pObjNewLo, pObjNew );
        pObjLi->Value = Abc_ObjId( pObjNewLi );
        pObjLo->Value = Abc_ObjId( pObjNewLo );
        Abc_LatchSetInit0( pObjNew );
    }
    // rebuild the AIG
752
    if ( p->pMuxes )
753
    {
754
        Gia_ManForEachAnd( p, pObj, i )
755
        {
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
            pObjNew = Abc_NtkCreateNode( pNtkNew );
            if ( Gia_ObjIsMuxId(p, i) )
            {
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ObjFanin2(p, pObj))) );
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ObjFanin1(pObj))) );
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ObjFanin0(pObj))) );
                pObjNew->pData = Abc_SopCreateMux( (Mem_Flex_t *)pNtkNew->pManFunc );
                if ( Gia_ObjFaninC2(p, pObj) )  Abc_SopComplementVar( (char *)pObjNew->pData, 0 );
                if ( Gia_ObjFaninC1(pObj) )     Abc_SopComplementVar( (char *)pObjNew->pData, 1 );
                if ( Gia_ObjFaninC0(pObj) )     Abc_SopComplementVar( (char *)pObjNew->pData, 2 );
            }
            else if ( Gia_ObjIsXor(pObj) )
            {
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ObjFanin0(pObj))) );
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ObjFanin1(pObj))) );
                pObjNew->pData = Abc_SopCreateXor( (Mem_Flex_t *)pNtkNew->pManFunc, 2 );
                if ( Gia_ObjFaninC0(pObj) )  Abc_SopComplementVar( (char *)pObjNew->pData, 0 );
                if ( Gia_ObjFaninC1(pObj) )  Abc_SopComplementVar( (char *)pObjNew->pData, 1 );
            }
            else 
            {
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ObjFanin0(pObj))) );
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ObjFanin1(pObj))) );
                pObjNew->pData = Abc_SopCreateAnd( (Mem_Flex_t *)pNtkNew->pManFunc, 2, NULL );
                if ( Gia_ObjFaninC0(pObj) )  Abc_SopComplementVar( (char *)pObjNew->pData, 0 );
                if ( Gia_ObjFaninC1(pObj) )  Abc_SopComplementVar( (char *)pObjNew->pData, 1 );
            }
            pObj->Value = Abc_ObjId( pObjNew );
        }
    }
    else
    {
        vReflect = Vec_PtrStart( Gia_ManObjNum(p) );
        Gia_ManForEachLut( p, i )
        {
            pObj = Gia_ManObj(p, i);
            assert( pObj->Value == ~0 );
            if ( Gia_ObjLutSize(p, i) == 0 )
            {
                pObj->Value = Abc_ObjId(pConst0);
                continue;
            }
            pObjNew = Abc_NtkCreateNode( pNtkNew );
            Gia_LutForEachFanin( p, i, iFan, k )
                Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ManObj(p, iFan))) );
            pObjNew->pData = Abc_ObjHopFromGia( (Hop_Man_t *)pNtkNew->pManFunc, p, i, vReflect );
            pObj->Value = Abc_ObjId( pObjNew );
803
        }
804
        Vec_PtrFree( vReflect );
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
    }
    // connect the PO nodes
    Gia_ManForEachCo( p, pObj, i )
    {
        pObjNew = Abc_NtkObj( pNtkNew, Gia_ObjValue(Gia_ObjFanin0(pObj)) );
        Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), Abc_ObjNotCond( pObjNew, Gia_ObjFaninC0(pObj) ) );
    }
    // create names
    Abc_NtkAddDummyPiNames( pNtkNew );
    Abc_NtkAddDummyPoNames( pNtkNew );
    Abc_NtkAddDummyBoxNames( pNtkNew );

    // decouple the PO driver nodes to reduce the number of levels
    nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, fDuplicate );
    if ( fVerbose && nDupGates && !Abc_FrameReadFlag("silentmode") )
    {
        if ( !fDuplicate )
            printf( "Added %d buffers/inverters to decouple the CO drivers.\n", nDupGates );
        else
            printf( "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
    }
    // remove const node if it is not used
827
    if ( !Abc_ObjIsNone(pConst0) && Abc_ObjFanoutNum(pConst0) == 0 )
828 829 830 831 832 833 834 835 836 837 838 839
        Abc_NtkDeleteObj( pConst0 );

    assert( Gia_ManPiNum(p) == Abc_NtkPiNum(pNtkNew) );
    assert( Gia_ManPoNum(p) == Abc_NtkPoNum(pNtkNew) );
    assert( Gia_ManRegNum(p) == Abc_NtkLatchNum(pNtkNew) );

    // check the resulting AIG
    if ( !Abc_NtkCheck( pNtkNew ) )
        Abc_Print( 1, "Abc_NtkFromMappedGia(): Network check has failed.\n" );
    return pNtkNew;
}

840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
/**Function*************************************************************

  Synopsis    [Converts the network from the mapped GIA manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Abc_NtkFromCellWrite( Vec_Int_t * vCopyLits, int i, int c, int Id )
{
    Vec_IntWriteEntry( vCopyLits, Abc_Var2Lit(i, c), Id );
}
static inline Abc_Obj_t * Abc_NtkFromCellRead( Abc_Ntk_t * p, Vec_Int_t * vCopyLits, int i, int c )
{
    Abc_Obj_t * pObjNew;
    int iObjNew = Vec_IntEntry( vCopyLits, Abc_Var2Lit(i, c) );
    if ( iObjNew >= 0 )
        return Abc_NtkObj(p, iObjNew);
861 862
    // opposite phase should be already constructed
    assert( 0 );
863 864 865 866 867 868 869 870 871 872 873 874
    if ( i == 0 )
        pObjNew = c ? Abc_NtkCreateNodeConst1(p) : Abc_NtkCreateNodeConst0(p);
    else
    {
        iObjNew = Vec_IntEntry( vCopyLits, Abc_Var2Lit(i, !c) );   assert( iObjNew >= 0 );
        pObjNew = Abc_NtkCreateNodeInv( p, Abc_NtkObj(p, iObjNew) );
    }
    Abc_NtkFromCellWrite( vCopyLits, i, c, Abc_ObjId(pObjNew) );
    return pObjNew;
}
Abc_Ntk_t * Abc_NtkFromCellMappedGia( Gia_Man_t * p )
{
875
    int fFixDrivers = 1;
876
    int fDuplicate = 1;
877
    int fVerbose = 1;
878 879 880 881
    Abc_Ntk_t * pNtkNew;
    Vec_Int_t * vCopyLits;
    Abc_Obj_t * pObjNew, * pObjNewLi, * pObjNewLo;
    Gia_Obj_t * pObj, * pObjLi, * pObjLo;
882
    int i, k, iLit, iFanLit, nCells, fNeedConst[2] = {0}; 
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
    Mio_Cell_t * pCells = Mio_CollectRootsNewDefault( 6, &nCells, 0 );
    assert( Gia_ManHasCellMapping(p) );
    // start network
    pNtkNew = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_MAP, 1 );
    pNtkNew->pName = Extra_UtilStrsav(p->pName);
    pNtkNew->pSpec = Extra_UtilStrsav(p->pSpec);
    assert( pNtkNew->pManFunc == Abc_FrameReadLibGen() );
    vCopyLits = Vec_IntStartFull( 2*Gia_ManObjNum(p) );
    // create PIs
    Gia_ManForEachPi( p, pObj, i )
        Abc_NtkFromCellWrite( vCopyLits, Gia_ObjId(p, pObj), 0, Abc_ObjId( Abc_NtkCreatePi( pNtkNew ) ) );
    // create POs
    Gia_ManForEachPo( p, pObj, i )
        Abc_NtkFromCellWrite( vCopyLits, Gia_ObjId(p, pObj), 0, Abc_ObjId( Abc_NtkCreatePo( pNtkNew ) ) );
    // create as many latches as there are registers in the manager
    Gia_ManForEachRiRo( p, pObjLi, pObjLo, i )
    {
        pObjNew = Abc_NtkCreateLatch( pNtkNew );
        pObjNewLi = Abc_NtkCreateBi( pNtkNew );
        pObjNewLo = Abc_NtkCreateBo( pNtkNew );
        Abc_ObjAddFanin( pObjNew, pObjNewLi );
        Abc_ObjAddFanin( pObjNewLo, pObjNew );
//        pObjLi->Value = Abc_ObjId( pObjNewLi );
//        pObjLo->Value = Abc_ObjId( pObjNewLo );
        Abc_NtkFromCellWrite( vCopyLits, Gia_ObjId(p, pObjLi), 0, Abc_ObjId( pObjNewLi ) );
        Abc_NtkFromCellWrite( vCopyLits, Gia_ObjId(p, pObjLo), 0, Abc_ObjId( pObjNewLo ) );
        Abc_LatchSetInit0( pObjNew );
    }
911 912 913 914 915

    // create constants
    Gia_ManForEachCo( p, pObj, i )
        if ( Gia_ObjFaninId0p(p, pObj) == 0 )
            fNeedConst[Gia_ObjFaninC0(pObj)] = 1;
916 917 918
    Gia_ManForEachBuf( p, pObj, i )
        if ( Gia_ObjFaninId0p(p, pObj) == 0 )
            fNeedConst[Gia_ObjFaninC0(pObj)] = 1;
919 920 921 922 923
    if ( fNeedConst[0] )
        Abc_NtkFromCellWrite( vCopyLits, 0, 0, Abc_ObjId(Abc_NtkCreateNodeConst0(pNtkNew)) );
    if ( fNeedConst[1] )
        Abc_NtkFromCellWrite( vCopyLits, 0, 1, Abc_ObjId(Abc_NtkCreateNodeConst1(pNtkNew)) );

924 925 926
    // rebuild the AIG
    Gia_ManForEachCell( p, iLit )
    {
927 928 929 930 931 932 933
        int fSkip = 0;
        if ( Gia_ObjIsCellBuf(p, iLit) )
        {
            assert( !Abc_LitIsCompl(iLit) );
            // build buffer
            pObjNew = Abc_NtkCreateNode( pNtkNew );
            iFanLit = Gia_ObjFaninLit0p( p, Gia_ManObj(p, Abc_Lit2Var(iLit)) );
934
            Abc_ObjAddFanin( pObjNew, Abc_NtkFromCellRead(pNtkNew, vCopyLits, Abc_Lit2Var(iFanLit), Abc_LitIsCompl(iFanLit)) );
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965
            pObjNew->pData = NULL; // barrier buffer
            assert( Abc_ObjIsBarBuf(pObjNew) );
            pNtkNew->nBarBufs2++;
        }
        else if ( Gia_ObjIsCellInv(p, iLit) )
        {
            int iLitNot = Abc_LitNot(iLit);
            if ( !Abc_LitIsCompl(iLit) ) // positive phase
            {
                // build negative phase
                assert( Vec_IntEntry(vCopyLits, iLitNot) == -1 );
                assert( Gia_ObjCellId(p, iLitNot) > 0 );
                pObjNew = Abc_NtkCreateNode( pNtkNew );
                Gia_CellForEachFanin( p, iLitNot, iFanLit, k )
                    Abc_ObjAddFanin( pObjNew, Abc_NtkFromCellRead(pNtkNew, vCopyLits, Abc_Lit2Var(iFanLit), Abc_LitIsCompl(iFanLit)) );
                pObjNew->pData = Mio_LibraryReadGateByName( (Mio_Library_t *)pNtkNew->pManFunc, pCells[Gia_ObjCellId(p, iLitNot)].pName, NULL );
                Abc_NtkFromCellWrite( vCopyLits, Abc_Lit2Var(iLitNot), Abc_LitIsCompl(iLitNot), Abc_ObjId(pObjNew) );
                fSkip = 1;
            }
            else // negative phase
            {
                // positive phase is available
                assert( Vec_IntEntry(vCopyLits, iLitNot) != -1 );
            }
            // build inverter
            pObjNew = Abc_NtkCreateNode( pNtkNew );
            Abc_ObjAddFanin( pObjNew, Abc_NtkFromCellRead(pNtkNew, vCopyLits, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLitNot)) );
            pObjNew->pData = Mio_LibraryReadGateByName( (Mio_Library_t *)pNtkNew->pManFunc, pCells[3].pName, NULL );
        }
        else
        {
966
            assert( Gia_ObjCellId(p, iLit) >= 0 );
967 968 969 970 971 972
            pObjNew = Abc_NtkCreateNode( pNtkNew );
            Gia_CellForEachFanin( p, iLit, iFanLit, k )
                Abc_ObjAddFanin( pObjNew, Abc_NtkFromCellRead(pNtkNew, vCopyLits, Abc_Lit2Var(iFanLit), Abc_LitIsCompl(iFanLit)) );
            pObjNew->pData = Mio_LibraryReadGateByName( (Mio_Library_t *)pNtkNew->pManFunc, pCells[Gia_ObjCellId(p, iLit)].pName, NULL );
        }
        assert( Vec_IntEntry(vCopyLits, iLit) == -1 );
973
        Abc_NtkFromCellWrite( vCopyLits, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit), Abc_ObjId(pObjNew) );
974 975
        // skip next
        iLit += fSkip;
976
    }
977

978 979 980 981 982 983 984 985 986 987 988 989
    // connect the PO nodes
    Gia_ManForEachCo( p, pObj, i )
    {
        pObjNew = Abc_NtkFromCellRead( pNtkNew, vCopyLits, Gia_ObjFaninId0p(p, pObj), Gia_ObjFaninC0(pObj) );
        Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), pObjNew );
    }
    // create names
    Abc_NtkAddDummyPiNames( pNtkNew );
    Abc_NtkAddDummyPoNames( pNtkNew );
    Abc_NtkAddDummyBoxNames( pNtkNew );

    // decouple the PO driver nodes to reduce the number of levels
990
    if ( fFixDrivers )
991
    {
992 993 994 995 996 997 998 999
        int nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, fDuplicate );
        if ( fVerbose && nDupGates && !Abc_FrameReadFlag("silentmode") )
        {
            if ( !fDuplicate )
                printf( "Added %d buffers/inverters to decouple the CO drivers.\n", nDupGates );
            else
                printf( "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
        }
1000
    }
1001

1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
    assert( Gia_ManPiNum(p) == Abc_NtkPiNum(pNtkNew) );
    assert( Gia_ManPoNum(p) == Abc_NtkPoNum(pNtkNew) );
    assert( Gia_ManRegNum(p) == Abc_NtkLatchNum(pNtkNew) );
    Vec_IntFree( vCopyLits );
    ABC_FREE( pCells );

    // check the resulting AIG
    if ( !Abc_NtkCheck( pNtkNew ) )
        Abc_Print( 1, "Abc_NtkFromMappedGia(): Network check has failed.\n" );
    return pNtkNew;
}

1014

Alan Mishchenko committed
1015 1016 1017 1018
/**Function*************************************************************

  Synopsis    [Converts the network from the AIG manager into ABC.]

Alan Mishchenko committed
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
  Description [This procedure should be called after seq sweeping, 
  which changes the number of registers.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkAfterTrim( Aig_Man_t * pMan, Abc_Ntk_t * pNtkOld )
{
    Vec_Ptr_t * vNodes; 
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pObjNew, * pObjOld;
    Aig_Obj_t * pObj, * pObjLo, * pObjLi;
    int i; 
    assert( pMan->nAsserts == 0 );
1035
    assert( pNtkOld->nBarBufs == 0 );
Alan Mishchenko committed
1036 1037 1038 1039 1040 1041
    assert( Aig_ManRegNum(pMan) <= Abc_NtkLatchNum(pNtkOld) );
    assert( Saig_ManPiNum(pMan) <= Abc_NtkCiNum(pNtkOld) );
    assert( Saig_ManPoNum(pMan) == Abc_NtkPoNum(pNtkOld) );
    assert( pMan->vCiNumsOrig != NULL );
    // perform strashing
    pNtkNew = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
1042
    pNtkNew->nConstrs = pMan->nConstrs;
1043
    pNtkNew->nBarBufs = pMan->nBarBufs;
Alan Mishchenko committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
    // duplicate the name and the spec
//    pNtkNew->pName = Extra_UtilStrsav(pMan->pName);
//    pNtkNew->pSpec = Extra_UtilStrsav(pMan->pSpec);
    Aig_ManConst1(pMan)->pData = Abc_AigConst1(pNtkNew);
    // create PIs
    Aig_ManForEachPiSeq( pMan, pObj, i )
    {
        pObjNew = Abc_NtkCreatePi( pNtkNew );
        pObj->pData = pObjNew;
        // find the name
        pObjOld = Abc_NtkCi( pNtkOld, Vec_IntEntry(pMan->vCiNumsOrig, i) );
        Abc_ObjAssignName( pObjNew, Abc_ObjName(pObjOld), NULL );
    }
    // create POs
    Aig_ManForEachPoSeq( pMan, pObj, i )
    {
        pObjNew = Abc_NtkCreatePo( pNtkNew );
        pObj->pData = pObjNew;
        // find the name
        pObjOld = Abc_NtkCo( pNtkOld, i );
        Abc_ObjAssignName( pObjNew, Abc_ObjName(pObjOld), NULL );
    }
1066 1067
    assert( Abc_NtkCiNum(pNtkNew) == Aig_ManCiNum(pMan) - Aig_ManRegNum(pMan) );
    assert( Abc_NtkCoNum(pNtkNew) == Aig_ManCoNum(pMan) - Aig_ManRegNum(pMan) );
Alan Mishchenko committed
1068 1069 1070 1071 1072 1073
    // create as many latches as there are registers in the manager
    Aig_ManForEachLiLoSeq( pMan, pObjLi, pObjLo, i )
    {
        pObjNew = Abc_NtkCreateLatch( pNtkNew );
        pObjLi->pData = Abc_NtkCreateBi( pNtkNew );
        pObjLo->pData = Abc_NtkCreateBo( pNtkNew );
1074 1075
        Abc_ObjAddFanin( pObjNew, (Abc_Obj_t *)pObjLi->pData );
        Abc_ObjAddFanin( (Abc_Obj_t *)pObjLo->pData, pObjNew );
Alan Mishchenko committed
1076 1077 1078
        Abc_LatchSetInit0( pObjNew );
        // find the name
        pObjOld = Abc_NtkCi( pNtkOld, Vec_IntEntry(pMan->vCiNumsOrig, Saig_ManPiNum(pMan)+i) );
1079
        Abc_ObjAssignName( (Abc_Obj_t *)pObjLo->pData, Abc_ObjName(pObjOld), NULL );
Alan Mishchenko committed
1080 1081
        // find the name
        pObjOld = Abc_NtkCo( pNtkOld, Saig_ManPoNum(pMan)+i );
1082
        Abc_ObjAssignName( (Abc_Obj_t *)pObjLi->pData, Abc_ObjName(pObjOld), NULL );
Alan Mishchenko committed
1083 1084 1085
    }
    // rebuild the AIG
    vNodes = Aig_ManDfs( pMan, 1 );
1086
    Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
1087 1088 1089
        if ( Aig_ObjIsBuf(pObj) )
            pObj->pData = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
        else
1090
            pObj->pData = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, (Abc_Obj_t *)Aig_ObjChild0Copy(pObj), (Abc_Obj_t *)Aig_ObjChild1Copy(pObj) );
Alan Mishchenko committed
1091 1092
    Vec_PtrFree( vNodes );
    // connect the PO nodes
1093
    Aig_ManForEachCo( pMan, pObj, i )
Alan Mishchenko committed
1094 1095 1096 1097 1098 1099
    {
        pObjNew = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
        Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), pObjNew );
    }
    // check the resulting AIG
    if ( !Abc_NtkCheck( pNtkNew ) )
1100
        Abc_Print( 1, "Abc_NtkAfterTrim(): Network check has failed.\n" );
Alan Mishchenko committed
1101 1102 1103 1104 1105 1106 1107
    return pNtkNew;
}

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

  Synopsis    [Converts the network from the AIG manager into ABC.]

Alan Mishchenko committed
1108 1109 1110 1111 1112 1113 1114
  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1115 1116 1117 1118 1119
Abc_Ntk_t * Abc_NtkFromDarChoices( Abc_Ntk_t * pNtkOld, Aig_Man_t * pMan )
{
    Abc_Ntk_t * pNtkNew;
    Aig_Obj_t * pObj, * pTemp;
    int i;
Alan Mishchenko committed
1120
    assert( pMan->pEquivs != NULL );
Alan Mishchenko committed
1121 1122
    assert( Aig_ManBufNum(pMan) == 0 );
    // perform strashing
Alan Mishchenko committed
1123
    pNtkNew = Abc_NtkStartFrom( pNtkOld, ABC_NTK_STRASH, ABC_FUNC_AIG );
1124
    pNtkNew->nConstrs = pMan->nConstrs;
1125
    pNtkNew->nBarBufs = pNtkOld->nBarBufs;
Alan Mishchenko committed
1126
    // transfer the pointers to the basic nodes
1127
    Aig_ManCleanData( pMan );
Alan Mishchenko committed
1128
    Aig_ManConst1(pMan)->pData = Abc_AigConst1(pNtkNew);
1129
    Aig_ManForEachCi( pMan, pObj, i )
Alan Mishchenko committed
1130 1131
        pObj->pData = Abc_NtkCi(pNtkNew, i);
    // rebuild the AIG
1132
    Aig_ManForEachNode( pMan, pObj, i )
Alan Mishchenko committed
1133
    {
1134
        pObj->pData = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, (Abc_Obj_t *)Aig_ObjChild0Copy(pObj), (Abc_Obj_t *)Aig_ObjChild1Copy(pObj) );
Alan Mishchenko committed
1135
        if ( (pTemp = Aig_ObjEquiv(pMan, pObj)) )
Alan Mishchenko committed
1136 1137
        {
            assert( pTemp->pData != NULL );
1138
            ((Abc_Obj_t *)pObj->pData)->pData = ((Abc_Obj_t *)pTemp->pData);
Alan Mishchenko committed
1139 1140 1141
        }
    }
    // connect the PO nodes
1142
    Aig_ManForEachCo( pMan, pObj, i )
Alan Mishchenko committed
1143 1144
        Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), (Abc_Obj_t *)Aig_ObjChild0Copy(pObj) );
    if ( !Abc_NtkCheck( pNtkNew ) )
1145
        Abc_Print( 1, "Abc_NtkFromDar(): Network check has failed.\n" );
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160

    // verify topological order
    if ( 0 )
    {
        Abc_Obj_t * pNode;
        Abc_NtkForEachNode( pNtkNew, pNode, i )
            if ( Abc_AigNodeIsChoice( pNode ) )
            {
                int Counter = 0;
                for ( pNode = Abc_ObjEquiv(pNode); pNode; pNode = Abc_ObjEquiv(pNode) )
                    Counter++;
                printf( "%d ", Counter );
            }
        printf( "\n" );
    }
Alan Mishchenko committed
1161 1162 1163 1164 1165
    return pNtkNew;
}

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

Alan Mishchenko committed
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
  Synopsis    [Converts the network from the AIG manager into ABC.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkFromDarSeq( Abc_Ntk_t * pNtkOld, Aig_Man_t * pMan )
{
    Vec_Ptr_t * vNodes;
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pObjNew, * pFaninNew, * pFaninNew0, * pFaninNew1;
    Aig_Obj_t * pObj;
    int i;
//    assert( Aig_ManLatchNum(pMan) > 0 );
1183
    assert( pNtkOld->nBarBufs == 0 );
Alan Mishchenko committed
1184 1185
    // perform strashing
    pNtkNew = Abc_NtkStartFromNoLatches( pNtkOld, ABC_NTK_STRASH, ABC_FUNC_AIG );
1186
    pNtkNew->nConstrs = pMan->nConstrs;
1187
    pNtkNew->nBarBufs = pMan->nBarBufs;
Alan Mishchenko committed
1188 1189
    // transfer the pointers to the basic nodes
    Aig_ManConst1(pMan)->pData = Abc_AigConst1(pNtkNew);
1190
    Aig_ManForEachCi( pMan, pObj, i )
Alan Mishchenko committed
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
        pObj->pData = Abc_NtkPi(pNtkNew, i);
    // create latches of the new network
    Aig_ManForEachObj( pMan, pObj, i )
    {
        pObjNew = Abc_NtkCreateLatch( pNtkNew );
        pFaninNew0 = Abc_NtkCreateBi( pNtkNew );
        pFaninNew1 = Abc_NtkCreateBo( pNtkNew );
        Abc_ObjAddFanin( pObjNew, pFaninNew0 );
        Abc_ObjAddFanin( pFaninNew1, pObjNew );
        Abc_LatchSetInit0( pObjNew );
        pObj->pData = Abc_ObjFanout0( pObjNew );
    }
    Abc_NtkAddDummyBoxNames( pNtkNew );
    // rebuild the AIG
Alan Mishchenko committed
1205
    vNodes = Aig_ManDfs( pMan, 1 );
1206
    Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
1207 1208 1209 1210 1211 1212 1213 1214 1215
    {
        // add the first fanin
        pObj->pData = pFaninNew0 = (Abc_Obj_t *)Aig_ObjChild0Copy(pObj);
        if ( Aig_ObjIsBuf(pObj) )
            continue;
        // add the second fanin
        pFaninNew1 = (Abc_Obj_t *)Aig_ObjChild1Copy(pObj);
        // create the new node
        if ( Aig_ObjIsExor(pObj) )
1216
            pObj->pData = pObjNew = Abc_AigXor( (Abc_Aig_t *)pNtkNew->pManFunc, pFaninNew0, pFaninNew1 );
Alan Mishchenko committed
1217
        else
1218
            pObj->pData = pObjNew = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, pFaninNew0, pFaninNew1 );
Alan Mishchenko committed
1219 1220 1221
    }
    Vec_PtrFree( vNodes );
    // connect the PO nodes
1222
    Aig_ManForEachCo( pMan, pObj, i )
Alan Mishchenko committed
1223 1224 1225 1226 1227 1228 1229 1230
    {
        pFaninNew = (Abc_Obj_t *)Aig_ObjChild0Copy( pObj );
        Abc_ObjAddFanin( Abc_NtkPo(pNtkNew, i), pFaninNew );
    }
    // connect the latches
    Aig_ManForEachObj( pMan, pObj, i )
    {
        pFaninNew = (Abc_Obj_t *)Aig_ObjChild0Copy( pObj );
1231
        Abc_ObjAddFanin( Abc_ObjFanin0(Abc_ObjFanin0((Abc_Obj_t *)pObj->pData)), pFaninNew );
Alan Mishchenko committed
1232 1233
    }
    if ( !Abc_NtkCheck( pNtkNew ) )
1234
        Abc_Print( 1, "Abc_NtkFromIvySeq(): Network check has failed.\n" );
Alan Mishchenko committed
1235 1236 1237 1238 1239
    return pNtkNew;
}

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

Alan Mishchenko committed
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
  Synopsis    [Collects CI of the network.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Ptr_t * Abc_NtkCollectCiNames( Abc_Ntk_t * pNtk )
{
    Abc_Obj_t * pObj;
    int i;
    Vec_Ptr_t * vNames;
    vNames = Vec_PtrAlloc( 100 );
    Abc_NtkForEachCi( pNtk, pObj, i )
        Vec_PtrPush( vNames, Extra_UtilStrsav(Abc_ObjName(pObj)) );
    return vNames;
}

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

  Synopsis    [Collects CO of the network.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Ptr_t * Abc_NtkCollectCoNames( Abc_Ntk_t * pNtk )
{
    Abc_Obj_t * pObj;
    int i;
    Vec_Ptr_t * vNames;
    vNames = Vec_PtrAlloc( 100 );
    Abc_NtkForEachCo( pNtk, pObj, i )
        Vec_PtrPush( vNames, Extra_UtilStrsav(Abc_ObjName(pObj)) );
    return vNames;
}

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

Alan Mishchenko committed
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
  Synopsis    [Collect latch values.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Abc_NtkGetLatchValues( Abc_Ntk_t * pNtk )
{
    Vec_Int_t * vInits;
    Abc_Obj_t * pLatch;
    int i;
    vInits = Vec_IntAlloc( Abc_NtkLatchNum(pNtk) );
    Abc_NtkForEachLatch( pNtk, pLatch, i )
    {
Alan Mishchenko committed
1301 1302 1303 1304 1305 1306 1307 1308
        if ( Abc_LatchIsInit0(pLatch) )
            Vec_IntPush( vInits, 0 );
        else if ( Abc_LatchIsInit1(pLatch) )
            Vec_IntPush( vInits, 1 );
        else if ( Abc_LatchIsInitDc(pLatch) )
            Vec_IntPush( vInits, 2 );
        else
            assert( 0 );
Alan Mishchenko committed
1309 1310 1311 1312 1313 1314
    }
    return vInits;
}

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

Alan Mishchenko committed
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDar( Abc_Ntk_t * pNtk )
{
Alan Mishchenko committed
1326 1327 1328
    Abc_Ntk_t * pNtkAig = NULL;
    Aig_Man_t * pMan;
    extern void Fra_ManPartitionTest( Aig_Man_t * p, int nComLim );
Alan Mishchenko committed
1329 1330 1331

    assert( Abc_NtkIsStrash(pNtk) );
    // convert to the AIG manager
Alan Mishchenko committed
1332
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1333 1334 1335
    if ( pMan == NULL )
        return NULL;

Alan Mishchenko committed
1336 1337 1338
    // perform computation
//    Fra_ManPartitionTest( pMan, 4 );
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
Alan Mishchenko committed
1339
    Aig_ManStop( pMan );
Alan Mishchenko committed
1340

Alan Mishchenko committed
1341
    // make sure everything is okay
Alan Mishchenko committed
1342
    if ( pNtkAig && !Abc_NtkCheck( pNtkAig ) )
Alan Mishchenko committed
1343
    {
1344
        Abc_Print( 1, "Abc_NtkDar: The network check has failed.\n" );
Alan Mishchenko committed
1345 1346 1347 1348 1349 1350
        Abc_NtkDelete( pNtkAig );
        return NULL;
    }
    return pNtkAig;
}

Alan Mishchenko committed
1351

Alan Mishchenko committed
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
/**Function*************************************************************

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1363
Abc_Ntk_t * Abc_NtkDarFraig( Abc_Ntk_t * pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fSpeculate, int fChoicing, int fVerbose )
Alan Mishchenko committed
1364
{
Alan Mishchenko committed
1365
    Fra_Par_t Pars, * pPars = &Pars; 
Alan Mishchenko committed
1366
    Abc_Ntk_t * pNtkAig;
Alan Mishchenko committed
1367
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
1368
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1369 1370
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
    Fra_ParamsDefault( pPars );
    pPars->nBTLimitNode = nConfLimit;
    pPars->fChoicing    = fChoicing;
    pPars->fDoSparse    = fDoSparse;
    pPars->fSpeculate   = fSpeculate;
    pPars->fProve       = fProve;
    pPars->fVerbose     = fVerbose;
    pMan = Fra_FraigPerform( pTemp = pMan, pPars );
    if ( fChoicing )
        pNtkAig = Abc_NtkFromDarChoices( pNtk, pMan );
    else
        pNtkAig = Abc_NtkFromDar( pNtk, pMan );
    Aig_ManStop( pTemp );
Alan Mishchenko committed
1384
    Aig_ManStop( pMan );
Alan Mishchenko committed
1385 1386 1387
    return pNtkAig;
}

Alan Mishchenko committed
1388 1389
/**Function*************************************************************

Alan Mishchenko committed
1390
  Synopsis    [Gives the current ABC network to AIG manager for processing.]
Alan Mishchenko committed
1391 1392 1393 1394 1395 1396

  Description []
               
  SideEffects []

  SeeAlso     []
Alan Mishchenko committed
1397

Alan Mishchenko committed
1398
***********************************************************************/
Alan Mishchenko committed
1399 1400 1401 1402
Abc_Ntk_t * Abc_NtkDarFraigPart( Abc_Ntk_t * pNtk, int nPartSize, int nConfLimit, int nLevelMax, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
1403
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
    if ( pMan == NULL )
        return NULL;
    pMan = Aig_ManFraigPartitioned( pTemp = pMan, nPartSize, nConfLimit, nLevelMax, fVerbose );
    Aig_ManStop( pTemp );
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1424
Abc_Ntk_t * Abc_NtkCSweep( Abc_Ntk_t * pNtk, int nCutsMax, int nLeafMax, int fVerbose )
Alan Mishchenko committed
1425
{
1426
//    extern Aig_Man_t * Csw_Sweep( Aig_Man_t * pAig, int nCutsMax, int nLeafMax, int fVerbose );
Alan Mishchenko committed
1427
    Abc_Ntk_t * pNtkAig;
Alan Mishchenko committed
1428
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
1429
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1430 1431
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
1432 1433
    pMan = Csw_Sweep( pTemp = pMan, nCutsMax, nLeafMax, fVerbose );
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
Alan Mishchenko committed
1434
    Aig_ManStop( pTemp );
Alan Mishchenko committed
1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDRewrite( Abc_Ntk_t * pNtk, Dar_RwrPar_t * pPars )
{
    Aig_Man_t * pMan, * pTemp;
    Abc_Ntk_t * pNtkAig;
1454
    abctime clk;
Alan Mishchenko committed
1455
    assert( Abc_NtkIsStrash(pNtk) );
Alan Mishchenko committed
1456
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1457 1458 1459 1460 1461
    if ( pMan == NULL )
        return NULL;
//    Aig_ManPrintStats( pMan );
/*
//    Aig_ManSupports( pMan );
Alan Mishchenko committed
1462
    {
Alan Mishchenko committed
1463 1464 1465
        Vec_Vec_t * vParts;
        vParts = Aig_ManPartitionSmart( pMan, 50, 1, NULL );
        Vec_VecFree( vParts );
Alan Mishchenko committed
1466
    }
Alan Mishchenko committed
1467 1468 1469 1470 1471
*/
    Dar_ManRewrite( pMan, pPars );
//    pMan = Dar_ManBalance( pTemp = pMan, pPars->fUpdateLevel );
//    Aig_ManStop( pTemp );

1472
clk = Abc_Clock();
Alan Mishchenko committed
1473
    pMan = Aig_ManDupDfs( pTemp = pMan ); 
Alan Mishchenko committed
1474
    Aig_ManStop( pTemp );
1475
//ABC_PRT( "time", Abc_Clock() - clk );
Alan Mishchenko committed
1476 1477 1478

//    Aig_ManPrintStats( pMan );
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
Alan Mishchenko committed
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1494
Abc_Ntk_t * Abc_NtkDRefactor( Abc_Ntk_t * pNtk, Dar_RefPar_t * pPars )
Alan Mishchenko committed
1495
{
Alan Mishchenko committed
1496
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
1497
    Abc_Ntk_t * pNtkAig;
1498
    abctime clk;
Alan Mishchenko committed
1499
    assert( Abc_NtkIsStrash(pNtk) );
Alan Mishchenko committed
1500
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1501 1502 1503
    if ( pMan == NULL )
        return NULL;
//    Aig_ManPrintStats( pMan );
Alan Mishchenko committed
1504

Alan Mishchenko committed
1505 1506 1507 1508
    Dar_ManRefactor( pMan, pPars );
//    pMan = Dar_ManBalance( pTemp = pMan, pPars->fUpdateLevel );
//    Aig_ManStop( pTemp );

1509
clk = Abc_Clock();
Alan Mishchenko committed
1510
    pMan = Aig_ManDupDfs( pTemp = pMan ); 
Alan Mishchenko committed
1511
    Aig_ManStop( pTemp );
1512
//ABC_PRT( "time", Abc_Clock() - clk );
Alan Mishchenko committed
1513 1514 1515 1516 1517

//    Aig_ManPrintStats( pMan );
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
Alan Mishchenko committed
1518 1519
}

Alan Mishchenko committed
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
/**Function*************************************************************

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1531
Abc_Ntk_t * Abc_NtkDC2( Abc_Ntk_t * pNtk, int fBalance, int fUpdateLevel, int fFanout, int fPower, int fVerbose )
Alan Mishchenko committed
1532 1533 1534
{
    Aig_Man_t * pMan, * pTemp;
    Abc_Ntk_t * pNtkAig;
1535
    abctime clk;
Alan Mishchenko committed
1536
    assert( Abc_NtkIsStrash(pNtk) );
Alan Mishchenko committed
1537
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1538 1539
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
1540
//    Aig_ManPrintStats( pMan );
Alan Mishchenko committed
1541

1542
clk = Abc_Clock();
Alan Mishchenko committed
1543
    pMan = Dar_ManCompress2( pTemp = pMan, fBalance, fUpdateLevel, fFanout, fPower, fVerbose ); 
Alan Mishchenko committed
1544
    Aig_ManStop( pTemp );
1545
//ABC_PRT( "time", Abc_Clock() - clk );
Alan Mishchenko committed
1546

Alan Mishchenko committed
1547 1548
//    Aig_ManPrintStats( pMan );
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
Alan Mishchenko committed
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1564
Abc_Ntk_t * Abc_NtkDChoice( Abc_Ntk_t * pNtk, int fBalance, int fUpdateLevel, int fConstruct, int nConfMax, int nLevelMax, int fVerbose )
Alan Mishchenko committed
1565
{
Alan Mishchenko committed
1566 1567 1568
    Aig_Man_t * pMan, * pTemp;
    Abc_Ntk_t * pNtkAig;
    assert( Abc_NtkIsStrash(pNtk) );
Alan Mishchenko committed
1569
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1570 1571
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
1572
    pMan = Dar_ManChoice( pTemp = pMan, fBalance, fUpdateLevel, fConstruct, nConfMax, nLevelMax, fVerbose );
Alan Mishchenko committed
1573 1574 1575 1576 1577 1578 1579
    Aig_ManStop( pTemp );
    pNtkAig = Abc_NtkFromDarChoices( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

/**Function*************************************************************
Alan Mishchenko committed
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDch( Abc_Ntk_t * pNtk, Dch_Pars_t * pPars )
{
1592
    extern Gia_Man_t * Dar_NewChoiceSynthesis( Aig_Man_t * pAig, int fBalance, int fUpdateLevel, int fPower, int fLightSynth, int fVerbose );
Alan Mishchenko committed
1593
    extern Aig_Man_t * Cec_ComputeChoices( Gia_Man_t * pGia, Dch_Pars_t * pPars );
Alan Mishchenko committed
1594 1595 1596

    Aig_Man_t * pMan, * pTemp;
    Abc_Ntk_t * pNtkAig;
Alan Mishchenko committed
1597
    Gia_Man_t * pGia;
1598
    abctime clk;
Alan Mishchenko committed
1599 1600 1601 1602
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
    if ( pMan == NULL )
        return NULL;
1603
clk = Abc_Clock();
Alan Mishchenko committed
1604
    if ( pPars->fSynthesis )
1605
        pGia = Dar_NewChoiceSynthesis( pMan, 1, 1, pPars->fPower, pPars->fLightSynth, pPars->fVerbose );
Alan Mishchenko committed
1606 1607
    else
    {
Alan Mishchenko committed
1608 1609
        pGia = Gia_ManFromAig( pMan );
        Aig_ManStop( pMan );
Alan Mishchenko committed
1610
    }
1611
pPars->timeSynth = Abc_Clock() - clk;
Alan Mishchenko committed
1612
    if ( pPars->fUseGia )
Alan Mishchenko committed
1613
        pMan = Cec_ComputeChoices( pGia, pPars );
Alan Mishchenko committed
1614
    else
Alan Mishchenko committed
1615 1616 1617 1618 1619 1620
    {
        pMan = Gia_ManToAigSkip( pGia, 3 );
        Gia_ManStop( pGia );
        pMan = Dch_ComputeChoices( pTemp = pMan, pPars );
        Aig_ManStop( pTemp );
    }
Alan Mishchenko committed
1621
    pNtkAig = Abc_NtkFromDarChoices( pNtk, pMan );
Alan Mishchenko committed
1622 1623 1624 1625 1626
    Aig_ManStop( pMan );
    return pNtkAig;
}

/**Function*************************************************************
Alan Mishchenko committed
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDrwsat( Abc_Ntk_t * pNtk, int fBalance, int fVerbose )
{
    Aig_Man_t * pMan, * pTemp;
    Abc_Ntk_t * pNtkAig;
1641
    abctime clk;
Alan Mishchenko committed
1642
    assert( Abc_NtkIsStrash(pNtk) );
Alan Mishchenko committed
1643
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1644 1645 1646 1647
    if ( pMan == NULL )
        return NULL;
//    Aig_ManPrintStats( pMan );

1648
clk = Abc_Clock();
Alan Mishchenko committed
1649 1650
    pMan = Dar_ManRwsat( pTemp = pMan, fBalance, fVerbose ); 
    Aig_ManStop( pTemp );
1651
//ABC_PRT( "time", Abc_Clock() - clk );
Alan Mishchenko committed
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683

//    Aig_ManPrintStats( pMan );
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkConstructFromCnf( Abc_Ntk_t * pNtk, Cnf_Man_t * p, Vec_Ptr_t * vMapped )
{
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pNode, * pNodeNew;
    Aig_Obj_t * pObj, * pLeaf;
    Cnf_Cut_t * pCut;
    Vec_Int_t * vCover;
    unsigned uTruth;
    int i, k, nDupGates;
    // create the new network
    pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_SOP );
    // make the mapper point to the new network
    Aig_ManConst1(p->pManAig)->pData = Abc_NtkCreateNodeConst1(pNtkNew);
    Abc_NtkForEachCi( pNtk, pNode, i )
1684
        Aig_ManCi(p->pManAig, i)->pData = pNode->pCopy;
Alan Mishchenko committed
1685 1686
    // process the nodes in topological order
    vCover = Vec_IntAlloc( 1 << 16 );
1687
    Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
Alan Mishchenko committed
1688 1689 1690 1691
    {
        // create new node
        pNodeNew = Abc_NtkCreateNode( pNtkNew );
        // add fanins according to the cut
1692
        pCut = (Cnf_Cut_t *)pObj->pData;
Alan Mishchenko committed
1693
        Cnf_CutForEachLeaf( p->pManAig, pCut, pLeaf, k )
1694
            Abc_ObjAddFanin( pNodeNew, (Abc_Obj_t *)pLeaf->pData );
Alan Mishchenko committed
1695 1696 1697 1698 1699
        // add logic function
        if ( pCut->nFanins < 5 )
        {
            uTruth = 0xFFFF & *Cnf_CutTruth(pCut);
            Cnf_SopConvertToVector( p->pSops[uTruth], p->pSopSizes[uTruth], vCover );
1700
            pNodeNew->pData = Abc_SopCreateFromIsop( (Mem_Flex_t *)pNtkNew->pManFunc, pCut->nFanins, vCover );
Alan Mishchenko committed
1701 1702
        }
        else
1703
            pNodeNew->pData = Abc_SopCreateFromIsop( (Mem_Flex_t *)pNtkNew->pManFunc, pCut->nFanins, pCut->vIsop[1] );
Alan Mishchenko committed
1704 1705 1706 1707 1708 1709 1710
        // save the node
        pObj->pData = pNodeNew;
    }
    Vec_IntFree( vCover );
    // add the CO drivers
    Abc_NtkForEachCo( pNtk, pNode, i )
    {
1711
        pObj = Aig_ManCo(p->pManAig, i);
1712
        pNodeNew = Abc_ObjNotCond( (Abc_Obj_t *)Aig_ObjFanin0(pObj)->pData, Aig_ObjFaninC0(pObj) );
Alan Mishchenko committed
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
        Abc_ObjAddFanin( pNode->pCopy, pNodeNew );
    }

    // remove the constant node if not used
    pNodeNew = (Abc_Obj_t *)Aig_ManConst1(p->pManAig)->pData;
    if ( Abc_ObjFanoutNum(pNodeNew) == 0 )
        Abc_NtkDeleteObj( pNodeNew );
    // minimize the node
//    Abc_NtkSweep( pNtkNew, 0 );
    // decouple the PO driver nodes to reduce the number of levels
    nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, 1 );
//    if ( nDupGates && If_ManReadVerbose(pIfMan) )
1725
//        Abc_Print( 1, "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
Alan Mishchenko committed
1726
    if ( !Abc_NtkCheck( pNtkNew ) )
1727
        Abc_Print( 1, "Abc_NtkConstructFromCnf(): Network check has failed.\n" );
Alan Mishchenko committed
1728 1729
    return pNtkNew;
}
Alan Mishchenko committed
1730
 
Alan Mishchenko committed
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
/**Function*************************************************************

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
1742
Abc_Ntk_t * Abc_NtkDarToCnf( Abc_Ntk_t * pNtk, char * pFileName, int fFastAlgo, int fChangePol, int fVerbose )
Alan Mishchenko committed
1743
{
1744
//    Vec_Ptr_t * vMapped = NULL;
Alan Mishchenko committed
1745
    Aig_Man_t * pMan;
1746
//    Cnf_Man_t * pManCnf = NULL;
Alan Mishchenko committed
1747 1748
    Cnf_Dat_t * pCnf;
    Abc_Ntk_t * pNtkNew = NULL;
1749
    abctime clk = Abc_Clock();
Alan Mishchenko committed
1750 1751 1752
    assert( Abc_NtkIsStrash(pNtk) );

    // convert to the AIG manager
Alan Mishchenko committed
1753
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
Alan Mishchenko committed
1754 1755 1756 1757
    if ( pMan == NULL )
        return NULL;
    if ( !Aig_ManCheck( pMan ) )
    {
1758
        Abc_Print( 1, "Abc_NtkDarToCnf: AIG check has failed.\n" );
Alan Mishchenko committed
1759 1760 1761 1762
        Aig_ManStop( pMan );
        return NULL;
    }
    // perform balance
1763
    if ( fVerbose )
Alan Mishchenko committed
1764 1765 1766
    Aig_ManPrintStats( pMan );

    // derive CNF
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
    if ( fFastAlgo )
        pCnf = Cnf_DeriveFast( pMan, 0 );
    else
        pCnf = Cnf_Derive( pMan, 0 );

    // adjust polarity
    if ( fChangePol )
        Cnf_DataTranformPolarity( pCnf, 0 );

    // print stats
1777
//    if ( fVerbose )
1778
    {
1779
        Abc_Print( 1, "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d.   ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
1780
        Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
1781
    }
Alan Mishchenko committed
1782

Alan Mishchenko committed
1783
/*
Alan Mishchenko committed
1784
    // write the network for verification
Alan Mishchenko committed
1785
    pManCnf = Cnf_ManRead();
Alan Mishchenko committed
1786 1787 1788
    vMapped = Cnf_ManScanMapping( pManCnf, 1, 0 );
    pNtkNew = Abc_NtkConstructFromCnf( pNtk, pManCnf, vMapped );
    Vec_PtrFree( vMapped );
Alan Mishchenko committed
1789
*/
Alan Mishchenko committed
1790
    // write CNF into a file
1791
    Cnf_DataWriteIntoFile( pCnf, pFileName, 0, NULL, NULL );
Alan Mishchenko committed
1792
    Cnf_DataFree( pCnf );
1793
    Cnf_ManFree();
Alan Mishchenko committed
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809
    Aig_ManStop( pMan );
    return pNtkNew;
}


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

  Synopsis    [Solves combinational miter using a SAT solver.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
1810
int Abc_NtkDSat( Abc_Ntk_t * pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int nLearnedStart, int nLearnedDelta, int nLearnedPerce, int fAlignPol, int fAndOuts, int fNewSolver, int fVerbose )
Alan Mishchenko committed
1811 1812
{
    Aig_Man_t * pMan;
1813
    int RetValue;//, clk = Abc_Clock();
Alan Mishchenko committed
1814 1815
    assert( Abc_NtkIsStrash(pNtk) );
    assert( Abc_NtkLatchNum(pNtk) == 0 );
1816
//    assert( Abc_NtkPoNum(pNtk) == 1 );
Alan Mishchenko committed
1817
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
1818
    RetValue = Fra_FraigSat( pMan, nConfLimit, nInsLimit, nLearnedStart, nLearnedDelta, nLearnedPerce, fAlignPol, fAndOuts, fNewSolver, fVerbose ); 
1819
    pNtk->pModel = (int *)pMan->pData, pMan->pData = NULL;
Alan Mishchenko committed
1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
    Aig_ManStop( pMan );
    return RetValue;
}

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

  Synopsis    [Solves combinational miter using a SAT solver.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkPartitionedSat( Abc_Ntk_t * pNtk, int nAlgo, int nPartSize, int nConfPart, int nConfTotal, int fAlignPol, int fSynthesize, int fVerbose )
{
    extern int Aig_ManPartitionedSat( Aig_Man_t * pNtk, int nAlgo, int nPartSize, int nConfPart, int nConfTotal, int fAlignPol, int fSynthesize, int fVerbose );
    Aig_Man_t * pMan;
1839
    int RetValue;//, clk = Abc_Clock();
Alan Mishchenko committed
1840 1841 1842 1843
    assert( Abc_NtkIsStrash(pNtk) );
    assert( Abc_NtkLatchNum(pNtk) == 0 );
    pMan = Abc_NtkToDar( pNtk, 0, 0 );
    RetValue = Aig_ManPartitionedSat( pMan, nAlgo, nPartSize, nConfPart, nConfTotal, fAlignPol, fSynthesize, fVerbose ); 
1844
    pNtk->pModel = (int *)pMan->pData, pMan->pData = NULL;
Alan Mishchenko committed
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
    Aig_ManStop( pMan );
    return RetValue;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1860
int Abc_NtkDarCec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int fPartition, int fVerbose )
Alan Mishchenko committed
1861 1862 1863
{
    Aig_Man_t * pMan, * pMan1, * pMan2;
    Abc_Ntk_t * pMiter;
1864
    int RetValue;
1865
    abctime clkTotal = Abc_Clock();
Alan Mishchenko committed
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876
/*
    {
    extern void Cec_ManVerifyTwoAigs( Aig_Man_t * pAig0, Aig_Man_t * pAig1, int fVerbose );
    Aig_Man_t * pAig0 = Abc_NtkToDar( pNtk1, 0, 0 );
    Aig_Man_t * pAig1 = Abc_NtkToDar( pNtk2, 0, 0 );
    Cec_ManVerifyTwoAigs( pAig0, pAig1, 1 );
    Aig_ManStop( pAig0 );
    Aig_ManStop( pAig1 );
    return 1;
    }
*/
Alan Mishchenko committed
1877 1878 1879
    // cannot partition if it is already a miter
    if ( pNtk2 == NULL && fPartition == 1 )
    {
1880
        Abc_Print( 1, "Abc_NtkDarCec(): Switching to non-partitioned CEC for the miter.\n" );
Alan Mishchenko committed
1881 1882 1883 1884 1885 1886
        fPartition = 0;
    }

    // if partitioning is selected, call partitioned CEC
    if ( fPartition )
    {
Alan Mishchenko committed
1887 1888
        pMan1 = Abc_NtkToDar( pNtk1, 0, 0 );
        pMan2 = Abc_NtkToDar( pNtk2, 0, 0 );
Alan Mishchenko committed
1889
        RetValue = Fra_FraigCecPartitioned( pMan1, pMan2, nConfLimit, 100, 1, fVerbose );
Alan Mishchenko committed
1890 1891 1892 1893 1894 1895 1896 1897
        Aig_ManStop( pMan1 );
        Aig_ManStop( pMan2 );
        goto finish;
    }

    if ( pNtk2 != NULL )
    {
        // get the miter of the two networks
Alan Mishchenko committed
1898
        pMiter = Abc_NtkMiter( pNtk1, pNtk2, 0, 0, 0, 0 );
Alan Mishchenko committed
1899 1900
        if ( pMiter == NULL )
        {
1901
            Abc_Print( 1, "Miter computation has failed.\n" );
Alan Mishchenko committed
1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912
            return 0;
        }
    }
    else
    {
        pMiter = Abc_NtkDup( pNtk1 );
    }
    RetValue = Abc_NtkMiterIsConstant( pMiter );
    if ( RetValue == 0 )
    {
//        extern void Abc_NtkVerifyReportErrorSeq( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int * pModel, int nFrames );
1913
        Abc_Print( 1, "Networks are NOT EQUIVALENT after structural hashing.\n" );
Alan Mishchenko committed
1914 1915 1916 1917 1918
        // report the error
        if ( pNtk2 == NULL )
            pNtk1->pModel = Abc_NtkVerifyGetCleanModel( pNtk1, 1 );
//        pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, nFrames );
//        Abc_NtkVerifyReportErrorSeq( pNtk1, pNtk2, pMiter->pModel, nFrames );
Alan Mishchenko committed
1919
//        ABC_FREE( pMiter->pModel );
Alan Mishchenko committed
1920 1921 1922 1923 1924 1925
        Abc_NtkDelete( pMiter );
        return 0;
    }
    if ( RetValue == 1 )
    {
        Abc_NtkDelete( pMiter );
1926
        Abc_Print( 1, "Networks are equivalent after structural hashing.\n" );
Alan Mishchenko committed
1927 1928 1929 1930
        return 1;
    }

    // derive the AIG manager
Alan Mishchenko committed
1931
    pMan = Abc_NtkToDar( pMiter, 0, 0 );
Alan Mishchenko committed
1932 1933 1934
    Abc_NtkDelete( pMiter );
    if ( pMan == NULL )
    {
1935
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
1936 1937 1938
        return -1;
    }
    // perform verification
Alan Mishchenko committed
1939
    RetValue = Fra_FraigCec( &pMan, 100000, fVerbose );
Alan Mishchenko committed
1940 1941
    // transfer model if given
    if ( pNtk2 == NULL )
1942
        pNtk1->pModel = (int *)pMan->pData, pMan->pData = NULL;
Alan Mishchenko committed
1943 1944 1945 1946 1947 1948
    Aig_ManStop( pMan );

finish:
    // report the miter
    if ( RetValue == 1 )
    {
1949
        Abc_Print( 1, "Networks are equivalent.   " );
1950
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
1951 1952 1953
    }
    else if ( RetValue == 0 )
    {
1954
        Abc_Print( 1, "Networks are NOT EQUIVALENT.   " );
1955
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
1956 1957 1958
    }
    else
    {
1959
        Abc_Print( 1, "Networks are UNDECIDED.   " );
1960
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
    }
    fflush( stdout );
    return RetValue;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1977
Abc_Ntk_t * Abc_NtkDarSeqSweep( Abc_Ntk_t * pNtk, Fra_Ssw_t * pPars )
Alan Mishchenko committed
1978 1979
{
    Fraig_Params_t Params;
Alan Mishchenko committed
1980
    Abc_Ntk_t * pNtkAig = NULL, * pNtkFraig;
Alan Mishchenko committed
1981
    Aig_Man_t * pMan, * pTemp;
1982
    abctime clk = Abc_Clock();
Alan Mishchenko committed
1983 1984 1985 1986 1987 1988

    // preprocess the miter by fraiging it
    // (note that for each functional class, fraiging leaves one representative;
    // so fraiging does not reduce the number of functions represented by nodes
    Fraig_ParamsSetDefault( &Params );
    Params.nBTLimit = 100000;
Alan Mishchenko committed
1989 1990
    if ( pPars->fFraiging && pPars->nPartSize == 0 )
    {
Alan Mishchenko committed
1991
        pNtkFraig = Abc_NtkFraig( pNtk, &Params, 0, 0 );
Alan Mishchenko committed
1992
if ( pPars->fVerbose ) 
Alan Mishchenko committed
1993
{
1994
ABC_PRT( "Initial fraiging time", Abc_Clock() - clk );
Alan Mishchenko committed
1995
}
Alan Mishchenko committed
1996 1997 1998
    }
    else
        pNtkFraig = Abc_NtkDup( pNtk );
Alan Mishchenko committed
1999

Alan Mishchenko committed
2000
    pMan = Abc_NtkToDar( pNtkFraig, 0, 1 );
Alan Mishchenko committed
2001 2002 2003 2004
    Abc_NtkDelete( pNtkFraig );
    if ( pMan == NULL )
        return NULL;

Alan Mishchenko committed
2005
//    pPars->TimeLimit = 5.0;
Alan Mishchenko committed
2006
    pMan = Fra_FraigInduction( pTemp = pMan, pPars );
Alan Mishchenko committed
2007
    Aig_ManStop( pTemp );
Alan Mishchenko committed
2008
    if ( pMan )
Alan Mishchenko committed
2009
    {
Alan Mishchenko committed
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020
        if ( Aig_ManRegNum(pMan) < Abc_NtkLatchNum(pNtk) )
            pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
        else
        {
            Abc_Obj_t * pObj;
            int i;
            pNtkAig = Abc_NtkFromDar( pNtk, pMan );
            Abc_NtkForEachLatch( pNtkAig, pObj, i )
                Abc_LatchSetInit0( pObj );
        }
        Aig_ManStop( pMan );
Alan Mishchenko committed
2021 2022 2023 2024 2025 2026
    }
    return pNtkAig;
}

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

Alan Mishchenko committed
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037
  Synopsis    [Print Latch Equivalence Classes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkPrintLatchEquivClasses( Abc_Ntk_t * pNtk, Aig_Man_t * pAig )
{
2038
    int header_dumped = 0;
Alan Mishchenko committed
2039
    int num_orig_latches = Abc_NtkLatchNum(pNtk);
Alan Mishchenko committed
2040
    char **pNames = ABC_ALLOC( char *, num_orig_latches );
2041
    int *p_irrelevant = ABC_ALLOC( int, num_orig_latches );
Alan Mishchenko committed
2042 2043 2044 2045 2046 2047 2048 2049 2050
    char * pFlopName, * pReprName;
    Aig_Obj_t * pFlop, * pRepr;
    Abc_Obj_t * pNtkFlop; 
    int repr_idx;
    int i;

    Abc_NtkForEachLatch( pNtk, pNtkFlop, i )
    {
        char *temp_name = Abc_ObjName( Abc_ObjFanout0(pNtkFlop) );
Alan Mishchenko committed
2051
        pNames[i] = ABC_ALLOC( char , strlen(temp_name)+1);
Alan Mishchenko committed
2052 2053 2054 2055
        strcpy(pNames[i], temp_name);
    }
    i = 0;
    
2056
    Aig_ManSetCioIds( pAig );
Alan Mishchenko committed
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066
    Saig_ManForEachLo( pAig, pFlop, i )
    {
        p_irrelevant[i] = false;
        
        pFlopName = pNames[i];

        pRepr = Aig_ObjRepr(pAig, pFlop);

        if ( pRepr == NULL )
        {
2067
            // Abc_Print( 1, "Nothing equivalent to flop %s\n", pFlopName);
Alan Mishchenko committed
2068
//            p_irrelevant[i] = true;
Alan Mishchenko committed
2069 2070 2071 2072 2073
            continue;
        }

        if (!header_dumped)
        {
2074
            Abc_Print( 1, "Here are the flop equivalences:\n");
Alan Mishchenko committed
2075 2076 2077 2078 2079 2080
            header_dumped = true;
        }

        // pRepr is representative of the equivalence class, to which pFlop belongs
        if ( Aig_ObjIsConst1(pRepr) )
        {
2081 2082
            Abc_Print( 1, "Original flop %s is proved equivalent to constant.\n", pFlopName );
            // Abc_Print( 1, "Original flop # %d is proved equivalent to constant.\n", i );
Alan Mishchenko committed
2083 2084 2085 2086
            continue;
        }

        assert( Saig_ObjIsLo( pAig, pRepr ) );
2087
        repr_idx = Aig_ObjCioId(pRepr) - Saig_ManPiNum(pAig);
Alan Mishchenko committed
2088
        pReprName = pNames[repr_idx];
2089 2090
        Abc_Print( 1, "Original flop %s is proved equivalent to flop %s.\n",  pFlopName, pReprName );
        // Abc_Print( 1, "Original flop # %d is proved equivalent to flop # %d.\n",  i, repr_idx );
Alan Mishchenko committed
2091 2092 2093 2094 2095 2096 2097 2098 2099
    }

    header_dumped = false;
    for (i=0; i<num_orig_latches; ++i)
    {
        if (p_irrelevant[i])
        {
            if (!header_dumped)
            {
2100
                Abc_Print( 1, "The following flops have been deemed irrelevant:\n");
Alan Mishchenko committed
2101 2102
                header_dumped = true;
            }
2103
            Abc_Print( 1, "%s ", pNames[i]);
Alan Mishchenko committed
2104 2105
        }
        
Alan Mishchenko committed
2106
        ABC_FREE(pNames[i]);
Alan Mishchenko committed
2107 2108
    }
    if (header_dumped)
2109
        Abc_Print( 1, "\n");
Alan Mishchenko committed
2110
    
Alan Mishchenko committed
2111 2112
    ABC_FREE(pNames);
    ABC_FREE(p_irrelevant);
Alan Mishchenko committed
2113 2114 2115 2116
}

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

Alan Mishchenko committed
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135
  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarSeqSweep2( Abc_Ntk_t * pNtk, Ssw_Pars_t * pPars )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;

    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;

    pMan = Ssw_SignalCorrespondence( pTemp = pMan, pPars );
Alan Mishchenko committed
2136 2137 2138 2139

    if ( pPars->fFlopVerbose )
        Abc_NtkPrintLatchEquivClasses(pNtk, pTemp);

2140
    Aig_ManStop( pTemp );
Alan Mishchenko committed
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159
    if ( pMan == NULL )
        return NULL;

    if ( Aig_ManRegNum(pMan) < Abc_NtkLatchNum(pNtk) )
        pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    else
    {
        Abc_Obj_t * pObj;
        int i;
        pNtkAig = Abc_NtkFromDar( pNtk, pMan );
        Abc_NtkForEachLatch( pNtkAig, pObj, i )
            Abc_LatchSetInit0( pObj );
    }
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

Alan Mishchenko committed
2160 2161
  Synopsis    [Computes latch correspondence.]

Alan Mishchenko committed
2162
  Description [] 
Alan Mishchenko committed
2163 2164 2165 2166 2167 2168 2169 2170 2171
               
  SideEffects []

  SeeAlso     []
 
***********************************************************************/
Abc_Ntk_t * Abc_NtkDarLcorr( Abc_Ntk_t * pNtk, int nFramesP, int nConfMax, int fVerbose )
{
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
2172
    Abc_Ntk_t * pNtkAig = NULL;
Alan Mishchenko committed
2173
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
2174 2175
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
2176
    pMan = Fra_FraigLatchCorrespondence( pTemp = pMan, nFramesP, nConfMax, 0, fVerbose, NULL, 0.0 );
Alan Mishchenko committed
2177
    Aig_ManStop( pTemp );
Alan Mishchenko committed
2178
    if ( pMan )
Alan Mishchenko committed
2179
    {
Alan Mishchenko committed
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
        if ( Aig_ManRegNum(pMan) < Abc_NtkLatchNum(pNtk) )
            pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
        else
        {
            Abc_Obj_t * pObj;
            int i;
            pNtkAig = Abc_NtkFromDar( pNtk, pMan );
            Abc_NtkForEachLatch( pNtkAig, pObj, i )
                Abc_LatchSetInit0( pObj );
        }
        Aig_ManStop( pMan );
Alan Mishchenko committed
2191 2192 2193 2194 2195 2196
    }
    return pNtkAig;
}

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

Alan Mishchenko committed
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237
  Synopsis    [Computes latch correspondence.]

  Description [] 
               
  SideEffects []

  SeeAlso     []
 
***********************************************************************/
Abc_Ntk_t * Abc_NtkDarLcorrNew( Abc_Ntk_t * pNtk, int nVarsMax, int nConfMax, int fVerbose )
{
    Ssw_Pars_t Pars, * pPars = &Pars;
    Aig_Man_t * pMan, * pTemp;
    Abc_Ntk_t * pNtkAig = NULL;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    Ssw_ManSetDefaultParams( pPars );
    pPars->fLatchCorrOpt = 1;
    pPars->nBTLimit      = nConfMax;
    pPars->nSatVarMax    = nVarsMax;
    pPars->fVerbose      = fVerbose;
    pMan = Ssw_SignalCorrespondence( pTemp = pMan, pPars );
    Aig_ManStop( pTemp );
    if ( pMan )
    {
        if ( Aig_ManRegNum(pMan) < Abc_NtkLatchNum(pNtk) )
            pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
        else
        {
            Abc_Obj_t * pObj;
            int i;
            pNtkAig = Abc_NtkFromDar( pNtk, pMan );
            Abc_NtkForEachLatch( pNtkAig, pObj, i )
                Abc_LatchSetInit0( pObj );
        }
        Aig_ManStop( pMan );
    }
    return pNtkAig;
}

Alan Mishchenko committed
2238 2239
/*
#include <signal.h>
2240
#include "misc/util/utilMem.h"
Alan Mishchenko committed
2241 2242 2243
static void sigfunc( int signo ) 
{
    if (signo == SIGINT) {
2244
        Abc_Print( 1, "SIGINT received!\n");
Alan Mishchenko committed
2245 2246 2247 2248 2249
        s_fInterrupt = 1;
    }
}
*/

Alan Mishchenko committed
2250 2251
/**Function*************************************************************

Alan Mishchenko committed
2252 2253 2254 2255 2256 2257 2258 2259 2260
  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2261
int Abc_NtkDarBmc( Abc_Ntk_t * pNtk, int nStart, int nFrames, int nSizeMax, int nNodeDelta, int nTimeOut, int nBTLimit, int nBTLimitAll, int fRewrite, int fNewAlgo, int fOrDecomp, int nCofFanLit, int fVerbose, int * piFrames )
Alan Mishchenko committed
2262 2263
{
    Aig_Man_t * pMan;
2264
    Vec_Int_t * vMap = NULL;
2265
    int status, RetValue = -1;
2266 2267
    abctime clk = Abc_Clock();
    abctime nTimeLimit = nTimeOut ? nTimeOut * CLOCKS_PER_SEC + Abc_Clock(): 0;
Alan Mishchenko committed
2268
    // derive the AIG manager
2269 2270 2271 2272
    if ( fOrDecomp )
        pMan = Abc_NtkToDarBmc( pNtk, &vMap );
    else
        pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
2273 2274
    if ( pMan == NULL )
    {
2275
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
2276
        return RetValue;
Alan Mishchenko committed
2277 2278
    }
    assert( pMan->nRegs > 0 );
2279
    assert( vMap == NULL || Vec_IntSize(vMap) == Saig_ManPoNum(pMan) );
2280
    if ( fVerbose && vMap && Abc_NtkPoNum(pNtk) != Saig_ManPoNum(pMan) ) 
2281
        Abc_Print( 1, "Expanded %d outputs into %d outputs using OR decomposition.\n", Abc_NtkPoNum(pNtk), Saig_ManPoNum(pMan) );
2282

Alan Mishchenko committed
2283
    // perform verification
2284
    if ( fNewAlgo ) // command 'bmc'
Alan Mishchenko committed
2285
    {
Alan Mishchenko committed
2286
        int iFrame;
Alan Mishchenko committed
2287
        RetValue = Saig_ManBmcSimple( pMan, nFrames, nSizeMax, nBTLimit, fRewrite, fVerbose, &iFrame, nCofFanLit );
2288 2289
        if ( piFrames )
            *piFrames = iFrame;
Alan Mishchenko committed
2290 2291
        ABC_FREE( pNtk->pModel );
        ABC_FREE( pNtk->pSeqModel );
Alan Mishchenko committed
2292
        pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
Alan Mishchenko committed
2293
        if ( RetValue == 1 )
2294
            Abc_Print( 1, "Incorrect return value.  " );
Alan Mishchenko committed
2295
        else if ( RetValue == -1 )
2296
        {
2297
            Abc_Print( 1, "No output asserted in %d frames. Resource limit reached ", Abc_MaxInt(iFrame+1,0) );
2298
            if ( nTimeLimit && Abc_Clock() > nTimeLimit )
2299
                Abc_Print( 1, "(timeout %d sec). ", nTimeLimit );
2300
            else
2301
                Abc_Print( 1, "(conf limit %d). ", nBTLimit );
2302
        }
Alan Mishchenko committed
2303 2304
        else // if ( RetValue == 0 )
        {
2305
            Abc_Cex_t * pCex = pNtk->pSeqModel;
2306
            Abc_Print( 1, "Output %d of miter \"%s\" was asserted in frame %d. ", pCex->iPo, pNtk->pName, pCex->iFrame );
Alan Mishchenko committed
2307
        }
2308
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
2309 2310
    }
    else
2311
    { 
2312
        RetValue = Saig_BmcPerform( pMan, nStart, nFrames, nNodeDelta, nTimeOut, nBTLimit, nBTLimitAll, fVerbose, 0, piFrames, 0 );
Alan Mishchenko committed
2313 2314
        ABC_FREE( pNtk->pModel );
        ABC_FREE( pNtk->pSeqModel );
Alan Mishchenko committed
2315
        pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
Alan Mishchenko committed
2316
    }
Alan Mishchenko committed
2317 2318 2319
    // verify counter-example
    if ( pNtk->pSeqModel ) 
    {
2320
        status = Saig_ManVerifyCex( pMan, pNtk->pSeqModel );
Alan Mishchenko committed
2321
        if ( status == 0 )
2322
            Abc_Print( 1, "Abc_NtkDarBmc(): Counter-example verification has FAILED.\n" );
Alan Mishchenko committed
2323
    }
Alan Mishchenko committed
2324
    Aig_ManStop( pMan );
2325 2326 2327
    // update the counter-example
    if ( pNtk->pSeqModel && vMap )
        pNtk->pSeqModel->iPo = Vec_IntEntry( vMap, pNtk->pSeqModel->iPo );
2328
    Vec_IntFreeP( &vMap );
Alan Mishchenko committed
2329
    return RetValue;
Alan Mishchenko committed
2330 2331 2332 2333
}

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

2334 2335 2336 2337 2338 2339 2340 2341 2342
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2343
int Abc_NtkDarBmc3( Abc_Ntk_t * pNtk, Saig_ParBmc_t * pPars, int fOrDecomp )
2344 2345
{
    Aig_Man_t * pMan;
2346
    Vec_Int_t * vMap = NULL;
2347
    int status, RetValue = -1;
2348 2349
    abctime clk = Abc_Clock();
    abctime nTimeOut = pPars->nTimeOut ? pPars->nTimeOut * CLOCKS_PER_SEC + Abc_Clock(): 0;
2350
    if ( fOrDecomp && !pPars->fSolveAll )
2351
        pMan = Abc_NtkToDarBmc( pNtk, &vMap );
2352 2353
    else
        pMan = Abc_NtkToDar( pNtk, 0, 1 );
2354 2355
    if ( pMan == NULL )
    {
2356
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
2357 2358 2359
        return RetValue;
    }
    assert( pMan->nRegs > 0 );
2360
    if ( pPars->fVerbose && vMap && Abc_NtkPoNum(pNtk) != Saig_ManPoNum(pMan) ) 
2361
        Abc_Print( 1, "Expanded %d outputs into %d outputs using OR decomposition.\n", Abc_NtkPoNum(pNtk), Saig_ManPoNum(pMan) );
2362

2363 2364 2365 2366
    RetValue = Saig_ManBmcScalable( pMan, pPars );
    ABC_FREE( pNtk->pModel );
    ABC_FREE( pNtk->pSeqModel );
    pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
2367
    if ( !pPars->fSilent )
2368
    {
2369
        if ( RetValue == 1 )
2370
        {
2371
            Abc_Print( 1, "Explored all reachable states after completing %d frames.  ", 1<<Aig_ManRegNum(pMan) );
2372
        }
2373
        else if ( RetValue == -1 )
2374
        {
2375 2376
            if ( pPars->nFailOuts == 0 )
            {
2377
                Abc_Print( 1, "No output asserted in %d frames. Resource limit reached ", Abc_MaxInt(pPars->iFrame+1,0) );
2378 2379 2380 2381 2382
                if ( nTimeOut && Abc_Clock() > nTimeOut )
                    Abc_Print( 1, "(timeout %d sec). ", pPars->nTimeOut );
                else
                    Abc_Print( 1, "(conf limit %d). ", pPars->nConfLimit );
            }
2383
            else
2384 2385 2386 2387 2388 2389 2390
            {
                Abc_Print( 1, "The total of %d outputs asserted in %d frames. Resource limit reached ", pPars->nFailOuts, pPars->iFrame );
                if ( Abc_Clock() > nTimeOut )
                    Abc_Print( 1, "(timeout %d sec). ", pPars->nTimeOut );
                else
                    Abc_Print( 1, "(conf limit %d). ", pPars->nConfLimit );
            }
2391
        }
2392
        else // if ( RetValue == 0 )
2393
        {
2394 2395 2396 2397 2398
            if ( !pPars->fSolveAll )
            {
                Abc_Cex_t * pCex = pNtk->pSeqModel;
                Abc_Print( 1, "Output %d of miter \"%s\" was asserted in frame %d. ", pCex->iPo, pNtk->pName, pCex->iFrame );
            }
Alan Mishchenko committed
2399
            else
2400
            {
2401 2402
                int nOutputs = Saig_ManPoNum(pMan) - Saig_ManConstrNum(pMan);
                if ( pMan->vSeqModelVec == NULL || Vec_PtrCountZero(pMan->vSeqModelVec) == nOutputs )
2403
                    Abc_Print( 1, "None of the %d outputs is found to be SAT", nOutputs );
2404
                else if ( Vec_PtrCountZero(pMan->vSeqModelVec) == 0 )
2405
                    Abc_Print( 1, "All %d outputs are found to be SAT", nOutputs );
2406 2407 2408 2409 2410 2411
                else
                {
                    Abc_Print( 1, "Some outputs are SAT (%d out of %d)", nOutputs - Vec_PtrCountZero(pMan->vSeqModelVec), nOutputs );
                    if ( pPars->nDropOuts )
                        Abc_Print( 1, " while others timed out (%d out of %d)", pPars->nDropOuts, nOutputs );
                }
2412
                Abc_Print( 1, " after %d frames", pPars->iFrame+2 );
2413
                Abc_Print( 1, ".   " );
2414
            }
2415
        }
2416 2417 2418 2419 2420 2421 2422
        ABC_PRT( "Time", Abc_Clock() - clk );
    }
    if ( RetValue == 0 && pPars->fSolveAll )
    {
        if ( pNtk->vSeqModelVec )
            Vec_PtrFreeFree( pNtk->vSeqModelVec );
        pNtk->vSeqModelVec = pMan->vSeqModelVec;  pMan->vSeqModelVec = NULL;
2423 2424 2425
    }
    if ( pNtk->pSeqModel ) 
    {
2426
        status = Saig_ManVerifyCex( pMan, pNtk->pSeqModel );
2427
        if ( status == 0 )
2428
            Abc_Print( 1, "Abc_NtkDarBmc3(): Counter-example verification has FAILED.\n" );
2429 2430
    }
    Aig_ManStop( pMan );
2431 2432 2433
    // update the counter-example
    if ( pNtk->pSeqModel && vMap )
        pNtk->pSeqModel->iPo = Vec_IntEntry( vMap, pNtk->pSeqModel->iPo );
2434
    Vec_IntFreeP( &vMap );
2435 2436 2437 2438 2439
    return RetValue;
}

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

Alan Mishchenko committed
2440 2441 2442 2443 2444 2445 2446 2447 2448
  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2449
int Abc_NtkDarBmcInter_int( Aig_Man_t * pMan, Inter_ManParams_t * pPars, Aig_Man_t ** ppNtkRes )
Alan Mishchenko committed
2450
{
2451
    int RetValue = -1, iFrame;
2452
    abctime clk = Abc_Clock();
2453
    int nTotalProvedSat = 0;
Alan Mishchenko committed
2454
    assert( pMan->nRegs > 0 );
2455 2456
    if ( ppNtkRes )
        *ppNtkRes = NULL;
Alan Mishchenko committed
2457
    if ( pPars->fUseSeparate )
Alan Mishchenko committed
2458
    {
Alan Mishchenko committed
2459 2460 2461 2462 2463 2464 2465
        Aig_Man_t * pTemp, * pAux;
        Aig_Obj_t * pObjPo;
        int i, Counter = 0;
        Saig_ManForEachPo( pMan, pObjPo, i )
        {
            if ( Aig_ObjFanin0(pObjPo) == Aig_ManConst1(pMan) )
                continue;
2466
            if ( pPars->fVerbose )
2467
                Abc_Print( 1, "Solving output %2d (out of %2d):\n", i, Saig_ManPoNum(pMan) );
Alan Mishchenko committed
2468
            pTemp = Aig_ManDupOneOutput( pMan, i, 1 );
2469
            pTemp = Aig_ManScl( pAux = pTemp, 1, 1, 0, -1, -1, 0, 0 );
Alan Mishchenko committed
2470
            Aig_ManStop( pAux );
2471 2472 2473
            if ( Aig_ManRegNum(pTemp) == 0 )
            {
                pTemp->pSeqModel = NULL;
2474
                RetValue = Fra_FraigSat( pTemp, pPars->nBTLimit, 0, 0, 0, 0, 0, 0, 0, 0 ); 
2475
                if ( pTemp->pData )
2476
                    pTemp->pSeqModel = Abc_CexCreate( Aig_ManRegNum(pMan), Saig_ManPiNum(pMan), (int *)pTemp->pData, 0, i, 1 );
2477 2478 2479 2480
//                pNtk->pModel = pTemp->pData, pTemp->pData = NULL;
            }
            else
                RetValue = Inter_ManPerformInterpolation( pTemp, pPars, &iFrame );
Alan Mishchenko committed
2481 2482
            if ( pTemp->pSeqModel )
            {
2483 2484
                if ( pPars->fDropSatOuts )
                {
2485
                    Abc_Print( 1, "Output %d proved SAT in frame %d (replacing by const 0 and continuing...)\n", i, pTemp->pSeqModel->iFrame );
2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498
                    Aig_ObjPatchFanin0( pMan, pObjPo, Aig_ManConst0(pMan) );
                    Aig_ManStop( pTemp );
                    nTotalProvedSat++;
                    continue;
                }
                else
                {
                    Abc_Cex_t * pCex;
                    pCex = pMan->pSeqModel = pTemp->pSeqModel; pTemp->pSeqModel = NULL;
                    pCex->iPo = i;
                    Aig_ManStop( pTemp );
                    break;
                }
Alan Mishchenko committed
2499 2500 2501 2502 2503
            }
            // if solved, remove the output
            if ( RetValue == 1 )
            {
                Aig_ObjPatchFanin0( pMan, pObjPo, Aig_ManConst0(pMan) );
2504
//                    Abc_Print( 1, "Output %3d : Solved ", i );
Alan Mishchenko committed
2505 2506 2507 2508
            }
            else
            {
                Counter++;
2509
//                    Abc_Print( 1, "Output %3d : Undec  ", i );
Alan Mishchenko committed
2510 2511 2512
            }
//                Aig_ManPrintStats( pTemp );
            Aig_ManStop( pTemp );
2513
            Abc_Print( 1, "Solving output %3d (out of %3d) using interpolation.\r", i, Saig_ManPoNum(pMan) );
Alan Mishchenko committed
2514 2515 2516 2517
        }
        Aig_ManCleanup( pMan );
        if ( pMan->pSeqModel == NULL )
        {
2518
            Abc_Print( 1, "Interpolation left %d (out of %d) outputs unsolved              \n", Counter, Saig_ManPoNum(pMan) );
Alan Mishchenko committed
2519 2520 2521
            if ( Counter )
                RetValue = -1;
        }
2522 2523 2524
        if ( ppNtkRes )
        {
            pTemp = Aig_ManDupUnsolvedOutputs( pMan, 1 );
2525
            *ppNtkRes = Aig_ManScl( pTemp, 1, 1, 0, -1, -1, 0, 0 );
2526 2527
            Aig_ManStop( pTemp );
        }
Alan Mishchenko committed
2528 2529 2530 2531
    }
    else
    {    
        RetValue = Inter_ManPerformInterpolation( pMan, pPars, &iFrame );
Alan Mishchenko committed
2532
    }
2533
    if ( nTotalProvedSat )
2534
        Abc_Print( 1, "The total of %d outputs proved SAT and replaced by const 0 in this run.\n", nTotalProvedSat );
Alan Mishchenko committed
2535
    if ( RetValue == 1 )
2536
        Abc_Print( 1, "Property proved.  " );
Alan Mishchenko committed
2537
    else if ( RetValue == 0 )
2538
        Abc_Print( 1, "Output %d of miter \"%s\" was asserted in frame %d.  ", pMan->pSeqModel ? pMan->pSeqModel->iPo : -1, pMan->pName, iFrame );
Alan Mishchenko committed
2539
    else if ( RetValue == -1 )
2540
        Abc_Print( 1, "Property UNDECIDED.  " );
Alan Mishchenko committed
2541 2542
    else
        assert( 0 );
2543
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
    return RetValue;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2558
int Abc_NtkDarBmcInter( Abc_Ntk_t * pNtk, Inter_ManParams_t * pPars, Abc_Ntk_t ** ppNtkRes )
Alan Mishchenko committed
2559 2560
{
    Aig_Man_t * pMan;
2561 2562 2563
    int RetValue;
    if ( ppNtkRes )
        *ppNtkRes = NULL;
Alan Mishchenko committed
2564 2565 2566
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
    {
2567
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
2568 2569
        return -1;
    }
2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580
    if ( pPars->fUseSeparate && ppNtkRes )
    {
        Aig_Man_t * pManNew;
        RetValue = Abc_NtkDarBmcInter_int( pMan, pPars, &pManNew );
        *ppNtkRes = Abc_NtkFromAigPhase( pManNew );
        Aig_ManStop( pManNew );
    }
    else
    {
        RetValue = Abc_NtkDarBmcInter_int( pMan, pPars, NULL );
    }
Alan Mishchenko committed
2581 2582 2583
    ABC_FREE( pNtk->pModel );
    ABC_FREE( pNtk->pSeqModel );
    pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
Alan Mishchenko committed
2584
    Aig_ManStop( pMan );
2585
    return RetValue;
Alan Mishchenko committed
2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
2599 2600
int Abc_NtkDarDemiter( Abc_Ntk_t * pNtk )
{ 
2601
    char * pFileNameGeneric, pFileName0[1000], pFileName1[1000];
Alan Mishchenko committed
2602
    Aig_Man_t * pMan, * pPart0, * pPart1;//, * pMiter;
Alan Mishchenko committed
2603 2604 2605 2606
    // derive the AIG manager
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
    {
2607
        Abc_Print( 1, "Converting network into AIG has failed.\n" );
Alan Mishchenko committed
2608 2609
        return 0;
    }
Alan Mishchenko committed
2610 2611
//    if ( !Saig_ManDemiterSimple( pMan, &pPart0, &pPart1 ) )
    if ( !Saig_ManDemiterSimpleDiff( pMan, &pPart0, &pPart1 ) )
Alan Mishchenko committed
2612
    {
2613
        Aig_ManStop( pMan );
2614
        Abc_Print( 1, "Demitering has failed.\n" );
Alan Mishchenko committed
2615 2616
        return 0;
    }
2617
    // create file names
2618
    pFileNameGeneric = Extra_FileNameGeneric( pNtk->pSpec ? pNtk->pSpec : pNtk->pName );
2619 2620 2621 2622
//    sprintf( pFileName0,  "%s%s",  pFileNameGeneric, "_part0.aig" ); 
//    sprintf( pFileName1,  "%s%s",  pFileNameGeneric, "_part1.aig" ); 
    sprintf( pFileName0,  "%s",  "part0.aig" ); 
    sprintf( pFileName1,  "%s",  "part1.aig" ); 
2623 2624 2625 2626
    ABC_FREE( pFileNameGeneric );
    // dump files
    Ioa_WriteAiger( pPart0, pFileName0, 0, 0 );
    Ioa_WriteAiger( pPart1, pFileName1, 0, 0 );
2627
    Abc_Print( 1, "Demitering produced two files \"%s\" and \"%s\".\n", pFileName0, pFileName1 );
2628 2629 2630 2631
    // create two-level miter
//    pMiter = Saig_ManCreateMiterTwo( pPart0, pPart1, 2 );
//    Aig_ManDumpBlif( pMiter, "miter01.blif", NULL, NULL );
//    Aig_ManStop( pMiter );
2632
//    Abc_Print( 1, "The new miter is written into file \"%s\".\n", "miter01.blif" );
2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657
    Aig_ManStop( pPart0 );
    Aig_ManStop( pPart1 );
    Aig_ManStop( pMan );
    return 1;
} 

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkDarDemiterNew( Abc_Ntk_t * pNtk )
{ 
    char * pFileNameGeneric, pFileName0[1000], pFileName1[1000];
    Aig_Man_t * pMan, * pPart0, * pPart1;//, * pMiter;
    // derive the AIG manager
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
    {
2658
        Abc_Print( 1, "Converting network into AIG has failed.\n" );
2659 2660 2661 2662 2663 2664 2665 2666 2667 2668
        return 0;
    }

    Saig_ManDemiterNew( pMan );
    Aig_ManStop( pMan );
    return 1;

//    if ( !Saig_ManDemiterSimple( pMan, &pPart0, &pPart1 ) )
    if ( !Saig_ManDemiterSimpleDiff( pMan, &pPart0, &pPart1 ) )
    {
2669
        Abc_Print( 1, "Demitering has failed.\n" );
2670 2671 2672 2673 2674 2675 2676 2677 2678 2679
        return 0;
    }
    // create file names
    pFileNameGeneric = Extra_FileNameGeneric( pNtk->pSpec );
    sprintf( pFileName0,  "%s%s",  pFileNameGeneric, "_part0.aig" ); 
    sprintf( pFileName1,  "%s%s",  pFileNameGeneric, "_part1.aig" ); 
    ABC_FREE( pFileNameGeneric );
    // dump files
    Ioa_WriteAiger( pPart0, pFileName0, 0, 0 );
    Ioa_WriteAiger( pPart1, pFileName1, 0, 0 );
2680
    Abc_Print( 1, "Demitering produced two files \"%s\" and \"%s\".\n", pFileName0, pFileName1 );
Alan Mishchenko committed
2681
    // create two-level miter
Alan Mishchenko committed
2682 2683 2684
//    pMiter = Saig_ManCreateMiterTwo( pPart0, pPart1, 2 );
//    Aig_ManDumpBlif( pMiter, "miter01.blif", NULL, NULL );
//    Aig_ManStop( pMiter );
2685
//    Abc_Print( 1, "The new miter is written into file \"%s\".\n", "miter01.blif" );
Alan Mishchenko committed
2686 2687 2688 2689
    Aig_ManStop( pPart0 );
    Aig_ManStop( pPart1 );
    Aig_ManStop( pMan );
    return 1;
Alan Mishchenko committed
2690
} 
2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkDarDemiterDual( Abc_Ntk_t * pNtk, int fVerbose )
{ 
    char * pFileNameGeneric, pFileName0[1000], pFileName1[1000];
    Aig_Man_t * pMan, * pPart0, * pPart1;//, * pMiter;
    if ( (Abc_NtkPoNum(pNtk) & 1) )
    {
2709
        Abc_Print( 1, "The number of POs should be even.\n" );
2710 2711 2712 2713 2714 2715
        return 0;
    }
    // derive the AIG manager
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
    {
2716
        Abc_Print( 1, "Converting network into AIG has failed.\n" );
2717 2718 2719 2720 2721
        return 0;
    }
//    if ( !Saig_ManDemiterSimple( pMan, &pPart0, &pPart1 ) )
    if ( !Saig_ManDemiterDual( pMan, &pPart0, &pPart1 ) )
    {
2722
        Abc_Print( 1, "Demitering has failed.\n" );
2723 2724 2725 2726
        return 0;
    }
    // create new AIG
    ABC_FREE( pPart0->pName );
2727
    pPart0->pName = Abc_UtilStrsav( "part0" );
2728 2729
    // create new AIGs
    ABC_FREE( pPart1->pName );
2730
    pPart1->pName = Abc_UtilStrsav( "part1" );
2731 2732
    // create file names
    pFileNameGeneric = Extra_FileNameGeneric( pNtk->pSpec );
2733 2734 2735 2736
//    sprintf( pFileName0,  "%s%s",  pFileNameGeneric, "_part0.aig" ); 
//    sprintf( pFileName1,  "%s%s",  pFileNameGeneric, "_part1.aig" ); 
    sprintf( pFileName0,  "%s",  "part0.aig" ); 
    sprintf( pFileName1,  "%s",  "part1.aig" ); 
2737 2738 2739
    ABC_FREE( pFileNameGeneric );
    Ioa_WriteAiger( pPart0, pFileName0, 0, 0 );
    Ioa_WriteAiger( pPart1, pFileName1, 0, 0 );
2740
    Abc_Print( 1, "Demitering produced two files \"%s\" and \"%s\".\n", pFileName0, pFileName1 );
2741 2742 2743
    // dump files
    if ( fVerbose )
    {
2744
//        Abc_Print( 1, "Init:  " );
2745
        Aig_ManPrintStats( pMan );
2746
//        Abc_Print( 1, "Part1: " );
2747
        Aig_ManPrintStats( pPart0 );
2748
//        Abc_Print( 1, "Part2: " );
2749 2750 2751 2752 2753 2754
        Aig_ManPrintStats( pPart1 );
    }
    // create two-level miter
//    pMiter = Saig_ManCreateMiterTwo( pPart0, pPart1, 2 );
//    Aig_ManDumpBlif( pMiter, "miter01.blif", NULL, NULL );
//    Aig_ManStop( pMiter );
2755
//    Abc_Print( 1, "The new miter is written into file \"%s\".\n", "miter01.blif" );
2756 2757 2758 2759 2760
    Aig_ManStop( pPart0 );
    Aig_ManStop( pPart1 );
    Aig_ManStop( pMan );
    return 1;
} 
Alan Mishchenko committed
2761
 
Alan Mishchenko committed
2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772
/**Function*************************************************************

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2773
int Abc_NtkDarProve( Abc_Ntk_t * pNtk, Fra_Sec_t * pSecPar, int nBmcFramesMax, int nBmcConfMax )
Alan Mishchenko committed
2774 2775
{
    Aig_Man_t * pMan;
2776
    int iFrame = -1, RetValue = -1;
2777
    abctime clkTotal = Abc_Clock();
Alan Mishchenko committed
2778
    if ( pSecPar->fTryComb || Abc_NtkLatchNum(pNtk) == 0 )
Alan Mishchenko committed
2779 2780 2781
    {
        Prove_Params_t Params, * pParams = &Params;
        Abc_Ntk_t * pNtkComb;
2782
        int RetValue;
2783
        abctime clk = Abc_Clock();
Alan Mishchenko committed
2784
        if ( Abc_NtkLatchNum(pNtk) == 0 )
2785
            Abc_Print( 1, "The network has no latches. Running CEC.\n" );
Alan Mishchenko committed
2786 2787 2788 2789 2790
        // create combinational network
        pNtkComb = Abc_NtkDup( pNtk );
        Abc_NtkMakeComb( pNtkComb, 1 );
        // solve it using combinational equivalence checking
        Prove_ParamsSetDefault( pParams );
Alan Mishchenko committed
2791
        pParams->fVerbose = 1;
Alan Mishchenko committed
2792 2793
        RetValue = Abc_NtkIvyProve( &pNtkComb, pParams );
        // transfer model if given
Alan Mishchenko committed
2794
//        pNtk->pModel = pNtkComb->pModel; pNtkComb->pModel = NULL;
Alan Mishchenko committed
2795 2796 2797
        if ( RetValue == 0  && (Abc_NtkLatchNum(pNtk) == 0) )
        {
            pNtk->pModel = pNtkComb->pModel; pNtkComb->pModel = NULL;
2798
            Abc_Print( 1, "Networks are not equivalent.\n" );
2799
            ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
2800 2801
            if ( pSecPar->fReportSolution )
            {
2802
                Abc_Print( 1, "SOLUTION: FAIL       " );
2803
                ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
2804 2805 2806
            }
            return RetValue;
        }
Alan Mishchenko committed
2807 2808 2809 2810
        Abc_NtkDelete( pNtkComb );
        // return the result, if solved
        if ( RetValue == 1 )
        {
2811
            Abc_Print( 1, "Networks are equivalent after CEC.   " );
2812
            ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
2813 2814
            if ( pSecPar->fReportSolution )
            {
2815
            Abc_Print( 1, "SOLUTION: PASS       " );
2816
            ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
2817
            }
Alan Mishchenko committed
2818 2819 2820
            return RetValue;
        }
    }
2821 2822 2823 2824
    // derive the AIG manager
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
    {
2825
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
2826 2827 2828 2829
        return -1;
    }
    assert( pMan->nRegs > 0 );

Alan Mishchenko committed
2830
    if ( pSecPar->fTryBmc )
Alan Mishchenko committed
2831
    {
2832
        RetValue = Saig_BmcPerform( pMan, 0, nBmcFramesMax, 2000, 0, nBmcConfMax, 0, pSecPar->fVerbose, 0, &iFrame, 0 );
Alan Mishchenko committed
2833
        if ( RetValue == 0 )
Alan Mishchenko committed
2834
        {
2835
            Abc_Print( 1, "Networks are not equivalent.\n" );
Alan Mishchenko committed
2836 2837
            if ( pSecPar->fReportSolution )
            {
2838
                Abc_Print( 1, "SOLUTION: FAIL       " );
2839
                ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
2840
            }
2841 2842 2843 2844
            // return the counter-example generated
            ABC_FREE( pNtk->pModel );
            ABC_FREE( pNtk->pSeqModel );
            pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
2845
            Aig_ManStop( pMan );
Alan Mishchenko committed
2846
            return RetValue;
Alan Mishchenko committed
2847
        }
Alan Mishchenko committed
2848
    } 
Alan Mishchenko committed
2849
    // perform verification
Alan Mishchenko committed
2850
    if ( pSecPar->fUseNewProver )
Alan Mishchenko committed
2851
    {
Alan Mishchenko committed
2852 2853 2854 2855
        RetValue = Ssw_SecGeneralMiter( pMan, NULL );
    }
    else
    {
Alan Mishchenko committed
2856
        RetValue = Fra_FraigSec( pMan, pSecPar, NULL );
Alan Mishchenko committed
2857 2858
        ABC_FREE( pNtk->pModel );
        ABC_FREE( pNtk->pSeqModel );
Alan Mishchenko committed
2859 2860 2861
        pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
        if ( pNtk->pSeqModel )
        {
2862
            Abc_Cex_t * pCex = pNtk->pSeqModel;
2863
            Abc_Print( 1, "Output %d of miter \"%s\" was asserted in frame %d.\n", pCex->iPo, pNtk->pName, pCex->iFrame );
2864
            if ( !Saig_ManVerifyCex( pMan, pNtk->pSeqModel ) )
2865
                Abc_Print( 1, "Abc_NtkDarProve(): Counter-example verification has FAILED.\n" );
Alan Mishchenko committed
2866
        }
Alan Mishchenko committed
2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882
    }
    Aig_ManStop( pMan );
    return RetValue;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
2883
int Abc_NtkDarSec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Fra_Sec_t * pSecPar )
Alan Mishchenko committed
2884 2885 2886
{
//    Fraig_Params_t Params;
    Aig_Man_t * pMan;
Alan Mishchenko committed
2887
    Abc_Ntk_t * pMiter;//, * pTemp;
Alan Mishchenko committed
2888
    int RetValue;
Alan Mishchenko committed
2889
 
Alan Mishchenko committed
2890
    // get the miter of the two networks
Alan Mishchenko committed
2891
    pMiter = Abc_NtkMiter( pNtk1, pNtk2, 0, 0, 0, 0 );
Alan Mishchenko committed
2892 2893
    if ( pMiter == NULL )
    {
2894
        Abc_Print( 1, "Miter computation has failed.\n" );
Alan Mishchenko committed
2895 2896 2897 2898 2899 2900
        return 0;
    }
    RetValue = Abc_NtkMiterIsConstant( pMiter );
    if ( RetValue == 0 )
    {
        extern void Abc_NtkVerifyReportErrorSeq( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int * pModel, int nFrames );
2901
        Abc_Print( 1, "Networks are NOT EQUIVALENT after structural hashing.\n" );
Alan Mishchenko committed
2902
        // report the error
Alan Mishchenko committed
2903
        pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, pSecPar->nFramesMax );
2904
//        Abc_NtkVerifyReportErrorSeq( pNtk1, pNtk2, pMiter->pModel, pSecPar->nFramesMax );
Alan Mishchenko committed
2905
        ABC_FREE( pMiter->pModel );
Alan Mishchenko committed
2906 2907 2908 2909 2910 2911
        Abc_NtkDelete( pMiter );
        return 0;
    }
    if ( RetValue == 1 )
    {
        Abc_NtkDelete( pMiter );
2912
        Abc_Print( 1, "Networks are equivalent after structural hashing.\n" );
Alan Mishchenko committed
2913 2914 2915
        return 1;
    }

Alan Mishchenko committed
2916
    // commented out because sometimes the problem became non-inductive
Alan Mishchenko committed
2917
/*
Alan Mishchenko committed
2918 2919 2920 2921
    // preprocess the miter by fraiging it
    // (note that for each functional class, fraiging leaves one representative;
    // so fraiging does not reduce the number of functions represented by nodes
    Fraig_ParamsSetDefault( &Params );
Alan Mishchenko committed
2922
    Params.nBTLimit = 100000;
Alan Mishchenko committed
2923 2924
    pMiter = Abc_NtkFraig( pTemp = pMiter, &Params, 0, 0 );
    Abc_NtkDelete( pTemp );
Alan Mishchenko committed
2925 2926 2927 2928
    RetValue = Abc_NtkMiterIsConstant( pMiter );
    if ( RetValue == 0 )
    {
        extern void Abc_NtkVerifyReportErrorSeq( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int * pModel, int nFrames );
2929
        Abc_Print( 1, "Networks are NOT EQUIVALENT after structural hashing.\n" );
Alan Mishchenko committed
2930 2931 2932
        // report the error
        pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, nFrames );
        Abc_NtkVerifyReportErrorSeq( pNtk1, pNtk2, pMiter->pModel, nFrames );
Alan Mishchenko committed
2933
        ABC_FREE( pMiter->pModel );
Alan Mishchenko committed
2934 2935 2936 2937 2938 2939
        Abc_NtkDelete( pMiter );
        return 0;
    }
    if ( RetValue == 1 )
    {
        Abc_NtkDelete( pMiter );
2940
        Abc_Print( 1, "Networks are equivalent after structural hashing.\n" );
Alan Mishchenko committed
2941 2942 2943
        return 1;
    }
*/
Alan Mishchenko committed
2944
    // derive the AIG manager
Alan Mishchenko committed
2945
    pMan = Abc_NtkToDar( pMiter, 0, 1 );
Alan Mishchenko committed
2946 2947 2948
    Abc_NtkDelete( pMiter );
    if ( pMan == NULL )
    {
2949
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
2950 2951 2952 2953 2954
        return -1;
    }
    assert( pMan->nRegs > 0 );

    // perform verification
Alan Mishchenko committed
2955
    RetValue = Fra_FraigSec( pMan, pSecPar, NULL );
Alan Mishchenko committed
2956 2957 2958 2959
    Aig_ManStop( pMan );
    return RetValue;
}

2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970
/**Function*************************************************************

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2971
int Abc_NtkDarPdr( Abc_Ntk_t * pNtk, Pdr_Par_t * pPars )
2972
{
2973
    int RetValue = -1;
2974
    abctime clk = Abc_Clock();
2975 2976 2977 2978
    Aig_Man_t * pMan;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
    {
2979
        Abc_Print( 1, "Converting network into AIG has failed.\n" );
2980 2981
        return -1;
    }
2982
    RetValue = Pdr_ManSolve( pMan, pPars );
2983
    pPars->nDropOuts = Saig_ManPoNum(pMan) - pPars->nProveOuts - pPars->nFailOuts;
2984 2985
    if ( !pPars->fSilent )
    {
2986 2987 2988 2989
        if ( pPars->fSolveAll )
            Abc_Print( 1, "Properties:  All = %d. Proved = %d. Disproved = %d. Undecided = %d.   ", 
                Saig_ManPoNum(pMan), pPars->nProveOuts, pPars->nFailOuts, pPars->nDropOuts );
        else if ( RetValue == 1 )
2990
            Abc_Print( 1, "Property proved.  " );
2991
        else 
2992
        {
2993
            if ( RetValue == 0 )
2994
            {
2995 2996 2997 2998 2999 3000 3001 3002
                if ( pMan->pSeqModel == NULL )
                    Abc_Print( 1, "Abc_NtkDarPdr(): Counter-example is not available.\n" );
                else
                {
                    Abc_Print( 1, "Output %d of miter \"%s\" was asserted in frame %d.  ", pMan->pSeqModel->iPo, pNtk->pName, pMan->pSeqModel->iFrame );
                    if ( !Saig_ManVerifyCex( pMan, pMan->pSeqModel ) )
                        Abc_Print( 1, "Abc_NtkDarPdr(): Counter-example verification has FAILED.\n" );
                }
3003
            }
3004 3005 3006 3007
            else if ( RetValue == -1 )
                Abc_Print( 1, "Property UNDECIDED.  " );
            else
                assert( 0 );
3008
        }
3009
        ABC_PRT( "Time", Abc_Clock() - clk );
3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025
/*
        Abc_Print( 1, "Status: " );
        if ( pPars->pOutMap )
        {
            int i;
            for ( i = 0; i < Saig_ManPoNum(pMan); i++ )
                if ( pPars->pOutMap[i] == 1 )
                    Abc_Print( 1, "%d=%s ", i, "unsat" );
                else if ( pPars->pOutMap[i] == 0 )
                    Abc_Print( 1, "%d=%s ", i, "sat" );
                else if ( pPars->pOutMap[i] < 0 )
                    Abc_Print( 1, "%d=%s ", i, "undec" );
                else assert( 0 );
        }
        Abc_Print( 1, "\n" );
*/
3026
    }
3027 3028
    ABC_FREE( pNtk->pSeqModel );
    pNtk->pSeqModel = pMan->pSeqModel;
3029
    pMan->pSeqModel = NULL;
3030 3031 3032 3033
    if ( pNtk->vSeqModelVec )
        Vec_PtrFreeFree( pNtk->vSeqModelVec );
    pNtk->vSeqModelVec = pMan->vSeqModelVec;
    pMan->vSeqModelVec = NULL;
3034 3035 3036
    Aig_ManStop( pMan );
    return RetValue;
}
Alan Mishchenko committed
3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056

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

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkDarAbSec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nFrames, int fVerbose )
{
    Aig_Man_t * pMan1, * pMan2 = NULL;
    int RetValue;
    // derive AIG manager
    pMan1 = Abc_NtkToDar( pNtk1, 0, 1 );
    if ( pMan1 == NULL )
    {
3057
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
3058 3059 3060 3061 3062 3063 3064 3065 3066
        return -1;
    }
    assert( Aig_ManRegNum(pMan1) > 0 );
    // derive AIG manager
    if ( pNtk2 )
    {
        pMan2 = Abc_NtkToDar( pNtk2, 0, 1 );
        if ( pMan2 == NULL )
        {
3067
            Aig_ManStop( pMan1 );
3068
            Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
3069 3070 3071
            return -1;
        }
        assert( Aig_ManRegNum(pMan2) > 0 );
3072 3073 3074 3075
        if ( Saig_ManPiNum(pMan1) != Saig_ManPiNum(pMan2) )
        {
            Aig_ManStop( pMan1 );
            Aig_ManStop( pMan2 );
3076
            Abc_Print( 1, "The networks have different number of PIs.\n" );
3077 3078 3079 3080 3081 3082
            return -1;
        }
        if ( Saig_ManPoNum(pMan1) != Saig_ManPoNum(pMan2) )
        {
            Aig_ManStop( pMan1 );
            Aig_ManStop( pMan2 );
3083
            Abc_Print( 1, "The networks have different number of POs.\n" );
3084 3085 3086 3087 3088 3089
            return -1;
        }
        if ( Aig_ManRegNum(pMan1) != Aig_ManRegNum(pMan2) )
        {
            Aig_ManStop( pMan1 );
            Aig_ManStop( pMan2 );
3090
            Abc_Print( 1, "The networks have different number of flops.\n" );
3091 3092
            return -1;
        }
Alan Mishchenko committed
3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121
    }
    // perform verification
    RetValue = Ssw_SecSpecialMiter( pMan1, pMan2, nFrames, fVerbose );
    Aig_ManStop( pMan1 );
    if ( pMan2 )
        Aig_ManStop( pMan2 );
    return RetValue;
}


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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkDarSimSec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Ssw_Pars_t * pPars )
{
    Aig_Man_t * pMan1, * pMan2 = NULL;
    int RetValue;
    // derive AIG manager
    pMan1 = Abc_NtkToDar( pNtk1, 0, 1 );
    if ( pMan1 == NULL )
    {
3122
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
3123 3124 3125 3126 3127 3128 3129 3130 3131
        return -1;
    }
    assert( Aig_ManRegNum(pMan1) > 0 );
    // derive AIG manager
    if ( pNtk2 )
    {
        pMan2 = Abc_NtkToDar( pNtk2, 0, 1 );
        if ( pMan2 == NULL )
        {
3132
            Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167
            return -1;
        }
        assert( Aig_ManRegNum(pMan2) > 0 );
    }

    // perform verification
    RetValue = Ssw_SecWithSimilarity( pMan1, pMan2, pPars );
    Aig_ManStop( pMan1 );
    if ( pMan2 )
        Aig_ManStop( pMan2 );
    return RetValue;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarMatch( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nDist, int fVerbose )
{
    extern Vec_Int_t * Saig_StrSimPerformMatching( Aig_Man_t * p0, Aig_Man_t * p1, int nDist, int fVerbose, Aig_Man_t ** ppMiter );
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan1, * pMan2 = NULL, * pManRes;
    Vec_Int_t * vPairs;
    assert( Abc_NtkIsStrash(pNtk1) );
    // derive AIG manager
    pMan1 = Abc_NtkToDar( pNtk1, 0, 1 );
    if ( pMan1 == NULL )
    {
3168
        Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
3169 3170 3171 3172 3173 3174 3175 3176 3177
        return NULL;
    }
    assert( Aig_ManRegNum(pMan1) > 0 );
    // derive AIG manager
    if ( pNtk2 )
    {
        pMan2 = Abc_NtkToDar( pNtk2, 0, 1 );
        if ( pMan2 == NULL )
        {
3178
            Abc_Print( 1, "Converting miter into AIG has failed.\n" );
Alan Mishchenko committed
3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197
            return NULL;
        }
        assert( Aig_ManRegNum(pMan2) > 0 );
    }

    // perform verification
    vPairs = Saig_StrSimPerformMatching( pMan1, pMan2, nDist, 1, &pManRes );
    pNtkAig = Abc_NtkFromAigPhase( pManRes );
    if ( vPairs )
        Vec_IntFree( vPairs );
    if ( pManRes )
        Aig_ManStop( pManRes );
    Aig_ManStop( pMan1 );
    if ( pMan2 )
        Aig_ManStop( pMan2 );
    return pNtkAig;
}


Alan Mishchenko committed
3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208
/**Function*************************************************************

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
3209
Abc_Ntk_t * Abc_NtkDarLatchSweep( Abc_Ntk_t * pNtk, int fLatchConst, int fLatchEqual, int fSaveNames, int fUseMvSweep, int nFramesSymb, int nFramesSatur, int fVerbose, int fVeryVerbose )
Alan Mishchenko committed
3210
{
Alan Mishchenko committed
3211
    extern void Aig_ManPrintControlFanouts( Aig_Man_t * p );
Alan Mishchenko committed
3212
    Abc_Ntk_t * pNtkAig;
Alan Mishchenko committed
3213
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
3214
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3215 3216
    if ( pMan == NULL )
        return NULL;
3217 3218 3219 3220
    if ( fSaveNames )
    {
        Aig_ManSeqCleanup( pMan );
        if ( fLatchConst && pMan->nRegs )
3221
            pMan = Aig_ManConstReduce( pMan, fUseMvSweep, nFramesSymb, nFramesSatur, fVerbose, fVeryVerbose );
3222 3223 3224 3225 3226 3227 3228 3229
        if ( fLatchEqual && pMan->nRegs )
            pMan = Aig_ManReduceLaches( pMan, fVerbose );
    }
    else
    {
        if ( pMan->vFlopNums )
            Vec_IntFree( pMan->vFlopNums );
        pMan->vFlopNums = NULL;
3230
        pMan = Aig_ManScl( pTemp = pMan, fLatchConst, fLatchEqual, fUseMvSweep, nFramesSymb, nFramesSatur, fVerbose, fVeryVerbose );
3231 3232
        Aig_ManStop( pTemp );
    }
Alan Mishchenko committed
3233

Alan Mishchenko committed
3234
    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
Alan Mishchenko committed
3235
//Aig_ManPrintControlFanouts( pMan );
Alan Mishchenko committed
3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarRetime( Abc_Ntk_t * pNtk, int nStepsMax, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
3255
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3256 3257 3258 3259 3260 3261 3262
    if ( pMan == NULL )
        return NULL;
//    Aig_ManReduceLachesCount( pMan );
    if ( pMan->vFlopNums )
        Vec_IntFree( pMan->vFlopNums ); 
    pMan->vFlopNums = NULL;

Alan Mishchenko committed
3263
    pMan = Rtm_ManRetime( pTemp = pMan, 1, nStepsMax, fVerbose );
Alan Mishchenko committed
3264 3265 3266
    Aig_ManStop( pTemp );

//    pMan = Aig_ManReduceLaches( pMan, 1 );
3267
//    pMan = Aig_ManConstReduce( pMan, 1, 0 );
Alan Mishchenko committed
3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284

    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3285
Abc_Ntk_t * Abc_NtkDarRetimeF( Abc_Ntk_t * pNtk, int nStepsMax, int fVerbose )
Alan Mishchenko committed
3286 3287 3288 3289 3290 3291
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
3292
//    Aig_ManReduceLachesCount( pMan );
Alan Mishchenko committed
3293 3294 3295 3296
    if ( pMan->vFlopNums )
        Vec_IntFree( pMan->vFlopNums ); 
    pMan->vFlopNums = NULL;

Alan Mishchenko committed
3297
    pMan = Aig_ManRetimeFrontier( pTemp = pMan, nStepsMax );
Alan Mishchenko committed
3298 3299
    Aig_ManStop( pTemp );

Alan Mishchenko committed
3300
//    pMan = Aig_ManReduceLaches( pMan, 1 );
3301
//    pMan = Aig_ManConstReduce( pMan, 1, 0 );
Alan Mishchenko committed
3302

Alan Mishchenko committed
3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318
    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3319
Abc_Ntk_t * Abc_NtkDarRetimeMostFwd( Abc_Ntk_t * pNtk, int nMaxIters, int fVerbose )
Alan Mishchenko committed
3320
{
Alan Mishchenko committed
3321 3322
    extern Aig_Man_t * Saig_ManRetimeForward( Aig_Man_t * p, int nIters, int fVerbose );

Alan Mishchenko committed
3323 3324
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
3325
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3326 3327 3328 3329 3330 3331 3332
    if ( pMan == NULL )
        return NULL;
//    Aig_ManReduceLachesCount( pMan );
    if ( pMan->vFlopNums )
        Vec_IntFree( pMan->vFlopNums ); 
    pMan->vFlopNums = NULL;

Alan Mishchenko committed
3333
    pMan = Saig_ManRetimeForward( pTemp = pMan, nMaxIters, fVerbose );
Alan Mishchenko committed
3334 3335 3336
    Aig_ManStop( pTemp );

//    pMan = Aig_ManReduceLaches( pMan, 1 );
3337
//    pMan = Aig_ManConstReduce( pMan, 1, 0 );
Alan Mishchenko committed
3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354

    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385
Abc_Ntk_t * Abc_NtkDarRetimeMinArea( Abc_Ntk_t * pNtk, int nMaxIters, int fForwardOnly, int fBackwardOnly, int fInitial, int fVerbose )
{
    extern Aig_Man_t * Saig_ManRetimeMinArea( Aig_Man_t * p, int nMaxIters, int fForwardOnly, int fBackwardOnly, int fInitial, int fVerbose );
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    if ( pMan->vFlopNums )
        Vec_IntFree( pMan->vFlopNums ); 
    pMan->vFlopNums = NULL;

    pMan = Saig_ManRetimeMinArea( pTemp = pMan, nMaxIters, fForwardOnly, fBackwardOnly, fInitial, fVerbose );
    Aig_ManStop( pTemp );

    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398
Abc_Ntk_t * Abc_NtkDarRetimeStep( Abc_Ntk_t * pNtk, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan;
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    if ( pMan->vFlopNums )
        Vec_IntFree( pMan->vFlopNums ); 
    pMan->vFlopNums = NULL;

    Aig_ManPrintStats(pMan);
Alan Mishchenko committed
3399
    Saig_ManRetimeSteps( pMan, 1000, 1, 0 );
Alan Mishchenko committed
3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417
    Aig_ManPrintStats(pMan);

    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3418
/*
Alan Mishchenko committed
3419
Abc_Ntk_t * Abc_NtkDarHaigRecord( Abc_Ntk_t * pNtk, int nIters, int nSteps, int fRetimingOnly, int fAddBugs, int fUseCnf, int fVerbose )
Alan Mishchenko committed
3420
{
Alan Mishchenko committed
3421 3422
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
3423
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3424
    if ( pMan == NULL )
Alan Mishchenko committed
3425
        return NULL;
Alan Mishchenko committed
3426 3427 3428
    if ( pMan->vFlopNums )
        Vec_IntFree( pMan->vFlopNums ); 
    pMan->vFlopNums = NULL;
Alan Mishchenko committed
3429

Alan Mishchenko committed
3430 3431 3432 3433
    pMan = Saig_ManHaigRecord( pTemp = pMan, nIters, nSteps, fRetimingOnly, fAddBugs, fUseCnf, fVerbose );
    Aig_ManStop( pTemp );

    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
Alan Mishchenko committed
3434
    Aig_ManStop( pMan );
Alan Mishchenko committed
3435
    return pNtkAig;
Alan Mishchenko committed
3436
}
Alan Mishchenko committed
3437
*/
Alan Mishchenko committed
3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449

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

  Synopsis    [Performs random simulation.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
3450
int Abc_NtkDarSeqSim( Abc_Ntk_t * pNtk, int nFrames, int nWords, int TimeOut, int fNew, int fMiter, int fVerbose, char * pFileSim )
Alan Mishchenko committed
3451 3452
{
    Aig_Man_t * pMan;
3453
    Abc_Cex_t * pCex;
3454
    int status, RetValue = -1;
3455
    abctime clk = Abc_Clock();
Alan Mishchenko committed
3456 3457
    if ( Abc_NtkGetChoiceNum(pNtk) )
    {
3458
        Abc_Print( 1, "Removing %d choices from the AIG.\n", Abc_NtkGetChoiceNum(pNtk) );
3459
        Abc_AigCleanup((Abc_Aig_t *)pNtk->pManFunc);
Alan Mishchenko committed
3460
    }
Alan Mishchenko committed
3461
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
3462
    if ( fNew )
Alan Mishchenko committed
3463
    {
Alan Mishchenko committed
3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474
        Gia_Man_t * pGia;
        Gia_ParSim_t Pars, * pPars = &Pars;
        Gia_ManSimSetDefaultParams( pPars );
        pPars->nWords = nWords;
        pPars->nIters = nFrames;
        pPars->TimeLimit = TimeOut;
        pPars->fCheckMiter = fMiter;
        pPars->fVerbose = fVerbose;
        pGia = Gia_ManFromAig( pMan );
        if ( Gia_ManSimSimulate( pGia, pPars ) )
        { 
3475
            if ( pGia->pCexSeq )
Alan Mishchenko committed
3476
            {
3477
                Abc_Print( 1, "Simulation of %d frames with %d words asserted output %d in frame %d. ", 
3478
                    nFrames, nWords, pGia->pCexSeq->iPo, pGia->pCexSeq->iFrame );
3479
                status = Saig_ManVerifyCex( pMan, pGia->pCexSeq );
Alan Mishchenko committed
3480
                if ( status == 0 )
3481
                    Abc_Print( 1, "Abc_NtkDarSeqSim(): Counter-example verification has FAILED.\n" );
Alan Mishchenko committed
3482
            }
Alan Mishchenko committed
3483 3484
            ABC_FREE( pNtk->pModel );
            ABC_FREE( pNtk->pSeqModel );
3485 3486
            pNtk->pSeqModel = pGia->pCexSeq; pGia->pCexSeq = NULL;
            RetValue = 0;
Alan Mishchenko committed
3487 3488 3489
        }
        else
        {
3490
            Abc_Print( 1, "Simulation of %d frames with %d words did not assert the outputs.    ", 
Alan Mishchenko committed
3491 3492
                nFrames, nWords );
        }
Alan Mishchenko committed
3493
        Gia_ManStop( pGia );
Alan Mishchenko committed
3494
    }
3495
    else // comb/seq simulator
Alan Mishchenko committed
3496
    {
Alan Mishchenko committed
3497
        Fra_Sml_t * pSml;
3498 3499 3500 3501 3502 3503 3504 3505 3506
        if ( pFileSim != NULL )
        {
            assert( Abc_NtkLatchNum(pNtk) == 0 );
            pSml = Fra_SmlSimulateCombGiven( pMan, pFileSim, fMiter, fVerbose );
        }
        else if ( Abc_NtkLatchNum(pNtk) == 0 )
            pSml = Fra_SmlSimulateComb( pMan, nWords, fMiter );
        else
            pSml = Fra_SmlSimulateSeq( pMan, 0, nFrames, nWords, fMiter );
Alan Mishchenko committed
3507 3508 3509 3510
        if ( pSml->fNonConstOut )
        {
            pCex = Fra_SmlGetCounterExample( pSml );
            if ( pCex )
Alan Mishchenko committed
3511
            {
3512 3513 3514 3515
                Abc_Print( 1, "Simulation of %d frame%s with %d word%s asserted output %d in frame %d. ", 
                    pSml->nFrames, pSml->nFrames == 1 ? "": "s", 
                    pSml->nWordsFrame, pSml->nWordsFrame == 1 ? "": "s", 
                    pCex->iPo, pCex->iFrame );
3516
                status = Saig_ManVerifyCex( pMan, pCex );
Alan Mishchenko committed
3517
                if ( status == 0 )
3518
                    Abc_Print( 1, "Abc_NtkDarSeqSim(): Counter-example verification has FAILED.\n" );
Alan Mishchenko committed
3519
            }
Alan Mishchenko committed
3520 3521
            ABC_FREE( pNtk->pModel );
            ABC_FREE( pNtk->pSeqModel );
Alan Mishchenko committed
3522
            pNtk->pSeqModel = pCex;
3523
            RetValue = 0;
Alan Mishchenko committed
3524 3525 3526
        }
        else
        {
3527
            Abc_Print( 1, "Simulation of %d frames with %d words did not assert the outputs.    ", 
Alan Mishchenko committed
3528 3529 3530
                nFrames, nWords );
        }
        Fra_SmlStop( pSml );
Alan Mishchenko committed
3531
    }
3532
    ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
3533 3534 3535 3536 3537 3538
    Aig_ManStop( pMan );
    return RetValue;
}

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

3539 3540 3541 3542 3543 3544 3545 3546 3547
  Synopsis    [Performs random simulation.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
3548
int Abc_NtkDarSeqSim3( Abc_Ntk_t * pNtk, Ssw_RarPars_t * pPars )
3549 3550
{
    Aig_Man_t * pMan;
3551
    int status, RetValue = -1;
3552
//    abctime clk = Abc_Clock();
3553 3554
    if ( Abc_NtkGetChoiceNum(pNtk) )
    {
3555
        Abc_Print( 1, "Removing %d choices from the AIG.\n", Abc_NtkGetChoiceNum(pNtk) );
3556 3557 3558
        Abc_AigCleanup((Abc_Aig_t *)pNtk->pManFunc);
    }
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
3559
    if ( Ssw_RarSimulate( pMan, pPars ) == 0 )
3560 3561 3562
    { 
        if ( pMan->pSeqModel )
        {
3563 3564
//            Abc_Print( 1, "Simulation of %d frames with %d words asserted output %d in frame %d. ", 
//                nFrames, nWords, pMan->pSeqModel->iPo, pMan->pSeqModel->iFrame );
3565 3566
            status = Saig_ManVerifyCex( pMan, pMan->pSeqModel );
            if ( status == 0 )
3567
                Abc_Print( 1, "Abc_NtkDarSeqSim(): Counter-example verification has FAILED.\n" );
3568 3569 3570 3571 3572 3573 3574 3575
        }
        ABC_FREE( pNtk->pModel );
        ABC_FREE( pNtk->pSeqModel );
        pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
        RetValue = 0;
    }
    else
    {
3576
//        Abc_Print( 1, "Simulation of %d frames with %d words did not assert the outputs.    ", 
3577
//            nFrames, nWords );
3578
    }
3579 3580 3581
    if ( pNtk->vSeqModelVec )
        Vec_PtrFreeFree( pNtk->vSeqModelVec );
    pNtk->vSeqModelVec = pMan->vSeqModelVec;  pMan->vSeqModelVec = NULL;
3582
//    ABC_PRT( "Time", Abc_Clock() - clk );
3583
    pNtk->pData = pMan->pData; pMan->pData = NULL;
3584 3585 3586 3587 3588 3589
    Aig_ManStop( pMan );
    return RetValue;
}

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

Alan Mishchenko committed
3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605
  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkDarClau( Abc_Ntk_t * pNtk, int nFrames, int nPref, int nClauses, int nLutSize, int nLevels, int nCutsMax, int nBatches, int fStepUp, int fBmc, int fRefs, int fTarget, int fVerbose, int fVeryVerbose )
{
    extern int Fra_Clau( Aig_Man_t * pMan, int nIters, int fVerbose, int fVeryVerbose );
    extern int Fra_Claus( Aig_Man_t * pAig, int nFrames, int nPref, int nClauses, int nLutSize, int nLevels, int nCutsMax, int nBatches, int fStepUp, int fBmc, int fRefs, int fTarget, int fVerbose, int fVeryVerbose );
    Aig_Man_t * pMan;
    if ( fTarget && Abc_NtkPoNum(pNtk) != 1 )
    {
3606
        Abc_Print( 1, "The number of outputs should be 1.\n" );
Alan Mishchenko committed
3607 3608
        return 1;
    }
Alan Mishchenko committed
3609
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637
    if ( pMan == NULL )
        return 1;
//    Aig_ManReduceLachesCount( pMan );
    if ( pMan->vFlopNums )
        Vec_IntFree( pMan->vFlopNums ); 
    pMan->vFlopNums = NULL;

//    Fra_Clau( pMan, nStepsMax, fVerbose, fVeryVerbose );
    Fra_Claus( pMan, nFrames, nPref, nClauses, nLutSize, nLevels, nCutsMax, nBatches, fStepUp, fBmc, fRefs, fTarget, fVerbose, fVeryVerbose );
    Aig_ManStop( pMan );
    return 1;
}

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

  Synopsis    [Performs targe enlargement.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarEnlarge( Abc_Ntk_t * pNtk, int nFrames, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
3638
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3639 3640 3641 3642 3643 3644 3645 3646
    if ( pMan == NULL )
        return NULL;
    pMan = Aig_ManFrames( pTemp = pMan, nFrames, 0, 1, 1, 1, NULL );
    Aig_ManStop( pTemp );
    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}
Alan Mishchenko committed
3647

Alan Mishchenko committed
3648 3649
/**Function*************************************************************

3650 3651 3652 3653 3654 3655 3656 3657 3658
  Synopsis    [Performs targe enlargement.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
3659
Abc_Ntk_t * Abc_NtkDarTempor( Abc_Ntk_t * pNtk, int nFrames, int TimeOut, int nConfLimit, int fUseBmc, int fUseTransSigs, int fVerbose, int fVeryVerbose )
3660
{
3661
    extern Aig_Man_t * Saig_ManTempor( Aig_Man_t * pAig, int nFrames, int TimeOut, int nConfLimit, int fUseBmc, int fUseTransSigs, int fVerbose, int fVeryVerbose );
3662 3663 3664 3665 3666
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
3667
    pTemp = Saig_ManTempor( pMan, nFrames, TimeOut, nConfLimit, fUseBmc, fUseTransSigs, fVerbose, fVeryVerbose );
3668 3669 3670 3671 3672 3673 3674 3675 3676 3677
    Aig_ManStop( pMan );
    if ( pTemp == NULL )
        return Abc_NtkDup( pNtk );
    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pTemp );
    Aig_ManStop( pTemp );
    return pNtkAig;
}

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

Alan Mishchenko committed
3678
  Synopsis    [Performs induction for property only.]
Alan Mishchenko committed
3679 3680 3681 3682 3683 3684 3685 3686

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
3687
int Abc_NtkDarInduction( Abc_Ntk_t * pNtk, int nTimeOut, int nFramesMax, int nConfMax, int fUnique, int fUniqueAll, int fGetCex, int fVerbose, int fVeryVerbose )
3688
{ 
3689
    Aig_Man_t * pMan;
3690
    abctime clkTotal = Abc_Clock();
Alan Mishchenko committed
3691 3692 3693
    int RetValue;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
3694
        return -1;
3695
    RetValue = Saig_ManInduction( pMan, nTimeOut, nFramesMax, nConfMax, fUnique, fUniqueAll, fGetCex, fVerbose, fVeryVerbose );
Alan Mishchenko committed
3696 3697
    if ( RetValue == 1 )
    {
3698
        Abc_Print( 1, "Networks are equivalent.   " );
3699
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
3700 3701 3702
    }
    else if ( RetValue == 0 )
    {
3703
        Abc_Print( 1, "Networks are NOT EQUIVALENT.   " );
3704
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
3705 3706 3707
    }
    else
    {
3708
        Abc_Print( 1, "Networks are UNDECIDED.   " );
3709
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
3710
    }
3711 3712 3713 3714 3715 3716 3717
    if ( fGetCex )
    {
        ABC_FREE( pNtk->pModel );
        ABC_FREE( pNtk->pSeqModel );
        pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
    }
    Aig_ManStop( pMan );
3718
    return RetValue;
Alan Mishchenko committed
3719 3720
}

Alan Mishchenko committed
3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732

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

  Synopsis    [Interplates two networks.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3733
Abc_Ntk_t * Abc_NtkInterOne( Abc_Ntk_t * pNtkOn, Abc_Ntk_t * pNtkOff, int fRelation, int fVerbose )
Alan Mishchenko committed
3734
{
Alan Mishchenko committed
3735
    extern Aig_Man_t * Aig_ManInter( Aig_Man_t * pManOn, Aig_Man_t * pManOff, int fRelation, int fVerbose );
Alan Mishchenko committed
3736 3737 3738 3739
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pManOn, * pManOff, * pManAig;
    if ( Abc_NtkCoNum(pNtkOn) != 1 || Abc_NtkCoNum(pNtkOff) != 1 )
    {
3740
        Abc_Print( 1, "Currently works only for single-output networks.\n" );
Alan Mishchenko committed
3741 3742 3743 3744
        return NULL;
    }
    if ( Abc_NtkCiNum(pNtkOn) != Abc_NtkCiNum(pNtkOff) )
    {
3745
        Abc_Print( 1, "The number of PIs should be the same.\n" );
Alan Mishchenko committed
3746 3747 3748
        return NULL;
    }
    // create internal AIGs
Alan Mishchenko committed
3749
    pManOn = Abc_NtkToDar( pNtkOn, 0, 0 );
Alan Mishchenko committed
3750 3751
    if ( pManOn == NULL )
        return NULL;
Alan Mishchenko committed
3752
    pManOff = Abc_NtkToDar( pNtkOff, 0, 0 );
Alan Mishchenko committed
3753 3754 3755
    if ( pManOff == NULL )
        return NULL;
    // derive the interpolant
Alan Mishchenko committed
3756
    pManAig = Aig_ManInter( pManOn, pManOff, fRelation, fVerbose );
Alan Mishchenko committed
3757 3758
    if ( pManAig == NULL )
    {
3759
        Abc_Print( 1, "Interpolant computation failed.\n" );
Alan Mishchenko committed
3760 3761 3762 3763
        return NULL;
    }
    Aig_ManStop( pManOn );
    Aig_ManStop( pManOff );
Alan Mishchenko committed
3764 3765 3766 3767 3768 3769 3770
    // for the relation, add an extra input
    if ( fRelation )
    {
        Abc_Obj_t * pObj;
        pObj = Abc_NtkCreatePi( pNtkOff );
        Abc_ObjAssignName( pObj, "New", NULL );
    }
Alan Mishchenko committed
3771
    // create logic network
Alan Mishchenko committed
3772
    pNtkAig = Abc_NtkFromDar( pNtkOff, pManAig );
Alan Mishchenko committed
3773 3774 3775 3776
    Aig_ManStop( pManAig );
    return pNtkAig;
}

Alan Mishchenko committed
3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792
/**Function*************************************************************

  Synopsis    [Fast interpolation.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkInterFast( Abc_Ntk_t * pNtkOn, Abc_Ntk_t * pNtkOff, int fVerbose )
{
    extern void Aig_ManInterFast( Aig_Man_t * pManOn, Aig_Man_t * pManOff, int fVerbose );
    Aig_Man_t * pManOn, * pManOff;
    // create internal AIGs
Alan Mishchenko committed
3793
    pManOn = Abc_NtkToDar( pNtkOn, 0, 0 );
Alan Mishchenko committed
3794 3795
    if ( pManOn == NULL )
        return;
Alan Mishchenko committed
3796
    pManOff = Abc_NtkToDar( pNtkOff, 0, 0 );
Alan Mishchenko committed
3797 3798 3799 3800 3801 3802
    if ( pManOff == NULL )
        return;
    Aig_ManInterFast( pManOn, pManOff, fVerbose );
    Aig_ManStop( pManOn );
    Aig_ManStop( pManOff );
}
Alan Mishchenko committed
3803

3804 3805 3806
abctime timeCnf;
abctime timeSat;
abctime timeInt;
Alan Mishchenko committed
3807

Alan Mishchenko committed
3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818
/**Function*************************************************************

  Synopsis    [Interplates two networks.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3819
Abc_Ntk_t * Abc_NtkInter( Abc_Ntk_t * pNtkOn, Abc_Ntk_t * pNtkOff, int fRelation, int fVerbose )
Alan Mishchenko committed
3820 3821 3822
{
    Abc_Ntk_t * pNtkOn1, * pNtkOff1, * pNtkInter1, * pNtkInter;
    Abc_Obj_t * pObj;
3823
    int i; //, clk = Abc_Clock();
Alan Mishchenko committed
3824 3825
    if ( Abc_NtkCoNum(pNtkOn) != Abc_NtkCoNum(pNtkOff) )
    {
3826
        Abc_Print( 1, "Currently works only for networks with equal number of POs.\n" );
Alan Mishchenko committed
3827 3828
        return NULL;
    }
Alan Mishchenko committed
3829 3830 3831
    // compute the fast interpolation time
//    Abc_NtkInterFast( pNtkOn, pNtkOff, fVerbose );
    // consider the case of one output
Alan Mishchenko committed
3832
    if ( Abc_NtkCoNum(pNtkOn) == 1 )
Alan Mishchenko committed
3833
        return Abc_NtkInterOne( pNtkOn, pNtkOff, fRelation, fVerbose );
Alan Mishchenko committed
3834
    // start the new network
Alan Mishchenko committed
3835 3836 3837 3838 3839
    pNtkInter = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
    pNtkInter->pName = Extra_UtilStrsav(pNtkOn->pName);
    Abc_NtkForEachPi( pNtkOn, pObj, i )
        Abc_NtkDupObj( pNtkInter, pObj, 1 );
    // process each POs separately
Alan Mishchenko committed
3840 3841 3842
timeCnf = 0;
timeSat = 0;
timeInt = 0;
Alan Mishchenko committed
3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861
    Abc_NtkForEachCo( pNtkOn, pObj, i )
    {
        pNtkOn1 = Abc_NtkCreateCone( pNtkOn, Abc_ObjFanin0(pObj), Abc_ObjName(pObj), 1 );
        if ( Abc_ObjFaninC0(pObj) )
            Abc_ObjXorFaninC( Abc_NtkPo(pNtkOn1, 0), 0 );

        pObj   = Abc_NtkCo(pNtkOff, i);
        pNtkOff1 = Abc_NtkCreateCone( pNtkOff, Abc_ObjFanin0(pObj), Abc_ObjName(pObj), 1 );
        if ( Abc_ObjFaninC0(pObj) )
            Abc_ObjXorFaninC( Abc_NtkPo(pNtkOff1, 0), 0 );

        if ( Abc_NtkNodeNum(pNtkOn1) == 0 )
            pNtkInter1 = Abc_NtkDup( pNtkOn1 );
        else if ( Abc_NtkNodeNum(pNtkOff1) == 0 )
        {
            pNtkInter1 = Abc_NtkDup( pNtkOff1 );
            Abc_ObjXorFaninC( Abc_NtkPo(pNtkInter1, 0), 0 );
        }
        else
Alan Mishchenko committed
3862
            pNtkInter1 = Abc_NtkInterOne( pNtkOn1, pNtkOff1, 0, fVerbose );
Alan Mishchenko committed
3863 3864 3865 3866 3867
        if ( pNtkInter1 )
        {
            Abc_NtkAppend( pNtkInter, pNtkInter1, 1 );
            Abc_NtkDelete( pNtkInter1 );
        }
Alan Mishchenko committed
3868 3869 3870 3871

        Abc_NtkDelete( pNtkOn1 );
        Abc_NtkDelete( pNtkOff1 );
    }
Alan Mishchenko committed
3872 3873 3874
//    ABC_PRT( "CNF", timeCnf );
//    ABC_PRT( "SAT", timeSat );
//    ABC_PRT( "Int", timeInt );
3875
//    ABC_PRT( "Slow interpolation time", Abc_Clock() - clk );
Alan Mishchenko committed
3876

Alan Mishchenko committed
3877 3878
    // return the network
    if ( !Abc_NtkCheck( pNtkInter ) )
3879
        Abc_Print( 1, "Abc_NtkAttachBottom(): Network check has failed.\n" );
Alan Mishchenko committed
3880 3881 3882 3883 3884
    return pNtkInter;
}

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

Alan Mishchenko committed
3885
  Synopsis    []
Alan Mishchenko committed
3886 3887 3888 3889 3890 3891 3892 3893

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3894 3895
void Abc_NtkPrintSccs( Abc_Ntk_t * pNtk, int fVerbose )
{
Alan Mishchenko committed
3896
//    extern Vec_Ptr_t * Aig_ManRegPartitionLinear( Aig_Man_t * pAig, int nPartSize );
Alan Mishchenko committed
3897
    Aig_Man_t * pMan;
Alan Mishchenko committed
3898
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3899 3900 3901
    if ( pMan == NULL )
        return;
    Aig_ManComputeSccs( pMan );
Alan Mishchenko committed
3902
//    Aig_ManRegPartitionLinear( pMan, 1000 );
Alan Mishchenko committed
3903 3904 3905
    Aig_ManStop( pMan );
}

Alan Mishchenko committed
3906 3907
/**Function*************************************************************

Alan Mishchenko committed
3908 3909 3910 3911 3912 3913 3914 3915 3916
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
3917
int Abc_NtkDarPrintCone( Abc_Ntk_t * pNtk )
Alan Mishchenko committed
3918 3919 3920 3921 3922
{
    extern void Saig_ManPrintCones( Aig_Man_t * pAig );
    Aig_Man_t * pMan;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
3923
        return 0;
Alan Mishchenko committed
3924 3925 3926
    assert( Aig_ManRegNum(pMan) > 0 );
    Saig_ManPrintCones( pMan );
    Aig_ManStop( pMan );
3927
    return 1;
Alan Mishchenko committed
3928 3929 3930 3931 3932
}

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

  Synopsis    []
Alan Mishchenko committed
3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963

  Description []
               
  SideEffects []

  SeeAlso     []
 
***********************************************************************/
Abc_Ntk_t * Abc_NtkBalanceExor( Abc_Ntk_t * pNtk, int fUpdateLevel, int fVerbose )
{
    extern void Dar_BalancePrintStats( Aig_Man_t * p );
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;//, * pTemp2;
    assert( Abc_NtkIsStrash(pNtk) );
    // derive AIG with EXORs
    pMan = Abc_NtkToDar( pNtk, 1, 0 );
    if ( pMan == NULL )
        return NULL;
//    Aig_ManPrintStats( pMan );
    if ( fVerbose )
        Dar_BalancePrintStats( pMan );
    // perform balancing
    pTemp = Dar_ManBalance( pMan, fUpdateLevel );
//    Aig_ManPrintStats( pTemp );
    // create logic network
    pNtkAig = Abc_NtkFromDar( pNtk, pTemp );
    Aig_ManStop( pTemp );
    Aig_ManStop( pMan );
    return pNtkAig;
}

Alan Mishchenko committed
3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974
/**Function*************************************************************

  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
3975
Abc_Ntk_t * Abc_NtkPhaseAbstract( Abc_Ntk_t * pNtk, int nFrames, int nPref, int fIgnore, int fPrint, int fVerbose )
Alan Mishchenko committed
3976
{
Alan Mishchenko committed
3977
    extern Aig_Man_t * Saig_ManPhaseAbstract( Aig_Man_t * p, Vec_Int_t * vInits, int nFrames, int nPref, int fIgnore, int fPrint, int fVerbose );
Alan Mishchenko committed
3978 3979 3980
    Vec_Int_t * vInits;
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
3981
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
3982 3983 3984
    if ( pMan == NULL )
        return NULL;
    vInits = Abc_NtkGetLatchValues(pNtk);
Alan Mishchenko committed
3985
    pMan = Saig_ManPhaseAbstract( pTemp = pMan, vInits, nFrames, nPref, fIgnore, fPrint, fVerbose );
Alan Mishchenko committed
3986 3987 3988 3989 3990
    Vec_IntFree( vInits );
    Aig_ManStop( pTemp );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromAigPhase( pMan );
Alan Mishchenko committed
3991 3992
//    pNtkAig->pName = Extra_UtilStrsav(pNtk->pName);
//    pNtkAig->pSpec = Extra_UtilStrsav(pNtk->pSpec);
Alan Mishchenko committed
3993 3994 3995 3996
    Aig_ManStop( pMan );
    return pNtkAig;
}

Alan Mishchenko committed
3997 3998
/**Function*************************************************************

Alan Mishchenko committed
3999 4000 4001 4002 4003 4004 4005 4006 4007
  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034
int Abc_NtkPhaseFrameNum( Abc_Ntk_t * pNtk )
{
    extern int Saig_ManPhaseFrameNum( Aig_Man_t * p, Vec_Int_t * vInits );
    Vec_Int_t * vInits;
    Aig_Man_t * pMan;
    int nFrames;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return 1;
    vInits = Abc_NtkGetLatchValues(pNtk);
    nFrames = Saig_ManPhaseFrameNum( pMan, vInits );
    Vec_IntFree( vInits );
    Aig_ManStop( pMan );
    return nFrames;
}

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

  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082
Abc_Ntk_t * Abc_NtkDarSynchOne( Abc_Ntk_t * pNtk, int nWords, int fVerbose )
{
    extern Aig_Man_t * Saig_SynchSequenceApply( Aig_Man_t * pAig, int nWords, int fVerbose );
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    pMan = Saig_SynchSequenceApply( pTemp = pMan, nWords, fVerbose );
    Aig_ManStop( pTemp );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarSynch( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nWords, int fVerbose )
{
    extern Aig_Man_t * Saig_Synchronize( Aig_Man_t * pAig1, Aig_Man_t * pAig2, int nWords, int fVerbose );
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan1, * pMan2, * pMan;
    pMan1 = Abc_NtkToDar( pNtk1, 0, 1 );
    if ( pMan1 == NULL )
        return NULL;
    pMan2 = Abc_NtkToDar( pNtk2, 0, 1 );
    if ( pMan2 == NULL )
    {
        Aig_ManStop( pMan1 );
        return NULL;
    }
    pMan = Saig_Synchronize( pMan1, pMan2, nWords, fVerbose );
    Aig_ManStop( pMan1 );
    Aig_ManStop( pMan2 );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromAigPhase( pMan );
Alan Mishchenko committed
4083 4084
//    pNtkAig->pName = Extra_UtilStrsav("miter");
//    pNtkAig->pSpec = NULL;
Alan Mishchenko committed
4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137
Abc_Ntk_t * Abc_NtkDarClockGate( Abc_Ntk_t * pNtk, Abc_Ntk_t * pCare, Cgt_Par_t * pPars )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan1, * pMan2 = NULL, * pMan;
    pMan1 = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan1 == NULL )
        return NULL;
    if ( pCare )
    {
        pMan2 = Abc_NtkToDar( pCare, 0, 0 );
        if ( pMan2 == NULL )
        {
            Aig_ManStop( pMan1 );
            return NULL;
        }
    }
    pMan = Cgt_ClockGating( pMan1, pMan2, pPars );
    Aig_ManStop( pMan1 );
    if ( pMan2 )
        Aig_ManStop( pMan2 );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148
Abc_Ntk_t * Abc_NtkDarExtWin( Abc_Ntk_t * pNtk, int nObjId, int nDist, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan1, * pMan;
    Aig_Obj_t * pObj;
    pMan1 = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan1 == NULL )
        return NULL;
    if ( nObjId == -1 )
    {
        pObj = Saig_ManFindPivot( pMan1 );
4149
        Abc_Print( 1, "Selected object %d as a window pivot.\n", pObj->Id );
Alan Mishchenko committed
4150 4151 4152 4153 4154 4155
    }
    else
    {
        if ( nObjId >= Aig_ManObjNumMax(pMan1) )
        {
            Aig_ManStop( pMan1 );
4156
            Abc_Print( 1, "The ID is too large.\n" );
Alan Mishchenko committed
4157 4158 4159 4160 4161 4162
            return NULL;
        }
        pObj = Aig_ManObj( pMan1, nObjId );
        if ( pObj == NULL )
        {
            Aig_ManStop( pMan1 );
4163
            Abc_Print( 1, "Object with ID %d does not exist.\n", nObjId );
Alan Mishchenko committed
4164 4165 4166 4167 4168
            return NULL;
        }
        if ( !Saig_ObjIsLo(pMan1, pObj) && !Aig_ObjIsNode(pObj) )
        {
            Aig_ManStop( pMan1 );
4169
            Abc_Print( 1, "Object with ID %d is not a node or reg output.\n", nObjId );
Alan Mishchenko committed
4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205
            return NULL;
        }
    }
    pMan = Saig_ManWindowExtract( pMan1, pObj, nDist );
    Aig_ManStop( pMan1 );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pNtk->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pNtk->pSpec);
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarInsWin( Abc_Ntk_t * pNtk, Abc_Ntk_t * pCare, int nObjId, int nDist, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan1, * pMan2 = NULL, * pMan;
    Aig_Obj_t * pObj;
    pMan1 = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan1 == NULL )
        return NULL;
    if ( nObjId == -1 )
    {
        pObj = Saig_ManFindPivot( pMan1 );
4206
        Abc_Print( 1, "Selected object %d as a window pivot.\n", pObj->Id );
Alan Mishchenko committed
4207 4208 4209 4210 4211 4212
    }
    else
    {
        if ( nObjId >= Aig_ManObjNumMax(pMan1) )
        {
            Aig_ManStop( pMan1 );
4213
            Abc_Print( 1, "The ID is too large.\n" );
Alan Mishchenko committed
4214 4215 4216 4217 4218 4219
            return NULL;
        }
        pObj = Aig_ManObj( pMan1, nObjId );
        if ( pObj == NULL )
        {
            Aig_ManStop( pMan1 );
4220
            Abc_Print( 1, "Object with ID %d does not exist.\n", nObjId );
Alan Mishchenko committed
4221 4222 4223 4224 4225
            return NULL;
        }
        if ( !Saig_ObjIsLo(pMan1, pObj) && !Aig_ObjIsNode(pObj) )
        {
            Aig_ManStop( pMan1 );
4226
            Abc_Print( 1, "Object with ID %d is not a node or reg output.\n", nObjId );
Alan Mishchenko committed
4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260
            return NULL;
        }
    }
    if ( pCare )
    {
        pMan2 = Abc_NtkToDar( pCare, 0, 0 );
        if ( pMan2 == NULL )
        {
            Aig_ManStop( pMan1 );
            return NULL;
        }
    }
    pMan = Saig_ManWindowInsert( pMan1, pObj, nDist, pMan2 );
    Aig_ManStop( pMan1 );
    if ( pMan2 )
        Aig_ManStop( pMan2 );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromDarSeqSweep( pNtk, pMan );
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
4261 4262 4263 4264
Abc_Ntk_t * Abc_NtkDarFrames( Abc_Ntk_t * pNtk, int nPrefix, int nFrames, int fInit, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
Alan Mishchenko committed
4265
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280
    if ( pMan == NULL )
        return NULL;
    pMan = Saig_ManTimeframeSimplify( pTemp = pMan, nPrefix, nFrames, fInit, fVerbose );
    Aig_ManStop( pTemp );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pNtk->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pNtk->pSpec);
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

Alan Mishchenko committed
4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298
  Synopsis    [Performs phase abstraction.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarCleanupAig( Abc_Ntk_t * pNtk, int fCleanupPis, int fCleanupPos, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan;
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    if ( fCleanupPis )
    {
4299
        int Temp = Aig_ManCiCleanup( pMan );
Alan Mishchenko committed
4300
        if ( fVerbose )
4301
            Abc_Print( 1, "Cleanup removed %d primary inputs without fanout.\n", Temp );                                                                     
Alan Mishchenko committed
4302 4303 4304
    }
    if ( fCleanupPos )
    {
4305
        int Temp = Aig_ManCoCleanup( pMan );
Alan Mishchenko committed
4306
        if ( fVerbose )
4307
            Abc_Print( 1, "Cleanup removed %d primary outputs driven by const-0.\n", Temp );                                                                     
Alan Mishchenko committed
4308 4309 4310 4311 4312 4313 4314 4315 4316 4317
    }
    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pNtk->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pNtk->pSpec);
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

Alan Mishchenko committed
4318 4319 4320 4321 4322 4323 4324 4325 4326
  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
4327
int Abc_NtkDarReach( Abc_Ntk_t * pNtk, Saig_ParBbr_t * pPars )
Alan Mishchenko committed
4328 4329
{
    Aig_Man_t * pMan;
4330
    int RetValue;
Alan Mishchenko committed
4331
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
Alan Mishchenko committed
4332
    if ( pMan == NULL )
4333 4334
        return -1;
    RetValue = Aig_ManVerifyUsingBdds( pMan, pPars );
Alan Mishchenko committed
4335 4336
    ABC_FREE( pNtk->pModel );
    ABC_FREE( pNtk->pSeqModel );
Alan Mishchenko committed
4337
    pNtk->pSeqModel = pMan->pSeqModel; pMan->pSeqModel = NULL;
Alan Mishchenko committed
4338
    Aig_ManStop( pMan );
4339
    return RetValue;
Alan Mishchenko committed
4340 4341
}

4342 4343
ABC_NAMESPACE_IMPL_END

4344 4345
#include "map/amap/amap.h"
#include "map/mio/mio.h"
Alan Mishchenko committed
4346

4347 4348 4349
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Amap_ManProduceNetwork( Abc_Ntk_t * pNtk, Vec_Ptr_t * vMapping )
{
4363 4364
//    extern void * Abc_FrameReadLibGen();
    Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen();
Alan Mishchenko committed
4365 4366 4367 4368 4369 4370
    Amap_Out_t * pRes;
    Vec_Ptr_t * vNodesNew;
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pNodeNew, * pFaninNew;
    int i, k, iPis, iPos, nDupGates;
    // make sure gates exist in the current library
4371
    Vec_PtrForEachEntry( Amap_Out_t *, vMapping, pRes, i )
4372
        if ( pRes->pName && Mio_LibraryReadGateByName( pLib, pRes->pName, NULL ) == NULL )
Alan Mishchenko committed
4373
        {
4374
            Abc_Print( 1, "Current library does not contain gate \"%s\".\n", pRes->pName );
Alan Mishchenko committed
4375 4376 4377 4378 4379 4380 4381
            return NULL;
        }
    // create the network
    pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_MAP );
    pNtkNew->pManFunc = pLib;
    iPis = iPos = 0;
    vNodesNew = Vec_PtrAlloc( Vec_PtrSize(vMapping) );
4382
    Vec_PtrForEachEntry( Amap_Out_t *, vMapping, pRes, i )
Alan Mishchenko committed
4383 4384 4385 4386 4387 4388 4389 4390
    {
        if ( pRes->Type == -1 )
            pNodeNew = Abc_NtkCi( pNtkNew, iPis++ );
        else if ( pRes->Type == 1 )
            pNodeNew = Abc_NtkCo( pNtkNew, iPos++ );
        else
        {
            pNodeNew = Abc_NtkCreateNode( pNtkNew );
4391
            pNodeNew->pData = Mio_LibraryReadGateByName( pLib, pRes->pName, NULL );
Alan Mishchenko committed
4392 4393 4394
        }
        for ( k = 0; k < pRes->nFans; k++ )
        {
4395
            pFaninNew = (Abc_Obj_t *)Vec_PtrEntry( vNodesNew, pRes->pFans[k] );
Alan Mishchenko committed
4396 4397 4398 4399 4400 4401 4402 4403
            Abc_ObjAddFanin( pNodeNew, pFaninNew );
        }
        Vec_PtrPush( vNodesNew, pNodeNew );
    }
    Vec_PtrFree( vNodesNew );
    assert( iPis == Abc_NtkCiNum(pNtkNew) );
    assert( iPos == Abc_NtkCoNum(pNtkNew) );
    // decouple the PO driver nodes to reduce the number of levels
4404
    nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, 0 );
Alan Mishchenko committed
4405
//    if ( nDupGates && Map_ManReadVerbose(pMan) )
4406
//        Abc_Print( 1, "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
Alan Mishchenko committed
4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422
    return pNtkNew;
}

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

  Synopsis    [Gives the current ABC network to AIG manager for processing.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarAmap( Abc_Ntk_t * pNtk, Amap_Par_t * pPars )
{
Alan Mishchenko committed
4423
    extern Vec_Ptr_t * Amap_ManTest( Aig_Man_t * pAig, Amap_Par_t * pPars );
Alan Mishchenko committed
4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439
    Vec_Ptr_t * vMapping;
    Abc_Ntk_t * pNtkAig = NULL;
    Aig_Man_t * pMan;
    Aig_MmFlex_t * pMem;

    assert( Abc_NtkIsStrash(pNtk) );
    // convert to the AIG manager
    pMan = Abc_NtkToDarChoices( pNtk );
    if ( pMan == NULL )
        return NULL;

    // perform computation
    vMapping = Amap_ManTest( pMan, pPars );
    Aig_ManStop( pMan );
    if ( vMapping == NULL )
        return NULL;
4440
    pMem = (Aig_MmFlex_t *)Vec_PtrPop( vMapping );
Alan Mishchenko committed
4441 4442 4443 4444 4445 4446 4447
    pNtkAig = Amap_ManProduceNetwork( pNtk, vMapping );
    Aig_MmFlexStop( pMem, 0 );
    Vec_PtrFree( vMapping );

    // make sure everything is okay
    if ( pNtkAig && !Abc_NtkCheck( pNtkAig ) )
    {
4448
        Abc_Print( 1, "Abc_NtkDar: The network check has failed.\n" );
Alan Mishchenko committed
4449 4450 4451 4452 4453
        Abc_NtkDelete( pNtkAig );
        return NULL;
    }
    return pNtkAig;
}
Alan Mishchenko committed
4454

Alan Mishchenko committed
4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465
/**Function*************************************************************

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486
void Abc_NtkDarConstr( Abc_Ntk_t * pNtk, int nFrames, int nConfs, int nProps, int fStruct, int fOldAlgo, int fVerbose )
{
    Aig_Man_t * pMan;//, * pMan2;//, * pTemp;
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return;
    if ( fStruct )
        Saig_ManDetectConstrTest( pMan );
    else
        Saig_ManDetectConstrFuncTest( pMan, nFrames, nConfs, nProps, fOldAlgo, fVerbose );
    Aig_ManStop( pMan );
}

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

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []
4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarOutdec( Abc_Ntk_t * pNtk, int nLits, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    pMan = Saig_ManDecPropertyOutput( pTemp = pMan, nLits, fVerbose );
    Aig_ManStop( pTemp );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pMan->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pMan->pSpec);
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []
4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarUnfold( Abc_Ntk_t * pNtk, int nFrames, int nConfs, int nProps, int fStruct, int fOldAlgo, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    if ( fStruct )
        pMan = Saig_ManDupUnfoldConstrs( pTemp = pMan );
    else
        pMan = Saig_ManDupUnfoldConstrsFunc( pTemp = pMan, nFrames, nConfs, nProps, fOldAlgo, fVerbose );
    Aig_ManStop( pTemp );
    if ( pMan == NULL )
        return NULL;
    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pMan->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pMan->pSpec);
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarFold( Abc_Ntk_t * pNtk, int fCompl, int fVerbose )
{
    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
    pMan = Saig_ManDupFoldConstrsFunc( pTemp = pMan, fCompl, fVerbose );
    Aig_ManStop( pTemp );
    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pMan->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pMan->pSpec);
    Aig_ManStop( pMan );
    return pNtkAig;
}

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

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkDarConstrProfile( Abc_Ntk_t * pNtk, int fVerbose )
{
    extern int Ssw_ManProfileConstraints( Aig_Man_t * p, int nWords, int nFrames, int fVerbose );
    extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
    Aig_Man_t * pMan;
//    Vec_Int_t * vProbOne;
//    Aig_Obj_t * pObj;
//    int i, Entry;
    assert( Abc_NtkIsStrash(pNtk) );
    assert( Abc_NtkConstrNum(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return;
    // value in the init state
//    Abc_AigSetNodePhases( pNtk );
/*
    // derive probabilities
    vProbOne = Saig_ManComputeSwitchProbs( pMan, 48, 16, 1 );
    // iterate over the constraint outputs
    Saig_ManForEachPo( pMan, pObj, i )
    {
        Entry = Vec_IntEntry( vProbOne, Aig_ObjId(pObj) );
        if ( i < Saig_ManPoNum(pMan) - Saig_ManConstrNum(pMan) )
4605
            Abc_Print( 1, "Primary output :  ", i );
4606
        else
4607 4608 4609 4610
            Abc_Print( 1, "Constraint %3d :  ", i-(Saig_ManPoNum(pMan) - Saig_ManConstrNum(pMan)) );
        Abc_Print( 1, "ProbOne = %f  ", Abc_Int2Float(Entry) );
        Abc_Print( 1, "AllZeroValue = %d ", Aig_ObjPhase(pObj) );
        Abc_Print( 1, "\n" );
4611 4612 4613 4614
    }
*/
    // double-check
    Ssw_ManProfileConstraints( pMan, 16, 64, 1 );
4615
    Abc_Print( 1, "TwoFrameSatValue = %d.\n", Ssw_ManSetConstrPhases(pMan, 2, NULL) );
4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631
    // clean up
//    Vec_IntFree( vProbOne );
    Aig_ManStop( pMan );
}

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

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
4632
void Abc_NtkDarTest( Abc_Ntk_t * pNtk, int Num )
Alan Mishchenko committed
4633
{
4634 4635
//    extern void Saig_ManDetectConstr( Aig_Man_t * p );
//    extern void Saig_ManDetectConstrFuncTest( Aig_Man_t * p );
4636 4637 4638
//    extern void Saig_ManFoldConstrTest( Aig_Man_t * pAig );
    extern void Llb_ManComputeDomsTest( Aig_Man_t * pAig, int Num );

4639 4640


Alan Mishchenko committed
4641
//    extern void Fsim_ManTest( Aig_Man_t * pAig );
Alan Mishchenko committed
4642 4643 4644
    extern Vec_Int_t * Saig_StrSimPerformMatching( Aig_Man_t * p0, Aig_Man_t * p1, int nDist, int fVerbose, Aig_Man_t ** ppMiter );
//    Vec_Int_t * vPairs;
    Aig_Man_t * pMan;//, * pMan2;//, * pTemp;
Alan Mishchenko committed
4645 4646 4647 4648
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return;
Alan Mishchenko committed
4649
/*
Alan Mishchenko committed
4650 4651 4652 4653 4654 4655
Aig_ManSetRegNum( pMan, pMan->nRegs );
Aig_ManPrintStats( pMan );
Saig_ManDumpBlif( pMan, "_temp_.blif" );
Aig_ManStop( pMan );
pMan = Saig_ManReadBlif( "_temp_.blif" );
Aig_ManPrintStats( pMan );
Alan Mishchenko committed
4656
*/
Alan Mishchenko committed
4657
/*
Alan Mishchenko committed
4658 4659 4660
    Aig_ManSetRegNum( pMan, pMan->nRegs );
    pTemp = Ssw_SignalCorrespondeceTestPairs( pMan );
    Aig_ManStop( pTemp );
Alan Mishchenko committed
4661 4662
*/

Alan Mishchenko committed
4663 4664 4665 4666 4667
/*
//    Ssw_SecSpecialMiter( pMan, NULL, 2, 1 );
    pMan2 = Aig_ManDupSimple(pMan);
    vPairs = Saig_StrSimPerformMatching( pMan, pMan2, 0, 1, NULL );
    Vec_IntFree( vPairs );
Alan Mishchenko committed
4668
    Aig_ManStop( pMan );
Alan Mishchenko committed
4669 4670
    Aig_ManStop( pMan2 );
*/
4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683
//    Ioa_WriteAigerBufferTest( pMan, "test.aig", 0, 0 );
//    Saig_ManFoldConstrTest( pMan );
    {
    extern void Saig_ManBmcSectionsTest( Aig_Man_t * p );
    extern void Saig_ManBmcTerSimTest( Aig_Man_t * p );
    extern void Saig_ManBmcSupergateTest( Aig_Man_t * p );
    extern void Saig_ManBmcMappingTest( Aig_Man_t * p );
//    Saig_ManBmcSectionsTest( pMan );
//    Saig_ManBmcTerSimTest( pMan );
//    Saig_ManBmcSupergateTest( pMan );
//    Saig_ManBmcMappingTest( pMan );
    }

4684 4685 4686 4687
    {
//        void Pdr_ManEquivClasses( Aig_Man_t * pMan );
//        Pdr_ManEquivClasses( pMan );
    }
4688

4689 4690 4691 4692 4693 4694
//    Llb_ManComputeDomsTest( pMan, Num );
    {
        extern void Llb_ManMinCutTest( Aig_Man_t * pMan, int Num );
        extern void Llb_BddStructAnalysis( Aig_Man_t * pMan );
        extern void Llb_NonlinExperiment( Aig_Man_t * pAig, int Num );
//        Llb_BddStructAnalysis( pMan );
4695
//        Llb_ManMinCutTest( pMan, Num );
4696 4697
//        Llb_NonlinExperiment( pMan, Num );
    }
Alan Mishchenko committed
4698 4699

//    Saig_MvManSimulate( pMan, 1 );
4700 4701
//    Saig_ManDetectConstr( pMan );
//    Saig_ManDetectConstrFuncTest( pMan );
Alan Mishchenko committed
4702

Alan Mishchenko committed
4703
//    Fsim_ManTest( pMan );
Alan Mishchenko committed
4704 4705
    Aig_ManStop( pMan );

Alan Mishchenko committed
4706
}
Alan Mishchenko committed
4707

Alan Mishchenko committed
4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720
/**Function*************************************************************

  Synopsis    [Performs BDD-based reachability analysis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkDarTestNtk( Abc_Ntk_t * pNtk )
{
Alan Mishchenko committed
4721
//    extern Aig_Man_t * Saig_ManDualRail( Aig_Man_t * p, int fMiter );
Alan Mishchenko committed
4722

Alan Mishchenko committed
4723
/*
Alan Mishchenko committed
4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735
    extern Aig_Man_t * Ssw_SignalCorrespondeceTestPairs( Aig_Man_t * pAig );

    Abc_Ntk_t * pNtkAig;
    Aig_Man_t * pMan, * pTemp;
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;

    Aig_ManSetRegNum( pMan, pMan->nRegs );
    pMan = Ssw_SignalCorrespondeceTestPairs( pTemp = pMan );
    Aig_ManStop( pTemp );
Alan Mishchenko committed
4736 4737
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
4738 4739 4740 4741

    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pNtk->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pNtk->pSpec);
Alan Mishchenko committed
4742
    Aig_ManStop( pMan );
Alan Mishchenko committed
4743
    return pNtkAig;
Alan Mishchenko committed
4744 4745
*/
    Abc_Ntk_t * pNtkAig;
Alan Mishchenko committed
4746
    Aig_Man_t * pMan;//, * pTemp;
Alan Mishchenko committed
4747 4748 4749 4750
    assert( Abc_NtkIsStrash(pNtk) );
    pMan = Abc_NtkToDar( pNtk, 0, 1 );
    if ( pMan == NULL )
        return NULL;
4751

Alan Mishchenko committed
4752
/*
Alan Mishchenko committed
4753
    Aig_ManSetRegNum( pMan, pMan->nRegs );
Alan Mishchenko committed
4754
    pMan = Saig_ManDualRail( pTemp = pMan, 1 );
Alan Mishchenko committed
4755
    Aig_ManStop( pTemp );
Alan Mishchenko committed
4756 4757
    if ( pMan == NULL )
        return NULL;
Alan Mishchenko committed
4758 4759 4760 4761 4762

    pNtkAig = Abc_NtkFromAigPhase( pMan );
    pNtkAig->pName = Extra_UtilStrsav(pNtk->pName);
    pNtkAig->pSpec = Extra_UtilStrsav(pNtk->pSpec);
    Aig_ManStop( pMan );
Alan Mishchenko committed
4763 4764 4765 4766 4767
*/

    pNtkAig = Abc_NtkFromDar( pNtk, pMan );
    Aig_ManStop( pMan );

Alan Mishchenko committed
4768 4769
    return pNtkAig;

Alan Mishchenko committed
4770 4771
}

Alan Mishchenko committed
4772 4773 4774 4775
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////

Jiang Long committed
4776
#include "abcDarUnfold2.c"
4777 4778
ABC_NAMESPACE_IMPL_END