}
//All for loops are true in the model
- return CallSAT_ResultCheck(SatSolver, ASTTrue, original_input);
+ //return CallSAT_ResultCheck(SatSolver, ASTTrue, original_input);
+ return ret;
} //end of SATBased_AllFiniteLoops_Refinement()
int paramInit = GetUnsignedConst(finiteloop[1]);
int paramLimit = GetUnsignedConst(finiteloop[2]);
int paramIncrement = GetUnsignedConst(finiteloop[3]);
- ASTNode formulabody = finiteloop[4];
+ ASTNode exceptFormula = finiteloop[4];
+ ASTNode formulabody = finiteloop[5];
int paramCurrentValue = paramInit;
//Update ParamToCurrentValMap with parameter and its current
(*ParamToCurrentValMap)[parameter] =
CreateBVConst(finiteloop[1].GetValueWidth(),paramCurrentValue);
- SOLVER_RETURN_TYPE ret;
+ SOLVER_RETURN_TYPE ret = SOLVER_UNDECIDED;
//Go recursively thru' all the FOR-constructs.
if(FOR == formulabody.GetKind())
{
}
- //Update ParamToCurrentValMap with parameter and its current
- //value
- //
- //FIXME: Possible leak since I am not freeing the previous
- //'value' for the same 'key'
+ //Update ParamToCurrentValMap with parameter and its
+ //current value. FIXME: Possible leak since I am not
+ //freeing the previous 'value' for the same 'key'
paramCurrentValue = paramCurrentValue + paramIncrement;
(*ParamToCurrentValMap)[parameter] =
CreateBVConst(finiteloop[1].GetValueWidth(),paramCurrentValue);
return ret;
} //end of recursion FORs
- //ASTVec forloopFormulaVector;
//Expand the leaf level FOR-construct completely
+ //increment of paramCurrentValue done inside loop
int ThisForLoopAllTrue = 0;
- for(;paramCurrentValue < paramLimit;
- //increment of paramCurrentValue done inside loop
- )
+ for(;paramCurrentValue < paramLimit;)
{
ASTNode currentFormula;
- currentFormula =
- SimplifyFormula(formulabody, false, ParamToCurrentValMap);
-
+ ASTNode currentExceptFormula =
+ SimplifyFormula(exceptFormula, false, ParamToCurrentValMap);
+ if(ASTTrue == currentExceptFormula)
+ {
+ currentFormula = ASTTrue;
+ }
+ else
+ {
+ currentFormula =
+ SimplifyFormula(formulabody, false, ParamToCurrentValMap);
+ }
+
//Check the currentformula against the model, and add it to the
//SAT solver if it is false against the model
if(ASTFalse == ComputeFormulaUsingModel(currentFormula))
{
- // forloopFormulaVector.push_back(currentFormula); ASTNode
- // forloopFormulas =
- // (forloopFormulaVector.size() != 1) ?
- // CreateNode(AND, forloopFormulaVector) :
- // forloopFormulaVector[0];
-
currentFormula = TransformFormula_TopLevel(currentFormula);
SOLVER_RETURN_TYPE result =
CallSAT_ResultCheck(SatSolver, currentFormula, original_input);
int paramInit = GetUnsignedConst(finiteloop[1]);
int paramLimit = GetUnsignedConst(finiteloop[2]);
int paramIncrement = GetUnsignedConst(finiteloop[3]);
- ASTNode formulabody = finiteloop[4];
+ ASTNode exceptFormula = finiteloop[4];
+ ASTNode formulabody = finiteloop[5];
int paramCurrentValue = paramInit;
//Update ParamToCurrentValMap with parameter and its current
returnVec.push_back(ret);
}
- //Update ParamToCurrentValMap with parameter and its current
- //value
- //
- //FIXME: Possible leak since I am not freeing the previous
- //'value' for the same 'key'
+ //Update ParamToCurrentValMap with parameter and its
+ //current value. FIXME: Possible leak since I am not
+ //freeing the previous 'value' for the same 'key'
paramCurrentValue = paramCurrentValue + paramIncrement;
(*ParamToCurrentValMap)[parameter] =
CreateBVConst(finiteloop[1].GetValueWidth(),paramCurrentValue);
ASTVec forloopFormulaVector;
//Expand the leaf level FOR-construct completely
- for(;paramCurrentValue < paramLimit;
- //incrementing of paramCurrentValue is done inside loop
- )
+ //incrementing of paramCurrentValue is done inside loop
+ for(;paramCurrentValue < paramLimit;)
{
- ASTNode currentFormula;
- currentFormula =
- SimplifyFormula(formulabody, false, ParamToCurrentValMap);
-
+ ASTNode currentFormula;
+
+ ASTNode currentExceptFormula =
+ SimplifyFormula(exceptFormula, false, ParamToCurrentValMap);
+ if(ASTTrue == currentExceptFormula)
+ {
+ currentFormula = ASTTrue;
+ //continue;
+ }
+ else
+ {
+ currentFormula =
+ SimplifyFormula(formulabody, false, ParamToCurrentValMap);
+ }
+
if(checkusingmodel_flag)
{
- //Check the currentformula against the model, and add it to the
- //SAT solver if it is false against the model
- if(ASTFalse == ComputeFormulaUsingModel(currentFormula))
- return ASTFalse;
+ //Check the currentformula against the model, and return
+ //immediately
+ //cout << "Printing current Formula: " << currentFormula << "\n";
+ ASTNode computedForm = ComputeFormulaUsingModel(currentFormula);
+ //cout << "Printing computed Formula: " << computedForm << "\n";
+ if(ASTFalse == computedForm)
+ {
+ return ASTFalse;
+ }
}
else
{
{
output = t1;
}
- else if (CheckAlwaysTrueFormMap(CreateNode(NOT, t0)) || (NOT == t0.GetKind() && CheckAlwaysTrueFormMap(t0[0])))
+ else if (CheckAlwaysTrueFormMap(CreateNode(NOT, t0)) ||
+ (NOT == t0.GetKind() && CheckAlwaysTrueFormMap(t0[0])))
{
output = t2;
}
if (CheckSubstitutionMap(inputterm, output))
{
//cout << "SolverMap:" << inputterm << " output: " << output << endl;
- return SimplifyTerm(output);
+ return SimplifyTerm(output, VarConstMap);
}
if (CheckSimplifyMap(inputterm, output, false, VarConstMap))
}
if (CheckSolverMap(inputterm, output))
{
- return SimplifyTerm(output);
+ return SimplifyTerm(output, VarConstMap);
}
output = inputterm;
break;
//sort, and create BVPLUS/BVMULT and return
for (ASTVec::iterator it = c.begin(), itend = c.end(); it != itend; it++)
{
- ASTNode aaa = SimplifyTerm(*it);
+ ASTNode aaa = SimplifyTerm(*it, VarConstMap);
if (BVCONST == aaa.GetKind())
{
constkids.push_back(aaa);
case BVSUB:
{
ASTVec c = inputterm.GetChildren();
- ASTNode a0 = SimplifyTerm(inputterm[0]);
- ASTNode a1 = SimplifyTerm(inputterm[1]);
+ ASTNode a0 = SimplifyTerm(inputterm[0], VarConstMap);
+ ASTNode a1 = SimplifyTerm(inputterm[1], VarConstMap);
unsigned int l = inputValueWidth;
if (a0 == a1)
output = CreateZeroConst(l);
//covert x-y into x+(-y) and simplify. this transformation
//triggers more simplifications
//
- a1 = SimplifyTerm(CreateTerm(BVUMINUS, l, a1));
- output = SimplifyTerm(CreateTerm(BVPLUS, l, a0, a1));
+ a1 = SimplifyTerm(CreateTerm(BVUMINUS, l, a1), VarConstMap);
+ output = SimplifyTerm(CreateTerm(BVPLUS, l, a0, a1), VarConstMap);
}
break;
}
//actually 0. One way to reveal this fact is to strip bvuminus
//out, and replace with something else so that combineliketerms
//can catch this fact.
- ASTNode a0 = SimplifyTerm(inputterm[0]);
+ ASTNode a0 = SimplifyTerm(inputterm[0], VarConstMap);
Kind k1 = a0.GetKind();
unsigned int l = a0.GetValueWidth();
ASTNode one = CreateOneConst(l);
}
case BVNEG:
{
- output = SimplifyTerm(CreateTerm(BVPLUS, l, a0[0], one));
+ output = SimplifyTerm(CreateTerm(BVPLUS, l, a0[0], one), VarConstMap);
break;
}
case BVMULT:
// not -(3*x).
if (BVCONST == a0[0].GetKind())
{
- ASTNode a00 = SimplifyTerm(CreateTerm(BVUMINUS, l, a0[0]));
+ ASTNode a00 = SimplifyTerm(CreateTerm(BVUMINUS, l, a0[0]), VarConstMap);
output = CreateTerm(BVMULT, l, a00, a0[1]);
}
else
for (ASTVec::iterator it = c.begin(), itend = c.end(); it != itend; it++)
{
//Simplify(BVUMINUS(a1x1))
- ASTNode aaa = SimplifyTerm(CreateTerm(BVUMINUS, l, *it));
+ ASTNode aaa = SimplifyTerm(CreateTerm(BVUMINUS, l, *it), VarConstMap);
o.push_back(aaa);
}
//simplify the bvplus
- output = SimplifyTerm(CreateTerm(BVPLUS, l, o));
+ output = SimplifyTerm(CreateTerm(BVPLUS, l, o), VarConstMap);
break;
}
case BVSUB:
{
//BVUMINUS(BVSUB(x,y)) <=> BVSUB(y,x)
- output = SimplifyTerm(CreateTerm(BVSUB, l, a0[1], a0[0]));
+ output = SimplifyTerm(CreateTerm(BVSUB, l, a0[1], a0[0]), VarConstMap);
break;
}
case ITE:
{
//BVUMINUS(ITE(c,t1,t2)) <==> ITE(c,BVUMINUS(t1),BVUMINUS(t2))
ASTNode c = a0[0];
- ASTNode t1 = SimplifyTerm(CreateTerm(BVUMINUS, l, a0[1]));
- ASTNode t2 = SimplifyTerm(CreateTerm(BVUMINUS, l, a0[2]));
+ ASTNode t1 = SimplifyTerm(CreateTerm(BVUMINUS, l, a0[1]), VarConstMap);
+ ASTNode t2 = SimplifyTerm(CreateTerm(BVUMINUS, l, a0[2]), VarConstMap);
output = CreateSimplifiedTermITE(c, t1, t2);
break;
}
//it is important to take care of wordlevel transformation in
//BVEXTRACT. it exposes oppurtunities for later simplification
//and solving (variable elimination)
- ASTNode a0 = SimplifyTerm(inputterm[0]);
+ ASTNode a0 = SimplifyTerm(inputterm[0], VarConstMap);
Kind k1 = a0.GetKind();
unsigned int a_len = inputValueWidth;
//Apply the following rule:
// (t@u)[i:j] <==> u[i:j], if len(u) > i
//
- output = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, u, i, j));
+ output = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, u, i, j), VarConstMap);
}
else if (len_a0 > i_val && j_val >= len_u)
{
// (t@u)[i:j] <==> t[i-len_u:j-len_u], if len(t@u) > i >= j >= len(u)
i = CreateBVConst(32, i_val - len_u);
j = CreateBVConst(32, j_val - len_u);
- output = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, t, i, j));
+ output = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, t, i, j), VarConstMap);
}
else
{
// (t@u)[i:j] <==> t[i-len_u:0] @ u[len_u-1:j]
i = CreateBVConst(32, i_val - len_u);
ASTNode m = CreateBVConst(32, len_u - 1);
- t = SimplifyTerm(CreateTerm(BVEXTRACT, i_val - len_u + 1, t, i, zero));
- u = SimplifyTerm(CreateTerm(BVEXTRACT, len_u - j_val, u, m, j));
+ t = SimplifyTerm(CreateTerm(BVEXTRACT, i_val - len_u + 1, t, i, zero), VarConstMap);
+ u = SimplifyTerm(CreateTerm(BVEXTRACT, len_u - j_val, u, m, j), VarConstMap);
output = CreateTerm(BVCONCAT, a_len, t, u);
}
break;
for (ASTVec::iterator jt = c.begin(), jtend = c.end(); jt != jtend; jt++)
{
ASTNode aaa = *jt;
- aaa = SimplifyTerm(CreateTerm(BVEXTRACT, i_val + 1, aaa, i, zero));
+ aaa = SimplifyTerm(CreateTerm(BVEXTRACT, i_val + 1, aaa, i, zero), VarConstMap);
o.push_back(aaa);
}
output = CreateTerm(a0.GetKind(), i_val + 1, o);
// (t op u)[i:j] <==> t[i:j] op u[i:j]
ASTNode t = a0[0];
ASTNode u = a0[1];
- t = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, t, i, j));
- u = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, u, i, j));
+ t = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, t, i, j), VarConstMap);
+ u = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, u, i, j), VarConstMap);
BVTypeCheck(t);
BVTypeCheck(u);
output = CreateTerm(k1, a_len, t, u);
{
// (~t)[i:j] <==> ~(t[i:j])
ASTNode t = a0[0];
- t = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, t, i, j));
+ t = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, t, i, j), VarConstMap);
output = CreateTerm(BVNEG, a_len, t);
break;
}
case ITE:
{
ASTNode t0 = a0[0];
- ASTNode t1 = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, a0[1], i, j));
- ASTNode t2 = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, a0[2], i, j));
+ ASTNode t1 = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, a0[1], i, j), VarConstMap);
+ ASTNode t2 = SimplifyTerm(CreateTerm(BVEXTRACT, a_len, a0[2], i, j), VarConstMap);
output = CreateSimplifiedTermITE(t0, t1, t2);
break;
}
}
case BVNEG:
{
- ASTNode a0 = SimplifyTerm(inputterm[0]);
+ ASTNode a0 = SimplifyTerm(inputterm[0], VarConstMap);
unsigned len = inputValueWidth;
switch (a0.GetKind())
{
break;
// case ITE: {
// ASTNode cond = a0[0];
- // ASTNode thenpart = SimplifyTerm(CreateTerm(BVNEG,len,a0[1]));
- // ASTNode elsepart = SimplifyTerm(CreateTerm(BVNEG,len,a0[2]));
+ // ASTNode thenpart = SimplifyTerm(CreateTerm(BVNEG,len,a0[1]), VarConstMap);
+ // ASTNode elsepart = SimplifyTerm(CreateTerm(BVNEG,len,a0[2]), VarConstMap);
// output = CreateSimplifiedTermITE(cond,thenpart,elsepart);
// break;
// }
case BVZX:
{
- ASTNode a0 = SimplifyTerm(inputterm[0]);
+ ASTNode a0 = SimplifyTerm(inputterm[0], VarConstMap);
if (a0.GetKind() == BVCONST)
output = BVConstEvaluator(CreateTerm(BVZX, inputValueWidth, a0, inputterm[1]));
else
case BVSX:
{
//a0 is the expr which is being sign extended
- ASTNode a0 = SimplifyTerm(inputterm[0]);
+ ASTNode a0 = SimplifyTerm(inputterm[0], VarConstMap);
//a1 represents the length of the term BVSX(a0)
ASTNode a1 = inputterm[1];
//output length of the BVSX term
ASTVec o;
for (ASTVec::iterator it = c.begin(), itend = c.end(); it != itend; it++)
{
- ASTNode aaa = SimplifyTerm(CreateTerm(BVSX, len, *it, a1));
+ ASTNode aaa = SimplifyTerm(CreateTerm(BVSX, len, *it, a1), VarConstMap);
o.push_back(aaa);
}
output = CreateTerm(a0.GetKind(), len, o);
{
//if you have BVSX(m,BVSX(n,a)) then you can drop the inner
//BVSX provided m is greater than n.
- a0 = SimplifyTerm(a0[0]);
+ a0 = SimplifyTerm(a0[0], VarConstMap);
output = CreateTerm(BVSX, len, a0, a1);
break;
}
case ITE:
{
ASTNode cond = a0[0];
- ASTNode thenpart = SimplifyTerm(CreateTerm(BVSX, len, a0[1], a1));
- ASTNode elsepart = SimplifyTerm(CreateTerm(BVSX, len, a0[2], a1));
+ ASTNode thenpart = SimplifyTerm(CreateTerm(BVSX, len, a0[1], a1), VarConstMap);
+ ASTNode elsepart = SimplifyTerm(CreateTerm(BVSX, len, a0[2], a1), VarConstMap);
output = CreateSimplifiedTermITE(cond, thenpart, elsepart);
break;
}
bool constant = true;
for (ASTVec::iterator it = c.begin(), itend = c.end(); it != itend; it++)
{
- ASTNode aaa = SimplifyTerm(*it);
+ ASTNode aaa = SimplifyTerm(*it, VarConstMap);
if (BVCONST != aaa.GetKind())
{
constant = false;
}
case BVCONCAT:
{
- ASTNode t = SimplifyTerm(inputterm[0]);
- ASTNode u = SimplifyTerm(inputterm[1]);
+ ASTNode t = SimplifyTerm(inputterm[0], VarConstMap);
+ ASTNode u = SimplifyTerm(inputterm[1], VarConstMap);
Kind tkind = t.GetKind();
Kind ukind = u.GetKind();
bool constant = true;
for (ASTVec::iterator it = c.begin(), itend = c.end(); it != itend; it++)
{
- ASTNode aaa = SimplifyTerm(*it);
+ ASTNode aaa = SimplifyTerm(*it, VarConstMap);
if (BVCONST != aaa.GetKind())
{
constant = false;
else if (ITE == inputterm[0].GetKind())
{
ASTNode cond = SimplifyFormula(inputterm[0][0], false, VarConstMap);
- ASTNode index = SimplifyTerm(inputterm[1]);
+ ASTNode index = SimplifyTerm(inputterm[1], VarConstMap);
ASTNode read1 = CreateTerm(READ, inputValueWidth, inputterm[0][1], index);
ASTNode read2 = CreateTerm(READ, inputValueWidth, inputterm[0][2], index);
- read1 = SimplifyTerm(read1);
- read2 = SimplifyTerm(read2);
+ read1 = SimplifyTerm(read1, VarConstMap);
+ read2 = SimplifyTerm(read2, VarConstMap);
out1 = CreateSimplifiedTermITE(cond, read1, read2);
}
else
case ITE:
{
ASTNode t0 = SimplifyFormula(inputterm[0], false, VarConstMap);
- ASTNode t1 = SimplifyTerm(inputterm[1]);
- ASTNode t2 = SimplifyTerm(inputterm[2]);
+ ASTNode t1 = SimplifyTerm(inputterm[1], VarConstMap);
+ ASTNode t2 = SimplifyTerm(inputterm[2], VarConstMap);
output = CreateSimplifiedTermITE(t0, t1, t2);
break;
}
ASTVec o;
for (ASTVec::iterator it = c.begin(), itend = c.end(); it != itend; it++)
{
- ASTNode aaa = SimplifyTerm(*it);
+ ASTNode aaa = SimplifyTerm(*it, VarConstMap);
o.push_back(aaa);
}
output = CreateTerm(k, inputValueWidth, o);