abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fpga.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fpga.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Command file for the FPGA package.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - August 18, 2004.]
14 
15  Revision [$Id: fpga.c,v 1.4 2004/10/28 17:36:07 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fpgaInt.h"
20 #include "base/main/main.h"
21 
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 static int Fpga_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
30 static int Fpga_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
31 
32 // the library file format should be as follows:
33 /*
34 # The area/delay of k-variable LUTs:
35 # k area delay
36 1 1 1
37 2 2 2
38 3 4 3
39 4 8 4
40 5 16 5
41 6 32 6
42 */
43 
44 ////////////////////////////////////////////////////////////////////////
45 /// FUNCTION DEFINITIONS ///
46 ////////////////////////////////////////////////////////////////////////
47 
48 /**Function*************************************************************
49 
50  Synopsis [Package initialization procedure.]
51 
52  Description []
53 
54  SideEffects []
55 
56  SeeAlso []
57 
58 ***********************************************************************/
59 void Fpga_Init( Abc_Frame_t * pAbc )
60 {
61  // set the default library
62  //Fpga_LutLib_t s_LutLib = { "lutlib", 6, 0, {0,1,2,4,8,16,32}, {{0},{1},{2},{3},{4},{5},{6}} };
63 // Fpga_LutLib_t s_LutLib = { "lutlib", 5, 0, {0,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1}} };
64  Fpga_LutLib_t s_LutLib = { "lutlib", 4, 0, {0,1,1,1,1}, {{0},{1},{1},{1},{1}} };
65  //Fpga_LutLib_t s_LutLib = { "lutlib", 3, 0, {0,1,1,1}, {{0},{1},{1},{1}} };
66 
67  Abc_FrameSetLibLut( Fpga_LutLibDup(&s_LutLib) );
68 
69  Cmd_CommandAdd( pAbc, "FPGA mapping", "read_lut", Fpga_CommandReadLibrary, 0 );
70  Cmd_CommandAdd( pAbc, "FPGA mapping", "print_lut", Fpga_CommandPrintLibrary, 0 );
71 }
72 
73 /**Function*************************************************************
74 
75  Synopsis [Package ending procedure.]
76 
77  Description []
78 
79  SideEffects []
80 
81  SeeAlso []
82 
83 ***********************************************************************/
84 void Fpga_End( Abc_Frame_t * pAbc )
85 {
87 }
88 
89 
90 /**Function*************************************************************
91 
92  Synopsis [Command procedure to read LUT libraries.]
93 
94  Description []
95 
96  SideEffects []
97 
98  SeeAlso []
99 
100 ***********************************************************************/
101 int Fpga_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
102 {
103  FILE * pFile;
104  FILE * pOut, * pErr;
105  Fpga_LutLib_t * pLib;
106  Abc_Ntk_t * pNet;
107  char * FileName;
108  int fVerbose;
109  int c;
110 
111  pNet = Abc_FrameReadNtk(pAbc);
112  pOut = Abc_FrameReadOut(pAbc);
113  pErr = Abc_FrameReadErr(pAbc);
114 
115  // set the defaults
116  fVerbose = 1;
118  while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
119  {
120  switch (c)
121  {
122  case 'v':
123  fVerbose ^= 1;
124  break;
125  case 'h':
126  goto usage;
127  break;
128  default:
129  goto usage;
130  }
131  }
132 
133 
134  if ( argc != globalUtilOptind + 1 )
135  {
136  goto usage;
137  }
138 
139  // get the input file name
140  FileName = argv[globalUtilOptind];
141  if ( (pFile = fopen( FileName, "r" )) == NULL )
142  {
143  fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
144  if ( (FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) )
145  fprintf( pErr, "Did you mean \"%s\"?", FileName );
146  fprintf( pErr, "\n" );
147  return 1;
148  }
149  fclose( pFile );
150 
151  // set the new network
152  pLib = Fpga_LutLibRead( FileName, fVerbose );
153  if ( pLib == NULL )
154  {
155  fprintf( pErr, "Reading LUT library has failed.\n" );
156  goto usage;
157  }
158  // replace the current library
160  Abc_FrameSetLibLut( pLib );
161  return 0;
162 
163 usage:
164  fprintf( pErr, "usage: read_lut [-vh]\n");
165  fprintf( pErr, "\t read the LUT library from the file\n" );
166  fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
167  fprintf( pErr, "\t-h : print the command usage\n");
168  fprintf( pErr, "\t \n");
169  fprintf( pErr, "\t File format for a LUT library:\n");
170  fprintf( pErr, "\t (the default library is shown)\n");
171  fprintf( pErr, "\t \n");
172  fprintf( pErr, "\t # The area/delay of k-variable LUTs:\n");
173  fprintf( pErr, "\t # k area delay\n");
174  fprintf( pErr, "\t 1 1 1\n");
175  fprintf( pErr, "\t 2 2 2\n");
176  fprintf( pErr, "\t 3 4 3\n");
177  fprintf( pErr, "\t 4 8 4\n");
178  fprintf( pErr, "\t 5 16 5\n");
179  fprintf( pErr, "\t 6 32 6\n");
180  return 1; /* error exit */
181 }
182 
183 /**Function*************************************************************
184 
185  Synopsis [Command procedure to read LUT libraries.]
186 
187  Description []
188 
189  SideEffects []
190 
191  SeeAlso []
192 
193 ***********************************************************************/
194 int Fpga_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
195 {
196  FILE * pOut, * pErr;
197  Abc_Ntk_t * pNet;
198  int fVerbose;
199  int c;
200 
201  pNet = Abc_FrameReadNtk(pAbc);
202  pOut = Abc_FrameReadOut(pAbc);
203  pErr = Abc_FrameReadErr(pAbc);
204 
205  // set the defaults
206  fVerbose = 1;
208  while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
209  {
210  switch (c)
211  {
212  case 'v':
213  fVerbose ^= 1;
214  break;
215  case 'h':
216  goto usage;
217  break;
218  default:
219  goto usage;
220  }
221  }
222 
223 
224  if ( argc != globalUtilOptind )
225  {
226  goto usage;
227  }
228 
229  // set the new network
231  return 0;
232 
233 usage:
234  fprintf( pErr, "usage: print_lut [-vh]\n");
235  fprintf( pErr, "\t print the current LUT library\n" );
236  fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
237  fprintf( pErr, "\t-h : print the command usage\n");
238  return 1; /* error exit */
239 }
240 
241 /**Function*************************************************************
242 
243  Synopsis [Sets simple LUT library.]
244 
245  Description []
246 
247  SideEffects []
248 
249  SeeAlso []
250 
251 ***********************************************************************/
252 void Fpga_SetSimpleLutLib( int nLutSize )
253 {
254  Fpga_LutLib_t s_LutLib10= { "lutlib",10, 0, {0,1,1,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1},{1},{1}} };
255  Fpga_LutLib_t s_LutLib9 = { "lutlib", 9, 0, {0,1,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1},{1}} };
256  Fpga_LutLib_t s_LutLib8 = { "lutlib", 8, 0, {0,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1}} };
257  Fpga_LutLib_t s_LutLib7 = { "lutlib", 7, 0, {0,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1}} };
258  Fpga_LutLib_t s_LutLib6 = { "lutlib", 6, 0, {0,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1}} };
259  Fpga_LutLib_t s_LutLib5 = { "lutlib", 5, 0, {0,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1}} };
260  Fpga_LutLib_t s_LutLib4 = { "lutlib", 4, 0, {0,1,1,1,1}, {{0},{1},{1},{1},{1}} };
261  Fpga_LutLib_t s_LutLib3 = { "lutlib", 3, 0, {0,1,1,1}, {{0},{1},{1},{1}} };
262  Fpga_LutLib_t * pLutLib;
263  assert( nLutSize >= 3 && nLutSize <= 10 );
264  switch ( nLutSize )
265  {
266  case 3: pLutLib = &s_LutLib3; break;
267  case 4: pLutLib = &s_LutLib4; break;
268  case 5: pLutLib = &s_LutLib5; break;
269  case 6: pLutLib = &s_LutLib6; break;
270  case 7: pLutLib = &s_LutLib7; break;
271  case 8: pLutLib = &s_LutLib8; break;
272  case 9: pLutLib = &s_LutLib9; break;
273  case 10: pLutLib = &s_LutLib10; break;
274  default: pLutLib = NULL; break;
275  }
276  if ( pLutLib == NULL )
277  return;
280 }
281 
282 ////////////////////////////////////////////////////////////////////////
283 /// END OF FILE ///
284 ////////////////////////////////////////////////////////////////////////
285 
286 
288 
Fpga_LutLib_t * Fpga_LutLibRead(char *FileName, int fVerbose)
Definition: fpgaLib.c:58
ABC_DLL void Abc_FrameSetLibLut(void *pLib)
Definition: mainFrame.c:80
void Fpga_LutLibPrint(Fpga_LutLib_t *pLutLib)
Definition: fpgaLib.c:205
char * Extra_FileGetSimilarName(char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
Definition: extraUtilFile.c:71
Fpga_LutLib_t * Fpga_LutLibDup(Fpga_LutLib_t *p)
Definition: fpgaLib.c:165
void Fpga_LutLibFree(Fpga_LutLib_t *p)
Definition: fpgaLib.c:185
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition: cmdApi.c:63
void Fpga_End(Abc_Frame_t *pAbc)
Definition: fpga.c:84
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
ABC_DLL void Extra_UtilGetoptReset()
Definition: extraUtilUtil.c:80
void Fpga_Init(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition: fpga.c:59
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Fpga_CommandPrintLibrary(Abc_Frame_t *pAbc, int argc, char **argv)
Definition: fpga.c:194
int globalUtilOptind
Definition: extraUtilUtil.c:45
#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
int Extra_UtilGetopt(int argc, char *argv[], const char *optstring)
Definition: extraUtilUtil.c:98
static ABC_NAMESPACE_IMPL_START int Fpga_CommandReadLibrary(Abc_Frame_t *pAbc, int argc, char **argv)
DECLARATIONS ///.
Definition: fpga.c:101
ABC_DLL FILE * Abc_FrameReadErr(Abc_Frame_t *p)
Definition: mainFrame.c:330
#define assert(ex)
Definition: util_old.h:213
void Fpga_SetSimpleLutLib(int nLutSize)
Definition: fpga.c:252
ABC_DLL FILE * Abc_FrameReadOut(Abc_Frame_t *p)
Definition: mainFrame.c:314
ABC_DLL void * Abc_FrameReadLibLut()
Definition: mainFrame.c:54