remove genlib.misc.optree (use reduce instead)
authorSebastien Bourdeauducq <sb@m-labs.hk>
Thu, 10 Sep 2015 20:56:56 +0000 (13:56 -0700)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Thu, 10 Sep 2015 20:56:56 +0000 (13:56 -0700)
examples/basic/namer.py
examples/sim/fir.py
migen/genlib/misc.py
migen/genlib/record.py

index 0983520ef1afefa59f0f9f4c4a39ca94ea285c90..670de37e20b2564b3d8289145c6a3cbaf3bcf7ce 100644 (file)
@@ -1,6 +1,8 @@
 from migen.fhdl.std import *
 from migen.fhdl import verilog
-from migen.genlib.misc import optree
+
+from functools import reduce
+from operator import or_
 
 
 def gen_list(n):
@@ -37,6 +39,6 @@ class Example(Module):
         for lst in [a, b, c]:
             for obj in lst:
                 allsigs.extend(obj.sigs)
-        self.comb += output.eq(optree("|", allsigs))
+        self.comb += output.eq(reduce(or_, allsigs))
 
 print(verilog.convert(Example()))
index e31cc144bace8847fb49d1bfdd5a1e925a146d28..641f6b38a08cafa0d8faf7219219dc0d038f0c5a 100644 (file)
@@ -4,9 +4,10 @@ import matplotlib.pyplot as plt
 
 from migen.fhdl.std import *
 from migen.fhdl import verilog
-from migen.genlib.misc import optree
 from migen.sim.generic import run_simulation
 
+from functools import reduce
+from operator import add
 
 # A synthesizable FIR filter.
 class FIR(Module):
@@ -27,7 +28,7 @@ class FIR(Module):
             c_fp = int(c*2**(self.wsize - 1))
             muls.append(c_fp*sreg)
         sum_full = Signal((2*self.wsize-1, True))
-        self.sync += sum_full.eq(optree("+", muls))
+        self.sync += sum_full.eq(reduce(add, muls))
         self.comb += self.o.eq(sum_full[self.wsize-1:])
 
 
index bd7828633250a5c94c2c4280e204c95217ee9ec4..aa610da3ddeddee70dcd22b057b8e3bc988da5af 100644 (file)
@@ -1,25 +1,4 @@
 from migen.fhdl.std import *
-from migen.fhdl.structure import _Operator
-
-
-def optree(op, operands, lb=None, ub=None, default=None):
-    if lb is None:
-        lb = 0
-    if ub is None:
-        ub = len(operands)
-    l = ub - lb
-    if l == 0:
-        if default is None:
-            raise AttributeError
-        else:
-            return default
-    elif l == 1:
-        return operands[lb]
-    else:
-        s = lb + l//2
-        return _Operator(op,
-            [optree(op, operands, lb, s, default),
-            optree(op, operands, s, ub, default)])
 
 
 def split(v, *counts):
index 05151bc678cb92c4ccc677aae4c4f03ceecc356c..238c9140d6f3dfb4b1929ed154d52a229424c836 100644 (file)
@@ -1,6 +1,9 @@
 from migen.fhdl.std import *
 from migen.fhdl.tracer import get_obj_var_name
-from migen.genlib.misc import optree
+
+from functools import reduce
+from operator import or_
+
 
 (DIR_NONE, DIR_S_TO_M, DIR_M_TO_S) = range(3)
 
@@ -141,7 +144,7 @@ class Record:
                     if direction == DIR_M_TO_S:
                         r += [getattr(slave, field).eq(self_e) for slave in slaves]
                     elif direction == DIR_S_TO_M:
-                        r.append(self_e.eq(optree("|", [getattr(slave, field) for slave in slaves])))
+                        r.append(self_e.eq(reduce(or_, [getattr(slave, field) for slave in slaves])))
                     else:
                         raise TypeError
                 else:
@@ -164,7 +167,7 @@ class Record:
                     s_signal, s_direction = next(iter_slave)
                     assert(s_direction == DIR_S_TO_M)
                     s_signals.append(s_signal)
-                r.append(m_signal.eq(optree("|", s_signals)))
+                r.append(m_signal.eq(reduce(or_, s_signals)))
             else:
                 raise TypeError
         return r