diff options
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/abci/abc.c | 13 | ||||
-rw-r--r-- | src/base/abci/abcDec.c | 12 | ||||
-rw-r--r-- | src/base/abci/abcNpn.c | 15 | ||||
-rw-r--r-- | src/base/io/io.c | 22 |
4 files changed, 43 insertions, 19 deletions
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 1b935fbd..b49a9ea0 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -4846,15 +4846,16 @@ usage: ***********************************************************************/ int Abc_CommandTestNpn( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fVerbose ); + extern int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fBinary, int fVerbose ); char * pFileName; int c; int fVerbose = 0; int NpnType = 0; int nVarNum = -1; int fDumpRes = 0; + int fBinary = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "ANdvh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "ANdbvh" ) ) != EOF ) { switch ( c ) { @@ -4883,6 +4884,9 @@ int Abc_CommandTestNpn( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'd': fDumpRes ^= 1; break; + case 'b': + fBinary ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -4905,11 +4909,11 @@ int Abc_CommandTestNpn( Abc_Frame_t * pAbc, int argc, char ** argv ) // get the output file name pFileName = argv[globalUtilOptind]; // call the testbench - Abc_NpnTest( pFileName, NpnType, nVarNum, fDumpRes, fVerbose ); + Abc_NpnTest( pFileName, NpnType, nVarNum, fDumpRes, fBinary, fVerbose ); return 0; usage: - Abc_Print( -2, "usage: testnpn [-AN <num>] [-dvh] <file>\n" ); + Abc_Print( -2, "usage: testnpn [-AN <num>] [-dbvh] <file>\n" ); Abc_Print( -2, "\t testbench for computing (semi-)canonical forms\n" ); Abc_Print( -2, "\t of completely-specified Boolean functions up to 16 varibles\n" ); Abc_Print( -2, "\t-A <num> : semi-caninical form computation algorithm [default = %d]\n", NpnType ); @@ -4920,6 +4924,7 @@ usage: Abc_Print( -2, "\t 4: Jake's hybrid semi-canonical form (high-effort)\n" ); Abc_Print( -2, "\t-N <num> : the number of support variables (binary files only) [default = unused]\n" ); Abc_Print( -2, "\t-d : toggle dumping resulting functions into a file [default = %s]\n", fDumpRes? "yes": "no" ); + Abc_Print( -2, "\t-b : toggle dumping in binary format [default = %s]\n", fBinary? "yes": "no" ); Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n"); Abc_Print( -2, "\t<file> : a text file with truth tables in hexadecimal, listed one per line,\n"); diff --git a/src/base/abci/abcDec.c b/src/base/abci/abcDec.c index 309c6a50..776ecda1 100644 --- a/src/base/abci/abcDec.c +++ b/src/base/abci/abcDec.c @@ -353,10 +353,10 @@ void Abc_TruthStoreRead( char * pFileName, Abc_TtStore_t * p ) SeeAlso [] ***********************************************************************/ -void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p ) +void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p, int fBinary ) { FILE * pFile; - int i; + int i, nBytes = 8 * Abc_Truth6WordNum( p->nVars ); pFile = fopen( pFileName, "wb" ); if ( pFile == NULL ) { @@ -365,8 +365,10 @@ void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p ) } for ( i = 0; i < p->nFuncs; i++ ) { - Abc_TruthWriteHex( pFile, p->pFuncs[i], p->nVars ); - fprintf( pFile, "\n" ); + if ( fBinary ) + fwrite( p->pFuncs[i], nBytes, 1, pFile ); + else + Abc_TruthWriteHex( pFile, p->pFuncs[i], p->nVars ), fprintf( pFile, "\n" ); } fclose( pFile ); } @@ -441,7 +443,7 @@ void Abc_TtStoreTest( char * pFileName ) return; // write into another file - Abc_TtStoreWrite( pFileOutput, p ); + Abc_TtStoreWrite( pFileOutput, p, 0 ); // delete data-structure Abc_TtStoreFree( p, -1 ); diff --git a/src/base/abci/abcNpn.c b/src/base/abci/abcNpn.c index 9494cba2..0e3f41f9 100644 --- a/src/base/abci/abcNpn.c +++ b/src/base/abci/abcNpn.c @@ -49,7 +49,7 @@ struct Abc_TtStore_t_ extern Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName, int nVarNum ); extern void Abc_TtStoreFree( Abc_TtStore_t * p, int nVarNum ); -extern void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p ); +extern void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p, int fBinary ); //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// @@ -276,7 +276,7 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose ) SeeAlso [] ***********************************************************************/ -void Abc_TruthNpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fVerbose ) +void Abc_TruthNpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fBinary, int fVerbose ) { Abc_TtStore_t * p; char * pFileNameOut; @@ -292,8 +292,11 @@ void Abc_TruthNpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, // write the result if ( fDumpRes ) { - pFileNameOut = Extra_FileNameGenericAppend( pFileName, "_out.txt" ); - Abc_TtStoreWrite( pFileNameOut, p ); + if ( fBinary ) + pFileNameOut = Extra_FileNameGenericAppend( pFileName, "_out.tt" ); + else + pFileNameOut = Extra_FileNameGenericAppend( pFileName, "_out.txt" ); + Abc_TtStoreWrite( pFileNameOut, p, fBinary ); if ( fVerbose ) printf( "The resulting functions are written into file \"%s\".\n", pFileNameOut ); } @@ -315,12 +318,12 @@ void Abc_TruthNpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, SeeAlso [] ***********************************************************************/ -int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fVerbose ) +int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fBinary, int fVerbose ) { if ( fVerbose ) printf( "Using truth tables from file \"%s\"...\n", pFileName ); if ( NpnType >= 0 && NpnType <= 4 ) - Abc_TruthNpnTest( pFileName, NpnType, nVarNum, fDumpRes, fVerbose ); + Abc_TruthNpnTest( pFileName, NpnType, nVarNum, fDumpRes, fBinary, fVerbose ); else printf( "Unknown canonical form value (%d).\n", NpnType ); fflush( stdout ); diff --git a/src/base/io/io.c b/src/base/io/io.c index 86e9dc80..cad4f765 100644 --- a/src/base/io/io.c +++ b/src/base/io/io.c @@ -2739,17 +2739,22 @@ int IoCommandWriteTruths( Abc_Frame_t * pAbc, int argc, char **argv ) char * pFileName; FILE * pFile; unsigned * pTruth; + int nBytes; int fReverse = 0; + int fBinary = 0; int c, i; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "rh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "rbh" ) ) != EOF ) { switch ( c ) { case 'r': fReverse ^= 1; break; + case 'b': + fBinary ^= 1; + break; case 'h': goto usage; default: @@ -2766,6 +2771,11 @@ int IoCommandWriteTruths( Abc_Frame_t * pAbc, int argc, char **argv ) Abc_Print( -1, "IoCommandWriteTruths(): Can write truth tables up to 16 inputs.\n" ); return 0; } + if ( Gia_ManPiNum(pAbc->pGia) < 3 ) + { + Abc_Print( -1, "IoCommandWriteTruths(): Can write truth tables for 3 inputs or more.\n" ); + return 0; + } if ( argc != globalUtilOptind + 1 ) goto usage; // get the input file name @@ -2777,19 +2787,23 @@ int IoCommandWriteTruths( Abc_Frame_t * pAbc, int argc, char **argv ) printf( "Cannot open file \"%s\" for writing.\n", pFileName ); return 0; } + nBytes = 8 * Abc_Truth6WordNum( Gia_ManPiNum(pAbc->pGia) ); Gia_ManForEachCo( pAbc->pGia, pObj, i ) { pTruth = Gia_ObjComputeTruthTable( pAbc->pGia, pObj ); - Extra_PrintHex( pFile, pTruth, Gia_ManPiNum(pAbc->pGia) ); - fprintf( pFile, "\n" ); + if ( fBinary ) + fwrite( pTruth, nBytes, 1, pFile ); + else + Extra_PrintHex( pFile, pTruth, Gia_ManPiNum(pAbc->pGia) ), fprintf( pFile, "\n" ); } fclose( pFile ); return 0; usage: - fprintf( pAbc->Err, "usage: &write_truths [-rh] <file>\n" ); + fprintf( pAbc->Err, "usage: &write_truths [-rbh] <file>\n" ); 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" ); + fprintf( pAbc->Err, "\t-b : toggle using binary format [default = %s]\n", fBinary? "yes":"no" ); fprintf( pAbc->Err, "\t-h : print the help massage\n" ); fprintf( pAbc->Err, "\tfile : the name of the file to write\n" ); return 1; |