return ((ASTBVConst *) _int_node_ptr)->GetBVConst();
} //End of GetBVConst()
+ unsigned int ASTNode::GetUnsignedConst() const
+ {
+ const ASTNode& n = *this;
+ assert(BVCONST == n.GetKind());
+
+ if (sizeof(unsigned int) * 8 < n.GetValueWidth())
+ {
+ // It may only contain a small value in a bit type,
+ // which fits nicely into an unsigned int. This is
+ // common for functions like: bvshl(bv1[128],
+ // bv1[128]) where both operands have the same type.
+ signed long maxBit = CONSTANTBV::Set_Max(n.GetBVConst());
+ if (maxBit >= ((signed long) sizeof(unsigned int)) * 8)
+ {
+ n.LispPrint(cerr); //print the node so they can find it.
+ FatalError("GetUnsignedConst: cannot convert bvconst "\
+ "of length greater than 32 to unsigned int");
+ }
+ }
+ return (unsigned int) *((unsigned int *) n.GetBVConst());
+ } //end of GetUnsignedConst
+
+
+
+
void ASTNode::NFASTPrint(int l, int max, int prefix) const
{
//****************************************
//Get the BVCONST value.
CBV GetBVConst() const;
+ unsigned int GetUnsignedConst() const;
+
+
/*******************************************************************
* ASTNode is of type BV <==> ((indexwidth=0)&&(valuewidth>0))*
* ASTNode is of type ARRAY <==> ((indexwidth>0)&&(valuewidth>0))*
FatalError("BVTypeCheck: should have exactly 3 args\n", n);
if (!(BVCONST == n[1].GetKind() && BVCONST == n[2].GetKind()))
FatalError("BVTypeCheck: indices should be BVCONST\n", n);
- if (n.GetValueWidth() != GetUnsignedConst(n[1]) - GetUnsignedConst(n[2]) + 1)
+ if (n.GetValueWidth() != n[1].GetUnsignedConst() - n[2].GetUnsignedConst() + 1)
FatalError("BVTypeCheck: length mismatch\n", n);
- if (GetUnsignedConst(n[1]) >= n[0].GetValueWidth())
+ if (n[1].GetUnsignedConst() >= n[0].GetValueWidth())
FatalError("BVTypeCheck: Top index of select is greater or equal to the bitwidth.\n", n);
break;
case BVLEFTSHIFT:
return true;
} //End of TypeCheck function
- //Return the unsigned constant value of the input 'n'
- unsigned int GetUnsignedConst(const ASTNode n)
- {
- if(BVCONST != n.GetKind()){
- FatalError("GetUnsignedConst: cannot extract an "\
- "unsigned value from a non-bvconst");
- }
-
- if (sizeof(unsigned int) * 8 <= n.GetValueWidth())
- {
- // It may only contain a small value in a bit type,
- // which fits nicely into an unsigned int. This is
- // common for functions like: bvshl(bv1[128],
- // bv1[128]) where both operands have the same type.
- signed long maxBit = CONSTANTBV::Set_Max(n.GetBVConst());
- if (maxBit >= ((signed long) sizeof(unsigned int)) * 8)
- {
- n.LispPrint(cerr); //print the node so they can find it.
- FatalError("GetUnsignedConst: cannot convert bvconst "\
- "of length greater than 32 to unsigned int");
- }
- }
- return (unsigned int) *((unsigned int *) n.GetBVConst());
- } //end of GetUnsignedConst
//if a is READ(Arr,const) or SYMBOL, and b is BVCONST then return 1
//if b is READ(Arr,const) or SYMBOL, and a is BVCONST then return -1
v = _ASTNode_to_BitvectorMap[symbol];
//kk is the index of BVGETBIT
- const unsigned int kk = GetUnsignedConst(s[1]);
+ const unsigned int kk = s[1].GetUnsignedConst();
//Collect the bits of 'symbol' and store in v. Store
//in reverse order.
GetCounterExample(t, readexpr);
//cout << "ASSERT( ";
//cout << " = ";
- out_int.push_back(GetUnsignedConst(val));
+ out_int.push_back(val.GetUnsignedConst());
//cout << "\n";
}
}
// we only accept indices that are byte-aligned
// (e.g., [15:8], [23:16])
// and round down to byte indices rather than bit indices
- upper = GetUnsignedConst(c[1]);
- lower = GetUnsignedConst(c[2]);
+ upper = c[1].GetUnsignedConst();
+ lower = c[2].GetUnsignedConst();
assert(upper > lower);
assert(lower % 8 == 0);
assert((upper + 1) % 8 == 0);
os << "(";
C_Print1(os, c[0], indentation, letize);
os << " << ";
- os << GetUnsignedConst(c[1]);
+ os << c[1].GetUnsignedConst();
os << ")";
break;
case BVRIGHTSHIFT:
os << "(";
C_Print1(os, c[0], indentation, letize);
os << " >> ";
- os << GetUnsignedConst(c[1]);
+ os << c[1].GetUnsignedConst();
os << ")";
break;
case BVMULT:
// comparison
if (LHSkind == BVEXTRACT)
{
- upper = GetUnsignedConst(c[0].GetChildren()[1]);
- lower = GetUnsignedConst(c[0].GetChildren()[2]);
+ upper = c[0].GetChildren()[1].GetUnsignedConst();
+ lower = c[0].GetChildren()[2].GetUnsignedConst();
num_bytes = (upper - lower + 1) / 8;
}
else if (RHSkind == BVEXTRACT)
{
- upper = GetUnsignedConst(c[1].GetChildren()[1]);
- lower = GetUnsignedConst(c[1].GetChildren()[2]);
+ upper = c[1].GetChildren()[1].GetUnsignedConst();
+ lower = c[1].GetChildren()[2].GetUnsignedConst();
num_bytes = (upper - lower + 1) / 8;
}
// see if it's a BVEXTRACT, and if so, whether it's multi-byte
if (it->second.GetKind() == BVEXTRACT)
{
- upper = GetUnsignedConst(it->second.GetChildren()[1]);
- lower = GetUnsignedConst(it->second.GetChildren()[2]);
+ upper = it->second.GetChildren()[1].GetUnsignedConst();
+ lower = it->second.GetChildren()[2].GetUnsignedConst();
num_bytes = (upper - lower + 1) / 8;
assert(num_bytes > 0);
}
case BVEXTRACT:
PL_Print1(os, c[0], indentation, letize);
os << "[";
- os << GetUnsignedConst(c[1]);
+ os << c[1].GetUnsignedConst();
os << ":";
- os << GetUnsignedConst(c[2]);
+ os << c[2].GetUnsignedConst();
os << "]";
break;
case BVLEFTSHIFT:
{
FatalError("PL_Print1: The shift argument to a left shift must be a constant. Found:",c[1]);
}
- os << GetUnsignedConst(c[1]);
+ os << c[1].GetUnsignedConst();
os << ")";
os << "[";
os << (c[0].GetValueWidth()-1);
case BVSX:
case BVZX:
{
- unsigned int amount = GetUnsignedConst(c[1]);
+ unsigned int amount = c[1].GetUnsignedConst();
if (BVZX == kind)
os << "(zero_extend[";
else
break;
case BVEXTRACT:
{
- unsigned int upper = GetUnsignedConst(c[1]);
- unsigned int lower = GetUnsignedConst(c[2]);
+ unsigned int upper = c[1].GetUnsignedConst();
+ unsigned int lower = c[2].GetUnsignedConst();
assert(upper >= lower);
os << "(extract[" << upper << ":" << lower << "] ";
SMTLIB1_Print1(os, c[0], indentation, letize);
case BVSX:
case BVZX:
{
- unsigned int amount = GetUnsignedConst(c[1]);
+ unsigned int amount = c[1].GetUnsignedConst();
if (BVZX == kind)
os << "((_ zero_extend ";
else
break;
case BVEXTRACT:
{
- unsigned int upper = GetUnsignedConst(c[1]);
- unsigned int lower = GetUnsignedConst(c[2]);
+ unsigned int upper = c[1].GetUnsignedConst();
+ unsigned int lower = c[2].GetUnsignedConst();
assert(upper >= lower);
os << "((_ extract " << upper << " " << lower << ") ";
SMTLIB2_Print1(os, c[0], indentation, letize);
// the shift is destructive, get a copy.
CONSTANTBV::BitVector_Interval_Copy(output, tmp0, 0, 0, inputwidth);
- unsigned int shift = GetUnsignedConst(shiftNode);
+ unsigned int shift = shiftNode.GetUnsignedConst();
if (k == BVLEFTSHIFT)
CONSTANTBV::BitVector_Move_Left(output, shift);
{
output = CONSTANTBV::BitVector_Create(inputwidth, true);
tmp0 = children[0].GetBVConst();
- unsigned int hi = GetUnsignedConst(children[1]);
- unsigned int low = GetUnsignedConst(children[2]);
+ unsigned int hi = children[1].GetUnsignedConst();
+ unsigned int low = children[2].GetUnsignedConst();
unsigned int len = hi - low + 1;
CONSTANTBV::BitVector_Destroy(output);
ASTNode zero = _bm->CreateBVConst(32, 0);
//recall that the indices of BVEXTRACT are always 32 bits
//long. therefore doing a GetBVUnsigned is ok.
- unsigned int i_val = GetUnsignedConst(i);
- unsigned int j_val = GetUnsignedConst(j);
+ unsigned int i_val = i.GetUnsignedConst();
+ unsigned int j_val = j.GetUnsignedConst();
// a0[i:0] and len(a0)=i+1, then return a0
if (0 == j_val && a_len == a0.GetValueWidth())
}
else
{
- const unsigned int shift = GetUnsignedConst(b);
+ const unsigned int shift = b.GetUnsignedConst();
if (shift >= width)
{
output = _bm->CreateZeroConst(width);
// with memo-ization.
const BBNodeVec& bbkids = BBTerm(term[0], support);
- const unsigned int high = GetUnsignedConst(term[1]);
- const unsigned int low = GetUnsignedConst(term[2]);
+ const unsigned int high = term[1].GetUnsignedConst();
+ const unsigned int low = term[2].GetUnsignedConst();
BBNodeVec::const_iterator bbkfit = bbkids.begin();
// I should have used pointers to BBNodeVec, to avoid this crock