예제 #1
0
 def __init__(self, message=None, node_type=None, expression=None):
     if message is None:
         message = "Unsupported operator '%s' (node_type: %d)" % (op.op_to_str(node_type), node_type)
     Exception.__init__(self)
     self.message = message
     self.expression = expression
     self.node_type = node_type
예제 #2
0
    def __init__(self, env=None):
        if env is None:
            import pysmt.environment
            env = pysmt.environment.get_env()
        self.env = env

        self.functions = {}
        self.functions[op.FORALL] = self.walk_forall
        self.functions[op.EXISTS] = self.walk_exists
        self.functions[op.AND] = self.walk_and
        self.functions[op.OR] = self.walk_or
        self.functions[op.NOT] = self.walk_not
        self.functions[op.IMPLIES] = self.walk_implies
        self.functions[op.IFF] = self.walk_iff
        self.functions[op.SYMBOL] = self.walk_symbol
        self.functions[op.FUNCTION] = self.walk_function
        self.functions[op.REAL_CONSTANT] = self.walk_real_constant
        self.functions[op.BOOL_CONSTANT] = self.walk_bool_constant
        self.functions[op.INT_CONSTANT] = self.walk_int_constant
        self.functions[op.PLUS] = self.walk_plus
        self.functions[op.MINUS] = self.walk_minus
        self.functions[op.TIMES] = self.walk_times
        self.functions[op.EQUALS] = self.walk_equals
        self.functions[op.LE] = self.walk_le
        self.functions[op.LT] = self.walk_lt
        self.functions[op.ITE] = self.walk_ite
        self.functions[op.TOREAL] = self.walk_toreal

        self.functions[op.BV_CONSTANT] = self.walk_bv_constant
        self.functions[op.BV_CONCAT] = self.walk_bv_concat
        self.functions[op.BV_EXTRACT] = self.walk_bv_extract
        self.functions[op.BV_NOT] = self.walk_bv_not
        self.functions[op.BV_AND] = self.walk_bv_and
        self.functions[op.BV_OR] = self.walk_bv_or
        self.functions[op.BV_XOR] = self.walk_bv_xor
        self.functions[op.BV_ULT] = self.walk_bv_ult
        self.functions[op.BV_ULE] = self.walk_bv_ule
        self.functions[op.BV_NEG] = self.walk_bv_neg
        self.functions[op.BV_ADD] = self.walk_bv_add
        self.functions[op.BV_SUB] = self.walk_bv_sub
        self.functions[op.BV_MUL] = self.walk_bv_mul
        self.functions[op.BV_UDIV] = self.walk_bv_udiv
        self.functions[op.BV_UREM] = self.walk_bv_urem
        self.functions[op.BV_LSHL] = self.walk_bv_lshl
        self.functions[op.BV_LSHR] = self.walk_bv_lshr
        self.functions[op.BV_ROL] = self.walk_bv_rol
        self.functions[op.BV_ROR] = self.walk_bv_ror
        self.functions[op.BV_ZEXT] = self.walk_bv_zext
        self.functions[op.BV_SEXT] = self.walk_bv_sext
        self.functions[op.BV_SLT] = self.walk_bv_slt
        self.functions[op.BV_SLE] = self.walk_bv_sle
        self.functions[op.BV_COMP] = self.walk_bv_comp
        self.functions[op.BV_SDIV] = self.walk_bv_sdiv
        self.functions[op.BV_SREM] = self.walk_bv_srem
        self.functions[op.BV_ASHR] = self.walk_bv_ashr

        undefined_types = set(op.ALL_TYPES) - set(self.functions.keys())
        assert len(undefined_types) == 0, \
            "The following types are not defined in the generic walker: {%s}" % \
            (", ".join(op.op_to_str(u) for u in undefined_types))
