📄 ntknames.c
字号:
/**CFile**************************************************************** FileName [ntkNames.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Procedures working with node names.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: ntkNames.c,v 1.13 2003/05/27 23:14:23 alanmi Exp $]***********************************************************************/#include "ntkInt.h"/////////////////////////////////////////////////////////////////////////// DECLARATIONS ///////////////////////////////////////////////////////////////////////////static void Ntk_NetworkAssignNewName( Ntk_Node_t * pNode, int iNum, int nChars );/////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function************************************************************* Synopsis [Get the printable output name of the node.] Description [If the node is the PI or the PO, returns its name. If the node has a single CO fanout the printable name is the CO name. Otherwise, the current name of the node is used, or if the current name is NULL, a new unique name is created.] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NodeGetNamePrintable( Ntk_Node_t * pNode ){ // if the node name mode is short, return short name if ( Ntk_NetworkIsModeShort(pNode->pNet) ) return Ntk_NodeGetNameShort(pNode); // otherwise, the node name mode is long return Ntk_NodeGetNameLong(pNode);}/**Function************************************************************* Synopsis [Get the printable short name of the node.] Description [] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NodeGetNameShort( Ntk_Node_t * pNode ){ Ntk_Node_t * pFanoutCo; // if the node has the only CO fanout, get the CO if ( pFanoutCo = Ntk_NodeHasCoName(pNode) ) return Ntk_NodeGetNameUniqueShort( pFanoutCo ); // assign the name if it was not found return Ntk_NodeGetNameUniqueShort( pNode );}/**Function************************************************************* Synopsis [Get the printable long name of the node.] Description [] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NodeGetNameLong( Ntk_Node_t * pNode ){ Ntk_Node_t * pFanoutCo; // if the only fanout of this node is a PO, write PO name if ( pFanoutCo = Ntk_NodeHasCoName(pNode) ) return Ntk_NodeGetNameUniqueLong( pFanoutCo ); // assign the name if it was not found return Ntk_NodeGetNameUniqueLong( pNode );}/**Function************************************************************* Synopsis [Returns a unique name of the node.] Description [] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NodeGetNameUniqueLong( Ntk_Node_t * pNode ){ static char NameBuffer[500]; int Counter = 0; if ( pNode->pName ) return pNode->pName; // get the name composed of the node ID sprintf( NameBuffer, "[%d]", pNode->Id ); // if it is not unique, add a character at the end until it becomes unique while ( st_is_member( pNode->pNet->tName2Node, NameBuffer ) ) { sprintf( NameBuffer, "[%d%c%d]", pNode->Id, 'a' + Counter % 26, Counter / 26 ); Counter++; } return NameBuffer;}/**Function************************************************************* Synopsis [Returns a unique name of the node.] Description [] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NodeGetNameUniqueShort( Ntk_Node_t * pNode ){ static char NameBuffer[500]; int Number = pNode->Id - 1; // get the name composed of the node ID if ( Number < 26 ) sprintf( NameBuffer, "%c", 'a' + Number % 26 ); else sprintf( NameBuffer, "%c%d", 'a' + Number % 26, Number / 26 ); return NameBuffer;}/**Function************************************************************* Synopsis [Assign the name to the node.] Description [Assumes that the given name is unique and is already in the memory manager of the network. If the name is not given, a unique name is created and assigned.] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NodeAssignName( Ntk_Node_t * pNode, char * pName ) { char * pNameNew; assert( pNode->pName == NULL ); if ( pName ) // the name is given { // make sure it is unique if ( st_is_member( pNode->pNet->tName2Node, pName ) ) { assert( 0 ); } } else // the name is not given { // get the unique name pNameNew = Ntk_NodeGetNameUniqueLong( pNode ); // register this name pName = Ntk_NetworkRegisterNewName( pNode->pNet, pNameNew ); } // assign the name st_insert( pNode->pNet->tName2Node, pName, (char *)pNode ); pNode->pName = pName; return pName;}/**Function************************************************************* Synopsis [Removes the node's name.] Description [] SideEffects [] SeeAlso []***********************************************************************/char * Ntk_NodeRemoveName( Ntk_Node_t * pNode ) { char * pName; assert( pNode->pName ); // make sure the node is registered with this name if ( !st_is_member( pNode->pNet->tName2Node, pNode->pName ) ) { assert( 0 ); } // remove the name st_delete( pNode->pNet->tName2Node, &pNode->pName, NULL ); pName = pNode->pName; pNode->pName = NULL; return pName;}/**Function************************************************************* Synopsis [Compares the nodes alphabetically by name.] Description [] SideEffects [] SeeAlso []***********************************************************************/int Ntk_NodeCompareByNameAndId( Ntk_Node_t ** ppN1, Ntk_Node_t ** ppN2 ){ char * pName1 = (*ppN1)->pName; char * pName2 = (*ppN2)->pName;// assert( (*ppN1)->Id > 0 ); // node ID should be assigned by adding the node to the network// assert( (*ppN2)->Id > 0 ); // node ID should be assigned by adding the node to the network // if this is the same node, return right away if ( (*ppN1) == (*ppN2) ) return 0; // make sure the comparison of nodes is valid assert( (*ppN1)->Id != (*ppN2)->Id ); // two different nodes cannot have the same ID // if both of these IDs are 0, it means that both nodes are not in the network // note that it is okay if one node is not in the network // in this case, its node ID is 0 but it still can be compared to other nodes if ( pName1 && pName2 ) return strcmp( pName1, pName2 ); if ( pName1 ) return -1; if ( pName2 ) return 1; if ( (*ppN1)->Id < (*ppN2)->Id ) return -1; if ( (*ppN1)->Id > (*ppN2)->Id ) return 1; assert( 0 ); return 0;}/**Function************************************************************* Synopsis [Compares the nodes alphabetically by name.] Description [] SideEffects [] SeeAlso []***********************************************************************/int Ntk_NodeCompareByNameAndIdOrder( Ntk_Node_t ** ppN1, Ntk_Node_t ** ppN2 ){ char * pName1 = (*ppN1)->pName; char * pName2 = (*ppN2)->pName;// assert( (*ppN1)->Id > 0 ); // node ID should be assigned by adding the node to the network// assert( (*ppN2)->Id > 0 ); // node ID should be assigned by adding the node to the network // if this is the same node, return right away if ( (*ppN1) == (*ppN2) ) return 0; if ( (*ppN1)->Type < (*ppN2)->Type ) return -1; if ( (*ppN1)->Type > (*ppN2)->Type ) return 1; // make sure the comparison of nodes is valid assert( (*ppN1)->Id != (*ppN2)->Id ); // two different nodes cannot have the same ID // if both of these IDs are 0, it means that both nodes are not in the network // note that it is okay if one node is not in the network // in this case, its node ID is 0 but it still can be compared to other nodes if ( pName1 && pName2 ) return strcmp( pName1, pName2 ); if ( pName1 ) return -1; if ( pName2 ) return 1; if ( (*ppN1)->Id < (*ppN2)->Id ) return -1; if ( (*ppN1)->Id > (*ppN2)->Id ) return 1; assert( 0 ); return 0;}/**Function************************************************************* Synopsis [Compares the nodes according to the accepted order.] Description [] SideEffects [] SeeAlso []***********************************************************************/int Ntk_NodeCompareByValueAndId( Ntk_Node_t ** ppN1, Ntk_Node_t ** ppN2 ){ // compare using number of values if ( (*ppN1)->nValues < (*ppN2)->nValues ) return -1; if ( (*ppN1)->nValues > (*ppN2)->nValues ) return 1; // compare using unique node ID if ( (*ppN1)->Id < (*ppN2)->Id ) return -1; if ( (*ppN1)->Id > (*ppN2)->Id ) return 1; // should never happen because node IDs are unique// assert( 0 ); // may happen if fanins are duplicated in the BLIF file return 0;}/**Function************************************************************* Synopsis [Compares the nodes according to the accepted order.] Description [] SideEffects [] SeeAlso []***********************************************************************/int Ntk_NodeCompareByLevel( Ntk_Node_t ** ppN1, Ntk_Node_t ** ppN2 ){ // compare using number of values if ( (*ppN1)->Level < (*ppN2)->Level ) return 1; if ( (*ppN1)->Level > (*ppN2)->Level ) return -1; return 0;}/**Function************************************************************* Synopsis [Returns 1 if the name mode is short.] Description [] SideEffects [] SeeAlso []***********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -