summaryrefslogtreecommitdiffstats
path: root/src/base/io/ioWriteBlif.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-09-19 16:28:06 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-09-19 16:28:06 -0700
commit3af0f719afa368cafbe7c8178d0995819b47be90 (patch)
treed7d4bb682fc4d3b9607569580810c9c229b48266 /src/base/io/ioWriteBlif.c
parent60c661488507d3ff5866e795979bdef64b10f58f (diff)
downloadabc-3af0f719afa368cafbe7c8178d0995819b47be90.tar.gz
abc-3af0f719afa368cafbe7c8178d0995819b47be90.tar.bz2
abc-3af0f719afa368cafbe7c8178d0995819b47be90.zip
Extending BLIF parser/write to hangle multi-output cells.
Diffstat (limited to 'src/base/io/ioWriteBlif.c')
-rw-r--r--src/base/io/ioWriteBlif.c140
1 files changed, 83 insertions, 57 deletions
diff --git a/src/base/io/ioWriteBlif.c b/src/base/io/ioWriteBlif.c
index 54be8434..a8305d07 100644
--- a/src/base/io/ioWriteBlif.c
+++ b/src/base/io/ioWriteBlif.c
@@ -37,9 +37,8 @@ static void Io_NtkWritePis( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches );
static void Io_NtkWritePos( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches );
static void Io_NtkWriteSubckt( FILE * pFile, Abc_Obj_t * pNode );
static void Io_NtkWriteAsserts( FILE * pFile, Abc_Ntk_t * pNtk );
-static void Io_NtkWriteNodeGate( FILE * pFile, Abc_Obj_t * pNode, int Length );
static void Io_NtkWriteNodeFanins( FILE * pFile, Abc_Obj_t * pNode );
-static void Io_NtkWriteNode( FILE * pFile, Abc_Obj_t * pNode, int Length );
+static int Io_NtkWriteNode( FILE * pFile, Abc_Obj_t * pNode, int Length );
static void Io_NtkWriteLatch( FILE * pFile, Abc_Obj_t * pLatch );
////////////////////////////////////////////////////////////////////////
@@ -251,7 +250,8 @@ void Io_NtkWriteOne( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches, int fBb2
Abc_NtkForEachNode( pNtk, pNode, i )
{
Extra_ProgressBarUpdate( pProgress, i, NULL );
- Io_NtkWriteNode( pFile, pNode, Length );
+ if ( Io_NtkWriteNode( pFile, pNode, Length ) ) // skip the next node
+ i++;
}
Extra_ProgressBarStop( pProgress );
}
@@ -462,7 +462,7 @@ void Io_NtkWriteLatch( FILE * pFile, Abc_Obj_t * pLatch )
/**Function*************************************************************
- Synopsis [Write the node into a file.]
+ Synopsis [Writes the primary input list.]
Description []
@@ -471,24 +471,47 @@ void Io_NtkWriteLatch( FILE * pFile, Abc_Obj_t * pLatch )
SeeAlso []
***********************************************************************/
-void Io_NtkWriteNode( FILE * pFile, Abc_Obj_t * pNode, int Length )
+void Io_NtkWriteNodeFanins( FILE * pFile, Abc_Obj_t * pNode )
{
- if ( Abc_NtkHasMapping(pNode->pNtk) )
+ Abc_Obj_t * pNet;
+ int LineLength;
+ int AddedLength;
+ int NameCounter;
+ char * pName;
+ int i;
+
+ LineLength = 6;
+ NameCounter = 0;
+ Abc_ObjForEachFanin( pNode, pNet, i )
{
- // write the .gate line
- fprintf( pFile, ".gate" );
- Io_NtkWriteNodeGate( pFile, pNode, Length );
- fprintf( pFile, "\n" );
+ // get the fanin name
+ pName = Abc_ObjName(pNet);
+ // get the line length after the fanin name is written
+ AddedLength = strlen(pName) + 1;
+ if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
+ { // write the line extender
+ fprintf( pFile, " \\\n" );
+ // reset the line length
+ LineLength = 0;
+ NameCounter = 0;
+ }
+ fprintf( pFile, " %s", pName );
+ LineLength += AddedLength;
+ NameCounter++;
}
- else
- {
- // write the .names line
- fprintf( pFile, ".names" );
- Io_NtkWriteNodeFanins( pFile, pNode );
- fprintf( pFile, "\n" );
- // write the cubes
- fprintf( pFile, "%s", (char*)Abc_ObjData(pNode) );
+
+ // get the output name
+ pName = Abc_ObjName(Abc_ObjFanout0(pNode));
+ // get the line length after the output name is written
+ AddedLength = strlen(pName) + 1;
+ if ( NameCounter && LineLength + AddedLength > 75 )
+ { // write the line extender
+ fprintf( pFile, " \\\n" );
+ // reset the line length
+ LineLength = 0;
+ NameCounter = 0;
}
+ fprintf( pFile, " %s", pName );
}
/**Function*************************************************************
@@ -502,10 +525,12 @@ void Io_NtkWriteNode( FILE * pFile, Abc_Obj_t * pNode, int Length )
SeeAlso []
***********************************************************************/
-void Io_NtkWriteNodeGate( FILE * pFile, Abc_Obj_t * pNode, int Length )
+int Io_NtkWriteNodeGate( FILE * pFile, Abc_Obj_t * pNode, int Length )
{
Mio_Gate_t * pGate = (Mio_Gate_t *)pNode->pData;
+ Mio_Gate_t * pGate2;
Mio_Pin_t * pGatePin;
+ Abc_Obj_t * pNode2;
int i;
// write the node
fprintf( pFile, " %-*s ", Length, Mio_GateReadName(pGate) );
@@ -513,11 +538,33 @@ void Io_NtkWriteNodeGate( FILE * pFile, Abc_Obj_t * pNode, int Length )
fprintf( pFile, "%s=%s ", Mio_PinReadName(pGatePin), Abc_ObjName( Abc_ObjFanin(pNode,i) ) );
assert ( i == Abc_ObjFaninNum(pNode) );
fprintf( pFile, "%s=%s", Mio_GateReadOutName(pGate), Abc_ObjName( Abc_ObjFanout0(pNode) ) );
+ if ( Mio_GateReadTwin(pGate) == NULL )
+ return 0;
+ // assuming the twin node is following next
+ if ( (int)Abc_ObjId(pNode) == Abc_NtkObjNumMax(pNode->pNtk) - 1 )
+ {
+ printf( "Warning: Missing second output of gate \"%s\".\n", Mio_GateReadName(pGate) );
+ return 0;
+ }
+ pNode2 = Abc_NtkObj( pNode->pNtk, Abc_ObjId(pNode) + 1 );
+ if ( !Abc_ObjIsNode(pNode2) || Abc_ObjFaninNum(pNode) != Abc_ObjFaninNum(pNode2) )
+ {
+ printf( "Warning: Missing second output of gate \"%s\".\n", Mio_GateReadName(pGate) );
+ return 0;
+ }
+ pGate2 = (Mio_Gate_t *)pNode2->pData;
+ if ( strcmp( Mio_GateReadName(pGate), Mio_GateReadName(pGate2)) )
+ {
+ printf( "Warning: Missing second output of gate \"%s\".\n", Mio_GateReadName(pGate) );
+ return 0;
+ }
+ fprintf( pFile, " %s=%s", Mio_GateReadOutName(pGate2), Abc_ObjName( Abc_ObjFanout0(pNode2) ) );
+ return 1;
}
/**Function*************************************************************
- Synopsis [Writes the primary input list.]
+ Synopsis [Write the node into a file.]
Description []
@@ -526,47 +573,26 @@ void Io_NtkWriteNodeGate( FILE * pFile, Abc_Obj_t * pNode, int Length )
SeeAlso []
***********************************************************************/
-void Io_NtkWriteNodeFanins( FILE * pFile, Abc_Obj_t * pNode )
+int Io_NtkWriteNode( FILE * pFile, Abc_Obj_t * pNode, int Length )
{
- Abc_Obj_t * pNet;
- int LineLength;
- int AddedLength;
- int NameCounter;
- char * pName;
- int i;
-
- LineLength = 6;
- NameCounter = 0;
- Abc_ObjForEachFanin( pNode, pNet, i )
+ int RetValue = 0;
+ if ( Abc_NtkHasMapping(pNode->pNtk) )
{
- // get the fanin name
- pName = Abc_ObjName(pNet);
- // get the line length after the fanin name is written
- AddedLength = strlen(pName) + 1;
- if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
- { // write the line extender
- fprintf( pFile, " \\\n" );
- // reset the line length
- LineLength = 0;
- NameCounter = 0;
- }
- fprintf( pFile, " %s", pName );
- LineLength += AddedLength;
- NameCounter++;
+ // write the .gate line
+ fprintf( pFile, ".gate" );
+ RetValue = Io_NtkWriteNodeGate( pFile, pNode, Length );
+ fprintf( pFile, "\n" );
}
-
- // get the output name
- pName = Abc_ObjName(Abc_ObjFanout0(pNode));
- // get the line length after the output name is written
- AddedLength = strlen(pName) + 1;
- if ( NameCounter && LineLength + AddedLength > 75 )
- { // write the line extender
- fprintf( pFile, " \\\n" );
- // reset the line length
- LineLength = 0;
- NameCounter = 0;
+ else
+ {
+ // write the .names line
+ fprintf( pFile, ".names" );
+ Io_NtkWriteNodeFanins( pFile, pNode );
+ fprintf( pFile, "\n" );
+ // write the cubes
+ fprintf( pFile, "%s", (char*)Abc_ObjData(pNode) );
}
- fprintf( pFile, " %s", pName );
+ return RetValue;
}
/**Function*************************************************************