wlcCom.c 67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**CFile****************************************************************

  FileName    [wlcCom.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Verilog parser.]

  Synopsis    [Command handlers.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - August 22, 2014.]

  Revision    [$Id: wlcCom.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]

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

#include "wlc.h"
22
#include "base/wln/wln.h"
23
#include "base/main/mainInt.h"
24
#include "aig/miniaig/ndr.h"
25 26 27 28 29 30 31 32

ABC_NAMESPACE_IMPL_START


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

33 34 35 36
static int  Abc_CommandReadWlc    ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandWriteWlc   ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandPs         ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandCone       ( Abc_Frame_t * pAbc, int argc, char ** argv );
37
static int  Abc_CommandAbs        ( Abc_Frame_t * pAbc, int argc, char ** argv );
Yen-Sheng Ho committed
38
static int  Abc_CommandPdrAbs     ( Abc_Frame_t * pAbc, int argc, char ** argv );
39
static int  Abc_CommandAbs2       ( Abc_Frame_t * pAbc, int argc, char ** argv );
Alan Mishchenko committed
40
static int  Abc_CommandMemAbs     ( Abc_Frame_t * pAbc, int argc, char ** argv );
41
static int  Abc_CommandMemAbs2    ( Abc_Frame_t * pAbc, int argc, char ** argv );
42
static int  Abc_CommandBlast      ( Abc_Frame_t * pAbc, int argc, char ** argv );
43
static int  Abc_CommandBlastMem   ( Abc_Frame_t * pAbc, int argc, char ** argv );
44
static int  Abc_CommandGraft      ( Abc_Frame_t * pAbc, int argc, char ** argv );
45
static int  Abc_CommandRetime     ( Abc_Frame_t * pAbc, int argc, char ** argv );
46 47 48 49 50 51 52 53 54
static int  Abc_CommandProfile    ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandShortNames ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandShow       ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandInvPs      ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandInvPrint   ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandInvCheck   ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandInvGet     ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandInvPut     ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int  Abc_CommandInvMin     ( Abc_Frame_t * pAbc, int argc, char ** argv );
Alan Mishchenko committed
55
static int  Abc_CommandTest       ( Abc_Frame_t * pAbc, int argc, char ** argv );
56

57 58 59 60
static inline Wlc_Ntk_t * Wlc_AbcGetNtk( Abc_Frame_t * pAbc )                       { return (Wlc_Ntk_t *)pAbc->pAbcWlc;                      }
static inline void        Wlc_AbcFreeNtk( Abc_Frame_t * pAbc )                      { if ( pAbc->pAbcWlc ) Wlc_NtkFree(Wlc_AbcGetNtk(pAbc));  }
static inline void        Wlc_AbcUpdateNtk( Abc_Frame_t * pAbc, Wlc_Ntk_t * pNtk )  { Wlc_AbcFreeNtk(pAbc); pAbc->pAbcWlc = pNtk;             }

