summaryrefslogtreecommitdiffstats
path: root/src/base/io/ioWriteEqn.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2008-01-30 20:01:00 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2008-01-30 20:01:00 -0800
commit0c6505a26a537dc911b6566f82d759521e527c08 (patch)
treef2687995efd4943fe3b1307fce7ef5942d0a57b3 /src/base/io/ioWriteEqn.c
parent4d30a1e4f1edecff86d5066ce4653a370e59e5e1 (diff)
downloadabc-0c6505a26a537dc911b6566f82d759521e527c08.tar.gz
abc-0c6505a26a537dc911b6566f82d759521e527c08.tar.bz2
abc-0c6505a26a537dc911b6566f82d759521e527c08.zip
Version abc80130_2
Diffstat (limited to 'src/base/io/ioWriteEqn.c')
-rw-r--r--src/base/io/ioWriteEqn.c117
1 files changed, 54 insertions, 63 deletions
diff --git a/src/base/io/ioWriteEqn.c b/src/base/io/ioWriteEqn.c
index 6c2893b5..95c54577 100644
--- a/src/base/io/ioWriteEqn.c
+++ b/src/base/io/ioWriteEqn.c
@@ -25,12 +25,12 @@
////////////////////////////////////////////////////////////////////////
static void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk );
-static void Io_NtkWriteEqnPis( FILE * pFile, Abc_Ntk_t * pNtk );
-static void Io_NtkWriteEqnPos( FILE * pFile, Abc_Ntk_t * pNtk );
-static void Io_NtkWriteEqnNode( FILE * pFile, Abc_Obj_t * pNode );
+static void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk );
+static void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk );
+static int Io_NtkWriteEqnCheck( Abc_Ntk_t * pNtk );
////////////////////////////////////////////////////////////////////////
-/// FUNCTION DEFITIONS ///
+/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
@@ -48,10 +48,14 @@ void Io_WriteEqn( Abc_Ntk_t * pNtk, char * pFileName )
{
FILE * pFile;
- assert( Abc_NtkIsSopNetlist(pNtk) );
+ assert( Abc_NtkIsAigNetlist(pNtk) );
if ( Abc_NtkLatchNum(pNtk) > 0 )
printf( "Warning: only combinational portion is being written.\n" );
+ // check that the names are fine for the EQN format
+ if ( !Io_NtkWriteEqnCheck(pNtk) )
+ return;
+
// start the output stream
pFile = fopen( pFileName, "w" );
if ( pFile == NULL )
@@ -80,28 +84,37 @@ void Io_WriteEqn( Abc_Ntk_t * pNtk, char * pFileName )
***********************************************************************/
void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk )
{
+ Vec_Vec_t * vLevels;
ProgressBar * pProgress;
- Abc_Obj_t * pNode;
- int i;
+ Abc_Obj_t * pNode, * pFanin;
+ int i, k;
// write the PIs
fprintf( pFile, "INORDER =" );
- Io_NtkWriteEqnPis( pFile, pNtk );
+ Io_NtkWriteEqnCis( pFile, pNtk );
fprintf( pFile, ";\n" );
// write the POs
fprintf( pFile, "OUTORDER =" );
- Io_NtkWriteEqnPos( pFile, pNtk );
+ Io_NtkWriteEqnCos( pFile, pNtk );
fprintf( pFile, ";\n" );
// write each internal node
+ vLevels = Vec_VecAlloc( 10 );
pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
Abc_NtkForEachNode( pNtk, pNode, i )
{
Extra_ProgressBarUpdate( pProgress, i, NULL );
- Io_NtkWriteEqnNode( pFile, pNode );
+ fprintf( pFile, "%s = ", Abc_ObjName(Abc_ObjFanout0(pNode)) );
+ // set the input names
+ Abc_ObjForEachFanin( pNode, pFanin, k )
+ Hop_IthVar(pNtk->pManFunc, k)->pData = Abc_ObjName(pFanin);
+ // write the formula
+ Hop_ObjPrintEqn( pFile, pNode->pData, vLevels, 0 );
+ fprintf( pFile, ";\n" );
}
Extra_ProgressBarStop( pProgress );
+ Vec_VecFree( vLevels );
}
@@ -116,7 +129,7 @@ void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk )
SeeAlso []
***********************************************************************/
-void Io_NtkWriteEqnPis( FILE * pFile, Abc_Ntk_t * pNtk )
+void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk )
{
Abc_Obj_t * pTerm, * pNet;
int LineLength;
@@ -156,7 +169,7 @@ void Io_NtkWriteEqnPis( FILE * pFile, Abc_Ntk_t * pNtk )
SeeAlso []
***********************************************************************/
-void Io_NtkWriteEqnPos( FILE * pFile, Abc_Ntk_t * pNtk )
+void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk )
{
Abc_Obj_t * pTerm, * pNet;
int LineLength;
@@ -187,73 +200,51 @@ void Io_NtkWriteEqnPos( FILE * pFile, Abc_Ntk_t * pNtk )
/**Function*************************************************************
- Synopsis [Write the node into a file.]
+ Synopsis [Make sure the network does not have offending names.]
Description []
-
+
SideEffects []
SeeAlso []
***********************************************************************/
-void Io_NtkWriteEqnNode( FILE * pFile, Abc_Obj_t * pNode )
+int Io_NtkWriteEqnCheck( Abc_Ntk_t * pNtk )
{
- Abc_Obj_t * pNet;
- int LineLength;
- int AddedLength;
- int NameCounter;
- char * pCube;
- int Value, fFirstLit, i;
-
- fprintf( pFile, "%s = ", Abc_ObjName(pNode) );
-
- if ( Abc_SopIsConst0(pNode->pData) )
- {
- fprintf( pFile, "0;\n" );
- return;
- }
- if ( Abc_SopIsConst1(pNode->pData) )
- {
- fprintf( pFile, "1;\n" );
- return;
- }
+ Abc_Obj_t * pObj;
+ char * pName;
+ int i, k, Length;
+ int RetValue = 1;
- NameCounter = 0;
- LineLength = strlen(Abc_ObjName(pNode)) + 3;
- Abc_SopForEachCube( pNode->pData, Abc_ObjFaninNum(pNode), pCube )
+ // make sure the network does not have proper names, such as "0" or "1" or containing parantheses
+ Abc_NtkForEachObj( pNtk, pObj, i )
{
- if ( pCube != pNode->pData )
+ pName = Nm_ManFindNameById(pNtk->pManName, i);
+ if ( pName == NULL )
+ continue;
+ Length = strlen(pName);
+ if ( pName[0] == '0' || pName[0] == '1' )
{
- fprintf( pFile, " + " );
- LineLength += 3;
+ RetValue = 0;
+ break;
}
-
- // add the cube
- fFirstLit = 1;
- Abc_CubeForEachVar( pCube, Value, i )
- {
- if ( Value == '-' )
- continue;
- pNet = Abc_ObjFanin( pNode, i );
- // get the line length after this name is written
- AddedLength = !fFirstLit + (Value == '0') + strlen(Abc_ObjName(pNet));
- if ( NameCounter && LineLength + AddedLength + 6 > IO_WRITE_LINE_LENGTH )
- { // write the line extender
- fprintf( pFile, " \n " );
- // reset the line length
- LineLength = 0;
- NameCounter = 0;
+ for ( k = 0; k < Length; k++ )
+ if ( pName[k] == '(' || pName[k] == ')' || pName[k] == '!' || pName[k] == '*' || pName[k] == '+' )
+ {
+ RetValue = 0;
+ break;
}
- fprintf( pFile, "%s%s%s", (fFirstLit? "": "*"), ((Value == '0')? "!":""), Abc_ObjName(pNet) );
- LineLength += AddedLength;
- NameCounter++;
- fFirstLit = 0;
- }
+ if ( k < Length )
+ break;
}
- fprintf( pFile, ";\n" );
+ if ( RetValue == 0 )
+ {
+ printf( "The network cannot be written in the EQN format because object %d has name \"%s\".\n", i, pName );
+ printf( "Consider renaming the objects using command \"short_names\" and trying again.\n" );
+ }
+ return RetValue;
}
-
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////