abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wlcCom.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [wlcCom.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Verilog parser.]
8 
9  Synopsis [Command handlers.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - August 22, 2014.]
16 
17  Revision [$Id: wlcCom.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "wlc.h"
22 #include "base/main/mainInt.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static int Abc_CommandReadVer ( Abc_Frame_t * pAbc, int argc, char ** argv );
32 static int Abc_CommandWriteVer ( Abc_Frame_t * pAbc, int argc, char ** argv );
33 static int Abc_CommandPs ( Abc_Frame_t * pAbc, int argc, char ** argv );
34 static int Abc_CommandBlast ( Abc_Frame_t * pAbc, int argc, char ** argv );
35 static int Abc_CommandTest ( Abc_Frame_t * pAbc, int argc, char ** argv );
36 
37 static inline Wlc_Ntk_t * Wlc_AbcGetNtk( Abc_Frame_t * pAbc ) { return (Wlc_Ntk_t *)pAbc->pAbcWlc; }
38 static inline void Wlc_AbcFreeNtk( Abc_Frame_t * pAbc ) { if ( pAbc->pAbcWlc ) Wlc_NtkFree(Wlc_AbcGetNtk(pAbc)); }
39 static inline void Wlc_AbcUpdateNtk( Abc_Frame_t * pAbc, Wlc_Ntk_t * pNtk ) { Wlc_AbcFreeNtk(pAbc); pAbc->pAbcWlc = pNtk; }
40 
41 ////////////////////////////////////////////////////////////////////////
42 /// FUNCTION DEFINITIONS ///
43 ////////////////////////////////////////////////////////////////////////
44 
45 /**Function********************************************************************
46 
47  Synopsis []
48 
49  Description []
50 
51  SideEffects []
52 
53  SeeAlso []
54 
55 ******************************************************************************/
56 void Wlc_Init( Abc_Frame_t * pAbc )
57 {
58  Cmd_CommandAdd( pAbc, "Word level", "%read_ver", Abc_CommandReadVer, 0 );
59  Cmd_CommandAdd( pAbc, "Word level", "%write_ver", Abc_CommandWriteVer, 0 );
60  Cmd_CommandAdd( pAbc, "Word level", "%ps", Abc_CommandPs, 0 );
61  Cmd_CommandAdd( pAbc, "Word level", "%blast", Abc_CommandBlast, 0 );
62  Cmd_CommandAdd( pAbc, "Word level", "%test", Abc_CommandTest, 0 );
63 }
64 
65 /**Function********************************************************************
66 
67  Synopsis []
68 
69  Description []
70 
71  SideEffects []
72 
73  SeeAlso []
74 
75 ******************************************************************************/
76 void Wlc_End( Abc_Frame_t * pAbc )
77 {
78  Wlc_AbcFreeNtk( pAbc );
79 }
80 
81 
82 /**Function********************************************************************
83 
84  Synopsis []
85 
86  Description []
87 
88  SideEffects []
89 
90  SeeAlso []
91 
92 ******************************************************************************/
93 int Abc_CommandReadVer( Abc_Frame_t * pAbc, int argc, char ** argv )
94 {
95  FILE * pFile;
96  Wlc_Ntk_t * pNtk = NULL;
97  char * pFileName = NULL;
98  int c, fVerbose = 0;
100  while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
101  {
102  switch ( c )
103  {
104  case 'v':
105  fVerbose ^= 1;
106  break;
107  case 'h':
108  goto usage;
109  default:
110  goto usage;
111  }
112  }
113  if ( argc != globalUtilOptind + 1 )
114  {
115  printf( "Abc_CommandReadVer(): Input file name should be given on the command line.\n" );
116  return 0;
117  }
118  // get the file name
119  pFileName = argv[globalUtilOptind];
120  if ( (pFile = fopen( pFileName, "r" )) == NULL )
121  {
122  Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName );
123  if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".smt", NULL, NULL, NULL )) )
124  Abc_Print( 1, "Did you mean \"%s\"?", pFileName );
125  Abc_Print( 1, "\n" );
126  return 0;
127  }
128  fclose( pFile );
129 
130  // perform reading
131  pNtk = Wlc_ReadVer( pFileName );
132  Wlc_AbcUpdateNtk( pAbc, pNtk );
133  return 0;
134 usage:
135  Abc_Print( -2, "usage: %%read_ver [-vh] <file_name>\n" );
136  Abc_Print( -2, "\t reads word-level design from Verilog file\n" );
137  Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
138  Abc_Print( -2, "\t-h : print the command usage\n");
139  return 1;
140 }
141 
142 /**Function********************************************************************
143 
144  Synopsis []
145 
146  Description []
147 
148  SideEffects []
149 
150  SeeAlso []
151 
152 ******************************************************************************/
153 int Abc_CommandWriteVer( Abc_Frame_t * pAbc, int argc, char ** argv )
154 {
155  Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
156  char * pFileName = NULL;
157  int c, fVerbose = 0;
159  while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
160  {
161  switch ( c )
162  {
163  case 'v':
164  fVerbose ^= 1;
165  break;
166  case 'h':
167  goto usage;
168  default:
169  goto usage;
170  }
171  }
172  if ( pNtk == NULL )
173  {
174  Abc_Print( 1, "Abc_CommandWriteVer(): There is no current design.\n" );
175  return 0;
176  }
177  if ( argc == globalUtilOptind )
178  pFileName = Extra_FileNameGenericAppend( pNtk->pName, "_out.v" );
179  else if ( argc == globalUtilOptind + 1 )
180  pFileName = argv[globalUtilOptind];
181  else
182  {
183  printf( "Output file name should be given on the command line.\n" );
184  return 0;
185  }
186  Wlc_WriteVer( pNtk, pFileName );
187  return 0;
188 usage:
189  Abc_Print( -2, "usage: %%write_ver [-vh]\n" );
190  Abc_Print( -2, "\t writes the design into a file\n" );
191  Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
192  Abc_Print( -2, "\t-h : print the command usage\n");
193  return 1;
194 }
195 
196 
197 /**Function********************************************************************
198 
199  Synopsis []
200 
201  Description []
202 
203  SideEffects []
204 
205  SeeAlso []
206 
207 ******************************************************************************/
208 int Abc_CommandPs( Abc_Frame_t * pAbc, int argc, char ** argv )
209 {
210  Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
211  int fShowMulti = 0;
212  int fShowAdder = 0;
213  int fDistrib = 0;
214  int c, fVerbose = 0;
216  while ( ( c = Extra_UtilGetopt( argc, argv, "madvh" ) ) != EOF )
217  {
218  switch ( c )
219  {
220  case 'm':
221  fShowMulti ^= 1;
222  break;
223  case 'a':
224  fShowAdder ^= 1;
225  break;
226  case 'd':
227  fDistrib ^= 1;
228  break;
229  case 'v':
230  fVerbose ^= 1;
231  break;
232  case 'h':
233  goto usage;
234  default:
235  goto usage;
236  }
237  }
238  if ( pNtk == NULL )
239  {
240  Abc_Print( 1, "Abc_CommandPs(): There is no current design.\n" );
241  return 0;
242  }
243  Wlc_NtkPrintStats( pNtk, fDistrib, fVerbose );
244  if ( fShowMulti )
246  if ( fShowAdder )
248  return 0;
249 usage:
250  Abc_Print( -2, "usage: %%ps [-madvh]\n" );
251  Abc_Print( -2, "\t prints statistics\n" );
252  Abc_Print( -2, "\t-m : toggle printing multipliers [default = %s]\n", fShowMulti? "yes": "no" );
253  Abc_Print( -2, "\t-a : toggle printing adders [default = %s]\n", fShowAdder? "yes": "no" );
254  Abc_Print( -2, "\t-d : toggle printing distrubition [default = %s]\n", fDistrib? "yes": "no" );
255  Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
256  Abc_Print( -2, "\t-h : print the command usage\n");
257  return 1;
258 }
259 
260 /**Function********************************************************************
261 
262  Synopsis []
263 
264  Description []
265 
266  SideEffects []
267 
268  SeeAlso []
269 
270 ******************************************************************************/
271 int Abc_CommandBlast( Abc_Frame_t * pAbc, int argc, char ** argv )
272 {
273  Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
274  Vec_Int_t * vBoxIds = NULL;
275  Gia_Man_t * pNew = NULL;
276  int c, fMulti = 0, fVerbose = 0;
278  while ( ( c = Extra_UtilGetopt( argc, argv, "mvh" ) ) != EOF )
279  {
280  switch ( c )
281  {
282  case 'm':
283  fMulti ^= 1;
284  break;
285  case 'v':
286  fVerbose ^= 1;
287  break;
288  case 'h':
289  goto usage;
290  default:
291  goto usage;
292  }
293  }
294  if ( pNtk == NULL )
295  {
296  Abc_Print( 1, "Abc_CommandBlast(): There is no current design.\n" );
297  return 0;
298  }
299  if ( fMulti )
300  {
301  vBoxIds = Wlc_NtkCollectMultipliers( pNtk );
302  if ( vBoxIds == NULL )
303  Abc_Print( 1, "Warning: There is no multipliers in the design.\n" );
304  }
305  // transform
306  pNew = Wlc_NtkBitBlast( pNtk, vBoxIds );
307  Vec_IntFreeP( &vBoxIds );
308  if ( pNew == NULL )
309  {
310  Abc_Print( 1, "Abc_CommandBlast(): Bit-blasting has failed.\n" );
311  return 0;
312  }
313  Abc_FrameUpdateGia( pAbc, pNew );
314  return 0;
315 usage:
316  Abc_Print( -2, "usage: %%blast [-mvh]\n" );
317  Abc_Print( -2, "\t performs bit-blasting of the word-level design\n" );
318  Abc_Print( -2, "\t-m : toggle creating boxes for all multipliers in the design [default = %s]\n", fMulti? "yes": "no" );
319  Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
320  Abc_Print( -2, "\t-h : print the command usage\n");
321  return 1;
322 }
323 
324 /**Function********************************************************************
325 
326  Synopsis []
327 
328  Description []
329 
330  SideEffects []
331 
332  SeeAlso []
333 
334 ******************************************************************************/
335 int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
336 {
337  Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
338  int c, fVerbose = 0;
340  while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
341  {
342  switch ( c )
343  {
344  case 'v':
345  fVerbose ^= 1;
346  break;
347  case 'h':
348  goto usage;
349  default:
350  goto usage;
351  }
352  }
353  if ( pNtk == NULL )
354  {
355  Abc_Print( 1, "Abc_CommandBlast(): There is no current design.\n" );
356  return 0;
357  }
358  // transform
359  pNtk = Wlc_NtkUifNodePairs( pNtk, NULL );
360  pNtk = Wlc_NtkAbstractNodes( pNtk, NULL );
361  Wlc_AbcUpdateNtk( pAbc, pNtk );
362  return 0;
363 usage:
364  Abc_Print( -2, "usage: %%test [-vh]\n" );
365  Abc_Print( -2, "\t experiments with word-level networks\n" );
366  Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
367  Abc_Print( -2, "\t-h : print the command usage\n");
368  return 1;
369 }
370 
371 ////////////////////////////////////////////////////////////////////////
372 /// END OF FILE ///
373 ////////////////////////////////////////////////////////////////////////
374 
375 
377 
Vec_Int_t * Wlc_NtkCollectMultipliers(Wlc_Ntk_t *p)
Definition: wlcAbs.c:76
Wlc_Ntk_t * Wlc_NtkAbstractNodes(Wlc_Ntk_t *pNtk, Vec_Int_t *vNodes)
Definition: wlcAbs.c:137
void Wlc_NtkPrintStats(Wlc_Ntk_t *p, int fDistrib, int fVerbose)
Definition: wlcNtk.c:375
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static void Wlc_AbcFreeNtk(Abc_Frame_t *pAbc)
Definition: wlcCom.c:38
char * Extra_FileGetSimilarName(char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
Definition: extraUtilFile.c:71
static void Wlc_AbcUpdateNtk(Abc_Frame_t *pAbc, Wlc_Ntk_t *pNtk)
Definition: wlcCom.c:39
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition: cmdApi.c:63
static int Abc_CommandWriteVer(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: wlcCom.c:153
void Wlc_WriteVer(Wlc_Ntk_t *p, char *pFileName)
Definition: wlcWriteVer.c:354
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
ABC_DLL void Extra_UtilGetoptReset()
Definition: extraUtilUtil.c:80
char * pName
Definition: wlc.h:117
static int Abc_CommandTest(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: wlcCom.c:335
void Wlc_NtkPrintNodes(Wlc_Ntk_t *p, int Type)
Definition: wlcNtk.c:354
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int globalUtilOptind
Definition: extraUtilUtil.c:45
void Wlc_NtkFree(Wlc_Ntk_t *p)
Definition: wlcNtk.c:195
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Abc_CommandBlast(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: wlcCom.c:271
Gia_Man_t * Wlc_NtkBitBlast(Wlc_Ntk_t *p, Vec_Int_t *vBoxIds)
Definition: wlcBlast.c:405
Definition: gia.h:95
int Extra_UtilGetopt(int argc, char *argv[], const char *optstring)
Definition: extraUtilUtil.c:98
Wlc_Ntk_t * Wlc_NtkUifNodePairs(Wlc_Ntk_t *pNtk, Vec_Int_t *vPairs)
Definition: wlcAbs.c:192
void Wlc_Init(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition: wlcCom.c:56
void Abc_FrameUpdateGia(Abc_Frame_t *pAbc, Gia_Man_t *pNew)
Definition: abc.c:616
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
void Wlc_End(Abc_Frame_t *pAbc)
Definition: wlcCom.c:76
static int Abc_CommandPs(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: wlcCom.c:208
static ABC_NAMESPACE_IMPL_START int Abc_CommandReadVer(Abc_Frame_t *pAbc, int argc, char **argv)
DECLARATIONS ///.
Definition: wlcCom.c:93
Wlc_Ntk_t * Wlc_ReadVer(char *pFileName)
Definition: wlcReadVer.c:1080
static Wlc_Ntk_t * Wlc_AbcGetNtk(Abc_Frame_t *pAbc)
Definition: wlcCom.c:37