about summary refs log tree commit diff homepage
path: root/lib/Expr
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-02 17:01:00 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-02 17:01:00 +0000
commit4aea9d3d47e7e47630704fdf6628221fa45f6151 (patch)
tree5e74319cdcc91f362f6d27bd4befcb5c42131d66 /lib/Expr
parent1016ee0df2a459881d6f9930f7b72929e8bdc8b8 (diff)
downloadklee-4aea9d3d47e7e47630704fdf6628221fa45f6151.tar.gz
Use ConstantExpr::alloc instead of ref<Expr> directly
 - The "constant optimization" embedded inside ref<Expr> is going away.

 - No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@72730 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Expr')
-rw-r--r--lib/Expr/Constraints.cpp4
-rw-r--r--lib/Expr/Expr.cpp44
-rw-r--r--lib/Expr/ExprEvaluator.cpp2
-rw-r--r--lib/Expr/ExprPPrinter.cpp7
-rw-r--r--lib/Expr/Parser.cpp61
5 files changed, 60 insertions, 58 deletions
diff --git a/lib/Expr/Constraints.cpp b/lib/Expr/Constraints.cpp
index e9c376f4..4c18a3b3 100644
--- a/lib/Expr/Constraints.cpp
+++ b/lib/Expr/Constraints.cpp
@@ -100,11 +100,11 @@ ref<Expr> ConstraintManager::simplifyExpr(ref<Expr> e) const {
                                          ee->left));
       } else {
         equalities.insert(std::make_pair(*it,
-                                         ref<Expr>(1,Expr::Bool)));
+                                         ConstantExpr::alloc(1, Expr::Bool)));
       }
     } else {
       equalities.insert(std::make_pair(*it,
-                                       ref<Expr>(1,Expr::Bool)));
+                                       ConstantExpr::alloc(1, Expr::Bool)));
     }
   }
 
diff --git a/lib/Expr/Expr.cpp b/lib/Expr/Expr.cpp
index 55b9a0a4..7f20e3fc 100644
--- a/lib/Expr/Expr.cpp
+++ b/lib/Expr/Expr.cpp
@@ -43,42 +43,42 @@ ref<Expr> Expr::createTempRead(const Array *array, Expr::Width w) {
   switch (w) {
   case Expr::Bool: 
     return ZExtExpr::create(ReadExpr::create(ul, 
-                                             ref<Expr>(0,kMachinePointerType)),
+                                             ConstantExpr::alloc(0,kMachinePointerType)),
                             Expr::Bool);
   case Expr::Int8: 
     return ReadExpr::create(ul, 
-                            ref<Expr>(0,kMachinePointerType));
+                            ConstantExpr::alloc(0,kMachinePointerType));
   case Expr::Int16: 
     return ConcatExpr::create(ReadExpr::create(ul, 
-                                               ref<Expr>(1,kMachinePointerType)),
+                                               ConstantExpr::alloc(1,kMachinePointerType)),
                               ReadExpr::create(ul, 
-                                               ref<Expr>(0,kMachinePointerType)));
+                                               ConstantExpr::alloc(0,kMachinePointerType)));
   case Expr::Int32: 
     return ConcatExpr::create4(ReadExpr::create(ul, 
-                                                ref<Expr>(3,kMachinePointerType)),
+                                                ConstantExpr::alloc(3,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(2,kMachinePointerType)),
+                                                ConstantExpr::alloc(2,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(1,kMachinePointerType)),
+                                                ConstantExpr::alloc(1,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(0,kMachinePointerType)));
+                                                ConstantExpr::alloc(0,kMachinePointerType)));
   case Expr::Int64: 
     return ConcatExpr::create8(ReadExpr::create(ul, 
-                                                ref<Expr>(7,kMachinePointerType)),
+                                                ConstantExpr::alloc(7,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(6,kMachinePointerType)),
+                                                ConstantExpr::alloc(6,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(5,kMachinePointerType)),
+                                                ConstantExpr::alloc(5,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(4,kMachinePointerType)),
+                                                ConstantExpr::alloc(4,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(3,kMachinePointerType)),
+                                                ConstantExpr::alloc(3,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(2,kMachinePointerType)),
+                                                ConstantExpr::alloc(2,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(1,kMachinePointerType)),
+                                                ConstantExpr::alloc(1,kMachinePointerType)),
                                ReadExpr::create(ul, 
-                                                ref<Expr>(0,kMachinePointerType)));
+                                                ConstantExpr::alloc(0,kMachinePointerType)));
   default: assert(0 && "invalid width");
   }
 }
