mio.c 22.7 KB
Newer Older
Alan Mishchenko committed
1 2
/**CFile****************************************************************

3
  pFileName    [mio.c]
Alan Mishchenko committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

  Synopsis    [File reading/writing for technology mapping.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - August 18, 2003.]

  Revision    [$Id: mio.c,v 1.4 2004/08/05 18:34:51 satrajit Exp $]

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

Alan Mishchenko committed
19 20 21 22 23 24
#define _BSD_SOURCE

#ifndef WIN32
#include <unistd.h>
#endif

25
#include "base/main/main.h"
26
#include "mio.h"
27 28
#include "map/mapper/mapper.h"
#include "map/amap/amap.h"
Alan Mishchenko committed
29

30 31
ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
32

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

Alan Mishchenko committed
37
static int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv );
38 39 40
static int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv );
41 42 43
static int Mio_CommandReadProfile( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandWriteProfile( Abc_Frame_t * pAbc, int argc, char **argv );
static int Mio_CommandPrintProfile( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
44

45
/*
46
// internal version of genlib library
Alan Mishchenko committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
static char * pMcncGenlib[25] = {
    "GATE inv1    1   O=!a;             PIN * INV     1 999 0.9 0.0 0.9 0.0\n",
    "GATE inv2    2   O=!a;             PIN * INV     2 999 1.0 0.0 1.0 0.0\n",
    "GATE inv3    3   O=!a;             PIN * INV     3 999 1.1 0.0 1.1 0.0\n",
    "GATE inv4    4   O=!a;             PIN * INV     4 999 1.2 0.0 1.2 0.0\n",
    "GATE nand2   2   O=!(a*b);         PIN * INV     1 999 1.0 0.0 1.0 0.0\n",
    "GATE nand3   3   O=!(a*b*c);       PIN * INV     1 999 1.1 0.0 1.1 0.0\n",
    "GATE nand4   4   O=!(a*b*c*d);     PIN * INV     1 999 1.4 0.0 1.4 0.0\n",
    "GATE nor2    2   O=!(a+b);         PIN * INV     1 999 1.4 0.0 1.4 0.0\n",
    "GATE nor3    3   O=!(a+b+c);       PIN * INV     1 999 2.4 0.0 2.4 0.0\n",
    "GATE nor4    4   O=!(a+b+c+d);     PIN * INV     1 999 3.8 0.0 3.8 0.0\n",
    "GATE xora    5   O=a*!b+!a*b;      PIN * UNKNOWN 2 999 1.9 0.0 1.9 0.0\n",
    "GATE xorb    5   O=!(a*b+!a*!b);   PIN * UNKNOWN 2 999 1.9 0.0 1.9 0.0\n",
    "GATE xnora   5   O=a*b+!a*!b;      PIN * UNKNOWN 2 999 2.1 0.0 2.1 0.0\n",
    "GATE xnorb   5   O=!(!a*b+a*!b);   PIN * UNKNOWN 2 999 2.1 0.0 2.1 0.0\n",
    "GATE aoi21   3   O=!(a*b+c);       PIN * INV     1 999 1.6 0.0 1.6 0.0\n",
    "GATE aoi22   4   O=!(a*b+c*d);     PIN * INV     1 999 2.0 0.0 2.0 0.0\n",
    "GATE oai21   3   O=!((a+b)*c);     PIN * INV     1 999 1.6 0.0 1.6 0.0\n",
    "GATE oai22   4   O=!((a+b)*(c+d)); PIN * INV     1 999 2.0 0.0 2.0 0.0\n",
    "GATE buf     1   O=a;              PIN * NONINV  1 999 1.0 0.0 1.0 0.0\n",
    "GATE zero    0   O=CONST0;\n",
    "GATE one     0   O=CONST1;\n"
};
70
*/
Alan Mishchenko committed
71
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
72
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mio_Init( Abc_Frame_t * pAbc )
{
88
//    Cmd_CommandAdd( pAbc, "SC mapping", "read_liberty",   Mio_CommandReadLiberty,  0 ); 
Alan Mishchenko committed
89

90 91 92
    Cmd_CommandAdd( pAbc, "SC mapping", "read_genlib",    Mio_CommandReadGenlib,  0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping", "write_genlib",   Mio_CommandWriteGenlib, 0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping", "print_genlib",   Mio_CommandPrintGenlib, 0 ); 
Alan Mishchenko committed
93

94 95 96 97
    Cmd_CommandAdd( pAbc, "SC mapping", "read_profile",   Mio_CommandReadProfile,  0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping", "write_profile",  Mio_CommandWriteProfile, 0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping", "print_profile",  Mio_CommandPrintProfile, 0 ); 

98 99 100
    Cmd_CommandAdd( pAbc, "SC mapping", "read_library",   Mio_CommandReadGenlib,  0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping", "write_library",  Mio_CommandWriteGenlib, 0 ); 
    Cmd_CommandAdd( pAbc, "SC mapping", "print_library",  Mio_CommandPrintGenlib, 0 ); 
Alan Mishchenko committed
101 102 103 104 105 106 107 108 109 110 111 112 113
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
114
void Mio_End( Abc_Frame_t * pAbc )
Alan Mishchenko committed
115
{
116 117
    Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
    Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
Alan Mishchenko committed
118 119
}

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mio_UpdateGenlib( Mio_Library_t * pLib )
{
    // free the current superlib because it depends on the old Mio library
    if ( Abc_FrameReadLibSuper() )
    {
        Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
        Abc_FrameSetLibSuper( NULL );
    }

    // replace the current library
    Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
    Abc_FrameSetLibGen( pLib );

    // replace the current library
    Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
    Abc_FrameSetLibGen2( NULL );
}
int Mio_UpdateGenlib2( Vec_Str_t * vStr, Vec_Str_t * vStr2, char * pFileName, int fVerbose )
{
    Mio_Library_t * pLib;
    // set the new network
    pLib = Mio_LibraryRead( pFileName, Vec_StrArray(vStr), NULL, fVerbose );  
    if ( pLib == NULL )
        return 0;

    // free the current superlib because it depends on the old Mio library
    if ( Abc_FrameReadLibSuper() )
    {
        Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() );
        Abc_FrameSetLibSuper( NULL );
    }

    // replace the current library
    Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() );
    Abc_FrameSetLibGen( pLib );

    // set the new network
    pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, Vec_StrArray(vStr2), 0, 0 );  
    if ( pLib == NULL )
        return 0;

    // replace the current library
    Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() );
    Abc_FrameSetLibGen2( pLib );
    return 1;
}
Alan Mishchenko committed
177 178 179 180 181 182 183 184 185 186 187 188

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
189 190
int Mio_CommandReadLiberty( Abc_Frame_t * pAbc, int argc, char **argv )
{
191
    int fUseFileInterface = 0;
192
    char Command[1000];
Alan Mishchenko committed
193 194
    FILE * pFile;
    FILE * pOut, * pErr;
195
    char * pFileName;
Alan Mishchenko committed
196 197 198 199 200 201 202
    int fVerbose;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
203
    fVerbose = 0;
Alan Mishchenko committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF ) 
    {
        switch (c) 
        {
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }

    if ( argc != globalUtilOptind + 1 )
        goto usage;

    // get the input file name
224 225
    pFileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( pFileName, "open_path", "r", 0 )) == NULL )
