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