📄 ntkutils.c
字号:
/**CFile**************************************************************** FileName [ntkUtils.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Various network manipulation utilities.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: ntkUtils.c,v 1.36 2003/05/27 23:14:27 alanmi Exp $]***********************************************************************/#include "ntkInt.h"/////////////////////////////////////////////////////////////////////////// DECLARATIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function************************************************************* Synopsis [Create a new network.] Description [If the relation manager is not NULL, the same manager is used. Otherwise, a new manager is created.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Network_t * Ntk_NetworkAlloc( Mv_Frame_t * pMvsis ){ Ntk_Network_t * pNet; pNet = ALLOC( Ntk_Network_t, 1 ); memset( pNet, 0, sizeof(Ntk_Network_t) ); // set affiliation of this network pNet->pMvsis = pMvsis; // start the hash table pNet->tName2Node = st_init_table(strcmp, st_strhash); // get the relation manager pNet->pMan = Mv_FrameReadMan(pMvsis); // start the memory managers pNet->pManNode = memManFixedStart( sizeof( Ntk_Node_t ), 10000, 1000 ); pNet->pManPin = memManFixedStart( sizeof( Ntk_Pin_t ), 10000, 1000 ); pNet->pNames = memManFlexStart( 10000, 1000 ); // get ready to assign the first node ID pNet->nIds = 1; pNet->nTravIds = 1; // alloc storage for network IDs pNet->nIdsAlloc = 1000; pNet->pId2Node = ALLOC( Ntk_Node_t *, pNet->nIdsAlloc ); pNet->pId2Node[0] = NULL; // temporary storage (this is very bad; we should get rid of this) pNet->pArray1 = ALLOC( Ntk_Node_t *, 2000 ); pNet->pArray2 = ALLOC( Ntk_Node_t *, 2000 ); pNet->pArray3 = ALLOC( Ntk_Node_t *, 2000 ); return pNet;}/**Function************************************************************* Synopsis [Duplicates the network.] Description [] SideEffects [] SeeAlso []***********************************************************************/Ntk_Network_t * Ntk_NetworkDup( Ntk_Network_t * pNet, Fnc_Manager_t * pMan ){ Ntk_Network_t * pNetNew; Ntk_Node_t * pNode, * pFanin, * pNodeNew; Ntk_Latch_t * pLatch, * pLatchNew; Ntk_Pin_t * pPin; if ( pNet == NULL ) return NULL; // allocate the empty network pNetNew = Ntk_NetworkAlloc( pNet->pMvsis ); // register the name if ( pNet->pName ) pNetNew->pName = Ntk_NetworkRegisterNewName( pNetNew, pNet->pName ); // register the network spec file name if ( pNet->pSpec ) pNetNew->pSpec = Ntk_NetworkRegisterNewName( pNetNew, pNet->pSpec ); // copy and add the CI nodes Ntk_NetworkForEachCi( pNet, pNode ) { pNodeNew = Ntk_NodeDup( pNetNew, pNode ); Ntk_NetworkAddNode( pNetNew, pNodeNew, 1 ); } // copy the internal nodes Ntk_NetworkForEachNode( pNet, pNode ) Ntk_NodeDup( pNetNew, pNode ); // add the internal nodes Ntk_NetworkForEachNode( pNet, pNode ) { pNodeNew = pNode->pCopy; // adjust the fanins of the new node to point to the new fanins // below, "pFanin" is the old fanin set by Ntk_NodeDup() Ntk_NodeForEachFanin( pNodeNew, pPin, pFanin ) pPin->pNode = pFanin->pCopy; Ntk_NetworkAddNode( pNetNew, pNodeNew, 1 ); } // copy and add the CO nodes Ntk_NetworkForEachCo( pNet, pNode ) { pNodeNew = Ntk_NodeDup( pNetNew, pNode ); // adjust the fanins of the new node to point to the new fanins // below, "pFanin" is the old fanin set by Ntk_NodeDup() Ntk_NodeForEachFanin( pNodeNew, pPin, pFanin ) pPin->pNode = pFanin->pCopy; Ntk_NetworkAddNode( pNetNew, pNodeNew, 1 ); } // copy and add the latches Ntk_NetworkForEachLatch( pNet, pLatch ) { // get the new latch pLatchNew = Ntk_LatchDup( pNetNew, pLatch ); // set the correct inputs/outputs pLatchNew->pInput = pLatch->pInput->pCopy; pLatchNew->pOutput = pLatch->pOutput->pCopy; // add the new latch to the network Ntk_NetworkAddLatch( pNetNew, pLatchNew ); } // copy the EXDC network if ( pNet->pNetExdc ) pNetNew->pNetExdc = Ntk_NetworkDup( pNet->pNetExdc, pNet->pMan ); // put IDs into a proper order Ntk_NetworkReassignIds( pNetNew ); if ( !Ntk_NetworkCheck( pNetNew ) ) fprintf( Ntk_NetworkReadMvsisOut(pNet), "Ntk_NetworkDup(): Network check has failed.\n" ); return pNetNew;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkDelete( Ntk_Network_t * pNet ){ int TotalMemory; Ntk_Node_t * pNode; Ntk_Latch_t * pLatch; if ( pNet == NULL ) return; // copy the EXDC network if ( pNet->pNetExdc ) Ntk_NetworkDelete( pNet->pNetExdc ); // deref and delete the functionality Ntk_NetworkForEachCi( pNet, pNode ) Fnc_FunctionDelete( pNode->pF ); Ntk_NetworkForEachCo( pNet, pNode ) Fnc_FunctionDelete( pNode->pF ); Ntk_NetworkForEachNode( pNet, pNode ) Fnc_FunctionDelete( pNode->pF ); // delete the latch functions Ntk_NetworkForEachLatch( pNet, pLatch ) if ( pLatch->pNode ) Fnc_FunctionDelete( Ntk_NodeReadFunc(pLatch->pNode) ); // free BDD managers// Fnc_ManagerDeref( pNet->pMan ); if ( pNet->nLevels ) FREE( pNet->ppLevels ); if ( pNet->nIdsAlloc ) FREE( pNet->pId2Node ); // free the hash table of node name into node ID st_free_table( pNet->tName2Node ); TotalMemory = 0; TotalMemory += memManFixedReadMemUsage(pNet->pManNode); TotalMemory += memManFixedReadMemUsage(pNet->pManPin); TotalMemory += memManFlexReadMemUsage(pNet->pNames);// fprintf( Ntk_NetworkReadMvsisOut(pNet), "The total memory allocated internally by the network = %d.\n", TotalMemory ); // free the storage allocated for nodes and pins memManFixedStop( pNet->pManNode, 0 ); memManFixedStop( pNet->pManPin, 0 ); // free the storage allocated for names memManFlexStop( pNet->pNames, 0 ); free( pNet->pArray1 ); free( pNet->pArray2 ); free( pNet->pArray3 ); free( pNet );}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkAddNode( Ntk_Network_t * pNet, Ntk_Node_t * pNode, bool fConnect ){ // set the network pNode->pNet = pNet; // assign the unique ID pNode->Id = pNet->nIds++; // add the node to the Id2Node table if ( pNode->Id == pNet->nIdsAlloc ) { pNet->nIdsAlloc *= 2; pNet->pId2Node = REALLOC( Ntk_Node_t *, pNet->pId2Node, pNet->nIdsAlloc ); } pNet->pId2Node[pNode->Id] = pNode; // add the name to the table if ( pNode->pName ) if ( st_insert( pNet->tName2Node, pNode->pName, (char *)pNode ) ) { assert( 0 ); } // add the node to the linked lists of nodes if ( pNode->Type == MV_NODE_CI ) Ntk_NetworkNodeCiListAddLast( pNode ); else if ( pNode->Type == MV_NODE_CO ) Ntk_NetworkNodeCoListAddLast( pNode ); else if ( pNode->Type == MV_NODE_INT ) Ntk_NetworkNodeListAddLast( pNode ); else { assert( 0 ); } // create the fanout structures for the fanin nodes if ( fConnect && pNode->Type != MV_NODE_CI ) Ntk_NodeAddFaninFanout( pNet, pNode );}/**Function************************************************************* Synopsis [Add a PO node functionally equivalent to the internal node.] Description [This function assumes that the internal node already exists in the network and is probably connected to other nodes (both fanins and fanouts). This function adds a new node with the name equal to the name of the given node, and leaves the given node without name. The new node is a PO node, with a fanin equal to the given node. The fanin's fanout of this node is not connected.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkAddNodeCo( Ntk_Network_t * pNet, Ntk_Node_t * pNode, bool fConnect ){ Ntk_Node_t * pNodePo; // the node should have the name assert( pNode->pName ); // the node should be already in the network assert( pNode->pNet == pNet ); assert( st_is_member( pNet->tName2Node, pNode->pName ) ); // the node should be internal assert( pNode->Type == MV_NODE_INT ); // remove the node from the table // because now this node has no name and should not be in the table st_delete( pNet->tName2Node, &pNode->pName, NULL ); // the node remains in the list of internal nodes // create a new PO node pNodePo = Ntk_NodeCreate( pNet, NULL, MV_NODE_CO, pNode->nValues ); // transfer the name pNodePo->pName = pNode->pName; pNode->pName = NULL; // transfer subtype pNodePo->Subtype = pNode->Subtype; pNode->Subtype = 0; // set the fanin of the new PO node to be the internal node pNodePo->pNet = pNet;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -