/**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 ); }