/**Function************************************************************* Synopsis [Used for automated debugging.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Abc_NtkRetimeDebug( Abc_Ntk_t * pNtk ) { extern int Abc_NtkSecFraig( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int nFrames, int fVerbose ); Abc_Ntk_t * pNtkRet; assert( Abc_NtkIsLogic(pNtk) ); Abc_NtkToSop( pNtk, 0 ); // if ( !Abc_NtkCheck( pNtk ) ) // fprintf( stdout, "Abc_NtkRetimeDebug(): Network check has failed.\n" ); // Io_WriteBlifLogic( pNtk, "debug_temp.blif", 1 ); pNtkRet = Abc_NtkDup( pNtk ); Abc_NtkRetime( pNtkRet, 3, 0, 1, 0, 0 ); // debugging backward flow return !Abc_NtkSecFraig( pNtk, pNtkRet, 10000, 3, 0 ); }
/**Function************************************************************* Synopsis [Visualizes AIG with choices.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Abc_NtkShow( Abc_Ntk_t * pNtk, int fGateNames, int fSeq, int fUseReverse ) { FILE * pFile; Abc_Obj_t * pNode; Vec_Ptr_t * vNodes; char FileNameDot[200]; int i; assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsLogic(pNtk) ); if ( Abc_NtkIsStrash(pNtk) && Abc_NtkGetChoiceNum(pNtk) ) { printf( "Temporarily visualization of AIGs with choice nodes is disabled.\n" ); return; } // convert to logic SOP if ( Abc_NtkIsLogic(pNtk) ) Abc_NtkToSop( pNtk, 0 ); // create the file name Abc_ShowGetFileName( pNtk->pName, FileNameDot ); // check that the file can be opened if ( (pFile = fopen( FileNameDot, "w" )) == NULL ) { fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot ); return; } fclose( pFile ); // collect all nodes in the network vNodes = Vec_PtrAlloc( 100 ); Abc_NtkForEachObj( pNtk, pNode, i ) Vec_PtrPush( vNodes, pNode ); // write the DOT file if ( fSeq ) Io_WriteDotSeq( pNtk, vNodes, NULL, FileNameDot, fGateNames, fUseReverse ); else Io_WriteDotNtk( pNtk, vNodes, NULL, FileNameDot, fGateNames, fUseReverse ); Vec_PtrFree( vNodes ); // visualize the file Abc_ShowFile( FileNameDot ); }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Ntk_t * Io_ReadBenchNetwork( Extra_FileReader_t * p ) { ProgressBar * pProgress; Vec_Ptr_t * vTokens; Abc_Ntk_t * pNtk; Abc_Obj_t * pNode, * pNet; Vec_Str_t * vString; unsigned uTruth[8]; char * pType, ** ppNames, * pString; int iLine, nNames, nDigits, fLutsPresent = 0; // allocate the empty network pNtk = Abc_NtkStartRead( Extra_FileReaderGetFileName(p) ); // go through the lines of the file vString = Vec_StrAlloc( 100 ); pProgress = Extra_ProgressBarStart( stdout, Extra_FileReaderGetFileSize(p) ); for ( iLine = 0; (vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p)); iLine++ ) { Extra_ProgressBarUpdate( pProgress, Extra_FileReaderGetCurPosition(p), NULL ); if ( vTokens->nSize == 1 ) { printf( "%s: Wrong input file format.\n", Extra_FileReaderGetFileName(p) ); Vec_StrFree( vString ); Abc_NtkDelete( pNtk ); return NULL; } // get the type of the line if ( strncmp( (char *)vTokens->pArray[0], "INPUT", 5 ) == 0 ) Io_ReadCreatePi( pNtk, (char *)vTokens->pArray[1] ); else if ( strncmp( (char *)vTokens->pArray[0], "OUTPUT", 5 ) == 0 ) Io_ReadCreatePo( pNtk, (char *)vTokens->pArray[1] ); else { // get the node name and the node type pType = (char *)vTokens->pArray[1]; if ( strncmp(pType, "DFF", 3) == 0 ) // works for both DFF and DFFRSE { pNode = Io_ReadCreateLatch( pNtk, (char *)vTokens->pArray[2], (char *)vTokens->pArray[0] ); // Abc_LatchSetInit0( pNode ); if ( pType[3] == '0' ) Abc_LatchSetInit0( pNode ); else if ( pType[3] == '1' ) Abc_LatchSetInit1( pNode ); else Abc_LatchSetInitDc( pNode ); } else if ( strcmp(pType, "LUT") == 0 ) { fLutsPresent = 1; ppNames = (char **)vTokens->pArray + 3; nNames = vTokens->nSize - 3; // check the number of inputs if ( nNames > 8 ) { printf( "%s: Currently cannot read truth tables with more than 8 inputs (%d).\n", Extra_FileReaderGetFileName(p), nNames ); Vec_StrFree( vString ); Abc_NtkDelete( pNtk ); return NULL; } // get the hex string pString = (char *)vTokens->pArray[2]; if ( strncmp( pString, "0x", 2 ) ) { printf( "%s: The LUT signature (%s) does not look like a hexadecimal beginning with \"0x\".\n", Extra_FileReaderGetFileName(p), pString ); Vec_StrFree( vString ); Abc_NtkDelete( pNtk ); return NULL; } pString += 2; // pad the string with zero's if needed nDigits = (1 << nNames) / 4; if ( nDigits == 0 ) nDigits = 1; if ( strlen(pString) < (unsigned)nDigits ) { Vec_StrFill( vString, nDigits - strlen(pString), '0' ); Vec_StrPrintStr( vString, pString ); Vec_StrPush( vString, 0 ); pString = Vec_StrArray( vString ); } // read the hex number from the string if ( !Extra_ReadHexadecimal( uTruth, pString, nNames ) ) { printf( "%s: Reading hexadecimal number (%s) has failed.\n", Extra_FileReaderGetFileName(p), pString ); Vec_StrFree( vString ); Abc_NtkDelete( pNtk ); return NULL; } // check if the node is a constant node if ( Extra_TruthIsConst0(uTruth, nNames) ) { pNode = Io_ReadCreateNode( pNtk, (char *)vTokens->pArray[0], ppNames, 0 ); Abc_ObjSetData( pNode, Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, " 0\n" ) ); } else if ( Extra_TruthIsConst1(uTruth, nNames) ) { pNode = Io_ReadCreateNode( pNtk, (char *)vTokens->pArray[0], ppNames, 0 ); Abc_ObjSetData( pNode, Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, " 1\n" ) ); } else { // create the node pNode = Io_ReadCreateNode( pNtk, (char *)vTokens->pArray[0], ppNames, nNames ); assert( nNames > 0 ); if ( nNames > 1 ) Abc_ObjSetData( pNode, Abc_SopCreateFromTruth((Mem_Flex_t *)pNtk->pManFunc, nNames, uTruth) ); else if ( pString[0] == '2' ) Abc_ObjSetData( pNode, Abc_SopCreateBuf((Mem_Flex_t *)pNtk->pManFunc) ); else if ( pString[0] == '1' ) Abc_ObjSetData( pNode, Abc_SopCreateInv((Mem_Flex_t *)pNtk->pManFunc) ); else { printf( "%s: Reading truth table (%s) of single-input node has failed.\n", Extra_FileReaderGetFileName(p), pString ); Vec_StrFree( vString ); Abc_NtkDelete( pNtk ); return NULL; } } } else { // create a new node and add it to the network ppNames = (char **)vTokens->pArray + 2; nNames = vTokens->nSize - 2; pNode = Io_ReadCreateNode( pNtk, (char *)vTokens->pArray[0], ppNames, nNames ); // assign the cover if ( strcmp(pType, "AND") == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateAnd((Mem_Flex_t *)pNtk->pManFunc, nNames, NULL) ); else if ( strcmp(pType, "OR") == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateOr((Mem_Flex_t *)pNtk->pManFunc, nNames, NULL) ); else if ( strcmp(pType, "NAND") == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateNand((Mem_Flex_t *)pNtk->pManFunc, nNames) ); else if ( strcmp(pType, "NOR") == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateNor((Mem_Flex_t *)pNtk->pManFunc, nNames) ); else if ( strcmp(pType, "XOR") == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateXor((Mem_Flex_t *)pNtk->pManFunc, nNames) ); else if ( strcmp(pType, "NXOR") == 0 || strcmp(pType, "XNOR") == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateNxor((Mem_Flex_t *)pNtk->pManFunc, nNames) ); else if ( strncmp(pType, "BUF", 3) == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateBuf((Mem_Flex_t *)pNtk->pManFunc) ); else if ( strcmp(pType, "NOT") == 0 ) Abc_ObjSetData( pNode, Abc_SopCreateInv((Mem_Flex_t *)pNtk->pManFunc) ); else if ( strncmp(pType, "MUX", 3) == 0 ) // Abc_ObjSetData( pNode, Abc_SopRegister(pNtk->pManFunc, "1-0 1\n-11 1\n") ); Abc_ObjSetData( pNode, Abc_SopRegister((Mem_Flex_t *)pNtk->pManFunc, "0-1 1\n11- 1\n") ); else if ( strncmp(pType, "gnd", 3) == 0 ) Abc_ObjSetData( pNode, Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, " 0\n" ) ); else if ( strncmp(pType, "vdd", 3) == 0 ) Abc_ObjSetData( pNode, Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, " 1\n" ) ); else { printf( "Io_ReadBenchNetwork(): Cannot determine gate type \"%s\" in line %d.\n", pType, Extra_FileReaderGetLineNumber(p, 0) ); Vec_StrFree( vString ); Abc_NtkDelete( pNtk ); return NULL; } } } } Extra_ProgressBarStop( pProgress ); Vec_StrFree( vString ); // check if constant 0 is present if ( (pNet = Abc_NtkFindNet( pNtk, "gnd" )) ) { if ( Abc_ObjFaninNum(pNet) == 0 ) Io_ReadCreateConst( pNtk, "gnd", 0 ); } if ( (pNet = Abc_NtkFindNet( pNtk, "1" )) ) { if ( Abc_ObjFaninNum(pNet) == 0 ) { printf( "Io_ReadBenchNetwork(): Adding constant 0 fanin to non-driven net \"1\".\n" ); Io_ReadCreateConst( pNtk, "1", 0 ); } } // check if constant 1 is present if ( (pNet = Abc_NtkFindNet( pNtk, "vdd" )) ) { if ( Abc_ObjFaninNum(pNet) == 0 ) Io_ReadCreateConst( pNtk, "vdd", 1 ); } if ( (pNet = Abc_NtkFindNet( pNtk, "2" )) ) { if ( Abc_ObjFaninNum(pNet) == 0 ) { printf( "Io_ReadBenchNetwork(): Adding constant 1 fanin to non-driven net \"2\".\n" ); Io_ReadCreateConst( pNtk, "2", 1 ); } } Abc_NtkFinalizeRead( pNtk ); // if LUTs are present, collapse the truth tables into cubes if ( fLutsPresent ) { if ( !Abc_NtkToBdd(pNtk) ) { printf( "Io_ReadBenchNetwork(): Converting to BDD has failed.\n" ); Abc_NtkDelete( pNtk ); return NULL; } if ( !Abc_NtkToSop(pNtk, 0) ) { printf( "Io_ReadBenchNetwork(): Converting to SOP has failed.\n" ); Abc_NtkDelete( pNtk ); return NULL; } } return pNtk; }
/**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 [Write the network into file.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Io_Write( Abc_Ntk_t * pNtk, char * pFileName, Io_FileType_t FileType ) { Abc_Ntk_t * pNtkTemp, * pNtkCopy; // check if the current network is available if ( pNtk == NULL ) { fprintf( stdout, "Empty network.\n" ); return; } // check if the file extension if given if ( FileType == IO_FILE_NONE || FileType == IO_FILE_UNKNOWN ) { fprintf( stdout, "The generic file writer requires a known file extension.\n" ); return; } // write the AIG formats if ( FileType == IO_FILE_AIGER || FileType == IO_FILE_BAF ) { if ( !Abc_NtkIsStrash(pNtk) ) { fprintf( stdout, "Writing this format is only possible for structurally hashed AIGs.\n" ); return; } if ( FileType == IO_FILE_AIGER ) Io_WriteAiger( pNtk, pFileName, 1 ); else // if ( FileType == IO_FILE_BAF ) Io_WriteBaf( pNtk, pFileName ); return; } // write non-netlist types if ( FileType == IO_FILE_CNF ) { Io_WriteCnf( pNtk, pFileName, 0 ); return; } if ( FileType == IO_FILE_DOT ) { Io_WriteDot( pNtk, pFileName ); return; } if ( FileType == IO_FILE_GML ) { Io_WriteGml( pNtk, pFileName ); return; } /* if ( FileType == IO_FILE_BLIFMV ) { Io_WriteBlifMv( pNtk, pFileName ); return; } */ // convert logic network into netlist if ( FileType == IO_FILE_PLA ) { if ( Abc_NtkLevel(pNtk) > 1 ) { fprintf( stdout, "PLA writing is available for collapsed networks.\n" ); return; } if ( Abc_NtkIsComb(pNtk) ) pNtkTemp = Abc_NtkToNetlist( pNtk ); else { fprintf( stdout, "Latches are writen into the PLA file at PI/PO pairs.\n" ); pNtkCopy = Abc_NtkDup( pNtk ); Abc_NtkMakeComb( pNtkCopy ); pNtkTemp = Abc_NtkToNetlist( pNtk ); Abc_NtkDelete( pNtkCopy ); } if ( !Abc_NtkToSop( pNtk, 1 ) ) return; } else if ( FileType == IO_FILE_BENCH ) { if ( !Abc_NtkIsStrash(pNtk) ) { fprintf( stdout, "Writing traditional BENCH is available for AIGs only (use \"write_bench\").\n" ); return; } pNtkTemp = Abc_NtkToNetlistBench( pNtk ); } else pNtkTemp = Abc_NtkToNetlist( pNtk ); if ( pNtkTemp == NULL ) { fprintf( stdout, "Converting to netlist has failed.\n" ); return; } if ( FileType == IO_FILE_BLIF ) { if ( !Abc_NtkHasSop(pNtkTemp) && !Abc_NtkHasMapping(pNtkTemp) ) Abc_NtkToSop( pNtkTemp, 0 ); Io_WriteBlif( pNtkTemp, pFileName, 1 ); } else if ( FileType == IO_FILE_BLIFMV ) { if ( !Abc_NtkConvertToBlifMv( pNtkTemp ) ) return; Io_WriteBlifMv( pNtkTemp, pFileName ); } else if ( FileType == IO_FILE_BENCH ) Io_WriteBench( pNtkTemp, pFileName ); else if ( FileType == IO_FILE_PLA ) Io_WritePla( pNtkTemp, pFileName ); else if ( FileType == IO_FILE_EQN ) { if ( !Abc_NtkHasAig(pNtkTemp) ) Abc_NtkToAig( pNtkTemp ); Io_WriteEqn( pNtkTemp, pFileName ); } else if ( FileType == IO_FILE_VERILOG ) { if ( !Abc_NtkHasAig(pNtkTemp) && !Abc_NtkHasMapping(pNtkTemp) ) Abc_NtkToAig( pNtkTemp ); Io_WriteVerilog( pNtkTemp, pFileName ); } else fprintf( stderr, "Unknown file format.\n" ); Abc_NtkDelete( pNtkTemp ); }