def test_ite(self): b = Bool("b") x = BitVec(32, "x") y = BitVec(32, "y") z = BitVec(32, "z") v = ite(32, x == 0, y, z) w = ite(32, b, y, z) self.assertEqual(v.value, "(ite (= x #x00000000) y z)") self.assertEqual(w.value, "(ite b y z)")
def _translate_bsh(self, oprnd1, oprnd2, oprnd3): """Return a formula representation of a BSH instruction. """ assert oprnd1.size and oprnd2.size and oprnd3.size assert oprnd1.size == oprnd2.size op1_var = self._translate_src_oprnd(oprnd1) op2_var = self._translate_src_oprnd(oprnd2) op3_var, op3_var_constrs = self._translate_dst_oprnd(oprnd3) if oprnd3.size > oprnd1.size: op1_var_zx = smtfunction.zero_extend(op1_var, oprnd3.size) op2_var_zx = smtfunction.zero_extend(op2_var, oprnd3.size) op2_var_neg_sx = smtfunction.sign_extend(-op2_var, oprnd3.size) shr = smtfunction.extract(op1_var_zx >> op2_var_neg_sx, 0, op3_var.size) shl = smtfunction.extract(op1_var_zx << op2_var_zx, 0, op3_var.size) elif oprnd3.size < oprnd1.size: shr = smtfunction.extract(op1_var >> -op2_var, 0, op3_var.size) shl = smtfunction.extract(op1_var << op2_var, 0, op3_var.size) else: shr = op1_var >> -op2_var shl = op1_var << op2_var result = smtfunction.ite(oprnd3.size, op2_var >= 0, shl, shr) return [op3_var == result] + op3_var_constrs
def _translate_bisz(self, oprnd1, oprnd2, oprnd3): """Return a formula representation of a BISZ instruction. """ assert oprnd1.size and oprnd3.size op1_var = self._translate_src_oprnd(oprnd1) op3_var, op3_var_constrs = self._translate_dst_oprnd(oprnd3) result = smtfunction.ite(oprnd3.size, op1_var == 0x0, smtsymbol.Constant(oprnd3.size, 0x1), smtsymbol.Constant(oprnd3.size, 0x0)) return [op3_var == result] + op3_var_constrs