io.c 111 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
#ifdef WIN32
28
#include <process.h> 
29
#define unlink _unlink
30 31
#else
#include <unistd.h>
32 33
#endif

34 35
ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
36 37 38 39 40
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

static int IoCommandRead        ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
41 42
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
43
static int IoCommandReadBblif   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
44
static int IoCommandReadBlif    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
45
static int IoCommandReadBlifMv  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
46
static int IoCommandReadBench   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
47
static int IoCommandReadDsd     ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
48
static int IoCommandReadEdif    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
49
static int IoCommandReadEqn     ( Abc_Frame_t * pAbc, int argc, char **argv );
50
static int IoCommandReadFins    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
51
static int IoCommandReadInit    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
52
static int IoCommandReadPla     ( Abc_Frame_t * pAbc, int argc, char **argv );
53
static int IoCommandReadPlaMo   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
54 55
static int IoCommandReadTruth   ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadVerilog ( Abc_Frame_t * pAbc, int argc, char **argv );
56
static int IoCommandReadStatus  ( Abc_Frame_t * pAbc, int argc, char **argv );
57
static int IoCommandReadGig     ( Abc_Frame_t * pAbc, int argc, char **argv );
58
static int IoCommandReadJson    ( Abc_Frame_t * pAbc, int argc, char **argv );
59
static int IoCommandReadSF      ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
60

Alan Mishchenko committed
61 62 63
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 );
64
static int IoCommandWriteAigerCex( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
65
static int IoCommandWriteBaf    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
66
static int IoCommandWriteBblif  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
67
static int IoCommandWriteBlif   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
68
static int IoCommandWriteBlifMv ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
69
static int IoCommandWriteBench  ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
70
static int IoCommandWriteBook   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
71
static int IoCommandWriteCellNet( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
72
static int IoCommandWriteCnf    ( Abc_Frame_t * pAbc, int argc, char **argv );
73
static int IoCommandWriteCnf2   ( Abc_Frame_t * pAbc, int argc, char **argv );
74
static int IoCommandWriteCex    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
75 76 77
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
78
static int IoCommandWriteList   ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
79
static int IoCommandWritePla    ( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
80
static int IoCommandWriteVerilog( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
81
static int IoCommandWriteSortCnf( Abc_Frame_t * pAbc, int argc, char **argv );
Alan Mishchenko committed
82
static int IoCommandWriteTruth  ( Abc_Frame_t * pAbc, int argc, char **argv );
83
static int IoCommandWriteTruths ( Abc_Frame_t * pAbc, int argc, char **argv );
84 85
static int IoCommandWriteStatus ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteSmv    ( Abc_Frame_t * pAbc, int argc, char **argv );
86
static int IoCommandWriteJson   ( Abc_Frame_t * pAbc, int argc, char **argv );
87 88

extern void Abc_FrameCopyLTLDataBase( Abc_Frame_t *pAbc, Abc_Ntk_t * pNtk );
Alan Mishchenko committed
89 90

extern int glo_fMapped;
Alan Mishchenko committed
91

Alan Mishchenko committed
92
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
93
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Io_Init( Abc_Frame_t * pAbc )
{
    Cmd_CommandAdd( pAbc, "I/O", "read",          IoCommandRead,         1 );
Alan Mishchenko committed
110 111
    Cmd_CommandAdd( pAbc, "I/O", "read_aiger",    IoCommandReadAiger,    1 );
    Cmd_CommandAdd( pAbc, "I/O", "read_baf",      IoCommandReadBaf,      1 );
Alan Mishchenko committed
112
    Cmd_CommandAdd( pAbc, "I/O", "read_bblif",    IoCommandReadBblif,    1 );
Alan Mishchenko committed
113
    Cmd_CommandAdd( pAbc, "I/O", "read_blif",     IoCommandReadBlif,     1 );
Alan Mishchenko committed
114
    Cmd_CommandAdd( pAbc, "I/O", "read_blif_mv",  IoCommandReadBlifMv,   1 );
Alan Mishchenko committed
115
    Cmd_CommandAdd( pAbc, "I/O", "read_bench",    IoCommandReadBench,    1 );
Alan Mishchenko committed
116
    Cmd_CommandAdd( pAbc, "I/O", "read_dsd",      IoCommandReadDsd,      1 );
117
    Cmd_CommandAdd( pAbc, "I/O", "read_formula",  IoCommandReadDsd,      1 );
Alan Mishchenko committed
118
//    Cmd_CommandAdd( pAbc, "I/O", "read_edif",     IoCommandReadEdif,     1 );
Alan Mishchenko committed
119
    Cmd_CommandAdd( pAbc, "I/O", "read_eqn",      IoCommandReadEqn,      1 );
120
    Cmd_CommandAdd( pAbc, "I/O", "read_fins",     IoCommandReadFins,     0 );
Alan Mishchenko committed
121
    Cmd_CommandAdd( pAbc, "I/O", "read_init",     IoCommandReadInit,     1 );
Alan Mishchenko committed
122
    Cmd_CommandAdd( pAbc, "I/O", "read_pla",      IoCommandReadPla,      1 );
123
    Cmd_CommandAdd( pAbc, "I/O", "read_plamo",    IoCommandReadPlaMo,    1 );
Alan Mishchenko committed
124 125
    Cmd_CommandAdd( pAbc, "I/O", "read_truth",    IoCommandReadTruth,    1 );
    Cmd_CommandAdd( pAbc, "I/O", "read_verilog",  IoCommandReadVerilog,  1 );
126
    Cmd_CommandAdd( pAbc, "I/O", "read_status",   IoCommandReadStatus,   0 );
127
    Cmd_CommandAdd( pAbc, "I/O", "&read_gig",     IoCommandReadGig,      0 );
128
    Cmd_CommandAdd( pAbc, "I/O", "read_json",     IoCommandReadJson,     0 );
129
    Cmd_CommandAdd( pAbc, "I/O", "read_sf",       IoCommandReadSF,       0 );
Alan Mishchenko committed
130

Alan Mishchenko committed
131 132 133
    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 );
134
    Cmd_CommandAdd( pAbc, "I/O", "write_aiger_cex",   IoCommandWriteAigerCex,   0 );
Alan Mishchenko committed
135
    Cmd_CommandAdd( pAbc, "I/O", "write_baf",     IoCommandWriteBaf,     0 );
Alan Mishchenko committed
136
    Cmd_CommandAdd( pAbc, "I/O", "write_bblif",   IoCommandWriteBblif,   0 );
Alan Mishchenko committed
137
    Cmd_CommandAdd( pAbc, "I/O", "write_blif",    IoCommandWriteBlif,    0 );
Alan Mishchenko committed
138
    Cmd_CommandAdd( pAbc, "I/O", "write_blif_mv", IoCommandWriteBlifMv,  0 );
Alan Mishchenko committed
139
    Cmd_CommandAdd( pAbc, "I/O", "write_bench",   IoCommandWriteBench,   0 );
Alan Mishchenko committed
140
    Cmd_CommandAdd( pAbc, "I/O", "write_book",    IoCommandWriteBook,    0 );
Alan Mishchenko committed
141
    Cmd_CommandAdd( pAbc, "I/O", "write_cellnet", IoCommandWriteCellNet, 0 );
142
    Cmd_CommandAdd( pAbc, "I/O", "write_cex",     IoCommandWriteCex,     0 );
Alan Mishchenko committed
143
    Cmd_CommandAdd( pAbc, "I/O", "write_cnf",     IoCommandWriteCnf,     0 );
144
    Cmd_CommandAdd( pAbc, "I/O", "&write_cnf",    IoCommandWriteCnf2,    0 );
Alan Mishchenko committed
145 146 147
    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
148
//    Cmd_CommandAdd( pAbc, "I/O", "write_list",    IoCommandWriteList,    0 );
Alan Mishchenko committed
149
    Cmd_CommandAdd( pAbc, "I/O", "write_pla",     IoCommandWritePla,     0 );
Alan Mishchenko committed
150 151
    Cmd_CommandAdd( pAbc, "I/O", "write_verilog", IoCommandWriteVerilog, 0 );
//    Cmd_CommandAdd( pAbc, "I/O", "write_verlib",  IoCommandWriteVerLib,  0 );
Alan Mishchenko committed
152
    Cmd_CommandAdd( pAbc, "I/O", "write_sorter_cnf", IoCommandWriteSortCnf,  0 );
Alan Mishchenko committed
153
    Cmd_CommandAdd( pAbc, "I/O", "write_truth",   IoCommandWriteTruth,   0 );
154
    Cmd_CommandAdd( pAbc, "I/O", "&write_truths", IoCommandWriteTruths,  0 );
155 156
    Cmd_CommandAdd( pAbc, "I/O", "write_status",  IoCommandWriteStatus,  0 );
    Cmd_CommandAdd( pAbc, "I/O", "write_smv",     IoCommandWriteSmv,     0 );
157
    Cmd_CommandAdd( pAbc, "I/O", "write_json",    IoCommandWriteJson,    0 );
Alan Mishchenko committed
158 159 160 161 162 163 164 165 166 167 168 169 170
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
171
void Io_End( Abc_Frame_t * pAbc )
Alan Mishchenko committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
{
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandRead( Abc_Frame_t * pAbc, int argc, char ** argv )
{
188
    char Command[1000];
Alan Mishchenko committed
189
    Abc_Ntk_t * pNtk;
Alan Mishchenko committed
190
    char * pFileName, * pTemp;
191
    int c, fCheck, fBarBufs, fReadGia;
Alan Mishchenko committed
192 193

    fCheck = 1;
194
    fBarBufs = 0;
195
    fReadGia = 0;
Alan Mishchenko committed
196 197
    glo_fMapped = 0;
    Extra_UtilGetoptReset();
198
    while ( ( c = Extra_UtilGetopt( argc, argv, "mcbgh" ) ) != EOF )
Alan Mishchenko committed
199 200 201
    {
        switch ( c )
        {
Alan Mishchenko committed
202 203 204
            case 'm':
                glo_fMapped ^= 1;
                break;
Alan Mishchenko committed
205 206 207
            case 'c':
                fCheck ^= 1;
                break;
208 209 210
            case 'b':
                fBarBufs ^= 1;
                break;
211 212 213
            case 'g':
                fReadGia ^= 1;
                break;
Alan Mishchenko committed
214 215 216 217 218 219
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
220
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
221 222
        goto usage;
    // get the input file name
Alan Mishchenko committed
223
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
224 225
    // fix the wrong symbol
    for ( pTemp = pFileName; *pTemp; pTemp++ )
226 227
        if ( *pTemp == '>' || *pTemp == '\\' )
            *pTemp = '/';
228 229 230 231
    // read libraries
    Command[0] = 0;
    assert( strlen(pFileName) < 900 );
    if ( !strcmp( Extra_FileNameExtension(pFileName), "genlib" )  )
232
        sprintf( Command, "read_genlib %s", pFileName );
233
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "lib" ) )
234
        sprintf( Command, "read_lib %s", pFileName );
235 236
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "scl" ) )
        sprintf( Command, "read_scl %s", pFileName );
237 238
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "super" ) )
        sprintf( Command, "read_super %s", pFileName );
239 240
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "constr" ) )
        sprintf( Command, "read_constr %s", pFileName );
