about summary refs log tree commit diff homepage
path: root/lib/Solver
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Solver')
-rw-r--r--lib/Solver/STPBuilder.cpp20
-rw-r--r--lib/Solver/STPBuilder.h2
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/Solver/STPBuilder.cpp b/lib/Solver/STPBuilder.cpp
index 28b5c1a5..b5dddad1 100644
--- a/lib/Solver/STPBuilder.cpp
+++ b/lib/Solver/STPBuilder.cpp
@@ -107,13 +107,13 @@ ExprHandle STPBuilder::getFalse() {
   return vc_falseExpr(vc);
 }
 ExprHandle STPBuilder::bvOne(unsigned width) {
-  return bvConst32(width, 1);
+  return bvZExtConst(width, 1);
 }
 ExprHandle STPBuilder::bvZero(unsigned width) {
-  return bvConst32(width, 0);
+  return bvZExtConst(width, 0);
 }
 ExprHandle STPBuilder::bvMinusOne(unsigned width) {
-  return bvConst64(width, (int64_t) -1);
+  return bvSExtConst(width, (int64_t) -1);
 }
 ExprHandle STPBuilder::bvConst32(unsigned width, uint32_t value) {
   return vc_bvConstExprFromInt(vc, width, value);
@@ -121,6 +121,20 @@ ExprHandle STPBuilder::bvConst32(unsigned width, uint32_t value) {
 ExprHandle STPBuilder::bvConst64(unsigned width, uint64_t value) {
   return vc_bvConstExprFromLL(vc, width, value);
 }
+ExprHandle STPBuilder::bvZExtConst(unsigned width, uint64_t value) {
+  if (width <= 64)
+    return bvConst64(width, value);
+
+  ExprHandle expr = bvConst64(64, value), zero = bvConst64(64, 0);
+  for (width -= 64; width > 64; width -= 64)
+    expr = vc_bvConcatExpr(vc, zero, expr);
+  return vc_bvConcatExpr(vc, bvConst64(width, 0), expr);
+}
+ExprHandle STPBuilder::bvSExtConst(unsigned width, uint64_t value) {
+  if (width <= 64)
+    return bvConst64(width, value);
+  return vc_bvSignExtend(vc, bvConst64(64, value), width);
+}
 
 ExprHandle STPBuilder::bvBoolExtract(ExprHandle expr, int bit) {
   return vc_eqExpr(vc, bvExtract(expr, bit, bit), bvOne(1));
diff --git a/lib/Solver/STPBuilder.h b/lib/Solver/STPBuilder.h
index a4d6d0f8..7cc026bc 100644
--- a/lib/Solver/STPBuilder.h
+++ b/lib/Solver/STPBuilder.h
@@ -81,6 +81,8 @@ private:
   ExprHandle bvMinusOne(unsigned width);
   ExprHandle bvConst32(unsigned width, uint32_t value);
   ExprHandle bvConst64(unsigned width, uint64_t value);
+  ExprHandle bvZExtConst(unsigned width, uint64_t value);
+  ExprHandle bvSExtConst(unsigned width, uint64_t value);
 
   ExprHandle bvBoolExtract(ExprHandle expr, int bit);
   ExprHandle bvExtract(ExprHandle expr, unsigned top, unsigned bottom);