Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
helgikrs committed Dec 1, 2017
1 parent 4eadec4 commit 4ec15aa
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions irpy/libirpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import itypes


if False:
# A hook swhich spawns an ipdb debugger if an uncaught exception is thrown
from IPython.core import ultratb
Expand Down Expand Up @@ -79,12 +80,21 @@ def _solver_copy(self, memo=None):
s.add(z3.parse_smt2_string(self.to_smt2()))
return s


# In case of emergencies
# setattr(z3.Solver, '__copy__', _solver_copy)
# setattr(z3.Solver, '__deepcopy__', _solver_copy)
# Should probably not be used
def enable_solver_copy():
setattr(z3.Solver, '__copy__', _solver_copy)
setattr(z3.Solver, '__deepcopy__', _solver_copy)


def equal(a, b):
def definitely_equal(a, b):
"""
A conservative equals function. Must return a Python boolean.
Returns True only if we can definitely determine that a and b are equal.
A value of False only means they are potentially not equal.
"""
if type(a) != type(b):
return False
container_types = [dict, list, tuple]
Expand All @@ -100,13 +110,15 @@ def equal(a, b):


def is_true(cond):
"""Same as z3.is_true but supports python booleans"""
if hasattr(cond, 'sexpr'):
return z3.is_true(simplify(cond))
assert isinstance(cond, bool)
return cond


def is_false(cond):
"""Same as z3.is_false but supports python booleans"""
if hasattr(cond, 'sexpr'):
return z3.is_false(simplify(cond))
assert isinstance(cond, bool)
Expand Down Expand Up @@ -150,7 +162,7 @@ def If(cond, a, b):
assert a.size() == b.size(
), "Can not ite types of different size {} v. {}".format(a.size(), b.size())

if equal(a, b):
if definitely_equal(a, b):
return a

if hasattr(a, 'ite'):
Expand Down Expand Up @@ -468,8 +480,8 @@ def _coerce_exprs(a, b, ctx=None):
b = s.cast(b)
return (a, b)

# From https://stackoverflow.com/questions/22568867/z3-bitvector-overflow-checking-from-python

# From https://stackoverflow.com/questions/22568867/z3-bitvector-overflow-checking-from-python
def bvadd_no_overflow(a, b, signed):
if a.size() != b.size():
raise Exception(
Expand Down

0 comments on commit 4ec15aa

Please sign in to comment.