// does mean that we can't short cut, for example, if the first argument to a BVOR is all trues,
// then all the other arguments have already been simplified, so won't be short-cutted.
-// I tried enabling it on the formulae, but it interferred with the bvsolver (sometime),
-// so that's disabled.
- const bool simplify_upfront = true;
-
// is it ITE(p,bv0[1], bv1[1]) OR ITE(p,bv0[0], bv1[0])
bool isPropositionToTerm(const ASTNode& n)
{
kind = a.GetKind();
- if (false && simplify_upfront)
+ if (false)
{
if (!a.isConstant() && kind != SYMBOL) // const and symbols need to be created specially.
{
unsigned int inputValueWidth = inputterm.GetValueWidth();
- if (simplify_upfront)
{
assert(k != BVCONST);
if (k != SYMBOL) // const and symbols need to be created specially.
{
ASTNode aaa = *it;
- if (!simplify_upfront)
- aaa = SimplifyTerm(aaa);
assert(hasBeenSimplified(aaa));
if (BVCONST == aaa.GetKind())
}
case BVSUB:
{
- ASTVec c = inputterm.GetChildren();
+ assert(inputterm.Degree() == 2);
ASTNode a0 =inputterm[0];
- if (!simplify_upfront)
- a0 = SimplifyTerm(a0);
assert(hasBeenSimplified(a0));
ASTNode a1 =inputterm[1];
- if (!simplify_upfront)
- a1 = SimplifyTerm(a1);
assert(hasBeenSimplified(a1));
unsigned int l = inputValueWidth;
//can catch this fact.
ASTNode a0 =inputterm[0];
- if (!simplify_upfront)
- a0 = SimplifyTerm(a0);
assert(hasBeenSimplified(a0));
Kind k1 = a0.GetKind();
unsigned int l = a0.GetValueWidth();
ASTNode one = _bm->CreateOneConst(l);
+ assert(k1 != BVCONST);
switch (k1)
{
case BVUMINUS:
output = a0[0];
break;
- case BVCONST:
- {
- output = BVConstEvaluator(nf->CreateTerm(BVUMINUS, l, a0));
- break;
- }
case BVNEG:
{
output =
//BVEXTRACT. it exposes oppurtunities for later simplification
//and solving (variable elimination)
ASTNode a0 =inputterm[0];
- if (!simplify_upfront)
- a0 = SimplifyTerm(a0);
assert(hasBeenSimplified(a0));
Kind k1 = a0.GetKind();
break;
}
+ assert(k1 != BVCONST);
+
switch (k1)
{
case BVEXTRACT:
}
break;
- case BVCONST:
- {
- //extract the constant
- output =
- BVConstEvaluator(nf->CreateTerm(BVEXTRACT,
- a_len, a0, i, j));
- break;
- }
+
case BVCONCAT:
{
//assumes concatenation is binary
case BVNEG:
{
ASTNode a0 =inputterm[0];
- if (!simplify_upfront)
- a0 = SimplifyTerm(a0);
assert(hasBeenSimplified(a0));
unsigned len = inputValueWidth;
+ assert (a0.GetKind() != BVCONST);
+
switch (a0.GetKind())
{
- case BVCONST:
- output = BVConstEvaluator(nf->CreateTerm(BVNEG, len, a0));
- break;
case BVNEG:
output = a0[0];
break;
{
//a0 is the expr which is being sign extended
ASTNode a0 =inputterm[0];
- if (!simplify_upfront)
- a0 = SimplifyTerm(a0);
assert(hasBeenSimplified(a0));
//a1 represents the length of the term BVSX(a0)
break;
}
+ assert (a0.GetKind() != BVCONST);
switch (a0.GetKind())
{
- case BVCONST:
- output = BVConstEvaluator(nf->CreateTerm(BVSX, len, a0, a1));
- break;
+
case BVNEG:
output =
nf->CreateTerm(a0.GetKind(), len,
//if you have BVSX(m,BVSX(n,a)) then you can drop the inner
//BVSX provided m is greater than n.
a0 =a0[0];
- if (!simplify_upfront)
- a0 = SimplifyTerm(a0);
assert(hasBeenSimplified(a0));
output = nf->CreateTerm(BVSX, len, a0, a1);
it = c.begin(), itend = c.end(); it != itend; it++)
{
ASTNode aaa =*it;
- if (!simplify_upfront)
- aaa = SimplifyTerm(aaa);
assert(hasBeenSimplified(aaa));
if (aaa == annihilator)
case BVCONCAT:
{
ASTNode t =inputterm[0];
- if (!simplify_upfront)
- t = SimplifyTerm(t);
assert(hasBeenSimplified(t));
ASTNode u =inputterm[1];
- if (!simplify_upfront)
- u = SimplifyTerm(u);
assert(hasBeenSimplified(u));
- Kind tkind = t.GetKind();
- Kind ukind = u.GetKind();
+ const Kind tkind = t.GetKind();
+ const Kind ukind = u.GetKind();
- if (BVCONST == tkind && BVCONST == ukind)
- {
- output =
- BVConstEvaluator(nf->CreateTerm(BVCONCAT,
- inputValueWidth, t, u));
- }
- else if (BVEXTRACT == tkind
+ assert (BVCONST != tkind || BVCONST != ukind);
+
+ if (BVEXTRACT == tkind
&& BVEXTRACT == ukind
&& t[0] == u[0])
{
{ // If the shift amount is known. Then replace it by an extract.
ASTNode a =inputterm[0];
- if (!simplify_upfront)
- a = SimplifyTerm(a);
assert(hasBeenSimplified(a));
ASTNode b =inputterm[1];
- if (!simplify_upfront)
- b = SimplifyTerm(b);
assert(hasBeenSimplified(b));
const unsigned int width = a.GetValueWidth();
case BVVARSHIFT:
case BVSRSHIFT:
{
- ASTVec c = inputterm.GetChildren();
- ASTVec o;
- bool constant = true;
- for (ASTVec::iterator
- it = c.begin(), itend = c.end(); it != itend; it++)
- {
- ASTNode aaa = *it;
- if (!simplify_upfront)
- aaa = SimplifyTerm(aaa);
- assert(hasBeenSimplified(aaa));
-
- if (BVCONST != aaa.GetKind())
- {
- constant = false;
- }
- o.push_back(aaa);
- }
- output = nf->CreateTerm(k, inputValueWidth, o);
- if (constant)
- output = BVConstEvaluator(output);
- break;
+ output = inputterm;
+ break;
}
case READ:
{
{
ASTNode t0 = SimplifyFormula(inputterm[0], false, VarConstMap);
- ASTNode t1 = inputterm[1];
- if (!simplify_upfront)
- t1 = SimplifyTerm(t1);
+ const ASTNode& t1 = inputterm[1];
assert(hasBeenSimplified(t1));
- ASTNode t2 = inputterm[2];
- if (!simplify_upfront)
- t2 = SimplifyTerm(t2);
+ const ASTNode& t2 = inputterm[2];
assert(hasBeenSimplified(t2));
output = CreateSimplifiedTermITE(t0, t1, t2);
break;
}
- // run on.
+ output = inputterm;
+ break;
}
case SBVDIV:
{
break;
}
-
- ASTVec c = inputterm.GetChildren();
- ASTVec o;
- for (ASTVec::iterator
- it = c.begin(), itend = c.end(); it != itend; it++)
- {
- ASTNode aaa = SimplifyTerm(*it, VarConstMap);
- o.push_back(aaa);
- }
- output = nf->CreateTerm(k, inputValueWidth, o);
+ output = inputterm;
break;
}
case WRITE: