-
Notifications
You must be signed in to change notification settings - Fork 274
Add incremental SMT2 sort checked construction of bit vector predicate application and application of core theory functions #6256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomasspriggs
merged 10 commits into
diffblue:develop
from
thomasspriggs:tas/smt_function_factories
Aug 4, 2021
+891
−87
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6fcc368
Add sort casting
thomasspriggs f5d4d30
Add parameterised function application factory
thomasspriggs c44f4b0
Add bitvector theory predicates
thomasspriggs 9025514
Refactor `smt_not_term` into core theory
thomasspriggs 5b5aabc
Add `equal` to smt core theory
thomasspriggs 01f4b18
Make `smt_function_application_termt` constructor private
thomasspriggs aea57ed
Add SMT2 core theory "distinct"
thomasspriggs cf23d63
Add core theory "if then else" operation
thomasspriggs 2f09110
Add core theory "implies" operation
thomasspriggs 686ba37
Add SMT2 incremental core theory logical operators
thomasspriggs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Author: Diffblue Ltd. | ||
|
||
#include <solvers/smt2_incremental/smt_bit_vector_theory.h> | ||
|
||
#include <util/invariant.h> | ||
|
||
static void validate_bit_vector_predicate_arguments( | ||
const smt_termt &left, | ||
const smt_termt &right) | ||
{ | ||
const auto left_sort = left.get_sort().cast<smt_bit_vector_sortt>(); | ||
INVARIANT(left_sort, "Left operand must have bitvector sort."); | ||
const auto right_sort = right.get_sort().cast<smt_bit_vector_sortt>(); | ||
INVARIANT(right_sort, "Right operand must have bitvector sort."); | ||
// The below invariant is based on the smtlib standard. | ||
// See http://smtlib.cs.uiowa.edu/logics-all.shtml#QF_BV | ||
INVARIANT( | ||
left_sort->bit_width() == right_sort->bit_width(), | ||
"Left and right operands must have the same bit width."); | ||
} | ||
|
||
#define SMT_BITVECTOR_THEORY_PREDICATE(the_identifier, the_name) \ | ||
void smt_bit_vector_theoryt::the_name##t::validate( \ | ||
const smt_termt &left, const smt_termt &right) \ | ||
{ \ | ||
validate_bit_vector_predicate_arguments(left, right); \ | ||
} \ | ||
\ | ||
smt_sortt smt_bit_vector_theoryt::the_name##t::return_sort( \ | ||
const smt_termt &, const smt_termt &) \ | ||
{ \ | ||
return smt_bool_sortt{}; \ | ||
} \ | ||
\ | ||
const char *smt_bit_vector_theoryt::the_name##t::identifier() \ | ||
{ \ | ||
return #the_identifier; \ | ||
} \ | ||
\ | ||
const smt_function_application_termt::factoryt< \ | ||
smt_bit_vector_theoryt::the_name##t> \ | ||
smt_bit_vector_theoryt::the_name{}; | ||
#include "smt_bit_vector_theory.def" | ||
#undef SMT_BITVECTOR_THEORY_PREDICATE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// \file | ||
/// This set of definitions is used as part of the | ||
/// [X-macro](https://en.wikipedia.org/wiki/X_Macro) pattern. These define the | ||
/// set of bitvector theory functions which are implemented and it is used to | ||
/// automate repetitive parts of the implementation. | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvult, unsigned_less_than) | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvule, unsigned_less_than_or_equal) | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvugt, unsigned_greater_than) | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvuge, unsigned_greater_than_or_equal) | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvslt, signed_less_than) | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvsle, signed_less_than_or_equal) | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvsgt, signed_greater_than) | ||
SMT_BITVECTOR_THEORY_PREDICATE(bvsge, signed_greater_than_or_equal) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Author: Diffblue Ltd. | ||
|
||
#ifndef CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_BIT_VECTOR_THEORY_H | ||
#define CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_BIT_VECTOR_THEORY_H | ||
|
||
#include <solvers/smt2_incremental/smt_terms.h> | ||
|
||
class smt_bit_vector_theoryt | ||
{ | ||
public: | ||
#define SMT_BITVECTOR_THEORY_PREDICATE(the_identifier, the_name) \ | ||
/* NOLINTNEXTLINE(readability/identifiers) cpplint does not match the ## */ \ | ||
struct the_name##t final \ | ||
{ \ | ||
static const char *identifier(); \ | ||
static smt_sortt \ | ||
return_sort(const smt_termt &left, const smt_termt &right); \ | ||
static void validate(const smt_termt &left, const smt_termt &right); \ | ||
}; \ | ||
static const smt_function_application_termt::factoryt<the_name##t> the_name; | ||
#include "smt_bit_vector_theory.def" | ||
#undef SMT_BITVECTOR_THEORY_PREDICATE | ||
}; | ||
|
||
#endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_BIT_VECTOR_THEORY_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
// Author: Diffblue Ltd. | ||
|
||
#include <solvers/smt2_incremental/smt_core_theory.h> | ||
|
||
const char *smt_core_theoryt::nott::identifier() | ||
{ | ||
return "not"; | ||
} | ||
|
||
smt_sortt smt_core_theoryt::nott::return_sort(const smt_termt &operand) | ||
{ | ||
return smt_bool_sortt{}; | ||
} | ||
|
||
void smt_core_theoryt::nott::validate(const smt_termt &operand) | ||
{ | ||
INVARIANT( | ||
operand.get_sort() == smt_bool_sortt{}, | ||
"\"not\" may only be applied to terms which have bool sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::nott> | ||
smt_core_theoryt::make_not{}; | ||
|
||
const char *smt_core_theoryt::impliest::identifier() | ||
{ | ||
return "=>"; | ||
} | ||
|
||
smt_sortt | ||
smt_core_theoryt::impliest::return_sort(const smt_termt &, const smt_termt &) | ||
{ | ||
return smt_bool_sortt{}; | ||
} | ||
|
||
void smt_core_theoryt::impliest::validate( | ||
const smt_termt &lhs, | ||
const smt_termt &rhs) | ||
{ | ||
INVARIANT( | ||
lhs.get_sort() == smt_bool_sortt{}, | ||
"Left hand side of \"=>\" must have bool sort."); | ||
INVARIANT( | ||
rhs.get_sort() == smt_bool_sortt{}, | ||
"Right hand side of \"=>\" must have bool sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::impliest> | ||
smt_core_theoryt::implies{}; | ||
|
||
const char *smt_core_theoryt::andt::identifier() | ||
{ | ||
return "and"; | ||
} | ||
|
||
smt_sortt | ||
smt_core_theoryt::andt::return_sort(const smt_termt &, const smt_termt &) | ||
{ | ||
return smt_bool_sortt{}; | ||
} | ||
|
||
void smt_core_theoryt::andt::validate( | ||
const smt_termt &lhs, | ||
const smt_termt &rhs) | ||
{ | ||
INVARIANT( | ||
lhs.get_sort() == smt_bool_sortt{}, | ||
"Left hand side of \"and\" must have bool sort."); | ||
INVARIANT( | ||
rhs.get_sort() == smt_bool_sortt{}, | ||
"Right hand side of \"and\" must have bool sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::andt> | ||
smt_core_theoryt::make_and{}; | ||
|
||
const char *smt_core_theoryt::ort::identifier() | ||
{ | ||
return "or"; | ||
} | ||
|
||
smt_sortt | ||
smt_core_theoryt::ort::return_sort(const smt_termt &, const smt_termt &) | ||
{ | ||
return smt_bool_sortt{}; | ||
} | ||
|
||
void smt_core_theoryt::ort::validate(const smt_termt &lhs, const smt_termt &rhs) | ||
{ | ||
INVARIANT( | ||
lhs.get_sort() == smt_bool_sortt{}, | ||
"Left hand side of \"or\" must have bool sort."); | ||
INVARIANT( | ||
rhs.get_sort() == smt_bool_sortt{}, | ||
"Right hand side of \"or\" must have bool sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::ort> | ||
smt_core_theoryt::make_or{}; | ||
|
||
const char *smt_core_theoryt::xort::identifier() | ||
{ | ||
return "xor"; | ||
} | ||
|
||
smt_sortt | ||
smt_core_theoryt::xort::return_sort(const smt_termt &, const smt_termt &) | ||
{ | ||
return smt_bool_sortt{}; | ||
} | ||
|
||
void smt_core_theoryt::xort::validate( | ||
const smt_termt &lhs, | ||
const smt_termt &rhs) | ||
{ | ||
INVARIANT( | ||
lhs.get_sort() == smt_bool_sortt{}, | ||
"Left hand side of \"xor\" must have bool sort."); | ||
INVARIANT( | ||
rhs.get_sort() == smt_bool_sortt{}, | ||
"Right hand side of \"xor\" must have bool sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::xort> | ||
smt_core_theoryt::make_xor{}; | ||
|
||
const char *smt_core_theoryt::equalt::identifier() | ||
{ | ||
return "="; | ||
} | ||
|
||
smt_sortt | ||
smt_core_theoryt::equalt::return_sort(const smt_termt &, const smt_termt &) | ||
{ | ||
return smt_bool_sortt{}; | ||
} | ||
|
||
void smt_core_theoryt::equalt::validate( | ||
const smt_termt &lhs, | ||
const smt_termt &rhs) | ||
{ | ||
INVARIANT( | ||
lhs.get_sort() == rhs.get_sort(), | ||
"\"=\" may only be applied to terms which have the same sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::equalt> | ||
smt_core_theoryt::equal{}; | ||
|
||
const char *smt_core_theoryt::distinctt::identifier() | ||
{ | ||
return "distinct"; | ||
} | ||
|
||
smt_sortt | ||
smt_core_theoryt::distinctt::return_sort(const smt_termt &, const smt_termt &) | ||
{ | ||
return smt_bool_sortt{}; | ||
} | ||
|
||
void smt_core_theoryt::distinctt::validate( | ||
const smt_termt &lhs, | ||
const smt_termt &rhs) | ||
{ | ||
INVARIANT( | ||
lhs.get_sort() == rhs.get_sort(), | ||
"\"distinct\" may only be applied to terms which have the same sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::distinctt> | ||
smt_core_theoryt::distinct{}; | ||
|
||
const char *smt_core_theoryt::if_then_elset::identifier() | ||
{ | ||
return "ite"; | ||
} | ||
|
||
smt_sortt smt_core_theoryt::if_then_elset::return_sort( | ||
const smt_termt &, | ||
const smt_termt &then_term, | ||
const smt_termt &) | ||
{ | ||
return then_term.get_sort(); | ||
} | ||
|
||
void smt_core_theoryt::if_then_elset::validate( | ||
const smt_termt &condition, | ||
const smt_termt &then_term, | ||
const smt_termt &else_term) | ||
{ | ||
INVARIANT( | ||
condition.get_sort() == smt_bool_sortt{}, | ||
"Condition term must have bool sort."); | ||
INVARIANT( | ||
then_term.get_sort() == else_term.get_sort(), | ||
"\"ite\" must have \"then\" and \"else\" terms of the same sort."); | ||
} | ||
|
||
const smt_function_application_termt::factoryt<smt_core_theoryt::if_then_elset> | ||
smt_core_theoryt::if_then_else; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.