Alan Mishchenko committed
226
    {
227
        fprintf( pErr, "Cannot open input file \"%s\". ", pFileName );
228
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".genlib", ".lib", ".scl", ".g", NULL )) )
229
            fprintf( pErr, "Did you mean \"%s\"?", pFileName );
Alan Mishchenko committed
230 231 232 233 234
        fprintf( pErr, "\n" );
        return 1;
    }
    fclose( pFile );

235 236 237 238 239 240 241 242 243 244 245
    if ( fUseFileInterface )
    {
        if ( !Amap_LibertyParse( pFileName, fVerbose ) )
            return 0;
        assert( strlen(pFileName) < 900 );
        sprintf( Command, "read_genlib %s", Extra_FileNameGenericAppend(pFileName, ".genlib") );
        Cmd_CommandExecute( pAbc, Command );
    }
    else
    {
        Vec_Str_t * vStr, * vStr2;
246
        int RetValue;
247 248 249
        vStr = Amap_LibertyParseStr( pFileName, fVerbose );
        if ( vStr == NULL )
            return 0;
250 251
        vStr2 = Vec_StrDup(vStr);
        RetValue = Mio_UpdateGenlib2( vStr, vStr2, pFileName, fVerbose );
252 253
        Vec_StrFree( vStr );
        Vec_StrFree( vStr2 );
254 255
        if ( !RetValue )
            printf( "Reading library has filed.\n" );
256
    }
Alan Mishchenko committed
257 258 259 260 261 262 263 264 265 266
    return 0;

