abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcShow.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcShow.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Visualization procedures using DOT software and GSView.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcShow.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
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 #include "misc/extra/extraBdd.h"
32 
34 
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// DECLARATIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 extern void Abc_ShowFile( char * FileNameDot );
41 static void Abc_ShowGetFileName( char * pName, char * pBuffer );
42 
43 ////////////////////////////////////////////////////////////////////////
44 /// FUNCTION DEFINITIONS ///
45 ////////////////////////////////////////////////////////////////////////
46 
47 /**Function*************************************************************
48 
49  Synopsis [Visualizes BDD of the node.]
50 
51  Description []
52 
53  SideEffects []
54 
55  SeeAlso []
56 
57 ***********************************************************************/
58 void Abc_NodeShowBdd( Abc_Obj_t * pNode )
59 {
60  FILE * pFile;
61  Vec_Ptr_t * vNamesIn;
62  char FileNameDot[200];
63  char * pNameOut;
64 
65  assert( Abc_NtkIsBddLogic(pNode->pNtk) );
66  // create the file name
67  Abc_ShowGetFileName( Abc_ObjName(pNode), FileNameDot );
68  // check that the file can be opened
69  if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
70  {
71  fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
72  return;
73  }
74 
75  // set the node names
76  vNamesIn = Abc_NodeGetFaninNames( pNode );
77  pNameOut = Abc_ObjName(pNode);
78  Cudd_DumpDot( (DdManager *)pNode->pNtk->pManFunc, 1, (DdNode **)&pNode->pData, (char **)vNamesIn->pArray, &pNameOut, pFile );
79  Abc_NodeFreeNames( vNamesIn );
80  Abc_NtkCleanCopy( pNode->pNtk );
81  fclose( pFile );
82 
83  // visualize the file
84  Abc_ShowFile( FileNameDot );
85 }
86 
87 /**Function*************************************************************
88 
89  Synopsis [Visualizes BDD of the node.]
90 
91  Description []
92 
93  SideEffects []
94 
95  SeeAlso []
96 
97 ***********************************************************************/
98 void Abc_NodeShowBddOne( DdManager * dd, DdNode * bFunc )
99 {
100  char * FileNameDot = "temp.dot";
101  FILE * pFile;
102  if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
103  {
104  fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
105  return;
106  }
107  Cudd_DumpDot( dd, 1, (DdNode **)&bFunc, NULL, NULL, pFile );
108  fclose( pFile );
109  Abc_ShowFile( FileNameDot );
110 }
111 /**Function*************************************************************
112 
113  Synopsis [Visualizes a reconvergence driven cut at the node.]
114 
115  Description []
116 
117  SideEffects []
118 
119  SeeAlso []
120 
121 ***********************************************************************/
122 void Abc_NodeShowCut( Abc_Obj_t * pNode, int nNodeSizeMax, int nConeSizeMax )
123 {
124  FILE * pFile;
125  char FileNameDot[200];
126  Abc_ManCut_t * p;
127  Vec_Ptr_t * vCutSmall;
128  Vec_Ptr_t * vCutLarge;
129  Vec_Ptr_t * vInside;
130  Vec_Ptr_t * vNodesTfo;
131  Abc_Obj_t * pTemp;
132  int i;
133 
134  assert( Abc_NtkIsStrash(pNode->pNtk) );
135 
136  // start the cut computation manager
137  p = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, ABC_INFINITY );
138  // get the recovergence driven cut
139  vCutSmall = Abc_NodeFindCut( p, pNode, 1 );
140  // get the containing cut
141  vCutLarge = Abc_NtkManCutReadCutLarge( p );
142  // get the array for the inside nodes
143  vInside = Abc_NtkManCutReadVisited( p );
144  // get the inside nodes of the containing cone
145  Abc_NodeConeCollect( &pNode, 1, vCutLarge, vInside, 1 );
146 
147  // add the nodes in the TFO
148  vNodesTfo = Abc_NodeCollectTfoCands( p, pNode, vCutSmall, ABC_INFINITY );
149  Vec_PtrForEachEntry( Abc_Obj_t *, vNodesTfo, pTemp, i )
150  Vec_PtrPushUnique( vInside, pTemp );
151 
152  // create the file name
153  Abc_ShowGetFileName( Abc_ObjName(pNode), FileNameDot );
154  // check that the file can be opened
155  if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
156  {
157  fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
158  return;
159  }
160  // add the root node to the cone (for visualization)
161  Vec_PtrPush( vCutSmall, pNode );
162  // write the DOT file
163  Io_WriteDotNtk( pNode->pNtk, vInside, vCutSmall, FileNameDot, 0, 0 );
164  // stop the cut computation manager
165  Abc_NtkManCutStop( p );
166 
167  // visualize the file
168  Abc_ShowFile( FileNameDot );
169 }
170 
171 /**Function*************************************************************
172 
173  Synopsis [Visualizes AIG with choices.]
174 
175  Description []
176 
177  SideEffects []
178 
179  SeeAlso []
180 
181 ***********************************************************************/
182 void Abc_NtkShow( Abc_Ntk_t * pNtk0, int fGateNames, int fSeq, int fUseReverse )
183 {
184  FILE * pFile;
185  Abc_Ntk_t * pNtk;
186  Abc_Obj_t * pNode;
187  Vec_Ptr_t * vNodes;
188  int nBarBufs;
189  char FileNameDot[200];
190  int i;
191 
192  assert( Abc_NtkIsStrash(pNtk0) || Abc_NtkIsLogic(pNtk0) );
193  if ( Abc_NtkIsStrash(pNtk0) && Abc_NtkGetChoiceNum(pNtk0) )
194  {
195  printf( "Temporarily visualization of AIGs with choice nodes is disabled.\n" );
196  return;
197  }
198  // create the file name
199  Abc_ShowGetFileName( pNtk0->pName, FileNameDot );
200  // check that the file can be opened
201  if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
202  {
203  fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
204  return;
205  }
206  fclose( pFile );
207 
208 
209  // convert to logic SOP
210  pNtk = Abc_NtkDup( pNtk0 );
211  if ( Abc_NtkIsLogic(pNtk) && !Abc_NtkHasMapping(pNtk) )
212  Abc_NtkToSop( pNtk, 0 );
213 
214  // collect all nodes in the network
215  vNodes = Vec_PtrAlloc( 100 );
216  Abc_NtkForEachObj( pNtk, pNode, i )
217  Vec_PtrPush( vNodes, pNode );
218  // write the DOT file
219  nBarBufs = pNtk->nBarBufs;
220  pNtk->nBarBufs = 0;
221  if ( fSeq )
222  Io_WriteDotSeq( pNtk, vNodes, NULL, FileNameDot, fGateNames, fUseReverse );
223  else
224  Io_WriteDotNtk( pNtk, vNodes, NULL, FileNameDot, fGateNames, fUseReverse );
225  pNtk->nBarBufs = nBarBufs;
226  Vec_PtrFree( vNodes );
227 
228  // visualize the file
229  Abc_ShowFile( FileNameDot );
230  Abc_NtkDelete( pNtk );
231 }
232 
233 
234 /**Function*************************************************************
235 
236  Synopsis [Shows the given DOT file.]
237 
238  Description []
239 
240  SideEffects []
241 
242  SeeAlso []
243 
244 ***********************************************************************/
245 void Abc_ShowFile( char * FileNameDot )
246 {
247  FILE * pFile;
248  char * FileGeneric;
249  char FileNamePs[200];
250  char CommandDot[1000];
251  char * pDotName;
252  char * pDotNameWin = "dot.exe";
253  char * pDotNameUnix = "dot";
254  char * pGsNameWin = "gsview32.exe";
255  char * pGsNameUnix = "gv";
256  int RetValue;
257 
258  // get DOT names from the resource file
259  if ( Abc_FrameReadFlag("dotwin") )
260  pDotNameWin = Abc_FrameReadFlag("dotwin");
261  if ( Abc_FrameReadFlag("dotunix") )
262  pDotNameUnix = Abc_FrameReadFlag("dotunix");
263 
264 #ifdef WIN32
265  pDotName = pDotNameWin;
266 #else
267  pDotName = pDotNameUnix;
268 #endif
269 
270  // check if the input DOT file is okay
271  if ( (pFile = fopen( FileNameDot, "r" )) == NULL )
272  {
273  fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
274  return;
275  }
276  fclose( pFile );
277 
278  // create the PostScript file name
279  FileGeneric = Extra_FileNameGeneric( FileNameDot );
280  sprintf( FileNamePs, "%s.ps", FileGeneric );
281  ABC_FREE( FileGeneric );
282 
283  // generate the PostScript file using DOT
284  sprintf( CommandDot, "%s -Tps -o %s %s", pDotName, FileNamePs, FileNameDot );
285  RetValue = system( CommandDot );
286  if ( RetValue == -1 )
287  {
288  fprintf( stdout, "Command \"%s\" did not succeed.\n", CommandDot );
289  return;
290  }
291  // check that the input PostScript file is okay
292  if ( (pFile = fopen( FileNamePs, "r" )) == NULL )
293  {
294  fprintf( stdout, "Cannot open intermediate file \"%s\".\n", FileNamePs );
295  return;
296  }
297  fclose( pFile );
298 
299 
300  // get GSVIEW names from the resource file
301  if ( Abc_FrameReadFlag("gsviewwin") )
302  pGsNameWin = Abc_FrameReadFlag("gsviewwin");
303  if ( Abc_FrameReadFlag("gsviewunix") )
304  pGsNameUnix = Abc_FrameReadFlag("gsviewunix");
305 
306  // spawn the viewer
307 #ifdef WIN32
308  _unlink( FileNameDot );
309  if ( _spawnl( _P_NOWAIT, pGsNameWin, pGsNameWin, FileNamePs, NULL ) == -1 )
310  if ( _spawnl( _P_NOWAIT, "C:\\Program Files\\Ghostgum\\gsview\\gsview32.exe",
311  "C:\\Program Files\\Ghostgum\\gsview\\gsview32.exe", FileNamePs, NULL ) == -1 )
312  if ( _spawnl( _P_NOWAIT, "C:\\Program Files\\Ghostgum\\gsview\\gsview64.exe",
313  "C:\\Program Files\\Ghostgum\\gsview\\gsview64.exe", FileNamePs, NULL ) == -1 )
314  {
315  fprintf( stdout, "Cannot find \"%s\".\n", pGsNameWin );
316  return;
317  }
318 #else
319  {
320  char CommandPs[1000];
321  unlink( FileNameDot );
322  sprintf( CommandPs, "%s %s &", pGsNameUnix, FileNamePs );
323  if ( system( CommandPs ) == -1 )
324  {
325  fprintf( stdout, "Cannot execute \"%s\".\n", CommandPs );
326  return;
327  }
328  }
329 #endif
330 }
331 
332 /**Function*************************************************************
333 
334  Synopsis [Derives the DOT file name.]
335 
336  Description []
337 
338  SideEffects []
339 
340  SeeAlso []
341 
342 ***********************************************************************/
343 void Abc_ShowGetFileName( char * pName, char * pBuffer )
344 {
345  char * pCur;
346  // creat the file name
347  sprintf( pBuffer, "%s.dot", pName );
348  // get rid of not-alpha-numeric characters
349  for ( pCur = pBuffer; *pCur; pCur++ )
350  if ( !((*pCur >= '0' && *pCur <= '9') || (*pCur >= 'a' && *pCur <= 'z') ||
351  (*pCur >= 'A' && *pCur <= 'Z') || (*pCur == '.')) )
352  *pCur = '_';
353 }
354 
355 
356 /**Function*************************************************************
357 
358  Synopsis []
359 
360  Description []
361 
362  SideEffects []
363 
364  SeeAlso []
365 
366 ***********************************************************************/
367 void Abc_NtkWriteFlopDependency( Abc_Ntk_t * pNtk, char * pFileName )
368 {
369  FILE * pFile;
370  Vec_Ptr_t * vSupp;
371  Abc_Obj_t * pObj, * pTemp;
372  int i, k, Count;
373  pFile = fopen( pFileName, "w" );
374  if ( pFile == NULL )
375  {
376  printf( "Cannot open input file %s.\n", pFileName );
377  return;
378  }
379  fprintf( pFile, "# Flop dependency for \"%s\" generated by ABC on %s\n", Abc_NtkName(pNtk), Extra_TimeStamp() );
380  fprintf( pFile, "digraph G {\n" );
381  fprintf( pFile, " graph [splines=true overlap=false];\n" );
382  fprintf( pFile, " size = \"7.5,10\";\n" );
383  fprintf( pFile, " center = true;\n" );
384 // fprintf( pFile, " edge [len=3,dir=forward];\n" );
385  fprintf( pFile, " edge [dir=forward];\n" );
386  Abc_NtkForEachLatchInput( pNtk, pObj, i )
387  {
388  Abc_ObjFanout0( Abc_ObjFanout0(pObj) )->iTemp = i;
389  vSupp = Abc_NtkNodeSupport( pNtk, &pObj, 1 );
390  Count = 0;
391  Vec_PtrForEachEntry( Abc_Obj_t *, vSupp, pTemp, k )
392  Count += Abc_ObjIsPi(pTemp);
393  Vec_PtrFree( vSupp );
394  fprintf( pFile, " { rank = same; %d [label=\"%d(%d)\"]; }\n", i, i, Count );
395  }
396  Abc_NtkForEachLatchInput( pNtk, pObj, i )
397  {
398  vSupp = Abc_NtkNodeSupport( pNtk, &pObj, 1 );
399  Count = 0;
400  Vec_PtrForEachEntry( Abc_Obj_t *, vSupp, pTemp, k )
401  if ( !Abc_ObjIsPi(pTemp) )
402  fprintf( pFile, " %4d -> %4d\n", pTemp->iTemp, i );
403  Vec_PtrFree( vSupp );
404  }
405  fprintf( pFile, "}\n" );
406  fclose( pFile );
407 }
408 
409 
410 /**Function*************************************************************
411 
412  Synopsis [Visualizes AIG with choices.]
413 
414  Description []
415 
416  SideEffects []
417 
418  SeeAlso []
419 
420 ***********************************************************************/
422 {
423  FILE * pFile;
424  char FileNameDot[200];
425  assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsLogic(pNtk) );
426  // create the file name
427  Abc_ShowGetFileName( pNtk->pName, FileNameDot );
428  // check that the file can be opened
429  if ( (pFile = fopen( FileNameDot, "w" )) == NULL )
430  {
431  fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot );
432  return;
433  }
434  fclose( pFile );
435  // write the DOT file
436  Abc_NtkWriteFlopDependency( pNtk, FileNameDot );
437  // visualize the file
438  Abc_ShowFile( FileNameDot );
439 }
440 
441 
442 ////////////////////////////////////////////////////////////////////////
443 /// END OF FILE ///
444 ////////////////////////////////////////////////////////////////////////
445 
446 
448 
int iTemp
Definition: abc.h:149
void Abc_NtkShowFlopDependency(Abc_Ntk_t *pNtk)
Definition: abcShow.c:421
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
void Abc_NtkShow(Abc_Ntk_t *pNtk0, int fGateNames, int fSeq, int fUseReverse)
Definition: abcShow.c:182
Definition: cudd.h:278
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Abc_NodeShowBddOne(DdManager *dd, DdNode *bFunc)
Definition: abcShow.c:98
void Abc_NodeShowBdd(Abc_Obj_t *pNode)
FUNCTION DEFINITIONS ///.
Definition: abcShow.c:58
static int Vec_PtrPushUnique(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:656
void Io_WriteDotSeq(Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes, Vec_Ptr_t *vNodesShow, char *pFileName, int fGateNames, int fUseReverse)
Definition: ioWriteDot.c:434
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadCutLarge(Abc_ManCut_t *p)
Definition: abcReconv.c:637
static int Abc_NtkHasMapping(Abc_Ntk_t *pNtk)
Definition: abc.h:256
static int Abc_ObjIsPi(Abc_Obj_t *pObj)
Definition: abc.h:347
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadVisited(Abc_ManCut_t *p)
Definition: abcReconv.c:669
ABC_DLL Vec_Ptr_t * Abc_NodeGetFaninNames(Abc_Obj_t *pNode)
Definition: abcNames.c:199
ABC_DLL int Abc_NtkGetChoiceNum(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:430
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
ABC_DLL Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
Definition: abcReconv.c:253
ABC_DLL void Abc_NodeFreeNames(Vec_Ptr_t *vNames)
Definition: abcNames.c:257
void * pManFunc
Definition: abc.h:191
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fDirect)
Definition: abcFunc.c:1124
char * Extra_FileNameGeneric(char *FileName)
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_DLL Vec_Ptr_t * Abc_NtkNodeSupport(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition: abcDfs.c:859
ABC_NAMESPACE_IMPL_START void Abc_ShowFile(char *FileNameDot)
DECLARATIONS ///.
Definition: abcShow.c:245
void Abc_NtkWriteFlopDependency(Abc_Ntk_t *pNtk, char *pFileName)
Definition: abcShow.c:367
char * sprintf()
int system()
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Abc_Ntk_t * pNtk
Definition: abc.h:130
ABC_DLL Vec_Ptr_t * Abc_NodeCollectTfoCands(Abc_ManCut_t *p, Abc_Obj_t *pRoot, Vec_Ptr_t *vFanins, int LevelMax)
Definition: abcReconv.c:692
static char * Abc_NtkName(Abc_Ntk_t *pNtk)
Definition: abc.h:270
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int nBarBufs
Definition: abc.h:174
static int Abc_NtkIsBddLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:265
#define ABC_FREE(obj)
Definition: abc_global.h:232
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
char * Extra_TimeStamp()
void Abc_NodeShowCut(Abc_Obj_t *pNode, int nNodeSizeMax, int nConeSizeMax)
Definition: abcShow.c:122
#define Abc_NtkForEachLatchInput(pNtk, pObj, i)
Definition: abc.h:500
ABC_DLL Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
Definition: abcReconv.c:588
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
int Cudd_DumpDot(DdManager *dd, int n, DdNode **f, char **inames, char **onames, FILE *fp)
Definition: cuddExport.c:344
#define assert(ex)
Definition: util_old.h:213
static void Abc_ShowGetFileName(char *pName, char *pBuffer)
Definition: abcShow.c:343
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
Definition: abcReconv.c:616
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition: mainFrame.c:64
void * pData
Definition: abc.h:145
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
void Io_WriteDotNtk(Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes, Vec_Ptr_t *vNodesShow, char *pFileName, int fGateNames, int fUseReverse)
Definition: ioWriteDot.c:71
char * pName
Definition: abc.h:158
DECLARATIONS ///.
Definition: abcReconv.c:31
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
ABC_DLL void Abc_NodeConeCollect(Abc_Obj_t **ppRoots, int nRoots, Vec_Ptr_t *vFanins, Vec_Ptr_t *vVisited, int fIncludeFanins)
Definition: abcReconv.c:441
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223