📄 ntknames.c
字号:
bool Ntk_NetworkIsModeShort( Ntk_Network_t * pNet ){ Mv_Frame_t * pMvsis; if ( pNet == NULL ) return 1; pMvsis = Ntk_NetworkReadMvsis( pNet ); return Mv_FrameReadMode( pMvsis );}/**Function************************************************************* Synopsis [Returns the pointer to the node if the node name is known.] Description [Checks the internal hash table of the network for existance of the node with the given name. If the node exists, returns the pointer to the node structure. If the node does not exist, returns NULL.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkFindOrAddNodeByName( Ntk_Network_t * pNet, char * pName, Ntk_NodeType_t Type ){ Ntk_Node_t * pNode; if ( st_lookup( pNet->tName2Node, pName, (char**)&pNode ) ) return pNode; // create a new node pNode = Ntk_NodeCreate( pNet, pName, Type, -1 ); // add the node to the network Ntk_NetworkAddNode( pNet, pNode, 0 ); return pNode;}/**Function************************************************************* Synopsis [Returns the pointer to the node if the node name is known.] Description [Checks the internal hash table of the network for existence of the node with the given name. If the node exists, returns the pointer to the node structure. If the node does not exist, returns NULL.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkFindNodeByName( Ntk_Network_t * pNet, char * pName ){ Ntk_Node_t * pNode; if ( st_lookup( pNet->tName2Node, pName, (char**)&pNode ) ) return pNode; return NULL;}/**Function************************************************************* Synopsis [Returns the pointer to the node if the node name is known.] Description [The name of the node may be its short or long name, which is not actually assigned to the node, but derived from its node ID. This procedure find the node in this case, too.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkFindNodeByNameWithMode( Ntk_Network_t * pNet, char * pName ){ if ( Ntk_NetworkIsModeShort( pNet ) ) return Ntk_NetworkFindNodeByNameShort( pNet, pName ); return Ntk_NetworkFindNodeByNameLong( pNet, pName );}/**Function************************************************************* Synopsis [Returns the pointer to the node using its long name.] Description [] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkFindNodeByNameLong( Ntk_Network_t * pNet, char * pName ){ Ntk_Node_t * pNode; int NumId; // look for the regular name in the table if ( st_lookup( pNet->tName2Node, pName, (char**)&pNode ) ) return pNode; // look for a long printable name if ( pName[0] >= '[' && pName[1] >= '0' && pName[1] <= '9' ) { NumId = atoi(pName + 1); return Ntk_NetworkFindNodeById( pNet, NumId ); } return NULL;}/**Function************************************************************* Synopsis [Returns the pointer to the node using its short name.] Description [] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkFindNodeByNameShort( Ntk_Network_t * pNet, char * pName ){ char Buffer[20]; int NumId, Number; // look for a short printable name if ( pName[0] >= 'a' && pName[0] <= 'z' ) { if ( pName[1] != '\0' && (pName[1] < '0' || pName[1] > '9') ) return NULL; // make sure that there are no trailing chars if ( pName[1] == 0 ) { Number = 0; sprintf( Buffer, "%c", pName[0] ); } else { Number = atoi(pName + 1); sprintf( Buffer, "%c%d", pName[0], Number ); } if ( strcmp( pName, Buffer ) != 0 ) return NULL; // get the node pointer by the node ID NumId = Number * 26 + (pName[0] - 'a') + 1; return Ntk_NetworkFindNodeById( pNet, NumId ); } return NULL;}/**Function************************************************************* Synopsis [Returns the pointer to the node if the node name is known.] Description [Checks the internal hash table of the network for existance of the node with the given name. If the node exists, returns the pointer to the node structure. If the node does not exist, returns NULL.] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkFindNodeById( Ntk_Network_t * pNet, int Id ){ if ( Id > 0 && Id < pNet->nIds ) return pNet->pId2Node[Id]; return NULL;}/**Function************************************************************* Synopsis [Registers the name with the string memory manager.] Description [This function should be used to register all names permanentsly stored with the network. The pointer returned by this procedure contains the copy of the name, which should be used in all network manipulation procedures.] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NetworkRegisterNewName( Ntk_Network_t * pNet, char * pName ){ char * pRegisteredName; pRegisteredName = memManFlexEntryFetch( pNet->pNames, strlen(pName) + 1 ); strcpy( pRegisteredName, pName ); return pRegisteredName;}/**Function************************************************************* Synopsis [Renames all nodes of the network.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkRenameNodes( Ntk_Network_t * pNet ){ Ntk_Node_t * pNode; char * pNetName; int nNodes, nChars, iNode; // reset the hash table, hashing current node names into pointers st_free_table( pNet->tName2Node ); pNet->tName2Node = st_init_table(strcmp, st_strhash); // save network's name pNetName = util_strsav( pNet->pName ); // reset the name storage memManFlexStop( pNet->pNames, 0 ); pNet->pNames = memManFlexStart( 10000, 1000 ); // insert the network's name into the new storage pNet->pName = Ntk_NetworkRegisterNewName( pNet, pNetName ); FREE( pNetName ); // get the number of chars in the node name nNodes = Ntk_NetworkReadNodeTotalNum( pNet ); for ( nChars = 0; nNodes; nNodes /= 26, nChars++ ); // go through the nodes and set their names iNode = 0; Ntk_NetworkForEachCi( pNet, pNode ) Ntk_NetworkAssignNewName( pNode, iNode++, nChars ); Ntk_NetworkForEachCo( pNet, pNode ) Ntk_NetworkAssignNewName( pNode, iNode++, nChars ); Ntk_NetworkForEachNode( pNet, pNode ) Ntk_NetworkAssignNewName( pNode, iNode++, nChars ); // reorder the nodes and the fanins Ntk_NetworkOrderFanins( pNet ); if ( !Ntk_NetworkCheck( pNet ) ) fprintf( Ntk_NetworkReadMvsisOut(pNet), "Ntk_NetworkRenameNodes(): Network check has failed.\n" );}/**Function************************************************************* Synopsis [Assign a simple name to the node.] Description [This procedure ignores whatever name the node may have had and assigns the new name using a simple naming scheme. Should not be called only from Ntk_NetworkRenameNodes(). ] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkAssignNewName( Ntk_Node_t * pNode, int iNum, int nChars ){ Ntk_Network_t * pNet; char Name[10], * pName; int i; // derive a simple name// sprintf( Name, "%c%0*d", 'a' + (pNode->Id - 1) % 26, nChars, (pNode->Id - 1) / 26 ); for ( i = 0; i < nChars; i++ ) { Name[nChars-1-i] = 'a' + iNum % 26; iNum = iNum / 26; } Name[nChars] = 0; // register this name with the name manager pNet = pNode->pNet; pName = Ntk_NetworkRegisterNewName( pNet, Name ); // set the name pNode->pName = pName; if ( st_insert( pNet->tName2Node, pName, (char *)pNode ) ) { assert( 0 ); // why the brand new names should be in the table? }}/**Function************************************************************* Synopsis [Collects one node by name.] Description [] SideEffects [] SeeAlso []***********************************************************************/Ntk_Node_t * Ntk_NetworkCollectNodeByName( Ntk_Network_t * pNet, char * pName, int fCollectCis ){ FILE * pFile ; Ntk_Node_t * pNode, * pFanin; pFile = Ntk_NetworkReadMvsisOut( pNet ); pNode = Ntk_NetworkFindNodeByNameWithMode( pNet, pName ); if ( pNode == NULL ) { fprintf( pFile, "Cannot find node \"%s\".\n", pName ); return NULL; } if ( Ntk_NodeHasCoName(pNode) ) { fprintf( pFile, "Cannot find node \"%s\".\n", pName ); return NULL; } if ( pNode->Type == MV_NODE_CI && !fCollectCis ) { fprintf( pFile, "Skipping CI node \"%s\".\n", pName ); return NULL; } if ( pNode->Type == MV_NODE_CO ) { pFanin = Ntk_NodeReadFaninNode( pNode, 0 ); if ( Ntk_NodeHasCoName(pFanin) ) return pFanin; else return pNode; } else return pNode;}/**Function************************************************************* Synopsis [Collects the input and output names of the network.] Description [] SideEffects [] SeeAlso []***********************************************************************/void Ntk_NetworkCollectIoNames( Ntk_Network_t * pNet, char *** ppsLeaves, char *** ppsRoots ){ char ** psLeaves; char ** psRoots; Ntk_Node_t * pNode; int i; // collect CI names psLeaves = ALLOC( char *, Ntk_NetworkReadCiNum(pNet) ); i = 0; Ntk_NetworkForEachCi( pNet, pNode ) psLeaves[i++] = pNode->pName; assert( i == Ntk_NetworkReadCiNum(pNet) ); // collect CO names psRoots = ALLOC( char *, Ntk_NetworkReadCoNum(pNet) ); i = 0; Ntk_NetworkForEachCo( pNet, pNode ) psRoots[i++] = pNode->pName; assert( i == Ntk_NetworkReadCoNum(pNet) ); *ppsLeaves = psLeaves; *ppsRoots = psRoots;}/////////////////////////////////////////////////////////////////////////// END OF FILE ///////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -