abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWriteBench.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioWriteBench.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedures to write the network in BENCH format.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: ioWriteBench.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ioAbc.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static int Io_WriteBenchCheckNames( Abc_Ntk_t * pNtk );
31 
32 static int Io_WriteBenchOne( FILE * pFile, Abc_Ntk_t * pNtk );
33 static int Io_WriteBenchOneNode( FILE * pFile, Abc_Obj_t * pNode );
34 
35 static int Io_WriteBenchLutOne( FILE * pFile, Abc_Ntk_t * pNtk );
36 static int Io_WriteBenchLutOneNode( FILE * pFile, Abc_Obj_t * pNode, Vec_Int_t * vTruth );
37 
38 ////////////////////////////////////////////////////////////////////////
39 /// FUNCTION DEFINITIONS ///
40 ////////////////////////////////////////////////////////////////////////
41 
42 /**Function*************************************************************
43 
44  Synopsis [Writes the network in BENCH format.]
45 
46  Description []
47 
48  SideEffects []
49 
50  SeeAlso []
51 
52 ***********************************************************************/
53 int Io_WriteBench( Abc_Ntk_t * pNtk, const char * pFileName )
54 {
55  Abc_Ntk_t * pExdc;
56  FILE * pFile;
57  assert( Abc_NtkIsSopNetlist(pNtk) );
58  if ( !Io_WriteBenchCheckNames(pNtk) )
59  {
60  fprintf( stdout, "Io_WriteBench(): Signal names in this benchmark contain parantheses making them impossible to reproduce in the BENCH format. Use \"short_names\".\n" );
61  return 0;
62  }
63  pFile = fopen( pFileName, "w" );
64  if ( pFile == NULL )
65  {
66  fprintf( stdout, "Io_WriteBench(): Cannot open the output file.\n" );
67  return 0;
68  }
69  fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
70  // write the network
71  Io_WriteBenchOne( pFile, pNtk );
72  // write EXDC network if it exists
73  pExdc = Abc_NtkExdc( pNtk );
74  if ( pExdc )
75  printf( "Io_WriteBench: EXDC is not written (warning).\n" );
76  // finalize the file
77  fclose( pFile );
78  return 1;
79 }
80 
81 /**Function*************************************************************
82 
83  Synopsis [Writes the network in BENCH format.]
84 
85  Description []
86 
87  SideEffects []
88 
89  SeeAlso []
90 
91 ***********************************************************************/
92 int Io_WriteBenchOne( FILE * pFile, Abc_Ntk_t * pNtk )
93 {
94  ProgressBar * pProgress;
95  Abc_Obj_t * pNode;
96  int i;
97 
98  // write the PIs/POs/latches
99  Abc_NtkForEachPi( pNtk, pNode, i )
100  fprintf( pFile, "INPUT(%s)\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
101  Abc_NtkForEachPo( pNtk, pNode, i )
102  fprintf( pFile, "OUTPUT(%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
103  Abc_NtkForEachLatch( pNtk, pNode, i )
104  fprintf( pFile, "%-11s = DFF(%s)\n",
106 
107  // write internal nodes
108  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
109  Abc_NtkForEachNode( pNtk, pNode, i )
110  {
111  Extra_ProgressBarUpdate( pProgress, i, NULL );
112  Io_WriteBenchOneNode( pFile, pNode );
113  }
114  Extra_ProgressBarStop( pProgress );
115  return 1;
116 }
117 
118 
119 /**Function*************************************************************
120 
121  Synopsis [Writes the network in BENCH format.]
122 
123  Description []
124 
125  SideEffects []
126 
127  SeeAlso []
128 
129 ***********************************************************************/
130 int Io_WriteBenchOneNode( FILE * pFile, Abc_Obj_t * pNode )
131 {
132  int nFanins;
133 
134  assert( Abc_ObjIsNode(pNode) );
135  nFanins = Abc_ObjFaninNum(pNode);
136  if ( nFanins == 0 )
137  { // write the constant 1 node
138  assert( Abc_NodeIsConst1(pNode) );
139  fprintf( pFile, "%-11s", Abc_ObjName(Abc_ObjFanout0(pNode)) );
140  fprintf( pFile, " = vdd\n" );
141  }
142  else if ( nFanins == 1 )
143  { // write the interver/buffer
144  if ( Abc_NodeIsBuf(pNode) )
145  {
146  fprintf( pFile, "%-11s = BUFF(", Abc_ObjName(Abc_ObjFanout0(pNode)) );
147  fprintf( pFile, "%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
148  }
149  else
150  {
151  fprintf( pFile, "%-11s = NOT(", Abc_ObjName(Abc_ObjFanout0(pNode)) );
152  fprintf( pFile, "%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
153  }
154  }
155  else
156  { // write the AND gate
157  fprintf( pFile, "%-11s", Abc_ObjName(Abc_ObjFanout0(pNode)) );
158  fprintf( pFile, " = AND(%s, ", Abc_ObjName(Abc_ObjFanin0(pNode)) );
159  fprintf( pFile, "%s)\n", Abc_ObjName(Abc_ObjFanin1(pNode)) );
160  }
161  return 1;
162 }
163 
164 /**Function*************************************************************
165 
166  Synopsis [Writes the network in BENCH format with LUTs and DFFRSE.]
167 
168  Description []
169 
170  SideEffects []
171 
172  SeeAlso []
173 
174 ***********************************************************************/
175 int Io_WriteBenchLut( Abc_Ntk_t * pNtk, char * pFileName )
176 {
177  Abc_Ntk_t * pExdc;
178  FILE * pFile;
179  assert( Abc_NtkIsAigNetlist(pNtk) );
180  if ( !Io_WriteBenchCheckNames(pNtk) )
181  {
182  fprintf( stdout, "Io_WriteBenchLut(): Signal names in this benchmark contain parantheses making them impossible to reproduce in the BENCH format. Use \"short_names\".\n" );
183  return 0;
184  }
185  pFile = fopen( pFileName, "w" );
186  if ( pFile == NULL )
187  {
188  fprintf( stdout, "Io_WriteBench(): Cannot open the output file.\n" );
189  return 0;
190  }
191  fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
192  // write the network
193  Io_WriteBenchLutOne( pFile, pNtk );
194  // write EXDC network if it exists
195  pExdc = Abc_NtkExdc( pNtk );
196  if ( pExdc )
197  printf( "Io_WriteBench: EXDC is not written (warning).\n" );
198  // finalize the file
199  fclose( pFile );
200  return 1;
201 }
202 
203 /**Function*************************************************************
204 
205  Synopsis [Writes the network in BENCH format.]
206 
207  Description []
208 
209  SideEffects []
210 
211  SeeAlso []
212 
213 ***********************************************************************/
214 int Io_WriteBenchLutOne( FILE * pFile, Abc_Ntk_t * pNtk )
215 {
216  ProgressBar * pProgress;
217  Abc_Obj_t * pNode;
218  Vec_Int_t * vMemory;
219  int i;
220 
221  // write the PIs/POs/latches
222  Abc_NtkForEachPi( pNtk, pNode, i )
223  fprintf( pFile, "INPUT(%s)\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
224  Abc_NtkForEachPo( pNtk, pNode, i )
225  fprintf( pFile, "OUTPUT(%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
226  Abc_NtkForEachLatch( pNtk, pNode, i )
227  fprintf( pFile, "%-11s = DFFRSE( %s, gnd, gnd, gnd, gnd )\n",
229 //Abc_NtkLevel(pNtk);
230  // write internal nodes
231  vMemory = Vec_IntAlloc( 10000 );
232  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
233  Abc_NtkForEachNode( pNtk, pNode, i )
234  {
235  Extra_ProgressBarUpdate( pProgress, i, NULL );
236  Io_WriteBenchLutOneNode( pFile, pNode, vMemory );
237  }
238  Extra_ProgressBarStop( pProgress );
239  Vec_IntFree( vMemory );
240  return 1;
241 }
242 
243 
244 /**Function*************************************************************
245 
246  Synopsis [Writes the network in BENCH format.]
247 
248  Description []
249 
250  SideEffects []
251 
252  SeeAlso []
253 
254 ***********************************************************************/
255 int Io_WriteBenchLutOneNode( FILE * pFile, Abc_Obj_t * pNode, Vec_Int_t * vTruth )
256 {
257  Abc_Obj_t * pFanin;
258  unsigned * pTruth;
259  int i, nFanins;
260  assert( Abc_ObjIsNode(pNode) );
261  nFanins = Abc_ObjFaninNum(pNode);
262  assert( nFanins <= 8 );
263  // compute the truth table
264  pTruth = Hop_ManConvertAigToTruth( (Hop_Man_t *)pNode->pNtk->pManFunc, Hop_Regular((Hop_Obj_t *)pNode->pData), nFanins, vTruth, 0 );
265  if ( Hop_IsComplement((Hop_Obj_t *)pNode->pData) )
266  Extra_TruthNot( pTruth, pTruth, nFanins );
267  // consider simple cases
268  if ( Extra_TruthIsConst0(pTruth, nFanins) )
269  {
270  fprintf( pFile, "%-11s = gnd\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
271  return 1;
272  }
273  if ( Extra_TruthIsConst1(pTruth, nFanins) )
274  {
275  fprintf( pFile, "%-11s = vdd\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
276  return 1;
277  }
278  if ( nFanins == 1 )
279  {
280  fprintf( pFile, "%-11s = LUT 0x%d ( %s )\n",
281  Abc_ObjName(Abc_ObjFanout0(pNode)),
282  Abc_NodeIsBuf(pNode)? 2 : 1,
283  Abc_ObjName(Abc_ObjFanin0(pNode)) );
284  return 1;
285  }
286  // write it in the hexadecimal form
287  fprintf( pFile, "%-11s = LUT 0x", Abc_ObjName(Abc_ObjFanout0(pNode)) );
288  Extra_PrintHexadecimal( pFile, pTruth, nFanins );
289 /*
290  {
291 extern void Kit_DsdTest( unsigned * pTruth, int nVars );
292 Abc_ObjForEachFanin( pNode, pFanin, i )
293 printf( "%c%d ", 'a'+i, Abc_ObjFanin0(pFanin)->Level );
294 printf( "\n" );
295 Kit_DsdTest( pTruth, nFanins );
296  }
297  if ( pNode->Id % 1000 == 0 )
298  {
299  int x = 0;
300  }
301 */
302  // write the fanins
303  fprintf( pFile, " (" );
304  Abc_ObjForEachFanin( pNode, pFanin, i )
305  fprintf( pFile, " %s%s", Abc_ObjName(pFanin), ((i==nFanins-1)? "" : ",") );
306  fprintf( pFile, " )\n" );
307  return 1;
308 }
309 
310 
311 /**Function*************************************************************
312 
313  Synopsis [Returns 1 if the names cannot be written into the bench file.]
314 
315  Description []
316 
317  SideEffects []
318 
319  SeeAlso []
320 
321 ***********************************************************************/
323 {
324  Abc_Obj_t * pObj;
325  char * pName;
326  int i;
327  Abc_NtkForEachObj( pNtk, pObj, i )
328  for ( pName = Nm_ManFindNameById(pNtk->pManName, i); pName && *pName; pName++ )
329  if ( *pName == '(' || *pName == ')' )
330  return 0;
331  return 1;
332 }
333 
334 ////////////////////////////////////////////////////////////////////////
335 /// END OF FILE ///
336 ////////////////////////////////////////////////////////////////////////
337 
338 
340 
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static int Io_WriteBenchOneNode(FILE *pFile, Abc_Obj_t *pNode)
Definition: ioWriteBench.c:130
Nm_Man_t * pManName
Definition: abc.h:160
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static Abc_Ntk_t * Abc_NtkExdc(Abc_Ntk_t *pNtk)
Definition: abc.h:272
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
Definition: hop.h:65
static ABC_NAMESPACE_IMPL_START int Io_WriteBenchCheckNames(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWriteBench.c:322
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition: abcObj.c:920
int Io_WriteBench(Abc_Ntk_t *pNtk, const char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: ioWriteBench.c:53
void * pManFunc
Definition: abc.h:191
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
DECLARATIONS ///.
static int Io_WriteBenchLutOne(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteBench.c:214
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Io_WriteBenchLutOneNode(FILE *pFile, Abc_Obj_t *pNode, Vec_Int_t *vTruth)
Definition: ioWriteBench.c:255
static int Abc_NtkIsAigNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:261
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:199
int Io_WriteBenchLut(Abc_Ntk_t *pNtk, char *pFileName)
Definition: ioWriteBench.c:175
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
static int Io_WriteBenchOne(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteBench.c:92
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Extra_TruthIsConst1(unsigned *pIn, int nVars)
Definition: extra.h:286
Abc_Ntk_t * pNtk
Definition: abc.h:130
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
char * Extra_TimeStamp()
static int Abc_NtkIsSopNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:260
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
static int Extra_TruthIsConst0(unsigned *pIn, int nVars)
Definition: extra.h:278
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Definition: hopTruth.c:143
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition: abcObj.c:890
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
void Extra_PrintHexadecimal(FILE *pFile, unsigned Sign[], int nVars)
void * pData
Definition: abc.h:145
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
static void Extra_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:320
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
char * pName
Definition: abc.h:158
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513