ioReadPla.c 20.5 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    [ioReadPla.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Command processing package.]

  Synopsis    [Procedure to read network from file.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

Alan Mishchenko committed
21
#include "ioAbc.h"
22
#include "misc/util/utilTruth.h"
Alan Mishchenko committed
23

24 25 26
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
27 28 29 30
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

31
static Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p, int fZeros, int fBoth, int fOnDc, int fSkipPrepro );
Alan Mishchenko committed
32 33

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
34
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
35 36
////////////////////////////////////////////////////////////////////////

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
/**Function*************************************************************

  Synopsis    [Checks if cubes are distance-1.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Io_ReadPlaPrintCube( word * p, int nVars )
{
    char Symbs[3] = {'-', '0', '1'}; int v;
    for ( v = 0; v < nVars; v++ )
        printf( "%c", Symbs[Abc_TtGetQua(p, v)] );
    printf( "\n" );
}

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

  Synopsis    [Checks if cubes are distance-1.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline int Io_ReadPlaDistance1( word * p, word * q, int nWords )
{
    word Test; int c, fFound = 0;
    for ( c = 0; c < nWords; c++ )
    {
        if ( p[c] == q[c] )
            continue;
        if ( fFound )
            return 0;
        // check if the number of 1s is one
//        Test = ((p[c] ^ q[c]) & ((p[c] ^ q[c]) >> 1)) & ABC_CONST(0x5555555555555555); // exactly one 0/1 literal (but may be -/0 or -/1)
        Test = ((p[c] ^ q[c]) | ((p[c] ^ q[c]) >> 1)) & ABC_CONST(0x5555555555555555);
        if ( !Abc_TtOnlyOneOne(Test) )
            return 0;
        fFound = 1;
    }
    return fFound;
}
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
static inline int Io_ReadPlaConsensus( word * p, word * q, int nWords, int * piVar )
{
    word Test; int c, fFound = 0;
    for ( c = 0; c < nWords; c++ )
    {
        if ( p[c] == q[c] )
            continue;
        if ( fFound )
            return 0;
        // check if there is exactly one opposite literal (0/1) but may have other diffs (-/0 or -/1)
        Test = ((p[c] ^ q[c]) & ((p[c] ^ q[c]) >> 1)) & ABC_CONST(0x5555555555555555); 
        if ( !Abc_TtOnlyOneOne(Test) )
            return 0;
        fFound = 1;
        *piVar = c * 32 + Abc_Tt6FirstBit(Test)/2;
    }
    return fFound;
}
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
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Io_ReadPlaMarkIdentical( word ** pCs, int nCubes, int nWords, Vec_Bit_t * vMarks )
{
    int c1, c2;
    Vec_BitFill( vMarks, nCubes, 0 );
    for ( c1 = 0; c1 < nCubes; c1++ )
        if ( !Vec_BitEntry(vMarks, c1) )
            for ( c2 = c1 + 1; c2 < nCubes; c2++ )
                if ( !Vec_BitEntry(vMarks, c2) )
                    if ( Abc_TtEqual(pCs[c1], pCs[c2], nWords) )
                        Vec_BitWriteEntry( vMarks, c2, 1 );
}
void Io_ReadPlaMarkContained( word ** pCs, int nCubes, int nWords, Vec_Bit_t * vMarks )
{
    int c1, c2;
    Vec_BitFill( vMarks, nCubes, 0 );
    for ( c1 = 0; c1 < nCubes; c1++ )
        if ( !Vec_BitEntry(vMarks, c1) )
            for ( c2 = c1 + 1; c2 < nCubes; c2++ )
                if ( !Vec_BitEntry(vMarks, c2) )
                {
                    if ( Abc_TtImply(pCs[c1], pCs[c2], nWords) )
                        Vec_BitWriteEntry( vMarks, c2, 1 );
                    else if ( Abc_TtImply(pCs[c2], pCs[c1], nWords) )
                    {
                        Vec_BitWriteEntry( vMarks, c1, 1 );
                        break;
                    }
                }
}
int Io_ReadPlaRemoveMarked( word ** pCs, int nCubes, int nWords, Vec_Bit_t * vMarks )
{
    int c1, c;
    for ( c1 = c = 0; c1 < nCubes; c1++ )
        if ( !Vec_BitEntry(vMarks, c1) )
        {
            if ( c == c1 )
                c++;
            else
                Abc_TtCopy( pCs[c++], pCs[c1], nWords, 0 );
        }
    return c;
157
}
158
int Io_ReadPlaMergeDistance1( word ** pCs, int nCubes, int nWords, Vec_Bit_t * vMarks )
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
{
    int c1, c2, Res, Counter = 0;
    Vec_BitFill( vMarks, nCubes, 0 );
    for ( c1 = 0; c1 < nCubes; c1++ )
        if ( !Vec_BitEntry(vMarks, c1) )
            for ( c2 = c1 + 1; c2 < nCubes; c2++ )
                if ( !Vec_BitEntry(vMarks, c2) )
                {
                    Res = Io_ReadPlaDistance1( pCs[c1], pCs[c2], nWords );
                    if ( !Res )
                        continue;
                    Abc_TtAnd( pCs[c1], pCs[c1], pCs[c2], nWords, 0 );
                    Vec_BitWriteEntry( vMarks, c2, 1 );
                    Counter++;
                    break;
                }
    return Counter;
}
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
int Io_ReadPlaSelfSubsumption( word ** pCs, int nCubes, int nWords, Vec_Bit_t * vMarks )
{
    int c1, c2, Res, Counter = 0, iVar = -1, Val0, Val1;
    Vec_BitFill( vMarks, nCubes, 0 );
    for ( c1 = 0; c1 < nCubes; c1++ )
        if ( !Vec_BitEntry(vMarks, c1) )
            for ( c2 = c1 + 1; c2 < nCubes; c2++ )
                if ( !Vec_BitEntry(vMarks, c2) )
                {
                    Res = Io_ReadPlaConsensus( pCs[c1], pCs[c2], nWords, &iVar );
                    if ( !Res )
                        continue;
                    assert( iVar >= 0  && iVar < nWords*32 );
                    Val0 = Abc_TtGetQua( pCs[c1], iVar );
                    Val1 = Abc_TtGetQua( pCs[c2], iVar );
                    // remove values
                    Abc_TtXorQua( pCs[c1], iVar, Val0 );
                    Abc_TtXorQua( pCs[c2], iVar, Val1 );
                    // check containment
                    if ( Abc_TtImply(pCs[c1], pCs[c2], nWords) )
                    {
                        Abc_TtXorQua( pCs[c1], iVar, Val0 );
                        Vec_BitWriteEntry( vMarks, c2, 1 );
                        Counter++;
                    }
                    else if ( Abc_TtImply(pCs[c2], pCs[c1], nWords) )
                    {
                        Abc_TtXorQua( pCs[c2], iVar, Val1 );
                        Vec_BitWriteEntry( vMarks, c1, 1 );
                        Counter++;
                        break;
                    }
                    else
                    {
                        Abc_TtXorQua( pCs[c1], iVar, Val0 );
                        Abc_TtXorQua( pCs[c2], iVar, Val1 );
                    }

/*
                    printf( "Var = %3d  ", iVar );
                    printf( "Cube0 = %d  ", Abc_TtGetQua(pCs[c1], iVar) );
                    printf( "Cube1 = %d  ", Abc_TtGetQua(pCs[c2], iVar) );
                    printf( "\n" );
                    Io_ReadPlaPrintCube( pCs[c1], 32 * nWords );
                    Io_ReadPlaPrintCube( pCs[c2], 32 * nWords );
                    printf( "\n" );
*/
                    break;
                }
    return Counter;
}
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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
word ** Io_ReadPlaCubeSetup( Vec_Str_t * vSop )
{
    char * pSop = Vec_StrArray( vSop ), * pCube, Lit;
    int nCubes  = Abc_SopGetCubeNum( pSop );
    int nVars   = Abc_SopGetVarNum( pSop );
    int nWords  = Abc_Bit6WordNum( 2*nVars ), c, v;
    word ** pCs = ABC_ALLOC( word *, nCubes );
    pCs[0] = ABC_CALLOC( word, nCubes * nWords );
    for ( c = 1; c < nCubes; c++ )
        pCs[c] = pCs[c-1] + nWords;
    c = 0;
    Abc_SopForEachCube( pSop, nVars, pCube )
    {
        Abc_CubeForEachVar( pCube, Lit, v )
            if ( Lit == '0' )
                Abc_TtSetBit( pCs[c], Abc_Var2Lit(v,0) );
            else if ( Lit == '1' )
                Abc_TtSetBit( pCs[c], Abc_Var2Lit(v,1) );
        c++;
    }
    assert( c == nCubes );
    return pCs;
}
void Io_ReadPlaCubeSetdown( Vec_Str_t * vSop, word ** pCs, int nCubes, int nVars )
{
265
    char Symbs[3] = {'-', '0', '1'}; int c, v;
266 267 268
    Vec_StrClear( vSop );
    for ( c = 0; c < nCubes; c++ )
    {
269 270
        for ( v = 0; v < nVars; v++ )
            Vec_StrPush( vSop, Symbs[Abc_TtGetQua(pCs[c], v)] );
271 272 273 274 275 276 277 278 279
        Vec_StrPrintStr( vSop, " 1\n" );
    }
    Vec_StrPush( vSop, 0 );
}
void Io_ReadPlaCubePreprocess( Vec_Str_t * vSop, int iCover, int fVerbose )
{
    word ** pCs = Io_ReadPlaCubeSetup( vSop );
    int nCubes  = Abc_SopGetCubeNum( Vec_StrArray(vSop) );
    int nVars   = Abc_SopGetVarNum( Vec_StrArray(vSop) );
280
    int nWords  = Abc_Bit6WordNum( 2*nVars );
281
    int nCubesNew, Count, Iter = 0;
282 283
    Vec_Bit_t * vMarks = Vec_BitStart( nCubes );
    if ( fVerbose )
284 285
        printf( "Cover %5d : V =%5d  C%d =%5d", iCover, nVars, Iter, nCubes );

286 287
    do 
    {
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
        Iter++;
        do 
        {
            // remove contained
            Io_ReadPlaMarkContained( pCs, nCubes, nWords, vMarks );
            nCubesNew = Io_ReadPlaRemoveMarked( pCs, nCubes, nWords, vMarks );
            //if ( fVerbose )
            //    printf( "  C =%5d", nCubes - nCubesNew );
            nCubes = nCubesNew;
            // merge distance-1
            Count = Io_ReadPlaMergeDistance1( pCs, nCubes, nWords, vMarks );
        } while ( Count );
        if ( fVerbose )
            printf( "  C%d =%5d", Iter, nCubes );
        // try consensus
303
        //Count = Io_ReadPlaSelfSubsumption( pCs, nCubes, nWords, vMarks );
304
        if ( fVerbose )
305
            printf( "%4d", Count );
306
    } while ( Count );
307

308 309 310 311 312 313 314 315 316 317
    // translate
    Io_ReadPlaCubeSetdown( vSop, pCs, nCubes, nVars );
    // finalize
    if ( fVerbose )
        printf( "\n" );
    Vec_BitFree( vMarks );
    ABC_FREE( pCs[0] );
    ABC_FREE( pCs );
}

