klee
ArrayExprVisitor.h
Go to the documentation of this file.
1//===-- ArrayExprVisitor.h ------------------------------------------------===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_ARRAYEXPRVISITOR_H
11#define KLEE_ARRAYEXPRVISITOR_H
12
17
18#include <unordered_map>
19#include <unordered_set>
20
21namespace klee {
22
23//------------------------------ HELPER FUNCTIONS ---------------------------//
25private:
26 static bool isReadExprAtOffset(ref<Expr> e, const ReadExpr *base,
27 ref<Expr> offset);
28
29public:
30 static ReadExpr *hasOrderedReads(const ConcatExpr &ce);
31};
32
33//--------------------------- INDEX-BASED OPTIMIZATION-----------------------//
35private:
36 using bindings_ty = std::map<const Array *, std::vector<ref<Expr>>>;
38 // Avoids adding the same index twice
39 std::unordered_set<unsigned> addedIndexes;
41
42protected:
43 Action visitConcat(const ConcatExpr &) override;
44 Action visitRead(const ReadExpr &) override;
45
46public:
48 : arrays(_arrays), incompatible(false) {}
49 inline bool isIncompatible() { return incompatible; }
50};
51
53private:
54 bool compatible{true};
55 bool inner{false};
56
57protected:
58 Action visitRead(const ReadExpr &) override;
59 Action visitURem(const URemExpr &) override;
60 Action visitSRem(const SRemExpr &) override;
61 Action visitOr(const OrExpr &) override;
62
63public:
65
66 inline bool isCompatible() { return compatible; }
67 inline bool hasInnerReads() { return inner; }
68};
69
71private:
72 const Array *array;
75
76protected:
77 Action visitConcat(const ConcatExpr &) override;
78 Action visitMul(const MulExpr &) override;
79
80public:
81 explicit IndexTransformationExprVisitor(const Array *_array)
82 : array(_array), width(Expr::InvalidWidth) {}
83
86 }
87 inline ref<Expr> getMul() { return mul; }
88};
89
90//------------------------- VALUE-BASED OPTIMIZATION-------------------------//
92private:
93 std::vector<const ReadExpr *> &reads;
94 std::map<const ReadExpr *, std::pair<ref<Expr>, Expr::Width>> &readInfo;
97
98 Action inspectRead(ref<Expr> hash, Expr::Width width, const ReadExpr &);
99
100protected:
101 Action visitConcat(const ConcatExpr &) override;
102 Action visitRead(const ReadExpr &) override;
103
104public:
106 std::vector<const ReadExpr *> &_reads,
107 std::map<const ReadExpr *, std::pair<ref<Expr>, Expr::Width>> &_readInfo)
108 : ExprVisitor(true), reads(_reads), readInfo(_readInfo), symbolic(false),
109 incompatible(false) {}
110 inline bool isIncompatible() { return incompatible; }
111 inline bool containsSymbolic() { return symbolic; }
112};
113
115private:
117
118protected:
119 Action visitConcat(const ConcatExpr &) override;
120 Action visitRead(const ReadExpr &re) override;
121
122public:
124 bool recursive = true)
125 : ExprVisitor(recursive), optimized(_optimized) {}
126};
127} // namespace klee
128
129#endif /* KLEE_ARRAYEXPRVISITOR_H */
static bool isReadExprAtOffset(ref< Expr > e, const ReadExpr *base, ref< Expr > offset)
static ReadExpr * hasOrderedReads(const ConcatExpr &ce)
std::map< const ReadExpr *, std::pair< ref< Expr >, Expr::Width > > & readInfo
Action visitConcat(const ConcatExpr &) override
Action inspectRead(ref< Expr > hash, Expr::Width width, const ReadExpr &)
std::vector< const ReadExpr * > & reads
ArrayReadExprVisitor(std::vector< const ReadExpr * > &_reads, std::map< const ReadExpr *, std::pair< ref< Expr >, Expr::Width > > &_readInfo)
Action visitRead(const ReadExpr &) override
Action visitConcat(const ConcatExpr &) override
Action visitRead(const ReadExpr &re) override
ExprHashMap< ref< Expr > > optimized
ArrayValueOptReplaceVisitor(ExprHashMap< ref< Expr > > &_optimized, bool recursive=true)
Action visitConcat(const ConcatExpr &) override
ConstantArrayExprVisitor(bindings_ty &_arrays)
Action visitRead(const ReadExpr &) override
std::map< const Array *, std::vector< ref< Expr > > > bindings_ty
std::unordered_set< unsigned > addedIndexes
Class representing symbolic expressions.
Definition: Expr.h:91
static const Width InvalidWidth
Definition: Expr.h:99
unsigned Width
The type of an expression is simply its width, in bits.
Definition: Expr.h:97
static const Width Int8
Definition: Expr.h:101
Action visitRead(const ReadExpr &) override
Action visitURem(const URemExpr &) override
Action visitOr(const OrExpr &) override
Action visitSRem(const SRemExpr &) override
Action visitConcat(const ConcatExpr &) override
IndexTransformationExprVisitor(const Array *_array)
Action visitMul(const MulExpr &) override
Class representing a one byte read from an array.
Definition: Expr.h:565
Definition: main.cpp:291