00001 
00019 #include "mapperInt.h"
00020 
00024 
00028 
00048 Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, bool fAlgorithm, bool fVerbose )
00049 {
00050     Map_SuperLib_t * p;
00051     int clk;
00052 
00053     
00054     p = ALLOC( Map_SuperLib_t, 1 );
00055     memset( p, 0, sizeof(Map_SuperLib_t) );
00056     p->pName     = pFileName;
00057     p->fVerbose  = fVerbose;
00058     p->mmSupers  = Extra_MmFixedStart( sizeof(Map_Super_t) );
00059     p->mmEntries = Extra_MmFixedStart( sizeof(Map_HashEntry_t) );
00060     p->mmForms   = Extra_MmFlexStart();
00061     Map_MappingSetupTruthTables( p->uTruths );
00062 
00063     
00064     p->tTableC = Map_SuperTableCreate( p );
00065     p->tTable  = Map_SuperTableCreate( p );
00066 
00067     
00068 clk = clock();
00069     if ( fAlgorithm )
00070     {
00071         if ( !Map_LibraryReadTree( p, pFileName, pExcludeFile ) )
00072         {
00073             Map_SuperLibFree( p );
00074             return NULL;
00075         }
00076     }
00077     else
00078     {
00079         if ( pExcludeFile != 0 )
00080         {
00081             printf ("Error: Exclude file support not present for old format. Stop.\n");
00082             return NULL;
00083         }
00084         if ( !Map_LibraryRead( p, pFileName ) )
00085         {
00086             Map_SuperLibFree( p );
00087             return NULL;
00088         }
00089     }
00090     assert( p->nVarsMax > 0 );
00091 
00092     
00093 if ( fVerbose ) {
00094     printf( "Loaded %d unique %d-input supergates from \"%s\".  ", 
00095         p->nSupersReal, p->nVarsMax, pFileName );
00096     PRT( "Time", clock() - clk );
00097 }
00098 
00099     
00100     p->pGateInv        = Mio_LibraryReadInv( p->pGenlib );
00101     p->tDelayInv.Rise  = Mio_LibraryReadDelayInvRise( p->pGenlib );
00102     p->tDelayInv.Fall  = Mio_LibraryReadDelayInvFall( p->pGenlib );
00103     p->tDelayInv.Worst = MAP_MAX( p->tDelayInv.Rise, p->tDelayInv.Fall );
00104     p->AreaInv         = Mio_LibraryReadAreaInv( p->pGenlib );
00105     p->AreaBuf         = Mio_LibraryReadAreaBuf( p->pGenlib );
00106 
00107     
00108     p->pSuperInv = (Map_Super_t *)Extra_MmFixedEntryFetch( p->mmSupers );
00109     memset( p->pSuperInv, 0, sizeof(Map_Super_t) );
00110     p->pSuperInv->Num         = -1;
00111     p->pSuperInv->nGates      =  1;
00112     p->pSuperInv->nFanins     =  1;
00113     p->pSuperInv->nFanLimit   = 10;
00114     p->pSuperInv->pFanins[0]  = p->ppSupers[0];
00115     p->pSuperInv->pRoot       = p->pGateInv;
00116     p->pSuperInv->Area        = p->AreaInv;
00117     p->pSuperInv->tDelayMax   = p->tDelayInv;
00118     p->pSuperInv->tDelaysR[0].Rise = MAP_NO_VAR;
00119     p->pSuperInv->tDelaysR[0].Fall = p->tDelayInv.Rise;
00120     p->pSuperInv->tDelaysF[0].Rise = p->tDelayInv.Fall;
00121     p->pSuperInv->tDelaysF[0].Fall = MAP_NO_VAR;
00122     return p;
00123 }
00124 
00125 
00137 void Map_SuperLibFree( Map_SuperLib_t * p )
00138 {
00139     if ( p == NULL ) return;
00140     if ( p->pGenlib )
00141     {
00142         assert( p->pGenlib == Abc_FrameReadLibGen() );
00143         Mio_LibraryDelete( p->pGenlib );
00144         Abc_FrameSetLibGen( NULL );
00145     }
00146     if ( p->tTableC )
00147         Map_SuperTableFree( p->tTableC );
00148     if ( p->tTable )
00149         Map_SuperTableFree( p->tTable );
00150     Extra_MmFixedStop( p->mmSupers );
00151     Extra_MmFixedStop( p->mmEntries );
00152     Extra_MmFlexStop( p->mmForms );
00153     FREE( p->ppSupers );
00154     FREE( p );
00155 }
00156 
00168 int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib )
00169 {
00170     Abc_Frame_t * pAbc = Abc_FrameGetGlobalFrame();
00171     char * pNameGeneric;
00172     char FileNameGenlib[100];
00173     char FileNameSuper[100];
00174     char CommandSuper[500];
00175     char CommandRead[500];
00176     FILE * pFile;
00177 
00178     if ( pLib == NULL )
00179         return 0;
00180 
00181     
00182     sprintf( FileNameGenlib, "%s_temp", Mio_LibraryReadName(pLib) );
00183     pFile = fopen( FileNameGenlib, "w" );
00184     Mio_WriteLibrary( pFile, pLib, 0 );
00185     fclose( pFile );
00186 
00187     
00188     pNameGeneric = Extra_FileNameGeneric( Mio_LibraryReadName(pLib) );
00189     sprintf( FileNameSuper, "%s.super", pNameGeneric );
00190     free( pNameGeneric );
00191 
00192     sprintf( CommandSuper,  "super -l 1 -i 5 -d 10000000 -a 10000000 -t 100 %s", FileNameGenlib ); 
00193     if ( Cmd_CommandExecute( pAbc, CommandSuper ) )
00194     {
00195         fprintf( stdout, "Cannot execute command \"%s\".\n", CommandSuper );
00196         return 0;
00197     }
00198 
00199 
00200 
00201 
00202 
00203 
00204     sprintf( CommandRead,  "read_super %s", FileNameSuper ); 
00205     if ( Cmd_CommandExecute( pAbc, CommandRead ) )
00206     {
00207 #ifdef WIN32
00208         _unlink( FileNameSuper );
00209 #else
00210         unlink( FileNameSuper );
00211 #endif
00212         fprintf( stdout, "Cannot execute command \"%s\".\n", CommandRead );
00213         return 0;
00214     }
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223      return 1;
00224 }
00225 
00226 
00230 
00231