21#ifndef ABC__base__prs__prs_h
22#define ABC__base__prs__prs_h
138static inline Prs_Ntk_t * Prs_ManNtk(
Vec_Ptr_t * vPrs,
int i ) {
return i >= 0 && i < Vec_PtrSize(vPrs) ? (
Prs_Ntk_t *)Vec_PtrEntry(vPrs, i) : NULL; }
139static inline Prs_Ntk_t * Prs_ManRoot(
Vec_Ptr_t * vPrs ) {
return Prs_ManNtk(vPrs, 0); }
140static inline Abc_Nam_t * Prs_ManNameMan(
Vec_Ptr_t * vPrs ) {
return Prs_ManRoot(vPrs)->pStrs; }
141static inline Abc_Nam_t * Prs_ManFuncMan(
Vec_Ptr_t * vPrs ) {
return Prs_ManRoot(vPrs)->pFuns; }
143static inline int Prs_NtkId(
Prs_Ntk_t *
p ) {
return p->iModuleName; }
144static inline int Prs_NtkPioNum(
Prs_Ntk_t *
p ) {
return Vec_IntSize(&
p->vInouts); }
145static inline int Prs_NtkPiNum(
Prs_Ntk_t *
p ) {
return Vec_IntSize(&
p->vInputs); }
146static inline int Prs_NtkPoNum(
Prs_Ntk_t *
p ) {
return Vec_IntSize(&
p->vOutputs); }
147static inline int Prs_NtkBoxNum(
Prs_Ntk_t *
p ) {
return Vec_IntSize(&
p->vObjs); }
148static inline int Prs_NtkObjNum(
Prs_Ntk_t *
p ) {
return Prs_NtkPioNum(
p) + Prs_NtkPiNum(
p) + Prs_NtkPoNum(
p) + Prs_NtkBoxNum(
p); }
152static inline char * Prs_NtkName(
Prs_Ntk_t *
p ) {
return Prs_NtkStr(
p, Prs_NtkId(
p)); }
153static inline int Prs_NtkSigName(
Prs_Ntk_t *
p,
int i ) {
if (!
p->fSlices)
return i;
assert(Abc_Lit2Att2(i) ==
CBA_PRS_NAME);
return Abc_Lit2Var2(i); }
154static inline int Ptr_NtkRangeSize(
Prs_Ntk_t *
p,
int h ) {
int l = Hash_IntObjData0(
p->vHash, h), r = Hash_IntObjData1(
p->vHash, h);
return 1 + (l > r ? l-r : r-l); }
156static inline int Prs_SliceName(
Prs_Ntk_t *
p,
int h ) {
return Vec_IntEntry(&
p->vSlices, h); }
157static inline int Prs_SliceRange(
Prs_Ntk_t *
p,
int h ) {
return Vec_IntEntry(&
p->vSlices, h+1); }
159static inline int Prs_CatSize(
Prs_Ntk_t *
p,
int h ) {
return Vec_IntEntry(&
p->vConcats, h); }
160static inline int * Prs_CatArray(
Prs_Ntk_t *
p,
int h ) {
return Vec_IntEntryP(&
p->vConcats, h+1); }
161static inline Vec_Int_t * Prs_CatSignals(
Prs_Ntk_t *
p,
int h ) {
static Vec_Int_t V; V.nSize = V.nCap = Prs_CatSize(
p, h); V.pArray = Prs_CatArray(
p, h);
return &V; }
163static inline int Prs_BoxHand(
Prs_Ntk_t *
p,
int i ) {
return Vec_IntEntry(&
p->vObjs, i); }
164static inline int Prs_BoxSize(
Prs_Ntk_t *
p,
int i ) {
return Vec_IntEntry(&
p->vBoxes, Prs_BoxHand(
p, i))-2; }
165static inline int Prs_BoxIONum(
Prs_Ntk_t *
p,
int i ) {
return Prs_BoxSize(
p, i) / 2; }
166static inline int Prs_BoxNtk(
Prs_Ntk_t *
p,
int i ) {
return Vec_IntEntry(&
p->vBoxes, Prs_BoxHand(
p, i)+1); }
167static inline void Prs_BoxSetNtk(
Prs_Ntk_t *
p,
int i,
int m ) { Vec_IntWriteEntry(&
p->vBoxes, Prs_BoxHand(
p, i)+1, m); }
168static inline int Prs_BoxName(
Prs_Ntk_t *
p,
int i ) {
return Vec_IntEntry(&
p->vBoxes, Prs_BoxHand(
p, i)+2); }
169static inline int Prs_BoxIsNode(
Prs_Ntk_t *
p,
int i ) {
return!Vec_IntEntry(&
p->vBoxes, Prs_BoxHand(
p, i)+3); }
170static inline int * Prs_BoxArray(
Prs_Ntk_t *
p,
int i ) {
return Vec_IntEntryP(&
p->vBoxes, Prs_BoxHand(
p, i)+3); }
171static inline Vec_Int_t * Prs_BoxSignals(
Prs_Ntk_t *
p,
int i ) {
static Vec_Int_t V; V.nSize = V.nCap = Prs_BoxSize(
p, i); V.pArray = Prs_BoxArray(
p, i);
return &V; }
173#define Prs_ManForEachNameVec( vVec, p, pName, i ) \
174 for ( i = 0; (i < Vec_IntSize(vVec)) && ((pName) = Abc_NamStr(p->pStrs, Vec_IntEntry(vVec,i))); i++ )
176#define Prs_NtkForEachPio( p, NameId, i ) \
177 for ( i = 0; i < Prs_NtkPioNum(p) && ((NameId) = Vec_IntEntry(&p->vInouts, i)); i++ )
178#define Prs_NtkForEachPi( p, NameId, i ) \
179 for ( i = 0; i < Prs_NtkPiNum(p) && ((NameId) = Vec_IntEntry(&p->vInputs, i)); i++ )
180#define Prs_NtkForEachPo( p, NameId, i ) \
181 for ( i = 0; i < Prs_NtkPoNum(p) && ((NameId) = Vec_IntEntry(&p->vOutputs, i)); i++ )
182#define Prs_NtkForEachBox( p, vVec, i ) \
183 for ( i = 0; i < Prs_NtkBoxNum(p) && ((vVec) = Prs_BoxSignals(p, i)); i++ )
190static inline int Prs_ManErrorSet(
Prs_Man_t *
p,
char * pError,
int Value )
193 sprintf(
p->ErrorStr,
"%s", pError );
197static inline void Prs_ManErrorClear(
Prs_Man_t *
p )
199 p->ErrorStr[0] =
'\0';
202static inline int Prs_ManErrorPrint(
Prs_Man_t *
p )
204 char * pThis;
int iLine = 0;
205 if ( !
p->ErrorStr[0] )
return 1;
206 for ( pThis =
p->pBuffer; pThis < p->pCur; pThis++ )
207 iLine += (int)(*pThis ==
'\n');
208 printf(
"Line %d: %s\n", iLine,
p->ErrorStr );
213static inline void Prs_ManInitializeNtk(
Prs_Man_t *
p,
int iName,
int fSlices )
217 p->pNtk->iModuleName = iName;
218 p->pNtk->fSlices = fSlices;
221 p->pNtk->vHash = Hash_IntManRef(
p->vHash );
222 Vec_PtrPush(
p->vNtks,
p->pNtk );
224static inline void Prs_ManFinalizeNtk(
Prs_Man_t *
p )
230static inline int Prs_ManNewStrId(
Prs_Man_t *
p,
const char * format, ... )
234 int nAdded, nSize = 1000;
235 va_list args; va_start( args, format );
236 Vec_StrGrow( vBuf, Vec_StrSize(vBuf) + nSize );
237 nAdded = vsnprintf( Vec_StrLimit(vBuf), nSize, format, args );
238 if ( nAdded > nSize )
240 Vec_StrGrow( vBuf, Vec_StrSize(vBuf) + nAdded + nSize );
241 nSize = vsnprintf( Vec_StrLimit(vBuf), nAdded, format, args );
242 assert( nSize == nAdded );
249static inline int Prs_NtkAddSlice(
Prs_Ntk_t *
p,
int Name,
int Range )
251 int Value = Vec_IntSize(&
p->vSlices);
252 Vec_IntPushTwo( &
p->vSlices, Name, Range );
258 if ( !(Vec_IntSize(&
p->vConcats) & 1) )
259 Vec_IntPush(&
p->vConcats, -1);
260 Value = Vec_IntSize(&
p->vConcats);
262 Vec_IntPush( &
p->vConcats, Vec_IntSize(vTemp) );
263 Vec_IntAppend( &
p->vConcats, vTemp );
266static inline void Prs_NtkAddBox(
Prs_Ntk_t *
p,
int ModName,
int InstName,
Vec_Int_t * vTemp )
269 assert( Vec_IntSize(vTemp) % 2 == 0 );
270 if ( !(Vec_IntSize(&
p->vBoxes) & 1) )
271 Vec_IntPush(&
p->vBoxes, -1);
272 Value = Vec_IntSize(&
p->vBoxes);
274 Vec_IntPush( &
p->vObjs, Value );
276 Vec_IntPush( &
p->vBoxes, Vec_IntSize(vTemp)+2 );
277 Vec_IntPush( &
p->vBoxes, ModName );
278 Vec_IntPush( &
p->vBoxes, InstName );
279 Vec_IntAppend( &
p->vBoxes, vTemp );
281static inline char * Prs_ManLoadFile(
char * pFileName,
char ** ppLimit )
284 int nFileSize, RetValue;
285 FILE * pFile = fopen( pFileName,
"rb" );
288 printf(
"Cannot open input file.\n" );
293 nFileSize = ftell( pFile );
297 pBuffer =
ABC_ALLOC(
char, nFileSize + 16 );
299 RetValue = fread( pBuffer+1, nFileSize, 1, pFile );
302 pBuffer[nFileSize + 1] =
'\n';
303 pBuffer[nFileSize + 2] =
'\0';
304 *ppLimit = pBuffer + nFileSize + 3;
307static inline Prs_Man_t * Prs_ManAlloc(
char * pFileName )
313 char * pBuffer, * pLimit;
314 pBuffer = Prs_ManLoadFile( pFileName, &pLimit );
315 if ( pBuffer == NULL )
317 p->pName = pFileName;
318 p->pBuffer = pBuffer;
324 p->vHash = Hash_IntManStart( 1000 );
325 p->vNtks = Vec_PtrAlloc( 100 );
329static inline void Prs_NtkFree(
Prs_Ntk_t *
p )
333 if (
p->vHash ) Hash_IntManDeref(
p->vHash );
334 Vec_IntErase( &
p->vOrder );
335 Vec_IntErase( &
p->vInouts );
336 Vec_IntErase( &
p->vInputs );
337 Vec_IntErase( &
p->vOutputs );
338 Vec_IntErase( &
p->vWires );
339 Vec_IntErase( &
p->vInoutsR );
340 Vec_IntErase( &
p->vInputsR );
341 Vec_IntErase( &
p->vOutputsR );
342 Vec_IntErase( &
p->vWiresR );
343 Vec_IntErase( &
p->vSlices );
344 Vec_IntErase( &
p->vConcats );
345 Vec_IntErase( &
p->vBoxes );
346 Vec_IntErase( &
p->vObjs );
350static inline void Prs_ManVecFree(
Vec_Ptr_t * vPrs )
358static inline void Prs_ManFree(
Prs_Man_t *
p )
362 if (
p->vHash ) Hash_IntManDeref(
p->vHash );
363 if (
p->vNtks ) Prs_ManVecFree(
p->vNtks );
365 Vec_StrErase( &
p->vCover );
366 Vec_IntErase( &
p->vTemp );
367 Vec_IntErase( &
p->vTemp2 );
368 Vec_IntErase( &
p->vTemp3 );
369 Vec_IntErase( &
p->vTemp4 );
370 Vec_IntErase( &
p->vKnown );
371 Vec_IntErase( &
p->vFailed );
372 Vec_IntErase( &
p->vSucceeded );
377static inline int Prs_NtkMemory(
Prs_Ntk_t *
p )
380 nMem += Vec_IntMemory( &
p->vOrder );
381 nMem += Vec_IntMemory( &
p->vInouts );
382 nMem += Vec_IntMemory( &
p->vInputs );
383 nMem += Vec_IntMemory( &
p->vOutputs );
384 nMem += Vec_IntMemory( &
p->vWires );
385 nMem += Vec_IntMemory( &
p->vInoutsR );
386 nMem += Vec_IntMemory( &
p->vInputsR );
387 nMem += Vec_IntMemory( &
p->vOutputsR );
388 nMem += Vec_IntMemory( &
p->vWiresR );
389 nMem += Vec_IntMemory( &
p->vSlices );
390 nMem += Vec_IntMemory( &
p->vBoxes );
391 nMem += Vec_IntMemory( &
p->vConcats );
394static inline int Prs_ManMemory(
Vec_Ptr_t * vPrs )
397 int nMem = Vec_PtrMemory(vPrs);
399 nMem += Prs_NtkMemory( pNtk );
436static inline char * Ptr_SopToTypeName(
char * pSop )
438 if ( !
strcmp(pSop,
" 0\n") )
return "CBA_BOX_C0";
439 if ( !
strcmp(pSop,
" 1\n") )
return "CBA_BOX_C1";
440 if ( !
strcmp(pSop,
"1 1\n") )
return "CBA_BOX_BUF";
441 if ( !
strcmp(pSop,
"0 1\n") )
return "CBA_BOX_INV";
442 if ( !
strcmp(pSop,
"11 1\n") )
return "CBA_BOX_AND";
443 if ( !
strcmp(pSop,
"00 1\n") )
return "CBA_BOX_NOR";
444 if ( !
strcmp(pSop,
"00 0\n") )
return "CBA_BOX_OR";
445 if ( !
strcmp(pSop,
"-1 1\n1- 1\n") )
return "CBA_BOX_OR";
446 if ( !
strcmp(pSop,
"1- 1\n-1 1\n") )
return "CBA_BOX_OR";
447 if ( !
strcmp(pSop,
"01 1\n10 1\n") )
return "CBA_BOX_XOR";
448 if ( !
strcmp(pSop,
"10 1\n01 1\n") )
return "CBA_BOX_XOR";
449 if ( !
strcmp(pSop,
"11 1\n00 1\n") )
return "CBA_BOX_XNOR";
450 if ( !
strcmp(pSop,
"00 1\n11 1\n") )
return "CBA_BOX_XNOR";
451 if ( !
strcmp(pSop,
"10 1\n") )
return "CBA_BOX_SHARP";
452 if ( !
strcmp(pSop,
"01 1\n") )
return "CBA_BOX_SHARPL";
494 if ( Type ==
CBA_BOX_MUX )
return "11- 1\n0-1 1\n";
495 if ( Type ==
CBA_BOX_MAJ )
return "11- 1\n1-1 1\n-11 1\n";
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
Cba_VerType_t
INCLUDES ///.
struct Prs_Man_t_ Prs_Man_t
struct Prs_Ntk_t_ Prs_Ntk_t
BASIC TYPES ///.
void Prs_NtkAddVerilogDirectives(Prs_Man_t *p)
ITERATORS ///.
Cba_ObjType_t
INCLUDES ///.
int Abc_NamStrFindOrAddLim(Abc_Nam_t *p, char *pStr, char *pLim, int *pfFound)
int Abc_NamMemUsed(Abc_Nam_t *p)
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
Vec_Str_t * Abc_NamBuffer(Abc_Nam_t *p)
void Abc_NamDeref(Abc_Nam_t *p)
Abc_Nam_t * Abc_NamRef(Abc_Nam_t *p)
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
struct Hash_IntMan_t_ Hash_IntMan_t
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.