Skip to content

Commit 547bd40

Browse files
committed
[fear] Add PersistentHashMap
[feat] Use 'immer' data structures [feat] Add `UseImmerStructures` [feat] Add `FixedSizeStorageAdapter`
1 parent b3b2bef commit 547bd40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1838
-499
lines changed

.cirrus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ task:
66
deps_script:
77
- sed -i.bak -e 's/quarterly/latest/' /etc/pkg/FreeBSD.conf
88
- env ASSUME_ALWAYS_YES=yes pkg update -f
9-
- env ASSUME_ALWAYS_YES=yes pkg install -y llvm11 gmake z3 cmake pkgconf google-perftools python3 py39-sqlite3 py39-tabulate nlohmann-json bash coreutils
9+
- env ASSUME_ALWAYS_YES=yes pkg install -y llvm11 gmake z3 cmake pkgconf google-perftools python3 py39-sqlite3 py39-tabulate nlohmann-json bash coreutils immer
1010
build_script:
1111
- mkdir build
1212
- cd build
13-
- cmake -DLLVM_DIR=/usr/local/llvm11 -DMAKE_BINARY=/usr/local/bin/gmake -DJSON_SRC_DIR=/usr/local -DENABLE_TCMALLOC:BOOL=true -DENABLE_POSIX_RUNTIME:BOOL=ON -DENABLE_SOLVER_Z3:BOOL=true -DENABLE_SYSTEM_TESTS:BOOL=ON ..
13+
- cmake -DLLVM_DIR=/usr/local/llvm11 -DMAKE_BINARY=/usr/local/bin/gmake -DJSON_SRC_DIR=/usr/local -DIMMER_SRC_DIR=/usr/local -DENABLE_TCMALLOC:BOOL=true -DENABLE_POSIX_RUNTIME:BOOL=ON -DENABLE_SOLVER_Z3:BOOL=true -DENABLE_SYSTEM_TESTS:BOOL=ON ..
1414
- gmake
1515
test_script:
1616
- sed -i.bak -e 's/lit\./lit11\./' test/lit.cfg

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ env:
3232
SQLITE_VERSION: 3400100
3333
BITWUZLA_VERSION: 0.3.1
3434
JSON_VERSION: v3.11.3
35+
IMMER_VERSION: v0.8.1
3536

