Skip to content

Commit bfb2379

Browse files
Add BTOR2 Frontend (#74)
* Adding btor2 parser with antlr, not complete * Adding support for btor2 parser using btor2tools * Adding cmake file and updating README to explain btor2 frontend * Fixing include for btor2parser * Fixing cmake settings * Adding btor2 parsing tests and fixing bug * Disabling array types in btor2 for now * Correctly implementing invariants in transition systems * Implementing way to add invar via context * Fixing issue with multi-root btor files * Adding btor multi-root test --------- Co-authored-by: Ahmed Irfan <43099566+ahmed-irfan@users.noreply.github.com>
1 parent b35b5d9 commit bfb2379

Some content is hidden

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

43 files changed

+5457
-40
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ if (OPENSMT2_FOUND)
109109
include_directories(${OPENSMT2_INCLUDE_DIR})
110110
endif()
111111

112+
# Find Btor2Tools
113+
SET(BTOR2TOOLS_HOME CACHE STRING "Btor2Tools installation directory")
114+
find_package(Btor2Tools)
115+
if (BTOR2TOOLS_FOUND)
116+
add_definitions(-DWITH_BTOR2TOOLS)
117+
include_directories(${BTOR2TOOLS_INCLUDE_DIRS})
118+
set(CMAKE_INSTALL_RPATH "${BTOR2TOOLS_LIBRARY_DIR}")
119+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
120+
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
121+
set(CMAKE_INSTALL_RPATH "${BTOR2TOOLS_HOME}/build/lib")
122+
endif()
123+
112124
# Make sure antlr C runtime is here
113125
include(ExternalProject)
114126
ExternalProject_Add(

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ make check
6060
```
6161
You can also set YICES2_HOME, OPENSMT2_HOME, or DREAL_HOME.
6262

63+
To compile with the Btor2 frontend, ensure that you have btor2tools installed
64+
(using ``contrib/install_btor2tools.sh``).
65+
Then provide the BTOR2TOOLS_HOME directory to ``cmake`` and build with
66+
```bash
67+
cd build
68+
cmake .. -DBTOR2TOOLS_HOME=path/to/contrib/btor2tools
69+
make
70+
make check
71+
```
6372

6473
To compile Sally in debug mode, build with
6574
```bash

cmake/FindBtor2Tools.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# - Try to find Btor2Tools
2+
# Once done this will define
3+
# BTOR2TOOLS_FOUND - System has Btor2Tools
4+
# BTOR2TOOLS_INCLUDE_DIRS - The Btor2Tools include directories
5+
# BTOR2TOOLS_LIBRARIES - The libraries needed to use Btor2Tools
6+
7+
if (BTOR2TOOLS_HOME)
8+
find_path(BTOR2TOOLS_INCLUDE_DIR btor2parser/btor2parser.h PATHS "${BTOR2TOOLS_HOME}/src" NO_DEFAULT_PATH)
9+
else()
10+
find_path(BTOR2TOOLS_INCLUDE_DIR btor2parser/btor2parser.h)
11+
endif()
12+
13+
if (SALLY_STATIC_BUILD)
14+
if (BTOR2TOOLS_HOME)
15+
find_library(BTOR2TOOLS_LIBRARY libbtor2parser.a btor2parser PATHS "${BTOR2TOOLS_HOME}/build/lib" NO_DEFAULT_PATH)
16+
else()
17+
find_library(BTOR2TOOLS_LIBRARY libbtor2parser.a btor2parser)
18+
endif()
19+
else()
20+
if (BTOR2TOOLS_HOME)
21+
find_library(BTOR2TOOLS_LIBRARY btor2parser PATHS "${BTOR2TOOLS_HOME}/build/lib" NO_DEFAULT_PATH)
22+
else()
23+
find_library(BTOR2TOOLS_LIBRARY btor2parser)
24+
endif()
25+
endif()
26+
27+
set(BTOR2TOOLS_LIBRARIES ${BTOR2TOOLS_LIBRARY})
28+
set(BTOR2TOOLS_INCLUDE_DIRS ${BTOR2TOOLS_INCLUDE_DIR})
29+
30+
include(FindPackageHandleStandardArgs)
31+
find_package_handle_standard_args(Btor2Tools DEFAULT_MSG BTOR2TOOLS_LIBRARY BTOR2TOOLS_INCLUDE_DIR)
32+
33+
mark_as_advanced(BTOR2TOOLS_INCLUDE_DIR BTOR2TOOLS_LIBRARY)

contrib/install_btor2tools.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Installing btor2tools..."
5+
6+
# Clone the repository
7+
if ! git clone https://github.com/hwmcc/btor2tools.git; then
8+
echo "Error: Failed to clone btor2tools repository." >&2
9+
exit 1
10+
fi
11+
12+
# Navigate to btor2tools directory
13+
if ! pushd btor2tools; then
14+
echo "Error: Failed to enter btor2tools directory." >&2
15+
exit 1
16+
fi
17+
18+
# Run configure script
19+
if ! ./configure.sh; then
20+
echo "Error: Configuration failed." >&2
21+
popd > /dev/null 2>&1
22+
exit 1
23+
fi
24+
25+
# Enter build directory
26+
if ! pushd build; then
27+
echo "Error: Failed to enter build directory." >&2
28+
popd
29+
exit 1
30+
fi
31+
32+
# Run make
33+
if ! make; then
34+
echo "Error: Build failed." >&2
35+
popd; popd
36+
exit 1
37+
fi
38+
39+
# Return to original directories
40+
popd
41+
popd
42+
43+
echo "btor2tools installation completed successfully!"

src/CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,31 @@ endif()
4747
if (DREAL_FOUND)
4848
target_link_libraries(sally ${DREAL_LIBRARIES})
4949
endif()
50+
if (BTOR2TOOLS_FOUND)
51+
target_link_libraries(sally -lbtor2parser)
52+
endif()
5053

5154
target_link_libraries(sally ${Boost_LIBRARIES} ${GMP_LIBRARY})
5255

5356
# Add tests
5457

55-
file(GLOB_RECURSE regressions
56-
${sally_SOURCE_DIR}/test/regress/*.mcmt
57-
${sally_SOURCE_DIR}/test/regress/*.btor
58-
${sally_SOURCE_DIR}/test/regress/*.sal
58+
# Build the list of regression files based on available solvers
59+
set(regression_patterns
60+
${sally_SOURCE_DIR}/test/regress/**/*.mcmt
61+
${sally_SOURCE_DIR}/test/regress/**/*.btor
62+
${sally_SOURCE_DIR}/test/regress/**/*.sal
5963
)
64+
65+
# Add btor2 files only if Btor2Tools is found
66+
if (BTOR2TOOLS_FOUND)
67+
list(APPEND regression_patterns ${sally_SOURCE_DIR}/test/regress/**/*.btor2)
68+
endif()
69+
70+
# Get all the regression files
71+
file(GLOB_RECURSE regressions ${regression_patterns})
6072
list(SORT regressions)
6173

74+
6275
foreach(FILE ${regressions})
6376
# Get the options for this test
6477
file(READ "${FILE}.options" ALL_OPTIONS)

src/expr/bitvector.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,28 @@ size_t bitvector::hash() const {
7272
return hasher.get();
7373
}
7474

75-
bitvector::bitvector(const char* bits)
76-
: integer(bits, 2)
77-
, d_size(strlen(bits))
75+
bitvector::bitvector(const char* bits, size_t base, size_t size)
76+
: integer(bits, base)
7877
{
79-
assert(d_size > 0);
78+
if (size == 0) {
79+
d_size = strlen(bits);
80+
} else {
81+
d_size = size;
82+
}
8083
assert(sgn() >= 0);
8184
if (mpz_sizeinbase(d_gmp_int.get_mpz_t(), 2) > d_size) {
8285
mpz_fdiv_r_2exp(d_gmp_int.get_mpz_t(), d_gmp_int.get_mpz_t(), d_size);
8386
}
8487
}
8588

86-
bitvector::bitvector(std::string bits)
87-
: integer(bits, 2)
88-
, d_size(bits.size())
89+
bitvector::bitvector(std::string bits, size_t base, size_t size)
90+
: integer(bits, base)
8991
{
90-
assert(d_size > 0);
92+
if (size == 0) {
93+
d_size = bits.size();
94+
} else {
95+
d_size = size;
96+
}
9197
assert(sgn() >= 0);
9298
if (mpz_sizeinbase(d_gmp_int.get_mpz_t(), 2) > d_size) {
9399
mpz_fdiv_r_2exp(d_gmp_int.get_mpz_t(), d_gmp_int.get_mpz_t(), d_size);

src/expr/bitvector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class bitvector : protected integer {
4747
/** Construct from int */
4848
bitvector(size_t size, long x);
4949

50-
/** Construct from a string representation (0 terminated) */
51-
explicit bitvector(const char* bits);
50+
/** Construct from a string representation ('\0' terminated) */
51+
explicit bitvector(const char* bits, size_t base = 2, size_t size = 0);
5252

5353
/** Construct from a string representation */
54-
explicit bitvector(std::string bits);
54+
explicit bitvector(std::string bits, size_t base = 2, size_t size = 0);
5555

5656
/** Get the size of the bitvector */
5757
size_t size() const { return d_size; }

src/expr/term.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void term::mk_let_cache(term_manager& tm, expr_let_cache& let_cache, std::vector
140140
}
141141
break;
142142
default:
143-
assert(false);
143+
throw exception("Unsupported let caching for operator: " + std::to_string(d_op));
144144
}
145145

146146
// Record the mapping
@@ -282,7 +282,10 @@ std::string get_smt_keyword(term_op op) {
282282
return "bvsrem";
283283
case TERM_BV_SMOD:
284284
return "bvsmod";
285-
285+
case TERM_BV_ROR:
286+
return "bvror";
287+
case TERM_BV_ROL:
288+
return "bvrol";
286289
case TERM_ARRAY_READ:
287290
return "select";
288291
case TERM_ARRAY_WRITE:
@@ -660,7 +663,7 @@ void term::to_stream_smt_without_let(std::ostream& out, term_manager& tm, const
660663
break;
661664
}
662665
default:
663-
assert(false);
666+
throw exception("Unsupported term operation: " + std::to_string(d_op));
664667
}
665668
}
666669

@@ -695,7 +698,7 @@ std::string get_nuxmv_operator(expr::term_op op) {
695698
case TERM_BV_UDIV: return "/";
696699
case TERM_BV_UREM: return "mod";
697700
default:
698-
assert(false);
701+
throw exception("Unsupported term operation: " + std::to_string(op));
699702
}
700703
return "unknown";
701704
}

src/expr/term_manager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,10 @@ term_ref term_manager::mk_or(const std::vector<term_ref>& disjuncts) {
874874

875875
bool term_manager::is_type(term_ref t) const {
876876
return d_tm->is_type(t);
877+
}
878+
879+
bool term_manager::is_boolean_type(term_ref t) const {
880+
return d_tm->is_boolean_type(t);
877881
}
878882

879883
bool term_manager::is_function_type(term_ref t) const {

src/expr/term_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ class term_manager {
438438
/** Check if t is a type */
439439
bool is_type(term_ref t) const;
440440

441+
/** Check if t is a boolean type */
442+
bool is_boolean_type(term_ref t) const;
443+
441444
/** Check if t is a function type */
442445
bool is_function_type(term_ref t) const;
443446

0 commit comments

Comments
 (0)