@@ -639,7 +639,7 @@ static ref<Expr> SubExpr_create(Expr *l, Expr *r) {
   if (type == Expr::Bool) {
     return XorExpr_create(l, r);
   } else if (*l==*r) {
-    return ref<Expr>(0, type);
+    return ConstantExpr::alloc(0, type);
   } else {
     Expr::Kind lk = l->getKind(), rk = r->getKind();
     if (lk==Expr::Add && l->getKid(0).isConstant()) { // (k+a)-b = k+(a-b)
@@ -891,7 +891,7 @@ ref<Expr>  _e_op ::create(const ref<Expr> &l, const ref<Expr> &r) { \
 
 static ref<Expr> EqExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
   if (l == r) {
-    return ref<Expr>(1, Expr::Bool);
+    return ConstantExpr::alloc(1, Expr::Bool);
   } else {
     return EqExpr::alloc(l, r);
   }
@@ -952,7 +952,7 @@ static ref<Expr> TryConstArrayOpt(const ref<Expr> &cl,
     //llvm::cerr << "\n\n=== Applying const array optimization ===\n\n";
 
     if (matches == 0)
-      return ref<Expr>(0, Expr::Bool);
+      return ConstantExpr::alloc(0, Expr::Bool);
 
     ref<Expr> res = EqExpr::create(first_idx_match, rd->index);
     if (matches == 1)
@@ -1079,11 +1079,11 @@ static ref<Expr> UltExpr_create(const ref<Expr> &l, const ref<Expr> &r) {
     if (r.isConstant()) {      
       uint64_t value = r.getConstantValue();
       if (value <= 8) {
-        ref<Expr> res(0,Expr::Bool);
+        ref<Expr> res = ConstantExpr::alloc(0, Expr::Bool);
         for (unsigned i=0; i<value; i++) {
-          res = OrExpr::create(EqExpr::create(l, ref<Expr>(i,t)), res);
+          res = OrExpr::create(EqExpr::create(l, 
+                                              ConstantExpr::alloc(i, t)), res);
         }
-        //        llvm::cerr << l << "<" << r << "  <=>  " << res << "\n";
         return res;
       }
     }
diff --git a/lib/Expr/ExprEvaluator.cpp b/lib/Expr/ExprEvaluator.cpp
index 102387e1..cf901f0e 100644
--- a/lib/Expr/ExprEvaluator.cpp
+++ b/lib/Expr/ExprEvaluator.cpp
@@ -26,7 +26,7 @@ ExprVisitor::Action ExprEvaluator::evalRead(const UpdateList &ul,
       
       UpdateList fwd(ul.root, un, 0);
       return Action::changeTo(ReadExpr::create(fwd, 
-                                               ref<Expr>(index,Expr::Int32)));
+                                               ConstantExpr::alloc(index, Expr::Int32)));
     }
   }
   
diff --git a/lib/Expr/ExprPPrinter.cpp b/lib/Expr/ExprPPrinter.cpp
index dc7f4f64..fd367f23 100644
--- a/lib/Expr/ExprPPrinter.cpp
+++ b/lib/Expr/ExprPPrinter.cpp
@@ -240,7 +240,8 @@ class PPrinter : public ExprPPrinter {
 
     // Get stride expr in proper index width.
     Expr::Width idxWidth = base->index.getWidth();
-    ref<Expr> strideExpr(stride, idxWidth), offset(0, idxWidth);
+    ref<Expr> strideExpr = ConstantExpr::alloc(stride, idxWidth);
+    ref<Expr> offset = ConstantExpr::alloc(0, idxWidth);
     for (unsigned i=1; i<ep->getNumKids(); ++i) {
       const ReadExpr *re = dyn_ref_cast<ReadExpr>(ep->getKid(i));
       if (!re) 
@@ -357,7 +358,7 @@ public:
         // Detect Not.
         // FIXME: This should be in common code.
         if (const EqExpr *ee = dyn_ref_cast<EqExpr>(e)) {
-          if (ee->left == ref<Expr>(false, Expr::Bool)) {
+          if (ee->left == ConstantExpr::alloc(false, Expr::Bool)) {
             PC << "(Not";
             printWidth(PC, e);
             PC << ' ';
@@ -443,7 +444,7 @@ void ExprPPrinter::printOne(std::ostream &os,
 
 void ExprPPrinter::printConstraints(std::ostream &os,
                                     const ConstraintManager &constraints) {
-  printQuery(os, constraints, ref<Expr>(false, Expr::Bool));
+  printQuery(os, constraints, ConstantExpr::alloc(false, Expr::Bool));
 }
 
 void ExprPPrinter::printQuery(std::ostream &os,
diff --git a/lib/Expr/Parser.cpp b/lib/Expr/Parser.cpp
index dba089a5..a8ea0a6b 100644
--- a/lib/Expr/Parser.cpp
+++ b/lib/Expr/Parser.cpp
@@ -398,7 +398,7 @@ DeclResult ParserImpl::ParseQueryCommand() {
     if (Tok.kind == Token::EndOfFile) {
       Error("unexpected end of file.");
       return new QueryCommand(Constraints.begin(), Constraints.end(),
-                              ref<Expr>(false, Expr::Bool));
+                              ConstantExpr::alloc(false, Expr::Bool));
     }
 
     ExprResult Res = ParseExpr(TypeResult(Expr::Bool));
@@ -410,7 +410,7 @@ DeclResult ParserImpl::ParseQueryCommand() {
 
   ExprResult Res = ParseExpr(TypeResult());
   if (!Res.isValid()) // Error emitted by ParseExpr.
-    Res = ExprResult(ref<Expr>(0, Expr::Bool));
+    Res = ExprResult(ConstantExpr::alloc(0, Expr::Bool));
 
   ExpectRParen("unexpected argument to 'query'.");  
   return new QueryCommand(Constraints.begin(), Constraints.end(),
@@ -447,7 +447,7 @@ ExprResult ParserImpl::ParseExpr(TypeResult ExpectedType) {
   if (Tok.kind == Token::KWFalse || Tok.kind == Token::KWTrue) {
     bool Value = Tok.kind == Token::KWTrue;
     ConsumeToken();
-    return ExprResult(ref<Expr>(Value, Expr::Bool));
+    return ExprResult(ConstantExpr::alloc(Value, Expr::Bool));
   }
   
   if (Tok.kind == Token::Number) {
@@ -491,9 +491,10 @@ ExprResult ParserImpl::ParseExpr(TypeResult ExpectedType) {
     // use-of-undef errors. 
     // FIXME: Maybe we should let the symbol table map to invalid
     // entries?
-    if (Label && ExpectedType.isValid())
-      ExprSymTab.insert(std::make_pair(Label, 
-                                       ref<Expr>(0, ExpectedType.get())));
+    if (Label && ExpectedType.isValid()) {
+      ref<Expr> Value = ConstantExpr::alloc(0, ExpectedType.get());
+      ExprSymTab.insert(std::make_pair(Label, Value));
+    }
     return Res;
   } else if (ExpectedType.isValid()) {
     // Type check result.    
@@ -716,7 +717,7 @@ ExprResult ParserImpl::ParseParenExpr(TypeResult FIXME_UNUSED) {
     default:
       Error("internal error, unimplemented special form.", Name);
       SkipUntilRParen();
-      return ExprResult(ref<Expr>(0, ResTy));
+      return ExprResult(ConstantExpr::alloc(0, ResTy));
     }
   }
 
@@ -740,20 +741,20 @@ ExprResult ParserImpl::ParseUnaryParenExpr(const Token &Name,
   if (Tok.kind == Token::RParen) {
     Error("unexpected end of arguments.", Name);
     ConsumeRParen();
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   }
 
   ExprResult Arg = ParseExpr(IsFixed ? ResTy : TypeResult());
   if (!Arg.isValid())
-    Arg = ref<Expr>(0, ResTy);
+    Arg = ConstantExpr::alloc(0, ResTy);
 
   ExpectRParen("unexpected argument in unary expression.");  
   ExprHandle E = Arg.get();
   switch (Kind) {
   case eMacroKind_Not:
-    return EqExpr::alloc(ref<Expr>(0, E.getWidth()), E);
+    return EqExpr::alloc(ConstantExpr::alloc(0, E.getWidth()), E);
   case eMacroKind_Neg:
-    return SubExpr::alloc(ref<Expr>(0, E.getWidth()), E);
+    return SubExpr::alloc(ConstantExpr::alloc(0, E.getWidth()), E);
   case Expr::SExt:
     // FIXME: Type check arguments.
     return SExtExpr::alloc(E, ResTy);
@@ -762,7 +763,7 @@ ExprResult ParserImpl::ParseUnaryParenExpr(const Token &Name,
     return ZExtExpr::alloc(E, ResTy);
   default:
     Error("internal error, unhandled kind.", Name);
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   }
 }
 
@@ -831,7 +832,7 @@ ExprResult ParserImpl::ParseBinaryParenExpr(const Token &Name,
   ParseMatchedBinaryArgs(Name, IsFixed ? TypeResult(ResTy) : TypeResult(), 
                          LHS, RHS);
   if (!LHS.isValid() || !RHS.isValid())
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
 
   ref<Expr> LHS_E = LHS.get(), RHS_E = RHS.get();
   assert(LHS_E.getWidth() == RHS_E.getWidth() && "Mismatched types!");
@@ -865,7 +866,7 @@ ExprResult ParserImpl::ParseBinaryParenExpr(const Token &Name,
   case Expr::Sge: return SgeExpr::alloc(LHS_E, RHS_E);
   default:
     Error("FIXME: unhandled kind.", Name);
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   }  
 }
 
@@ -875,14 +876,14 @@ ExprResult ParserImpl::ParseSelectParenExpr(const Token &Name,
   if (Tok.kind == Token::RParen) {
     Error("unexpected end of arguments.", Name);
     ConsumeRParen();
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   }
 
   ExprResult Cond = ParseExpr(Expr::Bool);
   ExprResult LHS, RHS;
   ParseMatchedBinaryArgs(Name, ResTy, LHS, RHS);
   if (!Cond.isValid() || !LHS.isValid() || !RHS.isValid())
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   return SelectExpr::alloc(Cond.get(), LHS.get(), RHS.get());
 }
 
@@ -900,7 +901,7 @@ ExprResult ParserImpl::ParseConcatParenExpr(const Token &Name,
     // Skip to end of expr on error.
     if (!E.isValid()) {
       SkipUntilRParen();
-      return ref<Expr>(0, ResTy);
+      return ConstantExpr::alloc(0, ResTy);
     }
     
     Kids.push_back(E.get());
@@ -911,7 +912,7 @@ ExprResult ParserImpl::ParseConcatParenExpr(const Token &Name,
 
   if (Width != ResTy) {
     Error("concat does not match expected result size.");
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   }
 
   return ConcatExpr::createN(Kids.size(), &Kids[0]);
@@ -926,14 +927,14 @@ ExprResult ParserImpl::ParseExtractParenExpr(const Token &Name,
   ExpectRParen("unexpected argument to expression.");
 
   if (!OffsetExpr.isValid() || !Child.isValid())
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
 
   assert(OffsetExpr.get().isConstant() && "ParseNumber returned non-constant.");
   unsigned Offset = (unsigned) OffsetExpr.get().getConstantValue();
 
   if (Offset + ResTy > Child.get().getWidth()) {
     Error("extract out-of-range of child expression.", Name);
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   }
 
   return ExtractExpr::alloc(Child.get(), Offset, ResTy);
@@ -947,7 +948,7 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name,
   ExpectRParen("unexpected argument in read expression.");
   
   if (!Array.isValid())
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
 
   // FIXME: Need generic way to get array width. Needs to work with
   // anonymous arrays.
@@ -962,10 +963,10 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name,
     IndexExpr = Index.getExpr();
   
   if (!IndexExpr.isValid())
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   else if (IndexExpr.get().getWidth() != ArrayDomainType) {
     Error("index width does not match array domain.");
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   }
 
   // FIXME: Check range width.
@@ -973,13 +974,13 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name,
   switch (Kind) {
   default:
     assert(0 && "Invalid kind.");
-    return ref<Expr>(0, ResTy);
+    return ConstantExpr::alloc(0, ResTy);
   case eMacroKind_ReadLSB:
   case eMacroKind_ReadMSB: {
     unsigned NumReads = ResTy / ArrayRangeType;
     if (ResTy != NumReads*ArrayRangeType) {
       Error("invalid ordered read (not multiple of range type).", Name);
-      return ref<Expr>(0, ResTy);
+      return ConstantExpr::alloc(0, ResTy);
     }
     std::vector<ExprHandle> Kids;
     Kids.reserve(NumReads);
@@ -987,7 +988,7 @@ ExprResult ParserImpl::ParseAnyReadParenExpr(const Token &Name,
     for (unsigned i=0; i<NumReads; ++i) {
       // FIXME: using folding here
       ExprHandle OffsetIndex = AddExpr::create(IndexExpr.get(),
-                                               ref<Expr>(i, ArrayDomainType));
+                                               ConstantExpr::alloc(i, ArrayDomainType));
       Kids.push_back(ReadExpr::alloc(Array.get(), OffsetIndex));
     }
     if (Kind == eMacroKind_ReadLSB)
@@ -1185,7 +1186,7 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) {
     // Diagnose 0[box] with no trailing digits.
     if (!N) {
       Error("invalid numeric token (no digits).", Tok);
-      return ref<Expr>(0, Type);
+      return ConstantExpr::alloc(0, Type);
     }
   }
 
@@ -1207,12 +1208,12 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) {
       Digit = Char - 'A' + 10;
     else {
       Error("invalid character in numeric token.", Tok);
-      return ref<Expr>(0, Type);
+      return ConstantExpr::alloc(0, Type);
     }
 
     if (Digit >= Radix) {
       Error("invalid character in numeric token (out of range).", Tok);
-      return ref<Expr>(0, Type);
+      return ConstantExpr::alloc(0, Type);
     }
 
     DigitVal = Digit;
@@ -1223,7 +1224,7 @@ ExprResult ParserImpl::ParseNumberToken(Expr::Width Type, const Token &Tok) {
   if (HasMinus)
     Val = -Val;
 
-  return ExprResult(ref<Expr>(Val.trunc(Type).getZExtValue(), Type));
+  return ExprResult(ConstantExpr::alloc(Val.trunc(Type).getZExtValue(), Type));
 }
 
 /// ParseTypeSpecifier - Parse a type specifier.