Alan Mishchenko committed
61 62
static inline Vec_Int_t * Wlc_AbcGetInv( Abc_Frame_t * pAbc )                       { return pAbc->pAbcWlcInv;                                }

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
void Wlc_Init( Abc_Frame_t * pAbc )
{
80 81 82 83
    Cmd_CommandAdd( pAbc, "Word level", "%read",        Abc_CommandReadWlc,    0 );
    Cmd_CommandAdd( pAbc, "Word level", "%write",       Abc_CommandWriteWlc,   0 );
    Cmd_CommandAdd( pAbc, "Word level", "%ps",          Abc_CommandPs,         0 );
    Cmd_CommandAdd( pAbc, "Word level", "%cone",        Abc_CommandCone,       0 );
84
    Cmd_CommandAdd( pAbc, "Word level", "%abs",         Abc_CommandAbs,        0 );
Yen-Sheng Ho committed
85
    Cmd_CommandAdd( pAbc, "Word level", "%pdra",        Abc_CommandPdrAbs,     0 );
86
    Cmd_CommandAdd( pAbc, "Word level", "%abs2",        Abc_CommandAbs2,       0 );
Alan Mishchenko committed
87
    Cmd_CommandAdd( pAbc, "Word level", "%memabs",      Abc_CommandMemAbs,     0 );
88
    Cmd_CommandAdd( pAbc, "Word level", "%memabs2",     Abc_CommandMemAbs2,    0 );
89
    Cmd_CommandAdd( pAbc, "Word level", "%blast",       Abc_CommandBlast,      0 );
90
    Cmd_CommandAdd( pAbc, "Word level", "%blastmem",    Abc_CommandBlastMem,   0 );
91
    Cmd_CommandAdd( pAbc, "Word level", "%graft",       Abc_CommandGraft,      0 );
92
    Cmd_CommandAdd( pAbc, "Word level", "%retime",      Abc_CommandRetime,     0 );
93 94 95 96 97 98 99 100 101 102 103
    Cmd_CommandAdd( pAbc, "Word level", "%profile",     Abc_CommandProfile,    0 );
    Cmd_CommandAdd( pAbc, "Word level", "%short_names", Abc_CommandShortNames, 0 );
    Cmd_CommandAdd( pAbc, "Word level", "%show",        Abc_CommandShow,       0 );
    Cmd_CommandAdd( pAbc, "Word level", "%test",        Abc_CommandTest,       0 );

    Cmd_CommandAdd( pAbc, "Word level", "inv_ps",       Abc_CommandInvPs,      0 );
    Cmd_CommandAdd( pAbc, "Word level", "inv_print",    Abc_CommandInvPrint,   0 );
    Cmd_CommandAdd( pAbc, "Word level", "inv_check",    Abc_CommandInvCheck,   0 );
    Cmd_CommandAdd( pAbc, "Word level", "inv_get",      Abc_CommandInvGet,     0 );
    Cmd_CommandAdd( pAbc, "Word level", "inv_put",      Abc_CommandInvPut,     0 );
    Cmd_CommandAdd( pAbc, "Word level", "inv_min",      Abc_CommandInvMin,     0 );
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
void Wlc_End( Abc_Frame_t * pAbc )
{
    Wlc_AbcFreeNtk( pAbc );
}

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
/**Function********************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
void Wlc_SetNtk( Abc_Frame_t * pAbc, Wlc_Ntk_t * pNtk )
{
    Wlc_AbcUpdateNtk( pAbc, pNtk );
}


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

141 142 143 144 145 146 147 148 149
  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
150
int Abc_CommandReadWlc( Abc_Frame_t * pAbc, int argc, char ** argv )
151 152 153 154
{
    FILE * pFile;
    Wlc_Ntk_t * pNtk = NULL;
    char * pFileName = NULL;
155 156
    int fOldParser   =    0;
    int fPrintTree   =    0;
157 158
    int c, fVerbose  =    0;
    Extra_UtilGetoptReset();
159
    while ( ( c = Extra_UtilGetopt( argc, argv, "opvh" ) ) != EOF )
160 161 162
    {
        switch ( c )
        {
163
        case 'o':
164
            fOldParser ^= 1;
165 166
            break;
        case 'p':
167
            fPrintTree ^= 1;
168
            break;
169 170 171 172 173 174 175 176 177 178 179
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
    {
180
        printf( "Abc_CommandReadWlc(): Input file name should be given on the command line.\n" );
181 182 183 184 185 186 187
        return 0;
    }
    // get the file name
    pFileName = argv[globalUtilOptind];
    if ( (pFile = fopen( pFileName, "r" )) == NULL )
    {
        Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName );
188
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".smt", ".smt2", ".ndr", NULL )) )
189 190 191 192 193 194 195
            Abc_Print( 1, "Did you mean \"%s\"?", pFileName );
        Abc_Print( 1, "\n" );
        return 0;
    }
    fclose( pFile );

    // perform reading
196
    if ( !strcmp( Extra_FileNameExtension(pFileName), "v" )  )
197
        pNtk = Wlc_ReadVer( pFileName, NULL );
198
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "smt" ) || !strcmp( Extra_FileNameExtension(pFileName), "smt2" )  )
199
        pNtk = Wlc_ReadSmt( pFileName, fOldParser, fPrintTree );
200 201
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "ndr" )  )
        pNtk = Wlc_ReadNdr( pFileName );
202 203 204 205 206
    else
    {
        printf( "Abc_CommandReadWlc(): Unknown file extension.\n" );
        return 0;
    }
207 208 209
    Wlc_AbcUpdateNtk( pAbc, pNtk );
    return 0;
usage:
210
    Abc_Print( -2, "usage: %%read [-opvh] <file_name>\n" );
211
    Abc_Print( -2, "\t         reads word-level design from Verilog file\n" );
212 213
    Abc_Print( -2, "\t-o     : toggle using old SMT-LIB parser [default = %s]\n", fOldParser? "yes": "no" );
    Abc_Print( -2, "\t-p     : toggle printing parse SMT-LIB tree [default = %s]\n", fPrintTree? "yes": "no" );
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
230
int Abc_CommandWriteWlc( Abc_Frame_t * pAbc, int argc, char ** argv )
231 232 233
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    char * pFileName = NULL;
234 235
    int fAddCos      =    0; 
    int fSplitNodes  =    0; 
236
    int fNoFlops     =    0;
237 238
    int c, fVerbose  =    0;
    Extra_UtilGetoptReset();
239
    while ( ( c = Extra_UtilGetopt( argc, argv, "anfvh" ) ) != EOF )
240 241 242
    {
        switch ( c )
        {
243 244 245 246 247 248
        case 'a':
            fAddCos ^= 1;
            break;
        case 'n':
            fSplitNodes ^= 1;
            break;
249 250 251
        case 'f':
            fNoFlops ^= 1;
            break;
252 253 254 255 256 257 258 259 260 261 262
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
263
        Abc_Print( 1, "Abc_CommandWriteWlc(): There is no current design.\n" );
264 265 266 267 268 269 270 271 272 273 274
        return 0;
    }
    if ( argc == globalUtilOptind )
        pFileName = Extra_FileNameGenericAppend( pNtk->pName, "_out.v" );
    else if ( argc == globalUtilOptind + 1 )
        pFileName = argv[globalUtilOptind];
    else
    {
        printf( "Output file name should be given on the command line.\n" );
        return 0;
    }
275 276 277
    if ( !strcmp( Extra_FileNameExtension(pFileName), "ndr" )  )
        Wlc_WriteNdr( pNtk, pFileName );
    else if ( fSplitNodes )
278 279
    {
        pNtk = Wlc_NtkDupSingleNodes( pNtk );
280
        Wlc_WriteVer( pNtk, pFileName, fAddCos, fNoFlops );
281 282 283
        Wlc_NtkFree( pNtk );
    }
    else
284
        Wlc_WriteVer( pNtk, pFileName, fAddCos, fNoFlops );
285

286 287
    return 0;
usage:
288
    Abc_Print( -2, "usage: %%write [-anfvh]\n" );
289
    Abc_Print( -2, "\t         writes the design into a file\n" );
290 291
    Abc_Print( -2, "\t-a     : toggle adding a CO for each node [default = %s]\n",       fAddCos? "yes": "no" );
    Abc_Print( -2, "\t-n     : toggle splitting into individual nodes [default = %s]\n", fSplitNodes? "yes": "no" );
292
    Abc_Print( -2, "\t-f     : toggle skipping flops when writing file [default = %s]\n",fNoFlops? "yes": "no" );
293
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",    fVerbose? "yes": "no" );
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}


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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
int Abc_CommandPs( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
313
    int fShowCones   = 0;
314 315
    int fShowMulti   = 0;
    int fShowAdder   = 0;
Alan Mishchenko committed
316
    int fShowMem     = 0;
317
    int fDistrib     = 0;
318
    int fTwoSides    = 0;
Alan Mishchenko committed
319
    int fAllObjects  = 0;
320 321
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
322
    while ( ( c = Extra_UtilGetopt( argc, argv, "cbamdtovh" ) ) != EOF )
323 324 325
    {
        switch ( c )
        {
326 327 328
        case 'c':
            fShowCones ^= 1;
            break;
329
        case 'b':
330 331 332 333 334
            fShowMulti ^= 1;
            break;
        case 'a':
            fShowAdder ^= 1;
            break;
335
        case 'm':
Alan Mishchenko committed
336 337
            fShowMem ^= 1;
            break;
338 339 340
        case 'd':
            fDistrib ^= 1;
            break;
341 342 343
        case 't':
            fTwoSides ^= 1;
            break;
Alan Mishchenko committed
344 345 346
        case 'o':
            fAllObjects ^= 1;
            break;
347 348 349 350 351 352 353 354 355 356 357 358 359 360
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandPs(): There is no current design.\n" );
        return 0;
    }
361 362 363
    Wlc_NtkPrintStats( pNtk, fDistrib, fTwoSides, fVerbose );
    if ( fShowCones )
        Wlc_NtkProfileCones( pNtk ); 
364 365 366 367
    if ( fShowMulti )
        Wlc_NtkPrintNodes( pNtk, WLC_OBJ_ARI_MULTI );
    if ( fShowAdder )
        Wlc_NtkPrintNodes( pNtk, WLC_OBJ_ARI_ADD );
Alan Mishchenko committed
368 369
    if ( fShowMem )
        Wlc_NtkPrintMemory( pNtk );
Alan Mishchenko committed
370 371
    if ( fAllObjects )
        Wlc_NtkPrintObjects( pNtk );
372 373
    return 0;
usage:
374
    Abc_Print( -2, "usage: %%ps [-cbamdtovh]\n" );
375
    Abc_Print( -2, "\t         prints statistics\n" );
376
    Abc_Print( -2, "\t-c     : toggle printing cones [default = %s]\n",                 fShowCones? "yes": "no" );
377
    Abc_Print( -2, "\t-b     : toggle printing multipliers [default = %s]\n",           fShowMulti? "yes": "no" );
378
    Abc_Print( -2, "\t-a     : toggle printing adders [default = %s]\n",                fShowAdder? "yes": "no" );
379
    Abc_Print( -2, "\t-m     : toggle printing memories [default = %s]\n",              fShowMem?   "yes": "no" );
Alan Mishchenko committed
380 381
    Abc_Print( -2, "\t-d     : toggle printing distrubition [default = %s]\n",          fDistrib?   "yes": "no" );
    Abc_Print( -2, "\t-t     : toggle printing stats for LHS and RHS [default = %s]\n", fTwoSides?  "yes": "no" );
Alan Mishchenko committed
382
    Abc_Print( -2, "\t-o     : toggle printing all objects [default = %s]\n",           fAllObjects?"yes": "no" );
Alan Mishchenko committed
383
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",   fVerbose?   "yes": "no" );
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
399 400 401
int Abc_CommandCone( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
402
    int c, iOutput = -1, Range = 1, fAllPis = 0, fSeq = 0, fVerbose  = 0;
403
    char * pName;
404
    Extra_UtilGetoptReset();
405
    while ( ( c = Extra_UtilGetopt( argc, argv, "ORisvh" ) ) != EOF )
406 407 408 409 410 411 412 413 414 415 416 417 418 419
    {
        switch ( c )
        {
        case 'O':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
                goto usage;
            }
            iOutput = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( iOutput < 0 )
                goto usage;
            break;
420 421 422 423 424 425 426 427 428 429 430 431 432 433
        case 'R':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
                goto usage;
            }
            Range = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( Range < 0 )
                goto usage;
            break;
        case 'i':
            fAllPis ^= 1;
            break;
434 435 436
        case 's':
            fSeq ^= 1;
            break;
437 438 439 440 441 442 443 444 445 446 447 448 449 450
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandCone(): There is no current design.\n" );
        return 0;
    }
451
    if ( iOutput < 0 || iOutput >= Wlc_NtkCoNum(pNtk) )
452
    {
453
        Abc_Print( 1, "Abc_CommandCone(): Illegal output index (%d) (should be 0 <= num < %d).\n", iOutput, Wlc_NtkCoNum(pNtk) );
454 455
        return 0;
    }
456 457
    printf( "Extracting output %d as a %s word-level network.\n", iOutput, fSeq ? "sequential" : "combinational" );
    pName = Wlc_NtkNewName( pNtk, iOutput, fSeq );
458
    Wlc_NtkMarkCone( pNtk, iOutput, Range, fSeq, fAllPis );
459
    pNtk = Wlc_NtkDupDfs( pNtk, 1, fSeq );
460 461
    ABC_FREE( pNtk->pName );
    pNtk->pName = Abc_UtilStrsav( pName );
462 463 464
    Wlc_AbcUpdateNtk( pAbc, pNtk );
    return 0;
usage:
465 466 467 468 469
    Abc_Print( -2, "usage: %%cone [-OR num] [-isvh]\n" );
    Abc_Print( -2, "\t         extracts logic cone of one or more word-level outputs\n" );
    Abc_Print( -2, "\t-O num : zero-based index of the first word-level output to extract [default = %d]\n", iOutput );
    Abc_Print( -2, "\t-R num : total number of word-level outputs to extract [default = %d]\n", Range );
    Abc_Print( -2, "\t-i     : toggle using support composed of all primary inputs [default = %s]\n", fAllPis? "yes": "no" );
470
    Abc_Print( -2, "\t-s     : toggle performing extracting sequential cones [default = %s]\n", fSeq? "yes": "no" );
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
Yen-Sheng Ho committed
487 488 489
int Abc_CommandPdrAbs( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
Yen-Sheng Ho committed
490
    Wlc_Par_t Pars, * pPars = &Pars;
Yen-Sheng Ho committed
491
    int c;
Yen-Sheng Ho committed
492
    Wlc_ManSetDefaultParams( pPars );
Yen-Sheng Ho committed
493
    Extra_UtilGetoptReset();
494
    while ( ( c = Extra_UtilGetopt( argc, argv, "AMXFILabrcdilpqmstuxvwh" ) ) != EOF )
Yen-Sheng Ho committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    {
        switch ( c )
        {
        case 'A':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsAdd = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsAdd < 0 )
                goto usage;
            break;
        case 'M':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsMul = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsMul < 0 )
                goto usage;
            break;
        case 'X':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-X\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsMux = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsMux < 0 )
                goto usage;
            break;
        case 'F':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsFlop = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsFlop < 0 )
                goto usage;
            break;
        case 'I':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nIterMax = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nIterMax < 0 )
                goto usage;
            break;
553 554 555 556 557 558
        case 'L':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
                goto usage;
            }
559
            pPars->nLimit = atoi(argv[globalUtilOptind]);
560
            globalUtilOptind++;
561
            if ( pPars->nLimit < 0 )
562 563
                goto usage;
            break;
564 565 566
        case 'a':
            pPars->fPdra ^= 1;
            break;
567 568 569
        case 'b':
            pPars->fProofRefine ^= 1;
            break;
570 571 572
        case 'r':
            pPars->fHybrid ^= 1;
            break;
Yen-Sheng Ho committed
573 574 575
        case 'x':
            pPars->fXorOutput ^= 1;
            break;
576 577 578
        case 'c':
            pPars->fCheckClauses ^= 1;
            break;
579 580 581
        case 'd':
            pPars->fAbs2 ^= 1;
            break;
582 583 584
        case 'i':
            pPars->fProofUsePPI ^= 1;
            break;
585 586 587
        case 'l':
            pPars->fLoadTrace ^= 1;
            break;
588 589 590
        case 'p':
            pPars->fPushClauses ^= 1;
            break;
Yen-Sheng Ho committed
591 592 593
        case 'q':
            pPars->fUseBmc3 ^= 1;
            break;
594 595 596
        case 'm':
            pPars->fMFFC ^= 1;
            break;
597 598 599
        case 's':
            pPars->fShrinkAbs ^= 1;
            break;
600 601 602
        case 't':
            pPars->fShrinkScratch ^= 1;
            break;
603 604 605
        case 'u':
            pPars->fCheckCombUnsat ^= 1;
            break;
Yen-Sheng Ho committed
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
        case 'v':
            pPars->fVerbose ^= 1;
            break;
        case 'w':
            pPars->fPdrVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandCone(): There is no current design.\n" );
        return 0;
    }
Yen-Sheng Ho committed
623
    Wlc_NtkPdrAbs( pNtk, pPars );
Yen-Sheng Ho committed
624 625
    return 0;
usage:
626
    Abc_Print( -2, "usage: %%pdra [-AMXFIL num] [-abrcdilpqmxstuvwh]\n" );
Yen-Sheng Ho committed
627 628 629 630 631 632
    Abc_Print( -2, "\t         abstraction for word-level networks\n" );
    Abc_Print( -2, "\t-A num : minimum bit-width of an adder/subtractor to abstract [default = %d]\n", pPars->nBitsAdd );
    Abc_Print( -2, "\t-M num : minimum bit-width of a multiplier to abstract [default = %d]\n",        pPars->nBitsMul );
    Abc_Print( -2, "\t-X num : minimum bit-width of a MUX operator to abstract [default = %d]\n",      pPars->nBitsMux );
    Abc_Print( -2, "\t-F num : minimum bit-width of a flip-flop to abstract [default = %d]\n",         pPars->nBitsFlop );
    Abc_Print( -2, "\t-I num : maximum number of CEGAR iterations [default = %d]\n",                   pPars->nIterMax );
633
    Abc_Print( -2, "\t-L num : maximum number of each type of signals [default = %d]\n",               pPars->nLimit );
Yen-Sheng Ho committed
634
    Abc_Print( -2, "\t-x     : toggle XORing outputs of word-level miter [default = %s]\n",            pPars->fXorOutput? "yes": "no" );
635 636
    Abc_Print( -2, "\t-a     : toggle running pdr with -nct [default = %s]\n",                         pPars->fPdra? "yes": "no" );
    Abc_Print( -2, "\t-b     : toggle using proof-based refinement [default = %s]\n",                  pPars->fProofRefine? "yes": "no" );
637
    Abc_Print( -2, "\t-r     : toggle using both cex-based and proof-based refinement [default = %s]\n",                  pPars->fHybrid? "yes": "no" );
638
    Abc_Print( -2, "\t-c     : toggle checking clauses in the reloaded trace [default = %s]\n",        pPars->fCheckClauses? "yes": "no" );
639
    Abc_Print( -2, "\t-d     : toggle using another way of creating abstractions [default = %s]\n",    pPars->fAbs2? "yes": "no" );
640
    Abc_Print( -2, "\t-i     : toggle using PPI values in proof-based refinement [default = %s]\n",    pPars->fProofUsePPI? "yes": "no" );
641
    Abc_Print( -2, "\t-l     : toggle loading previous PDR traces [default = %s]\n",                   pPars->fLoadTrace? "yes": "no" );
642
    Abc_Print( -2, "\t-s     : toggle shrinking abstractions with BMC [default = %s]\n",               pPars->fShrinkAbs? "yes": "no" );
643
    Abc_Print( -2, "\t-t     : toggle restarting pdr from scratch after shrinking abstractions with BMC [default = %s]\n",               pPars->fShrinkScratch? "yes": "no" );
644
    Abc_Print( -2, "\t-u     : toggle checking combinationally unsat [default = %s]\n",                pPars->fCheckCombUnsat? "yes": "no" );
645
    Abc_Print( -2, "\t-p     : toggle pushing clauses in the reloaded trace [default = %s]\n",         pPars->fPushClauses? "yes": "no" );
Yen-Sheng Ho committed
646
    Abc_Print( -2, "\t-q     : toggle running bmc3 in parallel for CEX [default = %s]\n",              pPars->fUseBmc3? "yes": "no" );
647
    Abc_Print( -2, "\t-m     : toggle refining the whole MFFC of a PPI [default = %s]\n",              pPars->fMFFC? "yes": "no" );
Yen-Sheng Ho committed
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",                  pPars->fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-w     : toggle printing verbose PDR output [default = %s]\n",                   pPars->fPdrVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}


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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
666 667 668 669 670 671 672
int Abc_CommandAbs( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    Wlc_Par_t Pars, * pPars = &Pars;
    int c;
    Wlc_ManSetDefaultParams( pPars );
    Extra_UtilGetoptReset();
673
    while ( ( c = Extra_UtilGetopt( argc, argv, "AMXFILdxvwh" ) ) != EOF )
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
    {
        switch ( c )
        {
        case 'A':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsAdd = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsAdd < 0 )
                goto usage;
            break;
        case 'M':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsMul = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsMul < 0 )
                goto usage;
            break;
        case 'X':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-X\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsMux = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsMux < 0 )
                goto usage;
            break;
        case 'F':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsFlop = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsFlop < 0 )
                goto usage;
            break;
721 722 723 724 725 726 727 728 729 730 731
        case 'I':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nIterMax = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nIterMax < 0 )
                goto usage;
            break;
Yen-Sheng Ho committed
732 733 734 735 736 737 738 739 740 741 742
        case 'L':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nLimit = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nLimit < 0 )
                goto usage;
            break;
743 744 745
        case 'd':
            pPars->fAbs2 ^= 1;
            break;
746 747 748
        case 'x':
            pPars->fXorOutput ^= 1;
            break;
749 750 751
        case 'v':
            pPars->fVerbose ^= 1;
            break;
752 753 754
        case 'w':
            pPars->fPdrVerbose ^= 1;
            break;
755 756 757 758 759 760 761 762 763 764 765
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandCone(): There is no current design.\n" );
        return 0;
    }
766 767 768
    Wlc_NtkAbsCore( pNtk, pPars );
    return 0;
usage:
769
    Abc_Print( -2, "usage: %%abs [-AMXFIL num] [-dxvwh]\n" );
770 771 772 773 774 775
    Abc_Print( -2, "\t         abstraction for word-level networks\n" );
    Abc_Print( -2, "\t-A num : minimum bit-width of an adder/subtractor to abstract [default = %d]\n", pPars->nBitsAdd );
    Abc_Print( -2, "\t-M num : minimum bit-width of a multiplier to abstract [default = %d]\n",        pPars->nBitsMul );
    Abc_Print( -2, "\t-X num : minimum bit-width of a MUX operator to abstract [default = %d]\n",      pPars->nBitsMux );
    Abc_Print( -2, "\t-F num : minimum bit-width of a flip-flop to abstract [default = %d]\n",         pPars->nBitsFlop );
    Abc_Print( -2, "\t-I num : maximum number of CEGAR iterations [default = %d]\n",                   pPars->nIterMax );
Yen-Sheng Ho committed
776
    Abc_Print( -2, "\t-L num : maximum number of each type of signals [default = %d]\n",               pPars->nLimit );
777
    Abc_Print( -2, "\t-d     : toggle using another way of creating abstractions [default = %s]\n",    pPars->fAbs2? "yes": "no" );
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 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
    Abc_Print( -2, "\t-x     : toggle XORing outputs of word-level miter [default = %s]\n",            pPars->fXorOutput? "yes": "no" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",                  pPars->fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-w     : toggle printing verbose PDR output [default = %s]\n",                   pPars->fPdrVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
int Abc_CommandAbs2( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    Wlc_Par_t Pars, * pPars = &Pars;
    int c;
    Wlc_ManSetDefaultParams( pPars );
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "AMXFIxvwh" ) ) != EOF )
    {
        switch ( c )
        {
        case 'A':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsAdd = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsAdd < 0 )
                goto usage;
            break;
        case 'M':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsMul = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsMul < 0 )
                goto usage;
            break;
        case 'X':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-X\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsMux = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsMux < 0 )
                goto usage;
            break;
        case 'F':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nBitsFlop = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nBitsFlop < 0 )
                goto usage;
            break;
        case 'I':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
                goto usage;
            }
            pPars->nIterMax = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPars->nIterMax < 0 )
                goto usage;
            break;
        case 'x':
            pPars->fXorOutput ^= 1;
            break;
        case 'v':
            pPars->fVerbose ^= 1;
            break;
        case 'w':
            pPars->fPdrVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandCone(): There is no current design.\n" );
        return 0;
    }
    Wlc_NtkAbsCore2( pNtk, pPars );
883 884
    return 0;
usage:
885
    Abc_Print( -2, "usage: %%abs2 [-AMXFI num] [-xvwh]\n" );
886 887 888 889 890
    Abc_Print( -2, "\t         abstraction for word-level networks\n" );
    Abc_Print( -2, "\t-A num : minimum bit-width of an adder/subtractor to abstract [default = %d]\n", pPars->nBitsAdd );
    Abc_Print( -2, "\t-M num : minimum bit-width of a multiplier to abstract [default = %d]\n",        pPars->nBitsMul );
    Abc_Print( -2, "\t-X num : minimum bit-width of a MUX operator to abstract [default = %d]\n",      pPars->nBitsMux );
    Abc_Print( -2, "\t-F num : minimum bit-width of a flip-flop to abstract [default = %d]\n",         pPars->nBitsFlop );
891 892
    Abc_Print( -2, "\t-I num : maximum number of CEGAR iterations [default = %d]\n",                   pPars->nIterMax );
    Abc_Print( -2, "\t-x     : toggle XORing outputs of word-level miter [default = %s]\n",            pPars->fXorOutput? "yes": "no" );
893
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",                  pPars->fVerbose? "yes": "no" );
894
    Abc_Print( -2, "\t-w     : toggle printing verbose PDR output [default = %s]\n",                   pPars->fPdrVerbose? "yes": "no" );
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
Alan Mishchenko committed
910 911 912
int Abc_CommandMemAbs( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
Alan Mishchenko committed
913
    int c, nIterMax = 1000, fDumpAbs = 0, fPdrVerbose = 0, fVerbose = 0;
Alan Mishchenko committed
914
    Extra_UtilGetoptReset();
Alan Mishchenko committed
915
    while ( ( c = Extra_UtilGetopt( argc, argv, "Idwvh" ) ) != EOF )
Alan Mishchenko committed
916 917 918 919 920 921 922 923 924 925 926 927 928 929
    {
        switch ( c )
        {
        case 'I':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
                goto usage;
            }
            nIterMax = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( nIterMax <= 0 )
                goto usage;
            break;
Alan Mishchenko committed
930 931 932
        case 'd':
            fDumpAbs ^= 1;
            break;
Alan Mishchenko committed
933 934 935 936 937 938 939 940 941 942 943 944 945 946
        case 'w':
            fPdrVerbose ^= 1;
            break;
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
947
        Abc_Print( 1, "Abc_CommandMemAbs(): There is no current design.\n" );
Alan Mishchenko committed
948 949
        return 0;
    }
Alan Mishchenko committed
950
    Wlc_NtkMemAbstract( pNtk, nIterMax, fDumpAbs, fPdrVerbose, fVerbose );
Alan Mishchenko committed
951 952
    return 0;
usage:
Alan Mishchenko committed
953
    Abc_Print( -2, "usage: %%memabs [-I num] [-dwvh]\n" );
Alan Mishchenko committed
954 955
    Abc_Print( -2, "\t         memory abstraction for word-level networks\n" );
    Abc_Print( -2, "\t-I num : maximum number of CEGAR iterations [default = %d]\n",  nIterMax );
Alan Mishchenko committed
956
    Abc_Print( -2, "\t-d     : toggle dumping abstraction as an AIG [default = %s]\n",fDumpAbs? "yes": "no" );
Alan Mishchenko committed
957
    Abc_Print( -2, "\t-w     : toggle printing verbose PDR output [default = %s]\n",  fPdrVerbose? "yes": "no" );
Alan Mishchenko committed
958
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Alan Mishchenko committed
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
int Abc_CommandMemAbs2( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    int c, nFrames = 0, fVerbose = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "Fvh" ) ) != EOF )
    {
        switch ( c )
        {
        case 'F':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
                goto usage;
            }
            nFrames = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( nFrames <= 0 )
                goto usage;
            break;
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandMemAbs2(): There is no current design.\n" );
        return 0;
    }
    pNtk = Wlc_NtkAbstractMem( pNtk, nFrames, fVerbose );
    Wlc_AbcUpdateNtk( pAbc, pNtk );
    return 0;
usage:
    Abc_Print( -2, "usage: %%memabs2 [-F num] [-vh]\n" );
    Abc_Print( -2, "\t         memory abstraction for word-level networks\n" );
    Abc_Print( -2, "\t-F num : the number of timeframes [default = %d]\n",  nFrames );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1031 1032
int Abc_CommandBlast( Abc_Frame_t * pAbc, int argc, char ** argv )
{
1033
    extern void Wlc_NtkPrintInputInfo( Wlc_Ntk_t * pNtk );
1034
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
1035
    Gia_Man_t * pNew = NULL; int c, fMiter = 0, fDumpNames = 0, fPrintInputInfo = 0;
1036 1037 1038
    Wlc_BstPar_t Par, * pPar = &Par;
    Wlc_BstParDefault( pPar );
    pPar->nOutputRange = 2;
1039
    Extra_UtilGetoptReset();
1040
    while ( ( c = Extra_UtilGetopt( argc, argv, "ORAMcombqadestnizvh" ) ) != EOF )
1041 1042 1043
    {
        switch ( c )
        {
1044 1045 1046 1047 1048 1049
        case 'O':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
                goto usage;
            }
1050
            pPar->iOutput = atoi(argv[globalUtilOptind]);
1051
            globalUtilOptind++;
1052
            if ( pPar->iOutput < 0 )
1053 1054 1055 1056 1057 1058 1059 1060
                goto usage;
            break;
        case 'R':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
                goto usage;
            }
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
            pPar->nOutputRange = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPar->nOutputRange < 0 )
                goto usage;
            break;
        case 'A':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
                goto usage;
            }
            pPar->nAdderLimit = atoi(argv[globalUtilOptind]);
            globalUtilOptind++;
            if ( pPar->nAdderLimit < 0 )
                goto usage;
            break;
        case 'M':
            if ( globalUtilOptind >= argc )
            {
                Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
                goto usage;
            }
            pPar->nMultLimit = atoi(argv[globalUtilOptind]);
1084
            globalUtilOptind++;
1085
            if ( pPar->nMultLimit < 0 )
1086 1087
                goto usage;
            break;
1088
        case 'c':
1089
            pPar->fGiaSimple ^= 1;
1090
            break;
1091
        case 'o':
1092
            pPar->fAddOutputs ^= 1;
1093
            break;
1094
        case 'm':
1095
            pPar->fMulti ^= 1;
1096
            break;
1097
        case 'b':
1098
            pPar->fBooth ^= 1;
1099
            break;
1100 1101 1102
        case 'q':
            pPar->fNonRest ^= 1;
            break;
1103 1104 1105
        case 'a':
            pPar->fCla ^= 1;
            break;
1106
        case 'd':
1107
            pPar->fCreateMiter ^= 1;
1108
            break;
1109 1110 1111
        case 'e':
            pPar->fCreateWordMiter ^= 1;
            break;
1112
        case 's':
1113
            pPar->fDecMuxes ^= 1;
1114
            break;
1115 1116 1117 1118 1119 1120 1121
        case 't':
            pPar->fCreateMiter ^= 1;
            fMiter ^= 1;
            break;
        case 'n':
            fDumpNames ^= 1;
            break;
1122 1123 1124
        case 'i': 
            fPrintInputInfo ^= 1; 
            break;
1125 1126 1127
        case 'z': 
            pPar->fSaveFfNames ^= 1; 
            break;
1128
        case 'v':
1129
            pPar->fVerbose ^= 1;
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandBlast(): There is no current design.\n" );
        return 0;
    }
1142 1143 1144 1145 1146
    if ( pNtk->fAsyncRst )
    {
        Abc_Print( 1, "Abc_CommandBlast(): Trying to bit-blast network with asynchronous reset.\n" );
        return 0;
    }
1147 1148
    if ( fPrintInputInfo )
        Wlc_NtkPrintInputInfo(pNtk); 
1149
    if ( pPar->fMulti )
1150
    {
1151 1152
        pPar->vBoxIds = Wlc_NtkCollectMultipliers( pNtk );
        if ( pPar->vBoxIds == NULL )
1153 1154
            Abc_Print( 1, "Warning:  There is no multipliers in the design.\n" );
    }
1155
    else if ( pPar->nAdderLimit || pPar->nMultLimit )
1156
    {
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
        int CountA, CountM;
        pPar->vBoxIds = Wlc_NtkCollectAddMult( pNtk, pPar, &CountA, &CountM );
        if ( pPar->vBoxIds == NULL )
            Abc_Print( 1, "Warning:  There is no adders and multipliers that will not be blasted.\n" );
        else 
            Abc_Print( 1, "Warning:  %d adders and %d multipliers will not be blasted.\n", CountA, CountM );
    }
    if ( pPar->iOutput >= 0 && pPar->iOutput + pPar->nOutputRange > Wlc_NtkPoNum(pNtk) )
    {
        Abc_Print( 1, "Abc_CommandBlast(): The output range [%d:%d] is incorrect.\n", pPar->iOutput, pPar->iOutput + pPar->nOutputRange - 1 );
1167 1168
        return 0;
    }
1169
    // transform
1170 1171
    pNew = Wlc_NtkBitBlast( pNtk, pPar );
    Vec_IntFreeP( &pPar->vBoxIds );
1172 1173 1174 1175 1176
    if ( pNew == NULL )
    {
        Abc_Print( 1, "Abc_CommandBlast(): Bit-blasting has failed.\n" );
        return 0;
    }
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
    // generate miter
    if ( fMiter )
    {
        Gia_Man_t * pTemp = pNew;
        pNew = Gia_ManTransformMiter( pNew );
        Gia_ManStop( pTemp );
        Abc_Print( 1, "Bit-blasting created a traditional multi-output miter by XORing POs pair-wise.\n" );
        if ( fDumpNames )
        {
            int i; char * pName;
            FILE * pFile = fopen( "pio_name_map.txt", "wb" );
            if ( pNew->vNamesIn )
                Vec_PtrForEachEntry( char *, pNew->vNamesIn, pName, i )
                    fprintf( pFile, "i%d %s\n", i, pName );
            if ( pNew->vNamesOut )
                Vec_PtrForEachEntry( char *, pNew->vNamesOut, pName, i )
                    fprintf( pFile, "o%d %s\n", i, pName );
            fclose( pFile );
            Abc_Print( 1, "Finished dumping file \"pio_name_map.txt\" containing PI/PO name mapping.\n" );
        }
    }
1198 1199 1200
    Abc_FrameUpdateGia( pAbc, pNew );
    return 0;
usage:
1201
    Abc_Print( -2, "usage: %%blast [-ORAM num] [-combqadestnizvh]\n" );
1202
    Abc_Print( -2, "\t         performs bit-blasting of the word-level design\n" );
1203 1204 1205 1206 1207 1208 1209 1210
    Abc_Print( -2, "\t-O num : zero-based index of the first word-level PO to bit-blast [default = %d]\n", pPar->iOutput );
    Abc_Print( -2, "\t-R num : the total number of word-level POs to bit-blast [default = %d]\n",          pPar->nOutputRange );
    Abc_Print( -2, "\t-A num : blast adders smaller than this (0 = unused) [default = %d]\n",              pPar->nAdderLimit );
    Abc_Print( -2, "\t-M num : blast multipliers smaller than this (0 = unused) [default = %d]\n",         pPar->nMultLimit );
    Abc_Print( -2, "\t-c     : toggle using AIG w/o const propagation and strashing [default = %s]\n",     pPar->fGiaSimple? "yes": "no" );
    Abc_Print( -2, "\t-o     : toggle using additional POs on the word-level boundaries [default = %s]\n", pPar->fAddOutputs? "yes": "no" );
    Abc_Print( -2, "\t-m     : toggle creating boxes for all multipliers in the design [default = %s]\n",  pPar->fMulti? "yes": "no" );
    Abc_Print( -2, "\t-b     : toggle generating radix-4 Booth multipliers [default = %s]\n",              pPar->fBooth? "yes": "no" );
1211
    Abc_Print( -2, "\t-q     : toggle generating non-restoring square root [default = %s]\n",              pPar->fNonRest? "yes": "no" );
1212
    Abc_Print( -2, "\t-a     : toggle generating carry-look-ahead adder [default = %s]\n",                 pPar->fCla? "yes": "no" );
1213
    Abc_Print( -2, "\t-d     : toggle creating dual-output multi-output miter [default = %s]\n",           pPar->fCreateMiter? "yes": "no" );
1214
    Abc_Print( -2, "\t-e     : toggle creating miter with output word bits combined [default = %s]\n",     pPar->fCreateWordMiter? "yes": "no" );
1215
    Abc_Print( -2, "\t-s     : toggle creating decoded MUXes [default = %s]\n",                            pPar->fDecMuxes? "yes": "no" );
1216 1217
    Abc_Print( -2, "\t-t     : toggle creating regular multi-output miter [default = %s]\n",               fMiter? "yes": "no" );
    Abc_Print( -2, "\t-n     : toggle dumping signal names into a text file [default = %s]\n",             fDumpNames? "yes": "no" );
1218
    Abc_Print( -2, "\t-i     : toggle to print input names after blasting [default = %s]\n",               fPrintInputInfo ? "yes": "no" );
1219
    Abc_Print( -2, "\t-z     : toggle saving flop names after blasting [default = %s]\n",                  pPar->fSaveFfNames ? "yes": "no" );
1220
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",                      pPar->fVerbose? "yes": "no" );
1221 1222 1223 1224
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
/**Function********************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
int Abc_CommandBlastMem( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern Wlc_Ntk_t * Wlc_NtkMemBlast( Wlc_Ntk_t * p );
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
1257
        Abc_Print( 1, "Abc_CommandBlastMem(): There is no current design.\n" );
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
        return 0;
    }
    pNtk = Wlc_NtkMemBlast( pNtk );
    Wlc_AbcUpdateNtk( pAbc, pNtk );
    return 0;
usage:
    Abc_Print( -2, "usage: %%blastmem [-vh]\n" );
    Abc_Print( -2, "\t         performs blasting of memory read/write ports\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
int Abc_CommandGraft( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern Wlc_Ntk_t * Wlc_NtkGraftMulti( Wlc_Ntk_t * p, int fVerbose );
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandGraft(): There is no current design.\n" );
        return 0;
    }
    pNtk = Wlc_NtkGraftMulti( pNtk, fVerbose );
    Wlc_AbcUpdateNtk( pAbc, pNtk );
    return 0;
usage:
    Abc_Print( -2, "usage: %%graft [-vh]\n" );
    Abc_Print( -2, "\t         detects multipliers in LHS of the miter and moves them to RHS\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1328 1329
int Abc_CommandRetime( Abc_Frame_t * pAbc, int argc, char ** argv )
{
1330
    extern void Wln_NtkRetimeTest( char * pFileName, int fSkipSimple, int fVerbose );
1331 1332
    FILE * pFile;
    char * pFileName = NULL;
1333
    int fSkipSimple  = 0;
1334 1335
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
1336
    while ( ( c = Extra_UtilGetopt( argc, argv, "svh" ) ) != EOF )
1337 1338 1339
    {
        switch ( c )
        {
1340 1341 1342
        case 's':
            fSkipSimple ^= 1;
            break;
1343 1344 1345 1346 1347 1348 1349 1350 1351
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
    if ( pAbc->pNdr )
    {
        Vec_Int_t * vMoves;
        Wln_Ntk_t * pNtk = Wln_NtkFromNdr( pAbc->pNdr );
        Wln_NtkRetimeCreateDelayInfo( pNtk );
        if ( pNtk == NULL )
        {
            printf( "Transforming NDR into internal represnetation has failed.\n" );
            return 0;
        }
1362
        vMoves = Wln_NtkRetime( pNtk, fSkipSimple, fVerbose );
1363 1364 1365 1366 1367 1368
        Wln_NtkFree( pNtk );
        ABC_FREE( pAbc->pNdrArray );
        if ( vMoves ) pAbc->pNdrArray = Vec_IntReleaseNewArray( vMoves );
        Vec_IntFreeP( &vMoves );
        return 0;
    }
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
    if ( argc != globalUtilOptind + 1 )
    {
        printf( "Abc_CommandRetime(): Input file name should be given on the command line.\n" );
        return 0;
    }
    // get the file name
    pFileName = argv[globalUtilOptind];
    if ( (pFile = fopen( pFileName, "r" )) == NULL )
    {
        Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName );
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".ndr", NULL, NULL, NULL, NULL )) )
            Abc_Print( 1, "Did you mean \"%s\"?", pFileName );
        Abc_Print( 1, "\n" );
        return 0;
    }
    fclose( pFile );
1385
    Wln_NtkRetimeTest( pFileName, fSkipSimple, fVerbose );
1386 1387
    return 0;
usage:
1388
    Abc_Print( -2, "usage: %%retime [-svh]\n" );
1389
    Abc_Print( -2, "\t         performs retiming for the NDR design\n" );
1390
    Abc_Print( -2, "\t-s     : toggle printing simple nodes [default = %s]\n", !fSkipSimple? "yes": "no" );
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1407
int Abc_CommandProfile( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
1408
{
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandProfile(): There is no current design.\n" );
        return 0;
    }
    Wlc_WinProfileArith( pNtk );
    return 0;
usage:
    Abc_Print( -2, "usage: %%profile [-vh]\n" );
    Abc_Print( -2, "\t         profiles arithmetic components in the word-level networks\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
/**Function********************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
int Abc_CommandShortNames( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( 1, "Abc_CommandProfile(): There is no current design.\n" );
        return 0;
    }
    Wlc_NtkShortNames( pNtk );
    return 0;
usage:
    Abc_Print( -2, "usage: %%short_names [-vh]\n" );
    Abc_Print( -2, "\t         derives short names for all objects of the network\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
/**Function*************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_CommandShow( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern void Wlc_NtkShow( Wlc_Ntk_t * p, Vec_Int_t * vBold );
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
Alan Mishchenko committed
1499
    int c, fMemory = 0, fVerbose = 0;
1500 1501
    // set defaults
    Extra_UtilGetoptReset();
Alan Mishchenko committed
1502
    while ( ( c = Extra_UtilGetopt( argc, argv, "mvh" ) ) != EOF )
1503 1504 1505
    {
        switch ( c )
        {
Alan Mishchenko committed
1506 1507 1508
        case 'm':
            fMemory ^= 1;
            break;
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520
        case 'v':
            fVerbose ^= 1;
            break;
        default:
            goto usage;
        }
    }
    if ( pNtk == NULL )
    {
        Abc_Print( -1, "Empty network.\n" );
        return 1;
    }
Alan Mishchenko committed
1521 1522
    if ( fMemory )
    {
1523
        Vec_Int_t * vTemp = Wlc_NtkCollectMemory( pNtk, 1 );
Alan Mishchenko committed
1524 1525 1526 1527 1528
        Wlc_NtkShow( pNtk, vTemp );
        Vec_IntFree( vTemp );
    }
    else
        Wlc_NtkShow( pNtk, NULL );
1529 1530 1531
    return 0;

usage:
Alan Mishchenko committed
1532 1533
    Abc_Print( -2, "usage: %%show [-mh]\n" );
    Abc_Print( -2, "          visualizes the network structure using DOT and GSVIEW\n" );
1534
#ifdef WIN32
Alan Mishchenko committed
1535 1536
    Abc_Print( -2, "          \"dot.exe\" and \"gsview32.exe\" should be set in the paths\n" );
    Abc_Print( -2, "          (\"gsview32.exe\" may be in \"C:\\Program Files\\Ghostgum\\gsview\\\")\n" );
1537
#endif
Alan Mishchenko committed
1538 1539
    Abc_Print( -2, "\t-m   :  toggle showing memory subsystem [default = %s]\n", fMemory? "yes": "no" );
    Abc_Print( -2, "\t-h   :  print the command usage\n");
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
int Abc_CommandInvPs( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern Vec_Int_t * Pdr_InvCounts( Vec_Int_t * vInv );
Alan Mishchenko committed
1557 1558
    extern void Wlc_NtkPrintInvStats( Wlc_Ntk_t * pNtk, Vec_Int_t * vInv, int fVerbose );
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
1559
    Vec_Int_t * vCounts;
Alan Mishchenko committed
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pNtk == NULL )
    {
1577
        Abc_Print( 1, "Abc_CommandInvPs(): There is no current design.\n" );
Alan Mishchenko committed
1578 1579
        return 0;
    }
1580
    if ( Wlc_AbcGetInv(pAbc) == NULL )
Alan Mishchenko committed
1581
    {
1582
        Abc_Print( 1, "Abc_CommandInvPs(): Invariant is not available.\n" );
Alan Mishchenko committed
1583 1584
        return 0;
    }
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
    vCounts = Pdr_InvCounts( Wlc_AbcGetInv(pAbc) );
    Wlc_NtkPrintInvStats( pNtk, vCounts, fVerbose );
    Vec_IntFree( vCounts );
    return 0;
usage:
    Abc_Print( -2, "usage: inv_ps [-vh]\n" );
    Abc_Print( -2, "\t         prints statistics for inductive invariant\n" );
    Abc_Print( -2, "\t         (in the case of \'sat\' or \'undecided\', inifity clauses are used)\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
int Abc_CommandInvPrint( Abc_Frame_t * pAbc, int argc, char ** argv )
{
1611
    extern void Pdr_InvPrint( Vec_Int_t * vInv, int fVerbose );
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
1627 1628
    if ( Wlc_AbcGetInv(pAbc) == NULL )
    {
1629
        Abc_Print( 1, "Abc_CommandInvPs(): Invariant is not available.\n" );
1630 1631
        return 0;
    }
1632
    Pdr_InvPrint( Wlc_AbcGetInv(pAbc), fVerbose );
Alan Mishchenko committed
1633
    return 0;
1634 1635 1636
usage:
    Abc_Print( -2, "usage: inv_print [-vh]\n" );
    Abc_Print( -2, "\t         prints the current inductive invariant\n" );
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
    Abc_Print( -2, "\t         (in the case of \'sat\' or \'undecided\', inifity clauses are used)\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1654
int Abc_CommandInvCheck( Abc_Frame_t * pAbc, int argc, char ** argv )
1655
{
1656
    abctime clk = Abc_Clock();
1657
    extern int Pdr_InvCheck( Gia_Man_t * p, Vec_Int_t * vInv, int fVerbose );
1658
    int c, nFailed, fVerbose  = 0;
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
1673 1674 1675 1676 1677 1678
    if ( pAbc->pGia == NULL )
    {
        Abc_Print( 1, "Abc_CommandInvMin(): There is no current design.\n" );
        return 0;
    }
    if ( Wlc_AbcGetInv(pAbc) == NULL )
1679
    {
1680
        Abc_Print( 1, "Abc_CommandInvMin(): There is no saved invariant.\n" );
1681 1682
        return 0;
    }
1683
    if ( Gia_ManRegNum(pAbc->pGia) != Vec_IntEntryLast(Wlc_AbcGetInv(pAbc)) )
1684
    {
1685
        Abc_Print( 1, "Abc_CommandInvMin(): The number of flops in the invariant and in GIA should be the same.\n" );
1686 1687
        return 0;
    }
1688
    nFailed = Pdr_InvCheck( pAbc->pGia, Wlc_AbcGetInv(pAbc), fVerbose );
1689
    if ( nFailed )
1690
        printf( "Invariant verification failed for %d clauses (out of %d). ", nFailed, Vec_IntEntry(Wlc_AbcGetInv(pAbc),0) );
1691
    else
1692 1693
        printf( "Invariant verification succeeded.    " );
    Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
    return 0;
usage:
    Abc_Print( -2, "usage: inv_check [-vh]\n" );
    Abc_Print( -2, "\t         checks that the invariant is indeed an inductive invariant\n" );
    Abc_Print( -2, "\t         (AIG representing the design should be in the &-space)\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
int Abc_CommandInvGet( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern Abc_Ntk_t * Wlc_NtkGetInv( Wlc_Ntk_t * pNtk, Vec_Int_t * vInv );
    Abc_Ntk_t * pMainNtk;
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
1735 1736
    if ( Wlc_AbcGetInv(pAbc) == NULL )
    {
1737
        Abc_Print( 1, "Abc_CommandInvGet(): Invariant is not available.\n" );
1738 1739 1740
        return 0;
    }
    // derive the network
1741
    pMainNtk = Wlc_NtkGetInv( pNtk, Wlc_AbcGetInv(pAbc) );
1742
    // replace the current network
1743 1744
    if ( pMainNtk )
        Abc_FrameReplaceCurrentNetwork( pAbc, pMainNtk );
1745
    return 0;
1746 1747
usage:
    Abc_Print( -2, "usage: inv_get [-vh]\n" );
1748 1749
    Abc_Print( -2, "\t         places invariant found by PDR as the current network in the main-space\n" );
    Abc_Print( -2, "\t         (in the case of \'sat\' or \'undecided\', inifity clauses are used)\n" );
Alan Mishchenko committed
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1766
int Abc_CommandInvPut( Abc_Frame_t * pAbc, int argc, char ** argv )
1767
{
1768
    extern Vec_Int_t * Wlc_NtkGetPut( Abc_Ntk_t * pNtk, Gia_Man_t * pGia );
1769 1770
    Vec_Int_t * vInv = NULL;
    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1771 1772 1773 1774 1775 1776
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
1777 1778 1779 1780 1781 1782 1783
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
1784 1785 1786 1787
        }
    }
    if ( pNtk == NULL )
    {
1788
        Abc_Print( 1, "Abc_CommandInvPut(): There is no current design.\n" );
1789 1790
        return 0;
    }
1791 1792 1793 1794 1795 1796
    if ( pAbc->pGia == NULL )
    {
        Abc_Print( 1, "Abc_CommandInvPut(): There is no current AIG.\n" );
        return 0;
    }
    // derive the network
1797
    vInv = Wlc_NtkGetPut( pNtk, pAbc->pGia );
1798 1799
    if ( vInv )
        Abc_FrameSetInv( vInv );
1800 1801
    return 0;
usage:
1802 1803 1804
    Abc_Print( -2, "usage: inv_put [-vh]\n" );
    Abc_Print( -2, "\t         inputs the current network in the main-space as an invariant\n" );
    Abc_Print( -2, "\t         (AIG representing the design should be in the &-space)\n" );
1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
1821
int Abc_CommandInvMin( Abc_Frame_t * pAbc, int argc, char ** argv )
1822
{
1823 1824
    extern Vec_Int_t * Pdr_InvMinimize( Gia_Man_t * p, Vec_Int_t * vInv, int fVerbose );
    extern Vec_Int_t * Pdr_InvMinimizeLits( Gia_Man_t * p, Vec_Int_t * vInv, int fVerbose );
1825
    Vec_Int_t * vInv, * vInv2;
1826
    int c, fLits = 0, fVerbose  = 0;
1827
    Extra_UtilGetoptReset();
1828
    while ( ( c = Extra_UtilGetopt( argc, argv, "lvh" ) ) != EOF )
1829 1830 1831
    {
        switch ( c )
        {
1832 1833 1834
            case 'l':
                fLits ^= 1;
                break;
1835 1836 1837 1838 1839 1840 1841
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
1842 1843
        }
    }
1844
    if ( pAbc->pGia == NULL )
1845
    {
1846
        Abc_Print( 1, "Abc_CommandInvMin(): There is no current design.\n" );
1847 1848
        return 0;
    }
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
    if ( Wlc_AbcGetInv(pAbc) == NULL )
    {
        Abc_Print( 1, "Abc_CommandInvMin(): Invariant is not available.\n" );
        return 0;
    }
    vInv = Wlc_AbcGetInv(pAbc);
    if ( Gia_ManRegNum(pAbc->pGia) != Vec_IntEntryLast(vInv) )
    {
        Abc_Print( 1, "Abc_CommandInvMin(): The number of flops in the invariant and in GIA should be the same.\n" );
        return 0;
    }
1860
    if ( fLits )
1861
        vInv2 = Pdr_InvMinimizeLits( pAbc->pGia, vInv, fVerbose );
1862
    else
1863
        vInv2 = Pdr_InvMinimize( pAbc->pGia, vInv, fVerbose );
1864 1865
    if ( vInv2 )
        Abc_FrameSetInv( vInv2 );
1866 1867
    return 0;
usage:
1868 1869
    Abc_Print( -2, "usage: inv_min [-lvh]\n" );
    Abc_Print( -2, "\t         performs minimization of the current invariant\n" );
1870
    Abc_Print( -2, "\t         (AIG representing the design should be in the &-space)\n" );
1871
    Abc_Print( -2, "\t-l     : toggle minimizing literals rather than clauses [default = %s]\n", fLits? "yes": "no" );
1872
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
1873 1874 1875 1876
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

Alan Mishchenko committed
1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
/**Function********************************************************************

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

******************************************************************************/
int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
{
1890
    extern void Wlc_NtkExploreMem( Wlc_Ntk_t * p, int nFrames );
Alan Mishchenko committed
1891
    extern void Wlc_NtkSimulateTest( Wlc_Ntk_t * p );
1892
    Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
Alan Mishchenko committed
1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
    int c, fVerbose  = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
        case 'v':
            fVerbose ^= 1;
            break;
        case 'h':
            goto usage;
        default:
            goto usage;
        }
    }
