Commit 0f29f0ae by Alan Mishchenko

Improving SMT-LIB parser.

parent 34c5ac88
...@@ -61,40 +61,41 @@ typedef enum { ...@@ -61,40 +61,41 @@ typedef enum {
WLC_OBJ_BIT_AND, // 16: bitwise AND WLC_OBJ_BIT_AND, // 16: bitwise AND
WLC_OBJ_BIT_OR, // 17: bitwise OR WLC_OBJ_BIT_OR, // 17: bitwise OR
WLC_OBJ_BIT_XOR, // 18: bitwise XOR WLC_OBJ_BIT_XOR, // 18: bitwise XOR
WLC_OBJ_BIT_NAND, // 16: bitwise AND WLC_OBJ_BIT_NAND, // 19: bitwise AND
WLC_OBJ_BIT_NOR, // 17: bitwise OR WLC_OBJ_BIT_NOR, // 20: bitwise OR
WLC_OBJ_BIT_NXOR, // 19: bitwise NXOR WLC_OBJ_BIT_NXOR, // 21: bitwise NXOR
WLC_OBJ_BIT_SELECT, // 20: bit selection WLC_OBJ_BIT_SELECT, // 22: bit selection
WLC_OBJ_BIT_CONCAT, // 21: bit concatenation WLC_OBJ_BIT_CONCAT, // 23: bit concatenation
WLC_OBJ_BIT_ZEROPAD, // 22: zero padding WLC_OBJ_BIT_ZEROPAD, // 24: zero padding
WLC_OBJ_BIT_SIGNEXT, // 23: sign extension WLC_OBJ_BIT_SIGNEXT, // 25: sign extension
WLC_OBJ_LOGIC_NOT, // 24: logic NOT WLC_OBJ_LOGIC_NOT, // 26: logic NOT
WLC_OBJ_LOGIC_AND, // 25: logic AND WLC_OBJ_LOGIC_IMPL, // 27: logic implication
WLC_OBJ_LOGIC_OR, // 27: logic OR WLC_OBJ_LOGIC_AND, // 28: logic AND
WLC_OBJ_LOGIC_XOR, // 28: logic XOR WLC_OBJ_LOGIC_OR, // 29: logic OR
WLC_OBJ_COMP_EQU, // 29: compare equal WLC_OBJ_LOGIC_XOR, // 30: logic XOR
WLC_OBJ_COMP_NOTEQU, // 30: compare not equal WLC_OBJ_COMP_EQU, // 31: compare equal
WLC_OBJ_COMP_LESS, // 31: compare less WLC_OBJ_COMP_NOTEQU, // 32: compare not equal
WLC_OBJ_COMP_MORE, // 32: compare more WLC_OBJ_COMP_LESS, // 33: compare less
WLC_OBJ_COMP_LESSEQU, // 33: compare less or equal WLC_OBJ_COMP_MORE, // 34: compare more
WLC_OBJ_COMP_MOREEQU, // 34: compare more or equal WLC_OBJ_COMP_LESSEQU, // 35: compare less or equal
WLC_OBJ_REDUCT_AND, // 35: reduction AND WLC_OBJ_COMP_MOREEQU, // 36: compare more or equal
WLC_OBJ_REDUCT_OR, // 36: reduction OR WLC_OBJ_REDUCT_AND, // 37: reduction AND
WLC_OBJ_REDUCT_XOR, // 37: reduction XOR WLC_OBJ_REDUCT_OR, // 38: reduction OR
WLC_OBJ_REDUCT_NAND, // 38: reduction NAND WLC_OBJ_REDUCT_XOR, // 39: reduction XOR
WLC_OBJ_REDUCT_NOR, // 39: reduction NOR WLC_OBJ_REDUCT_NAND, // 40: reduction NAND
WLC_OBJ_REDUCT_NXOR, // 40: reduction NXOR WLC_OBJ_REDUCT_NOR, // 41: reduction NOR
WLC_OBJ_ARI_ADD, // 41: arithmetic addition WLC_OBJ_REDUCT_NXOR, // 42: reduction NXOR
WLC_OBJ_ARI_SUB, // 42: arithmetic subtraction WLC_OBJ_ARI_ADD, // 43: arithmetic addition
WLC_OBJ_ARI_MULTI, // 43: arithmetic multiplier WLC_OBJ_ARI_SUB, // 44: arithmetic subtraction
WLC_OBJ_ARI_DIVIDE, // 44: arithmetic division WLC_OBJ_ARI_MULTI, // 45: arithmetic multiplier
WLC_OBJ_ARI_MODULUS, // 45: arithmetic modulus WLC_OBJ_ARI_DIVIDE, // 46: arithmetic division
WLC_OBJ_ARI_POWER, // 46: arithmetic power WLC_OBJ_ARI_MODULUS, // 47: arithmetic modulus
WLC_OBJ_ARI_MINUS, // 47: arithmetic minus WLC_OBJ_ARI_POWER, // 48: arithmetic power
WLC_OBJ_ARI_SQRT, // 48: integer square root WLC_OBJ_ARI_MINUS, // 49: arithmetic minus
WLC_OBJ_ARI_SQUARE, // 49: integer square WLC_OBJ_ARI_SQRT, // 50: integer square root
WLC_OBJ_TABLE, // 50: bit table WLC_OBJ_ARI_SQUARE, // 51: integer square
WLC_OBJ_NUMBER // 51: unused WLC_OBJ_TABLE, // 52: bit table
WLC_OBJ_NUMBER // 53: unused
} Wlc_ObjType_t; } Wlc_ObjType_t;
// when adding new types, remember to update table Wlc_Names in "wlcNtk.c" // when adding new types, remember to update table Wlc_Names in "wlcNtk.c"
...@@ -273,8 +274,8 @@ extern Wlc_Ntk_t * Wlc_NtkDupDfs( Wlc_Ntk_t * p ); ...@@ -273,8 +274,8 @@ extern Wlc_Ntk_t * Wlc_NtkDupDfs( Wlc_Ntk_t * p );
extern void Wlc_NtkTransferNames( Wlc_Ntk_t * pNew, Wlc_Ntk_t * p ); extern void Wlc_NtkTransferNames( Wlc_Ntk_t * pNew, Wlc_Ntk_t * p );
extern Wlc_Ntk_t * Wlc_NtkDupSingleNodes( Wlc_Ntk_t * p ); extern Wlc_Ntk_t * Wlc_NtkDupSingleNodes( Wlc_Ntk_t * p );
/*=== wlcReadSmt.c ========================================================*/ /*=== wlcReadSmt.c ========================================================*/
extern Wlc_Ntk_t * Wlc_ReadSmtBuffer( char * pFileName, char * pBuffer, char * pLimit ); extern Wlc_Ntk_t * Wlc_ReadSmtBuffer( char * pFileName, char * pBuffer, char * pLimit, int fOldParser, int fPrintTree );
extern Wlc_Ntk_t * Wlc_ReadSmt( char * pFileName ); extern Wlc_Ntk_t * Wlc_ReadSmt( char * pFileName, int fOldParser, int fPrintTree );
/*=== wlcSim.c ========================================================*/ /*=== wlcSim.c ========================================================*/
extern Vec_Ptr_t * Wlc_NtkSimulate( Wlc_Ntk_t * p, Vec_Int_t * vNodes, int nWords, int nFrames ); extern Vec_Ptr_t * Wlc_NtkSimulate( Wlc_Ntk_t * p, Vec_Int_t * vNodes, int nWords, int nFrames );
extern void Wlc_NtkDeleteSim( Vec_Ptr_t * p ); extern void Wlc_NtkDeleteSim( Vec_Ptr_t * p );
......
...@@ -777,7 +777,9 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Vec_Int_t * vBoxIds, int fGiaSimple ...@@ -777,7 +777,9 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Vec_Int_t * vBoxIds, int fGiaSimple
// blast in the topological order // blast in the topological order
Wlc_NtkForEachObj( p, pObj, i ) Wlc_NtkForEachObj( p, pObj, i )
{ {
// char * pName = Wlc_ObjName(p, i); // char * pName1 = Wlc_ObjName(p, i);
// char * pName2 = Wlc_ObjFaninNum(pObj) ? Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) : NULL;
nAndPrev = Gia_ManAndNum(pNew); nAndPrev = Gia_ManAndNum(pNew);
nRange = Wlc_ObjRange( pObj ); nRange = Wlc_ObjRange( pObj );
nRange0 = Wlc_ObjFaninNum(pObj) > 0 ? Wlc_ObjRange( Wlc_ObjFanin0(p, pObj) ) : -1; nRange0 = Wlc_ObjFaninNum(pObj) > 0 ? Wlc_ObjRange( Wlc_ObjFanin0(p, pObj) ) : -1;
...@@ -1007,7 +1009,7 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Vec_Int_t * vBoxIds, int fGiaSimple ...@@ -1007,7 +1009,7 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Vec_Int_t * vBoxIds, int fGiaSimple
else if ( pObj->Type == WLC_OBJ_BIT_ZEROPAD || pObj->Type == WLC_OBJ_BIT_SIGNEXT ) else if ( pObj->Type == WLC_OBJ_BIT_ZEROPAD || pObj->Type == WLC_OBJ_BIT_SIGNEXT )
{ {
int Pad = pObj->Type == WLC_OBJ_BIT_ZEROPAD ? 0 : pFans0[nRange0-1]; int Pad = pObj->Type == WLC_OBJ_BIT_ZEROPAD ? 0 : pFans0[nRange0-1];
assert( nRange0 < nRange ); assert( nRange0 <= nRange );
for ( k = 0; k < nRange0; k++ ) for ( k = 0; k < nRange0; k++ )
Vec_IntPush( vRes, pFans0[k] ); Vec_IntPush( vRes, pFans0[k] );
for ( ; k < nRange; k++ ) for ( ; k < nRange; k++ )
...@@ -1020,6 +1022,14 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Vec_Int_t * vBoxIds, int fGiaSimple ...@@ -1020,6 +1022,14 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Vec_Int_t * vBoxIds, int fGiaSimple
for ( k = 1; k < nRange; k++ ) for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 ); Vec_IntPush( vRes, 0 );
} }
else if ( pObj->Type == WLC_OBJ_LOGIC_IMPL )
{
int iLit0 = Wlc_BlastReduction( pNew, pFans0, nRange0, WLC_OBJ_REDUCT_OR );
int iLit1 = Wlc_BlastReduction( pNew, pFans1, nRange1, WLC_OBJ_REDUCT_OR );
Vec_IntFill( vRes, 1, Gia_ManHashOr(pNew, Abc_LitNot(iLit0), iLit1) );
for ( k = 1; k < nRange; k++ )
Vec_IntPush( vRes, 0 );
}
else if ( pObj->Type == WLC_OBJ_LOGIC_AND ) else if ( pObj->Type == WLC_OBJ_LOGIC_AND )
{ {
int iLit0 = Wlc_BlastReduction( pNew, pFans0, nRange0, WLC_OBJ_REDUCT_OR ); int iLit0 = Wlc_BlastReduction( pNew, pFans0, nRange0, WLC_OBJ_REDUCT_OR );
......
...@@ -119,12 +119,20 @@ int Abc_CommandReadWlc( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -119,12 +119,20 @@ int Abc_CommandReadWlc( Abc_Frame_t * pAbc, int argc, char ** argv )
FILE * pFile; FILE * pFile;
Wlc_Ntk_t * pNtk = NULL; Wlc_Ntk_t * pNtk = NULL;
char * pFileName = NULL; char * pFileName = NULL;
int fOldParser = 0;
int fPrintTree = 0;
int c, fVerbose = 0; int c, fVerbose = 0;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "opvh" ) ) != EOF )
{ {
switch ( c ) switch ( c )
{ {
case 'o':
fPrintTree ^= 1;
break;
case 'p':
fOldParser ^= 1;
break;
case 'v': case 'v':
fVerbose ^= 1; fVerbose ^= 1;
break; break;
...@@ -155,7 +163,7 @@ int Abc_CommandReadWlc( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -155,7 +163,7 @@ int Abc_CommandReadWlc( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) )
pNtk = Wlc_ReadVer( pFileName ); pNtk = Wlc_ReadVer( pFileName );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "smt" ) || !strcmp( Extra_FileNameExtension(pFileName), "smt2" ) ) else if ( !strcmp( Extra_FileNameExtension(pFileName), "smt" ) || !strcmp( Extra_FileNameExtension(pFileName), "smt2" ) )
pNtk = Wlc_ReadSmt( pFileName ); pNtk = Wlc_ReadSmt( pFileName, fOldParser, fPrintTree );
else else
{ {
printf( "Abc_CommandReadWlc(): Unknown file extension.\n" ); printf( "Abc_CommandReadWlc(): Unknown file extension.\n" );
...@@ -164,8 +172,10 @@ int Abc_CommandReadWlc( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -164,8 +172,10 @@ int Abc_CommandReadWlc( Abc_Frame_t * pAbc, int argc, char ** argv )
Wlc_AbcUpdateNtk( pAbc, pNtk ); Wlc_AbcUpdateNtk( pAbc, pNtk );
return 0; return 0;
usage: usage:
Abc_Print( -2, "usage: %%read [-vh] <file_name>\n" ); Abc_Print( -2, "usage: %%read [-opvh] <file_name>\n" );
Abc_Print( -2, "\t reads word-level design from Verilog file\n" ); Abc_Print( -2, "\t reads word-level design from Verilog file\n" );
Abc_Print( -2, "\t-o : toggle using old SMT-LIB parser [default = %s]\n", fOldParser? "yes": "no" );
Abc_Print( -2, "\t-p : toggle printing parse SMT-LIB tree [default = %s]\n", fPrintTree? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n"); Abc_Print( -2, "\t-h : print the command usage\n");
return 1; return 1;
......
...@@ -50,40 +50,41 @@ static char * Wlc_Names[WLC_OBJ_NUMBER+1] = { ...@@ -50,40 +50,41 @@ static char * Wlc_Names[WLC_OBJ_NUMBER+1] = {
"&", // 16: bitwise AND "&", // 16: bitwise AND
"|", // 17: bitwise OR "|", // 17: bitwise OR
"^", // 18: bitwise XOR "^", // 18: bitwise XOR
"~&", // 16: bitwise NAND "~&", // 19: bitwise NAND
"~|", // 17: bitwise NOR "~|", // 20: bitwise NOR
"~^", // 19: bitwise NXOR "~^", // 21: bitwise NXOR
"[:]", // 20: bit selection "[:]", // 22: bit selection
"{,}", // 21: bit concatenation "{,}", // 23: bit concatenation
"zeroPad", // 22: zero padding "zeroPad", // 24: zero padding
"signExt", // 23: sign extension "signExt", // 25: sign extension
"!", // 24: logic NOT "!", // 26: logic NOT
"&&", // 25: logic AND "=>", // 27: logic implication
"||", // 27: logic OR "&&", // 28: logic AND
"^^", // 28: logic XOR "||", // 29: logic OR
"==", // 29: compare equal "^^", // 30: logic XOR
"!=", // 30: compare not equal "==", // 31: compare equal
"<", // 31: compare less "!=", // 32: compare not equal
">", // 32: compare more "<", // 33: compare less
"<=", // 33: compare less or equal ">", // 34: compare more
">=", // 34: compare more or equal "<=", // 35: compare less or equal
"&", // 35: reduction AND ">=", // 36: compare more or equal
"|", // 36: reduction OR "&", // 37: reduction AND
"^", // 37: reduction XOR "|", // 38: reduction OR
"~&", // 38: reduction NAND "^", // 39: reduction XOR
"~|", // 39: reduction NOR "~&", // 40: reduction NAND
"~^", // 40: reduction NXOR "~|", // 41: reduction NOR
"+", // 41: arithmetic addition "~^", // 42: reduction NXOR
"-", // 42: arithmetic subtraction "+", // 43: arithmetic addition
"*", // 43: arithmetic multiplier "-", // 44: arithmetic subtraction
"/", // 44: arithmetic division "*", // 45: arithmetic multiplier
"%", // 45: arithmetic modulus "/", // 46: arithmetic division
"**", // 46: arithmetic power "%", // 47: arithmetic modulus
"-", // 47: arithmetic minus "**", // 48: arithmetic power
"sqrt", // 48: integer square root "-", // 49: arithmetic minus
"square", // 49: integer square "sqrt", // 50: integer square root
"table", // 50: bit table "square", // 51: integer square
NULL // 51: unused "table", // 52: bit table
NULL // 53: unused
}; };
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
...@@ -380,6 +381,8 @@ void Wlc_NtkPrintDistrib( Wlc_Ntk_t * p, int fVerbose ) ...@@ -380,6 +381,8 @@ void Wlc_NtkPrintDistrib( Wlc_Ntk_t * p, int fVerbose )
Vec_IntAddToEntry( vAnds, WLC_OBJ_BIT_SIGNEXT, 0 ); Vec_IntAddToEntry( vAnds, WLC_OBJ_BIT_SIGNEXT, 0 );
else if ( pObj->Type == WLC_OBJ_LOGIC_NOT ) else if ( pObj->Type == WLC_OBJ_LOGIC_NOT )
Vec_IntAddToEntry( vAnds, WLC_OBJ_LOGIC_NOT, Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)) - 1 ); Vec_IntAddToEntry( vAnds, WLC_OBJ_LOGIC_NOT, Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)) - 1 );
else if ( pObj->Type == WLC_OBJ_LOGIC_IMPL )
Vec_IntAddToEntry( vAnds, WLC_OBJ_LOGIC_IMPL, Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)) + Wlc_ObjRange(Wlc_ObjFanin1(p, pObj)) - 1 );
else if ( pObj->Type == WLC_OBJ_LOGIC_AND ) else if ( pObj->Type == WLC_OBJ_LOGIC_AND )
Vec_IntAddToEntry( vAnds, WLC_OBJ_LOGIC_AND, Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)) + Wlc_ObjRange(Wlc_ObjFanin1(p, pObj)) - 1 ); Vec_IntAddToEntry( vAnds, WLC_OBJ_LOGIC_AND, Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)) + Wlc_ObjRange(Wlc_ObjFanin1(p, pObj)) - 1 );
else if ( pObj->Type == WLC_OBJ_LOGIC_OR ) else if ( pObj->Type == WLC_OBJ_LOGIC_OR )
......
...@@ -781,6 +781,7 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t * ...@@ -781,6 +781,7 @@ static inline int Wlc_PrsFindDefinition( Wlc_Prs_t * p, char * pStr, Vec_Int_t *
else if ( pStr[0] == '~' && pStr[1] == '&' ) pStr += 2, Type = WLC_OBJ_BIT_NAND; else if ( pStr[0] == '~' && pStr[1] == '&' ) pStr += 2, Type = WLC_OBJ_BIT_NAND;
else if ( pStr[0] == '~' && pStr[1] == '|' ) pStr += 2, Type = WLC_OBJ_BIT_NOR; else if ( pStr[0] == '~' && pStr[1] == '|' ) pStr += 2, Type = WLC_OBJ_BIT_NOR;
else if ( pStr[0] == '~' && pStr[1] == '^' ) pStr += 2, Type = WLC_OBJ_BIT_NXOR; else if ( pStr[0] == '~' && pStr[1] == '^' ) pStr += 2, Type = WLC_OBJ_BIT_NXOR;
else if ( pStr[0] == '=' && pStr[1] == '>' ) pStr += 2, Type = WLC_OBJ_LOGIC_IMPL;
else if ( pStr[0] == '&' && pStr[1] == '&' ) pStr += 2, Type = WLC_OBJ_LOGIC_AND; else if ( pStr[0] == '&' && pStr[1] == '&' ) pStr += 2, Type = WLC_OBJ_LOGIC_AND;
else if ( pStr[0] == '|' && pStr[1] == '|' ) pStr += 2, Type = WLC_OBJ_LOGIC_OR; else if ( pStr[0] == '|' && pStr[1] == '|' ) pStr += 2, Type = WLC_OBJ_LOGIC_OR;
else if ( pStr[0] == '^' && pStr[1] == '^' ) pStr += 2, Type = WLC_OBJ_LOGIC_XOR; else if ( pStr[0] == '^' && pStr[1] == '^' ) pStr += 2, Type = WLC_OBJ_LOGIC_XOR;
......
...@@ -192,7 +192,7 @@ int Wlc_StdinProcessSmt( Abc_Frame_t * pAbc, char * pCmd ) ...@@ -192,7 +192,7 @@ int Wlc_StdinProcessSmt( Abc_Frame_t * pAbc, char * pCmd )
// collect stdin until (check-sat) // collect stdin until (check-sat)
Vec_Str_t * vInput = Wlc_StdinCollectProblem( "(check-sat)" ); Vec_Str_t * vInput = Wlc_StdinCollectProblem( "(check-sat)" );
// parse input // parse input
Wlc_Ntk_t * pNtk = Wlc_ReadSmtBuffer( NULL, Vec_StrArray(vInput), Vec_StrArray(vInput) + Vec_StrSize(vInput) ); Wlc_Ntk_t * pNtk = Wlc_ReadSmtBuffer( NULL, Vec_StrArray(vInput), Vec_StrArray(vInput) + Vec_StrSize(vInput), 0, 0 );
Vec_StrFree( vInput ); Vec_StrFree( vInput );
// install current network // install current network
Wlc_SetNtk( pAbc, pNtk ); Wlc_SetNtk( pAbc, pNtk );
......
...@@ -314,6 +314,8 @@ void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p, int fNoFlops ) ...@@ -314,6 +314,8 @@ void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p, int fNoFlops )
fprintf( pFile, "~|" ); fprintf( pFile, "~|" );
else if ( pObj->Type == WLC_OBJ_BIT_NXOR ) else if ( pObj->Type == WLC_OBJ_BIT_NXOR )
fprintf( pFile, "~^" ); fprintf( pFile, "~^" );
else if ( pObj->Type == WLC_OBJ_LOGIC_IMPL )
fprintf( pFile, "=>" );
else if ( pObj->Type == WLC_OBJ_LOGIC_AND ) else if ( pObj->Type == WLC_OBJ_LOGIC_AND )
fprintf( pFile, "&&" ); fprintf( pFile, "&&" );
else if ( pObj->Type == WLC_OBJ_LOGIC_OR ) else if ( pObj->Type == WLC_OBJ_LOGIC_OR )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment