First commit of proof of regfile, not working yet
authorcolepoirier <colepoirier@gmail.com>
Wed, 27 May 2020 17:25:31 +0000 (10:25 -0700)
committercolepoirier <colepoirier@gmail.com>
Wed, 27 May 2020 18:26:56 +0000 (11:26 -0700)
src/soc/regfile/formal/proof_regfile.py [new file with mode: 0644]

diff --git a/src/soc/regfile/formal/proof_regfile.py b/src/soc/regfile/formal/proof_regfile.py
new file mode 100644 (file)
index 0000000..6ecad09
--- /dev/null
@@ -0,0 +1,61 @@
+# This is the proof for Regfile class from regfile/regfile.py
+
+from nmigen import (Module, Signal, Elaboratable, Mux, Cat, Repl,
+                    signed, ResetSignal)
+from nmigen.asserts import (Assert, AnyConst, Assume, Cover, Initial,
+                            Rose, Fell, Stable, Past)
+from nmigen.test.utils import FHDLTestCase
+from nmigen.cli import rtlil
+import unittest
+
+from soc.regfile import Register
+
+
+class Driver(Elaboratable):
+    def __init__(self):
+        pass
+
+    def elaborate(self, platform):
+        m = Module()
+        comb = m.d.comb
+        m.submodules.dut = dut = Register(32)
+
+        width     = dut.width
+        writethru = dut.writethru
+        _rdports  = dut._rdports
+        _wrports  = dut._wrports
+        reg       = dut.reg
+
+        for i in range(8):
+            dut.read_port(f"{i}")
+            dut.write_port(f"{i}")
+
+        comb += reg.eq(AnyConst(32))
+
+        for i in range(0,len(_rdports)):
+            with m.If(_rdports[i].ren & writethru):
+                with m.If(_wrports[i].wen):
+                    comb += Assert(rdports[i].data_o == _wrports[i].data_i)
+                with m.Else():
+                    comb += Assert(rdports[i].data_o == reg)
+            with m.Else():
+                comb += Assert(_rdports[i].data_o == reg)
+
+        return m
+
+
+    def TestCase(FHDLTestCase):
+        def test_formal(self):
+            module = Driver()
+            self.assertFormal(module, mode="bmc", depth=2)
+            self.assertFormal(module, mode="cover", depth=2)
+
+        def test_ilang(self):
+            dut = Driver()
+            vl = rtlil.convert(dut, ports=[])
+            with open("regfile.il", "w") as f:
+                f.write(vl)
+
+
+if __name__ == '__main__':
+    unittest.main()