io.c 90 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"
22 23
#include "base/main/mainInt.h"
#include "aig/saig/saig.h"
24
#include "proof/abs/abs.h"
25
#include "sat/bmc/bmc.h"
Alan Mishchenko committed
26

27 28
ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
29 30 31 32 33
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

static int IoCommandRead        ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
34 35
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
36
static int IoCommandReadBblif   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
37
static int IoCommandReadBlif    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
38
static int IoCommandReadBlifMv  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
39
static int IoCommandReadBench   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
40
static int IoCommandReadDsd     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
41
static int IoCommandReadEdif    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
42
static int IoCommandReadEqn     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
43
static int IoCommandReadInit    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
44
static int IoCommandReadPla     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
45 46
static int IoCommandReadTruth   ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadVerilog ( Abc_Frame_t * pAbc, int argc, char **argv );
47
static int IoCommandReadStatus  ( Abc_Frame_t * pAbc, int argc, char **argv );
48
static int IoCommandReadGig     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
49

Alan Mishchenko committed
50 51 52
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 );
53
static int IoCommandWriteAigerCex( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
54
static int IoCommandWriteBaf    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
55
static int IoCommandWriteBblif  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
56
static int IoCommandWriteBlif   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
57
static int IoCommandWriteBlifMv ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
58
static int IoCommandWriteBench  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
59
static int IoCommandWriteBook   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
60
static int IoCommandWriteCellNet( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
61
static int IoCommandWriteCnf    ( Abc_Frame_t * pAbc, int argc, char **argv );
62
static int IoCommandWriteCnf2   ( Abc_Frame_t * pAbc, int argc, char **argv );
63
static int IoCommandWriteCex    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
64 65 66
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
67
static int IoCommandWriteList   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
68
static int IoCommandWritePla    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
69
static int IoCommandWriteVerilog( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
70
static int IoCommandWriteSortCnf( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
71
static int IoCommandWriteTruth  ( Abc_Frame_t * pAbc, int argc, char **argv );
72
static int IoCommandWriteTruths ( Abc_Frame_t * pAbc, int argc, char **argv );
73 74 75 76
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
77 78

extern int glo_fMapped;
Alan Mishchenko committed
79

Alan Mishchenko committed
80
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
81
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

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

Alan Mishchenko committed
114 115 116
    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 );
117
    Cmd_CommandAdd( pAbc, "I/O", "write_aiger_cex",   IoCommandWriteAigerCex,   0 );
Alan Mishchenko committed
118
    Cmd_CommandAdd( pAbc, "I/O", "write_baf",     IoCommandWriteBaf,     0 );
Alan Mishchenko committed
119
    Cmd_CommandAdd( pAbc, "I/O", "write_bblif",   IoCommandWriteBblif,   0 );
Alan Mishchenko committed
120
    Cmd_CommandAdd( pAbc, "I/O", "write_blif",    IoCommandWriteBlif,    0 );
Alan Mishchenko committed
121
    Cmd_CommandAdd( pAbc, "I/O", "write_blif_mv", IoCommandWriteBlifMv,  0 );
Alan Mishchenko committed
122
    Cmd_CommandAdd( pAbc, "I/O", "write_bench",   IoCommandWriteBench,   0 );
Alan Mishchenko committed
123
    Cmd_CommandAdd( pAbc, "I/O", "write_book",    IoCommandWriteBook,    0 );
Alan Mishchenko committed
124
    Cmd_CommandAdd( pAbc, "I/O", "write_cellnet", IoCommandWriteCellNet, 0 );
125
    Cmd_CommandAdd( pAbc, "I/O", "write_cex",     IoCommandWriteCex,     0 );
Alan Mishchenko committed
126
    Cmd_CommandAdd( pAbc, "I/O", "write_cnf",     IoCommandWriteCnf,     0 );
127
    Cmd_CommandAdd( pAbc, "I/O", "&write_cnf",    IoCommandWriteCnf2,    0 );
Alan Mishchenko committed
128 129 130
    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
131
//    Cmd_CommandAdd( pAbc, "I/O", "write_list",    IoCommandWriteList,    0 );
Alan Mishchenko committed
132
    Cmd_CommandAdd( pAbc, "I/O", "write_pla",     IoCommandWritePla,     0 );
Alan Mishchenko committed
133 134
    Cmd_CommandAdd( pAbc, "I/O", "write_verilog", IoCommandWriteVerilog, 0 );
//    Cmd_CommandAdd( pAbc, "I/O", "write_verlib",  IoCommandWriteVerLib,  0 );
Alan Mishchenko committed
135
    Cmd_CommandAdd( pAbc, "I/O", "write_sorter_cnf", IoCommandWriteSortCnf,  0 );
Alan Mishchenko committed
136
    Cmd_CommandAdd( pAbc, "I/O", "write_truth",   IoCommandWriteTruth,   0 );
137
    Cmd_CommandAdd( pAbc, "I/O", "&write_truths", IoCommandWriteTruths,  0 );
138 139
    Cmd_CommandAdd( pAbc, "I/O", "write_status",  IoCommandWriteStatus,  0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_smv",     IoCommandWriteSmv,     0 );
Alan Mishchenko committed
140 141 142 143 144 145 146 147 148 149 150 151 152
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
153
void Io_End( Abc_Frame_t * pAbc )
Alan Mishchenko committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
{
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandRead( Abc_Frame_t * pAbc, int argc, char ** argv )
{
170
    char Command[1000];
Alan Mishchenko committed
171
    Abc_Ntk_t * pNtk;
Alan Mishchenko committed
172
    char * pFileName, * pTemp;
173
    int c, fCheck, fBarBufs, fReadGia;
Alan Mishchenko committed
174 175

    fCheck = 1;
176
    fBarBufs = 0;
177
    fReadGia = 0;
Alan Mishchenko committed
178 179
    glo_fMapped = 0;
    Extra_UtilGetoptReset();
180
    while ( ( c = Extra_UtilGetopt( argc, argv, "mcbgh" ) ) != EOF )
Alan Mishchenko committed
181 182 183
    {
        switch ( c )
        {
Alan Mishchenko committed
184 185 186
            case 'm':
                glo_fMapped ^= 1;
                break;
Alan Mishchenko committed
187 188 189
            case 'c':
                fCheck ^= 1;
                break;
190 191 192
            case 'b':
                fBarBufs ^= 1;
                break;
193 194 195
            case 'g':
                fReadGia ^= 1;
                break;
Alan Mishchenko committed
196 197 198 199 200 201
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
202
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
203 204
        goto usage;
    // get the input file name
Alan Mishchenko committed
205
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
206 207
    // fix the wrong symbol
    for ( pTemp = pFileName; *pTemp; pTemp++ )
208 209
        if ( *pTemp == '>' || *pTemp == '\\' )
            *pTemp = '/';
210 211 212 213
    // read libraries
    Command[0] = 0;
    assert( strlen(pFileName) < 900 );
    if ( !strcmp( Extra_FileNameExtension(pFileName), "genlib" )  )
214
        sprintf( Command, "read_genlib %s", pFileName );
215
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "lib" ) )
216
        sprintf( Command, "read_lib %s", pFileName );
217 218
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "scl" ) )
        sprintf( Command, "read_scl %s", pFileName );
219 220
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "super" ) )
        sprintf( Command, "read_super %s", pFileName );
221 222
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "constr" ) )
        sprintf( Command, "read_constr %s", pFileName );
223 224
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "c" ) )
        sprintf( Command, "so %s", pFileName );
225 226
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "dsd" ) )
        sprintf( Command, "dsd_load %s", pFileName );
227 228 229 230 231
    if ( Command[0] )
    {
        Cmd_CommandExecute( pAbc, Command );
        return 0;
    }
