📄 iowrite.c
字号:
/**CFile**************************************************************** FileName [ioWrite.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Various network writing procedures.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: ioWrite.c,v 1.16 2003/05/27 23:14:15 alanmi Exp $]***********************************************************************/#include "ioInt.h"/////////////////////////////////////////////////////////////////////////// DECLARATIONS ///////////////////////////////////////////////////////////////////////////#define IO_WRITE_LINE_LENGTH 78 // the output line lengthstatic void Io_WriteNetworkOne( FILE * pFile, Ntk_Network_t * pNet, int FileType );static void Io_WriteNetworkNodeFanins( FILE * pFile, Ntk_Node_t * pNode );static void Io_WriteNetworkNodeBlif( FILE * pFile, Vm_VarMap_t * pVm, Cvr_Cover_t * pCover );static void Io_WriteNetworkNodeBlifMvs( FILE * pFile, Vm_VarMap_t * pVm, Cvr_Cover_t * pCover );static void Io_WriteNetworkNodeBlifMv( FILE * pFile, Vm_VarMap_t * pVm, Cvr_Cover_t * pCover );static void Io_WriteNetworkNodeBlifCover( FILE * pFile, Vm_VarMap_t * pVm, Mvc_Cover_t * Cover, int Value );static void Io_WriteNetworkNodeBlifMvsCover( FILE * pFile, Vm_VarMap_t * pVm, Mvc_Cover_t * Cover, int Value, int Default, int nOutputValues );static void Io_WriteNetworkNodeBlifMvCover( FILE * pFile, Vm_VarMap_t * pVm, Mvc_Cover_t * Cover, int Value );static void Io_WriteNetworkLatch( FILE * pFile, Ntk_Latch_t * pLatch, int FileType );static void Io_WriteNetworkBuffer( FILE * pFile, Ntk_Node_t * pInput, Ntk_Node_t * pOutput, int FileType );/////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function************************************************************* Synopsis [Write the network into a BLIF file with the given name.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Io_WriteNetwork( Ntk_Network_t * pNet, char * FileName, int FileType ){ Ntk_Network_t * pNetExdc; FILE * pFile; pFile = fopen( FileName, "w" ); if ( pFile == NULL ) { fprintf( Ntk_NetworkReadMvsisOut(pNet), "Io_WriteNetwork(): Cannot open the output file.\n" ); return; } // write the model name fprintf( pFile, ".model %s\n", Ntk_NetworkReadName(pNet) ); // write the spec line name if ( FileType == IO_FILE_BLIF_MV && Ntk_NetworkReadSpec(pNet) ) fprintf( pFile, ".spec %s\n", Ntk_NetworkReadSpec(pNet) ); // write the network Io_WriteNetworkOne( pFile, pNet, FileType ); // write EXDC network if it exists pNetExdc = Ntk_NetworkReadNetExdc( pNet ); if ( pNetExdc ) { fprintf( pFile, "\n" ); fprintf( pFile, ".exdc\n" ); Io_WriteNetworkOne( pFile, pNetExdc, FileType ); } // finalize the file fprintf( pFile, ".end\n" ); fclose( pFile );}/**Function************************************************************* Synopsis [Write one network.] Description [Writes a network composed of PIs, POs, internal nodes, and latches. The following rules are used to print the names of internal nodes: ] SideEffects [] SeeAlso []***********************************************************************/void Io_WriteNetworkOne( FILE * pFile, Ntk_Network_t * pNet, int FileType ){ Ntk_Node_t * pFanout, * pFanin, * pNode; Ntk_Latch_t * pLatch; Ntk_Pin_t * pPin; // write the PIs fprintf( pFile, ".inputs" ); Io_WriteNetworkCis( pFile, pNet, 0 ); fprintf( pFile, "\n" ); // write the POs fprintf( pFile, ".outputs" ); Io_WriteNetworkCos( pFile, pNet, 0 ); fprintf( pFile, "\n" ); // write the .mv lines if ( FileType == IO_FILE_BLIF_MV ) {// fprintf( pFile, "\n" ); Ntk_NetworkForEachCi( pNet, pNode ) if ( Ntk_NodeReadValueNum(pNode) > 2 ) fprintf( pFile, ".mv %s %d\n", Ntk_NodeReadName(pNode), Ntk_NodeReadValueNum(pNode) );// fprintf( pFile, "\n" ); Ntk_NetworkForEachCo( pNet, pNode ) if ( Ntk_NodeReadValueNum(pNode) > 2 ) fprintf( pFile, ".mv %s %d\n", Ntk_NodeReadName(pNode), Ntk_NodeReadValueNum(pNode) ); // write all the .mv directives for the internal nodes on top of the file// fprintf( pFile, "\n" ); Ntk_NetworkForEachNode( pNet, pNode ) { // if an internal node has a single CO fanout, // the name of this node is the same as CO name // and the node's .mv is already written above as the CO's .mv if ( Ntk_NodeHasCoName(pNode) ) continue; // otherwise, write the .mv directive if it is non-binary if ( Ntk_NodeReadValueNum(pNode) > 2 ) fprintf( pFile, ".mv %s %d\n", Ntk_NodeGetNameLong(pNode), Ntk_NodeReadValueNum(pNode) ); } } // write the latches if ( Ntk_NetworkReadLatchNum( pNet ) ) fprintf( pFile, "\n" ); Ntk_NetworkForEachLatch( pNet, pLatch ) Io_WriteNetworkLatch( pFile, pLatch, FileType ); if ( Ntk_NetworkReadLatchNum( pNet ) ) fprintf( pFile, "\n" ); // write each internal node Ntk_NetworkForEachNode( pNet, pNode ) { // write the internal node Io_WriteNetworkNode( pFile, pNode, FileType, 0 ); // if an internal node has only one CO fanout, // the CO name is used for the internal node, and in this way, // the CO is written into the file // however, if an internal node has more than one CO fanout // it is written as an intenal node with its own name // in this case, the COs should be written as MV buffers // driven by the given internal node if ( Ntk_NodeIsCoFanin(pNode) && !Ntk_NodeHasCoName(pNode) ) { Ntk_NodeForEachFanout( pNode, pPin, pFanout ) if ( Ntk_NodeIsCo(pFanout) ) Io_WriteNetworkBuffer( pFile, pNode, pFanout, FileType ); } } // some PO nodes may have a fanin, which is a PI // such PO nodes are written here, because they are not written // in the above loop, which interates through the internal nodes Ntk_NetworkForEachCo( pNet, pNode ) { pFanin = Ntk_NodeReadFaninNode( pNode, 0 ); if ( Ntk_NodeIsCi(pFanin) ) Io_WriteNetworkBuffer( pFile, pFanin, pNode, FileType ); }}/**Function************************************************************* Synopsis [Writes the primary input list in a nice sort of way.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Io_WriteNetworkCis( FILE * pFile, Ntk_Network_t * pNet, bool fWriteAll ){ Ntk_Node_t * pNode; int LineLength; int AddedLength; int NameCounter; LineLength = 7; NameCounter = 0; Ntk_NetworkForEachCi( pNet, pNode ) { if ( !Ntk_NodeBelongsToLatch(pNode) ) { // get the line length after this name is written AddedLength = strlen(Ntk_NodeReadName(pNode)) + 1; if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH ) { // write the line extender fprintf( pFile, " \\\n" ); // reset the line length LineLength = 0; NameCounter = 0; } fprintf( pFile, " %s", Ntk_NodeReadName(pNode) ); LineLength += AddedLength; NameCounter++; } }}/**Function************************************************************* Synopsis [Writes the primary input list in a nice sort of way.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Io_WriteNetworkCisSpecial( FILE * pFile, Ntk_Network_t * pNet ){ Ntk_Node_t * pNode; int LineLength; int AddedLength; int NameCounter; LineLength = 7; NameCounter = 0; Ntk_NetworkForEachNodeSpecial( pNet, pNode ) { if ( Ntk_NodeIsCi(pNode) ) { // get the line length after this name is written AddedLength = strlen(Ntk_NodeReadName(pNode)) + 1; if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH ) { // write the line extender fprintf( pFile, " \\\n" ); // reset the line length LineLength = 0; NameCounter = 0; } fprintf( pFile, " %s", Ntk_NodeReadName(pNode) ); LineLength += AddedLength; NameCounter++; } }}/**Function************************************************************* Synopsis [Writes the primary input list in a nice sort of way.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Io_WriteNetworkCos( FILE * pFile, Ntk_Network_t * pNet, bool fWriteAll ){ Ntk_Node_t * pNode; int LineLength; int AddedLength; int NameCounter; LineLength = 8; NameCounter = 0; Ntk_NetworkForEachCo( pNet, pNode ) { if ( !Ntk_NodeBelongsToLatch(pNode) ) { // get the line length after this name is written AddedLength = strlen(Ntk_NodeReadName(pNode)) + 1; if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH ) { // write the line extender fprintf( pFile, " \\\n" ); // reset the line length LineLength = 0; NameCounter = 0; } fprintf( pFile, " %s", Ntk_NodeReadName(pNode) ); LineLength += AddedLength; NameCounter++; } }}/**Function************************************************************* Synopsis [Write the latch into a file.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Io_WriteNetworkLatch( FILE * pFile, Ntk_Latch_t * pLatch, int FileType ){ Ntk_Node_t * pLatchInput; Ntk_Node_t * pLatchOutput; Ntk_Node_t * pLatchNode; int nValues, Reset; int i; pLatchInput = Ntk_LatchReadInput( pLatch ); pLatchOutput = Ntk_LatchReadOutput( pLatch ); pLatchNode = Ntk_LatchReadNode( pLatch ); nValues = Ntk_NodeReadValueNum(pLatchOutput); Reset = Ntk_LatchReadReset(pLatch); // write the reset line if ( FileType != IO_FILE_BLIF ) { if ( pLatchNode ) { Ntk_NodeSetName( pLatchNode, Ntk_NodeReadName(pLatchOutput) ); Io_WriteNetworkNode( pFile, pLatchNode, FileType, 1 ); Ntk_NodeSetName( pLatchNode, NULL ); } else { // write the latch reset node based on the reset value fprintf( pFile, ".reset %s\n", Ntk_NodeReadName(pLatchOutput) ); if ( FileType == IO_FILE_BLIF_MVS ) { fprintf( pFile, " " ); for ( i = 0; i < nValues; i++ ) if ( i == Reset ) fprintf( pFile, "%d", i % 10 ); else fprintf( pFile, "%c", '-' ); fprintf( pFile, "\n" ); } else fprintf( pFile, "%d\n", Reset ); } } // write the latch line fprintf( pFile, ".latch %s %s", Ntk_NodeReadName(pLatchInput), Ntk_NodeReadName(pLatchOutput) ); // write the reset value if it is BLIF if ( FileType == IO_FILE_BLIF ) fprintf( pFile, " %d", Reset ); fprintf( pFile, "\n" );}/**Function************************************************************* Synopsis [Write the node into a file.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Io_WriteNetworkNode( FILE * pFile, Ntk_Node_t * pNode, int FileType, int fLatch ){ Cvr_Cover_t * pCover; Vm_VarMap_t * pVm; // write the .names line if ( fLatch ) fprintf( pFile, ".reset" ); else if ( FileType == IO_FILE_BLIF_MV ) fprintf( pFile, ".table" ); else fprintf( pFile, ".names" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -