00001
00019 #include "fpgaInt.h"
00020 #include "main.h"
00021
00025
00026 static int Fpga_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
00027 static int Fpga_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044
00056 void Fpga_Init( Abc_Frame_t * pAbc )
00057 {
00058
00059
00060
00061 Fpga_LutLib_t s_LutLib = { "lutlib", 4, 0, {0,1,1,1,1}, {{0},{1},{1},{1},{1}} };
00062
00063
00064 Abc_FrameSetLibLut( Fpga_LutLibDup(&s_LutLib) );
00065
00066 Cmd_CommandAdd( pAbc, "FPGA mapping", "read_lut", Fpga_CommandReadLibrary, 0 );
00067 Cmd_CommandAdd( pAbc, "FPGA mapping", "print_lut", Fpga_CommandPrintLibrary, 0 );
00068 }
00069
00081 void Fpga_End()
00082 {
00083 Fpga_LutLibFree( Abc_FrameReadLibLut() );
00084 }
00085
00086
00098 int Fpga_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
00099 {
00100 FILE * pFile;
00101 FILE * pOut, * pErr;
00102 Fpga_LutLib_t * pLib;
00103 Abc_Ntk_t * pNet;
00104 char * FileName;
00105 int fVerbose;
00106 int c;
00107
00108 pNet = Abc_FrameReadNtk(pAbc);
00109 pOut = Abc_FrameReadOut(pAbc);
00110 pErr = Abc_FrameReadErr(pAbc);
00111
00112
00113 fVerbose = 1;
00114 Extra_UtilGetoptReset();
00115 while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
00116 {
00117 switch (c)
00118 {
00119 case 'v':
00120 fVerbose ^= 1;
00121 break;
00122 case 'h':
00123 goto usage;
00124 break;
00125 default:
00126 goto usage;
00127 }
00128 }
00129
00130
00131 if ( argc != globalUtilOptind + 1 )
00132 {
00133 goto usage;
00134 }
00135
00136
00137 FileName = argv[globalUtilOptind];
00138 if ( (pFile = fopen( FileName, "r" )) == NULL )
00139 {
00140 fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
00141 if ( FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL ) )
00142 fprintf( pErr, "Did you mean \"%s\"?", FileName );
00143 fprintf( pErr, "\n" );
00144 return 1;
00145 }
00146 fclose( pFile );
00147
00148
00149 pLib = Fpga_LutLibCreate( FileName, fVerbose );
00150 if ( pLib == NULL )
00151 {
00152 fprintf( pErr, "Reading LUT library has failed.\n" );
00153 goto usage;
00154 }
00155
00156 Fpga_LutLibFree( Abc_FrameReadLibLut() );
00157 Abc_FrameSetLibLut( pLib );
00158 return 0;
00159
00160 usage:
00161 fprintf( pErr, "\nusage: read_lut [-vh]\n");
00162 fprintf( pErr, "\t read the LUT library from the file\n" );
00163 fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
00164 fprintf( pErr, "\t-h : print the command usage\n");
00165 fprintf( pErr, "\t \n");
00166 fprintf( pErr, "\t File format for a LUT library:\n");
00167 fprintf( pErr, "\t (the default library is shown)\n");
00168 fprintf( pErr, "\t \n");
00169 fprintf( pErr, "\t # The area/delay of k-variable LUTs:\n");
00170 fprintf( pErr, "\t # k area delay\n");
00171 fprintf( pErr, "\t 1 1 1\n");
00172 fprintf( pErr, "\t 2 2 2\n");
00173 fprintf( pErr, "\t 3 4 3\n");
00174 fprintf( pErr, "\t 4 8 4\n");
00175 fprintf( pErr, "\t 5 16 5\n");
00176 fprintf( pErr, "\t 6 32 6\n");
00177 return 1;
00178 }
00179
00191 int Fpga_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
00192 {
00193 FILE * pOut, * pErr;
00194 Abc_Ntk_t * pNet;
00195 int fVerbose;
00196 int c;
00197
00198 pNet = Abc_FrameReadNtk(pAbc);
00199 pOut = Abc_FrameReadOut(pAbc);
00200 pErr = Abc_FrameReadErr(pAbc);
00201
00202
00203 fVerbose = 1;
00204 Extra_UtilGetoptReset();
00205 while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
00206 {
00207 switch (c)
00208 {
00209 case 'v':
00210 fVerbose ^= 1;
00211 break;
00212 case 'h':
00213 goto usage;
00214 break;
00215 default:
00216 goto usage;
00217 }
00218 }
00219
00220
00221 if ( argc != globalUtilOptind )
00222 {
00223 goto usage;
00224 }
00225
00226
00227 Fpga_LutLibPrint( Abc_FrameReadLibLut() );
00228 return 0;
00229
00230 usage:
00231 fprintf( pErr, "\nusage: read_print [-vh]\n");
00232 fprintf( pErr, "\t print the current LUT library\n" );
00233 fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
00234 fprintf( pErr, "\t-h : print the command usage\n");
00235 return 1;
00236 }
00237
00249 void Fpga_SetSimpleLutLib( int nLutSize )
00250 {
00251 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}} };
00252 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}} };
00253 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}} };
00254 Fpga_LutLib_t s_LutLib7 = { "lutlib", 7, 0, {0,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1}} };
00255 Fpga_LutLib_t s_LutLib6 = { "lutlib", 6, 0, {0,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1}} };
00256 Fpga_LutLib_t s_LutLib5 = { "lutlib", 5, 0, {0,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1}} };
00257 Fpga_LutLib_t s_LutLib4 = { "lutlib", 4, 0, {0,1,1,1,1}, {{0},{1},{1},{1},{1}} };
00258 Fpga_LutLib_t s_LutLib3 = { "lutlib", 3, 0, {0,1,1,1}, {{0},{1},{1},{1}} };
00259 Fpga_LutLib_t * pLutLib;
00260 assert( nLutSize >= 3 && nLutSize <= 10 );
00261 switch ( nLutSize )
00262 {
00263 case 3: pLutLib = &s_LutLib3; break;
00264 case 4: pLutLib = &s_LutLib4; break;
00265 case 5: pLutLib = &s_LutLib5; break;
00266 case 6: pLutLib = &s_LutLib6; break;
00267 case 7: pLutLib = &s_LutLib7; break;
00268 case 8: pLutLib = &s_LutLib8; break;
00269 case 9: pLutLib = &s_LutLib9; break;
00270 case 10: pLutLib = &s_LutLib10; break;
00271 default: pLutLib = NULL; break;
00272 }
00273 if ( pLutLib == NULL )
00274 return;
00275 Fpga_LutLibFree( Abc_FrameReadLibLut() );
00276 Abc_FrameSetLibLut( Fpga_LutLibDup(pLutLib) );
00277 }
00278
00282
00283