00001
00019 #include "abc.h"
00020 #include "mvc.h"
00021 #include "mainInt.h"
00022 #include "mioInt.h"
00023 #include "mapper.h"
00024
00028
00029 static int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
00030 static int Mio_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv );
00031
00032
00033 static char * pMcncGenlib[25] = {
00034 "GATE inv1 1 O=!a; PIN * INV 1 999 0.9 0.0 0.9 0.0\n",
00035 "GATE inv2 2 O=!a; PIN * INV 2 999 1.0 0.0 1.0 0.0\n",
00036 "GATE inv3 3 O=!a; PIN * INV 3 999 1.1 0.0 1.1 0.0\n",
00037 "GATE inv4 4 O=!a; PIN * INV 4 999 1.2 0.0 1.2 0.0\n",
00038 "GATE nand2 2 O=!(a*b); PIN * INV 1 999 1.0 0.0 1.0 0.0\n",
00039 "GATE nand3 3 O=!(a*b*c); PIN * INV 1 999 1.1 0.0 1.1 0.0\n",
00040 "GATE nand4 4 O=!(a*b*c*d); PIN * INV 1 999 1.4 0.0 1.4 0.0\n",
00041 "GATE nor2 2 O=!(a+b); PIN * INV 1 999 1.4 0.0 1.4 0.0\n",
00042 "GATE nor3 3 O=!(a+b+c); PIN * INV 1 999 2.4 0.0 2.4 0.0\n",
00043 "GATE nor4 4 O=!(a+b+c+d); PIN * INV 1 999 3.8 0.0 3.8 0.0\n",
00044 "GATE xora 5 O=a*!b+!a*b; PIN * UNKNOWN 2 999 1.9 0.0 1.9 0.0\n",
00045 "GATE xorb 5 O=!(a*b+!a*!b); PIN * UNKNOWN 2 999 1.9 0.0 1.9 0.0\n",
00046 "GATE xnora 5 O=a*b+!a*!b; PIN * UNKNOWN 2 999 2.1 0.0 2.1 0.0\n",
00047 "GATE xnorb 5 O=!(!a*b+a*!b); PIN * UNKNOWN 2 999 2.1 0.0 2.1 0.0\n",
00048 "GATE aoi21 3 O=!(a*b+c); PIN * INV 1 999 1.6 0.0 1.6 0.0\n",
00049 "GATE aoi22 4 O=!(a*b+c*d); PIN * INV 1 999 2.0 0.0 2.0 0.0\n",
00050 "GATE oai21 3 O=!((a+b)*c); PIN * INV 1 999 1.6 0.0 1.6 0.0\n",
00051 "GATE oai22 4 O=!((a+b)*(c+d)); PIN * INV 1 999 2.0 0.0 2.0 0.0\n",
00052 "GATE buf 1 O=a; PIN * NONINV 1 999 1.0 0.0 1.0 0.0\n",
00053 "GATE zero 0 O=CONST0;\n",
00054 "GATE one 0 O=CONST1;\n"
00055 };
00056
00060
00072 void Mio_Init( Abc_Frame_t * pAbc )
00073 {
00074 char * pFileTemp = "mcnc_temp.genlib";
00075 Mio_Library_t * pLibGen;
00076 FILE * pFile;
00077 int i;
00078
00079
00080 pFile = fopen( pFileTemp, "w" );
00081 for ( i = 0; pMcncGenlib[i]; i++ )
00082 fputs( pMcncGenlib[i], pFile );
00083 fclose( pFile );
00084
00085 pLibGen = Mio_LibraryRead( pAbc, pFileTemp, NULL, 0 );
00086 Abc_FrameSetLibGen( pLibGen );
00087 #ifdef WIN32
00088 _unlink( pFileTemp );
00089 #else
00090 unlink( pFileTemp );
00091 #endif
00092
00093 Cmd_CommandAdd( pAbc, "SC mapping", "read_library", Mio_CommandReadLibrary, 0 );
00094 Cmd_CommandAdd( pAbc, "SC mapping", "print_library", Mio_CommandPrintLibrary, 0 );
00095 }
00096
00108 void Mio_End()
00109 {
00110
00111 Mio_LibraryDelete( Abc_FrameReadLibGen() );
00112 }
00113
00114
00126 int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
00127 {
00128 FILE * pFile;
00129 FILE * pOut, * pErr;
00130 Mio_Library_t * pLib;
00131 Abc_Ntk_t * pNet;
00132 char * FileName;
00133 int fVerbose;
00134 int c;
00135
00136 pNet = Abc_FrameReadNtk(pAbc);
00137 pOut = Abc_FrameReadOut(pAbc);
00138 pErr = Abc_FrameReadErr(pAbc);
00139
00140
00141 fVerbose = 1;
00142 Extra_UtilGetoptReset();
00143 while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
00144 {
00145 switch (c)
00146 {
00147 case 'v':
00148 fVerbose ^= 1;
00149 break;
00150 case 'h':
00151 goto usage;
00152 break;
00153 default:
00154 goto usage;
00155 }
00156 }
00157
00158
00159 if ( argc != globalUtilOptind + 1 )
00160 {
00161 goto usage;
00162 }
00163
00164
00165 FileName = argv[globalUtilOptind];
00166 if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL )
00167 {
00168 fprintf( pErr, "Cannot open input file \"%s\". ", FileName );
00169 if ( (FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) )
00170 fprintf( pErr, "Did you mean \"%s\"?", FileName );
00171 fprintf( pErr, "\n" );
00172 return 1;
00173 }
00174 fclose( pFile );
00175
00176
00177 pLib = Mio_LibraryRead( pAbc, FileName, 0, fVerbose );
00178 if ( pLib == NULL )
00179 {
00180 fprintf( pErr, "Reading GENLIB library has failed.\n" );
00181 return 1;
00182 }
00183
00184 if ( Abc_FrameReadLibSuper() )
00185 {
00186 extern void Map_SuperLibFree( Map_SuperLib_t * p );
00187
00188
00189 Map_SuperLibFree( Abc_FrameReadLibSuper() );
00190 Abc_FrameSetLibSuper( NULL );
00191 }
00192
00193
00194
00195
00196 Mio_LibraryDelete( Abc_FrameReadLibGen() );
00197 Abc_FrameSetLibGen( pLib );
00198 return 0;
00199
00200 usage:
00201 fprintf( pErr, "usage: read_library [-vh]\n");
00202 fprintf( pErr, "\t read the library from a genlib file\n" );
00203 fprintf( pErr, "\t-h : enable verbose output\n");
00204 return 1;
00205 }
00206
00207
00219 int Mio_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv )
00220 {
00221 FILE * pOut, * pErr;
00222 Abc_Ntk_t * pNet;
00223 int fVerbose;
00224 int c;
00225
00226 pNet = Abc_FrameReadNtk(pAbc);
00227 pOut = Abc_FrameReadOut(pAbc);
00228 pErr = Abc_FrameReadErr(pAbc);
00229
00230
00231 fVerbose = 1;
00232 Extra_UtilGetoptReset();
00233 while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF )
00234 {
00235 switch (c)
00236 {
00237 case 'v':
00238 fVerbose ^= 1;
00239 break;
00240 case 'h':
00241 goto usage;
00242 break;
00243 default:
00244 goto usage;
00245 }
00246 }
00247
00248
00249 if ( argc != globalUtilOptind )
00250 {
00251 goto usage;
00252 }
00253
00254
00255 Mio_WriteLibrary( stdout, Abc_FrameReadLibGen(), 0 );
00256 return 0;
00257
00258 usage:
00259 fprintf( pErr, "\nusage: print_library [-vh]\n");
00260 fprintf( pErr, "\t print the current genlib library\n" );
00261 fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") );
00262 fprintf( pErr, "\t-h : print the command usage\n");
00263 return 1;
00264 }
00268
00269