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

📄 ioreadpla.c

📁 主要进行大规模的电路综合
💻 C
📖 第 1 页 / 共 2 页
字号:
/**CFile****************************************************************  FileName    [ioReadPla.c]  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]  Synopsis    [Procedures to read the binary PLA file.]  Author      [MVSIS Group]    Affiliation [UC Berkeley]  Date        [Ver. 1.0. Started - February 1, 2003.]  Revision    [$Id: ioReadPla.c,v 1.9 2003/05/27 23:14:15 alanmi Exp $]***********************************************************************/#include "mv.h"#include "ioInt.h"///////////////////////////////////////////////////////////////////////////                        DECLARATIONS                              ///////////////////////////////////////////////////////////////////////////typedef struct IoReadPlaStruct Io_ReadPla_t;struct IoReadPlaStruct{    // the file contents    char *      pBuffer;    int         FileSize;    // the file parts    char *      pDotType;    char *      pDotI;    char *      pDotO;    char *      pDotP;    char *      pDotIlb;    char *      pDotOb;    char *      pDotStart;    char *      pDotEnd;    // output for error messages    FILE *      pOutput;    // the number of inputs and outputs    int         nInputs;    int         nOutputs;    // the input/output names    char **     pNamesIn;    char **     pNamesOut;    // the covers    Mvc_Cover_t ** ppOns;    Mvc_Cover_t ** ppDcs;    // the functionality manager    Fnc_Manager_t * pMan;};static bool Io_ReadPlaFindDotLines( Io_ReadPla_t * p ); static bool Io_ReadPlaHeader( Io_ReadPla_t * p );static bool Io_ReadPlaBody( Io_ReadPla_t * p );static Ntk_Network_t * Io_ReadPlaConstructNetwork( Io_ReadPla_t * p, Mv_Frame_t * pMvsis, char * FileName );static void Io_ReadPlaCleanUp( Io_ReadPla_t * p );///////////////////////////////////////////////////////////////////////////                     FUNCTION DEFITIONS                           ////////////////////////////////////////////////////////////////////////////**Function*************************************************************  Synopsis    [Reads Espresso PLA format.]  Description [This procedure reads the standard (fd) Espresso PLA  file format. The don't-cares are either ignored or added to the  i-sets.]                 SideEffects []  SeeAlso     []***********************************************************************/Ntk_Network_t * Io_ReadPla( Mv_Frame_t * pMvsis, char * FileName ){    Ntk_Network_t * pNet = NULL;    Io_ReadPla_t * p;    // allocate the structure    p = ALLOC( Io_ReadPla_t, 1 );    memset( p, 0, sizeof(Io_ReadPla_t) );    // set the output file stream for errors    p->pOutput = Mv_FrameReadErr(pMvsis);    p->pMan = Mv_FrameReadMan(pMvsis);    // read the file    p->pBuffer = Io_ReadFileFileContents( FileName, &p->FileSize );    // remove comments if any    Io_ReadFileRemoveComments( p->pBuffer, NULL, NULL );    // split the file into parts    if ( !Io_ReadPlaFindDotLines( p ) )        goto cleanup;    // read the header of the file    if ( !Io_ReadPlaHeader( p ) )        goto cleanup;    // read the body of the file    if ( !Io_ReadPlaBody( p ) )        goto cleanup;    // construct the network    pNet = Io_ReadPlaConstructNetwork( p, pMvsis, FileName );cleanup:    // free storage    Io_ReadPlaCleanUp( p );    return pNet;}/**Function*************************************************************  Synopsis    []  Description []                 SideEffects []  SeeAlso     []***********************************************************************/bool Io_ReadPlaFindDotLines( Io_ReadPla_t * p ){    char * pCur, * pCurMax;    for ( pCur = p->pBuffer; *pCur; pCur++ )        if ( *pCur == '.' )        {            if ( pCur[1] == 'i' && pCur[2] == ' ' )            {                if ( p->pDotI )                {                    fprintf( p->pOutput, "The PLA file contains multiple .i lines.\n" );                    return 0;                }                p->pDotI = pCur;            }            else if ( pCur[1] == 'o' && pCur[2] == ' ' )            {                if ( p->pDotO )                {                    fprintf( p->pOutput, "The PLA file contains multiple .o lines.\n" );                    return 0;                }                p->pDotO = pCur;            }            else if ( pCur[1] == 'p' && pCur[2] == ' ' )            {                if ( p->pDotP )                {                    fprintf( p->pOutput, "The PLA file contains multiple .p lines.\n" );                    return 0;                }                p->pDotP = pCur;            }            else if ( pCur[1] == 'i' && pCur[2] == 'l' && pCur[3] == 'b' && pCur[4] == ' ' )            {                if ( p->pDotIlb )                {                    fprintf( p->pOutput, "The PLA file contains multiple .ilb lines.\n" );                    return 0;                }                p->pDotIlb = pCur;            }            else if ( pCur[1] == 'o' && pCur[2] == 'b' && pCur[3] == ' ' )            {                if ( p->pDotOb )                {                    fprintf( p->pOutput, "The PLA file contains multiple .ob lines.\n" );                    return 0;                }                p->pDotOb = pCur;            }            else if ( pCur[1] == 't' && pCur[2] == 'y' && pCur[3] == 'p' && pCur[4] == 'e' && pCur[5] == ' ' )            {                if ( p->pDotType )                {                    fprintf( p->pOutput, "The PLA file contains multiple .type lines.\n" );                    return 0;                }                p->pDotType = pCur;            }            else if ( pCur[1] == 'e' )            {                p->pDotEnd = pCur;                break;            }        }    if ( p->pDotI == NULL )    {        fprintf( p->pOutput, "The PLA file does not contain .i line.\n" );        return 0;    }    if ( p->pDotO == NULL )    {        fprintf( p->pOutput, "The PLA file does not contain .o line.\n" );        return 0;    }    // find the beginning of the table    pCurMax = p->pBuffer;    if ( p->pDotI && pCurMax < p->pDotI )        pCurMax = p->pDotI;    if ( p->pDotO && pCurMax < p->pDotO )        pCurMax = p->pDotO;    if ( p->pDotP && pCurMax < p->pDotP )        pCurMax = p->pDotP;    if ( p->pDotIlb && pCurMax < p->pDotIlb )        pCurMax = p->pDotIlb;    if ( p->pDotOb && pCurMax < p->pDotOb )        pCurMax = p->pDotOb;    if ( p->pDotType && pCurMax < p->pDotType )        pCurMax = p->pDotType;    // go to the next new line symbol    for ( ; *pCurMax; pCurMax++ )        if ( *pCurMax == '\n' )        {            p->pDotStart = pCurMax + 1;            break;        }    return 1;}/**Function*************************************************************  Synopsis    []  Description []                 SideEffects []  SeeAlso     []***********************************************************************/bool Io_ReadPlaHeader( Io_ReadPla_t * p ){    char * pTemp;    int i;    // read .type line    if ( p->pDotType )    {        pTemp = strtok( p->pDotType, " \t\n\r" );        assert( strcmp( p->pDotType, ".type" ) == 0 );        pTemp = strtok( NULL, " \t\n\r" );        if ( strcmp( p->pDotType, "fd" ) != 0 )        {            fprintf( p->pOutput, "The PLA file is of an unsupported type (%s).\n", pTemp );            return 0;        }    }    // get the number of inputs and outputs    pTemp = strtok( p->pDotI, " \t\n\r" );    assert( strcmp( pTemp, ".i" ) == 0 );    pTemp = strtok( NULL, " \t\n\r" );    p->nInputs = atoi( pTemp );    if ( p->nInputs < 1 || p->nInputs > 10000 )    {        fprintf( p->pOutput, "Unrealistic number of inputs in .i line (%d).\n", p->nInputs );        return 0;    }    pTemp = strtok( p->pDotO, " \t\n\r" );    assert( strcmp( pTemp, ".o" ) == 0 );    pTemp = strtok( NULL, " \t\n\r" );    p->nOutputs = atoi( pTemp );    if ( p->nOutputs < 1 || p->nOutputs > 10000 )    {        fprintf( p->pOutput, "Unrealistic number of outputs in .o line (%d).\n", p->nOutputs );        return 0;    }    // store away the input names    if ( p->pDotIlb )    {        p->pNamesIn = ALLOC( char *, p->nInputs );        pTemp = strtok( p->pDotIlb, " \t\n\r" );        assert( strcmp( pTemp, ".ilb" ) == 0 );        for ( i = 0; i < p->nInputs; i++ )        {            p->pNamesIn[i] = strtok( NULL, " \t\n\r" );            if ( p->pNamesIn[i] == NULL )            {                fprintf( p->pOutput, "Insufficient number of input names on .ilb line.\n" );                return 0;            }        }        pTemp = strtok( NULL, " \t\n\r" );        if ( strcmp( pTemp, ".ob" ) )        {            fprintf( p->pOutput, "Trailing symbols on .ilb line (%s).\n", pTemp );            return 0;        }        // overwrite 0 introduced by strtok()        *(pTemp + strlen(pTemp)) = ' ';    }    // store away the output names    if ( p->pDotOb )    {        p->pNamesOut = ALLOC( char *, p->nOutputs );        pTemp = strtok( p->pDotOb, " \t\n\r" );        assert( strcmp( pTemp, ".ob" ) == 0 );        for ( i = 0; i < p->nOutputs; i++ )        {            p->pNamesOut[i] = strtok( NULL, " \t\n\r" );            if ( p->pNamesOut[i] == NULL )            {                fprintf( p->pOutput, "Insufficient number of output names on .ob line.\n" );                return 0;            }        }        pTemp = strtok( NULL, " \t\n\r" );        if ( *pTemp >= 'a' && *pTemp <= 'z' )        {            fprintf( p->pOutput, "Trailing symbols on .ob line (%s).\n", pTemp );            return 0;        }        // overwrite 0 introduced by strtok()        *(pTemp + strlen(pTemp)) = ' ';    }    return 1;}/**Function*************************************************************  Synopsis    []  Description []                 SideEffects []  SeeAlso     []***********************************************************************/bool Io_ReadPlaBody( Io_ReadPla_t * p ){    Mvc_Cube_t * pCube, * pCubeDup;    int nOuts, iPos, iPosOld, i;    char * pfOuts, * pTemp;    // allocate covers    p->ppOns = ALLOC( Mvc_Cover_t *, p->nOutputs );    p->ppDcs = ALLOC( Mvc_Cover_t *, p->nOutputs );    for ( i = 0; i < p->nOutputs; i++ )

⌨️ 快捷键说明

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