ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioReadBaf.c File Reference
#include "ioAbc.h"
Include dependency graph for ioReadBaf.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START Abc_Ntk_tIo_ReadBaf (char *pFileName, int fCheck)
 DECLARATIONS ///.
 

Function Documentation

◆ Io_ReadBaf()

ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Io_ReadBaf ( char * pFileName,
int fCheck )

DECLARATIONS ///.

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

FileName [ioReadBaf.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

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

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

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

Synopsis [Reads the AIG in the binary format.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file ioReadBaf.c.

46{
47 ProgressBar * pProgress;
48 FILE * pFile;
49 Vec_Ptr_t * vNodes;
50 Abc_Obj_t * pObj, * pNode0, * pNode1;
51 Abc_Ntk_t * pNtkNew;
52 int nInputs, nOutputs, nLatches, nAnds, nFileSize, Num, i;
53 char * pContents, * pName, * pCur;
54 unsigned * pBufferNode;
55 int RetValue;
56
57 // read the file into the buffer
58 nFileSize = Extra_FileSize( pFileName );
59 pFile = fopen( pFileName, "rb" );
60 pContents = ABC_ALLOC( char, nFileSize );
61 RetValue = fread( pContents, nFileSize, 1, pFile );
62 fclose( pFile );
63
64 // skip the comments (comment lines begin with '#' and end with '\n')
65 for ( pCur = pContents; *pCur == '#'; )
66 while ( *pCur++ != '\n' );
67
68 // read the name
69 pName = pCur; while ( *pCur++ );
70 // read the number of inputs
71 nInputs = atoi( pCur ); while ( *pCur++ );
72 // read the number of outputs
73 nOutputs = atoi( pCur ); while ( *pCur++ );
74 // read the number of latches
75 nLatches = atoi( pCur ); while ( *pCur++ );
76 // read the number of nodes
77 nAnds = atoi( pCur ); while ( *pCur++ );
78
79 // allocate the empty AIG
81 pNtkNew->pName = Extra_UtilStrsav( pName );
82 pNtkNew->pSpec = Extra_UtilStrsav( pFileName );
83
84 // prepare the array of nodes
85 vNodes = Vec_PtrAlloc( 1 + nInputs + nLatches + nAnds );
86 Vec_PtrPush( vNodes, Abc_AigConst1(pNtkNew) );
87
88 // create the PIs
89 for ( i = 0; i < nInputs; i++ )
90 {
91 pObj = Abc_NtkCreatePi(pNtkNew);
92 Abc_ObjAssignName( pObj, pCur, NULL ); while ( *pCur++ );
93 Vec_PtrPush( vNodes, pObj );
94 }
95 // create the POs
96 for ( i = 0; i < nOutputs; i++ )
97 {
98 pObj = Abc_NtkCreatePo(pNtkNew);
99 Abc_ObjAssignName( pObj, pCur, NULL ); while ( *pCur++ );
100 }
101 // create the latches
102 for ( i = 0; i < nLatches; i++ )
103 {
104 pObj = Abc_NtkCreateLatch(pNtkNew);
105 Abc_ObjAssignName( pObj, pCur, NULL ); while ( *pCur++ );
106
107 pNode0 = Abc_NtkCreateBi(pNtkNew);
108 Abc_ObjAssignName( pNode0, pCur, NULL ); while ( *pCur++ );
109
110 pNode1 = Abc_NtkCreateBo(pNtkNew);
111 Abc_ObjAssignName( pNode1, pCur, NULL ); while ( *pCur++ );
112 Vec_PtrPush( vNodes, pNode1 );
113
114 Abc_ObjAddFanin( pObj, pNode0 );
115 Abc_ObjAddFanin( pNode1, pObj );
116 }
117
118 // get the pointer to the beginning of the node array
119 pBufferNode = (unsigned *)(pContents + (nFileSize - (2 * nAnds + nOutputs + nLatches) * sizeof(int)) );
120 // make sure we are at the place where the nodes begin
121 if ( pBufferNode != (unsigned *)pCur )
122 {
123 ABC_FREE( pContents );
124 Vec_PtrFree( vNodes );
125 Abc_NtkDelete( pNtkNew );
126 printf( "Warning: Internal reader error.\n" );
127 return NULL;
128 }
129
130 // create the AND gates
131 pProgress = Extra_ProgressBarStart( stdout, nAnds );
132 for ( i = 0; i < nAnds; i++ )
133 {
134 Extra_ProgressBarUpdate( pProgress, i, NULL );
135 pNode0 = Abc_ObjNotCond( (Abc_Obj_t *)Vec_PtrEntry(vNodes, pBufferNode[2*i+0] >> 1), pBufferNode[2*i+0] & 1 );
136 pNode1 = Abc_ObjNotCond( (Abc_Obj_t *)Vec_PtrEntry(vNodes, pBufferNode[2*i+1] >> 1), pBufferNode[2*i+1] & 1 );
137 Vec_PtrPush( vNodes, Abc_AigAnd((Abc_Aig_t *)pNtkNew->pManFunc, pNode0, pNode1) );
138 }
139 Extra_ProgressBarStop( pProgress );
140
141 // read the POs
142 Abc_NtkForEachCo( pNtkNew, pObj, i )
143 {
144 Num = pBufferNode[2*nAnds+i];
145 if ( Abc_ObjFanoutNum(pObj) > 0 && Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
146 {
147 Abc_ObjSetData( Abc_ObjFanout0(pObj), (void *)(ABC_PTRINT_T)(Num & 3) );
148 Num >>= 2;
149 }
150 pNode0 = Abc_ObjNotCond( (Abc_Obj_t *)Vec_PtrEntry(vNodes, Num >> 1), Num & 1 );
151 Abc_ObjAddFanin( pObj, pNode0 );
152 }
153 ABC_FREE( pContents );
154 Vec_PtrFree( vNodes );
155
156 // remove the extra nodes
157// Abc_AigCleanup( (Abc_Aig_t *)pNtkNew->pManFunc );
158
159 // check the result
160 if ( fCheck && !Abc_NtkCheckRead( pNtkNew ) )
161 {
162 printf( "Io_ReadBaf: The network check has failed.\n" );
163 Abc_NtkDelete( pNtkNew );
164 return NULL;
165 }
166 return pNtkNew;
167
168}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL int Abc_NtkCheckRead(Abc_Ntk_t *pNtk)
Definition abcCheck.c:80
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition abcNames.c:69
@ ABC_NTK_STRASH
Definition abc.h:58
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:700
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_AIG
Definition abc.h:67
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
int Extra_FileSize(char *pFileName)
void Extra_ProgressBarStop(ProgressBar *p)
char * Extra_UtilStrsav(const char *s)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
char * pSpec
Definition abc.h:159
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:
Here is the caller graph for this function: