io.c 78.9 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**CFile****************************************************************

  FileName    [io.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Command processing package.]

  Synopsis    [Command file.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

Alan Mishchenko committed
21
#include "ioAbc.h"
Alan Mishchenko committed
22 23
#include "mainInt.h"

24 25
ABC_NAMESPACE_IMPL_START

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

static int IoCommandRead        ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
31 32
static int IoCommandReadAiger   ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadBaf     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
33
static int IoCommandReadBblif   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
34
static int IoCommandReadBlif    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
35
static int IoCommandReadBlifMv  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
36
static int IoCommandReadBench   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
37
static int IoCommandReadDsd     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
38
static int IoCommandReadEdif    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
39
static int IoCommandReadEqn     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
40
static int IoCommandReadInit    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
41
static int IoCommandReadPla     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
42 43 44 45
static int IoCommandReadTruth   ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadVerilog ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadVer     ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadVerLib  ( Abc_Frame_t * pAbc, int argc, char **argv );
46
static int IoCommandReadStatus  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
47

Alan Mishchenko committed
48 49 50
static int IoCommandWrite       ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteHie    ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteAiger  ( Abc_Frame_t * pAbc, int argc, char **argv );
51
static int IoCommandWriteAigerCex( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
52
static int IoCommandWriteBaf    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
53
static int IoCommandWriteBblif  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
54
static int IoCommandWriteBlif   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
55
static int IoCommandWriteBlifMv ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
56
static int IoCommandWriteBench  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
57
static int IoCommandWriteBook   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
58
static int IoCommandWriteCellNet( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
59
static int IoCommandWriteCnf    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
60
static int IoCommandWriteCounter( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
61 62 63
static int IoCommandWriteDot    ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteEqn    ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteGml    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
64
static int IoCommandWriteList   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
65
static int IoCommandWritePla    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
66 67
static int IoCommandWriteVerilog( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteVerLib ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
68
static int IoCommandWriteSortCnf( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
69
static int IoCommandWriteTruth  ( Abc_Frame_t * pAbc, int argc, char **argv );
70 71 72 73
static int IoCommandWriteStatus ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteSmv    ( Abc_Frame_t * pAbc, int argc, char **argv );

extern void Abc_FrameCopyLTLDataBase( Abc_Frame_t *pAbc, Abc_Ntk_t * pNtk );
Alan Mishchenko committed
74 75

extern int glo_fMapped;
Alan Mishchenko committed
76

Alan Mishchenko committed
77
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
78
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Io_Init( Abc_Frame_t * pAbc )
{
    Cmd_CommandAdd( pAbc, "I/O", "read",          IoCommandRead,         1 );
Alan Mishchenko committed
95 96
    Cmd_CommandAdd( pAbc, "I/O", "read_aiger",    IoCommandReadAiger,    1 );
    Cmd_CommandAdd( pAbc, "I/O", "read_baf",      IoCommandReadBaf,      1 );
Alan Mishchenko committed
97
    Cmd_CommandAdd( pAbc, "I/O", "read_bblif",    IoCommandReadBblif,    1 );
Alan Mishchenko committed
98
    Cmd_CommandAdd( pAbc, "I/O", "read_blif",     IoCommandReadBlif,     1 );
Alan Mishchenko committed
99
    Cmd_CommandAdd( pAbc, "I/O", "read_blif_mv",  IoCommandReadBlifMv,   1 );
Alan Mishchenko committed
100
    Cmd_CommandAdd( pAbc, "I/O", "read_bench",    IoCommandReadBench,    1 );
Alan Mishchenko committed
101 102
    Cmd_CommandAdd( pAbc, "I/O", "read_dsd",      IoCommandReadDsd,      1 );
//    Cmd_CommandAdd( pAbc, "I/O", "read_edif",     IoCommandReadEdif,     1 );
Alan Mishchenko committed
103
    Cmd_CommandAdd( pAbc, "I/O", "read_eqn",      IoCommandReadEqn,      1 );
Alan Mishchenko committed
104
    Cmd_CommandAdd( pAbc, "I/O", "read_init",     IoCommandReadInit,     1 );
Alan Mishchenko committed
105
    Cmd_CommandAdd( pAbc, "I/O", "read_pla",      IoCommandReadPla,      1 );
Alan Mishchenko committed
106 107 108 109
    Cmd_CommandAdd( pAbc, "I/O", "read_truth",    IoCommandReadTruth,    1 );
    Cmd_CommandAdd( pAbc, "I/O", "read_verilog",  IoCommandReadVerilog,  1 );
//    Cmd_CommandAdd( pAbc, "I/O", "read_ver",      IoCommandReadVer,      1 );
//    Cmd_CommandAdd( pAbc, "I/O", "read_verlib",   IoCommandReadVerLib,   0 );
110
    Cmd_CommandAdd( pAbc, "I/O", "read_status",   IoCommandReadStatus,   0 );
Alan Mishchenko committed
111

Alan Mishchenko committed
112 113 114
    Cmd_CommandAdd( pAbc, "I/O", "write",         IoCommandWrite,        0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_hie",     IoCommandWriteHie,     0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_aiger",   IoCommandWriteAiger,   0 );
115
    Cmd_CommandAdd( pAbc, "I/O", "write_aiger_cex",   IoCommandWriteAigerCex,   0 );
Alan Mishchenko committed
116
    Cmd_CommandAdd( pAbc, "I/O", "write_baf",     IoCommandWriteBaf,     0 );
Alan Mishchenko committed
117
    Cmd_CommandAdd( pAbc, "I/O", "write_bblif",   IoCommandWriteBblif,   0 );
Alan Mishchenko committed
118
    Cmd_CommandAdd( pAbc, "I/O", "write_blif",    IoCommandWriteBlif,    0 );
Alan Mishchenko committed
119
    Cmd_CommandAdd( pAbc, "I/O", "write_blif_mv", IoCommandWriteBlifMv,  0 );
Alan Mishchenko committed
120
    Cmd_CommandAdd( pAbc, "I/O", "write_bench",   IoCommandWriteBench,   0 );
Alan Mishchenko committed
121
    Cmd_CommandAdd( pAbc, "I/O", "write_book",    IoCommandWriteBook,    0 );
Alan Mishchenko committed
122 123
    Cmd_CommandAdd( pAbc, "I/O", "write_cellnet", IoCommandWriteCellNet, 0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_counter", IoCommandWriteCounter, 0 );
Alan Mishchenko committed
124
    Cmd_CommandAdd( pAbc, "I/O", "write_cnf",     IoCommandWriteCnf,     0 );
Alan Mishchenko committed
125 126 127
    Cmd_CommandAdd( pAbc, "I/O", "write_dot",     IoCommandWriteDot,     0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_eqn",     IoCommandWriteEqn,     0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_gml",     IoCommandWriteGml,     0 );
Alan Mishchenko committed
128
//    Cmd_CommandAdd( pAbc, "I/O", "write_list",    IoCommandWriteList,    0 );
Alan Mishchenko committed
129
    Cmd_CommandAdd( pAbc, "I/O", "write_pla",     IoCommandWritePla,     0 );
Alan Mishchenko committed
130 131
    Cmd_CommandAdd( pAbc, "I/O", "write_verilog", IoCommandWriteVerilog, 0 );
//    Cmd_CommandAdd( pAbc, "I/O", "write_verlib",  IoCommandWriteVerLib,  0 );
Alan Mishchenko committed
132
    Cmd_CommandAdd( pAbc, "I/O", "write_sorter_cnf", IoCommandWriteSortCnf,  0 );
Alan Mishchenko committed
133
    Cmd_CommandAdd( pAbc, "I/O", "write_truth",   IoCommandWriteTruth,   0 );
134 135
    Cmd_CommandAdd( pAbc, "I/O", "write_status",  IoCommandWriteStatus,  0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_smv",     IoCommandWriteSmv,     0 );
Alan Mishchenko committed
136 137 138 139 140 141 142 143 144 145 146 147 148
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
149
void Io_End( Abc_Frame_t * pAbc )
Alan Mishchenko committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
{
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandRead( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk;
Alan Mishchenko committed
167
    char * pFileName, * pTemp;
Alan Mishchenko committed
168 169 170 171
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
172 173 174
    glo_fMapped = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "mch" ) ) != EOF )
Alan Mishchenko committed
175 176 177
    {
        switch ( c )
        {
Alan Mishchenko committed
178 179 180
            case 'm':
                glo_fMapped ^= 1;
                break;
Alan Mishchenko committed
181 182 183 184 185 186 187 188 189
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
190
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
191 192
        goto usage;
    // get the input file name
Alan Mishchenko committed
193
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
194 195 196 197
    // fix the wrong symbol
    for ( pTemp = pFileName; *pTemp; pTemp++ )
        if ( *pTemp == '>' )
            *pTemp = '\\';
Alan Mishchenko committed
198 199
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, Io_ReadFileType(pFileName), fCheck );
Alan Mishchenko committed
200 201 202 203
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
204 205
    Abc_FrameCopyLTLDataBase( pAbc, pNtk );
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
206 207 208
    return 0;

usage:
Alan Mishchenko committed
209 210 211 212 213
    fprintf( pAbc->Err, "usage: read [-mch] <file>\n" );
    fprintf( pAbc->Err, "\t         replaces the current network by the network read from <file>\n" );
    fprintf( pAbc->Err, "\t         by calling the parser that matches the extension of <file>\n" );
    fprintf( pAbc->Err, "\t         (to read a hierarchical design, use \"read_hie\")\n" );
    fprintf( pAbc->Err, "\t-m     : toggle reading mapped Verilog [default = %s]\n", glo_fMapped? "yes":"no" );
Alan Mishchenko committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
231
int IoCommandReadAiger( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
232
{
Alan Mishchenko committed
233 234
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
235 236 237 238
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
239 240
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
241 242 243 244 245 246 247 248 249 250 251 252
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
253
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
254 255
        goto usage;
    // get the input file name
Alan Mishchenko committed
256 257 258
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_AIGER, fCheck );
Alan Mishchenko committed
259 260 261 262
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
263
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
264 265 266
    return 0;

usage:
Alan Mishchenko committed
267
    fprintf( pAbc->Err, "usage: read_aiger [-ch] <file>\n" );
268
    fprintf( pAbc->Err, "\t         reads the network in the AIGER format (http://fmv.jku.at/aiger)\n" );
Alan Mishchenko committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
286
int IoCommandReadBaf( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
287
{
Alan Mishchenko committed
288 289
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
290 291 292 293
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
294 295
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
296 297 298 299 300 301 302 303 304 305 306 307
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
308
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
309 310
        goto usage;
    // get the input file name
Alan Mishchenko committed
311 312 313
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_BAF, fCheck );
Alan Mishchenko committed
314 315 316 317
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
318
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
319 320 321
    return 0;

usage:
Alan Mishchenko committed
322
    fprintf( pAbc->Err, "usage: read_baf [-ch] <file>\n" );
323
    fprintf( pAbc->Err, "\t         reads the network in Binary Aig Format (BAF)\n" );
Alan Mishchenko committed
324 325 326 327 328
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}
Alan Mishchenko committed
329

Alan Mishchenko committed
330 331 332 333 334 335 336 337 338 339 340
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
int IoCommandReadBblif( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fCheck;
    int c;

    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_BBLIF, fCheck );
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
373
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
374 375 376 377
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_bblif [-ch] <file>\n" );
378
    fprintf( pAbc->Err, "\t         reads the network in a binary BLIF format\n" );
Alan Mishchenko committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
396
int IoCommandReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
397
{
Alan Mishchenko committed
398 399 400
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fReadAsAig;
Alan Mishchenko committed
401
    int fCheck;
402
    int fUseNewParser;
Alan Mishchenko committed
403
    int c;
Alan Mishchenko committed
404
    extern Abc_Ntk_t * Io_ReadBlifAsAig( char * pFileName, int fCheck );
Alan Mishchenko committed
405 406

    fCheck = 1;
Alan Mishchenko committed
407
    fReadAsAig = 0;
408
    fUseNewParser = 1;
Alan Mishchenko committed
409
    Extra_UtilGetoptReset();
410
    while ( ( c = Extra_UtilGetopt( argc, argv, "nach" ) ) != EOF )
Alan Mishchenko committed
411 412 413
    {
        switch ( c )
        {
414 415 416
            case 'n':
                fUseNewParser ^= 1;
                break;
Alan Mishchenko committed
417 418 419
            case 'a':
                fReadAsAig ^= 1;
                break;
Alan Mishchenko committed
420 421 422 423 424 425 426 427 428
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
429
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
430 431
        goto usage;
    // get the input file name
Alan Mishchenko committed
432 433 434 435
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    if ( fReadAsAig )
        pNtk = Io_ReadBlifAsAig( pFileName, fCheck );
436 437
    else if ( fUseNewParser )
        pNtk = Io_Read( pFileName, IO_FILE_BLIF, fCheck );
Alan Mishchenko committed
438
    else
Alan Mishchenko committed
439
    {
Alan Mishchenko committed
440 441 442 443 444 445
        Abc_Ntk_t * pTemp;
        pNtk = Io_ReadBlif( pFileName, fCheck );
        if ( pNtk == NULL )
            return 1;
        pNtk = Abc_NtkToLogic( pTemp = pNtk );
        Abc_NtkDelete( pTemp );
Alan Mishchenko committed
446 447
    }

Alan Mishchenko committed
448 449 450 451
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
452
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
453 454 455
    return 0;

usage:
456 457 458 459
    fprintf( pAbc->Err, "usage: read_blif [-nach] <file>\n" );
    fprintf( pAbc->Err, "\t         reads the network in binary BLIF format\n" );
    fprintf( pAbc->Err, "\t         (if this command does not work, try \"read\")\n" );
    fprintf( pAbc->Err, "\t-n     : toggle using old BLIF parser without hierarchy support [default = %s]\n", !fUseNewParser? "yes":"no" );
Alan Mishchenko committed
460
    fprintf( pAbc->Err, "\t-a     : toggle creating AIG while reading the file [default = %s]\n", fReadAsAig? "yes":"no" );
Alan Mishchenko committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
478
int IoCommandReadBlifMv( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
479
{
Alan Mishchenko committed
480 481
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
482 483 484 485
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
486 487
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
488 489 490 491 492 493 494 495 496 497 498 499
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
500
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
501 502
        goto usage;
    // get the input file name
Alan Mishchenko committed
503 504 505
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_BLIFMV, fCheck );
Alan Mishchenko committed
506 507 508 509
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
510
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
511 512 513
    return 0;

usage:
Alan Mishchenko committed
514
    fprintf( pAbc->Err, "usage: read_blif_mv [-ch] <file>\n" );
515 516
    fprintf( pAbc->Err, "\t         reads the network in BLIF-MV format\n" );
    fprintf( pAbc->Err, "\t         (if this command does not work, try \"read\")\n" );
Alan Mishchenko committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
534
int IoCommandReadBench( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
535
{
Alan Mishchenko committed
536 537
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
538 539 540 541
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
542 543
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
544 545 546 547 548 549 550 551 552 553 554 555
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
556
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
557 558
        goto usage;
    // get the input file name
Alan Mishchenko committed
559 560 561
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_BENCH, fCheck );
Alan Mishchenko committed
562 563 564 565
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
566
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
567 568 569
    return 0;

usage:
Alan Mishchenko committed
570
    fprintf( pAbc->Err, "usage: read_bench [-ch] <file>\n" );
571
    fprintf( pAbc->Err, "\t         reads the network in BENCH format\n" );
Alan Mishchenko committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
589
int IoCommandReadDsd( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
590
{
Alan Mishchenko committed
591 592
    Abc_Ntk_t * pNtk;
    char * pString;
Alan Mishchenko committed
593 594
    int fCheck;
    int c;
Alan Mishchenko committed
595
    extern Abc_Ntk_t * Io_ReadDsd( char * pFormula );
Alan Mishchenko committed
596 597

    fCheck = 1;
Alan Mishchenko committed
598 599
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
600 601 602 603 604 605 606 607 608 609 610 611
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
612
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
613 614
        goto usage;
    // get the input file name
Alan Mishchenko committed
615 616 617
    pString = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_ReadDsd( pString );
Alan Mishchenko committed
618 619 620 621
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
622
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
623 624 625
    return 0;

usage:
Alan Mishchenko committed
626 627 628 629 630 631 632 633 634 635 636
    fprintf( pAbc->Err, "usage: read_dsd [-h] <formula>\n" );
    fprintf( pAbc->Err, "\t          parses a formula representing DSD of a function\n" );
    fprintf( pAbc->Err, "\t-h      : prints the command summary\n" );
    fprintf( pAbc->Err, "\tformula : the formula representing disjoint-support decomposition (DSD)\n" );
    fprintf( pAbc->Err, "\t          Example of a formula: !(a*(b+CA(!d,e*f,c))*79B3(g,h,i,k))\n" );
    fprintf( pAbc->Err, "\t          where \'!\' is an INV, \'*\' is an AND, \'+\' is an XOR, \n" );
    fprintf( pAbc->Err, "\t          CA and 79B3 are hexadecimal representations of truth tables\n" );
    fprintf( pAbc->Err, "\t          (in this case CA=11001010 is truth table of MUX(Data0,Data1,Ctrl))\n" );
    fprintf( pAbc->Err, "\t          The lower chars (a,b,c,etc) are reserved for elementary variables.\n" );
    fprintf( pAbc->Err, "\t          The upper chars (A,B,C,etc) are reserved for hexadecimal digits.\n" );
    fprintf( pAbc->Err, "\t          No spaces are allowed in formulas. In parantheses, LSB goes first.\n" );
Alan Mishchenko committed
637 638 639 640 641 642 643 644 645 646 647 648 649 650
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
651
int IoCommandReadEdif( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
652
{
Alan Mishchenko committed
653
    Abc_Ntk_t * pNtk;
Alan Mishchenko committed
654 655
    char * pFileName;
    int fCheck;
Alan Mishchenko committed
656 657
    int c;

Alan Mishchenko committed
658 659 660
    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
661 662 663
    {
        switch ( c )
        {
Alan Mishchenko committed
664 665
            case 'c':
                fCheck ^= 1;
Alan Mishchenko committed
666 667 668 669 670 671 672
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
673
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
674
        goto usage;
Alan Mishchenko committed
675 676 677 678 679 680 681 682
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_EDIF, fCheck );
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
683
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
684 685 686
    return 0;

usage:
Alan Mishchenko committed
687
    fprintf( pAbc->Err, "usage: read_edif [-ch] <file>\n" );
688
    fprintf( pAbc->Err, "\t         reads the network in EDIF (works only for ISCAS benchmarks)\n" );
Alan Mishchenko committed
689 690 691
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
Alan Mishchenko committed
692 693 694 695 696 697 698 699 700 701 702 703 704 705
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
706
int IoCommandReadEqn( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
707
{
Alan Mishchenko committed
708 709 710
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fCheck;
Alan Mishchenko committed
711 712
    int c;

Alan Mishchenko committed
713 714 715
    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
716 717 718
    {
        switch ( c )
        {
Alan Mishchenko committed
719 720
            case 'c':
                fCheck ^= 1;
Alan Mishchenko committed
721 722 723 724 725 726 727
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
728
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
729 730
        goto usage;
    // get the input file name
Alan Mishchenko committed
731 732 733 734 735 736 737
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_EQN, fCheck );
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
738
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
739 740 741
    return 0;

usage:
Alan Mishchenko committed
742
    fprintf( pAbc->Err, "usage: read_eqn [-ch] <file>\n" );
743
    fprintf( pAbc->Err, "\t         reads the network in equation format\n" );
Alan Mishchenko committed
744 745 746
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
Alan Mishchenko committed
747 748 749 750 751 752 753 754 755 756 757 758 759 760
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
761
int IoCommandReadInit( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
762
{
Alan Mishchenko committed
763 764 765
    FILE * pOut, * pErr;
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
766
    int c;
Alan Mishchenko committed
767 768 769 770

    pNtk = Abc_FrameReadNtk(pAbc);
    pOut = Abc_FrameReadOut(pAbc);
    pErr = Abc_FrameReadErr(pAbc);
Alan Mishchenko committed
771

Alan Mishchenko committed
772 773
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
774 775 776 777 778 779 780 781 782
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
783
    if ( argc != globalUtilOptind && argc != globalUtilOptind + 1 )
Alan Mishchenko committed
784 785
        goto usage;

Alan Mishchenko committed
786
    if ( pNtk == NULL )
Alan Mishchenko committed
787
    {
Alan Mishchenko committed
788
        fprintf( pErr, "Empty network.\n" );
Alan Mishchenko committed
789 790
        return 1;
    }
Alan Mishchenko committed
791
    // get the input file name
Alan Mishchenko committed
792 793 794 795 796 797 798 799 800 801
    if ( argc == globalUtilOptind + 1 )
        pFileName = argv[globalUtilOptind];
    else if ( pNtk->pSpec )
        pFileName = Extra_FileNameGenericAppend( pNtk->pSpec, ".init" );
    else
    {
        printf( "File name should be given on the command line.\n" );
        return 1;
    }

Alan Mishchenko committed
802 803 804 805 806
    // read the file using the corresponding file reader
    pNtk = Abc_NtkDup( pNtk );
    Io_ReadBenchInit( pNtk, pFileName );
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
807
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
808 809 810
    return 0;

usage:
Alan Mishchenko committed
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
    fprintf( pAbc->Err, "usage: read_init [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         reads initial state of the network in BENCH format\n" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadPla( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fCheck;
Alan Mishchenko committed
834
    int fZeros;
Alan Mishchenko committed
835 836
    int c;

Alan Mishchenko committed
837
    fZeros = 0;
Alan Mishchenko committed
838 839
    fCheck = 1;
    Extra_UtilGetoptReset();
Alan Mishchenko committed
840
    while ( ( c = Extra_UtilGetopt( argc, argv, "zch" ) ) != EOF )
Alan Mishchenko committed
841 842 843
    {
        switch ( c )
        {
Alan Mishchenko committed
844 845 846
            case 'z':
                fZeros ^= 1;
                break;
Alan Mishchenko committed
847 848 849 850 851 852 853 854 855 856 857 858 859 860
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
Alan Mishchenko committed
861 862 863 864 865 866 867 868 869 870 871 872 873 874
    if ( fZeros )
    {
        Abc_Ntk_t * pTemp;
        pNtk = Io_ReadPla( pFileName, fZeros, fCheck );
        if ( pNtk == NULL )
        {
            printf( "Reading PLA file has failed.\n" );
            return 1;
        }
        pNtk = Abc_NtkToLogic( pTemp = pNtk );
        Abc_NtkDelete( pTemp );
    }
    else
        pNtk = Io_Read( pFileName, IO_FILE_PLA, fCheck );
Alan Mishchenko committed
875 876 877 878
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
879
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
880 881 882
    return 0;

usage:
Alan Mishchenko committed
883
    fprintf( pAbc->Err, "usage: read_pla [-zch] <file>\n" );
884
    fprintf( pAbc->Err, "\t         reads the network in PLA\n" );
Alan Mishchenko committed
885
    fprintf( pAbc->Err, "\t-z     : toggle reading on-set and off-set [default = %s]\n", fZeros? "off-set":"on-set" );
Alan Mishchenko committed
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk;
    char * pSopCover;
    int fHex;
    int c;

    fHex = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "xh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'x':
                fHex ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }

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

    // convert truth table to SOP
    if ( fHex )
        pSopCover = Abc_SopFromTruthHex(argv[globalUtilOptind]);
    else
        pSopCover = Abc_SopFromTruthBin(argv[globalUtilOptind]);
Alan Mishchenko committed
936
    if ( pSopCover == NULL || pSopCover[0] == 0 )
Alan Mishchenko committed
937
    {
938
        ABC_FREE( pSopCover );
Alan Mishchenko committed
939 940 941 942 943
        fprintf( pAbc->Err, "Reading truth table has failed.\n" );
        return 1;
    }

    pNtk = Abc_NtkCreateWithNode( pSopCover );
Alan Mishchenko committed
944
    ABC_FREE( pSopCover );
Alan Mishchenko committed
945 946 947 948 949 950 951
    if ( pNtk == NULL )
    {
        fprintf( pAbc->Err, "Deriving the network has failed.\n" );
        return 1;
    }
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
952
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 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
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_truth [-xh] <truth>\n" );
    fprintf( pAbc->Err, "\t         creates network with node having given truth table\n" );
    fprintf( pAbc->Err, "\t-x     : toggles between bin and hex representation [default = %s]\n", fHex? "hex":"bin" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\ttruth  : truth table with most signficant bit first (e.g. 1000 for AND(a,b))\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadVerilog( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fCheck;
    int c;

    fCheck = 1;
    glo_fMapped = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "mch" ) ) != EOF )
    {
        switch ( c )
        {
            case 'm':
                glo_fMapped ^= 1;
                break;
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_Read( pFileName, IO_FILE_VERILOG, fCheck );
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
1011
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
1012 1013 1014 1015
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_verilog [-mch] <file>\n" );
1016
    fprintf( pAbc->Err, "\t         reads the network in Verilog (IWLS 2002/2005 subset)\n" );
Alan Mishchenko committed
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
    fprintf( pAbc->Err, "\t-m     : toggle reading mapped Verilog [default = %s]\n", glo_fMapped? "yes":"no" );
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadVer( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk, * pNtkNew;
    Abc_Lib_t * pDesign;
    char * pFileName;
    FILE * pFile;
    int fCheck;
    int c;
    extern Abc_Ntk_t * Abc_LibDeriveAig( Abc_Ntk_t * pNtk, Abc_Lib_t * pLib );
    extern Abc_Lib_t * Ver_ParseFile( char * pFileName, Abc_Lib_t * pGateLib, int fCheck, int fUseMemMan );

    printf( "Stand-alone structural Verilog reader is available as command \"read_verilog\".\n" );
    return 0;

    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }

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

    // get the input file name
    pFileName = argv[globalUtilOptind];
    if ( (pFile = fopen( pFileName, "r" )) == NULL )
    {
        fprintf( pAbc->Err, "Cannot open input file \"%s\". ", pFileName );
Alan Mishchenko committed
1075
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".blif", ".bench", ".pla", ".baf", ".aig" )) )
Alan Mishchenko committed
1076 1077 1078 1079 1080 1081 1082
            fprintf( pAbc->Err, "Did you mean \"%s\"?", pFileName );
        fprintf( pAbc->Err, "\n" );
        return 1;
    }
    fclose( pFile );

    // set the new network
1083
    pDesign = Ver_ParseFile( pFileName, (Abc_Lib_t *)Abc_FrameReadLibVer(), fCheck, 1 );
Alan Mishchenko committed
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
    if ( pDesign == NULL )
    {
        fprintf( pAbc->Err, "Reading network from the verilog file has failed.\n" );
        return 1;
    }

    // derive root design
    pNtk = Abc_LibDeriveRoot( pDesign );
    Abc_LibFree( pDesign, NULL );
    if ( pNtk == NULL )
    {
        fprintf( pAbc->Err, "Deriving root module has failed.\n" );
        return 1;
    }

    // derive the AIG network from this design
1100
    pNtkNew = Abc_LibDeriveAig( pNtk, (Abc_Lib_t *)Abc_FrameReadLibVer() );
Alan Mishchenko committed
1101 1102 1103 1104 1105 1106 1107 1108
    Abc_NtkDelete( pNtk );
    if ( pNtkNew == NULL )
    {
        fprintf( pAbc->Err, "Converting root module to AIG has failed.\n" );
        return 1;
    }
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew );
1109
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
1110 1111 1112 1113
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_ver [-ch] <file>\n" );
1114
    fprintf( pAbc->Err, "\t         reads a network in structural verilog (using current library)\n" );
Alan Mishchenko committed
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadVerLib( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Lib_t * pLibrary;
    char * pFileName;
    FILE * pFile;
    int fCheck;
    int c;
    extern Abc_Lib_t * Ver_ParseFile( char * pFileName, Abc_Lib_t * pGateLib, int fCheck, int fUseMemMan );

    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }

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

    // get the input file name
    pFileName = argv[globalUtilOptind];
    if ( (pFile = fopen( pFileName, "r" )) == NULL )
    {
        fprintf( pAbc->Err, "Cannot open input file \"%s\". ", pFileName );
Alan Mishchenko committed
1167
        if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".blif", ".bench", ".pla", ".baf", ".aig" )) )
Alan Mishchenko committed
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
            fprintf( pAbc->Err, "Did you mean \"%s\"?", pFileName );
        fprintf( pAbc->Err, "\n" );
        return 1;
    }
    fclose( pFile );

    // set the new network
    pLibrary = Ver_ParseFile( pFileName, NULL, fCheck, 0 );
    if ( pLibrary == NULL )
    {
        fprintf( pAbc->Err, "Reading library from the verilog file has failed.\n" );
        return 1;
    }
    printf( "The library contains %d gates.\n", st_count(pLibrary->tModules) );
Alan Mishchenko committed
1182
    // free old library
Alan Mishchenko committed
1183
    if ( Abc_FrameReadLibVer() )
1184
        Abc_LibFree( (Abc_Lib_t *)Abc_FrameReadLibVer(), NULL );
Alan Mishchenko committed
1185 1186
    // read new library
    Abc_FrameSetLibVer( pLibrary );
1187
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
1188 1189 1190 1191
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_verlib [-ch] <file>\n" );
1192
    fprintf( pAbc->Err, "\t         reads a gate library in structural verilog\n" );
Alan Mishchenko committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
1211 1212 1213 1214 1215
int IoCommandReadStatus( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    char * pFileName;
    FILE * pFile;
    int c;
1216
    extern int Abc_NtkReadLogFile( char * pFileName, Abc_Cex_t ** ppCex, int * pnFrames );
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244

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

    // get the input file name
    pFileName = argv[globalUtilOptind];
    if ( (pFile = fopen( pFileName, "r" )) == NULL )
    {
        fprintf( pAbc->Err, "Cannot open input file \"%s\". \n", pFileName );
        return 1;
    }
    fclose( pFile );

    // set the new network
    Abc_FrameClearVerifStatus( pAbc );
1245
    pAbc->Status = Abc_NtkReadLogFile( pFileName, &pAbc->pCex, &pAbc->nFrames );
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_status [-ch] <file>\n" );
    fprintf( pAbc->Err, "\t         reads verification log file\n" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
    return 1;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1284 1285 1286 1287 1288
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
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 1328 1329 1330 1331 1332 1333 1334 1335 1336
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, Io_ReadFileType(pFileName) );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         writes the current network into <file> by calling\n" );
    fprintf( pAbc->Err, "\t         the writer that matches the extension of <file>\n" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteHie( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pBaseName, * pFileName;
    int c;

    glo_fMapped = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "mh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'm':
                glo_fMapped ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1337 1338 1339 1340 1341
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
    if ( argc != globalUtilOptind + 2 )
        goto usage;
    // get the output file name
    pBaseName = argv[globalUtilOptind];
    pFileName = argv[globalUtilOptind+1];
    // call the corresponding file writer
//    Io_Write( pAbc->pNtkCur, pFileName, Io_ReadFileType(pFileName) );
    Io_WriteHie( pAbc->pNtkCur, pBaseName, pFileName );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_hie [-h] <orig> <file>\n" );
    fprintf( pAbc->Err, "\t         writes the current network into <file> by calling\n" );
    fprintf( pAbc->Err, "\t         the hierarchical writer that matches the extension of <file>\n" );
    fprintf( pAbc->Err, "\t-m     : toggle reading mapped Verilog for <orig> [default = %s]\n", glo_fMapped? "yes":"no" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\torig   : the name of the original file with the hierarchical design\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteAiger( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int fWriteSymbols;
    int fCompact;
    int c;

    fCompact      = 1;
    fWriteSymbols = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "sch" ) ) != EOF )
    {
        switch ( c )
        {
            case 's':
                fWriteSymbols ^= 1;
                break;
            case 'c':
                fCompact ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1400 1401 1402 1403 1404
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    if ( !Abc_NtkIsStrash(pAbc->pNtkCur) )
    {
        fprintf( stdout, "Writing this format is only possible for structurally hashed AIGs.\n" );
        return 1;
    }
    Io_WriteAiger( pAbc->pNtkCur, pFileName, fWriteSymbols, fCompact );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_aiger [-sch] <file>\n" );
1420
    fprintf( pAbc->Err, "\t         writes the network in the AIGER format (http://fmv.jku.at/aiger)\n" );
Alan Mishchenko committed
1421 1422 1423 1424 1425 1426 1427 1428
    fprintf( pAbc->Err, "\t-s     : toggle saving I/O names [default = %s]\n", fWriteSymbols? "yes" : "no" );
    fprintf( pAbc->Err, "\t-c     : toggle writing more compactly [default = %s]\n", fCompact? "yes" : "no" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .aig)\n" );
    return 1;
}

/**Function*************************************************************
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteAigerCex( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pCex == NULL )
    {
        fprintf( pAbc->Out, "There is no current CEX.\n" );
        return 0;
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    Io_WriteAigerCex( pAbc->pCex, pAbc->pNtkCur, pAbc->pGia, pFileName );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_aiger_cex [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         writes the current CEX in the AIGER format (http://fmv.jku.at/aiger)\n" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

/**Function*************************************************************
Alan Mishchenko committed
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteBaf( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1501 1502 1503 1504 1505
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BAF );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_baf [-h] <file>\n" );
1516
    fprintf( pAbc->Err, "\t         writes the network into a BLIF file\n" );
Alan Mishchenko committed
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .baf)\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
int IoCommandWriteBblif( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BBLIF );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_bblif [-h] <file>\n" );
1564
    fprintf( pAbc->Err, "\t         writes the network into a binary BLIF file\n" );
Alan Mishchenko committed
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .bblif)\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1581 1582 1583
int IoCommandWriteBlif( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
Alan Mishchenko committed
1584
    int c, fSpecial = 0;
Alan Mishchenko committed
1585 1586

    Extra_UtilGetoptReset();
Alan Mishchenko committed
1587
    while ( ( c = Extra_UtilGetopt( argc, argv, "jh" ) ) != EOF )
Alan Mishchenko committed
1588 1589 1590
    {
        switch ( c )
        {
Alan Mishchenko committed
1591 1592 1593
            case 'j':
                fSpecial ^= 1;
                break;
Alan Mishchenko committed
1594 1595 1596 1597 1598 1599
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1600 1601 1602 1603 1604
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1605 1606 1607 1608 1609
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
1610 1611 1612
    if ( fSpecial )
        Io_WriteBlifSpecial( pAbc->pNtkCur, pFileName );
    else
Alan Mishchenko committed
1613
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BLIF );
Alan Mishchenko committed
1614 1615 1616
    return 0;

usage:
Alan Mishchenko committed
1617
    fprintf( pAbc->Err, "usage: write_blif [-jh] <file>\n" );
1618
    fprintf( pAbc->Err, "\t         writes the network into a BLIF file\n" );
Alan Mishchenko committed
1619
    fprintf( pAbc->Err, "\t-j     : enables special BLIF writing [default = %s]\n", fSpecial? "yes" : "no" );;
Alan Mishchenko committed
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .blif)\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteBlifMv( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1652 1653 1654 1655 1656
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BLIFMV );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_blif_mv [-h] <file>\n" );
1667
    fprintf( pAbc->Err, "\t         writes the network into a BLIF-MV file\n" );
Alan Mishchenko committed
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .mv)\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteBench( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int fUseLuts;
    int c;

    fUseLuts = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "lh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'l':
                fUseLuts ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1705 1706 1707 1708 1709
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1710 1711 1712 1713 1714 1715 1716
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    if ( !fUseLuts )
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BENCH );
Alan Mishchenko committed
1717
    else if ( pAbc->pNtkCur )
Alan Mishchenko committed
1718 1719 1720 1721 1722 1723 1724
    {
        Abc_Ntk_t * pNtkTemp;
        pNtkTemp = Abc_NtkToNetlist( pAbc->pNtkCur );
        Abc_NtkToAig( pNtkTemp );
        Io_WriteBenchLut( pNtkTemp, pFileName );
        Abc_NtkDelete( pNtkTemp );
    }
Alan Mishchenko committed
1725 1726
    else
        printf( "There is no current network.\n" );
Alan Mishchenko committed
1727 1728 1729 1730
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_bench [-lh] <file>\n" );
1731
    fprintf( pAbc->Err, "\t         writes the network in BENCH format\n" );
Alan Mishchenko committed
1732 1733 1734
    fprintf( pAbc->Err, "\t-l     : toggle using LUTs in the output [default = %s]\n", fUseLuts? "yes" : "no" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .bench)\n" );
Alan Mishchenko committed
1735 1736 1737 1738 1739 1740 1741 1742 1743
    return 1;
}

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

  Synopsis    []

  Description []
               
Alan Mishchenko committed
1744
  SideEffects []
Alan Mishchenko committed
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773

  SeeAlso     []

***********************************************************************/
int IoCommandWriteBook( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
        int c;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
        // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BOOK );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_book [-h] <file> [-options]\n" );
1774
    fprintf( pAbc->Err, "\t-h     : prints the help massage\n" );
Alan Mishchenko committed
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .aux, .nodes, .nets)\n" );
    fprintf( pAbc->Err, "\t\n" );
    fprintf( pAbc->Err, "\tThis command is developed by Myungchul Kim (University of Michigan).\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []
Alan Mishchenko committed
1788 1789 1790 1791

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1792
int IoCommandWriteCellNet( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
1793
{
Alan Mishchenko committed
1794 1795
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
1796
    int c;
Alan Mishchenko committed
1797
    extern void Io_WriteCellNet( Abc_Ntk_t * pNtk, char * pFileName );
Alan Mishchenko committed
1798

Alan Mishchenko committed
1799 1800
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
1801 1802 1803 1804 1805 1806 1807 1808 1809
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1810
    if ( pAbc->pNtkCur == NULL )
Alan Mishchenko committed
1811 1812 1813 1814
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1815 1816 1817
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    pNtk = pAbc->pNtkCur;
Alan Mishchenko committed
1818 1819 1820 1821
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    if ( !Abc_NtkIsLogic(pNtk) )
Alan Mishchenko committed
1822
    {
Alan Mishchenko committed
1823
        fprintf( pAbc->Out, "The network should be a logic network (if it an AIG, use command \"logic\")\n" );
Alan Mishchenko committed
1824 1825
        return 0;
    }
Alan Mishchenko committed
1826 1827 1828 1829 1830
    Io_WriteCellNet( pNtk, pFileName );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_cellnet [-h] <file>\n" );
1831
    fprintf( pAbc->Err, "\t         writes the network is the cellnet format\n" );
Alan Mishchenko committed
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []
Alan Mishchenko committed
1846

Alan Mishchenko committed
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
***********************************************************************/
int IoCommandWriteCnf( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
    int fAllPrimes;
    int fNewAlgo;
    extern Abc_Ntk_t * Abc_NtkDarToCnf( Abc_Ntk_t * pNtk, char * pFileName );

    fNewAlgo = 1;
    fAllPrimes = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "nph" ) ) != EOF )
Alan Mishchenko committed
1860
    {
Alan Mishchenko committed
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873
        switch ( c )
        {
            case 'n':
                fNewAlgo ^= 1;
                break;
            case 'p':
                fAllPrimes ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
1874
    }
Alan Mishchenko committed
1875 1876 1877 1878 1879
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // check if the feature will be used
    if ( Abc_NtkIsStrash(pAbc->pNtkCur) && fAllPrimes )
    {
        fAllPrimes = 0;
        printf( "Warning: Selected option to write all primes has no effect when deriving CNF from AIG.\n" );
    }
    // call the corresponding file writer
    if ( fNewAlgo )
        Abc_NtkDarToCnf( pAbc->pNtkCur, pFileName );
    else if ( fAllPrimes )
        Io_WriteCnf( pAbc->pNtkCur, pFileName, 1 );
    else
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_CNF );
    return 0;
Alan Mishchenko committed
1898

Alan Mishchenko committed
1899 1900
usage:
    fprintf( pAbc->Err, "usage: write_cnf [-nph] <file>\n" );
1901
    fprintf( pAbc->Err, "\t         writes the miter cone into a CNF file\n" );
Alan Mishchenko committed
1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
    fprintf( pAbc->Err, "\t-n     : toggle using new algorithm [default = %s]\n", fNewAlgo? "yes" : "no" );
    fprintf( pAbc->Err, "\t-p     : toggle using all primes to enhance implicativity [default = %s]\n", fAllPrimes? "yes" : "no" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteDot( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1936 1937 1938 1939 1940
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1941 1942 1943 1944 1945 1946
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_DOT );
Alan Mishchenko committed
1947 1948 1949 1950
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_dot [-h] <file>\n" );
1951
    fprintf( pAbc->Err, "\t         writes the current network into a DOT file\n" );
Alan Mishchenko committed
1952 1953 1954 1955 1956
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

1957 1958
ABC_NAMESPACE_IMPL_END

Alan Mishchenko committed
1959 1960
#include "fra.h"

1961 1962 1963
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1975
int IoCommandWriteCounter( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
1976
{
Alan Mishchenko committed
1977 1978
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
1979
    int c;
Alan Mishchenko committed
1980
    int fNames;
Alan Mishchenko committed
1981
    int forceSeq;
Alan Mishchenko committed
1982

Alan Mishchenko committed
1983
    fNames = 0;
Alan Mishchenko committed
1984
    forceSeq = 0;
Alan Mishchenko committed
1985
    Extra_UtilGetoptReset();
Alan Mishchenko committed
1986
    while ( ( c = Extra_UtilGetopt( argc, argv, "snh" ) ) != EOF )
Alan Mishchenko committed
1987 1988 1989
    {
        switch ( c )
        {
Alan Mishchenko committed
1990 1991 1992
            case 's':
                forceSeq ^= 1;
                break;
Alan Mishchenko committed
1993 1994 1995
            case 'n':
                fNames ^= 1;
                break;
Alan Mishchenko committed
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }

    pNtk = pAbc->pNtkCur;
    if ( pNtk == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }

Alan Mishchenko committed
2010
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
2011
    {
Alan Mishchenko committed
2012
        printf( "File name is missing on the command line.\n" );
Alan Mishchenko committed
2013 2014
        goto usage;
    }
Alan Mishchenko committed
2015 2016
    // get the input file name
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
2017

2018
    if ( pNtk->pModel == NULL && pAbc->pCex == NULL )
Alan Mishchenko committed
2019
    {
Alan Mishchenko committed
2020
        fprintf( pAbc->Out, "Counter-example is not available.\n" );
Alan Mishchenko committed
2021 2022 2023
        return 0;
    }

Alan Mishchenko committed
2024
    // write the counter-example into the file
2025
    if ( pAbc->pCex )
Alan Mishchenko committed
2026
    { 
2027
        Abc_Cex_t * pCex = pAbc->pCex;
Alan Mishchenko committed
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060
        Abc_Obj_t * pObj;
        FILE * pFile;
        int i, f;
        Abc_NtkForEachLatch( pNtk, pObj, i )
            if ( !Abc_LatchIsInit0(pObj) )
            {
                fprintf( stdout, "IoCommandWriteCounter(): The init-state should be all-0 for counter-example to work.\n" );
                fprintf( stdout, "Run commands \"undc\" and \"zero\" and then rerun the equivalence check.\n" );
                return 1;
            }

        pFile = fopen( pFileName, "w" );
        if ( pFile == NULL )
        {
            fprintf( stdout, "IoCommandWriteCounter(): Cannot open the output file \"%s\".\n", pFileName );
            return 1;
        }
        if ( fNames )
        {
            Abc_NtkForEachLatch( pNtk, pObj, i )
                fprintf( pFile, "%s@0=%c ", Abc_ObjName(Abc_ObjFanout0(pObj)), '0'+!Abc_LatchIsInit0(pObj) );
            for ( f = 0; f <= pCex->iFrame; f++ )
                Abc_NtkForEachPi( pNtk, pObj, i )
                    fprintf( pFile, "%s@%d=%c ", Abc_ObjName(pObj), f, '0'+Abc_InfoHasBit(pCex->pData, pCex->nRegs+pCex->nPis*f + i) );
        }
        else
        {
            Abc_NtkForEachLatch( pNtk, pObj, i )
                fprintf( pFile, "%c", '0'+!Abc_LatchIsInit0(pObj) );
            for ( i = pCex->nRegs; i < pCex->nBits; i++ )
                fprintf( pFile, "%c", '0'+Abc_InfoHasBit(pCex->pData, i) );
        }
        fprintf( pFile, "\n" );
Alan Mishchenko committed
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074
        fclose( pFile );
    }
    else
    {
        Abc_Obj_t * pObj;
        FILE * pFile = fopen( pFileName, "w" );
        int i;
        if ( pFile == NULL )
        {
            fprintf( stdout, "IoCommandWriteCounter(): Cannot open the output file \"%s\".\n", pFileName );
            return 1;
        }
        if ( fNames )
        {
2075
            const char *cycle_ctr = forceSeq?"@0":"";
Alan Mishchenko committed
2076
            Abc_NtkForEachPi( pNtk, pObj, i )
Alan Mishchenko committed
2077 2078
//                fprintf( pFile, "%s=%c\n", Abc_ObjName(pObj), '0'+(pNtk->pModel[i]==1) );
                fprintf( pFile, "%s%s=%c\n", Abc_ObjName(pObj), cycle_ctr, '0'+(pNtk->pModel[i]==1) );
Alan Mishchenko committed
2079 2080 2081 2082 2083 2084 2085
        }
        else
        {
            Abc_NtkForEachPi( pNtk, pObj, i )
                fprintf( pFile, "%c", '0'+(pNtk->pModel[i]==1) );
        }
        fprintf( pFile, "\n" );
Alan Mishchenko committed
2086 2087 2088 2089 2090 2091
        fclose( pFile );
    }

    return 0;

usage:
Alan Mishchenko committed
2092
    fprintf( pAbc->Err, "usage: write_counter [-snh] <file>\n" );
Alan Mishchenko committed
2093 2094
    fprintf( pAbc->Err, "\t         saves counter-example derived by \"sat\", \"iprove\", or \"dprove\"\n" );
    fprintf( pAbc->Err, "\t         the file contains values for each PI in the natural order\n" );
Alan Mishchenko committed
2095
    fprintf( pAbc->Err, "\t-s     : always report a sequential ctrex (cycle 0 for comb) [default = %s]\n", forceSeq? "yes": "no" );
Alan Mishchenko committed
2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
    fprintf( pAbc->Err, "\t-n     : write input names into the file [default = %s]\n", fNames? "yes": "no" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteEqn( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2129
    }
Alan Mishchenko committed
2130 2131 2132 2133 2134
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2135 2136 2137 2138 2139 2140
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_EQN );
Alan Mishchenko committed
2141
    return 0;
Alan Mishchenko committed
2142

Alan Mishchenko committed
2143 2144
usage:
    fprintf( pAbc->Err, "usage: write_eqn [-h] <file>\n" );
2145
    fprintf( pAbc->Err, "\t         writes the current network in the equation format\n" );
Alan Mishchenko committed
2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteGml( Abc_Frame_t * pAbc, int argc, char **argv )
{
Alan Mishchenko committed
2164
    char * pFileName;
Alan Mishchenko committed
2165
    int c;
Alan Mishchenko committed
2166

Alan Mishchenko committed
2167 2168
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
2169
    {
Alan Mishchenko committed
2170 2171 2172 2173 2174 2175 2176
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2177
    }
Alan Mishchenko committed
2178 2179 2180 2181 2182
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_GML );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_gml [-h] <file>\n" );
2193
    fprintf( pAbc->Err, "\t         writes network using graph representation formal GML\n" );
Alan Mishchenko committed
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteList( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int fUseHost;
    int c;

    printf( "This command currently does not work.\n" );
    return 0;
Alan Mishchenko committed
2218

Alan Mishchenko committed
2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233
    fUseHost = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "nh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'n':
                fUseHost ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
2234 2235 2236 2237 2238
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2239 2240
    if ( argc != globalUtilOptind + 1 )
        goto usage;
Alan Mishchenko committed
2241 2242
/*
    if ( !Abc_NtkIsSeq(pAbc->pNtkCur) )
Alan Mishchenko committed
2243
    {
Alan Mishchenko committed
2244
        fprintf( stdout, "IoCommandWriteList(): Can write adjacency list for sequential AIGs only.\n" );
Alan Mishchenko committed
2245 2246
        return 0;
    }
Alan Mishchenko committed
2247
*/
Alan Mishchenko committed
2248
    // get the input file name
Alan Mishchenko committed
2249
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
2250
    // write the file
Alan Mishchenko committed
2251
    Io_WriteList( pAbc->pNtkCur, pFileName, fUseHost );
Alan Mishchenko committed
2252 2253 2254
    return 0;

usage:
Alan Mishchenko committed
2255
    fprintf( pAbc->Err, "usage: write_list [-nh] <file>\n" );
2256
    fprintf( pAbc->Err, "\t         writes network using graph representation formal GML\n" );
Alan Mishchenko committed
2257
    fprintf( pAbc->Err, "\t-n     : toggle writing host node [default = %s]\n", fUseHost? "yes":"no" );
Alan Mishchenko committed
2258 2259
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
Alan Mishchenko committed
2260 2261 2262
    return 1;
}

Alan Mishchenko committed
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWritePla( Abc_Frame_t * pAbc, int argc, char **argv )
{
Alan Mishchenko committed
2276
    char * pFileName;
Alan Mishchenko committed
2277 2278
    int c;

Alan Mishchenko committed
2279 2280
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
2281 2282 2283 2284 2285 2286 2287 2288 2289
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
2290 2291 2292 2293 2294
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2295 2296 2297 2298 2299 2300 2301
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_PLA );
    return 0;
Alan Mishchenko committed
2302

Alan Mishchenko committed
2303 2304
usage:
    fprintf( pAbc->Err, "usage: write_pla [-h] <file>\n" );
2305
    fprintf( pAbc->Err, "\t         writes the collapsed network into a PLA file\n" );
Alan Mishchenko committed
2306 2307 2308 2309
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}
Alan Mishchenko committed
2310

Alan Mishchenko committed
2311 2312 2313 2314 2315 2316 2317
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []
Alan Mishchenko committed
2318

Alan Mishchenko committed
2319 2320 2321 2322 2323 2324 2325 2326 2327 2328
  SeeAlso     []

***********************************************************************/
int IoCommandWriteVerilog( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
2329
    {
Alan Mishchenko committed
2330 2331 2332 2333 2334 2335 2336
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2337
    }
Alan Mishchenko committed
2338 2339 2340 2341 2342
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2343 2344 2345 2346 2347 2348 2349
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_VERILOG );
    return 0;
Alan Mishchenko committed
2350

Alan Mishchenko committed
2351 2352
usage:
    fprintf( pAbc->Err, "usage: write_verilog [-h] <file>\n" );
2353
    fprintf( pAbc->Err, "\t         writes the current network in Verilog format\n" );
Alan Mishchenko committed
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteVerLib( Abc_Frame_t * pAbc, int argc, char **argv )
{
    Abc_Lib_t * pLibrary;
    char * pFileName;
    int c;
    extern void Io_WriteVerilogLibrary( Abc_Lib_t * pLibrary, char * pFileName );

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
2379
    {
Alan Mishchenko committed
2380 2381 2382 2383 2384 2385 2386
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2387
    }
Alan Mishchenko committed
2388 2389
    if ( argc != globalUtilOptind + 1 )
        goto usage;
Alan Mishchenko committed
2390
    // get the input file name
Alan Mishchenko committed
2391
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
2392
    // derive the netlist
2393
    pLibrary = (Abc_Lib_t *)Abc_FrameReadLibVer();
Alan Mishchenko committed
2394
    if ( pLibrary == NULL )
Alan Mishchenko committed
2395
    {
Alan Mishchenko committed
2396
        fprintf( pAbc->Out, "Verilog library is not specified.\n" );
Alan Mishchenko committed
2397 2398
        return 0;
    }
Alan Mishchenko committed
2399
//    Io_WriteVerilogLibrary( pLibrary, pFileName );
Alan Mishchenko committed
2400 2401 2402
    return 0;

usage:
Alan Mishchenko committed
2403
    fprintf( pAbc->Err, "usage: write_verlib [-h] <file>\n" );
2404
    fprintf( pAbc->Err, "\t         writes the current verilog library\n" );
Alan Mishchenko committed
2405 2406 2407 2408 2409
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

Alan Mishchenko committed
2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteSortCnf( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
    int nVars = 16;
    int nQueens = 4;
    extern void Abc_NtkWriteSorterCnf( char * pFileName, int nVars, int nQueens );

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "NQh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'N':
                if ( globalUtilOptind >= argc )
                {
                    fprintf( stdout, "Command line switch \"-N\" should be followed by an integer.\n" );
                    goto usage;
                }
                nVars = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( nVars <= 0 ) 
                    goto usage;
                break;
            case 'Q':
                if ( globalUtilOptind >= argc )
                {
                    fprintf( stdout, "Command line switch \"-Q\" should be followed by an integer.\n" );
                    goto usage;
                }
                nQueens = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                if ( nQueens <= 0 ) 
                    goto usage;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    Abc_NtkWriteSorterCnf( pFileName, nVars, nQueens );
    // call the corresponding file writer
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_sorter_cnf [-N <num>] [-Q <num>] <file>\n" );
2472
    fprintf( pAbc->Err, "\t         writes CNF for the sorter\n" );
Alan Mishchenko committed
2473 2474 2475 2476 2477 2478 2479
    fprintf( pAbc->Err, "\t-N num : the number of sorter bits [default = %d]\n", nVars );
    fprintf( pAbc->Err, "\t-Q num : the number of bits to be asserted to 1 [default = %d]\n", nQueens );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

Alan Mishchenko committed
2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteTruth( Abc_Frame_t * pAbc, int argc, char **argv )
{
    Vec_Int_t * vTruth;
    Abc_Ntk_t * pNtk = pAbc->pNtkCur;
    Abc_Obj_t * pNode;
    char * pFileName;
    FILE * pFile;
    unsigned * pTruth;
Alan Mishchenko committed
2499
    int fReverse = 0;
Alan Mishchenko committed
2500 2501 2502
    int c;

    Extra_UtilGetoptReset();
Alan Mishchenko committed
2503
    while ( ( c = Extra_UtilGetopt( argc, argv, "rh" ) ) != EOF )
Alan Mishchenko committed
2504 2505 2506
    {
        switch ( c )
        {
Alan Mishchenko committed
2507 2508 2509
            case 'r':
                fReverse ^= 1;
                break;
Alan Mishchenko committed
2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pNtkCur == NULL )
    {
        printf( "Current networks is not available.\n" );
        return 0;
    }
    if ( !Abc_NtkIsLogic(pNtk) )
    {
        printf( "Current networks should not an AIG. Run \"logic\".\n" );
        return 0;
    }
    if ( Abc_NtkPoNum(pNtk) != 1 )
    {
        printf( "Current networks should have exactly one primary output.\n" );
        return 0;
    }
    if ( Abc_NtkNodeNum(pNtk) != 1 )
    {
        printf( "Current networks should have exactly one node.\n" );
        return 0;
    }
    pNode = Abc_ObjFanin0( Abc_NtkPo(pNtk, 0) );
    if ( Abc_ObjFaninNum(pNode) == 0 )
    { 
        printf( "Can only write logic function with 0 inputs.\n" );
        return 0;
    }
    if ( Abc_ObjFaninNum(pNode) > 16 )
    { 
        printf( "Can only write logic function with no more than 16 inputs.\n" );
        return 0;
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // convert to logic
    Abc_NtkToAig( pNtk );
    vTruth = Vec_IntAlloc( 0 );
2554
    pTruth = Hop_ManConvertAigToTruth( (Hop_Man_t *)pNtk->pManFunc, (Hop_Obj_t *)pNode->pData, Abc_ObjFaninNum(pNode), vTruth, fReverse );
Alan Mishchenko committed
2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567
    pFile = fopen( pFileName, "w" );
    if ( pFile == NULL )
    {
        Vec_IntFree( vTruth );
        printf( "Cannot open file \"%s\" for writing.\n", pFileName );
        return 0;
    }
    Extra_PrintBinary( pFile, pTruth, 1<<Abc_ObjFaninNum(pNode) );
    fclose( pFile );
    Vec_IntFree( vTruth );
    return 0;

usage:
Alan Mishchenko committed
2568
    fprintf( pAbc->Err, "usage: write_truth [-rh] <file>\n" );
Alan Mishchenko committed
2569
    fprintf( pAbc->Err, "\t         writes truth table into a file\n" );
Alan Mishchenko committed
2570
    fprintf( pAbc->Err, "\t-r     : toggle reversing bits in the truth table [default = %s]\n", fReverse? "yes":"no" );
Alan Mishchenko committed
2571 2572 2573 2574 2575
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteStatus( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
2591
    extern void Abc_NtkWriteLogFile( char * pFileName, Abc_Cex_t * pCex, int Status, int nFrames, char * pCommand );
2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
2608
    Abc_NtkWriteLogFile( pFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, NULL );
2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_status [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         writes verification log file\n" );
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteSmv( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int fUseLuts;
    int c;

    fUseLuts = 0;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_SMV );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_smv [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         write the network in SMV format\n" );
    fprintf( pAbc->Err, "\t-h     : print the help message\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .smv)\n" );
    return 1;
}
Alan Mishchenko committed
2668 2669 2670 2671 2672
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


2673 2674
ABC_NAMESPACE_IMPL_END