📄 ntkutils.c
字号:
Ntk_NodeAddFanin( pNodePo, pNode ); // add the new node to the network Ntk_NetworkAddNode( pNet, pNodePo, fConnect ); return pNodePo;}/**Function************************************************************* Synopsis [Adds a CO node which originally had the same name as the CI node.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkTransformCiToCo( Ntk_Network_t * pNet, Ntk_Node_t * pNodeCi ){ Ntk_Node_t * pNodeCo; char * pNameCi; // make sure the given node is a CI node assert( Ntk_NodeIsCi(pNodeCi) ); // create the new CO node pNodeCo = Ntk_NodeCreate( pNet, NULL, MV_NODE_CO, pNodeCi->nValues ); // assign the CI name to the CO (this name is already registered) pNodeCo->pName = pNodeCi->pName; // remove the CI node with this name from the table st_delete( pNet->tName2Node, (char **)&pNodeCi->pName, NULL ); // create a new CI node name (just like in SIS) pNameCi = ALLOC( char, strlen(pNodeCi->pName) + 5 ); strcpy( pNameCi, "IN-" ); strcat( pNameCi, pNodeCi->pName ); // assign the new name to the CI node pNodeCi->pName = Ntk_NetworkRegisterNewName( pNet, pNameCi ); FREE( pNameCi ); // add the CI node with this name to the table if ( st_insert( pNet->tName2Node, pNodeCi->pName, (char *)pNodeCi ) ) { assert( 0 ); } // add the CI node as a fanin to the CO node Ntk_NodeAddFanin( pNodeCo, pNodeCi ); // add the CO node to the network Ntk_NetworkAddNode( pNet, pNodeCo, 1 );}/**Function************************************************************* Synopsis [Updates the node from CO to CI.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkTransformNodeIntToCi( Ntk_Network_t * pNet, Ntk_Node_t * pNode ){ // make sure the given node is a CO node assert( Ntk_NodeIsInternal(pNode) ); // the node should have the name assert( pNode->pName ); // set the new node type pNode->Type = MV_NODE_CI; // remove the node from the linked list of CO nodes Ntk_NetworkNodeListDelete( pNode ); // add the node to the linked list of CI nodes Ntk_NetworkNodeCiListAddLast( pNode ); // the node remains in the table of nodes with names}/**Function************************************************************* Synopsis [Updates the node from INT to CO.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkTransformNodeIntToCo( Ntk_Network_t * pNet, Ntk_Node_t * pNode ){ // 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 ); // set the new node type pNode->Type = MV_NODE_CO; // remove the nodes functionality if ( pNode->pF ) Fnc_FunctionClean( pNode->pF ); // remove the node from the linked list of int nodes Ntk_NetworkNodeListDelete( pNode ); // add the node to the linked list of CO nodes Ntk_NetworkNodeCoListAddLast( pNode ); // the node remains in the table of nodes with names}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkDeleteNode( Ntk_Network_t * pNet, Ntk_Node_t * pNode, bool fConnect, bool fDeleteNode ){ assert( pNode->pNet == pNet ); // delete the name from the tables assert( pNode->Id > 0 && pNode->Id < pNet->nIdsAlloc ); pNet->pId2Node[pNode->Id] = NULL; if ( pNode->pName ) if ( !st_delete( pNet->tName2Node, (char **)&pNode->pName, (char **)&pNode ) ) { assert( 0 ); } // delete the node to the linked lists of nodes if ( pNode->Type == MV_NODE_CI ) Ntk_NetworkNodeCiListDelete( pNode ); else if ( pNode->Type == MV_NODE_CO ) Ntk_NetworkNodeCoListDelete( pNode ); else if ( pNode->Type == MV_NODE_INT ) Ntk_NetworkNodeListDelete( pNode ); else { assert( 0 ); } // remove the fanout structures for the fanin nodes if ( fConnect && pNode->Type != MV_NODE_CI ) Ntk_NodeDeleteFaninFanout( pNet, pNode ); // delete the node that is no longer in the network if ( fDeleteNode ) Ntk_NodeDelete( pNode );}/**Function************************************************************* Synopsis [Returns 1 if the network is binary.] Description [] SideEffects [] SeeAlso []***********************************************************************/bool Ntk_NetworkIsBinary( Ntk_Network_t * pNet ){ Ntk_Node_t * pNode; Ntk_NetworkForEachCi( pNet, pNode ) if ( pNode->nValues > 2 ) return 0; Ntk_NetworkForEachNode( pNet, pNode ) if ( pNode->nValues > 2 ) return 0; return 1;}/**Function************************************************************* Synopsis [Returns 1 if the network is binary.] Description [] SideEffects [] SeeAlso []***********************************************************************/bool Ntk_NetworkIsND( Ntk_Network_t * pNet ){ Mvr_Relation_t * pMvr; Ntk_Node_t * pNode; Ntk_NetworkForEachNode( pNet, pNode ) { pMvr = Ntk_NodeGetFuncMvr( pNode ); if ( Mvr_RelationIsND( pMvr ) ) return 1; } return 0;}/**Function************************************************************* Synopsis [Returns the CI node with the given index.] Description [CI/CO hashing can be added later.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkReadCiNode( Ntk_Network_t * pNet, int i ){ Ntk_Node_t * pNode; int Counter; Counter = 0; Ntk_NetworkForEachCi( pNet, pNode ) if ( Counter++ == i ) return pNode; return NULL;}/**Function************************************************************* Synopsis [Returns the CO node with the given index.] Description [CI/CO hashing can be added later.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkReadCoNode( Ntk_Network_t * pNet, int i ){ Ntk_Node_t * pNode; int Counter; Counter = 0; Ntk_NetworkForEachCo( pNet, pNode ) if ( Counter++ == i ) return pNode; return NULL;}/**Function************************************************************* Synopsis [Returns the index of the given CI in the list of CIs.] Description [] SideEffects [] SeeAlso []***********************************************************************/int Ntk_NetworkReadCiIndex( Ntk_Network_t * pNet, Ntk_Node_t * pNode ){ Ntk_Node_t * pNodeCi; int Counter; assert( pNode->Type == MV_NODE_CI ); Counter = 0; Ntk_NetworkForEachCi( pNet, pNodeCi ) if ( pNodeCi == pNode ) return Counter; else Counter++; return -1;}/**Function************************************************************* Synopsis [Returns the index of the given CO in the list of COs.] Description [] SideEffects [] SeeAlso []***********************************************************************/int Ntk_NetworkReadCoIndex( Ntk_Network_t * pNet, Ntk_Node_t * pNode ){ Ntk_Node_t * pNodeCo; int Counter; assert( pNode->Type == MV_NODE_CO ); Counter = 0; Ntk_NetworkForEachCo( pNet, pNodeCo ) if ( pNodeCo == pNode ) return Counter; else Counter++; return -1;}/////////////////////////////////////////////////////////////////////////// END OF FILE ///////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -