61static inline void Psr_NtkAddBlifDirectives(
Psr_Man_t *
p )
64 for ( i = 1; s_BlifTypes[i]; i++ )
85static inline int Psr_CharIsSpace(
char c ) {
return c ==
' ' || c ==
'\t' || c ==
'\r'; }
86static inline int Psr_CharIsStop(
char c ) {
return c ==
'#' || c ==
'\\' || c ==
'\n' || c ==
'='; }
87static inline int Psr_CharIsLit(
char c ) {
return c ==
'0' || c ==
'1' || c ==
'-'; }
89static inline int Psr_ManIsSpace(
Psr_Man_t *
p ) {
return Psr_CharIsSpace(*
p->pCur); }
90static inline int Psr_ManIsStop(
Psr_Man_t *
p ) {
return Psr_CharIsStop(*
p->pCur); }
91static inline int Psr_ManIsLit(
Psr_Man_t *
p ) {
return Psr_CharIsLit(*
p->pCur); }
93static inline int Psr_ManIsChar(
Psr_Man_t *
p,
char c ) {
return *
p->pCur == c; }
94static inline int Psr_ManIsChar2(
Psr_Man_t *
p,
char c ) {
return *
p->pCur++ == c; }
96static inline void Psr_ManSkip(
Psr_Man_t *
p ) {
p->pCur++; }
97static inline char Psr_ManSkip2(
Psr_Man_t *
p ) {
return *
p->pCur++; }
111static inline void Psr_ManSkipToChar(
Psr_Man_t *
p,
char c )
113 while ( !Psr_ManIsChar(
p, c) )
116static inline void Psr_ManSkipSpaces(
Psr_Man_t *
p )
120 while ( Psr_ManIsSpace(
p) )
122 if ( Psr_ManIsChar(
p,
'\\') )
124 Psr_ManSkipToChar(
p,
'\n' );
128 if ( Psr_ManIsChar(
p,
'#') )
129 Psr_ManSkipToChar(
p,
'\n' );
134static inline int Psr_ManReadName(
Psr_Man_t *
p )
137 Psr_ManSkipSpaces(
p );
138 if ( Psr_ManIsChar(
p,
'\n') )
141 while ( !Psr_ManIsSpace(
p) && !Psr_ManIsStop(
p) )
143 if ( pStart ==
p->pCur )
150 Vec_IntClear( &
p->vTemp );
151 while ( (iToken = Psr_ManReadName(
p)) )
153 Vec_IntPush( &
p->vTemp, iToken );
154 Vec_IntPush( vOrder, Abc_Var2Lit2(iToken, Type) );
156 if ( Vec_IntSize(&
p->vTemp) == 0 )
return Psr_ManErrorSet(
p,
"Signal list is empty.", 1);
159static inline int Psr_ManReadList2(
Psr_Man_t *
p )
162 Vec_IntClear( &
p->vTemp );
163 while ( (iToken = Psr_ManReadName(
p)) )
164 Vec_IntPushTwo( &
p->vTemp, 0, iToken );
165 if ( Vec_IntSize(&
p->vTemp) == 0 )
return Psr_ManErrorSet(
p,
"Signal list is empty.", 1);
168static inline int Psr_ManReadList3(
Psr_Man_t *
p )
170 Vec_IntClear( &
p->vTemp );
171 while ( !Psr_ManIsChar(
p,
'\n') )
173 int iToken = Psr_ManReadName(
p);
174 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read formal name.", 1);
175 Vec_IntPush( &
p->vTemp, iToken );
176 Psr_ManSkipSpaces(
p );
177 if ( !Psr_ManIsChar2(
p,
'=') )
return Psr_ManErrorSet(
p,
"Cannot find symbol \"=\".", 1);
178 iToken = Psr_ManReadName(
p);
179 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read actual name.", 1);
180 Vec_IntPush( &
p->vTemp, iToken );
181 Psr_ManSkipSpaces(
p );
183 if ( Vec_IntSize(&
p->vTemp) == 0 )
return Psr_ManErrorSet(
p,
"Cannot read a list of formal/actual names.", 1);
184 if ( Vec_IntSize(&
p->vTemp) % 2 )
return Psr_ManErrorSet(
p,
"The number of formal/actual names is not even.", 1);
199static inline int Psr_ManReadCube(
Psr_Man_t *
p )
202 while ( Psr_ManIsLit(
p) )
203 Vec_StrPush( &
p->vCover, Psr_ManSkip2(
p) );
204 Psr_ManSkipSpaces(
p );
205 if ( Psr_ManIsChar(
p,
'\n') )
207 if ( Vec_StrSize(&
p->vCover) != 1 )
return Psr_ManErrorSet(
p,
"Cannot read cube.", 1);
209 Vec_StrPush( &
p->vCover, Vec_StrEntry(&
p->vCover,0) );
210 Vec_StrWriteEntry( &
p->vCover, 0,
' ' );
211 Vec_StrPush( &
p->vCover,
'\n' );
214 if ( !Psr_ManIsLit(
p) )
return Psr_ManErrorSet(
p,
"Cannot read output literal.", 1);
215 Vec_StrPush( &
p->vCover,
' ' );
216 Vec_StrPush( &
p->vCover, Psr_ManSkip2(
p) );
217 Vec_StrPush( &
p->vCover,
'\n' );
218 Psr_ManSkipSpaces(
p );
219 if ( !Psr_ManIsChar(
p,
'\n') )
return Psr_ManErrorSet(
p,
"Cannot read end of cube.", 1);
222static inline void Psr_ManSaveCover(
Psr_Man_t *
p )
225 if ( Vec_StrSize(&
p->vCover) == 0 )
226 p->pNtk->fHasC0s = 1;
227 else if ( Vec_StrSize(&
p->vCover) == 2 )
229 if ( Vec_StrEntryLast(&
p->vCover) ==
'0' )
230 p->pNtk->fHasC0s = 1;
231 else if ( Vec_StrEntryLast(&
p->vCover) ==
'1' )
232 p->pNtk->fHasC1s = 1;
235 assert( Vec_StrSize(&
p->vCover) > 0 );
236 Vec_StrPush( &
p->vCover,
'\0' );
238 iToken = Ptr_SopToType( Vec_StrArray(&
p->vCover) );
239 Vec_StrClear( &
p->vCover );
241 assert( Psr_BoxNtk(
p->pNtk, Psr_NtkBoxNum(
p->pNtk)-1) == 1 );
242 Psr_BoxSetNtk(
p->pNtk, Psr_NtkBoxNum(
p->pNtk)-1, iToken );
256static inline int Psr_ManReadInouts(
Psr_Man_t *
p )
258 if ( Psr_ManReadList(
p, &
p->pNtk->vOrder, 3) )
return 1;
259 Vec_IntAppend( &
p->pNtk->vInouts, &
p->vTemp );
262static inline int Psr_ManReadInputs(
Psr_Man_t *
p )
264 if ( Psr_ManReadList(
p, &
p->pNtk->vOrder, 1) )
return 1;
265 Vec_IntAppend( &
p->pNtk->vInputs, &
p->vTemp );
268static inline int Psr_ManReadOutputs(
Psr_Man_t *
p )
270 if ( Psr_ManReadList(
p, &
p->pNtk->vOrder, 2) )
return 1;
271 Vec_IntAppend( &
p->pNtk->vOutputs, &
p->vTemp );
274static inline int Psr_ManReadNode(
Psr_Man_t *
p )
276 if ( Psr_ManReadList2(
p) )
return 1;
278 Psr_NtkAddBox(
p->pNtk, 1, 0, &
p->vTemp );
281static inline int Psr_ManReadBox(
Psr_Man_t *
p,
int fGate )
283 int iToken = Psr_ManReadName(
p);
284 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read model name.", 1);
285 if ( Psr_ManReadList3(
p) )
return 1;
287 Psr_NtkAddBox(
p->pNtk, iToken, 0, &
p->vTemp );
288 if ( fGate )
p->pNtk->fMapped = 1;
291static inline int Psr_ManReadLatch(
Psr_Man_t *
p )
293 int iToken = Psr_ManReadName(
p);
294 Vec_IntClear( &
p->vTemp );
295 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read latch input.", 1);
296 Vec_IntWriteEntry( &
p->vTemp, 1, iToken );
297 iToken = Psr_ManReadName(
p);
298 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read latch output.", 1);
299 Vec_IntWriteEntry( &
p->vTemp, 0, iToken );
300 Psr_ManSkipSpaces(
p );
301 if ( Psr_ManIsChar(
p,
'0') )
303 else if ( Psr_ManIsChar(
p,
'1') )
307 Psr_ManSkipToChar(
p,
'\n' );
309 Psr_NtkAddBox(
p->pNtk, -1, iToken, &
p->vTemp );
312static inline int Psr_ManReadShort(
Psr_Man_t *
p )
314 int iToken = Psr_ManReadName(
p);
315 Vec_IntClear( &
p->vTemp );
316 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read .short input.", 1);
317 Vec_IntWriteEntry( &
p->vTemp, 1, iToken );
318 iToken = Psr_ManReadName(
p);
319 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read .short output.", 1);
320 Vec_IntWriteEntry( &
p->vTemp, 0, iToken );
321 Psr_ManSkipSpaces(
p );
322 if ( !Psr_ManIsChar(
p,
'\n') )
return Psr_ManErrorSet(
p,
"Trailing symbols on .short line.", 1);
325 Psr_NtkAddBox(
p->pNtk, iToken, 0, &
p->vTemp );
328static inline int Psr_ManReadModel(
Psr_Man_t *
p )
331 if (
p->pNtk != NULL )
return Psr_ManErrorSet(
p,
"Parsing previous model is unfinished.", 1);
332 iToken = Psr_ManReadName(
p);
333 if ( iToken == 0 )
return Psr_ManErrorSet(
p,
"Cannot read model name.", 1);
334 Psr_ManInitializeNtk(
p, iToken, 0 );
335 Psr_ManSkipSpaces(
p );
336 if ( !Psr_ManIsChar(
p,
'\n') )
return Psr_ManErrorSet(
p,
"Trailing symbols on .model line.", 1);
339static inline int Psr_ManReadEnd(
Psr_Man_t *
p )
341 if (
p->pNtk == 0 )
return Psr_ManErrorSet(
p,
"Directive .end without .model.", 1);
343 Psr_ManFinalizeNtk(
p );
344 Psr_ManSkipSpaces(
p );
345 if ( !Psr_ManIsChar(
p,
'\n') )
return Psr_ManErrorSet(
p,
"Trailing symbols on .end line.", 1);
349static inline int Psr_ManReadDirective(
Psr_Man_t *
p )
352 if ( !Psr_ManIsChar(
p,
'.') )
353 return Psr_ManReadCube(
p );
354 if ( Vec_StrSize(&
p->vCover) > 0 )
355 Psr_ManSaveCover(
p );
356 iToken = Psr_ManReadName(
p );
358 return Psr_ManReadModel(
p );
360 return Psr_ManReadInouts(
p );
362 return Psr_ManReadInputs(
p );
364 return Psr_ManReadOutputs(
p );
366 return Psr_ManReadNode(
p );
368 return Psr_ManReadBox(
p, 0 );
370 return Psr_ManReadBox(
p, 1 );
372 return Psr_ManReadLatch(
p );
374 return Psr_ManReadShort(
p );
376 return Psr_ManReadEnd(
p );
377 printf(
"Cannot read directive \"%s\".\n",
Abc_NamStr(
p->pStrs, iToken) );
380static inline int Psr_ManReadLines(
Psr_Man_t *
p )
382 while (
p->pCur[1] !=
'\0' )
384 assert( Psr_ManIsChar(
p,
'\n') );
386 Psr_ManSkipSpaces(
p );
387 if ( Psr_ManIsChar(
p,
'\n') )
389 if ( Psr_ManReadDirective(
p) )
412 Psr_NtkAddBlifDirectives(
p );
413 Psr_ManReadLines(
p );
414 if ( Psr_ManErrorPrint(
p) )
438 printf(
"Finished reading %d networks. ", Vec_PtrSize(vPrs) );
440 printf(
"Memory = %.2f MB. ", 1.0*Psr_ManMemory(vPrs)/(1<<20) );
441 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
444 Psr_ManVecFree( vPrs );
#define ABC_SWAP(Type, a, b)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
struct Psr_Man_t_ Psr_Man_t
void Psr_ManReadBlifTest()
Bac_BlifType_t
DECLARATIONS ///.
Vec_Ptr_t * Psr_ManReadBlif(char *pFileName)
void Psr_ManWriteBlif(char *pFileName, Vec_Ptr_t *p)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
int Abc_NamStrFindOrAddLim(Abc_Nam_t *p, char *pStr, char *pLim, int *pfFound)
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
int Abc_NamObjNumMax(Abc_Nam_t *p)
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.