bmcCexCut.c 19.9 KB
Newer Older
1 2 3 4 5 6 7 8
/**CFile****************************************************************

  FileName    [bmcCexCut.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [SAT-based bounded model checking.]

9
  Synopsis    [Derives characterization of bad states.]
10 11 12 13 14 15 16 17 18 19 20 21

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "bmc.h"
22
#include "aig/gia/giaAig.h"
23 24 25 26 27 28 29 30 31 32 33 34 35 36

ABC_NAMESPACE_IMPL_START


////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
  Synopsis    [Generate justifying assignments.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Bmc_GiaGenerateJust_rec( Gia_Man_t * p, int iFrame, int iObj, Vec_Bit_t * vValues, Vec_Bit_t * vJustis )
{
    Gia_Obj_t * pObj;
    int Shift = Gia_ManObjNum(p) * iFrame;
    if ( iFrame < 0 )
        return 0;
    assert( iFrame >= 0 );
    if ( Vec_BitEntry( vJustis, Shift + iObj ) )
        return 0;
    Vec_BitWriteEntry( vJustis, Shift + iObj, 1 );
    pObj = Gia_ManObj( p, iObj );
    if ( Gia_ObjIsCo(pObj) )
        return Bmc_GiaGenerateJust_rec( p, iFrame, Gia_ObjFaninId0(pObj, iObj), vValues, vJustis );
    if ( Gia_ObjIsCi(pObj) )
        return Bmc_GiaGenerateJust_rec( p, iFrame-1, Gia_ObjId(p, Gia_ObjRoToRi(p, pObj)), vValues, vJustis );
    assert( Gia_ObjIsAnd(pObj) );
    if ( Vec_BitEntry( vValues, Shift + iObj ) )
    {
        Bmc_GiaGenerateJust_rec( p, iFrame, Gia_ObjFaninId0(pObj, iObj), vValues, vJustis );
        Bmc_GiaGenerateJust_rec( p, iFrame, Gia_ObjFaninId1(pObj, iObj), vValues, vJustis );
    }
    else if ( Vec_BitEntry( vValues, Shift + Gia_ObjFaninId0(pObj, iObj) ) == Gia_ObjFaninC0(pObj) )
        Bmc_GiaGenerateJust_rec( p, iFrame, Gia_ObjFaninId0(pObj, iObj), vValues, vJustis );
    else if ( Vec_BitEntry( vValues, Shift + Gia_ObjFaninId1(pObj, iObj) ) == Gia_ObjFaninC1(pObj) )
        Bmc_GiaGenerateJust_rec( p, iFrame, Gia_ObjFaninId1(pObj, iObj), vValues, vJustis );
    else assert( 0 );
    return 0;
}
void Bmc_GiaGenerateJustNonRec( Gia_Man_t * p, int iFrame, Vec_Bit_t * vValues, Vec_Bit_t * vJustis )
{
    Gia_Obj_t * pObj;
    int i, k, Shift = Gia_ManObjNum(p) * iFrame;
    for ( i = iFrame; i >= 0; i--, Shift -= Gia_ManObjNum(p) )
    {
        Gia_ManForEachObjReverse( p, pObj, k )
        {
            if ( k == 0 || Gia_ObjIsPi(p, pObj) )
                continue;
            if ( !Vec_BitEntry( vJustis, Shift + k ) )
                continue;
            if ( Gia_ObjIsAnd(pObj) )
            {
                if ( Vec_BitEntry( vValues, Shift + k ) )
                {
                    Vec_BitWriteEntry( vJustis, Shift + Gia_ObjFaninId0(pObj, k), 1 );
                    Vec_BitWriteEntry( vJustis, Shift + Gia_ObjFaninId1(pObj, k), 1 );
                }
                else if ( Vec_BitEntry( vValues, Shift + Gia_ObjFaninId0(pObj, k) ) == Gia_ObjFaninC0(pObj) )
                    Vec_BitWriteEntry( vJustis, Shift + Gia_ObjFaninId0(pObj, k), 1 );
                else if ( Vec_BitEntry( vValues, Shift + Gia_ObjFaninId1(pObj, k) ) == Gia_ObjFaninC1(pObj) )
                    Vec_BitWriteEntry( vJustis, Shift + Gia_ObjFaninId1(pObj, k), 1 );
                else assert( 0 );
            }
            else if ( Gia_ObjIsCo(pObj) )
                Vec_BitWriteEntry( vJustis, Shift + Gia_ObjFaninId0(pObj, k), 1 );
            else if ( Gia_ObjIsCi(pObj) && i )
                Vec_BitWriteEntry( vJustis, Shift - Gia_ManObjNum(p) + Gia_ObjId(p, Gia_ObjRoToRi(p, pObj)), 1 );
        }
    }
}
void Bmc_GiaGenerateJust( Gia_Man_t * p, Abc_Cex_t * pCex, Vec_Bit_t ** pvValues, Vec_Bit_t ** pvJustis )
{
    Vec_Bit_t * vValues = Vec_BitStart( Gia_ManObjNum(p) * (pCex->iFrame + 1) );
    Vec_Bit_t * vJustis = Vec_BitStart( Gia_ManObjNum(p) * (pCex->iFrame + 1) );
    Gia_Obj_t * pObj;
    int i, k, iBit = 0, fCompl0, fCompl1, fJusti0, fJusti1, Shift;

    Gia_ManCleanMark0(p);
    Gia_ManCleanMark1(p);
    Gia_ManForEachRi( p, pObj, k )
        pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
    for ( Shift = i = 0; i <= pCex->iFrame; i++, Shift += Gia_ManObjNum(p) )
    {
        Gia_ManForEachObj( p, pObj, k )
        {
            if ( Gia_ObjIsAnd(pObj) )
            {
                fCompl0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
                fCompl1 = Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj);
                fJusti0 = Gia_ObjFanin0(pObj)->fMark1;
                fJusti1 = Gia_ObjFanin1(pObj)->fMark1;
                pObj->fMark0 = fCompl0 & fCompl1;
                if ( pObj->fMark0 )
                    pObj->fMark1 = fJusti0 & fJusti1;
                else if ( !fCompl0 && !fCompl1 )
                    pObj->fMark1 = fJusti0 | fJusti1;
                else if ( !fCompl0 )
                    pObj->fMark1 = fJusti0;
                else if ( !fCompl1 )
                    pObj->fMark1 = fJusti1;
                else assert( 0 );
            }
            else if ( Gia_ObjIsCi(pObj) )
            {
                if ( Gia_ObjIsPi(p, pObj) )
                {
                    pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
                    pObj->fMark1 = 1;
                }
                else
                {
                    pObj->fMark0 = Gia_ObjRoToRi(p, pObj)->fMark0;
                    pObj->fMark1 = Gia_ObjRoToRi(p, pObj)->fMark1;
                }
            }
            else if ( Gia_ObjIsCo(pObj) )
            {
                pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
                pObj->fMark1 = Gia_ObjFanin0(pObj)->fMark1;
            }
            else if ( Gia_ObjIsConst0(pObj) )
                pObj->fMark1 = 1;
            else assert( 0 );
            if ( pObj->fMark0 )
                Vec_BitWriteEntry( vValues, Shift + k, 1 );
            if ( pObj->fMark1 )
                Vec_BitWriteEntry( vJustis, Shift + k, 1 );
        }
    }
    assert( iBit == pCex->nBits );
    Gia_ManCleanMark0(p);
    Gia_ManCleanMark1(p);
    // perform backward traversal to mark just nodes
    pObj = Gia_ManPo( p, pCex->iPo );
    assert( Vec_BitEntry(vJustis, Gia_ManObjNum(p) * pCex->iFrame + Gia_ObjId(p, pObj)) == 0 );
//    Bmc_GiaGenerateJust_rec( p, pCex->iFrame, Gia_ObjId(p, pObj), vValues, vJustis );
    Vec_BitWriteEntry(vJustis, Gia_ManObjNum(p) * pCex->iFrame + Gia_ObjId(p, pObj), 1);
    Bmc_GiaGenerateJustNonRec( p, pCex->iFrame, vValues, vJustis );
    assert( Vec_BitEntry(vJustis, Gia_ManObjNum(p) * pCex->iFrame + Gia_ObjId(p, pObj)) == 1 );

    // return the result
    *pvValues = vValues;
    *pvJustis = vJustis;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Gia_Man_t * Bmc_GiaGenerateGiaOne( Gia_Man_t * p, Abc_Cex_t * pCex, Vec_Bit_t ** pvInits, int iFrBeg, int iFrEnd )
{
    Vec_Bit_t * vValues;
    Vec_Bit_t * vJustis;
    Gia_Man_t * pNew;
    Gia_Obj_t * pObj;
    int k, Cube = 1, Counter = 0;
    Bmc_GiaGenerateJust( p, pCex, &vValues, &vJustis );
    // collect flop values in frame iFrBeg
    *pvInits = Vec_BitStart( Gia_ManRegNum(p) );
    Gia_ManForEachRo( p, pObj, k )
        if ( Vec_BitEntry(vValues, Gia_ManObjNum(p) * iFrBeg + Gia_ObjId(p, pObj)) )
            Vec_BitWriteEntry( *pvInits, k, 1 );
    // create GIA with justified values in iFrEnd
    pNew = Gia_ManStart( 2 * Gia_ManRegNum(p) + 2 );
    pNew->pName = Abc_UtilStrsav( p->pName );
    Gia_ManForEachRo( p, pObj, k )
    {
        int Literal = Gia_ManAppendCi(pNew);
        if ( !Vec_BitEntry(vJustis, Gia_ManObjNum(p) * iFrEnd + Gia_ObjId(p, pObj)) )
            continue;
        if ( Vec_BitEntry(vValues, Gia_ManObjNum(p) * iFrEnd + Gia_ObjId(p, pObj)) )
            Cube = Gia_ManAppendAnd( pNew, Cube, Literal );
        else
            Cube = Gia_ManAppendAnd( pNew, Cube, Abc_LitNot(Literal) );
        Counter++;
    }
//    printf( "Only %d flops (out of %d) belong to the care set.\n", Counter, Gia_ManRegNum(p) );
    Gia_ManAppendCo( pNew, Cube );
    Vec_BitFree( vValues );
    Vec_BitFree( vJustis );
    return pNew;
}

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

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
  Synopsis    [Generates all frames from G to the last one.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Gia_Man_t * Bmc_GiaGenerateGiaAllFrames( Gia_Man_t * p, Abc_Cex_t * pCex, Vec_Bit_t ** pvInits, int iFrBeg, int iFrEnd )
{
    Vec_Bit_t * vInitEnd;
    Gia_Man_t * pNew, * pTemp;
    Gia_Obj_t * pObj, * pObjRo, * pObjRi;
    int f, i, k, iBitOld, iBit = 0, fCompl0, fCompl1;

    // skip trough the first iFrEnd frames
    Gia_ManCleanMark0(p);
    Gia_ManForEachRo( p, pObj, k )
        pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
    *pvInits = Vec_BitStart( Gia_ManRegNum(p) );
    for ( i = 0; i < iFrEnd; i++ )
    {
        // remember values in frame iFrBeg
        if ( i == iFrBeg )
            Gia_ManForEachRo( p, pObjRo, k )
                if ( pObjRo->fMark0 )
                    Vec_BitWriteEntry( *pvInits, k, 1 );
        // simulate other values
        Gia_ManForEachPi( p, pObj, k )
            pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
        Gia_ManForEachAnd( p, pObj, k )
            pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) & 
                           (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
        Gia_ManForEachCo( p, pObj, k )
            pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
        Gia_ManForEachRiRo( p, pObjRi, pObjRo, k )
            pObjRo->fMark0 = pObjRi->fMark0;
    }
    assert( i == iFrEnd );
    vInitEnd = Vec_BitStart( Gia_ManRegNum(p) );
    Gia_ManForEachRo( p, pObjRo, k )
        if ( pObjRo->fMark0 )
            Vec_BitWriteEntry( vInitEnd, k, 1 );

    // create new AIG manager
    pNew = Gia_ManStart( 10000 );
    pNew->pName = Abc_UtilStrsav( p->pName );
    Gia_ManForEachRo( p, pObjRo, k )
        Gia_ManAppendCi(pNew);
    Gia_ManHashStart( pNew );

    Gia_ManConst0(p)->Value = 1;
    Gia_ManForEachPi( p, pObj, k )
        pObj->Value = 1;

    iBitOld = iBit;
    for ( f = iFrEnd; f <= pCex->iFrame; f++ )
    {
        // set up correct init state
        Gia_ManForEachRo( p, pObjRo, k )
            pObjRo->fMark0 = Vec_BitEntry( vInitEnd, k );
        // simulate it for a few frames
        iBit = iBitOld;
        for ( i = iFrEnd; i < f; i++ )
        {
            Gia_ManForEachPi( p, pObj, k )
                pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
            Gia_ManForEachAnd( p, pObj, k )
                pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) & 
                               (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
            Gia_ManForEachCo( p, pObj, k )
                pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
            Gia_ManForEachRiRo( p, pObjRi, pObjRo, k )
                pObjRo->fMark0 = pObjRi->fMark0;
        }
        // start creating values
        Gia_ManForEachRo( p, pObjRo, k )
            pObjRo->Value = Abc_LitNotCond( Gia_Obj2Lit(pNew, Gia_ManPi(pNew, k)), !pObjRo->fMark0 );
        for ( i = f; i <= pCex->iFrame; i++ )
        {
            Gia_ManForEachPi( p, pObj, k )
                pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
            Gia_ManForEachAnd( p, pObj, k )
            {
                fCompl0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
                fCompl1 = Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj);
                pObj->fMark0 = fCompl0 & fCompl1;
                if ( pObj->fMark0 )
                    pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value );
                else if ( !fCompl0 && !fCompl1 )
                    pObj->Value = Gia_ManHashOr( pNew, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value );
                else if ( !fCompl0 )
                    pObj->Value = Gia_ObjFanin0(pObj)->Value;
                else if ( !fCompl1 )
                    pObj->Value = Gia_ObjFanin1(pObj)->Value;
                else assert( 0 );
                assert( pObj->Value > 0 );
            }
            Gia_ManForEachCo( p, pObj, k )
            {
                pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
                pObj->Value = Gia_ObjFanin0(pObj)->Value;
                assert( pObj->Value > 0 );
            } 
            if ( i == pCex->iFrame )
                break;
            Gia_ManForEachRiRo( p, pObjRi, pObjRo, k )
            {
                pObjRo->fMark0 = pObjRi->fMark0;
                pObjRo->Value = pObjRi->Value;
            }
        }
        assert( iBit == pCex->nBits );
        // create PO
        Gia_ManAppendCo( pNew, Gia_ManPo(p, pCex->iPo)->Value );
    }
    Gia_ManHashStop( pNew );
    Vec_BitFree( vInitEnd );

    // cleanup
    pNew = Gia_ManCleanup( pTemp = pNew );
    Gia_ManStop( pTemp );
    return pNew;
}

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

  Synopsis    [Generates one frame.]
357 358 359 360 361 362 363 364

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
365
Gia_Man_t * Bmc_GiaGenerateGiaAllOne( Gia_Man_t * p, Abc_Cex_t * pCex, Vec_Bit_t ** pvInits, int iFrBeg, int iFrEnd )
366
{
367 368
    Gia_Man_t * pNew, * pTemp;
    Gia_Obj_t * pObj, * pObjRo, * pObjRi;
369
    int i, k, iBit = 0, fCompl0, fCompl1;
370 371 372

    // skip trough the first iFrEnd frames
    Gia_ManCleanMark0(p);
373
    Gia_ManForEachRo( p, pObj, k )
374
        pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
375
    *pvInits = Vec_BitStart( Gia_ManRegNum(p) );
376 377 378 379 380 381
    for ( i = 0; i < iFrEnd; i++ )
    {
        // remember values in frame iFrBeg
        if ( i == iFrBeg )
            Gia_ManForEachRo( p, pObjRo, k )
                if ( pObjRo->fMark0 )
382
                    Vec_BitWriteEntry( *pvInits, k, 1 );
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
        // simulate other values
        Gia_ManForEachPi( p, pObj, k )
            pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
        Gia_ManForEachAnd( p, pObj, k )
            pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) & 
                           (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
        Gia_ManForEachCo( p, pObj, k )
            pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
        Gia_ManForEachRiRo( p, pObjRi, pObjRo, k )
            pObjRo->fMark0 = pObjRi->fMark0;
    }
    assert( i == iFrEnd );

    // create new AIG manager
    pNew = Gia_ManStart( 10000 );
398
    pNew->pName = Abc_UtilStrsav( p->pName );
399 400 401
    Gia_ManConst0(p)->Value = 1;
    Gia_ManForEachPi( p, pObj, k )
        pObj->Value = 1;
402 403 404
    Gia_ManForEachRo( p, pObjRo, k )
        pObjRo->Value = Abc_LitNotCond( Gia_ManAppendCi(pNew), !pObjRo->fMark0 );
    Gia_ManHashStart( pNew );
405 406 407 408 409 410
    for ( i = iFrEnd; i <= pCex->iFrame; i++ )
    {
        Gia_ManForEachPi( p, pObj, k )
            pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
        Gia_ManForEachAnd( p, pObj, k )
        {
411 412 413
            fCompl0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
            fCompl1 = Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj);
            pObj->fMark0 = fCompl0 & fCompl1;
414
            if ( pObj->fMark0 )
415 416 417 418
                pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value );
            else if ( !fCompl0 && !fCompl1 )
                pObj->Value = Gia_ManHashOr( pNew, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value );
            else if ( !fCompl0 )
419
                pObj->Value = Gia_ObjFanin0(pObj)->Value;
420
            else if ( !fCompl1 )
421 422
                pObj->Value = Gia_ObjFanin1(pObj)->Value;
            else assert( 0 );
423
            assert( pObj->Value > 0 );
424 425 426 427 428
        }
        Gia_ManForEachCo( p, pObj, k )
        {
            pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
            pObj->Value = Gia_ObjFanin0(pObj)->Value;
429 430
            assert( pObj->Value > 0 );
        } 
431 432 433 434 435 436 437 438
        if ( i == pCex->iFrame )
            break;
        Gia_ManForEachRiRo( p, pObjRi, pObjRo, k )
        {
            pObjRo->fMark0 = pObjRi->fMark0;
            pObjRo->Value = pObjRi->Value;
        }
    }
439
    Gia_ManHashStop( pNew );
440 441 442 443 444 445 446
    assert( iBit == pCex->nBits );

    // create PO
    Gia_ManAppendCo( pNew, Gia_ManPo(p, pCex->iPo)->Value );
    // cleanup
    pNew = Gia_ManCleanup( pTemp = pNew );
    Gia_ManStop( pTemp );
447 448 449 450 451 452 453 454 455 456 457 458 459 460
    return pNew;
}

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

  Synopsis    [Generate GIA for target bad states.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
461
Gia_Man_t * Bmc_GiaTargetStates( Gia_Man_t * p, Abc_Cex_t * pCex, int iFrBeg, int iFrEnd, int fCombOnly, int fUseOne, int fAllFrames, int fVerbose )
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
{
    Gia_Man_t * pNew, * pTemp;
    Vec_Bit_t * vInitNew;

    if ( iFrBeg < 0 )
        { printf( "Starting frame is less than 0.\n" ); return NULL; }
    if ( iFrEnd < 0 )
        { printf( "Stopping frame is less than 0.\n" ); return NULL; }
    if ( iFrBeg > pCex->iFrame )
        { printf( "Starting frame is more than the last frame of CEX (%d).\n", pCex->iFrame ); return NULL; }
    if ( iFrEnd > pCex->iFrame )
        { printf( "Stopping frame is more than the last frame of CEX (%d).\n", pCex->iFrame ); return NULL; }
    if ( iFrBeg > iFrEnd )
        { printf( "Starting frame (%d) should be less than stopping frame (%d).\n", iFrBeg, iFrEnd ); return NULL; }
    assert( iFrBeg >= 0 && iFrBeg <= pCex->iFrame );
    assert( iFrEnd >= 0 && iFrEnd <= pCex->iFrame );
    assert( iFrBeg < iFrEnd );

    if ( fUseOne )
        pNew = Bmc_GiaGenerateGiaOne( p, pCex, &vInitNew, iFrBeg, iFrEnd );
482 483 484 485
    else if ( fAllFrames )
        pNew = Bmc_GiaGenerateGiaAllFrames( p, pCex, &vInitNew, iFrBeg, iFrEnd );
    else 
        pNew = Bmc_GiaGenerateGiaAllOne( p, pCex, &vInitNew, iFrBeg, iFrEnd );
486

487 488 489 490 491
    if ( !fCombOnly )
    {
        // create new GIA
        pNew = Gia_ManDupWithNewPo( p, pTemp = pNew ); 
        Gia_ManStop( pTemp );
492

493 494 495 496
        // create new initial state
        pNew = Gia_ManDupFlip( pTemp = pNew, Vec_BitArray(vInitNew) );
        Gia_ManStop( pTemp );
    }
497

498 499
    Vec_BitFree( vInitNew );
    return pNew;
500
}
501

502 503 504 505 506 507 508 509 510 511 512
/**Function*************************************************************

  Synopsis    [Generate AIG for target bad states.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
513
Aig_Man_t * Bmc_AigTargetStates( Aig_Man_t * p, Abc_Cex_t * pCex, int iFrBeg, int iFrEnd, int fCombOnly, int fUseOne, int fAllFrames, int fVerbose )
514 515 516 517 518 519
{
    Aig_Man_t * pAig;
    Gia_Man_t * pGia, * pRes;
    pGia = Gia_ManFromAigSimple( p );
    if ( !Gia_ManVerifyCex( pGia, pCex, 0 ) )
    {
520
        Abc_Print( 1, "Current CEX does not fail AIG \"%s\".\n", p->pName ); 
521 522 523
        Gia_ManStop( pGia );
        return NULL;
    }
524
    pRes = Bmc_GiaTargetStates( pGia, pCex, iFrBeg, iFrEnd, fCombOnly, fUseOne, fAllFrames, fVerbose );
525
    Gia_ManStop( pGia );
526
    pAig = Gia_ManToAigSimple( pRes );
527 528 529 530
    Gia_ManStop( pRes );
    return pAig;
}

531 532 533 534 535 536 537
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END