about summary refs log tree commit diff homepage
path: root/include/klee/Expr/ArrayCache.h
blob: f482cba67b4025af75cee87427bf447c48878df9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//===-- ArrayCache.h --------------------------------------------*- C++ -*-===//
//
//                     The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef KLEE_ARRAYCACHE_H
#define KLEE_ARRAYCACHE_H

#include "klee/Expr/Expr.h"
#include "klee/Expr/ArrayExprHash.h" // For klee::ArrayHashFn

#include <string>
#include <unordered_set>
#include <vector>

namespace klee {

struct EquivArrayCmpFn {
  bool operator()(const Array *array1, const Array *array2) const {
    if (array1 == NULL || array2 == NULL)
      return false;
    return (array1->size == array2->size) && (array1->name == array2->name);
  }
};

/// Provides an interface for creating and destroying Array objects.
class ArrayCache {
public:
  ArrayCache() {}
  ~ArrayCache();
  /// Create an Array object.
  //
  /// Symbolic Arrays are cached so that only one instance exists. This
  /// provides a limited form of "alpha-renaming". Constant arrays are not
  /// cached.
  ///
  /// This class retains ownership of Array object so that upon destruction
  /// of this object all allocated Array objects are deleted.
  ///
  /// \param _name The name of the array
  /// \param _size The size of the array in bytes
  /// \param constantValuesBegin A pointer to the beginning of a block of
  //         memory that constains a ``ref<ConstantExpr>`` (i.e. concrete values
  //         for the //array). This should be NULL for symbolic arrays.
  /// for symbolic arrays.
  /// \param constantValuesEnd A pointer +1 pass the end of a block of memory
  ///        that contains a ``ref<ConstantExpr>``. This should be NULL for a
  ///        symbolic array.
  /// \param _domain The size of the domain (i.e. the bitvector used to index
  /// the array)
  /// \param _range The size of range (i.e. the bitvector that is indexed to)
  const Array *CreateArray(const std::string &_name, uint64_t _size,
                           const ref<ConstantExpr> *constantValuesBegin = 0,
                           const ref<ConstantExpr> *constantValuesEnd = 0,
                           Expr::Width _domain = Expr::Int32,
                           Expr::Width _range = Expr::Int8);

private:
  typedef std::unordered_set<const Array *, klee::ArrayHashFn,
                             klee::EquivArrayCmpFn>
      ArrayHashMap;
  ArrayHashMap cachedSymbolicArrays;
  typedef std::vector<const Array *> ArrayPtrVec;
  ArrayPtrVec concreteArrays;
};
}

#endif /* KLEE_ARRAYCACHE_H */