abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWriteEqn.c File Reference
#include "ioAbc.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START void 
Io_NtkWriteEqnOne (FILE *pFile, Abc_Ntk_t *pNtk)
 DECLARATIONS ///. More...
 
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)
 
void Io_WriteEqn (Abc_Ntk_t *pNtk, char *pFileName)
 FUNCTION DEFINITIONS ///. More...
 

Function Documentation

int Io_NtkWriteEqnCheck ( Abc_Ntk_t pNtk)
static

Function*************************************************************

Synopsis [Make sure the network does not have offending names.]

Description []

SideEffects []

SeeAlso []

Definition at line 215 of file ioWriteEqn.c.

216 {
217  Abc_Obj_t * pObj;
218  char * pName = NULL;
219  int i, k, Length;
220  int RetValue = 1;
221 
222  // make sure the network does not have proper names, such as "0" or "1" or containing parantheses
223  Abc_NtkForEachObj( pNtk, pObj, i )
224  {
225  pName = Nm_ManFindNameById(pNtk->pManName, i);
226  if ( pName == NULL )
227  continue;
228  Length = strlen(pName);
229  if ( pName[0] == '0' || pName[0] == '1' )
230  {
231  RetValue = 0;
232  break;
233  }
234  for ( k = 0; k < Length; k++ )
235  if ( pName[k] == '(' || pName[k] == ')' || pName[k] == '!' || pName[k] == '*' || pName[k] == '+' )
236  {
237  RetValue = 0;
238  break;
239  }
240  if ( k < Length )
241  break;
242  }
243  if ( RetValue == 0 )
244  {
245  printf( "The network cannot be written in the EQN format because object %d has name \"%s\".\n", i, pName );
246  printf( "Consider renaming the objects using command \"short_names\" and trying again.\n" );
247  }
248  return RetValue;
249 }
Nm_Man_t * pManName
Definition: abc.h:160
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:199
int strlen()
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
void Io_NtkWriteEqnCis ( FILE *  pFile,
Abc_Ntk_t pNtk 
)
static

Function*************************************************************

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 135 of file ioWriteEqn.c.

136 {
137  Abc_Obj_t * pTerm, * pNet;
138  int LineLength;
139  int AddedLength;
140  int NameCounter;
141  int i;
142 
143  LineLength = 9;
144  NameCounter = 0;
145 
146  Abc_NtkForEachCi( pNtk, pTerm, i )
147  {
148  pNet = Abc_ObjFanout0(pTerm);
149  // get the line length after this name is written
150  AddedLength = strlen(Abc_ObjName(pNet)) + 1;
151  if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
152  { // write the line extender
153  fprintf( pFile, " \n" );
154  // reset the line length
155  LineLength = 0;
156  NameCounter = 0;
157  }
158  fprintf( pFile, " %s", Abc_ObjName(pNet) );
159  LineLength += AddedLength;
160  NameCounter++;
161  }
162 }
#define IO_WRITE_LINE_LENGTH
MACRO DEFINITIONS ///.
Definition: ioAbc.h:71
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
int strlen()
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
void Io_NtkWriteEqnCos ( FILE *  pFile,
Abc_Ntk_t pNtk 
)
static

Function*************************************************************

Synopsis [Writes the primary input list.]

Description []

SideEffects []

SeeAlso []

Definition at line 175 of file ioWriteEqn.c.

176 {
177  Abc_Obj_t * pTerm, * pNet;
178  int LineLength;
179  int AddedLength;
180  int NameCounter;
181  int i;
182 
183  LineLength = 10;
184  NameCounter = 0;
185 
186  Abc_NtkForEachCo( pNtk, pTerm, i )
187  {
188  pNet = Abc_ObjFanin0(pTerm);
189  // get the line length after this name is written
190  AddedLength = strlen(Abc_ObjName(pNet)) + 1;
191  if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
192  { // write the line extender
193  fprintf( pFile, " \n" );
194  // reset the line length
195  LineLength = 0;
196  NameCounter = 0;
197  }
198  fprintf( pFile, " %s", Abc_ObjName(pNet) );
199  LineLength += AddedLength;
200  NameCounter++;
201  }
202 }
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
#define IO_WRITE_LINE_LENGTH
MACRO DEFINITIONS ///.
Definition: ioAbc.h:71
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
int strlen()
void Io_NtkWriteEqnOne ( FILE *  pFile,
Abc_Ntk_t pNtk 
)
static