1908 1909 1910 1911 1912 1913
//    if ( pNtk == NULL )
//    {
//        Abc_Print( 1, "Abc_CommandTest(): There is no current design.\n" );
//        return 0;
//    }

Alan Mishchenko committed
1914 1915 1916 1917 1918 1919 1920 1921
    // transform
    //pNtk = Wlc_NtkUifNodePairs( pNtk, NULL );
    //pNtk = Wlc_NtkAbstractNodes( pNtk, NULL );
    //Wlc_AbcUpdateNtk( pAbc, pNtk );
    //Wlc_GenerateSmtStdout( pAbc );
    //Wlc_NtkSimulateTest( (Wlc_Ntk_t *)pAbc->pAbcWlc );
    //pNtk = Wlc_NtkDupSingleNodes( pNtk );
    //Wlc_AbcUpdateNtk( pAbc, pNtk );
1922
    //Wln_ReadNdrTest();
1923 1924
    //pNtk = Wlc_NtkMemAbstractTest( pNtk );
    //Wlc_AbcUpdateNtk( pAbc, pNtk );
1925
    //Wln_NtkFromWlcTest( pNtk );
1926
    Wlc_NtkExploreMem( pNtk, 0 );
Alan Mishchenko committed
1927 1928 1929 1930 1931 1932 1933 1934 1935
    return 0;
usage:
    Abc_Print( -2, "usage: %%test [-vh]\n" );
    Abc_Print( -2, "\t         experiments with word-level networks\n" );
    Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
    Abc_Print( -2, "\t-h     : print the command usage\n");
    return 1;
}

1936 1937 1938 1939 1940 1941 1942
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END