usage:
    fprintf( pErr, "usage: read_liberty [-vh]\n");
    fprintf( pErr, "\t         read standard cell library in Liberty format\n" );  
    fprintf( pErr, "\t         (if the library contains more than one gate\n" );  
    fprintf( pErr, "\t         with the same Boolean function, only the gate\n" );  
    fprintf( pErr, "\t         with the smallest area will be used)\n" );  
    fprintf( pErr, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
    fprintf( pErr, "\t-h     : enable verbose output\n");
267
    return 1;       
Alan Mishchenko committed
268 269 270 271 272 273 274 275 276 277 278 279 280
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
281
int Mio_CommandReadGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
282 283 284 285
{
    FILE * pFile;
    FILE * pOut, * pErr;
    Mio_Library_t * pLib;
286
    Amap_Lib_t * pLib2;
287 288
    char * pFileName;
    char * pExcludeFile = NULL;
289 290 291
    double WireDelay = 0.0;
    int fShortNames = 0;
    int c, fVerbose = 1;
Alan Mishchenko committed
292 293 294

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);
Alan Mishchenko committed
295
    Extra_UtilGetoptReset();
296
    while ( (c = Extra_UtilGetopt(argc, argv, "WEnvh")) != EOF ) 
Alan Mishchenko committed
297 298 299
    {
        switch (c) 
        {
300 301 302 303 304 305 306 307 308 309 310
            case 'W':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-W\" should be followed by a floating point number.\n" );
                    goto usage;
                }
                WireDelay = (float)atof(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( WireDelay <= 0.0 ) 
                    goto usage;
                break;
311 312 313 314 315 316 317 318 319
            case 'E':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-E\" should be followed by a file name.\n" );
                    goto usage;
                }
                pExcludeFile = argv[globalUtilOptind];
                globalUtilOptind++;
                break;
320 321 322
            case 'n':
                fShortNames ^= 1;
                break;
Alan Mishchenko committed
323 324 325 326 327 328 329 330 331 332
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
333
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
334 335 336 337 338
    {
        goto usage;
    }

    // get the input file name
339 340
    pFileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( pFileName, "open_path", "r", 0 )) == NULL )
Alan Mishchenko committed
341
    {
342
        fprintf( pErr, "Cannot open input file \"%s\". ", pFileName );
343
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".genlib", ".lib", ".scl", ".g", NULL )) )
344
            fprintf( pErr, "Did you mean \"%s\"?", pFileName );
Alan Mishchenko committed
345 346 347 348 349 350
        fprintf( pErr, "\n" );
        return 1;
    }
    fclose( pFile );

    // set the new network
351
    pLib = Mio_LibraryRead( pFileName, NULL, pExcludeFile, fVerbose );  
Alan Mishchenko committed
352 353
    if ( pLib == NULL )
    {
354
        fprintf( pErr, "Reading genlib library has failed.\n" );
Alan Mishchenko committed
355 356
        return 1;
    }
357 358 359
    if ( fVerbose )
        printf( "Entered genlib library with %d gates from file \"%s\".\n", Mio_LibraryReadGateNum(pLib), pFileName );

360 361 362 363
    // convert the library if needed
    if ( fShortNames )
        Mio_LibraryShortNames( pLib );

364 365
    // add the fixed number (wire delay) to all delays in the library
    if ( WireDelay != 0.0 )
366
        Mio_LibraryShiftDelay( pLib, WireDelay );
367

368 369
    // prepare libraries
    Mio_UpdateGenlib( pLib );
Alan Mishchenko committed
370 371

    // replace the current library
372 373
    pLib2 = Amap_LibReadAndPrepare( pFileName, NULL, 0, 0 );  
    if ( pLib2 == NULL )
Alan Mishchenko committed
374
    {
375
        fprintf( pErr, "Reading second genlib library has failed.\n" );
Alan Mishchenko committed
376 377
        return 1;
    }
378
    Abc_FrameSetLibGen2( pLib2 );
Alan Mishchenko committed
379 380 381
    return 0;

usage:
382
    fprintf( pErr, "usage: read_genlib [-W float] [-E filename] [-nvh]\n");
383 384 385 386
    fprintf( pErr, "\t           read the library from a genlib file\n" );  
    fprintf( pErr, "\t           (if the library contains more than one gate\n" );  
    fprintf( pErr, "\t           with the same Boolean function, only the gate\n" );  
    fprintf( pErr, "\t           with the smallest area will be used)\n" );  
387 388
    fprintf( pErr, "\t-W float : wire delay (added to pin-to-pin gate delays) [default = %g]\n", WireDelay );  
    fprintf( pErr, "\t-E file :  the file name with gates to be excluded [default = none]\n" );
