Exemplo n.º 1
0
    def __str__(self):
        ''' Returns a smtlib representation of the current state '''
        result = ''
        translator = TranslatorSmtlib(use_bindings=True)
        for expression in self.constraints:
            translator.visit(expression)

        for d in self.declarations:
            result += d.declaration + '\n'

        for name, exp, smtlib in translator.bindings:
            if isinstance(exp, BitVec):
                result += '(declare-fun %s () (_ BitVec %d))'%(name, exp.size)
            elif isinstance(exp, Bool):
                result += '(declare-fun %s () Bool)' % name
            elif isinstance(exp, Array):
                result += '(declare-fun %s () (Array (_ BitVec %d) (_ BitVec 8)))' % (name, exp.index_bits)
            else:
                raise Exception("Type not supported %r", exp)
            result += '(assert (= %s %s))\n' % (name, smtlib)

        r = translator.pop()
        while r is not None:
            result += '(assert %s)\n' % r
            r = translator.pop()

        return result

        buf = ''
        for d in self.declarations:
            buf += d.declaration + '\n'
        for a in self.constraints:
            buf += '(assert %s)\n' % translate_to_smtlib(a, use_bindings=True)
        return buf
Exemplo n.º 2
0
    def __str__(self):
        ''' Returns a smtlib representation of the current state '''
        result = ''
        translator = TranslatorSmtlib(use_bindings=True)
        for expression in self.constraints:
            translator.visit(expression)

        for d in self.declarations:
            result += d.declaration + '\n'

        for name, exp, smtlib in translator.bindings:
            if isinstance(exp, BitVec):
                result += '(declare-fun %s () (_ BitVec %d))'%(name, exp.size)
            elif isinstance(exp, Bool):
                result += '(declare-fun %s () Bool)' % name
            elif isinstance(exp, Array):
                result += '(declare-fun %s () (Array (_ BitVec %d) (_ BitVec 8)))' % (name, exp.index_bits)
            else:
                raise Exception("Type not supported %r", exp)
            result += '(assert (= %s %s))\n' % (name, smtlib)

        r = translator.pop()
        while r is not None:
            result += '(assert %s)\n' % r
            r = translator.pop()

        return result

        buf = ''
        for d in self.declarations:
            buf += d.declaration + '\n'
        for a in self.constraints:
            buf += '(assert %s)\n' % translate_to_smtlib(a, use_bindings=True)
        return buf
Exemplo n.º 3
0
    def __str__(self):
        ''' Returns a smtlib representation of the current state '''
        result = ''
        translator = TranslatorSmtlib(use_bindings=True)
        for expression in self.constraints:
            translator.visit(expression)

        # band aid hack around the fact that we are double declaring stuff :( :(
        tmp = set()
        for d in self.declarations:
            tmp.add(d.declaration)
        for d in tmp:
            result += d + '\n'

        for name, exp, smtlib in translator.bindings:
            if isinstance(exp, BitVec):
                result += '(declare-fun %s () (_ BitVec %d))' % (name,
                                                                 exp.size)
            elif isinstance(exp, Bool):
                result += '(declare-fun %s () Bool)' % name
            elif isinstance(exp, Array):
                result += '(declare-fun %s () (Array (_ BitVec %d) (_ BitVec %d)))' % (
                    name, exp.index_bits, exp.value_bits)
            else:
                raise Exception("Type not supported %r", exp)
            result += '(assert (= %s %s))\n' % (name, smtlib)

        constraint_str = translator.pop()
        while constraint_str is not None:
            if constraint_str != 'true':
                result += '(assert %s)\n' % constraint_str
            constraint_str = translator.pop()

        return result

        buf = ''
        for d in self.declarations:
            buf += d.declaration + '\n'
        for constraint in self.constraints:
            constraint_str = translate_to_smtlib(constraint, use_bindings=True)
            if constraint_str != 'true':
                buf += '(assert %s)\n' % constraint_str
        return buf