summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2019-05-07 07:27:31 +0800
committerAlan Mishchenko <alanmi@berkeley.edu>2019-05-07 07:27:31 +0800
commit7ccb25bfe929787dc0a4dafc0dead5951cdf0246 (patch)
tree2e5b8901f255fc147bcfb907ed95ef8a6692cb4b
parenteb2764b5251aa23588f5aa6179197a378f15d759 (diff)
downloadabc-7ccb25bfe929787dc0a4dafc0dead5951cdf0246.tar.gz
abc-7ccb25bfe929787dc0a4dafc0dead5951cdf0246.tar.bz2
abc-7ccb25bfe929787dc0a4dafc0dead5951cdf0246.zip
Modifying 'write_truth' to dump truth table in hex.
-rw-r--r--src/base/io/io.c14
-rw-r--r--src/misc/extra/extra.h1
-rw-r--r--src/misc/extra/extraUtilFile.c18
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<<Abc_ObjFaninNum(pNode) );
+ if ( fHex )
+ Extra_PrintHex2( pFile, pTruth, Abc_ObjFaninNum(pNode) );
+ else
+ Extra_PrintBinary( pFile, pTruth, 1<<Abc_ObjFaninNum(pNode) );
fclose( pFile );
Vec_IntFree( vTruth );
return 0;
usage:
- fprintf( pAbc->Err, "usage: write_truth [-rh] <file>\n" );
+ fprintf( pAbc->Err, "usage: write_truth [-xrh] <file>\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;