15#include "llvm/ADT/APFloat.h"
16#include "llvm/ADT/APInt.h"
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/Support/CommandLine.h"
20#include "llvm/Support/raw_ostream.h"
39template<
class T>
class ref;
41extern llvm::cl::OptionCategory
ExprCat;
216 virtual void print(llvm::raw_ostream &os)
const;
289 typedef llvm::DenseSet<std::pair<const Expr *, const Expr *> >
ExprEquivSet;
315 return !(lhs == rhs);
344 llvm::raw_string_ostream TmpStr(str);
352 llvm::raw_string_ostream TmpStr(str);
518 Array(
const std::string &_name, uint64_t _size,
561 unsigned hash()
const;
649 return create(kids[0], kids[1], kids[2]);
698 if (i == 0)
return left;
699 else if (i == 1)
return right;
871#define CAST_EXPR_CLASS(_class_kind) \
872class _class_kind ## Expr : public CastExpr { \
874 static const Kind kind = _class_kind; \
875 static const unsigned numKids = 1; \
877 _class_kind ## Expr(ref<Expr> e, Width w) : CastExpr(e,w) {} \
878 static ref<Expr> alloc(const ref<Expr> &e, Width w) { \
879 ref<Expr> r(new _class_kind ## Expr(e, w)); \
883 static ref<Expr> create(const ref<Expr> &e, Width w); \
884 Kind getKind() const { return _class_kind; } \
885 virtual ref<Expr> rebuild(ref<Expr> kids[]) const { \
886 return create(kids[0], width); \
889 static bool classof(const Expr *E) { \
890 return E->getKind() == Expr::_class_kind; \
892 static bool classof(const _class_kind ## Expr *) { \
902#define ARITHMETIC_EXPR_CLASS(_class_kind) \
903 class _class_kind##Expr : public BinaryExpr { \
905 static const Kind kind = _class_kind; \
906 static const unsigned numKids = 2; \
909 _class_kind##Expr(const ref<Expr> &l, const ref<Expr> &r) \
910 : BinaryExpr(l, r) {} \
911 static ref<Expr> alloc(const ref<Expr> &l, const ref<Expr> &r) { \
912 ref<Expr> res(new _class_kind##Expr(l, r)); \
913 res->computeHash(); \
916 static ref<Expr> create(const ref<Expr> &l, const ref<Expr> &r); \
917 Width getWidth() const { return left->getWidth(); } \
918 Kind getKind() const { return _class_kind; } \
919 virtual ref<Expr> rebuild(ref<Expr> kids[]) const { \
920 return create(kids[0], kids[1]); \
923 static bool classof(const Expr *E) { \
924 return E->getKind() == Expr::_class_kind; \
926 static bool classof(const _class_kind##Expr *) { return true; } \
929 virtual int compareContents(const Expr &b) const { \
951#define COMPARISON_EXPR_CLASS(_class_kind) \
952 class _class_kind##Expr : public CmpExpr { \
954 static const Kind kind = _class_kind; \
955 static const unsigned numKids = 2; \
958 _class_kind##Expr(const ref<Expr> &l, const ref<Expr> &r) \
960 static ref<Expr> alloc(const ref<Expr> &l, const ref<Expr> &r) { \
961 ref<Expr> res(new _class_kind##Expr(l, r)); \
962 res->computeHash(); \
965 static ref<Expr> create(const ref<Expr> &l, const ref<Expr> &r); \
966 Kind getKind() const { return _class_kind; } \
967 virtual ref<Expr> rebuild(ref<Expr> kids[]) const { \
968 return create(kids[0], kids[1]); \
971 static bool classof(const Expr *E) { \
972 return E->getKind() == Expr::_class_kind; \
974 static bool classof(const _class_kind##Expr *) { return true; } \
977 virtual int compareContents(const Expr &b) const { \
998 static const Kind kind = Constant;
999 static const unsigned numKids = 0;
1031 assert(getWidth() <= bits &&
"Value may be out of range!");
1032 return value.getZExtValue();
1038 return value.getLimitedValue(Limit);
1044 void toString(std::string &Res,
unsigned radix = 10)
const;
1049 return getWidth() < cb.
getWidth() ? -1 : 1;
1050 if (value == cb.
value)
1052 return value.ult(cb.
value) ? -1 : 1;
1056 assert(0 &&
"rebuild() on ConstantExpr");
1060 virtual unsigned computeHash();
1062 static ref<Expr> fromMemory(
void *address, Width w);
1063 void toMemory(
void *address);
1072 return alloc(f.bitcastToAPInt());
1076 return alloc(llvm::APInt(w, v));
1093 bool isZero()
const {
return getAPValue().isMinValue(); }
1096 bool isOne()
const {
return getLimitedValue() == 1; }
1100 return (getWidth() ==
Expr::Bool && value.getBoolValue() ==
true);
1105 return (getWidth() ==
Expr::Bool && value.getBoolValue() ==
false);
1109 bool isAllOnes()
const {
return getAPValue().isAllOnesValue(); }
1151 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this))
1152 return CE->isZero();
1158 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this))
1159 return CE->isTrue();
1165 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this))
1166 return CE->isFalse();
#define ARITHMETIC_EXPR_CLASS(_class_kind)
#define CAST_EXPR_CLASS(_class_kind)
#define COMPARISON_EXPR_CLASS(_class_kind)
Implements smart-pointer ref<> used by KLEE.
Provides an interface for creating and destroying Array objects.
Array(const Array &array)
Expr::Width getRange() const
bool isConstantArray() const
Array & operator=(const Array &array)
bool isSymbolicArray() const
const std::vector< ref< ConstantExpr > > constantValues
const std::string getName() const
unsigned computeHash()
ComputeHash must take into account the name, the size, the domain, and the range.
Expr::Width getDomain() const
BinaryExpr(const ref< Expr > &l, const ref< Expr > &r)
static bool classof(const BinaryExpr *)
ref< Expr > getKid(unsigned i) const
static bool classof(const Expr *E)
unsigned getNumKids() const
int compareContents(const Expr &b) const
static bool classof(const Expr *E)
static bool classof(const CastExpr *)
static bool needsResultType()
virtual unsigned computeHash()
unsigned getNumKids() const
ref< Expr > getKid(unsigned i) const
CastExpr(const ref< Expr > &e, Width w)
static bool classof(const Expr *E)
static bool classof(const CmpExpr *)
CmpExpr(ref< Expr > l, ref< Expr > r)
ref< Expr > getRight() const
static ref< Expr > createN(unsigned nKids, const ref< Expr > kids[])
Shortcuts to create larger concats. The chain returned is unbalanced to the right.
static ref< Expr > alloc(const ref< Expr > &l, const ref< Expr > &r)
ConcatExpr(const ref< Expr > &l, const ref< Expr > &r)
virtual int compareContents(const Expr &b) const
static ref< Expr > create(const ref< Expr > &l, const ref< Expr > &r)
ref< Expr > getKid(unsigned i) const
static const unsigned numKids
static ref< Expr > create8(const ref< Expr > &kid1, const ref< Expr > &kid2, const ref< Expr > &kid3, const ref< Expr > &kid4, const ref< Expr > &kid5, const ref< Expr > &kid6, const ref< Expr > &kid7, const ref< Expr > &kid8)
Shortcut to concat 8 kids. The chain returned is unbalanced to the right.
static bool classof(const ConcatExpr *)
ref< Expr > getLeft() const
static ref< Expr > create4(const ref< Expr > &kid1, const ref< Expr > &kid2, const ref< Expr > &kid3, const ref< Expr > &kid4)
Shortcut to concat 4 kids. The chain returned is unbalanced to the right.
virtual ref< Expr > rebuild(ref< Expr > kids[]) const
unsigned getNumKids() const
static bool classof(const Expr *E)
bool isTrue() const
isTrue - Is this the true expression.
static ref< ConstantExpr > alloc(uint64_t v, Width w)
static ref< ConstantExpr > alloc(const llvm::APFloat &f)
virtual ref< Expr > rebuild(ref< Expr > kids[]) const
bool isZero() const
isZero - Is this a constant zero.
bool isOne() const
isOne - Is this a constant one.
bool isFalse() const
isFalse - Is this the false expression.
int compareContents(const Expr &b) const
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
ConstantExpr(const llvm::APInt &v)
static bool classof(const ConstantExpr *)
ref< Expr > getKid(unsigned i) const
static ref< ConstantExpr > create(uint64_t v, Width w)
static ref< ConstantExpr > alloc(const llvm::APInt &v)
const llvm::APInt & getAPValue() const
unsigned getNumKids() const
uint64_t getZExtValue(unsigned bits=64) const
static bool classof(const Expr *E)
bool isAllOnes() const
isAllOnes - Is this constant all ones.
Class representing symbolic expressions.
static const unsigned MAGIC_HASH_CONSTANT
static bool needsResultType()
static bool classof(const Expr *)
virtual unsigned computeHash()
static const Width InvalidWidth
virtual Kind getKind() const =0
virtual void print(llvm::raw_ostream &os) const
int compare(const Expr &b) const
static ref< Expr > createZExtToPointerWidth(ref< Expr > e)
static ref< Expr > createIsZero(ref< Expr > e)
virtual int compareContents(const Expr &b) const =0
virtual unsigned hash() const
Returns the pre-computed hash of the current expression.
static ref< Expr > createSExtToPointerWidth(ref< Expr > e)
virtual Width getWidth() const =0
static ref< ConstantExpr > createPointer(uint64_t v)
virtual unsigned getNumKids() const =0
static void printWidth(llvm::raw_ostream &os, Expr::Width w)
@ Sge
Not used in canonical form.
@ Ne
Not used in canonical form.
@ Ugt
Not used in canonical form.
@ Sgt
Not used in canonical form.
@ Uge
Not used in canonical form.
unsigned Width
The type of an expression is simply its width, in bits.
bool isZero() const
isZero - Is this a constant zero.
static ref< Expr > createTempRead(const Array *array, Expr::Width w)
static unsigned getMinBytesForWidth(Width w)
returns the smallest number of bytes in which the given width fits
static bool isValidKidWidth(unsigned kid, Width w)
bool isFalse() const
isFalse - Is this the false expression.
llvm::DenseSet< std::pair< const Expr *, const Expr * > > ExprEquivSet
virtual ref< Expr > rebuild(ref< Expr > kids[]) const =0
bool isTrue() const
isTrue - Is this the true expression.
static ref< Expr > createFromKind(Kind k, std::vector< CreateArg > args)
virtual ref< Expr > getKid(unsigned i) const =0
static ref< Expr > createImplies(ref< Expr > hyp, ref< Expr > conc)
static void printKind(llvm::raw_ostream &os, Kind k)
void dump() const
dump - Print the expression to stderr.
class ReferenceCounter _refCount
Required by klee::ref-managed objects.
static bool classof(const Expr *E)
static bool classof(const NonConstantExpr *)
virtual int compareContents(const Expr &b) const
static ref< Expr > create(const ref< Expr > &e)
static bool classof(const Expr *E)
NotExpr(const ref< Expr > &e)
static const unsigned numKids
virtual ref< Expr > rebuild(ref< Expr > kids[]) const
static ref< Expr > alloc(const ref< Expr > &e)
unsigned getNumKids() const
static bool classof(const NotExpr *)
ref< Expr > getKid(unsigned i) const
virtual unsigned computeHash()
static ref< Expr > create(ref< Expr > src)
virtual ref< Expr > rebuild(ref< Expr > kids[]) const
static ref< Expr > alloc(const ref< Expr > &src)
NotOptimizedExpr(const ref< Expr > &_src)
static bool classof(const Expr *E)
static bool classof(const NotOptimizedExpr *)
static const unsigned numKids
ref< Expr > getKid(unsigned i) const
virtual int compareContents(const Expr &b) const
unsigned getNumKids() const
Class representing a one byte read from an array.
static const unsigned numKids
virtual unsigned computeHash()
unsigned getNumKids() const
virtual ref< Expr > rebuild(ref< Expr > kids[]) const
ReadExpr(const UpdateList &_updates, const ref< Expr > &_index)
int compareContents(const Expr &b) const
static bool classof(const Expr *E)
ref< Expr > getKid(unsigned i) const
static ref< Expr > alloc(const UpdateList &updates, const ref< Expr > &index)
static ref< Expr > create(const UpdateList &updates, ref< Expr > i)
static bool classof(const ReadExpr *)
Reference counter to be used as part of a ref-managed struct or class.
Class representing an if-then-else expression.
static bool classof(const Expr *E)
static bool classof(const SelectExpr *)
static bool isValidKidWidth(unsigned kid, Width w)
virtual int compareContents(const Expr &b) const
ref< Expr > getKid(unsigned i) const
virtual ref< Expr > rebuild(ref< Expr > kids[]) const
static ref< Expr > create(ref< Expr > c, ref< Expr > t, ref< Expr > f)
static ref< Expr > alloc(const ref< Expr > &c, const ref< Expr > &t, const ref< Expr > &f)
unsigned getNumKids() const
SelectExpr(const ref< Expr > &c, const ref< Expr > &t, const ref< Expr > &f)
static const unsigned numKids
Class representing a complete list of updates into an array.
UpdateList & operator=(const UpdateList &b)=default
void extend(const ref< Expr > &index, const ref< Expr > &value)
UpdateList(const Array *_root, const ref< UpdateNode > &_head)
ref< UpdateNode > head
pointer to the most recent update node
unsigned getSize() const
size of this update list
int compare(const UpdateList &b) const
UpdateList(const UpdateList &b)=default
Class representing a byte update of an array.
class ReferenceCounter _refCount
Required by klee::ref-managed objects.
unsigned size
size of this update sequence, including this update
int compare(const UpdateNode &b) const
const ref< UpdateNode > next
uint64_t truncateToNBits(uint64_t x, unsigned N)
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const MemoryMap &mm)
bool operator!=(const Expr &lhs, const Expr &rhs)
bool operator<(const Expr &lhs, const Expr &rhs)
bool operator>(const Expr &lhs, const Expr &rhs)
bool operator>=(const Expr &lhs, const Expr &rhs)
llvm::cl::OptionCategory ExprCat
bool operator<=(const Expr &lhs, const Expr &rhs)
bool operator==(const Expr &lhs, const Expr &rhs)