ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlnNdr.c
Go to the documentation of this file.
1
20
21#include "wln.h"
22#include "aig/miniaig/ndr.h"
23
25
29
33
46{
47 Vec_Int_t * vFanins;
48 int i, k, iObj, iFanin;
49 // create a new module
50 void * pDesign = Ndr_Create( 1 );
51 int ModId = Ndr_AddModule( pDesign, 1 );
52 // add primary inputs
53 Wln_NtkForEachPi( p, iObj, i )
54 {
55 Ndr_AddObject( pDesign, ModId, ABC_OPER_CI, 0,
56 Wln_ObjRangeEnd(p, iObj), Wln_ObjRangeBeg(p, iObj), Wln_ObjIsSigned(p, iObj),
57 0, NULL, 1, &iObj, NULL ); // no fanins
58 }
59 // add internal nodes
60 vFanins = Vec_IntAlloc( 10 );
62 {
63 Vec_IntClear( vFanins );
64 Wln_ObjForEachFanin( p, iObj, iFanin, k )
65 Vec_IntPush( vFanins, iFanin );
66 Ndr_AddObject( pDesign, ModId, Wln_ObjType(p, iObj), 0,
67 Wln_ObjRangeEnd(p, iObj), Wln_ObjRangeBeg(p, iObj), Wln_ObjIsSigned(p, iObj),
68 Vec_IntSize(vFanins), Vec_IntArray(vFanins), 1, &iObj,
69 Wln_ObjIsConst(p, iObj) ? Wln_ObjConstString(p, iObj) : NULL );
70 }
71 Vec_IntFree( vFanins );
72 // add primary outputs
73 Wln_NtkForEachPo( p, iObj, i )
74 {
75 Ndr_AddObject( pDesign, ModId, ABC_OPER_CO, 0,
76 Wln_ObjRangeEnd(p, iObj), Wln_ObjRangeBeg(p, iObj), Wln_ObjIsSigned(p, iObj),
77 1, &iObj, 0, NULL, NULL );
78 }
79 return pDesign;
80}
81void Wln_WriteNdr( Wln_Ntk_t * p, char * pFileName )
82{
83 void * pDesign = Wln_NtkToNdr( p );
84 Ndr_Write( pFileName, pDesign );
85 Ndr_Delete( pDesign );
86 printf( "Dumped the current design into file \"%s\".\n", pFileName );
87}
89{
90 // transform
91 void * pDesign = Wln_NtkToNdr( p );
92
93 // collect names
94 char ** ppNames = ABC_ALLOC( char *, Wln_NtkObjNum(p) + 1 ); int i;
95 Wln_NtkForEachObj( p, i )
96 ppNames[i] = Abc_UtilStrsav(Wln_ObjName(p, i));
97
98 // verify by writing Verilog
99 Ndr_WriteVerilog( NULL, pDesign, ppNames, 0 );
100 Ndr_Write( "test.ndr", pDesign );
101
102 // cleanup
103 Ndr_Delete( pDesign );
104 Wln_NtkForEachObj( p, i )
105 ABC_FREE( ppNames[i] );
106 ABC_FREE( ppNames );
107}
108
120int Ndr_ObjGetRange( Ndr_Data_t * p, int Obj, int * End, int * Beg )
121{
122 int * pArray, nArray = Ndr_ObjReadArray( p, Obj, NDR_RANGE, &pArray );
123 int Signed = 0; *End = *Beg = 0;
124 if ( nArray == 0 )
125 return 0;
126 if ( nArray == 3 )
127 Signed = 1;
128 if ( nArray == 1 )
129 *End = *Beg = pArray[0];
130 else
131 *End = pArray[0], *Beg = pArray[1];
132 return Signed;
133}
135{
136 int k, iObj, iFanin;
137 printf( "Node IDs and their fanins:\n" );
138 Wln_NtkForEachObj( pNtk, iObj )
139 {
140 printf( "%5d = ", iObj );
141 Wln_ObjForEachFanin( pNtk, iObj, iFanin, k )
142 printf( "%5d ", iFanin );
143 for ( ; k < 4; k++ )
144 printf( " " );
145 printf( " Name Id %d ", Wln_ObjNameId(pNtk, iObj) );
146 if ( Wln_ObjIsPi(pNtk, iObj) )
147 printf( " pi " );
148 if ( Wln_ObjIsPo(pNtk, iObj) )
149 printf( " po " );
150 printf( "\n" );
151 }
152}
153void Wln_NtkCheckIntegrity( void * pData )
154{
155 Ndr_Data_t * p = (Ndr_Data_t *)pData;
156 Vec_Int_t * vMap = Vec_IntAlloc( 100 );
157 int Mod = 2, Obj;
158 Ndr_ModForEachObj( p, Mod, Obj )
159 {
160 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
161 if ( NameId == -1 )
162 {
163 int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
164 if ( Type != ABC_OPER_CO )
165 printf( "Internal object %d of type %s has no output name.\n", Obj, Abc_OperName(Type) );
166 continue;
167 }
168 if ( Vec_IntGetEntry(vMap, NameId) > 0 )
169 printf( "Output name %d is used more than once (obj %d and obj %d).\n", NameId, Vec_IntGetEntry(vMap, NameId), Obj );
170 Vec_IntSetEntry( vMap, NameId, Obj );
171 }
172 Ndr_ModForEachObj( p, Mod, Obj )
173 {
174 int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
175 int i, * pArray, nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
176 for ( i = 0; i < nArray; i++ )
177 if ( Vec_IntGetEntry(vMap, pArray[i]) == 0 && !(Type == ABC_OPER_DFFRSE && (i >= 5 && i <= 7)) )
178 printf( "Input name %d appearing as fanin %d of obj %d is not used as output name in any object.\n", pArray[i], i, Obj );
179 }
180 Vec_IntFree( vMap );
181}
182Wln_Ntk_t * Wln_NtkFromNdr( void * pData, int fDump )
183{
184 Ndr_Data_t * p = (Ndr_Data_t *)pData;
185 Vec_Int_t * vName2Obj, * vFanins = Vec_IntAlloc( 100 );
186 Vec_Ptr_t * vConstStrings = Vec_PtrAlloc( 100 );
187 int Mod = 2, i, k, iFanin, iObj, Obj, * pArray, nDigits, fFound, NameId, NameIdMax;
188 Wln_Ntk_t * pTemp, * pNtk = Wln_NtkAlloc( "top", Ndr_DataObjNum(p, Mod) );
189 Wln_NtkCheckIntegrity( pData );
190 //pNtk->pSpec = Abc_UtilStrsav( pFileName );
191 // construct network and save name IDs
192 Wln_NtkCleanNameId( pNtk );
193 Wln_NtkCleanInstId( pNtk );
194 Ndr_ModForEachPi( p, Mod, Obj )
195 {
196 int End, Beg, Signed = Ndr_ObjGetRange(p, Obj, &End, &Beg);
197 int iObj = Wln_ObjAlloc( pNtk, ABC_OPER_CI, Signed, End, Beg );
198 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
199 int InstId = Ndr_ObjReadBody( p, Obj, NDR_NAME );
200 Wln_ObjSetNameId( pNtk, iObj, NameId );
201 if ( InstId > 0 ) Wln_ObjSetInstId( pNtk, iObj, InstId );
202 }
203 Ndr_ModForEachNode( p, Mod, Obj )
204 {
205 int End, Beg, Signed = Ndr_ObjGetRange(p, Obj, &End, &Beg);
206 int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
207 int nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
208 Vec_Int_t F = {nArray, nArray, pArray}, * vTemp = &F;
209 int iObj = Wln_ObjAlloc( pNtk, Type, Signed, End, Beg );
210 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
211 int InstId = Ndr_ObjReadBody( p, Obj, NDR_NAME );
212 Vec_IntClear( vFanins );
213 Vec_IntAppend( vFanins, vTemp );
214 assert( Type != ABC_OPER_DFF );
215 if ( Wln_ObjIsSlice(pNtk, iObj) )
216 Wln_ObjSetSlice( pNtk, iObj, Hash_Int2ManInsert(pNtk->pRanges, End, Beg, 0) );
217 else if ( Wln_ObjIsConst(pNtk, iObj) )
218 Vec_PtrPush( vConstStrings, (char *)Ndr_ObjReadBodyP(p, Obj, NDR_FUNCTION) );
219// else if ( Type == ABC_OPER_BIT_MUX && Vec_IntSize(vFanins) == 3 )
220// ABC_SWAP( int, Wln_ObjFanins(pNtk, iObj)[1], Wln_ObjFanins(pNtk, iObj)[2] );
221 Wln_ObjAddFanins( pNtk, iObj, vFanins );
222 Wln_ObjSetNameId( pNtk, iObj, NameId );
223 if ( InstId > 0 ) Wln_ObjSetInstId( pNtk, iObj, InstId );
224 if ( Type == ABC_OPER_ARI_SMUL )
225 {
226 assert( Wln_ObjFaninNum(pNtk, iObj) == 2 );
227 Wln_ObjSetSigned( pNtk, Wln_ObjFanin0(pNtk, iObj) );
228 Wln_ObjSetSigned( pNtk, Wln_ObjFanin1(pNtk, iObj) );
229 }
230 }
231 // mark primary outputs
232 Ndr_ModForEachPo( p, Mod, Obj )
233 {
234 int End, Beg, Signed = Ndr_ObjGetRange(p, Obj, &End, &Beg);
235 int nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
236 int iObj = Wln_ObjAlloc( pNtk, ABC_OPER_CO, Signed, End, Beg );
237 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
238 int InstId = Ndr_ObjReadBody( p, Obj, NDR_NAME );
239 assert( nArray == 1 && NameId == -1 && InstId == -1 );
240 Wln_ObjAddFanin( pNtk, iObj, pArray[0] );
241 }
242 Vec_IntFree( vFanins );
243 // remove instance names if they are not given
244 //Vec_IntPrint( &pNtk->vInstIds );
245 if ( Vec_IntCountPositive(&pNtk->vInstIds) == 0 )
246 Vec_IntErase( &pNtk->vInstIds );
247 // map name IDs into object IDs
248 vName2Obj = Vec_IntInvert( &pNtk->vNameIds, 0 );
249 Wln_NtkForEachObj( pNtk, i )
250 Wln_ObjForEachFanin( pNtk, i, iFanin, k )
251 Wln_ObjSetFanin( pNtk, i, k, Vec_IntEntry(vName2Obj, iFanin) );
252 Vec_IntFree(vName2Obj);
253 // create fake object names
254 NameIdMax = Vec_IntFindMax(&pNtk->vNameIds);
255 nDigits = Abc_Base10Log( NameIdMax+1 );
256 pNtk->pManName = Abc_NamStart( NameIdMax+1, 10 );
257 for ( i = 1; i <= NameIdMax; i++ )
258 {
259 char pName[1000]; sprintf( pName, "s%0*d", (unsigned char)nDigits, i );
260 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pName, &fFound );
261 assert( !fFound && i == NameId );
262 }
263 // add const strings
264 i = 0;
265 Wln_NtkForEachObj( pNtk, iObj )
266 if ( Wln_ObjIsConst(pNtk, iObj) )
267 Wln_ObjSetConst( pNtk, iObj, Abc_NamStrFindOrAdd(pNtk->pManName, (char *)Vec_PtrEntry(vConstStrings, i++), NULL) );
268 assert( i == Vec_PtrSize(vConstStrings) );
269 Vec_PtrFree( vConstStrings );
270 //Ndr_NtkPrintObjects( pNtk );
271 Wln_WriteVer( pNtk, "temp_ndr.v" );
272 printf( "Dumped design \"%s\" into file \"temp_ndr.v\".\n", pNtk->pName );
273 if ( !Wln_NtkIsAcyclic(pNtk) )
274 {
275 Wln_NtkFree(pNtk);
276 return NULL;
277 }
278 // derive topological order
279 pNtk = Wln_NtkDupDfs( pTemp = pNtk );
280 Wln_NtkFree( pTemp );
281 //Ndr_NtkPrintObjects( pNtk );
282 //pNtk->fMemPorts = 1; // the network contains memory ports
283 //pNtk->fEasyFfs = 1; // the network contains simple flops
284 return pNtk;
285}
286
298Wln_Ntk_t * Wln_ReadNdr( char * pFileName )
299{
300 void * pData = Ndr_Read( pFileName );
301 Wln_Ntk_t * pNtk = pData ? Wln_NtkFromNdr( pData, 0 ) : NULL;
302 if ( pNtk ) return NULL;
303 //char * ppNames[10] = { NULL, "a", "b", "c", "d", "e", "f", "g", "h", "i" };
304 //Ndr_WriteVerilog( NULL, pData, ppNames, 0 );
305 Ndr_Delete( pData );
306 return pNtk;
307}
309{
310 Wln_Ntk_t * pNtk = Wln_ReadNdr( "D:\\temp\\brijesh\\for_alan_dff_warning\\work_fir_filter_fir_filter_proc_out.ndr" );
311 //Wln_Ntk_t * pNtk = Wln_ReadNdr( "flop.ndr" );
312 Wln_WriteVer( pNtk, "test__test.v" );
313 Wln_NtkPrint( pNtk );
315 Wln_NtkFree( pNtk );
316}
317void Wln_NtkRetimeTest( char * pFileName, int fIgnoreIO, int fSkipSimple, int fDump, int fVerbose )
318{
319 Vec_Int_t * vMoves;
320 void * pData = Ndr_Read( pFileName );
321 Wln_Ntk_t * pNtk = pData ? Wln_NtkFromNdr( pData, fDump ) : NULL;
322 Ndr_Delete( pData );
323 if ( pNtk == NULL )
324 {
325 printf( "Retiming network is not available.\n" );
326 return;
327 }
329 vMoves = Wln_NtkRetime( pNtk, fIgnoreIO, fSkipSimple, fVerbose );
330 //Vec_IntPrint( vMoves );
331 Vec_IntFree( vMoves );
332 Wln_NtkFree( pNtk );
333}
334
338
339
341
@ ABC_OPER_DFF
Definition abcOper.h:142
@ ABC_OPER_ARI_SMUL
Definition abcOper.h:102
@ ABC_OPER_CI
Definition abcOper.h:45
@ ABC_OPER_DFFRSE
Definition abcOper.h:143
@ ABC_OPER_CO
Definition abcOper.h:46
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
@ NDR_RANGE
Definition ndr.h:107
@ NDR_INPUT
Definition ndr.h:103
@ NDR_FUNCTION
Definition ndr.h:108
@ NDR_NAME
Definition ndr.h:106
@ NDR_OPERTYPE
Definition ndr.h:105
@ NDR_OUTPUT
Definition ndr.h:104
#define Ndr_ModForEachObj(p, Mod, Obj)
Definition ndr.h:147
struct Ndr_Data_t_ Ndr_Data_t
BASIC TYPES ///.
Definition ndr.h:119
#define Ndr_ModForEachPo(p, Mod, Obj)
Definition ndr.h:159
#define Ndr_ModForEachPi(p, Mod, Obj)
Definition ndr.h:155
#define Ndr_ModForEachNode(p, Mod, Obj)
Definition ndr.h:163
Hash_IntMan_t * pRanges
Definition wln.h:67
Vec_Int_t vInstIds
Definition wln.h:69
Vec_Int_t vNameIds
Definition wln.h:68
Abc_Nam_t * pManName
Definition wln.h:70
char * pName
Definition wln.h:58
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
Definition utilNam.c:453
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
Definition utilNam.c:80
#define assert(ex)
Definition util_old.h:213
char * sprintf()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Wln_Ntk_t * Wln_ReadNdr(char *pFileName)
FUNCTION DECLARATIONS ///.
Definition wlnNdr.c:298
int Ndr_ObjGetRange(Ndr_Data_t *p, int Obj, int *End, int *Beg)
Definition wlnNdr.c:120
void Ndr_NtkPrintObjects(Wln_Ntk_t *pNtk)
Definition wlnNdr.c:134
Wln_Ntk_t * Wln_NtkFromNdr(void *pData, int fDump)
Definition wlnNdr.c:182
void Wln_NtkRetimeTest(char *pFileName, int fIgnoreIO, int fSkipSimple, int fDump, int fVerbose)
Definition wlnNdr.c:317
void Wln_NtkToNdrTest(Wln_Ntk_t *p)
Definition wlnNdr.c:88
void Wln_ReadNdrTest()
Definition wlnNdr.c:308
void Wln_WriteNdr(Wln_Ntk_t *p, char *pFileName)
Definition wlnNdr.c:81
void Wln_NtkCheckIntegrity(void *pData)
Definition wlnNdr.c:153
ABC_NAMESPACE_IMPL_START void * Wln_NtkToNdr(Wln_Ntk_t *p)
DECLARATIONS ///.
Definition wlnNdr.c:45
void Wln_NtkStaticFanoutTest(Wln_Ntk_t *p)
Definition wlnNtk.c:428
void Wln_WriteVer(Wln_Ntk_t *p, char *pFileName)
void Wln_ObjSetSlice(Wln_Ntk_t *p, int iObj, int SliceId)
Definition wlnObj.c:70
int Wln_NtkIsAcyclic(Wln_Ntk_t *p)
Definition wlnNtk.c:192
Wln_Ntk_t * Wln_NtkDupDfs(Wln_Ntk_t *p)
Definition wlnNtk.c:325
#define Wln_NtkForEachObjInternal(p, i)
Definition wln.h:191
Vec_Int_t * Wln_NtkRetime(Wln_Ntk_t *p, int fIgnoreIO, int fSkipSimple, int fVerbose)
Definition wlnRetime.c:718
#define Wln_ObjForEachFanin(p, iObj, iFanin, i)
Definition wln.h:205
#define Wln_NtkForEachPo(p, iPo, i)
Definition wln.h:196
void Wln_ObjAddFanin(Wln_Ntk_t *p, int iObj, int i)
Definition wlnObj.c:75
char * Wln_ObjConstString(Wln_Ntk_t *p, int iObj)
Definition wlnObj.c:53
char * Wln_ObjName(Wln_Ntk_t *p, int iObj)
DECLARATIONS ///.
Definition wlnObj.c:45
void Wln_NtkFree(Wln_Ntk_t *p)
Definition wlnNtk.c:68
void Wln_NtkRetimeCreateDelayInfo(Wln_Ntk_t *pNtk)
Definition wlnRetime.c:592
#define Wln_NtkForEachPi(p, iPi, i)
Definition wln.h:194
int Wln_ObjAlloc(Wln_Ntk_t *p, int Type, int Signed, int End, int Beg)
Definition wlnObj.c:105
struct Wln_Ntk_t_ Wln_Ntk_t
Definition wln.h:55
void Wln_ObjSetConst(Wln_Ntk_t *p, int iObj, int NameId)
Definition wlnObj.c:65
#define Wln_NtkForEachObj(p, i)
MACRO DEFINITIONS ///.
Definition wln.h:187
Wln_Ntk_t * Wln_NtkAlloc(char *pName, int nObjsMax)
DECLARATIONS ///.
Definition wlnNtk.c:45
void Wln_NtkPrint(Wln_Ntk_t *p)
Definition wlnNtk.c:123
int Wln_ObjAddFanins(Wln_Ntk_t *p, int iObj, Vec_Int_t *vFanins)
Definition wlnObj.c:98