52#define SMT_GLO_SUFFIX ""
94 if ( s_Types[i].Type == Type )
95 return s_Types[i].pName;
98static inline void Smt_AddTypes(
Abc_Nam_t *
p )
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) ); }
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)); }
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
134static inline int Smt_StrToType(
char * pName,
int * pfSigned )
136 int Type = 0; *pfSigned = 0;
137 if ( !
strcmp(pName,
"ite") )
139 else if ( !
strcmp(pName,
"bvlshr") )
141 else if ( !
strcmp(pName,
"bvashr") )
143 else if ( !
strcmp(pName,
"bvshl") )
147 else if ( !
strcmp(pName,
"rotate_right") )
149 else if ( !
strcmp(pName,
"rotate_left") )
151 else if ( !
strcmp(pName,
"bvnot") )
153 else if ( !
strcmp(pName,
"bvand") )
155 else if ( !
strcmp(pName,
"bvor") )
157 else if ( !
strcmp(pName,
"bvxor") )
159 else if ( !
strcmp(pName,
"bvnand") )
161 else if ( !
strcmp(pName,
"bvnor") )
163 else if ( !
strcmp(pName,
"bvxnor") )
165 else if ( !
strcmp(pName,
"extract") )
167 else if ( !
strcmp(pName,
"concat") )
169 else if ( !
strcmp(pName,
"zero_extend") )
171 else if ( !
strcmp(pName,
"sign_extend") )
173 else if ( !
strcmp(pName,
"not") )
175 else if ( !
strcmp(pName,
"=>") )
177 else if ( !
strcmp(pName,
"and") )
179 else if ( !
strcmp(pName,
"or") )
181 else if ( !
strcmp(pName,
"xor") )
183 else if ( !
strcmp(pName,
"bvcomp") || !
strcmp(pName,
"=") )
185 else if ( !
strcmp(pName,
"distinct") )
187 else if ( !
strcmp(pName,
"bvult") )
189 else if ( !
strcmp(pName,
"bvugt") )
191 else if ( !
strcmp(pName,
"bvule") )
193 else if ( !
strcmp(pName,
"bvuge") )
195 else if ( !
strcmp(pName,
"bvslt") )
197 else if ( !
strcmp(pName,
"bvsgt") )
199 else if ( !
strcmp(pName,
"bvsle") )
201 else if ( !
strcmp(pName,
"bvsge") )
203 else if ( !
strcmp(pName,
"bvredand") )
205 else if ( !
strcmp(pName,
"bvredor") )
207 else if ( !
strcmp(pName,
"bvredxor") )
209 else if ( !
strcmp(pName,
"bvadd") )
211 else if ( !
strcmp(pName,
"bvsub") )
213 else if ( !
strcmp(pName,
"bvmul") )
215 else if ( !
strcmp(pName,
"bvudiv") )
217 else if ( !
strcmp(pName,
"bvurem") )
219 else if ( !
strcmp(pName,
"bvsdiv") )
221 else if ( !
strcmp(pName,
"bvsrem") )
223 else if ( !
strcmp(pName,
"bvsmod") )
225 else if ( !
strcmp(pName,
"=") )
229 else if ( !
strcmp(pName,
"bvneg") )
235 printf(
"The following operations is currently not supported (%s)\n", pName );
240static inline int Smt_PrsReadType(
Smt_Prs_t *
p,
int iSig,
int * pfSigned,
int * Value1,
int * Value2 )
242 if ( Smt_EntryIsName(iSig) )
243 return Smt_StrToType( Smt_EntryName(
p, iSig), pfSigned );
247 char * pStr = Smt_VecEntryName(
p, vFans, 0 );
int Type;
248 assert( Vec_IntSize(vFans) >= 3 );
250 *Value1 = *Value2 = -1;
251 assert( pStr[0] !=
'b' || pStr[1] !=
'v' );
253 Type = Smt_StrToType( Smt_VecEntryName(
p, vFans, 1), pfSigned );
256 *Value1 = atoi( Smt_VecEntryName(
p, vFans, 2) );
257 if ( Vec_IntSize(vFans) > 3 )
258 *Value2 = atoi( Smt_VecEntryName(
p, vFans, 3) );
263static inline int Smt_StrType(
char * str ) {
return Smt_StrToType(str, NULL); }
276static inline int Smt_PrsCreateNodeOld(
Wlc_Ntk_t * pNtk,
int Type,
int fSigned,
int Range,
Vec_Int_t * vFanins,
char * pName )
280 int iObj =
Wlc_ObjAlloc( pNtk, Type, fSigned, Range-1, 0 );
288 sprintf( Buffer,
"_n%d_", iObj );
298 Wlc_NtkObj(pNtk, iObj)->Signed = fSigned;
307static inline int Smt_PrsCreateNode(
Wlc_Ntk_t * pNtk,
int Type,
int fSigned,
int Range,
Vec_Int_t * vFanins,
char * pName )
311 int NameId, fFound, old_size, new_size;
312 int iObj, iFanin0, iFanin1;
313 Vec_Int_t * v2Fanins = Vec_IntStartFull(2);
321 if (Vec_IntSize(vFanins)<=2 ||
345 goto FINISHED_WITH_FANINS;
348 while (Vec_IntSize(vFanins)>2)
351 old_size = Vec_IntSize(vFanins);
352 iFanin0 = Vec_IntPop(vFanins);
353 iFanin1 = Vec_IntPop(vFanins);
355 Vec_IntWriteEntry(v2Fanins,0,iFanin0);
356 Vec_IntWriteEntry(v2Fanins,1,iFanin1);
359 sprintf( Buffer,
"_n%d_", iObj );
369 Vec_IntPush(vFanins, iObj);
370 new_size = Vec_IntSize(vFanins);
371 assert(new_size<old_size);
376 Vec_IntFree(v2Fanins);
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) );
391 Vec_Int_t * newFanins = Vec_IntAlloc(10);
392 Vec_IntPush(newFanins,iFanin1);
393 Vec_IntPushTwo( newFanins, 30, 0 );
396 sprintf( Buffer,
"_n%d_", iObj1 );
401 assert( iObj1 == NameId );
408 Vec_IntPop(newFanins);
409 Vec_IntPop(newFanins);
410 Vec_IntPushTwo( newFanins, range1-1, 31 );
412 sprintf( Buffer,
"_n%d_", iObj2 );
417 assert( iObj2 == NameId );
423 Vec_IntPop( newFanins );
424 Vec_IntPop( newFanins );
425 Vec_IntWriteEntry( newFanins, 0, iObj2 );
427 sprintf( Buffer,
"_n%d_", iObj3 );
432 assert( iObj3 == NameId );
438 Vec_IntWriteEntry( newFanins, 0, iObj3 );
439 Vec_IntPush( newFanins, iObj1 );
441 sprintf( Buffer,
"_n%d_", iObj );
452 Vec_IntWriteEntry(vFanins, 1, iObj);
453 Vec_IntFree(newFanins);
462 sprintf( Buffer,
"_n%d_", iObj );
472 Wlc_NtkObj(pNtk, iObj)->Signed = fSigned;
482static inline char * Smt_GetHexFromDecimalString(
char * pStr)
484 int i,k=0, nDigits =
strlen(pStr);
485 int digit, carry = 0;
486 int metNonZeroBit = 0;
488 Vec_Int_t * decimal = Vec_IntAlloc(nDigits);
493 for (i=0;i<nDigits;i++)
494 Vec_IntPush(decimal,pStr[i]-
'0');
497 rev = Vec_IntAlloc(10);
500 digit = Vec_IntEntry(decimal,k);
501 if (!digit && !carry)
510 Vec_IntPush(rev,carry);
522 digit = carry*10 + digit;
525 Vec_IntWriteEntry(decimal,k,digit);
530 Vec_IntPush(rev,carry);
537 Vec_IntFree(decimal);
539 if (!Vec_IntSize(rev))
542 while (Vec_IntSize(rev)%4)
545 nBits = Vec_IntSize(rev);
546 hex = (
char *)
malloc((nBits/4+1)*
sizeof(
char));
548 for (k=0;k<nBits/4;k++)
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);
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;
572 hex[nBits/4-1-k] = letter;
584static inline int Smt_PrsBuildConstant(
Wlc_Ntk_t * pNtk,
char * pStr,
int nBits,
char * pName )
586 int i, nDigits, iObj;
587 Vec_Int_t * vFanins = Vec_IntAlloc( 10 );
588 if ( pStr[0] !=
'#' )
590 if ( pStr[0] >=
'0' && pStr[0] <=
'9' )
600 char * pHex = Smt_GetHexFromDecimalString(pStr);
607 Vec_IntFill( vFanins, Abc_BitWordNum(nBits), 0 );
608 nDigits = Abc_TtReadHexNumber( (
word *)Vec_IntArray(vFanins), pHex );
627 Vec_IntFree( vFanins );
631 else if ( pStr[1] ==
'b' )
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' )
641 Vec_IntFree( vFanins );
645 else if ( pStr[1] ==
'x' )
649 Vec_IntFill( vFanins, Abc_BitWordNum(nBits), 0 );
650 nDigits = Abc_TtReadHexNumber( (
word *)Vec_IntArray(vFanins), pStr+2 );
651 if ( nDigits != (nBits + 3)/4 )
653 Vec_IntFree( vFanins );
659 Vec_IntFree( vFanins );
663 iObj = Smt_PrsCreateNode( pNtk,
WLC_OBJ_CONST, 0, nBits, vFanins, pName );
664 Vec_IntFree( vFanins );
669 if ( Smt_EntryIsName(iNode) )
671 char * pStr =
Abc_NamStr(
p->pStrs, Abc_Lit2Var(iNode));
672 if ( (pStr[0] >=
'0' && pStr[0] <=
'9') || pStr[0] ==
'#' )
675 return Smt_PrsBuildConstant( pNtk, pStr, RangeOut, pName );
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' )
693 char * pStr2 = Smt_VecEntryName(
p, vFans, 2 );
694 assert( Vec_IntSize(vFans) == 3 );
695 return Smt_PrsBuildConstant( pNtk, pStr1+2, atoi(pStr2), pName );
697 else if ( pStr0 && pStr0[0] ==
'=' )
699 assert( Vec_IntSize(vFans) == 3 );
700 iNode = Vec_IntEntry(vFans, 2);
701 assert( Smt_EntryIsName(iNode) );
702 pStr0 = Smt_EntryName(
p, iNode);
704 if ( !
strcmp(
"#b1", pStr0) )
706 iNode = Vec_IntEntry(vFans, 1);
713 int iObj, iOper, iConst = Smt_PrsBuildConstant( pNtk, pStr0, -1, NULL );
715 iNode = Vec_IntEntry(vFans, 1);
718 Vec_IntPushTwo( vFanins, iOper, iConst );
720 Vec_IntFree( vFanins );
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 );
729 Vec_Int_t * vFanins = Vec_IntAlloc( 100 );
735 Vec_IntFree( vFanins );
738 Vec_IntPush( vFanins, iFanin );
744 assert( Value1 >= 0 && Value2 >= 0 && Value1 >= Value2 );
745 Vec_IntPushTwo( vFanins, Value1, Value2 );
751 sprintf( Buffer,
"%d", Value1 );
752 NameId = Smt_PrsBuildConstant( pNtk, Buffer, -1, NULL );
753 Vec_IntPush( vFanins, NameId );
760 Range = Value1 - Value2 + 1;
764 Range += Wlc_ObjRange( Wlc_NtkObj(pNtk, NameId) );
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) );
776 NameId = Vec_IntEntry(vFanins, 0);
777 Range = Wlc_ObjRange( Wlc_NtkObj(pNtk, NameId) );
781 NameId = Smt_PrsCreateNode( pNtk, Type, fSigned, Range, vFanins, pName );
782 Vec_IntFree( vFanins );
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;
807 vFans = Vec_WecEntry( &
p->vObjs, 0 );
810 assert( !Smt_EntryIsName(Fan) );
811 vFans2 = Smt_VecEntryNode(
p, vFans, i );
812 Fan = Vec_IntEntry(vFans2, 0);
813 assert( Smt_EntryIsName(Fan) );
815 printf(
"Ignoring directive \"%s\".\n", Smt_EntryName(
p, Fan) );
823 assert( Vec_IntSize(vFans) == 4 );
826 Fan = Vec_IntEntry(vFans, 1);
827 assert( Smt_EntryIsName(Fan) );
828 pName = Smt_EntryName(
p, Fan);
830 Fan = Vec_IntEntry(vFans, 2);
831 assert( !Smt_EntryIsName(Fan) );
833 Fan = Vec_IntEntry(vFans, 3);
834 if ( Smt_EntryIsName(Fan) )
844 Fan = Vec_IntEntry(vFans, 3);
845 assert( !Smt_EntryIsName(Fan) );
846 vFans2 = Smt_EntryNode(
p, Fan);
847 assert( Vec_IntSize(vFans2) == 3 );
850 Fan = Vec_IntEntry(vFans2, 2);
851 assert( Smt_EntryIsName(Fan) );
852 pRange = Smt_EntryName(
p, Fan);
853 Range = atoi(pRange);
860 Vec_IntPush( &pNtk->
vValues, NameId );
861 Vec_IntPush( &pNtk->
vValues, nBits );
862 Vec_IntPush( &pNtk->
vValues, Range );
868 assert( Vec_IntSize(vFans) == 5 );
871 Fan = Vec_IntEntry(vFans, 1);
872 assert( Smt_EntryIsName(Fan) );
873 pName = Smt_EntryName(
p, Fan);
875 Fan = Vec_IntEntry(vFans, 2);
876 assert( !Smt_EntryIsName(Fan) );
878 Fan = Vec_IntEntry(vFans, 3);
879 if ( Smt_EntryIsName(Fan) )
884 pValue = Smt_VecEntryName(
p, vFans, 4);
885 if ( !
strcmp(
"false", pValue) )
887 else if ( !
strcmp(
"true", pValue) )
890 Status = Smt_PrsBuildConstant( pNtk, pValue, Range, pName );
897 Fan = Vec_IntEntry(vFans, 3);
898 assert( !Smt_EntryIsName(Fan) );
899 vFans2 = Smt_VecEntryNode(
p, vFans, 3);
900 assert( Vec_IntSize(vFans2) == 3 );
904 Fan = Vec_IntEntry(vFans2, 2);
905 assert( Smt_EntryIsName(Fan) );
906 pRange = Smt_EntryName(
p, Fan);
907 Range = atoi(pRange);
909 Fan = Vec_IntEntry(vFans, 4);
922 assert( Vec_IntSize(vFans) == 3 );
925 Fan = Vec_IntEntry(vFans, 1);
926 assert( !Smt_EntryIsName(Fan) );
927 vFans2 = Smt_EntryNode(
p, Fan);
934 Fan = Vec_IntEntry(vFans2, 0);
935 assert( !Smt_EntryIsName(Fan) );
936 vFans3 = Smt_EntryNode(
p, Fan);
938 Fan3 = Vec_IntEntry(vFans3, 0);
939 assert( Smt_EntryIsName(Fan3) );
940 pName = Smt_EntryName(
p, Fan3);
942 Fan3 = Vec_IntEntry(vFans3, 1);
943 assert( !Smt_EntryIsName(Fan3) );
953 Vec_IntClear( vAsserts );
960 assert( Vec_IntSize(vFans) == 2 );
963 Fan = Vec_IntEntry(vFans, 1);
964 if ( !Smt_EntryIsName(Fan) )
967 vFans2 = Smt_VecEntryNode(
p, vFans, 1);
968 while ( Smt_VecEntryIsType(vFans2, 0,
SMT_PRS_LET) )
970 Fan = Vec_IntEntry(vFans2, 2);
971 if ( Smt_EntryIsName(Fan) )
973 vFans2 = Smt_VecEntryNode(
p, vFans2, 2);
983 Vec_IntPush( vAsserts, iObj );
986 if ( Vec_IntSize(vAsserts) == 1 )
987 iObj = Smt_PrsCreateNode( pNtk,
WLC_OBJ_BUF, 0, 1, vAsserts,
"miter_output" );
990 iObj = Smt_PrsCreateNode( pNtk,
WLC_OBJ_BIT_CONCAT, 0, Vec_IntSize(vAsserts), vAsserts, NULL );
991 Vec_IntFill( vAsserts, 1, iObj );
996 vFans = Vec_IntStartNatural( Wlc_NtkObjNumMax(pNtk) );
997 Vec_IntAppend( &pNtk->
vNameIds, vFans );
998 Vec_IntFree( vFans );
1002 Vec_IntFree(vAsserts);
1021 static char Buffer[16];
1022 sprintf( Buffer,
"_%0*X_",
p->nDigits, ++
p->NameCount );
1035 if ( Smt_EntryIsName(iNode) )
1037 char * pStr =
Abc_NamStr(
p->pStrs, Abc_Lit2Var(iNode));
1039 if ( !
strcmp(pStr,
"false") )
1041 else if ( !
strcmp(pStr,
"true") )
1043 if ( pStr[0] ==
'#' )
1044 return Smt_PrsBuildConstant( pNtk, pStr, -1, pName ? pName :
Smt_PrsGenName(
p) );
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 );
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) )
1089 char * pName2, * pStr0 =
Abc_NamStr(
p->pStrs, Abc_Lit2Var(iRoot0));
1093 assert( Vec_IntSize(vRoots) == 3 );
1096 iRoot1 = Vec_IntEntry(vRoots, 1);
1097 assert( !Smt_EntryIsName(iRoot1) );
1098 vRoots1 = Smt_EntryNode(
p, iRoot1);
1104 assert( !Smt_EntryIsName(Fan) );
1105 vFans3 = Smt_EntryNode(
p, Fan);
1106 assert( Vec_IntSize(vFans3) == 2 );
1108 Fan3 = Vec_IntEntry(vFans3, 0);
1109 assert( Smt_EntryIsName(Fan3) );
1110 pName2 = Smt_EntryName(
p, Fan3);
1126 Fan3 = Vec_IntEntry(vFans3, 1);
1138 iRoot2 = Vec_IntEntry(vRoots, 2);
1141 else if ( pStr0[0] ==
'_' )
1143 char * pStr1 = Smt_VecEntryName(
p, vRoots, 1 );
1144 if ( pStr1[0] ==
'b' && pStr1[1] ==
'v' )
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) );
1153 int Type1, fSigned = 0, Range = -1;
1154 assert( iObjPrev != -1 );
1155 Type1 = Smt_StrToType( pStr1, &fSigned );
1159 Vec_IntFill( &
p->vTempFans, 1, iObjPrev );
1162 int iRoot2 = Vec_IntEntry(vRoots, 2);
1163 char * pStr2 =
Abc_NamStr(
p->pStrs, Abc_Lit2Var(iRoot2));
1164 int Num = atoi( pStr2 );
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) );
1174 Range = Num + Wlc_ObjRange( Wlc_NtkObj(pNtk, iObjPrev) );
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 );
1185 Range = Num1 - Num2 + 1;
1186 Vec_IntPushTwo( &
p->vTempFans, Num1, Num2 );
1189 iObj = Smt_PrsCreateNode( pNtk, Type1, fSigned, Range, &
p->vTempFans, pName ? pName :
Smt_PrsGenName(
p) );
1196 int i, Fan, fSigned = 0, Range, Type0;
1200 Type0 = Smt_StrToType( pStr0, &fSigned );
1206 vFanins = Vec_IntAlloc( 100 );
1212 Vec_IntFree( vFanins );
1215 Vec_IntPush( vFanins, iObj );
1224 Range += Wlc_ObjRange( Wlc_NtkObj(pNtk, Fan) );
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) );
1236 iObj = Vec_IntEntry(vFanins, 0);
1237 Range = Wlc_ObjRange( Wlc_NtkObj(pNtk, iObj) );
1241 iObj = Smt_PrsCreateNode( pNtk, Type0, fSigned, Range, vFanins, pName ? pName :
Smt_PrsGenName(
p) );
1242 Vec_IntFree( vFanins );
1246 else if ( Vec_IntSize(vRoots) == 2 )
1249 if ( iObjPrev == 0 )
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;
1269 vFansRoot = Vec_WecEntry( &
p->vObjs, 0 );
1272 assert( !Smt_EntryIsName(Root) );
1273 vFans = Smt_VecEntryNode(
p, vFansRoot, i );
1274 Fan = Vec_IntEntry(vFans, 0);
1275 assert( Smt_EntryIsName(Fan) );
1280 assert( Vec_IntSize(vFans) == 4 );
1283 Fan = Vec_IntEntry(vFans, 1);
1284 assert( Smt_EntryIsName(Fan) );
1285 pName = Smt_EntryName(
p, Fan);
1293 Fan = Vec_IntEntry(vFans, 2);
1294 assert( !Smt_EntryIsName(Fan) );
1296 Fan = Vec_IntEntry(vFans, 3);
1297 if ( Smt_EntryIsName(Fan) )
1304 Fan = Vec_IntEntry(vFans, 3);
1305 assert( !Smt_EntryIsName(Fan) );
1306 vFans2 = Smt_EntryNode(
p, Fan);
1307 assert( Vec_IntSize(vFans2) == 3 );
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);
1318 assert( iObj == NameId );
1320 Vec_IntPush( &pNtk->
vValues, NameId );
1321 Vec_IntPush( &pNtk->
vValues, nBits );
1322 Vec_IntPush( &pNtk->
vValues, Range );
1414 assert( Vec_IntSize(vFans) == 5 );
1417 Fan = Vec_IntEntry(vFans, 1);
1418 assert( Smt_EntryIsName(Fan) );
1419 pName = Smt_EntryName(
p, Fan);
1428 Fan = Vec_IntEntry(vFans, 3);
1429 if ( Smt_EntryIsName(Fan) )
1439 assert( !Smt_EntryIsName(Fan) );
1440 vFans2 = Smt_VecEntryNode(
p, vFans, 3);
1441 assert( Vec_IntSize(vFans2) == 3 );
1443 assert( !
strcmp(
"BitVec", Smt_VecEntryName(
p, vFans2, 1)) );
1445 Fan = Vec_IntEntry(vFans2, 2);
1446 assert( Smt_EntryIsName(Fan) );
1447 pRange = Smt_EntryName(
p, Fan);
1448 Range = atoi(pRange);
1463 assert( Vec_IntSize(vFans) == 2 );
1472 Vec_IntPush( vAsserts, iObj );
1476 printf(
"Ignoring directive \"%s\".\n", Smt_EntryName(
p, Fan) );
1479 if ( Vec_IntSize(vAsserts) == 1 )
1480 iObj = Smt_PrsCreateNode( pNtk,
WLC_OBJ_BUF, 0, 1, vAsserts,
"miter" );
1482 else if ( Vec_IntSize(vAsserts) == 0 )
1483 iObj = Smt_PrsBuildConstant( pNtk,
"#b1", 1,
"miter" );
1486 iObj = Smt_PrsCreateNode( pNtk,
WLC_OBJ_BIT_CONCAT, 0, Vec_IntSize(vAsserts), vAsserts, NULL );
1487 Vec_IntFill( vAsserts, 1, iObj );
1492 vFans = Vec_IntStartNatural( Wlc_NtkObjNumMax(pNtk) );
1493 Vec_IntAppend( &pNtk->
vNameIds, vFans );
1494 Vec_IntFree( vFans );
1498 Vec_IntFree(vAsserts);
1516static inline int Smt_PrsErrorSet(
Smt_Prs_t *
p,
char * pError,
int Value )
1519 sprintf(
p->ErrorStr,
"%s", pError );
1523static inline int Smt_PrsErrorPrint(
Smt_Prs_t *
p )
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 );
1532static inline char * Smt_PrsLoadFile(
char * pFileName,
char ** ppLimit )
1535 int nFileSize, RetValue;
1536 FILE * pFile = fopen( pFileName,
"rb" );
1537 if ( pFile == NULL )
1539 printf(
"Cannot open input file.\n" );
1544 nFileSize = ftell( pFile );
1548 pBuffer =
ABC_ALLOC(
char, nFileSize + 16 );
1550 RetValue = fread( pBuffer+1, nFileSize, 1, pFile );
1553 pBuffer[nFileSize + 1] =
'\n';
1554 pBuffer[nFileSize + 2] =
'\0';
1555 *ppLimit = pBuffer + nFileSize + 2;
1558static inline int Smt_PrsRemoveComments(
char * pBuffer,
char * pLimit )
1560 char * pTemp;
int nCount1 = 0, nCount2 = 0, fHaveBar = 0;
1562 for ( pTemp = pBuffer; pTemp < pLimit; pTemp++ )
1564 if ( *pTemp ==
'(' )
1565 {
if ( !fHaveBar ) nCount1++; }
1566 else if ( *pTemp ==
')' )
1567 {
if ( !fHaveBar ) nCount2++; }
1568 else if ( *pTemp ==
'|' )
1570 else if ( *pTemp ==
';' && !fHaveBar )
1571 while ( *pTemp && *pTemp !=
'\n' )
1574 else if ( *pTemp ==
'\"' && *(pTemp-1) !=
'\\' && !fHaveBar )
1577 while ( *pTemp && (*pTemp !=
'\"' || backslash))
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;
1596static inline Smt_Prs_t * Smt_PrsAlloc(
char * pFileName,
char * pBuffer,
char * pLimit,
int nObjs )
1602 p->pName = pFileName;
1603 p->pBuffer = pBuffer;
1607 Smt_AddTypes(
p->pStrs );
1608 Vec_IntGrow( &
p->vStack, 100 );
1610 Vec_WecGrow( &
p->vObjs, nObjs+1 );
1613static inline void Smt_PrsFree(
Smt_Prs_t *
p )
1617 Vec_IntErase( &
p->vStack );
1618 Vec_IntErase( &
p->vTempFans );
1620 Vec_WecErase( &
p->vObjs );
1635static inline int Smt_PrsIsSpace(
char c )
1637 return c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n';
1639static inline void Smt_PrsSkipSpaces(
Smt_Prs_t *
p )
1641 while ( Smt_PrsIsSpace(*
p->pCur) )
1644static inline void Smt_PrsSkipNonSpaces(
Smt_Prs_t *
p )
1646 while (
p->pCur <
p->pLimit && !Smt_PrsIsSpace(*
p->pCur) && *
p->pCur !=
'(' && *
p->pCur !=
')' )
1652 assert( Vec_IntSize(&
p->vStack) == 0 );
1654 assert( Vec_WecSize(&
p->vObjs) == 0 );
1659 Vec_IntPush( &
p->vStack, Vec_WecSize(&
p->vObjs) );
1660 Vec_WecPushLevel( &
p->vObjs );
1662 for (
p->pCur =
p->pBuffer;
p->pCur <
p->pLimit;
p->pCur++ )
1664 Smt_PrsSkipSpaces(
p );
1665 if ( fFirstTime && *
p->pCur ==
'|' )
1669 while ( *
p->pCur && *
p->pCur !=
'|' )
1671 if ( *
p->pCur ==
'|' )
1675 if ( *
p->pCur ==
'(' )
1683 Vec_IntPush( Vec_WecEntry(&
p->vObjs, Vec_IntEntryLast(&
p->vStack)), Abc_Var2Lit(Vec_WecSize(&
p->vObjs), 0) );
1685 Vec_IntPush( &
p->vStack, Vec_WecSize(&
p->vObjs) );
1686 Vec_WecPushLevel( &
p->vObjs );
1688 else if ( *
p->pCur ==
')' )
1690 Vec_IntPop( &
p->vStack );
1694 char * pStart =
p->pCur;
1695 Smt_PrsSkipNonSpaces(
p );
1696 if (
p->pCur <
p->pLimit )
1709 Vec_IntPush( Vec_WecEntry(&
p->vObjs, Vec_IntEntryLast(&
p->vStack)), Abc_Var2Lit(iToken, 1) );
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) );
1720 printf(
"%*s(\n", Depth,
"" );
1721 vFans = Vec_WecEntry( &
p->vObjs, iObj );
1724 if ( Abc_LitIsCompl(Fan) )
1726 printf(
"%*s", Depth+2,
"" );
1727 printf(
"%s\n",
Abc_NamStr(
p->pStrs, Abc_Lit2Var(Fan)) );
1732 printf(
"%*s)\n", Depth,
"" );
1754 int nCount = Smt_PrsRemoveComments( pBuffer, pLimit );
1755 Smt_Prs_t *
p = Smt_PrsAlloc( pFileName, pBuffer, pLimit, nCount );
1761 if ( Smt_PrsErrorPrint(
p) )
1769 char * pBuffer, * pLimit;
1770 pBuffer = Smt_PrsLoadFile( pFileName, &pLimit );
1771 if ( pBuffer == NULL )
#define ABC_SWAP(Type, a, b)
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
unsigned __int64 word
DECLARATIONS ///.
int Abc_NamStrFind(Abc_Nam_t *p, char *pStr)
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)
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
void Abc_NamDeref(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 ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
int Smt_PrsBuildNode(Wlc_Ntk_t *pNtk, Smt_Prs_t *p, int iNode, int RangeOut, char *pName)
char * Smt_PrsGenName(Smt_Prs_t *p)
Wlc_Ntk_t * Smt_PrsBuild(Smt_Prs_t *p)
struct Smt_Pair_t_ Smt_Pair_t
void Smt_PrsReadLines(Smt_Prs_t *p)
Wlc_Ntk_t * Smt_PrsBuild2(Smt_Prs_t *p)
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 ///.
#define Smt_ManForEachDir(p, Type, vVec, i)
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)
void Wlc_ObjSetCo(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, int fFlopInput)
Wlc_Ntk_t * Wlc_NtkAlloc(char *pName, int nObjsAlloc)
void Wlc_NtkFree(Wlc_Ntk_t *p)
struct Wlc_Ntk_t_ Wlc_Ntk_t
void Wlc_ObjAddFanins(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, Vec_Int_t *vFanins)
char * Wlc_ObjName(Wlc_Ntk_t *p, int iObj)