📄 shcreate.c
字号:
/**CFile**************************************************************** FileName [shCreate.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Creates the main data structures (manager, network).] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: shCreate.c,v 1.2 2003/05/27 23:14:50 alanmi Exp $]***********************************************************************/#include "shInt.h"/////////////////////////////////////////////////////////////////////////// DECLARATIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/Sh_Manager_t * Sh_ManagerCreate( int nVars ){ Sh_Manager_t * p; p = ALLOC( Sh_Manager_t, 1 ); memset( p, 0, sizeof(Sh_Manager_t) ); // allocate the memory manager#ifndef USE_SYSTEM_MEMORY_MANAGEMENT p->pMem = memManFixedStart( sizeof(Sh_Node_t), 5000, 1000 ); #endif // create the costant node p->pConst1 = ALLOC( Sh_Node_t, 1 ); memset( p->pConst1, 0, sizeof(Sh_Node_t) ); // mark the constant node p->pConst1->pOne = (Sh_Node_t *)1; // allocate the table p->pTable = Sh_TableAlloc( 50000 ); // add resizing later!!! // allocate elementary variables Sh_ManagerResize( p, nVars ); // create the canonicity table p->pCanTable = Sh_SignPrecompute(); // set the starting traversal ID p->nTravIds = 1; return p;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/void Sh_ManagerResize( Sh_Manager_t * pMan, int nVarsNew ){ int i; if ( pMan->nVars >= nVarsNew ) return; // allocate, or reallocate storage for vars if ( pMan->nVars == 0 ) pMan->pVars = ALLOC( Sh_Node_t *, nVarsNew ); else pMan->pVars = REALLOC( Sh_Node_t *, pMan->pVars, nVarsNew ); // create the vars for ( i = pMan->nVars; i < nVarsNew; i++ ) {#ifdef USE_SYSTEM_MEMORY_MANAGEMENT pMan->pVars[i] = ALLOC( Sh_Node_t, 1 );#else pMan->pVars[i] = (Sh_Node_t *)memManFixedEntryFetch( pMan->pMem );#endif memset( pMan->pVars[i], 0, sizeof(Sh_Node_t) ); // set the number of this constant pMan->pVars[i]->pTwo = (Sh_Node_t *)i; pMan->pVars[i]->fVar = 1; pMan->pVars[i]->Num = Sh_TableIncrementNodes( pMan ); } // set the new number of variables pMan->nVars = nVarsNew;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/void Sh_ManagerFree( Sh_Manager_t * p ){ if ( !p ) return; Sh_TableFree( p->pTable );#ifdef USE_SYSTEM_MEMORY_MANAGEMENT { int i; for ( i = 0; i < p->nVars; i++ ) { assert( p->pVars[i]->nRefs == 0 ); FREE( p->pVars[i] ); } }#else memManFixedStop( p->pMem, 0 ); #endif FREE( p->pConst1 ); FREE( p->pVars ); FREE( p->pCanTable ); FREE( p );} /**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/Sh_Network_t * Sh_NetworkCreate( Sh_Manager_t * pMan, int nInputs, int nOutputs ){ Sh_Network_t * p; p = ALLOC( Sh_Network_t, 1 ); memset( p, 0, sizeof(Sh_Network_t) ); // allocate arrays p->pMan = pMan; p->nInputs = nInputs; p->nOutputs = nOutputs; p->ppOutputs = ALLOC( Sh_Node_t *, p->nOutputs ); memset( p->ppOutputs, 0, sizeof(Sh_Node_t *) * p->nOutputs ); // resize the manager if needed Sh_ManagerResize( pMan, nInputs ); return p;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/void Sh_NetworkFree( Sh_Network_t * p ){ int i; if ( !p ) return; // deref all sorts of referenced nodes for ( i = 0; i < p->nOutputs; i++ ) Sh_NodeRecursiveDeref( p->ppOutputs[i] ); for ( i = 0; i < p->nOutputsCore; i++ ) Sh_NodeRecursiveDeref( p->ppOutputsCore[i] ); for ( i = 0; i < p->nInputsCore; i++ ) Sh_NodeRecursiveDeref( p->ppInputsCore[i] ); for ( i = 0; i < p->nSpecials; i++ ) Sh_NodeRecursiveDeref( p->ppSpecials[i] ); FREE( p->ppOutputs ); FREE( p->ppOutputsCore ); FREE( p->ppInputsCore ); FREE( p->ppSpecials ); FREE( p );}/////////////////////////////////////////////////////////////////////////// END OF FILE ///////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -