def tuple_array_create(self, arr_type, fields, const_array, domain):
        # Two things this can be: a constant array where each element has the
        # provided value, or just an array of values. As it happens, this is
        # trivial to implement in Z3.
        arr_sort = self.convert_sort(arr_type)
        if const_array:
            ast = z3.K(arr_sort.dom_sort.sort, fields[0].ast)
            arr_ast = Z3ast(ast, self, arr_sort)
        else:
            # Generate a fresh array
            arr_name = "fresh_tuple_array_create_{}".format(self.fresh_arr_idx)
            self.fresh_arr_idx += 1
            arr = z3.Const(arr_name, arr_sort.sort)
            arr_ast = Z3ast(arr, self, arr_sort)

            # Save initial ast... it's not referred to anywhere, and passing
            # it into update method won't keep it alive.
            self.store_ast(arr_ast)

            # Store at increasing indexes, the values from fields. Alas, there
            # isn't a python utility for easy constant int creation like C++.
            for x in range(len(fields)):
                intval = esbmc.BigInt(x)
                dom_type = esbmc.type.unsignedbv.make(
                    arr_sort.dom_sort.data_width)
                intexpr = esbmc.expr.constant_int.make(dom_type, intval)
                arr_ast = arr_ast.update(self, fields[x], x, intexpr)

        return arr_ast
Beispiel #2
0
    def symex_step(self, art):
        # Pick out src obj
        gss = art.get_cur_state().get_active_state()
        src = gss.source
        # pc becomes an insn number, lookup insns. Select current insn
        insns = src.prog.get_instructions()
        localpc = src.pc - insns[0].location_number
        insn = src.prog.get_instructions()[localpc]

        normal = True
        if insn.type == gptypes.FUNCTION_CALL:
            # Pick out function calls
            call = esbmc.downcast_expr(insn.code)
            sym = esbmc.downcast_expr(call.function)

            # Pick out the desired function
            if sym.name.as_string() == 'c::foobar':
                # Build a constant for 'one'
                bigint = esbmc.BigInt(1)
                ubv = esbmc.type.unsignedbv.make(32)
                one = esbmc.expr.constant_int.make(ubv, bigint)

                # Assign one to the given return symbol
                exobj.symex_assign_symbol(call.return_sym, one, gss.guard)

                # Increment the program counter _past_ the call we just
                # interpreted, set normal to indicate this shouldn't be
                # interpreted by the usual symex_step operation.
                src.pc += 1
                normal = False
        
        if normal: 
            super(ExState2, self).symex_step(art)
Beispiel #3
0
    def test_fixedbv(self):
        import esbmc
        fbv = esbmc.fixedbv()
        fbv_spec = esbmc.fixedbv_spec(32, 32)
        fbv.spec = fbv_spec
        fbv.from_integer(esbmc.BigInt(0))

        fbvt = esbmc.type.fixedbv.make(32, 32)
        const_fbv = esbmc.expr.constant_fixedbv.make(fbvt, fbv)
        reftext = "constant_fixedbv\n* value : 0\n* type : fixedbv\n  * width : 32\n  * integer_bits : 32"
        self.assertTrue(const_fbv.pretty(0) == reftext, "Created fixedbv has wrong form")
Beispiel #4
0
 def make_bigint(self, value=0):
     import esbmc
     return esbmc.BigInt(value)
 def get_bv(self, thetype, ast):
     val = self.solver.model().eval(ast.ast)
     val = val.as_long()
     expr = esbmc.expr.constant_int.make(thetype, esbmc.BigInt(val))
     return expr