241 242
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "c" ) )
        sprintf( Command, "so %s", pFileName );
243 244
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "script" ) )
        sprintf( Command, "so %s", pFileName );
245 246
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "dsd" ) )
        sprintf( Command, "dsd_load %s", pFileName );
247 248 249 250 251
    if ( Command[0] )
    {
        Cmd_CommandExecute( pAbc, Command );
        return 0;
    }
252 253 254
    if ( fReadGia )
    {
        Abc_Ntk_t * pNtk = Io_ReadNetlist( pFileName, Io_ReadFileType(pFileName), fCheck );
255
        if ( pNtk )
256
        {
257
            Gia_Man_t * pGia = Abc_NtkFlattenHierarchyGia( pNtk, NULL, 0 );
258 259 260 261 262 263 264
            Abc_NtkDelete( pNtk );
            if ( pGia == NULL )
            {
                Abc_Print( 1, "Abc_CommandBlast(): Bit-blasting has failed.\n" );
                return 0;
            }
            Abc_FrameUpdateGia( pAbc, pGia );
265 266 267
        }
        return 0;
    }
268 269 270 271 272 273
    // 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
274
    // read the file using the corresponding file reader
275
    pNtk = Io_Read( pFileName, Io_ReadFileType(pFileName), fCheck, fBarBufs );
Alan Mishchenko committed
276
    if ( pNtk == NULL )
277
        return 0;
278 279 280 281 282
    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
283 284
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
285 286
    Abc_FrameCopyLTLDataBase( pAbc, pNtk );
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
287 288 289
    return 0;

usage:
290
    fprintf( pAbc->Err, "usage: read [-mcbgh] <file>\n" );
Alan Mishchenko committed
291 292 293 294
    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
