abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWriteBaf.c File Reference
#include "ioAbc.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Io_WriteBaf (Abc_Ntk_t *pNtk, char *pFileName)
 DECLARATIONS ///. More...
 

Function Documentation

ABC_NAMESPACE_IMPL_START void Io_WriteBaf ( Abc_Ntk_t pNtk,
char *  pFileName 
)

DECLARATIONS ///.

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

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

Synopsis [Writes the AIG in the binary format.]

Description []

SideEffects []

SeeAlso []

Definition at line 84 of file ioWriteBaf.c.

85 {
86  ProgressBar * pProgress;
87  FILE * pFile;
88  Abc_Obj_t * pObj;
89  int i, nNodes, nAnds, nBufferSize;
90  unsigned * pBufferNode;
91  assert( Abc_NtkIsStrash(pNtk) );
92  // start the output stream
93  pFile = fopen( pFileName, "wb" );
94  if ( pFile == NULL )
95  {
96  fprintf( stdout, "Io_WriteBaf(): Cannot open the output file \"%s\".\n", pFileName );
97  return;
98  }
99 
100  // write the comment
101  fprintf( pFile, "# BAF (Binary Aig Format) for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
102 
103  // write the network name
104  fprintf( pFile, "%s%c", pNtk->pName, 0 );
105  // write the number of PIs
106  fprintf( pFile, "%d%c", Abc_NtkPiNum(pNtk), 0 );
107  // write the number of POs
108  fprintf( pFile, "%d%c", Abc_NtkPoNum(pNtk), 0 );
109  // write the number of latches
110  fprintf( pFile, "%d%c", Abc_NtkLatchNum(pNtk), 0 );
111  // write the number of internal nodes
112  fprintf( pFile, "%d%c", Abc_NtkNodeNum(pNtk), 0 );
113 
114  // write PIs
115  Abc_NtkForEachPi( pNtk, pObj, i )
116  fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
117  // write POs
118  Abc_NtkForEachPo( pNtk, pObj, i )
119  fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
120  // write latches
121  Abc_NtkForEachLatch( pNtk, pObj, i )
122  {
123  fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
124  fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanin0(pObj)), 0 );
125  fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanout0(pObj)), 0 );
126  }
127 
128  // set the node numbers to be used in the output file
129  Abc_NtkCleanCopy( pNtk );
130  nNodes = 1;
131  Abc_NtkForEachCi( pNtk, pObj, i )
132  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)nNodes++;
133  Abc_AigForEachAnd( pNtk, pObj, i )
134  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)nNodes++;
135 
136  // write the nodes into the buffer
137  nAnds = 0;
138  nBufferSize = Abc_NtkNodeNum(pNtk) * 2 + Abc_NtkCoNum(pNtk);
139  pBufferNode = ABC_ALLOC( unsigned, nBufferSize );
140  pProgress = Extra_ProgressBarStart( stdout, nBufferSize );
141  Abc_AigForEachAnd( pNtk, pObj, i )
142  {
143  Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
144  pBufferNode[nAnds++] = (((int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy) << 1) | (int)Abc_ObjFaninC0(pObj);
145  pBufferNode[nAnds++] = (((int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy) << 1) | (int)Abc_ObjFaninC1(pObj);
146  }
147 
148  // write the COs into the buffer
149  Abc_NtkForEachCo( pNtk, pObj, i )
150  {
151  Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
152  pBufferNode[nAnds] = (((int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy) << 1) | (int)Abc_ObjFaninC0(pObj);
153  if ( Abc_ObjFanoutNum(pObj) > 0 && Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
154  pBufferNode[nAnds] = (pBufferNode[nAnds] << 2) | ((int)(ABC_PTRINT_T)Abc_ObjData(Abc_ObjFanout0(pObj)) & 3);
155  nAnds++;
156  }
157  Extra_ProgressBarStop( pProgress );
158  assert( nBufferSize == nAnds );
159 
160  // write the buffer
161  fwrite( pBufferNode, 1, sizeof(int) * nBufferSize, pFile );
162  fclose( pFile );
163  ABC_FREE( pBufferNode );
164 }
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int Abc_NtkCoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:288
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition: abc.h:485
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
DECLARATIONS ///.
Abc_Obj_t * pCopy
Definition: abc.h:148
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Abc_NtkPiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:285
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
char * Extra_TimeStamp()
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
static void * Abc_ObjData(Abc_Obj_t *pObj)
Definition: abc.h:336
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
char * pName
Definition: abc.h:158
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513