abc/src/base/io/ioWritePla.c

203 lines
6.1 KiB
C
Raw Normal View History

2005-08-09 17:01:00 +02:00
/**CFile****************************************************************
FileName [ioWritePla.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [Procedures to write the network in BENCH format.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: ioWritePla.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
2008-05-08 17:01:00 +02:00
#include "ioAbc.h"
2005-08-09 17:01:00 +02:00
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_START
2005-08-09 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static int Io_WritePlaOne( FILE * pFile, Abc_Ntk_t * pNtk );
////////////////////////////////////////////////////////////////////////
2008-01-31 05:01:00 +01:00
/// FUNCTION DEFINITIONS ///
2005-08-09 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
2005-08-14 17:01:00 +02:00
Synopsis [Writes the network in PLA format.]
2005-08-09 17:01:00 +02:00
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Io_WritePla( Abc_Ntk_t * pNtk, char * pFileName )
{
Abc_Ntk_t * pExdc;
FILE * pFile;
2005-08-29 17:01:00 +02:00
assert( Abc_NtkIsSopNetlist(pNtk) );
2008-01-31 05:01:00 +01:00
assert( Abc_NtkLevel(pNtk) == 1 );
2005-08-09 17:01:00 +02:00
pFile = fopen( pFileName, "w" );
if ( pFile == NULL )
{
fprintf( stdout, "Io_WritePla(): Cannot open the output file.\n" );
return 0;
}
fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
// write the network
Io_WritePlaOne( pFile, pNtk );
// write EXDC network if it exists
pExdc = Abc_NtkExdc( pNtk );
if ( pExdc )
printf( "Io_WritePla: EXDC is not written (warning).\n" );
// finalize the file
fclose( pFile );
return 1;
}
/**Function*************************************************************
2005-08-14 17:01:00 +02:00
Synopsis [Writes the network in PLA format.]
2005-08-09 17:01:00 +02:00
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Io_WritePlaOne( FILE * pFile, Abc_Ntk_t * pNtk )
{
ProgressBar * pProgress;
Abc_Obj_t * pNode, * pFanin, * pDriver;
char * pCubeIn, * pCubeOut, * pCube;
int i, k, nProducts, nInputs, nOutputs, nFanins;
nProducts = 0;
2005-08-12 17:01:00 +02:00
Abc_NtkForEachCo( pNtk, pNode, i )
2005-08-09 17:01:00 +02:00
{
2008-01-31 05:01:00 +01:00
pDriver = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pNode) );
2005-08-09 17:01:00 +02:00
if ( !Abc_ObjIsNode(pDriver) )
{
nProducts++;
continue;
}
if ( Abc_NodeIsConst(pDriver) )
{
if ( Abc_NodeIsConst1(pDriver) )
nProducts++;
continue;
}
2010-11-01 09:35:04 +01:00
nProducts += Abc_SopGetCubeNum((char *)pDriver->pData);
2005-08-09 17:01:00 +02:00
}
// collect the parameters
nInputs = Abc_NtkCiNum(pNtk);
nOutputs = Abc_NtkCoNum(pNtk);
2009-02-15 17:01:00 +01:00
pCubeIn = ABC_ALLOC( char, nInputs + 1 );
pCubeOut = ABC_ALLOC( char, nOutputs + 1 );
2005-08-09 17:01:00 +02:00
memset( pCubeIn, '-', nInputs ); pCubeIn[nInputs] = 0;
memset( pCubeOut, '0', nOutputs ); pCubeOut[nOutputs] = 0;
// write the header
fprintf( pFile, ".i %d\n", nInputs );
fprintf( pFile, ".o %d\n", nOutputs );
fprintf( pFile, ".ilb" );
Abc_NtkForEachCi( pNtk, pNode, i )
2005-08-12 17:01:00 +02:00
fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pNode)) );
2005-08-09 17:01:00 +02:00
fprintf( pFile, "\n" );
fprintf( pFile, ".ob" );
Abc_NtkForEachCo( pNtk, pNode, i )
2005-08-12 17:01:00 +02:00
fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pNode)) );
2005-08-09 17:01:00 +02:00
fprintf( pFile, "\n" );
fprintf( pFile, ".p %d\n", nProducts );
// mark the CI nodes
Abc_NtkForEachCi( pNtk, pNode, i )
2009-02-15 17:01:00 +01:00
pNode->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)i;
2005-08-09 17:01:00 +02:00
// write the cubes
pProgress = Extra_ProgressBarStart( stdout, nOutputs );
Abc_NtkForEachCo( pNtk, pNode, i )
{
// prepare the output cube
if ( i - 1 >= 0 )
pCubeOut[i-1] = '0';
pCubeOut[i] = '1';
// consider special cases of nodes
2008-01-31 05:01:00 +01:00
pDriver = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pNode) );
2005-08-09 17:01:00 +02:00
if ( !Abc_ObjIsNode(pDriver) )
{
2008-01-31 05:01:00 +01:00
assert( Abc_ObjIsCi(pDriver) );
2009-02-15 17:01:00 +01:00
pCubeIn[(int)(ABC_PTRUINT_T)pDriver->pCopy] = '1' - Abc_ObjFaninC0(pNode);
2005-08-09 17:01:00 +02:00
fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
2009-02-15 17:01:00 +01:00
pCubeIn[(int)(ABC_PTRUINT_T)pDriver->pCopy] = '-';
2005-08-09 17:01:00 +02:00
continue;
}
if ( Abc_NodeIsConst(pDriver) )
{
if ( Abc_NodeIsConst1(pDriver) )
fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
continue;
}
2008-01-31 05:01:00 +01:00
// make sure the cover is not complemented
2010-11-01 09:35:04 +01:00
assert( !Abc_SopIsComplement( (char *)pDriver->pData ) );
2008-01-31 05:01:00 +01:00
2005-08-09 17:01:00 +02:00
// write the cubes
nFanins = Abc_ObjFaninNum(pDriver);
2010-11-01 09:35:04 +01:00
Abc_SopForEachCube( (char *)pDriver->pData, nFanins, pCube )
2005-08-09 17:01:00 +02:00
{
Abc_ObjForEachFanin( pDriver, pFanin, k )
2008-01-31 05:01:00 +01:00
{
pFanin = Abc_ObjFanin0Ntk(pFanin);
2009-02-15 17:01:00 +01:00
assert( (int)(ABC_PTRUINT_T)pFanin->pCopy < nInputs );
pCubeIn[(int)(ABC_PTRUINT_T)pFanin->pCopy] = pCube[k];
2008-01-31 05:01:00 +01:00
}
2005-08-09 17:01:00 +02:00
fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
}
// clean the cube for future writing
Abc_ObjForEachFanin( pDriver, pFanin, k )
2008-01-31 05:01:00 +01:00
{
pFanin = Abc_ObjFanin0Ntk(pFanin);
assert( Abc_ObjIsCi(pFanin) );
2009-02-15 17:01:00 +01:00
pCubeIn[(int)(ABC_PTRUINT_T)pFanin->pCopy] = '-';
2008-01-31 05:01:00 +01:00
}
2005-08-09 17:01:00 +02:00
Extra_ProgressBarUpdate( pProgress, i, NULL );
}
Extra_ProgressBarStop( pProgress );
fprintf( pFile, ".e\n" );
// clean the CI nodes
Abc_NtkForEachCi( pNtk, pNode, i )
pNode->pCopy = NULL;
2009-02-15 17:01:00 +01:00
ABC_FREE( pCubeIn );
ABC_FREE( pCubeOut );
2005-08-09 17:01:00 +02:00
return 1;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_END