예제 #3
0
    def __init__(self, env=None):
        if env is None:
            import pysmt.environment
            env = pysmt.environment.get_env()
        self.env = env

        self.functions = {}
        self.functions[op.FORALL] = self.walk_forall
        self.functions[op.EXISTS] = self.walk_exists
        self.functions[op.AND] = self.walk_and
        self.functions[op.OR] = self.walk_or
        self.functions[op.NOT] = self.walk_not
        self.functions[op.IMPLIES] = self.walk_implies
        self.functions[op.IFF] = self.walk_iff
        self.functions[op.SYMBOL] = self.walk_symbol
        self.functions[op.FUNCTION] = self.walk_function
        self.functions[op.REAL_CONSTANT] = self.walk_real_constant
        self.functions[op.BOOL_CONSTANT] = self.walk_bool_constant
        self.functions[op.INT_CONSTANT] = self.walk_int_constant
        self.functions[op.PLUS] = self.walk_plus
        self.functions[op.MINUS] = self.walk_minus
        self.functions[op.TIMES] = self.walk_times
        self.functions[op.EQUALS] = self.walk_equals
        self.functions[op.LE] = self.walk_le
        self.functions[op.LT] = self.walk_lt
        self.functions[op.ITE] = self.walk_ite
        self.functions[op.TOREAL] = self.walk_toreal

        self.functions[op.BV_CONSTANT] = self.walk_bv_constant
        self.functions[op.BV_CONCAT] = self.walk_bv_concat
        self.functions[op.BV_EXTRACT] = self.walk_bv_extract
        self.functions[op.BV_NOT] = self.walk_bv_not
        self.functions[op.BV_AND] = self.walk_bv_and
        self.functions[op.BV_OR] = self.walk_bv_or
        self.functions[op.BV_XOR] = self.walk_bv_xor
        self.functions[op.BV_ULT] = self.walk_bv_ult
        self.functions[op.BV_ULE] = self.walk_bv_ule
        self.functions[op.BV_NEG] = self.walk_bv_neg
        self.functions[op.BV_ADD] = self.walk_bv_add
        self.functions[op.BV_SUB] = self.walk_bv_sub
        self.functions[op.BV_MUL] = self.walk_bv_mul
        self.functions[op.BV_UDIV] = self.walk_bv_udiv
        self.functions[op.BV_UREM] = self.walk_bv_urem
        self.functions[op.BV_LSHL] = self.walk_bv_lshl
        self.functions[op.BV_LSHR] = self.walk_bv_lshr
        self.functions[op.BV_ROL] = self.walk_bv_rol
        self.functions[op.BV_ROR] = self.walk_bv_ror
        self.functions[op.BV_ZEXT] = self.walk_bv_zext
        self.functions[op.BV_SEXT] = self.walk_bv_sext
        self.functions[op.BV_SLT] = self.walk_bv_slt
        self.functions[op.BV_SLE] = self.walk_bv_sle
        self.functions[op.BV_COMP] = self.walk_bv_comp
        self.functions[op.BV_SDIV] = self.walk_bv_sdiv
        self.functions[op.BV_SREM] = self.walk_bv_srem
        self.functions[op.BV_ASHR] = self.walk_bv_ashr

        undefined_types = set(op.ALL_TYPES) - set(self.functions.keys())
        assert len(undefined_types) == 0, \
            "The following types are not defined in the generic walker: {%s}" % \
            (", ".join(op.op_to_str(u) for u in undefined_types))
예제 #4
0
def to_json(node, debug=False):
    if debug: print(node, node.get_type(), node.args())
    if node.is_real_constant():
        type_str = "0_REAL_CONSTANT"  #hack to put real constant at the end
    else:

        type_str = pyopt.op_to_str(node.node_type())
        if debug:
            print("NODE TYPE:", node.node_type())
            print("TYPE_STR:", type_str)
    if len(node.args()) == 0:
        obj = {"type": type_str, "content": calculate_val(node)}
        return obj
    else:
        args = []
        for a in node.args():
            args.append(to_json(a, debug))
        obj = {"type": type_str, "content": args}
        return obj
예제 #5
0
def nt_to_fun(o):
    """Returns the name of the walk function for the given nodetype."""
    return "walk_%s" % op.op_to_str(o).lower()