📄 ioreadnode.c
字号:
/**CFile**************************************************************** FileName [ioReadNode.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Deriving MV SOP for a node specified using BLIF/BLIF-MVS/BLIF-MV.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: ioReadNode.c,v 1.20 2003/05/27 23:14:15 alanmi Exp $]***********************************************************************/#include "ioInt.h"#include "vmInt.h"/* The following restrictions on BLIF-MV file are assumed: (1) No subcircuits. (2) No "!" directive in the tables. (3) No multi-output nodes. These restrictions seem to be true for the available benchmarks.*//////////////////////////////////////////////////////////////////////////// DECLARATIONS ///////////////////////////////////////////////////////////////////////////// BLIFstatic int Io_ReadNodeBlifCover( Io_Read_t * p, Mvc_Cover_t * pCovers[] );static int Io_ReadNodeBlifCoverCube( Io_Read_t * p, Mvc_Cube_t * pCube, int * pPhase );// BLIF-MVSstatic int Io_ReadNodeBlifMvsCover( Io_Read_t * p, Mvc_Cover_t * pCovers[] );static int Io_ReadNodeBlifMvsCoverCube( Io_Read_t * p, Mvc_Cube_t * pCube, char ** pPhase );// BLIF-MVstatic int Io_ReadNodeBlifMvCover( Io_Read_t * p, Mvc_Cover_t * pCovers[] );static int Io_ReadNodeBlifMvCoverCube( Io_Read_t * p, Mvc_Cube_t * pCube, char * pPhase, int * pEqual1, int * pEqual2 );static int Io_ReadNodeBlifMvCoverCubeLiteral( Io_Read_t * p, int Lit, char * pPhase, int * pEqual1, int * pEqual2, char * pString );static int Io_ReadNodeBlifMvCoverCubeLiteralValue( Io_Read_t * p, int Lit, char * pString );static char * Io_ReadNodeBlifMvCoverCubePart( char * pLine, char ** pPart );static char * Io_ReadNodeBlifMvSkipSpaces( char * pStr );static char * Io_ReadNodeBlifMvSkipNonSpaces( char * pStr );static char * Io_ReadNodeBlifMvScrollToBrace( char * pStr );/////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function************************************************************* Synopsis [Derives the functionality of the node.] Description [Derives the functionality of the node. First, creates the variable map using the information about the number of values of the fanins. Second, derives the MV SOP representation. Third, derives the relation from the MV SOP representation.] SideEffects [] SeeAlso []***********************************************************************/int Io_ReadNodeFunctions( Io_Read_t * p, Ntk_Node_t * pNode ){ Cvr_Cover_t * pCvr; Mvc_Cover_t ** pCovers; int RetValue; int i, nValues; // make sure that the node belongs to the network assert( Ntk_NodeReadNetwork(pNode) ); assert( Fnc_FunctionReadMvr( Ntk_NodeReadFunc(pNode) ) == NULL ); assert( Ntk_NodeIsInternal(pNode) ); // set the current node p->pNodeCur = pNode; // create Cvr and get hold of the covers nValues = Ntk_NodeReadValueNum(pNode); pCovers = ALLOC( Mvc_Cover_t *, nValues ); memset( pCovers, 0, sizeof(Mvc_Cover_t *) * nValues ); // set the 0 covers for the node without functionality if ( Ntk_NodeReadData(pNode) == NULL ) { for ( i = 1; i < nValues; i++ ) pCovers[i] = Mvc_CoverAlloc( Fnc_ManagerReadManMvc(Mv_FrameReadMan(p->pMvsis)), 0 ); } else { // derive the MV SOP representation if ( p->Type == IO_FILE_BLIF ) RetValue = Io_ReadNodeBlifCover( p, pCovers ); else if ( p->Type == IO_FILE_BLIF_MVS ) RetValue = Io_ReadNodeBlifMvsCover( p, pCovers ); else if ( p->Type == IO_FILE_BLIF_MV ) RetValue = Io_ReadNodeBlifMvCover( p, pCovers ); if ( RetValue == 1 ) { FREE( pCovers ); return 1; } } // create the covers pCvr = Cvr_CoverCreate( Fnc_FunctionReadVm( Ntk_NodeReadFunc(pNode) ), pCovers ); Ntk_NodeSetFuncCvr( pNode, pCvr ); return 0;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int Io_ReadNodeBlifCover( Io_Read_t * p, Mvc_Cover_t * pCovers[] ){ Ntk_Node_t * pNode; Io_Node_t * pIoNode; Vm_VarMap_t * pVm; Mvc_Cover_t * pCover; int LineCounter, k; int Phase, PhasePrev; // initialize important pointers pNode = p->pNodeCur; pIoNode = (Io_Node_t *)Ntk_NodeReadData(pNode); pVm = Fnc_FunctionReadVm( Ntk_NodeReadFunc(pNode) ); // start the cover pCover = Mvc_CoverAlloc( Fnc_ManagerReadManMvc(Mv_FrameReadMan(p->pMvsis)), pVm->nValuesIn ); if ( pIoNode->nLines ) { // go through the cubes LineCounter = 0; PhasePrev = -1; for ( k = pIoNode->LineTable; p->pLines[k][0] != '.'; k++ ) if ( p->pLines[k][0] != '\0' ) { // get the line number p->LineCur = k; // parse the cube if ( Io_ReadNodeBlifCoverCube( p, p->pCube, &Phase ) ) { Mvc_CoverFree( pCover ); return 1; } // add the cube Mvc_CoverAddDupCubeTail( pCover, p->pCube ); // save the phase if ( PhasePrev == -1 ) PhasePrev = Phase; else if ( PhasePrev != Phase ) { Mvc_CoverFree( pCover ); sprintf( p->sError, "The phases of the cubes are out of synch." ); Io_ReadPrintErrorMessage( p ); return 1; } LineCounter++; } // make sure we read the correct number of lines assert( LineCounter == pIoNode->nLines ); } else {// pCover->count = 1; // set one cube (empty cube) Mvc_CoverMakeEmpty( pCover ); Phase = 1; // set the positive phase } // set the resulting cover if ( Phase == 0 ) { pIoNode->Default = 1; pCovers[0] = pCover; } else { pIoNode->Default = 0; pCovers[1] = pCover; } return 0;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int Io_ReadNodeBlifCoverCube( Io_Read_t * p, Mvc_Cube_t * pCube, int * pPhase ){ Ntk_Node_t * pNode; Io_Node_t * pIoNode; Vm_VarMap_t * pVm; char * pLine, * pTemp; int Length, i; // initialize important pointers pNode = p->pNodeCur; pIoNode = (Io_Node_t *)Ntk_NodeReadData(pNode); pVm = Fnc_FunctionReadVm( Ntk_NodeReadFunc(pNode) ); // get the line pLine = p->pLines[p->LineCur]; // get the input part of the cube pTemp = strtok( pLine, " \t" ); // get its length Length = strlen(pTemp); // if more than one variable in the map, this is the input part of the cube if ( pVm->nVarsIn != 0 ) { assert( pVm->nVarsOut == 1 ); // check the length of the input cube if ( Length != pVm->nVarsIn ) { sprintf( p->sError, "The input cube size (%d) is not equal to the fanin count (%d).", Length, pVm->nVarsIn ); Io_ReadPrintErrorMessage( p ); return 1; } // clean the cube Mvc_CubeBitFill( pCube ); // remove values from the cube, based on the input part of the cube for ( i = 0; i < Length; i++ ) if ( pTemp[i] == '0' ) Mvc_CubeBitRemove( pCube, 2*i + 1 ); else if ( pTemp[i] == '1' ) Mvc_CubeBitRemove( pCube, 2*i ); else if ( pTemp[i] != '-' ) { sprintf( p->sError, "Strange char (%c) in the input cube (%s).", pTemp[i], pTemp ); Io_ReadPrintErrorMessage( p ); return 1; } // get the output part of the cube (phase) pTemp = strtok( NULL, " \t" ); // get its length Length = strlen(pTemp); } // check the length if ( Length != 1 ) { sprintf( p->sError, "The size of the output part of the cube (%s) is not equal to 1.", pTemp ); Io_ReadPrintErrorMessage( p ); return 1; } // otherwise, this is the phase if ( pTemp[0] == '1' ) *pPhase = 1; else if ( pTemp[0] == '0' ) *pPhase = 0; else { sprintf( p->sError, "Strange char (%c) in the output part of the cube (%s).", pTemp[0], pTemp ); Io_ReadPrintErrorMessage( p ); return 1; } return 0;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int Io_ReadNodeBlifMvsCover( Io_Read_t * p, Mvc_Cover_t * pCovers[] ){ Ntk_Node_t * pNode; Io_Node_t * pIoNode; Vm_VarMap_t * pVm; int LineCounter; char * pPhase; int i, k; int fFirstTime; int nValues; // initialize important pointers pNode = p->pNodeCur; pIoNode = (Io_Node_t *)Ntk_NodeReadData(pNode); pVm = Fnc_FunctionReadVm( Ntk_NodeReadFunc(pNode) ); nValues = Ntk_NodeReadValueNum(pNode); // go through the cubes fFirstTime = 1; LineCounter = 0; for ( k = pIoNode->LineTable; p->pLines[k][0] != '.'; k++ ) if ( p->pLines[k][0] != '\0' ) { // get the line number
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -