Skip to content

Commit b6ca874

Browse files
author
Arie Gurfinkel
committed
bitblasting example
1 parent bbdf71e commit b6ca874

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

examples/python/bitblast.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys
2+
import z3
3+
4+
def bitblast (e):
5+
ctx = e.ctx
6+
goal = z3.Goal (ctx=ctx)
7+
goal.add (z3.simplify (e))
8+
tactic = z3.Tactic ('bit-blast', ctx=ctx)
9+
res = tactic.apply (goal, blast_full=True)
10+
assert (len (res) == 1)
11+
return res [0].as_expr ()
12+
13+
def parseArgs (argv):
14+
import argparse as a
15+
p = a.ArgumentParser (description = 'bitblaster')
16+
p.add_argument ('file', metavar='FILE', type=str,
17+
help = 'Input file')
18+
p.add_argument ('--no-blast', help='Disable bit blasting',
19+
action='store_true', default=False)
20+
p.add_argument ('--check-sat', help='Run solver',
21+
action='store_true', default=False)
22+
p.add_argument ('-o', metavar='FILE', type=str,
23+
help='File to store the formula', default=None)
24+
args = p.parse_args (argv)
25+
return args
26+
27+
def main (argv):
28+
print 'In main'
29+
args = parseArgs (argv[1:])
30+
31+
ctx = z3.Context ()
32+
fmla = z3.parse_smt2_file (args.file, ctx=ctx)
33+
34+
msg = 'Solving'
35+
if not args.no_blast:
36+
msg = msg + ' (blasted)'
37+
blasted = bitblast (fmla)
38+
else:
39+
blasted = fmla
40+
msg = msg + " ..."
41+
42+
if args.o <> None:
43+
with open (args.o, 'w') as f:
44+
f.write (blasted.sexpr ())
45+
46+
47+
print msg
48+
solver = z3.Solver (ctx=ctx)
49+
solver.add (blasted)
50+
res = solver.check ()
51+
print res
52+
return 0
53+
if __name__ == '__main__':
54+
sys.exit (main (sys.argv))

0 commit comments

Comments
 (0)