232 233 234
    if ( fReadGia )
    {
        Abc_Ntk_t * pNtk = Io_ReadNetlist( pFileName, Io_ReadFileType(pFileName), fCheck );
235
        if ( pNtk )
236
        {
237
            Gia_Man_t * pGia = Abc_NtkFlattenHierarchyGia( pNtk, NULL, 0 );
238 239 240 241 242 243 244
            Abc_NtkDelete( pNtk );
            if ( pGia == NULL )
            {
                Abc_Print( 1, "Abc_CommandBlast(): Bit-blasting has failed.\n" );
                return 0;
            }
            Abc_FrameUpdateGia( pAbc, pGia );
245 246 247
        }
        return 0;
    }
248 249 250 251 252 253
    // check if the library is available
    if ( glo_fMapped && Abc_FrameReadLibGen() == NULL )
    {
        Abc_Print( 1, "Cannot read mapped design when the library is not given.\n" );
        return 0;
    }
Alan Mishchenko committed
254
    // read the file using the corresponding file reader
255
    pNtk = Io_Read( pFileName, Io_ReadFileType(pFileName), fCheck, fBarBufs );
Alan Mishchenko committed
256
    if ( pNtk == NULL )
257
        return 0;
258 259 260 261 262
    if ( Abc_NtkPiNum(pNtk) == 0 )
    {
        Abc_Print( 0, "The new network has no primary inputs. It is recommended\n" );
        Abc_Print( 1, "to add a dummy PI to make sure all commands work correctly.\n" );
    }
Alan Mishchenko committed
263 264
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
265 266
    Abc_FrameCopyLTLDataBase( pAbc, pNtk );
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
267 268 269
    return 0;

usage:
270
    fprintf( pAbc->Err, "usage: read [-mcbgh] <file>\n" );
Alan Mishchenko committed
271 272 273 274
    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
275
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
276
    fprintf( pAbc->Err, "\t-b     : toggle reading barrier buffers [default = %s]\n", fBarBufs? "yes":"no" );
277
    fprintf( pAbc->Err, "\t-g     : toggle reading and flattening into &-space [default = %s]\n", fBarBufs? "yes":"no" );
Alan Mishchenko committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
    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
