-
Notifications
You must be signed in to change notification settings - Fork 273
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
An SMT2 frontend plus solver binary #1879
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7b670cd
fix line number counting in SMT2 tokenizer
37f69b2
added to_mathematical_function_type
6dde6b1
add support for let_exprt
5268c44
a translator from SMT2 into expressions
a75ee3f
Add missing langapi dependency to util
peterschrammel 246472f
an SMT2 solver using boolbv and satcheckt
ab68848
tests for smt2_solver
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 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 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 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,18 @@ | ||
default: tests.log | ||
|
||
test: | ||
@../test.pl -p -c ../../../src/solvers/smt2_solver | ||
|
||
tests.log: ../test.pl | ||
@../test.pl -p -c ../../../src/solvers/smt2_solver | ||
|
||
show: | ||
@for dir in *; do \ | ||
if [ -d "$$dir" ]; then \ | ||
vim -o "$$dir/*.c" "$$dir/*.out"; \ | ||
fi; \ | ||
done; | ||
|
||
clean: | ||
find -name '*.out' -execdir $(RM) '{}' \; | ||
$(RM) tests.log |
This file contains 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,64 @@ | ||
(set-logic QF_BV) | ||
|
||
; From https://rise4fun.com/z3/tutorialcontent/guide | ||
|
||
; Basic Bitvector Arithmetic | ||
(define-fun b01 () Bool (= (bvadd #x07 #x03) #x0a)) ; addition | ||
(define-fun b02 () Bool (= (bvsub #x07 #x03) #x04)) ; subtraction | ||
(define-fun b03 () Bool (= (bvneg #x07) #xf9)) ; unary minus | ||
(define-fun b04 () Bool (= (bvmul #x07 #x03) #x15)) ; multiplication | ||
(define-fun b05 () Bool (= (bvurem #x07 #x03) #x01)) ; unsigned remainder | ||
(define-fun b06 () Bool (= (bvsrem #x07 #x03) #x01)) ; signed remainder | ||
(define-fun b07 () Bool (= (bvsmod #x07 #x03) #x01)) ; signed modulo | ||
(define-fun b08 () Bool (= (bvshl #x07 #x03) #x38)) ; shift left | ||
(define-fun b09 () Bool (= (bvlshr #xf0 #x03) #x1e)) ; unsigned (logical) shift right | ||
(define-fun b10 () Bool (= (bvashr #xf0 #x03) #xfe)) ; signed (arithmetical) shift right#x0a | ||
|
||
; Bitwise Operations | ||
|
||
(define-fun w1 () Bool (= (bvor #x6 #x3) #x7)) ; bitwise or | ||
(define-fun w2 () Bool (= (bvand #x6 #x3) #x2)) ; bitwise and | ||
(define-fun w3 () Bool (= (bvnot #x6) #x9)) ; bitwise not | ||
(define-fun w4 () Bool (= (bvnand #x6 #x3) #xd)) ; bitwise nand | ||
(define-fun w5 () Bool (= (bvnor #x6 #x3) #x8)) ; bitwise nor | ||
(define-fun w6 () Bool (= (bvxnor #x6 #x3) #xa)) ; bitwise xnor | ||
|
||
; We can prove a bitwise version of deMorgan's law | ||
|
||
(declare-const x (_ BitVec 64)) | ||
(declare-const y (_ BitVec 64)) | ||
(define-fun d01 () Bool (= (bvand (bvnot x) (bvnot y)) (bvnot (bvor x y)))) | ||
|
||
; There is a fast way to check that fixed size numbers are powers of two | ||
|
||
(define-fun is-power-of-two ((x (_ BitVec 4))) Bool | ||
(= #x0 (bvand x (bvsub x #x1)))) | ||
(declare-const a (_ BitVec 4)) | ||
(define-fun power-test () Bool | ||
(= (is-power-of-two a) | ||
(or (= a #x0) | ||
(= a #x1) | ||
(= a #x2) | ||
(= a #x4) | ||
(= a #x8)))) | ||
|
||
; Predicates over Bitvectors | ||
|
||
(define-fun p1 () Bool (= (bvule #x0a #xf0) true)) ; unsigned less or equal | ||
(define-fun p2 () Bool (= (bvult #x0a #xf0) true)) ; unsigned less than | ||
(define-fun p3 () Bool (= (bvuge #x0a #xf0) false)) ; unsigned greater or equal | ||
(define-fun p4 () Bool (= (bvugt #x0a #xf0) false)) ; unsigned greater than | ||
(define-fun p5 () Bool (= (bvsle #x0a #xf0) false)) ; signed less or equal | ||
(define-fun p6 () Bool (= (bvslt #x0a #xf0) false)) ; signed less than | ||
(define-fun p7 () Bool (= (bvsge #x0a #xf0) true)) ; signed greater or equal | ||
(define-fun p8 () Bool (= (bvsgt #x0a #xf0) true)) ; signed greater than | ||
|
||
; all must be true | ||
|
||
(assert (not (and | ||
b01 b02 b03 b04 b05 b06 b07 b08 b09 b10 | ||
d01 | ||
power-test | ||
p1 p2 p3 p4 p5 p6 p7 p8))) | ||
|
||
(check-sat) |
This file contains 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,7 @@ | ||
CORE | ||
basic-bv1.smt2 | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^unsat$ | ||
-- |
This file contains 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,32 @@ | ||
(set-logic QF_BV) | ||
|
||
; try 'let' on bitvectors | ||
|
||
(define-fun x () (_ BitVec 4) #x0) | ||
|
||
; very simple | ||
(define-fun let0 () Bool (= (let ((x #x0)) #x1) #x1)) | ||
|
||
; let hides the function 'x' | ||
(define-fun let1 () Bool (= (let ((x #x1)) x) #x1)) | ||
|
||
; the binding isn't visible immediately | ||
(define-fun let2 () Bool (= (let ((x x)) x) #x0)) | ||
|
||
; parallel let | ||
(define-fun let3 () Bool (= (let ((x #x1) (y x)) y) #x0)) | ||
|
||
; limited scope | ||
(define-fun let4 () Bool (and (= (let ((x #x1)) x) #x1) (= x #x0))) | ||
|
||
; all must be true | ||
|
||
(assert (not (and | ||
let0 | ||
let1 | ||
let2 | ||
let3 | ||
let4 | ||
))) | ||
|
||
(check-sat) |
This file contains 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,7 @@ | ||
CORE | ||
let-with-bv1.smt2 | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^unsat$ | ||
-- |
This file contains 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,30 @@ | ||
(set-logic QF_BV) | ||
|
||
(define-fun x () Bool false) | ||
|
||
; very simple | ||
(define-fun let0 () Bool (let ((x false)) true)) | ||
|
||
; let hides the function 'x' | ||
(define-fun let1 () Bool (let ((x true)) x)) | ||
|
||
; the binding isn't visible immediately | ||
(define-fun let2 () Bool (not (let ((x x)) x))) | ||
|
||
; parallel let | ||
(define-fun let3 () Bool (let ((x true) (y x)) (not y))) | ||
|
||
; limited scope | ||
(define-fun let4 () Bool (and (let ((x true)) x) (not x))) | ||
|
||
; all must be true | ||
|
||
(assert (not (and | ||
let0 | ||
let1 | ||
let2 | ||
let3 | ||
let4 | ||
))) | ||
|
||
(check-sat) |
This file contains 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,7 @@ | ||
CORE | ||
let1.smt2 | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^unsat$ | ||
-- |
This file contains 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 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 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 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 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 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 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,32 @@ | ||
/*******************************************************************\ | ||
|
||
Module: | ||
|
||
Author: Daniel Kroening, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#include "boolbv.h" | ||
|
||
#include <util/std_expr.h> | ||
#include <util/std_types.h> | ||
|
||
bvt boolbvt::convert_let(const let_exprt &expr) | ||
{ | ||
const bvt value_bv=convert_bv(expr.value()); | ||
|
||
// We expect the identifiers of the bound symbols to be unique, | ||
// and thus, these can go straight into the symbol to literal map. | ||
// This property also allows us to cache any subexpressions. | ||
const irep_idt &id=expr.symbol().get_identifier(); | ||
|
||
// the symbol shall be visible during the recursive call | ||
// to convert_bv | ||
map.set_literals(id, expr.symbol().type(), value_bv); | ||
bvt result_bv=convert_bv(expr.where()); | ||
|
||
// now remove, no longer needed | ||
map.erase_literals(id, expr.symbol().type()); | ||
|
||
return result_bv; | ||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though a later commit disables this: the .exe variant should be added now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done