abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ifCom.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ifCom.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [FPGA mapping based on priority cuts.]
8 
9  Synopsis [Command handlers.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 21, 2006.]
16 
17  Revision [$Id: ifCom.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "if.h"
22 #include "base/main/main.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static int If_CommandReadLut ( Abc_Frame_t * pAbc, int argc, char **argv );
32 static int If_CommandPrintLut( Abc_Frame_t * pAbc, int argc, char **argv );
33 static int If_CommandReadBox ( Abc_Frame_t * pAbc, int argc, char **argv );
34 static int If_CommandPrintBox( Abc_Frame_t * pAbc, int argc, char **argv );
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Package initialization procedure.]
43 
44  Description []
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
51 void If_Init( Abc_Frame_t * pAbc )
52 {
53  // set the default library
54  If_LibLut_t s_LutLib = { "lutlib", 4, 0, {0,1,1,1,1}, {{0},{1},{1},{1},{1}} };
55  Abc_FrameSetLibLut( If_LibLutDup(&s_LutLib) );
56 
57  Cmd_CommandAdd( pAbc, "FPGA mapping", "read_lut", If_CommandReadLut, 0 );
58  Cmd_CommandAdd( pAbc, "FPGA mapping", "print_lut", If_CommandPrintLut, 0 );
59 
60  Cmd_CommandAdd( pAbc, "FPGA mapping", "read_box", If_CommandReadBox, 0 );
61  Cmd_CommandAdd( pAbc, "FPGA mapping", "print_box", If_CommandPrintBox, 0 );
62 }
63 
64 /**Function*************************************************************
65 
66  Synopsis [Package ending procedure.]
67 
68  Description []
69 
70  SideEffects []
71 
72  SeeAlso []
73 
74 ***********************************************************************/
75 void If_End( Abc_Frame_t * pAbc )
76 {
79 }
80 
81 /**Function*************************************************************
82 
83  Synopsis [Command procedure to read LUT libraries.]
84 
85  Description []
86 
87  SideEffects []
88 
89  SeeAlso []
90 
91 ***********************************************************************/
92 int If_CommandReadLut( Abc_Frame_t * pAbc, int argc, char **argv )
93 {
94  FILE * pFile;
95  FILE * pOut, * pErr;
96  If_LibLut_t * pLib;
97  Abc_Ntk_t * pNet;
98  char * FileName;
99  int fVerbose;
100  int c;
101 
102  pNet = Abc_FrameReadNtk(pAbc);
103  pOut = Abc_FrameReadOut(pAbc);
104  pErr = Abc_FrameReadErr(pAbc);
105 
106  // set the defaults
107  fVerbose = 1;
109  while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
110  {
111  switch (c)
112  {
113  case 'v':
114  fVerbose ^= 1;
115  break;
116  case 'h':
117  goto usage;
118  break;
119  default:
120  goto usage;
121  }
122  }
123 
124  if ( argc != globalUtilOptind + 1 )
125  goto usage;
126 
127  // get the input file name
128  FileName = argv[globalUtilOptind];
129  if ( (pFile = fopen( FileName, "r" )) == NULL )
130  {
131  fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
132  if ( (FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) )
133  fprintf( pErr, "Did you mean \"%s\"?", FileName );
134  fprintf( pErr, "\n" );
135  return 1;
136  }
137  fclose( pFile );
138 
139  // set the new network
140  pLib = If_LibLutRead( FileName );
141  if ( pLib == NULL )
142  {
143  fprintf( pErr, "Reading LUT library has failed.\n" );
144  goto usage;
145  }
146  // replace the current library
148  Abc_FrameSetLibLut( pLib );
149  return 0;
150 
151 usage:
152  fprintf( pErr, "\nusage: read_lut [-vh]\n");
153  fprintf( pErr, "\t read the LUT library from the file\n" );
154  fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
155  fprintf( pErr, "\t-h : print the command usage\n");
156  fprintf( pErr, "\t \n");
157  fprintf( pErr, "\t File format for a LUT library:\n");
158  fprintf( pErr, "\t (the default library is shown)\n");
159  fprintf( pErr, "\t \n");
160  fprintf( pErr, "\t # The area/delay of k-variable LUTs:\n");
161  fprintf( pErr, "\t # k area delay\n");
162  fprintf( pErr, "\t 1 1 1\n");
163  fprintf( pErr, "\t 2 2 2\n");
164  fprintf( pErr, "\t 3 4 3\n");
165  fprintf( pErr, "\t 4 8 4\n");
166  fprintf( pErr, "\t 5 16 5\n");
167  fprintf( pErr, "\t 6 32 6\n");
168  return 1; /* error exit */
169 }
170 
171 /**Function*************************************************************
172 
173  Synopsis [Command procedure to read LUT libraries.]
174 
175  Description []
176 
177  SideEffects []
178 
179  SeeAlso []
180 
181 ***********************************************************************/
182 int If_CommandPrintLut( Abc_Frame_t * pAbc, int argc, char **argv )
183 {
184  FILE * pOut, * pErr;
185  Abc_Ntk_t * pNet;
186  int fVerbose;
187  int c;
188 
189  pNet = Abc_FrameReadNtk(pAbc);
190  pOut = Abc_FrameReadOut(pAbc);
191  pErr = Abc_FrameReadErr(pAbc);
192 
193  // set the defaults
194  fVerbose = 1;
196  while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
197  {
198  switch (c)
199  {
200  case 'v':
201  fVerbose ^= 1;
202  break;
203  case 'h':
204  goto usage;
205  break;
206  default:
207  goto usage;
208  }
209  }
210 
211  if ( argc != globalUtilOptind )
212  goto usage;
213 
214  // set the new network
216  return 0;
217 
218 usage:
219  fprintf( pErr, "\nusage: print_lut [-vh]\n");
220  fprintf( pErr, "\t print the current LUT library\n" );
221  fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
222  fprintf( pErr, "\t-h : print the command usage\n");
223  return 1; /* error exit */
224 }
225 
226 /**Function*************************************************************
227 
228  Synopsis []
229 
230  Description []
231 
232  SideEffects []
233 
234  SeeAlso []
235 
236 ***********************************************************************/
237 int If_CommandReadBox( Abc_Frame_t * pAbc, int argc, char **argv )
238 {
239  FILE * pFile;
240  FILE * pOut, * pErr;
241  If_LibBox_t * pLib;
242  Abc_Ntk_t * pNet;
243  char * FileName;
244  int fExtended;
245  int fVerbose;
246  int c;
247 
248  pNet = Abc_FrameReadNtk(pAbc);
249  pOut = Abc_FrameReadOut(pAbc);
250  pErr = Abc_FrameReadErr(pAbc);
251 
252  // set the defaults
253  fExtended = 0;
254  fVerbose = 1;
256  while ( (c = Extra_UtilGetopt(argc, argv, "evh")) != EOF )
257  {
258  switch (c)
259  {
260  case 'e':
261  fExtended ^= 1;
262  break;
263  case 'v':
264  fVerbose ^= 1;
265  break;
266  case 'h':
267  goto usage;
268  break;
269  default:
270  goto usage;
271  }
272  }
273 
274  if ( argc != globalUtilOptind + 1 )
275  goto usage;
276 
277  // get the input file name
278  FileName = argv[globalUtilOptind];
279  if ( (pFile = fopen( FileName, "r" )) == NULL )
280  {
281  fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
282  if ( (FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) )
283  fprintf( pErr, "Did you mean \"%s\"?", FileName );
284  fprintf( pErr, "\n" );
285  return 1;
286  }
287  fclose( pFile );
288 
289  // set the new network
290  pLib = fExtended ? If_LibBoxRead2( FileName ) : If_LibBoxRead( FileName );
291  if ( pLib == NULL )
292  {
293  fprintf( pErr, "Reading box library has failed.\n" );
294  goto usage;
295  }
296  // replace the current library
298  Abc_FrameSetLibBox( pLib );
299  return 0;
300 
301 usage:
302  fprintf( pErr, "\nusage: read_box [-evh]\n");
303  fprintf( pErr, "\t read the box library from the file\n" );
304  fprintf( pErr, "\t-e : toggles reading extended format [default = %s]\n", (fExtended? "yes" : "no") );
305  fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
306  fprintf( pErr, "\t-h : print the command usage\n");
307  return 1; /* error exit */
308 }
309 
310 /**Function*************************************************************
311 
312  Synopsis [Command procedure to read LUT libraries.]
313 
314  Description []
315 
316  SideEffects []
317 
318  SeeAlso []
319 
320 ***********************************************************************/
321 int If_CommandPrintBox( Abc_Frame_t * pAbc, int argc, char **argv )
322 {
323  FILE * pOut, * pErr;
324  Abc_Ntk_t * pNet;
325  int fVerbose;
326  int c;
327 
328  pNet = Abc_FrameReadNtk(pAbc);
329  pOut = Abc_FrameReadOut(pAbc);
330  pErr = Abc_FrameReadErr(pAbc);
331 
332  // set the defaults
333  fVerbose = 1;
335  while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
336  {
337  switch (c)
338  {
339  case 'v':
340  fVerbose ^= 1;
341  break;
342  case 'h':
343  goto usage;
344  break;
345  default:
346  goto usage;
347  }
348  }
349 
350  if ( argc != globalUtilOptind )
351  goto usage;
352 
353  // set the new network
355  return 0;
356 
357 usage:
358  fprintf( pErr, "\nusage: print_box [-vh]\n");
359  fprintf( pErr, "\t print the current box library\n" );
360  fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
361  fprintf( pErr, "\t-h : print the command usage\n");
362  return 1; /* error exit */
363 }
364 
365 
366 ////////////////////////////////////////////////////////////////////////
367 /// END OF FILE ///
368 ////////////////////////////////////////////////////////////////////////
369 
370 
372 
static int If_CommandPrintBox(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: ifCom.c:321
static int If_CommandReadBox(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: ifCom.c:237
ABC_DLL void Abc_FrameSetLibLut(void *pLib)
Definition: mainFrame.c:80
void If_LibBoxFree(If_LibBox_t *p)
Definition: ifLibBox.c:98
void If_LibLutPrint(If_LibLut_t *pLutLib)
Definition: ifLibLut.c:193
If_LibLut_t * If_LibLutRead(char *FileName)
FUNCTION DEFINITIONS ///.
Definition: ifLibLut.c:47
void If_LibBoxPrint(FILE *pFile, If_LibBox_t *p)
Definition: ifLibBox.c:334
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
If_LibBox_t * If_LibBoxRead2(char *pFileName)
Definition: ifLibBox.c:155
If_LibBox_t * If_LibBoxRead(char *pFileName)
Definition: ifLibBox.c:273
void If_Init(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition: ifCom.c:51
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
ABC_DLL void Extra_UtilGetoptReset()
Definition: extraUtilUtil.c:80
static int If_CommandPrintLut(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: ifCom.c:182
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_DLL void * Abc_FrameReadLibBox()
Definition: mainFrame.c:55
int globalUtilOptind
Definition: extraUtilUtil.c:45
If_LibLut_t * If_LibLutDup(If_LibLut_t *p)
Definition: ifLibLut.c:153
ABC_DLL void Abc_FrameSetLibBox(void *pLib)
Definition: mainFrame.c:81
static ABC_NAMESPACE_IMPL_START int If_CommandReadLut(Abc_Frame_t *pAbc, int argc, char **argv)
DECLARATIONS ///.
Definition: ifCom.c:92
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
ABC_DLL Abc_Ntk_t * Abc_FrameReadNtk(Abc_Frame_t *p)
Definition: mainFrame.c:282
void If_End(Abc_Frame_t *pAbc)
Definition: ifCom.c:75
int Extra_UtilGetopt(int argc, char *argv[], const char *optstring)
Definition: extraUtilUtil.c:98
void If_LibLutFree(If_LibLut_t *pLutLib)
Definition: ifLibLut.c:173
ABC_DLL FILE * Abc_FrameReadErr(Abc_Frame_t *p)
Definition: mainFrame.c:330
ABC_DLL FILE * Abc_FrameReadOut(Abc_Frame_t *p)
Definition: mainFrame.c:314
ABC_DLL void * Abc_FrameReadLibLut()
Definition: mainFrame.c:54