ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
bacPrs.h
Go to the documentation of this file.
1
20
21#ifndef ABC__base__prs__prs_h
22#define ABC__base__prs__prs_h
23
24
28
29#include "aig/gia/gia.h"
30#include "misc/util/utilNam.h"
31
35
37
38// parser name types
39typedef enum {
40 BAC_PRS_NAME = 0, // 0: name/variable
41 BAC_PRS_SLICE, // 1: slice
42 BAC_PRS_CONST, // 2: constant
43 BAC_PRS_CONCAT, // 3: concatentation
45
49
50// network
51typedef struct Psr_Ntk_t_ Psr_Ntk_t;
53{
54 // general info
56 unsigned fMapped : 1;
57 unsigned fSlices : 1;
58 unsigned fHasC0s : 1;
59 unsigned fHasC1s : 1;
60 unsigned fHasCXs : 1;
61 unsigned fHasCZs : 1;
63 // interface
64 Vec_Int_t vOrder; // order of signals
65 // signal names
66 Vec_Int_t vInouts; // inouts
67 Vec_Int_t vInputs; // inputs
68 Vec_Int_t vOutputs; // outputs
69 Vec_Int_t vWires; // wires
70 // signal ranges
71 Vec_Int_t vInoutsR; // inouts
72 Vec_Int_t vInputsR; // inputs
73 Vec_Int_t vOutputsR; // outputs
74 Vec_Int_t vWiresR; // wires
75 // slices/concatenations/objects
76 Vec_Int_t vSlices; // NameId + RangeId
77 Vec_Int_t vConcats; // array of NameId/SliceId/ConstId
78 Vec_Int_t vBoxes; // ModuleId + InstId + array of pairs {FormNameId, ActSignalId(NameId/SliceId/ConstId/ConcatId)}
79 Vec_Int_t vObjs; // box handles
80};
81
82// parser
83typedef struct Psr_Man_t_ Psr_Man_t;
85{
86 // input data
87 char * pName; // file name
88 char * pBuffer; // file contents
89 char * pLimit; // end of file
90 char * pCur; // current position
91 Abc_Nam_t * pStrs; // string manager
92 Psr_Ntk_t * pNtk; // current network
93 Vec_Ptr_t * vNtks; // input networks
94 // temporary data
95 Vec_Str_t vCover; // one SOP cover
96 Vec_Int_t vTemp; // array of tokens
97 Vec_Int_t vTemp2; // array of tokens
98 // statistics
102 // error handling
103 int fUsingTemp2; // vTemp2 is in use
104 char ErrorStr[1000]; // error
105};
106
107static inline Psr_Ntk_t * Psr_ManNtk( Vec_Ptr_t * vPrs, int i ) { return i >= 0 && i < Vec_PtrSize(vPrs) ? (Psr_Ntk_t *)Vec_PtrEntry(vPrs, i) : NULL; }
108static inline Psr_Ntk_t * Psr_ManRoot( Vec_Ptr_t * vPrs ) { return Psr_ManNtk(vPrs, 0); }
109static inline Abc_Nam_t * Psr_ManNameMan( Vec_Ptr_t * vPrs ) { return Psr_ManRoot(vPrs)->pStrs; }
110
111static inline int Psr_NtkId( Psr_Ntk_t * p ) { return p->iModuleName; }
112static inline int Psr_NtkPioNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vInouts); }
113static inline int Psr_NtkPiNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vInputs); }
114static inline int Psr_NtkPoNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vOutputs); }
115static inline int Psr_NtkBoxNum( Psr_Ntk_t * p ) { return Vec_IntSize(&p->vObjs); }
116static inline int Psr_NtkObjNum( Psr_Ntk_t * p ) { return Psr_NtkPioNum(p) + Psr_NtkPiNum(p) + Psr_NtkPoNum(p) + Psr_NtkBoxNum(p); }
117static inline char * Psr_NtkStr( Psr_Ntk_t * p, int h ) { return Abc_NamStr(p->pStrs, h); }
118static inline char * Psr_NtkName( Psr_Ntk_t * p ) { return Psr_NtkStr(p, Psr_NtkId(p)); }
119static inline int Psr_NtkSigName( Psr_Ntk_t * p, int i ) { if (!p->fSlices) return i; assert(Abc_Lit2Att2(i) == BAC_PRS_NAME); return Abc_Lit2Var2(i); }
120
121static inline int Psr_SliceName( Psr_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vSlices, h); }
122static inline int Psr_SliceRange( Psr_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vSlices, h+1); }
123
124static inline int Psr_CatSize( Psr_Ntk_t * p, int h ) { return Vec_IntEntry(&p->vConcats, h); }
125static inline int * Psr_CatArray( Psr_Ntk_t * p, int h ) { return Vec_IntEntryP(&p->vConcats, h+1); }
126static inline Vec_Int_t * Psr_CatSignals( Psr_Ntk_t * p, int h ) { static Vec_Int_t V; V.nSize = V.nCap = Psr_CatSize(p, h); V.pArray = Psr_CatArray(p, h); return &V; }
127
128static inline int Psr_BoxHand( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vObjs, i); }
129static inline int Psr_BoxSize( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i))-2; }
130static inline int Psr_BoxIONum( Psr_Ntk_t * p, int i ) { return Psr_BoxSize(p, i) / 2; }
131static inline int Psr_BoxNtk( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i)+1); }
132static inline void Psr_BoxSetNtk( Psr_Ntk_t * p, int i, int m ) { Vec_IntWriteEntry(&p->vBoxes, Psr_BoxHand(p, i)+1, m); }
133static inline int Psr_BoxName( Psr_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i)+2); }
134static inline int Psr_BoxIsNode( Psr_Ntk_t * p, int i ) { return!Vec_IntEntry(&p->vBoxes, Psr_BoxHand(p, i)+3); } // no formal names
135static inline int * Psr_BoxArray( Psr_Ntk_t * p, int i ) { return Vec_IntEntryP(&p->vBoxes, Psr_BoxHand(p, i)+3); }
136static inline Vec_Int_t * Psr_BoxSignals( Psr_Ntk_t * p, int i ) { static Vec_Int_t V; V.nSize = V.nCap = Psr_BoxSize(p, i); V.pArray = Psr_BoxArray(p, i); return &V; }
137
138#define Psr_ManForEachNameVec( vVec, p, pName, i ) \
139 for ( i = 0; (i < Vec_IntSize(vVec)) && ((pName) = Abc_NamStr(p->pStrs, Vec_IntEntry(vVec,i))); i++ )
140
141#define Psr_NtkForEachPio( p, NameId, i ) \
142 for ( i = 0; i < Psr_NtkPioNum(p) && ((NameId) = Vec_IntEntry(&p->vInouts, i)); i++ )
143#define Psr_NtkForEachPi( p, NameId, i ) \
144 for ( i = 0; i < Psr_NtkPiNum(p) && ((NameId) = Vec_IntEntry(&p->vInputs, i)); i++ )
145#define Psr_NtkForEachPo( p, NameId, i ) \
146 for ( i = 0; i < Psr_NtkPoNum(p) && ((NameId) = Vec_IntEntry(&p->vOutputs, i)); i++ )
147#define Psr_NtkForEachBox( p, vVec, i ) \
148 for ( i = 0; i < Psr_NtkBoxNum(p) && ((vVec) = Psr_BoxSignals(p, i)); i++ )
149
153
154// create error message
155static inline int Psr_ManErrorSet( Psr_Man_t * p, char * pError, int Value )
156{
157 assert( !p->ErrorStr[0] );
158 sprintf( p->ErrorStr, "%s", pError );
159 return Value;
160}
161// clear error message
162static inline void Psr_ManErrorClear( Psr_Man_t * p )
163{
164 p->ErrorStr[0] = '\0';
165}
166// print error message
167static inline int Psr_ManErrorPrint( Psr_Man_t * p )
168{
169 char * pThis; int iLine = 0;
170 if ( !p->ErrorStr[0] ) return 1;
171 for ( pThis = p->pBuffer; pThis < p->pCur; pThis++ )
172 iLine += (int)(*pThis == '\n');
173 printf( "Line %d: %s\n", iLine, p->ErrorStr );
174 return 0;
175}
176
177// parsing network
178static inline void Psr_ManInitializeNtk( Psr_Man_t * p, int iName, int fSlices )
179{
180 assert( p->pNtk == NULL );
181 p->pNtk = ABC_CALLOC( Psr_Ntk_t, 1 );
182 p->pNtk->iModuleName = iName;
183 p->pNtk->fSlices = fSlices;
184 p->pNtk->pStrs = Abc_NamRef( p->pStrs );
185 Vec_PtrPush( p->vNtks, p->pNtk );
186}
187static inline void Psr_ManFinalizeNtk( Psr_Man_t * p )
188{
189 assert( p->pNtk != NULL );
190 p->pNtk = NULL;
191}
192
193// parsing slice/concatentation/box
194static inline int Psr_NtkAddSlice( Psr_Ntk_t * p, int Name, int Range )
195{
196 int Value = Vec_IntSize(&p->vSlices);
197 Vec_IntPushTwo( &p->vSlices, Name, Range );
198 return Value;
199}
200static inline int Psr_NtkAddConcat( Psr_Ntk_t * p, Vec_Int_t * vTemp )
201{
202 int Value;
203 if ( !(Vec_IntSize(&p->vConcats) & 1) )
204 Vec_IntPush(&p->vConcats, -1);
205 Value = Vec_IntSize(&p->vConcats);
206 assert( Value & 1 );
207 Vec_IntPush( &p->vConcats, Vec_IntSize(vTemp) );
208 Vec_IntAppend( &p->vConcats, vTemp );
209 return Value;
210}
211static inline void Psr_NtkAddBox( Psr_Ntk_t * p, int ModName, int InstName, Vec_Int_t * vTemp )
212{
213 int Value;
214 assert( Vec_IntSize(vTemp) % 2 == 0 );
215 if ( !(Vec_IntSize(&p->vBoxes) & 1) )
216 Vec_IntPush(&p->vBoxes, -1);
217 Value = Vec_IntSize(&p->vBoxes);
218 assert( Value & 1 );
219 Vec_IntPush( &p->vObjs, Value );
220 // create entry
221 Vec_IntPush( &p->vBoxes, Vec_IntSize(vTemp)+2 );
222 Vec_IntPush( &p->vBoxes, ModName );
223 Vec_IntPush( &p->vBoxes, InstName );
224 Vec_IntAppend( &p->vBoxes, vTemp );
225}
226
227
228static inline char * Psr_ManLoadFile( char * pFileName, char ** ppLimit )
229{
230 char * pBuffer;
231 int nFileSize, RetValue;
232 FILE * pFile = fopen( pFileName, "rb" );
233 if ( pFile == NULL )
234 {
235 printf( "Cannot open input file.\n" );
236 return NULL;
237 }
238 // get the file size, in bytes
239 fseek( pFile, 0, SEEK_END );
240 nFileSize = ftell( pFile );
241 // move the file current reading position to the beginning
242 rewind( pFile );
243 // load the contents of the file into memory
244 pBuffer = ABC_ALLOC( char, nFileSize + 16 );
245 pBuffer[0] = '\n';
246 RetValue = fread( pBuffer+1, nFileSize, 1, pFile );
247 fclose( pFile );
248 // terminate the string with '\0'
249 pBuffer[nFileSize + 1] = '\n';
250 pBuffer[nFileSize + 2] = '\0';
251 *ppLimit = pBuffer + nFileSize + 3;
252 return pBuffer;
253}
254static inline Psr_Man_t * Psr_ManAlloc( char * pFileName )
255{
256 Psr_Man_t * p;
257 char * pBuffer, * pLimit;
258 pBuffer = Psr_ManLoadFile( pFileName, &pLimit );
259 if ( pBuffer == NULL )
260 return NULL;
261 p = ABC_CALLOC( Psr_Man_t, 1 );
262 p->pName = pFileName;
263 p->pBuffer = pBuffer;
264 p->pLimit = pLimit;
265 p->pCur = pBuffer;
266 p->pStrs = Abc_NamStart( 1000, 24 );
267 p->vNtks = Vec_PtrAlloc( 100 );
268 return p;
269}
270
271static inline void Psr_NtkFree( Psr_Ntk_t * p )
272{
273 if ( p->pStrs )
274 Abc_NamDeref( p->pStrs );
275 Vec_IntErase( &p->vOrder );
276 Vec_IntErase( &p->vInouts );
277 Vec_IntErase( &p->vInputs );
278 Vec_IntErase( &p->vOutputs );
279 Vec_IntErase( &p->vWires );
280 Vec_IntErase( &p->vInoutsR );
281 Vec_IntErase( &p->vInputsR );
282 Vec_IntErase( &p->vOutputsR );
283 Vec_IntErase( &p->vWiresR );
284 Vec_IntErase( &p->vSlices );
285 Vec_IntErase( &p->vConcats );
286 Vec_IntErase( &p->vBoxes );
287 Vec_IntErase( &p->vObjs );
288 ABC_FREE( p );
289}
290
291static inline void Psr_ManVecFree( Vec_Ptr_t * vPrs )
292{
293 Psr_Ntk_t * pNtk; int i;
294 Vec_PtrForEachEntry( Psr_Ntk_t *, vPrs, pNtk, i )
295 Psr_NtkFree( pNtk );
296 Vec_PtrFree( vPrs );
297}
298
299static inline void Psr_ManFree( Psr_Man_t * p )
300{
301 if ( p->pStrs )
302 Abc_NamDeref( p->pStrs );
303 if ( p->vNtks )
304 Psr_ManVecFree( p->vNtks );
305 // temporary
306 Vec_StrErase( &p->vCover );
307 Vec_IntErase( &p->vTemp );
308 Vec_IntErase( &p->vTemp2 );
309 Vec_IntErase( &p->vKnown );
310 Vec_IntErase( &p->vFailed );
311 Vec_IntErase( &p->vSucceeded );
312 ABC_FREE( p->pBuffer );
313 ABC_FREE( p );
314}
315
316static inline int Psr_NtkMemory( Psr_Ntk_t * p )
317{
318 int nMem = sizeof(Psr_Ntk_t);
319 nMem += Vec_IntMemory( &p->vOrder );
320 nMem += Vec_IntMemory( &p->vInouts );
321 nMem += Vec_IntMemory( &p->vInputs );
322 nMem += Vec_IntMemory( &p->vOutputs );
323 nMem += Vec_IntMemory( &p->vWires );
324 nMem += Vec_IntMemory( &p->vInoutsR );
325 nMem += Vec_IntMemory( &p->vInputsR );
326 nMem += Vec_IntMemory( &p->vOutputsR );
327 nMem += Vec_IntMemory( &p->vWiresR );
328 nMem += Vec_IntMemory( &p->vSlices );
329 nMem += Vec_IntMemory( &p->vBoxes );
330 nMem += Vec_IntMemory( &p->vConcats );
331 return nMem;
332}
333static inline int Psr_ManMemory( Vec_Ptr_t * vPrs )
334{
335 Psr_Ntk_t * pNtk; int i;
336 int nMem = Vec_PtrMemory(vPrs);
337 Vec_PtrForEachEntry( Psr_Ntk_t *, vPrs, pNtk, i )
338 nMem += Psr_NtkMemory( pNtk );
339 nMem += Abc_NamMemUsed(Psr_ManNameMan(vPrs));
340 return nMem;
341}
342
343
344
348
352
353/*=== bac.c ========================================================*/
354
355
357
358#endif
359
363
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
struct Psr_Ntk_t_ Psr_Ntk_t
BASIC TYPES ///.
Definition bacPrs.h:51
Psr_ManType_t
INCLUDES ///.
Definition bacPrs.h:39
@ BAC_PRS_CONST
Definition bacPrs.h:42
@ BAC_PRS_CONCAT
Definition bacPrs.h:43
@ BAC_PRS_NAME
Definition bacPrs.h:40
@ BAC_PRS_SLICE
Definition bacPrs.h:41
struct Psr_Man_t_ Psr_Man_t
Definition bacPrs.h:83
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
Cube * p
Definition exorList.c:222
Vec_Int_t vTemp
Definition bacPrs.h:96
char * pCur
Definition bacPrs.h:90
char * pBuffer
Definition bacPrs.h:88
Vec_Int_t vSucceeded
Definition bacPrs.h:101
char ErrorStr[1000]
Definition bacPrs.h:104
Vec_Str_t vCover
Definition bacPrs.h:95
char * pLimit
Definition bacPrs.h:89
int fUsingTemp2
Definition bacPrs.h:103
Vec_Int_t vTemp2
Definition bacPrs.h:97
char * pName
Definition bacPrs.h:87
Vec_Ptr_t * vNtks
Definition bacPrs.h:93
Vec_Int_t vFailed
Definition bacPrs.h:100
Abc_Nam_t * pStrs
Definition bacPrs.h:91
Psr_Ntk_t * pNtk
Definition bacPrs.h:92
Vec_Int_t vKnown
Definition bacPrs.h:99
Vec_Int_t vSlices
Definition bacPrs.h:76
unsigned fHasC1s
Definition bacPrs.h:59
Vec_Int_t vInputsR
Definition bacPrs.h:72
unsigned fHasCZs
Definition bacPrs.h:61
Vec_Int_t vBoxes
Definition bacPrs.h:78
Vec_Int_t vInputs
Definition bacPrs.h:67
unsigned fMapped
Definition bacPrs.h:56
unsigned fSlices
Definition bacPrs.h:57
Vec_Int_t vOrder
Definition bacPrs.h:64
unsigned fHasCXs
Definition bacPrs.h:60
Vec_Int_t vOutputsR
Definition bacPrs.h:73
unsigned fHasC0s
Definition bacPrs.h:58
int iModuleName
Definition bacPrs.h:55
Vec_Int_t vWiresR
Definition bacPrs.h:74
Vec_Int_t vInouts
Definition bacPrs.h:66
Vec_Int_t vOutputs
Definition bacPrs.h:68
Abc_Nam_t * pStrs
Definition bacPrs.h:62
Vec_Int_t vConcats
Definition bacPrs.h:77
Vec_Int_t vObjs
Definition bacPrs.h:79
Vec_Int_t vInoutsR
Definition bacPrs.h:71
Vec_Int_t vWires
Definition bacPrs.h:69
int Abc_NamMemUsed(Abc_Nam_t *p)
Definition utilNam.c:247
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
Definition utilNam.c:80
void Abc_NamDeref(Abc_Nam_t *p)
Definition utilNam.c:212
Abc_Nam_t * Abc_NamRef(Abc_Nam_t *p)
Definition utilNam.c:195
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
Definition utilNam.c:555
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
Definition utilNam.h:39
#define assert(ex)
Definition util_old.h:213
char * sprintf()
VOID_HACK rewind()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
#define SEEK_END
Definition zconf.h:392