295
    fprintf( pAbc->Err, "\t-c     : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
296
    fprintf( pAbc->Err, "\t-b     : toggle reading barrier buffers [default = %s]\n", fBarBufs? "yes":"no" );
297
    fprintf( pAbc->Err, "\t-g     : toggle reading and flattening into &-space [default = %s]\n", fBarBufs? "yes":"no" );
Alan Mishchenko committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    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
314
int IoCommandReadAiger( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
315
{
Alan Mishchenko committed
316 317
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
318 319 320 321
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
322 323
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
324 325 326 327 328 329 330 331 332 333 334 335
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
336
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
337 338
        goto usage;
    // get the input file name
Alan Mishchenko committed
339 340
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
341
    pNtk = Io_Read( pFileName, IO_FILE_AIGER, fCheck, 0 );
Alan Mishchenko committed
342 343 344 345
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
346
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
347 348 349
    return 0;

usage:
Alan Mishchenko committed
350
    fprintf( pAbc->Err, "usage: read_aiger [-ch] <file>\n" );
351
    fprintf( pAbc->Err, "\t         reads the network in the AIGER format (http://fmv.jku.at/aiger)\n" );
Alan Mishchenko committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
    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
369
int IoCommandReadBaf( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
370
{
Alan Mishchenko committed
371 372
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
373 374 375 376
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
377 378
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
379 380 381 382 383 384 385 386 387 388 389 390
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
391
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
392 393
        goto usage;
    // get the input file name
Alan Mishchenko committed
394 395
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
396
    pNtk = Io_Read( pFileName, IO_FILE_BAF, fCheck, 0 );
Alan Mishchenko committed
397 398 399 400
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
401
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
402 403 404
    return 0;

usage:
Alan Mishchenko committed
405
    fprintf( pAbc->Err, "usage: read_baf [-ch] <file>\n" );
406
    fprintf( pAbc->Err, "\t         reads the network in Binary Aig Format (BAF)\n" );
Alan Mishchenko committed
407 408 409 410 411
    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
412

Alan Mishchenko committed
413 414 415 416 417 418 419 420 421 422 423
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
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
451
    pNtk = Io_Read( pFileName, IO_FILE_BBLIF, fCheck, 0 );
Alan Mishchenko committed
452 453 454 455
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
456
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
457 458 459 460
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_bblif [-ch] <file>\n" );
461
    fprintf( pAbc->Err, "\t         reads the network in a binary BLIF format\n" );
Alan Mishchenko committed
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
    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
479
int IoCommandReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
480
{
Alan Mishchenko committed
481 482 483
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fReadAsAig;
Alan Mishchenko committed
484
    int fCheck;
485
    int fUseNewParser;
486
    int fSaveNames;
Alan Mishchenko committed
487
    int c;
Alan Mishchenko committed
488
    extern Abc_Ntk_t * Io_ReadBlifAsAig( char * pFileName, int fCheck );
Alan Mishchenko committed
489 490

    fCheck = 1;
Alan Mishchenko committed
491
    fReadAsAig = 0;
492
    fUseNewParser = 1;
493
    fSaveNames = 0;
Alan Mishchenko committed
494
    Extra_UtilGetoptReset();
495
    while ( ( c = Extra_UtilGetopt( argc, argv, "nmach" ) ) != EOF )
Alan Mishchenko committed
496 497 498
    {
        switch ( c )
        {
499 500 501
            case 'n':
                fUseNewParser ^= 1;
                break;
502 503 504
            case 'm':
                fSaveNames ^= 1;
                break;
Alan Mishchenko committed
505 506 507
            case 'a':
                fReadAsAig ^= 1;
                break;
Alan Mishchenko committed
508 509 510 511 512 513 514 515 516
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
517
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
518 519
        goto usage;
    // get the input file name
Alan Mishchenko committed
520 521 522 523
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    if ( fReadAsAig )
        pNtk = Io_ReadBlifAsAig( pFileName, fCheck );
524
    else if ( fUseNewParser )
525
        pNtk = Io_Read( pFileName, IO_FILE_BLIF, fCheck, 0 );
Alan Mishchenko committed
526
    else
Alan Mishchenko committed
527
    {
Alan Mishchenko committed
528 529 530 531
        Abc_Ntk_t * pTemp;
        pNtk = Io_ReadBlif( pFileName, fCheck );
        if ( pNtk == NULL )
            return 1;
532 533
        if ( fSaveNames )
            Abc_NtkStartNameIds( pNtk );
Alan Mishchenko committed
534
        pNtk = Abc_NtkToLogic( pTemp = pNtk );
535 536
        if ( fSaveNames )
            Abc_NtkTransferNameIds( pTemp, pNtk );
Alan Mishchenko committed
537
        Abc_NtkDelete( pTemp );
Alan Mishchenko committed
538 539
    }

Alan Mishchenko committed
540 541 542 543
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
544
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
545 546 547
    return 0;

usage:
548
    fprintf( pAbc->Err, "usage: read_blif [-nmach] <file>\n" );
549 550 551
    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" );
552
    fprintf( pAbc->Err, "\t-m     : toggle saving original circuit names into a file [default = %s]\n", fSaveNames? "yes":"no" );
Alan Mishchenko committed
553
    fprintf( pAbc->Err, "\t-a     : toggle creating AIG while reading the file [default = %s]\n", fReadAsAig? "yes":"no" );
Alan Mishchenko committed
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
    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
571
int IoCommandReadBlifMv( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
572
{
Alan Mishchenko committed
573 574
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
575 576 577 578
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
579 580
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
581 582 583 584 585 586 587 588 589 590 591 592
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
593
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
594 595
        goto usage;
    // get the input file name
Alan Mishchenko committed
596 597
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
598
    pNtk = Io_Read( pFileName, IO_FILE_BLIFMV, fCheck, 0 );
Alan Mishchenko committed
599 600 601 602
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
603
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
604 605 606
    return 0;

usage:
Alan Mishchenko committed
607
    fprintf( pAbc->Err, "usage: read_blif_mv [-ch] <file>\n" );
608 609
    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
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
    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
627
int IoCommandReadBench( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
628
{
Alan Mishchenko committed
629 630
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
631 632 633 634
    int fCheck;
    int c;

    fCheck = 1;
Alan Mishchenko committed
635 636
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
637 638 639 640 641 642 643 644 645 646 647 648
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
649
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
650 651
        goto usage;
    // get the input file name
Alan Mishchenko committed
652 653
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
654
    pNtk = Io_Read( pFileName, IO_FILE_BENCH, fCheck, 0 );
Alan Mishchenko committed
655 656 657 658
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
659
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
660 661 662
    return 0;

usage:
Alan Mishchenko committed
663
    fprintf( pAbc->Err, "usage: read_bench [-ch] <file>\n" );
664
    fprintf( pAbc->Err, "\t         reads the network in BENCH format\n" );
Alan Mishchenko committed
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
    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
682
int IoCommandReadDsd( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
683
{
Alan Mishchenko committed
684 685
    Abc_Ntk_t * pNtk;
    char * pString;
Alan Mishchenko committed
686 687
    int fCheck;
    int c;
Alan Mishchenko committed
688
    extern Abc_Ntk_t * Io_ReadDsd( char * pFormula );
Alan Mishchenko committed
689 690

    fCheck = 1;
Alan Mishchenko committed
691 692
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
693 694 695 696 697 698 699 700 701 702 703 704
    {
        switch ( c )
        {
            case 'c':
                fCheck ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
705
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
706 707
        goto usage;
    // get the input file name
Alan Mishchenko committed
708 709 710
    pString = argv[globalUtilOptind];
    // read the file using the corresponding file reader
    pNtk = Io_ReadDsd( pString );
Alan Mishchenko committed
711 712 713 714
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
715
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
716 717 718
    return 0;

usage:
Alan Mishchenko committed
719 720 721 722 723 724 725 726 727 728
    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" );
729
    fprintf( pAbc->Err, "\t          No spaces are allowed in formulas. In parentheses, LSB goes first.\n" );
Alan Mishchenko committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
744
int IoCommandReadEdif( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
745
{
Alan Mishchenko committed
746
    Abc_Ntk_t * pNtk;
Alan Mishchenko committed
747 748
    char * pFileName;
    int fCheck;
Alan Mishchenko committed
749 750
    int c;

Alan Mishchenko committed
751 752 753
    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
754 755 756
    {
        switch ( c )
        {
Alan Mishchenko committed
757 758
            case 'c':
                fCheck ^= 1;
Alan Mishchenko committed
759 760 761 762 763 764 765
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
766
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
767
        goto usage;
Alan Mishchenko committed
768 769 770
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
771
    pNtk = Io_Read( pFileName, IO_FILE_EDIF, fCheck, 0 );
Alan Mishchenko committed
772 773 774 775
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
776
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
777 778 779
    return 0;

usage:
Alan Mishchenko committed
780
    fprintf( pAbc->Err, "usage: read_edif [-ch] <file>\n" );
781
    fprintf( pAbc->Err, "\t         reads the network in EDIF (works only for ISCAS benchmarks)\n" );
Alan Mishchenko committed
782 783 784
    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
785 786 787 788 789 790 791 792 793 794 795 796 797 798
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
799
int IoCommandReadEqn( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
800
{
Alan Mishchenko committed
801 802 803
    Abc_Ntk_t * pNtk;
    char * pFileName;
    int fCheck;
Alan Mishchenko committed
804 805
    int c;

Alan Mishchenko committed
806 807 808
    fCheck = 1;
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
Alan Mishchenko committed
809 810 811
    {
        switch ( c )
        {
Alan Mishchenko committed
812 813
            case 'c':
                fCheck ^= 1;
Alan Mishchenko committed
814 815 816 817 818 819 820
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
821
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
822 823
        goto usage;
    // get the input file name
Alan Mishchenko committed
824 825
    pFileName = argv[globalUtilOptind];
    // read the file using the corresponding file reader
826
    pNtk = Io_Read( pFileName, IO_FILE_EQN, fCheck, 0 );
Alan Mishchenko committed
827 828 829 830
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
831
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
832 833 834
    return 0;

usage:
Alan Mishchenko committed
835
    fprintf( pAbc->Err, "usage: read_eqn [-ch] <file>\n" );
836
    fprintf( pAbc->Err, "\t         reads the network in equation format\n" );
Alan Mishchenko committed
837 838 839
    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
840
    return 1;
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadFins( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern Vec_Int_t * Io_ReadFins( Abc_Ntk_t * pNtk, char * pFileName, int fVerbose );
    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
    char * pFileName;
    int c, fVerbose = 0;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
    {
        switch ( c )
        {
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // check current network
    if ( pNtk == NULL )
    {
        Abc_Print( -1, "Empty network.\n" );
        return 1;
    }
    // compute information and save it in the network
    Vec_IntFreeP( &pNtk->vFins );
    pNtk->vFins = Io_ReadFins( pNtk, pFileName, fVerbose );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_fins [-vh] <file>\n" );
    fprintf( pAbc->Err, "\t         reads the network in equation format\n" );
    fprintf( pAbc->Err, "\t-v     : enable verbose output [default = %s].\n", fVerbose? "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
897 898 899 900 901 902 903 904 905 906 907 908 909
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
910
int IoCommandReadInit( Abc_Frame_t * pAbc, int argc, char ** argv )
Alan Mishchenko committed
911
{
Alan Mishchenko committed
912 913 914
    FILE * pOut, * pErr;
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
915
    int c;
Alan Mishchenko committed
916 917 918 919

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

Alan Mishchenko committed
921 922
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
923 924 925 926 927 928 929 930 931
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
932
    if ( argc != globalUtilOptind && argc != globalUtilOptind + 1 )
Alan Mishchenko committed
933 934
        goto usage;

Alan Mishchenko committed
935
    if ( pNtk == NULL )
Alan Mishchenko committed
936
    {
Alan Mishchenko committed
937
        fprintf( pErr, "Empty network.\n" );
Alan Mishchenko committed
938 939
        return 1;
    }
Alan Mishchenko committed
940
    // get the input file name
Alan Mishchenko committed
941 942 943 944 945 946 947 948 949 950
    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
951 952 953 954 955
    // read the file using the corresponding file reader
    pNtk = Abc_NtkDup( pNtk );
    Io_ReadBenchInit( pNtk, pFileName );
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
956
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
957 958 959
    return 0;

usage:
Alan Mishchenko committed
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
    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;
982
    int c, fZeros = 0, fBoth = 0, fOnDc = 0, fSkipPrepro = 0, fCheck = 1;
Alan Mishchenko committed
983 984

    Extra_UtilGetoptReset();
985
    while ( ( c = Extra_UtilGetopt( argc, argv, "zbdxch" ) ) != EOF )
Alan Mishchenko committed
986 987 988
    {
        switch ( c )
        {
Alan Mishchenko committed
989 990 991
            case 'z':
                fZeros ^= 1;
                break;
992 993 994
            case 'b':
                fBoth ^= 1;
                break;
995 996 997
            case 'd':
                fOnDc ^= 1;
                break;
998 999 1000
            case 'x':
                fSkipPrepro ^= 1;
                break;
Alan Mishchenko committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
            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
1015
    if ( fZeros || fBoth || fOnDc || fSkipPrepro )
Alan Mishchenko committed
1016 1017
    {
        Abc_Ntk_t * pTemp;
1018
        pNtk = Io_ReadPla( pFileName, fZeros, fBoth, fOnDc, fSkipPrepro, fCheck );
Alan Mishchenko committed
1019 1020 1021 1022 1023 1024 1025 1026 1027
        if ( pNtk == NULL )
        {
            printf( "Reading PLA file has failed.\n" );
            return 1;
        }
        pNtk = Abc_NtkToLogic( pTemp = pNtk );
        Abc_NtkDelete( pTemp );
    }
    else
1028
        pNtk = Io_Read( pFileName, IO_FILE_PLA, fCheck, 0 );
Alan Mishchenko committed
1029 1030 1031 1032
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
1033
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
1034 1035 1036
    return 0;

usage:
1037
    fprintf( pAbc->Err, "usage: read_pla [-zbdxch] <file>\n" );
1038
    fprintf( pAbc->Err, "\t         reads the network in PLA\n" );
Alan Mishchenko committed
1039
    fprintf( pAbc->Err, "\t-z     : toggle reading on-set and off-set [default = %s]\n", fZeros? "off-set":"on-set" );
1040
    fprintf( pAbc->Err, "\t-b     : toggle reading both on-set and off-set as on-set [default = %s]\n", fBoth? "off-set":"on-set" );
1041
    fprintf( pAbc->Err, "\t-d     : toggle reading both on-set and dc-set as on-set [default = %s]\n", fOnDc? "off-set":"on-set" );
1042
    fprintf( pAbc->Err, "\t-x     : toggle reading Exclusive SOP rather than SOP [default = %s]\n", fSkipPrepro? "yes":"no" );
Alan Mishchenko committed
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
    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     []

***********************************************************************/
1060 1061
int IoCommandReadPlaMo( Abc_Frame_t * pAbc, int argc, char ** argv )
{
1062
    extern Abc_Ntk_t * Mop_ManTest( char * pFileName, int fMerge, int fVerbose );
1063
    Abc_Ntk_t * pNtk;
1064
    int c, fMerge = 0, fVerbose = 0;
1065
    Extra_UtilGetoptReset();
1066
    while ( ( c = Extra_UtilGetopt( argc, argv, "mvh" ) ) != EOF )
1067 1068 1069
    {
        switch ( c )
        {
1070 1071 1072
            case 'm':
                fMerge ^= 1;
                break;
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
            case 'v':
                fVerbose ^= 1;
                break;
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
1085
    pNtk = Mop_ManTest( argv[globalUtilOptind], fMerge, fVerbose );
1086 1087 1088 1089 1090 1091 1092 1093
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
    Abc_FrameClearVerifStatus( pAbc );
    return 0;

usage:
1094
    fprintf( pAbc->Err, "usage: read_plamo [-mvh] <file>\n" );
1095
    fprintf( pAbc->Err, "\t         reads the network in multi-output PLA\n" );
1096
    fprintf( pAbc->Err, "\t-m     : toggle dist-1 merge for cubes with identical outputs [default = %s]\n", fMerge? "yes":"no" );
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
    fprintf( pAbc->Err, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "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
1114 1115 1116
int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk;
1117
    char * pStr = NULL;
1118
    Vec_Ptr_t * vSops;
1119 1120
    int fHex  = 1;
    int fFile = 0;
Alan Mishchenko committed
1121 1122 1123
    int c;

    Extra_UtilGetoptReset();
1124
    while ( ( c = Extra_UtilGetopt( argc, argv, "xfh" ) ) != EOF )
Alan Mishchenko committed
1125 1126 1127 1128 1129 1130
    {
        switch ( c )
        {
            case 'x':
                fHex ^= 1;
                break;
1131 1132 1133
            case 'f':
                fFile ^= 1;
                break;
Alan Mishchenko committed
1134 1135 1136 1137 1138 1139 1140 1141 1142
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }

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

    if ( fFile )
1145 1146 1147 1148 1149 1150 1151 1152 1153
    {
        FILE * pFile = fopen( argv[globalUtilOptind], "rb" );
        if ( pFile == NULL )
        {
            printf( "The file \"%s\" cannot be found.\n", argv[globalUtilOptind] );
            return 1;
        }
        else 
            fclose( pFile );
1154
        pStr = Extra_FileReadContents( argv[globalUtilOptind] );
1155
    }
1156 1157
    else
        pStr = argv[globalUtilOptind];
Alan Mishchenko committed
1158 1159 1160

    // convert truth table to SOP
    if ( fHex )
1161
        vSops = Abc_SopFromTruthsHex(pStr);
Alan Mishchenko committed
1162
    else
1163
        vSops = Abc_SopFromTruthsBin(pStr);
1164 1165
    if ( fFile )
        ABC_FREE( pStr );
1166
    if ( Vec_PtrSize(vSops) == 0 )
Alan Mishchenko committed
1167
    {
1168
        Vec_PtrFreeFree( vSops );
Alan Mishchenko committed
1169 1170 1171 1172
        fprintf( pAbc->Err, "Reading truth table has failed.\n" );
        return 1;
    }

1173 1174
    pNtk = Abc_NtkCreateWithNodes( vSops );
    Vec_PtrFreeFree( vSops );
Alan Mishchenko committed
1175 1176 1177 1178 1179 1180 1181
    if ( pNtk == NULL )
    {
        fprintf( pAbc->Err, "Deriving the network has failed.\n" );
        return 1;
    }
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
1182
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
1183 1184 1185
    return 0;

usage:
1186
    fprintf( pAbc->Err, "usage: read_truth [-xfh] <truth> <file>\n" );
1187 1188 1189
    fprintf( pAbc->Err, "\t         creates network with node(s) having given truth table(s)\n" );
    fprintf( pAbc->Err, "\t-x     : toggles between bin and hex notation [default = %s]\n", fHex?  "hex":"bin" );
    fprintf( pAbc->Err, "\t-f     : toggles reading truth table(s) from file [default = %s]\n",      fFile? "yes": "no" );
Alan Mishchenko committed
1190 1191
    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" );
1192
    fprintf( pAbc->Err, "\tfile   : file name with the truth table\n" );
Alan Mishchenko committed
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadVerilog( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk;
    char * pFileName;
1211
    int fCheck, fBarBufs;
Alan Mishchenko committed
1212 1213 1214
    int c;

    fCheck = 1;
1215
    fBarBufs = 0;
Alan Mishchenko committed
1216 1217
    glo_fMapped = 0;
    Extra_UtilGetoptReset();
1218
    while ( ( c = Extra_UtilGetopt( argc, argv, "mcbh" ) ) != EOF )
Alan Mishchenko committed
1219 1220 1221 1222 1223 1224 1225 1226 1227
    {
        switch ( c )
        {
            case 'm':
                glo_fMapped ^= 1;
                break;
            case 'c':
                fCheck ^= 1;
                break;
1228 1229 1230
            case 'b':
                fBarBufs ^= 1;
                break;
Alan Mishchenko committed
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
            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
1242
    pNtk = Io_Read( pFileName, IO_FILE_VERILOG, fCheck, fBarBufs );
Alan Mishchenko committed
1243 1244 1245 1246
    if ( pNtk == NULL )
        return 1;
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
1247
    Abc_FrameClearVerifStatus( pAbc );
Alan Mishchenko committed
1248 1249 1250
    return 0;

usage:
1251
    fprintf( pAbc->Err, "usage: read_verilog [-mcbh] <file>\n" );
1252
    fprintf( pAbc->Err, "\t         reads the network in Verilog (IWLS 2002/2005 subset)\n" );
Alan Mishchenko committed
1253 1254
    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" );
1255
    fprintf( pAbc->Err, "\t-b     : toggle reading barrier buffers [default = %s]\n", fBarBufs? "yes":"no" );
Alan Mishchenko committed
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
    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     []

***********************************************************************/
1272 1273 1274 1275 1276
int IoCommandReadStatus( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    char * pFileName;
    FILE * pFile;
    int c;
1277
    extern int Abc_NtkReadLogFile( char * pFileName, Abc_Cex_t ** ppCex, int * pnFrames );
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

    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 );
1306
    pAbc->Status = Abc_NtkReadLogFile( pFileName, &pAbc->pCex, &pAbc->nFrames );
1307 1308 1309 1310 1311 1312 1313
    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" );
1314 1315 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 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
    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 );
Alan Mishchenko committed
1363
    Abc_FrameUpdateGia( pAbc, pAig );
1364 1365 1366 1367 1368 1369 1370
    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" );
1371 1372 1373
    return 1;
}

1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadJson( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern Vec_Wec_t * Json_Read( char * pFileName, Abc_Nam_t ** ppStrs );
    Vec_Wec_t * vObjs;
    Abc_Nam_t * pStrs;
    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
    vObjs = Json_Read( pFileName, &pStrs );
    if ( vObjs == NULL )
        return 0;
    Abc_FrameSetJsonStrs( pStrs );
    Abc_FrameSetJsonObjs( vObjs );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_json [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         reads file in JSON 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;
}

1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandReadSF( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    extern void Io_TransformSF2PLA( char * pNameIn, char * pNameOut );

    Abc_Ntk_t * pNtk;
    FILE * pFile;
    char * pFileName, * pFileTemp = "_temp_sf_.pla";
    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 );
    Io_TransformSF2PLA( pFileName, pFileTemp );
    pNtk = Io_Read( pFileTemp, IO_FILE_PLA, 1, 0 );
    unlink( pFileTemp );
    if ( pNtk == NULL )
        return 1;
    ABC_FREE( pNtk->pName );
    pNtk->pName = Extra_FileNameGeneric( pFileName );
    ABC_FREE( pNtk->pSpec );
    pNtk->pSpec = Abc_UtilStrsav( pFileName );
    // replace the current network
    Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
    Abc_FrameClearVerifStatus( pAbc );

    return 0;

usage:
    fprintf( pAbc->Err, "usage: read_sf [-h] <file>\n" );
    fprintf( pAbc->Err, "\t         reads file in SF 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;
}

1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
1514 1515
int IoCommandWrite( Abc_Frame_t * pAbc, int argc, char **argv )
{
1516
    char Command[1000];
Alan Mishchenko committed
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
    char * pFileName;
    int c;

    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541
    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 );
1542 1543
    else if ( !strcmp( Extra_FileNameExtension(pFileName), "dsd" ) )
        sprintf( Command, "dsd_save %s", pFileName );
1544 1545 1546 1547 1548
    if ( Command[0] )
    {
        Cmd_CommandExecute( pAbc, Command );
        return 0;
    }
Alan Mishchenko committed
1549 1550 1551 1552 1553
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
    // 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
1598 1599 1600 1601 1602
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
    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;
1640 1641
    int fUnique;
    int fVerbose;
Alan Mishchenko committed
1642 1643 1644
    int c;

    fWriteSymbols = 0;
1645
    fCompact      = 0;
1646 1647
    fUnique       = 0;
    fVerbose      = 0;
Alan Mishchenko committed
1648
    Extra_UtilGetoptReset();
1649
    while ( ( c = Extra_UtilGetopt( argc, argv, "scuvh" ) ) != EOF )
Alan Mishchenko committed
1650 1651 1652 1653 1654 1655 1656 1657 1658
    {
        switch ( c )
        {
            case 's':
                fWriteSymbols ^= 1;
                break;
            case 'c':
                fCompact ^= 1;
                break;
1659 1660 1661 1662 1663 1664
            case 'u':
                fUnique ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
Alan Mishchenko committed
1665 1666 1667 1668 1669 1670
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1671 1672 1673 1674 1675
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
    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;
    }
1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
    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
1700 1701 1702
    return 0;

usage:
1703
    fprintf( pAbc->Err, "usage: write_aiger [-scuvh] <file>\n" );
1704
    fprintf( pAbc->Err, "\t         writes the network in the AIGER format (http://fmv.jku.at/aiger)\n" );
Alan Mishchenko committed
1705 1706
    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" );
1707 1708
    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
1709 1710 1711 1712 1713 1714
    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*************************************************************
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760

  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
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786

  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
1787 1788 1789 1790 1791
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
    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" );
1802
    fprintf( pAbc->Err, "\t         writes the network into a BLIF file\n" );
Alan Mishchenko committed
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818
    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
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
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" );
1850
    fprintf( pAbc->Err, "\t         writes the network into a binary BLIF file\n" );
Alan Mishchenko committed
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
    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
1867 1868 1869
int IoCommandWriteBlif( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
1870
    char * pLutStruct = NULL;
Alan Mishchenko committed
1871
    int c, fSpecial = 0;
1872
    int fUseHie = 0;
Alan Mishchenko committed
1873 1874

    Extra_UtilGetoptReset();
1875
    while ( ( c = Extra_UtilGetopt( argc, argv, "Sjah" ) ) != EOF )
Alan Mishchenko committed
1876 1877 1878
    {
        switch ( c )
        {
1879 1880 1881 1882 1883 1884 1885 1886
            case 'S':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-S\" should be followed by string.\n" );
                    goto usage;
                }
                pLutStruct = argv[globalUtilOptind];
                globalUtilOptind++;
1887
                if ( strlen(pLutStruct) != 2 && strlen(pLutStruct) != 3 ) 
1888 1889 1890 1891 1892
                {
                    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
1893 1894 1895
            case 'j':
                fSpecial ^= 1;
                break;
1896 1897 1898
            case 'a':
                fUseHie ^= 1;
                break;
Alan Mishchenko committed
1899 1900 1901 1902 1903 1904
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
1905 1906 1907 1908 1909
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1910 1911 1912 1913 1914
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
1915
    if ( fSpecial || pLutStruct )
1916
        Io_WriteBlifSpecial( pAbc->pNtkCur, pFileName, pLutStruct, fUseHie );
1917
    else
Alan Mishchenko committed
1918
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BLIF );
Alan Mishchenko committed
1919 1920 1921
    return 0;

usage:
1922
    fprintf( pAbc->Err, "usage: write_blif [-S str] [-jah] <file>\n" );
1923
    fprintf( pAbc->Err, "\t         writes the network into a BLIF file\n" );
1924
    fprintf( pAbc->Err, "\t-S str : string representing the LUT structure [default = %s]\n", pLutStruct ? pLutStruct : "not used" );  
Alan Mishchenko committed
1925
    fprintf( pAbc->Err, "\t-j     : enables special BLIF writing [default = %s]\n", fSpecial? "yes" : "no" );;
1926
    fprintf( pAbc->Err, "\t-a     : enables hierarchical BLIF writing for LUT structures [default = %s]\n", fUseHie? "yes" : "no" );;
Alan Mishchenko committed
1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
    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
1959 1960 1961 1962 1963
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
1964 1965 1966 1967 1968 1969 1970 1971 1972 1973
    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" );
1974
    fprintf( pAbc->Err, "\t         writes the network into a BLIF-MV file\n" );
Alan Mishchenko committed
1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
    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
2012 2013 2014 2015 2016
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2017 2018 2019 2020 2021 2022 2023
    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
2024
    else if ( pAbc->pNtkCur )
Alan Mishchenko committed
2025 2026 2027 2028 2029 2030 2031
    {
        Abc_Ntk_t * pNtkTemp;
        pNtkTemp = Abc_NtkToNetlist( pAbc->pNtkCur );
        Abc_NtkToAig( pNtkTemp );
        Io_WriteBenchLut( pNtkTemp, pFileName );
        Abc_NtkDelete( pNtkTemp );
    }
Alan Mishchenko committed
2032 2033
    else
        printf( "There is no current network.\n" );
Alan Mishchenko committed
2034 2035 2036 2037
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_bench [-lh] <file>\n" );
2038
    fprintf( pAbc->Err, "\t         writes the network in BENCH format\n" );
Alan Mishchenko committed
2039 2040 2041
    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
2042 2043 2044 2045 2046 2047 2048 2049 2050
    return 1;
}

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

  Synopsis    []

  Description []
               
Alan Mishchenko committed
2051
  SideEffects []
Alan Mishchenko committed
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080

  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" );
2081
    fprintf( pAbc->Err, "\t-h     : prints the help massage\n" );
Alan Mishchenko committed
2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094
    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
2095 2096 2097 2098

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
2099
int IoCommandWriteCellNet( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
2100
{
Alan Mishchenko committed
2101 2102
    Abc_Ntk_t * pNtk;
    char * pFileName;
Alan Mishchenko committed
2103
    int c;
Alan Mishchenko committed
2104
    extern void Io_WriteCellNet( Abc_Ntk_t * pNtk, char * pFileName );
Alan Mishchenko committed
2105

Alan Mishchenko committed
2106 2107
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
2108 2109 2110 2111 2112 2113 2114 2115 2116
    {
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
2117
    if ( pAbc->pNtkCur == NULL )
Alan Mishchenko committed
2118 2119 2120 2121
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2122 2123 2124
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    pNtk = pAbc->pNtkCur;
Alan Mishchenko committed
2125 2126 2127 2128
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
    if ( !Abc_NtkIsLogic(pNtk) )
Alan Mishchenko committed
2129
    {
Alan Mishchenko committed
2130
        fprintf( pAbc->Out, "The network should be a logic network (if it an AIG, use command \"logic\")\n" );
Alan Mishchenko committed
2131 2132
        return 0;
    }
Alan Mishchenko committed
2133 2134 2135 2136 2137
    Io_WriteCellNet( pNtk, pFileName );
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_cellnet [-h] <file>\n" );
2138
    fprintf( pAbc->Err, "\t         writes the network is the cellnet format\n" );
Alan Mishchenko committed
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152
    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
2153

Alan Mishchenko committed
2154 2155 2156 2157 2158 2159
***********************************************************************/
int IoCommandWriteCnf( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
    int fNewAlgo;
2160 2161 2162 2163 2164
    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
2165 2166

    fNewAlgo = 1;
2167
    fFastAlgo = 0;
Alan Mishchenko committed
2168
    fAllPrimes = 0;
2169 2170
    fChangePol = 1;
    fVerbose = 0;
Alan Mishchenko committed
2171
    Extra_UtilGetoptReset();
2172
    while ( ( c = Extra_UtilGetopt( argc, argv, "nfpcvh" ) ) != EOF )
Alan Mishchenko committed
2173
    {
Alan Mishchenko committed
2174 2175 2176 2177 2178
        switch ( c )
        {
            case 'n':
                fNewAlgo ^= 1;
                break;
2179 2180 2181
            case 'f':
                fFastAlgo ^= 1;
                break;
Alan Mishchenko committed
2182 2183 2184
            case 'p':
                fAllPrimes ^= 1;
                break;
2185 2186 2187 2188 2189 2190
            case 'c':
                fChangePol ^= 1;
                break;
            case 'v':
                fVerbose ^= 1;
                break;
Alan Mishchenko committed
2191 2192 2193 2194 2195
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2196
    }
Alan Mishchenko committed
2197 2198 2199 2200 2201
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212
    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
2213 2214 2215 2216
    if ( fFastAlgo )
        Abc_NtkDarToCnf( pAbc->pNtkCur, pFileName, 1, fChangePol, fVerbose );
    else if ( fNewAlgo )
        Abc_NtkDarToCnf( pAbc->pNtkCur, pFileName, 0, fChangePol, fVerbose );
Alan Mishchenko committed
2217 2218 2219 2220 2221
    else if ( fAllPrimes )
        Io_WriteCnf( pAbc->pNtkCur, pFileName, 1 );
    else
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_CNF );
    return 0;
Alan Mishchenko committed
2222

Alan Mishchenko committed
2223
usage:
2224
    fprintf( pAbc->Err, "usage: write_cnf [-nfpcvh] <file>\n" );
2225
    fprintf( pAbc->Err, "\t         generates CNF for the miter (see also \"&write_cnf\")\n" );
Alan Mishchenko committed
2226
    fprintf( pAbc->Err, "\t-n     : toggle using new algorithm [default = %s]\n", fNewAlgo? "yes" : "no" );
2227
    fprintf( pAbc->Err, "\t-f     : toggle using fast algorithm [default = %s]\n", fFastAlgo? "yes" : "no" );
Alan Mishchenko committed
2228
    fprintf( pAbc->Err, "\t-p     : toggle using all primes to enhance implicativity [default = %s]\n", fAllPrimes? "yes" : "no" );
2229 2230
    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
2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246
    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     []

***********************************************************************/
2247 2248
int IoCommandWriteCnf2( Abc_Frame_t * pAbc, int argc, char **argv )
{
2249
    extern void Jf_ManDumpCnf( Gia_Man_t * p, char * pFileName, int fVerbose );
2250
    extern void Mf_ManDumpCnf( Gia_Man_t * p, char * pFileName, int nLutSize, int fCnfObjIds, int fAddOrCla, int fVerbose );
2251 2252
    FILE * pFile;
    char * pFileName;
2253
    int nLutSize    = 8;
2254 2255 2256
    int fNewAlgo    = 1;
    int fCnfObjIds  = 0;
    int fAddOrCla   = 1;
2257 2258
    int c, fVerbose = 0;
    Extra_UtilGetoptReset();
2259
    while ( ( c = Extra_UtilGetopt( argc, argv, "Kaiovh" ) ) != EOF )
2260 2261 2262
    {
        switch ( c )
        {
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274
            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;
2275 2276 2277 2278 2279 2280
            case 'i':
                fCnfObjIds ^= 1;
                break;
            case 'o':
                fAddOrCla ^= 1;
                break;
2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299
            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;
    }
2300 2301 2302 2303 2304 2305
    if ( nLutSize < 3 || nLutSize > 8 )
    {
        Abc_Print( -1, "IoCommandWriteCnf2(): Invalid LUT size (%d).\n", nLutSize );
        return 0;
    }
    if ( !fNewAlgo && !Sdm_ManCanRead() )
2306 2307 2308 2309
    {
        Abc_Print( -1, "IoCommandWriteCnf2(): Cannot input precomputed DSD information.\n" );
        return 0;
    }
2310 2311 2312 2313 2314 2315 2316 2317 2318 2319
    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;
    }
2320 2321
    fclose( pFile );
    if ( fNewAlgo )
2322
        Mf_ManDumpCnf( pAbc->pGia, pFileName, nLutSize, fCnfObjIds, fAddOrCla, fVerbose );
2323 2324
    else
        Jf_ManDumpCnf( pAbc->pGia, pFileName, fVerbose );
2325 2326 2327
    return 0;

usage:
2328
    fprintf( pAbc->Err, "usage: &write_cnf [-Kaiovh] <file>\n" );
2329 2330 2331
    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" );
2332 2333
    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" );
2334 2335 2336
    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" );
2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347
    fprintf( pAbc->Err, "\n" );
    fprintf( pAbc->Err, "\t           CNF variable mapping rules:\n" );
    fprintf( pAbc->Err, "\n" );
    fprintf( pAbc->Err, "\t           Assume CNF has N variables, with variable IDs running from 0 to N-1.\n" );
    fprintf( pAbc->Err, "\t           Variable number 0 is not used in the CNF.\n" );
    fprintf( pAbc->Err, "\t           Variables 1, 2, 3,... <nPOs> represent POs in their natural order.\n" );
    fprintf( pAbc->Err, "\t           Variables N-<nPIs>, N-<nPIs>+1, N-<nPIs>+2, ... N-1, represent PIs in their natural order.\n" );
    fprintf( pAbc->Err, "\t           The internal variables are ordered in a reverse topological order from outputs to inputs.\n" );
    fprintf( pAbc->Err, "\t           That is, smaller variable IDs tend to be closer to the outputs, while larger\n" );
    fprintf( pAbc->Err, "\t           variable IDs tend to be closer to the inputs. It was found that this ordering\n" );
    fprintf( pAbc->Err, "\t           leads to faster SAT solving for hard UNSAT CEC problems.\n" );
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
    return 1;
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378
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
2379 2380 2381 2382 2383
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2384 2385 2386 2387 2388 2389
    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
2390 2391 2392 2393
    return 0;

usage:
    fprintf( pAbc->Err, "usage: write_dot [-h] <file>\n" );
2394
    fprintf( pAbc->Err, "\t         writes the current network into a DOT file\n" );
Alan Mishchenko committed
2395 2396 2397 2398 2399
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

2400 2401
ABC_NAMESPACE_IMPL_END

2402
#include "proof/fra/fra.h"
Alan Mishchenko committed
2403

2404 2405
ABC_NAMESPACE_IMPL_START

2406 2407 2408 2409 2410 2411 2412 2413
int Abc_NtkCheckSpecialPi( Abc_Ntk_t * pNtk )
{
    Abc_Obj_t * pObj;  int i;
    Abc_NtkForEachPi( pNtk, pObj, i )
        if ( !strcmp(Abc_ObjName(pObj), "_abc_190121_abc_") )
            return 1;
    return 0;
}
2414

Alan Mishchenko committed
2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451
void Abc_NtkDumpOneCexSpecial( FILE * pFile, Abc_Ntk_t * pNtk, Abc_Cex_t * pCex )
{
    Abc_Cex_t * pCare = NULL; int i, f; Abc_Obj_t * pObj;
    extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
    Aig_Man_t * pAig = Abc_NtkToDar( pNtk, 0, 1 );
    //fprintf( pFile, "# FALSIFYING OUTPUTS:");                                       
    //fprintf( pFile, " %s", Abc_ObjName(Abc_NtkCo(pNtk, pCex->iPo)) ); 
    pCare = Bmc_CexCareMinimize( pAig, Saig_ManPiNum(pAig), pCex, 4, 0, 0 );
    Aig_ManStop( pAig );
    if( pCare == NULL )   
    {
        printf( "Counter-example minimization has failed.\n" ); 
        return;
    }
    // output flop values (unaffected by the minimization)
    Abc_NtkForEachLatch( pNtk, pObj, i )
        fprintf( pFile, "CEX: %s@0=%c\n", Abc_ObjName(Abc_ObjFanout0(pObj)), '0'+!Abc_LatchIsInit0(pObj) );
    // output PI values (while skipping the minimized ones)
    for ( f = 0; f <= pCex->iFrame; f++ )
        Abc_NtkForEachPi( pNtk, pObj, i )
            if ( !pCare || Abc_InfoHasBit(pCare->pData, pCare->nRegs+pCare->nPis*f + i) )
                fprintf( pFile, "CEX: %s@%d=%c\n", Abc_ObjName(pObj), f, '0'+Abc_InfoHasBit(pCex->pData, pCex->nRegs+pCex->nPis*f + i) );
    Abc_CexFreeP( &pCare );
}


2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576
void Abc_NtkDumpOneCex( FILE * pFile, Abc_Ntk_t * pNtk, Abc_Cex_t * pCex, 
    int fPrintFull, int fNames, int fUseFfNames, int fMinimize, int fUseOldMin, 
    int fCheckCex, int fUseSatBased, int fHighEffort, int fAiger, int fVerbose )
{
    Abc_Obj_t * pObj;
    int i, f;
    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 )
    {
        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 );
            fprintf( pFile, "# FALSIFYING OUTPUTS:");                                       
            fprintf( pFile, " %s", Abc_ObjName(Abc_NtkCo(pNtk, pCex->iPo)) ); 
            if ( fUseOldMin )
            {
                pCare = Saig_ManCbaFindCexCareBits( pAig, pCex, 0, fVerbose );
                if ( fCheckCex )
                    Bmc_CexCareVerify( pAig, pCex, pCare, fVerbose );
            }
            else if ( fUseSatBased )
                pCare = Bmc_CexCareSatBasedMinimize( pAig, Saig_ManPiNum(pAig), pCex, fHighEffort, fCheckCex, fVerbose );
            else
                pCare = Bmc_CexCareMinimize( pAig, Saig_ManPiNum(pAig), pCex, 4, fCheckCex, fVerbose );
            Aig_ManStop( pAig );
            if(pCare == NULL)                                           
                printf( "Counter-example minimization has failed.\n" ); 
        }
        else
        {
            fprintf( pFile, "# FALSIFYING OUTPUTS:");                        
            fprintf( pFile, " %s", Abc_ObjName(Abc_NtkCo(pNtk, pCex->iPo)) );
        }
        fprintf( pFile, "\n");                                           
        fprintf( pFile, "# COUNTEREXAMPLE LENGTH: %u\n", pCex->iFrame+1);
        if ( fUseFfNames && Abc_NtkCheckSpecialPi(pNtk) )
        {
            int * pValues;
            int nXValues = 0, iFlop = 0, iPivotPi = -1;
            Abc_NtkForEachPi( pNtk, pObj, iPivotPi )
                if ( !strcmp(Abc_ObjName(pObj), "_abc_190121_abc_") )
                    break;
            if ( iPivotPi == Abc_NtkPiNum(pNtk) )
            {
                fprintf( stdout, "IoCommandWriteCex(): Cannot find special PI required by switch \"-z\".\n" );
                return;
            }
            // count X-valued flops
            for ( i = iPivotPi+1; i < Abc_NtkPiNum(pNtk); i++ )
                if ( Abc_ObjName(Abc_NtkPi(pNtk, i))[0] == 'x' )
                    nXValues++;
            // map X-valued flops into auxiliary PIs
            pValues = ABC_FALLOC( int, Abc_NtkPiNum(pNtk) );
            for ( i = iPivotPi+1; i < Abc_NtkPiNum(pNtk); i++ )
                if ( Abc_ObjName(Abc_NtkPi(pNtk, i))[0] == 'x' )
                    pValues[i] = iPivotPi - nXValues + iFlop++;
            assert( iFlop == nXValues );
            // write flop values
            for ( i = iPivotPi+1; i < Abc_NtkPiNum(pNtk); i++ )
                if ( pValues[i] == -1 )
                    fprintf( pFile, "%s@0=%c\n", Abc_ObjName(Abc_NtkPi(pNtk, i))+1, Abc_ObjName(Abc_NtkPi(pNtk, i))[0] );
                else if ( Abc_InfoHasBit(pCare->pData, pCare->nRegs + pValues[i]) )
                    fprintf( pFile, "%s@0=%c\n", Abc_ObjName(Abc_NtkPi(pNtk, i))+1, '0'+Abc_InfoHasBit(pCex->pData, pCex->nRegs + pValues[i]) );
            ABC_FREE( pValues );
            // output PI values (while skipping the minimized ones)
            for ( f = 0; f <= pCex->iFrame; f++ )
                Abc_NtkForEachPi( pNtk, pObj, i )
                {
                    if ( i == iPivotPi - nXValues ) break;
                    if ( !pCare || Abc_InfoHasBit(pCare->pData, pCare->nRegs+pCare->nPis*f + i) )
                        fprintf( pFile, "%s@%d=%c\n", Abc_ObjName(pObj), f, '0'+Abc_InfoHasBit(pCex->pData, pCex->nRegs+pCex->nPis*f + i) );
                }
        }
        else
        {
            // output flop values (unaffected by the minimization)
            Abc_NtkForEachLatch( pNtk, pObj, i )
                fprintf( pFile, "%s@0=%c\n", Abc_ObjName(Abc_ObjFanout0(pObj)), '0'+!Abc_LatchIsInit0(pObj) );
            // output PI values (while skipping the minimized ones)
            for ( f = 0; f <= pCex->iFrame; f++ )
                Abc_NtkForEachPi( pNtk, pObj, i )
                    if ( !pCare || Abc_InfoHasBit(pCare->pData, pCare->nRegs+pCare->nPis*f + i) )
                        fprintf( pFile, "%s@%d=%c\n", Abc_ObjName(pObj), f, '0'+Abc_InfoHasBit(pCex->pData, pCex->nRegs+pCex->nPis*f + i) );
        }
        Abc_CexFreeP( &pCare );
    }
    else
    {
        Abc_NtkForEachLatch( pNtk, pObj, i )
            fprintf( pFile, "%c", '0'+!Abc_LatchIsInit0(pObj) );

        for ( i = pCex->nRegs; i < pCex->nBits; i++ )
        {
            if ( fAiger && (i-pCex->nRegs)%pCex->nPis == 0)
                fprintf( pFile, "\n");
            fprintf( pFile, "%c", '0'+Abc_InfoHasBit(pCex->pData, i) );
        }
    }
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
2577
int IoCommandWriteCex( Abc_Frame_t * pAbc, int argc, char **argv )
Alan Mishchenko committed
2578
{
Alan Mishchenko committed
2579 2580
    Abc_Ntk_t * pNtk;
    char * pFileName;
2581 2582
    int c, fNames  = 0;
    int fMinimize  = 0;
2583 2584
    int fUseSatBased = 0;
    int fHighEffort = 0;
2585 2586
    int fUseOldMin = 0;
    int fCheckCex  = 0;
2587
    int forceSeq   = 0;
2588
    int fAiger     = 0;
2589
    int fPrintFull = 0;
2590
    int fUseFfNames = 0;
2591
    int fVerbose   = 0;
Alan Mishchenko committed
2592

Alan Mishchenko committed
2593
    Extra_UtilGetoptReset();
2594
    while ( ( c = Extra_UtilGetopt( argc, argv, "snmueocafzvh" ) ) != EOF )
Alan Mishchenko committed
2595 2596 2597
    {
        switch ( c )
        {
Alan Mishchenko committed
2598 2599 2600
            case 's':
                forceSeq ^= 1;
                break;
Alan Mishchenko committed
2601 2602 2603
            case 'n':
                fNames ^= 1;
                break;
2604 2605 2606
            case 'm':
                fMinimize ^= 1;
                break;
2607 2608 2609 2610 2611 2612
            case 'u':
                fUseSatBased ^= 1;
                break;
            case 'e':
                fHighEffort ^= 1;
                break;
2613 2614 2615 2616 2617 2618
            case 'o':
                fUseOldMin ^= 1;
                break;
            case 'c':
                fCheckCex ^= 1;
                break;
2619 2620 2621
            case 'a':
                fAiger ^= 1;
                break;
2622 2623 2624
            case 'f':
                fPrintFull ^= 1;
                break;
2625 2626 2627
            case 'z':
                fUseFfNames ^= 1;
                break;
2628 2629 2630
            case 'v':
                fVerbose ^= 1;
                break;
Alan Mishchenko committed
2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    pNtk = pAbc->pNtkCur;
    if ( pNtk == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
2643
    if ( pNtk->pModel == NULL && pAbc->pCex == NULL && pAbc->vCexVec == NULL )
2644 2645 2646 2647
    {
        fprintf( pAbc->Out, "Counter-example is not available.\n" );
        return 0;
    }
Alan Mishchenko committed
2648
    if ( argc != globalUtilOptind + 1 )
Alan Mishchenko committed
2649
    {
Alan Mishchenko committed
2650
        printf( "File name is missing on the command line.\n" );
Alan Mishchenko committed
2651 2652
        goto usage;
    }
2653

Alan Mishchenko committed
2654 2655 2656
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // write the counter-example into the file
2657
    if ( pAbc->pCex || pAbc->vCexVec )
Alan Mishchenko committed
2658
    { 
2659
        Abc_Cex_t * pCex = pAbc->pCex;
2660
        FILE * pFile; int i;
2661
        /*
Alan Mishchenko committed
2662 2663 2664
        Abc_NtkForEachLatch( pNtk, pObj, i )
            if ( !Abc_LatchIsInit0(pObj) )
            {
2665
                fprintf( stdout, "IoCommandWriteCex(): The init-state should be all-0 for counter-example to work.\n" );
Alan Mishchenko committed
2666 2667 2668
                fprintf( stdout, "Run commands \"undc\" and \"zero\" and then rerun the equivalence check.\n" );
                return 1;
            }
2669
        */
Alan Mishchenko committed
2670 2671 2672
        pFile = fopen( pFileName, "w" );
        if ( pFile == NULL )
        {
2673
            fprintf( stdout, "IoCommandWriteCex(): Cannot open the output file \"%s\".\n", pFileName );
Alan Mishchenko committed
2674 2675
            return 1;
        }
2676
        if ( pAbc->pCex )
2677
        {
2678 2679 2680
            Abc_NtkDumpOneCex( pFile, pNtk, pCex, 
                fPrintFull, fNames, fUseFfNames, fMinimize, fUseOldMin, 
                fCheckCex, fUseSatBased, fHighEffort, fAiger, fVerbose );
Alan Mishchenko committed
2681
        }
2682
        else if ( pAbc->vCexVec )
Alan Mishchenko committed
2683
        {
2684
            Vec_PtrForEachEntry( Abc_Cex_t *, pAbc->vCexVec, pCex, i )
2685
            {
2686 2687
                if ( pCex == NULL )
                    continue;
2688
                fprintf( pFile, "#\n#\n# CEX for output %d\n#\n", i ); 
2689 2690 2691
                Abc_NtkDumpOneCex( pFile, pNtk, pCex, 
                    fPrintFull, fNames, fUseFfNames, fMinimize, fUseOldMin, 
                    fCheckCex, fUseSatBased, fHighEffort, fAiger, fVerbose );
2692
            }
Alan Mishchenko committed
2693
        }
2694
        fprintf( pFile, "# DONE\n" ); 
Alan Mishchenko committed
2695 2696 2697 2698 2699 2700 2701 2702 2703
        fclose( pFile );
    }
    else
    {
        Abc_Obj_t * pObj;
        FILE * pFile = fopen( pFileName, "w" );
        int i;
        if ( pFile == NULL )
        {
2704
            fprintf( stdout, "IoCommandWriteCex(): Cannot open the output file \"%s\".\n", pFileName );
Alan Mishchenko committed
2705 2706 2707 2708
            return 1;
        }
        if ( fNames )
        {
2709
            const char *cycle_ctr = forceSeq?"@0":"";
Alan Mishchenko committed
2710
            Abc_NtkForEachPi( pNtk, pObj, i )
Alan Mishchenko committed
2711 2712
//                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
2713 2714 2715 2716 2717 2718 2719
        }
        else
        {
            Abc_NtkForEachPi( pNtk, pObj, i )
                fprintf( pFile, "%c", '0'+(pNtk->pModel[i]==1) );
        }
        fprintf( pFile, "\n" );
Alan Mishchenko committed
2720 2721 2722 2723 2724 2725
        fclose( pFile );
    }

    return 0;

usage:
2726
    fprintf( pAbc->Err, "usage: write_cex [-snmueocfzvh] <file>\n" );
2727 2728 2729
    fprintf( pAbc->Err, "\t         saves counter-example (CEX) derived by \"sat\", \"iprove\", \"dprove\", etc\n" );
    fprintf( pAbc->Err, "\t         the output file <file> contains values for each PI in natural order\n" );
    fprintf( pAbc->Err, "\t-s     : always report a sequential CEX (cycle 0 for comb) [default = %s]\n", forceSeq? "yes": "no" );
Alan Mishchenko committed
2730
    fprintf( pAbc->Err, "\t-n     : write input names into the file [default = %s]\n", fNames? "yes": "no" );
2731 2732
    fprintf( pAbc->Err, "\t-m     : minimize CEX by dropping don't-care values [default = %s]\n", fMinimize? "yes": "no" );
    fprintf( pAbc->Err, "\t-u     : use fast SAT-based CEX minimization [default = %s]\n", fUseSatBased? "yes": "no" );
2733 2734 2735
    fprintf( pAbc->Err, "\t-e     : use high-effort SAT-based CEX minimization [default = %s]\n", fHighEffort? "yes": "no" );
    fprintf( pAbc->Err, "\t-o     : use old CEX minimization algorithm [default = %s]\n", fUseOldMin? "yes": "no" );
    fprintf( pAbc->Err, "\t-c     : check generated CEX using ternary simulation [default = %s]\n", fCheckCex? "yes": "no" );
2736 2737 2738 2739
    fprintf( pAbc->Err, "\t-a     : print cex in AIGER 1.9 format [default = %s]\n", fAiger? "yes": "no" );
    fprintf( pAbc->Err, "\t-f     : enable printing flop values in each timeframe [default = %s]\n", fPrintFull? "yes": "no" );  
    fprintf( pAbc->Err, "\t-z     : toggle using saved flop names [default = %s]\n", fUseFfNames? "yes": "no" );  
    fprintf( pAbc->Err, "\t-v     : enable verbose output [default = %s]\n", fVerbose? "yes": "no" );  
Alan Mishchenko committed
2740
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
2741
    fprintf( pAbc->Err, "\t<file> : the name of the file to write\n" );
Alan Mishchenko committed
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770
    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
2771
    }
Alan Mishchenko committed
2772 2773 2774 2775 2776
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2777 2778 2779 2780 2781 2782
    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
2783
    return 0;
Alan Mishchenko committed
2784

Alan Mishchenko committed
2785 2786
usage:
    fprintf( pAbc->Err, "usage: write_eqn [-h] <file>\n" );
2787
    fprintf( pAbc->Err, "\t         writes the current network in the equation format\n" );
Alan Mishchenko committed
2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805
    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
2806
    char * pFileName;
Alan Mishchenko committed
2807
    int c;
Alan Mishchenko committed
2808

Alan Mishchenko committed
2809 2810
    Extra_UtilGetoptReset();
    while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
Alan Mishchenko committed
2811
    {
Alan Mishchenko committed
2812 2813 2814 2815 2816 2817 2818
        switch ( c )
        {
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
2819
    }
Alan Mishchenko committed
2820 2821 2822 2823 2824
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2825 2826 2827 2828 2829 2830 2831 2832 2833 2834
    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" );
2835
    fprintf( pAbc->Err, "\t         writes network using graph representation formal GML\n" );
Alan Mishchenko committed
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
    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
2860

Alan Mishchenko committed
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875
    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
2876 2877 2878 2879 2880
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2881 2882
    if ( argc != globalUtilOptind + 1 )
        goto usage;
Alan Mishchenko committed
2883 2884
/*
    if ( !Abc_NtkIsSeq(pAbc->pNtkCur) )
Alan Mishchenko committed
2885
    {
Alan Mishchenko committed
2886
        fprintf( stdout, "IoCommandWriteList(): Can write adjacency list for sequential AIGs only.\n" );
Alan Mishchenko committed
2887 2888
        return 0;
    }
Alan Mishchenko committed
2889
*/
Alan Mishchenko committed
2890
    // get the input file name
Alan Mishchenko committed
2891
    pFileName = argv[globalUtilOptind];
Alan Mishchenko committed
2892
    // write the file
Alan Mishchenko committed
2893
    Io_WriteList( pAbc->pNtkCur, pFileName, fUseHost );
Alan Mishchenko committed
2894 2895 2896
    return 0;

usage:
Alan Mishchenko committed
2897
    fprintf( pAbc->Err, "usage: write_list [-nh] <file>\n" );
2898
    fprintf( pAbc->Err, "\t         writes network using graph representation formal GML\n" );
Alan Mishchenko committed
2899
    fprintf( pAbc->Err, "\t-n     : toggle writing host node [default = %s]\n", fUseHost? "yes":"no" );
Alan Mishchenko committed
2900 2901
    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
2902 2903 2904
    return 1;
}

Alan Mishchenko committed
2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWritePla( Abc_Frame_t * pAbc, int argc, char **argv )
{
2918
    extern int Io_WriteMoPlaM( Abc_Ntk_t * pNtk, char * pFileName, int nMints );
Alan Mishchenko committed
2919
    char * pFileName;
2920
    int c, fUseMoPla = 0, nMints = 0;
Alan Mishchenko committed
2921

Alan Mishchenko committed
2922
    Extra_UtilGetoptReset();
2923
    while ( ( c = Extra_UtilGetopt( argc, argv, "Mmh" ) ) != EOF )
Alan Mishchenko committed
2924 2925 2926
    {
        switch ( c )
        {
2927 2928 2929 2930 2931 2932 2933 2934 2935
            case 'M':
                if ( globalUtilOptind >= argc )
                {
                    Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
                    goto usage;
                }
                nMints = atoi(argv[globalUtilOptind]);
                globalUtilOptind++;
                break;
2936 2937 2938
            case 'm':
                fUseMoPla ^= 1;
                break;
Alan Mishchenko committed
2939 2940 2941 2942 2943 2944
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
Alan Mishchenko committed
2945 2946 2947 2948 2949
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
2950 2951 2952 2953 2954
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967
    if ( nMints )
    {
        if ( Abc_NtkIsBddLogic(pAbc->pNtkCur) )
            Io_WriteMoPlaM( pAbc->pNtkCur, pFileName, nMints );
        else
        {
            Abc_Ntk_t * pStrash = Abc_NtkStrash( pAbc->pNtkCur, 0, 0, 0 );
            Io_WriteMoPlaM( pStrash, pFileName, nMints );
            Abc_NtkDelete( pStrash );
        }
    }
    else
        Io_Write( pAbc->pNtkCur, pFileName, fUseMoPla ? IO_FILE_MOPLA : IO_FILE_PLA );
Alan Mishchenko committed
2968
    return 0;
Alan Mishchenko committed
2969

Alan Mishchenko committed
2970
usage:
2971 2972 2973 2974 2975 2976
    fprintf( pAbc->Err, "usage: write_pla [-M <num>] [-mh] <file>\n" );
    fprintf( pAbc->Err, "\t           writes the collapsed network into a PLA file\n" );
    fprintf( pAbc->Err, "\t-M <num> : the number of on-set minterms to write [default = %d]\n", nMints );
    fprintf( pAbc->Err, "\t-m       : toggle writing multi-output PLA [default = %s]\n", fUseMoPla? "yes":"no" );
    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
2977 2978
    return 1;
}
Alan Mishchenko committed
2979

Alan Mishchenko committed
2980 2981 2982 2983 2984 2985 2986
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []
Alan Mishchenko committed
2987

Alan Mishchenko committed
2988 2989 2990 2991 2992
  SeeAlso     []

***********************************************************************/
int IoCommandWriteVerilog( Abc_Frame_t * pAbc, int argc, char **argv )
{
2993
    extern void Io_WriteVerilogLut( Abc_Ntk_t * pNtk, char * pFileName, int nLutSize, int fFixed, int fNoModules );
Alan Mishchenko committed
2994
    char * pFileName;
2995
    int c, fFixed = 0, fOnlyAnds = 0, fNoModules = 0;
2996
    int nLutSize = -1;
Alan Mishchenko committed
2997 2998

    Extra_UtilGetoptReset();
2999
    while ( ( c = Extra_UtilGetopt( argc, argv, "Kfamh" ) ) != EOF )
Alan Mishchenko committed
3000
    {
Alan Mishchenko committed
3001 3002
        switch ( c )
        {
3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013
            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++;
                if ( nLutSize < 2 || nLutSize > 6 )
                    goto usage;
                break;
3014 3015 3016
            case 'f':
                fFixed ^= 1;
                break;
3017 3018 3019
            case 'a':
                fOnlyAnds ^= 1;
                break;
3020 3021 3022
            case 'm':
                fNoModules ^= 1;
                break;
Alan Mishchenko committed
3023 3024 3025 3026 3027
            case 'h':
                goto usage;
            default:
                goto usage;
        }
Alan Mishchenko committed
3028
    }
Alan Mishchenko committed
3029 3030 3031 3032 3033
    if ( pAbc->pNtkCur == NULL )
    {
        fprintf( pAbc->Out, "Empty network.\n" );
        return 0;
    }
Alan Mishchenko committed
3034 3035
    if ( argc != globalUtilOptind + 1 )
        goto usage;
3036 3037
    if ( fFixed )
        nLutSize = 6;
Alan Mishchenko committed
3038 3039 3040
    // get the output file name
    pFileName = argv[globalUtilOptind];
    // call the corresponding file writer
3041 3042 3043 3044 3045 3046 3047 3048
    if ( fOnlyAnds )
    {
        Abc_Ntk_t * pNtkTemp = Abc_NtkToNetlist( pAbc->pNtkCur );
        if ( !Abc_NtkHasAig(pNtkTemp) && !Abc_NtkHasMapping(pNtkTemp) )
            Abc_NtkToAig( pNtkTemp );
        Io_WriteVerilog( pNtkTemp, pFileName, 1 );
        Abc_NtkDelete( pNtkTemp );
    }
3049
    else if ( nLutSize >= 2 && nLutSize <= 6 )
3050
        Io_WriteVerilogLut( pAbc->pNtkCur, pFileName, nLutSize, fFixed, fNoModules );
3051
    else
3052
        Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_VERILOG );
Alan Mishchenko committed
3053
    return 0;
Alan Mishchenko committed
3054

Alan Mishchenko committed
3055
usage:
3056
    fprintf( pAbc->Err, "usage: write_verilog [-K num] [-famh] <file>\n" );
3057
    fprintf( pAbc->Err, "\t         writes the current network in Verilog format\n" );
3058
    fprintf( pAbc->Err, "\t-K num : write the network using instances of K-LUTs (2 <= K <= 6) [default = not used]\n" );
3059
    fprintf( pAbc->Err, "\t-f     : toggle using fixed format [default = %s]\n", fFixed? "yes":"no" );
3060
    fprintf( pAbc->Err, "\t-a     : toggle writing expressions with only ANDs (without XORs and MUXes) [default = %s]\n", fOnlyAnds? "yes":"no" );
3061
    fprintf( pAbc->Err, "\t-m     : toggle writing additional modules [default = %s]\n", !fNoModules? "yes":"no" );
Alan Mishchenko committed
3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077
    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
3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128
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" );
3129
    fprintf( pAbc->Err, "\t         writes CNF for the sorter\n" );
Alan Mishchenko committed
3130 3131 3132 3133 3134 3135 3136
    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
3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155
/**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;
3156
    int fHex = 1;
Alan Mishchenko committed
3157
    int fReverse = 0;
Alan Mishchenko committed
3158 3159 3160
    int c;

    Extra_UtilGetoptReset();
3161
    while ( ( c = Extra_UtilGetopt( argc, argv, "xrh" ) ) != EOF )
Alan Mishchenko committed
3162 3163 3164
    {
        switch ( c )
        {
3165 3166 3167
            case 'x':
                fHex ^= 1;
                break;
Alan Mishchenko committed
3168 3169 3170
            case 'r':
                fReverse ^= 1;
                break;
Alan Mishchenko committed
3171 3172 3173 3174 3175 3176 3177 3178
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( pAbc->pNtkCur == NULL )
    {
Alan Mishchenko committed
3179
        printf( "Current network is not available.\n" );
Alan Mishchenko committed
3180 3181 3182 3183
        return 0;
    }
    if ( !Abc_NtkIsLogic(pNtk) )
    {
Alan Mishchenko committed
3184
        printf( "Current network should not an AIG. Run \"logic\".\n" );
Alan Mishchenko committed
3185 3186 3187 3188
        return 0;
    }
    if ( Abc_NtkPoNum(pNtk) != 1 )
    {
Alan Mishchenko committed
3189
        printf( "Current network should have exactly one primary output.\n" );
Alan Mishchenko committed
3190 3191 3192 3193
        return 0;
    }
    if ( Abc_NtkNodeNum(pNtk) != 1 )
    {
Alan Mishchenko committed
3194
        printf( "Current network should have exactly one node.\n" );
Alan Mishchenko committed
3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214
        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 );
3215
    pTruth = Hop_ManConvertAigToTruth( (Hop_Man_t *)pNtk->pManFunc, (Hop_Obj_t *)pNode->pData, Abc_ObjFaninNum(pNode), vTruth, fReverse );
Alan Mishchenko committed
3216 3217 3218 3219 3220 3221 3222
    pFile = fopen( pFileName, "w" );
    if ( pFile == NULL )
    {
        Vec_IntFree( vTruth );
        printf( "Cannot open file \"%s\" for writing.\n", pFileName );
        return 0;
    }
3223 3224 3225 3226
    if ( fHex )
        Extra_PrintHex2( pFile, pTruth, Abc_ObjFaninNum(pNode) );
    else
        Extra_PrintBinary( pFile, pTruth, 1<<Abc_ObjFaninNum(pNode) );
Alan Mishchenko committed
3227 3228 3229 3230 3231
    fclose( pFile );
    Vec_IntFree( vTruth );
    return 0;

usage:
3232
    fprintf( pAbc->Err, "usage: write_truth [-xrh] <file>\n" );
Alan Mishchenko committed
3233
    fprintf( pAbc->Err, "\t         writes truth table into a file\n" );
3234
    fprintf( pAbc->Err, "\t-x     : toggles between bin and hex representation [default = %s]\n", fHex?  "hex":"bin" );
Alan Mishchenko committed
3235
    fprintf( pAbc->Err, "\t-r     : toggle reversing bits in the truth table [default = %s]\n", fReverse? "yes":"no" );
Alan Mishchenko committed
3236 3237 3238 3239 3240
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}

3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteTruths( Abc_Frame_t * pAbc, int argc, char **argv )
{
    Gia_Obj_t * pObj;
    char * pFileName;
    FILE * pFile;
3258
    word * pTruth;
3259
    int nBytes;
3260
    int fReverse = 0;
3261 3262
    int fHex = 1;
    int fBinaryFile = 0;
3263 3264 3265
    int c, i;
 
    Extra_UtilGetoptReset();
3266
    while ( ( c = Extra_UtilGetopt( argc, argv, "rxbh" ) ) != EOF )
3267 3268 3269 3270 3271 3272
    {
        switch ( c )
        {
            case 'r':
                fReverse ^= 1;
                break;
3273 3274 3275
            case 'x':
                fHex ^= 1;
                break;
3276
            case 'b':
3277
                fBinaryFile ^= 1;
3278
                break;
3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294
            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;
    }
3295 3296 3297 3298 3299
    if ( Gia_ManPiNum(pAbc->pGia) < 3 )
    {
        Abc_Print( -1, "IoCommandWriteTruths(): Can write truth tables for 3 inputs or more.\n" );
        return 0;
    }
3300 3301 3302 3303 3304
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    // get the input file name
    pFileName = argv[globalUtilOptind];
    // convert to logic
3305
    pFile = fopen( pFileName, "wb" );
3306 3307 3308 3309 3310
    if ( pFile == NULL )
    {
        printf( "Cannot open file \"%s\" for writing.\n", pFileName );
        return 0;
    }
3311
    nBytes = 8 * Abc_Truth6WordNum( Gia_ManPiNum(pAbc->pGia) );
3312 3313 3314
    Gia_ManForEachCo( pAbc->pGia, pObj, i )
    {
        pTruth = Gia_ObjComputeTruthTable( pAbc->pGia, pObj );
3315
        if ( fBinaryFile )
3316
            fwrite( pTruth, nBytes, 1, pFile );
3317
        else if ( fHex )
3318
            Extra_PrintHex( pFile, (unsigned *)pTruth, Gia_ManPiNum(pAbc->pGia) ), fprintf( pFile, "\n" );
3319 3320
        else
            Extra_PrintBinary( pFile, (unsigned *)pTruth, 1 << Gia_ManPiNum(pAbc->pGia) ), fprintf( pFile, "\n" );
3321 3322 3323 3324 3325
    }
    fclose( pFile );
    return 0;

usage:
3326
    fprintf( pAbc->Err, "usage: &write_truths [-rxbh] <file>\n" );
3327 3328
    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" );
3329 3330
    fprintf( pAbc->Err, "\t-x     : toggle writing in the hex notation [default = %s]\n", fHex? "yes":"no" );
    fprintf( pAbc->Err, "\t-b     : toggle using binary file format [default = %s]\n", fBinaryFile? "yes":"no" );
3331 3332 3333 3334 3335 3336
    fprintf( pAbc->Err, "\t-h     : print the help massage\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write\n" );
    return 1;
}


3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteStatus( Abc_Frame_t * pAbc, int argc, char **argv )
{
    char * pFileName;
    int c;
3352
    extern void Abc_NtkWriteLogFile( char * pFileName, Abc_Cex_t * pCex, int Status, int nFrames, char * pCommand );
3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368

    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];
3369
    Abc_NtkWriteLogFile( pFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, NULL );
3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426
    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 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_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;
}
3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int IoCommandWriteJson( Abc_Frame_t * pAbc, int argc, char **argv )
{
    extern void Json_Write( char * pFileName, Abc_Nam_t * pStr, Vec_Wec_t * vObjs );
3442 3443
    extern void Json_Extract( char * pFileName, Abc_Nam_t * pStr, Vec_Wec_t * vObjs );
    int c, fExtract = 0;
3444 3445 3446
    char * pFileName;

    Extra_UtilGetoptReset();
3447
    while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
3448 3449 3450
    {
        switch ( c )
        {
3451 3452 3453
            case 'c':
                fExtract ^= 1;
                break;
3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467
            case 'h':
                goto usage;
            default:
                goto usage;
        }
    }
    if ( Abc_FrameReadJsonStrs(Abc_FrameReadGlobalFrame()) == NULL )
    {
        fprintf( pAbc->Out, "No JSON info is available.\n" );
        return 0;
    }
    if ( argc != globalUtilOptind + 1 )
        goto usage;
    pFileName = argv[globalUtilOptind];
3468 3469 3470 3471
    if ( fExtract )
        Json_Extract( pFileName, Abc_FrameReadJsonStrs(Abc_FrameReadGlobalFrame()), Abc_FrameReadJsonObjs(Abc_FrameReadGlobalFrame()) );
    else
        Json_Write( pFileName, Abc_FrameReadJsonStrs(Abc_FrameReadGlobalFrame()), Abc_FrameReadJsonObjs(Abc_FrameReadGlobalFrame()) );
3472 3473 3474
    return 0;

usage:
3475
    fprintf( pAbc->Err, "usage: write_json [-ch] <file>\n" );
3476
    fprintf( pAbc->Err, "\t         write the network in JSON format\n" );
3477
    fprintf( pAbc->Err, "\t-c     : output extracted version\n" );
3478 3479 3480 3481 3482
    fprintf( pAbc->Err, "\t-h     : print the help message\n" );
    fprintf( pAbc->Err, "\tfile   : the name of the file to write (extension .json)\n" );
    return 1;
}

Alan Mishchenko committed
3483 3484 3485 3486 3487
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


3488 3489
ABC_NAMESPACE_IMPL_END