ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fpga.c
Go to the documentation of this file.
1
18
19#include "fpgaInt.h"
20#include "base/main/main.h"
21
23
24
28
29static int Fpga_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
30static 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
361 1 1
372 2 2
383 4 3
394 8 4
405 16 5
416 32 6
42*/
43
47
59void 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
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
88
89
101int 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
163usage:
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
194int 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
233usage:
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
252void 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
285
286
288
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
ABC_DLL void * Abc_FrameReadLibLut()
Definition mainFrame.c:57
ABC_DLL Abc_Ntk_t * Abc_FrameReadNtk(Abc_Frame_t *p)
Definition mainFrame.c:327
ABC_DLL FILE * Abc_FrameReadErr(Abc_Frame_t *p)
Definition mainFrame.c:375
ABC_DLL FILE * Abc_FrameReadOut(Abc_Frame_t *p)
Definition mainFrame.c:359
ABC_DLL void Abc_FrameSetLibLut(void *pLib)
Definition mainFrame.c:93
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition cmdApi.c:63
int globalUtilOptind
char * Extra_FileGetSimilarName(char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
int Extra_UtilGetopt(int argc, char *argv[], const char *optstring)
ABC_DLL void Extra_UtilGetoptReset()
void Fpga_LutLibPrint(Fpga_LutLib_t *pLutLib)
Definition fpgaLib.c:205
void Fpga_LutLibFree(Fpga_LutLib_t *p)
Definition fpgaLib.c:185
Fpga_LutLib_t * Fpga_LutLibRead(char *FileName, int fVerbose)
Definition fpgaLib.c:58
void Fpga_Init(Abc_Frame_t *pAbc)
FUNCTION DEFINITIONS ///.
Definition fpga.c:59
void Fpga_End(Abc_Frame_t *pAbc)
Definition fpga.c:84
void Fpga_SetSimpleLutLib(int nLutSize)
Definition fpga.c:252
Fpga_LutLib_t * Fpga_LutLibDup(Fpga_LutLib_t *p)
Definition fpgaLib.c:165
struct Fpga_LutLibStruct_t_ Fpga_LutLib_t
Definition fpga.h:47
usage()
Definition main.c:626
#define assert(ex)
Definition util_old.h:213