3637
jobs:
3738
Linux:

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ configure_file(${CMAKE_SOURCE_DIR}/include/klee/Config/CompileTimeInfo.h.cmin
681681
include_directories("${CMAKE_BINARY_DIR}/include")
682682
include_directories("${CMAKE_SOURCE_DIR}/include")
683683
include_directories("${JSON_SRC_DIR}/include")
684+
include_directories("${IMMER_SRC_DIR}")
684685
# set(KLEE_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include)
685686

686687
################################################################################

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ENV USE_LIBCXX=1
3636
ENV KLEE_RUNTIME_BUILD="Debug+Asserts"
3737
ENV SQLITE_VERSION=3400100
3838
ENV JSON_VERSION=v3.11.3
39+
ENV IMMER_VERSION=v0.8.1
3940
LABEL maintainer="KLEE Developers"
4041

4142
# TODO remove adding sudo package

build.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Base folder where dependencies and KLEE itself are installed
77
BASE=$HOME/klee_build
8-
BUILD_SUFFIX="Release"
8+
BUILD_SUFFIX="Debug"
99

1010
## KLEE Required options
1111
# Build type for KLEE. The options are:
@@ -26,7 +26,6 @@ USE_LIBCXX=1
2626
# Also required despite not being mentioned in the guide
2727
SQLITE_VERSION="3400100"
2828

29-
3029
## LLVM Required options
3130
LLVM_VERSION=14
3231
ENABLE_OPTIMIZED=1
@@ -44,6 +43,9 @@ GTEST_VERSION=1.11.0
4443
## json options
4544
JSON_VERSION=v3.11.3
4645

46+
## immer options
47+
IMMER_VERSION=v0.8.1
48+
4749
## UClibC Required options
4850
UCLIBC_VERSION=klee_uclibc_v1.3
4951
# LLVM_VERSION is also required for UClibC
@@ -56,4 +58,4 @@ MINISAT_VERSION=master
5658

5759
BITWUZLA_VERSION=0.3.1
5860

59-
BASE="$BASE" BUILD_SUFFIX="$BUILD_SUFFIX" KLEE_RUNTIME_BUILD=$KLEE_RUNTIME_BUILD COVERAGE=$COVERAGE ENABLE_DOXYGEN=$ENABLE_DOXYGEN USE_TCMALLOC=$USE_TCMALLOC USE_LIBCXX=$USE_LIBCXX LLVM_VERSION=$LLVM_VERSION ENABLE_OPTIMIZED=$ENABLE_OPTIMIZED ENABLE_DEBUG=$ENABLE_DEBUG DISABLE_ASSERTIONS=$DISABLE_ASSERTIONS REQUIRES_RTTI=$REQUIRES_RTTI SOLVERS=$SOLVERS GTEST_VERSION=$GTEST_VERSION UCLIBC_VERSION=$UCLIBC_VERSION STP_VERSION=$STP_VERSION MINISAT_VERSION=$MINISAT_VERSION Z3_VERSION=$Z3_VERSION BITWUZLA_VERSION=$BITWUZLA_VERSION SQLITE_VERSION=$SQLITE_VERSION JSON_VERSION=$JSON_VERSION ./scripts/build/build.sh klee --install-system-deps
61+
BASE="$BASE" BUILD_SUFFIX="$BUILD_SUFFIX" KLEE_RUNTIME_BUILD=$KLEE_RUNTIME_BUILD COVERAGE=$COVERAGE ENABLE_DOXYGEN=$ENABLE_DOXYGEN USE_TCMALLOC=$USE_TCMALLOC USE_LIBCXX=$USE_LIBCXX LLVM_VERSION=$LLVM_VERSION ENABLE_OPTIMIZED=$ENABLE_OPTIMIZED ENABLE_DEBUG=$ENABLE_DEBUG DISABLE_ASSERTIONS=$DISABLE_ASSERTIONS REQUIRES_RTTI=$REQUIRES_RTTI SOLVERS=$SOLVERS GTEST_VERSION=$GTEST_VERSION UCLIBC_VERSION=$UCLIBC_VERSION STP_VERSION=$STP_VERSION MINISAT_VERSION=$MINISAT_VERSION Z3_VERSION=$Z3_VERSION BITWUZLA_VERSION=$BITWUZLA_VERSION SQLITE_VERSION=$SQLITE_VERSION JSON_VERSION=$JSON_VERSION IMMER_VERSION=$IMMER_VERSION ./scripts/build/build.sh klee --install-system-deps

include/klee/ADT/PersistentHashMap.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//===-- PersistentHashMap.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_PRESISTENTHASHMAP_H
11+
#define KLEE_PRESISTENTHASHMAP_H
12+
13+
#ifndef IMMER_NO_EXCEPTIONS
14+
#define IMMER_NO_EXCEPTIONS
15+
#endif /* IMMER_NO_EXCEPTIONS */
16+
17+
#include <immer/map.hpp>
18+
19+
namespace klee {
20+
21+
template <class K, class D, class HASH = std::hash<K>,
22+
class EQUAL = std::equal_to<K>>
23+
class PersistentHashMap {
24+
public:
25+
typedef immer::map<K, D, HASH, EQUAL> Map;
26+
typedef typename Map::iterator iterator;
27+
typedef K key_type;
28+
typedef std::pair<K, D> value_type;
29+
30+
private:
31+
Map elts;
32+
33+
PersistentHashMap(const Map &b) : elts(b) {}
34+
35+
public:
36+
PersistentHashMap() {}
37+
PersistentHashMap(const PersistentHashMap &b) : elts(b.elts) {}
38+
~PersistentHashMap() {}
39+
40+
PersistentHashMap &operator=(const PersistentHashMap &b) {
41+
elts = b.elts;
42+
return *this;
43+
}
44+
bool operator==(const PersistentHashMap &b) const { return elts == b.elts; }
45+
bool operator<(const PersistentHashMap &b) const { return elts < b.elts; }
46+
47+
bool empty() const { return elts.empty(); }
48+
size_t count(const key_type &key) const { return elts.count(key); }
49+
const D *lookup(const key_type &key) const { return elts.find(key); }
50+
size_t size() const { return elts.size(); }
51+
52+
void insert(const value_type &value) {
53+
if (!lookup(value.first)) {
54+
elts = elts.insert(value);
55+
}
56+
}
57+
void replace(const value_type &value) { elts = elts.insert(value); }
58+
void remove(const key_type &key) { elts = elts.erase(key); }
59+
60+
iterator begin() const { return elts.begin(); }
61+
iterator end() const { return elts.end(); }
62+
63+
const D &operator[](const key_type &key) {
64+
return elts[key];
65+
// auto value = lookup(key);
66+
// if (value) {
67+
// return *value;
68+
// } else {
69+
// value_type defVal;
70+
// defVal.first = key;
71+
// insert(defVal);
72+
// return *lookup(key);
73+
// }
74+
}
75+
76+
const D &at(const key_type &key) const { return elts.at(key); }
77+
78+
void clear() { elts = Map(); }
79+
};
80+
} // namespace klee
81+
82+
#endif /* KLEE_PRESISTENTHASHMAP_H */

include/klee/ADT/PersistentVector.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===-- PersistentVector.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_PRESISTENTVECTOR_H
11+
#define KLEE_PRESISTENTVECTOR_H
12+
13+
#ifndef IMMER_NO_EXCEPTIONS
14+
#define IMMER_NO_EXCEPTIONS
15+
#endif /* IMMER_NO_EXCEPTIONS */
16+
17+
#include <immer/vector.hpp>
18+
19+
namespace klee {
20+
21+
template <class T> class PersistentVector {
22+
public:
23+
using Vector = immer::vector<T>;
24+
using iterator = typename Vector::iterator;
25+
using value_type = T;
26+
27+
private:
28+
Vector elts;
29+
30+
PersistentVector(const Vector &b) : elts(b) {}
31+
32+
public:
33+
PersistentVector() {}
34+
PersistentVector(const PersistentVector &b) : elts(b.elts) {}
35+
~PersistentVector() {}
36+
37+
PersistentVector &operator=(const PersistentVector &b) {
38+
elts = b.elts;
39+
return *this;
40+
}
41+
42+
bool operator==(const PersistentVector &b) const { return elts == b.elts; }
43+
bool operator!=(const PersistentVector &other) const {
44+
return !(*this == other);
45+
}
46+
bool empty() const { return elts.empty(); }
47+
size_t size() const { return elts.size(); }
48+
49+
void set(size_t index, const value_type &value) {
50+
elts = elts.set(index, value);
51+
}
52+
void init(const size_t &n) { elts = Vector(n); }
53+
void push_back(const value_type &value) { elts = elts.push_back(value); }
54+
const value_type &back() const { return elts.back(); }
55+
const value_type &front() const { return elts.front(); }
56+
const value_type &operator[](const size_t &index) const {
57+
return elts[index];
58+
}
59+
const value_type &at(const size_t &index) const { return elts[index]; }
60+
61+
iterator begin() const { return elts.begin(); }
62+
iterator end() const { return elts.end(); }
63+
};
64+
} // namespace klee
65+
66+
#endif /* KLEE_PRESISTENTVECTOR_H */

0 commit comments

Comments
 (0)