about summary refs log tree commit diff homepage
path: root/lib/Expr
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-09 08:42:08 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-09 08:42:08 +0000
commit58d1592fa3fd84aded956801183949b9c710490e (patch)
tree097d091d23bf0f5906f9e3542531c5ddb39c4588 /lib/Expr
parent54d8a1aee4b05daee1244ee1d34df8059a40d5a9 (diff)
downloadklee-58d1592fa3fd84aded956801183949b9c710490e.tar.gz
More constant Array support.
 - The are parsed, printed, and solved now.

 - Remove some members of ArrayDecl which are only duplicates of Array members.

 - KLEE still doesn't create these, but you can write them by hand.

The EXE style constant array optimization for STP (turning the initial writes
into asserts) is now only a stones throw away, but I need to leave something fun
to do tomorrow. :)


git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@73133 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Expr')
-rw-r--r--lib/Expr/ExprPPrinter.cpp14
-rw-r--r--lib/Expr/Parser.cpp32
2 files changed, 27 insertions, 19 deletions
diff --git a/lib/Expr/ExprPPrinter.cpp b/lib/Expr/ExprPPrinter.cpp
index e3a83f9a..6ad5fffd 100644
--- a/lib/Expr/ExprPPrinter.cpp
+++ b/lib/Expr/ExprPPrinter.cpp
@@ -532,8 +532,18 @@ void ExprPPrinter::printQuery(std::ostream &os,
       // FIXME: Print correct name, domain, and range.
       PC << "array " << A->name
          << "[" << A->size << "]"
-         << " : " << "w32" << " -> " << "w8"
-         << " = symbolic";
+         << " : " << "w32" << " -> " << "w8" << " = ";
+      if (A->isSymbolicArray()) {
+        PC << "symbolic";
+      } else {
+        PC << "[";
+        for (unsigned i = 0, e = A->size; i != e; ++i) {
+          if (i)
+            PC << " ";
+          PC << A->constantValues[i];
+        }
+        PC << "]";
+      }
       PC.breakLine();
     }
   }
diff --git a/lib/Expr/Parser.cpp b/lib/Expr/Parser.cpp
index 8e5349c5..1f2f8412 100644
--- a/lib/Expr/Parser.cpp
+++ b/lib/Expr/Parser.cpp
@@ -407,7 +407,7 @@ DeclResult ParserImpl::ParseArrayDecl() {
   IntegerResult Size;
   TypeResult DomainType;
   TypeResult RangeType;
-  std::vector<ExprHandle> Values;
+  std::vector< ref<ConstantExpr> > Values;
 
   ConsumeToken();
   
@@ -458,7 +458,7 @@ DeclResult ParserImpl::ParseArrayDecl() {
 
       ExprResult Res = ParseNumber(RangeType.get());
       if (Res.isValid())
-        Values.push_back(Res.get());
+        Values.push_back(cast<ConstantExpr>(Res.get()));
     }
     ConsumeRSquare();
   } else {
@@ -502,11 +502,6 @@ DeclResult ParserImpl::ParseArrayDecl() {
     Values.clear();
   }
 
-  if (!Values.empty()) {
-    Error("constant arrays are not yet supported.");
-    Values.clear();
-  }
-
   // FIXME: Validate that this array is undeclared.
 
  exit:
@@ -519,7 +514,12 @@ DeclResult ParserImpl::ParseArrayDecl() {
 
   // FIXME: Array should take domain and range.
   const Identifier *Label = GetOrCreateIdentifier(Name);
-  Array *Root = new Array(Label->Name, Size.get());
+  Array *Root;
+  if (!Values.empty())
+    Root = new Array(Label->Name, Size.get(),
+                     &Values[0], &Values[0] + Values.size());
+  else
+    Root = new Array(Label->Name, Size.get());
   ArrayDecl *AD = new ArrayDecl(Label, Size.get(), 
                                 DomainType.get(), RangeType.get(), Root);
 
@@ -1554,22 +1554,20 @@ void ParserImpl::Error(const char *Message, const Token &At) {
 Decl::Decl(DeclKind _Kind) : Kind(_Kind) {}
 
 void ArrayDecl::dump() {
-  // FIXME: For now, print using the Array* "name".
   std::cout << "array " << Root->name
-            << "[" << Size << "]"
+            << "[" << Root->size << "]"
             << " : " << 'w' << Domain << " -> " << 'w' << Range << " = ";
 
-  if (Contents.empty()) {
+  if (Root->isSymbolicArray()) {
     std::cout << "symbolic\n";
   } else {
-    std::cout << '{';
-    for (std::vector<ExprHandle>::const_iterator it = Contents.begin(),
-           ie = Contents.end(); it != ie;) {
-      std::cout << *it;
-      if (++it != ie)
+    std::cout << '[';
+    for (unsigned i = 0, e = Root->size; i != e; ++i) {
+      if (i)
         std::cout << " ";
+      std::cout << Root->constantValues[i];
     }
-    std::cout << "}\n";
+    std::cout << "]\n";
   }
 }