diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 0d8f5c5f1..39df508cf 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -7441,14 +7441,58 @@ int Abc_CommandRunEco( Abc_Frame_t * pAbc, int argc, char ** argv ) ***********************************************************************/ int Abc_CommandRunGen( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern void Acb_NtkRunGen( char * pFileNames[2], int fVerbose ); - char * pFileNames[4] = {NULL}; - int c, fVerbose = 0; + extern void Acb_NtkRunGen( int nInputs, int nMints, int nFuncs, int Seed, int fVerbose, char * pScript ); + int c, nInputs = 10, nMints = 10, nFuncs = 10, Seed = 0, fVerbose = 0; char * pScript = NULL; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "IMRSCvh" ) ) != EOF ) { switch ( c ) { + case 'I': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" ); + goto usage; + } + nInputs = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + break; + 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; + case 'R': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" ); + goto usage; + } + nFuncs = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + break; + case 'S': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" ); + goto usage; + } + Seed = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + break; + case 'C': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-C\" should be followed by a script.\n" ); + goto usage; + } + pScript = argv[globalUtilOptind]; + globalUtilOptind++; + break; case 'v': fVerbose ^= 1; break; @@ -7458,21 +7502,24 @@ int Abc_CommandRunGen( Abc_Frame_t * pAbc, int argc, char ** argv ) goto usage; } } - if ( argc - globalUtilOptind != 2 ) + if ( pScript == NULL ) { - Abc_Print( 1, "Expecting two file names on the command line.\n" ); - goto usage; + Abc_Print( -1, "Command line switch \"-C\" should be specified and followed by a string.\n" ); + goto usage; } - for ( c = 0; c < 2; c++ ) - pFileNames[c] = argv[globalUtilOptind+c]; - Acb_NtkRunGen( pFileNames, fVerbose ); + Acb_NtkRunGen( nInputs, nMints, nFuncs, Seed, fVerbose, pScript ); return 0; usage: - Abc_Print( -2, "usage: rungen [-vh] \n" ); - Abc_Print( -2, "\t experimental command\n" ); - Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-h : print the command usage\n"); + Abc_Print( -2, "usage: rungen [-IMRS num] [-C script] [-vh]\n" ); + Abc_Print( -2, "\t running the script on a set of randomly generated functions\n" ); + Abc_Print( -2, "\t-I : the number of input variables [default = %d]\n", nInputs ); + Abc_Print( -2, "\t-M : the number of positive minterms in the random function [default = %d]\n", nMints ); + Abc_Print( -2, "\t-R : the number of random functions to try [default = %d]\n", nFuncs ); + Abc_Print( -2, "\t-S : the random seed [default = %d]\n", Seed ); + Abc_Print( -2, "\t-C : the script to apply [default = provided by the user]\n" ); + Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); + Abc_Print( -2, "\t-h : print the command usage\n"); return 1; } @@ -9905,7 +9952,7 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'S': if ( globalUtilOptind >= argc ) { - Abc_Print( -1, "Command line switch \"-S\" should be followed by a file name.\n" ); + Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" ); goto usage; } pPars->pSymStr = argv[globalUtilOptind]; @@ -9914,7 +9961,7 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'R': if ( globalUtilOptind >= argc ) { - Abc_Print( -1, "Command line switch \"-R\" should be followed by a file name.\n" ); + Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" ); goto usage; } pPars->nRandFuncs = atoi(argv[globalUtilOptind]); @@ -9923,7 +9970,7 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'M': if ( globalUtilOptind >= argc ) { - Abc_Print( -1, "Command line switch \"-M\" should be followed by a file name.\n" ); + Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" ); goto usage; } pPars->nMintNum = atoi(argv[globalUtilOptind]); diff --git a/src/base/abci/abcRunGen.c b/src/base/abci/abcRunGen.c index 9130fdad0..d82ba7fe4 100644 --- a/src/base/abci/abcRunGen.c +++ b/src/base/abci/abcRunGen.c @@ -19,7 +19,16 @@ ***********************************************************************/ #include "base/abc/abc.h" -#include "opt/cut/cut.h" +#include "base/main/main.h" +#include "base/cmd/cmd.h" +#include "misc/util/utilTruth.h" + +#ifdef WIN32 +#include +#define unlink _unlink +#else +#include +#endif ABC_NAMESPACE_IMPL_START @@ -42,8 +51,79 @@ ABC_NAMESPACE_IMPL_START SeeAlso [] ***********************************************************************/ -void Acb_NtkRunGen( char * pFileNames[2], int fVerbose ) +int Abc_NtkRunGenOne( Abc_Ntk_t * p, char * pScript ) +{ + Abc_FrameReplaceCurrentNetwork( Abc_FrameGetGlobalFrame(), p ); + if ( Abc_FrameIsBatchMode() ) + { + if ( Cmd_CommandExecute(Abc_FrameGetGlobalFrame(), pScript) ) + { + Abc_Print( 1, "Something did not work out with the command \"%s\".\n", pScript ); + return 0; + } + } + else + { + Abc_FrameSetBatchMode( 1 ); + if ( Cmd_CommandExecute(Abc_FrameGetGlobalFrame(), pScript) ) + { + Abc_Print( 1, "Something did not work out with the command \"%s\".\n", pScript ); + return 0; + } + Abc_FrameSetBatchMode( 0 ); + } + Abc_Ntk_t * pTemp = Abc_FrameReadNtk(Abc_FrameGetGlobalFrame()); + return Abc_NtkNodeNum(pTemp); +} +void Acb_NtkRunGen( int nInputs, int nMints, int nFuncs, int Seed, int fVerbose, char * pScript ) { + abctime clkStart = Abc_Clock(); + Vec_Int_t * vNodes = Vec_IntAlloc( 1000 ); + int i, k, nNodes, nWords = Abc_TtWordNum(nInputs); + word * pFun = ABC_ALLOC( word, nWords ); + Abc_Ntk_t * pNtkNew; char * pTtStr, * pSop; + Abc_Random(1); + for ( i = 0; i < 10+Seed; i++ ) + Abc_Random(0); + printf( "Synthesizing %d random %d-variable functions with %d positive minterms using script \"%s\".\n", nFuncs, nInputs, nMints, pScript ); + for ( i = 0; i < nFuncs; i++ ) + { + if ( nMints == 0 ) + for ( k = 0; k < nWords; k++ ) + pFun[k] = Abc_RandomW(0); + else { + Abc_TtClear( pFun, nWords ); + for ( k = 0; k < nMints; k++ ) { + int iMint = 0; + do iMint = Abc_Random(0) % (1 << nInputs); + while ( Abc_TtGetBit(pFun, iMint) ); + Abc_TtSetBit( pFun, iMint ); + } + } + pTtStr = ABC_CALLOC( char, nInputs > 2 ? (1 << (nInputs-2)) + 1 : 2 ); + Extra_PrintHexadecimalString( pTtStr, (unsigned *)pFun, nInputs ); + pSop = Abc_SopFromTruthHex( pTtStr ); + pNtkNew = Abc_NtkCreateWithNode( pSop ); + nNodes = Abc_NtkRunGenOne( pNtkNew, pScript ); + if ( nNodes >= Vec_IntSize(vNodes) ) + Vec_IntSetEntry( vNodes, nNodes, 0 ); + Vec_IntAddToEntry( vNodes, nNodes, 1 ); + + if ( fVerbose ) { + printf( "Iteration %3d : ", i ); + printf( "Random function has %d positive minterms ", nMints ); + printf( "and maps into %d nodes.\n", nNodes ); + if ( fVerbose ) + printf( "Truth table : %s\n", pTtStr ); + } + ABC_FREE( pTtStr ); + ABC_FREE( pSop ); + } + Vec_IntForEachEntry( vNodes, i, k ) + if ( i ) + printf( "Nodes %3d : Functions %3d Ratio %5.2f %%\n", k, i, 100.0*i/nFuncs ); + ABC_FREE( pFun ); + Abc_PrintTime( 0, "Total time", Abc_Clock() - clkStart ); } ////////////////////////////////////////////////////////////////////////