src/base/io/ioWriteBaf.c File Reference

#include "io.h"
Include dependency graph for ioWriteBaf.c:

Go to the source code of this file.

Functions

void Io_WriteBaf (Abc_Ntk_t *pNtk, char *pFileName)

Function Documentation

void Io_WriteBaf ( Abc_Ntk_t pNtk,
char *  pFileName 
)

CFile****************************************************************

FileName [ioWriteBaf.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to write AIG in the binary format.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
ioWriteBaf.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

] DECLARATIONS /// FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Writes the AIG in the binary format.]

Description []

SideEffects []

SeeAlso []

Definition at line 81 of file ioWriteBaf.c.

00082 {
00083     ProgressBar * pProgress;
00084     FILE * pFile;
00085     Abc_Obj_t * pObj;
00086     int i, nNodes, nAnds, nBufferSize;
00087     unsigned * pBufferNode;
00088     assert( Abc_NtkIsStrash(pNtk) );
00089     // start the output stream
00090     pFile = fopen( pFileName, "wb" );
00091     if ( pFile == NULL )
00092     {
00093         fprintf( stdout, "Io_WriteBaf(): Cannot open the output file \"%s\".\n", pFileName );
00094         return;
00095     }
00096 
00097     // write the comment
00098     fprintf( pFile, "# BAF (Binary Aig Format) for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00099 
00100     // write the network name
00101     fprintf( pFile, "%s%c", pNtk->pName, 0 );
00102     // write the number of PIs
00103     fprintf( pFile, "%d%c", Abc_NtkPiNum(pNtk), 0 );
00104     // write the number of POs
00105     fprintf( pFile, "%d%c", Abc_NtkPoNum(pNtk), 0 );
00106     // write the number of latches
00107     fprintf( pFile, "%d%c", Abc_NtkLatchNum(pNtk), 0 );
00108     // write the number of internal nodes
00109     fprintf( pFile, "%d%c", Abc_NtkNodeNum(pNtk), 0 );
00110 
00111     // write PIs
00112     Abc_NtkForEachPi( pNtk, pObj, i )
00113         fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
00114     // write POs
00115     Abc_NtkForEachPo( pNtk, pObj, i )
00116         fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
00117     // write latches
00118     Abc_NtkForEachLatch( pNtk, pObj, i )
00119     {
00120         fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
00121         fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanin0(pObj)), 0 );
00122         fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanout0(pObj)), 0 );
00123     }
00124 
00125     // set the node numbers to be used in the output file
00126     Abc_NtkCleanCopy( pNtk );
00127     nNodes = 1;
00128     Abc_NtkForEachCi( pNtk, pObj, i )
00129         pObj->pCopy = (void *)nNodes++;
00130     Abc_AigForEachAnd( pNtk, pObj, i )
00131         pObj->pCopy = (void *)nNodes++;
00132 
00133     // write the nodes into the buffer
00134     nAnds = 0;
00135     nBufferSize = Abc_NtkNodeNum(pNtk) * 2 + Abc_NtkCoNum(pNtk);
00136     pBufferNode = ALLOC( int, nBufferSize );
00137     pProgress = Extra_ProgressBarStart( stdout, nBufferSize );
00138     Abc_AigForEachAnd( pNtk, pObj, i )
00139     {
00140         Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
00141         pBufferNode[nAnds++] = (((int)Abc_ObjFanin0(pObj)->pCopy) << 1) | Abc_ObjFaninC0(pObj);
00142         pBufferNode[nAnds++] = (((int)Abc_ObjFanin1(pObj)->pCopy) << 1) | Abc_ObjFaninC1(pObj);
00143     }
00144 
00145     // write the COs into the buffer
00146     Abc_NtkForEachCo( pNtk, pObj, i )
00147     {
00148         Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
00149         pBufferNode[nAnds] = (((int)Abc_ObjFanin0(pObj)->pCopy) << 1) | Abc_ObjFaninC0(pObj);
00150         if ( Abc_ObjFanoutNum(pObj) > 0 && Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
00151             pBufferNode[nAnds] = (pBufferNode[nAnds] << 2) | ((unsigned)Abc_ObjData(Abc_ObjFanout0(pObj)) & 3);
00152         nAnds++;
00153     }
00154     Extra_ProgressBarStop( pProgress );
00155     assert( nBufferSize == nAnds );
00156 
00157     // write the buffer
00158     fwrite( pBufferNode, 1, sizeof(int) * nBufferSize, pFile );
00159         fclose( pFile );
00160     free( pBufferNode );
00161 }


Generated on Tue Jan 5 12:18:47 2010 for abc70930 by  doxygen 1.6.1