fhdl: improve automatic signal naming
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Dec 2011 20:28:20 +0000 (21:28 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 8 Dec 2011 20:28:20 +0000 (21:28 +0100)
migen/fhdl/structure.py

index 6097c243372d5564461cb1b629f7e4ce190cd04c..f1ecb0e4c144d851cb5316c83ca624ab9fffc832 100644 (file)
@@ -120,7 +120,13 @@ class Signal(Value):
                return id(self)
 
 def Declare(parent, name, bv=BV(), variable=False, reset=0):
-       setattr(parent, name, Signal(bv, parent.__class__.__name__ + "_" + name, variable, reset))
+       # try to find a meaningful prefix
+       if parent.__module__ == "__main__":
+               prefix = parent.__class__.__name__
+       else:
+               modules = parent.__module__.split('.')
+               prefix = modules[len(modules)-1]
+       setattr(parent, name, Signal(bv, prefix + "_" + name, variable, reset))
 
 # statements