Alan Mishchenko committed
318 319
/**Function*************************************************************

Alan Mishchenko committed
320
  Synopsis    [Reads the network from a PLA file.]
Alan Mishchenko committed
321

Alan Mishchenko committed
322
  Description []
Alan Mishchenko committed
323 324 325 326 327 328
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
329
Abc_Ntk_t * Io_ReadPla( char * pFileName, int fZeros, int fBoth, int fOnDc, int fSkipPrepro, int fCheck )
Alan Mishchenko committed
330 331 332 333 334
{
    Extra_FileReader_t * p;
    Abc_Ntk_t * pNtk;

    // start the file
Alan Mishchenko committed
335
    p = Extra_FileReaderAlloc( pFileName, "#", "\n\r", " \t|" );
336
//    p = Extra_FileReaderAlloc( pFileName, "", "\n\r", " \t|" );
Alan Mishchenko committed
337 338 339 340
    if ( p == NULL )
        return NULL;

    // read the network
341
    pNtk = Io_ReadPlaNetwork( p, fZeros, fBoth, fOnDc, fSkipPrepro );
Alan Mishchenko committed
342 343 344 345 346
    Extra_FileReaderFree( p );
    if ( pNtk == NULL )
        return NULL;

    // make sure that everything is okay with the network structure
Alan Mishchenko committed
347
    if ( fCheck && !Abc_NtkCheckRead( pNtk ) )
Alan Mishchenko committed
348 349 350 351 352 353 354 355 356
    {
        printf( "Io_ReadPla: The network check has failed.\n" );
        Abc_NtkDelete( pNtk );
        return NULL;
    }
    return pNtk;
}
/**Function*************************************************************

Alan Mishchenko committed
357
  Synopsis    []
Alan Mishchenko committed
358

Alan Mishchenko committed
359
  Description []
Alan Mishchenko committed
360 361 362 363 364 365
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
366
Abc_Ntk_t * Io_ReadPlaNetwork( Extra_FileReader_t * p, int fZeros, int fBoth, int fOnDc, int fSkipPrepro )
Alan Mishchenko committed
367 368 369 370
{
    ProgressBar * pProgress;
    Vec_Ptr_t * vTokens;
    Abc_Ntk_t * pNtk;
Alan Mishchenko committed
371
    Abc_Obj_t * pTermPi, * pTermPo, * pNode;
Alan Mishchenko committed
372
    Vec_Str_t ** ppSops = NULL;
Alan Mishchenko committed
373 374 375 376
    char Buffer[100];
    int nInputs = -1, nOutputs = -1, nProducts = -1;
    char * pCubeIn, * pCubeOut;
    int i, k, iLine, nDigits, nCubes;
377

Alan Mishchenko committed
378
    // allocate the empty network
Alan Mishchenko committed
379
    pNtk = Abc_NtkStartRead( Extra_FileReaderGetFileName(p) );
Alan Mishchenko committed
380 381 382 383

    // go through the lines of the file
    nCubes = 0;
    pProgress = Extra_ProgressBarStart( stdout, Extra_FileReaderGetFileSize(p) );
384
    while ( (vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p)) )
Alan Mishchenko committed
385 386
    {
        Extra_ProgressBarUpdate( pProgress, Extra_FileReaderGetCurPosition(p), NULL );
387
        iLine = Extra_FileReaderGetLineNumber( p, 0 );
Alan Mishchenko committed
388 389

        // if it is the end of file, quit the loop
390
        if ( strncmp( (char *)vTokens->pArray[0], ".e", 2 ) == 0 )
Alan Mishchenko committed
391 392
            break;

393 394 395 396
        // if it is type directive, ignore it for now
        if ( strncmp( (char *)vTokens->pArray[0], ".type", 5 ) == 0 )
            continue;

397 398 399 400 401 402 403 404
        // if it is the model name, get the name
        if ( strcmp( (char *)vTokens->pArray[0], ".model" ) == 0 )
        {
            ABC_FREE( pNtk->pName );
            pNtk->pName = Extra_UtilStrsav( (char *)vTokens->pArray[1] );
            continue;
        }

Alan Mishchenko committed
405 406 407
        if ( vTokens->nSize == 1 )
        {
            printf( "%s (line %d): Wrong number of token.\n", 
408
                Extra_FileReaderGetFileName(p), iLine );
Alan Mishchenko committed
409
            Abc_NtkDelete( pNtk );
410 411
            Extra_ProgressBarStop( pProgress );
            ABC_FREE( ppSops );
Alan Mishchenko committed
412 413 414
            return NULL;
        }

415 416 417 418 419 420 421
        if ( strcmp( (char *)vTokens->pArray[0], ".i" ) == 0 )
            nInputs = atoi((char *)vTokens->pArray[1]);
        else if ( strcmp( (char *)vTokens->pArray[0], ".o" ) == 0 )
            nOutputs = atoi((char *)vTokens->pArray[1]);
        else if ( strcmp( (char *)vTokens->pArray[0], ".p" ) == 0 )
            nProducts = atoi((char *)vTokens->pArray[1]);
        else if ( strcmp( (char *)vTokens->pArray[0], ".ilb" ) == 0 )
Alan Mishchenko committed
422 423 424 425
        {
            if ( vTokens->nSize - 1 != nInputs )
                printf( "Warning: Mismatch between the number of PIs on the .i line (%d) and the number of PIs on the .ilb line (%d).\n", nInputs, vTokens->nSize - 1 );
            for ( i = 1; i < vTokens->nSize; i++ )
426
                Io_ReadCreatePi( pNtk, (char *)vTokens->pArray[i] );
Alan Mishchenko committed
427
        }
428
        else if ( strcmp( (char *)vTokens->pArray[0], ".ob" ) == 0 )
Alan Mishchenko committed
429 430 431 432
        {
            if ( vTokens->nSize - 1 != nOutputs )
                printf( "Warning: Mismatch between the number of POs on the .o line (%d) and the number of POs on the .ob line (%d).\n", nOutputs, vTokens->nSize - 1 );
            for ( i = 1; i < vTokens->nSize; i++ )
433
                Io_ReadCreatePo( pNtk, (char *)vTokens->pArray[i] );
Alan Mishchenko committed
434
        }
Alan Mishchenko committed
435
        else 
Alan Mishchenko committed
436 437 438 439 440 441 442 443
        {
            // check if the input/output names are given
            if ( Abc_NtkPiNum(pNtk) == 0 )
            {
                if ( nInputs == -1 )
                {
                    printf( "%s: The number of inputs is not specified.\n", Extra_FileReaderGetFileName(p) );
                    Abc_NtkDelete( pNtk );
444 445
                    Extra_ProgressBarStop( pProgress );
                    ABC_FREE( ppSops );
Alan Mishchenko committed
446 447
                    return NULL;
                }
448
                nDigits = Abc_Base10Log( nInputs );
Alan Mishchenko committed
449 450 451
                for ( i = 0; i < nInputs; i++ )
                {
                    sprintf( Buffer, "x%0*d", nDigits, i );
Alan Mishchenko committed
452
                    Io_ReadCreatePi( pNtk, Buffer );
Alan Mishchenko committed
453 454 455 456 457 458 459 460
                }
            }
            if ( Abc_NtkPoNum(pNtk) == 0 )
            {
                if ( nOutputs == -1 )
                {
                    printf( "%s: The number of outputs is not specified.\n", Extra_FileReaderGetFileName(p) );
                    Abc_NtkDelete( pNtk );
461 462
                    Extra_ProgressBarStop( pProgress );
                    ABC_FREE( ppSops );
Alan Mishchenko committed
463 464
                    return NULL;
                }
465
                nDigits = Abc_Base10Log( nOutputs );
Alan Mishchenko committed
466 467 468
                for ( i = 0; i < nOutputs; i++ )
                {
                    sprintf( Buffer, "z%0*d", nDigits, i );
Alan Mishchenko committed
469
                    Io_ReadCreatePo( pNtk, Buffer );
Alan Mishchenko committed
470 471 472 473 474 475
                }
            }
            if ( Abc_NtkNodeNum(pNtk) == 0 )
            { // first time here
                // create the PO drivers and add them
                // start the SOP covers
Alan Mishchenko committed
476
                ppSops = ABC_ALLOC( Vec_Str_t *, nOutputs );
Alan Mishchenko committed
477
                Abc_NtkForEachPo( pNtk, pTermPo, i )
Alan Mishchenko committed
478 479
                {
                    ppSops[i] = Vec_StrAlloc( 100 );
Alan Mishchenko committed
480
                    // create the node
Alan Mishchenko committed
481
                    pNode = Abc_NtkCreateNode(pNtk);
Alan Mishchenko committed
482 483 484 485 486
                    // connect the node to the PO net
                    Abc_ObjAddFanin( Abc_ObjFanin0Ntk(pTermPo), pNode );
                    // connect the node to the PI nets
                    Abc_NtkForEachPi( pNtk, pTermPi, k )
                        Abc_ObjAddFanin( pNode, Abc_ObjFanout0Ntk(pTermPi) );
Alan Mishchenko committed
487 488 489 490 491 492
                }
            }
            // read the cubes
            if ( vTokens->nSize != 2 )
            {
                printf( "%s (line %d): Input and output cubes are not specified.\n", 
493
                    Extra_FileReaderGetFileName(p), iLine );
Alan Mishchenko committed
494
                Abc_NtkDelete( pNtk );
495 496
                Extra_ProgressBarStop( pProgress );
                ABC_FREE( ppSops );
Alan Mishchenko committed
497 498
                return NULL;
            }
499 500
            pCubeIn  = (char *)vTokens->pArray[0];
            pCubeOut = (char *)vTokens->pArray[1];
501
            if ( (int)strlen(pCubeIn) != nInputs )
Alan Mishchenko committed
502
            {
503
                printf( "%s (line %d): Input cube length (%d) differs from the number of inputs (%d).\n",
504
                    Extra_FileReaderGetFileName(p), iLine, (int)strlen(pCubeIn), nInputs );
Alan Mishchenko committed
505
                Abc_NtkDelete( pNtk );
506
                ABC_FREE( ppSops );
Alan Mishchenko committed
507 508
                return NULL;
            }
509
            if ( (int)strlen(pCubeOut) != nOutputs )
Alan Mishchenko committed
510
            {
511
                printf( "%s (line %d): Output cube length (%d) differs from the number of outputs (%d).\n",
512
                    Extra_FileReaderGetFileName(p), iLine, (int)strlen(pCubeOut), nOutputs );
Alan Mishchenko committed
513
                Abc_NtkDelete( pNtk );
514 515
                Extra_ProgressBarStop( pProgress );
                ABC_FREE( ppSops );
Alan Mishchenko committed
516 517
                return NULL;
            }
518 519 520 521 522 523 524 525 526 527 528 529
            if ( fZeros )
            {
                for ( i = 0; i < nOutputs; i++ )
                {
                    if ( pCubeOut[i] == '0' )
                    {
                        Vec_StrPrintStr( ppSops[i], pCubeIn );
                        Vec_StrPrintStr( ppSops[i], " 1\n" );
                    }
                }
            }
            else if ( fBoth )
530 531 532 533 534 535 536 537 538 539
            {
                for ( i = 0; i < nOutputs; i++ )
                {
                    if ( pCubeOut[i] == '0' || pCubeOut[i] == '1' )
                    {
                        Vec_StrPrintStr( ppSops[i], pCubeIn );
                        Vec_StrPrintStr( ppSops[i], " 1\n" );
                    }
                }
            }
540
            else if ( fOnDc )
Alan Mishchenko committed
541
            {
Alan Mishchenko committed
542 543
                for ( i = 0; i < nOutputs; i++ )
                {
544
                    if ( pCubeOut[i] == '-' || pCubeOut[i] == '1' )
Alan Mishchenko committed
545
                    {
546 547
                        Vec_StrPrintStr( ppSops[i], pCubeIn );
                        Vec_StrPrintStr( ppSops[i], " 1\n" );
Alan Mishchenko committed
548 549 550
                    }
                }
            }
551
            else 
Alan Mishchenko committed
552 553
            {
                for ( i = 0; i < nOutputs; i++ )
Alan Mishchenko committed
554
                {
Alan Mishchenko committed
555 556
                    if ( pCubeOut[i] == '1' )
                    {
557 558
                        Vec_StrPrintStr( ppSops[i], pCubeIn );
                        Vec_StrPrintStr( ppSops[i], " 1\n" );
Alan Mishchenko committed
559
                    }
Alan Mishchenko committed
560 561 562 563 564 565 566 567 568 569 570
                }
            }
            nCubes++;
        }
    }
    Extra_ProgressBarStop( pProgress );
    if ( nProducts != -1 && nCubes != nProducts )
        printf( "Warning: Mismatch between the number of cubes (%d) and the number on .p line (%d).\n", 
            nCubes, nProducts );

    // add the SOP covers
Alan Mishchenko committed
571
    Abc_NtkForEachPo( pNtk, pTermPo, i )
Alan Mishchenko committed
572
    {
Alan Mishchenko committed
573
        pNode = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pTermPo) );
Alan Mishchenko committed
574 575 576
        if ( ppSops[i]->nSize == 0 )
        {
            Abc_ObjRemoveFanins(pNode);
577
            pNode->pData = Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, " 0\n" );
Alan Mishchenko committed
578
            Vec_StrFree( ppSops[i] );
Alan Mishchenko committed
579 580 581
            continue;
        }
        Vec_StrPush( ppSops[i], 0 );
582 583
        if ( !fSkipPrepro )
            Io_ReadPlaCubePreprocess( ppSops[i], i, 0 );
584
        pNode->pData = Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, ppSops[i]->pArray );
Alan Mishchenko committed
585 586
        Vec_StrFree( ppSops[i] );
    }
Alan Mishchenko committed
587
    ABC_FREE( ppSops );
Alan Mishchenko committed
588
    Abc_NtkFinalizeRead( pNtk );
Alan Mishchenko committed
589 590 591 592 593 594 595 596 597 598
    return pNtk;
}


////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////



599 600
ABC_NAMESPACE_IMPL_END