389
    fprintf( pErr, "\t-n       : toggle replacing gate/pin names by short strings [default = %s]\n", fShortNames? "yes": "no" );
390 391
    fprintf( pErr, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
    fprintf( pErr, "\t-h       : enable verbose output\n");
392
    return 1;       
Alan Mishchenko committed
393 394 395 396 397 398 399 400 401 402 403 404 405
}

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

  Synopsis    [Command procedure to read LUT libraries.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
406
int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
407
{
408
    FILE * pOut, * pErr, * pFile;
409
    char * pFileName;
410
    int fSelected = 0;
411
    int fVerilog = 0;
412
    int fVerbose = 0;
Alan Mishchenko committed
413 414 415 416 417
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

Alan Mishchenko committed
418
    Extra_UtilGetoptReset();
419
    while ( (c = Extra_UtilGetopt(argc, argv, "agvh")) != EOF ) 
Alan Mishchenko committed
420 421 422
    {
        switch (c) 
        {
423 424 425
            case 'a':
                fSelected ^= 1;
                break;
426 427 428 429 430 431
            case 'g':
                fVerilog ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
Alan Mishchenko committed
432 433 434 435 436 437 438
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }
439 440 441 442 443
    if ( Abc_FrameReadLibGen() == NULL )
    {
        printf( "Library is not available.\n" );
        return 1;
    }
444 445 446 447 448 449
    if ( argc != globalUtilOptind + 1 )
    {
        printf( "The file name is not given.\n" );
        return 1;
    }

450
    pFileName = argv[globalUtilOptind];
451 452
    pFile = fopen( pFileName, "w" );
    if ( pFile == NULL )
Alan Mishchenko committed
453
    {
454 455
        printf( "Error! Cannot open file \"%s\" for writing the library.\n", pFileName );
        return 1;
Alan Mishchenko committed
456
    }
457 458 459 460
    if ( fVerilog )
        Mio_WriteLibraryVerilog( pFile, (Mio_Library_t *)Abc_FrameReadLibGen(), 0, 0, fSelected );
    else
        Mio_WriteLibrary( pFile, (Mio_Library_t *)Abc_FrameReadLibGen(), 0, 0, fSelected );
461
    fclose( pFile );
462
    printf( "The current genlib library is written into file \"%s\".\n", pFileName );
Alan Mishchenko committed
463 464 465
    return 0;

usage:
466
    fprintf( pErr, "\nusage: write_genlib [-agvh] <file>\n");
467
    fprintf( pErr, "\t          writes the current genlib library into a file\n" );  
468
    fprintf( pErr, "\t-a      : toggles writing min-area gates [default = %s]\n", fSelected? "yes" : "no" );
469 470
    fprintf( pErr, "\t-g      : toggles writing the library in Verilog [default = %s]\n", fVerilog? "yes" : "no" );
    fprintf( pErr, "\t-v      : toggles enabling of verbose output [default = %s]\n", fVerbose? "yes" : "no" );
Alan Mishchenko committed
471
    fprintf( pErr, "\t-h      : print the command usage\n");
472
    fprintf( pErr, "\t<file>  : optional file name to write the library\n");
473
    return 1;       
Alan Mishchenko committed
474
}
Alan Mishchenko committed
475 476 477 478 479 480 481 482 483 484 485 486

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

  Synopsis    [Command procedure to read LUT libraries.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
487
int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
488 489
{
    FILE * pOut, * pErr;
490
    int fShort = 0;
491
    int fSelected = 0;
492
    int fVerbose = 0;
Alan Mishchenko committed
493 494 495 496 497 498 499
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    Extra_UtilGetoptReset();
500
    while ( (c = Extra_UtilGetopt(argc, argv, "savh")) != EOF ) 
Alan Mishchenko committed
501 502 503
    {
        switch (c) 
        {
504 505 506
            case 's':
                fShort ^= 1;
                break;
507 508 509
            case 'a':
                fSelected ^= 1;
                break;
Alan Mishchenko committed
510 511 512 513 514 515 516 517 518 519
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }
520
    if ( Abc_FrameReadLibGen() == NULL )
Alan Mishchenko committed
521
    {
522 523
        printf( "Library is not available.\n" );
        return 1;
Alan Mishchenko committed
524
    }
525
    Mio_WriteLibrary( stdout, (Mio_Library_t *)Abc_FrameReadLibGen(), 0, fShort, fSelected );
Alan Mishchenko committed
526 527 528
    return 0;

usage:
529
    fprintf( pErr, "\nusage: print_genlib [-savh]\n");
530
    fprintf( pErr, "\t          print the current genlib library\n" );  
531
    fprintf( pErr, "\t-s      : toggles writing short form [default = %s]\n", fShort? "yes" : "no" );
532
    fprintf( pErr, "\t-a      : toggles writing min-area gates [default = %s]\n", fSelected? "yes" : "no" );
533
    fprintf( pErr, "\t-v      : toggles enabling of verbose output [default = %s]\n", fVerbose? "yes" : "no" );
Alan Mishchenko committed
534
    fprintf( pErr, "\t-h      : print the command usage\n");
535
    return 1;       
Alan Mishchenko committed
536 537
}

538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Mio_CommandReadProfile( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pFile, * pOut, * pErr;
    Mio_Library_t * pLib;
    char * pFileName;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "h")) != EOF ) 
    {
        switch (c) 
        {
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
    {
        goto usage;
    }

    pLib = (Mio_Library_t *)Abc_FrameReadLibGen();
    if ( pLib == NULL )
    {
        fprintf( pErr, "There is no Genlib library entered.\n" );
        return 1;
    }

    // get the input file name
    pFileName = argv[globalUtilOptind];
    if ( (pFile = Io_FileOpen( pFileName, "open_path", "r", 0 )) == NULL )
    {
        fprintf( pErr, "Cannot open input file \"%s\". ", pFileName );
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".profile", NULL, NULL, NULL, NULL )) )
            fprintf( pErr, "Did you mean \"%s\"?", pFileName );
        fprintf( pErr, "\n" );
        return 1;
    }

    // set the new network
    Mio_LibraryReadProfile( pFile, pLib );
    fclose( pFile );
    return 0;

usage:
    fprintf( pErr, "usage: read_profile [-h] <file>\n");
    fprintf( pErr, "\t          read a gate profile from a profile file\n" );  
    fprintf( pErr, "\t-h      : enable verbose output\n");
    fprintf( pErr, "\t<file>  : file name to read the profile\n");
    return 1;       
}

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

  Synopsis    [Command procedure to read LUT libraries.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Mio_CommandWriteProfile( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pOut, * pErr, * pFile;
    char * pFileName;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "h")) != EOF ) 
    {
        switch (c) 
        {
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }
    if ( Abc_FrameReadLibGen() == NULL )
    {
        printf( "Library is not available.\n" );
        return 1;
    }
    if ( argc != globalUtilOptind + 1 )
    {
        printf( "The file name is not given.\n" );
        return 1;
    }

    pFileName = argv[globalUtilOptind];
    pFile = fopen( pFileName, "w" );
    if ( pFile == NULL )
    {
        printf( "Error! Cannot open file \"%s\" for writing the library.\n", pFileName );
        return 1;
    }
    Mio_LibraryWriteProfile( pFile, (Mio_Library_t *)Abc_FrameReadLibGen() );
    fclose( pFile );
    printf( "The current profile is written into file \"%s\".\n", pFileName );
    return 0;

usage:
    fprintf( pErr, "\nusage: write_profile [-h] <file>\n");
    fprintf( pErr, "\t          writes the current profile into a file\n" );  
    fprintf( pErr, "\t-h      : print the command usage\n");
    fprintf( pErr, "\t<file>  : file name to write the profile\n");
    return 1;       
}

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

  Synopsis    [Command procedure to read LUT libraries.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Mio_CommandPrintProfile( Abc_Frame_t * pAbc, int argc, char **argv )
{
    FILE * pOut, * pErr;
    int fShort = 0;
    int fSelected = 0;
    int fVerbose = 0;
    int c;

    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);

    // set the defaults
    Extra_UtilGetoptReset();
    while ( (c = Extra_UtilGetopt(argc, argv, "savh")) != EOF ) 
    {
        switch (c) 
        {
            case 's':
                fShort ^= 1;
                break;
            case 'a':
                fSelected ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
        }
    }
    if ( Abc_FrameReadLibGen() == NULL )
    {
        printf( "Library is not available.\n" );
        return 1;
    }
    Mio_LibraryWriteProfile( stdout, (Mio_Library_t *)Abc_FrameReadLibGen() );
    return 0;

usage:
    fprintf( pErr, "\nusage: print_profile [-h]\n");
    fprintf( pErr, "\t          print the current gate profile\n" );  
    fprintf( pErr, "\t-h      : print the command usage\n");
    return 1;       
}
Alan Mishchenko committed
730 731 732 733 734
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


735 736
ABC_NAMESPACE_IMPL_END