call value_bits_sign direct
[rv32.git] / pipestage.py
index dfa2a3ef42eeb7744db5b6a3aaa7c8256543ffdf..91087a0ae54e9eae0a80739aa8a41be2edbe176d 100644 (file)
@@ -1,8 +1,9 @@
 """ Example 5: Making use of PyRTL and Introspection. """
 
 from copy import deepcopy
-from migen import *
+from migen import Module, Signal
 from migen.fhdl import verilog
+from migen.fhdl.bitcontainer import value_bits_sign
 
 
 # The following example shows how pyrtl can be used to make some interesting
@@ -21,7 +22,10 @@ class SimplePipeline(object):
         self._current_stage_num = 0
 
     def _setup(self):
-        stage_list = [method for method in dir(self) if method.startswith('stage')]
+        stage_list = []
+        for method in dir(self):
+            if method.startswith('stage'):
+                stage_list.append(method)
         for stage in sorted(stage_list):
             stage_method = getattr(self, stage)
             stage_method()
@@ -43,8 +47,7 @@ class SimplePipeline(object):
             next_stage = self._current_stage_num + 1
             pipereg_id = str(self._current_stage_num) + 'to' + str(next_stage)
             rname = 'pipereg_' + pipereg_id + '_' + name
-            #new_pipereg = pyrtl.Register(bitwidth=len(value), name=rname)
-            new_pipereg = Signal(len(value), name_override=rname)
+            new_pipereg = Signal(value_bits_sign(value), name_override=rname)
             if next_stage not in self._pipeline_register_map:
                 self._pipeline_register_map[next_stage] = {}
             self._pipeline_register_map[next_stage][name] = new_pipereg
@@ -56,11 +59,10 @@ class SimplePipelineExample(SimplePipeline):
 
     def __init__(self, pipe):
         super(SimplePipelineExample, self).__init__(pipe)
-        self._loopback = Signal()
+        self._loopback = Signal(4)
         self._setup()
 
     def stage0(self):
-        n = Signal()
         self.n = ~self._loopback
 
     def stage1(self):