/**Function************************************************************* Synopsis [Read the network from a file.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Io_Read( char * pFileName, Io_FileType_t FileType, int fCheck ) { Abc_Ntk_t * pNtk, * pTemp; // get the netlist pNtk = Io_ReadNetlist( pFileName, FileType, fCheck ); if ( pNtk == NULL ) return NULL; if ( !Abc_NtkIsNetlist(pNtk) ) return pNtk; // flatten logic hierarchy assert( Abc_NtkIsNetlist(pNtk) ); if ( Abc_NtkWhiteboxNum(pNtk) > 0 ) { pNtk = Abc_NtkFlattenLogicHierarchy( pTemp = pNtk ); Abc_NtkDelete( pTemp ); if ( pNtk == NULL ) { fprintf( stdout, "Flattening logic hierarchy has failed.\n" ); return NULL; } } // convert blackboxes if ( Abc_NtkBlackboxNum(pNtk) > 0 ) { printf( "Hierarchy reader converted %d instances of blackboxes.\n", Abc_NtkBlackboxNum(pNtk) ); pNtk = Abc_NtkConvertBlackboxes( pTemp = pNtk ); Abc_NtkDelete( pTemp ); if ( pNtk == NULL ) { fprintf( stdout, "Converting blackboxes has failed.\n" ); return NULL; } } // consider the case of BLIF-MV if ( Io_ReadFileType(pFileName) == IO_FILE_BLIFMV ) { //Abc_NtkPrintStats( stdout, pNtk, 0 ); // Io_WriteBlifMv( pNtk, "_temp_.mv" ); pNtk = Abc_NtkStrashBlifMv( pTemp = pNtk ); Abc_NtkDelete( pTemp ); if ( pNtk == NULL ) { fprintf( stdout, "Converting BLIF-MV to AIG has failed.\n" ); return NULL; } return pNtk; } // convert the netlist into the logic network pNtk = Abc_NtkToLogic( pTemp = pNtk ); Abc_NtkDelete( pTemp ); if ( pNtk == NULL ) { fprintf( stdout, "Converting netlist to logic network after reading has failed.\n" ); return NULL; } return pNtk; }
/**Function************************************************************* Synopsis [Transform the netlist into a logic network.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Abc_NtkToLogic( Abc_Ntk_t * pNtk ) { Abc_Ntk_t * pNtkNew; Abc_Obj_t * pObj, * pFanin; int i, k; // consider the case of the AIG if ( Abc_NtkIsStrash(pNtk) ) return Abc_NtkAigToLogicSop( pNtk ); assert( Abc_NtkIsNetlist(pNtk) ); // consider simple case when there is hierarchy // assert( pNtk->pDesign == NULL ); assert( Abc_NtkWhiteboxNum(pNtk) == 0 ); assert( Abc_NtkBlackboxNum(pNtk) == 0 ); // start the network pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, pNtk->ntkFunc ); // duplicate the nodes Abc_NtkForEachNode( pNtk, pObj, i ) Abc_NtkDupObj(pNtkNew, pObj, 0); // reconnect the internal nodes in the new network Abc_NtkForEachNode( pNtk, pObj, i ) Abc_ObjForEachFanin( pObj, pFanin, k ) Abc_ObjAddFanin( pObj->pCopy, Abc_ObjFanin0(pFanin)->pCopy ); // collect the CO nodes Abc_NtkFinalize( pNtk, pNtkNew ); // fix the problem with CO pointing directly to CIs Abc_NtkLogicMakeSimpleCos( pNtkNew, 0 ); // duplicate EXDC if ( pNtk->pExdc ) pNtkNew->pExdc = Abc_NtkToLogic( pNtk->pExdc ); if ( !Abc_NtkCheck( pNtkNew ) ) fprintf( stdout, "Abc_NtkToLogic(): Network check has failed.\n" ); return pNtkNew; }
/**Function************************************************************* Synopsis [Write the network into a BLIF file with the given name.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Io_WriteBlif( Abc_Ntk_t * pNtk, char * FileName, int fWriteLatches, int fBb2Wb, int fSeq ) { FILE * pFile; Abc_Ntk_t * pNtkTemp; int i; assert( Abc_NtkIsNetlist(pNtk) ); // start writing the file pFile = fopen( FileName, "w" ); if ( pFile == NULL ) { fprintf( stdout, "Io_WriteBlif(): Cannot open the output file.\n" ); return; } fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() ); // write the master network Io_NtkWrite( pFile, pNtk, fWriteLatches, fBb2Wb, fSeq ); // make sure there is no logic hierarchy assert( Abc_NtkWhiteboxNum(pNtk) == 0 ); // write the hierarchy if present if ( Abc_NtkBlackboxNum(pNtk) > 0 ) { Vec_PtrForEachEntry( Abc_Ntk_t *, pNtk->pDesign->vModules, pNtkTemp, i ) { if ( pNtkTemp == pNtk ) continue; fprintf( pFile, "\n\n" ); Io_NtkWrite( pFile, pNtkTemp, fWriteLatches, fBb2Wb, fSeq ); } }
/**Function************************************************************* Synopsis [Strashes the BLIF-MV netlist.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Abc_NtkStrashBlifMv( Abc_Ntk_t * pNtk ) { int fUsePositional = 0; Vec_Ptr_t * vNodes; Abc_Obj_t ** pBits; Abc_Obj_t ** pValues; Abc_Ntk_t * pNtkNew; Abc_Obj_t * pObj, * pTemp, * pBit, * pNet; int i, k, v, nValues, nValuesMax, nBits; int nCount1, nCount2; assert( Abc_NtkIsNetlist(pNtk) ); assert( Abc_NtkHasBlifMv(pNtk) ); assert( Abc_NtkWhiteboxNum(pNtk) == 0 ); assert( Abc_NtkBlackboxNum(pNtk) == 0 ); // get the largest number of values nValuesMax = 2; Abc_NtkForEachNet( pNtk, pObj, i ) { nValues = Abc_ObjMvVarNum(pObj); if ( nValuesMax < nValues ) nValuesMax = nValues; }
/**Function************************************************************* Synopsis [Read the network from a file.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Io_ReadNetlist( char * pFileName, Io_FileType_t FileType, int fCheck ) { FILE * pFile; Abc_Ntk_t * pNtk; if ( FileType == IO_FILE_NONE || FileType == IO_FILE_UNKNOWN ) { fprintf( stdout, "Generic file reader requires a known file extension to open \"%s\".\n", pFileName ); return NULL; } // check if the file exists pFile = fopen( pFileName, "r" ); if ( pFile == NULL ) { fprintf( stdout, "Cannot open input file \"%s\". ", pFileName ); if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".blif", ".bench", ".pla", ".baf", ".aig" )) ) fprintf( stdout, "Did you mean \"%s\"?", pFileName ); fprintf( stdout, "\n" ); return NULL; } fclose( pFile ); // read the AIG if ( FileType == IO_FILE_AIGER || FileType == IO_FILE_BAF || FileType == IO_FILE_BBLIF ) { if ( FileType == IO_FILE_AIGER ) pNtk = Io_ReadAiger( pFileName, fCheck ); else if ( FileType == IO_FILE_BAF ) pNtk = Io_ReadBaf( pFileName, fCheck ); else // if ( FileType == IO_FILE_BBLIF ) pNtk = Io_ReadBblif( pFileName, fCheck ); if ( pNtk == NULL ) { fprintf( stdout, "Reading AIG from file has failed.\n" ); return NULL; } return pNtk; } // read the new netlist if ( FileType == IO_FILE_BLIF ) // pNtk = Io_ReadBlif( pFileName, fCheck ); pNtk = Io_ReadBlifMv( pFileName, 0, fCheck ); else if ( Io_ReadFileType(pFileName) == IO_FILE_BLIFMV ) pNtk = Io_ReadBlifMv( pFileName, 1, fCheck ); else if ( FileType == IO_FILE_BENCH ) pNtk = Io_ReadBench( pFileName, fCheck ); else if ( FileType == IO_FILE_EDIF ) pNtk = Io_ReadEdif( pFileName, fCheck ); else if ( FileType == IO_FILE_EQN ) pNtk = Io_ReadEqn( pFileName, fCheck ); else if ( FileType == IO_FILE_PLA ) pNtk = Io_ReadPla( pFileName, 0, 0, fCheck ); else if ( FileType == IO_FILE_VERILOG ) pNtk = Io_ReadVerilog( pFileName, fCheck ); else { fprintf( stderr, "Unknown file format.\n" ); return NULL; } if ( pNtk == NULL ) { fprintf( stdout, "Reading network from file has failed.\n" ); return NULL; } if ( fCheck && (Abc_NtkBlackboxNum(pNtk) || Abc_NtkWhiteboxNum(pNtk)) ) { int i, fCycle = 0; Abc_Ntk_t * pModel; fprintf( stdout, "Warning: The network contains hierarchy.\n" ); Vec_PtrForEachEntry( Abc_Ntk_t *, pNtk->pDesign->vModules, pModel, i ) if ( !Abc_NtkIsAcyclicWithBoxes( pModel ) ) fCycle = 1; if ( fCycle ) { Abc_NtkDelete( pNtk ); return NULL; } }
/**Function************************************************************* Synopsis [Write the network into file.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Io_WriteHie( Abc_Ntk_t * pNtk, char * pBaseName, char * pFileName ) { Abc_Ntk_t * pNtkTemp, * pNtkResult, * pNtkBase = NULL; // check if the current network is available if ( pNtk == NULL ) { fprintf( stdout, "Empty network.\n" ); return; } // read the base network assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsLogic(pNtk) ); if ( Io_ReadFileType(pBaseName) == IO_FILE_BLIF ) pNtkBase = Io_ReadBlifMv( pBaseName, 0, 1 ); else if ( Io_ReadFileType(pBaseName) == IO_FILE_BLIFMV ) pNtkBase = Io_ReadBlifMv( pBaseName, 1, 1 ); else if ( Io_ReadFileType(pBaseName) == IO_FILE_VERILOG ) pNtkBase = Io_ReadVerilog( pBaseName, 1 ); else fprintf( stderr, "Unknown input file format.\n" ); if ( pNtkBase == NULL ) return; // flatten logic hierarchy if present if ( Abc_NtkWhiteboxNum(pNtkBase) > 0 ) { pNtkBase = Abc_NtkFlattenLogicHierarchy( pNtkTemp = pNtkBase ); if ( pNtkBase == NULL ) return; Abc_NtkDelete( pNtkTemp ); } // reintroduce the boxes into the netlist if ( Io_ReadFileType(pBaseName) == IO_FILE_BLIFMV ) { if ( Abc_NtkBlackboxNum(pNtkBase) > 0 ) { printf( "Hierarchy writer does not support BLIF-MV with blackboxes.\n" ); Abc_NtkDelete( pNtkBase ); return; } // convert the current network to BLIF-MV assert( !Abc_NtkIsNetlist(pNtk) ); pNtkResult = Abc_NtkToNetlist( pNtk ); if ( !Abc_NtkConvertToBlifMv( pNtkResult ) ) return; // reintroduce the network pNtkResult = Abc_NtkInsertBlifMv( pNtkBase, pNtkTemp = pNtkResult ); Abc_NtkDelete( pNtkTemp ); } else if ( Abc_NtkBlackboxNum(pNtkBase) > 0 ) { // derive the netlist pNtkResult = Abc_NtkToNetlist( pNtk ); pNtkResult = Abc_NtkInsertNewLogic( pNtkBase, pNtkTemp = pNtkResult ); Abc_NtkDelete( pNtkTemp ); if ( pNtkResult ) printf( "Hierarchy writer reintroduced %d instances of blackboxes.\n", Abc_NtkBlackboxNum(pNtkBase) ); } else { printf( "Warning: The output network does not contain blackboxes.\n" ); pNtkResult = Abc_NtkToNetlist( pNtk ); } Abc_NtkDelete( pNtkBase ); if ( pNtkResult == NULL ) return; // write the resulting network if ( Io_ReadFileType(pFileName) == IO_FILE_BLIF ) { if ( !Abc_NtkHasSop(pNtkResult) && !Abc_NtkHasMapping(pNtkResult) ) Abc_NtkToSop( pNtkResult, 0 ); Io_WriteBlif( pNtkResult, pFileName, 1 ); } else if ( Io_ReadFileType(pFileName) == IO_FILE_VERILOG ) { if ( !Abc_NtkHasAig(pNtkResult) && !Abc_NtkHasMapping(pNtkResult) ) Abc_NtkToAig( pNtkResult ); Io_WriteVerilog( pNtkResult, pFileName ); } else if ( Io_ReadFileType(pFileName) == IO_FILE_BLIFMV ) { Io_WriteBlifMv( pNtkResult, pFileName ); } else fprintf( stderr, "Unknown output file format.\n" ); Abc_NtkDelete( pNtkResult ); }
/**Function************************************************************* Synopsis [Print the vital stats of the network.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Abc_NtkPrintStats( FILE * pFile, Abc_Ntk_t * pNtk, int fFactored ) { int Num; // if ( Abc_NtkIsStrash(pNtk) ) // Abc_AigCountNext( pNtk->pManFunc ); fprintf( pFile, "%-13s:", pNtk->pName ); if ( Abc_NtkAssertNum(pNtk) ) fprintf( pFile, " i/o/a = %4d/%4d/%4d", Abc_NtkPiNum(pNtk), Abc_NtkPoNum(pNtk), Abc_NtkAssertNum(pNtk) ); else fprintf( pFile, " i/o = %4d/%4d", Abc_NtkPiNum(pNtk), Abc_NtkPoNum(pNtk) ); fprintf( pFile, " lat = %4d", Abc_NtkLatchNum(pNtk) ); if ( Abc_NtkIsNetlist(pNtk) ) { fprintf( pFile, " net = %5d", Abc_NtkNetNum(pNtk) ); fprintf( pFile, " nd = %5d", Abc_NtkNodeNum(pNtk) ); fprintf( pFile, " wbox = %3d", Abc_NtkWhiteboxNum(pNtk) ); fprintf( pFile, " bbox = %3d", Abc_NtkBlackboxNum(pNtk) ); } else if ( Abc_NtkIsStrash(pNtk) ) { fprintf( pFile, " and = %5d", Abc_NtkNodeNum(pNtk) ); if ( Num = Abc_NtkGetChoiceNum(pNtk) ) fprintf( pFile, " (choice = %d)", Num ); if ( Num = Abc_NtkGetExorNum(pNtk) ) fprintf( pFile, " (exor = %d)", Num ); // if ( Num2 = Abc_NtkGetMuxNum(pNtk) ) // fprintf( pFile, " (mux = %d)", Num2-Num ); // if ( Num2 ) // fprintf( pFile, " (other = %d)", Abc_NtkNodeNum(pNtk)-3*Num2 ); } else { fprintf( pFile, " nd = %5d", Abc_NtkNodeNum(pNtk) ); fprintf( pFile, " net = %5d", Abc_NtkGetTotalFanins(pNtk) ); } if ( Abc_NtkIsStrash(pNtk) || Abc_NtkIsNetlist(pNtk) ) { } else if ( Abc_NtkHasSop(pNtk) ) { fprintf( pFile, " cube = %5d", Abc_NtkGetCubeNum(pNtk) ); // fprintf( pFile, " lit(sop) = %5d", Abc_NtkGetLitNum(pNtk) ); if ( fFactored ) fprintf( pFile, " lit(fac) = %5d", Abc_NtkGetLitFactNum(pNtk) ); } else if ( Abc_NtkHasAig(pNtk) ) fprintf( pFile, " aig = %5d", Abc_NtkGetAigNodeNum(pNtk) ); else if ( Abc_NtkHasBdd(pNtk) ) fprintf( pFile, " bdd = %5d", Abc_NtkGetBddNodeNum(pNtk) ); else if ( Abc_NtkHasMapping(pNtk) ) { fprintf( pFile, " area = %5.2f", Abc_NtkGetMappedArea(pNtk) ); fprintf( pFile, " delay = %5.2f", Abc_NtkDelayTrace(pNtk) ); } else if ( !Abc_NtkHasBlackbox(pNtk) ) { assert( 0 ); } if ( Abc_NtkIsStrash(pNtk) ) fprintf( pFile, " lev = %3d", Abc_AigLevel(pNtk) ); else fprintf( pFile, " lev = %3d", Abc_NtkLevel(pNtk) ); fprintf( pFile, "\n" ); // Abc_NtkCrossCut( pNtk ); // print the statistic into a file /* { FILE * pTable; pTable = fopen( "iscas/seqmap__stats.txt", "a+" ); fprintf( pTable, "%s ", pNtk->pName ); fprintf( pTable, "%d ", Abc_NtkPiNum(pNtk) ); fprintf( pTable, "%d ", Abc_NtkPoNum(pNtk) ); fprintf( pTable, "%d ", Abc_NtkLatchNum(pNtk) ); fprintf( pTable, "%d ", Abc_NtkNodeNum(pNtk) ); fprintf( pTable, "%d ", Abc_NtkLevel(pNtk) ); fprintf( pTable, "\n" ); fclose( pTable ); } */ /* // print the statistic into a file { FILE * pTable; pTable = fopen( "stats.txt", "a+" ); fprintf( pTable, "%s ", pNtk->pSpec ); fprintf( pTable, "%.0f ", Abc_NtkGetMappedArea(pNtk) ); fprintf( pTable, "%.2f ", Abc_NtkDelayTrace(pNtk) ); fprintf( pTable, "\n" ); fclose( pTable ); } */ /* // print the statistic into a file { FILE * pTable; pTable = fopen( "x/stats_new.txt", "a+" ); fprintf( pTable, "%s ", pNtk->pName ); // fprintf( pTable, "%d ", Abc_NtkPiNum(pNtk) ); // fprintf( pTable, "%d ", Abc_NtkPoNum(pNtk) ); // fprintf( pTable, "%d ", Abc_NtkLevel(pNtk) ); // fprintf( pTable, "%d ", Abc_NtkNodeNum(pNtk) ); // fprintf( pTable, "%d ", Abc_NtkGetTotalFanins(pNtk) ); // fprintf( pTable, "%d ", Abc_NtkLatchNum(pNtk) ); // fprintf( pTable, "%.2f ", (float)(s_MappingMem)/(float)(1<<20) ); fprintf( pTable, "%.2f", (float)(s_MappingTime)/(float)(CLOCKS_PER_SEC) ); // fprintf( pTable, "%.2f", (float)(s_ResynTime)/(float)(CLOCKS_PER_SEC) ); fprintf( pTable, "\n" ); fclose( pTable ); s_ResynTime = 0; } */ /* // print the statistic into a file { static int Counter = 0; extern int timeRetime; FILE * pTable; Counter++; pTable = fopen( "a/ret__stats.txt", "a+" ); fprintf( pTable, "%s ", pNtk->pName ); fprintf( pTable, "%d ", Abc_NtkNodeNum(pNtk) ); fprintf( pTable, "%d ", Abc_NtkLatchNum(pNtk) ); fprintf( pTable, "%d ", Abc_NtkLevel(pNtk) ); fprintf( pTable, "%.2f ", (float)(timeRetime)/(float)(CLOCKS_PER_SEC) ); if ( Counter % 4 == 0 ) fprintf( pTable, "\n" ); fclose( pTable ); } */ /* // print the statistic into a file { static int Counter = 0; extern int timeRetime; FILE * pTable; Counter++; pTable = fopen( "d/stats.txt", "a+" ); fprintf( pTable, "%s ", pNtk->pName ); // fprintf( pTable, "%d ", Abc_NtkPiNum(pNtk) ); // fprintf( pTable, "%d ", Abc_NtkPoNum(pNtk) ); // fprintf( pTable, "%d ", Abc_NtkLatchNum(pNtk) ); fprintf( pTable, "%d ", Abc_NtkNodeNum(pNtk) ); fprintf( pTable, "%.2f ", (float)(timeRetime)/(float)(CLOCKS_PER_SEC) ); fprintf( pTable, "\n" ); fclose( pTable ); } */ /* s_TotalNodes += Abc_NtkNodeNum(pNtk); printf( "Total nodes = %6d %6.2f Mb Changes = %6d.\n", s_TotalNodes, s_TotalNodes * 20.0 / (1<<20), s_TotalChanges ); */ }