ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioWriteBench.c
Go to the documentation of this file.
1
20
21#include "ioAbc.h"
22
24
25
29
30static int Io_WriteBenchCheckNames( Abc_Ntk_t * pNtk );
31
32static int Io_WriteBenchOne( FILE * pFile, Abc_Ntk_t * pNtk );
33static int Io_WriteBenchOneNode( FILE * pFile, Abc_Obj_t * pNode );
34
35static int Io_WriteBenchLutOne( FILE * pFile, Abc_Ntk_t * pNtk );
36static int Io_WriteBenchLutOneNode( FILE * pFile, Abc_Obj_t * pNode, Vec_Int_t * vTruth );
37
41
53int 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 parentheses 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
92int 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",
105 Abc_ObjName(Abc_ObjFanout0(Abc_ObjFanout0(pNode))), Abc_ObjName(Abc_ObjFanin0(Abc_ObjFanin0(pNode))) );
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
130int 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
175int 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 parentheses 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
214int 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",
228 Abc_ObjName(Abc_ObjFanout0(Abc_ObjFanout0(pNode))), Abc_ObjName(Abc_ObjFanin0(Abc_ObjFanin0(pNode))) );
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
255int 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 <= 15 );
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 {
291extern void Kit_DsdTest( unsigned * pTruth, int nVars );
292Abc_ObjForEachFanin( pNode, pFanin, i )
293printf( "%c%d ", 'a'+i, Abc_ObjFanin0(pFanin)->Level );
294printf( "\n" );
295Kit_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
322int Io_WriteBenchCheckNames( Abc_Ntk_t * pNtk )
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
337
338
340
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition abcObj.c:948
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition abcObj.c:916
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
void Extra_ProgressBarStop(ProgressBar *p)
void Extra_PrintHexadecimal(FILE *pFile, unsigned Sign[], int nVars)
char * Extra_TimeStamp()
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Definition hopTruth.c:143
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
int Io_WriteBenchLut(Abc_Ntk_t *pNtk, char *pFileName)
int Io_WriteBench(Abc_Ntk_t *pNtk, const char *pFileName)
FUNCTION DEFINITIONS ///.
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition nmApi.c:199
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
Nm_Man_t * pManName
Definition abc.h:160
void * pData
Definition abc.h:145
Abc_Ntk_t * pNtk
Definition abc.h:130
#define assert(ex)
Definition util_old.h:213