ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcShow.c
Go to the documentation of this file.
1
20
21#ifdef WIN32
22#include <process.h>
23#else
24#include <unistd.h>
25#endif
26
27
28#include "abc.h"
29#include "base/main/main.h"
30#include "base/io/ioAbc.h"
31
32#ifdef ABC_USE_CUDD
33#include "bdd/extrab/extraBdd.h"
34#endif
35
37
38
42
43extern void Abc_ShowFile( char * FileNameDot, int fKeepDot );
44static void Abc_ShowGetFileName( char * pName, char * pBuffer );
45
49
50#ifdef ABC_USE_CUDD
51
63void Abc_NodeShowBddOne( DdManager * dd, DdNode * bFunc )
64{
65 char * FileNameDot = "temp.dot";
66 FILE * pFile;
67 if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
68 {
69 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
70 return;
71 }
72 Cudd_DumpDot( dd, 1, (DdNode **)&bFunc, NULL, NULL, pFile );
73 fclose( pFile );
74 Abc_ShowFile( FileNameDot, 0 );
75}
76
88void Abc_NodeShowBdd( Abc_Obj_t * pNode, int fCompl )
89{
90 FILE * pFile;
91 Vec_Ptr_t * vNamesIn;
92 char FileNameDot[200];
93 char * pNameOut;
94 DdManager * dd = (DdManager *)pNode->pNtk->pManFunc;
95
96 assert( Abc_NtkIsBddLogic(pNode->pNtk) );
97 // create the file name
98 Abc_ShowGetFileName( Abc_ObjName(pNode), FileNameDot );
99 // check that the file can be opened
100 if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
101 {
102 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
103 return;
104 }
105
106 // set the node names
107 vNamesIn = Abc_NodeGetFaninNames( pNode );
108 pNameOut = Abc_ObjName(pNode);
109 if ( fCompl )
110 Cudd_DumpDot( dd, 1, (DdNode **)&pNode->pData, (char **)vNamesIn->pArray, &pNameOut, pFile );
111 else
112 {
113 DdNode * bAdd = Cudd_BddToAdd( dd, (DdNode *)pNode->pData ); Cudd_Ref( bAdd );
114 Cudd_DumpDot( dd, 1, (DdNode **)&bAdd, (char **)vNamesIn->pArray, &pNameOut, pFile );
115 Cudd_RecursiveDeref( dd, bAdd );
116 }
117 Abc_NodeFreeNames( vNamesIn );
118 Abc_NtkCleanCopy( pNode->pNtk );
119 fclose( pFile );
120
121 // visualize the file
122 Abc_ShowFile( FileNameDot, 0 );
123}
124void Abc_NtkShowBdd( Abc_Ntk_t * pNtk, int fCompl, int fReorder )
125{
126 char FileNameDot[200];
127 char ** ppNamesIn, ** ppNamesOut;
128 DdManager * dd; DdNode * bFunc;
129 Vec_Ptr_t * vFuncsGlob;
130 Abc_Obj_t * pObj; int i;
131 FILE * pFile;
132
133 assert( Abc_NtkIsStrash(pNtk) );
134 dd = (DdManager *)Abc_NtkBuildGlobalBdds( pNtk, 10000000, 1, fReorder, 0, 0 );
135 if ( dd == NULL )
136 {
137 printf( "Construction of global BDDs has failed.\n" );
138 return;
139 }
140 //printf( "Shared BDD size = %6d nodes.\n", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
141
142 // complement the global functions
143 vFuncsGlob = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) );
144 Abc_NtkForEachCo( pNtk, pObj, i )
145 Vec_PtrPush( vFuncsGlob, Abc_ObjGlobalBdd(pObj) );
146
147 // create the file name
148 Abc_ShowGetFileName( pNtk->pName, FileNameDot );
149 // check that the file can be opened
150 if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
151 {
152 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
153 return;
154 }
155
156 // set the node names
157 ppNamesIn = Abc_NtkCollectCioNames( pNtk, 0 );
158 ppNamesOut = Abc_NtkCollectCioNames( pNtk, 1 );
159 if ( fCompl )
160 Cudd_DumpDot( dd, Abc_NtkCoNum(pNtk), (DdNode **)Vec_PtrArray(vFuncsGlob), ppNamesIn, ppNamesOut, pFile );
161 else
162 {
163 DdNode ** pbAdds = ABC_ALLOC( DdNode *, Vec_PtrSize(vFuncsGlob) );
164 Vec_PtrForEachEntry( DdNode *, vFuncsGlob, bFunc, i )
165 { pbAdds[i] = Cudd_BddToAdd( dd, bFunc ); Cudd_Ref( pbAdds[i] ); }
166 Cudd_DumpDot( dd, Abc_NtkCoNum(pNtk), pbAdds, ppNamesIn, ppNamesOut, pFile );
167 Vec_PtrForEachEntry( DdNode *, vFuncsGlob, bFunc, i )
168 Cudd_RecursiveDeref( dd, pbAdds[i] );
169 ABC_FREE( pbAdds );
170 }
171 ABC_FREE( ppNamesIn );
172 ABC_FREE( ppNamesOut );
173 fclose( pFile );
174
175 // cleanup
176 Abc_NtkFreeGlobalBdds( pNtk, 0 );
177 Vec_PtrForEachEntry( DdNode *, vFuncsGlob, bFunc, i )
178 Cudd_RecursiveDeref( dd, bFunc );
179 Vec_PtrFree( vFuncsGlob );
180 Extra_StopManager( dd );
181 Abc_NtkCleanCopy( pNtk );
182
183 // visualize the file
184 Abc_ShowFile( FileNameDot, 0 );
185}
186
187#else
188void Abc_NodeShowBdd( Abc_Obj_t * pNode, int fCompl ) {}
189void Abc_NtkShowBdd( Abc_Ntk_t * pNtk, int fCompl, int fReorder ) {}
190#endif
191
203void Abc_NodeShowCut( Abc_Obj_t * pNode, int nNodeSizeMax, int nConeSizeMax )
204{
205 FILE * pFile;
206 char FileNameDot[200];
207 Abc_ManCut_t * p;
208 Vec_Ptr_t * vCutSmall;
209 Vec_Ptr_t * vCutLarge;
210 Vec_Ptr_t * vInside;
211 Vec_Ptr_t * vNodesTfo;
212 Abc_Obj_t * pTemp;
213 int i;
214
215 assert( Abc_NtkIsStrash(pNode->pNtk) );
216
217 // start the cut computation manager
218 p = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, ABC_INFINITY );
219 // get the recovergence driven cut
220 vCutSmall = Abc_NodeFindCut( p, pNode, 1 );
221 // get the containing cut
222 vCutLarge = Abc_NtkManCutReadCutLarge( p );
223 // get the array for the inside nodes
224 vInside = Abc_NtkManCutReadVisited( p );
225 // get the inside nodes of the containing cone
226 Abc_NodeConeCollect( &pNode, 1, vCutLarge, vInside, 1 );
227
228 // add the nodes in the TFO
229 vNodesTfo = Abc_NodeCollectTfoCands( p, pNode, vCutSmall, ABC_INFINITY );
230 Vec_PtrForEachEntry( Abc_Obj_t *, vNodesTfo, pTemp, i )
231 Vec_PtrPushUnique( vInside, pTemp );
232
233 // create the file name
234 Abc_ShowGetFileName( Abc_ObjName(pNode), FileNameDot );
235 // check that the file can be opened
236 if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
237 {
238 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
239 return;
240 }
241 // add the root node to the cone (for visualization)
242 Vec_PtrPush( vCutSmall, pNode );
243 // write the DOT file
244 Io_WriteDotNtk( pNode->pNtk, vInside, vCutSmall, FileNameDot, 0, 0, 0 );
245 // stop the cut computation manager
247
248 // visualize the file
249 Abc_ShowFile( FileNameDot, 0 );
250}
251
263void Abc_NtkShow( Abc_Ntk_t * pNtk0, int fGateNames, int fSeq, int fUseReverse, int fKeepDot, int fAigIds )
264{
265 FILE * pFile;
266 Abc_Ntk_t * pNtk;
267 Abc_Obj_t * pNode;
268 Vec_Ptr_t * vNodes;
269 int nBarBufs;
270 char FileNameDot[200];
271 int i;
272
273 assert( Abc_NtkIsStrash(pNtk0) || Abc_NtkIsLogic(pNtk0) );
274 if ( Abc_NtkIsStrash(pNtk0) && Abc_NtkGetChoiceNum(pNtk0) )
275 {
276 printf( "Temporarily visualization of AIGs with choice nodes is disabled.\n" );
277 return;
278 }
279 // create the file name
280 Abc_ShowGetFileName( pNtk0->pName, FileNameDot );
281 // check that the file can be opened
282 if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
283 {
284 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
285 return;
286 }
287 fclose( pFile );
288
289
290 // convert to logic SOP
291 pNtk = Abc_NtkDup( pNtk0 );
292 if ( Abc_NtkIsLogic(pNtk) && !Abc_NtkHasMapping(pNtk) )
293 Abc_NtkToSop( pNtk, -1, ABC_INFINITY );
294
295 // collect all nodes in the network
296 vNodes = Vec_PtrAlloc( 100 );
297 Abc_NtkForEachObj( pNtk, pNode, i )
298 Vec_PtrPush( vNodes, pNode );
299 // write the DOT file
300 nBarBufs = pNtk->nBarBufs;
301 pNtk->nBarBufs = 0;
302 if ( fSeq )
303 Io_WriteDotSeq( pNtk, vNodes, NULL, FileNameDot, fGateNames, fUseReverse );
304 else
305 Io_WriteDotNtk( pNtk, vNodes, NULL, FileNameDot, fGateNames, fUseReverse, fAigIds );
306 pNtk->nBarBufs = nBarBufs;
307 Vec_PtrFree( vNodes );
308
309 // visualize the file
310 Abc_ShowFile( FileNameDot, fKeepDot );
311 Abc_NtkDelete( pNtk );
312}
313
314
326void Abc_ShowFile( char * FileNameDot, int fKeepDot )
327{
328 FILE * pFile;
329 char * FileGeneric;
330 char FileNamePs[200];
331 char CommandDot[1000];
332 char * pDotName;
333 char * pDotNameWin = "dot.exe";
334 char * pDotNameUnix = "dot";
335 char * pGsNameWin = "gsview32.exe";
336 char * pGsNameUnix = "gv";
337 int RetValue;
338
339 // get DOT names from the resource file
340 if ( Abc_FrameReadFlag("dotwin") )
341 pDotNameWin = Abc_FrameReadFlag("dotwin");
342 if ( Abc_FrameReadFlag("dotunix") )
343 pDotNameUnix = Abc_FrameReadFlag("dotunix");
344
345#ifdef WIN32
346 pDotName = pDotNameWin;
347#else
348 pDotName = pDotNameUnix;
349#endif
350
351 // check if the input DOT file is okay
352 if ( (pFile = fopen( FileNameDot, "r" )) == NULL )
353 {
354 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
355 return;
356 }
357 fclose( pFile );
358
359 // create the PostScript file name
360 FileGeneric = Extra_FileNameGeneric( FileNameDot );
361 sprintf( FileNamePs, "%s.ps", FileGeneric );
362 ABC_FREE( FileGeneric );
363
364 // generate the PostScript file using DOT
365 sprintf( CommandDot, "%s -Tps -o %s %s", pDotName, FileNamePs, FileNameDot );
366#if defined(__wasm)
367 RetValue = -1;
368#else
369 RetValue = system( CommandDot );
370#endif
371 if ( RetValue == -1 )
372 {
373 fprintf( stdout, "Command \"%s\" did not succeed.\n", CommandDot );
374 return;
375 }
376 // check that the input PostScript file is okay
377 if ( (pFile = fopen( FileNamePs, "r" )) == NULL )
378 {
379 fprintf( stdout, "Cannot open intermediate file \"%s\".\n", FileNamePs );
380 return;
381 }
382 fclose( pFile );
383
384
385 // get GSVIEW names from the resource file
386 if ( Abc_FrameReadFlag("gsviewwin") )
387 pGsNameWin = Abc_FrameReadFlag("gsviewwin");
388 if ( Abc_FrameReadFlag("gsviewunix") )
389 pGsNameUnix = Abc_FrameReadFlag("gsviewunix");
390
391 // spawn the viewer
392#ifdef WIN32
393 if ( !fKeepDot ) _unlink( FileNameDot );
394 if ( _spawnl( _P_NOWAIT, pGsNameWin, pGsNameWin, FileNamePs, NULL ) == -1 )
395 if ( _spawnl( _P_NOWAIT, "C:\\Program Files\\Ghostgum\\gsview\\gsview32.exe",
396 "C:\\Program Files\\Ghostgum\\gsview\\gsview32.exe", FileNamePs, NULL ) == -1 )
397 if ( _spawnl( _P_NOWAIT, "C:\\Program Files\\Ghostgum\\gsview\\gsview64.exe",
398 "C:\\Program Files\\Ghostgum\\gsview\\gsview64.exe", FileNamePs, NULL ) == -1 )
399 {
400 fprintf( stdout, "Cannot find \"%s\".\n", pGsNameWin );
401 return;
402 }
403#else
404 {
405 char CommandPs[1000];
406 if ( !fKeepDot ) unlink( FileNameDot );
407 sprintf( CommandPs, "%s %s &", pGsNameUnix, FileNamePs );
408#if defined(__wasm)
409 if ( 1 )
410#else
411 if ( system( CommandPs ) == -1 )
412#endif
413 {
414 fprintf( stdout, "Cannot execute \"%s\".\n", CommandPs );
415 return;
416 }
417 }
418#endif
419}
420
432void Abc_ShowGetFileName( char * pName, char * pBuffer )
433{
434 char * pCur;
435 // creat the file name
436 sprintf( pBuffer, "%s.dot", pName );
437 // get rid of not-alpha-numeric characters
438 for ( pCur = pBuffer; *pCur; pCur++ )
439 if ( !((*pCur >= '0' && *pCur <= '9') || (*pCur >= 'a' && *pCur <= 'z') ||
440 (*pCur >= 'A' && *pCur <= 'Z') || (*pCur == '.')) )
441 *pCur = '_';
442}
443
444
456void Abc_NtkWriteFlopDependency( Abc_Ntk_t * pNtk, char * pFileName )
457{
458 FILE * pFile;
459 Vec_Ptr_t * vSupp;
460 Abc_Obj_t * pObj, * pTemp;
461 int i, k, Count;
462 pFile = fopen( pFileName, "w" );
463 if ( pFile == NULL )
464 {
465 printf( "Cannot open input file %s.\n", pFileName );
466 return;
467 }
468 fprintf( pFile, "# Flop dependency for \"%s\" generated by ABC on %s\n", Abc_NtkName(pNtk), Extra_TimeStamp() );
469 fprintf( pFile, "digraph G {\n" );
470 fprintf( pFile, " graph [splines=true overlap=false];\n" );
471 fprintf( pFile, " size = \"7.5,10\";\n" );
472 fprintf( pFile, " center = true;\n" );
473// fprintf( pFile, " edge [len=3,dir=forward];\n" );
474 fprintf( pFile, " edge [dir=forward];\n" );
475 Abc_NtkForEachLatchInput( pNtk, pObj, i )
476 {
477 Abc_ObjFanout0( Abc_ObjFanout0(pObj) )->iTemp = i;
478 vSupp = Abc_NtkNodeSupport( pNtk, &pObj, 1 );
479 Count = 0;
480 Vec_PtrForEachEntry( Abc_Obj_t *, vSupp, pTemp, k )
481 Count += Abc_ObjIsPi(pTemp);
482 Vec_PtrFree( vSupp );
483 fprintf( pFile, " { rank = same; %d [label=\"%d(%d)\"]; }\n", i, i, Count );
484 }
485 Abc_NtkForEachLatchInput( pNtk, pObj, i )
486 {
487 vSupp = Abc_NtkNodeSupport( pNtk, &pObj, 1 );
488 Count = 0;
489 Vec_PtrForEachEntry( Abc_Obj_t *, vSupp, pTemp, k )
490 if ( !Abc_ObjIsPi(pTemp) )
491 fprintf( pFile, " %4d -> %4d\n", pTemp->iTemp, i );
492 Vec_PtrFree( vSupp );
493 }
494 fprintf( pFile, "}\n" );
495 fclose( pFile );
496}
497
498
511{
512 FILE * pFile;
513 char FileNameDot[200];
514 assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsLogic(pNtk) );
515 // create the file name
516 Abc_ShowGetFileName( pNtk->pName, FileNameDot );
517 // check that the file can be opened
518 if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
519 {
520 fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
521 return;
522 }
523 fclose( pFile );
524 // write the DOT file
525 Abc_NtkWriteFlopDependency( pNtk, FileNameDot );
526 // visualize the file
527 Abc_ShowFile( FileNameDot, 0 );
528}
529
530
534
535
537
void Abc_NtkShow(Abc_Ntk_t *pNtk0, int fGateNames, int fSeq, int fUseReverse, int fKeepDot, int fAigIds)
Definition abcShow.c:263
void Abc_NodeShowBdd(Abc_Obj_t *pNode, int fCompl)
FUNCTION DEFINITIONS ///.
Definition abcShow.c:188
void Abc_NtkShowFlopDependency(Abc_Ntk_t *pNtk)
Definition abcShow.c:510
void Abc_NodeShowCut(Abc_Obj_t *pNode, int nNodeSizeMax, int nConeSizeMax)
Definition abcShow.c:203
ABC_NAMESPACE_IMPL_START void Abc_ShowFile(char *FileNameDot, int fKeepDot)
DECLARATIONS ///.
Definition abcShow.c:326
void Abc_NtkWriteFlopDependency(Abc_Ntk_t *pNtk, char *pFileName)
Definition abcShow.c:456
void Abc_NtkShowBdd(Abc_Ntk_t *pNtk, int fCompl, int fReorder)
Definition abcShow.c:189
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Vec_Ptr_t * Abc_NodeGetFaninNames(Abc_Obj_t *pNode)
Definition abcNames.c:206
ABC_DLL int Abc_NtkGetChoiceNum(Abc_Ntk_t *pNtk)
Definition abcUtil.c:463
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
ABC_DLL void Abc_NodeFreeNames(Vec_Ptr_t *vNames)
Definition abcNames.c:264
struct Abc_ManCut_t_ Abc_ManCut_t
Definition abc.h:119
ABC_DLL void Abc_NodeConeCollect(Abc_Obj_t **ppRoots, int nRoots, Vec_Ptr_t *vFanins, Vec_Ptr_t *vVisited, int fIncludeFanins)
Definition abcReconv.c:444
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
Definition abcReconv.c:623
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
ABC_DLL Vec_Ptr_t * Abc_NtkNodeSupport(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition abcDfs.c:890
ABC_DLL Vec_Ptr_t * Abc_NodeCollectTfoCands(Abc_ManCut_t *p, Abc_Obj_t *pRoot, Vec_Ptr_t *vFanins, int LevelMax)
Definition abcReconv.c:699
ABC_DLL void * Abc_NtkFreeGlobalBdds(Abc_Ntk_t *pNtk, int fFreeMan)
ABC_DLL Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
Definition abcReconv.c:256
#define Abc_NtkForEachLatchInput(pNtk, pObj, i)
Definition abc.h:503
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fMode, int nCubeLimit)
Definition abcFunc.c:1261
ABC_DLL void * Abc_NtkBuildGlobalBdds(Abc_Ntk_t *pNtk, int fBddSizeMax, int fDropInternal, int fReorder, int fReverse, int fVerbose)
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadVisited(Abc_ManCut_t *p)
Definition abcReconv.c:676
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadCutLarge(Abc_ManCut_t *p)
Definition abcReconv.c:644
ABC_DLL char ** Abc_NtkCollectCioNames(Abc_Ntk_t *pNtk, int fCollectCos)
Definition abcNames.c:285
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition abcNtk.c:472
ABC_DLL Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
Definition abcReconv.c:595
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition mainFrame.c:69
Cube * p
Definition exorList.c:222
void Extra_StopManager(DdManager *dd)
char * Extra_TimeStamp()
char * Extra_FileNameGeneric(char *FileName)
void Io_WriteDotSeq(Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes, Vec_Ptr_t *vNodesShow, char *pFileName, int fGateNames, int fUseReverse)
Definition ioWriteDot.c:447
void Io_WriteDotNtk(Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes, Vec_Ptr_t *vNodesShow, char *pFileName, int fGateNames, int fUseReverse, int fAigIds)
Definition ioWriteDot.c:71
char * pName
Definition abc.h:158
int nBarBufs
Definition abc.h:174
void * pManFunc
Definition abc.h:191
Abc_Ntk_t * pNtk
Definition abc.h:130
int iTemp
Definition abc.h:149
#define assert(ex)
Definition util_old.h:213
int system()
char * sprintf()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55