Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 12th, 2013  |  syntax: None  |  size: 1.11 KB  |  views: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. From 60883bea6b1ce168cd997d989c4e3d20901c5179 Mon Sep 17 00:00:00 2001
  2. From: Lars-Peter Clausen <lars@metafoo.de>
  3. Date: Tue, 19 Mar 2013 10:05:45 +0100
  4. Subject: [PATCH] Implement __len__ for Splice, Cat and Replicate
  5.  
  6. ---
  7.  migen/fhdl/structure.py |    9 +++++++++
  8.  1 files changed, 9 insertions(+), 0 deletions(-)
  9.  
  10. diff --git a/migen/fhdl/structure.py b/migen/fhdl/structure.py
  11. index 350670f..32a13ff 100644
  12. --- a/migen/fhdl/structure.py
  13. +++ b/migen/fhdl/structure.py
  14. @@ -126,17 +126,26 @@ class _Slice(Value):
  15.                 self.start = start
  16.                 self.stop = stop
  17.  
  18. +       def __len__(self):
  19. +               return self.stop - self.start + 1
  20. +
  21.  class Cat(Value):
  22.         def __init__(self, *args):
  23.                 Value.__init__(self)
  24.                 self.l = args
  25.  
  26. +       def __len__(self):
  27. +               return sum([len(x) for x in self.l])
  28. +
  29.  class Replicate(Value):
  30.         def __init__(self, v, n):
  31.                 Value.__init__(self)
  32.                 self.v = v
  33.                 self.n = n
  34.  
  35. +       def __len__(self):
  36. +               return len(self.v) * n
  37. +
  38.  class Signal(Value):
  39.         def __init__(self, bits_sign=None, name=None, variable=False, reset=0, name_override=None, min=None, max=None):
  40.                 Value.__init__(self)
  41. --
  42. 1.7.2.5
clone this paste RAW Paste Data