⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioreadpla.c

📁 主要进行大规模的电路综合
💻 C
📖 第 1 页 / 共 2 页
字号:
    {        p->ppOns[i] = Mvc_CoverAlloc( Fnc_ManagerReadManMvc(p->pMan), p->nInputs * 2 );        p->ppDcs[i] = Mvc_CoverAlloc( Fnc_ManagerReadManMvc(p->pMan), p->nInputs * 2 );    }    // allocate the output part    pfOuts = ALLOC( char, p->nOutputs );    // read the table    pTemp = strtok( p->pDotStart, " |\t\r\n" );    while ( pTemp )    {        // read the cube        iPos = 0;        pCube = Mvc_CubeAlloc( p->ppOns[0] );        Mvc_CubeBitFill( pCube );        while ( 1 )        {            iPosOld = iPos;            iPos += strlen( pTemp );            if ( iPos > p->nInputs )            {                fprintf( p->pOutput, "Cannot correctly scan the input part of the table.\n" );                FREE( pfOuts );                return 0;            }            // read the cube            for ( i = iPosOld; i < iPos; i++ )                if ( pTemp[i-iPosOld] == '0' )                    Mvc_CubeBitRemove( pCube, i * 2 + 1 );                else if ( pTemp[i-iPosOld] == '1' )                    Mvc_CubeBitRemove( pCube, i * 2 );            // read the next part            pTemp = strtok( NULL, " |\t\r\n" );            // check if it is time to quit            if ( iPos == p->nInputs )                break;        }        // read the output part        nOuts = 0;        iPos = 0;        memset( pfOuts, 0, sizeof(char) * p->nOutputs );        while ( 1 )        {            iPosOld = iPos;            iPos += strlen( pTemp );            if ( iPos > p->nOutputs )            {                fprintf( p->pOutput, "Cannot correctly scan the output part of the table.\n" );                FREE( pfOuts );                return 0;            }            // read the cube            for ( i = iPosOld; i < iPos; i++ )            {                pfOuts[i] = pTemp[i-iPosOld];                if ( pfOuts[i] != '0' && pfOuts[i] != '~' )                    nOuts++;            }            // read the next part            pTemp = strtok( NULL, " |\t\r\n" );            // check if it is time to quit            if ( iPos == p->nOutputs )                break;        }        // add this cube to the outputs        for ( i = 0; i < p->nOutputs; i++ )            if ( pfOuts[i] == '1' )            {                if ( --nOuts == 0 )                {                    Mvc_CoverAddCubeTail( p->ppOns[i], pCube );                }                else                {                    pCubeDup = Mvc_CubeDup( p->ppOns[i], pCube );                    Mvc_CoverAddCubeTail( p->ppOns[i], pCubeDup );                }            }            else if ( pfOuts[i] == '-' )            {                if ( --nOuts == 0 )                {                    Mvc_CoverAddCubeTail( p->ppDcs[i], pCube );                }                else                {                    pCubeDup = Mvc_CubeDup( p->ppDcs[i], pCube );                    Mvc_CoverAddCubeTail( p->ppDcs[i], pCubeDup );                }            }            else if ( pfOuts[i] != '0' && pfOuts[i] != '~' )            {                fprintf( p->pOutput, "Strange char (%c) in the output part of the table.\n", pfOuts[i] );                FREE( pfOuts );                return 0;            }        if ( pTemp >= p->pDotEnd )            break;    }    FREE( pfOuts );    return 1;}/**Function*************************************************************  Synopsis    []  Description []                 SideEffects []  SeeAlso     []***********************************************************************/Ntk_Network_t * Io_ReadPlaConstructNetwork( Io_ReadPla_t * p, Mv_Frame_t * pMvsis, char * FileName ){    Fnc_Manager_t * pMan;    char Buffer[10];    char * pName;    Vm_VarMap_t * pVm;    Cvr_Cover_t * pCvr;    Mvr_Relation_t * pMvr, * pMvrDc;    Ntk_Network_t * pNet;    Ntk_Node_t * pNodeGen, * pNode, * pDriver;    Mvc_Cover_t ** ppIsets, * pMvcTemp;    int * pValues;    int i, nDigitsIn, nDigitsOut;    // start the network    pNet = Ntk_NetworkAlloc( pMvsis );    Ntk_NetworkSetName( pNet, Ntk_NetworkRegisterNewName( pNet, FileName ) );    Ntk_NetworkSetSpec( pNet, Ntk_NetworkRegisterNewName( pNet, FileName ) );    // get the manager    pMan = Ntk_NetworkReadMan( pNet );    // get the number of digits in the numbers	for ( nDigitsIn = 0,  i = p->nInputs;  i;  i /= 10,  nDigitsIn++ );	for ( nDigitsOut = 0, i = p->nOutputs; i;  i /= 10,  nDigitsOut++ );    // create the var map for this function    pValues = ALLOC( int, p->nInputs + 1 );    for ( i = 0; i <= p->nInputs; i++ )        pValues[i] = 2;    pVm = Vm_VarMapLookup( Fnc_ManagerReadManVm(pMan), p->nInputs, 1, pValues );    FREE( pValues );    // create the PI nodes    for ( i = 0; i < p->nInputs; i++ )    {        // get the input name        if ( p->pDotIlb )            pName = p->pNamesIn[i];        else        {	        sprintf( Buffer, "x%0*d", nDigitsIn, i );            pName = Buffer;        }        // add the input node        pNode = Ntk_NetworkFindOrAddNodeByName( pNet, pName, MV_NODE_CI );        Ntk_NodeSetValueNum( pNode, 2 );    }    // create the generic internal node    pNodeGen = Ntk_NodeCreateFromNetwork( pNet, NULL );    Ntk_NodeSetValueNum( pNodeGen, 2 );    // create the internal nodes    for ( i = 0; i < p->nOutputs; i++ )    {        // get the output name        if ( p->pDotOb )            pName = p->pNamesOut[i];        else        {	        sprintf( Buffer, "z%0*d", nDigitsOut, i );            pName = Buffer;        }        // copy the generic node        pNode = Ntk_NodeDup( pNet, pNodeGen );        // set the node's name        Ntk_NodeSetName( pNode, Ntk_NetworkRegisterNewName( pNet, pName ) );        // add the node to the network        Ntk_NetworkAddNode( pNet, pNode, 1 );        // create Cvr for this node        ppIsets = ALLOC( Mvc_Cover_t *, 2 );        ppIsets[0] = NULL;        ppIsets[1] = p->ppOns[i];         p->ppOns[i] = NULL;        // create Cvr        pCvr = Cvr_CoverCreate( pVm, ppIsets );        // set the current representation at the node        Ntk_NodeWriteFuncVm( pNode, pVm );        Ntk_NodeWriteFuncCvr( pNode, pCvr );        // create the CO node        Ntk_NetworkAddNodeCo( pNet, pNode, 1 );    }    Ntk_NodeDelete( pNodeGen );    // if some nodes have don't-cares, we create Mvr instead    i = 0;    Ntk_NetworkForEachCoDriver( pNet, pNode, pDriver )    {        if ( Mvc_CoverReadCubeNum( p->ppDcs[i] ) == 0 )        {            i++;            continue;        }        // remember the on-set        pCvr = Ntk_NodeReadFuncCvr( pDriver );        ppIsets = Cvr_CoverReadIsets( pCvr );        assert( ppIsets[0] == NULL );        pMvcTemp = ppIsets[1];        // derive the relation for the function        pMvr = Fnc_FunctionDeriveMvrFromCvr( Fnc_ManagerReadManMvr(pMan), Fnc_ManagerReadManVmx(pMan), pCvr );        // set the DC set        ppIsets[1] = p->ppDcs[i];        // derive the relation for the dc-set        pMvrDc = Fnc_FunctionDeriveMvrFromCvr( Fnc_ManagerReadManMvr(pMan), Fnc_ManagerReadManVmx(pMan), pCvr );        // reset back the i-sets        ppIsets[1] = pMvcTemp;        // remove the DC cover        Mvc_CoverFree( p->ppDcs[i] );        p->ppDcs[i] = NULL;        // add the relation of DC to the relation of on-set        Mvr_RelationAddDontCare( pMvr, pMvrDc );        Mvr_RelationFree( pMvrDc );        // set the relation at the node (this will free the old Cvr)        Ntk_NodeSetFuncMvr( pDriver, pMvr );        i++;    }    // order the fanins    Ntk_NetworkOrderFanins( pNet );    // make the nodes minimum base    Ntk_NetworkForEachCoDriver( pNet, pNode, pDriver )        Ntk_NodeMakeMinimumBase( pDriver );    if ( !Ntk_NetworkCheck( pNet ) )    {        fprintf( p->pOutput, "Io_ReadPla(): Network check has failed.\n" );        Ntk_NetworkDelete( pNet );        pNet = NULL;    }    return pNet; }/**Function*************************************************************  Synopsis    []  Description []                 SideEffects []  SeeAlso     []***********************************************************************/void Io_ReadPlaCleanUp( Io_ReadPla_t * p ){    int i;    for ( i = 0; i < p->nOutputs; i++ )    {        if ( p->ppOns && p->ppOns[i] )            Mvc_CoverFree( p->ppOns[i] );        if ( p->ppDcs && p->ppDcs[i] )            Mvc_CoverFree( p->ppDcs[i] );    }    FREE( p->pBuffer );    FREE( p->ppOns );    FREE( p->ppDcs );    FREE( p->pNamesIn );    FREE( p->pNamesOut );    FREE( p );}/**Function*************************************************************  Synopsis    []  Description []                 SideEffects []  SeeAlso     []***********************************************************************/int Io_ReadFileType( char * FileName ){    FILE * pFile;    char * pBuffer;    int nFileSize;    int SizeLimit;    int FileType;    // open the BLIF file for binary reading    pFile = fopen( FileName, "rb" );    if ( pFile == NULL )        return IO_FILE_NONE;    // get the file size, in bytes    fseek( pFile, 0, SEEK_END );      nFileSize = ftell( pFile );      // determine the size limit    SizeLimit = (nFileSize < 5000)? nFileSize: 5000;    // move the file current reading position to the beginning    rewind( pFile );     // load the contents of the file into memory    pBuffer   = ALLOC( char, SizeLimit + 1 );    fread( pBuffer, SizeLimit, 1, pFile );    pBuffer[SizeLimit] = 0;    // detect the file type    if ( strstr( pBuffer, ".inputs" ) && strstr( pBuffer, ".outputs" ) )        FileType = IO_FILE_BLIF;    else if ( strstr( pBuffer, ".mv" ) )        FileType = IO_FILE_PLA_MV;    else if ( strstr( pBuffer, ".i " ) && strstr( pBuffer, ".o " ) )        FileType = IO_FILE_PLA;    else        FileType = IO_FILE_NONE;    FREE( pBuffer );    fclose( pFile );    return FileType;}///////////////////////////////////////////////////////////////////////////                       END OF FILE                                ///////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -