mainMC.c 5.37 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 21 22 23 24 25 26
/**CFile****************************************************************

  FileName    [mainMC.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [The main package.]

  Synopsis    [The main file for the model checker.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "mainInt.h"
#include "aig.h"
#include "saig.h"
#include "fra.h"
#include "ioa.h"

27 28 29
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [The main() procedure.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int main( int argc, char * argv[] )
{
Alan Mishchenko committed
51 52 53 54 55
    int fEnableBmcOnly = 0;  // enable to make it BMC-only

    int fEnableCounter = 1;  // should be 1 in the final version
    int fEnableComment = 0;  // should be 0 in the final version

Alan Mishchenko committed
56 57 58
    Fra_Sec_t SecPar, * pSecPar = &SecPar;
    FILE * pFile;
    Aig_Man_t * pAig;
Alan Mishchenko committed
59 60
    int RetValue = -1;
    int Depth    = -1;
Alan Mishchenko committed
61
    // BMC parameters
Alan Mishchenko committed
62 63
    int nFrames  = 50;
    int nSizeMax = 500000;
Alan Mishchenko committed
64 65 66 67
    int nBTLimit = 10000;
    int fRewrite = 0;
    int fNewAlgo = 1;
    int fVerbose = 0;
Alan Mishchenko committed
68
    int clkTotal = clock();
Alan Mishchenko committed
69 70 71 72

    if ( argc != 2 )
    {
        printf( "  Expecting one command-line argument (an input file in AIGER format).\n" );
Alan Mishchenko committed
73
        printf( "  usage: %s <file.aig>\n", argv[0] );
Alan Mishchenko committed
74 75 76 77 78 79
        return 0;
    }
    pFile = fopen( argv[1], "r" );
    if ( pFile == NULL )
    {
        printf( "  Cannot open input AIGER file \"%s\".\n", argv[1] );
Alan Mishchenko committed
80
        printf( "  usage: %s <file.aig>\n", argv[0] );
Alan Mishchenko committed
81 82 83 84 85 86 87
        return 0;
    }
    fclose( pFile );
    pAig = Ioa_ReadAiger( argv[1], 1 );
    if ( pAig == NULL )
    {
        printf( "  Parsing the AIGER file \"%s\" has failed.\n", argv[1] );
Alan Mishchenko committed
88
        printf( "  usage: %s <file.aig>\n", argv[0] );
Alan Mishchenko committed
89 90 91 92
        return 0;
    }

    Aig_ManSetRegNum( pAig, pAig->nRegs );
Alan Mishchenko committed
93
    if ( !fEnableBmcOnly )
Alan Mishchenko committed
94
    {
Alan Mishchenko committed
95 96
        // perform BMC
        if ( pAig->nRegs != 0 )
Alan Mishchenko committed
97
            RetValue = Saig_ManBmcSimple( pAig, nFrames, nSizeMax, nBTLimit, fRewrite, fVerbose, NULL, 0 );
Alan Mishchenko committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

        // perform full-blown SEC
        if ( RetValue != 0 )
        {
            extern void Dar_LibStart();
            extern void Dar_LibStop();
            extern void Cnf_ClearMemory();

            Fra_SecSetDefaultParams( pSecPar );
            pSecPar->TimeLimit       = 600;
            pSecPar->nFramesMax      =   4;  // the max number of frames used for induction
            pSecPar->fPhaseAbstract  =   0;  // disable phase-abstraction
            pSecPar->fSilent         =   1;  // disable phase-abstraction

            Dar_LibStart();
Alan Mishchenko committed
113
            RetValue = Fra_FraigSec( pAig, pSecPar, NULL );
Alan Mishchenko committed
114 115 116
            Dar_LibStop();
            Cnf_ClearMemory();
        }
Alan Mishchenko committed
117 118 119
    }

    // perform BMC again
Alan Mishchenko committed
120
    if ( RetValue == -1 && pAig->nRegs != 0 )
Alan Mishchenko committed
121
    {
Alan Mishchenko committed
122 123 124 125
        int nFrames  = 200;
        int nSizeMax = 500000;
        int nBTLimit = 10000000;
        int fRewrite = 0;
Alan Mishchenko committed
126
        RetValue = Saig_ManBmcSimple( pAig, nFrames, nSizeMax, nBTLimit, fRewrite, fVerbose, &Depth, 0 );
Alan Mishchenko committed
127 128
        if ( RetValue != 0 )
            RetValue = -1;
Alan Mishchenko committed
129 130 131 132 133 134 135 136 137
    }

    // decide how to report the output
    pFile = stdout;

    // report the result
    if ( RetValue == 0 ) 
    {
//        fprintf(stdout, "s SATIFIABLE\n");
Alan Mishchenko committed
138 139 140 141 142
        fprintf( pFile, "1" );
        if ( fEnableCounter  )
        {
        printf( "\n" );
        if ( pAig->pSeqModel )
Alan Mishchenko committed
143
        Fra_SmlWriteCounterExample( pFile, pAig, pAig->pSeqModel );
Alan Mishchenko committed
144 145 146 147 148 149 150 151
        }

        if ( fEnableComment )
        {
        printf( "  # File %10s.  ", argv[1] );
        PRT( "Time", clock() - clkTotal );
        }

Alan Mishchenko committed
152 153 154 155 156 157 158 159
        if ( pFile != stdout )
            fclose(pFile);
        Aig_ManStop( pAig );
        exit(10);
    } 
    else if ( RetValue == 1 ) 
    {
//    fprintf(stdout, "s UNSATISFIABLE\n");
Alan Mishchenko committed
160 161 162 163 164 165 166 167 168
        fprintf( pFile, "0" );

        if ( fEnableComment )
        {
        printf( "  # File %10s.  ", argv[1] );
        PRT( "Time", clock() - clkTotal );
        }
        printf( "\n" );

Alan Mishchenko committed
169 170 171 172 173 174 175 176
        if ( pFile != stdout )
            fclose(pFile);
        Aig_ManStop( pAig );
        exit(20);
    } 
    else // if ( RetValue == -1 ) 
    {
//    fprintf(stdout, "s UNKNOWN\n");
Alan Mishchenko committed
177 178 179 180 181 182 183 184 185
        fprintf( pFile, "2" );

        if ( fEnableComment )
        {
        printf( "  # File %10s.  ", argv[1] );
        PRT( "Time", clock() - clkTotal );
        }
        printf( "\n" );

Alan Mishchenko committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
        if ( pFile != stdout )
            fclose(pFile);
        Aig_ManStop( pAig );
        exit(0);
    }
    return 0;
}




////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


202 203
ABC_NAMESPACE_IMPL_END