create separate pipeline examples
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 29 Mar 2019 11:29:32 +0000 (11:29 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 29 Mar 2019 11:29:32 +0000 (11:29 +0000)
src/add/pipeline_example.py

index 44d453da35a5ea648b9a1c7b026867416f0b4b80..6474a39684fac4a20ddba37c835d75421caa3722 100644 (file)
@@ -13,9 +13,36 @@ class SimplePipelineExample(SimplePipeline):
     def __init__(self, pipe):
         SimplePipeline.__init__(self, pipe)
         self._loopback = Signal(4)
-        self._obj = ObjectProxy(pipe)
-        self._obj.a = Signal(4)
-        self._obj.b = Signal(4)
+        self._setup()
+
+    def stage0(self):
+        self.n = ~self._loopback
+
+    def stage1(self):
+        self.n = self.n + 2
+
+    def stage2(self):
+        localv = Signal(4)
+        self._pipe.comb += localv.eq(2)
+        self.n = self.n << localv
+
+    def stage3(self):
+        self.n = ~self.n
+
+    def stage4(self):
+        self._pipe.sync += self._loopback.eq(self.n + 3)
+
+
+class ObjectBasedPipelineExample(SimplePipeline):
+    """ A very simple pipeline to show how registers are inferred. """
+
+    def __init__(self, pipe):
+        ObjectBasedPipeline.__init__(self, pipe)
+        self._loopback = Signal(4)
+        o = ObjectProxy(pipe)
+        o.a = Signal(4)
+        o.b = Signal(4)
+        self._obj = o
         self._setup()
 
     def stage0(self):
@@ -24,16 +51,18 @@ class SimplePipelineExample(SimplePipeline):
 
     def stage1(self):
         self.n = self.n + self.o.a
-        self.o = self.o
-        self.o.a = self.n
-        self.o.b = self.o.b
+        o = ObjectProxy(self._pipe)
+        o.a = self.n
+        o.b = self.o.b
+        self.o = o
 
     def stage2(self):
         localv = Signal(4)
         self._pipe.comb += localv.eq(2)
         self.n = self.n << localv
-        self.o = self.o
-        self.o.b = self.n + self.o.a + self.o.b
+        o = ObjectProxy(self._pipe)
+        o.b = self.n + self.o.a + self.o.b
+        self.o = o
 
     def stage3(self):
         self.n = ~self.n
@@ -41,14 +70,14 @@ class SimplePipelineExample(SimplePipeline):
         self.o.b = self.o.b + self.n
 
     def stage4(self):
-        self.o.b = self.o.b
         self._pipe.sync += self._loopback.eq(self.n + 3 + self.o.b)
 
+
 class PipeModule:
 
     def __init__(self):
         self.m = Module()
-        self.p = SimplePipelineExample(self.m.d)
+        self.p = ObjectBasedPipelineExample(self.m.d)
 
     def get_fragment(self, platform=None):
         return self.m