summaryrefslogtreecommitdiffstats
path: root/src/base/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/io')
-rw-r--r--src/base/io/io.c11
-rw-r--r--src/base/io/ioReadBlif.c75
-rw-r--r--src/base/io/ioReadBlifMv.c8
3 files changed, 91 insertions, 3 deletions
diff --git a/src/base/io/io.c b/src/base/io/io.c
index e29a3009..ecc6302f 100644
--- a/src/base/io/io.c
+++ b/src/base/io/io.c
@@ -2343,13 +2343,17 @@ int IoCommandWriteTruth( Abc_Frame_t * pAbc, int argc, char **argv )
char * pFileName;
FILE * pFile;
unsigned * pTruth;
+ int fReverse = 0;
int c;
Extra_UtilGetoptReset();
- while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
+ while ( ( c = Extra_UtilGetopt( argc, argv, "rh" ) ) != EOF )
{
switch ( c )
{
+ case 'r':
+ fReverse ^= 1;
+ break;
case 'h':
goto usage;
default:
@@ -2394,7 +2398,7 @@ int IoCommandWriteTruth( Abc_Frame_t * pAbc, int argc, char **argv )
// convert to logic
Abc_NtkToAig( pNtk );
vTruth = Vec_IntAlloc( 0 );
- pTruth = Hop_ManConvertAigToTruth( pNtk->pManFunc, pNode->pData, Abc_ObjFaninNum(pNode), vTruth, 0 );
+ pTruth = Hop_ManConvertAigToTruth( pNtk->pManFunc, pNode->pData, Abc_ObjFaninNum(pNode), vTruth, fReverse );
pFile = fopen( pFileName, "w" );
if ( pFile == NULL )
{
@@ -2408,8 +2412,9 @@ int IoCommandWriteTruth( Abc_Frame_t * pAbc, int argc, char **argv )
return 0;
usage:
- fprintf( pAbc->Err, "usage: write_truth [-h] <file>\n" );
+ fprintf( pAbc->Err, "usage: write_truth [-rh] <file>\n" );
fprintf( pAbc->Err, "\t writes truth table 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-h : print the help massage\n" );
fprintf( pAbc->Err, "\tfile : the name of the file to write\n" );
return 1;
diff --git a/src/base/io/ioReadBlif.c b/src/base/io/ioReadBlif.c
index b6eb29e3..f2c3e8c2 100644
--- a/src/base/io/ioReadBlif.c
+++ b/src/base/io/ioReadBlif.c
@@ -535,6 +535,71 @@ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens )
SeeAlso []
***********************************************************************/
+int Io_ReadBlifReorderFormalNames( Vec_Ptr_t * vTokens, Mio_Gate_t * pGate )
+{
+ Mio_Pin_t * pGatePin;
+ char * pName, * pNamePin;
+ int i, k, nSize, Length;
+ nSize = Vec_PtrSize(vTokens);
+ if ( nSize - 3 != Mio_GateReadInputs(pGate) )
+ return 0;
+ // check if the names are in order
+ for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ )
+ {
+ pNamePin = Mio_PinReadName(pGatePin);
+ Length = strlen(pNamePin);
+ pName = Vec_PtrEntry(vTokens, i+2);
+ if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' )
+ continue;
+ break;
+ }
+ if ( i == nSize - 3 )
+ return 1;
+ // reorder the pins
+ for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ )
+ {
+ pNamePin = Mio_PinReadName(pGatePin);
+ Length = strlen(pNamePin);
+ for ( k = 2; k < nSize; k++ )
+ {
+ pName = Vec_PtrEntry(vTokens, k);
+ if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' )
+ {
+ Vec_PtrPush( vTokens, pName );
+ break;
+ }
+ }
+ }
+ pNamePin = Mio_GateReadOutName(pGate);
+ Length = strlen(pNamePin);
+ for ( k = 2; k < nSize; k++ )
+ {
+ pName = Vec_PtrEntry(vTokens, k);
+ if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' )
+ {
+ Vec_PtrPush( vTokens, pName );
+ break;
+ }
+ }
+ if ( Vec_PtrSize(vTokens) - nSize != nSize - 2 )
+ return 0;
+ Vec_PtrForEachEntryStart( vTokens, pName, k, nSize )
+ Vec_PtrWriteEntry( vTokens, k - nSize + 2, pName );
+ Vec_PtrShrink( vTokens, nSize );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
int Io_ReadBlifNetworkGate( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
{
Mio_Library_t * pGenlib;
@@ -581,6 +646,16 @@ int Io_ReadBlifNetworkGate( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens )
p->pNtkCur->pManFunc = pGenlib;
}
+ // reorder the formal inputs to be in the same order as in the gate
+ if ( !Io_ReadBlifReorderFormalNames( vTokens, pGate ) )
+ {
+ p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0);
+ sprintf( p->sError, "Mismatch in the fanins of gate \"%s\".", (char*)vTokens->pArray[1] );
+ Io_ReadBlifPrintErrorMessage( p );
+ return 1;
+ }
+
+
// remove the formal parameter names
for ( i = 2; i < vTokens->nSize; i++ )
{
diff --git a/src/base/io/ioReadBlifMv.c b/src/base/io/ioReadBlifMv.c
index 95e7cd1d..2e2388d3 100644
--- a/src/base/io/ioReadBlifMv.c
+++ b/src/base/io/ioReadBlifMv.c
@@ -1828,6 +1828,7 @@ static char * Io_ReadBlifCleanName( char * pName )
***********************************************************************/
static int Io_MvParseLineGateBlif( Io_MvMod_t * p, Vec_Ptr_t * vTokens )
{
+ extern int Io_ReadBlifReorderFormalNames( Vec_Ptr_t * vTokens, Mio_Gate_t * pGate );
Mio_Library_t * pGenlib;
Mio_Gate_t * pGate;
Abc_Obj_t * pNode;
@@ -1868,6 +1869,13 @@ static int Io_MvParseLineGateBlif( Io_MvMod_t * p, Vec_Ptr_t * vTokens )
p->pNtk->pManFunc = pGenlib;
}
+ // reorder the formal inputs to be in the same order as in the gate
+ if ( !Io_ReadBlifReorderFormalNames( vTokens, pGate ) )
+ {
+ sprintf( p->pMan->sError, "Line %d: Mismatch in the fanins of gate \"%s\".", Io_MvGetLine(p->pMan, pName), (char*)vTokens->pArray[1] );
+ return 0;
+ }
+
// remove the formal parameter names
for ( i = 2; i < vTokens->nSize; i++ )
{