Exemplo n.º 1
0
 def FPV(self, ast):  #pylint:disable=unused-argument
     val = str(ast.args[0])
     sort = self._convert(ast.args[1])
     if val == 'inf':
         return z3.fpPlusInfinity(sort)
     elif val == '-inf':
         return z3.fpMinusInfinity(sort)
     elif val == '0.0':
         return z3.fpPlusZero(sort)
     elif val == '-0.0':
         return z3.fpMinusZero(sort)
     elif val == 'nan':
         return z3.fpNaN(sort)
     else:
         better_val = str(Decimal(ast.args[0]))
         return z3.FPVal(better_val, sort, ctx=self._context)
Exemplo n.º 2
0
 def FPV(self, ast, result=None): #pylint:disable=unused-argument
     val = str(ast.args[0])
     sort = self._convert(ast.args[1])
     if val == 'inf':
         return z3.fpPlusInfinity(sort)
     elif val == '-inf':
         return z3.fpMinusInfinity(sort)
     elif val == '0.0':
         return z3.fpPlusZero(sort)
     elif val == '-0.0':
         return z3.fpMinusZero(sort)
     elif val == 'nan':
         return z3.fpNaN(sort)
     else:
         better_val = str(Decimal(ast.args[0]))
         return z3.FPVal(better_val, sort, ctx=self._context)
Exemplo n.º 3
0
 def _convert(self, obj, result=None):
     if type(obj) is NativeBVV:
         return z3.BitVecVal(obj.value, obj.bits)
     elif isinstance(obj, FSort):
         return z3.FPSort(obj.exp, obj.mantissa)
     elif isinstance(obj, RM):
         if obj == RM_RNE:
             return z3.RNE()
         elif obj == RM_RNA:
             return z3.RNA()
         elif obj == RM_RTP:
             return z3.RTP()
         elif obj == RM_RTN:
             return z3.RTN()
         elif obj == RM_RTZ:
             return z3.RTZ()
         else:
             raise BackendError("unrecognized rounding mode")
     elif isinstance(obj, NativeFPV):
         val = str(obj.value)
         sort = self._convert(obj.sort)
         if val == 'inf':
             return z3.fpPlusInfinity(sort)
         elif val == '-inf':
             return z3.fpMinusInfinity(sort)
         elif val == '0.0':
             return z3.fpPlusZero(sort)
         elif val == '-0.0':
             return z3.fpMinusZero(sort)
         elif val == 'nan':
             return z3.fpNaN(sort)
         else:
             better_val = str(Decimal(obj.value))
             return z3.FPVal(better_val, sort)
     elif obj is True:
         return z3.BoolVal(True)
     elif obj is False:
         return z3.BoolVal(False)
     elif type(obj) in (int, long, float, str):
         return obj
     elif hasattr(obj, '__module__') and obj.__module__ == 'z3':
         return obj
     else:
         l.debug("BackendZ3 encountered unexpected type %s", type(obj))
         raise BackendError("unexpected type %s encountered in BackendZ3" %
                            type(obj))
Exemplo n.º 4
0
 def _convert(self, obj, result=None):
     if type(obj) is NativeBVV:
         return z3.BitVecVal(obj.value, obj.bits)
     elif isinstance(obj, FSort):
         return z3.FPSort(obj.exp, obj.mantissa)
     elif isinstance(obj, RM):
         if obj == RM_RNE:
             return z3.RNE()
         elif obj == RM_RNA:
             return z3.RNA()
         elif obj == RM_RTP:
             return z3.RTP()
         elif obj == RM_RTN:
             return z3.RTN()
         elif obj == RM_RTZ:
             return z3.RTZ()
         else:
             raise BackendError("unrecognized rounding mode")
     elif isinstance(obj, NativeFPV):
         val = str(obj.value)
         sort = self._convert(obj.sort)
         if val == 'inf':
             return z3.fpPlusInfinity(sort)
         elif val == '-inf':
             return z3.fpMinusInfinity(sort)
         elif val == '0.0':
             return z3.fpPlusZero(sort)
         elif val == '-0.0':
             return z3.fpMinusZero(sort)
         elif val == 'nan':
             return z3.fpNaN(sort)
         else:
             better_val = str(Decimal(obj.value))
             return z3.FPVal(better_val, sort)
     elif obj is True:
         return z3.BoolVal(True)
     elif obj is False:
         return z3.BoolVal(False)
     elif type(obj) in (int, long, float, str):
         return obj
     elif hasattr(obj, '__module__') and obj.__module__ == 'z3':
         return obj
     else:
         l.debug("BackendZ3 encountered unexpected type %s", type(obj))
         raise BackendError("unexpected type %s encountered in BackendZ3" % type(obj))
Exemplo n.º 5
0
# Constants
# ---------

@eval.register(Literal, BaseSMTTranslator)
def _literal(term, smt):
  ty = smt.type(term)
  if isinstance(ty, FloatType):
    return z3.FPVal(term.val, _ty_sort(ty))

  return z3.BitVecVal(term.val, ty.width)

eval.register(FLiteralVal, BaseSMTTranslator,
  lambda term, smt: z3.FPVal(term.val, _ty_sort(smt.type(term))))

eval.register(FLiteralNaN, BaseSMTTranslator,
  lambda term, smt: z3.fpNaN(_ty_sort(smt.type(term))))

eval.register(FLiteralPlusInf, BaseSMTTranslator,
  lambda term, smt: z3.fpPlusInfinity(_ty_sort(smt.type(term))))

eval.register(FLiteralMinusInf, BaseSMTTranslator,
  lambda term, smt: z3.fpMinusInfinity(_ty_sort(smt.type(term))))

eval.register(FLiteralMinusZero, BaseSMTTranslator,
  lambda term, smt: z3.fpMinusZero(_ty_sort(smt.type(term))))

@eval.register(UndefValue, BaseSMTTranslator)
def _undef(term, smt):
  ty = smt.type(term)
  x = smt.fresh_var(ty)
  smt.add_qvar(x)
Exemplo n.º 6
0

@eval.register(Literal, BaseSMTTranslator)
def _literal(term, smt):
    ty = smt.type(term)
    if isinstance(ty, FloatType):
        return z3.FPVal(term.val, _ty_sort(ty))

    return z3.BitVecVal(term.val, ty.width)


eval.register(FLiteralVal, BaseSMTTranslator,
              lambda term, smt: z3.FPVal(term.val, _ty_sort(smt.type(term))))

eval.register(FLiteralNaN, BaseSMTTranslator,
              lambda term, smt: z3.fpNaN(_ty_sort(smt.type(term))))

eval.register(FLiteralPlusInf, BaseSMTTranslator,
              lambda term, smt: z3.fpPlusInfinity(_ty_sort(smt.type(term))))

eval.register(FLiteralMinusInf, BaseSMTTranslator,
              lambda term, smt: z3.fpMinusInfinity(_ty_sort(smt.type(term))))

eval.register(FLiteralMinusZero, BaseSMTTranslator,
              lambda term, smt: z3.fpMinusZero(_ty_sort(smt.type(term))))


@eval.register(UndefValue, BaseSMTTranslator)
def _undef(term, smt):
    ty = smt.type(term)
    x = smt.fresh_var(ty)