Exemple #1
0
    def test_depict_bv_3(self):
        x = ["and", ["=", "var_x", ["_", "bv1", "8"]], ["=", ["bvurem", "var_y", ["_", "bv2", "8"]], ["_", "bv0", "8"]]]
        res, vars = depict.depict_bv(x, 8)
        expect = """^var_y
>var_x
........
.*......
........
.*......
........
.*......
........
.*......
"""
        self.assertEqual(res, expect)
Exemple #2
0
    def test_depict_bv_2(self):
        x = ["bvult", "var_x", ["bvadd", "var_y", ["_", "bv2", "8"]]]
        res, vars = depict.depict_bv(x, 8)
        expect = """^var_y
>var_x
*.......
........
*******.
******..
*****...
****....
***.....
**......
"""
        self.assertEqual(res, expect)
    def test_convert_lia2bv(self):
        m = 8
        s = "(and (<= 0 var_9_i) (<= var_9_i 7) (<= (+ var_9_i (* -8 (floor (* 1/8 (* 1 var_9_i))))) 0) (<= (+ var_5_x (* -4 (floor (* 1/4 (* 1 var_5_x))))) 0))"
        t = util.read_tree(s)
        opt = util.SMTUtilOption("strategy1", False, True)
        res = treeutil.convert_lia2bv(t, m, opt)
        pict = depict.depict_bv(res, 8)[0]
        ress = util.debug_print_list(res)
        expect = """^var_9_i
>var_5_x
........
........
........
........
........
........
........
*...*...
"""
        self.assertEqual(expect, pict)
Exemple #4
0
 def test_depict_bv(self):
     x = ["bvult", "var_x", 3]
     res, vars = depict.depict_bv(x, 8)
     self.assertEqual(res, ">var_x\n***.....\n")
Exemple #5
0
    def print(self, name="unwind", debug=False, draw=True, format="png"):
        if debug:
            logging.debug("The debug print of graph is omitted")
            return
        if draw:
            # usual
            G = Digraph(format=format)
            for n in self.nodes:
                # logging.debug(f"node from {n.id}")
                c = "(C)" if n in self.covereds else ""
                G.node(str(n.id), f"{n.get_info()}{c}")
            for e in self.edges:
                # logging.debug(f"edge from {e.src.id} to {e.tgt.id}")
                if self.error_trace is not None and e in self.error_trace:
                    color = "red"
                else:
                    color = "black"
                G.edge(str(e.src.id), str(e.tgt.id), str(e.id), color=color)
            for covered, covering in self.coverings:
                G.edge(str(covered.id), str(covering.id), style="dotted")
            G.render("out/" + name)

            # covereds are dropped
            G = Digraph(format=format)
            droppeds = set()
            for n in self.nodes:
                if n in self.covereds and n.coming.src in self.covereds:
                    droppeds.add(n)
                    continue
                c = "(C)" if n in self.covereds else ""
                G.node(str(n.id), f"{n.get_info()}{c}")
            for e in self.edges:
                if e.src in droppeds or e.tgt in droppeds:
                    continue
                # logging.debug(f"edge from {e.src.id} to {e.tgt.id}")
                if self.error_trace is not None and e in self.error_trace:
                    color = "red"
                else:
                    color = "black"
                G.edge(str(e.src.id), str(e.tgt.id), str(e.id), color=color)
            for covered, covering in self.coverings:
                if covered in droppeds or covering in droppeds:
                    continue
                G.edge(str(covered.id), str(covering.id), style="dotted")
            G.render("out/" + name + "_dropped")

        # text
        with open("out/unwind.txt", "w") as f:
            for n in self.nodes:
                f.writelines(
                    [str(n.id), "\n",
                     debug_print_list(n.label), "\n"])
                if self.config.theory == "liabv":
                    m = 2**self.config.bitwidth
                    if draw:
                        f.write(depict.depict_bv(n.label, m)[0])
                f.write("-" * 40 + "\n")
        # covering
        with open("out/covering.txt", "w") as f:
            for cfrom, cto in self.coverings:
                if cto in self.covereds:
                    print("Wow!")
                f.write(f"[{cfrom.get_info()}->{cto.get_info()}]\n")
                f.write(debug_print_list(cfrom.label) + "\n")
                f.write(debug_print_list(cto.label) + "\n")
                if self.config.theory == "liabv":
                    m = 2**self.config.bitwidth
                    f.write(
                        debug_print_list(
                            simplifier.erase_obvious_connectives(
                                treeutil.convert_bv2lia(cfrom.label, m))) +
                        "\n")
                    f.write(
                        debug_print_list(
                            simplifier.erase_obvious_connectives(
                                treeutil.convert_bv2lia(cto.label, m))) + "\n")
                    f.write(depict.depict_bv(cfrom.label, m)[0])
                    f.write(depict.depict_bv(cto.label, m)[0])
                f.write("-" * 80 + "\n")
        print("hoge")