DECLARATIONS ///.

CFile****************************************************************

FileName [ioWriteEqn.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to write equation representation of the network.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
ioWriteEqn.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Function*************************************************************

Synopsis [Write one network.]

Description []

SideEffects []

SeeAlso []

Definition at line 88 of file ioWriteEqn.c.

89 {
90  Vec_Vec_t * vLevels;
91  ProgressBar * pProgress;
92  Abc_Obj_t * pNode, * pFanin;
93  int i, k;
94 
95  // write the PIs
96  fprintf( pFile, "INORDER =" );
97  Io_NtkWriteEqnCis( pFile, pNtk );
98  fprintf( pFile, ";\n" );
99 
100  // write the POs
101  fprintf( pFile, "OUTORDER =" );
102  Io_NtkWriteEqnCos( pFile, pNtk );
103  fprintf( pFile, ";\n" );
104 
105  // write each internal node
106  vLevels = Vec_VecAlloc( 10 );
107  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
108  Abc_NtkForEachNode( pNtk, pNode, i )
109  {
110  Extra_ProgressBarUpdate( pProgress, i, NULL );
111  fprintf( pFile, "%s = ", Abc_ObjName(Abc_ObjFanout0(pNode)) );
112  // set the input names
113  Abc_ObjForEachFanin( pNode, pFanin, k )
114  Hop_IthVar((Hop_Man_t *)pNtk->pManFunc, k)->pData = Abc_ObjName(pFanin);
115  // write the formula
116  Hop_ObjPrintEqn( pFile, (Hop_Obj_t *)pNode->pData, vLevels, 0 );
117  fprintf( pFile, ";\n" );
118  }
119  Extra_ProgressBarStop( pProgress );
120  Vec_VecFree( vLevels );
121 }
static Vec_Vec_t * Vec_VecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecVec.h:145
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static void Io_NtkWriteEqnCos(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteEqn.c:175
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
Definition: hop.h:65
static void Io_NtkWriteEqnCis(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteEqn.c:135
DECLARATIONS ///.
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
void Hop_ObjPrintEqn(FILE *pFile, Hop_Obj_t *pObj, Vec_Vec_t *vLevels, int Level)
Definition: hopUtil.c:322
void Io_WriteEqn ( Abc_Ntk_t pNtk,
char *  pFileName 
)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Writes the logic network in the equation format.]

Description []

SideEffects []

SeeAlso []

Definition at line 50 of file ioWriteEqn.c.

51 {
52  FILE * pFile;
53 
54  assert( Abc_NtkIsAigNetlist(pNtk) );
55  if ( Abc_NtkLatchNum(pNtk) > 0 )
56  printf( "Warning: only combinational portion is being written.\n" );
57 
58  // check that the names are fine for the EQN format
59  if ( !Io_NtkWriteEqnCheck(pNtk) )
60  return;
61 
62  // start the output stream
63  pFile = fopen( pFileName, "w" );
64  if ( pFile == NULL )
65  {
66  fprintf( stdout, "Io_WriteEqn(): Cannot open the output file \"%s\".\n", pFileName );
67  return;
68  }
69  fprintf( pFile, "# Equations for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
70 
71  // write the equations for the network
72  Io_NtkWriteEqnOne( pFile, pNtk );
73  fprintf( pFile, "\n" );
74  fclose( pFile );
75 }
static ABC_NAMESPACE_IMPL_START void Io_NtkWriteEqnOne(FILE *pFile, Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWriteEqn.c:88
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static int Abc_NtkIsAigNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:261
char * Extra_TimeStamp()
#define assert(ex)
Definition: util_old.h:213
char * pName
Definition: abc.h:158
static int Io_NtkWriteEqnCheck(Abc_Ntk_t *pNtk)
Definition: ioWriteEqn.c:215