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

Go to the source code of this file.

Functions

static ABC_NAMESPACE_IMPL_START int Io_WriteBenchCheckNames (Abc_Ntk_t *pNtk)
 DECLARATIONS ///. More...
 
static int Io_WriteBenchOne (FILE *pFile, Abc_Ntk_t *pNtk)
 
static int Io_WriteBenchOneNode (FILE *pFile, Abc_Obj_t *pNode)
 
static int Io_WriteBenchLutOne (FILE *pFile, Abc_Ntk_t *pNtk)
 
static int Io_WriteBenchLutOneNode (FILE *pFile, Abc_Obj_t *pNode, Vec_Int_t *vTruth)
 
int Io_WriteBench (Abc_Ntk_t *pNtk, const char *pFileName)
 FUNCTION DEFINITIONS ///. More...
 
int Io_WriteBenchLut (Abc_Ntk_t *pNtk, char *pFileName)
 

Function Documentation

int Io_WriteBench ( Abc_Ntk_t pNtk,
const char *  pFileName 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Writes the network in BENCH format.]

Description []

SideEffects []

SeeAlso []

Definition at line 53 of file ioWriteBench.c.

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 }
static Abc_Ntk_t * Abc_NtkExdc(Abc_Ntk_t *pNtk)
Definition: abc.h:272
static ABC_NAMESPACE_IMPL_START int Io_WriteBenchCheckNames(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWriteBench.c:322
static int Io_WriteBenchOne(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteBench.c:92
char * Extra_TimeStamp()
static int Abc_NtkIsSopNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:260
#define assert(ex)
Definition: util_old.h:213
char * pName
Definition: abc.h:158
int Io_WriteBenchCheckNames ( Abc_Ntk_t pNtk)
static

DECLARATIONS ///.

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

FileName [ioWriteBench.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to write the network in BENCH format.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]

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

Synopsis [Returns 1 if the names cannot be written into the bench file.]

Description []

SideEffects []

SeeAlso []

Definition at line 322 of file ioWriteBench.c.

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 }
for(p=first;p->value< newval;p=p->next)
if(last==0)
Definition: sparse_int.h:34
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:199
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
int Io_WriteBenchLut ( Abc_Ntk_t pNtk,
char *  pFileName 
)

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

Synopsis [Writes the network in BENCH format with LUTs and DFFRSE.]

Description []

SideEffects []

SeeAlso []

Definition at line 175 of file ioWriteBench.c.

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 }
static Abc_Ntk_t * Abc_NtkExdc(Abc_Ntk_t *pNtk)
Definition: abc.h:272
static ABC_NAMESPACE_IMPL_START int Io_WriteBenchCheckNames(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWriteBench.c:322
static int Io_WriteBenchLutOne(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteBench.c:214
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
int Io_WriteBenchLutOne ( FILE *  pFile,
Abc_Ntk_t pNtk 
)
static

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

Synopsis [Writes the network in BENCH format.]

Description []

SideEffects []

SeeAlso []

Definition at line 214 of file ioWriteBench.c.

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 }
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
DECLARATIONS ///.
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
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
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
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
int Io_WriteBenchLutOneNode ( FILE *  pFile,
Abc_Obj_t pNode,
Vec_Int_t vTruth 
)
static

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

Synopsis [Writes the network in BENCH format.]

Description []

SideEffects []

SeeAlso []

Definition at line 255 of file ioWriteBench.c.

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 }
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
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition: abcObj.c:920
void * pManFunc
Definition: abc.h:191
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
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
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
#define assert(ex)
Definition: util_old.h:213
void Extra_PrintHexadecimal(FILE *pFile, unsigned Sign[], int nVars)
void * pData
Definition: abc.h:145
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
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
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
int Io_WriteBenchOne ( FILE *  pFile,
Abc_Ntk_t pNtk 
)
static

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

Synopsis [Writes the network in BENCH format.]

Description []

SideEffects []

SeeAlso []

Definition at line 92 of file ioWriteBench.c.

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 }
static int Io_WriteBenchOneNode(FILE *pFile, Abc_Obj_t *pNode)
Definition: ioWriteBench.c:130
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
DECLARATIONS ///.
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
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
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
int Io_WriteBenchOneNode ( FILE *  pFile,
Abc_Obj_t pNode 
)
static

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

Synopsis [Writes the network in BENCH format.]

Description []

SideEffects []

SeeAlso []

Definition at line 130 of file ioWriteBench.c.

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 }
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
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
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition: abcObj.c:920
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition: abcObj.c:890
#define assert(ex)
Definition: util_old.h:213
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371