klee
STPBuilder.h
Go to the documentation of this file.
1//===-- STPBuilder.h --------------------------------------------*- C++ -*-===//
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_STPBUILDER_H
11#define KLEE_STPBUILDER_H
12
13#include "klee/Config/config.h"
16
17#include <vector>
18
19#define Expr VCExpr
20#include <stp/c_interface.h>
21#undef Expr
22
23namespace klee {
24 class ExprHolder {
25 friend class ExprHandle;
26 ::VCExpr expr;
27 unsigned count;
28
29 public:
30 ExprHolder(const ::VCExpr _expr) : expr(_expr), count(0) {}
32 if (expr) vc_DeleteExpr(expr);
33 }
34 };
35
36 class ExprHandle {
38
39 public:
40 ExprHandle() : H(new ExprHolder(0)) { H->count++; }
41 ExprHandle(::VCExpr _expr) : H(new ExprHolder(_expr)) { H->count++; }
42 ExprHandle(const ExprHandle &b) : H(b.H) { H->count++; }
43 ~ExprHandle() { if (--H->count == 0) delete H; }
44
46 if (--H->count == 0) delete H;
47 H = b.H;
48 H->count++;
49 return *this;
50 }
51
52 operator bool () { return H->expr; }
53 operator ::VCExpr () { return H->expr; }
54 };
55
56 class STPArrayExprHash : public ArrayExprHash< ::VCExpr > {
57
58 friend class STPBuilder;
59
60 public:
63 };
64
66 ::VC vc;
68
73
75
76private:
77
78 ExprHandle bvOne(unsigned width);
79 ExprHandle bvZero(unsigned width);
80 ExprHandle bvMinusOne(unsigned width);
81 ExprHandle bvConst32(unsigned width, uint32_t value);
82 ExprHandle bvConst64(unsigned width, uint64_t value);
83 ExprHandle bvZExtConst(unsigned width, uint64_t value);
84 ExprHandle bvSExtConst(unsigned width, uint64_t value);
85
87 ExprHandle bvExtract(ExprHandle expr, unsigned top, unsigned bottom);
89
90 //logical left and right shift (not arithmetic)
91 ExprHandle bvLeftShift(ExprHandle expr, unsigned shift);
92 ExprHandle bvRightShift(ExprHandle expr, unsigned shift);
97 unsigned &shiftBits);
98
100 ExprHandle isSigned);
101 ExprHandle constructMulByConstant(ExprHandle expr, unsigned width, uint64_t x);
102 ExprHandle constructUDivByConstant(ExprHandle expr_n, unsigned width, uint64_t d);
103 ExprHandle constructSDivByConstant(ExprHandle expr_n, unsigned width, uint64_t d);
104
105 ::VCExpr getInitialArray(const Array *os);
106 ::VCExpr getArrayForUpdate(const Array *root, const UpdateNode *un);
107
109 ExprHandle construct(ref<Expr> e, int *width_out);
110
111 ::VCExpr buildVar(const char *name, unsigned width);
112 ::VCExpr buildArray(const char *name, unsigned indexWidth, unsigned valueWidth);
113
114public:
115 STPBuilder(::VC _vc, bool _optimizeDivides=true);
117
120 ExprHandle getInitialRead(const Array *os, unsigned index);
121
123 ExprHandle res = construct(e, 0);
124 constructed.clear();
125 return res;
126 }
127};
128
129}
130
131#endif /* KLEE_STPBUILDER_H */
void vc_DeleteExpr(void *)
ExprHandle(::VCExpr _expr)
Definition: STPBuilder.h:41
ExprHandle & operator=(const ExprHandle &b)
Definition: STPBuilder.h:45
ExprHolder * H
Definition: STPBuilder.h:37
ExprHandle(const ExprHandle &b)
Definition: STPBuilder.h:42
unsigned count
Definition: STPBuilder.h:27
::VCExpr expr
Definition: STPBuilder.h:26
ExprHolder(const ::VCExpr _expr)
Definition: STPBuilder.h:30
ExprHandle constructUDivByConstant(ExprHandle expr_n, unsigned width, uint64_t d)
ExprHandle bvOne(unsigned width)
ExprHandle bvMinusOne(unsigned width)
ExprHandle eqExpr(ExprHandle a, ExprHandle b)
ExprHandle bvRightShift(ExprHandle expr, unsigned shift)
ExprHandle extractPartialShiftValue(ExprHandle shift, unsigned width, unsigned &shiftBits)
ExprHandle getInitialRead(const Array *os, unsigned index)
ExprHandle bvZExtConst(unsigned width, uint64_t value)
ExprHandle bvConst64(unsigned width, uint64_t value)
::VCExpr getArrayForUpdate(const Array *root, const UpdateNode *un)
ExprHandle constructAShrByConstant(ExprHandle expr, unsigned shift, ExprHandle isSigned)
ExprHandle constructSDivByConstant(ExprHandle expr_n, unsigned width, uint64_t d)
ExprHandle getTrue()
::VCExpr buildVar(const char *name, unsigned width)
ExprHandle bvExtract(ExprHandle expr, unsigned top, unsigned bottom)
ExprHandle bvZero(unsigned width)
ExprHandle bvVarLeftShift(ExprHandle expr, ExprHandle shift)
STPArrayExprHash _arr_hash
Definition: STPBuilder.h:74
::VCExpr getInitialArray(const Array *os)
ExprHandle bvLeftShift(ExprHandle expr, unsigned shift)
ExprHandle construct(ref< Expr > e)
Definition: STPBuilder.h:122
ExprHandle bvVarRightShift(ExprHandle expr, ExprHandle shift)
ExprHandle bvSExtConst(unsigned width, uint64_t value)
ExprHandle bvBoolExtract(ExprHandle expr, int bit)
ExprHandle construct(ref< Expr > e, int *width_out)
bool optimizeDivides
Definition: STPBuilder.h:72
ExprHandle constructMulByConstant(ExprHandle expr, unsigned width, uint64_t x)
ExprHandle getFalse()
ExprHandle bvConst32(unsigned width, uint32_t value)
::VCExpr buildArray(const char *name, unsigned indexWidth, unsigned valueWidth)
STPBuilder(::VC _vc, bool _optimizeDivides=true)
ExprHandle constructActual(ref< Expr > e, int *width_out)
ExprHandle bvVarArithRightShift(ExprHandle expr, ExprHandle shift)
ExprHashMap< std::pair< ExprHandle, unsigned > > constructed
Definition: STPBuilder.h:67
Class representing a byte update of an array.
Definition: Expr.h:451
Definition: main.cpp:291