/**Function************************************************************* Synopsis [Interface with the mapping package.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Abc_NtkSuperChoice( Abc_Ntk_t * pNtk ) { Abc_Ntk_t * pNtkNew; Map_Man_t * pMan; assert( Abc_NtkIsStrash(pNtk) ); // check that the library is available if ( Abc_FrameReadLibGen() == NULL ) { printf( "The current library is not available.\n" ); return 0; } // derive the supergate library if ( Abc_FrameReadLibSuper() == NULL && Abc_FrameReadLibGen() ) { // printf( "A simple supergate library is derived from gate library \"%s\".\n", // Mio_LibraryReadName((Mio_Library_t *)Abc_FrameReadLibGen()) ); Map_SuperLibDeriveFromGenlib( (Mio_Library_t *)Abc_FrameReadLibGen(), 0 ); } // print a warning about choice nodes if ( Abc_NtkGetChoiceNum( pNtk ) ) printf( "Performing mapping with choices.\n" ); // perform the mapping pMan = Abc_NtkToMap( pNtk, -1, 1, NULL, 0 ); if ( pMan == NULL ) return NULL; if ( !Map_Mapping( pMan ) ) { Map_ManFree( pMan ); return NULL; } // reconstruct the network after mapping pNtkNew = Abc_NtkFromMapSuperChoice( pMan, pNtk ); if ( pNtkNew == NULL ) return NULL; Map_ManFree( pMan ); // make sure that everything is okay if ( !Abc_NtkCheck( pNtkNew ) ) { printf( "Abc_NtkMap: The network check has failed.\n" ); Abc_NtkDelete( pNtkNew ); return NULL; } return pNtkNew; }
/**Function************************************************************* Synopsis [Command procedure to read LUT libraries.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Mio_CommandWriteProfile( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pOut, * pErr, * pFile; char * pFileName; int c; pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "h")) != EOF ) { switch (c) { case 'h': goto usage; break; default: goto usage; } } if ( Abc_FrameReadLibGen() == NULL ) { printf( "Library is not available.\n" ); return 1; } if ( argc != globalUtilOptind + 1 ) { printf( "The file name is not given.\n" ); return 1; } pFileName = argv[globalUtilOptind]; pFile = fopen( pFileName, "w" ); if ( pFile == NULL ) { printf( "Error! Cannot open file \"%s\" for writing the library.\n", pFileName ); return 1; } Mio_LibraryWriteProfile( pFile, (Mio_Library_t *)Abc_FrameReadLibGen() ); fclose( pFile ); printf( "The current profile is written into file \"%s\".\n", pFileName ); return 0; usage: fprintf( pErr, "\nusage: write_profile [-h] <file>\n"); fprintf( pErr, "\t writes the current profile into a file\n" ); fprintf( pErr, "\t-h : print the command usage\n"); fprintf( pErr, "\t<file> : file name to write the profile\n"); return 1; }
/**Function************************************************************* Synopsis [Command procedure to read LUT libraries.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Mio_CommandPrintGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pOut, * pErr; int fShort = 0; int fSelected = 0; int fVerbose = 0; int c; pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); // set the defaults Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "savh")) != EOF ) { switch (c) { case 's': fShort ^= 1; break; case 'a': fSelected ^= 1; break; case 'v': fVerbose ^= 1; break; case 'h': goto usage; break; default: goto usage; } } if ( Abc_FrameReadLibGen() == NULL ) { printf( "Library is not available.\n" ); return 1; } Mio_WriteLibrary( stdout, (Mio_Library_t *)Abc_FrameReadLibGen(), 0, fShort, fSelected ); return 0; usage: fprintf( pErr, "\nusage: print_genlib [-savh]\n"); fprintf( pErr, "\t print the current genlib library\n" ); fprintf( pErr, "\t-s : toggles writing short form [default = %s]\n", fShort? "yes" : "no" ); fprintf( pErr, "\t-a : toggles writing min-area gates [default = %s]\n", fSelected? "yes" : "no" ); fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", fVerbose? "yes" : "no" ); fprintf( pErr, "\t-h : print the command usage\n"); return 1; }
int Mio_UpdateGenlib2( Vec_Str_t * vStr, Vec_Str_t * vStr2, char * pFileName, int fVerbose ) { Mio_Library_t * pLib; // set the new network pLib = Mio_LibraryRead( pFileName, Vec_StrArray(vStr), NULL, fVerbose ); if ( pLib == NULL ) return 0; // free the current superlib because it depends on the old Mio library if ( Abc_FrameReadLibSuper() ) { Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() ); Abc_FrameSetLibSuper( NULL ); } // replace the current library Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() ); Abc_FrameSetLibGen( pLib ); // set the new network pLib = (Mio_Library_t *)Amap_LibReadAndPrepare( pFileName, Vec_StrArray(vStr2), 0, 0 ); if ( pLib == NULL ) return 0; // replace the current library Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() ); Abc_FrameSetLibGen2( pLib ); return 1; }
Abc_Obj_t * Abc_NodeFromMap_rec( Abc_Ntk_t * pNtkNew, Map_Node_t * pNodeMap, int fPhase ) { Abc_Obj_t * pNodeNew, * pNodeInv; // check the case of constant node if ( Map_NodeIsConst(pNodeMap) ) { pNodeNew = fPhase? Abc_NtkCreateNodeConst1(pNtkNew) : Abc_NtkCreateNodeConst0(pNtkNew); if ( pNodeNew->pData == NULL ) printf( "Error creating mapped network: Library does not have a constant %d gate.\n", fPhase ); return pNodeNew; } // check if the phase is already implemented pNodeNew = (Abc_Obj_t *)Map_NodeReadData( pNodeMap, fPhase ); if ( pNodeNew ) return pNodeNew; // implement the node if the best cut is assigned if ( Map_NodeReadCutBest(pNodeMap, fPhase) != NULL ) return Abc_NodeFromMapPhase_rec( pNtkNew, pNodeMap, fPhase ); // if the cut is not assigned, implement the node assert( Map_NodeReadCutBest(pNodeMap, !fPhase) != NULL || Map_NodeIsConst(pNodeMap) ); pNodeNew = Abc_NodeFromMapPhase_rec( pNtkNew, pNodeMap, !fPhase ); // add the inverter pNodeInv = Abc_NtkCreateNode( pNtkNew ); Abc_ObjAddFanin( pNodeInv, pNodeNew ); pNodeInv->pData = Mio_LibraryReadInv((Mio_Library_t *)Abc_FrameReadLibGen()); // set the inverter Map_NodeSetData( pNodeMap, fPhase, (char *)pNodeInv ); return pNodeInv; }
/**Function************************************************************* Synopsis [Command procedure to read LUT libraries.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Mio_CommandPrintProfile( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pOut, * pErr; int fShort = 0; int fSelected = 0; int fVerbose = 0; int c; pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); // set the defaults Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "savh")) != EOF ) { switch (c) { case 's': fShort ^= 1; break; case 'a': fSelected ^= 1; break; case 'v': fVerbose ^= 1; break; case 'h': goto usage; break; default: goto usage; } } if ( Abc_FrameReadLibGen() == NULL ) { printf( "Library is not available.\n" ); return 1; } Mio_LibraryWriteProfile( stdout, (Mio_Library_t *)Abc_FrameReadLibGen() ); return 0; usage: fprintf( pErr, "\nusage: print_profile [-h]\n"); fprintf( pErr, "\t print the current gate profile\n" ); fprintf( pErr, "\t-h : print the command usage\n"); return 1; }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Mio_CommandReadProfile( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pFile, * pOut, * pErr; Mio_Library_t * pLib; char * pFileName; int c; pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); // set the defaults Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "h")) != EOF ) { switch (c) { case 'h': goto usage; break; default: goto usage; } } if ( argc != globalUtilOptind + 1 ) { goto usage; } pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); if ( pLib == NULL ) { fprintf( pErr, "There is no Genlib library entered.\n" ); return 1; } // get the input file name pFileName = argv[globalUtilOptind]; if ( (pFile = Io_FileOpen( pFileName, "open_path", "r", 0 )) == NULL ) { fprintf( pErr, "Cannot open input file \"%s\". ", pFileName ); if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".profile", NULL, NULL, NULL, NULL )) ) fprintf( pErr, "Did you mean \"%s\"?", pFileName ); fprintf( pErr, "\n" ); return 1; } // set the new network Mio_LibraryReadProfile( pFile, pLib ); fclose( pFile ); return 0; usage: fprintf( pErr, "usage: read_profile [-h] <file>\n"); fprintf( pErr, "\t read a gate profile from a profile file\n" ); fprintf( pErr, "\t-h : enable verbose output\n"); fprintf( pErr, "\t<file> : file name to read the profile\n"); return 1; }
/**Function************************************************************* Synopsis [Command procedure to read LUT libraries.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Mio_CommandPrintLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pOut, * pErr; Abc_Ntk_t * pNet; int fVerbose; int c; pNet = Abc_FrameReadNtk(pAbc); pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); // set the defaults fVerbose = 1; Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF ) { switch (c) { case 'v': fVerbose ^= 1; break; case 'h': goto usage; break; default: goto usage; } } if ( argc != globalUtilOptind ) { goto usage; } // set the new network Mio_WriteLibrary( stdout, Abc_FrameReadLibGen(), 0 ); return 0; usage: fprintf( pErr, "\nusage: print_library [-vh]\n"); fprintf( pErr, "\t print the current genlib library\n" ); fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") ); fprintf( pErr, "\t-h : print the command usage\n"); return 1; /* error exit */ }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Mio_UpdateGenlib( Mio_Library_t * pLib ) { // free the current superlib because it depends on the old Mio library if ( Abc_FrameReadLibSuper() ) { Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() ); Abc_FrameSetLibSuper( NULL ); } // replace the current library Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() ); Abc_FrameSetLibGen( pLib ); // replace the current library Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() ); Abc_FrameSetLibGen2( NULL ); }
/**Function************************************************************* Synopsis [Creates the mapped network.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Obj_t * Abc_NodeFromMapSuper_rec( Abc_Ntk_t * pNtkNew, Map_Node_t * pNodeMap, Map_Super_t * pSuper, Abc_Obj_t * pNodePis[], int nNodePis ) { Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); Mio_Gate_t * pRoot; Map_Super_t ** ppFanins; Abc_Obj_t * pNodeNew, * pNodeFanin; int nFanins, Number, i; // get the parameters of the supergate pRoot = Map_SuperReadRoot(pSuper); if ( pRoot == NULL ) { Number = Map_SuperReadNum(pSuper); if ( Number < nNodePis ) { return pNodePis[Number]; } else { // assert( 0 ); /* It might happen that a super gate with 5 inputs is constructed that * actually depends only on the first four variables; i.e the fifth is a * don't care -- in that case we connect constant node for the fifth * (since the cut only has 4 variables). An interesting question is what * if the first variable (and not the fifth one is the redundant one; * can that happen?) */ return Abc_NtkCreateNodeConst0(pNtkNew); } } pRoot = Mio_LibraryReadGateByName( pLib, Mio_GateReadName(pRoot), NULL ); // get information about the fanins of the supergate nFanins = Map_SuperReadFaninNum( pSuper ); ppFanins = Map_SuperReadFanins( pSuper ); // create a new node with these fanins pNodeNew = Abc_NtkCreateNode( pNtkNew ); for ( i = 0; i < nFanins; i++ ) { pNodeFanin = Abc_NodeFromMapSuper_rec( pNtkNew, pNodeMap, ppFanins[i], pNodePis, nNodePis ); Abc_ObjAddFanin( pNodeNew, pNodeFanin ); } pNodeNew->pData = pRoot; return pNodeNew; }
/**Function************************************************************* Synopsis [This procedure transforms tech-ind Ptr into mapped Ptr.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Cba_PtrUpdateBox( Vec_Ptr_t * vBox, Vec_Ptr_t * vGatesNames ) { Mio_Gate_t * pGate; Mio_Pin_t * pPin; int i = 1; Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen( Abc_FrameGetGlobalFrame() ); // update gate name char * pNameNew, * pName = (char *)Vec_PtrEntry(vBox, 0); if ( !strcmp(pName, "Const0T") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_C0); else if ( !strcmp(pName, "Const1T") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_C1); else if ( !strcmp(pName, "BufT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_BUF); else if ( !strcmp(pName, "InvT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_INV); else if ( !strcmp(pName, "AndT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_AND); else if ( !strcmp(pName, "NandT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_NAND); else if ( !strcmp(pName, "OrT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_OR); else if ( !strcmp(pName, "NorT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_NOR); else if ( !strcmp(pName, "XorT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_XOR); else if ( !strcmp(pName, "XnorT") ) pNameNew = (char *)Vec_PtrEntry(vGatesNames, PTR_GATE_XNOR); else // user hierarchy return; ABC_FREE( pName ); Vec_PtrWriteEntry( vBox, 0, Abc_UtilStrsav(pNameNew) ); // remove instance name pName = (char *)Vec_PtrEntry(vBox, 1); ABC_FREE( pName ); Vec_PtrWriteEntry( vBox, 1, NULL ); // update formal input names pGate = Mio_LibraryReadGateByName( pLib, pNameNew, NULL ); Mio_GateForEachPin( pGate, pPin ) { pName = (char *)Vec_PtrEntry( vBox, 2 * i ); ABC_FREE( pName ); pNameNew = Mio_PinReadName(pPin); Vec_PtrWriteEntry( vBox, 2 * i++, Abc_UtilStrsav(pNameNew) ); }
/**Function************************************************************* Synopsis [Deallocates the supergate library.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Map_SuperLibFree( Map_SuperLib_t * p ) { if ( p == NULL ) return; if ( p->pGenlib ) { assert( p->pGenlib == Abc_FrameReadLibGen() ); Mio_LibraryDelete( p->pGenlib ); Abc_FrameSetLibGen( NULL ); } if ( p->tTableC ) Map_SuperTableFree( p->tTableC ); if ( p->tTable ) Map_SuperTableFree( p->tTable ); Extra_MmFixedStop( p->mmSupers ); Extra_MmFixedStop( p->mmEntries ); Extra_MmFlexStop( p->mmForms ); ABC_FREE( p->ppSupers ); ABC_FREE( p ); }
/**Function************************************************************* Synopsis [Creates a new Ntk.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Abc_NtkAlloc( Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan ) { Abc_Ntk_t * pNtk; pNtk = ALLOC( Abc_Ntk_t, 1 ); memset( pNtk, 0, sizeof(Abc_Ntk_t) ); pNtk->ntkType = Type; pNtk->ntkFunc = Func; // start the object storage pNtk->vObjs = Vec_PtrAlloc( 100 ); pNtk->vAsserts = Vec_PtrAlloc( 100 ); pNtk->vPios = Vec_PtrAlloc( 100 ); pNtk->vPis = Vec_PtrAlloc( 100 ); pNtk->vPos = Vec_PtrAlloc( 100 ); pNtk->vCis = Vec_PtrAlloc( 100 ); pNtk->vCos = Vec_PtrAlloc( 100 ); pNtk->vBoxes = Vec_PtrAlloc( 100 ); // start the memory managers pNtk->pMmObj = fUseMemMan? Extra_MmFixedStart( sizeof(Abc_Obj_t) ) : NULL; pNtk->pMmStep = fUseMemMan? Extra_MmStepStart( ABC_NUM_STEPS ) : NULL; // get ready to assign the first Obj ID pNtk->nTravIds = 1; // start the functionality manager if ( Abc_NtkIsStrash(pNtk) ) pNtk->pManFunc = Abc_AigAlloc( pNtk ); else if ( Abc_NtkHasSop(pNtk) || Abc_NtkHasBlifMv(pNtk) ) pNtk->pManFunc = Extra_MmFlexStart(); else if ( Abc_NtkHasBdd(pNtk) ) pNtk->pManFunc = Cudd_Init( 20, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 ); else if ( Abc_NtkHasAig(pNtk) ) pNtk->pManFunc = Hop_ManStart(); else if ( Abc_NtkHasMapping(pNtk) ) pNtk->pManFunc = Abc_FrameReadLibGen(); else if ( !Abc_NtkHasBlackbox(pNtk) ) assert( 0 ); // name manager pNtk->pManName = Nm_ManCreate( 200 ); // attribute manager pNtk->vAttrs = Vec_PtrStart( VEC_ATTR_TOTAL_NUM ); return pNtk; }
ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Psr_ManIsMapped( Psr_Ntk_t * pNtk ) { Vec_Int_t * vSigs; int iBox; Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); if ( pLib == NULL ) return 0; Psr_NtkForEachBox( pNtk, vSigs, iBox ) if ( !Psr_BoxIsNode(pNtk, iBox) ) { int NtkId = Psr_BoxNtk( pNtk, iBox ); if ( Mio_LibraryReadGateByName(pLib, Psr_NtkStr(pNtk, NtkId), NULL) ) return 1; } return 0; }
/**Function************************************************************* Synopsis [Command procedure to read LUT libraries.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Mio_CommandWriteGenlib( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pOut, * pErr, * pFile; char * pFileName; int fSelected = 0; int fVerbose = 0; int c; pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "vah")) != EOF ) { switch (c) { case 'v': fVerbose ^= 1; break; case 'a': fSelected ^= 1; break; case 'h': goto usage; break; default: goto usage; } } if ( Abc_FrameReadLibGen() == NULL ) { printf( "Library is not available.\n" ); return 1; } if ( argc != globalUtilOptind + 1 ) { printf( "The file name is not given.\n" ); return 1; } pFileName = argv[globalUtilOptind]; pFile = fopen( pFileName, "w" ); if ( pFile == NULL ) { printf( "Error! Cannot open file \"%s\" for writing the library.\n", pFileName ); return 1; } Mio_WriteLibrary( pFile, (Mio_Library_t *)Abc_FrameReadLibGen(), 0, 0, fSelected ); fclose( pFile ); printf( "The current genlib library is written into file \"%s\".\n", pFileName ); return 0; usage: fprintf( pErr, "\nusage: write_genlib [-vah] <file>\n"); fprintf( pErr, "\t writes the current genlib library into a file\n" ); fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", fVerbose? "yes" : "no" ); fprintf( pErr, "\t-a : toggles writing min-area gates [default = %s]\n", fSelected? "yes" : "no" ); fprintf( pErr, "\t-h : print the command usage\n"); fprintf( pErr, "\t<file> : optional file name to write the library\n"); return 1; }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Mio_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pFile; FILE * pOut, * pErr; Mio_Library_t * pLib; Abc_Ntk_t * pNet; char * FileName; int fVerbose; int c; pNet = Abc_FrameReadNtk(pAbc); pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); // set the defaults fVerbose = 1; Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "vh")) != EOF ) { switch (c) { case 'v': fVerbose ^= 1; break; case 'h': goto usage; break; default: goto usage; } } if ( argc != globalUtilOptind + 1 ) { goto usage; } // get the input file name FileName = argv[globalUtilOptind]; if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL ) { fprintf( pErr, "Cannot open input file \"%s\". ", FileName ); if ( (FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) ) fprintf( pErr, "Did you mean \"%s\"?", FileName ); fprintf( pErr, "\n" ); return 1; } fclose( pFile ); // set the new network pLib = Mio_LibraryRead( pAbc, FileName, 0, fVerbose ); if ( pLib == NULL ) { fprintf( pErr, "Reading GENLIB library has failed.\n" ); return 1; } // free the current superlib because it depends on the old Mio library if ( Abc_FrameReadLibSuper() ) { extern void Map_SuperLibFree( Map_SuperLib_t * p ); // Map_SuperLibFree( s_pSuperLib ); // s_pSuperLib = NULL; Map_SuperLibFree( Abc_FrameReadLibSuper() ); Abc_FrameSetLibSuper( NULL ); } // replace the current library // Mio_LibraryDelete( s_pLib ); // s_pLib = pLib; Mio_LibraryDelete( Abc_FrameReadLibGen() ); Abc_FrameSetLibGen( pLib ); return 0; usage: fprintf( pErr, "usage: read_library [-vh]\n"); fprintf( pErr, "\t read the library from a genlib file\n" ); fprintf( pErr, "\t-h : enable verbose output\n"); return 1; /* error exit */ }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Mio_End( Abc_Frame_t * pAbc ) { Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() ); Amap_LibFree( (Amap_Lib_t *)Abc_FrameReadLibGen2() ); }
/**Function************************************************************* Synopsis [Interface with the mapping package.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, double DelayMulti, float LogFan, float Slew, float Gain, int nGatesMin, int fRecovery, int fSwitching, int fSkipFanout, int fVerbose ) { static int fUseMulti = 0; int fShowSwitching = 1; Abc_Ntk_t * pNtkNew; Map_Man_t * pMan; Vec_Int_t * vSwitching = NULL; float * pSwitching = NULL; abctime clk, clkTotal = Abc_Clock(); Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen(); assert( Abc_NtkIsStrash(pNtk) ); // derive library from SCL // if the library is created here, it will be deleted when pSuperLib is deleted in Map_SuperLibFree() if ( Abc_FrameReadLibScl() && Abc_SclHasDelayInfo( Abc_FrameReadLibScl() ) ) { pLib = Abc_SclDeriveGenlib( Abc_FrameReadLibScl(), Slew, Gain, nGatesMin, fVerbose ); if ( Abc_FrameReadLibGen() ) Mio_LibraryTransferDelays( (Mio_Library_t *)Abc_FrameReadLibGen(), pLib ); // remove supergate library Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() ); Abc_FrameSetLibSuper( NULL ); } // quit if there is no library if ( pLib == NULL ) { printf( "The current library is not available.\n" ); return 0; } if ( AreaMulti != 0.0 ) fUseMulti = 1, printf( "The cell areas are multiplied by the factor: <num_fanins> ^ (%.2f).\n", AreaMulti ); if ( DelayMulti != 0.0 ) fUseMulti = 1, printf( "The cell delays are multiplied by the factor: <num_fanins> ^ (%.2f).\n", DelayMulti ); // penalize large gates by increasing their area if ( AreaMulti != 0.0 ) Mio_LibraryMultiArea( pLib, AreaMulti ); if ( DelayMulti != 0.0 ) Mio_LibraryMultiDelay( pLib, DelayMulti ); // derive the supergate library if ( fUseMulti || Abc_FrameReadLibSuper() == NULL ) { if ( fVerbose ) printf( "Converting \"%s\" into supergate library \"%s\".\n", Mio_LibraryReadName(pLib), Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super") ); // compute supergate library to be used for mapping Map_SuperLibDeriveFromGenlib( pLib, fVerbose ); } // return the library to normal if ( AreaMulti != 0.0 ) Mio_LibraryMultiArea( (Mio_Library_t *)Abc_FrameReadLibGen(), -AreaMulti ); if ( DelayMulti != 0.0 ) Mio_LibraryMultiDelay( (Mio_Library_t *)Abc_FrameReadLibGen(), -DelayMulti ); // print a warning about choice nodes if ( fVerbose && Abc_NtkGetChoiceNum( pNtk ) ) printf( "Performing mapping with choices.\n" ); // compute switching activity fShowSwitching |= fSwitching; if ( fShowSwitching ) { extern Vec_Int_t * Sim_NtkComputeSwitching( Abc_Ntk_t * pNtk, int nPatterns ); vSwitching = Sim_NtkComputeSwitching( pNtk, 4096 ); pSwitching = (float *)vSwitching->pArray; } // perform the mapping pMan = Abc_NtkToMap( pNtk, DelayTarget, fRecovery, pSwitching, fVerbose ); if ( pSwitching ) Vec_IntFree( vSwitching ); if ( pMan == NULL ) return NULL; clk = Abc_Clock(); Map_ManSetSwitching( pMan, fSwitching ); Map_ManSetSkipFanout( pMan, fSkipFanout ); if ( LogFan != 0 ) Map_ManCreateNodeDelays( pMan, LogFan ); if ( !Map_Mapping( pMan ) ) { Map_ManFree( pMan ); return NULL; } // Map_ManPrintStatsToFile( pNtk->pSpec, Map_ManReadAreaFinal(pMan), Map_ManReadRequiredGlo(pMan), Abc_Clock()-clk ); // reconstruct the network after mapping pNtkNew = Abc_NtkFromMap( pMan, pNtk ); Map_ManFree( pMan ); if ( pNtkNew == NULL ) return NULL; if ( pNtk->pExdc ) pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc ); if ( fVerbose ) { ABC_PRT( "Total runtime", Abc_Clock() - clkTotal ); } // make sure that everything is okay if ( !Abc_NtkCheck( pNtkNew ) ) { printf( "Abc_NtkMap: The network check has failed.\n" ); Abc_NtkDelete( pNtkNew ); return NULL; } return pNtkNew; }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Map_CommandReadLibrary( Abc_Frame_t * pAbc, int argc, char **argv ) { FILE * pFile; FILE * pOut, * pErr; Map_SuperLib_t * pLib; Abc_Ntk_t * pNet; char * FileName, * ExcludeFile; int fVerbose; int fAlgorithm; int c; pNet = Abc_FrameReadNtk(pAbc); pOut = Abc_FrameReadOut(pAbc); pErr = Abc_FrameReadErr(pAbc); // set the defaults fVerbose = 1; fAlgorithm = 1; ExcludeFile = 0; Extra_UtilGetoptReset(); while ( (c = Extra_UtilGetopt(argc, argv, "eovh")) != EOF ) { switch (c) { case 'e': ExcludeFile = argv[globalUtilOptind]; if ( ExcludeFile == 0 ) goto usage; globalUtilOptind++; break; case 'o': fAlgorithm ^= 1; break; case 'v': fVerbose ^= 1; break; case 'h': goto usage; break; default: goto usage; } } if ( argc != globalUtilOptind + 1 ) { goto usage; } // get the input file name FileName = argv[globalUtilOptind]; if ( (pFile = Io_FileOpen( FileName, "open_path", "r", 0 )) == NULL ) // if ( (pFile = fopen( FileName, "r" )) == NULL ) { fprintf( pErr, "Cannot open input file \"%s\". ", FileName ); if (( FileName = Extra_FileGetSimilarName( FileName, ".genlib", ".lib", ".gen", ".g", NULL )) ) fprintf( pErr, "Did you mean \"%s\"?", FileName ); fprintf( pErr, "\n" ); return 1; } fclose( pFile ); // set the new network pLib = Map_SuperLibCreate( FileName, ExcludeFile, fAlgorithm, fVerbose ); if ( pLib == NULL ) { fprintf( pErr, "Reading supergate library has failed.\n" ); goto usage; } // replace the current library // Map_SuperLibFree( s_pSuperLib ); // s_pSuperLib = pLib; Map_SuperLibFree( (Map_SuperLib_t *)Abc_FrameReadLibSuper() ); Abc_FrameSetLibSuper( pLib ); // replace the current genlib library // if ( s_pLib ) Mio_LibraryDelete( s_pLib ); // s_pLib = s_pSuperLib->pGenlib; Mio_LibraryDelete( (Mio_Library_t *)Abc_FrameReadLibGen() ); Abc_FrameSetLibGen( (Mio_Library_t *)pLib->pGenlib ); return 0; usage: fprintf( pErr, "\nusage: read_super [-ovh]\n"); fprintf( pErr, "\t read the supergate library from the file\n" ); fprintf( pErr, "\t-e file : file contains list of genlib gates to exclude\n" ); fprintf( pErr, "\t-o : toggles the use of old file format [default = %s]\n", (fAlgorithm? "new" : "old") ); fprintf( pErr, "\t-v : toggles enabling of verbose output [default = %s]\n", (fVerbose? "yes" : "no") ); fprintf( pErr, "\t-h : print the command usage\n"); return 1; /* error exit */ }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Mio_End() { // Mio_LibraryDelete( s_pLib ); Mio_LibraryDelete( Abc_FrameReadLibGen() ); }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Io_ReadBlifNetworkGate( Io_ReadBlif_t * p, Vec_Ptr_t * vTokens ) { Mio_Library_t * pGenlib; Mio_Gate_t * pGate; Abc_Obj_t * pNode; char ** ppNames; int i, nNames; // check that the library is available pGenlib = (Mio_Library_t *)Abc_FrameReadLibGen(); if ( pGenlib == NULL ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "The current library is not available." ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // create a new node and add it to the network if ( vTokens->nSize < 2 ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "The .gate line has less than two tokens." ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // get the gate pGate = Mio_LibraryReadGateByName( pGenlib, (char *)vTokens->pArray[1] ); if ( pGate == NULL ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "Cannot find gate \"%s\" in the library.", (char*)vTokens->pArray[1] ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // if this is the first line with gate, update the network type if ( Abc_NtkNodeNum(p->pNtkCur) == 0 ) { assert( p->pNtkCur->ntkFunc == ABC_FUNC_SOP ); p->pNtkCur->ntkFunc = ABC_FUNC_MAP; Mem_FlexStop( (Mem_Flex_t *)p->pNtkCur->pManFunc, 0 ); p->pNtkCur->pManFunc = pGenlib; } // reorder the formal inputs to be in the same order as in the gate if ( !Io_ReadBlifReorderFormalNames( vTokens, pGate ) ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "Mismatch in the fanins of gate \"%s\".", (char*)vTokens->pArray[1] ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // remove the formal parameter names for ( i = 2; i < vTokens->nSize; i++ ) { vTokens->pArray[i] = Io_ReadBlifCleanName( (char *)vTokens->pArray[i] ); if ( vTokens->pArray[i] == NULL ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "Invalid gate input assignment." ); Io_ReadBlifPrintErrorMessage( p ); return 1; } } // create the node ppNames = (char **)vTokens->pArray + 2; nNames = vTokens->nSize - 3; pNode = Io_ReadCreateNode( p->pNtkCur, ppNames[nNames], ppNames, nNames ); // set the pointer to the functionality of the node Abc_ObjSetData( pNode, pGate ); return 0; }
/**Function************************************************************* Synopsis [Checks the integrity of the network.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Abc_NtkDoCheck( Abc_Ntk_t * pNtk ) { Abc_Obj_t * pObj, * pNet, * pNode; int i; // check network types if ( !Abc_NtkIsNetlist(pNtk) && !Abc_NtkIsLogic(pNtk) && !Abc_NtkIsStrash(pNtk) ) { fprintf( stdout, "NetworkCheck: Unknown network type.\n" ); return 0; } if ( !Abc_NtkHasSop(pNtk) && !Abc_NtkHasBdd(pNtk) && !Abc_NtkHasAig(pNtk) && !Abc_NtkHasMapping(pNtk) && !Abc_NtkHasBlifMv(pNtk) && !Abc_NtkHasBlackbox(pNtk) ) { fprintf( stdout, "NetworkCheck: Unknown functionality type.\n" ); return 0; } if ( Abc_NtkHasMapping(pNtk) ) { if ( pNtk->pManFunc != Abc_FrameReadLibGen() ) { fprintf( stdout, "NetworkCheck: The library of the mapped network is not the global library.\n" ); return 0; } } if ( Abc_NtkHasOnlyLatchBoxes(pNtk) ) { // check CI/CO numbers if ( Abc_NtkPiNum(pNtk) + Abc_NtkLatchNum(pNtk) != Abc_NtkCiNum(pNtk) ) { fprintf( stdout, "NetworkCheck: Number of CIs does not match number of PIs and latches.\n" ); fprintf( stdout, "One possible reason is that latches are added twice:\n" ); fprintf( stdout, "in procedure Abc_NtkCreateObj() and in the user's code.\n" ); return 0; } if ( Abc_NtkPoNum(pNtk) + Abc_NtkLatchNum(pNtk) != Abc_NtkCoNum(pNtk) ) { fprintf( stdout, "NetworkCheck: Number of COs does not match number of POs, asserts, and latches.\n" ); fprintf( stdout, "One possible reason is that latches are added twice:\n" ); fprintf( stdout, "in procedure Abc_NtkCreateObj() and in the user's code.\n" ); return 0; } } // check the names if ( !Abc_NtkCheckNames( pNtk ) ) return 0; // check PIs and POs Abc_NtkCleanCopy( pNtk ); if ( !Abc_NtkCheckPis( pNtk ) ) return 0; if ( !Abc_NtkCheckPos( pNtk ) ) return 0; if ( Abc_NtkHasBlackbox(pNtk) ) return 1; // check the connectivity of objects Abc_NtkForEachObj( pNtk, pObj, i ) if ( !Abc_NtkCheckObj( pNtk, pObj ) ) return 0; // if it is a netlist change nets and latches if ( Abc_NtkIsNetlist(pNtk) ) { if ( Abc_NtkNetNum(pNtk) == 0 ) fprintf( stdout, "NetworkCheck: Warning! Netlist has no nets.\n" ); // check the nets Abc_NtkForEachNet( pNtk, pNet, i ) if ( !Abc_NtkCheckNet( pNtk, pNet ) ) return 0; } else { if ( Abc_NtkNetNum(pNtk) != 0 )