ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlcReadSmt.c
Go to the documentation of this file.
1
20
21#include "wlc.h"
22#include "misc/vec/vecWec.h"
23
25
29
30// parser
31typedef struct Smt_Prs_t_ Smt_Prs_t;
33{
34 // input data
35 char * pName; // file name
36 char * pBuffer; // file contents
37 char * pLimit; // end of file
38 char * pCur; // current position
39 Abc_Nam_t * pStrs; // string manager
40 // network structure
41 Vec_Int_t vStack; // current node on each level
42 //Vec_Wec_t vDepth; // objects on each level
43 Vec_Wec_t vObjs; // objects
47 // error handling
48 char ErrorStr[1000];
49};
50
51//#define SMT_GLO_SUFFIX "_glb"
52#define SMT_GLO_SUFFIX ""
53
54// parser name types
69
70typedef struct Smt_Pair_t_ Smt_Pair_t;
72{
74 char * pName;
75};
76static Smt_Pair_t s_Types[SMT_PRS_END] =
77{
78 { SMT_PRS_NONE, NULL },
79 { SMT_PRS_SET_OPTION, "set-option" },
80 { SMT_PRS_SET_LOGIC, "set-logic" },
81 { SMT_PRS_SET_INFO, "set-info" },
82 { SMT_PRS_DEFINE_FUN, "define-fun" },
83 { SMT_PRS_DECLARE_FUN, "declare-fun" },
84 { SMT_PRS_ASSERT, "assert" },
85 { SMT_PRS_LET, "let" },
86 { SMT_PRS_CHECK_SAT, "check-sat" },
87 { SMT_PRS_GET_VALUE, "get-value" },
88 { SMT_PRS_EXIT, "exit" }
89};
90static inline char * Smt_GetTypeName( Smt_LineType_t Type )
91{
92 int i;
93 for ( i = 1; i < SMT_PRS_END; i++ )
94 if ( s_Types[i].Type == Type )
95 return s_Types[i].pName;
96 return NULL;
97}
98static inline void Smt_AddTypes( Abc_Nam_t * p )
99{
100 int Type;
101 for ( Type = 1; Type < SMT_PRS_END; Type++ )
102 Abc_NamStrFindOrAdd( p, Smt_GetTypeName((Smt_LineType_t)Type), NULL );
104}
105
106static inline int Smt_EntryIsName( int Fan ) { return Abc_LitIsCompl(Fan); }
107static inline int Smt_EntryIsType( int Fan, Smt_LineType_t Type ) { assert(Smt_EntryIsName(Fan)); return Abc_Lit2Var(Fan) == Type; }
108static inline char * Smt_EntryName( Smt_Prs_t * p, int Fan ) { assert(Smt_EntryIsName(Fan)); return Abc_NamStr( p->pStrs, Abc_Lit2Var(Fan) ); }
109static inline Vec_Int_t * Smt_EntryNode( Smt_Prs_t * p, int Fan ) { assert(!Smt_EntryIsName(Fan)); return Vec_WecEntry( &p->vObjs, Abc_Lit2Var(Fan) ); }
110
111static inline int Smt_VecEntryIsType( Vec_Int_t * vFans, int i, Smt_LineType_t Type ) { return i < Vec_IntSize(vFans) && Smt_EntryIsName(Vec_IntEntry(vFans, i)) && Smt_EntryIsType(Vec_IntEntry(vFans, i), Type); }
112static inline char * Smt_VecEntryName( Smt_Prs_t * p, Vec_Int_t * vFans, int i ) { return Smt_EntryIsName(Vec_IntEntry(vFans, i)) ? Smt_EntryName(p, Vec_IntEntry(vFans, i)) : NULL; }
113static inline Vec_Int_t * Smt_VecEntryNode( Smt_Prs_t * p, Vec_Int_t * vFans, int i ) { return Smt_EntryIsName(Vec_IntEntry(vFans, i)) ? NULL : Smt_EntryNode(p, Vec_IntEntry(vFans, i)); }
114
115#define Smt_ManForEachDir( p, Type, vVec, i ) \
116 for ( i = 0; (i < Vec_WecSize(&p->vObjs)) && (((vVec) = Vec_WecEntry(&p->vObjs, i)), 1); i++ ) \
117 if ( !Smt_VecEntryIsType(vVec, 0, Type) ) {} else
118
122
134static inline int Smt_StrToType( char * pName, int * pfSigned )
135{
136 int Type = 0; *pfSigned = 0;
137 if ( !strcmp(pName, "ite") )
138 Type = WLC_OBJ_MUX; // 08: multiplexer
139 else if ( !strcmp(pName, "bvlshr") )
140 Type = WLC_OBJ_SHIFT_R; // 09: shift right
141 else if ( !strcmp(pName, "bvashr") )
142 Type = WLC_OBJ_SHIFT_RA , *pfSigned = 1; // 10: shift right (arithmetic)
143 else if ( !strcmp(pName, "bvshl") )
144 Type = WLC_OBJ_SHIFT_L; // 11: shift left
145// else if ( !strcmp(pName, "") )
146// Type = WLC_OBJ_SHIFT_LA; // 12: shift left (arithmetic)
147 else if ( !strcmp(pName, "rotate_right") )
148 Type = WLC_OBJ_ROTATE_R; // 13: rotate right
149 else if ( !strcmp(pName, "rotate_left") )
150 Type = WLC_OBJ_ROTATE_L; // 14: rotate left
151 else if ( !strcmp(pName, "bvnot") )
152 Type = WLC_OBJ_BIT_NOT; // 15: bitwise NOT
153 else if ( !strcmp(pName, "bvand") )
154 Type = WLC_OBJ_BIT_AND; // 16: bitwise AND
155 else if ( !strcmp(pName, "bvor") )
156 Type = WLC_OBJ_BIT_OR; // 17: bitwise OR
157 else if ( !strcmp(pName, "bvxor") )
158 Type = WLC_OBJ_BIT_XOR; // 18: bitwise XOR
159 else if ( !strcmp(pName, "bvnand") )
160 Type = WLC_OBJ_BIT_NAND; // 16: bitwise NAND
161 else if ( !strcmp(pName, "bvnor") )
162 Type = WLC_OBJ_BIT_NOR; // 17: bitwise NOR
163 else if ( !strcmp(pName, "bvxnor") )
164 Type = WLC_OBJ_BIT_NXOR; // 18: bitwise NXOR
165 else if ( !strcmp(pName, "extract") )
166 Type = WLC_OBJ_BIT_SELECT; // 19: bit selection
167 else if ( !strcmp(pName, "concat") )
168 Type = WLC_OBJ_BIT_CONCAT; // 20: bit concatenation
169 else if ( !strcmp(pName, "zero_extend") )
170 Type = WLC_OBJ_BIT_ZEROPAD; // 21: zero padding
171 else if ( !strcmp(pName, "sign_extend") )
172 Type = WLC_OBJ_BIT_SIGNEXT; // 22: sign extension
173 else if ( !strcmp(pName, "not") )
174 Type = WLC_OBJ_LOGIC_NOT; // 23: logic NOT
175 else if ( !strcmp(pName, "=>") )
176 Type = WLC_OBJ_LOGIC_IMPL; // 24: logic AND
177 else if ( !strcmp(pName, "and") )
178 Type = WLC_OBJ_LOGIC_AND; // 24: logic AND
179 else if ( !strcmp(pName, "or") )
180 Type = WLC_OBJ_LOGIC_OR; // 25: logic OR
181 else if ( !strcmp(pName, "xor") )
182 Type = WLC_OBJ_LOGIC_XOR; // 26: logic OR
183 else if ( !strcmp(pName, "bvcomp") || !strcmp(pName, "=") )
184 Type = WLC_OBJ_COMP_EQU; // 27: compare equal
185 else if ( !strcmp(pName, "distinct") )
186 Type = WLC_OBJ_COMP_NOTEQU; // 28: compare not equal
187 else if ( !strcmp(pName, "bvult") )
188 Type = WLC_OBJ_COMP_LESS; // 29: compare less
189 else if ( !strcmp(pName, "bvugt") )
190 Type = WLC_OBJ_COMP_MORE; // 30: compare more
191 else if ( !strcmp(pName, "bvule") )
192 Type = WLC_OBJ_COMP_LESSEQU; // 31: compare less or equal
193 else if ( !strcmp(pName, "bvuge") )
194 Type = WLC_OBJ_COMP_MOREEQU; // 32: compare more or equal
195 else if ( !strcmp(pName, "bvslt") )
196 Type = WLC_OBJ_COMP_LESS, *pfSigned = 1; // 29: compare less
197 else if ( !strcmp(pName, "bvsgt") )
198 Type = WLC_OBJ_COMP_MORE, *pfSigned = 1; // 30: compare more
199 else if ( !strcmp(pName, "bvsle") )
200 Type = WLC_OBJ_COMP_LESSEQU, *pfSigned = 1; // 31: compare less or equal
201 else if ( !strcmp(pName, "bvsge") )
202 Type = WLC_OBJ_COMP_MOREEQU, *pfSigned = 1; // 32: compare more or equal
203 else if ( !strcmp(pName, "bvredand") )
204 Type = WLC_OBJ_REDUCT_AND; // 33: reduction AND
205 else if ( !strcmp(pName, "bvredor") )
206 Type = WLC_OBJ_REDUCT_OR; // 34: reduction OR
207 else if ( !strcmp(pName, "bvredxor") )
208 Type = WLC_OBJ_REDUCT_XOR; // 35: reduction XOR
209 else if ( !strcmp(pName, "bvadd") )
210 Type = WLC_OBJ_ARI_ADD; // 36: arithmetic addition
211 else if ( !strcmp(pName, "bvsub") )
212 Type = WLC_OBJ_ARI_SUB; // 37: arithmetic subtraction
213 else if ( !strcmp(pName, "bvmul") )
214 Type = WLC_OBJ_ARI_MULTI; // 38: arithmetic multiplier
215 else if ( !strcmp(pName, "bvudiv") )
216 Type = WLC_OBJ_ARI_DIVIDE; // 39: arithmetic division
217 else if ( !strcmp(pName, "bvurem") )
218 Type = WLC_OBJ_ARI_REM; // 40: arithmetic remainder
219 else if ( !strcmp(pName, "bvsdiv") )
220 Type = WLC_OBJ_ARI_DIVIDE, *pfSigned = 1; // 39: arithmetic division
221 else if ( !strcmp(pName, "bvsrem") )
222 Type = WLC_OBJ_ARI_REM, *pfSigned = 1; // 40: arithmetic remainder
223 else if ( !strcmp(pName, "bvsmod") )
224 Type = WLC_OBJ_ARI_MODULUS, *pfSigned = 1; // 40: arithmetic modulus
225 else if ( !strcmp(pName, "=") )
226 Type = WLC_OBJ_COMP_EQU; // 40: arithmetic modulus
227// else if ( !strcmp(pName, "") )
228// Type = WLC_OBJ_ARI_POWER; // 41: arithmetic power
229 else if ( !strcmp(pName, "bvneg") )
230 Type = WLC_OBJ_ARI_MINUS; // 42: arithmetic minus
231// else if ( !strcmp(pName, "") )
232// Type = WLC_OBJ_TABLE; // 43: bit table
233 else
234 {
235 printf( "The following operations is currently not supported (%s)\n", pName );
236 fflush( stdout );
237 }
238 return Type;
239}
240static inline int Smt_PrsReadType( Smt_Prs_t * p, int iSig, int * pfSigned, int * Value1, int * Value2 )
241{
242 if ( Smt_EntryIsName(iSig) )
243 return Smt_StrToType( Smt_EntryName(p, iSig), pfSigned );
244 else
245 {
246 Vec_Int_t * vFans = Smt_EntryNode( p, iSig );
247 char * pStr = Smt_VecEntryName( p, vFans, 0 ); int Type;
248 assert( Vec_IntSize(vFans) >= 3 );
249 assert( !strcmp(pStr, "_") ); // special op
250 *Value1 = *Value2 = -1;
251 assert( pStr[0] != 'b' || pStr[1] != 'v' );
252 // read type
253 Type = Smt_StrToType( Smt_VecEntryName(p, vFans, 1), pfSigned );
254 if ( Type == 0 )
255 return 0;
256 *Value1 = atoi( Smt_VecEntryName(p, vFans, 2) );
257 if ( Vec_IntSize(vFans) > 3 )
258 *Value2 = atoi( Smt_VecEntryName(p, vFans, 3) );
259 return Type;
260 }
261}
262
263static inline int Smt_StrType( char * str ) { return Smt_StrToType(str, NULL); }
264
276static inline int Smt_PrsCreateNodeOld( Wlc_Ntk_t * pNtk, int Type, int fSigned, int Range, Vec_Int_t * vFanins, char * pName )
277{
278 char Buffer[100];
279 int NameId, fFound;
280 int iObj = Wlc_ObjAlloc( pNtk, Type, fSigned, Range-1, 0 );
281 assert( Type > 0 );
282 assert( Range >= 0 );
283 assert( fSigned >= 0 );
284
285 // add node's name
286 if ( pName == NULL )
287 {
288 sprintf( Buffer, "_n%d_", iObj );
289 pName = Buffer;
290 }
291 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pName, &fFound );
292 assert( !fFound );
293 assert( iObj == NameId );
294
295 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj), vFanins );
296 if ( fSigned )
297 {
298 Wlc_NtkObj(pNtk, iObj)->Signed = fSigned;
299// if ( Vec_IntSize(vFanins) > 0 )
300// Wlc_NtkObj(pNtk, Vec_IntEntry(vFanins, 0))->Signed = fSigned;
301// if ( Vec_IntSize(vFanins) > 1 )
302// Wlc_NtkObj(pNtk, Vec_IntEntry(vFanins, 1))->Signed = fSigned;
303 }
304
305 return iObj;
306}
307static inline int Smt_PrsCreateNode( Wlc_Ntk_t * pNtk, int Type, int fSigned, int Range, Vec_Int_t * vFanins, char * pName )
308{
309 char Buffer[100];
310 char * pNameFanin;
311 int NameId, fFound, old_size, new_size;
312 int iObj, iFanin0, iFanin1;
313 Vec_Int_t * v2Fanins = Vec_IntStartFull(2);
314
315 assert( Type > 0 );
316 assert( Range >= 0 );
317 assert( fSigned >= 0 );
318
319 //if (Vec_IntSize(vFanins)<=2 || Type == WLC_OBJ_BIT_CONCAT || Type == WLC_OBJ_MUX )
320 // explicitely secify allowed multi operators
321 if (Vec_IntSize(vFanins)<=2 ||
322 !( Type == WLC_OBJ_BIT_AND || // 16:`` bitwise AND
323 Type == WLC_OBJ_BIT_OR || // 17: bitwise OR
324 Type == WLC_OBJ_BIT_XOR || // 18: bitwise XOR
325 Type == WLC_OBJ_BIT_NAND || // 19: bitwise AND
326 Type == WLC_OBJ_BIT_NOR || // 20: bitwise OR
327 Type == WLC_OBJ_BIT_NXOR || // 21: bitwise NXOR
328
329 Type == WLC_OBJ_LOGIC_IMPL || // 27: logic implication
330 Type == WLC_OBJ_LOGIC_AND || // 28: logic AND
331 Type == WLC_OBJ_LOGIC_OR || // 29: logic OR
332 Type == WLC_OBJ_LOGIC_XOR || // 30: logic XOR
333 Type == WLC_OBJ_COMP_EQU || // 31: compare equal
334// Type == WLC_OBJ_COMP_NOTEQU || // 32: compare not equal -- bug fix
335 Type == WLC_OBJ_COMP_LESS || // 33: compare less
336 Type == WLC_OBJ_COMP_MORE || // 34: compare more
337 Type == WLC_OBJ_COMP_LESSEQU || // 35: compare less or equal
338 Type == WLC_OBJ_COMP_MOREEQU || // 36: compare more or equal
339
340 Type == WLC_OBJ_ARI_ADD || // 43: arithmetic addition
341 Type == WLC_OBJ_ARI_SUB || // 44: arithmetic subtraction
342 Type == WLC_OBJ_ARI_MULTI || // 45: arithmetic multiplier
343 Type == WLC_OBJ_ARI_DIVIDE // 46: arithmetic division
344 ))
345 goto FINISHED_WITH_FANINS;
346
347 // we will be creating nodes backwards. this way we can pop from vFanins easier
348 while (Vec_IntSize(vFanins)>2)
349 {
350 // getting 2 fanins at a time
351 old_size = Vec_IntSize(vFanins);
352 iFanin0 = Vec_IntPop(vFanins);
353 iFanin1 = Vec_IntPop(vFanins);
354
355 Vec_IntWriteEntry(v2Fanins,0,iFanin0);
356 Vec_IntWriteEntry(v2Fanins,1,iFanin1);
357
358 iObj = Wlc_ObjAlloc( pNtk, Type, fSigned, Range-1, 0 );
359 sprintf( Buffer, "_n%d_", iObj );
360 pNameFanin = Buffer;
361 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pNameFanin, &fFound );
362
363 assert( !fFound );
364 assert( iObj == NameId );
365
366 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj), v2Fanins );
367
368 // pushing the new node
369 Vec_IntPush(vFanins, iObj);
370 new_size = Vec_IntSize(vFanins);
371 assert(new_size<old_size);
372 }
373
374FINISHED_WITH_FANINS:
375
376 Vec_IntFree(v2Fanins);
377
378 //added to deal with long shifts create extra bit select (ROTATE as well ??)
379 // this is a temporary hack
380 // basically we keep only 32 bits.
381 // bit[31] will be the copy of original MSB (sign bit, just in case) UPDATE: assume it is unsigned first????
382 // bit[31] will be the reduction or of any bits from [31] to Range
383 if (Type == WLC_OBJ_SHIFT_R || Type == WLC_OBJ_SHIFT_RA || Type == WLC_OBJ_SHIFT_L)
384 {
385 int range1, iObj1, iObj2, iObj3;
386 assert(Vec_IntSize(vFanins)>=2);
387 iFanin1 = Vec_IntEntry(vFanins,1);
388 range1 = Wlc_ObjRange( Wlc_NtkObj(pNtk, iFanin1) );
389 if (range1>32)
390 {
391 Vec_Int_t * newFanins = Vec_IntAlloc(10);
392 Vec_IntPush(newFanins,iFanin1);
393 Vec_IntPushTwo( newFanins, 30, 0 );
394
395 iObj1 = Wlc_ObjAlloc( pNtk, WLC_OBJ_BIT_SELECT, 0, 30, 0 );
396 sprintf( Buffer, "_n%d_", iObj1 );
397 pNameFanin = Buffer;
398 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pNameFanin, &fFound );
399
400 assert( !fFound );
401 assert( iObj1 == NameId );
402
403 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj1), newFanins );
404
405 //printf("obj1: %d\n",iObj1);
406
407 // bit select of larger bits
408 Vec_IntPop(newFanins);
409 Vec_IntPop(newFanins);
410 Vec_IntPushTwo( newFanins, range1-1, 31 );
411 iObj2 = Wlc_ObjAlloc( pNtk, WLC_OBJ_BIT_SELECT, 0, range1-1, 31 );
412 sprintf( Buffer, "_n%d_", iObj2 );
413 pNameFanin = Buffer;
414 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pNameFanin, &fFound );
415
416 assert( !fFound );
417 assert( iObj2 == NameId );
418
419 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj2), newFanins );
420 //printf("obj2: %d\n",iObj2);
421
422 // reduction or
423 Vec_IntPop( newFanins );
424 Vec_IntPop( newFanins );
425 Vec_IntWriteEntry( newFanins, 0, iObj2 );
426 iObj3 = Wlc_ObjAlloc( pNtk, WLC_OBJ_REDUCT_OR, 0, 0, 0 );
427 sprintf( Buffer, "_n%d_", iObj3 );
428 pNameFanin = Buffer;
429 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pNameFanin, &fFound );
430
431 assert( !fFound );
432 assert( iObj3 == NameId );
433
434 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj3), newFanins );
435 //printf("obj3: %d\n",iObj3);
436
437 // concat all together
438 Vec_IntWriteEntry( newFanins, 0, iObj3 );
439 Vec_IntPush( newFanins, iObj1 );
440 iObj = Wlc_ObjAlloc( pNtk, WLC_OBJ_BIT_CONCAT, 0, 31, 0 );
441 sprintf( Buffer, "_n%d_", iObj );
442 pNameFanin = Buffer;
443 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pNameFanin, &fFound );
444
445 assert( !fFound );
446 assert( iObj == NameId );
447
448 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj), newFanins );
449 //printf("obj: %d\n",iObj);
450
451 // pushing the new node
452 Vec_IntWriteEntry(vFanins, 1, iObj);
453 Vec_IntFree(newFanins);
454 }
455 }
456
457 iObj = Wlc_ObjAlloc( pNtk, Type, fSigned, Range-1, 0 );
458
459 // add node's name
460 if ( pName == NULL )
461 {
462 sprintf( Buffer, "_n%d_", iObj );
463 pName = Buffer;
464 }
465 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pName, &fFound );
466 assert( !fFound );
467 assert( iObj == NameId );
468
469 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj), vFanins );
470 if ( fSigned )
471 {
472 Wlc_NtkObj(pNtk, iObj)->Signed = fSigned;
473// if ( Vec_IntSize(vFanins) > 0 )
474// Wlc_NtkObj(pNtk, Vec_IntEntry(vFanins, 0))->Signed = fSigned;
475// if ( Vec_IntSize(vFanins) > 1 )
476// Wlc_NtkObj(pNtk, Vec_IntEntry(vFanins, 1))->Signed = fSigned;
477 }
478
479 return iObj;
480}
481
482static inline char * Smt_GetHexFromDecimalString(char * pStr)
483{
484 int i,k=0, nDigits = strlen(pStr);
485 int digit, carry = 0;
486 int metNonZeroBit = 0;
487
488 Vec_Int_t * decimal = Vec_IntAlloc(nDigits);
489 Vec_Int_t * rev;
490 int nBits;
491 char * hex;
492
493 for (i=0;i<nDigits;i++)
494 Vec_IntPush(decimal,pStr[i]-'0');
495
496 // firstly fillin the reversed vector
497 rev = Vec_IntAlloc(10);
498 while(k<nDigits)
499 {
500 digit = Vec_IntEntry(decimal,k);
501 if (!digit && !carry)
502 {
503 k++;
504 if (k>=nDigits)
505 {
506 if (!metNonZeroBit)
507 break;
508 else
509 {
510 Vec_IntPush(rev,carry);
511 carry = 0;
512 k = 0;
513 metNonZeroBit = 0;
514 }
515 }
516 continue;
517 }
518
519 if (!metNonZeroBit)
520 metNonZeroBit = 1;
521
522 digit = carry*10 + digit;
523 carry = digit%2;
524 digit = digit / 2;
525 Vec_IntWriteEntry(decimal,k,digit);
526
527 k++;
528 if (k>=nDigits)
529 {
530 Vec_IntPush(rev,carry);
531 carry = 0;
532 k = 0;
533 metNonZeroBit = 0;
534 }
535 }
536
537 Vec_IntFree(decimal);
538
539 if (!Vec_IntSize(rev))
540 Vec_IntPush(rev,0);
541
542 while (Vec_IntSize(rev)%4)
543 Vec_IntPush(rev,0);
544
545 nBits = Vec_IntSize(rev);
546 hex = (char *)malloc((nBits/4+1)*sizeof(char));
547
548 for (k=0;k<nBits/4;k++)
549 {
550 int number = Vec_IntEntry(rev,k*4) + 2*Vec_IntEntry(rev,k*4+1) + 4*Vec_IntEntry(rev,k*4+2) + 8*Vec_IntEntry(rev,k*4+3);
551 char letter;
552
553 switch(number) {
554 case 0: letter = '0'; break;
555 case 1: letter = '1'; break;
556 case 2: letter = '2'; break;
557 case 3: letter = '3'; break;
558 case 4: letter = '4'; break;
559 case 5: letter = '5'; break;
560 case 6: letter = '6'; break;
561 case 7: letter = '7'; break;
562 case 8: letter = '8'; break;
563 case 9: letter = '9'; break;
564 case 10: letter = 'a'; break;
565 case 11: letter = 'b'; break;
566 case 12: letter = 'c'; break;
567 case 13: letter = 'd'; break;
568 case 14: letter = 'e'; break;
569 case 15: letter = 'f'; break;
570 default: assert(0);
571 }
572 hex[nBits/4-1-k] = letter;
573 //if (k<Vec_IntSize(rev))
574 // Vec_IntPush(vFanins,Vec_IntEntry(rev,k));
575 //else
576 // Vec_IntPush(vFanins,0);
577 }
578 hex[nBits/4] = '\0';
579 Vec_IntFree(rev);
580
581 return hex;
582}
583
584static inline int Smt_PrsBuildConstant( Wlc_Ntk_t * pNtk, char * pStr, int nBits, char * pName )
585{
586 int i, nDigits, iObj;
587 Vec_Int_t * vFanins = Vec_IntAlloc( 10 );
588 if ( pStr[0] != '#' ) // decimal
589 {
590 if ( pStr[0] >= '0' && pStr[0] <= '9' )
591 {
592 // added: sanity check for large constants
593 /*
594 Vec_Int_t * temp = Vec_IntAlloc(10);
595 int fullBits = -1;
596 Smt_GetBinaryFromDecimalString(pStr,temp,&fullBits);
597 Vec_IntFree(temp);
598 assert(fullBits < 32);*/
599
600 char * pHex = Smt_GetHexFromDecimalString(pStr);
601
602 if ( nBits == -1 )
603 nBits = strlen(pHex)*4;
604
605 //printf("nbits: %d\n",nBits);
606
607 Vec_IntFill( vFanins, Abc_BitWordNum(nBits), 0 );
608 nDigits = Abc_TtReadHexNumber( (word *)Vec_IntArray(vFanins), pHex );
609 ABC_FREE( pHex );
610
611 /*
612 int w, nWords, Number = atoi( pStr );
613 if ( nBits == -1 )
614 {
615 nBits = Abc_Base2Log( Number+1 );
616 assert( nBits < 32 );
617 }
618 nWords = Abc_BitWordNum( nBits );
619 for ( w = 0; w < nWords; w++ )
620 Vec_IntPush( vFanins, w ? 0 : Number );
621 */
622 }
623 else
624 {
625 int fFound, iObj = Abc_NamStrFindOrAdd( pNtk->pManName, pStr, &fFound );
626 assert( fFound );
627 Vec_IntFree( vFanins );
628 return iObj;
629 }
630 }
631 else if ( pStr[1] == 'b' ) // binary
632 {
633 if ( nBits == -1 )
634 nBits = strlen(pStr+2);
635 Vec_IntFill( vFanins, Abc_BitWordNum(nBits), 0 );
636 for ( i = 0; i < nBits; i++ )
637 if ( pStr[2+i] == '1' )
638 Abc_InfoSetBit( (unsigned *)Vec_IntArray(vFanins), nBits-1-i );
639 else if ( pStr[2+i] != '0' )
640 {
641 Vec_IntFree( vFanins );
642 return 0;
643 }
644 }
645 else if ( pStr[1] == 'x' ) // hexadecimal
646 {
647 if ( nBits == -1 )
648 nBits = strlen(pStr+2)*4;
649 Vec_IntFill( vFanins, Abc_BitWordNum(nBits), 0 );
650 nDigits = Abc_TtReadHexNumber( (word *)Vec_IntArray(vFanins), pStr+2 );
651 if ( nDigits != (nBits + 3)/4 )
652 {
653 Vec_IntFree( vFanins );
654 return 0;
655 }
656 }
657 else
658 {
659 Vec_IntFree( vFanins );
660 return 0;
661 }
662 // create constant node
663 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_CONST, 0, nBits, vFanins, pName );
664 Vec_IntFree( vFanins );
665 return iObj;
666}
667int Smt_PrsBuildNode( Wlc_Ntk_t * pNtk, Smt_Prs_t * p, int iNode, int RangeOut, char * pName )
668{
669 if ( Smt_EntryIsName(iNode) ) // name or constant
670 {
671 char * pStr = Abc_NamStr(p->pStrs, Abc_Lit2Var(iNode));
672 if ( (pStr[0] >= '0' && pStr[0] <= '9') || pStr[0] == '#' )
673 {
674 // (_ BitVec 8) #x19
675 return Smt_PrsBuildConstant( pNtk, pStr, RangeOut, pName );
676 }
677 else
678 {
679 // s3087
680 int fFound, iObj = Abc_NamStrFindOrAdd( pNtk->pManName, pStr, &fFound );
681 assert( fFound );
682 return iObj;
683 }
684 }
685 else // node
686 {
687 Vec_Int_t * vFans = Smt_EntryNode( p, iNode );
688 char * pStr0 = Smt_VecEntryName( p, vFans, 0 );
689 char * pStr1 = Smt_VecEntryName( p, vFans, 1 );
690 if ( pStr0 && pStr1 && pStr0[0] == '_' && pStr1[0] == 'b' && pStr1[1] == 'v' )
691 {
692 // (_ bv1 32)
693 char * pStr2 = Smt_VecEntryName( p, vFans, 2 );
694 assert( Vec_IntSize(vFans) == 3 );
695 return Smt_PrsBuildConstant( pNtk, pStr1+2, atoi(pStr2), pName );
696 }
697 else if ( pStr0 && pStr0[0] == '=' )
698 {
699 assert( Vec_IntSize(vFans) == 3 );
700 iNode = Vec_IntEntry(vFans, 2);
701 assert( Smt_EntryIsName(iNode) );
702 pStr0 = Smt_EntryName(p, iNode);
703 // check the last one is "#b1"
704 if ( !strcmp("#b1", pStr0) )
705 {
706 iNode = Vec_IntEntry(vFans, 1);
707 return Smt_PrsBuildNode( pNtk, p, iNode, -1, pName );
708 }
709 else
710 {
711 Vec_Int_t * vFanins = Vec_IntAlloc( 2 );
712 // get the constant
713 int iObj, iOper, iConst = Smt_PrsBuildConstant( pNtk, pStr0, -1, NULL );
714 // check the middle one is an operator
715 iNode = Vec_IntEntry(vFans, 1);
716 iOper = Smt_PrsBuildNode( pNtk, p, iNode, -1, pName );
717 // build comparator
718 Vec_IntPushTwo( vFanins, iOper, iConst );
719 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_COMP_EQU, 0, 1, vFanins, pName );
720 Vec_IntFree( vFanins );
721 return iObj;
722 }
723 }
724 else
725 {
726 int i, Fan, NameId, iFanin, fSigned, Range, Value1 = -1, Value2 = -1;
727 int Type = Smt_PrsReadType( p, Vec_IntEntry(vFans, 0), &fSigned, &Value1, &Value2 );
728 // collect fanins
729 Vec_Int_t * vFanins = Vec_IntAlloc( 100 );
730 Vec_IntForEachEntryStart( vFans, Fan, i, 1 )
731 {
732 iFanin = Smt_PrsBuildNode( pNtk, p, Fan, -1, NULL );
733 if ( iFanin == 0 )
734 {
735 Vec_IntFree( vFanins );
736 return 0;
737 }
738 Vec_IntPush( vFanins, iFanin );
739 }
740 // update specialized nodes
741 assert( Type != WLC_OBJ_BIT_SIGNEXT && Type != WLC_OBJ_BIT_ZEROPAD );
742 if ( Type == WLC_OBJ_BIT_SELECT )
743 {
744 assert( Value1 >= 0 && Value2 >= 0 && Value1 >= Value2 );
745 Vec_IntPushTwo( vFanins, Value1, Value2 );
746 }
747 else if ( Type == WLC_OBJ_ROTATE_R || Type == WLC_OBJ_ROTATE_L )
748 {
749 char Buffer[100];
750 assert( Value1 >= 0 );
751 sprintf( Buffer, "%d", Value1 );
752 NameId = Smt_PrsBuildConstant( pNtk, Buffer, -1, NULL );
753 Vec_IntPush( vFanins, NameId );
754 }
755 // find range
756 Range = 0;
757 if ( Type >= WLC_OBJ_LOGIC_NOT && Type <= WLC_OBJ_REDUCT_XOR )
758 Range = 1;
759 else if ( Type == WLC_OBJ_BIT_SELECT )
760 Range = Value1 - Value2 + 1;
761 else if ( Type == WLC_OBJ_BIT_CONCAT )
762 {
763 Vec_IntForEachEntry( vFanins, NameId, i )
764 Range += Wlc_ObjRange( Wlc_NtkObj(pNtk, NameId) );
765 }
766 else if ( Type == WLC_OBJ_MUX )
767 {
768 int * pArray = Vec_IntArray(vFanins);
769 assert( Vec_IntSize(vFanins) == 3 );
770 ABC_SWAP( int, pArray[1], pArray[2] );
771 NameId = Vec_IntEntry(vFanins, 1);
772 Range = Wlc_ObjRange( Wlc_NtkObj(pNtk, NameId) );
773 }
774 else // to determine range, look at the first argument
775 {
776 NameId = Vec_IntEntry(vFanins, 0);
777 Range = Wlc_ObjRange( Wlc_NtkObj(pNtk, NameId) );
778 }
779 // create node
780 assert( Range > 0 );
781 NameId = Smt_PrsCreateNode( pNtk, Type, fSigned, Range, vFanins, pName );
782 Vec_IntFree( vFanins );
783 return NameId;
784 }
785 }
786}
787
800{
801 Wlc_Ntk_t * pNtk;
802 Vec_Int_t * vFans, * vFans2, * vFans3;
803 Vec_Int_t * vAsserts = Vec_IntAlloc(100);
804 char * pName, * pRange, * pValue;
805 int i, k, Fan, Fan3, iObj, Status, Range, NameId, nBits = 0;
806 // issue warnings about unknown dirs
807 vFans = Vec_WecEntry( &p->vObjs, 0 );
808 Vec_IntForEachEntry( vFans, Fan, i )
809 {
810 assert( !Smt_EntryIsName(Fan) );
811 vFans2 = Smt_VecEntryNode( p, vFans, i );
812 Fan = Vec_IntEntry(vFans2, 0);
813 assert( Smt_EntryIsName(Fan) );
814 if ( Abc_Lit2Var(Fan) >= SMT_PRS_END )
815 printf( "Ignoring directive \"%s\".\n", Smt_EntryName(p, Fan) );
816 }
817 // start network and create primary inputs
818 pNtk = Wlc_NtkAlloc( p->pName, 1000 );
819 pNtk->pManName = Abc_NamStart( 1000, 24 );
820 pNtk->fSmtLib = 1;
822 {
823 assert( Vec_IntSize(vFans) == 4 );
824 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_DECLARE_FUN) );
825 // get name
826 Fan = Vec_IntEntry(vFans, 1);
827 assert( Smt_EntryIsName(Fan) );
828 pName = Smt_EntryName(p, Fan);
829 // skip ()
830 Fan = Vec_IntEntry(vFans, 2);
831 assert( !Smt_EntryIsName(Fan) );
832 // check type (Bool or BitVec)
833 Fan = Vec_IntEntry(vFans, 3);
834 if ( Smt_EntryIsName(Fan) )
835 {
836 //(declare-fun s1 () Bool)
837 assert( !strcmp("Bool", Smt_VecEntryName(p, vFans, 3)) );
838 Range = 1;
839 }
840 else
841 {
842 // (declare-fun s1 () (_ BitVec 64))
843 // get range
844 Fan = Vec_IntEntry(vFans, 3);
845 assert( !Smt_EntryIsName(Fan) );
846 vFans2 = Smt_EntryNode(p, Fan);
847 assert( Vec_IntSize(vFans2) == 3 );
848 assert( !strcmp("_", Smt_VecEntryName(p, vFans2, 0)) );
849 assert( !strcmp("BitVec", Smt_VecEntryName(p, vFans2, 1)) );
850 Fan = Vec_IntEntry(vFans2, 2);
851 assert( Smt_EntryIsName(Fan) );
852 pRange = Smt_EntryName(p, Fan);
853 Range = atoi(pRange);
854 }
855 // create node
856 iObj = Wlc_ObjAlloc( pNtk, WLC_OBJ_PI, 0, Range-1, 0 );
857 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pName, NULL );
858 assert( iObj == NameId );
859 // save values
860 Vec_IntPush( &pNtk->vValues, NameId );
861 Vec_IntPush( &pNtk->vValues, nBits );
862 Vec_IntPush( &pNtk->vValues, Range );
863 nBits += Range;
864 }
865 // create constants
867 {
868 assert( Vec_IntSize(vFans) == 5 );
869 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_DEFINE_FUN) );
870 // get name
871 Fan = Vec_IntEntry(vFans, 1);
872 assert( Smt_EntryIsName(Fan) );
873 pName = Smt_EntryName(p, Fan);
874 // skip ()
875 Fan = Vec_IntEntry(vFans, 2);
876 assert( !Smt_EntryIsName(Fan) );
877 // check type (Bool or BitVec)
878 Fan = Vec_IntEntry(vFans, 3);
879 if ( Smt_EntryIsName(Fan) )
880 {
881 // (define-fun s_2 () Bool false)
882 assert( !strcmp("Bool", Smt_VecEntryName(p, vFans, 3)) );
883 Range = 1;
884 pValue = Smt_VecEntryName(p, vFans, 4);
885 if ( !strcmp("false", pValue) )
886 pValue = "#b0";
887 else if ( !strcmp("true", pValue) )
888 pValue = "#b1";
889 else assert( 0 );
890 Status = Smt_PrsBuildConstant( pNtk, pValue, Range, pName );
891 }
892 else
893 {
894 // (define-fun s702 () (_ BitVec 4) #xe)
895 // (define-fun s1 () (_ BitVec 8) (bvneg #x7f))
896 // get range
897 Fan = Vec_IntEntry(vFans, 3);
898 assert( !Smt_EntryIsName(Fan) );
899 vFans2 = Smt_VecEntryNode(p, vFans, 3);
900 assert( Vec_IntSize(vFans2) == 3 );
901 assert( !strcmp("_", Smt_VecEntryName(p, vFans2, 0)) );
902 assert( !strcmp("BitVec", Smt_VecEntryName(p, vFans2, 1)) );
903 // get range
904 Fan = Vec_IntEntry(vFans2, 2);
905 assert( Smt_EntryIsName(Fan) );
906 pRange = Smt_EntryName(p, Fan);
907 Range = atoi(pRange);
908 // get constant
909 Fan = Vec_IntEntry(vFans, 4);
910 Status = Smt_PrsBuildNode( pNtk, p, Fan, Range, pName );
911 }
912 if ( !Status )
913 {
914 Wlc_NtkFree( pNtk ); pNtk = NULL;
915 goto finish;
916 }
917 }
918 // process let-statements
919 Smt_ManForEachDir( p, SMT_PRS_LET, vFans, i )
920 {
921 // let ((s35550 (bvor s48 s35549)))
922 assert( Vec_IntSize(vFans) == 3 );
923 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_LET) );
924 // get parts
925 Fan = Vec_IntEntry(vFans, 1);
926 assert( !Smt_EntryIsName(Fan) );
927 vFans2 = Smt_EntryNode(p, Fan);
928 if ( Smt_VecEntryIsType(vFans2, 0, SMT_PRS_LET) )
929 continue;
930 // iterate through the parts
931 Vec_IntForEachEntry( vFans2, Fan, k )
932 {
933 // s35550 (bvor s48 s35549)
934 Fan = Vec_IntEntry(vFans2, 0);
935 assert( !Smt_EntryIsName(Fan) );
936 vFans3 = Smt_EntryNode(p, Fan);
937 // get the name
938 Fan3 = Vec_IntEntry(vFans3, 0);
939 assert( Smt_EntryIsName(Fan3) );
940 pName = Smt_EntryName(p, Fan3);
941 // get function
942 Fan3 = Vec_IntEntry(vFans3, 1);
943 assert( !Smt_EntryIsName(Fan3) );
944 Status = Smt_PrsBuildNode( pNtk, p, Fan3, -1, pName );
945 if ( !Status )
946 {
947 Wlc_NtkFree( pNtk ); pNtk = NULL;
948 goto finish;
949 }
950 }
951 }
952 // process assert-statements
953 Vec_IntClear( vAsserts );
955 {
956 //(assert ; no quantifiers
957 // (let ((s2 (bvsge s0 s1)))
958 // (not s2)))
959 //(assert (not (= s0 #x00)))
960 assert( Vec_IntSize(vFans) == 2 );
961 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_ASSERT) );
962 // get second directive
963 Fan = Vec_IntEntry(vFans, 1);
964 if ( !Smt_EntryIsName(Fan) )
965 {
966 // find the final let-statement
967 vFans2 = Smt_VecEntryNode(p, vFans, 1);
968 while ( Smt_VecEntryIsType(vFans2, 0, SMT_PRS_LET) )
969 {
970 Fan = Vec_IntEntry(vFans2, 2);
971 if ( Smt_EntryIsName(Fan) )
972 break;
973 vFans2 = Smt_VecEntryNode(p, vFans2, 2);
974 }
975 }
976 // find name or create node
977 iObj = Smt_PrsBuildNode( pNtk, p, Fan, -1, NULL );
978 if ( !iObj )
979 {
980 Wlc_NtkFree( pNtk ); pNtk = NULL;
981 goto finish;
982 }
983 Vec_IntPush( vAsserts, iObj );
984 }
985 // build AND of asserts
986 if ( Vec_IntSize(vAsserts) == 1 )
987 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_BUF, 0, 1, vAsserts, "miter_output" );
988 else
989 {
990 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_BIT_CONCAT, 0, Vec_IntSize(vAsserts), vAsserts, NULL );
991 Vec_IntFill( vAsserts, 1, iObj );
992 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_REDUCT_AND, 0, 1, vAsserts, "miter_output" );
993 }
994 Wlc_ObjSetCo( pNtk, Wlc_NtkObj(pNtk, iObj), 0 );
995 // create nameIDs
996 vFans = Vec_IntStartNatural( Wlc_NtkObjNumMax(pNtk) );
997 Vec_IntAppend( &pNtk->vNameIds, vFans );
998 Vec_IntFree( vFans );
999 //Wlc_NtkReport( pNtk, NULL );
1000finish:
1001 // cleanup
1002 Vec_IntFree(vAsserts);
1003 return pNtk;
1004}
1005
1006
1007
1020{
1021 static char Buffer[16];
1022 sprintf( Buffer, "_%0*X_", p->nDigits, ++p->NameCount );
1023 return Buffer;
1024}
1025int Smt_PrsBuild2_rec( Wlc_Ntk_t * pNtk, Smt_Prs_t * p, int iNode, int iObjPrev, char * pName )
1026{
1027 char suffix[100];
1028 sprintf(suffix,"_as%d",pNtk->nAssert);
1029
1030 //char * prepStr = Abc_NamStr(p->pStrs, Abc_Lit2Var(iNode));
1031 //printf("prestr: %s\n",prepStr);
1032
1033 //printf("inode: %d %d\n",iNode,Smt_EntryIsName(iNode));
1034
1035 if ( Smt_EntryIsName(iNode) )
1036 {
1037 char * pStr = Abc_NamStr(p->pStrs, Abc_Lit2Var(iNode));
1038 // handle built-in constants
1039 if ( !strcmp(pStr, "false") )
1040 pStr = "#b0";
1041 else if ( !strcmp(pStr, "true") )
1042 pStr = "#b1";
1043 if ( pStr[0] == '#' )
1044 return Smt_PrsBuildConstant( pNtk, pStr, -1, pName ? pName : Smt_PrsGenName(p) );
1045 else
1046 {
1047 int fFound, iObj;
1048 // look either for global DECLARE-FUN variable or local LET
1049 char * pStr_glb = (char *)malloc(strlen(pStr) + 4 +1); //glb
1050 char * pStr_loc = (char *)malloc(strlen(pStr) + strlen(suffix) +1);
1051 strcpy(pStr_glb,pStr);
1052 strcat(pStr_glb,SMT_GLO_SUFFIX);
1053 strcpy(pStr_loc,pStr);
1054 strcat(pStr_loc,suffix);
1055
1056 fFound = Abc_NamStrFind( pNtk->pManName, pStr_glb );
1057
1058 if (fFound)
1059 pStr = pStr_glb;
1060 else
1061 {
1062 assert( Abc_NamStrFind( pNtk->pManName, pStr_loc ));
1063 pStr = pStr_loc;
1064 }
1065 // FIXME: delete memory of pStr
1066
1067 iObj = Abc_NamStrFindOrAdd( pNtk->pManName, pStr, &fFound );
1068 assert( fFound );
1069 // create buffer if the name of the fanin has different name
1070 if ( pName && strcmp(Wlc_ObjName(pNtk, iObj), pName) )
1071 {
1072 Vec_IntFill( &p->vTempFans, 1, iObj );
1073 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_BUF, 0, Wlc_ObjRange(Wlc_NtkObj(pNtk, iObj)), &p->vTempFans, pName );
1074 }
1075 ABC_FREE( pStr_glb );
1076 ABC_FREE( pStr_loc );
1077 return iObj;
1078 }
1079 }
1080 else
1081 {
1082 Vec_Int_t * vRoots, * vRoots1, * vFans3;
1083 int iObj, iRoot0, iRoot1, iRoot2, Fan, Fan3, k;
1084 assert( !Smt_EntryIsName(iNode) );
1085 vRoots = Smt_EntryNode( p, iNode );
1086 iRoot0 = Vec_IntEntry( vRoots, 0 );
1087 if ( Smt_EntryIsName(iRoot0) )
1088 {
1089 char * pName2, * pStr0 = Abc_NamStr(p->pStrs, Abc_Lit2Var(iRoot0));
1090 if ( Abc_Lit2Var(iRoot0) == SMT_PRS_LET || Abc_Lit2Var(iRoot0) == SMT_PRS_DEFINE_FUN) //added define-fun is similar to let
1091 {
1092 // let ((s35550 (bvor s48 s35549)))
1093 assert( Vec_IntSize(vRoots) == 3 );
1094 assert( Smt_VecEntryIsType(vRoots, 0, SMT_PRS_LET) );
1095 // get parts
1096 iRoot1 = Vec_IntEntry(vRoots, 1);
1097 assert( !Smt_EntryIsName(iRoot1) );
1098 vRoots1 = Smt_EntryNode(p, iRoot1);
1099 // iterate through the parts
1100 Vec_IntForEachEntry( vRoots1, Fan, k )
1101 {
1102 char * temp;
1103 // s35550 (bvor s48 s35549)
1104 assert( !Smt_EntryIsName(Fan) );
1105 vFans3 = Smt_EntryNode(p, Fan);
1106 assert( Vec_IntSize(vFans3) == 2 );
1107 // get the name
1108 Fan3 = Vec_IntEntry(vFans3, 0);
1109 assert( Smt_EntryIsName(Fan3) );
1110 pName2 = Smt_EntryName(p, Fan3);
1111 // create a local name with suffix
1112 if ( Abc_Lit2Var(iRoot0) == SMT_PRS_LET )
1113 {
1114 temp = (char *)malloc(strlen(pName2) + strlen(suffix) + 1);
1115 strcpy(temp, pName2);
1116 strcat(temp,suffix);
1117 }
1118 else
1119 { temp = (char *)malloc(strlen(pName2) + 4 + 1);
1120 strcpy(temp, pName2);
1121 strcat(temp,SMT_GLO_SUFFIX);
1122 }
1123 // FIXME: need to delete memory of pName2
1124 pName2 = temp;
1125 // get function
1126 Fan3 = Vec_IntEntry(vFans3, 1);
1127 //assert( !Smt_EntryIsName(Fan3) );
1128 // solve the problem
1129 iObj = Smt_PrsBuild2_rec( pNtk, p, Fan3, -1, pName2 ); // NULL ); //pName2 );
1130 ABC_FREE( temp );
1131 if ( iObj == 0 )
1132 return 0;
1133 // create buffer
1134 //Vec_IntFill( &p->vTempFans, 1, iObj );
1135 //Smt_PrsCreateNode( pNtk, WLC_OBJ_BUF, 0, Wlc_ObjRange(Wlc_NtkObj(pNtk, iObj)), &p->vTempFans, pName2 );
1136 }
1137 // process the final part of let
1138 iRoot2 = Vec_IntEntry(vRoots, 2);
1139 return Smt_PrsBuild2_rec( pNtk, p, iRoot2, -1, pName );
1140 }
1141 else if ( pStr0[0] == '_' )
1142 {
1143 char * pStr1 = Smt_VecEntryName( p, vRoots, 1 );
1144 if ( pStr1[0] == 'b' && pStr1[1] == 'v' )
1145 {
1146 // (_ bv1 32)
1147 char * pStr2 = Smt_VecEntryName( p, vRoots, 2 );
1148 assert( Vec_IntSize(vRoots) == 3 );
1149 return Smt_PrsBuildConstant( pNtk, pStr1+2, atoi(pStr2), pName ? pName : Smt_PrsGenName(p) );
1150 }
1151 else
1152 {
1153 int Type1, fSigned = 0, Range = -1;
1154 assert( iObjPrev != -1 );
1155 Type1 = Smt_StrToType( pStr1, &fSigned );
1156 if ( Type1 == 0 )
1157 return 0;
1158 // find out this branch
1159 Vec_IntFill( &p->vTempFans, 1, iObjPrev );
1160 if ( Type1 == WLC_OBJ_BIT_SIGNEXT || Type1 == WLC_OBJ_BIT_ZEROPAD || Type1 == WLC_OBJ_ROTATE_R || Type1 == WLC_OBJ_ROTATE_L )
1161 {
1162 int iRoot2 = Vec_IntEntry(vRoots, 2);
1163 char * pStr2 = Abc_NamStr(p->pStrs, Abc_Lit2Var(iRoot2));
1164 int Num = atoi( pStr2 );
1165 //fSigned = (Type1 == WLC_OBJ_BIT_SIGNEXT);
1166 if ( Type1 == WLC_OBJ_ROTATE_R || Type1 == WLC_OBJ_ROTATE_L )
1167 {
1168 int iConst = Smt_PrsBuildConstant( pNtk, pStr2, -1, Smt_PrsGenName(p) );
1169 Vec_IntClear( &p->vTempFans );
1170 Vec_IntPushTwo( &p->vTempFans, iObjPrev, iConst );
1171 Range = Wlc_ObjRange( Wlc_NtkObj(pNtk, iObjPrev) );
1172 }
1173 else
1174 Range = Num + Wlc_ObjRange( Wlc_NtkObj(pNtk, iObjPrev) );
1175 }
1176 else if ( Type1 == WLC_OBJ_BIT_SELECT )
1177 {
1178 int iRoot2 = Vec_IntEntry( vRoots, 2 );
1179 int iRoot3 = Vec_IntEntry( vRoots, 3 );
1180 char * pStr2 = Abc_NamStr(p->pStrs, Abc_Lit2Var(iRoot2));
1181 char * pStr3 = Abc_NamStr(p->pStrs, Abc_Lit2Var(iRoot3));
1182 int Num1 = atoi( pStr2 );
1183 int Num2 = atoi( pStr3 );
1184 assert( Num1 >= Num2 );
1185 Range = Num1 - Num2 + 1;
1186 Vec_IntPushTwo( &p->vTempFans, Num1, Num2 );
1187 }
1188 else assert( 0 );
1189 iObj = Smt_PrsCreateNode( pNtk, Type1, fSigned, Range, &p->vTempFans, pName ? pName : Smt_PrsGenName(p) );
1190 return iObj;
1191 }
1192 }
1193 else
1194 {
1195 Vec_Int_t * vFanins;
1196 int i, Fan, fSigned = 0, Range, Type0;
1197 int iObj = Abc_NamStrFind( pNtk->pManName, pStr0 );
1198 if ( iObj )
1199 return iObj;
1200 Type0 = Smt_StrToType( pStr0, &fSigned );
1201 if ( Type0 == 0 )
1202 return 0;
1203 assert( Type0 != WLC_OBJ_BIT_SIGNEXT && Type0 != WLC_OBJ_BIT_ZEROPAD && Type0 != WLC_OBJ_BIT_SELECT && Type0 != WLC_OBJ_ROTATE_R && Type0 != WLC_OBJ_ROTATE_L );
1204
1205 // collect fanins
1206 vFanins = Vec_IntAlloc( 100 );
1207 Vec_IntForEachEntryStart( vRoots, Fan, i, 1 )
1208 {
1209 iObj = Smt_PrsBuild2_rec( pNtk, p, Fan, -1, NULL );
1210 if ( iObj == 0 )
1211 {
1212 Vec_IntFree( vFanins );
1213 return 0;
1214 }
1215 Vec_IntPush( vFanins, iObj );
1216 }
1217 // find range
1218 Range = 0;
1219 if ( Type0 >= WLC_OBJ_LOGIC_NOT && Type0 <= WLC_OBJ_REDUCT_XOR )
1220 Range = 1;
1221 else if ( Type0 == WLC_OBJ_BIT_CONCAT )
1222 {
1223 Vec_IntForEachEntry( vFanins, Fan, i )
1224 Range += Wlc_ObjRange( Wlc_NtkObj(pNtk, Fan) );
1225 }
1226 else if ( Type0 == WLC_OBJ_MUX )
1227 {
1228 int * pArray = Vec_IntArray(vFanins);
1229 assert( Vec_IntSize(vFanins) == 3 );
1230 ABC_SWAP( int, pArray[1], pArray[2] );
1231 iObj = Vec_IntEntry(vFanins, 1);
1232 Range = Wlc_ObjRange( Wlc_NtkObj(pNtk, iObj) );
1233 }
1234 else // to determine range, look at the first argument
1235 {
1236 iObj = Vec_IntEntry(vFanins, 0);
1237 Range = Wlc_ObjRange( Wlc_NtkObj(pNtk, iObj) );
1238 }
1239 // create node
1240 assert( Range > 0 );
1241 iObj = Smt_PrsCreateNode( pNtk, Type0, fSigned, Range, vFanins, pName ? pName : Smt_PrsGenName(p) );
1242 Vec_IntFree( vFanins );
1243 return iObj;
1244 }
1245 }
1246 else if ( Vec_IntSize(vRoots) == 2 ) // could be ((_ extract 48 16) (bvmul ?v_5 ?v_12))
1247 {
1248 int iObjPrev = Smt_PrsBuild2_rec( pNtk, p, Vec_IntEntry(vRoots, 1), -1, NULL );
1249 if ( iObjPrev == 0 )
1250 return 0;
1251 return Smt_PrsBuild2_rec( pNtk, p, Vec_IntEntry(vRoots, 0), iObjPrev, pName );
1252 }
1253 else assert( 0 ); // return Smt_PrsBuild2_rec( pNtk, p, iRoot0 );
1254 return 0;
1255 }
1256}
1258{
1259 Wlc_Ntk_t * pNtk;
1260 Vec_Int_t * vFansRoot, * vFans, * vFans2;
1261 Vec_Int_t * vAsserts = Vec_IntAlloc(100);
1262 int i, Root, Fan, iObj, NameId, Range, nBits = 0;
1263 char * pName, * pRange;
1264 // start network and create primary inputs
1265 pNtk = Wlc_NtkAlloc( p->pName, 1000 );
1266 pNtk->pManName = Abc_NamStart( 1000, 24 );
1267 pNtk->fSmtLib = 1;
1268 // collect top-level asserts
1269 vFansRoot = Vec_WecEntry( &p->vObjs, 0 );
1270 Vec_IntForEachEntry( vFansRoot, Root, i )
1271 {
1272 assert( !Smt_EntryIsName(Root) );
1273 vFans = Smt_VecEntryNode( p, vFansRoot, i );
1274 Fan = Vec_IntEntry(vFans, 0);
1275 assert( Smt_EntryIsName(Fan) );
1276 // create variables
1277 if ( Abc_Lit2Var(Fan) == SMT_PRS_DECLARE_FUN )
1278 {
1279 char * pName_glb;
1280 assert( Vec_IntSize(vFans) == 4 );
1281 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_DECLARE_FUN) );
1282 // get name
1283 Fan = Vec_IntEntry(vFans, 1);
1284 assert( Smt_EntryIsName(Fan) );
1285 pName = Smt_EntryName(p, Fan);
1286 // added: giving a global suffix
1287 pName_glb = (char *) malloc(strlen(pName) + 4 + 1);
1288 strcpy(pName_glb,pName);
1289 strcat(pName_glb,SMT_GLO_SUFFIX);
1290 // FIXME: delete memory of pName
1291 pName = pName_glb;
1292 // skip ()
1293 Fan = Vec_IntEntry(vFans, 2);
1294 assert( !Smt_EntryIsName(Fan) );
1295 // check type (Bool or BitVec)
1296 Fan = Vec_IntEntry(vFans, 3);
1297 if ( Smt_EntryIsName(Fan) )
1298 { //(declare-fun s1 () Bool)
1299 assert( !strcmp("Bool", Smt_VecEntryName(p, vFans, 3)) );
1300 Range = 1;
1301 }
1302 else
1303 { // (declare-fun s1 () (_ BitVec 64))
1304 Fan = Vec_IntEntry(vFans, 3);
1305 assert( !Smt_EntryIsName(Fan) );
1306 vFans2 = Smt_EntryNode(p, Fan);
1307 assert( Vec_IntSize(vFans2) == 3 );
1308 assert( !strcmp("_", Smt_VecEntryName(p, vFans2, 0)) );
1309 assert( !strcmp("BitVec", Smt_VecEntryName(p, vFans2, 1)) );
1310 Fan = Vec_IntEntry(vFans2, 2);
1311 assert( Smt_EntryIsName(Fan) );
1312 pRange = Smt_EntryName(p, Fan);
1313 Range = atoi(pRange);
1314 }
1315 // create node
1316 iObj = Wlc_ObjAlloc( pNtk, WLC_OBJ_PI, 0, Range-1, 0 );
1317 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pName, NULL );
1318 assert( iObj == NameId );
1319 // save values
1320 Vec_IntPush( &pNtk->vValues, NameId );
1321 Vec_IntPush( &pNtk->vValues, nBits );
1322 Vec_IntPush( &pNtk->vValues, Range );
1323 nBits += Range;
1324 ABC_FREE( pName_glb );
1325 }
1326 // create constants
1327 /*
1328 else if ( Abc_Lit2Var(Fan) == SMT_PRS_DEFINE_FUN ) // added: we parse DEFINE_FUN in LET
1329 {
1330 assert( Vec_IntSize(vFans) == 5 );
1331 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_DEFINE_FUN) );
1332 // get name
1333 Fan = Vec_IntEntry(vFans, 1);
1334 assert( Smt_EntryIsName(Fan) );
1335 pName = Smt_EntryName(p, Fan);
1336
1337 // added: giving a global suffix
1338 char * pName_glb = (char *) malloc(strlen(pName) + 4 + 1);
1339 strcpy(pName_glb,pName);
1340 strcat(pName_glb,SMT_GLO_SUFFIX);
1341 // FIXME: delete memory of pName
1342 pName = pName_glb;
1343
1344 // skip ()
1345 Fan = Vec_IntEntry(vFans, 2);
1346 assert( !Smt_EntryIsName(Fan) );
1347 // check type (Bool or BitVec)
1348 Fan = Vec_IntEntry(vFans, 3);
1349 if ( Smt_EntryIsName(Fan) )
1350 {
1351 // (define-fun s_2 () Bool false)
1352 assert( !strcmp("Bool", Smt_VecEntryName(p, vFans, 3)) );
1353 Range = 1;
1354 pValue = Smt_VecEntryName(p, vFans, 4);
1355
1356 //printf("value: %s\n",pValue);
1357
1358 if ( !strcmp("false", pValue) )
1359 pValue = "#b0";
1360 else if ( !strcmp("true", pValue) )
1361 pValue = "#b1";
1362 else assert( 0 );
1363 Status = Smt_PrsBuildConstant( pNtk, pValue, Range, pName );
1364 }
1365 else
1366 {
1367 // (define-fun s702 () (_ BitVec 4) #xe)
1368 // (define-fun s1 () (_ BitVec 8) (bvneg #x7f))
1369 // get range
1370 Fan = Vec_IntEntry(vFans, 3);
1371
1372 assert( !Smt_EntryIsName(Fan) );
1373 vFans2 = Smt_VecEntryNode(p, vFans, 3);
1374 assert( Vec_IntSize(vFans2) == 3 );
1375 assert( !strcmp("_", Smt_VecEntryName(p, vFans2, 0)) );
1376 assert( !strcmp("BitVec", Smt_VecEntryName(p, vFans2, 1)) );
1377 // get range
1378 Fan = Vec_IntEntry(vFans2, 2);
1379
1380 assert( Smt_EntryIsName(Fan) );
1381 pRange = Smt_EntryName(p, Fan);
1382 Range = atoi(pRange);
1383
1384 // added: can parse functions too
1385 Vec_Int_t * vFans3 = Smt_VecEntryNode(p, vFans, 4);
1386 Fan = Vec_IntEntry(vFans3, 0);
1387
1388 // get constant
1389 //Fan = Vec_IntEntry(vFans, 4);
1390
1391 //printf("fan3: %s\n",Fan);
1392 //printf("fan0: %s\n",Smt_VecEntryName(p, vFans3, 0));
1393 //printf("fan1: %s\n",Smt_VecEntryName(p, vFans3, 1));
1394 //printf("fan2: %s\n",Smt_VecEntryName(p, vFans3, 2));
1395 //printf("fan3: %s\n",Smt_VecEntryName(p, vFans3, 3));
1396
1397 Status = Smt_PrsBuildNode( pNtk, p, Fan, Range, pName );
1398 }
1399 if ( !Status )
1400 {
1401 Wlc_NtkFree( pNtk ); pNtk = NULL;
1402 goto finish;
1403 }
1404 }
1405 */
1406 // added: new way to parse define-fun
1407 // create constants
1408 else if ( Abc_Lit2Var(Fan) == SMT_PRS_DEFINE_FUN )
1409 {
1410 char * pName_glb;
1411 // (define-fun def_16001 () Bool (or def_15999 def_16000))
1412 // (define-fun def_15990 () (_ BitVec 24) (concat def_15988 def_15989))
1413 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_DEFINE_FUN) );
1414 assert( Vec_IntSize(vFans) == 5 ); // const or definition
1415
1416 // get name
1417 Fan = Vec_IntEntry(vFans, 1);
1418 assert( Smt_EntryIsName(Fan) );
1419 pName = Smt_EntryName(p, Fan);
1420 // added: giving a global suffix
1421 pName_glb = (char *) malloc(strlen(pName) + 4 + 1);
1422 strcpy(pName_glb,pName);
1423 strcat(pName_glb,SMT_GLO_SUFFIX);
1424 // FIXME: delete memory of pName
1425 pName = pName_glb;
1426
1427 //get range
1428 Fan = Vec_IntEntry(vFans, 3);
1429 if ( Smt_EntryIsName(Fan) )
1430 {
1431 // (define-fun s_2 () Bool false)
1432 assert( !strcmp("Bool", Smt_VecEntryName(p, vFans, 3)) );
1433 Range = 1;
1434 }
1435 else
1436 {
1437 // (define-fun s702 () (_ BitVec 4) #xe)
1438 // (define-fun s1 () (_ BitVec 8) (bvneg #x7f))
1439 assert( !Smt_EntryIsName(Fan) );
1440 vFans2 = Smt_VecEntryNode(p, vFans, 3);
1441 assert( Vec_IntSize(vFans2) == 3 );
1442 assert( !strcmp("_", Smt_VecEntryName(p, vFans2, 0)) );
1443 assert( !strcmp("BitVec", Smt_VecEntryName(p, vFans2, 1)) );
1444 // get range
1445 Fan = Vec_IntEntry(vFans2, 2);
1446 assert( Smt_EntryIsName(Fan) );
1447 pRange = Smt_EntryName(p, Fan);
1448 Range = atoi(pRange);
1449 }
1450
1451 iObj = Smt_PrsBuild2_rec( pNtk, p, Vec_IntEntry(vFans, 4), Range, pName );
1452 assert( iObj );
1453 ABC_FREE( pName_glb );
1454 }
1455
1456 // collect assertion outputs
1457 else if ( Abc_Lit2Var(Fan) == SMT_PRS_ASSERT )
1458 {
1459 //(assert ; no quantifiers
1460 // (let ((s2 (bvsge s0 s1)))
1461 // (not s2)))
1462 //(assert (not (= s0 #x00)))
1463 assert( Vec_IntSize(vFans) == 2 );
1464 assert( Smt_VecEntryIsType(vFans, 0, SMT_PRS_ASSERT) );
1465 pNtk->nAssert++; // added
1466 iObj = Smt_PrsBuild2_rec( pNtk, p, Vec_IntEntry(vFans, 1), -1, NULL );
1467 if ( iObj == 0 )
1468 {
1469 Wlc_NtkFree( pNtk ); pNtk = NULL;
1470 goto finish;
1471 }
1472 Vec_IntPush( vAsserts, iObj );
1473 }
1474 // issue warnings about unknown dirs
1475 else if ( Abc_Lit2Var(Fan) >= SMT_PRS_END )
1476 printf( "Ignoring directive \"%s\".\n", Smt_EntryName(p, Fan) );
1477 }
1478 // build AND of asserts
1479 if ( Vec_IntSize(vAsserts) == 1 )
1480 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_BUF, 0, 1, vAsserts, "miter" );
1481 // added: 0 asserts
1482 else if ( Vec_IntSize(vAsserts) == 0 )
1483 iObj = Smt_PrsBuildConstant( pNtk, "#b1", 1, "miter" );
1484 else
1485 {
1486 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_BIT_CONCAT, 0, Vec_IntSize(vAsserts), vAsserts, NULL );
1487 Vec_IntFill( vAsserts, 1, iObj );
1488 iObj = Smt_PrsCreateNode( pNtk, WLC_OBJ_REDUCT_AND, 0, 1, vAsserts, "miter" );
1489 }
1490 Wlc_ObjSetCo( pNtk, Wlc_NtkObj(pNtk, iObj), 0 );
1491 // create nameIDs
1492 vFans = Vec_IntStartNatural( Wlc_NtkObjNumMax(pNtk) );
1493 Vec_IntAppend( &pNtk->vNameIds, vFans );
1494 Vec_IntFree( vFans );
1495 //Wlc_NtkReport( pNtk, NULL );
1496finish:
1497 // cleanup
1498 Vec_IntFree(vAsserts);
1499 return pNtk;
1500}
1501
1502
1503
1515// create error message
1516static inline int Smt_PrsErrorSet( Smt_Prs_t * p, char * pError, int Value )
1517{
1518 assert( !p->ErrorStr[0] );
1519 sprintf( p->ErrorStr, "%s", pError );
1520 return Value;
1521}
1522// print error message
1523static inline int Smt_PrsErrorPrint( Smt_Prs_t * p )
1524{
1525 char * pThis; int iLine = 0;
1526 if ( !p->ErrorStr[0] ) return 1;
1527 for ( pThis = p->pBuffer; pThis < p->pCur; pThis++ )
1528 iLine += (int)(*pThis == '\n');
1529 printf( "Line %d: %s\n", iLine, p->ErrorStr );
1530 return 0;
1531}
1532static inline char * Smt_PrsLoadFile( char * pFileName, char ** ppLimit )
1533{
1534 char * pBuffer;
1535 int nFileSize, RetValue;
1536 FILE * pFile = fopen( pFileName, "rb" );
1537 if ( pFile == NULL )
1538 {
1539 printf( "Cannot open input file.\n" );
1540 return NULL;
1541 }
1542 // get the file size, in bytes
1543 fseek( pFile, 0, SEEK_END );
1544 nFileSize = ftell( pFile );
1545 // move the file current reading position to the beginning
1546 rewind( pFile );
1547 // load the contents of the file into memory
1548 pBuffer = ABC_ALLOC( char, nFileSize + 16 );
1549 pBuffer[0] = '\n';
1550 RetValue = fread( pBuffer+1, nFileSize, 1, pFile );
1551 fclose( pFile );
1552 // terminate the string with '\0'
1553 pBuffer[nFileSize + 1] = '\n';
1554 pBuffer[nFileSize + 2] = '\0';
1555 *ppLimit = pBuffer + nFileSize + 2;
1556 return pBuffer;
1557}
1558static inline int Smt_PrsRemoveComments( char * pBuffer, char * pLimit )
1559{
1560 char * pTemp; int nCount1 = 0, nCount2 = 0, fHaveBar = 0;
1561 int backslash = 0;
1562 for ( pTemp = pBuffer; pTemp < pLimit; pTemp++ )
1563 {
1564 if ( *pTemp == '(' )
1565 { if ( !fHaveBar ) nCount1++; }
1566 else if ( *pTemp == ')' )
1567 { if ( !fHaveBar ) nCount2++; }
1568 else if ( *pTemp == '|' )
1569 fHaveBar ^= 1;
1570 else if ( *pTemp == ';' && !fHaveBar )
1571 while ( *pTemp && *pTemp != '\n' )
1572 *pTemp++ = ' ';
1573 // added: hack to remove quotes
1574 else if ( *pTemp == '\"' && *(pTemp-1) != '\\' && !fHaveBar )
1575 {
1576 *pTemp++ = ' ';
1577 while ( *pTemp && (*pTemp != '\"' || backslash))
1578 {
1579 if (*pTemp == '\\')
1580 backslash = 1;
1581 else
1582 backslash = 0;
1583 *pTemp++ = ' ';
1584 }
1585 // remove the last quote symbol
1586 *pTemp = ' ';
1587 }
1588 }
1589
1590 if ( nCount1 != nCount2 )
1591 printf( "The input SMTLIB file has different number of opening and closing parentheses (%d and %d).\n", nCount1, nCount2 );
1592 else if ( nCount1 == 0 )
1593 printf( "The input SMTLIB file has no opening or closing parentheses.\n" );
1594 return nCount1 == nCount2 ? nCount1 : 0;
1595}
1596static inline Smt_Prs_t * Smt_PrsAlloc( char * pFileName, char * pBuffer, char * pLimit, int nObjs )
1597{
1598 Smt_Prs_t * p;
1599 if ( nObjs == 0 )
1600 return NULL;
1601 p = ABC_CALLOC( Smt_Prs_t, 1 );
1602 p->pName = pFileName;
1603 p->pBuffer = pBuffer;
1604 p->pLimit = pLimit;
1605 p->pCur = pBuffer;
1606 p->pStrs = Abc_NamStart( 1000, 24 );
1607 Smt_AddTypes( p->pStrs );
1608 Vec_IntGrow( &p->vStack, 100 );
1609 //Vec_WecGrow( &p->vDepth, 100 );
1610 Vec_WecGrow( &p->vObjs, nObjs+1 );
1611 return p;
1612}
1613static inline void Smt_PrsFree( Smt_Prs_t * p )
1614{
1615 if ( p->pStrs )
1616 Abc_NamDeref( p->pStrs );
1617 Vec_IntErase( &p->vStack );
1618 Vec_IntErase( &p->vTempFans );
1619 //Vec_WecErase( &p->vDepth );
1620 Vec_WecErase( &p->vObjs );
1621 ABC_FREE( p );
1622}
1623
1635static inline int Smt_PrsIsSpace( char c )
1636{
1637 return c == ' ' || c == '\t' || c == '\r' || c == '\n';
1638}
1639static inline void Smt_PrsSkipSpaces( Smt_Prs_t * p )
1640{
1641 while ( Smt_PrsIsSpace(*p->pCur) )
1642 p->pCur++;
1643}
1644static inline void Smt_PrsSkipNonSpaces( Smt_Prs_t * p )
1645{
1646 while ( p->pCur < p->pLimit && !Smt_PrsIsSpace(*p->pCur) && *p->pCur != '(' && *p->pCur != ')' )
1647 p->pCur++;
1648}
1650{
1651 int fFirstTime = 1;
1652 assert( Vec_IntSize(&p->vStack) == 0 );
1653 //assert( Vec_WecSize(&p->vDepth) == 0 );
1654 assert( Vec_WecSize(&p->vObjs) == 0 );
1655 // add top node at level 0
1656 //Vec_WecPushLevel( &p->vDepth );
1657 //Vec_WecPush( &p->vDepth, Vec_IntSize(&p->vStack), Vec_WecSize(&p->vObjs) );
1658 // add top node
1659 Vec_IntPush( &p->vStack, Vec_WecSize(&p->vObjs) );
1660 Vec_WecPushLevel( &p->vObjs );
1661 // add other nodes
1662 for ( p->pCur = p->pBuffer; p->pCur < p->pLimit; p->pCur++ )
1663 {
1664 Smt_PrsSkipSpaces( p );
1665 if ( fFirstTime && *p->pCur == '|' )
1666 {
1667 fFirstTime = 0;
1668 *p->pCur = ' ';
1669 while ( *p->pCur && *p->pCur != '|' )
1670 *p->pCur++ = ' ';
1671 if ( *p->pCur == '|' )
1672 *p->pCur = ' ';
1673 continue;
1674 }
1675 if ( *p->pCur == '(' )
1676 {
1677 // add new node at this depth
1678 //assert( Vec_WecSize(&p->vDepth) >= Vec_IntSize(&p->vStack) );
1679 //if ( Vec_WecSize(&p->vDepth) == Vec_IntSize(&p->vStack) )
1680 // Vec_WecPushLevel(&p->vDepth);
1681 //Vec_WecPush( &p->vDepth, Vec_IntSize(&p->vStack), Vec_WecSize(&p->vObjs) );
1682 // add fanin to node on the previous level
1683 Vec_IntPush( Vec_WecEntry(&p->vObjs, Vec_IntEntryLast(&p->vStack)), Abc_Var2Lit(Vec_WecSize(&p->vObjs), 0) );
1684 // add node to the stack
1685 Vec_IntPush( &p->vStack, Vec_WecSize(&p->vObjs) );
1686 Vec_WecPushLevel( &p->vObjs );
1687 }
1688 else if ( *p->pCur == ')' )
1689 {
1690 Vec_IntPop( &p->vStack );
1691 }
1692 else // token
1693 {
1694 char * pStart = p->pCur;
1695 Smt_PrsSkipNonSpaces( p );
1696 if ( p->pCur < p->pLimit )
1697 {
1698 // remove strange characters (this can lead to name clashes)
1699 int iToken;
1700 /* commented out for SMT comp
1701 char * pTemp;
1702 if ( *pStart == '?' )
1703 *pStart = '_';
1704 for ( pTemp = pStart; pTemp < p->pCur; pTemp++ )
1705 if ( *pTemp == '.' )
1706 *pTemp = '_';*/
1707 // create and save token for this string
1708 iToken = Abc_NamStrFindOrAddLim( p->pStrs, pStart, p->pCur--, NULL );
1709 Vec_IntPush( Vec_WecEntry(&p->vObjs, Vec_IntEntryLast(&p->vStack)), Abc_Var2Lit(iToken, 1) );
1710 }
1711 }
1712 }
1713 assert( Vec_IntSize(&p->vStack) == 1 );
1714 assert( Vec_WecSize(&p->vObjs) == Vec_WecCap(&p->vObjs) );
1715 p->nDigits = Abc_Base16Log( Vec_WecSize(&p->vObjs) );
1716}
1717void Smt_PrsPrintParser_rec( Smt_Prs_t * p, int iObj, int Depth )
1718{
1719 Vec_Int_t * vFans; int i, Fan;
1720 printf( "%*s(\n", Depth, "" );
1721 vFans = Vec_WecEntry( &p->vObjs, iObj );
1722 Vec_IntForEachEntry( vFans, Fan, i )
1723 {
1724 if ( Abc_LitIsCompl(Fan) )
1725 {
1726 printf( "%*s", Depth+2, "" );
1727 printf( "%s\n", Abc_NamStr(p->pStrs, Abc_Lit2Var(Fan)) );
1728 }
1729 else
1730 Smt_PrsPrintParser_rec( p, Abc_Lit2Var(Fan), Depth+4 );
1731 }
1732 printf( "%*s)\n", Depth, "" );
1733}
1735{
1736// Vec_WecPrint( &p->vDepth, 0 );
1737 Smt_PrsPrintParser_rec( p, 0, 0 );
1738}
1739
1751Wlc_Ntk_t * Wlc_ReadSmtBuffer( char * pFileName, char * pBuffer, char * pLimit, int fOldParser, int fPrintTree )
1752{
1753 Wlc_Ntk_t * pNtk = NULL;
1754 int nCount = Smt_PrsRemoveComments( pBuffer, pLimit );
1755 Smt_Prs_t * p = Smt_PrsAlloc( pFileName, pBuffer, pLimit, nCount );
1756 if ( p == NULL )
1757 return NULL;
1759 if ( fPrintTree )
1761 if ( Smt_PrsErrorPrint(p) )
1762 pNtk = fOldParser ? Smt_PrsBuild(p) : Smt_PrsBuild2(p);
1763 Smt_PrsFree( p );
1764 return pNtk;
1765}
1766Wlc_Ntk_t * Wlc_ReadSmt( char * pFileName, int fOldParser, int fPrintTree )
1767{
1768 Wlc_Ntk_t * pNtk = NULL;
1769 char * pBuffer, * pLimit;
1770 pBuffer = Smt_PrsLoadFile( pFileName, &pLimit );
1771 if ( pBuffer == NULL )
1772 return NULL;
1773 pNtk = Wlc_ReadSmtBuffer( pFileName, pBuffer, pLimit, fOldParser, fPrintTree );
1774 ABC_FREE( pBuffer );
1775 return pNtk;
1776}
1777
1778
1782
1783
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
#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_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
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
char * pName
Definition wlcReadSmt.c:74
Smt_LineType_t Type
Definition wlcReadSmt.c:73
char * pBuffer
Definition wlcReadSmt.c:36
Abc_Nam_t * pStrs
Definition wlcReadSmt.c:39
char * pName
Definition wlcReadSmt.c:35
Vec_Int_t vTempFans
Definition wlcReadSmt.c:46
Vec_Wec_t vObjs
Definition wlcReadSmt.c:43
Vec_Int_t vStack
Definition wlcReadSmt.c:41
char ErrorStr[1000]
Definition wlcReadSmt.c:48
int NameCount
Definition wlcReadSmt.c:44
char * pCur
Definition wlcReadSmt.c:38
char * pLimit
Definition wlcReadSmt.c:37
int fSmtLib
Definition wlc.h:151
Abc_Nam_t * pManName
Definition wlc.h:165
int nAssert
Definition wlc.h:155
Vec_Int_t vValues
Definition wlc.h:167
Vec_Int_t vNameIds
Definition wlc.h:166
int Abc_NamStrFind(Abc_Nam_t *p, char *pStr)
Definition utilNam.c:433
int Abc_NamStrFindOrAddLim(Abc_Nam_t *p, char *pStr, char *pLim, int *pfFound)
Definition utilNam.c:492
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
Definition utilNam.c:453
int Abc_NamObjNumMax(Abc_Nam_t *p)
Definition utilNam.c:231
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
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
int strlen()
int strcmp()
char * sprintf()
char * strcpy()
VOID_HACK rewind()
char * strcat()
char * malloc()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
int Smt_PrsBuildNode(Wlc_Ntk_t *pNtk, Smt_Prs_t *p, int iNode, int RangeOut, char *pName)
Definition wlcReadSmt.c:667
char * Smt_PrsGenName(Smt_Prs_t *p)
#define SMT_GLO_SUFFIX
Definition wlcReadSmt.c:52
Wlc_Ntk_t * Smt_PrsBuild(Smt_Prs_t *p)
Definition wlcReadSmt.c:799
struct Smt_Pair_t_ Smt_Pair_t
Definition wlcReadSmt.c:70
void Smt_PrsReadLines(Smt_Prs_t *p)
Wlc_Ntk_t * Smt_PrsBuild2(Smt_Prs_t *p)
Smt_LineType_t
Definition wlcReadSmt.c:55
@ SMT_PRS_NONE
Definition wlcReadSmt.c:56
@ SMT_PRS_DEFINE_FUN
Definition wlcReadSmt.c:60
@ SMT_PRS_SET_OPTION
Definition wlcReadSmt.c:57
@ SMT_PRS_SET_INFO
Definition wlcReadSmt.c:59
@ SMT_PRS_LET
Definition wlcReadSmt.c:63
@ SMT_PRS_END
Definition wlcReadSmt.c:67
@ SMT_PRS_ASSERT
Definition wlcReadSmt.c:62
@ SMT_PRS_DECLARE_FUN
Definition wlcReadSmt.c:61
@ SMT_PRS_SET_LOGIC
Definition wlcReadSmt.c:58
@ SMT_PRS_EXIT
Definition wlcReadSmt.c:66
@ SMT_PRS_GET_VALUE
Definition wlcReadSmt.c:65
@ SMT_PRS_CHECK_SAT
Definition wlcReadSmt.c:64
void Smt_PrsPrintParser(Smt_Prs_t *p)
Wlc_Ntk_t * Wlc_ReadSmtBuffer(char *pFileName, char *pBuffer, char *pLimit, int fOldParser, int fPrintTree)
typedefABC_NAMESPACE_IMPL_START struct Smt_Prs_t_ Smt_Prs_t
DECLARATIONS ///.
Definition wlcReadSmt.c:31
#define Smt_ManForEachDir(p, Type, vVec, i)
Definition wlcReadSmt.c:115
void Smt_PrsPrintParser_rec(Smt_Prs_t *p, int iObj, int Depth)
int Smt_PrsBuild2_rec(Wlc_Ntk_t *pNtk, Smt_Prs_t *p, int iNode, int iObjPrev, char *pName)
Wlc_Ntk_t * Wlc_ReadSmt(char *pFileName, int fOldParser, int fPrintTree)
int Wlc_ObjAlloc(Wlc_Ntk_t *p, int Type, int Signed, int End, int Beg)
Definition wlcNtk.c:199
void Wlc_ObjSetCo(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, int fFlopInput)
Definition wlcNtk.c:188
Wlc_Ntk_t * Wlc_NtkAlloc(char *pName, int nObjsAlloc)
Definition wlcNtk.c:152
void Wlc_NtkFree(Wlc_Ntk_t *p)
Definition wlcNtk.c:253
struct Wlc_Ntk_t_ Wlc_Ntk_t
Definition wlc.h:135
void Wlc_ObjAddFanins(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, Vec_Int_t *vFanins)
Definition wlcNtk.c:240
char * Wlc_ObjName(Wlc_Ntk_t *p, int iObj)
Definition wlcNtk.c:225
@ WLC_OBJ_ARI_MULTI
Definition wlc.h:90
@ WLC_OBJ_BIT_SIGNEXT
Definition wlc.h:70
@ WLC_OBJ_COMP_LESSEQU
Definition wlc.h:80
@ WLC_OBJ_LOGIC_XOR
Definition wlc.h:75
@ WLC_OBJ_BIT_ZEROPAD
Definition wlc.h:69
@ WLC_OBJ_COMP_MOREEQU
Definition wlc.h:81
@ WLC_OBJ_BUF
Definition wlc.h:52
@ WLC_OBJ_COMP_MORE
Definition wlc.h:79
@ WLC_OBJ_REDUCT_AND
Definition wlc.h:82
@ WLC_OBJ_ARI_REM
Definition wlc.h:92
@ WLC_OBJ_ARI_SUB
Definition wlc.h:89
@ WLC_OBJ_LOGIC_OR
Definition wlc.h:74
@ WLC_OBJ_LOGIC_AND
Definition wlc.h:73
@ WLC_OBJ_COMP_LESS
Definition wlc.h:78
@ WLC_OBJ_BIT_NOT
Definition wlc.h:60
@ WLC_OBJ_SHIFT_R
Definition wlc.h:54
@ WLC_OBJ_BIT_AND
Definition wlc.h:61
@ WLC_OBJ_CONST
Definition wlc.h:51
@ WLC_OBJ_ARI_DIVIDE
Definition wlc.h:91
@ WLC_OBJ_BIT_SELECT
Definition wlc.h:67
@ WLC_OBJ_REDUCT_OR
Definition wlc.h:83
@ WLC_OBJ_MUX
Definition wlc.h:53
@ WLC_OBJ_BIT_NAND
Definition wlc.h:64
@ WLC_OBJ_LOGIC_NOT
Definition wlc.h:71
@ WLC_OBJ_COMP_NOTEQU
Definition wlc.h:77
@ WLC_OBJ_PI
Definition wlc.h:46
@ WLC_OBJ_REDUCT_XOR
Definition wlc.h:84
@ WLC_OBJ_BIT_NOR
Definition wlc.h:65
@ WLC_OBJ_BIT_CONCAT
Definition wlc.h:68
@ WLC_OBJ_BIT_OR
Definition wlc.h:62
@ WLC_OBJ_BIT_XOR
Definition wlc.h:63
@ WLC_OBJ_ARI_MINUS
Definition wlc.h:95
@ WLC_OBJ_ARI_MODULUS
Definition wlc.h:93
@ WLC_OBJ_ARI_ADD
Definition wlc.h:88
@ WLC_OBJ_COMP_EQU
Definition wlc.h:76
@ WLC_OBJ_LOGIC_IMPL
Definition wlc.h:72
@ WLC_OBJ_SHIFT_L
Definition wlc.h:56
@ WLC_OBJ_BIT_NXOR
Definition wlc.h:66
@ WLC_OBJ_ROTATE_L
Definition wlc.h:59
@ WLC_OBJ_SHIFT_RA
Definition wlc.h:55
@ WLC_OBJ_ROTATE_R
Definition wlc.h:58
#define SEEK_END
Definition zconf.h:392