From 7ccb25bfe929787dc0a4dafc0dead5951cdf0246 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Tue, 7 May 2019 07:27:31 +0800 Subject: Modifying 'write_truth' to dump truth table in hex. --- src/base/io/io.c | 14 +++++++++++--- src/misc/extra/extra.h | 1 + src/misc/extra/extraUtilFile.c | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/base/io/io.c b/src/base/io/io.c index 5ba7f32c..ab23be3b 100644 --- a/src/base/io/io.c +++ b/src/base/io/io.c @@ -2968,14 +2968,18 @@ int IoCommandWriteTruth( Abc_Frame_t * pAbc, int argc, char **argv ) char * pFileName; FILE * pFile; unsigned * pTruth; + int fHex = 1; int fReverse = 0; int c; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "rh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "xrh" ) ) != EOF ) { switch ( c ) { + case 'x': + fHex ^= 1; + break; case 'r': fReverse ^= 1; break; @@ -3031,14 +3035,18 @@ int IoCommandWriteTruth( Abc_Frame_t * pAbc, int argc, char **argv ) printf( "Cannot open file \"%s\" for writing.\n", pFileName ); return 0; } - Extra_PrintBinary( pFile, pTruth, 1<Err, "usage: write_truth [-rh] \n" ); + fprintf( pAbc->Err, "usage: write_truth [-xrh] \n" ); fprintf( pAbc->Err, "\t writes truth table into a file\n" ); + fprintf( pAbc->Err, "\t-x : toggles between bin and hex representation [default = %s]\n", fHex? "hex":"bin" ); fprintf( pAbc->Err, "\t-r : toggle reversing bits in the truth table [default = %s]\n", fReverse? "yes":"no" ); fprintf( pAbc->Err, "\t-h : print the help massage\n" ); fprintf( pAbc->Err, "\tfile : the name of the file to write\n" ); diff --git a/src/misc/extra/extra.h b/src/misc/extra/extra.h index e8afebd8..2f38692d 100644 --- a/src/misc/extra/extra.h +++ b/src/misc/extra/extra.h @@ -125,6 +125,7 @@ extern int Extra_ReadHexadecimal( unsigned Sign[], char * pString, int extern void Extra_PrintHexadecimal( FILE * pFile, unsigned Sign[], int nVars ); extern void Extra_PrintHexadecimalString( char * pString, unsigned Sign[], int nVars ); extern void Extra_PrintHex( FILE * pFile, unsigned * pTruth, int nVars ); +extern void Extra_PrintHex2( FILE * pFile, unsigned * pTruth, int nVars ); extern void Extra_PrintHexReverse( FILE * pFile, unsigned * pTruth, int nVars ); extern void Extra_PrintSymbols( FILE * pFile, char Char, int nTimes, int fPrintNewLine ); diff --git a/src/misc/extra/extraUtilFile.c b/src/misc/extra/extraUtilFile.c index 0af78ac4..eb1b7dce 100644 --- a/src/misc/extra/extraUtilFile.c +++ b/src/misc/extra/extraUtilFile.c @@ -656,6 +656,24 @@ void Extra_PrintHex( FILE * pFile, unsigned * pTruth, int nVars ) } // fprintf( pFile, "\n" ); } +void Extra_PrintHex2( FILE * pFile, unsigned * pTruth, int nVars ) +{ + int nMints, nDigits, Digit, k; + + // write the number into the file + //fprintf( pFile, "0x" ); + nMints = (1 << nVars); + nDigits = nMints / 4 + ((nMints % 4) > 0); + for ( k = nDigits - 1; k >= 0; k-- ) + { + Digit = ((pTruth[k/8] >> (k * 4)) & 15); + if ( Digit < 10 ) + fprintf( pFile, "%d", Digit ); + else + fprintf( pFile, "%c", 'A' + Digit-10 ); + } +// fprintf( pFile, "\n" ); +} void Extra_PrintHexReverse( FILE * pFile, unsigned * pTruth, int nVars ) { int nMints, nDigits, Digit, k; -- cgit v1.2.3