294
int IoCommandReadAiger( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
295
{
Alan Mishchenko committed
296 297
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
298 299 300 301
    int fCheck;
    int c;

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

usage:
Alan Mishchenko committed
330
    fprintf( pAbc->Err, "usage: read_aiger [-ch] <file>\n" );
331
    fprintf( pAbc->Err, "\t         reads the network in the AIGER format (http://fmv.jku.at/aiger)\n" );
Alan Mishchenko committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
    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
349
int IoCommandReadBaf( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
350
{
Alan Mishchenko committed
351 352
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
353 354 355 356
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
357 358
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
359 360 361 362 363 364 365 366 367 368 369 370
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
371
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
372 373
        goto usage;
    // get the input file name
Alan Mishchenko committed
374 375
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
376
    pNtk = Io_Read( pFileName, IO_FILE_BAF, fCheck, 0 );
Alan Mishchenko committed
377 378 379 380
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
381
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
382 383 384
    return 0;

usage:
Alan Mishchenko committed
385
    fprintf( pAbc->Err, "usage: read_baf [-ch] <file>\n" );
386
    fprintf( pAbc->Err, "\t         reads the network in Binary Aig Format (BAF)\n" );
Alan Mishchenko committed
387 388 389 390 391
    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
392

Alan Mishchenko committed
393 394 395 396 397 398 399 400 401 402 403
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
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
431
    pNtk = Io_Read( pFileName, IO_FILE_BBLIF, fCheck, 0 );
Alan Mishchenko committed
432 433 434 435
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
436
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
437 438 439 440
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_bblif [-ch] <file>\n" );
441
    fprintf( pAbc->Err, "\t         reads the network in a binary BLIF format\n" );
Alan Mishchenko committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
    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
459
int IoCommandReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
460
{
Alan Mishchenko committed
461 462 463
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fReadAsAig;
Alan Mishchenko committed
464
    int fCheck;
465
    int fUseNewParser;
466
    int fSaveNames;
Alan Mishchenko committed
467
    int c;
Alan Mishchenko committed
468
    extern Abc_Ntk_t * Io_ReadBlifAsAig( char * pFileName, int fCheck );
Alan Mishchenko committed
469 470

    fCheck = 1;
Alan Mishchenko committed
471
    fReadAsAig = 0;
472
    fUseNewParser = 1;
473
    fSaveNames = 0;
Alan Mishchenko committed
474
    Extra_UtilGetoptReset();
475
    while ( ( c = Extra_UtilGetopt( argc, argv, "nmach" ) ) != EOF )
Alan Mishchenko committed
476 477 478
    {
        switch ( c )
        {
479 480 481
            case 'n':
                fUseNewParser ^= 1;
                break;
482 483 484
            case 'm':
                fSaveNames ^= 1;
                break;
Alan Mishchenko committed
485 486 487
            case 'a':
                fReadAsAig ^= 1;
                break;
Alan Mishchenko committed
488 489 490 491 492 493 494 495 496
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
497
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
498 499
        goto usage;
    // get the input file name
Alan Mishchenko committed
500 501 502 503
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    if ( fReadAsAig )
        pNtk = Io_ReadBlifAsAig( pFileName, fCheck );
504
    else if ( fUseNewParser )
505
        pNtk = Io_Read( pFileName, IO_FILE_BLIF, fCheck, 0 );
Alan Mishchenko committed
506
    else
Alan Mishchenko committed
507
    {
Alan Mishchenko committed
508 509 510 511
        Abc_Ntk_t * pTemp;
        pNtk = Io_ReadBlif( pFileName, fCheck );
        if ( pNtk == NULL )
            return 1;
512 513
        if ( fSaveNames )
            Abc_NtkStartNameIds( pNtk );
Alan Mishchenko committed
514
        pNtk = Abc_NtkToLogic( pTemp = pNtk );
515 516
        if ( fSaveNames )
            Abc_NtkTransferNameIds( pTemp, pNtk );
Alan Mishchenko committed
517
        Abc_NtkDelete( pTemp );
Alan Mishchenko committed
518 519
    }

Alan Mishchenko committed
520 521 522 523
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
524
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
525 526 527
    return 0;

usage:
528
    fprintf( pAbc->Err, "usage: read_blif [-nmach] <file>\n" );
529 530 531
    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" );
532
    fprintf( pAbc->Err, "\t-m     : toggle saving original circuit names into a file [default = %s]\n", fSaveNames? "yes":"no" );
Alan Mishchenko committed
533
    fprintf( pAbc->Err, "\t-a     : toggle creating AIG while reading the file [default = %s]\n", fReadAsAig? "yes":"no" );
Alan Mishchenko committed
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
    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
551
int IoCommandReadBlifMv( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
552
{
Alan Mishchenko committed
553 554
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
555 556 557 558
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
559 560
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
561 562 563 564 565 566 567 568 569 570 571 572
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
573
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
574 575
        goto usage;
    // get the input file name
Alan Mishchenko committed
576 577
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
578
    pNtk = Io_Read( pFileName, IO_FILE_BLIFMV, fCheck, 0 );
Alan Mishchenko committed
579 580 581 582
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
583
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
584 585 586
    return 0;

usage:
Alan Mishchenko committed
587
    fprintf( pAbc->Err, "usage: read_blif_mv [-ch] <file>\n" );
588 589
    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
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
    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
607
int IoCommandReadBench( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
608
{
Alan Mishchenko committed
609 610
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
611 612 613 614
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
615 616
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
617 618 619 620 621 622 623 624 625 626 627 628
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
629
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
630 631
        goto usage;
    // get the input file name
Alan Mishchenko committed
632 633
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
634
    pNtk = Io_Read( pFileName, IO_FILE_BENCH, fCheck, 0 );
Alan Mishchenko committed
635 636 637 638
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
639
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
640 641 642
    return 0;

usage:
Alan Mishchenko committed
643
    fprintf( pAbc->Err, "usage: read_bench [-ch] <file>\n" );
644
    fprintf( pAbc->Err, "\t         reads the network in BENCH format\n" );
Alan Mishchenko committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
    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
662
int IoCommandReadDsd( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
663
{
Alan Mishchenko committed
664 665
    Abc_Ntk_t * pNtk;
    char * pString;
Alan Mishchenko committed
666 667
    int fCheck;
    int c;
Alan Mishchenko committed
668
    extern Abc_Ntk_t * Io_ReadDsd( char * pFormula );
Alan Mishchenko committed
669 670

    fCheck = 1;
Alan Mishchenko committed
671 672
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
673 674 675 676 677 678 679 680 681 682 683 684
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
685
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
686 687
        goto usage;
    // get the input file name
Alan Mishchenko committed
688 689 690
    pString = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_ReadDsd( pString );
Alan Mishchenko committed
691 692 693 694
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
695
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
696 697 698
    return 0;

usage:
Alan Mishchenko committed
699 700 701 702 703 704 705 706 707 708
    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" );
709
    fprintf( pAbc->Err, "\t          No spaces are allowed in formulas. In parentheses, LSB goes first.\n" );
Alan Mishchenko committed
710 711 712 713 714 715 716 717 718 719 720 721 722 723
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
724
int IoCommandReadEdif( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
725
{
Alan Mishchenko committed
726
    Abc_Ntk_t * pNtk;
Alan Mishchenko committed
727 728
    char * pFileName;
    int fCheck;
Alan Mishchenko committed
729 730
    int c;

Alan Mishchenko committed
731 732 733
    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
734 735 736
    {
        switch ( c )
        {
Alan Mishchenko committed
737 738
            case 'c':
                fCheck ^= 1;
Alan Mishchenko committed
739 740 741 742 743 744 745
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
746
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
747
        goto usage;
Alan Mishchenko committed
748 749 750
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
751
    pNtk = Io_Read( pFileName, IO_FILE_EDIF, fCheck, 0 );
Alan Mishchenko committed
752 753 754 755
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
756
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
757 758 759
    return 0;

usage:
Alan Mishchenko committed
760
    fprintf( pAbc->Err, "usage: read_edif [-ch] <file>\n" );
761
    fprintf( pAbc->Err, "\t         reads the network in EDIF (works only for ISCAS benchmarks)\n" );
Alan Mishchenko committed
762 763 764
    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
765 766 767 768 769 770 771 772 773 774 775 776 777 778
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
779
int IoCommandReadEqn( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
780
{
Alan Mishchenko committed
781 782 783
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fCheck;
Alan Mishchenko committed
784 785
    int c;

Alan Mishchenko committed
786 787 788
    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
789 790 791
    {
        switch ( c )
        {
Alan Mishchenko committed
792 793
            case 'c':
                fCheck ^= 1;
Alan Mishchenko committed
794 795 796 797 798 799 800
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
801
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
802 803
        goto usage;
    // get the input file name
Alan Mishchenko committed
804 805
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
806
    pNtk = Io_Read( pFileName, IO_FILE_EQN, fCheck, 0 );
Alan Mishchenko committed
807 808 809 810
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
811
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
812 813 814
    return 0;

usage:
Alan Mishchenko committed
815
    fprintf( pAbc->Err, "usage: read_eqn [-ch] <file>\n" );
816
    fprintf( pAbc->Err, "\t         reads the network in equation format\n" );
Alan Mishchenko committed
817 818 819
    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
820 821 822 823 824 825 826 827 828 829 830 831 832 833
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
834
int IoCommandReadInit( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
835
{
Alan Mishchenko committed
836 837 838
    FILE * pOut, * pErr;
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
839
    int c;
Alan Mishchenko committed
840 841 842 843

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

Alan Mishchenko committed
845 846
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
847 848 849 850 851 852 853 854 855
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
856
    if ( argc != globalUtilOptind && argc != globalUtilOptind + 1 )
Alan Mishchenko committed
857 858
        goto usage;

Alan Mishchenko committed
859
    if ( pNtk == NULL )
Alan Mishchenko committed
860
    {
Alan Mishchenko committed
861
        fprintf( pErr, "Empty network.\n" );
Alan Mishchenko committed
862 863
        return 1;
    }
Alan Mishchenko committed
864
    // get the input file name
Alan Mishchenko committed
865 866 867 868 869 870 871 872 873 874
    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
875 876 877 878 879
    // read the file using the corresponding file reader
    pNtk = Abc_NtkDup( pNtk );
    Io_ReadBenchInit( pNtk, pFileName );
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
880
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
881 882 883
    return 0;

usage:
Alan Mishchenko committed
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
    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;
906
    int c, fZeros = 0, fBoth = 0, fCheck = 1;
Alan Mishchenko committed
907 908

    Extra_UtilGetoptReset();
909
    while ( ( c = Extra_UtilGetopt( argc, argv, "zbch" ) ) != EOF )
Alan Mishchenko committed
910 911 912
    {
        switch ( c )
        {
Alan Mishchenko committed
913 914 915
            case 'z':
                fZeros ^= 1;
                break;
916 917 918
            case 'b':
                fBoth ^= 1;
                break;
Alan Mishchenko committed
919 920 921 922 923 924 925 926 927 928 929 930 931 932
            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
933
    if ( fZeros || fBoth )
Alan Mishchenko committed
934 935
    {
        Abc_Ntk_t * pTemp;
936
        pNtk = Io_ReadPla( pFileName, fZeros, fBoth, fCheck );
Alan Mishchenko committed
937 938 939 940 941 942 943 944 945
        if ( pNtk == NULL )
        {
            printf( "Reading PLA file has failed.\n" );
            return 1;
        }
        pNtk = Abc_NtkToLogic( pTemp = pNtk );
        Abc_NtkDelete( pTemp );
    }
    else
946
        pNtk = Io_Read( pFileName, IO_FILE_PLA, fCheck, 0 );
Alan Mishchenko committed
947 948 949 950
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
951
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
952 953 954
    return 0;

usage:
955
    fprintf( pAbc->Err, "usage: read_pla [-zbch] <file>\n" );
956
    fprintf( pAbc->Err, "\t         reads the network in PLA\n" );
Alan Mishchenko committed
957
    fprintf( pAbc->Err, "\t-z     : toggle reading on-set and off-set [default = %s]\n", fZeros? "off-set":"on-set" );
958
    fprintf( pAbc->Err, "\t-b     : toggle reading both on-set and off-set as on-set [default = %s]\n", fBoth? "off-set":"on-set" );
Alan Mishchenko committed
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
    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
1009
    if ( pSopCover == NULL || pSopCover[0] == 0 )
Alan Mishchenko committed
1010
    {
1011
        ABC_FREE( pSopCover );
Alan Mishchenko committed
1012 1013 1014 1015 1016
        fprintf( pAbc->Err, "Reading truth table has failed.\n" );
        return 1;
    }

    pNtk = Abc_NtkCreateWithNode( pSopCover );
Alan Mishchenko committed
1017
    ABC_FREE( pSopCover );
Alan Mishchenko committed
1018 1019 1020 1021 1022 1023 1024
    if ( pNtk == NULL )
    {
        fprintf( pAbc->Err, "Deriving the network has failed.\n" );
        return 1;
    }
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
1025
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
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
    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;
1052
    int fCheck, fBarBufs;
Alan Mishchenko committed
1053 1054 1055
    int c;

    fCheck = 1;
1056
    fBarBufs = 0;
Alan Mishchenko committed
1057 1058
    glo_fMapped = 0;
    Extra_UtilGetoptReset();
1059
    while ( ( c = Extra_UtilGetopt( argc, argv, "mcbh" ) ) != EOF )
Alan Mishchenko committed
1060 1061 1062 1063 1064 1065 1066 1067 1068
    {
        switch ( c )
        {
            case 'm':
                glo_fMapped ^= 1;
                break;
            case 'c':
                fCheck ^= 1;
                break;
1069 1070 1071
            case 'b':
                fBarBufs ^= 1;
                break;
Alan Mishchenko committed
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
            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
1083
    pNtk = Io_Read( pFileName, IO_FILE_VERILOG, fCheck, fBarBufs );
Alan Mishchenko committed
1084 1085 1086 1087
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
1088
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
1089 1090 1091
    return 0;

usage:
1092
    fprintf( pAbc->Err, "usage: read_verilog [-mcbh] <file>\n" );
1093
    fprintf( pAbc->Err, "\t         reads the network in Verilog (IWLS 2002/2005 subset)\n" );
Alan Mishchenko committed
1094 1095
    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" );
1096
    fprintf( pAbc->Err, "\t-b     : toggle reading barrier buffers [default = %s]\n", fBarBufs? "yes":"no" );
Alan Mishchenko committed
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
    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     []

***********************************************************************/
1113 1114 1115 1116 1117
int IoCommandReadStatus( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    char * pFileName;
    FILE * pFile;
    int c;
1118
    extern int Abc_NtkReadLogFile( char * pFileName, Abc_Cex_t ** ppCex, int * pnFrames );
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

    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 );
1147
    pAbc->Status = Abc_NtkReadLogFile( pFileName, &pAbc->pCex, &pAbc->nFrames );
1148 1149 1150 1151 1152 1153 1154
    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" );
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadGig( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern Gia_Man_t * Gia_ManReadGig( char * pFileName );
    Gia_Man_t * pAig;
    char * pFileName;
    FILE * pFile;
    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 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
    pAig = Gia_ManReadGig( pFileName );
    //Abc_FrameUpdateGia( pAbc, pAig );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: &read_gig [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         reads design in GIG format\n" );
    fprintf( pAbc->Err, "\t-h     : prints the command summary\n" );
    fprintf( pAbc->Err, "\tfile   : the name of a file to read\n" );
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
    return 1;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1227 1228
int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv )
{
1229
    char Command[1000];
Alan Mishchenko committed
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // write libraries
    Command[0] = 0;
    assert( strlen(pFileName) < 900 );
    if ( !strcmp( Extra_FileNameExtension(pFileName), "genlib" )  )
        sprintf( Command, "write_genlib %s", pFileName );
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "lib" ) )
        sprintf( Command, "write_liberty %s", pFileName );
1255 1256
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "dsd" ) )
        sprintf( Command, "dsd_save %s", pFileName );
1257 1258 1259 1260 1261
    if ( Command[0] )
    {
        Cmd_CommandExecute( pAbc, Command );
        return 0;
    }
Alan Mishchenko committed
1262 1263 1264 1265 1266
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
    // 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
1311 1312 1313 1314 1315
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
    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;
1353 1354
    int fUnique;
    int fVerbose;
Alan Mishchenko committed
1355 1356 1357
    int c;

    fWriteSymbols = 0;
1358
    fCompact      = 0;
1359 1360
    fUnique       = 0;
    fVerbose      = 0;
Alan Mishchenko committed
1361
    Extra_UtilGetoptReset();
1362
    while ( ( c = Extra_UtilGetopt( argc, argv, "scuvh" ) ) != EOF )
Alan Mishchenko committed
1363 1364 1365 1366 1367 1368 1369 1370 1371
    {
        switch ( c )
        {
            case 's':
                fWriteSymbols ^= 1;
                break;
            case 'c':
                fCompact ^= 1;
                break;
1372 1373 1374 1375 1376 1377
            case 'u':
                fUnique ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
Alan Mishchenko committed
1378 1379 1380 1381 1382 1383
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1384 1385 1386 1387 1388
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
    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;
    }
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
    if ( fUnique )
    {
        extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
        extern Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan );
        Aig_Man_t * pAig = Abc_NtkToDar( pAbc->pNtkCur, 0, 1 );
        Aig_Man_t * pCan = Saig_ManDupIsoCanonical( pAig, fVerbose );
        Abc_Ntk_t * pTemp = Abc_NtkFromAigPhase( pCan );
        Aig_ManStop( pCan );
        Aig_ManStop( pAig );
        Io_WriteAiger( pTemp, pFileName, fWriteSymbols, fCompact, fUnique );
        Abc_NtkDelete( pTemp );
    }
    else
        Io_WriteAiger( pAbc->pNtkCur, pFileName, fWriteSymbols, fCompact, fUnique );
Alan Mishchenko committed
1413 1414 1415
    return 0;

usage:
1416
    fprintf( pAbc->Err, "usage: write_aiger [-scuvh] <file>\n" );
1417
    fprintf( pAbc->Err, "\t         writes the network in the AIGER format (http://fmv.jku.at/aiger)\n" );
Alan Mishchenko committed
1418 1419
    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" );
1420 1421
    fprintf( pAbc->Err, "\t-u     : toggle writing canonical AIG structure [default = %s]\n", fUnique? "yes" : "no" );
    fprintf( pAbc->Err, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes" : "no" );
Alan Mishchenko committed
1422 1423 1424 1425 1426 1427
    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*************************************************************
1428 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

  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
1474 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

  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
1500 1501 1502 1503 1504
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
    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" );
1515
    fprintf( pAbc->Err, "\t         writes the network into a BLIF file\n" );
Alan Mishchenko committed
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
    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
1532 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
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" );
1563
    fprintf( pAbc->Err, "\t         writes the network into a binary BLIF file\n" );
Alan Mishchenko committed
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
    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
1580 1581 1582
int IoCommandWriteBlif( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
1583
    char * pLutStruct = NULL;
Alan Mishchenko committed
1584
    int c, fSpecial = 0;
1585
    int fUseHie = 0;
Alan Mishchenko committed
1586 1587

    Extra_UtilGetoptReset();
1588
    while ( ( c = Extra_UtilGetopt( argc, argv, "Sjah" ) ) != EOF )
Alan Mishchenko committed
1589 1590 1591
    {
        switch ( c )
        {
1592 1593 1594 1595 1596 1597 1598 1599
            case 'S':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-S\" should be followed by string.\n" );
                    goto usage;
                }
                pLutStruct = argv[globalUtilOptind];
                globalUtilOptind++;
1600
                if ( strlen(pLutStruct) != 2 && strlen(pLutStruct) != 3 ) 
1601 1602 1603 1604 1605
                {
                    Abc_Print( -1, "Command line switch \"-S\" should be followed by a 2- or 3-char string (e.g. \"44\" or \"555\").\n" );
                    goto usage;
                }
                break;
Alan Mishchenko committed
1606 1607 1608
            case 'j':
                fSpecial ^= 1;
                break;
1609 1610 1611
            case 'a':
                fUseHie ^= 1;
                break;
Alan Mishchenko committed
1612 1613 1614 1615 1616 1617
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1618 1619 1620 1621 1622
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1623 1624 1625 1626 1627
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
1628
    if ( fSpecial || pLutStruct )
1629
        Io_WriteBlifSpecial( pAbc->pNtkCur, pFileName, pLutStruct, fUseHie );
1630
    else
Alan Mishchenko committed
1631
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BLIF );
Alan Mishchenko committed
1632 1633 1634
    return 0;

usage:
1635
    fprintf( pAbc->Err, "usage: write_blif [-S str] [-jah] <file>\n" );
1636
    fprintf( pAbc->Err, "\t         writes the network into a BLIF file\n" );
1637
    fprintf( pAbc->Err, "\t-S str : string representing the LUT structure [default = %s]\n", pLutStruct ? pLutStruct : "not used" );  
Alan Mishchenko committed
1638
    fprintf( pAbc->Err, "\t-j     : enables special BLIF writing [default = %s]\n", fSpecial? "yes" : "no" );;
1639
    fprintf( pAbc->Err, "\t-a     : enables hierarchical BLIF writing for LUT structures [default = %s]\n", fUseHie? "yes" : "no" );;
Alan Mishchenko committed
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
    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
1672 1673 1674 1675 1676
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
    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" );
1687
    fprintf( pAbc->Err, "\t         writes the network into a BLIF-MV file\n" );
Alan Mishchenko committed
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
    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
1725 1726 1727 1728 1729
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1730 1731 1732 1733 1734 1735 1736
    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
1737
    else if ( pAbc->pNtkCur )
Alan Mishchenko committed
1738 1739 1740 1741 1742 1743 1744
    {
        Abc_Ntk_t * pNtkTemp;
        pNtkTemp = Abc_NtkToNetlist( pAbc->pNtkCur );
        Abc_NtkToAig( pNtkTemp );
        Io_WriteBenchLut( pNtkTemp, pFileName );
        Abc_NtkDelete( pNtkTemp );
    }
Alan Mishchenko committed
1745 1746
    else
        printf( "There is no current network.\n" );
Alan Mishchenko committed
1747 1748 1749 1750
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_bench [-lh] <file>\n" );
1751
    fprintf( pAbc->Err, "\t         writes the network in BENCH format\n" );
Alan Mishchenko committed
1752 1753 1754
    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
1755 1756 1757 1758 1759 1760 1761 1762 1763
    return 1;
}

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

  Synopsis    []

  Description []
               
Alan Mishchenko committed
1764
  SideEffects []
Alan Mishchenko committed
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793

  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" );
1794
    fprintf( pAbc->Err, "\t-h     : prints the help massage\n" );
Alan Mishchenko committed
1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
    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
1808 1809 1810 1811

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1812
int IoCommandWriteCellNet( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
1813
{
Alan Mishchenko committed
1814 1815
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
1816
    int c;
Alan Mishchenko committed
1817
    extern void Io_WriteCellNet( Abc_Ntk_t * pNtk, char * pFileName );
Alan Mishchenko committed
1818

Alan Mishchenko committed
1819 1820
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
1821 1822 1823 1824 1825 1826 1827 1828 1829
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1830
    if ( pAbc->pNtkCur == NULL )
Alan Mishchenko committed
1831 1832 1833 1834
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1835 1836 1837
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    pNtk = pAbc->pNtkCur;
Alan Mishchenko committed
1838 1839 1840 1841
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    if ( !Abc_NtkIsLogic(pNtk) )
Alan Mishchenko committed
1842
    {
Alan Mishchenko committed
1843
        fprintf( pAbc->Out, "The network should be a logic network (if it an AIG, use command \"logic\")\n" );
Alan Mishchenko committed
1844 1845
        return 0;
    }
Alan Mishchenko committed
1846 1847 1848 1849 1850
    Io_WriteCellNet( pNtk, pFileName );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_cellnet [-h] <file>\n" );
1851
    fprintf( pAbc->Err, "\t         writes the network is the cellnet format\n" );
Alan Mishchenko committed
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865
    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
1866

Alan Mishchenko committed
1867 1868 1869 1870 1871 1872
***********************************************************************/
int IoCommandWriteCnf( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
    int fNewAlgo;
1873 1874 1875 1876 1877
    int fFastAlgo;
    int fAllPrimes;
    int fChangePol;
    int fVerbose;
    extern Abc_Ntk_t * Abc_NtkDarToCnf( Abc_Ntk_t * pNtk, char * pFileName, int fFastAlgo, int fChangePol, int fVerbose );
Alan Mishchenko committed
1878 1879

    fNewAlgo = 1;
1880
    fFastAlgo = 0;
Alan Mishchenko committed
1881
    fAllPrimes = 0;
1882 1883
    fChangePol = 1;
    fVerbose = 0;
Alan Mishchenko committed
1884
    Extra_UtilGetoptReset();
1885
    while ( ( c = Extra_UtilGetopt( argc, argv, "nfpcvh" ) ) != EOF )
Alan Mishchenko committed
1886
    {
Alan Mishchenko committed
1887 1888 1889 1890 1891
        switch ( c )
        {
            case 'n':
                fNewAlgo ^= 1;
                break;
1892 1893 1894
            case 'f':
                fFastAlgo ^= 1;
                break;
Alan Mishchenko committed
1895 1896 1897
            case 'p':
                fAllPrimes ^= 1;
                break;
1898 1899 1900 1901 1902 1903
            case 'c':
                fChangePol ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
Alan Mishchenko committed
1904 1905 1906 1907 1908
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
1909
    }
Alan Mishchenko committed
1910 1911 1912 1913 1914
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
    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
1926 1927 1928 1929
    if ( fFastAlgo )
        Abc_NtkDarToCnf( pAbc->pNtkCur, pFileName, 1, fChangePol, fVerbose );
    else if ( fNewAlgo )
        Abc_NtkDarToCnf( pAbc->pNtkCur, pFileName, 0, fChangePol, fVerbose );
Alan Mishchenko committed
1930 1931 1932 1933 1934
    else if ( fAllPrimes )
        Io_WriteCnf( pAbc->pNtkCur, pFileName, 1 );
    else
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_CNF );
    return 0;
Alan Mishchenko committed
1935

Alan Mishchenko committed
1936
usage:
1937
    fprintf( pAbc->Err, "usage: write_cnf [-nfpcvh] <file>\n" );
1938
    fprintf( pAbc->Err, "\t         generates CNF for the miter (see also \"&write_cnf\")\n" );
Alan Mishchenko committed
1939
    fprintf( pAbc->Err, "\t-n     : toggle using new algorithm [default = %s]\n", fNewAlgo? "yes" : "no" );
1940
    fprintf( pAbc->Err, "\t-f     : toggle using fast algorithm [default = %s]\n", fFastAlgo? "yes" : "no" );
Alan Mishchenko committed
1941
    fprintf( pAbc->Err, "\t-p     : toggle using all primes to enhance implicativity [default = %s]\n", fAllPrimes? "yes" : "no" );
1942 1943
    fprintf( pAbc->Err, "\t-c     : toggle adjasting polarity of internal variables [default = %s]\n", fChangePol? "yes" : "no" );
    fprintf( pAbc->Err, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes" : "no" );
Alan Mishchenko committed
1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959
    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     []

***********************************************************************/
1960 1961
int IoCommandWriteCnf2( Abc_Frame_t * pAbc, int argc, char **argv )
{
1962
    extern void Jf_ManDumpCnf( Gia_Man_t * p, char * pFileName, int fVerbose );
1963
    extern void Mf_ManDumpCnf( Gia_Man_t * p, char * pFileName, int nLutSize, int fCnfObjIds, int fAddOrCla, int fVerbose );
1964 1965
    FILE * pFile;
    char * pFileName;
1966 1967 1968 1969
    int nLutSize    = 6;
    int fNewAlgo    = 1;
    int fCnfObjIds  = 0;
    int fAddOrCla   = 1;
1970 1971
    int c, fVerbose = 0;
    Extra_UtilGetoptReset();
1972
    while ( ( c = Extra_UtilGetopt( argc, argv, "Kaiovh" ) ) != EOF )
1973 1974 1975
    {
        switch ( c )
        {
1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987
            case 'K':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
                    goto usage;
                }
                nLutSize = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                break;
            case 'a':
                fNewAlgo ^= 1;
                break;
1988 1989 1990 1991 1992 1993
            case 'i':
                fCnfObjIds ^= 1;
                break;
            case 'o':
                fAddOrCla ^= 1;
                break;
1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pGia == NULL )
    {
        Abc_Print( -1, "IoCommandWriteCnf2(): There is no AIG.\n" );
        return 1;
    } 
    if ( Gia_ManRegNum(pAbc->pGia) > 0 )
    {
        Abc_Print( -1, "IoCommandWriteCnf2(): Works only for combinational miters.\n" );
        return 0;
    }
2013 2014 2015 2016 2017 2018
    if ( nLutSize < 3 || nLutSize > 8 )
    {
        Abc_Print( -1, "IoCommandWriteCnf2(): Invalid LUT size (%d).\n", nLutSize );
        return 0;
    }
    if ( !fNewAlgo && !Sdm_ManCanRead() )
2019 2020 2021 2022
    {
        Abc_Print( -1, "IoCommandWriteCnf2(): Cannot input precomputed DSD information.\n" );
        return 0;
    }
2023 2024 2025 2026 2027 2028 2029 2030 2031 2032
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    pFile = fopen( pFileName, "wb" );
    if ( pFile == NULL )
    {
        printf( "Cannot open file \"%s\" for writing.\n", pFileName );
        return 0;
    }
2033 2034
    fclose( pFile );
    if ( fNewAlgo )
2035
        Mf_ManDumpCnf( pAbc->pGia, pFileName, nLutSize, fCnfObjIds, fAddOrCla, fVerbose );
2036 2037
    else
        Jf_ManDumpCnf( pAbc->pGia, pFileName, fVerbose );
2038 2039 2040
    return 0;

usage:
2041
    fprintf( pAbc->Err, "usage: &write_cnf [-Kaiovh] <file>\n" );
2042 2043 2044
    fprintf( pAbc->Err, "\t           writes CNF produced by a new generator\n" );
    fprintf( pAbc->Err, "\t-K <num> : the LUT size (3 <= num <= 8) [default = %d]\n", nLutSize );
    fprintf( pAbc->Err, "\t-a       : toggle using new algorithm [default = %s]\n", fNewAlgo? "yes" : "no" );
2045 2046
    fprintf( pAbc->Err, "\t-i       : toggle using AIG object IDs as CNF variables [default = %s]\n", fCnfObjIds? "yes" : "no" );
    fprintf( pAbc->Err, "\t-o       : toggle adding OR clause for the outputs [default = %s]\n", fAddOrCla? "yes" : "no" );
2047 2048 2049
    fprintf( pAbc->Err, "\t-v       : toggle printing verbose information [default = %s]\n", fVerbose? "yes" : "no" );
    fprintf( pAbc->Err, "\t-h       : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile     : the name of the file to write\n" );
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064
    return 1;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080
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
2081 2082 2083 2084 2085
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2086 2087 2088 2089 2090 2091
    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
2092 2093 2094 2095
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_dot [-h] <file>\n" );
2096
    fprintf( pAbc->Err, "\t         writes the current network into a DOT file\n" );
Alan Mishchenko committed
2097 2098 2099 2100 2101
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

2102 2103
ABC_NAMESPACE_IMPL_END

2104
#include "proof/fra/fra.h"
Alan Mishchenko committed
2105

2106 2107 2108
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2120
int IoCommandWriteCex( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
2121
{
Alan Mishchenko committed
2122 2123
    Abc_Ntk_t * pNtk;
    char * pFileName;
2124 2125
    int c, fNames  = 0;
    int fMinimize  = 0;
2126 2127
    int fUseOldMin = 0;
    int fCheckCex  = 0;
2128
    int forceSeq   = 0;
2129
    int fAiger     = 0;
2130 2131
    int fPrintFull = 0;
    int fVerbose   = 0;
Alan Mishchenko committed
2132

Alan Mishchenko committed
2133
    Extra_UtilGetoptReset();
2134
    while ( ( c = Extra_UtilGetopt( argc, argv, "snmocafvh" ) ) != EOF )
Alan Mishchenko committed
2135 2136 2137
    {
        switch ( c )
        {
Alan Mishchenko committed
2138 2139 2140
            case 's':
                forceSeq ^= 1;
                break;
Alan Mishchenko committed
2141 2142 2143
            case 'n':
                fNames ^= 1;
                break;
2144 2145 2146
            case 'm':
                fMinimize ^= 1;
                break;
2147 2148 2149 2150 2151 2152
            case 'o':
                fUseOldMin ^= 1;
                break;
            case 'c':
                fCheckCex ^= 1;
                break;
2153 2154 2155
            case 'a':
                fAiger ^= 1;
                break;
2156 2157 2158
            case 'f':
                fPrintFull ^= 1;
                break;
2159 2160 2161
            case 'v':
                fVerbose ^= 1;
                break;
Alan Mishchenko committed
2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    pNtk = pAbc->pNtkCur;
    if ( pNtk == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
2174 2175 2176 2177 2178
    if ( pNtk->pModel == NULL && pAbc->pCex == NULL )
    {
        fprintf( pAbc->Out, "Counter-example is not available.\n" );
        return 0;
    }
Alan Mishchenko committed
2179
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
2180
    {
Alan Mishchenko committed
2181
        printf( "File name is missing on the command line.\n" );
Alan Mishchenko committed
2182 2183
        goto usage;
    }
2184

Alan Mishchenko committed
2185 2186 2187
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // write the counter-example into the file
2188
    if ( pAbc->pCex )
Alan Mishchenko committed
2189
    { 
2190
        Abc_Cex_t * pCex = pAbc->pCex;
Alan Mishchenko committed
2191 2192 2193 2194 2195 2196
        Abc_Obj_t * pObj;
        FILE * pFile;
        int i, f;
        Abc_NtkForEachLatch( pNtk, pObj, i )
            if ( !Abc_LatchIsInit0(pObj) )
            {
2197
                fprintf( stdout, "IoCommandWriteCex(): The init-state should be all-0 for counter-example to work.\n" );
Alan Mishchenko committed
2198 2199 2200 2201 2202 2203 2204
                fprintf( stdout, "Run commands \"undc\" and \"zero\" and then rerun the equivalence check.\n" );
                return 1;
            }

        pFile = fopen( pFileName, "w" );
        if ( pFile == NULL )
        {
2205
            fprintf( stdout, "IoCommandWriteCex(): Cannot open the output file \"%s\".\n", pFileName );
Alan Mishchenko committed
2206 2207
            return 1;
        }
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221
        if ( fPrintFull )
        {
            extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
            Aig_Man_t * pAig = Abc_NtkToDar( pNtk, 0, 1 );
            Abc_Cex_t * pCexFull = Saig_ManExtendCex( pAig, pCex );
            Aig_ManStop( pAig );
            // output PI values (while skipping the minimized ones)
            assert( pCexFull->nBits == Abc_NtkCiNum(pNtk) * (pCex->iFrame + 1) );
            for ( f = 0; f <= pCex->iFrame; f++ )
                Abc_NtkForEachCi( pNtk, pObj, i )
                    fprintf( pFile, "%s@%d=%c ", Abc_ObjName(pObj), f, '0'+Abc_InfoHasBit(pCexFull->pData, Abc_NtkCiNum(pNtk)*f + i) );
            Abc_CexFreeP( &pCexFull );
        }
        else if ( fNames )
Alan Mishchenko committed
2222
        {
2223 2224 2225 2226 2227
            Abc_Cex_t * pCare = NULL;
            if ( fMinimize )
            {
                extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
                Aig_Man_t * pAig = Abc_NtkToDar( pNtk, 0, 1 );
2228 2229 2230 2231 2232 2233 2234 2235
                if ( fUseOldMin )
                {
                    pCare = Saig_ManCbaFindCexCareBits( pAig, pCex, 0, fVerbose );
                    if ( fCheckCex )
                        Bmc_CexCareVerify( pAig, pCex, pCare, fVerbose );
                }
                else
                    pCare = Bmc_CexCareMinimize( pAig, pCex, fCheckCex, fVerbose );
2236 2237 2238
                Aig_ManStop( pAig );
            }
            // output flop values (unaffected by the minimization)
Alan Mishchenko committed
2239 2240
            Abc_NtkForEachLatch( pNtk, pObj, i )
                fprintf( pFile, "%s@0=%c ", Abc_ObjName(Abc_ObjFanout0(pObj)), '0'+!Abc_LatchIsInit0(pObj) );
2241
            // output PI values (while skipping the minimized ones)
Alan Mishchenko committed
2242 2243
            for ( f = 0; f <= pCex->iFrame; f++ )
                Abc_NtkForEachPi( pNtk, pObj, i )
2244 2245 2246
                    if ( !pCare || Abc_InfoHasBit(pCare->pData, pCare->nRegs+pCare->nPis*f + i) )
                        fprintf( pFile, "%s@%d=%c ", Abc_ObjName(pObj), f, '0'+Abc_InfoHasBit(pCex->pData, pCex->nRegs+pCex->nPis*f + i) );
            Abc_CexFreeP( &pCare );
Alan Mishchenko committed
2247 2248 2249 2250 2251
        }
        else
        {
            Abc_NtkForEachLatch( pNtk, pObj, i )
                fprintf( pFile, "%c", '0'+!Abc_LatchIsInit0(pObj) );
2252

Alan Mishchenko committed
2253
            for ( i = pCex->nRegs; i < pCex->nBits; i++ )
2254 2255 2256
            {
                if ( fAiger && (i-pCex->nRegs)%pCex->nPis == 0)
                    fprintf( pFile, "\n");
Alan Mishchenko committed
2257
                fprintf( pFile, "%c", '0'+Abc_InfoHasBit(pCex->pData, i) );
2258
            }
Alan Mishchenko committed
2259 2260
        }
        fprintf( pFile, "\n" );
Alan Mishchenko committed
2261 2262 2263 2264 2265 2266 2267 2268 2269
        fclose( pFile );
    }
    else
    {
        Abc_Obj_t * pObj;
        FILE * pFile = fopen( pFileName, "w" );
        int i;
        if ( pFile == NULL )
        {
2270
            fprintf( stdout, "IoCommandWriteCex(): Cannot open the output file \"%s\".\n", pFileName );
Alan Mishchenko committed
2271 2272 2273 2274
            return 1;
        }
        if ( fNames )
        {
2275
            const char *cycle_ctr = forceSeq?"@0":"";
Alan Mishchenko committed
2276
            Abc_NtkForEachPi( pNtk, pObj, i )
Alan Mishchenko committed
2277 2278
//                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
2279 2280 2281 2282 2283 2284 2285
        }
        else
        {
            Abc_NtkForEachPi( pNtk, pObj, i )
                fprintf( pFile, "%c", '0'+(pNtk->pModel[i]==1) );
        }
        fprintf( pFile, "\n" );
Alan Mishchenko committed
2286 2287 2288 2289 2290 2291
        fclose( pFile );
    }

    return 0;

usage:
2292
    fprintf( pAbc->Err, "usage: write_cex [-snmocfvh] <file>\n" );
Alan Mishchenko committed
2293 2294
    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
2295
    fprintf( pAbc->Err, "\t-s     : always report a sequential ctrex (cycle 0 for comb) [default = %s]\n", forceSeq? "yes": "no" );
Alan Mishchenko committed
2296
    fprintf( pAbc->Err, "\t-n     : write input names into the file [default = %s]\n", fNames? "yes": "no" );
2297
    fprintf( pAbc->Err, "\t-m     : minimize counter-example by dropping don't-care values [default = %s]\n", fMinimize? "yes": "no" );
2298 2299
    fprintf( pAbc->Err, "\t-o     : use old counter-example minimization algorithm [default = %s]\n", fUseOldMin? "yes": "no" );
    fprintf( pAbc->Err, "\t-c     : check generated counter-example using ternary simulation [default = %s]\n", fCheckCex? "yes": "no" );
2300
    fprintf( pAbc->Err, "\t-a     : print cex in AIGER 1.9 format [default = %s].\n", fAiger? "yes": "no" );
2301
    fprintf( pAbc->Err, "\t-f     : enable printing flop values in each timeframe [default = %s].\n", fPrintFull? "yes": "no" );  
2302
    fprintf( pAbc->Err, "\t-v     : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );  
Alan Mishchenko committed
2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333
    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
2334
    }
Alan Mishchenko committed
2335 2336 2337 2338 2339
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2340 2341 2342 2343 2344 2345
    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
2346
    return 0;
Alan Mishchenko committed
2347

Alan Mishchenko committed
2348 2349
usage:
    fprintf( pAbc->Err, "usage: write_eqn [-h] <file>\n" );
2350
    fprintf( pAbc->Err, "\t         writes the current network in the equation format\n" );
Alan Mishchenko committed
2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368
    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
2369
    char * pFileName;
Alan Mishchenko committed
2370
    int c;
Alan Mishchenko committed
2371

Alan Mishchenko committed
2372 2373
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
2374
    {
Alan Mishchenko committed
2375 2376 2377 2378 2379 2380 2381
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2382
    }
Alan Mishchenko committed
2383 2384 2385 2386 2387
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2388 2389 2390 2391 2392 2393 2394 2395 2396 2397
    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" );
2398
    fprintf( pAbc->Err, "\t         writes network using graph representation formal GML\n" );
Alan Mishchenko committed
2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422
    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
2423

Alan Mishchenko committed
2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438
    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
2439 2440 2441 2442 2443
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2444 2445
    if ( argc != globalUtilOptind + 1 )
        goto usage;
Alan Mishchenko committed
2446 2447
/*
    if ( !Abc_NtkIsSeq(pAbc->pNtkCur) )
Alan Mishchenko committed
2448
    {
Alan Mishchenko committed
2449
        fprintf( stdout, "IoCommandWriteList(): Can write adjacency list for sequential AIGs only.\n" );
Alan Mishchenko committed
2450 2451
        return 0;
    }
Alan Mishchenko committed
2452
*/
Alan Mishchenko committed
2453
    // get the input file name
Alan Mishchenko committed
2454
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
2455
    // write the file
Alan Mishchenko committed
2456
    Io_WriteList( pAbc->pNtkCur, pFileName, fUseHost );
Alan Mishchenko committed
2457 2458 2459
    return 0;

usage:
Alan Mishchenko committed
2460
    fprintf( pAbc->Err, "usage: write_list [-nh] <file>\n" );
2461
    fprintf( pAbc->Err, "\t         writes network using graph representation formal GML\n" );
Alan Mishchenko committed
2462
    fprintf( pAbc->Err, "\t-n     : toggle writing host node [default = %s]\n", fUseHost? "yes":"no" );
Alan Mishchenko committed
2463 2464
    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
2465 2466 2467
    return 1;
}

Alan Mishchenko committed
2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWritePla( Abc_Frame_t * pAbc, int argc, char **argv )
{
Alan Mishchenko committed
2481
    char * pFileName;
2482
    int c, fUseMoPla = 0;
Alan Mishchenko committed
2483

Alan Mishchenko committed
2484
    Extra_UtilGetoptReset();
2485
    while ( ( c = Extra_UtilGetopt( argc, argv, "mh" ) ) != EOF )
Alan Mishchenko committed
2486 2487 2488
    {
        switch ( c )
        {
2489 2490 2491
            case 'm':
                fUseMoPla ^= 1;
                break;
Alan Mishchenko committed
2492 2493 2494 2495 2496 2497
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
2498 2499 2500 2501 2502
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2503 2504 2505 2506 2507
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
2508
    Io_Write( pAbc->pNtkCur, pFileName, fUseMoPla ? IO_FILE_MOPLA : IO_FILE_PLA );
Alan Mishchenko committed
2509
    return 0;
Alan Mishchenko committed
2510

Alan Mishchenko committed
2511
usage:
2512
    fprintf( pAbc->Err, "usage: write_pla [-mh] <file>\n" );
2513
    fprintf( pAbc->Err, "\t         writes the collapsed network into a PLA file\n" );
2514
    fprintf( pAbc->Err, "\t-m     : toggle writing multi-output PLA [default = %s]\n", fUseMoPla? "yes":"no" );
Alan Mishchenko committed
2515 2516 2517 2518
    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
2519

Alan Mishchenko committed
2520 2521 2522 2523 2524 2525 2526
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []
Alan Mishchenko committed
2527

Alan Mishchenko committed
2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
  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
2538
    {
Alan Mishchenko committed
2539 2540 2541 2542 2543 2544 2545
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2546
    }
Alan Mishchenko committed
2547 2548 2549 2550 2551
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2552 2553 2554 2555 2556 2557 2558
    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
2559

Alan Mishchenko committed
2560 2561
usage:
    fprintf( pAbc->Err, "usage: write_verilog [-h] <file>\n" );
2562
    fprintf( pAbc->Err, "\t         writes the current network in Verilog format\n" );
Alan Mishchenko committed
2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578
    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
2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629
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" );
2630
    fprintf( pAbc->Err, "\t         writes CNF for the sorter\n" );
Alan Mishchenko committed
2631 2632 2633 2634 2635 2636 2637
    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
2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656
/**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
2657
    int fReverse = 0;
Alan Mishchenko committed
2658 2659 2660
    int c;

    Extra_UtilGetoptReset();
Alan Mishchenko committed
2661
    while ( ( c = Extra_UtilGetopt( argc, argv, "rh" ) ) != EOF )
Alan Mishchenko committed
2662 2663 2664
    {
        switch ( c )
        {
Alan Mishchenko committed
2665 2666 2667
            case 'r':
                fReverse ^= 1;
                break;
Alan Mishchenko committed
2668 2669 2670 2671 2672 2673 2674 2675
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pNtkCur == NULL )
    {
Alan Mishchenko committed
2676
        printf( "Current network is not available.\n" );
Alan Mishchenko committed
2677 2678 2679 2680
        return 0;
    }
    if ( !Abc_NtkIsLogic(pNtk) )
    {
Alan Mishchenko committed
2681
        printf( "Current network should not an AIG. Run \"logic\".\n" );
Alan Mishchenko committed
2682 2683 2684 2685
        return 0;
    }
    if ( Abc_NtkPoNum(pNtk) != 1 )
    {
Alan Mishchenko committed
2686
        printf( "Current network should have exactly one primary output.\n" );
Alan Mishchenko committed
2687 2688 2689 2690
        return 0;
    }
    if ( Abc_NtkNodeNum(pNtk) != 1 )
    {
Alan Mishchenko committed
2691
        printf( "Current network should have exactly one node.\n" );
Alan Mishchenko committed
2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711
        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 );
2712
    pTruth = Hop_ManConvertAigToTruth( (Hop_Man_t *)pNtk->pManFunc, (Hop_Obj_t *)pNode->pData, Abc_ObjFaninNum(pNode), vTruth, fReverse );
Alan Mishchenko committed
2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725
    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
2726
    fprintf( pAbc->Err, "usage: write_truth [-rh] <file>\n" );
Alan Mishchenko committed
2727
    fprintf( pAbc->Err, "\t         writes truth table into a file\n" );
Alan Mishchenko committed
2728
    fprintf( pAbc->Err, "\t-r     : toggle reversing bits in the truth table [default = %s]\n", fReverse? "yes":"no" );
Alan Mishchenko committed
2729 2730 2731 2732 2733
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteTruths( Abc_Frame_t * pAbc, int argc, char **argv )
{
    Gia_Obj_t * pObj;
    char * pFileName;
    FILE * pFile;
2751
    word * pTruth;
2752
    int nBytes;
2753
    int fReverse = 0;
2754
    int fBinary = 0;
2755 2756 2757
    int c, i;
 
    Extra_UtilGetoptReset();
2758
    while ( ( c = Extra_UtilGetopt( argc, argv, "rbh" ) ) != EOF )
2759 2760 2761 2762 2763 2764
    {
        switch ( c )
        {
            case 'r':
                fReverse ^= 1;
                break;
2765 2766 2767
            case 'b':
                fBinary ^= 1;
                break;
2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pGia == NULL )
    {
        Abc_Print( -1, "IoCommandWriteTruths(): There is no AIG.\n" );
        return 1;
    } 
    if ( Gia_ManPiNum(pAbc->pGia) > 16 )
    {
        Abc_Print( -1, "IoCommandWriteTruths(): Can write truth tables up to 16 inputs.\n" );
        return 0;
    }
2784 2785 2786 2787 2788
    if ( Gia_ManPiNum(pAbc->pGia) < 3 )
    {
        Abc_Print( -1, "IoCommandWriteTruths(): Can write truth tables for 3 inputs or more.\n" );
        return 0;
    }
2789 2790 2791 2792 2793
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // convert to logic
2794
    pFile = fopen( pFileName, "wb" );
2795 2796 2797 2798 2799
    if ( pFile == NULL )
    {
        printf( "Cannot open file \"%s\" for writing.\n", pFileName );
        return 0;
    }
2800
    nBytes = 8 * Abc_Truth6WordNum( Gia_ManPiNum(pAbc->pGia) );
2801 2802 2803
    Gia_ManForEachCo( pAbc->pGia, pObj, i )
    {
        pTruth = Gia_ObjComputeTruthTable( pAbc->pGia, pObj );
2804 2805 2806
        if ( fBinary )
            fwrite( pTruth, nBytes, 1, pFile );
        else
2807
            Extra_PrintHex( pFile, (unsigned *)pTruth, Gia_ManPiNum(pAbc->pGia) ), fprintf( pFile, "\n" );
2808 2809 2810 2811 2812
    }
    fclose( pFile );
    return 0;

usage:
2813
    fprintf( pAbc->Err, "usage: &write_truths [-rbh] <file>\n" );
2814 2815
    fprintf( pAbc->Err, "\t         writes truth tables of each PO of GIA manager into a file\n" );
    fprintf( pAbc->Err, "\t-r     : toggle reversing bits in the truth table [default = %s]\n", fReverse? "yes":"no" );
2816
    fprintf( pAbc->Err, "\t-b     : toggle using binary format [default = %s]\n", fBinary? "yes":"no" );
2817 2818 2819 2820 2821 2822
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}


2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteStatus( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
2838
    extern void Abc_NtkWriteLogFile( char * pFileName, Abc_Cex_t * pCex, int Status, int nFrames, char * pCommand );
2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854

    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];
2855
    Abc_NtkWriteLogFile( pFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, NULL );
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914
    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
2915 2916 2917 2918 2919
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


2920 2921
ABC_NAMESPACE_IMPL_END